From b1ccdb760b9c16200831a2617caf9318b1be86b3 Mon Sep 17 00:00:00 2001 From: hwh <332078369@qq.com> Date: 星期四, 27 六月 2024 08:11:09 +0800 Subject: [PATCH] 重构用户管理 --- Wms/Wms/Controllers/BasisController.cs | 279 +++++++++++++------------------------------------------ 1 files changed, 66 insertions(+), 213 deletions(-) diff --git a/Wms/Wms/Controllers/BasisController.cs b/Wms/Wms/Controllers/BasisController.cs index 41d72d9..7980ce4 100644 --- a/Wms/Wms/Controllers/BasisController.cs +++ b/Wms/Wms/Controllers/BasisController.cs @@ -20,6 +20,7 @@ using System.Security.Cryptography; using System.Data; using Model.ModelDto.LogDto; +using Utility; namespace Wms.Controllers { @@ -44,6 +45,7 @@ private readonly IFunSettingServer _setting; //鍔熻兘璁惧畾 private readonly IInterfaceServer _interface;//鎺ュ彛绠$悊 private readonly IOperationSysServer _operation; //鎿嶄綔鏃ュ織 + private readonly UserManager _userManager; /// <summary> /// 鏋勯�犲嚱鏁� /// </summary> @@ -58,7 +60,7 @@ /// <param name="department">閮ㄩ棬</param> /// <param name="setting">鍔熻兘璁惧畾</param> /// <param name="operation">鎿嶄綔鏃ュ織</param> - public BasisController(ICustomerServer customerSvc, ILogisticsInfoServer logisticsSvc, IUserInforServer userInforServer, IRolesServer rolesServer, IRoleRightServer roleRightServer, IRBACServer rBACServer, IUnitServer unitSvc, IPackagServer packagServer, IMaterialsServer mate, IDepartmentServer department, IFunSettingServer setting, IInterfaceServer interfaceS, IOperationSysServer operation) + public BasisController(ICustomerServer customerSvc, ILogisticsInfoServer logisticsSvc, IUserInforServer userInforServer, IRolesServer rolesServer, IRoleRightServer roleRightServer, IRBACServer rBACServer, IUnitServer unitSvc, IPackagServer packagServer, IMaterialsServer mate, IDepartmentServer department, IFunSettingServer setting, IInterfaceServer interfaceS, IOperationSysServer operation, UserManager userManager) { _customerSvc = customerSvc;//瀹㈡埛Svc _logisticsSvc = logisticsSvc;//鐗╂祦Svc @@ -73,6 +75,7 @@ _setting = setting; //鍔熻兘璁惧畾 _interface = interfaceS;//鎺ュ彛绠$悊 _operation = operation; //鎿嶄綔鏃ュ織 + _userManager = userManager; } //鍩烘湰淇℃伅绠$悊 @@ -89,15 +92,10 @@ /// <param name="Status">鐘舵��</param> /// <returns></returns> [HttpGet] - public IActionResult GetUserRoleList(string UserName, string DepartmentNo, string RoleNo, string Status) + [ServiceFilter(typeof(ApiResponseActionFilter))] + public async Task<List<UserInfoDto>> GetUserRoleList(string UserName, string DepartmentNo, string RoleNo, string Status) { - List<UserInfoDto> userdtolist = _userInforServer.GetUserRoleList(UserName, DepartmentNo, RoleNo, Status); - return Ok(new - { - data = userdtolist, - code = 0, - mes = "鎴愬姛" - }); + return await _userInforServer.GetUserRoleList(UserName, DepartmentNo, RoleNo, Status); } /// <summary> @@ -106,15 +104,10 @@ /// <param name="id">鐢ㄦ埛id</param> /// <returns></returns> [HttpGet] - public IActionResult GetUserinfoListById(int id) + [ServiceFilter(typeof(ApiResponseActionFilter))] + public async Task<SysUserInfor> GetUserinfoListById(int id) { - SysUserInfor userinfo = _userInforServer.GetUserInfoById(id); - return Ok(new - { - data = userinfo, - code = 0, - msg = "鎴愬姛" - }); + return await _userInforServer.GetUserInfoById(id); } @@ -125,38 +118,13 @@ /// <returns></returns> /// <exception cref="System.Exception">鎹曡幏寮傚父</exception> [HttpPost] - public async Task<IActionResult> InsertUserinfo(UserInfoDto UserInfoDto) + [ServiceFilter(typeof(ApiResponseActionFilter))] + public async Task InsertUserinfo(UserInfoDto UserInfoDto) { - //鎹曡幏寮傚父 - try - { - //鑾峰彇褰撳墠鎿嶄綔鐢ㄦ埛id - var claimsIdentity = this.User.Identity as ClaimsIdentity; - var userId = claimsIdentity.FindFirst(ClaimTypes.Name)?.Value; - int uid = Convert.ToInt32(userId); - UserInfoDto.CreateUser = uid; - int i = await _userInforServer.InsertUserInfo(UserInfoDto); + UserInfoDto.CreateUser = _userManager.UserId; + await _userInforServer.InsertUserInfo(UserInfoDto); + await _operation.InsertOperation("绯荤粺璁剧疆", "鐢ㄦ埛绠$悊", UserInfoDto.UserNo, "娣诲姞", "娣诲姞鐢ㄦ埛淇℃伅 鐢ㄦ埛鍙凤細" + UserInfoDto.UserNo, _userManager.UserId); - //鍒ゆ柇鏄惁鏂板鎴愬姛 - if (i == 0) - { - return Ok(new { data = i, code = 1, msg = "鏂板澶辫触" }); - } - else if (i == 3) - { - return Ok(new { data = i, code = 3, msg = "鐢ㄦ埛鍚嶆垨鐧诲綍鍚嶉噸澶�" }); - } - else - { - await _operation.InsertOperation("绯荤粺璁剧疆", "鐢ㄦ埛绠$悊", UserInfoDto.UserNo, "娣诲姞", "娣诲姞鐢ㄦ埛淇℃伅 鐢ㄦ埛鍙凤細" + UserInfoDto.UserNo, uid); - return Ok(new { data = i, code = 0, msg = "鏂板鎴愬姛" }); - } - } - catch (System.Exception ex) - { - //鎶涘嚭寮傚父 - throw new System.Exception("鏂板鐢ㄦ埛寮傚父", ex); - } } @@ -167,34 +135,13 @@ /// <returns></returns> /// <exception cref="System.Exception">寮傚父</exception> [HttpGet] - public async Task<IActionResult> DeleteUserInfo(int userids) + [ServiceFilter(typeof(ApiResponseActionFilter))] + public async Task DeleteUserInfo(int userids) { - //寮傚父 - try - { - //鑾峰彇鐢ㄦ埛淇℃伅 - SysUserInfor user = _userInforServer.GetUserInfoById(userids); - //鑾峰彇褰撳墠鎿嶄綔鐢ㄦ埛id - var claimsIdentity = this.User.Identity as ClaimsIdentity; - var userId = claimsIdentity.FindFirst(ClaimTypes.Name)?.Value; - int uid = Convert.ToInt32(userId); - int i = await _userInforServer.DeleteUserinfo(user); - //鍒ゆ柇鏄惁鍒犻櫎鎴愬姛 - if (i == 0) - { - return Ok(new { data = i, code = 1, msg = "鍒犻櫎澶辫触" }); - } - else - { - await _operation.InsertOperation("绯荤粺璁剧疆", "鐢ㄦ埛绠$悊", user.UserNo, "鍒犻櫎", "鍒犻櫎鐢ㄦ埛淇℃伅 鐢ㄦ埛鍙凤細" + user.UserNo, uid); - return Ok(new { data = i, code = 0, msg = "鍒犻櫎鎴愬姛" }); - } - } - catch (System.Exception ex) - { - //鎶涘嚭寮傚父 - throw new System.Exception("鍒犻櫎鐢ㄦ埛淇℃伅寮傚父", ex); - } + //鑾峰彇鐢ㄦ埛淇℃伅 + SysUserInfor user = await _userInforServer.GetUserInfoById(userids); + await _userInforServer.DeleteUserinfo(user); + await _operation.InsertOperation("绯荤粺璁剧疆", "鐢ㄦ埛绠$悊", user.UserNo, "鍒犻櫎", "鍒犻櫎鐢ㄦ埛淇℃伅 鐢ㄦ埛鍙凤細" + user.UserNo, _userManager.UserId); } @@ -205,41 +152,13 @@ /// <returns></returns> /// <exception cref="System.Exception">鎹曡幏寮傚父</exception> [HttpPost] - public async Task<IActionResult> UpdateUserinfo(UserInfoDto userdto) + [ServiceFilter(typeof(ApiResponseActionFilter))] + public async Task UpdateUserinfo(UserInfoDto userdto) { - //鎹曡幏寮傚父 - try - { - //鑾峰彇褰撳墠鎿嶄綔鐢ㄦ埛id - var claimsIdentity = this.User.Identity as ClaimsIdentity; - var userId = claimsIdentity.FindFirst(ClaimTypes.Name)?.Value; - int uid = Convert.ToInt32(userId); - //userdto.UpdateUser = Convert.ToInt32(userId); - //鏇存敼浜� - userdto.UpdateUser = uid; + userdto.UpdateUser = _userManager.UserId; + await _userInforServer.UpdateUserinfo(userdto); + await _operation.InsertOperation("绯荤粺璁剧疆", "鐢ㄦ埛绠$悊", userdto.UserNo, "淇敼", "淇敼鐢ㄦ埛淇℃伅 鐢ㄦ埛鍙凤細" + userdto.UserNo, _userManager.UserId); - //缂栬緫鐢ㄦ埛淇℃伅 - int i = await _userInforServer.UpdateUserinfo(userdto); - //鍒ゆ柇鏄惁缂栬緫鎴愬姛 - if (i == 0) - { - return Ok(new { data = i, code = 1, msg = "缂栬緫澶辫触" }); - } - else if (i == 3) - { - return Ok(new { data = i, code = 1, msg = "鐢ㄦ埛鍚嶆垨鐧诲綍鍚嶉噸澶�" }); - } - else - { - await _operation.InsertOperation("绯荤粺璁剧疆", "鐢ㄦ埛绠$悊", userdto.UserNo, "淇敼", "淇敼鐢ㄦ埛淇℃伅 鐢ㄦ埛鍙凤細" + userdto.UserNo, uid); - return Ok(new { data = i, code = 0, msg = "缂栬緫鎴愬姛" }); - } - } - catch (System.Exception ex) - { - //鎶涘嚭寮傚父 - throw new System.Exception("缂栬緫鐢ㄦ埛淇℃伅寮傚父", ex); - } } @@ -252,26 +171,21 @@ /// </summary> /// <param name="PassWord">鐢ㄦ埛鍘熷瘑鐮�</param> /// <returns></returns> - [HttpGet] - public int GetUserUptPassById(string PassWord, int userId) - { - ////鑾峰彇褰撳墠鎿嶄綔鐢ㄦ埛id - //var claimsIdentity = this.User.Identity as ClaimsIdentity; - //var userId = claimsIdentity.FindFirst(ClaimTypes.Name)?.Value; - //int uid = Convert.ToInt32(userId); - - //鏍规嵁鐢ㄦ埛id鑾峰彇鐢ㄦ埛瀵嗙爜 - SysUserInfor user = _userInforServer.GetUserInfoById(userId); - //鍒ゆ柇鍘熷瘑鐮佹槸鍚︽纭� - if (user.PassWord == PassWord) - { - return 1; - } - else - { - return 0; - } - } + //[HttpGet] + //public async int GetUserUptPassById(string PassWord, int userId) + //{ + // //鏍规嵁鐢ㄦ埛id鑾峰彇鐢ㄦ埛瀵嗙爜 + // SysUserInfor user = await _userInforServer.GetUserInfoById(userId); + // //鍒ゆ柇鍘熷瘑鐮佹槸鍚︽纭� + // if (user.PassWord == PassWord) + // { + // return 1; + // } + // else + // { + // return 0; + // } + //} ///// <param name="userId">鐢ㄦ埛id</param> /// <summary> @@ -283,69 +197,28 @@ /// <returns></returns> /// <exception cref="Exception">鎹曡幏寮傚父</exception> [HttpGet] - public async Task<IActionResult> UptUserPassWord(string pwdOld, string pwdNew, string pwdNewTwo/*, int userId*/) + [ServiceFilter(typeof(ApiResponseActionFilter))] + public async Task UptUserPassWord(string pwdOld, string pwdNew, string pwdNewTwo/*, int userId*/) { - //鎹曡幏寮傚父 - try + pwdOld = Md5Tools.CalcMd5(pwdOld); + pwdNew = Md5Tools.CalcMd5(pwdNew); + pwdNewTwo = Md5Tools.CalcMd5(pwdNewTwo); + //鑾峰彇褰撳墠鎿嶄綔鐢ㄦ埛id + SysUserInfor user = await _userInforServer.GetUserInfoById(_userManager.UserId); + if (user == null) { - pwdOld = Md5Tools.CalcMd5(pwdOld); - pwdNew = Md5Tools.CalcMd5(pwdNew); - pwdNewTwo = Md5Tools.CalcMd5(pwdNewTwo); - //鑾峰彇褰撳墠鎿嶄綔鐢ㄦ埛id - var claimsIdentity = this.User.Identity as ClaimsIdentity; - var userId = claimsIdentity.FindFirst(ClaimTypes.Name)?.Value; - int uid = Convert.ToInt32(userId); - //鍒ゆ柇鍘熷瘑鐮佹槸鍚︽纭� - int a = GetUserUptPassById(pwdOld, uid); - if (a == 1) - { - //淇敼瀵嗙爜 - int i = await _userInforServer.UptUserPassWord(pwdOld, pwdNew, pwdNewTwo, uid); - if (i == 0) - { - return Ok(new - { - data = i, - code = 1, - msg = "淇敼澶辫触" - }); - } - //鍒ゆ柇涓ゆ鏂板瘑鐮佹槸鍚︿竴鑷� - else if (i == 3) - { - return Ok(new - { - data = i, - code = 0, - msg = "淇敼鎴愬姛 璇烽噸鏂扮櫥褰�" - }); - } - else - { - return Ok(new - { - data = i, - code = 0, - msg = "淇敼鎴愬姛 璇烽噸鏂扮櫥褰�" - }); - } - } - else - { - //閿欒 - return Ok(new - { - data = a, - code = 1, - msg = "鍘熷瘑鐮佷笉姝g‘" - }); - } - + throw Oops.Bah("鎵句笉鍒扮敤鎴蜂俊鎭�"); } - catch (Exception ex) + if (user.PassWord != pwdOld) { - //鎶涘嚭寮傚父 - throw new Exception("淇敼瀵嗙爜寮傚父", ex); + throw Oops.Bah("鍘熷瘑鐮佷笉姝g‘"); + } + else + { + //淇敼瀵嗙爜 + int i = await _userInforServer.UptUserPassWord(pwdNew, _userManager.UserId); + if (i <= 0) + throw Oops.Bah("淇敼瀵嗙爜澶辫触"); } } /// <summary> @@ -353,30 +226,10 @@ /// </summary> /// <returns></returns> [HttpGet] - public IActionResult IsPassWordTime() + [ServiceFilter(typeof(ApiResponseActionFilter))] + public async Task<int> IsPassWordTime() { - //鎹曡幏寮傚父 - try - { - //鑾峰彇褰撳墠鎿嶄綔鐢ㄦ埛id - var claimsIdentity = this.User.Identity as ClaimsIdentity; - var userId = claimsIdentity.FindFirst(ClaimTypes.Name)?.Value; - int uid = Convert.ToInt32(userId); - //鍒ゆ柇鍘熷瘑鐮佹槸鍚︽纭� - int a = _userInforServer.IsPassWordTime(uid); - return Ok(new - { - data = a, - code = 0, - msg = "淇敼澶辫触" - }); - - } - catch (Exception ex) - { - //鎶涘嚭寮傚父 - throw new Exception("淇敼瀵嗙爜寮傚父", ex); - } + return await _userInforServer.IsPassWordTime(_userManager.UserId); } #endregion @@ -1283,7 +1136,7 @@ matedto.CreateUser = uid; //鏂板 int i = await _mate.AddMate(matedto); - + await _operation.InsertOperation("鍩虹淇℃伅", "鐗╂枡绠$悊", matedto.SkuNo, "娣诲姞", "娣诲姞鐗╂枡淇℃伅 鐗╂枡鍙凤細" + matedto.SkuNo, uid); return Ok(new { data = i, code = 0, msg = "鎴愬姛" }); @@ -1291,7 +1144,7 @@ catch (Exception ex) { //鎶涘嚭寮傚父 - return Ok(new { code = 1, msg = "鏂板鐗╂枡寮傚父"+ ex.Message }); + return Ok(new { code = 1, msg = "鏂板鐗╂枡寮傚父" + ex.Message }); } } @@ -1385,7 +1238,7 @@ catch (Exception ex) { //鎶涘嚭寮� - return Ok(new { code = 1, msg = "缂栬緫鐗╂枡寮傚父"+ex.Message }); + return Ok(new { code = 1, msg = "缂栬緫鐗╂枡寮傚父" + ex.Message }); } } @@ -1612,7 +1465,7 @@ { try { - var bolls = _customerSvc.GetCustomerList(model.CustomerNo,model.CustomerName, model.Type, model.LinkMan, model.Phone, model.Page, model.Limit, out int count); + var bolls = _customerSvc.GetCustomerList(model.CustomerNo, model.CustomerName, model.Type, model.LinkMan, model.Phone, model.Page, model.Limit, out int count); return Ok(new { code = 0, count, msg = "瀹㈡埛淇℃伅", data = bolls }); } -- Gitblit v1.8.0