diff --git a/IRaCIS.Core.Infra.EFCore/Common/AuditingData.cs b/IRaCIS.Core.Infra.EFCore/Common/AuditingData.cs index 02e9b3882..ac0c2741c 100644 --- a/IRaCIS.Core.Infra.EFCore/Common/AuditingData.cs +++ b/IRaCIS.Core.Infra.EFCore/Common/AuditingData.cs @@ -95,7 +95,7 @@ namespace IRaCIS.Core.Infra.EFCore.Common #region 所有 //foreach (var item in entitys) //{ - // await InsertInspection(item, type); + // await InsertInspection(item.Entity, type); //} #endregion @@ -114,7 +114,7 @@ namespace IRaCIS.Core.Infra.EFCore.Common var userTypeIds = userTypes.Select(x => x.NeedConfirmUserTypeId).ToList(); var usertypeNames = await _dbContext.UserType.Where(x => userTypeIds.Contains(x.Id)).Select(x => x.UserTypeShortName).ToListAsync(); var usertypeName = string.Join(",", usertypeNames); - await InsertInspection(item, type, x => new DataInspection() + await InsertInspection(item.Entity, type, x => new DataInspection() { GeneralId = x.Id }, new @@ -126,9 +126,7 @@ namespace IRaCIS.Core.Infra.EFCore.Common // 签名模板 foreach (var item in entitys.Where(x => x.Entity.GetType() == typeof(SystemBasicData))) { - var entity = item.Entity as SystemBasicData; - type = type + (entity.ParentId == null ? "/parent" : string.Empty); - await InsertInspection(item, type, x => new DataInspection() + await InsertInspection(item.Entity, type, x => new DataInspection() { GeneralId = x.Id, }); @@ -137,20 +135,7 @@ namespace IRaCIS.Core.Infra.EFCore.Common // 项目 foreach (var item in entitys.Where(x => x.Entity.GetType() == typeof(Trial))) { - var originalValues = item.OriginalValues.ToObject() as Trial; - switch (GetRequestUrl().ToLower()) - { - case "configtrialbasicinfo/configtrialbasicinfoconfirm": - type = type + "/" + originalValues.IsTrialBasicLogicConfirmed.ToString(); - break; - case "configtrialbasicinfo/configtrialprocessinfoconfirm": - type = type + "/" + originalValues.IsTrialProcessConfirmed.ToString(); - break; - case "configtrialbasicinfo/configtrialurgentinfoconfirm": - type = type + "/" + originalValues.IsTrialUrgentConfirmed.ToString(); - break; - } - + var entity = item.Entity as Trial; List trials = new List(); var trialids = new List(); @@ -167,7 +152,7 @@ namespace IRaCIS.Core.Infra.EFCore.Common trials = await this._dbContext.Dictionary.Where(x => trialids.Contains(x.Id)).Select(x => x.ValueCN).ToListAsync(); - await InsertInspection(item, type, x => new DataInspection() + await InsertInspection(item.Entity, type, x => new DataInspection() { TrialId = x.Id, @@ -191,7 +176,7 @@ namespace IRaCIS.Core.Infra.EFCore.Common { VisitPlanStatus = false; } - await InsertInspection(item, type, x => new DataInspection() + await InsertInspection(item.Entity, type, x => new DataInspection() { VisitStageId = x.Id, GeneralId = x.Id, @@ -215,7 +200,7 @@ namespace IRaCIS.Core.Infra.EFCore.Common var userTypeIds = userTypes.Select(x => x.NeedConfirmUserTypeId).ToList(); var usertypeNames = await _dbContext.UserType.Where(x => userTypeIds.Contains(x.Id)).Select(x => x.UserTypeShortName).ToListAsync(); var usertypeName = string.Join(",", usertypeNames); - await InsertInspection(item, type, x => new DataInspection() + await InsertInspection(item.Entity, type, x => new DataInspection() { GeneralId = x.Id }, new @@ -231,7 +216,7 @@ namespace IRaCIS.Core.Infra.EFCore.Common { var entity = item.Entity as SystemDocConfirmedUser; var systemDocument = await _dbContext.SystemDocument.Where(x => x.Id == entity.SystemDocumentId).FirstOrDefaultAsync(); - await InsertInspection(item, type, x => new DataInspection() + await InsertInspection(item.Entity, type, x => new DataInspection() { GeneralId = x.Id, }, new @@ -241,7 +226,7 @@ namespace IRaCIS.Core.Infra.EFCore.Common Name = systemDocument.Name, CreateTime = systemDocument.CreateTime, IsSigned = "是",// 是否签署 添加了就是签署了 - }, null); + }); } // 项目文件签署 @@ -251,7 +236,7 @@ namespace IRaCIS.Core.Infra.EFCore.Common var trialDocument = await _dbContext.TrialDocument.Where(x => x.Id == entity.TrialDocumentId).FirstOrDefaultAsync(); var trialid = trialDocument.TrialId; - await InsertInspection(item, type, x => new DataInspection() + await InsertInspection(item.Entity, type, x => new DataInspection() { TrialId = trialid, GeneralId = x.Id, @@ -261,13 +246,13 @@ namespace IRaCIS.Core.Infra.EFCore.Common Name = trialDocument.Name, CreateTime = trialDocument.CreateTime, IsSigned = "是",// 是否签署 添加了就是签署了 - }, null); + }); } // 医生 foreach (var item in entitys.Where(x => x.Entity.GetType() == typeof(Enroll))) { - await InsertInspection(item, type, x => new DataInspection() + await InsertInspection(item.Entity, type, x => new DataInspection() { GeneralId = x.Id, }); @@ -276,7 +261,7 @@ namespace IRaCIS.Core.Infra.EFCore.Common // 医生详情 foreach (var item in entitys.Where(x => x.Entity.GetType() == typeof(EnrollDetail))) { - await InsertInspection(item, type, x => new DataInspection() + await InsertInspection(item.Entity, type, x => new DataInspection() { GeneralId = x.Id, }); @@ -290,7 +275,7 @@ namespace IRaCIS.Core.Infra.EFCore.Common { entity.Site = await _dbContext.Site.Where(x => x.Id == entity.SiteId).FirstOrDefaultAsync(); } - await InsertInspection(item, type, x => new DataInspection() + await InsertInspection(item.Entity, type, x => new DataInspection() { GeneralId = x.Id, @@ -311,7 +296,7 @@ namespace IRaCIS.Core.Infra.EFCore.Common var entity = item.Entity as TrialUser; var user = await _dbContext.Users.Include(x => x.UserTypeRole).FirstOrDefaultAsync(x => x.Id == entity.UserId); - await InsertInspection(item, type, x => new DataInspection + await InsertInspection(item.Entity, type, x => new DataInspection { TrialId = x.TrialId, }, new @@ -358,7 +343,7 @@ namespace IRaCIS.Core.Infra.EFCore.Common UserType userType = new UserType(); userType = await _dbContext.UserType.Where(x => x.Id == user.UserTypeId).FirstOrDefaultAsync(); - await InsertInspection(item, type, x => new DataInspection() + await InsertInspection(item.Entity, type, x => new DataInspection() { GeneralId = x.Id, }, new @@ -398,7 +383,7 @@ namespace IRaCIS.Core.Infra.EFCore.Common entity.ReviewerUser = await _dbContext.User.Where(x => x.Id == entity.ReviewerUserId).FirstOrDefaultAsync(); } - await InsertInspection(item, type, x => new DataInspection() + await InsertInspection(item.Entity, type, x => new DataInspection() { GeneralId = x.Id, @@ -420,7 +405,7 @@ namespace IRaCIS.Core.Infra.EFCore.Common { var entity = item.Entity as TrialQCQuestion; var paretName = await _dbContext.TrialQCQuestionConfigure.Where(x => x.Id == entity.ParentId).Select(x => x.QuestionName).FirstOrDefaultAsync(); - await InsertInspection(item, type, x => new DataInspection() + await InsertInspection(item.Entity, type, x => new DataInspection() { GeneralId = x.Id, }, new @@ -443,7 +428,7 @@ namespace IRaCIS.Core.Infra.EFCore.Common var entity = item.Entity as Subject; var FinalSubjectVisitName = await _dbContext.SubjectVisit.AsNoTracking().Where(x => x.Id == entity.FinalSubjectVisitId && entity.FinalSubjectVisitId != null).Select(x => x.VisitName).FirstOrDefaultAsync(); - await InsertInspection(item, type, x => new DataInspection() + await InsertInspection(item.Entity, type, x => new DataInspection() { SubjectId = x.Id, SubjectCode = x.Code, @@ -456,7 +441,7 @@ namespace IRaCIS.Core.Infra.EFCore.Common // 检查 foreach (var item in entitys.Where(x => x.Entity.GetType() == typeof(DicomStudy))) { - await InsertInspection(item, type, x => new DataInspection() + await InsertInspection(item.Entity, type, x => new DataInspection() { GeneralId = x.Id, }); @@ -471,7 +456,7 @@ namespace IRaCIS.Core.Infra.EFCore.Common { dicomStudy = await _dbContext.DicomStudys.AsNoTracking().FirstOrDefaultAsync(x => x.Id == entity.StudyId); } - await InsertInspection(item, type, x => new DataInspection() + await InsertInspection(item.Entity, type, x => new DataInspection() { GeneralId = x.Id, }, new @@ -487,14 +472,9 @@ namespace IRaCIS.Core.Infra.EFCore.Common { var entity = item.Entity as NoneDicomStudy; var filecount = await _dbContext.NoneDicomStudyFile.Where(x => x.NoneDicomStudyId == entity.Id).CountAsync(); - switch (GetRequestUrl().ToLower()) - { - case "nonedicomstudy/addorupdatenonedicomstudy": - type = _userInfo.UserTypeShortName + "/" + type; - break; - } + - await InsertInspection(item, type, x => new DataInspection() + await InsertInspection(item.Entity, type, x => new DataInspection() { GeneralId = x.Id, }, new @@ -521,13 +501,13 @@ namespace IRaCIS.Core.Infra.EFCore.Common filecount = filecount + count; } - await InsertInspection(null, type, x => new DataInspection() + await InsertInspection(noneDicomStudy, type, x => new DataInspection() { GeneralId = x.Id, }, new { FileCount = filecount, - }, noneDicomStudy); + }); } } @@ -553,7 +533,7 @@ namespace IRaCIS.Core.Infra.EFCore.Common // { // fileCount = _dbContext.NoneDicomStudyFile.Where(x => x.NoneDicomStudyId == entity.NoneDicomStudyId).Count() - 1; // } - // await InsertInspection(item, type, x => new DataInspection() + // await InsertInspection(item.Entity, type, x => new DataInspection() // { // GeneralId = x.Id, // TrialId = noneDicomStudy.TrialId, @@ -578,19 +558,19 @@ namespace IRaCIS.Core.Infra.EFCore.Common //一致性核查 foreach (var item in entitys.Where(x => x.Entity.GetType() == typeof(CheckChallengeDialog))) { - type = _userInfo.UserTypeShortName + "/" + type; + var entity = item.Entity as CheckChallengeDialog; var subjectvisit = await _dbContext.SubjectVisit.Where(x => x.Id == entity.SubjectVisitId).FirstOrDefaultAsync(); subjectvisit = subjectvisit ?? new SubjectVisit(); var reason = string.Empty; - switch (GetRequestUrl().ToLower()) + switch (_userInfo.RequestUrl.ToLower()) { case "qcoperation/closecheckchallenge": reason = entity.TalkContent.Substring(entity.TalkContent.LastIndexOf(':') + 1); break; } - await InsertInspection(item, type, x => new DataInspection() + await InsertInspection(item.Entity, type, x => new DataInspection() { GeneralId = entity.SubjectVisitId, TrialId = subjectvisit.TrialId, @@ -615,31 +595,14 @@ namespace IRaCIS.Core.Infra.EFCore.Common var entity = item.Entity as SubjectVisit; string reason = string.Empty; - switch (GetRequestUrl().ToLower()) + if (_userInfo.RequestUrl.ToLower() == "qcoperation/setcheckpass") { - case "qcoperation/obtainorcancelqctask": - type = type + "/" + entity.IsTake.ToString(); - break; - // 设置通过一致性核查 - case "qcoperation/setcheckpass": - reason = entity.ManualPassReason; - break; - case "qcoperation/qcpassedorfailed": - try - { - type = type + "/" + (40 % (int)entity.AuditState).ToString(); - } - catch (Exception) - { - - - } - - break; + reason = entity.ManualPassReason; } + var subjectCode = entity.Subject?.Code; - await InsertInspection(item, type, x => new DataInspection() + await InsertInspection(item.Entity, type, x => new DataInspection() { SubjectCode = subjectCode, SubjectId = x.SubjectId, @@ -656,7 +619,7 @@ namespace IRaCIS.Core.Infra.EFCore.Common var entity = item.Entity as PreviousSurgery; var subjectvisit = await _dbContext.SubjectVisit.Where(x => x.Id == entity.SubjectVisitId).FirstOrDefaultAsync(); subjectvisit = subjectvisit ?? new SubjectVisit(); - await InsertInspection(item, type, x => new DataInspection() + await InsertInspection(item.Entity, type, x => new DataInspection() { GeneralId = x.Id, SiteId = subjectvisit.SiteId, @@ -676,7 +639,7 @@ namespace IRaCIS.Core.Infra.EFCore.Common var entity = item.Entity as PreviousHistory; var subjectvisit = await _dbContext.SubjectVisit.Where(x => x.Id == entity.SubjectVisitId).FirstOrDefaultAsync(); subjectvisit = subjectvisit ?? new SubjectVisit(); - await InsertInspection(item, type, x => new DataInspection() + await InsertInspection(item.Entity, type, x => new DataInspection() { GeneralId = x.Id, SiteId = subjectvisit.SiteId, @@ -695,7 +658,7 @@ namespace IRaCIS.Core.Infra.EFCore.Common var entity = item.Entity as PreviousOther; var subjectvisit = await _dbContext.SubjectVisit.Where(x => x.Id == entity.SubjectVisitId).FirstOrDefaultAsync(); subjectvisit = subjectvisit ?? new SubjectVisit(); - await InsertInspection(item, type, x => new DataInspection() + await InsertInspection(item.Entity, type, x => new DataInspection() { GeneralId = x.Id, SiteId = subjectvisit.SiteId, @@ -712,7 +675,7 @@ namespace IRaCIS.Core.Infra.EFCore.Common foreach (var item in entitys.Where(x => x.Entity.GetType() == typeof(QCChallenge))) { var entity = item.Entity as QCChallenge; - type = _userInfo.UserTypeShortName + "/" + type; + var subjectvisit = await _dbContext.SubjectVisit.Where(x => x.Id == entity.SubjectVisitId).FirstOrDefaultAsync(); subjectvisit = subjectvisit ?? new SubjectVisit(); var content = string.Empty; @@ -720,7 +683,7 @@ namespace IRaCIS.Core.Infra.EFCore.Common { content = entity.Content; } - await InsertInspection(item, type, x => new DataInspection() + await InsertInspection(item.Entity, type, x => new DataInspection() { GeneralId = x.Id, TrialId = x.TrialId, @@ -743,18 +706,18 @@ namespace IRaCIS.Core.Infra.EFCore.Common { var reason = string.Empty; var entity = item.Entity as QCChallengeDialog; - switch (GetRequestUrl().ToLower()) + switch (_userInfo.RequestUrl.ToLower()) { case "qcoperation/closeqcchallenge": reason = entity.TalkContent.Substring(entity.TalkContent.LastIndexOf(':') + 1); break; } - type = _userInfo.UserTypeShortName + "/" + type; + var subjectvisit = await _dbContext.SubjectVisit.Where(x => x.Id == entity.SubjectVisitId).FirstOrDefaultAsync(); var qCChallenge = await _dbContext.QCChallenge.Where(x => x.Id == entity.QCChallengeId).FirstOrDefaultAsync(); subjectvisit = subjectvisit ?? new SubjectVisit(); qCChallenge = qCChallenge ?? new QCChallenge(); - await InsertInspection(item, type, x => new DataInspection() + await InsertInspection(item.Entity, type, x => new DataInspection() { GeneralId = qCChallenge.Id, TrialId = subjectvisit.TrialId, @@ -780,7 +743,7 @@ namespace IRaCIS.Core.Infra.EFCore.Common //Qc 问题 foreach (var item in entitys.Where(x => x.Entity.GetType() == typeof(QCQuestion))) { - await InsertInspection(item, type, x => new DataInspection() + await InsertInspection(item.Entity, type, x => new DataInspection() { GeneralId = x.Id, }); @@ -855,7 +818,7 @@ namespace IRaCIS.Core.Infra.EFCore.Common // var subjectvisit = await _dbContext.SubjectVisit.Where(x => x.Id == entity.SubjectVisitId).FirstOrDefaultAsync(); // subjectvisit = subjectvisit ?? new SubjectVisit(); // type = type == "Update" ? "Add" : type; - // await InsertInspection(item, type, x => new DataInspection() + // await InsertInspection(item.Entity, type, x => new DataInspection() // { // SiteId= subjectvisit.SiteId, // SubjectId= subjectvisit.SubjectId, @@ -873,21 +836,20 @@ namespace IRaCIS.Core.Infra.EFCore.Common /// 插入稽查实体 /// /// 泛型 - /// 数据 EF 跟踪实体信息 - /// 类型 Add|Update|delete - /// 表达式 稽查实体部分字段赋值 - /// 实体对象 添加到稽查记录详细Json 匿名对象 - /// 实体名称 + /// 数据 + /// 类型 + /// 表达式 + /// 其他对象 /// - public async Task InsertInspection(EntityEntry data, string type, Expression> expression = null, object otherItem = null, T entityData = null) where T : class + public async Task InsertInspection(object data, string type, Expression> expression = null, object otherItem = null,object originaldata=null) where T : class { - object entityobj = entityData == null ? data.Entity : entityData; + object entityobj = data; DataInspection inspection = new DataInspection(); if (expression != null) { var f = expression.Compile(); - var entity = entityobj as T; - inspection = f(entity); + var entitydata = entityobj as T; + inspection = f(entitydata); } var entityTypeName = entityobj.GetType().Name; @@ -900,6 +862,63 @@ namespace IRaCIS.Core.Infra.EFCore.Common + dynamic entity; + switch (entityobj.GetType().Name) + { + case nameof(QCChallengeDialog): + case nameof(QCChallenge): + case nameof(CheckChallengeDialog): + type = type + "/(" + _userInfo.UserTypeShortName + ")"; + break; + + case nameof(NoneDicomStudy): + switch (_userInfo.RequestUrl.ToLower()) + { + case "nonedicomstudy/addorupdatenonedicomstudy": + type = type + "/("+ _userInfo.UserTypeShortName + ")"; + break; + } + break; + case nameof(SystemBasicData): + entity = entityobj as SystemBasicData; + type = type + (entity.ParentId == null ? "/parent" : string.Empty); + break; + case nameof(Trial): + entity = originaldata as Trial; + switch (_userInfo.RequestUrl.ToLower()) + { + case "configtrialbasicinfo/configtrialbasicinfoconfirm": + type = type + "/" + entity.IsTrialBasicLogicConfirmed.ToString(); + break; + case "configtrialbasicinfo/configtrialprocessinfoconfirm": + type = type + "/" + entity.IsTrialProcessConfirmed.ToString(); + break; + case "configtrialbasicinfo/configtrialurgentinfoconfirm": + type = type + "/" + entity.IsTrialUrgentConfirmed.ToString(); + break; + } + break; + case nameof(SubjectVisit): + entity = originaldata as SubjectVisit; + switch (_userInfo.RequestUrl.ToLower()) + { + case "qcoperation/obtainorcancelqctask": + type = type + "/" + entity.IsTake.ToString(); + break; + case "qcoperation/qcpassedorfailed": + try + { + type = type + "/" + (40 % (int)entity.AuditState).ToString(); + } + catch (Exception) + { + } + break; + } + break; + } + + inspection.Identification = $"{_userInfo.RequestUrl}/{ entityTypeName}/{type}"; @@ -926,10 +945,10 @@ namespace IRaCIS.Core.Infra.EFCore.Common /// 获取URl参数 /// /// - public string GetRequestUrl() - { - return _userInfo.RequestUrl; - } + //public string GetRequestUrl() + //{ + // return _userInfo.RequestUrl; + //} /// /// 映射数据