PingAnYeXianSZCG_API 接口代码

UserAccountController.cs 21KB

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