Nenhuma Descrição

DepartmentController.cs 18KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457
  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. /// 获取部门列表 - Pc和微信(不用身份验证)
  19. /// </summary>
  20. /// <returns></returns>
  21. public ActionResult GetAllList()
  22. {
  23. //if (Request.IsAuthenticated)
  24. //{
  25. DataTable dt = new DataTable();
  26. dt = new BLL.T_Sys_Department().GetList(" F_State=1 ").Tables[0];
  27. return Success("加载成功", dt);
  28. //}
  29. //return NoToken("未知错误,请重新登录");
  30. }
  31. /// <summary>
  32. /// 获取大区分公司
  33. /// </summary>
  34. /// <returns></returns>
  35. public ActionResult GetLinkList(int F_Layer)
  36. {
  37. DataTable dt = new DataTable();
  38. dt = new BLL.T_Sys_Department().GetList(" F_State=1 and F_Layer=+" + F_Layer).Tables[0];
  39. List<Model.TreeModel> modelList = BindTree(dt, "0");
  40. if (modelList != null)
  41. {
  42. if (modelList.Count > 0)
  43. return Success("加载成功", modelList);
  44. }
  45. return Success(null );
  46. }
  47. /// <summary>
  48. /// 获取大区分公司
  49. /// </summary>
  50. /// <returns></returns>
  51. public ActionResult GetList(int F_Layer, string F_DeptName="" )
  52. {
  53. DataTable dt = new DataTable();
  54. if (F_DeptName!="")
  55. {
  56. Model.T_Sys_Department dModel = departmentBLL.GetModel(F_DeptName);
  57. if (dModel!=null )
  58. {
  59. dt = new BLL.T_Sys_Department().GetList(" F_State=1 and F_Layer=" + F_Layer+ " and F_ParentId=" + dModel.F_DeptId ).Tables[0];
  60. }
  61. else
  62. {
  63. return Success(null );
  64. }
  65. }
  66. else
  67. {
  68. dt = new BLL.T_Sys_Department().GetList(" F_State=1 and F_Layer=" + F_Layer ).Tables[0];
  69. }
  70. if (dt != null)
  71. {
  72. if (dt.Rows .Count > 0)
  73. return Success("加载成功", dt);
  74. }
  75. return Success(null);
  76. }
  77. /// <summary>
  78. /// 获取部门
  79. /// </summary>
  80. /// <param name="deptId"></param>
  81. /// <returns></returns>
  82. public ActionResult GetDept(int deptId = 0)
  83. {
  84. if (Request.IsAuthenticated)
  85. {
  86. BLL.T_Sys_Department dBLL = new BLL.T_Sys_Department();
  87. Model.T_Sys_Department dModel = dBLL.GetModel(deptId);
  88. if (dModel != null)
  89. return Success("获取部门信息成功", new
  90. {
  91. deptid = dModel.F_DeptId,
  92. depname = dModel.F_DeptName,
  93. sort = dModel.F_Sort,
  94. parentid = dModel.F_ParentId,
  95. parentname = dModel.F_ParentName,
  96. remark = dModel.F_Remark,
  97. layerType=dModel .F_Layer,
  98. //部门类型0不区分1大区2分公司
  99. // headerid = dModel.F_Header, //部门权限范围:9全部,1区域,2项目,3期
  100. // TypeId = dModel.F_Type, //部门操作权限:1接待部,2办理人员,3区域客服,4监管
  101. });
  102. return Error("获取部门信息失败");
  103. }
  104. return NoToken("未知错误,请重新登录");
  105. }
  106. private readonly BLL.T_Sys_UserAccount userAccountBLL = new BLL.T_Sys_UserAccount();
  107. /// <summary>
  108. /// 获取部门
  109. /// </summary>
  110. /// <param name="deptId"></param>
  111. /// <returns></returns>
  112. public ActionResult GetWXDept(string name)
  113. {
  114. BLL.T_Sys_Department dBLL = new BLL.T_Sys_Department();
  115. int deptId = 0;
  116. int userid = 0;
  117. Model.T_Sys_UserAccount user = userAccountBLL.GetworkModel(name);
  118. if (user != null)
  119. {
  120. deptId = user.F_DeptId;
  121. userid = user.F_UserId;
  122. }
  123. else
  124. {
  125. Model.T_Sys_UserAccount userer = userAccountBLL.GetName(name);
  126. if (userer != null)
  127. {
  128. deptId = userer.F_DeptId;
  129. userid = userer.F_UserId;
  130. }
  131. }
  132. if (deptId==0)
  133. return Error("请输入正确的姓名或编号");
  134. Model.T_Sys_Department dModel = dBLL.GetModel(deptId);
  135. if (dModel != null)
  136. return Success("获取部门信息成功", new
  137. {
  138. deptid = dModel.F_DeptId,
  139. depname = dModel.F_DeptName,
  140. sort = dModel.F_Sort,
  141. parentid = dModel.F_ParentId,
  142. parentname = dModel.F_ParentName,
  143. remark = dModel.F_Remark,
  144. layerType = dModel.F_Layer,
  145. userid,
  146. //部门类型0不区分1大区2分公司
  147. // headerid = dModel.F_Header, //部门权限范围:9全部,1区域,2项目,3期
  148. // TypeId = dModel.F_Type, //部门操作权限:1接待部,2办理人员,3区域客服,4监管
  149. });
  150. return Error("获取部门信息失败");
  151. }
  152. /// <summary>
  153. /// 添加部门
  154. /// </summary>
  155. /// <param name="input"></param>
  156. /// <returns></returns>
  157. [HttpPost]
  158. public ActionResult AddDept(DepartmentInput input)
  159. {
  160. ActionResult res = NoToken("未知错误,请重新登录");
  161. if (Request.IsAuthenticated)
  162. {
  163. string pcode = "";
  164. Model.T_Sys_Department dModel = new Model.T_Sys_Department();
  165. dModel.F_ParentId = input.PId;
  166. if (input.PId != 0)
  167. {
  168. Model.T_Sys_Department pdModel = departmentBLL.GetModel(input.PId);
  169. if (pdModel != null)
  170. {
  171. pcode = dModel.F_ParentCode = pdModel.F_DeptCode;
  172. }
  173. }
  174. dModel.F_Sort = input.Sort;
  175. dModel.F_DeptName = input.DeptName;
  176. if (!string.IsNullOrEmpty(input.Remark))
  177. dModel.F_Remark = input.Remark;
  178. dModel.F_State = 1;
  179. dModel.F_Layer = input.F_Layer;//部门类型0不区分1大区2分公司
  180. // dModel.F_Header = input.Headerid; //部门权限范围:9全部,1区域,2项目,3期
  181. // dModel.F_Type = input.TypeId; //部门操作权限:1接待部,2办理人员,3区域客服,4监管
  182. int id = departmentBLL.Add(dModel);
  183. if (id > 0)
  184. {
  185. departmentBLL.UpdateDeptCode(pcode + id.ToString() + "|", id);
  186. res = Success("添加成功");
  187. }
  188. else
  189. res = Success("添加失败");
  190. }
  191. return res;
  192. }
  193. /// <summary>
  194. /// 编辑部门
  195. /// </summary>
  196. /// <param name="input"></param>
  197. /// <returns></returns>
  198. [HttpPost]
  199. public ActionResult EditDept(DepartmentInput input)
  200. {
  201. if (Request.IsAuthenticated)
  202. {
  203. if (input.DeptId <= 0)
  204. return Error("请选择要编辑的部门");
  205. BLL.T_Sys_Department dBLL = new BLL.T_Sys_Department();
  206. Model.T_Sys_Department dModel = dBLL.GetModel(input.DeptId);
  207. if (dModel == null)
  208. return Error("获取信息失败");
  209. dModel.F_ParentId = input.PId;
  210. if (input.PId != 0)
  211. {
  212. Model.T_Sys_Department pdModel = departmentBLL.GetModel(input.PId);
  213. if (pdModel != null)
  214. {
  215. dModel.F_ParentCode = pdModel.F_DeptCode;
  216. dModel.F_DeptCode = pdModel.F_DeptCode + input.DeptId.ToString() + "|";
  217. }
  218. }
  219. dModel.F_Sort = input.Sort;
  220. dModel.F_DeptName = input.DeptName;
  221. if (!string.IsNullOrEmpty(input.Remark))
  222. dModel.F_Remark = input.Remark;
  223. dModel.F_Layer = input.F_Layer;//部门类型0不区分1大区2分公司
  224. // dModel.F_Header = input.Headerid; //部门权限范围:9全部,1区域,2项目,3期
  225. // dModel.F_Type = input.TypeId; //部门操作权限:1接待部,2办理人员,3区域客服,4监管
  226. if (dBLL.Update(dModel))
  227. return Success("编辑成功");
  228. return Error("编辑失败");
  229. }
  230. return NoToken("未知错误,请重新登录");
  231. }
  232. /// <summary>
  233. /// 删除部门
  234. /// </summary>
  235. /// <param name="ids"></param>
  236. /// <returns></returns>
  237. public ActionResult DelDept(string[] ids)
  238. {
  239. if (Request.IsAuthenticated)
  240. {
  241. if (ids == null || ids.Length <= 0)
  242. return Error("请选择要删除的部门");
  243. var idStr = string.Join(",", ids);
  244. if (string.IsNullOrEmpty(idStr.Trim()))
  245. return Error("请选择要删除的部门");
  246. if (departmentBLL.DeleteList(idStr))
  247. return Success("删除成功");
  248. return Error("删除失败");
  249. }
  250. return NoToken("未知错误,请重新登录");
  251. }
  252. /// <summary>
  253. /// tree 树形部门
  254. /// </summary>
  255. /// <param name="tab"></param>
  256. /// <param name="parentid"></param>
  257. /// <returns></returns>
  258. private List<Model.TreeModel> BindAssignTree(DataTable tab, string parentid,int type)
  259. {
  260. DataTable tab2 = new DataTable();
  261. if (tab != null && tab.Rows.Count > 0)
  262. {
  263. List<Model.T_Sys_Department> categorylist = new BLL.T_Sys_Department().DataTableToList(tab);
  264. List<Model.TreeModel> modelList = new List<Model.TreeModel>(categorylist.Count);
  265. for (int i = 0; i < categorylist.Count; i++)
  266. {
  267. Model.TreeModel model = new Model.TreeModel();
  268. string currentID = categorylist[i].F_DeptId.ToString();//当前功能ID
  269. model.id = currentID;
  270. model.code = categorylist[i].F_DeptCode;
  271. model.IconCls = "";//图标
  272. model.text = categorylist[i].F_DeptName;
  273. model.headerid = categorylist[i].F_Header ?? 0; //部门权限范围:9全部,1区域,2项目,3期
  274. string msg = "";
  275. if (type ==0)
  276. {
  277. msg = " and F_Layer=0";
  278. }
  279. tab2 = new BLL.T_Sys_Department().GetList("F_ParentId=" + currentID + " and F_State=1"+ msg).Tables[0];
  280. if (tab2 != null && tab2.Rows.Count > 0)
  281. {
  282. model.children = BindAssignTree(tab2, currentID, type);
  283. }
  284. modelList.Add(model);
  285. }
  286. return modelList;
  287. }
  288. else
  289. {
  290. return null;
  291. }
  292. }
  293. /// <summary>
  294. /// 获取部门列表
  295. /// </summary>
  296. /// <returns></returns>
  297. public ActionResult GetAssignDeptList(int pId = 0, string keywords = "",int type=0)
  298. {
  299. //if (Request.IsAuthenticated)
  300. //{
  301. DataTable dt = new DataTable();
  302. if (keywords != "")
  303. {
  304. if (keywords.Contains("'"))
  305. {
  306. keywords = keywords.Replace("'", "");
  307. }
  308. dt = new BLL.T_Sys_Department().GetList(" F_State=1" + $" and F_DeptName like '%" + keywords.Trim() + "%' and F_DeptId !=2 ").Tables[0];
  309. }
  310. else
  311. {
  312. dt = new BLL.T_Sys_Department().GetList(" F_State=1 and F_DeptId !=2 and F_ParentId=" + pId).Tables[0];
  313. }
  314. List<Model.TreeModel> modelList = BindAssignTree(dt, "0", type);
  315. if (modelList != null)
  316. {
  317. if (modelList.Count > 0)
  318. return Success("加载成功", modelList);
  319. }
  320. return Success(null);
  321. //}
  322. //return NoToken("未知错误,请重新登录");
  323. }
  324. /// <summary>
  325. /// 获取部门列表
  326. /// </summary>
  327. /// <returns></returns>
  328. public ActionResult GetDeptList(int pId = 0,string keywords = "")
  329. {
  330. //if (Request.IsAuthenticated)
  331. //{
  332. DataTable dt = new DataTable();
  333. if (keywords != "")
  334. {
  335. if (keywords.Contains("'"))
  336. {
  337. keywords= keywords.Replace("'", "");
  338. }
  339. dt = new BLL.T_Sys_Department().GetList(" F_State=1" + $" and F_DeptName like '%" + keywords.Trim()+"%'").Tables[0];
  340. }
  341. else
  342. {
  343. dt = new BLL.T_Sys_Department().GetList(" F_State=1 and F_ParentId=" + pId).Tables[0];
  344. }
  345. List<Model.TreeModel> modelList = BindTree(dt, "0");
  346. if (modelList != null)
  347. {
  348. if (modelList.Count > 0)
  349. return Success("加载成功", modelList);
  350. }
  351. return Success(null );
  352. //}
  353. //return NoToken("未知错误,请重新登录");
  354. }
  355. /// <summary>
  356. /// 获取部门列表 by 处理人员
  357. /// </summary>
  358. /// <returns></returns>
  359. public ActionResult GetDeptListbyReceive(int pId = 0)
  360. {
  361. DataTable dt = new DataTable();
  362. string sqlstr = "SELECT F_ParentId FROM dbo.T_Sys_Department WHERE F_Type = 2"; //一级
  363. //string sqlstr2 = "SELECT F_DeptId FROM dbo.T_Sys_Department WHERE F_Type = 2"; //二级
  364. string sqlstr3 = "SELECT F_ParentId FROM dbo.T_Sys_Department WHERE F_Type = 3"; //一级 区域客服(分类显示成其他)
  365. //string sqlstr4 = "SELECT TOP 1 F_DeptId FROM dbo.T_Sys_Department WHERE F_Type = 3 ORDER BY F_Sort ASC"; //二级 区域客服(分类显示成其他)
  366. //dt = new BLL.T_Sys_Department().GetList($" F_State=1 and (F_ParentId=0 OR F_DeptId IN({sqlstr}) OR F_DeptId IN({sqlstr2}) OR F_DeptId IN({sqlstr3}) OR F_DeptId IN({sqlstr4}) )").Tables[0];
  367. dt = new BLL.T_Sys_Department().GetList($" F_State=1 and (F_ParentId=0 OR F_DeptId IN({sqlstr}) OR F_DeptId IN({sqlstr3}) )").Tables[0];
  368. List<DepartmentTreeList> list = new List<DepartmentTreeList>();
  369. for (int i = 0; i < dt.Rows.Count; i++)
  370. {
  371. var model = new DepartmentTreeList();
  372. model.id = Convert.ToInt32(dt.Rows[i]["F_DeptId"]); //当前功能ID
  373. model.ParentId = Convert.ToInt32(dt.Rows[i]["F_ParentId"]);
  374. model.text = dt.Rows[i]["F_DeptName"].ToString();
  375. model.sort = Convert.ToInt32(dt.Rows[i]["F_Sort"].ToString());
  376. list.Add(model);
  377. }
  378. return Success("加载成功", list);
  379. }
  380. /// <summary>
  381. /// tree 树形部门
  382. /// </summary>
  383. /// <param name="tab"></param>
  384. /// <param name="parentid"></param>
  385. /// <returns></returns>
  386. private List<Model.TreeModel> BindTree(DataTable tab, string parentid)
  387. {
  388. DataTable tab2 = new DataTable();
  389. if (tab != null && tab.Rows.Count > 0)
  390. {
  391. List<Model.T_Sys_Department> categorylist = new BLL.T_Sys_Department().DataTableToList(tab);
  392. List<Model.TreeModel> modelList = new List<Model.TreeModel>(categorylist.Count);
  393. for (int i = 0; i < categorylist.Count; i++)
  394. {
  395. Model.TreeModel model = new Model.TreeModel();
  396. string currentID = categorylist[i].F_DeptId.ToString();//当前功能ID
  397. model.id = currentID;
  398. model.code = categorylist[i].F_DeptCode;
  399. model.IconCls = "";//图标
  400. model.text = categorylist[i].F_DeptName;
  401. model.headerid = categorylist[i].F_Header ?? 0; //部门权限范围:9全部,1区域,2项目,3期
  402. tab2 = new BLL.T_Sys_Department().GetList("F_ParentId=" + currentID + " and F_State=1 ").Tables[0];
  403. if (tab2 != null && tab2.Rows.Count > 0)
  404. {
  405. model.children = BindTree(tab2, currentID);
  406. }
  407. modelList.Add(model);
  408. }
  409. return modelList;
  410. }
  411. else
  412. {
  413. return null;
  414. }
  415. }
  416. public class DepartmentTreeList
  417. {
  418. /// <summary>
  419. /// 文章ID
  420. /// </summary>
  421. public int id { get; set; }
  422. /// <summary>
  423. /// 父ID
  424. /// </summary>
  425. public int ParentId { get; set; }
  426. /// <summary>
  427. /// 分类名称
  428. /// </summary>
  429. public string text { get; set; }
  430. /// <summary>
  431. /// 排序
  432. /// </summary>
  433. public int sort { get; set; }
  434. }
  435. }
  436. }