|  |  |  | 
|---|
|  |  |  | 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 | 
|---|
|  |  |  | { | 
|---|
|  |  |  | 
|---|
|  |  |  | 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) | 
|---|
|  |  |  | 
|---|
|  |  |  | 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.UserName, img = user.HeadImageUrl }); | 
|---|
|  |  |  | content = WebResponseContent.Instance.OK(data: new { token, userName = user.UserName, img = user.HeadImageUrl, user.UserTrueName }); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | else | 
|---|
|  |  |  | { | 
|---|
|  |  |  | 
|---|
|  |  |  | }; | 
|---|
|  |  |  | }; | 
|---|
|  |  |  | 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) | 
|---|
|  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 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; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|