郑州颐和随访系统

ConversationController.cs 17KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Web;
  5. using System.Web.Mvc;
  6. using CallCenterApi.Interface.Controllers.Base;
  7. using System.Data;
  8. using CallCenter.Utility;
  9. using CallCenterApi.Common;
  10. using CallCenterApi.DB;
  11. using System.IO;
  12. using NPOI.XSSF.UserModel;
  13. using NPOI.HSSF.UserModel;
  14. using NPOI.SS.UserModel;
  15. using Newtonsoft.Json;
  16. using CallCenterApi.Interface.Models.Input;
  17. using System.Text.RegularExpressions;
  18. namespace CallCenterApi.Interface.Controllers
  19. {
  20. public class ConversationController : BaseController
  21. {
  22. BLL.T_Con_Conversation bll = new BLL.T_Con_Conversation();
  23. BLL.T_Sys_Department bll_Dep = new BLL.T_Sys_Department();
  24. /// <summary>
  25. /// 获取内外线列表
  26. /// </summary>
  27. /// <returns></returns>
  28. public ActionResult GetList()
  29. {
  30. ActionResult res = NoToken("未知错误,请重新登录");
  31. if (Request.IsAuthenticated)
  32. {
  33. string sql = " and F_IsDelete=0";
  34. DataTable dt = new DataTable();
  35. string keyword = RequestString.GetQueryString("keyword");
  36. //电话
  37. string strtel = RequestString.GetQueryString("tel");
  38. //部门id
  39. int department = RequestString.GetInt("department", 0);
  40. //科室id
  41. int section = RequestString.GetInt("section", 0);
  42. //医师
  43. string physician = RequestString.GetQueryString("physician");
  44. string stringtype = RequestString.GetQueryString("type");
  45. int type = 0;
  46. string strpageindex = RequestString.GetQueryString("pageindex");
  47. int pageindex = 1;
  48. string strpagesize = RequestString.GetQueryString("pagesize");
  49. int pagesize = 10;
  50. if (keyword.Trim() != "" && keyword != "undefined")
  51. {
  52. var modelfept = new BLL.T_Sys_Department().GetModelList("F_DeptName='"+ keyword.Trim()+"'").FirstOrDefault ();
  53. if (modelfept!=null )
  54. {
  55. sql += $" and (F_Department ='" + modelfept.F_DeptId + "' or F_Section= '" + modelfept.F_DeptId + "') ";
  56. }
  57. else
  58. sql += $" and ( F_Telephone like'%" + keyword.Trim() + "%' or F_Title like'%" + keyword.Trim() + "%'" + "or F_Physician like'%" + keyword.Trim() + "%') ";
  59. }
  60. if (strtel.Trim() != "" && strtel != "undefined")
  61. {
  62. sql += " and F_Telephone like'%" + strtel+"%'";
  63. }
  64. if (department > 0)
  65. {
  66. sql += " and F_Department=" + department;
  67. }
  68. if (section > 0)
  69. {
  70. sql += " and F_Section=" + section;
  71. }
  72. if (physician.Trim() != "" && physician != "undefined")
  73. {
  74. sql += " and F_Physician=" + physician;
  75. }
  76. if (strpageindex.Trim() != "")
  77. {
  78. pageindex = Convert.ToInt32(strpageindex);
  79. }
  80. if (strpagesize.Trim() != "")
  81. {
  82. pagesize = Convert.ToInt32(strpagesize);
  83. }
  84. if (stringtype .Trim() != "")
  85. {
  86. type = Convert.ToInt32(stringtype);
  87. sql += " and F_Type=" + type;
  88. }
  89. int recordCount = 0;
  90. dt = BLL.PagerBLL.GetListPager(
  91. "T_Con_Conversation",
  92. "T_Con_Conversation.ID",
  93. "*,(SELECT F_DeptName FROM dbo.T_Sys_Department WHERE F_DeptId = dbo.T_Con_Conversation.F_Department) AS Department_Name,(SELECT F_DeptName FROM dbo.T_Sys_Department WHERE F_DeptId = dbo.T_Con_Conversation.F_Section) AS Section_Name ",
  94. sql,
  95. "ORDER BY T_Con_Conversation.ID desc",
  96. pagesize,
  97. pageindex,
  98. true,
  99. out recordCount);
  100. //List<Model.T_Con_Conversation> modlelist = new BLL.T_Con_Conversation().DataTableToList(dt);
  101. var obj = new
  102. {
  103. state = "success",
  104. message = "成功",
  105. rows = dt,
  106. total = recordCount
  107. };
  108. res = Content(obj.ToJson());
  109. }
  110. return res;
  111. }
  112. /// <summary>
  113. /// 获取内外线列表详情
  114. /// </summary>
  115. /// <returns></returns>
  116. public ActionResult GetDetails()
  117. {
  118. ActionResult res = NoToken("未知错误,请重新登录");
  119. if (Request.IsAuthenticated)
  120. {
  121. int cid = Utils.StrToInt(RequestString.GetQueryString("id"), 0);
  122. if (cid != 0)
  123. {
  124. Model.T_Con_Conversation model = new BLL.T_Con_Conversation().GetModel(cid);
  125. if (model != null)
  126. {
  127. res = Success("获取成功", model);
  128. }
  129. else
  130. {
  131. res = Error("获取失败");
  132. }
  133. }
  134. else
  135. {
  136. res = Error("参数传输失败");
  137. }
  138. }
  139. return res;
  140. }
  141. public class Conversation
  142. {
  143. public int ID { get; set; }
  144. public int F_Type { get; set; }// 1内线2外线
  145. public int F_Department { get; set; }// 部门
  146. public int F_Section { get; set; }//科室
  147. public string F_Telephone { get; set; }//电话
  148. public string F_Physician { get; set; }//医师
  149. public string F_Title { get; set; }//职称
  150. }
  151. /// <summary>
  152. /// 验证客户电话是否唯一
  153. /// </summary>
  154. private bool getunphone(int id, string phone)
  155. {
  156. var sql = " F_IsDelete=0 ";
  157. sql += "and (F_Telephone='" + phone + "')";
  158. if (id > 0)
  159. sql += " and ID<>" + id;
  160. var count = bll.GetModelList(sql).Count();
  161. return count > 0;
  162. }
  163. /// <summary>
  164. /// 添加一键转接三方通话
  165. /// </summary>
  166. /// <returns></returns>
  167. public ActionResult Add(Conversation input)
  168. {
  169. #region 获取部门id by 科室id
  170. var model_Dep = new Model.T_Sys_Department();
  171. int dep_Sectionid = input.F_Section;
  172. if (dep_Sectionid > 0)
  173. model_Dep = bll_Dep.GetModel(dep_Sectionid);
  174. #endregion
  175. #region 添加验证判断
  176. if (string.IsNullOrEmpty(input.F_Telephone))
  177. return Error("电话不能为空!");
  178. if (getunphone(0, input.F_Telephone))
  179. return Error("电话重复请勿重复添加");
  180. if (input.F_Type<=0)
  181. return Error("请选择电话类别");
  182. #endregion
  183. var model = new Model.T_Con_Conversation();
  184. model.F_Type = input.F_Type; //1内线2外线
  185. model.F_Department = model_Dep != null ? model_Dep.F_ParentId : input.F_Department; //部门id
  186. model.F_Section = input.F_Section; // 科室id
  187. model.F_Telephone = input.F_Telephone; // 电话
  188. model.F_Physician = input.F_Physician; //医师
  189. model.F_Title = input.F_Title;//职称
  190. model.F_IsDelete = 0;
  191. int n = bll.Add(model);
  192. if (n > 0)
  193. return Success("新增成功!", model);
  194. else
  195. return Error("新增失败!");
  196. }
  197. /// <summary>
  198. /// 修改一键转接三方通话
  199. /// </summary>
  200. /// <returns></returns>
  201. public ActionResult Update(Conversation input)
  202. {
  203. int userId = CurrentUser.UserData.F_UserId;
  204. #region 获取部门id by 科室id
  205. var model_Dep = new Model.T_Sys_Department();
  206. int dep_Sectionid = input.F_Section;
  207. if(dep_Sectionid > 0)
  208. model_Dep = bll_Dep.GetModel(dep_Sectionid);
  209. #endregion
  210. #region 添加验证判断
  211. if (input.ID <= 0)
  212. return Error("参数错误!");
  213. if (string.IsNullOrEmpty(input.F_Telephone))
  214. return Error("电话不能为空!");
  215. if (input.F_Type <= 0)
  216. return Error("请选择电话类别");
  217. #endregion
  218. var model = bll.GetModel(input.ID);
  219. if (getunphone(0, input.F_Telephone) && input.F_Telephone != model.F_Telephone)
  220. return Error("电话重复请勿重复添加");
  221. model.F_Type = input.F_Type; //1内线2外线
  222. model.F_Department = model_Dep != null ? model_Dep.F_ParentId : input.F_Department; //部门id
  223. model.F_Section = input.F_Section; // 科室id
  224. model.F_Telephone = input.F_Telephone; // 电话
  225. model.F_Physician = input.F_Physician; //医师
  226. model.F_Title = input.F_Title;//职称
  227. model.F_IsDelete = 0;
  228. bool n = bll.Update(model);
  229. if (n)
  230. return Success("保存成功!", model);
  231. else
  232. return Error("保存失败!");
  233. }
  234. /// <summary>
  235. /// 删除一键转接三方通话
  236. /// </summary>
  237. /// <param name="ids"></param>
  238. /// <returns></returns>
  239. public ActionResult DelConver(string[] ids)
  240. {
  241. ActionResult res = NoToken("未知错误,请重新登录");
  242. if (Request.IsAuthenticated)
  243. {
  244. if (ids != null && ids.Length > 0)
  245. {
  246. string idd = " ";
  247. foreach (string str in ids)
  248. {
  249. idd += str + ",";
  250. }
  251. string sql = "update T_Con_Conversation set F_IsDelete=1 where ID in (" + idd.TrimEnd(',') + ")";
  252. if (!string.IsNullOrEmpty(idd.Trim()))
  253. {
  254. if (DbHelperSQL.ExecuteSql(sql) > 0)
  255. {
  256. res = Success("设置成功");
  257. }
  258. else
  259. {
  260. res = Error("设置失败");
  261. }
  262. }
  263. else
  264. {
  265. res = Error("请选择用户");
  266. }
  267. }
  268. else
  269. {
  270. res = Error("获取参数失败");
  271. }
  272. }
  273. return res;
  274. }
  275. /// <summary>
  276. /// 导入excel
  277. /// </summary>
  278. /// <param name="areaid">区域id</param>
  279. /// <param name="regionid">项目id</param>
  280. /// <param name="buldingid">楼号id</param>
  281. /// <returns></returns>
  282. public ActionResult ImportExcel(int type=0)
  283. {
  284. string usercode = CurrentUser.UserData.F_UserCode;
  285. string ip = DTRequest.GetIP();
  286. if (!string.IsNullOrWhiteSpace(usercode))
  287. {
  288. HttpPostedFile _upFile = RequestString.GetFile("upFile");
  289. if (_upFile != null)
  290. {
  291. if (type <= 0)
  292. return Error("请选择上传类别");
  293. int headrow = 0;
  294. #region 上传文件
  295. string filepath = "";
  296. string datepath = DateTime.Now.ToString("yyyyMMddHHMMss");
  297. string aLastName = Path.GetExtension(_upFile.FileName);
  298. string oriname = Path.GetFileNameWithoutExtension(_upFile.FileName);
  299. if (aLastName != ".xls" && aLastName != ".xlsx")
  300. {
  301. return Error("文件类型错误,请选择Excel文件");
  302. }
  303. string newpath = datepath + "_" + _upFile.FileName;
  304. if (!Directory.Exists(Server.MapPath(this.Request.ApplicationPath + "\\ExcelData")))
  305. {
  306. Directory.CreateDirectory(Server.MapPath(this.Request.ApplicationPath + "\\ExcelData"));
  307. }
  308. filepath = this.Request.ApplicationPath + "/ExcelData/" + newpath;
  309. string PhysicalPath = Server.MapPath(filepath);
  310. _upFile.SaveAs(PhysicalPath);
  311. #endregion
  312. #region 添加附件日志
  313. Model.T_Sys_Accessories model_T_Sys_Accessories = new Model.T_Sys_Accessories();
  314. model_T_Sys_Accessories.F_AddTime = DateTime.Now;//上传时间
  315. model_T_Sys_Accessories.F_FileName = newpath;//附件名称
  316. model_T_Sys_Accessories.F_FileType = aLastName;//附件类型
  317. model_T_Sys_Accessories.F_FileUrl = filepath;//附件地址
  318. model_T_Sys_Accessories.F_UserCode = usercode;//上传人
  319. int fid = new BLL.T_Sys_Accessories().Add(model_T_Sys_Accessories);
  320. #endregion
  321. NPOIHelper np = new NPOIHelper();
  322. DataTable dt = np.ExcelToTable(_upFile, headrow);
  323. string msg = string.Empty;
  324. if (dt == null || dt.Rows.Count == 0)
  325. return Error("文件没有数据");
  326. else
  327. {
  328. Model.T_Con_Conversation dModel = new Model.T_Con_Conversation();
  329. dModel.F_IsDelete = 0;
  330. dModel.F_FileId = fid;
  331. dModel.F_Type = type ;
  332. //获取之前所有客户档案信息
  333. var list_Dep = bll_Dep.DataTableToList(bll_Dep.GetList(" 1=1").Tables[0]).ToList();
  334. foreach (DataRow dr in dt.Rows)
  335. {
  336. headrow = headrow + 1;
  337. if (dr["电话"].ToString() != "" )
  338. {
  339. if (!getunphone(0, dr["电话"].ToString()))
  340. {
  341. var model_Dept = list_Dep.SingleOrDefault(x => x.F_DeptName.Equals(dr["部门"].ToString()));
  342. var model_Sec = list_Dep.SingleOrDefault(x => x.F_DeptName.Equals(dr["科室"].ToString()));
  343. dModel.F_Department = model_Dept != null ? model_Dept.F_DeptId : 0; //dr["部门"].ToString();
  344. dModel.F_Section = model_Sec != null ? model_Sec.F_DeptId : 0; //dr["科室"].ToString();
  345. dModel.F_Telephone = dr["电话"].ToString();
  346. if (type == 2)
  347. {
  348. dModel.F_Physician = dr["医师"].ToString();
  349. dModel.F_Title = dr["职称"].ToString();
  350. }
  351. var res = bll.Add(dModel);
  352. if (res <= 0)
  353. {
  354. msg = msg + "第" + headrow + "行,导入失败<br>";
  355. }
  356. }
  357. else
  358. msg = msg + "第" + headrow + "行,电话重复,未导入<br>";
  359. }
  360. else
  361. msg = msg + "第" + headrow + "行,电话为空,未导入<br>";
  362. }
  363. if (string.IsNullOrEmpty(msg))
  364. return Success("导入成功 ");
  365. else
  366. return Error(msg);
  367. }
  368. }
  369. return Error("数据源上传失败");
  370. }
  371. return Error("用户登录失败,请重新登录");
  372. }
  373. }
  374. }