From c020f31a67fc5aa5644511bddff075f7ecc85234 Mon Sep 17 00:00:00 2001
From: qinchulong <qinchulong@hnkhzn.com>
Date: 星期二, 27 五月 2025 15:35:27 +0800
Subject: [PATCH] Merge branch 'master' of http://115.159.85.185:8098/r/HuaYiZhongHeng/ZhongHeLiTiKu

---
 代码管理/WMS/WIDESEA_WMSServer/WIDESEA_SystemService/Sys_UserService.cs |  192 ++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 192 insertions(+), 0 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"
new file mode 100644
index 0000000..11f2d94
--- /dev/null
+++ "b/\344\273\243\347\240\201\347\256\241\347\220\206/WMS/WIDESEA_WMSServer/WIDESEA_SystemService/Sys_UserService.cs"
@@ -0,0 +1,192 @@
+锘縰sing WIDESEA_Core.Authorization;
+using WIDESEA_Core;
+using WIDESEA_Core.BaseServices;
+using WIDESEA_Core.Const;
+using WIDESEA_Core.Helper;
+using WIDESEA_Core.HttpContextUser;
+using WIDESEA_ISystemService;
+using WIDESEA_Model;
+using WIDESEA_Model.Models;
+using WIDESEA_ISystemRepository;
+using WIDESEA_Core.BaseRepository;
+using System.Net;
+using WIDESEA_Core.Caches;
+using SqlSugar;
+using ICacheService = WIDESEA_Core.Caches.ICacheService;
+
+namespace WIDESEA_SystemService
+{
+    public class Sys_UserService : ServiceBase<Sys_User, ISys_UserRepository>, ISys_UserService
+    {
+        private readonly IUnitOfWorkManage _unitOfWorkManage;
+        private readonly ICacheService _cacheService;
+        private readonly ISys_MenuService _menuService;
+
+        public ISys_UserRepository Repository => BaseDal;
+
+        public Sys_UserService(ISys_UserRepository repository, IUnitOfWorkManage unitOfWorkManage, ICacheService cacheService, ISys_MenuService menuService) : base(repository)
+        {
+            _unitOfWorkManage = unitOfWorkManage;
+            _cacheService = cacheService;
+            _menuService = menuService;
+        }
+
+        public WebResponseContent Login(LoginInfo loginInfo)
+        {
+            WebResponseContent content = new WebResponseContent();
+            try
+            {
+                //BaseDal.QueryFirst(x => x.UserName == loginInfo.UserName);
+
+                string msg = string.Empty;
+
+                #region 涓存椂浣跨敤
+                try
+                {
+                    loginInfo.Password = loginInfo.Password.EncryptDES(AppSecret.User);
+                }
+                catch
+                {
+
+                }
+                #endregion
+
+                UserInfo user = BaseDal.GetUserInfo(loginInfo.UserName, loginInfo.Password);
+                if (user != null)
+                {
+                    object obj = _menuService.GetMenuActionList(user.RoleId);
+                    if (obj is not IEnumerable<object> list)
+                    {
+                        return WebResponseContent.Instance.Error("鏃犵櫥褰曟潈闄�");
+                    }
+                    if (!list.Any())
+                    {
+                        return WebResponseContent.Instance.Error("鏃犵櫥褰曟潈闄�");
+                    }
+
+                    string token = JwtHelper.IssueJwt(new TokenModelJwt()
+                    {
+                        UserId = user.UserId,
+                        RoleId = user.RoleId,
+                        UserName = user.UserName,
+                        TenantId = user.TenantId,
+                    });
+
+                    _cacheService.AddOrUpdate(user.UserId.ToString(), token);
+
+                    content = WebResponseContent.Instance.OK(data: new { token, userName = user.UserTrueName, img = user.HeadImageUrl });
+                }
+                else
+                {
+                    content = WebResponseContent.Instance.Error("璐﹀彿鎴栧瘑鐮侀敊璇�");
+                }
+            }
+            catch (Exception ex)
+            {
+                content = WebResponseContent.Instance.Error(ex.Message);
+            }
+
+            return content;
+        }
+
+        public override WebResponseContent UpdateData(SaveModel saveModel)
+        {
+            UpdateIgnoreColOnExecute = x =>
+            {
+                return new List<string>
+                {
+                    nameof(Sys_User.UserPwd),
+                    nameof(Sys_User.TenantId)
+                };
+            };
+            return base.UpdateData(saveModel);
+        }
+
+        public override WebResponseContent AddData(SaveModel saveModel)
+        {
+            string pwd = "123456";
+            string uesrName = saveModel.MainData[nameof(Sys_User.UserName).FirstLetterToLower()].ToString();
+            saveModel.MainData[nameof(Sys_User.UserPwd).FirstLetterToLower()] = pwd.EncryptDES(AppSecret.User);
+
+            WebResponseContent content = base.AddData(saveModel);
+            if (content.Status)
+            {
+                return WebResponseContent.Instance.OK($"鐢ㄦ埛鏂板缓鎴愬姛.甯愬彿{uesrName}瀵嗙爜{pwd}");
+            }
+            else
+            {
+                return content;
+            }
+        }
+
+        /// <summary>
+        /// 涓汉涓績鑾峰彇褰撳墠鐢ㄦ埛淇℃伅
+        /// </summary>
+        /// <returns></returns>
+        public WebResponseContent GetCurrentUserInfo()
+        {
+            var data = BaseDal.QueryFirst(x => x.User_Id == App.User.UserId, s => new
+            {
+                s.UserName,
+                s.UserTrueName,
+                s.Address,
+                s.PhoneNo,
+                s.Email,
+                s.Remark,
+                s.Gender,
+                s.RoleName,
+                s.HeadImageUrl,
+                s.CreateDate
+            });
+            return WebResponseContent.Instance.OK(null, data);
+        }
+
+        /// <summary>
+        /// 淇敼瀵嗙爜
+        /// </summary>
+        /// <param name="parameters"></param>
+        /// <returns></returns>
+        public WebResponseContent ModifyPwd(string oldPwd, string newPwd)
+        {
+            WebResponseContent content = WebResponseContent.Instance;
+            oldPwd = oldPwd?.Trim();
+            newPwd = newPwd?.Trim();
+            string message = "";
+            try
+            {
+                if (string.IsNullOrEmpty(oldPwd)) return WebResponseContent.Instance.Error("鏃у瘑鐮佷笉鑳戒负绌�");
+                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);
+
+                string _oldPwd = oldPwd.EncryptDES(AppSecret.User);
+                if (_oldPwd != userCurrentPwd) return WebResponseContent.Instance.Error("鏃у瘑鐮佷笉姝g‘");
+
+                string _newPwd = newPwd.EncryptDES(AppSecret.User);
+                if (userCurrentPwd == _newPwd) return WebResponseContent.Instance.Error("鏂板瘑鐮佷笉鑳戒笌鏃у瘑鐮佺浉鍚�");
+
+
+                BaseDal.UpdateData(new Sys_User
+                {
+                    User_Id = userId,
+                    UserPwd = _newPwd,
+                    LastModifyPwdDate = DateTime.Now
+                }, new List<string>
+                {
+                    nameof(Sys_User.LastModifyPwdDate),
+                    nameof(Sys_User.UserPwd)
+                });
+
+                content = WebResponseContent.Instance.OK("瀵嗙爜淇敼鎴愬姛");
+            }
+            catch (Exception ex)
+            {
+                message = ex.Message;
+                content = WebResponseContent.Instance.Error("鏈嶅姟鍣ㄤ簡鐐归棶棰�,璇风◢鍚庡啀璇�");
+            }
+            return content;
+        }
+    }
+}

--
Gitblit v1.9.3