Нет описания

DepartmentController.cs 13KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335
  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 Error("加载失败");
  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 Error("加载失败");
  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 Error("加载失败");
  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. /// <summary>
  107. /// 添加部门
  108. /// </summary>
  109. /// <param name="input"></param>
  110. /// <returns></returns>
  111. [HttpPost]
  112. public ActionResult AddDept(DepartmentInput input)
  113. {
  114. ActionResult res = NoToken("未知错误,请重新登录");
  115. if (Request.IsAuthenticated)
  116. {
  117. string pcode = "";
  118. Model.T_Sys_Department dModel = new Model.T_Sys_Department();
  119. dModel.F_ParentId = input.PId;
  120. if (input.PId != 0)
  121. {
  122. Model.T_Sys_Department pdModel = departmentBLL.GetModel(input.PId);
  123. if (pdModel != null)
  124. {
  125. pcode = dModel.F_ParentCode = pdModel.F_DeptCode;
  126. }
  127. }
  128. dModel.F_Sort = input.Sort;
  129. dModel.F_DeptName = input.DeptName;
  130. if (!string.IsNullOrEmpty(input.Remark))
  131. dModel.F_Remark = input.Remark;
  132. dModel.F_State = 1;
  133. dModel.F_Layer = input.F_Layer;//部门类型0不区分1大区2分公司
  134. // dModel.F_Header = input.Headerid; //部门权限范围:9全部,1区域,2项目,3期
  135. // dModel.F_Type = input.TypeId; //部门操作权限:1接待部,2办理人员,3区域客服,4监管
  136. int id = departmentBLL.Add(dModel);
  137. if (id > 0)
  138. {
  139. departmentBLL.UpdateDeptCode(pcode + id.ToString() + "|", id);
  140. res = Success("添加成功");
  141. }
  142. else
  143. res = Success("添加失败");
  144. }
  145. return res;
  146. }
  147. /// <summary>
  148. /// 编辑部门
  149. /// </summary>
  150. /// <param name="input"></param>
  151. /// <returns></returns>
  152. [HttpPost]
  153. public ActionResult EditDept(DepartmentInput input)
  154. {
  155. if (Request.IsAuthenticated)
  156. {
  157. if (input.DeptId <= 0)
  158. return Error("请选择要编辑的部门");
  159. BLL.T_Sys_Department dBLL = new BLL.T_Sys_Department();
  160. Model.T_Sys_Department dModel = dBLL.GetModel(input.DeptId);
  161. if (dModel == null)
  162. return Error("获取信息失败");
  163. dModel.F_ParentId = input.PId;
  164. if (input.PId != 0)
  165. {
  166. Model.T_Sys_Department pdModel = departmentBLL.GetModel(input.PId);
  167. if (pdModel != null)
  168. {
  169. dModel.F_ParentCode = pdModel.F_DeptCode;
  170. dModel.F_DeptCode = pdModel.F_DeptCode + input.DeptId.ToString() + "|";
  171. }
  172. }
  173. dModel.F_Sort = input.Sort;
  174. dModel.F_DeptName = input.DeptName;
  175. if (!string.IsNullOrEmpty(input.Remark))
  176. dModel.F_Remark = input.Remark;
  177. dModel.F_Layer = input.F_Layer;//部门类型0不区分1大区2分公司
  178. // dModel.F_Header = input.Headerid; //部门权限范围:9全部,1区域,2项目,3期
  179. // dModel.F_Type = input.TypeId; //部门操作权限:1接待部,2办理人员,3区域客服,4监管
  180. if (dBLL.Update(dModel))
  181. return Success("编辑成功");
  182. return Error("编辑失败");
  183. }
  184. return NoToken("未知错误,请重新登录");
  185. }
  186. /// <summary>
  187. /// 删除部门
  188. /// </summary>
  189. /// <param name="ids"></param>
  190. /// <returns></returns>
  191. public ActionResult DelDept(string[] ids)
  192. {
  193. if (Request.IsAuthenticated)
  194. {
  195. if (ids == null || ids.Length <= 0)
  196. return Error("请选择要删除的部门");
  197. var idStr = string.Join(",", ids);
  198. if (string.IsNullOrEmpty(idStr.Trim()))
  199. return Error("请选择要删除的部门");
  200. if (departmentBLL.DeleteList(idStr))
  201. return Success("删除成功");
  202. return Error("删除失败");
  203. }
  204. return NoToken("未知错误,请重新登录");
  205. }
  206. /// <summary>
  207. /// 获取部门列表
  208. /// </summary>
  209. /// <returns></returns>
  210. public ActionResult GetDeptList(int pId = 0,string keywords = "")
  211. {
  212. //if (Request.IsAuthenticated)
  213. //{
  214. DataTable dt = new DataTable();
  215. if (keywords != "")
  216. {
  217. if (keywords.Contains("'"))
  218. {
  219. keywords= keywords.Replace("'", "");
  220. }
  221. dt = new BLL.T_Sys_Department().GetList(" F_State=1" + $" and F_DeptName like '%" + keywords.Trim()+"%'").Tables[0];
  222. }
  223. else
  224. {
  225. dt = new BLL.T_Sys_Department().GetList(" F_State=1 and F_ParentId=" + pId).Tables[0];
  226. }
  227. List<Model.TreeModel> modelList = BindTree(dt, "0");
  228. if (modelList != null)
  229. {
  230. if (modelList.Count > 0)
  231. return Success("加载成功", modelList);
  232. }
  233. return Success(null );
  234. //}
  235. //return NoToken("未知错误,请重新登录");
  236. }
  237. /// <summary>
  238. /// 获取部门列表 by 处理人员
  239. /// </summary>
  240. /// <returns></returns>
  241. public ActionResult GetDeptListbyReceive(int pId = 0)
  242. {
  243. DataTable dt = new DataTable();
  244. string sqlstr = "SELECT F_ParentId FROM dbo.T_Sys_Department WHERE F_Type = 2"; //一级
  245. //string sqlstr2 = "SELECT F_DeptId FROM dbo.T_Sys_Department WHERE F_Type = 2"; //二级
  246. string sqlstr3 = "SELECT F_ParentId FROM dbo.T_Sys_Department WHERE F_Type = 3"; //一级 区域客服(分类显示成其他)
  247. //string sqlstr4 = "SELECT TOP 1 F_DeptId FROM dbo.T_Sys_Department WHERE F_Type = 3 ORDER BY F_Sort ASC"; //二级 区域客服(分类显示成其他)
  248. //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];
  249. 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];
  250. List<DepartmentTreeList> list = new List<DepartmentTreeList>();
  251. for (int i = 0; i < dt.Rows.Count; i++)
  252. {
  253. var model = new DepartmentTreeList();
  254. model.id = Convert.ToInt32(dt.Rows[i]["F_DeptId"]); //当前功能ID
  255. model.ParentId = Convert.ToInt32(dt.Rows[i]["F_ParentId"]);
  256. model.text = dt.Rows[i]["F_DeptName"].ToString();
  257. model.sort = Convert.ToInt32(dt.Rows[i]["F_Sort"].ToString());
  258. list.Add(model);
  259. }
  260. return Success("加载成功", list);
  261. }
  262. /// <summary>
  263. /// tree 树形部门
  264. /// </summary>
  265. /// <param name="tab"></param>
  266. /// <param name="parentid"></param>
  267. /// <returns></returns>
  268. private List<Model.TreeModel> BindTree(DataTable tab, string parentid)
  269. {
  270. DataTable tab2 = new DataTable();
  271. if (tab != null && tab.Rows.Count > 0)
  272. {
  273. List<Model.T_Sys_Department> categorylist = new BLL.T_Sys_Department().DataTableToList(tab);
  274. List<Model.TreeModel> modelList = new List<Model.TreeModel>(categorylist.Count);
  275. for (int i = 0; i < categorylist.Count; i++)
  276. {
  277. Model.TreeModel model = new Model.TreeModel();
  278. string currentID = categorylist[i].F_DeptId.ToString();//当前功能ID
  279. model.id = currentID;
  280. model.code = categorylist[i].F_DeptCode;
  281. model.IconCls = "";//图标
  282. model.text = categorylist[i].F_DeptName;
  283. model.headerid = categorylist[i].F_Header ?? 0; //部门权限范围:9全部,1区域,2项目,3期
  284. tab2 = new BLL.T_Sys_Department().GetList("F_ParentId=" + currentID + " and F_State=1 ").Tables[0];
  285. if (tab2 != null && tab2.Rows.Count > 0)
  286. {
  287. model.children = BindTree(tab2, currentID);
  288. }
  289. modelList.Add(model);
  290. }
  291. return modelList;
  292. }
  293. else
  294. {
  295. return null;
  296. }
  297. }
  298. public class DepartmentTreeList
  299. {
  300. /// <summary>
  301. /// 文章ID
  302. /// </summary>
  303. public int id { get; set; }
  304. /// <summary>
  305. /// 父ID
  306. /// </summary>
  307. public int ParentId { get; set; }
  308. /// <summary>
  309. /// 分类名称
  310. /// </summary>
  311. public string text { get; set; }
  312. /// <summary>
  313. /// 排序
  314. /// </summary>
  315. public int sort { get; set; }
  316. }
  317. }
  318. }