Geen omschrijving

UserAccountController.cs 23KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546
  1. using CallCenter.Utility;
  2. using CallCenterApi.Common;
  3. using CallCenterApi.DB;
  4. using CallCenterApi.Interface.Controllers.Base;
  5. using CallCenterApi.Interface.Models.Filter;
  6. using CallCenterApi.Interface.Models.Input;
  7. using System;
  8. using System.Collections.Generic;
  9. using System.Data;
  10. using System.Linq;
  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. //[Authority]
  21. //用户列表
  22. public ActionResult GetList(FilterUserAccount filter)
  23. {
  24. ActionResult res = NoToken("未知错误,请重新登录");
  25. if (Request.IsAuthenticated)
  26. {
  27. DataTable dt = new DataTable();
  28. string sql = " ";
  29. if (filter.dptid > 0)
  30. {
  31. Model.T_Sys_Department deptModel = departmentBLL.GetModel(filter.dptid);
  32. if (deptModel != null)
  33. {
  34. sql += " and F_DeptId in ( select F_DeptId from T_Sys_Department where F_DeptCode like '" + deptModel.F_DeptCode + "%') ";
  35. }
  36. }
  37. if (!string.IsNullOrWhiteSpace(filter.Key))
  38. {
  39. sql = "";
  40. string str = string.Format(" and (F_UserCode like '%{0}%' or F_UserName like '%{1}%')", filter.Key, filter.Key);
  41. sql += str;
  42. }
  43. if (!string.IsNullOrWhiteSpace(filter.sgid))
  44. {
  45. sql += " and F_SeartGroupID in (" + filter.sgid + ")";
  46. }
  47. int recordCount = 0;
  48. dt = BLL.PagerBLL.GetListPager(
  49. "T_Sys_UserAccount",
  50. "F_UserId",
  51. "*",
  52. sql,
  53. "ORDER BY F_UserId desc",
  54. filter.PageSize,
  55. filter.PageIndex,
  56. true,
  57. out recordCount);
  58. List<Model.UserAccount> modelList = new BLL.UserAccount().DataTableToList(dt);
  59. var obj = new
  60. {
  61. rows = modelList.Select(x => new
  62. {
  63. F_UserId = x.F_UserId,
  64. F_UserCode = x.F_UserCode,
  65. F_ExtensionNumber = x.F_ExtensionNumber,
  66. F_UserName = x.F_UserName,
  67. F_GroupName = x.F_GroupName,
  68. F_DeptId = x.F_DeptId,
  69. F_RoleId = x.F_RoleId,
  70. F_GroupId = x.F_GroupId,
  71. F_SeatFlag = x.F_SeatFlag,
  72. F_SeatRight = x.F_SeatRight,
  73. F_SeatLevel = x.F_SeatLevel,
  74. F_SexFlag = x.F_SexFlag,
  75. F_RemindFlag = x.F_RemindFlag,
  76. F_Remark = x.F_Remark,
  77. F_Telephone = x.F_Telephone,
  78. F_Mobile = x.F_Mobile,
  79. F_HomePhone = x.F_HomePhone,
  80. F_Birthday = x.F_Birthday,
  81. F_CreateOn = x.F_CreateOn,
  82. F_CancelOn = x.F_CancelOn,
  83. F_DeleteFlag = x.F_DeleteFlag,
  84. F_APPOnFlag = x.F_APPOnFlag,
  85. F_LastActiveTime = x.F_LastActiveTime,
  86. F_See = x.F_See,
  87. F_HJType = x.F_HJType,
  88. F_PId = x.F_PId,
  89. F_TmId = x.F_TmId,
  90. F_RoleName = x.F_RoleName,
  91. F_DeptName = x.F_DeptName,
  92. F_WorkNumber = x.F_WorkNumber,
  93. //F_WXNo=x.F_WXNo,
  94. F_SeatGroup = x.F_SeartGroup
  95. }),
  96. total = recordCount
  97. };
  98. res = Content(obj.ToJson());
  99. dt.Clear();
  100. dt.Dispose();
  101. }
  102. return res;
  103. }
  104. //[Authority]
  105. //获取用户信息
  106. public ActionResult GetUser(int userId = 0, string userCode = "")
  107. {
  108. ActionResult res = NoToken("未知错误,请重新登录");
  109. if (Request.IsAuthenticated)
  110. {
  111. string sql = "";
  112. if (userId > 0)
  113. {
  114. sql += " and F_UserId=" + userId;
  115. }
  116. if (!string.IsNullOrWhiteSpace(userCode))
  117. {
  118. sql += " and F_UserCode=" + userCode;
  119. }
  120. if (string.IsNullOrWhiteSpace(sql))
  121. return Error("获取失败");
  122. Model.T_Sys_UserAccount userModel = sysUserAccountBll.GetModelList(" 1=1 " + sql).FirstOrDefault();
  123. if (userModel == null) return Error("获取失败");
  124. var depModel = departmentBLL.GetModel(userModel.F_DeptId);
  125. var zxzModel = dicValueBLL.GetModel(userModel.F_GroupId ?? 0);
  126. res = Success("获取成功", new
  127. {
  128. F_UserId = userModel.F_UserId,
  129. F_UserCode = userModel.F_UserCode,
  130. F_ExtensionNumber = userModel.F_ExtensionNumber,
  131. F_UserName = userModel.F_UserName,
  132. F_DeptId = userModel.F_DeptId,
  133. F_RoleId = userModel.F_RoleId,
  134. F_GroupId = userModel.F_GroupId,
  135. F_SeatFlag = userModel.F_SeatFlag,
  136. F_SeatRight = userModel.F_SeatRight,
  137. F_SeatLevel = userModel.F_SeatLevel,
  138. F_SexFlag = userModel.F_SexFlag,
  139. F_RemindFlag = userModel.F_RemindFlag,
  140. F_Remark = userModel.F_Remark,
  141. F_Telephone = userModel.F_Telephone,
  142. F_Mobile = userModel.F_Mobile,
  143. F_HomePhone = userModel.F_HomePhone,
  144. F_Birthday = (userModel.F_Birthday!=null? userModel.F_Birthday.Value.ToString("yyyy-MM-dd"):""),
  145. F_CreateOn = userModel.F_CreateOn,
  146. F_CancelOn = userModel.F_CancelOn,
  147. F_DeleteFlag = userModel.F_DeleteFlag,
  148. F_APPOnFlag = userModel.F_APPOnFlag,
  149. F_LastActiveTime = userModel.F_LastActiveTime,
  150. F_See = userModel.F_See,
  151. F_HJType = userModel.F_HJType ?? 0,
  152. F_PId = userModel.F_PId,
  153. F_TmId = userModel.F_TmId,
  154. F_WorkNumber = userModel.F_WorkNumber,
  155. //F_WXNo = userModel.F_WXNo,
  156. F_SeatGroup=userModel.F_SeartGroup,
  157. zxzname = zxzModel?.F_Name ?? "",
  158. depname = depModel?.F_DeptName ?? ""
  159. });
  160. }
  161. return res;
  162. }
  163. //[Authority]
  164. //添加用户信息
  165. public ActionResult AddUsers(UserAccountInput input)
  166. {
  167. ActionResult res = NoToken("未知错误,请重新登录");
  168. if (Request.IsAuthenticated)
  169. {
  170. Model.T_Sys_UserAccount userAccountModel = new Model.T_Sys_UserAccount();
  171. if (input.Usercode != null)
  172. {
  173. userAccountModel.F_UserCode = input.Usercode.Trim();
  174. userAccountModel.F_WorkNumber = input.Usercode.Trim();
  175. }
  176. if (input.Username != null)
  177. userAccountModel.F_UserName = input.Username.Trim();
  178. if (input.Password != null)
  179. userAccountModel.F_Password = input.Password.Trim();
  180. if (input.Extno != null)
  181. userAccountModel.F_ExtensionNumber = input.Extno.Trim();
  182. if (input.DeptId != 0)
  183. userAccountModel.F_DeptId = input.DeptId;
  184. if (input.RoleId != 0)
  185. userAccountModel.F_RoleId = input.RoleId;
  186. //if (input.GroupId != 0)
  187. // userAccountModel.F_GroupId = input.GroupId;
  188. userAccountModel.F_SeatFlag = input.IsSeat;
  189. if (input.SearRight != null)
  190. userAccountModel.F_SeatRight = input.SearRight;
  191. if (input.Sex != null)
  192. userAccountModel.F_SexFlag = input.Sex;
  193. if (input.Remark != null)
  194. userAccountModel.F_Remark = input.Remark;
  195. if (input.Mobile != null)
  196. userAccountModel.F_Mobile = input.Mobile;
  197. if (input.Telphone != null)
  198. userAccountModel.F_Telephone = input.Telphone;
  199. if (input.Birth != null)
  200. userAccountModel.F_Birthday = input.Birth;
  201. userAccountModel.F_CreateOn = DateTime.Now;
  202. userAccountModel.F_DeleteFlag = 0;
  203. if (input.HjType != null)
  204. userAccountModel.F_HJType = input.HjType;
  205. //if (input.IsSeat)
  206. //{
  207. // userAccountModel.F_WXNo = input.WXNo.Trim();
  208. //}
  209. //if (input.SeartGroupID != 0)
  210. if (input.GroupId != 0)
  211. {
  212. userAccountModel.F_SeartGroupID = input.GroupId;
  213. Model.T_Sys_SeatGroup sm = new BLL.T_Sys_SeatGroup().GetModel(input.GroupId);
  214. if (sm != null)
  215. {
  216. userAccountModel.F_SeartGroup = sm.F_ZXZName;
  217. }
  218. }
  219. if (input.IsSeat)
  220. {
  221. SysConfigController sys = new SysConfigController();
  222. //话务人员限制权限判断
  223. if (sys.IsValidSeatPermission())
  224. {
  225. var model = sysUserAccountBll.GetModel(int.Parse(input.Usercode));
  226. if (model != null)
  227. return Error("当前员工工号存在,请更换!");
  228. if (sysUserAccountBll.Add(userAccountModel) > 0)
  229. res = Success("新增成功!");
  230. else
  231. res = Error("新增失败!");
  232. }
  233. else
  234. {
  235. res = Error("话务人员数量已超!");
  236. }
  237. }
  238. else {
  239. if (sysUserAccountBll.Add(userAccountModel) > 0)
  240. res = Success("新增成功!");
  241. else
  242. res = Error("新增失败!");
  243. }
  244. }
  245. return res;
  246. }
  247. // [Authority]
  248. //修改用户信息
  249. public ActionResult EditUsers(UserAccountInput input)
  250. {
  251. ActionResult res = NoToken("未知错误,请重新登录");
  252. if (Request.IsAuthenticated)
  253. {
  254. Model.T_Sys_UserAccount userAccountModel = sysUserAccountBll.GetModelList(" F_UserId = " + input.UserId).FirstOrDefault();
  255. if (userAccountModel == null)
  256. return Error("获取用户失败");
  257. if (input.Usercode != null)
  258. {
  259. userAccountModel.F_UserCode = input.Usercode.Trim();
  260. userAccountModel.F_WorkNumber = input.Usercode;
  261. }
  262. if (input.Username != null)
  263. userAccountModel.F_UserName = input.Username.Trim();
  264. if(input.Password!=null)
  265. userAccountModel.F_Password = input.Password.Trim();
  266. if (input.Extno != null)
  267. userAccountModel.F_ExtensionNumber = input.Extno.Trim();
  268. //if (input.WXNo != null)
  269. // userAccountModel.F_WXNo = input.WXNo.Trim();
  270. if (input.DeptId != 0)
  271. userAccountModel.F_DeptId = input.DeptId;
  272. if (input.RoleId != 0)
  273. userAccountModel.F_RoleId = input.RoleId;
  274. //if (input.GroupId != 0)
  275. // userAccountModel.F_GroupId = input.GroupId;
  276. userAccountModel.F_SeatFlag = input.IsSeat;
  277. if (input.SearRight != null)
  278. userAccountModel.F_SeatRight = input.SearRight;
  279. if (input.Sex != null)
  280. userAccountModel.F_SexFlag = input.Sex;
  281. if (input.Remark != null)
  282. userAccountModel.F_Remark = input.Remark;
  283. if (input.Mobile != null)
  284. userAccountModel.F_Mobile = input.Mobile;
  285. if (input.Telphone != null)
  286. userAccountModel.F_Telephone = input.Telphone;
  287. if (input.Birth != null)
  288. userAccountModel.F_Birthday = input.Birth;
  289. //userAccountModel.F_CreateOn = DateTime.Now;
  290. //if (input.SeartGroupID != 0)
  291. if (input.GroupId != 0)
  292. {
  293. userAccountModel.F_SeartGroupID = input.GroupId;
  294. Model.T_Sys_SeatGroup sm = new BLL.T_Sys_SeatGroup().GetModel(input.GroupId);
  295. if (sm != null)
  296. {
  297. userAccountModel.F_SeartGroup = sm.F_ZXZName;
  298. }
  299. }
  300. userAccountModel.F_DeleteFlag = 0;
  301. if (input.HjType != null)
  302. userAccountModel.F_HJType = input.HjType;
  303. if (input.IsSeat)
  304. {
  305. SysConfigController sys = new SysConfigController();
  306. //话务人员限制权限判断
  307. if (sys.IsValidSeatPermission())
  308. {
  309. if (sysUserAccountBll.Update(userAccountModel))
  310. res = Success("编辑成功!");
  311. else
  312. res = Error("编辑失败!");
  313. }
  314. else
  315. {
  316. res = Error("话务人员数量已超!");
  317. }
  318. }
  319. else
  320. {
  321. if (sysUserAccountBll.Update(userAccountModel))
  322. res = Success("编辑成功!");
  323. else
  324. res = Error("编辑失败!");
  325. }
  326. }
  327. return res;
  328. }
  329. //[Authority]
  330. //删除/禁用/启用 用户
  331. [Authority]
  332. public ActionResult DelUsers(string[] ids, int state = 0)
  333. {
  334. //ActionResult res = NoToken("未知错误,请重新登录");
  335. //if (Request.IsAuthenticated)
  336. //{
  337. if (ids == null || ids.Length <= 0)
  338. return Error("请选择用户");
  339. var idStr = string.Join(",", ids);
  340. if (string.IsNullOrEmpty(idStr))
  341. return Error("请选择用户");
  342. SysConfigController sys = new SysConfigController();
  343. if (state == 0)
  344. {
  345. //话务人员限制权限判断
  346. if (sys.IsValidSeatPermission())
  347. {
  348. if (sysUserAccountBll.DeleteList(idStr, state))
  349. return Success("设置成功");
  350. else
  351. return Error("设置失败");
  352. }
  353. return Error("话务人员数量已超!");
  354. }
  355. if (sysUserAccountBll.DeleteList(idStr, state))
  356. return Success("设置成功");
  357. else
  358. return Error("设置失败");
  359. //}
  360. //return res;
  361. }
  362. //[Authority]
  363. //删除用户
  364. public ActionResult DeleteUsers(string[] ids)
  365. {
  366. ActionResult res = NoToken("未知错误,请重新登录");
  367. if (Request.IsAuthenticated)
  368. {
  369. if (ids == null || ids.Length <= 0)
  370. return Error("请选择用户");
  371. var idStr = string.Join(",", ids);
  372. if (string.IsNullOrEmpty(idStr))
  373. return Error("请选择用户");
  374. if (sysUserAccountBll.DeleteList(idStr))
  375. res = Success("删除成功");
  376. else
  377. res = Error("删除失败");
  378. }
  379. return res;
  380. }
  381. //获取坐席列表
  382. public ActionResult GetSeatList()
  383. {
  384. ActionResult res = NoToken("未知错误,请重新登录");
  385. if (Request.IsAuthenticated)
  386. {
  387. string sql = " f_seatflag=1 ";
  388. int roleid = CurrentUser.UserData.F_RoleId;
  389. int deptid = CurrentUser.UserData.F_DeptId;
  390. if (roleid != 0)
  391. {
  392. if (roleid != 17)
  393. {
  394. if (deptid != 0)
  395. sql += " and F_DeptId=" + deptid;
  396. }
  397. }
  398. List<Model.T_Sys_UserAccount> userSeartList = sysUserAccountBll.GetModelList(sql + " order by f_userid desc ");
  399. if (userSeartList.Count > 0)
  400. res = Success("列表加载成功", userSeartList);
  401. else
  402. res = Error("列表加载失败");
  403. }
  404. return res;
  405. }
  406. //根据部门获取用户
  407. public ActionResult GetDeptUserList(int deptid = 0)
  408. {
  409. ActionResult res = NoToken("未知错误,请重新登录");
  410. if (Request.IsAuthenticated)
  411. {
  412. List<Model.T_Sys_UserAccount> DeptUserList = sysUserAccountBll.GetModelList("F_DeptId='" + deptid + "' order by f_userid desc ");
  413. res = Success("列表加载成功", DeptUserList);
  414. }
  415. return res;
  416. }
  417. //获取当前用户信息
  418. public ActionResult GetNowUser()
  419. {
  420. ActionResult res = NoToken("未知错误,请重新登录");
  421. if (Request.IsAuthenticated)
  422. {
  423. Model.T_Sys_UserAccount userModel = sysUserAccountBll.GetModel(CurrentUser.UserData.F_UserId);
  424. if (userModel == null)
  425. return Error("获取失败");
  426. Model.T_Sys_RoleInfo roleModel = new BLL.T_Sys_RoleInfo().GetModel(userModel.F_RoleId);
  427. var obj = new
  428. {
  429. user = userModel,
  430. role = roleModel
  431. };
  432. res = Success("获取成功", obj);
  433. }
  434. return res;
  435. }
  436. // [Authority]
  437. /// <summary>
  438. /// 重置密码
  439. /// </summary>
  440. /// <param name="usercode"></param>
  441. /// <param name="pwd"></param>
  442. /// <returns></returns>
  443. public ActionResult ResetPwd(string usercode = "", string pwd = "")
  444. {
  445. var res = NoToken("未知错误,请重新登录");
  446. if (Request.IsAuthenticated)
  447. {
  448. if (string.IsNullOrWhiteSpace(pwd))
  449. return Error("请输入密码");
  450. var model = sysUserAccountBll.GetModel(usercode);
  451. if (model == null) return Error("此用户不存在");
  452. model.F_Password = pwd;
  453. if (sysUserAccountBll.Update(model))
  454. res = Success("重置密码成功");
  455. else
  456. res = Error("重置密码失败");
  457. }
  458. return res;
  459. }
  460. public ActionResult UpdatePwd(string usercode = "", string pwd = "", string oldPwd = "", string mobile = "")
  461. {
  462. var res = NoToken("未知错误,请重新登录");
  463. if (Request.IsAuthenticated)
  464. {
  465. if (string.IsNullOrWhiteSpace(pwd))
  466. return Error("请输入密码");
  467. if (string.IsNullOrWhiteSpace(usercode))
  468. return Error("账号错误");
  469. var model = sysUserAccountBll.GetModel(int.Parse(usercode));
  470. if (model == null) return Error("此用户不存在");
  471. if (!model.F_Password.Equals(oldPwd)) return Error("原密码不正确");
  472. model.F_Password = pwd;
  473. if (!string.IsNullOrWhiteSpace(mobile))
  474. model.F_Mobile = mobile;
  475. if (sysUserAccountBll.Update(model))
  476. res = Success("重置密码成功");
  477. else
  478. res = Error("重置密码失败");
  479. }
  480. return res;
  481. }
  482. /// <summary>
  483. /// 批量修改坐席的坐席组ID
  484. /// </summary>
  485. /// <param name="userids"></param>
  486. /// <param name="sgid"></param>
  487. /// <returns></returns>
  488. public ActionResult UpdateSeatGroup(string[] userids, string sgid)
  489. {
  490. if (userids == null || userids.Length <= 0)
  491. return Error("请选择要修改的坐席");
  492. var idStr = string.Join(",", userids);
  493. if (string.IsNullOrEmpty(idStr.Trim()))
  494. return Error("请选择要修改的坐席");
  495. Model.T_Sys_SeatGroup sgModel = new BLL.T_Sys_SeatGroup().GetModel(int.Parse(sgid));
  496. string sgname = sgModel != null ? sgModel.F_ZXZName : "";
  497. var res=sysUserAccountBll.UpdateSeatGroup(idStr, sgid, sgname);
  498. if(res)
  499. {
  500. return Success("修改坐席组成功");
  501. }
  502. return Error("修改坐席组失败!");
  503. }
  504. //根据工号获取坐席组号
  505. //public ActionResult GetSeatGroup(string worknum)
  506. //{
  507. // ActionResult res = NoToken("未知错误,请重新登录");
  508. // if (Request.IsAuthenticated)
  509. // {
  510. // string strwhere = "";
  511. // if (worknum != "")
  512. // {
  513. // strwhere = " F_WorkNumber='" + worknum + "'";
  514. // }
  515. // string setgroup = sysUserAccountBll.GetGroup(strwhere);
  516. // res = Success("坐席组号获取成功", setgroup);
  517. // }
  518. // return res;
  519. //}
  520. }
  521. }