县级监管平台

DepartmentController.cs 7.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. using CallCenterApi.Common;
  2. using CallCenterApi.Interface.Controllers.Base;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Data;
  6. using System.Linq;
  7. using System.Web;
  8. using System.Web.Mvc;
  9. namespace CallCenterApi.Interface.Controllers
  10. {
  11. [Authority]
  12. public class DepartmentController : BaseController
  13. {
  14. private BLL.T_Sys_Department departmentBLL = new BLL.T_Sys_Department();
  15. #region 部门
  16. /// <summary>
  17. /// 获取部门列表
  18. /// </summary>
  19. /// <returns></returns>
  20. public ActionResult GetDeptList()
  21. {
  22. DataTable dt = new DataTable();
  23. dt = departmentBLL.GetList(0, "F_State=0", " F_Sort").Tables[0];
  24. return Success("加载成功", dt);
  25. }
  26. /// <summary>
  27. /// 获取部门
  28. /// </summary>
  29. /// <param name="deptId"></param>
  30. /// <returns></returns>
  31. public ActionResult GetDept()
  32. {
  33. int id = RequestString.GetInt("id", 0);
  34. Model.T_Sys_Department dModel = departmentBLL.GetModel(id);
  35. if (dModel != null)
  36. return Success("获取信息成功", dModel);
  37. return Error("获取信息失败");
  38. }
  39. /// <summary>
  40. /// 添加部门
  41. /// </summary>
  42. /// <param name="input"></param>
  43. /// <returns></returns>
  44. [HttpPost]
  45. public ActionResult AddDept()
  46. {
  47. Model.T_Sys_UserAccount userModel = new BLL.T_Sys_UserAccount().GetModel(User.UserData["F_UserCode"]);
  48. int id = RequestString.GetInt("id", 0);
  49. int did = RequestString.GetInt("did", 0);
  50. int sort = RequestString.GetInt("sort", 0);
  51. int isdept = RequestString.GetInt("isdept", 0);
  52. int isdealdept = RequestString.GetInt("isdealdept", 0);
  53. string name = RequestString.GetFormString("name");
  54. string phone = RequestString.GetFormString("phone");
  55. string leader = RequestString.GetFormString("leader");
  56. string split = RequestString.GetFormString("split");
  57. string topleader = RequestString.GetFormString("topleader");
  58. Model.T_Sys_Department dModel = new Model.T_Sys_Department();
  59. if (id == 0)
  60. {
  61. var list = departmentBLL.GetModelList(" F_PartentId='" + did + "' and F_DeptName='" + name + "' ");
  62. if (list.Count > 0)
  63. {
  64. return Error("已经存在此部门");
  65. }
  66. else
  67. {
  68. dModel.F_PartentId = did;
  69. dModel.F_Sort = sort;
  70. dModel.F_DeptName = name;
  71. dModel.F_DeptPhone = phone;
  72. dModel.F_layer = did > 0 ? 1 : 0;
  73. dModel.F_Type = 0;
  74. dModel.F_LeaderUser = leader;
  75. dModel.F_TopSplitUser = split;
  76. dModel.F_TopLeaderUser = topleader;
  77. dModel.F_State = 0;
  78. dModel.F_IsDept = isdept;
  79. dModel.F_IsDealDept = isdealdept;
  80. dModel.F_CreateDate = DateTime.Now;
  81. dModel.F_CreateUser = userModel.F_UserCode;
  82. int n = departmentBLL.Add(dModel);
  83. if (n > 0)
  84. return Success("添加成功", n);
  85. else
  86. return Error("添加失败");
  87. }
  88. }
  89. else
  90. {
  91. dModel = departmentBLL.GetModel(id);
  92. if (dModel != null)
  93. {
  94. var list = departmentBLL.GetModelList(" F_PartentId='" + did + "' and F_DeptName='" + name + "' and F_DeptId!='" + id + "' ");
  95. if (list.Count > 0)
  96. {
  97. return Error("已经存在此部门");
  98. }
  99. else
  100. {
  101. dModel.F_PartentId = did;
  102. dModel.F_Sort = sort;
  103. dModel.F_DeptName = name;
  104. dModel.F_DeptPhone = phone;
  105. dModel.F_LeaderUser = leader;
  106. dModel.F_TopSplitUser = split;
  107. dModel.F_TopLeaderUser = topleader;
  108. dModel.F_IsDept = isdept;
  109. dModel.F_IsDealDept = isdealdept;
  110. if (departmentBLL.Update(dModel))
  111. return Success("修改成功");
  112. else
  113. return Error("修改失败");
  114. }
  115. }
  116. else
  117. {
  118. return Error("修改失败");
  119. }
  120. }
  121. }
  122. /// <summary>
  123. /// 删除部门
  124. /// </summary>
  125. /// <param name="ids"></param>
  126. /// <returns></returns>
  127. public ActionResult DelDept(string[] ids)
  128. {
  129. if (ids == null || ids.Length <= 0)
  130. return Error("请选择要删除的部门");
  131. var idStr = string.Join(",", ids);
  132. if (string.IsNullOrEmpty(idStr.Trim()))
  133. return Error("请选择要删除的部门");
  134. if (departmentBLL.DeleteList(idStr))
  135. return Success("删除成功");
  136. return Error("删除失败");
  137. }
  138. /// <summary>
  139. /// 删除部门和其下级部门
  140. /// </summary>
  141. /// <param name="ids"></param>
  142. /// <returns></returns>
  143. public ActionResult DelDepts(int id)
  144. {
  145. if (id > 0)
  146. {
  147. var model = new BLL.T_Sys_Department().GetModel(id);
  148. if (DelDeptsByPId(id))
  149. {
  150. new BLL.T_Sys_Department().Delete(id);
  151. }
  152. return Success("删除成功");
  153. }
  154. else
  155. {
  156. return Error("删除失败");
  157. }
  158. }
  159. public bool DelDeptsByPId(int id)
  160. {
  161. bool bl = true;
  162. var list = new BLL.T_Sys_Department().GetModelList(" F_PartentId ='" + id + "'");
  163. foreach (var l in list)
  164. {
  165. if (DelDeptsByPId(l.F_DeptId))
  166. {
  167. new BLL.T_Sys_Department().Delete(l.F_DeptId);
  168. }
  169. }
  170. return bl;
  171. }
  172. #endregion
  173. public ActionResult GetDeptList1(string branchcode)
  174. {
  175. string sqlwhere = " F_IsDelete=0 ";
  176. if (!string.IsNullOrEmpty(branchcode))
  177. {
  178. sqlwhere += " and F_Code='" + branchcode + "'";
  179. }
  180. else
  181. {
  182. return Error("请选择区县");
  183. }
  184. var list = new BLL.T_Branch_List().GetModelList(sqlwhere);
  185. if (list.Count == 0)
  186. {
  187. return Error("查询失败");
  188. }
  189. string controllername = RouteData.Values["controller"].ToString();
  190. string actionname = RouteData.Values["action"].ToString();
  191. if (!string.IsNullOrEmpty(list[0].F_Url))
  192. {
  193. string signcode = CommonHelper.getsigncode(controllername, actionname, list[0].F_Sign);
  194. string strparams = "?signcode=" + signcode;
  195. string result = HttpMethods.HttpGet(list[0].F_Url + "/" + controllername + "/" + actionname + strparams);
  196. return Content(result);
  197. }
  198. else
  199. {
  200. return Error("查询失败");
  201. }
  202. }
  203. }
  204. }