No Description

DepartmentController.cs 22KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560
  1. using CallCenter.Utility;
  2. using CallCenterApi.DB;
  3. using CallCenterApi.Interface.Controllers.Base;
  4. using CallCenterApi.Interface.Models.Input;
  5. using System;
  6. using System.Collections.Generic;
  7. using System.Data;
  8. using System.Linq;
  9. using System.Web;
  10. using System.Web.Mvc;
  11. namespace CallCenterApi.Interface.Controllers
  12. {
  13. [Authority]
  14. public class DepartmentController : BaseController
  15. {
  16. private BLL.T_Sys_Department departmentBLL = new BLL.T_Sys_Department();
  17. /// <summary>
  18. /// 获取部门列表
  19. /// </summary>
  20. /// <returns></returns>
  21. public ActionResult GetAllList()
  22. {
  23. if (Request.IsAuthenticated)
  24. {
  25. //int userId = CurrentUser.UserData.F_UserId;
  26. //Model.T_Sys_UserAccount userModel = new BLL.T_Sys_UserAccount().GetModel(userId);
  27. string where = "F_State='1'";
  28. //if (!string.IsNullOrEmpty(userModel.groupcode))
  29. //{
  30. // where += " and F_GroupCode = '" + userModel.groupcode + "'";
  31. //}
  32. DataTable dt = departmentBLL.GetList(0, where, " F_Sort asc").Tables[0];
  33. return Success("加载成功", dt);
  34. }
  35. return NoToken("未知错误,请重新登录");
  36. }
  37. /// <summary>
  38. /// 获取大区列表
  39. /// </summary>
  40. /// <returns></returns>
  41. public ActionResult GetDepartmentList(int pId = 1, int F_Layer = 1)
  42. {
  43. if (Request.IsAuthenticated)
  44. {
  45. DataTable dt = new DataTable();
  46. string where = " ";
  47. where = " isnull(F_DeptId,0) = '" + 1 + "' and F_State = 1" ;
  48. dt = new BLL.T_Sys_Department().GetList(0, where, " F_Sort asc").Tables[0];
  49. List<Model.TreeModel> modelList = BindAreaTree(dt, "0", 1);
  50. return Success("加载成功", modelList);
  51. }
  52. return NoToken("未知错误,请重新登录");
  53. }
  54. /// <summary>
  55. /// 获取大区列表
  56. /// </summary>
  57. /// <returns></returns>
  58. public ActionResult GetCusAreaList(string keyword, int pId = 1,int F_Layer=1)
  59. {
  60. if (Request.IsAuthenticated)
  61. {
  62. DataTable dt = new DataTable();
  63. string where = "isnull(F_ParentId, 1) = '" + pId + "' ";
  64. if (!string .IsNullOrEmpty (keyword))
  65. {
  66. where += "and F_DeptName like '%" + keyword.Trim () + "%'";
  67. }
  68. where += " and F_State = 1 and F_Layer = "+ F_Layer;
  69. dt = new BLL.T_Sys_Department().GetList(0, where, " F_Sort asc").Tables[0];
  70. return Success("加载成功", dt);
  71. }
  72. return NoToken("未知错误,请重新登录");
  73. }
  74. public ActionResult GetSubordinate()
  75. {
  76. if (Request.IsAuthenticated)
  77. {
  78. DataTable dt = new DataTable();
  79. string where = " ";
  80. //if (!string.IsNullOrEmpty(userModel.groupcode))
  81. //{
  82. // where += " and F_GroupCode = '" + userModel.groupcode + "'";
  83. //}
  84. int userId = CurrentUser.UserData.F_UserId;
  85. Model.T_Sys_UserAccount userModel = new BLL .T_Sys_UserAccount ().GetModel(userId);
  86. int pId = 1;
  87. if (userModel != null)
  88. pId = userModel.F_DeptId;
  89. if (pId == 1)
  90. where = "isnull(F_ParentId, 1) = '" + pId + "' and F_State = 1 and F_Layer = 1";
  91. else
  92. where = "F_DeptId=" + pId;
  93. dt = new BLL.T_Sys_Department().GetList(0, where, " F_Sort asc").Tables[0];
  94. List<Model.TreeModel> modelList = BindAreaTree(dt, "0");
  95. if (modelList != null)
  96. {
  97. if (modelList.Count > 0)
  98. return Success("加载成功", modelList);
  99. }
  100. return Error("加载失败");
  101. }
  102. return NoToken("未知错误,请重新登录");
  103. }
  104. private BLL.T_Sys_UserAccount userBLL = new BLL.T_Sys_UserAccount();
  105. private BLL.T_Sys_RoleInfo rolebll = new BLL.T_Sys_RoleInfo();
  106. public ActionResult GetAPPAreaList(int pId = 1)
  107. {
  108. if (Request.IsAuthenticated)
  109. {
  110. DataTable dt = new DataTable();
  111. string where = " ";
  112. if (pId == 1)
  113. where = "isnull(F_ParentId, 1) = '" + pId + "' and F_State = 1 and F_Layer = 1";
  114. else
  115. where = "F_DeptId=" + pId;
  116. dt = new BLL.T_Sys_Department().GetList(0, where, " F_Sort asc").Tables[0];
  117. List<Model.TreeModel> modelList = BindAreaTree(dt, "0");
  118. int userId = CurrentUser.UserData.F_UserId;
  119. Model.T_Sys_UserAccount userModel = userBLL.GetModel(userId);
  120. Model.T_Sys_RoleInfo ro = rolebll.GetModel(userModel.F_RoleId);
  121. if (ro.F_RoleCode == "CLZY")
  122. {
  123. Model.TreeModel model = new Model.TreeModel();
  124. string currentID = "0";//当前功能ID
  125. model.id = currentID;
  126. model.IconCls = "";//图标
  127. model.text = "双汇集团";
  128. List<Model.TreeModel> modelList1 = new List<Model.TreeModel>();
  129. Model.TreeModel model1 = new Model.TreeModel();
  130. model1.id = currentID;
  131. model1.IconCls = "";//图标
  132. model1.text = "管理区域";
  133. modelList1.Add(model1);
  134. model.children = modelList1;
  135. modelList.Add(model);
  136. }
  137. modelList.Sort((a, c) => a.id.CompareTo(c.id));
  138. if (modelList != null)
  139. {
  140. if (modelList.Count > 0)
  141. return Success("加载成功", modelList);
  142. }
  143. return Error("加载失败");
  144. }
  145. return NoToken("未知错误,请重新登录");
  146. }
  147. /// <summary>
  148. /// 获取大区列表
  149. /// </summary>
  150. /// <returns></returns>
  151. public ActionResult GetAreaList(int pId = 1)
  152. {
  153. if (Request.IsAuthenticated)
  154. {
  155. DataTable dt = new DataTable();
  156. string where = " ";
  157. if (pId == 1)
  158. where = "isnull(F_ParentId, 1) = '" + pId + "' and F_State = 1 and F_Layer = 1";
  159. else
  160. where = "F_DeptId="+ pId;
  161. dt = new BLL.T_Sys_Department().GetList(0, where, " F_Sort asc").Tables[0];
  162. List<Model.TreeModel> modelList = BindAreaTree(dt, "0");
  163. int userId = CurrentUser.UserData.F_UserId;
  164. Model.T_Sys_UserAccount userModel = userBLL.GetModel(userId);
  165. Model.T_Sys_RoleInfo ro = rolebll.GetModel(userModel.F_RoleId);
  166. if (ro.F_RoleCode == "CLZY")
  167. {
  168. Model.TreeModel model = new Model.TreeModel();
  169. string currentID = "0";//当前功能ID
  170. model.id = currentID;
  171. model.IconCls = "";//图标
  172. model.text = "双汇集团";
  173. List<Model.TreeModel> modelList1 = new List<Model.TreeModel>();
  174. Model.TreeModel model1 = new Model.TreeModel();
  175. model1.id = currentID;
  176. model1.IconCls = "";//图标
  177. model1.text = "管理区域";
  178. modelList1.Add(model1);
  179. model.children = modelList1;
  180. modelList.Add(model);
  181. }
  182. modelList.Sort((a, c) => a.id.CompareTo(c.id));
  183. if (modelList != null)
  184. {
  185. if (modelList.Count > 0)
  186. return Success("加载成功", modelList);
  187. }
  188. return Error("加载失败");
  189. }
  190. return NoToken("未知错误,请重新登录");
  191. }
  192. /// <summary>
  193. /// tree 树形部门
  194. /// </summary>
  195. /// <param name="tab"></param>
  196. /// <param name="parentid"></param>
  197. /// <returns></returns>
  198. private List<Model.TreeModel> BindAreaTree(DataTable tab, string parentid,int pid=0)
  199. {
  200. DataTable tab2 = new DataTable();
  201. if (tab != null && tab.Rows.Count > 0)
  202. {
  203. List<Model.T_Sys_Department> categorylist = new BLL.T_Sys_Department().DataTableToList(tab);
  204. List<Model.TreeModel> modelList = new List<Model.TreeModel>(categorylist.Count);
  205. for (int i = 0; i < categorylist.Count; i++)
  206. {
  207. Model.TreeModel model = new Model.TreeModel();
  208. string currentID = categorylist[i].F_DeptId.ToString();//当前功能ID
  209. model.id = currentID;
  210. model.IconCls = "";//图标
  211. model.text = categorylist[i].F_DeptName;
  212. if (pid==1)
  213. {
  214. tab2 = new BLL.T_Sys_Department().GetList("F_ParentId=" + currentID + " and F_State=1 and F_Layer = 1 order by f_sort").Tables[0];
  215. }
  216. else
  217. {
  218. tab2 = new BLL.T_Sys_Department().GetList("F_ParentId=" + currentID + " and F_State=1 order by f_sort").Tables[0];
  219. }
  220. if (tab2 != null && tab2.Rows.Count > 0)
  221. {
  222. model.children = BindBreaTree(tab2, currentID, pid);
  223. }
  224. modelList.Add(model);
  225. }
  226. return modelList;
  227. }
  228. else
  229. {
  230. return null;
  231. }
  232. }
  233. /// <summary>
  234. /// tree 树形部门
  235. /// </summary>
  236. /// <param name="tab"></param>
  237. /// <param name="parentid"></param>
  238. /// <returns></returns>
  239. private List<Model.TreeModel> BindBreaTree(DataTable tab, string parentid,int pid=0)
  240. {
  241. DataTable tab2 = new DataTable();
  242. if (tab != null && tab.Rows.Count > 0)
  243. {
  244. List<Model.T_Sys_Department> categorylist = new BLL.T_Sys_Department().DataTableToList(tab);
  245. List<Model.TreeModel> modelList = new List<Model.TreeModel>(categorylist.Count);
  246. for (int i = 0; i < categorylist.Count; i++)
  247. {
  248. Model.TreeModel model = new Model.TreeModel();
  249. string currentID = categorylist[i].F_DeptId.ToString();//当前功能ID
  250. model.id = currentID;
  251. model.IconCls = "";//图标
  252. model.text = categorylist[i].F_DeptName;
  253. tab2 = new BLL.T_Sys_Department().GetList("F_ParentId=" + currentID + " and F_State=1 order by f_sort").Tables[0];
  254. if (pid >0)
  255. {
  256. if (tab2 != null && tab2.Rows.Count > 0)
  257. {
  258. model.children = BindBreaTree(tab2, currentID, 0);
  259. }
  260. }
  261. modelList.Add(model);
  262. }
  263. return modelList;
  264. }
  265. else
  266. {
  267. return null;
  268. }
  269. }
  270. /// <summary>
  271. /// 获取部门
  272. /// </summary>
  273. /// <param name="deptId"></param>
  274. /// <returns></returns>
  275. public ActionResult GetDept(int deptId = 0)
  276. {
  277. if (Request.IsAuthenticated)
  278. {
  279. BLL.T_Sys_Department dBLL = new BLL.T_Sys_Department();
  280. Model.T_Sys_Department dModel = dBLL.GetModel(deptId);
  281. if (dModel != null)
  282. return Success("获取部门信息成功", new
  283. {
  284. deptid = dModel.F_DeptId,
  285. depname = dModel.F_DeptName,
  286. sort = dModel.F_Sort,
  287. parentid = dModel.F_ParentId,
  288. parentname = dModel.F_ParentName,
  289. layer= dModel.F_Layer
  290. });
  291. return Error("获取部门信息失败");
  292. }
  293. return NoToken("未知错误,请重新登录");
  294. }
  295. /// <summary>
  296. /// 获取部门
  297. /// </summary>
  298. /// <param name="deptId"></param>
  299. /// <returns></returns>
  300. public ActionResult GetwhereDept()
  301. {
  302. if (Request.IsAuthenticated)
  303. {
  304. int userId = CurrentUser.UserData.F_UserId;
  305. Model.T_Sys_UserAccount userModel = new BLL.T_Sys_UserAccount().GetModel(userId);
  306. int deptId = 0;
  307. if (userModel!=null )
  308. {
  309. deptId = userModel.F_DeptId;
  310. }
  311. BLL.T_Sys_Department dBLL = new BLL.T_Sys_Department();
  312. Model.T_Sys_Department dModel = dBLL.GetModel(deptId);
  313. if (dModel != null)
  314. return Success("获取部门信息成功", new
  315. {
  316. deptid = dModel.F_DeptId,
  317. depname = dModel.F_DeptName,
  318. sort = dModel.F_Sort,
  319. F_Layer = dModel.F_Layer,
  320. parentid = dModel.F_ParentId,
  321. parentname = dModel.F_ParentName
  322. });
  323. return Error("获取部门信息失败");
  324. }
  325. return NoToken("未知错误,请重新登录");
  326. }
  327. /// <summary>
  328. /// 添加部门
  329. /// </summary>
  330. /// <param name="input"></param>
  331. /// <returns></returns>
  332. [HttpPost]
  333. public ActionResult AddDept(DepartmentInput input)
  334. {
  335. if (Request.IsAuthenticated)
  336. {
  337. //int userId = CurrentUser.UserData.F_UserId;
  338. //Model.T_Sys_UserAccount userModel = new BLL.T_Sys_UserAccount().GetModel(userId);
  339. string pcode = "";
  340. Model.T_Sys_Department dModel = new Model.T_Sys_Department();
  341. dModel.F_ParentId = input.PId;
  342. if (input.PId != 0)
  343. {
  344. Model.T_Sys_Department pdModel = departmentBLL.GetModel(input.PId);
  345. if (pdModel != null)
  346. {
  347. pcode = dModel.F_ParentCode = pdModel.F_DeptCode;
  348. if (pdModel.F_Layer ==1)
  349. dModel.F_Layer = 2;
  350. else if (pdModel.F_Layer == 2)
  351. dModel.F_Layer = 3;
  352. dModel.F_ParentName = pdModel.F_DeptName;
  353. }
  354. }
  355. dModel.F_Sort = input.Sort;
  356. dModel.F_DeptName = input.DeptName;
  357. dModel.F_State = 1;
  358. dModel.F_Layer = input.F_Layer;
  359. //dModel.F_GroupCode = userModel.groupcode;
  360. int id = departmentBLL.Add(dModel);
  361. if (id> 0)
  362. {
  363. departmentBLL.UpdateDeptCode(pcode + id.ToString() + "|", id);
  364. return Success("添加成功");
  365. }
  366. else
  367. return Success("添加失败");
  368. }
  369. return NoToken("未知错误,请重新登录");
  370. }
  371. /// <summary>
  372. /// 编辑部门
  373. /// </summary>
  374. /// <param name="input"></param>
  375. /// <returns></returns>
  376. [HttpPost]
  377. public ActionResult EditDept(DepartmentInput input)
  378. {
  379. if (Request.IsAuthenticated)
  380. {
  381. if (input.DeptId <= 0)
  382. return Error("请选择要编辑的部门");
  383. BLL.T_Sys_Department dBLL = new BLL.T_Sys_Department();
  384. Model.T_Sys_Department dModel = dBLL.GetModel(input.DeptId);
  385. if (dModel == null)
  386. return Error("获取信息失败");
  387. dModel.F_ParentId = input.PId;
  388. if (input.PId != 0)
  389. {
  390. Model.T_Sys_Department pdModel = departmentBLL.GetModel(input.PId);
  391. if (pdModel != null)
  392. {
  393. dModel.F_ParentCode = pdModel.F_DeptCode;
  394. dModel.F_DeptCode = pdModel.F_DeptCode + input.DeptId.ToString() + "|";
  395. if (pdModel.F_Layer == 1)
  396. dModel.F_Layer = 2;
  397. else if (pdModel.F_Layer == 2)
  398. dModel.F_Layer = 3;
  399. dModel.F_ParentName = pdModel.F_DeptName;
  400. }
  401. }
  402. dModel.F_Sort = input.Sort;
  403. dModel.F_DeptName = input.DeptName;
  404. dModel.F_Layer = input.F_Layer;
  405. if (dBLL.Update(dModel))
  406. return Success("编辑成功");
  407. return Error("编辑失败");
  408. }
  409. return NoToken("未知错误,请重新登录");
  410. }
  411. /// <summary>
  412. /// 删除部门
  413. /// </summary>
  414. /// <param name="ids"></param>
  415. /// <returns></returns>
  416. public ActionResult DelDept(string[] ids)
  417. {
  418. if (Request.IsAuthenticated)
  419. {
  420. if (ids == null || ids.Length <= 0)
  421. return Error("请选择要删除的部门");
  422. var idStr = string.Join(",", ids);
  423. if (string.IsNullOrEmpty(idStr.Trim()))
  424. return Error("请选择要删除的部门");
  425. if (departmentBLL.DeleteList(idStr))
  426. return Success("删除成功");
  427. return Error("删除失败");
  428. }
  429. return NoToken("未知错误,请重新登录");
  430. }
  431. /// <summary>
  432. /// 获取部门列表
  433. /// </summary>
  434. /// <returns></returns>
  435. public ActionResult GetDeptList(int pId = 0)
  436. {
  437. if (Request.IsAuthenticated)
  438. {
  439. int userId = CurrentUser.UserData.F_UserId;
  440. Model.T_Sys_UserAccount userModel = new BLL.T_Sys_UserAccount().GetModel(userId);
  441. if (userModel != null)
  442. pId = userModel.F_DeptId;
  443. Model.T_Sys_RoleInfo ro = rolebll.GetModel(userModel.F_RoleId);
  444. string where = "";
  445. DataTable dt = new DataTable();
  446. if (ro != null)
  447. {
  448. if (ro.F_RoleCode == "CLZY")
  449. pId=1;
  450. else if (ro.F_RoleCode == "ZR")
  451. pId = 1;
  452. else if (ro.F_RoleCode == "XTGLY")
  453. pId = 1;
  454. }
  455. if (pId == 2)
  456. {
  457. where = "(isnull(F_DeptId,0)='" + pId + "'or F_Layer=1 ) and F_State=1";
  458. }
  459. else if (pId == 421)
  460. {
  461. where = "isnull(F_DeptId,0)='" + 1+ "'and F_State=1";
  462. }
  463. else
  464. {
  465. where = " isnull(F_DeptId,0)='" + pId + "' and F_State=1 ";
  466. }
  467. //if (!string.IsNullOrEmpty(userModel.groupcode))
  468. //{
  469. // where += " and F_GroupCode = '" + userModel.groupcode + "'";
  470. //}
  471. if (pId == 0)
  472. {
  473. var strList = RedisHelper.StringGet("ZTreeList_Shuanghui");
  474. if (strList != null)
  475. {
  476. return Success("加载成功", strList.ToString().ToObject<List<Model.TreeModel>>());
  477. }
  478. }
  479. dt = new BLL.T_Sys_Department().GetList(0, where, " F_Sort asc").Tables[0];
  480. List<Model.TreeModel> modelList = BindTree(dt, "0");
  481. if (pId == 0)
  482. {
  483. RedisHelper.StringSet("ZTreeList_Shuanghui", modelList.ToJson());
  484. }
  485. if (modelList != null)
  486. {
  487. if (modelList.Count > 0)
  488. return Success("加载成功", modelList);
  489. }
  490. return Error("加载失败");
  491. }
  492. return NoToken("未知错误,请重新登录");
  493. }
  494. /// <summary>
  495. /// tree 树形部门
  496. /// </summary>
  497. /// <param name="tab"></param>
  498. /// <param name="parentid"></param>
  499. /// <returns></returns>
  500. private List<Model.TreeModel> BindTree(DataTable tab, string parentid)
  501. {
  502. DataTable tab2 = new DataTable();
  503. if (tab != null && tab.Rows.Count > 0)
  504. {
  505. List<Model.T_Sys_Department> categorylist = new BLL.T_Sys_Department().DataTableToList(tab);
  506. List<Model.TreeModel> modelList = new List<Model.TreeModel>(categorylist.Count);
  507. for (int i = 0; i < categorylist.Count; i++)
  508. {
  509. Model.TreeModel model = new Model.TreeModel();
  510. string currentID = categorylist[i].F_DeptId.ToString();//当前功能ID
  511. model.id = currentID;
  512. model.IconCls = "";//图标
  513. model.text = categorylist[i].F_DeptName;
  514. tab2 = new BLL.T_Sys_Department().GetList("F_ParentId=" + currentID + " and F_State=1 order by f_sort").Tables[0];
  515. if (tab2 != null && tab2.Rows.Count > 0)
  516. {
  517. model.children = BindTree(tab2, currentID);
  518. }
  519. modelList.Add(model);
  520. }
  521. return modelList;
  522. }
  523. else
  524. {
  525. return null;
  526. }
  527. }
  528. }
  529. }