修改日志记录
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
parent
e38219a0ee
commit
9de6a3c813
|
|
@ -84,6 +84,8 @@ namespace IRaCIS.Core.API
|
|||
|
||||
triggerOptions.AddTrigger<IdenttiyUserRoleInfoTrigger>();
|
||||
|
||||
triggerOptions.AddTrigger<UserLogAfterTrigger>();
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -38,41 +38,6 @@ namespace IRaCIS.Core.Application.ViewModel
|
|||
public UserLogJsonObj UserObj => JsonObj.IsNotNullOrEmpty() ? JsonConvert.DeserializeObject<UserLogJsonObj>(JsonObj) : new UserLogJsonObj();
|
||||
}
|
||||
|
||||
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; }
|
||||
|
||||
public List<UserRoleLogObj> UserRoleList { get; set; }
|
||||
|
||||
}
|
||||
|
||||
public class UserRoleLogObj
|
||||
{
|
||||
public string UserTypeShortName { get; set; }
|
||||
|
||||
public UserTypeEnum UserTypeEnum { get; set; }
|
||||
|
||||
public bool IsUserRoleDisabled { get; set; }
|
||||
}
|
||||
|
||||
|
||||
public class SetIsIgnoreUncommonlyInDto
|
||||
|
|
|
|||
|
|
@ -0,0 +1,84 @@
|
|||
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
|
||||
{
|
||||
/// <summary>
|
||||
/// 账户日志 记录账户每次操作的信息
|
||||
/// </summary>
|
||||
/// <param name="_identityUserRepository"></param>
|
||||
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)
|
||||
{
|
||||
|
||||
//判断是否需要记录详情
|
||||
|
||||
if (userlog.OptType == UserOptType.AddUser || userlog.OptType == UserOptType.UpdateUser || userlog.OptType == UserOptType.UpdateUserRole
|
||||
|| userlog.OptType == UserOptType.AccountEnable || userlog.OptType == UserOptType.AccountLocked)
|
||||
{
|
||||
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(),
|
||||
|
||||
HospitalGroupList = t.IdentityUserHospitalGroupList.Select(t => new HospitalGroupLogObj()
|
||||
{
|
||||
HospitalGroupId = t.HospitalGroupId,
|
||||
Code = t.HospitalGroup.Code,
|
||||
Name = t.HospitalGroup.Name,
|
||||
}).ToList(),
|
||||
|
||||
}).FirstOrDefaultAsync();
|
||||
|
||||
|
||||
|
||||
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();
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -64,3 +64,49 @@ public class UserLog : BaseAddAuditEntity
|
|||
|
||||
}
|
||||
|
||||
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; }
|
||||
|
||||
public List<UserRoleLogObj> UserRoleList { get; set; }
|
||||
|
||||
public List<HospitalGroupLogObj> HospitalGroupList { get; set; }
|
||||
|
||||
}
|
||||
|
||||
|
||||
public class UserRoleLogObj
|
||||
{
|
||||
public string UserTypeShortName { get; set; }
|
||||
|
||||
public UserTypeEnum UserTypeEnum { get; set; }
|
||||
|
||||
public bool IsUserRoleDisabled { get; set; }
|
||||
}
|
||||
|
||||
public class HospitalGroupLogObj
|
||||
{
|
||||
public Guid HospitalGroupId { get; set; }
|
||||
public string Name { get; set; }
|
||||
|
||||
public string Code { get; set; }
|
||||
}
|
||||
Loading…
Reference in New Issue