diff --git a/IRaCIS.Core.API/Controllers/ExtraController.cs b/IRaCIS.Core.API/Controllers/ExtraController.cs index fb245ad1c..80a114def 100644 --- a/IRaCIS.Core.API/Controllers/ExtraController.cs +++ b/IRaCIS.Core.API/Controllers/ExtraController.cs @@ -136,7 +136,7 @@ namespace IRaCIS.Api.Controllers var loginReturn = new LoginReturnDTO() { BasicInfo = basicInfo }; - loginReturn.JWTStr = _tokenService.GetToken(new UserTokenInfo() { UserRoleId = basicInfo.IdentityUserId }); + loginReturn.JWTStr = _tokenService.GetToken(new UserTokenInfo() { IdentityUserId = basicInfo.IdentityUserId }); // 创建一个 CookieOptions 对象,用于设置 Cookie 的属性 diff --git a/IRaCIS.Core.Application/Service/Common/MailService.cs b/IRaCIS.Core.Application/Service/Common/MailService.cs index c8a639fb4..e3baad780 100644 --- a/IRaCIS.Core.Application/Service/Common/MailService.cs +++ b/IRaCIS.Core.Application/Service/Common/MailService.cs @@ -281,7 +281,7 @@ namespace IRaCIS.Core.Application.Service //---[来自展影IRC] 关于创建账户的提醒 - var token = _tokenService.GetToken(new UserTokenInfo() { UserRoleId = sysUserInfo.Id }); + var token = _tokenService.GetToken(new UserTokenInfo() { IdentityUserId = sysUserInfo.Id }); await _identityUserRepository.BatchUpdateNoTrackingAsync(t => t.Id == sysUserInfo.Id, u => new IdentityUser() { EmailToken = token }); @@ -507,7 +507,7 @@ namespace IRaCIS.Core.Application.Service // $"[来自展影IRC] [{trialInfo.ResearchProgramNo}]邀请信"; - var token = _tokenService.GetToken(new UserTokenInfo() { UserRoleId = sysUserInfo.Id }); + var token = _tokenService.GetToken(new UserTokenInfo() { IdentityUserId = sysUserInfo.Id }); if (sysUserInfo.IsFirstAdd) { diff --git a/IRaCIS.Core.Application/Service/Inspection/FrontAuditConfigService.cs b/IRaCIS.Core.Application/Service/Inspection/FrontAuditConfigService.cs index c36602cb3..c7d3b6981 100644 --- a/IRaCIS.Core.Application/Service/Inspection/FrontAuditConfigService.cs +++ b/IRaCIS.Core.Application/Service/Inspection/FrontAuditConfigService.cs @@ -389,8 +389,6 @@ namespace IRaCIS.Core.Application.Service objectLsit.Add(newNamepDic); } - - await AddJsonObjectToDic(relationParentInspection.Id, relationParentInspection.ObjectRelationParentId, relationParentInspection.CreateTime, relationParentInspection.BatchId, objectLsit); await AddJsonObjectToDic(relationParentInspection.Id, relationParentInspection.ObjectRelationParentId2, relationParentInspection.CreateTime, relationParentInspection.BatchId, objectLsit); await AddJsonObjectToDic(relationParentInspection.Id, relationParentInspection.ObjectRelationParentId3, relationParentInspection.CreateTime, relationParentInspection.BatchId, objectLsit); @@ -401,7 +399,7 @@ namespace IRaCIS.Core.Application.Service //用户的数据稽查没有 临时处理 - var userObj = await _userRoleRepository.Where(t => t.Id == objectRelationParentId).Select(t => new { UserRealName = t.FullName, t.Phone, t.UserName, UserType = t.UserTypeRole.UserTypeShortName, t.EMail, t.OrganizationName }).FirstOrDefaultAsync(); + var userObj = await _userRoleRepository.Where(t => t.Id == objectRelationParentId).Select(t => new { UserRealName = t.IdentityUser.FullName, t.IdentityUser.Phone, t.IdentityUser.UserName, UserType = t.UserTypeRole.UserTypeShortName, t.IdentityUser.EMail, t.IdentityUser.OrganizationName }).FirstOrDefaultAsync(); if (userObj != null) { diff --git a/IRaCIS.Core.Application/Service/Management/DTO/UserLogViewModel.cs b/IRaCIS.Core.Application/Service/Management/DTO/UserLogViewModel.cs index 5220efd63..5858be3db 100644 --- a/IRaCIS.Core.Application/Service/Management/DTO/UserLogViewModel.cs +++ b/IRaCIS.Core.Application/Service/Management/DTO/UserLogViewModel.cs @@ -17,7 +17,7 @@ namespace IRaCIS.Core.Application.ViewModel public string? ActionUserName { get; set; } - public UserTypeEnum? ActionUserTypeEnum { get; set; } + public string ActionUserRoleShortName { get; set; } public DateTime CreateTime { get; set; } public Guid CreateUserId { get; set; } @@ -25,9 +25,7 @@ namespace IRaCIS.Core.Application.ViewModel public string TargetIdentityUserName { get; set; } - public UserTypeEnum? OptUserTypeEnum { get; set; } - - public UserLogJsonObj JsonObj { get; set; } + public string JsonObj { get; set; } public string IPRegion { get; set; } } diff --git a/IRaCIS.Core.Application/Service/Management/UserService.cs b/IRaCIS.Core.Application/Service/Management/UserService.cs index 310e5b761..72fa8af47 100644 --- a/IRaCIS.Core.Application/Service/Management/UserService.cs +++ b/IRaCIS.Core.Application/Service/Management/UserService.cs @@ -435,7 +435,7 @@ namespace IRaCIS.Core.Application.Service if (!string.IsNullOrEmpty(editPwModel.NewUserName)) { - await VerifyUserNameAsync(_userInfo.UserRoleId, editPwModel.NewUserName); + await VerifyUserNameAsync(_userInfo.IdentityUserId, editPwModel.NewUserName); await _identityUserRepository.BatchUpdateNoTrackingAsync(t => t.Id == _userInfo.IdentityUserId, u => new IdentityUser() { @@ -556,6 +556,7 @@ namespace IRaCIS.Core.Application.Service addRole.UserTypeEnum = role.UserTypeEnum; addRole.UserTypeId = role.UserTypeId; + addRole.IsUserRoleDisabled = role.IsUserRoleDisabled; addRoleList.Add(addRole); } @@ -685,6 +686,7 @@ namespace IRaCIS.Core.Application.Service addRole.IdentityUserId = user.Id; addRole.UserTypeEnum = role.UserTypeEnum; addRole.UserTypeId = role.UserTypeId; + addRole.IsUserRoleDisabled = role.IsUserRoleDisabled; user.UserRoleList.Add(addRole); } @@ -906,13 +908,12 @@ namespace IRaCIS.Core.Application.Service var userLogQueryable = _userLogRepository.AsQueryable().IgnoreQueryFilters() - .WhereIf(inQuery.TrialId != null, t => t.CreateUserRole.UserRoleTrials.Any(c => c.TrialId == inQuery.TrialId && (c.UserId == t.LoginUserId || c.UserId == t.OptUserId))) + .WhereIf(inQuery.TrialId != null, t => t.ActionIdentityUser.UserTrialList.Any(c => c.TrialId == inQuery.TrialId)) .WhereIf(trialCreateTime != null, t => t.CreateTime >= trialCreateTime) .WhereIf(inQuery.OptType != null, t => t.OptType == inQuery.OptType) - .WhereIf(inQuery.UserId != null, t => t.LoginUserId == inQuery.UserId) .WhereIf(inQuery.BeginDate != null, t => t.CreateTime >= inQuery.BeginDate) .WhereIf(inQuery.EndDate != null, t => t.CreateTime <= inQuery.EndDate) - .WhereIf(!string.IsNullOrEmpty(inQuery.LoginUserName), t => t.CreateUserRole.UserName.Contains(inQuery.LoginUserName!)) + .WhereIf(!string.IsNullOrEmpty(inQuery.LoginUserName), t => t.ActionUserName.Contains(inQuery.LoginUserName!)) .WhereIf(!string.IsNullOrEmpty(inQuery.LoginFaildName), t => t.LoginFaildName.Contains(inQuery.LoginFaildName!)) .WhereIf(!string.IsNullOrEmpty(inQuery.IP), t => t.IP.Contains(inQuery.IP!)) .WhereIf(inQuery.LoginUserTypeEnum != null, t => t.CreateUserRole.UserTypeEnum == inQuery.LoginUserTypeEnum) @@ -1129,7 +1130,7 @@ namespace IRaCIS.Core.Application.Service IsZhiZhun = t.IdentityUser.IsZhiZhun, FullName = t.IdentityUser.FullName, PermissionStr = t.UserTypeRole.PermissionStr, - UserName = t.UserName, + UserName = t.IdentityUser.UserName, UserTypeShortName = t.UserTypeRole.UserTypeShortName, }).FirstOrDefaultAsync(); @@ -1139,8 +1140,6 @@ namespace IRaCIS.Core.Application.Service { var jwt = _tokenService.GetToken(userTokenInfo); - - return jwt; } else diff --git a/IRaCIS.Core.Application/Service/Management/_MapConfig.cs b/IRaCIS.Core.Application/Service/Management/_MapConfig.cs index 2758b4f1d..47a4784be 100644 --- a/IRaCIS.Core.Application/Service/Management/_MapConfig.cs +++ b/IRaCIS.Core.Application/Service/Management/_MapConfig.cs @@ -123,8 +123,8 @@ namespace IRaCIS.Core.Application.Service CreateMap() - .ForMember(d => d.TargetIdentityUserName, c => c.MapFrom(t => t.TargetIdentityUser.UserName)) - .ForMember(d => d.ActionUserTypeEnum, c => c.MapFrom(t => t.CreateUserRole.UserTypeEnum)); + .ForMember(d => d.ActionUserRoleShortName, c => c.MapFrom(t => t.CreateUserRole.UserTypeRole.UserTypeShortName)) + .ForMember(d => d.TargetIdentityUserName, c => c.MapFrom(t => t.TargetIdentityUser.UserName)); CreateMap() @@ -162,7 +162,7 @@ namespace IRaCIS.Core.Application.Service CreateMap(); - CreateMap(); + CreateMap().ReverseMap(); CreateMap(); diff --git a/IRaCIS.Core.Application/Service/SiteSurvey/TrialSiteSurveyService.cs b/IRaCIS.Core.Application/Service/SiteSurvey/TrialSiteSurveyService.cs index 558d14198..3a4852d10 100644 --- a/IRaCIS.Core.Application/Service/SiteSurvey/TrialSiteSurveyService.cs +++ b/IRaCIS.Core.Application/Service/SiteSurvey/TrialSiteSurveyService.cs @@ -251,7 +251,7 @@ namespace IRaCIS.Core.Application.Contracts result.ReviewStatus = info.ReviewStatus; } - result.Token = _tokenService.GetToken(new UserTokenInfo() { UserRoleId = Guid.NewGuid() }); + result.Token = _tokenService.GetToken(new UserTokenInfo() { IdentityUserId = Guid.NewGuid() }); } } diff --git a/IRaCIS.Core.Application/Service/TrialSiteUser/TrialMaintenanceService.cs b/IRaCIS.Core.Application/Service/TrialSiteUser/TrialMaintenanceService.cs index f16fa9675..140cdf627 100644 --- a/IRaCIS.Core.Application/Service/TrialSiteUser/TrialMaintenanceService.cs +++ b/IRaCIS.Core.Application/Service/TrialSiteUser/TrialMaintenanceService.cs @@ -4,6 +4,7 @@ using IRaCIS.Application.Interfaces; using IRaCIS.Core.Application.Contracts.DTO; using IRaCIS.Core.Application.Filter; using IRaCIS.Core.Domain.Share; +using MassTransit.Serialization; using Microsoft.AspNetCore.Mvc; namespace IRaCIS.Core.Application.Service @@ -174,23 +175,33 @@ namespace IRaCIS.Core.Application.Service //[Authorize(Policy = IRaCISPolicy.PM_APM)] public async Task AddTrialUsers(TrialUserAddCommand[] userTrialCommands) { - foreach (var item in userTrialCommands.GroupBy(t => t.IdentityUserId)) { var currentUserRoleList = item.ToList(); var first = currentUserRoleList.FirstOrDefault(); - var currentUser = new TrialIdentityUser() + var findTrialuser = await _trialIdentityUserRepository.Where(t => t.TrialId == first.TrialId && t.IdentityUserId == item.Key, true).Include(t => t.TrialUserRoleList).FirstOrDefaultAsync(); + + if (findTrialuser == null) { - TrialId = first.TrialId, - IdentityUserId = item.Key, - JoinTime = DateTime.Now, - TrialUserRoleList = currentUserRoleList.Select(t => new TrialUserRole() { UserId = t.UserId, TrialId = t.TrialId }).ToList() - }; + var currentUser = new TrialIdentityUser() + { + TrialId = first.TrialId, + IdentityUserId = item.Key, + JoinTime = DateTime.Now, + TrialUserRoleList = currentUserRoleList.Select(t => new TrialUserRole() { UserId = t.UserId, TrialId = t.TrialId }).ToList() + }; + + + await _trialIdentityUserRepository.AddAsync(currentUser); + } + else + { + findTrialuser.TrialUserRoleList.AddRange(currentUserRoleList.Select(t => new TrialUserRole() { UserId = t.UserId, TrialId = t.TrialId, TrialUserId = findTrialuser.Id }).ToList()); + } - await _trialIdentityUserRepository.AddAsync(currentUser); var success = await _trialIdentityUserRepository.SaveChangesAsync(); diff --git a/IRaCIS.Core.Application/Triggers/AfterSaveTrigger/UserLogAfterTrigger.cs b/IRaCIS.Core.Application/Triggers/AfterSaveTrigger/UserLogAfterTrigger.cs index e19a3012a..ce19b7e24 100644 --- a/IRaCIS.Core.Application/Triggers/AfterSaveTrigger/UserLogAfterTrigger.cs +++ b/IRaCIS.Core.Application/Triggers/AfterSaveTrigger/UserLogAfterTrigger.cs @@ -41,11 +41,20 @@ namespace IRaCIS.Core.Application.Triggers.AfterSaveTrigger }).FirstOrDefaultAsync(); - userlog.JsonObj = obj; - await _identityUserRepository.SaveChangesAsync(); + + userlog.JsonObj = obj.ToJsonStr(); + } + if (userlog.ActionIdentityUserId != null && userlog.ActionUserName.IsNullOrWhiteSpace()) + { + userlog.ActionUserName = await _identityUserRepository.Where(t => t.Id == userlog.ActionIdentityUserId).Select(t => t.UserName).FirstOrDefaultAsync(); + } + + await _identityUserRepository.SaveChangesAsync(); + + } } } diff --git a/IRaCIS.Core.Domain.Share/Reading/ImageFilterState.cs b/IRaCIS.Core.Domain.Share/Reading/ImageFilterState.cs index 748343ada..ad1f1e60b 100644 --- a/IRaCIS.Core.Domain.Share/Reading/ImageFilterState.cs +++ b/IRaCIS.Core.Domain.Share/Reading/ImageFilterState.cs @@ -15,7 +15,7 @@ public enum UserOptType Login = 1, [Description("选择登录角色")] - LoginSelectRole =11, + LoginSelectRole =18, [Description("更新用户角色")] UpdateUserRole =15, @@ -44,8 +44,6 @@ public enum UserOptType //admin 重置密码 ResetPassword = 9, - DeleteUser = 10, - UpdateUser = 11, MFALogin = 12, diff --git a/IRaCIS.Core.Domain/Management/User.cs b/IRaCIS.Core.Domain/Management/User.cs index 526d7846e..cb8e7f51f 100644 --- a/IRaCIS.Core.Domain/Management/User.cs +++ b/IRaCIS.Core.Domain/Management/User.cs @@ -115,6 +115,10 @@ public class UserRole : BaseFullAuditEntity [Table("IdentityUser")] public class IdentityUser: BaseFullAuditEntity { + [JsonIgnore] + public List UserTrialList { get; set; } + + [JsonIgnore] public List UserRoleList { get; set; } = new List(); [Projectable] diff --git a/IRaCIS.Core.Domain/Management/UserLog.cs b/IRaCIS.Core.Domain/Management/UserLog.cs index 34f74b227..c225a6fd6 100644 --- a/IRaCIS.Core.Domain/Management/UserLog.cs +++ b/IRaCIS.Core.Domain/Management/UserLog.cs @@ -10,6 +10,10 @@ public class UserLog : BaseAddAuditEntity [JsonIgnore] public IdentityUser TargetIdentityUser { get; set; } + + [JsonIgnore] + public IdentityUser ActionIdentityUser { get; set; } + #endregion public string IP { get; set; } = string.Empty; @@ -27,7 +31,7 @@ public class UserLog : BaseAddAuditEntity public string ActionUserName { get; set; } [MaxLength] - public UserLogJsonObj JsonObj { get; set; } + public string JsonObj { get; set; } [Comment("被操作的对象 admin 修改张三信息 张三是被操作对象")] @@ -66,7 +70,6 @@ public class UserLogJsonObj public string DepartmentName { get; set; } - [NotMapped] public List UserRoleList { get; set; } } diff --git a/IRaCIS.Core.Infra.EFCore/Context/IRaCISDBContext.cs b/IRaCIS.Core.Infra.EFCore/Context/IRaCISDBContext.cs index 634c11474..0bebe6d0a 100644 --- a/IRaCIS.Core.Infra.EFCore/Context/IRaCISDBContext.cs +++ b/IRaCIS.Core.Infra.EFCore/Context/IRaCISDBContext.cs @@ -63,15 +63,6 @@ public class IRaCISDBContext : DbContext protected override void OnModelCreating(ModelBuilder modelBuilder) { - modelBuilder.Entity(entity => - { - entity.OwnsOne(x => x.JsonObj, ownedNavigationBuilder => - { - ownedNavigationBuilder.ToJson(); - }); - - }); - modelBuilder.Entity(entity => { // 使用部分加密值转换器,前 2 个字符不加密,方便模糊搜索