No Description

AddressBookController.cs 24KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578
  1. using CallCenter.Utility;
  2. using CallCenterApi.DB;
  3. using CallCenterApi.Interface.Controllers.Base;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Data;
  7. using System.Linq;
  8. using System.Web;
  9. using System.Web.Mvc;
  10. namespace CallCenterApi.Interface.Controllers
  11. {
  12. public class AddressBookController : BaseController
  13. {
  14. private BLL.T_Cus_AddressBook bll = new BLL.T_Cus_AddressBook();
  15. public class AddressBook
  16. {
  17. public int id { get; set; }
  18. public string F_Name { get; set; }
  19. public string F_Sex { get; set; }
  20. public string F_Address { get; set; }
  21. public string F_Telephone { get; set; }
  22. public string F_Mobile { get; set; }
  23. public string F_ElseMobile { get; set; }
  24. public string F_Position { get; set; }
  25. public string F_Note { get; set; }
  26. public int F_Departmentid { get; set; }
  27. public string F_Area;
  28. public string F_Offce;
  29. public string F_Department;
  30. public string code;
  31. }
  32. public ActionResult Add(AddressBook address )
  33. {
  34. Model.T_Cus_AddressBook model = new Model.T_Cus_AddressBook();
  35. if (string.IsNullOrEmpty(address.F_Name))
  36. {
  37. return Error("姓名不能为空");
  38. }
  39. if (address.F_Departmentid <0)
  40. {
  41. return Error("部门不能为空");
  42. }
  43. if (string.IsNullOrEmpty(address.F_Mobile))
  44. {
  45. return Error("手机号不能为空");
  46. }
  47. if (address.id == 0)
  48. {
  49. model.F_Name = address.F_Name;
  50. model.F_Sex = address.F_Sex;
  51. model.F_Address = address.F_Address;
  52. model.F_Telephone = address.F_Telephone;
  53. model.F_Mobile = address.F_Mobile;
  54. model.F_ElseMobile = address.F_ElseMobile;
  55. var deptment = new BLL.T_Sys_Department().GetModel(address.F_Departmentid);
  56. if (deptment!=null )
  57. {
  58. model.F_Department = deptment.F_DeptName ;
  59. model.F_DepartmentId = deptment.F_DeptId ;
  60. }
  61. model.F_Position = address.F_Position;
  62. model.F_Note = address.F_Note;
  63. int n = bll.Add(model);
  64. if (n > 0)
  65. {
  66. return Success("添加成功", n);
  67. }
  68. else
  69. {
  70. return Error("添加失败");
  71. }
  72. }
  73. else
  74. {
  75. model = bll.GetModel(address.id);
  76. if (model != null)
  77. {
  78. model.F_UserId = address.id;
  79. model.F_Name = address.F_Name;
  80. model.F_Sex = address.F_Sex;
  81. model.F_Address = address.F_Address;
  82. model.F_Telephone = address.F_Telephone;
  83. model.F_Mobile = address.F_Mobile;
  84. model.F_ElseMobile = address.F_ElseMobile;
  85. var deptment = new BLL.T_Sys_Department().GetModel(address.F_Departmentid);
  86. if (deptment != null)
  87. {
  88. model.F_Department = deptment.F_DeptName;
  89. model.F_DepartmentId = deptment.F_DeptId;
  90. }
  91. model.F_Position = address.F_Position;
  92. model.F_Note = address.F_Note;
  93. if (bll.Update(model))
  94. {
  95. return Success("修改成功");
  96. }
  97. else
  98. {
  99. return Error("修改失败");
  100. }
  101. }
  102. return Error("信息不存在");
  103. }
  104. }
  105. public List<AddressBook> AddressBooks(List<Model.T_Cus_AddressBook> addressBooks)
  106. {
  107. List<AddressBook> Input = new List<AddressBook>();
  108. foreach (var it in addressBooks)
  109. {
  110. AddressBook model = new AddressBook();
  111. model.id = it.F_UserId;
  112. model.F_Name = it.F_Name;
  113. if (!string .IsNullOrEmpty (it.F_Name))
  114. {
  115. char[] strCharArr = it.F_Name.ToCharArray();
  116. model. code = GetSpellCode(strCharArr[0].ToString ());
  117. }
  118. model.F_Sex = it.F_Sex;
  119. model.F_Address = it.F_Address;
  120. model.F_Telephone = it.F_Telephone;
  121. model.F_Mobile = it.F_Mobile;
  122. model.F_ElseMobile = it.F_ElseMobile;
  123. model.F_Position = it.F_Position;
  124. model.F_Note = it.F_Note;
  125. if (it.F_DepartmentId >0 )
  126. {
  127. Model.T_Sys_Department t_Sys_Department = new BLL.T_Sys_Department().GetModel(it.F_DepartmentId);
  128. if (t_Sys_Department!=null )
  129. model.F_Department = t_Sys_Department.F_DeptName ;
  130. }
  131. else
  132. model.F_Department = it.F_Department;
  133. var deptment = new BLL.T_Sys_Department().GetModel(it.F_DepartmentId );
  134. if (deptment != null)
  135. {
  136. var deptment1 = new BLL.T_Sys_Department().GetModel(deptment.F_ParentId);
  137. if (deptment.F_Layer ==1)
  138. {
  139. model.F_Offce = deptment.F_DeptName;
  140. if (deptment1 != null)
  141. {
  142. model.F_Area = deptment1.F_DeptName;
  143. }
  144. }
  145. else if (deptment.F_Layer == 2)
  146. {
  147. model.F_Offce = deptment.F_DeptName;
  148. if (deptment1!=null )
  149. {
  150. model.F_Area = deptment1.F_DeptName;
  151. }
  152. }
  153. else if (deptment.F_Layer == 3)
  154. {
  155. if (deptment1 != null)
  156. {
  157. model.F_Offce = deptment1.F_DeptName;
  158. var deptment2 = new BLL.T_Sys_Department().GetModel(deptment.F_ParentId);
  159. if (deptment2!=null )
  160. {
  161. model.F_Area = deptment2.F_DeptName;
  162. }
  163. }
  164. }
  165. else
  166. {
  167. model.F_Offce = deptment.F_DeptName;
  168. if (deptment1 != null)
  169. {
  170. model.F_Area = deptment1.F_DeptName;
  171. }
  172. }
  173. }
  174. Input.Add(model);
  175. }
  176. return Input;
  177. }
  178. /// <summary>
  179. /// 得到一个汉字的拼音第一个字母,如果是一个英文字母则直接返回大写字母
  180. /// </summary>
  181. /// <param name="CnChar">单个汉字</param>
  182. /// <returns>单个大写字母</returns>
  183. private string GetSpellCode(string CnChar)
  184. {
  185. long iCnChar;
  186. byte[] arrCN = System.Text.Encoding.Default.GetBytes(CnChar);
  187. //如果是字母,则直接返回
  188. if (arrCN.Length == 1)
  189. {
  190. CnChar = CnChar.ToUpper();
  191. }
  192. else
  193. {
  194. int area = (short)arrCN[0];
  195. int pos = (short)arrCN[1];
  196. iCnChar = (area << 8) + pos;
  197. // iCnChar match the constant
  198. string letter = "ABCDEFGHJKLMNOPQRSTWXYZ";
  199. int[] areacode = { 45217, 45253, 45761, 46318, 46826, 47010, 47297, 47614,
  200. 48119, 49062, 49324, 49896, 50371, 50614, 50622, 50906,
  201. 51387, 51446, 52218, 52698, 52980, 53689, 54481, 55290 };
  202. for (int i = 0; i < 23; i++)
  203. {
  204. if (areacode[i] <= iCnChar && iCnChar < areacode[i + 1])
  205. {
  206. CnChar = letter.Substring(i, 1);
  207. break;
  208. }
  209. }
  210. }
  211. return CnChar;
  212. }
  213. /// <summary>
  214. /// 获取一条详细信息 Id
  215. /// </summary>
  216. /// <param name="infoid"></param>
  217. /// <returns></returns>
  218. public ActionResult GetAppInfo(string infoid)
  219. {
  220. if (infoid != null && infoid.Trim() != "")
  221. {
  222. Model.T_Cus_AddressBook model = bll.GetModel(int.Parse(infoid.Trim()));
  223. if (model != null)
  224. {
  225. var list = new List<Model.T_Cus_AddressBook>();
  226. if (model != null)
  227. list.Add(model);
  228. List<AddressBook> Input = AddressBooks(list);
  229. return Success("获取成功", Input);
  230. }
  231. else
  232. {
  233. return Error("获取失败");
  234. };
  235. }
  236. else
  237. {
  238. return Error("获取参数失败");
  239. }
  240. }
  241. public ActionResult GetAppList(string keywords)
  242. {
  243. if (Request.IsAuthenticated)
  244. {
  245. int userId = CurrentUser.UserData.F_UserId;
  246. Model.T_Sys_UserAccount userModel = new BLL.T_Sys_UserAccount().GetModel(userId);
  247. int dptid = 0;
  248. if (userModel != null)
  249. {
  250. dptid = userModel.F_DeptId;
  251. }
  252. if (userModel.F_RoleId == 49)
  253. {
  254. dptid = 1;
  255. }
  256. if (userModel.F_See == "5")
  257. return Success("暂无记录");
  258. DataTable dt = new DataTable();
  259. string sql = "F_IsDelete=0 ";
  260. if (!string.IsNullOrEmpty(keywords))
  261. {
  262. var dept = new BLL.T_Sys_Department().GetModelList("F_DeptName like '%" + keywords + "%'").FirstOrDefault();
  263. if (dept != null)
  264. {
  265. if (dptid == 1)
  266. dptid = dept.F_DeptId;
  267. else
  268. {
  269. sql += $" and ( F_Name like '%" + keywords.Trim() + "%'or F_Telephone like '%" + keywords.Trim() + "%'or F_Mobile like '%" + keywords.Trim() + "%'or F_ElseMobile like '%" + keywords.Trim() + "%'or F_Department like '%" + keywords.Trim() + "%' ) ";
  270. }
  271. }
  272. else
  273. {
  274. sql += $" and ( F_Name like '%" + keywords.Trim() + "%'or F_Telephone like '%" + keywords.Trim() + "%'or F_Mobile like '%" + keywords.Trim() + "%'or F_ElseMobile like '%" + keywords.Trim() + "%'or F_Department like '%" + keywords.Trim() + "%' ) ";
  275. }
  276. }
  277. Model.T_Sys_Department deptModel = new BLL.T_Sys_Department().GetModel(dptid);
  278. if (dptid > 0)
  279. {
  280. sql += " and F_DepartmentId in ( select F_DeptId from T_Sys_Department where F_DeptCode like '" + deptModel.F_DeptCode + "%') ";
  281. }
  282. var modelList = bll.GetAPPList(sql+ " order by code asc").Tables[0];
  283. // List<AddressBook> Input = AddressBooks(modelList);
  284. // var modelListOrder = Input.OrderBy(x => x.F_Name);
  285. return Content(modelList.ToJson());
  286. }
  287. return NoToken("未知错误,请重新登录");
  288. }
  289. public ActionResult GetAppModelList(string keywords, int pageindex = 1, int pagesize = 10)
  290. {
  291. if (Request.IsAuthenticated)
  292. {
  293. int userId = CurrentUser.UserData.F_UserId;
  294. Model.T_Sys_UserAccount userModel = new BLL.T_Sys_UserAccount().GetModel(userId);
  295. List<AddressBook> Input = new List<AddressBook>();
  296. int dptid = 0;
  297. if (userModel != null)
  298. {
  299. dptid = userModel.F_DeptId;
  300. }
  301. if (userModel.F_RoleId == 49)
  302. {
  303. dptid = 1;
  304. }
  305. if (userModel.F_See == "5")
  306. return Success("暂无记录");
  307. DataTable dt = new DataTable();
  308. string sql = "F_IsDelete=0 ";
  309. if (!string.IsNullOrEmpty(keywords))
  310. {
  311. var dept = new BLL.T_Sys_Department().GetModelList("F_DeptName like '%" + keywords + "%'").FirstOrDefault();
  312. if (dept != null)
  313. {
  314. if (dptid == 1)
  315. dptid = dept.F_DeptId;
  316. else
  317. {
  318. sql += $" and ( F_Name like '%" + keywords.Trim() + "%'or F_Telephone like '%" + keywords.Trim() + "%'or F_Mobile like '%" + keywords.Trim() + "%'or F_ElseMobile like '%" + keywords.Trim() + "%'or F_Department like '%" + keywords.Trim() + "%' ) ";
  319. }
  320. }
  321. else
  322. {
  323. sql += $" and ( F_Name like '%" + keywords.Trim() + "%'or F_Telephone like '%" + keywords.Trim() + "%'or F_Mobile like '%" + keywords.Trim() + "%'or F_ElseMobile like '%" + keywords.Trim() + "%'or F_Department like '%" + keywords.Trim() + "%' ) ";
  324. }
  325. }
  326. Model.T_Sys_Department deptModel = new BLL.T_Sys_Department().GetModel(dptid);
  327. if (dptid > 0)
  328. {
  329. sql += " and F_DepartmentId in ( select F_DeptId from T_Sys_Department where F_DeptCode like '" + deptModel.F_DeptCode + "%') ";
  330. }
  331. var modelList = bll.GetAPPList(sql + " order by code asc").Tables[0];
  332. if (pageindex* pagesize<modelList .Rows .Count )
  333. {
  334. for (int i=0;i< modelList.Rows .Count;i ++)
  335. {
  336. if (i>= pageindex * pagesize- pagesize&& i< pageindex * pagesize)
  337. {
  338. AddressBook model = new AddressBook();
  339. model = BookData(modelList.Rows[i]);
  340. Input.Add(model);
  341. }
  342. }
  343. }
  344. else
  345. {
  346. for (int i = 0; i < modelList.Rows.Count; i++)
  347. {
  348. AddressBook model = new AddressBook();
  349. model = BookData(modelList.Rows[i]);
  350. Input.Add(model);
  351. }
  352. }
  353. // List<AddressBook> Input = AddressBooks(modelList);
  354. // var modelListOrder = Input.OrderBy(x => x.F_Name);
  355. return Content(Input.ToJson());
  356. }
  357. return NoToken("未知错误,请重新登录");
  358. }
  359. public AddressBook BookData(DataRow dt)
  360. {
  361. AddressBook model = new AddressBook();
  362. if (dt["F_UserId"] != null && dt["F_UserId"].ToString() != "")
  363. model.id = int.Parse (dt["F_UserId"] .ToString());
  364. if (dt["F_Name"] != null && dt["F_Name"].ToString() != "")
  365. model.F_Name = dt["F_Name"].ToString();
  366. if (dt["code"] != null && dt["code"].ToString() != "")
  367. model.code = dt["code"].ToString();
  368. if (dt["F_Sex"] != null && dt["F_Sex"].ToString() != "")
  369. model.F_Sex = dt["F_Sex"].ToString();
  370. if (dt["F_Address"] != null && dt["F_Address"].ToString() != "")
  371. model.F_Address = dt["F_Address"].ToString();
  372. if (dt["F_Telephone"] != null && dt["F_Telephone"].ToString() != "")
  373. model.F_Telephone = dt["F_Telephone"].ToString();
  374. if (dt["F_Mobile"] != null && dt["F_Mobile"].ToString() != "")
  375. model.F_Mobile = dt["F_Mobile"].ToString();
  376. if (dt["F_ElseMobile"] != null && dt["F_ElseMobile"].ToString() != "")
  377. model.F_ElseMobile = dt["F_ElseMobile"].ToString();
  378. if (dt["F_Position"] != null && dt["F_Position"].ToString() != "")
  379. model.F_Position = dt["F_Position"].ToString();
  380. if (dt["F_Note"] != null && dt["F_Note"].ToString() != "")
  381. model.F_Note = dt["F_Note"].ToString();
  382. if (dt["F_Department"] != null && dt["F_Department"].ToString() != "")
  383. model.F_Department = dt["F_Department"].ToString();
  384. if (dt["F_Area"] != null && dt["F_Area"].ToString() != "")
  385. model.F_Area = dt["F_Area"].ToString();
  386. if (dt["F_Offce"] != null && dt["F_Offce"].ToString() != "")
  387. model.F_Offce = dt["F_Offce"].ToString();
  388. return model;
  389. }
  390. /// <summary>
  391. /// 获取一条详细信息 Id
  392. /// </summary>
  393. /// <param name="infoid"></param>
  394. /// <returns></returns>
  395. public ActionResult GetInfo(string infoid)
  396. {
  397. if (infoid != null && infoid.Trim() != "")
  398. {
  399. Model.T_Cus_AddressBook model = bll.GetModel(int.Parse(infoid.Trim()));
  400. if (model != null)
  401. {
  402. return Success("获取成功", model);
  403. }
  404. else
  405. {
  406. return Error("获取失败");
  407. };
  408. }
  409. else
  410. {
  411. return Error("获取参数失败");
  412. }
  413. }
  414. /// <summary>
  415. /// 删除通讯录信息
  416. /// </summary>
  417. /// <param name="ids"></param>
  418. /// <returns></returns>
  419. public ActionResult DelAddressBook(string[] ids)
  420. {
  421. if (ids != null && ids.Length > 0)
  422. {
  423. string idd = " ";
  424. foreach (string str in ids)
  425. {
  426. idd += str + ",";
  427. }
  428. string sql = "UPDATE dbo.T_Cus_AddressBook SET F_IsDelete = 1 WHERE F_UserId in(" + idd.TrimEnd(',') + ")";
  429. if (!string.IsNullOrEmpty(idd.Trim()))
  430. {
  431. if (DbHelperSQL.ExecuteSql(sql) > 0)
  432. {
  433. return Success("设置成功");
  434. }
  435. else
  436. {
  437. return Error("设置失败");
  438. }
  439. }
  440. else
  441. {
  442. return Error("请选择用户");
  443. }
  444. }
  445. else
  446. {
  447. return Error("获取参数失败");
  448. }
  449. }
  450. public ActionResult GetList(string keywords)
  451. {
  452. if (Request.IsAuthenticated)
  453. {
  454. int userId = CurrentUser.UserData.F_UserId;
  455. Model.T_Sys_UserAccount userModel = new BLL.T_Sys_UserAccount().GetModel(userId);
  456. Model.T_Sys_RoleInfo ro = new BLL.T_Sys_RoleInfo().GetModel(userModel.F_RoleId);
  457. int dptid = 0;
  458. if (userModel != null)
  459. {
  460. dptid = userModel.F_DeptId;
  461. }
  462. if (ro.F_RoleCode == "CLZY" || ro.F_RoleCode == "ZR" || ro.F_RoleCode == "XTGLY")
  463. {
  464. dptid = 1;
  465. }
  466. if (userModel.F_See == "5")
  467. return Success("暂无记录");
  468. Model.T_Sys_Department deptModel = new BLL.T_Sys_Department().GetModel(dptid);
  469. DataTable dt = new DataTable();
  470. string sql = "F_IsDelete=0 ";
  471. if (!string.IsNullOrEmpty(keywords))
  472. {
  473. sql += $" and ( F_Name like '%" + keywords.Trim() + "%'or F_Telephone like '%" + keywords.Trim() + "%'or F_Mobile like '%" + keywords.Trim() + "%'or F_ElseMobile like '%" + keywords.Trim() + "%'or F_Department like '%" + keywords.Trim() + "%' ) ";
  474. }
  475. if (dptid > 0)
  476. {
  477. sql += " and F_DepartmentId in ( select F_DeptId from T_Sys_Department where F_DeptCode like '" + deptModel.F_DeptCode + "%') ";
  478. }
  479. var modelList = bll .GetModelList(sql);
  480. List<AddressBook> Input = AddressBooks(modelList);
  481. var modelListOrder = Input.OrderBy(x => x.F_Name );
  482. return Content(modelListOrder.ToJson());
  483. }
  484. return NoToken("未知错误,请重新登录");
  485. }
  486. public ActionResult GetModelList(string keywords, int pageindex = 1, int pagesize = 10)
  487. {
  488. if (Request.IsAuthenticated)
  489. {
  490. int userId = CurrentUser.UserData.F_UserId;
  491. Model.T_Sys_UserAccount userModel = new BLL.T_Sys_UserAccount().GetModel(userId);
  492. Model.T_Sys_RoleInfo ro = new BLL.T_Sys_RoleInfo().GetModel(userModel.F_RoleId);
  493. int dptid = 0;
  494. if (userModel != null)
  495. {
  496. dptid = userModel.F_DeptId;
  497. }
  498. if (ro.F_RoleCode == "CLZY" || ro.F_RoleCode == "ZR" || ro.F_RoleCode == "XTGLY")
  499. {
  500. dptid = 1;
  501. }
  502. if (userModel.F_See == "5")
  503. return Success("暂无记录");
  504. Model.T_Sys_Department deptModel = new BLL.T_Sys_Department().GetModel(dptid);
  505. DataTable dt = new DataTable();
  506. string sql = "and F_IsDelete=0 ";
  507. if (!string.IsNullOrEmpty(keywords))
  508. {
  509. sql += $" and ( F_Name like '%" + keywords.Trim() + "%'or F_Telephone like '%" + keywords.Trim() + "%'or F_Mobile like '%" + keywords.Trim() + "%'or F_ElseMobile like '%" + keywords.Trim() + "%'or F_Department like '%" + keywords.Trim() + "%' ) ";
  510. }
  511. if (dptid > 0)
  512. {
  513. sql += " and F_DepartmentId in ( select F_DeptId from T_Sys_Department where F_DeptCode like '" + deptModel.F_DeptCode + "%') ";
  514. }
  515. int recordCount = 0;
  516. if (!string.IsNullOrWhiteSpace(sql))
  517. {
  518. dt = BLL.PagerBLL.GetListPager(
  519. "T_Cus_AddressBook",
  520. "F_UserId",
  521. "*",
  522. sql,
  523. "ORDER BY T_Cus_AddressBook.F_UserId desc",
  524. pagesize,
  525. pageindex,
  526. true,
  527. out recordCount);
  528. }
  529. List<Model.T_Cus_AddressBook> modlelist = new BLL.T_Cus_AddressBook().DataTableToList(dt);
  530. List<AddressBook> Input = AddressBooks(modlelist);
  531. var modelListOrder = Input.OrderBy(x => x.F_Name);
  532. if (modlelist.Count > 0)
  533. {
  534. var obj = new
  535. {
  536. state = "success",
  537. message = "成功",
  538. rows = modelListOrder,
  539. total = recordCount
  540. };
  541. return Content(obj.ToJson()); ;
  542. }
  543. else
  544. {
  545. return Success("暂无记录"); ;
  546. }
  547. }
  548. return NoToken("未知错误,请重新登录");
  549. }
  550. }
  551. }