From 663489b2ce63ee84851dfbc2db32814e40ae9a89 Mon Sep 17 00:00:00 2001
From: dengjunjie <dengjunjie@hnkhzn.com>
Date: 星期五, 25 十月 2024 23:15:10 +0800
Subject: [PATCH] 优化WCS用户管理功能

---
 项目代码/WCS/WIDESEAWCS_Server/WIDESEAWCS_SystemServices/Sys_UserService.cs |   66 +++++++++++++++++++++++++++++---
 1 files changed, 59 insertions(+), 7 deletions(-)

diff --git "a/\351\241\271\347\233\256\344\273\243\347\240\201/WCS/WIDESEAWCS_Server/WIDESEAWCS_SystemServices/Sys_UserService.cs" "b/\351\241\271\347\233\256\344\273\243\347\240\201/WCS/WIDESEAWCS_Server/WIDESEAWCS_SystemServices/Sys_UserService.cs"
index 874ff8f..8bd4df9 100644
--- "a/\351\241\271\347\233\256\344\273\243\347\240\201/WCS/WIDESEAWCS_Server/WIDESEAWCS_SystemServices/Sys_UserService.cs"
+++ "b/\351\241\271\347\233\256\344\273\243\347\240\201/WCS/WIDESEAWCS_Server/WIDESEAWCS_SystemServices/Sys_UserService.cs"
@@ -11,6 +11,10 @@
 using WIDESEAWCS_Core.BaseRepository;
 using System.Net;
 using WIDESEAWCS_Core.Caches;
+using System.Drawing.Drawing2D;
+using WIDESEAWCS_SystemServices.System;
+using OfficeOpenXml.FormulaParsing.Excel.Functions.RefAndLookup;
+using Newtonsoft.Json;
 
 namespace WIDESEAWCS_SystemServices
 {
@@ -18,12 +22,39 @@
     {
         private readonly IUnitOfWorkManage _unitOfWorkManage;
         private readonly ICacheService _cacheService;
-        public Sys_UserService(ISys_UserRepository repository, IUnitOfWorkManage unitOfWorkManage, ICacheService cacheService) : base(repository)
+        private readonly ISys_RoleService _sys_RoleService;
+        public Sys_UserService(ISys_UserRepository repository, IUnitOfWorkManage unitOfWorkManage, ICacheService cacheService, ISys_RoleService sys_RoleService) : base(repository)
         {
             _unitOfWorkManage = unitOfWorkManage;
             _cacheService = cacheService;
+            _sys_RoleService = sys_RoleService;
         }
+        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 WebResponseContent Login(LoginInfo loginInfo)
         {
             WebResponseContent content = new WebResponseContent();
@@ -47,6 +78,9 @@
                 UserInfo user = BaseDal.GetUserInfo(loginInfo.UserName, loginInfo.Password);
                 if (user != null)
                 {
+                    #region 鍒ゆ柇褰撳墠鐢ㄦ埛鏄惁鍚敤
+                    if (BaseDal.QueryFirst(x => x.User_Id == user.UserId, s => s.Enable) != 1) throw new Exception($"璐﹀彿{user.UserName}绂佹浣跨敤,璇疯仈绯荤鐞嗗憳");
+                    #endregion
                     string token = JwtHelper.IssueJwt(new TokenModelJwt()
                     {
                         UserId = user.UserId,
@@ -74,6 +108,18 @@
 
         public override WebResponseContent UpdateData(SaveModel saveModel)
         {
+            //var User1 = JsonConvert.DeserializeObject<Sys_User>(JsonConvert.SerializeObject(GetCurrentUserInfo().Data));
+            var User = JsonConvert.DeserializeObject<Sys_User>(GetCurrentUserInfo().Data.ToJson());
+
+            #region 鍙兘淇敼姣斿綋鍓嶇敤鎴疯鑹茬瓑绾т綆鐨勭敤鎴�
+            int userId = saveModel.MainData[nameof(Sys_User.User_Id).FirstLetterToLower()].ObjToInt();
+            var roleId = BaseDal.QueryFirst(x => x.User_Id == userId, s => s.Role_Id);
+            if (User.Role_Id > roleId || User.Role_Id == roleId && 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;
+            //saveModel.MainData[nameof(Sys_User.UserPwd).FirstLetterToLower()] = App.User.TenantId;
             UpdateIgnoreColOnExecute = x =>
             {
                 return new List<string>
@@ -111,6 +157,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,
@@ -129,7 +178,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();
@@ -141,19 +190,22 @@
                 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);
+                //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