县级监管平台

UserAccountController.cs 12KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321
  1. using CallCenterApi.Common;
  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.Text.RegularExpressions;
  10. using System.Web;
  11. using System.Web.Mvc;
  12. namespace CallCenterApi.Interface.Controllers
  13. {
  14. [Authority]
  15. public class UserAccountController : BaseController
  16. {
  17. private BLL.T_Sys_UserAccount sysUserAccountBll = new BLL.T_Sys_UserAccount();
  18. private BLL.T_Sys_Department departmentBLL = new BLL.T_Sys_Department();
  19. //用户列表
  20. public ActionResult GetList()
  21. {
  22. DataTable dt = new DataTable();
  23. string sql = " and F_IsDelete=0 ";
  24. try
  25. {
  26. string Key = RequestString.GetQueryString("Key");
  27. int deptid = RequestString.GetInt("deptid", 0);
  28. int roleid = RequestString.GetInt("roleid", 0);
  29. string strpageindex = RequestString.GetQueryString("page");
  30. int pageindex = 1;
  31. string strpagesize = RequestString.GetQueryString("pagesize");
  32. int pagesize = 10;
  33. if (deptid > 0)
  34. {
  35. sql += " and F_DeptId=" + deptid;
  36. }
  37. if (roleid > 0)
  38. {
  39. sql += " and F_RoleId=" + roleid;
  40. }
  41. if (!string.IsNullOrWhiteSpace(Key))
  42. {
  43. string str = string.Format(" and (F_UserCode like '%{0}%' or F_UserName like '%{1}%')", Key, Key);
  44. sql += str;
  45. }
  46. if (strpageindex.Trim() != "")
  47. {
  48. pageindex = Convert.ToInt32(strpageindex);
  49. }
  50. if (strpagesize.Trim() != "")
  51. {
  52. pagesize = Convert.ToInt32(strpagesize);
  53. }
  54. int recordCount = 0;
  55. dt = BLL.PagerBLL.GetListPager(
  56. "T_Sys_UserAccount",
  57. "F_Id",
  58. "*",
  59. sql,
  60. "ORDER BY F_CreateTime desc",
  61. pagesize,
  62. pageindex,
  63. true,
  64. out recordCount);
  65. var obj = new
  66. {
  67. rows = new BLL.T_Sys_UserAccount().DataTableToList(dt),
  68. total = recordCount
  69. };
  70. return Content(obj.ToJson());
  71. }
  72. catch (Exception err)
  73. {
  74. return Error("错误:" + err.ToString());
  75. }
  76. finally
  77. {
  78. dt.Clear();
  79. dt.Dispose();
  80. }
  81. }
  82. //获取用户信息
  83. public ActionResult GetUser(int userId = 0, string userCode = "")
  84. {
  85. string sql = " and F_IsDelete=0 ";
  86. if (userId > 0)
  87. {
  88. sql += " and F_Id=" + userId;
  89. }
  90. if (!string.IsNullOrWhiteSpace(userCode))
  91. {
  92. sql += " and F_UserCode='" + userCode+"'";
  93. }
  94. if (string.IsNullOrWhiteSpace(sql))
  95. return Error("获取失败");
  96. Model.T_Sys_UserAccount userModel = sysUserAccountBll.GetModelList(" 1=1 " + sql).FirstOrDefault();
  97. return Success("获取成功", userModel);
  98. }
  99. //添加用户信息
  100. public ActionResult AddUsers(UserAccountInput input)
  101. {
  102. Model.T_Sys_UserAccount userModel = new BLL.T_Sys_UserAccount().GetModel(User.UserData["F_UserCode"]);
  103. Regex reg = new Regex(@"^[1-9]\d*$");
  104. if (!reg.IsMatch(input.Usercode.Trim()))
  105. {
  106. return Error("工号必须为正整数");
  107. }
  108. var model = sysUserAccountBll.GetModel(input.Usercode);
  109. if (model != null)
  110. return Error("当前员工工号存在,请更换!");
  111. Model.T_Sys_UserAccount userAccountModel = new Model.T_Sys_UserAccount();
  112. userAccountModel.F_UserCode = input.Usercode.Trim();
  113. userAccountModel.F_UserName = input.Username.Trim();
  114. userAccountModel.F_Password = input.Password.Trim();
  115. userAccountModel.F_DeptId = input.DeptId;
  116. userAccountModel.F_RoleId = input.RoleId;
  117. userAccountModel.F_Sex = input.Sex;
  118. userAccountModel.F_Remark = input.Remark;
  119. userAccountModel.F_Mobile = input.Mobile;
  120. userAccountModel.F_Telephone = input.Telphone;
  121. userAccountModel.F_CreateUser = userModel.F_UserCode;
  122. userAccountModel.F_CreateTime = DateTime.Now;
  123. userAccountModel.F_IsDelete = 0;
  124. //userAccountModel.F_HJType = input.HjType;
  125. if (sysUserAccountBll.Add(userAccountModel) > 0)
  126. return Success("新增成功!");
  127. else
  128. return Error("新增失败!");
  129. }
  130. //修改用户信息
  131. public ActionResult EditUsers(UserAccountInput input)
  132. {
  133. Regex reg = new Regex(@"^[1-9]\d*$");
  134. if (!reg.IsMatch(input.Usercode.Trim()))
  135. {
  136. return Error("工号必须为正整数");
  137. }
  138. BLL.T_Sys_UserAccount sysUserAccountBll = new BLL.T_Sys_UserAccount();
  139. Model.T_Sys_UserAccount userAccountModel = sysUserAccountBll.GetModelList(" F_IsDelete=0 and F_Id = " + input.UserId).FirstOrDefault();
  140. if (userAccountModel == null)
  141. return Error("获取用户失败");
  142. userAccountModel.F_UserCode = input.Usercode.Trim();
  143. userAccountModel.F_UserName = input.Username.Trim();
  144. userAccountModel.F_DeptId = input.DeptId;
  145. userAccountModel.F_RoleId = input.RoleId;
  146. userAccountModel.F_Sex = input.Sex;
  147. userAccountModel.F_Remark = input.Remark;
  148. userAccountModel.F_Mobile = input.Mobile;
  149. userAccountModel.F_Telephone = input.Telphone;
  150. if (sysUserAccountBll.Update(userAccountModel))
  151. return Success("编辑成功!");
  152. else
  153. return Error("编辑失败!");
  154. }
  155. //删除/禁用/启用 用户
  156. public ActionResult DelUsers(string[] ids)
  157. {
  158. Model.T_Sys_UserAccount userModel = new BLL.T_Sys_UserAccount().GetModel(User.UserData["F_UserCode"]);
  159. if (ids == null || ids.Length <= 0)
  160. {
  161. return Error("请选择要删除的用户");
  162. }
  163. var idStr = string.Join(",", ids);
  164. if (string.IsNullOrEmpty(idStr.Trim()))
  165. {
  166. return Error("请选择要删除的用户");
  167. }
  168. int n = DbHelperSQL.ExecuteSql(" update T_Sys_UserAccount set F_IsDelete=1,F_DeleteUser='" + userModel.F_UserCode + "',F_DeleteTime=getdate() where F_Id in (" + idStr + ")");
  169. if (n > 0)
  170. {
  171. return Success("删除成功");
  172. }
  173. return Error("删除失败");
  174. }
  175. //根据部门获取用户
  176. public ActionResult GetDeptUserList(int deptid = 0)
  177. {
  178. List<Model.T_Sys_UserAccount> DeptUserList = sysUserAccountBll.GetModelList("F_DeptId='" + deptid + "' order by F_Id desc ");
  179. return Success("列表加载成功", DeptUserList);
  180. }
  181. //获取当前用户信息
  182. public ActionResult GetNowUser()
  183. {
  184. Model.T_Sys_UserAccount userModel = new BLL.T_Sys_UserAccount().GetModel(User.UserData["F_UserCode"]);
  185. return Success("获取成功", userModel);
  186. }
  187. /// <summary>
  188. /// 重置密码
  189. /// </summary>
  190. /// <param name="usercode"></param>
  191. /// <param name="pwd"></param>
  192. /// <returns></returns>
  193. public ActionResult ResetPwd(string usercode = "", string pwd = "")
  194. {
  195. if (string.IsNullOrWhiteSpace(pwd))
  196. return Error("请输入密码");
  197. var model = sysUserAccountBll.GetModel(usercode);
  198. if (model == null) return Error("此用户不存在");
  199. model.F_Password = pwd;
  200. if (sysUserAccountBll.Update(model))
  201. return Success("重置密码成功");
  202. else
  203. return Error("重置密码失败");
  204. }
  205. public ActionResult UpdatePwd(string usercode = "", string pwd = "", string oldPwd = "")
  206. {
  207. if (string.IsNullOrWhiteSpace(pwd))
  208. return Error("请输入密码");
  209. var model = sysUserAccountBll.GetModel(usercode);
  210. if (model == null) return Error("此用户不存在");
  211. if (!model.F_Password.Equals(oldPwd)) return Error("原密码不正确");
  212. model.F_Password = pwd;
  213. if (sysUserAccountBll.Update(model))
  214. return Success("重置密码成功");
  215. else
  216. return Error("重置密码失败");
  217. }
  218. //获取坐席列表
  219. public ActionResult GetSeatList(string branchcode)
  220. {
  221. string sqlwhere = " F_IsDelete=0 ";
  222. if (!string.IsNullOrEmpty(branchcode))
  223. {
  224. sqlwhere += " and F_Code='" + branchcode + "'";
  225. }
  226. else
  227. {
  228. return Error("请选择区县");
  229. }
  230. var list = new BLL.T_Branch_List().GetModelList(sqlwhere);
  231. if (list.Count == 0)
  232. {
  233. return Error("查询失败");
  234. }
  235. string controllername = RouteData.Values["controller"].ToString();
  236. string actionname = RouteData.Values["action"].ToString();
  237. if (!string.IsNullOrEmpty(list[0].F_Url))
  238. {
  239. string signcode = CommonHelper.getsigncode(controllername, actionname, list[0].F_Sign);
  240. string strparams = "?signcode=" + signcode;
  241. string result = HttpMethods.HttpGet(list[0].F_Url + "/" + controllername + "/" + actionname + strparams);
  242. return Content(result);
  243. }
  244. else
  245. {
  246. return Error("查询失败");
  247. }
  248. }
  249. //根据角色获取用户
  250. public ActionResult GetUsersList(string branchcode, string rolecode)
  251. {
  252. string sqlwhere = " F_IsDelete=0 ";
  253. if (!string.IsNullOrEmpty(branchcode))
  254. {
  255. sqlwhere += " and F_Code='" + branchcode + "'";
  256. }
  257. else
  258. {
  259. return Error("请选择区县");
  260. }
  261. var list = new BLL.T_Branch_List().GetModelList(sqlwhere);
  262. if (list.Count == 0)
  263. {
  264. return Error("查询失败");
  265. }
  266. if (string.IsNullOrEmpty(rolecode))
  267. {
  268. return Error("查询失败");
  269. }
  270. string controllername = RouteData.Values["controller"].ToString();
  271. string actionname = RouteData.Values["action"].ToString();
  272. if (!string.IsNullOrEmpty(list[0].F_Url))
  273. {
  274. string signcode = CommonHelper.getsigncode(controllername, actionname, list[0].F_Sign);
  275. string strparams = "?rolecode=" + rolecode + "&signcode=" + signcode;
  276. string result = HttpMethods.HttpGet(list[0].F_Url + "/" + controllername + "/" + actionname + strparams);
  277. return Content(result);
  278. }
  279. else
  280. {
  281. return Error("查询失败");
  282. }
  283. }
  284. }
  285. }