From 95fe14fece46f991bf55d4d3fd57977520064587 Mon Sep 17 00:00:00 2001 From: hang <872297557@qq.com> Date: Thu, 27 Mar 2025 16:30:43 +0800 Subject: [PATCH 1/3] =?UTF-8?q?HIR=20=E5=A2=9E=E5=8A=A0=E4=B8=8B=E6=8B=89?= =?UTF-8?q?=E6=A1=86=E5=88=87=E6=8D=A2=E8=B4=A6=E6=88=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/ExtraController.cs | 75 +++++++++++++++++++ .../Service/Management/DTO/UserModel.cs | 20 +++++ .../Management/Interface/IUserService.cs | 2 + .../Service/Management/UserService.cs | 36 ++++++++- .../Service/Management/_MapConfig.cs | 5 ++ 5 files changed, 134 insertions(+), 4 deletions(-) diff --git a/IRaCIS.Core.API/Controllers/ExtraController.cs b/IRaCIS.Core.API/Controllers/ExtraController.cs index 6bbb4f479..91b89b224 100644 --- a/IRaCIS.Core.API/Controllers/ExtraController.cs +++ b/IRaCIS.Core.API/Controllers/ExtraController.cs @@ -24,6 +24,7 @@ using RestSharp; using RestSharp.Authenticators; using System; using System.Collections.Generic; +using System.Globalization; using System.Linq; using System.Net; using System.Net.Http; @@ -101,6 +102,80 @@ namespace IRaCIS.Api.Controllers + [HttpGet, Route("user/loginSelectUserType")] + public async Task> LoginSelectUserType(Guid userId, Guid userTypeId, + [FromServices] IUserService _userService, + [FromServices] IFusionCache _fusionCache, + [FromServices] ITokenService _tokenService, + [FromServices] IReadingImageTaskService readingImageTaskService, + [FromServices] IOptionsMonitor _verifyConfig, + [FromServices] IOptionsMonitor _emailConfig, + + [FromServices] IMailVerificationService _mailVerificationService) + { + var emailConfig = _emailConfig.CurrentValue; + var companyInfo = new SystemEmailSendConfigView() { CompanyName = emailConfig.CompanyName, CompanyNameCN = emailConfig.CompanyNameCN, CompanyShortName = emailConfig.CompanyShortName, CompanyShortNameCN = emailConfig.CompanyShortNameCN }; + + var returnModel = await _userService.LoginSelectUserType(userId, userTypeId); + + if (returnModel.IsSuccess) + { + if (_verifyConfig.CurrentValue.OpenLoginMFA) + { + //MFA 发送邮件 + + returnModel.Data.IsMFA = true; + + var email = returnModel.Data.BasicInfo.EMail; + + var hiddenEmail = IRCEmailPasswordHelper.MaskEmail(email); + + returnModel.Data.BasicInfo.EMail = hiddenEmail; + + //修改密码 + if (returnModel.Data.BasicInfo.IsFirstAdd || returnModel.Data.BasicInfo.LoginState == 1) + { + returnModel.Data.JWTStr = _tokenService.GetToken(IRaCISClaims.Create(returnModel.Data.BasicInfo)); + } + else + { + //正常登录才发送邮件 + await _userService.SendMFAEmail(userId); + + } + + } + else + { + returnModel.Data.JWTStr = _tokenService.GetToken(IRaCISClaims.Create(returnModel.Data.BasicInfo)); + + // 创建一个 CookieOptions 对象,用于设置 Cookie 的属性 + var option = new CookieOptions + { + Expires = DateTime.Now.AddMonths(1), // 设置过期时间为 30 分钟之后 + HttpOnly = false, // 确保 cookie 只能通过 HTTP 访问 + SameSite = Microsoft.AspNetCore.Http.SameSiteMode.None, // 设置 SameSite 属性 + Secure = false // 确保 cookie 只能通过 HTTPS 访问 + }; + + HttpContext.Response.Cookies.Append("access_token", returnModel.Data.JWTStr, option); + + + + // 验证阅片休息时间 + await readingImageTaskService.ResetReadingRestTime(returnModel.Data.BasicInfo.Id); + + await _fusionCache.SetAsync(CacheKeys.UserToken(userId), returnModel.Data.JWTStr, TimeSpan.FromDays(7)); + + await _fusionCache.SetAsync(CacheKeys.UserAutoLoginOut(userId), DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), TimeSpan.FromMinutes(_verifyConfig.CurrentValue.AutoLoginOutMinutes)); + } + } + + returnModel.Data.CompanyInfo = companyInfo; + + return returnModel; + } + diff --git a/IRaCIS.Core.Application/Service/Management/DTO/UserModel.cs b/IRaCIS.Core.Application/Service/Management/DTO/UserModel.cs index 770e09914..5801402e4 100644 --- a/IRaCIS.Core.Application/Service/Management/DTO/UserModel.cs +++ b/IRaCIS.Core.Application/Service/Management/DTO/UserModel.cs @@ -31,6 +31,26 @@ namespace IRaCIS.Application.Contracts public SystemEmailSendConfigView CompanyInfo { get; set; } + public bool IsMutiAccount => AccountList?.Count > 1; + public List AccountList { get; set; } + + } + public class UserAccountInfo + { + public Guid Id { get; set; } + public string UserName { get; set; } = string.Empty; + public string FullName { get; set; } = string.Empty; + + public string Phone { get; set; } = string.Empty; + public string EMail { get; set; } = string.Empty; + + public Guid UserTypeId { get; set; } + + public UserTypeEnum UserTypeEnum { get; set; } + + public string UserTypeShortName { get; set; } + + public int Status { get; set; } } public class UserBasicInfo diff --git a/IRaCIS.Core.Application/Service/Management/Interface/IUserService.cs b/IRaCIS.Core.Application/Service/Management/Interface/IUserService.cs index dd3778899..7cf9372cc 100644 --- a/IRaCIS.Core.Application/Service/Management/Interface/IUserService.cs +++ b/IRaCIS.Core.Application/Service/Management/Interface/IUserService.cs @@ -9,6 +9,8 @@ namespace IRaCIS.Core.Application.Service Task DeleteUser(Guid userId); Task GetUser(Guid id); Task> GetUserList(UserListQueryDTO param); + + Task> LoginSelectUserType(Guid userId, Guid userTypeId); Task> Login(string userName, string password); Task VerifyMFACodeAsync(Guid userId, string Code); diff --git a/IRaCIS.Core.Application/Service/Management/UserService.cs b/IRaCIS.Core.Application/Service/Management/UserService.cs index ef6451214..d5e7354b0 100644 --- a/IRaCIS.Core.Application/Service/Management/UserService.cs +++ b/IRaCIS.Core.Application/Service/Management/UserService.cs @@ -2,6 +2,7 @@ using IRaCIS.Application.Contracts; using IRaCIS.Core.Application.Contracts; using IRaCIS.Core.Application.Helper; +using IRaCIS.Core.Application.Helper.OtherTool; using IRaCIS.Core.Application.ViewModel; using IRaCIS.Core.Domain.Share; using IRaCIS.Core.Infrastructure; @@ -339,7 +340,7 @@ namespace IRaCIS.Core.Application.Service } - + /// /// (未登陆) 设置新密码 @@ -393,7 +394,7 @@ namespace IRaCIS.Core.Application.Service .WhereIf(inQuery.UserState != null, t => t.Status == inQuery.UserState) .WhereIf(inQuery.IsTestUser != null, t => t.IsTestUser == inQuery.IsTestUser) .WhereIf(inQuery.IsZhiZhun != null, t => t.IsZhiZhun == inQuery.IsZhiZhun) - .WhereIf(_userInfo.UserTypeEnumInt ==(int)UserTypeEnum.OA, t => t.UserTypeEnum != UserTypeEnum.Admin) + .WhereIf(_userInfo.UserTypeEnumInt == (int)UserTypeEnum.OA, t => t.UserTypeEnum != UserTypeEnum.Admin) .ProjectTo(_mapper.ConfigurationProvider); return await userQueryable.ToPagedListAsync(inQuery); @@ -485,7 +486,7 @@ namespace IRaCIS.Core.Application.Service if (user == null) return Null404NotFound(user); - if (user.Status!=model.Status) + if (user.Status != model.Status) { await _userLogRepository.AddAsync(new UserLog() { IP = _userInfo.IP, LoginUserId = _userInfo.Id, OptUserId = model.Id, OptType = model.Status == UserStateEnum.Enable ? UserOptType.AccountEnable : UserOptType.AccountLocked }, true); @@ -501,7 +502,7 @@ namespace IRaCIS.Core.Application.Service await _userLogRepository.AddAsync(new UserLog() { IP = _userInfo.IP, LoginUserId = _userInfo.Id, OptUserId = model.Id, OptType = UserOptType.UpdateUser }); - + var success = await _userRepository.SaveChangesAsync(); @@ -622,6 +623,30 @@ namespace IRaCIS.Core.Application.Service return ResponseOutput.Ok(); } + + + //public async Task> HospitalUserLogin(string token) + //{ + // //同济医院token 地址:http://192.168.40.88:8080 + + // //本地测试地址接口 + + // //RestClientAPI.PostAsync<> + + //} + + + + + [NonDynamicMethod] + public async Task> LoginSelectUserType(Guid userId, Guid userTypeId) + { + var userNamePwd = await _userRepository.Where(t => t.Id == userId && t.UserTypeId == userTypeId).Select(t => new { t.UserName, t.Password }).FirstNotNullAsync(); + + return await Login(userNamePwd.UserName, userNamePwd.Password); + } + + /// /// 用户登陆 /// @@ -728,6 +753,9 @@ namespace IRaCIS.Core.Application.Service }); + userLoginReturnModel.AccountList = _userRepository.Where(t => t.EMail == userLoginReturnModel.BasicInfo.EMail && t.UserTypeEnum != UserTypeEnum.SuperAdmin) + .ProjectTo(_mapper.ConfigurationProvider).ToList(); + return ResponseOutput.Ok(userLoginReturnModel); } diff --git a/IRaCIS.Core.Application/Service/Management/_MapConfig.cs b/IRaCIS.Core.Application/Service/Management/_MapConfig.cs index bd6289e3f..a4adf5475 100644 --- a/IRaCIS.Core.Application/Service/Management/_MapConfig.cs +++ b/IRaCIS.Core.Application/Service/Management/_MapConfig.cs @@ -136,6 +136,11 @@ namespace IRaCIS.Core.Application.Service ; CreateMap().ReverseMap(); + + CreateMap() + .ForMember(d => d.UserTypeShortName, c => c.MapFrom(t => t.UserTypeRole.UserTypeShortName)); + + } } From dcddf88a66f5c134612f4e93e658de7576ed1c86 Mon Sep 17 00:00:00 2001 From: hang <872297557@qq.com> Date: Thu, 27 Mar 2025 17:31:01 +0800 Subject: [PATCH 2/3] =?UTF-8?q?getUser=20=E8=BF=94=E5=9B=9E=E8=B4=A6?= =?UTF-8?q?=E6=88=B7=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Service/Management/DTO/UserModel.cs | 3 +++ .../Service/Management/UserService.cs | 11 ++++++++--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/IRaCIS.Core.Application/Service/Management/DTO/UserModel.cs b/IRaCIS.Core.Application/Service/Management/DTO/UserModel.cs index 5801402e4..5bc5d1afe 100644 --- a/IRaCIS.Core.Application/Service/Management/DTO/UserModel.cs +++ b/IRaCIS.Core.Application/Service/Management/DTO/UserModel.cs @@ -140,6 +140,9 @@ namespace IRaCIS.Application.Contracts public class UserDetailDTO : UserInfo { public bool CanEditUserType { get; set; } + + public bool IsMutiAccount => AccountList?.Count > 1; + public List AccountList { get; set; } } public class UserInfo diff --git a/IRaCIS.Core.Application/Service/Management/UserService.cs b/IRaCIS.Core.Application/Service/Management/UserService.cs index d5e7354b0..9bd8fc53c 100644 --- a/IRaCIS.Core.Application/Service/Management/UserService.cs +++ b/IRaCIS.Core.Application/Service/Management/UserService.cs @@ -410,7 +410,12 @@ namespace IRaCIS.Core.Application.Service public async Task GetUser(Guid id) { var userQuery = _userRepository.Where(t => t.Id == id).ProjectTo(_mapper.ConfigurationProvider); - return await (userQuery.FirstOrDefaultAsync()).IfNullThrowException(); + var result = await (userQuery.FirstOrDefaultAsync()).IfNullThrowException(); + + result.AccountList = _userRepository.Where(t => t.EMail == result.EMail && t.UserTypeEnum != UserTypeEnum.SuperAdmin) + .ProjectTo(_mapper.ConfigurationProvider).ToList(); + + return result; } /// @@ -627,11 +632,11 @@ namespace IRaCIS.Core.Application.Service //public async Task> HospitalUserLogin(string token) //{ - // //同济医院token 地址:http://192.168.40.88:8080 + // //同济医院token 地址:http://192.168.40.88:8080 appid:third-hirs // //本地测试地址接口 - // //RestClientAPI.PostAsync<> + // RestClientAPI.PostAsync<> //} From ade2a25fc4652eec50c29c60cd59412ec8a34528 Mon Sep 17 00:00:00 2001 From: hang <872297557@qq.com> Date: Fri, 28 Mar 2025 09:38:12 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E8=8E=B7=E5=8F=96tj=20=E5=8C=BB=E9=99=A2to?= =?UTF-8?q?kenInfo?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Service/Management/DTO/UserModel.cs | 20 ++++++++++++++ .../Service/Management/UserService.cs | 26 ++++++++++++++----- 2 files changed, 40 insertions(+), 6 deletions(-) diff --git a/IRaCIS.Core.Application/Service/Management/DTO/UserModel.cs b/IRaCIS.Core.Application/Service/Management/DTO/UserModel.cs index 5bc5d1afe..dc272bd2f 100644 --- a/IRaCIS.Core.Application/Service/Management/DTO/UserModel.cs +++ b/IRaCIS.Core.Application/Service/Management/DTO/UserModel.cs @@ -22,6 +22,26 @@ namespace IRaCIS.Application.Contracts public Guid? UserId { get; set; } } + public class TJUserInfoDto + { + public string Code { get; set; } + public string Msg { get; set; } + public TJUserInfoData Data { get; set; } + } + + public class TJUserInfoData + { + public string UserCode { get; set; } + public string UserName { get; set; } + public string DeptCode { get; set; } + public string Sex { get; set; } + public string Birthday { get; set; } + public string Title { get; set; } + public string UserType { get; set; } + } + + + public class LoginReturnDTO { public UserBasicInfo BasicInfo { get; set; } = new UserBasicInfo(); diff --git a/IRaCIS.Core.Application/Service/Management/UserService.cs b/IRaCIS.Core.Application/Service/Management/UserService.cs index 9bd8fc53c..c81eb9c46 100644 --- a/IRaCIS.Core.Application/Service/Management/UserService.cs +++ b/IRaCIS.Core.Application/Service/Management/UserService.cs @@ -629,16 +629,30 @@ namespace IRaCIS.Core.Application.Service } + [AllowAnonymous] + public async Task TJUserLoginInfo(string token) + { + //同济医院token 地址:http://192.168.40.88:8080 appid:third-hirs - //public async Task> HospitalUserLogin(string token) - //{ - // //同济医院token 地址:http://192.168.40.88:8080 appid:third-hirs + //本地测试地址接口 - // //本地测试地址接口 + var apiUrl = "http://192.168.40.88:8080/dock/userinfo"; + var headers = new Dictionary + { + { "Content-Type", "application/json" } // 根据需要添加其他头部信息 + }; - // RestClientAPI.PostAsync<> + var requestData = new + { + userToken = token, + appId = "third-hirs", + }; - //} + var tjUserInfo = await RestClientAPI.PostAsync(apiUrl, requestData, headers); + + + return ResponseOutput.Ok(tjUserInfo); + }