From 9e579eda4601ed7b492b9d19a24e8146f6ebdf8d Mon Sep 17 00:00:00 2001
From: dengjunjie <dengjunjie@hnkhzn.com>
Date: 星期六, 19 四月 2025 19:50:43 +0800
Subject: [PATCH] 优化空托出入库逻辑

---
 项目代码/WMS/WIDESEA_WMSServer/WIDESEA_SystemService/Sys_UserService.cs |   61 +++++++++++++++++++++++++++---
 1 files changed, 54 insertions(+), 7 deletions(-)

diff --git "a/\351\241\271\347\233\256\344\273\243\347\240\201/WMS/WIDESEA_WMSServer/WIDESEA_SystemService/Sys_UserService.cs" "b/\351\241\271\347\233\256\344\273\243\347\240\201/WMS/WIDESEA_WMSServer/WIDESEA_SystemService/Sys_UserService.cs"
index 11f2d94..b96a532 100644
--- "a/\351\241\271\347\233\256\344\273\243\347\240\201/WMS/WIDESEA_WMSServer/WIDESEA_SystemService/Sys_UserService.cs"
+++ "b/\351\241\271\347\233\256\344\273\243\347\240\201/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)
@@ -88,9 +92,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 +171,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 +192,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 +204,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("鏃у瘑鐮佷笉姝g‘");
+                if (_oldPwd != User.UserPwd) return WebResponseContent.Instance.Error("鏃у瘑鐮佷笉姝g‘");
 
                 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>

--
Gitblit v1.9.3