1
dengjunjie
2025-09-29 d9c99e0480b4910cdb134778dd5c314b35ec4cf2
ÏîÄ¿´úÂë/WMS/WIDESEA_WMSServer/WIDESEA_SystemService/Sys_UserService.cs
@@ -13,6 +13,8 @@
using WIDESEA_Core.Caches;
using SqlSugar;
using ICacheService = WIDESEA_Core.Caches.ICacheService;
using Newtonsoft.Json;
using WIDESEA_Core.HostedService;
namespace WIDESEA_SystemService
{
@@ -21,14 +23,16 @@
        private readonly IUnitOfWorkManage _unitOfWorkManage;
        private readonly ICacheService _cacheService;
        private readonly ISys_MenuService _menuService;
        private readonly ISys_RoleService _sys_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 sys_RoleService) : base(repository)
        {
            _unitOfWorkManage = unitOfWorkManage;
            _cacheService = cacheService;
            _menuService = menuService;
            _sys_RoleService = sys_RoleService;
        }
        public WebResponseContent Login(LoginInfo loginInfo)
@@ -37,8 +41,21 @@
            try
            {
                //BaseDal.QueryFirst(x => x.UserName == loginInfo.UserName);
                string msg = string.Empty;
                if (App.ExpDateTime != null)
                {
                    if ((DateTime.Now - App.ExpDateTime.GetValueOrDefault()).TotalSeconds > 0)
                        return WebResponseContent.Instance.Error("授权已到期,请联系管理员");
                    var span = App.ExpDateTime.GetValueOrDefault() - DateTime.Now;
                    var Days = span.TotalDays;
                    var Hours = span.TotalHours;
                    var Minutes = span.TotalMinutes;
                    var Seconds = span.TotalSeconds;
                    if (Minutes < 1) msg = $"系统将在 {Math.Ceiling(Seconds)} ç§’钟后到期,到期时间:{App.ExpDateTime.GetValueOrDefault():yyyy-MM-dd HH:mm:ss}。请联系管理员续期。";
                    else if (Hours < 1) msg = $"系统将在 {Math.Ceiling(Minutes)} åˆ†é’ŸåŽåˆ°æœŸï¼Œåˆ°æœŸæ—¶é—´ï¼š{App.ExpDateTime.GetValueOrDefault():yyyy-MM-dd HH:mm:ss}。请联系管理员续期。";
                    else if (Hours < 72) msg = $"系统将在 {Math.Ceiling(Hours)} å°æ—¶åŽåˆ°æœŸï¼Œåˆ°æœŸæ—¶é—´ï¼š{App.ExpDateTime.GetValueOrDefault():yyyy-MM-dd HH:mm:ss}。请联系管理员续期。";
                    else if (Days < 7) msg = $"系统将在 {Math.Ceiling(Days)} å¤©åŽåˆ°æœŸï¼Œåˆ°æœŸæ—¶é—´ï¼š{App.ExpDateTime.GetValueOrDefault():yyyy-MM-dd HH:mm:ss}。请联系管理员续期。";
                }
                #region ä¸´æ—¶ä½¿ç”¨
                try
@@ -74,7 +91,7 @@
                    _cacheService.AddOrUpdate(user.UserId.ToString(), token);
                    content = WebResponseContent.Instance.OK(data: new { token, userName = user.UserTrueName, img = user.HeadImageUrl });
                    content = WebResponseContent.Instance.OK(msg, data: new { token, userName = user.UserTrueName, img = user.HeadImageUrl });
                }
                else
                {
@@ -88,9 +105,48 @@
            return content;
        }
        public override PageGridData<Sys_User> GetPageData(PageDataOptions options)
        {
            var roleIds = _sys_RoleService.GetAllChildren(App.User.RoleId).Select(x => x.Id);
            PageGridData<Sys_User> pageGridData = new PageGridData<Sys_User>();
            //树形菜单传查询角色下所有用户
            if (App.User.IsSuperAdmin)
            {
                var GridData = base.GetPageData(options);
                pageGridData = new PageGridData<Sys_User>()
                {
                    Rows = options.Order?.ToLower() == "asc" ? GridData.Rows.OrderBy(x => x.Role_Id).ToList() : GridData.Rows,
                    Total = GridData.Total
                };
                return pageGridData;
            }
            string where = ValidatePageOptions(options);
            var a = BaseDal.Db.Queryable<Sys_User>().Where(x => roleIds.Contains(x.Role_Id)).Where(where);
            int total = 0;
            pageGridData = new PageGridData<Sys_User>()
            {
                Rows = BaseDal.Db.Queryable<Sys_User>().Where(x => roleIds.Contains(x.Role_Id)).Where(where).ToPageList(options.Page, options.Rows),
                Total = total
            };
            return pageGridData;
        }
        public override WebResponseContent UpdateData(SaveModel saveModel)
        {
            var User = JsonConvert.DeserializeObject<Sys_User>(GetCurrentUserInfo().Data.ToJson());
            #region åªèƒ½ä¿®æ”¹æ¯”当前用户角色等级低的用户
            int userId = saveModel.MainData[nameof(Sys_User.User_Id).FirstLetterToLower()].ObjToInt();
            int RoleId = saveModel.MainData[nameof(Sys_User.Role_Id).FirstLetterToLower()].ObjToInt();
            var user = BaseDal.QueryFirst(x => x.User_Id == userId);
            if (User.User_Id == user.User_Id && User.Role_Id != RoleId) return WebResponseContent.Instance.Error("不可修改自己的角色");
            if (User.User_Id != user.User_Id && User.Role_Id >= RoleId) return WebResponseContent.Instance.Error("权限等级不足");
            if (User.Role_Id > user.Role_Id || User.Role_Id == user.Role_Id && User.User_Id != userId) return WebResponseContent.Instance.Error("暂无修改权限");
            //if (User.User_Id != userId) return WebResponseContent.Instance.Error("暂无修改权限");只限当前用户修改
            #endregion
            saveModel.MainData[nameof(Sys_User.UserPwd).FirstLetterToLower()] = User.UserPwd;
            UpdateIgnoreColOnExecute = x =>
            {
                return new List<string>
@@ -128,6 +184,9 @@
            var data = BaseDal.QueryFirst(x => x.User_Id == App.User.UserId, s => new
            {
                s.UserName,
                s.Role_Id,
                s.User_Id,
                s.UserPwd,
                s.UserTrueName,
                s.Address,
                s.PhoneNo,
@@ -146,7 +205,7 @@
        /// </summary>
        /// <param name="parameters"></param>
        /// <returns></returns>
        public WebResponseContent ModifyPwd(string oldPwd, string newPwd)
        public WebResponseContent ModifyPwd(string oldPwd, string newPwd, string userName)
        {
            WebResponseContent content = WebResponseContent.Instance;
            oldPwd = oldPwd?.Trim();
@@ -158,19 +217,20 @@
                if (string.IsNullOrEmpty(newPwd)) return WebResponseContent.Instance.Error("新密码不能为空");
                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);
                var User = JsonConvert.DeserializeObject<Sys_User>(GetCurrentUserInfo().Data.ToJson());
                if (User.UserName != userName) return WebResponseContent.Instance.Error($"非本人不可修改密码");
                string _oldPwd = oldPwd.EncryptDES(AppSecret.User);
                if (_oldPwd != userCurrentPwd) return WebResponseContent.Instance.Error("旧密码不正确");
                if (_oldPwd != User.UserPwd) return WebResponseContent.Instance.Error("旧密码不正确");
                string _newPwd = newPwd.EncryptDES(AppSecret.User);
                if (userCurrentPwd == _newPwd) return WebResponseContent.Instance.Error("新密码不能与旧密码相同");
                if (User.UserPwd == _newPwd) return WebResponseContent.Instance.Error("新密码不能与旧密码相同");
                BaseDal.UpdateData(new Sys_User
                {
                    User_Id = userId,
                    User_Id = User.User_Id,
                    UserPwd = _newPwd,
                    LastModifyPwdDate = DateTime.Now
                }, new List<string>