12345市长热线标准版-后端

GroupController.cs 7.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  1. using CallCenter.Utility;
  2. using CallCenterApi.Common;
  3. using CallCenterApi.DB;
  4. using CallCenterApi.Interface.Controllers.Base;
  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. public class GroupController : BaseController
  14. {
  15. // GET: Group
  16. /// <summary>
  17. /// 获取班组列表
  18. /// </summary>
  19. /// <returns></returns>
  20. [Authority]
  21. public ActionResult GetList(int isdc = 0)
  22. {
  23. DataTable dt = new DataTable();
  24. string sql = " and F_IsDelete=0 ";
  25. string strcode = HttpUtility.UrlDecode(RequestString.GetQueryString("code"));
  26. string strname = HttpUtility.UrlDecode(RequestString.GetQueryString("name"));
  27. string strpageindex = RequestString.GetQueryString("page");
  28. int pageindex = 1;
  29. string strpagesize = RequestString.GetQueryString("pagesize");
  30. int pagesize = 10;
  31. if (strcode.Trim() != "" && strcode != "undefined")
  32. {
  33. sql += " and F_GroupCode = '" + strcode.Trim() + "' ";
  34. }
  35. if (strname.Trim() != "" && strname != "undefined")
  36. {
  37. sql += " and F_GroupName like '%" + strname + "%' ";
  38. }
  39. if (strpageindex.Trim() != "")
  40. {
  41. pageindex = Convert.ToInt32(strpageindex);
  42. }
  43. if (strpagesize.Trim() != "")
  44. {
  45. pagesize = Convert.ToInt32(strpagesize);
  46. }
  47. string cols = "*,dbo.GetUserName(F_CreateUser) as UserName";
  48. if (isdc > 0)
  49. {
  50. var dtdc = DbHelperSQL.Query(" select " + cols + " from T_Sys_Group where 1=1 " + sql).Tables[0];
  51. var msg = new NPOIHelper().ExportToExcel("班组列表", dtdc);
  52. if (msg == "")
  53. {
  54. return Success("导出成功");
  55. }
  56. else
  57. {
  58. return Error("导出失败");
  59. }
  60. }
  61. int recordCount = 0;
  62. dt = BLL.PagerBLL.GetListPager(
  63. "T_Sys_Group",
  64. "F_Id",
  65. cols,
  66. sql,
  67. "ORDER BY F_CreateTime DESC",
  68. pagesize,
  69. pageindex,
  70. true,
  71. out recordCount);
  72. var obj = new
  73. {
  74. state = "success",
  75. message = "成功",
  76. rows = dt,
  77. total = recordCount
  78. };
  79. return Content(obj.ToJson());
  80. }
  81. /// <summary>
  82. /// 获取班组列表
  83. /// </summary>
  84. /// <returns></returns>
  85. [Authority]
  86. public ActionResult GetGroupList()
  87. {
  88. DataTable dt = new BLL.T_Sys_Group().GetList(" F_State=0 and F_IsDelete=0 ").Tables[0];
  89. dt.Columns.Add("Users", typeof(object));
  90. foreach (DataRow dr in dt.Rows)
  91. {
  92. dr["Users"] = new BLL.T_Sys_UserAccount().GetList(" F_GroupCode='"+dr["F_GroupCode"].ToString()+"' ").Tables[0];
  93. }
  94. return Success("加载成功", dt);
  95. }
  96. /// <summary>
  97. /// 获取班组
  98. /// </summary>
  99. /// <param name="GroupId"></param>
  100. /// <returns></returns>
  101. [Authority]
  102. public ActionResult GetGroup(int id = 0)
  103. {
  104. if (id != 0)
  105. {
  106. return Success("成功", new BLL.T_Sys_Group().GetModel(id));
  107. }
  108. else
  109. {
  110. return Error("参数错误");
  111. }
  112. }
  113. /// <summary>
  114. /// 获取班组
  115. /// </summary>
  116. /// <param name="GroupId"></param>
  117. /// <returns></returns>
  118. [Authority]
  119. public ActionResult GetGroupByCode(string code)
  120. {
  121. if (!string.IsNullOrEmpty(code))
  122. {
  123. return Success("成功", new BLL.T_Sys_Group().GetModelList(" F_GroupCode='" + code + "' ").FirstOrDefault());
  124. }
  125. else
  126. {
  127. return Error("参数错误");
  128. }
  129. }
  130. /// <summary>
  131. /// 添加班组
  132. /// </summary>
  133. /// <param name="input"></param>
  134. /// <returns></returns>
  135. [HttpPost]
  136. [Authority]
  137. public ActionResult AddGroup()
  138. {
  139. int userId = Utils.StrToInt(User.UserData["F_UserID"], 0);
  140. Model.T_Sys_UserAccount userModel = new BLL.T_Sys_UserAccount().GetModel(userId);
  141. int id = RequestString.GetInt("id", 0);
  142. string name = RequestString.GetFormString("name");
  143. string code = RequestString.GetFormString("code");
  144. string remark = RequestString.GetFormString("remark");
  145. Model.T_Sys_Group dModel = new Model.T_Sys_Group();
  146. if (id == 0)
  147. {
  148. var list = new BLL.T_Sys_Group().GetModelList(" F_GroupCode='" + code + "' and F_IsDelete=0 ");
  149. if (list.Count > 0)
  150. {
  151. return Error("已经存在此班组");
  152. }
  153. else
  154. {
  155. dModel.F_GroupCode = code;
  156. dModel.F_GroupName = name;
  157. dModel.F_Remark = remark;
  158. dModel.F_State = 0;
  159. dModel.F_IsDelete = 0;
  160. dModel.F_CreateUser = userModel.F_UserCode;
  161. dModel.F_CreateTime = DateTime.Now;
  162. int n = new BLL.T_Sys_Group().Add(dModel);
  163. if (n > 0)
  164. return Success("添加成功", n);
  165. else
  166. return Error("添加失败");
  167. }
  168. }
  169. else
  170. {
  171. dModel = new BLL.T_Sys_Group().GetModel(id);
  172. if (dModel != null)
  173. {
  174. var list = new BLL.T_Sys_Group().GetModelList(" F_GroupCode='" + code + "' and F_IsDelete=0 and F_Id!='" + id + "' ");
  175. if (list.Count > 0)
  176. {
  177. return Error("已经存在此班组");
  178. }
  179. else
  180. {
  181. dModel.F_GroupCode = code;
  182. dModel.F_GroupName = name;
  183. dModel.F_Remark = remark;
  184. if (new BLL.T_Sys_Group().Update(dModel))
  185. return Success("修改成功");
  186. else
  187. return Error("修改失败");
  188. }
  189. }
  190. else
  191. {
  192. return Error("修改失败");
  193. }
  194. }
  195. }
  196. /// <summary>
  197. /// 删除班组
  198. /// </summary>
  199. /// <param name="ids"></param>
  200. /// <returns></returns>
  201. [Authority]
  202. public ActionResult DelGroup(string[] ids)
  203. {
  204. int userId = Utils.StrToInt(User.UserData["F_UserID"], 0);
  205. Model.T_Sys_UserAccount userModel = new BLL.T_Sys_UserAccount().GetModel(userId);
  206. if (ids == null || ids.Length <= 0)
  207. {
  208. return Error("请选择要删除的班组");
  209. }
  210. var idStr = string.Join(",", ids);
  211. if (string.IsNullOrEmpty(idStr.Trim()))
  212. {
  213. return Error("请选择要删除的班组");
  214. }
  215. int n = DbHelperSQL.ExecuteSql(" update T_Sys_Group set F_IsDelete=1,F_DeleteUser='" + userModel.F_UserCode + "',F_DeleteTime=getdate() where F_Id in (" + idStr + ")");
  216. if (n > 0)
  217. {
  218. return Success("删除成功");
  219. }
  220. return Error("删除失败");
  221. }
  222. }
  223. }