修改用户日志
parent
5f9572a0ab
commit
cf9248b0cc
|
@ -1,5 +1,6 @@
|
|||
using EntityFramework.Exceptions.SqlServer;
|
||||
using IRaCIS.Core.Application.Triggers;
|
||||
using IRaCIS.Core.Application.Triggers.AfterSaveTrigger;
|
||||
using IRaCIS.Core.Domain.Share;
|
||||
using IRaCIS.Core.Infra.EFCore;
|
||||
using IRaCIS.Core.Infra.EFCore.Interceptor;
|
||||
|
@ -81,6 +82,9 @@ namespace IRaCIS.Core.API
|
|||
|
||||
triggerOptions.AddTrigger<UserAddTrigger>();
|
||||
|
||||
triggerOptions.AddTrigger<UserLogAfterTrigger>();
|
||||
|
||||
|
||||
|
||||
});
|
||||
});
|
||||
|
|
|
@ -4245,6 +4245,13 @@
|
|||
<param name="calculateType"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:IRaCIS.Core.Application.Service.ReadingCalculate.MRIPDFFCalculateService.GetFatFractionAvg(IRaCIS.Core.Application.Service.Reading.Dto.ReadingCalculateDto)">
|
||||
<summary>
|
||||
获取脂肪分数平均值
|
||||
</summary>
|
||||
<param name="inDto"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:IRaCIS.Core.Application.Service.ReadingCalculate.MRIPDFFCalculateService.CalculateAvg(IRaCIS.Core.Application.Service.Reading.Dto.ReadingCalculateDto)">
|
||||
<summary>
|
||||
计算平均值
|
||||
|
@ -14044,6 +14051,11 @@
|
|||
检查日期
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:IRaCIS.Core.Application.ViewModel.TableMarkInfo.RowId">
|
||||
<summary>
|
||||
表格问题标记
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:IRaCIS.Core.Application.ViewModel.IRECISTTargetLesionDto.NotExistsTargetLesion">
|
||||
<summary>
|
||||
基线未选择任何靶病灶
|
||||
|
|
|
@ -15,23 +15,19 @@ namespace IRaCIS.Core.Application.ViewModel
|
|||
public string LoginFaildName { get; set; }
|
||||
public int OptType { get; set; }
|
||||
|
||||
public string? ActionUserName { get; set; }
|
||||
|
||||
public string? LoginUserName { get; set; }
|
||||
|
||||
public UserTypeEnum? LoginUserTypeEnum { get; set; }
|
||||
public UserTypeEnum? ActionUserTypeEnum { get; set; }
|
||||
|
||||
public DateTime CreateTime { get; set; }
|
||||
public Guid CreateUserId { get; set; }
|
||||
|
||||
public string TargetIdentityUserName { get; set; }
|
||||
|
||||
|
||||
public string? OptUserName { get; set; }
|
||||
|
||||
public UserTypeEnum? OptUserTypeEnum { get; set; }
|
||||
|
||||
public Guid? LoginUserId { get; set; }
|
||||
|
||||
public Guid? OptUserId { get; set; }
|
||||
public UserLogJsonObj JsonObj { get; set; }
|
||||
|
||||
public string IPRegion { get; set; }
|
||||
}
|
||||
|
|
|
@ -1,9 +1,11 @@
|
|||
using DocumentFormat.OpenXml.Wordprocessing;
|
||||
using DocumentFormat.OpenXml.Spreadsheet;
|
||||
using DocumentFormat.OpenXml.Wordprocessing;
|
||||
using IP2Region.Net.Abstractions;
|
||||
using IRaCIS.Application.Contracts;
|
||||
using IRaCIS.Core.Application.Auth;
|
||||
using IRaCIS.Core.Application.Contracts;
|
||||
using IRaCIS.Core.Application.Helper;
|
||||
using IRaCIS.Core.Application.Service.OAuth;
|
||||
using IRaCIS.Core.Application.ViewModel;
|
||||
using IRaCIS.Core.Domain.Share;
|
||||
using IRaCIS.Core.Infrastructure;
|
||||
|
@ -202,7 +204,8 @@ namespace IRaCIS.Core.Application.Service
|
|||
//删除验证码历史记录
|
||||
await _verificationCodeRepository.BatchDeleteNoTrackingAsync(t => t.UserId == _userInfo.UserRoleId && t.CodeType == 0);
|
||||
|
||||
await _userLogRepository.AddAsync(new UserLog() { IP = _userInfo.IP, LoginUserId = _userInfo.UserRoleId, OptUserId = _userInfo.UserRoleId, OptType = UserOptType.UpdateUser }, true);
|
||||
await _userLogRepository.AddAsync(new UserLog() { IP = _userInfo.IP, ActionIdentityUserId = _userInfo.IdentityUserId, ActionUserName = _userInfo.UserName, TargetIdentityUserId = _userInfo.IdentityUserId, OptType = UserOptType.UpdateUser }, true);
|
||||
|
||||
|
||||
return ResponseOutput.Ok();
|
||||
|
||||
|
@ -222,7 +225,8 @@ namespace IRaCIS.Core.Application.Service
|
|||
Phone = newPhone
|
||||
});
|
||||
|
||||
await _userLogRepository.AddAsync(new UserLog() { IP = _userInfo.IP, LoginUserId = _userInfo.UserRoleId, OptUserId = _userInfo.UserRoleId, OptType = UserOptType.UpdateUser }, true);
|
||||
await _userLogRepository.AddAsync(new UserLog() { IP = _userInfo.IP, ActionIdentityUserId = _userInfo.IdentityUserId, ActionUserName = _userInfo.UserName, TargetIdentityUserId = _userInfo.IdentityUserId, OptType = UserOptType.UpdateUser }, true);
|
||||
|
||||
|
||||
return ResponseOutput.Ok();
|
||||
}
|
||||
|
@ -239,7 +243,8 @@ namespace IRaCIS.Core.Application.Service
|
|||
UserName = newUserName
|
||||
});
|
||||
|
||||
await _userLogRepository.AddAsync(new UserLog() { IP = _userInfo.IP, LoginUserId = _userInfo.UserRoleId, OptUserId = _userInfo.UserRoleId, OptType = UserOptType.UpdateUser }, true);
|
||||
await _userLogRepository.AddAsync(new UserLog() { IP = _userInfo.IP, ActionIdentityUserId = _userInfo.IdentityUserId, ActionUserName = _userInfo.UserName, TargetIdentityUserId = _userInfo.IdentityUserId, OptType = UserOptType.UpdateUser }, true);
|
||||
|
||||
return ResponseOutput.Ok();
|
||||
}
|
||||
|
||||
|
@ -267,7 +272,7 @@ namespace IRaCIS.Core.Application.Service
|
|||
|
||||
}, true);
|
||||
|
||||
await _userLogRepository.AddAsync(new UserLog() { IP = _userInfo.IP, LoginUserId = _userInfo.UserRoleId, OptUserId = _userInfo.UserRoleId, OptType = UserOptType.UpdateUser }, true);
|
||||
await _userLogRepository.AddAsync(new UserLog() { IP = _userInfo.IP, ActionIdentityUserId = _userInfo.IdentityUserId, ActionUserName = _userInfo.UserName, TargetIdentityUserId = _userInfo.IdentityUserId, OptType = UserOptType.UpdateUser }, true);
|
||||
|
||||
return ResponseOutput.Ok();
|
||||
}
|
||||
|
@ -298,7 +303,7 @@ namespace IRaCIS.Core.Application.Service
|
|||
|
||||
await _fusionCache.RemoveAsync(CacheKeys.UserLoginError(userName));
|
||||
|
||||
//await _userLogRepository.AddAsync(new UserLog() { IP = _userInfo.IP, LoginUserId = _userInfo.Id, OptUserId = userId, OptType = UserOptType.ResetPassword }, true);
|
||||
await _userLogRepository.AddAsync(new UserLog() { IP = _userInfo.IP, ActionIdentityUserId = _userInfo.IdentityUserId, ActionUserName = _userInfo.UserName, TargetIdentityUserId = _userInfo.IdentityUserId, OptType = UserOptType.ResetPassword }, true);
|
||||
|
||||
return ResponseOutput.Ok();
|
||||
}
|
||||
|
@ -408,7 +413,8 @@ namespace IRaCIS.Core.Application.Service
|
|||
IsFirstAdd = false
|
||||
});
|
||||
|
||||
//await _userLogRepository.AddAsync(new UserLog() { IP = _userInfo.IP, LoginUserId = userId, OptUserId = userId, LoginPassword = newPwd, OptType = UserOptType.UnloginModifyPasswoed }, true);
|
||||
await _userLogRepository.AddAsync(new UserLog() { IP = _userInfo.IP, ActionIdentityUserId = identityUserId, ActionUserName = _userInfo.UserName, TargetIdentityUserId = identityUserId, OptType = UserOptType.LoginModifyPassword }, true);
|
||||
|
||||
|
||||
return ResponseOutput.Result(success);
|
||||
|
||||
|
@ -444,7 +450,7 @@ namespace IRaCIS.Core.Application.Service
|
|||
IsFirstAdd = false
|
||||
});
|
||||
|
||||
await _userLogRepository.AddAsync(new UserLog() { IP = _userInfo.IP, LoginUserId = _userInfo.UserRoleId, OptUserId = _userInfo.UserRoleId, OptType = UserOptType.LoginModifyPassword }, true);
|
||||
await _userLogRepository.AddAsync(new UserLog() { IP = _userInfo.IP, ActionIdentityUserId = _userInfo.IdentityUserId, ActionUserName = _userInfo.UserName, TargetIdentityUserId = _userInfo.IdentityUserId, OptType = UserOptType.LoginModifyPassword }, true);
|
||||
|
||||
return ResponseOutput.Result(success);
|
||||
|
||||
|
@ -561,9 +567,11 @@ namespace IRaCIS.Core.Application.Service
|
|||
var success = await _identityUserRepository.SaveChangesAsync();
|
||||
}
|
||||
|
||||
|
||||
await _mailVerificationService.AddUserSendEmailAsync(saveItem.Id, userAddModel.BaseUrl, userAddModel.RouteUrl);
|
||||
|
||||
|
||||
|
||||
return ResponseOutput.Ok(new UserAddedReturnDTO { Id = saveItem.Id, UserCode = saveItem.UserCode });
|
||||
|
||||
}
|
||||
|
@ -591,7 +599,7 @@ namespace IRaCIS.Core.Application.Service
|
|||
|
||||
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);
|
||||
await _userLogRepository.AddAsync(new UserLog() { IP = _userInfo.IP, ActionIdentityUserId = _userInfo.IdentityUserId, ActionUserName = _userInfo.UserName, OptType = model.Status == UserStateEnum.Enable ? UserOptType.AccountEnable : UserOptType.AccountLocked }, true);
|
||||
|
||||
}
|
||||
|
||||
|
@ -631,6 +639,9 @@ namespace IRaCIS.Core.Application.Service
|
|||
|
||||
var success = await _userRoleRepository.SaveChangesAsync();
|
||||
|
||||
await _userLogRepository.AddAsync(new UserLog() { IP = _userInfo.IP, ActionIdentityUserId = _userInfo.IdentityUserId, ActionUserName = _userInfo.UserName, TargetIdentityUserId = model.Id, OptType = UserOptType.UpdateUser }, true);
|
||||
|
||||
|
||||
return ResponseOutput.Ok(success);
|
||||
|
||||
}
|
||||
|
@ -643,13 +654,12 @@ namespace IRaCIS.Core.Application.Service
|
|||
var user = await _identityUserRepository.Where(t => t.Id == command.Id, true).FirstOrDefaultAsync();
|
||||
|
||||
if (user == null) return Null404NotFound(user);
|
||||
|
||||
_mapper.Map(command, user);
|
||||
|
||||
await _userLogRepository.AddAsync(new UserLog() { IP = _userInfo.IP, ActionIdentityUserId = _userInfo.IdentityUserId, ActionUserName = _userInfo.UserName, TargetIdentityUserId = command.Id, OptType = UserOptType.UpdateUser }, true);
|
||||
|
||||
await _identityUserRepository.SaveChangesAsync();
|
||||
|
||||
return ResponseOutput.Ok();
|
||||
|
||||
}
|
||||
|
||||
[HttpPut]
|
||||
|
@ -682,6 +692,7 @@ namespace IRaCIS.Core.Application.Service
|
|||
|
||||
|
||||
var success = await _userRoleRepository.SaveChangesAsync();
|
||||
await _userLogRepository.AddAsync(new UserLog() { IP = _userInfo.IP, ActionIdentityUserId = _userInfo.IdentityUserId, ActionUserName = _userInfo.UserName, TargetIdentityUserId = command.Id, OptType = UserOptType.UpdateUserRole }, true);
|
||||
|
||||
return ResponseOutput.Ok();
|
||||
}
|
||||
|
@ -895,17 +906,17 @@ namespace IRaCIS.Core.Application.Service
|
|||
|
||||
var userLogQueryable =
|
||||
_userLogRepository.AsQueryable().IgnoreQueryFilters()
|
||||
.WhereIf(inQuery.TrialId != null, t => t.LoginUser.UserRoleTrials.Any(c => c.TrialId == inQuery.TrialId && (c.UserId == t.LoginUserId || c.UserId == t.OptUserId)))
|
||||
.WhereIf(inQuery.TrialId != null, t => t.CreateUserRole.UserRoleTrials.Any(c => c.TrialId == inQuery.TrialId && (c.UserId == t.LoginUserId || c.UserId == t.OptUserId)))
|
||||
.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.LoginUser.UserName.Contains(inQuery.LoginUserName!))
|
||||
.WhereIf(!string.IsNullOrEmpty(inQuery.LoginUserName), t => t.CreateUserRole.UserName.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.LoginUser.UserTypeEnum == inQuery.LoginUserTypeEnum)
|
||||
.WhereIf(inQuery.UserTypeId != null, t => t.LoginUser.UserTypeId == inQuery.UserTypeId)
|
||||
.WhereIf(inQuery.LoginUserTypeEnum != null, t => t.CreateUserRole.UserTypeEnum == inQuery.LoginUserTypeEnum)
|
||||
.WhereIf(inQuery.UserTypeId != null, t => t.CreateUserRole.UserTypeId == inQuery.UserTypeId)
|
||||
|
||||
.ProjectTo<UserLogView>(_mapper.ConfigurationProvider);
|
||||
|
||||
|
@ -916,10 +927,14 @@ namespace IRaCIS.Core.Application.Service
|
|||
|
||||
[AllowAnonymous]
|
||||
[HttpGet]
|
||||
public async Task<IResponseOutput> LoginOut(Guid identityUserId)
|
||||
public async Task<IResponseOutput> LoginOut(Guid identityUserId, Guid userRoleId)
|
||||
{
|
||||
await _fusionCache.RemoveAsync(CacheKeys.UserToken(identityUserId));
|
||||
|
||||
var userName = await _userRoleRepository.Where(t => t.Id == userRoleId).Select(t => t.IdentityUser.UserName).FirstOrDefaultAsync();
|
||||
|
||||
await _userLogRepository.AddAsync(new UserLog() { IP = _userInfo.IP, ActionIdentityUserId = identityUserId, ActionUserName = userName, OptType = UserOptType.LoginOut }, true);
|
||||
|
||||
return ResponseOutput.Ok();
|
||||
}
|
||||
|
||||
|
@ -966,7 +981,7 @@ namespace IRaCIS.Core.Application.Service
|
|||
|
||||
if (failCount >= maxFailures)
|
||||
{
|
||||
//await _userLogRepository.AddAsync(new UserLog() { IP = _userInfo.IP, LoginUserId = Guid.Empty, OptUserId = Guid.Empty, LoginFaildName = userName, LoginPassword = password, OptType = UserOptType.AccountLocked }, true);
|
||||
await _userLogRepository.AddAsync(new UserLog() { IP = _userInfo.IP, LoginFaildName = userName, LoginPassword = password, OptType = UserOptType.AccountLocked }, true);
|
||||
|
||||
//$"密码连续错误{maxFailures}次,当前账号已被限制登录,请等待 {lockoutMinutes} 分钟后再试。"
|
||||
throw new BusinessValidationFailedException(_localizer["User_ErrorLimit", maxFailures, lockoutMinutes]);
|
||||
|
@ -986,7 +1001,7 @@ namespace IRaCIS.Core.Application.Service
|
|||
|
||||
var errorPwdUserId = await _identityUserRepository.Where(u => u.UserName == userName).Select(t => t.Id).FirstOrDefaultAsync();
|
||||
|
||||
//await _userLogRepository.AddAsync(new UserLog() { IP = _userInfo.IP, LoginUserId = errorPwdUserId, OptUserId = errorPwdUserId, LoginFaildName = userName, LoginPassword = password, OptType = UserOptType.AccountOrPasswordError }, true);
|
||||
await _userLogRepository.AddAsync(new UserLog() { IP = _userInfo.IP, ActionUserName = userName, LoginFaildName = userName, LoginPassword = password, OptType = UserOptType.AccountOrPasswordError }, true);
|
||||
|
||||
return ResponseOutput.NotOk(_localizer["User_CheckNameOrPw"], new IRCLoginReturnDTO());
|
||||
|
||||
|
@ -994,7 +1009,7 @@ namespace IRaCIS.Core.Application.Service
|
|||
|
||||
if (loginUser.Status == 0)
|
||||
{
|
||||
//await _userLogRepository.AddAsync(new UserLog() { IP = _userInfo.IP, LoginUserId = loginUser.Id, OptUserId = loginUser.Id, LoginFaildName = userName, OptType = UserOptType.LoginLockedAccount }, true);
|
||||
await _userLogRepository.AddAsync(new UserLog() { IP = _userInfo.IP, ActionIdentityUserId = loginUser.IdentityUserId, LoginFaildName = userName, OptType = UserOptType.LoginLockedAccount }, true);
|
||||
|
||||
//---该用户已经被禁用。
|
||||
return ResponseOutput.NotOk(_localizer["User_Disabled"], new IRCLoginReturnDTO());
|
||||
|
@ -1021,7 +1036,7 @@ namespace IRaCIS.Core.Application.Service
|
|||
loginUser.LoginState = 1;
|
||||
}
|
||||
|
||||
//await _userLogRepository.AddAsync(new UserLog() { IP = _userInfo.IP, LoginUserId = loginUser.Id, OptUserId = loginUser.Id, OptType = UserOptType.Login }, true);
|
||||
await _userLogRepository.AddAsync(new UserLog() { IP = _userInfo.IP, ActionIdentityUserId = loginUser.IdentityUserId, OptType = UserOptType.Login }, true);
|
||||
|
||||
userLoginReturnModel.BasicInfo = loginUser;
|
||||
|
||||
|
@ -1116,9 +1131,10 @@ namespace IRaCIS.Core.Application.Service
|
|||
PermissionStr = t.UserTypeRole.PermissionStr,
|
||||
UserName = t.UserName,
|
||||
UserTypeShortName = t.UserTypeRole.UserTypeShortName,
|
||||
|
||||
}).FirstOrDefaultAsync();
|
||||
|
||||
await _userLogRepository.AddAsync(new UserLog() { IP = _userInfo.IP, ActionIdentityUserId = userTokenInfo.IdentityUserId, ActionUserName = userTokenInfo.UserName, OptType = UserOptType.LoginSelectRole }, true);
|
||||
|
||||
if (userTokenInfo != null)
|
||||
{
|
||||
var jwt = _tokenService.GetToken(userTokenInfo);
|
||||
|
|
|
@ -93,7 +93,7 @@ namespace IRaCIS.Core.Application.Service
|
|||
|
||||
CreateMap<IdentityUser, UserDetailDTO>();
|
||||
|
||||
var token = string.Empty;
|
||||
var token = string.Empty;
|
||||
var userId = Guid.Empty;
|
||||
CreateMap<SystemNotice, SystemNoticeView>()
|
||||
.ForMember(t => t.PublishUserName, d => d.MapFrom(t => t.PublishedUser.UserName))
|
||||
|
@ -123,11 +123,8 @@ namespace IRaCIS.Core.Application.Service
|
|||
|
||||
|
||||
CreateMap<UserLog, UserLogView>()
|
||||
.ForMember(d => d.LoginUserName, c => c.MapFrom(t => t.LoginUser.UserName))
|
||||
.ForMember(d => d.LoginUserTypeEnum, c => c.MapFrom(t => t.LoginUser.UserTypeEnum))
|
||||
.ForMember(d => d.OptUserName, c => c.MapFrom(t => t.OptUser.UserName))
|
||||
.ForMember(d => d.OptUserTypeEnum, c => c.MapFrom(t => t.OptUser.UserTypeEnum))
|
||||
;
|
||||
.ForMember(d => d.TargetIdentityUserName, c => c.MapFrom(t => t.TargetIdentityUser.UserName))
|
||||
.ForMember(d => d.ActionUserTypeEnum, c => c.MapFrom(t => t.CreateUserRole.UserTypeEnum));
|
||||
|
||||
|
||||
CreateMap<UserFeedBack, UserFeedBackView>()
|
||||
|
@ -157,7 +154,7 @@ namespace IRaCIS.Core.Application.Service
|
|||
.ForMember(d => d.IdentityUserId, c => c.MapFrom(t => t.Id));
|
||||
CreateMap<IdentityUser, UserListDTO>();
|
||||
|
||||
CreateMap<UserAddUserType, UserRole> ().ReverseMap();
|
||||
CreateMap<UserAddUserType, UserRole>().ReverseMap();
|
||||
|
||||
|
||||
CreateMap<UserRole, IdentityUserTypeDTO>()
|
||||
|
@ -167,6 +164,8 @@ namespace IRaCIS.Core.Application.Service
|
|||
|
||||
CreateMap<UserRole, IdentityUser>();
|
||||
|
||||
CreateMap<UserCommand, UserRole>();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,52 @@
|
|||
using AutoMapper.QueryableExtensions;
|
||||
using EntityFrameworkCore.Triggered;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace IRaCIS.Core.Application.Triggers.AfterSaveTrigger
|
||||
{
|
||||
public class UserLogAfterTrigger(IRepository<IdentityUser> _identityUserRepository) : IAfterSaveTrigger<UserLog>
|
||||
{
|
||||
public async Task AfterSave(ITriggerContext<UserLog> context, CancellationToken cancellationToken)
|
||||
{
|
||||
var userlog = context.Entity;
|
||||
|
||||
if (context.ChangeType == ChangeType.Added)
|
||||
{
|
||||
|
||||
if (userlog.TargetIdentityUserId != null)
|
||||
{
|
||||
var obj = await _identityUserRepository.Where(t => t.Id == userlog.TargetIdentityUserId).Select(t => new UserLogJsonObj()
|
||||
{
|
||||
DepartmentName = t.DepartmentName,
|
||||
EMail = t.EMail,
|
||||
FirstName = t.FirstName,
|
||||
LastName = t.LastName,
|
||||
OrganizationName = t.OrganizationName,
|
||||
Phone = t.Phone,
|
||||
PositionName = t.PositionName,
|
||||
Sex = t.Sex,
|
||||
Status = t.Status,
|
||||
UserCode = t.UserCode,
|
||||
UserName = t.UserName,
|
||||
UserRoleList = t.UserRoleList.Select(t => new UserRoleLogObj()
|
||||
{
|
||||
IsUserRoleDisabled = t.IsUserRoleDisabled,
|
||||
UserTypeEnum = t.UserTypeEnum,
|
||||
UserTypeShortName = t.UserTypeRole.UserTypeShortName
|
||||
}).ToList()
|
||||
|
||||
}).FirstOrDefaultAsync();
|
||||
|
||||
userlog.JsonObj = obj;
|
||||
|
||||
await _identityUserRepository.SaveChangesAsync();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -28,15 +28,16 @@ namespace IRaCIS.Core.Application.Triggers
|
|||
}
|
||||
|
||||
|
||||
public class UserAddTrigger(IUserInfo _userInfo, IRepository<UserLog> _userLogReposiotry) : IBeforeSaveTrigger<UserRole>
|
||||
public class UserAddTrigger(IUserInfo _userInfo, IRepository<UserLog> _userLogReposiotry) : IBeforeSaveTrigger<IdentityUser>
|
||||
{
|
||||
public async Task BeforeSave(ITriggerContext<UserRole> context, CancellationToken cancellationToken)
|
||||
public async Task BeforeSave(ITriggerContext<IdentityUser> context, CancellationToken cancellationToken)
|
||||
{
|
||||
var user = context.Entity;
|
||||
|
||||
if (context.ChangeType == ChangeType.Added)
|
||||
{
|
||||
await _userLogReposiotry.AddAsync(new UserLog() { OptType = UserOptType.AddUser, OptUserId = user.Id, LoginUserId = _userInfo.UserRoleId, IP = _userInfo.IP });
|
||||
await _userLogReposiotry.AddAsync(new UserLog() { IP = _userInfo.IP, ActionIdentityUserId = _userInfo.IdentityUserId, ActionUserName = _userInfo.UserName, OptType = UserOptType.AddUser }, true);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -14,6 +14,13 @@ public enum UserOptType
|
|||
[Description("用户登录")]
|
||||
Login = 1,
|
||||
|
||||
[Description("选择登录角色")]
|
||||
LoginSelectRole =11,
|
||||
|
||||
[Description("更新用户角色")]
|
||||
UpdateUserRole =15,
|
||||
|
||||
|
||||
[Description("用户登出")]
|
||||
LoginOut = 2,
|
||||
|
||||
|
|
|
@ -8,10 +8,8 @@ public class UserLog : BaseAddAuditEntity
|
|||
{
|
||||
#region 导航属性
|
||||
[JsonIgnore]
|
||||
public UserRole LoginUser { get; set; }
|
||||
public IdentityUser TargetIdentityUser { get; set; }
|
||||
|
||||
[JsonIgnore]
|
||||
public UserRole OptUser { get; set; }
|
||||
#endregion
|
||||
|
||||
public string IP { get; set; } = string.Empty;
|
||||
|
@ -24,20 +22,61 @@ public class UserLog : BaseAddAuditEntity
|
|||
|
||||
#region 账号修改 维护
|
||||
|
||||
//public Guid? LoginIdentityUserId { get; set; }
|
||||
public Guid? ActionIdentityUserId { get; set; }
|
||||
|
||||
//public string LoginUserName { get; set; }
|
||||
public string ActionUserName { get; set; }
|
||||
|
||||
//public UserTypeEnum loginUserType { get; set; }
|
||||
[MaxLength]
|
||||
public UserLogJsonObj JsonObj { get; set; }
|
||||
|
||||
|
||||
[Comment("被操作的对象 admin 修改张三信息 张三是被操作对象")]
|
||||
public Guid? TargetIdentityUserId { get; set; }
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
[Comment("后续删除")]
|
||||
public Guid? LoginUserId { get; set; }
|
||||
[Comment("被操作的人,自己操作的就是自己")]
|
||||
[Comment("被操作的人,自己操作的就是自己--后续删除")]
|
||||
public Guid? OptUserId { get; set; }
|
||||
|
||||
}
|
||||
|
||||
|
||||
public class UserLogJsonObj
|
||||
{
|
||||
public string FullName => LastName + " / " + FirstName;
|
||||
|
||||
public string UserCode { get; set; }
|
||||
public string UserName { get; set; }
|
||||
public string EMail { get; set; }
|
||||
|
||||
public string FirstName { get; set; }
|
||||
|
||||
public string LastName { get; set; }
|
||||
|
||||
public string Phone { get; set; }
|
||||
|
||||
public int? Sex { get; set; }
|
||||
|
||||
public UserStateEnum Status { get; set; } = UserStateEnum.Enable;
|
||||
|
||||
public string OrganizationName { get; set; }
|
||||
public string PositionName { get; set; }
|
||||
|
||||
public string DepartmentName { get; set; }
|
||||
|
||||
[NotMapped]
|
||||
public List<UserRoleLogObj> UserRoleList { get; set; }
|
||||
|
||||
}
|
||||
|
||||
|
||||
public class UserRoleLogObj
|
||||
{
|
||||
public string UserTypeShortName { get; set; }
|
||||
|
||||
public UserTypeEnum UserTypeEnum { get; set; }
|
||||
|
||||
public bool IsUserRoleDisabled { get; set; }
|
||||
}
|
||||
|
|
|
@ -63,6 +63,15 @@ public class IRaCISDBContext : DbContext
|
|||
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||
{
|
||||
|
||||
modelBuilder.Entity<UserLog>(entity =>
|
||||
{
|
||||
entity.OwnsOne(x => x.JsonObj, ownedNavigationBuilder =>
|
||||
{
|
||||
ownedNavigationBuilder.ToJson();
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
modelBuilder.Entity<TestLength>(entity =>
|
||||
{
|
||||
// 使用部分加密值转换器,前 2 个字符不加密,方便模糊搜索
|
||||
|
|
18583
IRaCIS.Core.Infra.EFCore/Migrations/20241226064658_UserlogModifg7.Designer.cs
generated
Normal file
18583
IRaCIS.Core.Infra.EFCore/Migrations/20241226064658_UserlogModifg7.Designer.cs
generated
Normal file
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,223 @@
|
|||
using System;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace IRaCIS.Core.Infra.EFCore.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class UserlogModifg7 : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropForeignKey(
|
||||
name: "FK_UserLog_User_LoginUserId",
|
||||
table: "UserLog");
|
||||
|
||||
migrationBuilder.DropForeignKey(
|
||||
name: "FK_UserLog_User_OptUserId",
|
||||
table: "UserLog");
|
||||
|
||||
//migrationBuilder.DropIndex(
|
||||
// name: "IX_UserLog_LoginUserId",
|
||||
// table: "UserLog");
|
||||
|
||||
//migrationBuilder.DropIndex(
|
||||
// name: "IX_UserLog_OptUserId",
|
||||
// table: "UserLog");
|
||||
|
||||
migrationBuilder.AlterColumn<Guid>(
|
||||
name: "OptUserId",
|
||||
table: "UserLog",
|
||||
type: "uniqueidentifier",
|
||||
nullable: true,
|
||||
comment: "被操作的人,自己操作的就是自己--后续删除",
|
||||
oldClrType: typeof(Guid),
|
||||
oldType: "uniqueidentifier",
|
||||
oldNullable: true,
|
||||
oldComment: "被操作的人,自己操作的就是自己");
|
||||
|
||||
//migrationBuilder.AlterColumn<Guid>(
|
||||
// name: "LoginUserId",
|
||||
// table: "UserLog",
|
||||
// type: "uniqueidentifier",
|
||||
// nullable: true,
|
||||
// comment: "后续删除",
|
||||
// oldClrType: typeof(Guid),
|
||||
// oldType: "uniqueidentifier",
|
||||
// oldNullable: true);
|
||||
|
||||
migrationBuilder.AddColumn<Guid>(
|
||||
name: "ActionIdentityUserId",
|
||||
table: "UserLog",
|
||||
type: "uniqueidentifier",
|
||||
nullable: true);
|
||||
|
||||
migrationBuilder.AddColumn<string>(
|
||||
name: "ActionUserName",
|
||||
table: "UserLog",
|
||||
type: "nvarchar(400)",
|
||||
maxLength: 400,
|
||||
nullable: false,
|
||||
defaultValue: "");
|
||||
|
||||
//migrationBuilder.AddColumn<string>(
|
||||
// name: "JsonObj",
|
||||
// table: "UserLog",
|
||||
// type: "nvarchar(max)",
|
||||
// nullable: false,
|
||||
// defaultValue: "");
|
||||
|
||||
migrationBuilder.AddColumn<Guid>(
|
||||
name: "TargetIdentityUserId",
|
||||
table: "UserLog",
|
||||
type: "uniqueidentifier",
|
||||
nullable: true,
|
||||
comment: "被操作的对象 admin 修改张三信息 张三是被操作对象");
|
||||
|
||||
//migrationBuilder.AlterColumn<Guid>(
|
||||
// name: "SystemUserId",
|
||||
// table: "TrialSiteUserSurvey",
|
||||
// type: "uniqueidentifier",
|
||||
// nullable: true,
|
||||
// comment: "IdentityUser 表的用户Id",
|
||||
// oldClrType: typeof(Guid),
|
||||
// oldType: "uniqueidentifier",
|
||||
// oldNullable: true);
|
||||
|
||||
//migrationBuilder.AlterColumn<Guid>(
|
||||
// name: "SystemUserId",
|
||||
// table: "TrialExternalUser",
|
||||
// type: "uniqueidentifier",
|
||||
// nullable: false,
|
||||
// comment: "IdentityUser 表的用户Id",
|
||||
// oldClrType: typeof(Guid),
|
||||
// oldType: "uniqueidentifier");
|
||||
|
||||
//migrationBuilder.AlterColumn<bool>(
|
||||
// name: "AutoCutNextTask",
|
||||
// table: "IdentityUser",
|
||||
// type: "bit",
|
||||
// nullable: false,
|
||||
// comment: "这个字段废除,放在用户角色上面,后续删除",
|
||||
// oldClrType: typeof(bool),
|
||||
// oldType: "bit",
|
||||
// oldComment: "自动切换下一个任务");
|
||||
|
||||
//migrationBuilder.CreateIndex(
|
||||
// name: "IX_UserLog_TargetIdentityUserId",
|
||||
// table: "UserLog",
|
||||
// column: "TargetIdentityUserId");
|
||||
|
||||
//migrationBuilder.AddForeignKey(
|
||||
// name: "FK_UserLog_IdentityUser_TargetIdentityUserId",
|
||||
// table: "UserLog",
|
||||
// column: "TargetIdentityUserId",
|
||||
// principalTable: "IdentityUser",
|
||||
// principalColumn: "Id");
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropForeignKey(
|
||||
name: "FK_UserLog_IdentityUser_TargetIdentityUserId",
|
||||
table: "UserLog");
|
||||
|
||||
migrationBuilder.DropIndex(
|
||||
name: "IX_UserLog_TargetIdentityUserId",
|
||||
table: "UserLog");
|
||||
|
||||
migrationBuilder.DropColumn(
|
||||
name: "ActionIdentityUserId",
|
||||
table: "UserLog");
|
||||
|
||||
migrationBuilder.DropColumn(
|
||||
name: "ActionUserName",
|
||||
table: "UserLog");
|
||||
|
||||
migrationBuilder.DropColumn(
|
||||
name: "JsonObj",
|
||||
table: "UserLog");
|
||||
|
||||
migrationBuilder.DropColumn(
|
||||
name: "TargetIdentityUserId",
|
||||
table: "UserLog");
|
||||
|
||||
migrationBuilder.AlterColumn<Guid>(
|
||||
name: "OptUserId",
|
||||
table: "UserLog",
|
||||
type: "uniqueidentifier",
|
||||
nullable: true,
|
||||
comment: "被操作的人,自己操作的就是自己",
|
||||
oldClrType: typeof(Guid),
|
||||
oldType: "uniqueidentifier",
|
||||
oldNullable: true,
|
||||
oldComment: "被操作的人,自己操作的就是自己--后续删除");
|
||||
|
||||
migrationBuilder.AlterColumn<Guid>(
|
||||
name: "LoginUserId",
|
||||
table: "UserLog",
|
||||
type: "uniqueidentifier",
|
||||
nullable: true,
|
||||
oldClrType: typeof(Guid),
|
||||
oldType: "uniqueidentifier",
|
||||
oldNullable: true,
|
||||
oldComment: "后续删除");
|
||||
|
||||
migrationBuilder.AlterColumn<Guid>(
|
||||
name: "SystemUserId",
|
||||
table: "TrialSiteUserSurvey",
|
||||
type: "uniqueidentifier",
|
||||
nullable: true,
|
||||
oldClrType: typeof(Guid),
|
||||
oldType: "uniqueidentifier",
|
||||
oldNullable: true,
|
||||
oldComment: "IdentityUser 表的用户Id");
|
||||
|
||||
migrationBuilder.AlterColumn<Guid>(
|
||||
name: "SystemUserId",
|
||||
table: "TrialExternalUser",
|
||||
type: "uniqueidentifier",
|
||||
nullable: false,
|
||||
oldClrType: typeof(Guid),
|
||||
oldType: "uniqueidentifier",
|
||||
oldComment: "IdentityUser 表的用户Id");
|
||||
|
||||
migrationBuilder.AlterColumn<bool>(
|
||||
name: "AutoCutNextTask",
|
||||
table: "IdentityUser",
|
||||
type: "bit",
|
||||
nullable: false,
|
||||
comment: "自动切换下一个任务",
|
||||
oldClrType: typeof(bool),
|
||||
oldType: "bit",
|
||||
oldComment: "这个字段废除,放在用户角色上面,后续删除");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_UserLog_LoginUserId",
|
||||
table: "UserLog",
|
||||
column: "LoginUserId");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_UserLog_OptUserId",
|
||||
table: "UserLog",
|
||||
column: "OptUserId");
|
||||
|
||||
migrationBuilder.AddForeignKey(
|
||||
name: "FK_UserLog_User_LoginUserId",
|
||||
table: "UserLog",
|
||||
column: "LoginUserId",
|
||||
principalTable: "User",
|
||||
principalColumn: "Id");
|
||||
|
||||
migrationBuilder.AddForeignKey(
|
||||
name: "FK_UserLog_User_OptUserId",
|
||||
table: "UserLog",
|
||||
column: "OptUserId",
|
||||
principalTable: "User",
|
||||
principalColumn: "Id");
|
||||
}
|
||||
}
|
||||
}
|
|
@ -2704,7 +2704,7 @@ namespace IRaCIS.Core.Infra.EFCore.Migrations
|
|||
|
||||
b.Property<bool>("AutoCutNextTask")
|
||||
.HasColumnType("bit")
|
||||
.HasComment("自动切换下一个任务");
|
||||
.HasComment("这个字段废除,放在用户角色上面,后续删除");
|
||||
|
||||
b.Property<int>("Code")
|
||||
.HasColumnType("int");
|
||||
|
@ -11676,7 +11676,8 @@ namespace IRaCIS.Core.Infra.EFCore.Migrations
|
|||
.HasColumnType("nvarchar(400)");
|
||||
|
||||
b.Property<Guid>("SystemUserId")
|
||||
.HasColumnType("uniqueidentifier");
|
||||
.HasColumnType("uniqueidentifier")
|
||||
.HasComment("IdentityUser 表的用户Id");
|
||||
|
||||
b.Property<Guid>("TrialId")
|
||||
.HasColumnType("uniqueidentifier");
|
||||
|
@ -12585,7 +12586,8 @@ namespace IRaCIS.Core.Infra.EFCore.Migrations
|
|||
.HasColumnType("nvarchar(400)");
|
||||
|
||||
b.Property<Guid?>("SystemUserId")
|
||||
.HasColumnType("uniqueidentifier");
|
||||
.HasColumnType("uniqueidentifier")
|
||||
.HasComment("IdentityUser 表的用户Id");
|
||||
|
||||
b.Property<int?>("TrialRoleCode")
|
||||
.HasColumnType("int");
|
||||
|
@ -12939,6 +12941,14 @@ namespace IRaCIS.Core.Infra.EFCore.Migrations
|
|||
b.Property<Guid>("Id")
|
||||
.HasColumnType("uniqueidentifier");
|
||||
|
||||
b.Property<Guid?>("ActionIdentityUserId")
|
||||
.HasColumnType("uniqueidentifier");
|
||||
|
||||
b.Property<string>("ActionUserName")
|
||||
.IsRequired()
|
||||
.HasMaxLength(400)
|
||||
.HasColumnType("nvarchar(400)");
|
||||
|
||||
b.Property<DateTime>("CreateTime")
|
||||
.HasColumnType("datetime2");
|
||||
|
||||
|
@ -12966,22 +12976,25 @@ namespace IRaCIS.Core.Infra.EFCore.Migrations
|
|||
.HasColumnType("nvarchar(400)");
|
||||
|
||||
b.Property<Guid?>("LoginUserId")
|
||||
.HasColumnType("uniqueidentifier");
|
||||
.HasColumnType("uniqueidentifier")
|
||||
.HasComment("后续删除");
|
||||
|
||||
b.Property<int>("OptType")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<Guid?>("OptUserId")
|
||||
.HasColumnType("uniqueidentifier")
|
||||
.HasComment("被操作的人,自己操作的就是自己");
|
||||
.HasComment("被操作的人,自己操作的就是自己--后续删除");
|
||||
|
||||
b.Property<Guid?>("TargetIdentityUserId")
|
||||
.HasColumnType("uniqueidentifier")
|
||||
.HasComment("被操作的对象 admin 修改张三信息 张三是被操作对象");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("CreateUserId");
|
||||
|
||||
b.HasIndex("LoginUserId");
|
||||
|
||||
b.HasIndex("OptUserId");
|
||||
b.HasIndex("TargetIdentityUserId");
|
||||
|
||||
b.ToTable("UserLog", t =>
|
||||
{
|
||||
|
@ -17746,19 +17759,82 @@ namespace IRaCIS.Core.Infra.EFCore.Migrations
|
|||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("IRaCIS.Core.Domain.Models.UserRole", "LoginUser")
|
||||
b.HasOne("IRaCIS.Core.Domain.Models.IdentityUser", "TargetIdentityUser")
|
||||
.WithMany()
|
||||
.HasForeignKey("LoginUserId");
|
||||
.HasForeignKey("TargetIdentityUserId");
|
||||
|
||||
b.HasOne("IRaCIS.Core.Domain.Models.UserRole", "OptUser")
|
||||
.WithMany()
|
||||
.HasForeignKey("OptUserId");
|
||||
b.OwnsOne("IRaCIS.Core.Domain.Models.UserLogJsonObj", "JsonObj", b1 =>
|
||||
{
|
||||
b1.Property<Guid>("UserLogId")
|
||||
.HasColumnType("uniqueidentifier");
|
||||
|
||||
b1.Property<string>("DepartmentName")
|
||||
.IsRequired()
|
||||
.HasMaxLength(400)
|
||||
.HasColumnType("nvarchar(400)");
|
||||
|
||||
b1.Property<string>("EMail")
|
||||
.IsRequired()
|
||||
.HasMaxLength(400)
|
||||
.HasColumnType("nvarchar(400)");
|
||||
|
||||
b1.Property<string>("FirstName")
|
||||
.IsRequired()
|
||||
.HasMaxLength(400)
|
||||
.HasColumnType("nvarchar(400)");
|
||||
|
||||
b1.Property<string>("LastName")
|
||||
.IsRequired()
|
||||
.HasMaxLength(400)
|
||||
.HasColumnType("nvarchar(400)");
|
||||
|
||||
b1.Property<string>("OrganizationName")
|
||||
.IsRequired()
|
||||
.HasMaxLength(400)
|
||||
.HasColumnType("nvarchar(400)");
|
||||
|
||||
b1.Property<string>("Phone")
|
||||
.IsRequired()
|
||||
.HasMaxLength(400)
|
||||
.HasColumnType("nvarchar(400)");
|
||||
|
||||
b1.Property<string>("PositionName")
|
||||
.IsRequired()
|
||||
.HasMaxLength(400)
|
||||
.HasColumnType("nvarchar(400)");
|
||||
|
||||
b1.Property<int?>("Sex")
|
||||
.HasColumnType("int");
|
||||
|
||||
b1.Property<int>("Status")
|
||||
.HasColumnType("int");
|
||||
|
||||
b1.Property<string>("UserCode")
|
||||
.IsRequired()
|
||||
.HasMaxLength(400)
|
||||
.HasColumnType("nvarchar(400)");
|
||||
|
||||
b1.Property<string>("UserName")
|
||||
.IsRequired()
|
||||
.HasMaxLength(400)
|
||||
.HasColumnType("nvarchar(400)");
|
||||
|
||||
b1.HasKey("UserLogId");
|
||||
|
||||
b1.ToTable("UserLog");
|
||||
|
||||
b1.ToJson("JsonObj");
|
||||
|
||||
b1.WithOwner()
|
||||
.HasForeignKey("UserLogId");
|
||||
});
|
||||
|
||||
b.Navigation("CreateUserRole");
|
||||
|
||||
b.Navigation("LoginUser");
|
||||
b.Navigation("JsonObj")
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("OptUser");
|
||||
b.Navigation("TargetIdentityUser");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("IRaCIS.Core.Domain.Models.UserPassWordLog", b =>
|
||||
|
@ -17781,7 +17857,7 @@ namespace IRaCIS.Core.Infra.EFCore.Migrations
|
|||
.IsRequired();
|
||||
|
||||
b.HasOne("IRaCIS.Core.Domain.Models.Doctor", null)
|
||||
.WithOne("User")
|
||||
.WithOne("UserRole")
|
||||
.HasForeignKey("IRaCIS.Core.Domain.Models.UserRole", "DoctorId");
|
||||
|
||||
b.HasOne("IRaCIS.Core.Domain.Models.IdentityUser", "IdentityUser")
|
||||
|
@ -18132,7 +18208,7 @@ namespace IRaCIS.Core.Infra.EFCore.Migrations
|
|||
|
||||
b.Navigation("TrialExperienceCriteriaList");
|
||||
|
||||
b.Navigation("User")
|
||||
b.Navigation("UserRole")
|
||||
.IsRequired();
|
||||
});
|
||||
|
||||
|
|
Loading…
Reference in New Issue