From a7ceaaa38a4394b82501ca60230e97d25a6871e3 Mon Sep 17 00:00:00 2001 From: wangxinhui <wangxinhui@hnkhzn.com> Date: 星期六, 18 一月 2025 17:30:33 +0800 Subject: [PATCH] 1 --- 代码管理/WMS/WIDESEA_WMSServer/WIDESEA_SystemService/Sys_UserService.cs | 90 ++++++++++++++++++++++++++++++++++++++++++--- 1 files changed, 84 insertions(+), 6 deletions(-) diff --git "a/\344\273\243\347\240\201\347\256\241\347\220\206/WMS/WIDESEA_WMSServer/WIDESEA_SystemService/Sys_UserService.cs" "b/\344\273\243\347\240\201\347\256\241\347\220\206/WMS/WIDESEA_WMSServer/WIDESEA_SystemService/Sys_UserService.cs" index 11f2d94..b71f4e9 100644 --- "a/\344\273\243\347\240\201\347\256\241\347\220\206/WMS/WIDESEA_WMSServer/WIDESEA_SystemService/Sys_UserService.cs" +++ "b/\344\273\243\347\240\201\347\256\241\347\220\206/WMS/WIDESEA_WMSServer/WIDESEA_SystemService/Sys_UserService.cs" @@ -13,6 +13,13 @@ using WIDESEA_Core.Caches; using SqlSugar; using ICacheService = WIDESEA_Core.Caches.ICacheService; +using HslCommunication.WebSocket; +using System.Drawing.Drawing2D; +using System.Linq; +using MailKit.Search; +using OrderByType = SqlSugar.OrderByType; +using System.Drawing.Printing; +using WIDESEA_Core.HostedService; namespace WIDESEA_SystemService { @@ -21,14 +28,16 @@ private readonly IUnitOfWorkManage _unitOfWorkManage; private readonly ICacheService _cacheService; private readonly ISys_MenuService _menuService; + private readonly ISys_RoleService _roleService; public ISys_UserRepository Repository => BaseDal; - public Sys_UserService(ISys_UserRepository repository, IUnitOfWorkManage unitOfWorkManage, ICacheService cacheService, ISys_MenuService menuService) : base(repository) + public Sys_UserService(ISys_UserRepository repository, IUnitOfWorkManage unitOfWorkManage, ICacheService cacheService, ISys_MenuService menuService, ISys_RoleService roleService) : base(repository) { _unitOfWorkManage = unitOfWorkManage; _cacheService = cacheService; _menuService = menuService; + _roleService = roleService; } public WebResponseContent Login(LoginInfo loginInfo) @@ -71,10 +80,12 @@ UserName = user.UserName, TenantId = user.TenantId, }); + App.User.UpdateToke(token, user.UserId); - _cacheService.AddOrUpdate(user.UserId.ToString(), token); + if (PermissionDataHostService.UserRoles.FirstOrDefault(x => x.UserId == user.UserId) == null) + PermissionDataHostService.UserRoles.AddRange(PermissionDataHostService.GetUserRoles(Db, user.UserId)); - content = WebResponseContent.Instance.OK(data: new { token, userName = user.UserTrueName, img = user.HeadImageUrl }); + content = WebResponseContent.Instance.OK(data: new { token, userName = user.UserName, img = user.HeadImageUrl, user.UserTrueName }); } else { @@ -102,6 +113,40 @@ return base.UpdateData(saveModel); } + public override PageGridData<Sys_User> GetPageData(PageDataOptions options) + { + int roleId = -1; + //鏍戝舰鑿滃崟浼犳煡璇㈣鑹蹭笅鎵�鏈夌敤鎴� + if (options.Value != null) + { + roleId = options.Value.ObjToInt(); + } + + if (roleId <= 0) + { + if (App.User.IsHighestRole) return base.GetPageData(options); + roleId = App.User.RoleId; + } + int totalCount = 0; + List<int> roleIds = _roleService.GetAllChildrenRoleId(roleId).Where(x => x != roleId).ToList(); + ISugarQueryable<Sys_User> sugarQueryable = Db.Queryable<Sys_User>(); + ValidatePageOptions(options, TProperties, ref sugarQueryable); + + Dictionary<string, OrderByType> orderbyDic = options.GetPageDataSort(TProperties); + List<OrderByModel> orderByModels = new List<OrderByModel>(); + foreach (var item in orderbyDic) + { + OrderByModel orderByModel = new OrderByModel() + { + FieldName = item.Key, + OrderByType = item.Value + }; + orderByModels.Add(orderByModel); + } + List<Sys_User> users = sugarQueryable.Where(x => roleIds.Contains(x.RoleId) || x.UserId == App.User.UserId).OrderBy(orderByModels).ToPageList(options.Page, options.Rows, ref totalCount); + return new PageGridData<Sys_User> { Rows = users, Total = totalCount }; + } + public override WebResponseContent AddData(SaveModel saveModel) { string pwd = "123456"; @@ -125,7 +170,7 @@ /// <returns></returns> public WebResponseContent GetCurrentUserInfo() { - var data = BaseDal.QueryFirst(x => x.User_Id == App.User.UserId, s => new + var data = BaseDal.QueryFirst(x => x.UserId == App.User.UserId, s => new { s.UserName, s.UserTrueName, @@ -159,7 +204,7 @@ if (newPwd.Length < 6) return WebResponseContent.Instance.Error("瀵嗙爜涓嶈兘灏戜簬6浣�"); int userId = App.User.UserId; - string userCurrentPwd = BaseDal.QueryFirst(x => x.User_Id == userId, s => s.UserPwd); + string userCurrentPwd = BaseDal.QueryFirst(x => x.UserId == userId, s => s.UserPwd); string _oldPwd = oldPwd.EncryptDES(AppSecret.User); if (_oldPwd != userCurrentPwd) return WebResponseContent.Instance.Error("鏃у瘑鐮佷笉姝g‘"); @@ -170,7 +215,7 @@ BaseDal.UpdateData(new Sys_User { - User_Id = userId, + UserId = userId, UserPwd = _newPwd, LastModifyPwdDate = DateTime.Now }, new List<string> @@ -188,5 +233,38 @@ } return content; } + public WebResponseContent ModifyUserPwd(string password, string userName) + { + WebResponseContent content = new WebResponseContent(); + string message = ""; + password = password?.Trim(); + try + { + if (string.IsNullOrEmpty(password)) return WebResponseContent.Instance.Error("瀵嗙爜涓嶈兘涓虹┖"); + //鑾峰彇鐢ㄦ埛 + Sys_User user = BaseDal.QueryFirst(x => x.UserName == userName); + if (user == null) return WebResponseContent.Instance.Error("鐢ㄦ埛涓嶅瓨鍦�"); + user.UserPwd = password.EncryptDES(AppSecret.User); + BaseDal.UpdateData(user); + if (App.User.UserId == user.UserId) + { + string token = JwtHelper.IssueJwt(new TokenModelJwt() + { + UserId = user.UserId, + RoleId = user.RoleId, + UserName = user.UserName, + TenantId = user.TenantId, + }); + _cacheService.AddOrUpdate(user.UserId.ToString(), token); + } + return content.OK("鏇存敼鎴愬姛"); + } + catch (Exception ex) + { + message = ex.Message; + content.Error("鏈嶅姟鍣ㄤ簡鐐归棶棰�,璇风◢鍚庡啀璇�"); + } + return content; + } } } -- Gitblit v1.9.3