From 3460ffdc967b65ea67c959212c2505a19008401e Mon Sep 17 00:00:00 2001
From: 647556386 <647556386@qq.com>
Date: 星期四, 16 四月 2026 13:39:56 +0800
Subject: [PATCH] 盘点优化,智仓调智仓防呆
---
项目代码/WMS无仓储版/WIDESEA_WMSServer/WIDESEA_SystemService/Sys_UserService.cs | 126 ++++++++++++++++++++++++++++++++++++++++-
1 files changed, 121 insertions(+), 5 deletions(-)
diff --git "a/\351\241\271\347\233\256\344\273\243\347\240\201/WMS\346\227\240\344\273\223\345\202\250\347\211\210/WIDESEA_WMSServer/WIDESEA_SystemService/Sys_UserService.cs" "b/\351\241\271\347\233\256\344\273\243\347\240\201/WMS\346\227\240\344\273\223\345\202\250\347\211\210/WIDESEA_WMSServer/WIDESEA_SystemService/Sys_UserService.cs"
index cea2a5f..8c5b533 100644
--- "a/\351\241\271\347\233\256\344\273\243\347\240\201/WMS\346\227\240\344\273\223\345\202\250\347\211\210/WIDESEA_WMSServer/WIDESEA_SystemService/Sys_UserService.cs"
+++ "b/\351\241\271\347\233\256\344\273\243\347\240\201/WMS\346\227\240\344\273\223\345\202\250\347\211\210/WIDESEA_WMSServer/WIDESEA_SystemService/Sys_UserService.cs"
@@ -18,6 +18,8 @@
using MailKit.Search;
using OrderByType = SqlSugar.OrderByType;
using System.Drawing.Printing;
+using WIDESEA_Model.Models.Config;
+using WIDESEA_IBasicService;
//using WIDESEA_Core.HostedService;
namespace WIDESEA_SystemService
@@ -28,24 +30,29 @@
private readonly ICacheService _cacheService;
private readonly ISys_MenuService _menuService;
private readonly ISys_RoleService _roleService;
+ private readonly IPasswordPolicyConfigService _passwordPolicyConfigService;
public IRepository<Sys_User> Repository => BaseDal;
- public Sys_UserService(IRepository<Sys_User> repository, IUnitOfWorkManage unitOfWorkManage, ICacheService cacheService, ISys_MenuService menuService, ISys_RoleService roleService) : base(repository)
+ public Sys_UserService(IRepository<Sys_User> repository, IUnitOfWorkManage unitOfWorkManage, ICacheService cacheService, ISys_MenuService menuService, ISys_RoleService roleService, IPasswordPolicyConfigService passwordPolicyConfigService) : base(repository)
{
_unitOfWorkManage = unitOfWorkManage;
_cacheService = cacheService;
_menuService = menuService;
_roleService = roleService;
+ _passwordPolicyConfigService = passwordPolicyConfigService;
}
public WebResponseContent Login(LoginInfo loginInfo)
{
WebResponseContent content = new WebResponseContent();
+ PasswordPolicyConfig passwordPolicy = null;
+ string token = null;
try
{
//BaseDal.QueryFirst(x => x.UserName == loginInfo.UserName);
-
+ passwordPolicy = _passwordPolicyConfigService.GetConfigValue("") ?? new PasswordPolicyConfig();
+
string msg = string.Empty;
#region 涓存椂浣跨敤
@@ -59,9 +66,51 @@
}
#endregion
- UserInfo user = BaseDal.QueryFirst(x => x.UserName == loginInfo.UserName && x.UserPwd == loginInfo.Password, x => new UserInfo { HeadImageUrl = x.HeadImageUrl, RoleId = x.RoleId, TenantId = x.TenantId, UserId = x.UserId, UserName = x.UserName, UserTrueName = x.UserTrueName });
+ UserInfo user = BaseDal.QueryFirst(x => x.UserName == loginInfo.UserName && x.UserPwd == loginInfo.Password, x => new UserInfo { HeadImageUrl = x.HeadImageUrl, RoleId = x.RoleId, TenantId = x.TenantId, UserId = x.UserId, UserName = x.UserName, UserTrueName = x.UserTrueName,PwdLastModifyTime = x.LastModifyPwdDate });
if (user != null)
{
+ // 3. 瀵嗙爜杩囨湡绛栫暐妫�鏌ワ紙浠呭惎鐢ㄦ椂鎵ц锛�
+ if (passwordPolicy.EnablePasswordExpire)
+ {
+ DateTime pwdModifyTime = user.PwdLastModifyTime ?? DateTime.Now.AddYears(-1);
+ TimeSpan passwordAge = DateTime.Now - pwdModifyTime;
+ int daysToExpire = passwordPolicy.PasswordExpireDays - (int)passwordAge.TotalDays;
+
+ // 瀵嗙爜宸茶繃鏈燂紝寮哄埗鏀瑰瘑
+ if (daysToExpire <= 0)
+ {
+ return WebResponseContent.Instance.Error(
+ "鎮ㄧ殑瀵嗙爜宸茶繃鏈燂紝璇峰厛淇敼瀵嗙爜鍚庡啀鐧诲綍",
+ data: new { needChangePwd = true, userId = user.UserId });
+ }
+
+ // 瀵嗙爜鍗冲皢杩囨湡锛岀櫥褰曟垚鍔熷苟鎻愰啋
+ if (daysToExpire <= passwordPolicy.RemindBeforeExpireDays)
+ {
+ token = JwtHelper.IssueJwt(new TokenModelJwt()
+ {
+ UserId = user.UserId,
+ RoleId = user.RoleId,
+ UserName = user.UserName,
+ TenantId = user.TenantId,
+ });
+ App.User.UpdateToke(token, user.UserId);
+
+ content = WebResponseContent.Instance.OK(
+ message: $"鎮ㄧ殑瀵嗙爜灏嗗湪{daysToExpire}澶╁悗杩囨湡锛岃鍙婃椂淇敼",
+ data: new
+ {
+ token,
+ userName = user.UserName,
+ img = user.HeadImageUrl,
+ UserTrueName = user.UserTrueName,
+ needChangePwd = false,
+ pwdWillExpire = true,
+ daysToExpire = daysToExpire
+ });
+ return content;
+ }
+ }
object obj = _menuService.GetMenuActionList(user.RoleId);
if (obj is not IEnumerable<object> list)
{
@@ -72,7 +121,7 @@
return WebResponseContent.Instance.Error("鏃犵櫥褰曟潈闄�");
}
- string token = JwtHelper.IssueJwt(new TokenModelJwt()
+ token = JwtHelper.IssueJwt(new TokenModelJwt()
{
UserId = user.UserId,
RoleId = user.RoleId,
@@ -84,7 +133,12 @@
//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, user.UserTrueName });
+ content = WebResponseContent.Instance.OK(message: "鐧诲叆鎴愬姛,姝e湪璺宠浆椤甸潰", data: new { token, userName = user.UserName, img = user.HeadImageUrl, user.UserTrueName, needChangePwd = false,
+ pwdWillExpire = false,
+ daysToExpire = passwordPolicy.EnablePasswordExpire
+ ? passwordPolicy.PasswordExpireDays - (int)(DateTime.Now - (user.PwdLastModifyTime ?? DateTime.Now)).TotalDays
+ : 0
+ });
}
else
{
@@ -151,6 +205,9 @@
string pwd = "123456";
string uesrName = saveModel.MainData[nameof(Sys_User.UserName).FirstLetterToLower()].ToString();
saveModel.MainData[nameof(Sys_User.UserPwd).FirstLetterToLower()] = pwd.EncryptDES(AppSecret.User);
+
+ string pwdModifyTimeField = nameof(Sys_User.LastModifyPwdDate).FirstLetterToLower();
+ saveModel.MainData[pwdModifyTimeField] = DateTime.Now;
WebResponseContent content = base.AddData(saveModel);
if (content.Status)
@@ -244,6 +301,7 @@
Sys_User user = BaseDal.QueryFirst(x => x.UserName == userName);
if (user == null) return WebResponseContent.Instance.Error("鐢ㄦ埛涓嶅瓨鍦�");
user.UserPwd = password.EncryptDES(AppSecret.User);
+ user.LastModifyPwdDate = DateTime.Now;
BaseDal.UpdateData(user);
if (App.User.UserId == user.UserId)
{
@@ -265,5 +323,63 @@
}
return content;
}
+
+ public WebResponseContent ModifyUserNamePwd(string userName,string oldPwd, string password)
+ {
+ WebResponseContent content = new WebResponseContent();
+ string message = "";
+ // 鍘婚櫎棣栧熬绌烘牸锛岀┖鍊煎鐞�
+ oldPwd = oldPwd?.Trim();
+ password = password?.Trim();
+ userName = userName?.Trim();
+
+ try
+ {
+ // 1. 鍩虹鍙傛暟鏍¢獙
+ if (string.IsNullOrEmpty(userName)) return WebResponseContent.Instance.Error("鐢ㄦ埛鍚嶄笉鑳戒负绌�");
+ if (string.IsNullOrEmpty(oldPwd)) return WebResponseContent.Instance.Error("鏃у瘑鐮佷笉鑳戒负绌�");
+ if (string.IsNullOrEmpty(password)) return WebResponseContent.Instance.Error("鏂板瘑鐮佷笉鑳戒负绌�");
+ if (oldPwd == password) return WebResponseContent.Instance.Error("鏂板瘑鐮佷笉鑳戒笌鏃у瘑鐮佺浉鍚�");
+ if (password.Length < 6) return WebResponseContent.Instance.Error("鏂板瘑鐮侀暱搴︿笉鑳藉皯浜�6浣�");
+
+ // 2. 鑾峰彇鐢ㄦ埛淇℃伅
+ Sys_User user = BaseDal.QueryFirst(x => x.UserName == userName);
+ if (user == null) return WebResponseContent.Instance.Error("鐢ㄦ埛涓嶅瓨鍦�");
+
+ // 3. 鏍¢獙鏃у瘑鐮侊紙瑙e瘑鍚庡姣旓級
+ string decryptedOldPwd = user.UserPwd.DecryptDES(AppSecret.User); // 瑙e瘑鏁版嵁搴撲腑鐨勫瘑鐮�
+ if (decryptedOldPwd != oldPwd) // 瀵规瘮鍘熷鏃у瘑鐮�
+ {
+ return WebResponseContent.Instance.Error("鏃у瘑鐮佽緭鍏ラ敊璇�");
+ }
+
+ // 4. 鏇存柊瀵嗙爜鍙婄浉鍏充俊鎭�
+ user.UserPwd = password.EncryptDES(AppSecret.User); // 鍔犲瘑鏂板瘑鐮�
+ user.LastModifyPwdDate = DateTime.Now;
+ BaseDal.UpdateData(user);
+
+ // 5. 濡傛灉鏄綋鍓嶇櫥褰曠敤鎴凤紝閲嶆柊鐢熸垚JWT Token骞舵洿鏂扮紦瀛�
+ 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);
+ }
+
+ // 6. 杩斿洖鎴愬姛缁撴灉
+ return content.OK("瀵嗙爜淇敼鎴愬姛");
+ }
+ catch (Exception ex)
+ {
+ message = ex.Message; // 璁板綍寮傚父淇℃伅锛堝缓璁ˉ鍏呮棩蹇楁鏋惰褰曪級
+ content.Error("鏈嶅姟鍣ㄥ嚭浜嗙偣闂,璇风◢鍚庡啀璇�");
+ }
+ return content;
+ }
}
}
--
Gitblit v1.9.3