Нет описания

UserAccountController.cs 19KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485
  1. using CallCenter.Utility;
  2. using CallCenterApi.Common;
  3. using CallCenterApi.DB;
  4. using CallCenterApi.Interface.Controllers.Base;
  5. using CallCenterApi.Interface.Models.Input;
  6. using System;
  7. using System.Collections.Generic;
  8. using System.Data;
  9. using System.Linq;
  10. using System.Text.RegularExpressions;
  11. using System.Web;
  12. using System.Web.Mvc;
  13. namespace CallCenterApi.Interface.Controllers
  14. {
  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. private BLL.T_Sys_DictionaryValue dicValueBLL = new BLL.T_Sys_DictionaryValue();
  20. //用户列表
  21. [Authority]
  22. public ActionResult GetList()
  23. {
  24. DataTable dt = new DataTable();
  25. string sql = " ";
  26. try
  27. {
  28. string Key = RequestString.GetQueryString("Key");
  29. int Id = RequestString.GetInt("Id", 0);
  30. string strpageindex = RequestString.GetQueryString("page");
  31. int pageindex = 1;
  32. string strpagesize = RequestString.GetQueryString("pagesize");
  33. int pagesize = 10;
  34. if (Id > 0)
  35. {
  36. sql += " and F_DeptId=" + Id;
  37. }
  38. if (!string.IsNullOrWhiteSpace(Key))
  39. {
  40. sql = "";
  41. string str = string.Format(" and (F_UserCode like '%{0}%' or F_UserName like '%{1}%')", Key, Key);
  42. sql += str;
  43. }
  44. if (strpageindex.Trim() != "")
  45. {
  46. pageindex = Convert.ToInt32(strpageindex);
  47. }
  48. if (strpagesize.Trim() != "")
  49. {
  50. pagesize = Convert.ToInt32(strpagesize);
  51. }
  52. int recordCount = 0;
  53. dt = BLL.PagerBLL.GetListPager(
  54. "T_Sys_UserAccount",
  55. "F_UserId",
  56. "*",
  57. sql,
  58. "ORDER BY F_UserId desc",
  59. pagesize,
  60. pageindex,
  61. true,
  62. out recordCount);
  63. List<Model.UserAccount> modelList = new BLL.UserAccount().DataTableToList(dt);
  64. var obj = new
  65. {
  66. rows = modelList.Select(x => new
  67. {
  68. F_UserId = x.F_UserId,
  69. F_UserCode = x.F_UserCode,
  70. F_ExtensionNumber = x.F_ExtensionNumber,
  71. F_UserName = x.F_UserName,
  72. F_GroupName = x.F_GroupName,
  73. F_DeptId = x.F_DeptId,
  74. F_RoleId = x.F_RoleId,
  75. F_GroupId = x.F_GroupId,
  76. F_SeatFlag = x.F_SeatFlag,
  77. F_SeatRight = x.F_SeatRight,
  78. F_SeatLevel = x.F_SeatLevel,
  79. F_SexFlag = x.F_SexFlag,
  80. F_RemindFlag = x.F_RemindFlag,
  81. F_Remark = x.F_Remark,
  82. F_Telephone = x.F_Telephone,
  83. F_Mobile = x.F_Mobile,
  84. F_HomePhone = x.F_HomePhone,
  85. F_Birthday = x.F_Birthday,
  86. F_CreateOn = x.F_CreateOn,
  87. F_CancelOn = x.F_CancelOn,
  88. F_DeleteFlag = x.F_DeleteFlag,
  89. F_APPOnFlag = x.F_APPOnFlag,
  90. F_LastActiveTime = x.F_LastActiveTime,
  91. F_See = x.F_See,
  92. F_HJType = x.F_HJType,
  93. F_PId = x.F_PId,
  94. F_TmId = x.F_TmId,
  95. F_RoleName = x.F_RoleName,
  96. F_DeptName = x.F_DeptName,
  97. F_WorkNumber = x.F_WorkNumber
  98. }),
  99. total = recordCount
  100. };
  101. return Content(obj.ToJson());
  102. }
  103. catch (Exception err)
  104. {
  105. return Error("错误:" + err.ToString());
  106. }
  107. finally
  108. {
  109. dt.Clear();
  110. dt.Dispose();
  111. }
  112. }
  113. //获取用户信息
  114. [Authority]
  115. public ActionResult GetUser(int userId = 0, string userCode = "")
  116. {
  117. string sql = "";
  118. if (userId > 0)
  119. {
  120. sql += " and F_UserId=" + userId;
  121. }
  122. if (!string.IsNullOrWhiteSpace(userCode))
  123. {
  124. sql += " and F_UserCode='" + userCode+"'";
  125. }
  126. if (string.IsNullOrWhiteSpace(sql))
  127. return Error("获取失败");
  128. Model.T_Sys_UserAccount userModel = sysUserAccountBll.GetModelList(" 1=1 " + sql).FirstOrDefault();
  129. if (userModel == null) return Error("获取失败");
  130. var depModel = departmentBLL.GetModel(userModel.F_DeptId);
  131. var zxzModel = dicValueBLL.GetModel(userModel.F_GroupId ?? 0);
  132. return Success("获取成功", new
  133. {
  134. F_UserId = userModel.F_UserId,
  135. F_UserCode = userModel.F_UserCode,
  136. F_ExtensionNumber = userModel.F_ExtensionNumber,
  137. F_UserName = userModel.F_UserName,
  138. F_DeptId = userModel.F_DeptId,
  139. F_RoleId = userModel.F_RoleId,
  140. F_GroupId = userModel.F_GroupId,
  141. F_SeatFlag = userModel.F_SeatFlag,
  142. F_SeatRight = userModel.F_SeatRight,
  143. F_SeatLevel = userModel.F_SeatLevel,
  144. F_SexFlag = userModel.F_SexFlag,
  145. F_RemindFlag = userModel.F_RemindFlag,
  146. F_Remark = userModel.F_Remark,
  147. F_Telephone = userModel.F_Telephone,
  148. F_Mobile = userModel.F_Mobile,
  149. F_HomePhone = userModel.F_HomePhone,
  150. F_Birthday = (userModel.F_Birthday ?? DateTime.MinValue).ToString("yyyy-MM-dd"),
  151. F_CreateOn = userModel.F_CreateOn,
  152. F_CancelOn = userModel.F_CancelOn,
  153. F_DeleteFlag = userModel.F_DeleteFlag,
  154. F_APPOnFlag = userModel.F_APPOnFlag,
  155. F_LastActiveTime = userModel.F_LastActiveTime,
  156. F_See = userModel.F_See,
  157. F_HJType = userModel.F_HJType ?? 0,
  158. F_PId = userModel.F_PId,
  159. F_TmId = userModel.F_TmId,
  160. F_WorkNumber = userModel.F_WorkNumber,
  161. //zxzname = zxzModel?.F_Name ?? "",
  162. depname = depModel?.F_DeptName ?? ""
  163. });
  164. }
  165. [Authority]
  166. //添加用户信息
  167. public ActionResult AddUsers(UserAccountInput input)
  168. {
  169. Regex reg = new Regex(@"^[1-9]\d*$");
  170. if (!reg.IsMatch(input.Usercode.Trim()))
  171. {
  172. return Error("工号必须为正整数");
  173. }
  174. Model.T_Sys_UserAccount userAccountModel = new Model.T_Sys_UserAccount();
  175. userAccountModel.F_UserCode = input.Usercode.Trim();
  176. userAccountModel.F_UserName = input.Username.Trim();
  177. userAccountModel.F_Password = input.Password.Trim();
  178. //userAccountModel.F_ExtensionNumber = input.Extno.Trim();
  179. //userAccountModel.F_WorkNumber = input.Usercode;
  180. userAccountModel.F_DeptId = input.DeptId;
  181. userAccountModel.F_RoleId = input.RoleId;
  182. //userAccountModel.F_GroupId = input.GroupId;
  183. userAccountModel.F_SeatFlag = input.IsSeat;
  184. userAccountModel.F_SeatRight = input.SearRight;
  185. userAccountModel.F_SexFlag = input.Sex;
  186. userAccountModel.F_Remark = input.Remark;
  187. userAccountModel.F_Mobile = input.Mobile;
  188. userAccountModel.F_Telephone = input.Telphone;
  189. userAccountModel.F_Birthday = input.Birth;
  190. userAccountModel.F_CreateOn = DateTime.Now;
  191. userAccountModel.F_DeleteFlag = 0;
  192. //userAccountModel.F_HJType = input.HjType;
  193. var model = sysUserAccountBll.GetModel(input.Usercode);
  194. if (model != null)
  195. return Error("当前员工工号存在,请更换!");
  196. if (input.IsSeat)
  197. {
  198. userAccountModel.F_WorkNumber = input.Usercode.Trim();
  199. if (input.ClassId.Value > 0)
  200. {
  201. var cls = new BLL.T_Sys_Class().GetModel(input.ClassId.Value);
  202. userAccountModel.F_ClassCode = (cls != null ? cls.F_Code : "");
  203. }
  204. SysConfigController sys = new SysConfigController();
  205. //话务人员限制权限判断
  206. if (sys.IsValidSeatPermission())
  207. {
  208. if (sysUserAccountBll.Add(userAccountModel) > 0)
  209. return Success("新增成功!");
  210. else
  211. return Error("新增失败!");
  212. }
  213. else
  214. {
  215. return Error("话务人员数量已超!");
  216. }
  217. }
  218. if (sysUserAccountBll.Add(userAccountModel) > 0)
  219. return Success("新增成功!");
  220. else
  221. return Error("新增失败!");
  222. }
  223. [Authority]
  224. //修改用户信息
  225. public ActionResult EditUsers(UserAccountInput input)
  226. {
  227. Regex reg = new Regex(@"^[1-9]\d*$");
  228. if (!reg.IsMatch(input.Usercode.Trim()))
  229. {
  230. return Error("工号必须为正整数");
  231. }
  232. BLL.T_Sys_UserAccount sysUserAccountBll = new BLL.T_Sys_UserAccount();
  233. Model.T_Sys_UserAccount userAccountModel = sysUserAccountBll.GetModelList(" F_UserId = " + input.UserId).FirstOrDefault();
  234. if (userAccountModel == null)
  235. return Error("获取用户失败");
  236. userAccountModel.F_UserCode = input.Usercode.Trim();
  237. userAccountModel.F_UserName = input.Username.Trim();
  238. //userAccountModel.F_Password = input.Password.Trim();
  239. //userAccountModel.F_ExtensionNumber = input.Extno.Trim();
  240. //userAccountModel.F_WorkNumber = input.Usercode;
  241. userAccountModel.F_DeptId = input.DeptId;
  242. userAccountModel.F_RoleId = input.RoleId;
  243. //userAccountModel.F_GroupId = input.GroupId;
  244. userAccountModel.F_SeatFlag = input.IsSeat;
  245. userAccountModel.F_SeatRight = input.SearRight;
  246. userAccountModel.F_SexFlag = input.Sex;
  247. userAccountModel.F_Remark = input.Remark;
  248. userAccountModel.F_Mobile = input.Mobile;
  249. userAccountModel.F_Telephone = input.Telphone;
  250. userAccountModel.F_Birthday = input.Birth;
  251. userAccountModel.F_CreateOn = DateTime.Now;
  252. //userAccountModel.F_DeleteFlag = 0;
  253. //userAccountModel.F_HJType = input.HjType;
  254. if (input.IsSeat)
  255. {
  256. userAccountModel.F_WorkNumber = input.Usercode.Trim();
  257. if (input.ClassId.Value > 0)
  258. {
  259. var cls = new BLL.T_Sys_Class().GetModel(input.ClassId.Value);
  260. userAccountModel.F_ClassCode = (cls != null ? cls.F_Code : "");
  261. }
  262. SysConfigController sys = new SysConfigController();
  263. //话务人员限制权限判断
  264. if (sys.IsValidSeatPermission())
  265. {
  266. if (sysUserAccountBll.Update(userAccountModel))
  267. return Success("编辑成功!");
  268. else
  269. return Error("编辑失败!");
  270. }
  271. else
  272. {
  273. return Error("话务人员数量已超!");
  274. }
  275. }
  276. if (sysUserAccountBll.Update(userAccountModel))
  277. return Success("编辑成功!");
  278. else
  279. return Error("编辑失败!");
  280. }
  281. [Authority]
  282. //删除/禁用/启用 用户
  283. public ActionResult DelUsers(string[] ids, int state = 0)
  284. {
  285. if (ids == null || ids.Length <= 0)
  286. return Error("请选择用户");
  287. var idStr = string.Join(",", ids);
  288. if (string.IsNullOrEmpty(idStr))
  289. return Error("请选择用户");
  290. SysConfigController sys = new SysConfigController();
  291. //话务人员限制权限判断
  292. if (state == 0) {
  293. if (sys.IsValidSeatPermission())
  294. {
  295. if (sysUserAccountBll.DeleteList(idStr, state))
  296. return Success("设置成功");
  297. else
  298. return Error("设置失败");
  299. }
  300. else
  301. {
  302. return Error("话务人员数量已超!");
  303. }
  304. }
  305. if (sysUserAccountBll.DeleteList(idStr, state))
  306. return Success("设置成功");
  307. else
  308. return Error("设置失败");
  309. }
  310. [Authority]
  311. //删除用户
  312. public ActionResult WLDelUsers(string[] ids)
  313. {
  314. if (ids == null || ids.Length <= 0)
  315. return Error("请选择用户");
  316. var idStr = string.Join(",", ids);
  317. if (string.IsNullOrEmpty(idStr))
  318. return Error("请选择用户");
  319. if (sysUserAccountBll.DeleteList(idStr))
  320. return Success("删除成功");
  321. else
  322. return Error("删除失败");
  323. }
  324. //获取坐席列表
  325. public ActionResult GetSeatList()
  326. {
  327. List<Model.T_Sys_UserAccount> userSeartList = sysUserAccountBll.GetModelList(" f_seatflag=1 and F_DeleteFlag=0 order by f_userid desc ");
  328. if (userSeartList.Count > 0)
  329. return Success("列表加载成功", userSeartList);
  330. else
  331. return Error("列表加载失败");
  332. }
  333. //根据角色获取用户
  334. public ActionResult GetUsersList(string rolecode)
  335. {
  336. var sql = " 1=1 ";
  337. if (!string.IsNullOrWhiteSpace(rolecode.Trim()))
  338. sql += " and F_RoleId in (select F_RoleId from T_Sys_RoleInfo where F_RoleCode='" + rolecode.Trim() + "')";
  339. List<Model.T_Sys_UserAccount> userList = sysUserAccountBll.GetModelList(sql + " order by f_userid desc ");
  340. if (userList.Count > 0)
  341. return Success("列表加载成功", userList);
  342. else
  343. return Error("列表加载失败");
  344. }
  345. //根据部门获取用户
  346. public ActionResult GetDeptUserList(int deptid = 0)
  347. {
  348. List<Model.T_Sys_UserAccount> DeptUserList = sysUserAccountBll.GetModelList("F_DeptId='" + deptid + "' order by f_userid desc ");
  349. return Success("列表加载成功", DeptUserList);
  350. }
  351. [Authority]
  352. //获取当前用户信息
  353. public ActionResult GetNowUser()
  354. {
  355. Model.T_Sys_UserAccount userModel = new BLL.T_Sys_UserAccount().GetModel(User.UserData["F_UserCode"]);
  356. if (userModel == null)
  357. return Error("获取失败");
  358. Model.T_Sys_RoleInfo roleModel = new BLL.T_Sys_RoleInfo().GetModel(userModel.F_RoleId);
  359. var obj = new
  360. {
  361. user = userModel,
  362. role = roleModel
  363. };
  364. return Success("获取成功", obj);
  365. }
  366. [Authority]
  367. /// <summary>
  368. /// 重置密码
  369. /// </summary>
  370. /// <param name="usercode"></param>
  371. /// <param name="pwd"></param>
  372. /// <returns></returns>
  373. public ActionResult ResetPwd(string usercode = "", string pwd = "")
  374. {
  375. if (string.IsNullOrWhiteSpace(pwd))
  376. return Error("请输入密码");
  377. var model = sysUserAccountBll.GetModel(usercode);
  378. if (model == null) return Error("此用户不存在");
  379. model.F_Password = pwd;
  380. if (sysUserAccountBll.Update(model))
  381. return Success("重置密码成功");
  382. else
  383. return Error("重置密码失败");
  384. }
  385. public ActionResult UpdatePwd(string usercode = "", string pwd = "", string oldPwd = "")
  386. {
  387. if (string.IsNullOrWhiteSpace(pwd))
  388. return Error("请输入密码");
  389. var model = sysUserAccountBll.GetModel(usercode);
  390. if (model == null) return Error("此用户不存在");
  391. if (!model.F_Password.Equals(oldPwd)) return Error("原密码不正确");
  392. model.F_Password = pwd;
  393. if (sysUserAccountBll.Update(model))
  394. return Success("重置密码成功");
  395. else
  396. return Error("重置密码失败");
  397. }
  398. #region App手机端 用户列表
  399. /// <summary>
  400. /// App手机端 用户列表
  401. /// </summary>
  402. /// <returns></returns>
  403. [Authority]
  404. public ActionResult GetAppUserList()
  405. {
  406. DataTable dt = new DataTable();
  407. string sql = " 1=1 and F_RoleId=2 ";
  408. try
  409. {
  410. string Key = RequestString.GetQueryString("Key");
  411. if (!string.IsNullOrWhiteSpace(Key))
  412. {
  413. string str = string.Format(" and (F_DeptId IN (SELECT F_DeptId FROM dbo.T_Sys_Department WHERE F_DeptName like '%{0}%') or F_UserName like '%{1}%' or F_Mobile like '%{2}%' or F_Telephone like '%{3}%' or F_HomePhone like '%{3}%')", Key, Key, Key, Key, Key);
  414. sql += str;
  415. }
  416. dt = sysUserAccountBll.GetList(sql).Tables[0];
  417. List<Model.UserAccount> modelList = new BLL.UserAccount().DataTableToList(dt);
  418. return Success("获取成功",
  419. modelList.Select(x => new
  420. {
  421. F_UserId = x.F_UserId,
  422. F_UserCode = x.F_UserCode,
  423. F_UserName = x.F_UserName,
  424. F_DeptId = x.F_DeptId,
  425. F_SexFlag = x.F_SexFlag,
  426. F_Remark = x.F_Remark,
  427. F_Telephone = x.F_Telephone,
  428. F_Mobile = x.F_Mobile,
  429. F_HomePhone = x.F_HomePhone,
  430. F_Birthday = x.F_Birthday,
  431. F_CreateOn = x.F_CreateOn,
  432. F_APPOnFlag = x.F_APPOnFlag,
  433. F_LastActiveTime = x.F_LastActiveTime,
  434. F_RoleName = x.F_RoleName,
  435. F_DeptName = x.F_DeptName
  436. })
  437. );
  438. }
  439. catch (Exception err)
  440. {
  441. return Error("错误:" + err.ToString());
  442. }
  443. finally
  444. {
  445. dt.Clear();
  446. dt.Dispose();
  447. }
  448. }
  449. #endregion
  450. }
  451. }