diff --git a/IRaCIS.Core.API/Controllers/StudyController.cs b/IRaCIS.Core.API/Controllers/StudyController.cs index c58a5cffa..68212e428 100644 --- a/IRaCIS.Core.API/Controllers/StudyController.cs +++ b/IRaCIS.Core.API/Controllers/StudyController.cs @@ -10,19 +10,14 @@ using System.Threading.Tasks; using IRaCIS.Core.Application.Contracts.Dicom; using System.IO; using System.IO.Compression; -using IRaCIS.Core.Application.Dicom; using Microsoft.Extensions.Logging; using IRaCIS.Core.Application.Filter; using IRaCIS.Core.Infrastructure.Extention; using EasyCaching.Core; -using IRaCIS.Core.Infra.EFCore; using IRaCIS.Core.Application.Contracts; using IRaCIS.Core.Domain.Models; using IRaCIS.Core.Application.Service.Inspection.Interface; -using Newtonsoft.Json; -using IRaCIS.Core.Application.Service.Inspection.DTO; using IRaCIS.Core.Domain.Share; -using IRaCIS.Core.Domain.Common; namespace IRaCIS.Api.Controllers { diff --git a/IRaCIS.Core.Application/Service/Management/UserService.cs b/IRaCIS.Core.Application/Service/Management/UserService.cs index 89cfe5ef3..c12c4209b 100644 --- a/IRaCIS.Core.Application/Service/Management/UserService.cs +++ b/IRaCIS.Core.Application/Service/Management/UserService.cs @@ -87,7 +87,7 @@ namespace IRaCIS.Application.Services } - if (dbUser.Password == oldPwd) + if (dbUser.Password != oldPwd) { throw new BusinessValidationFailedException("旧密码验证失败。"); } diff --git a/IRaCIS.Core.Application/Triggers/SubjectVisitTrigger.cs b/IRaCIS.Core.Application/Triggers/SubjectVisitTrigger.cs index bd4dc587e..887a6a9b0 100644 --- a/IRaCIS.Core.Application/Triggers/SubjectVisitTrigger.cs +++ b/IRaCIS.Core.Application/Triggers/SubjectVisitTrigger.cs @@ -1,5 +1,4 @@ using EntityFrameworkCore.Triggered; -using IRaCIS.Core.Domain.Common; using IRaCIS.Core.Domain.Share; namespace IRaCIS.Core.Application.Triggers diff --git a/IRaCIS.Core.Domain/Common/JsonConvert.cs b/IRaCIS.Core.Domain/Common/JsonConvert.cs deleted file mode 100644 index 6d0d0cadd..000000000 --- a/IRaCIS.Core.Domain/Common/JsonConvert.cs +++ /dev/null @@ -1,29 +0,0 @@ -using Newtonsoft.Json; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Text.Json; -using System.Threading.Tasks; - -namespace IRaCIS.Core.Domain.Common -{ - public static class JJsonConvert - { - /// - /// 将对象序列化成稽查需要的Json字符串 - /// - /// 需要序列化的对象 - /// - public static string ToJcJson(this object obj) - { - //JsonSerializerSettings settings = new JsonSerializerSettings(); - //settings.PreserveReferencesHandling = PreserveReferencesHandling.Objects; - //settings.ReferenceLoopHandling = ReferenceLoopHandling.Serialize; - //return JsonConvert.SerializeObject(obj, settings); - - - return JsonConvert.SerializeObject(obj); - } - } -} diff --git a/IRaCIS.Core.Infra.EFCore/Common/AuditingData.cs b/IRaCIS.Core.Infra.EFCore/Common/AuditingData.cs index 597165fc5..eb620b330 100644 --- a/IRaCIS.Core.Infra.EFCore/Common/AuditingData.cs +++ b/IRaCIS.Core.Infra.EFCore/Common/AuditingData.cs @@ -1,5 +1,4 @@ -using IRaCIS.Core.Domain.Common; -using IRaCIS.Core.Domain.Models; +using IRaCIS.Core.Domain.Models; using IRaCIS.Core.Domain.Share; using IRaCIS.Core.Infra.EFCore.Common.Dto; using IRaCIS.Core.Infrastructure; @@ -51,8 +50,8 @@ namespace IRaCIS.Core.Infra.EFCore.Common { // 修改 await InsertAddEntitys( - entitys.Where(x => x.State == EntityState.Modified && - (!typeof(ISoftDelete).IsAssignableFrom(x.Entity.GetType())|| !(bool)x.Entity.GetType().GetProperty("IsDeleted").GetValue(x.Entity)|| NodeleteTableTypes.Contains(x.Entity.GetType())) + entitys.Where(x => x.State == EntityState.Modified && + (!typeof(ISoftDelete).IsAssignableFrom(x.Entity.GetType()) || !(bool)x.Entity.GetType().GetProperty("IsDeleted").GetValue(x.Entity) || NodeleteTableTypes.Contains(x.Entity.GetType())) ).ToList(), "Update"); // 新增 @@ -60,7 +59,7 @@ namespace IRaCIS.Core.Infra.EFCore.Common // 删除 await InsertAddEntitys(entitys.Where(x => x.State == EntityState.Deleted - || (typeof(ISoftDelete).IsAssignableFrom(x.Entity.GetType()) && (bool)x.Entity.GetType().GetProperty("IsDeleted").GetValue(x.Entity)&&x.State==EntityState.Modified&& !NodeleteTableTypes.Contains(x.Entity.GetType())) + || (typeof(ISoftDelete).IsAssignableFrom(x.Entity.GetType()) && (bool)x.Entity.GetType().GetProperty("IsDeleted").GetValue(x.Entity) && x.State == EntityState.Modified && !NodeleteTableTypes.Contains(x.Entity.GetType())) ).ToList(), "Deleted"); @@ -77,7 +76,7 @@ namespace IRaCIS.Core.Infra.EFCore.Common { get { - return new List() + return new List() { typeof(TrialUser), typeof(TrialSiteSurvey), @@ -92,7 +91,7 @@ namespace IRaCIS.Core.Infra.EFCore.Common /// 插入Add的实体 /// /// - public async Task InsertAddEntitys(List entitys,string type) + public async Task InsertAddEntitys(List entitys, string type) { @@ -121,8 +120,9 @@ namespace IRaCIS.Core.Infra.EFCore.Common await InsertInspection(item, type, x => new DataInspection() { GeneralId = x.Id - },new { - NeedConfirmedUserType= usertypeName, + }, new + { + NeedConfirmedUserType = usertypeName, }); } @@ -156,29 +156,30 @@ namespace IRaCIS.Core.Infra.EFCore.Common var entity = item.Entity as Trial; List trials = new List(); - var trialids =new List(); - if (entity.TrialDicList == null|| entity.TrialDicList.Count==0) + var trialids = new List(); + if (entity.TrialDicList == null || entity.TrialDicList.Count == 0) { - trialids = await this._dbContext.TrialDictionary.Where(x => x.TrialId == entity.Id&&x.KeyName== "Criterion").Select(x => x.DictionaryId).ToListAsync(); - + trialids = await this._dbContext.TrialDictionary.Where(x => x.TrialId == entity.Id && x.KeyName == "Criterion").Select(x => x.DictionaryId).ToListAsync(); + } else { - trialids = entity.TrialDicList.Select(x => x.DictionaryId).ToList(); - + trialids = entity.TrialDicList.Select(x => x.DictionaryId).ToList(); + } - trials = await this._dbContext.Dictionary.Where(x => trialids.Contains(x.Id)).Select(x => x.ValueCN).ToListAsync(); + trials = await this._dbContext.Dictionary.Where(x => trialids.Contains(x.Id)).Select(x => x.ValueCN).ToListAsync(); await InsertInspection(item, type, x => new DataInspection() { TrialId = x.Id, TrialName = x.ExperimentName, - ResearchProgramNo=x.ResearchProgramNo, + ResearchProgramNo = x.ResearchProgramNo, GeneralId = x.Id, - },new { - TrialDicList= string.Join(",", trials) + }, new + { + TrialDicList = string.Join(",", trials) }); } @@ -188,7 +189,7 @@ namespace IRaCIS.Core.Infra.EFCore.Common var entity = item.Entity as VisitStage; - var VisitPlanStatus =await this._dbContext.Trial.Where(x => x.Id == entity.TrialId).Select(x => x.VisitPlanConfirmed).FirstOrDefaultAsync(); + var VisitPlanStatus = await this._dbContext.Trial.Where(x => x.Id == entity.TrialId).Select(x => x.VisitPlanConfirmed).FirstOrDefaultAsync(); if (type == "Add") { VisitPlanStatus = false; @@ -196,9 +197,10 @@ namespace IRaCIS.Core.Infra.EFCore.Common await InsertInspection(item, type, x => new DataInspection() { VisitStageId = x.Id, - GeneralId=x.Id, - },new { - VisitPlanStatus= VisitPlanStatus, + GeneralId = x.Id, + }, new + { + VisitPlanStatus = VisitPlanStatus, }); } @@ -224,23 +226,24 @@ namespace IRaCIS.Core.Infra.EFCore.Common NeedConfirmedUserType = usertypeName, }); - + } // 系统文件签署 foreach (var item in entitys.Where(x => x.Entity.GetType() == typeof(SystemDocConfirmedUser))) { var entity = item.Entity as SystemDocConfirmedUser; - var systemDocument= await _dbContext.SystemDocument.Where(x => x.Id == entity.SystemDocumentId).FirstOrDefaultAsync(); + var systemDocument = await _dbContext.SystemDocument.Where(x => x.Id == entity.SystemDocumentId).FirstOrDefaultAsync(); await InsertInspection(item, type, x => new DataInspection() { GeneralId = x.Id, - },new { + }, new + { - FileTypeId= systemDocument.FileTypeId, + FileTypeId = systemDocument.FileTypeId, Name = systemDocument.Name, - CreateTime=systemDocument.CreateTime, - IsSigned="是",// 是否签署 添加了就是签署了 + CreateTime = systemDocument.CreateTime, + IsSigned = "是",// 是否签署 添加了就是签署了 }, null, "UserSigned"); } @@ -253,14 +256,15 @@ namespace IRaCIS.Core.Infra.EFCore.Common var trialid = trialDocument.TrialId; await InsertInspection(item, type, x => new DataInspection() { - TrialId= trialid, + TrialId = trialid, GeneralId = x.Id, - },new { + }, new + { FileTypeId = trialDocument.FileTypeId, Name = trialDocument.Name, CreateTime = trialDocument.CreateTime, IsSigned = "是",// 是否签署 添加了就是签署了 - },null, "UserSigned"); + }, null, "UserSigned"); } // 医生 @@ -287,20 +291,20 @@ namespace IRaCIS.Core.Infra.EFCore.Common var entity = item.Entity as TrialSite; if (entity.Site == null) { - entity.Site =await _dbContext.Site.Where(x => x.Id == entity.SiteId).FirstOrDefaultAsync(); + entity.Site = await _dbContext.Site.Where(x => x.Id == entity.SiteId).FirstOrDefaultAsync(); } await InsertInspection(item, type, x => new DataInspection() { GeneralId = x.Id, - - },new + + }, new { TrialSiteCode = entity.TrialSiteCode, - SiteName= entity.Site.SiteName, - SiteAliasName= entity.TrialSiteAliasName, - City= entity.Site.City, - Country= entity.Site.Country, - Status= entity.IsDeleted?"禁用":"启用", + SiteName = entity.Site.SiteName, + SiteAliasName = entity.TrialSiteAliasName, + City = entity.Site.City, + Country = entity.Site.Country, + Status = entity.IsDeleted ? "禁用" : "启用", }); } @@ -356,7 +360,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() { GeneralId = x.Id, @@ -384,7 +388,7 @@ namespace IRaCIS.Core.Infra.EFCore.Common var entity = item.Entity as TrialSiteSurvey; if (entity.TrialSite == null) { - entity.TrialSite = await _dbContext.TrialSite.Where(x => x.SiteId == entity.SiteId&&x.TrialId== entity.TrialId).FirstOrDefaultAsync(); + entity.TrialSite = await _dbContext.TrialSite.Where(x => x.SiteId == entity.SiteId && x.TrialId == entity.TrialId).FirstOrDefaultAsync(); } if (entity.PreliminaryUser == null) @@ -400,16 +404,17 @@ namespace IRaCIS.Core.Infra.EFCore.Common await InsertInspection(item, type, x => new DataInspection() { GeneralId = x.Id, - - },new { + + }, new + { TrialSiteCode = entity.TrialSite.TrialSiteCode, TrialSiteAliasName = entity.TrialSite.TrialSiteAliasName, - Phone= entity.Phone, - Email=entity.Email, - PreliminaryUser= entity.PreliminaryUser==null?"": entity.PreliminaryUser.LastName + " / " + entity.PreliminaryUser.FirstName, + Phone = entity.Phone, + Email = entity.Email, + PreliminaryUser = entity.PreliminaryUser == null ? "" : entity.PreliminaryUser.LastName + " / " + entity.PreliminaryUser.FirstName, ReviewerUser = entity.ReviewerUser == null ? "" : entity.ReviewerUser.LastName + " / " + entity.ReviewerUser.FirstName, - IsDeleted=entity.IsDeleted ? "是" : "否", + IsDeleted = entity.IsDeleted ? "是" : "否", }); } @@ -421,16 +426,17 @@ namespace IRaCIS.Core.Infra.EFCore.Common await InsertInspection(item, type, x => new DataInspection() { GeneralId = x.Id, - },new { - QuestionName= entity.QuestionName, - Type= entity.Type, - TypeValue=entity.TypeValue, - ShowOrder=entity.ShowOrder, - IsRequired= entity.IsRequired, - ParentName= paretName, - ParentTriggerValue=entity.ParentTriggerValue, - IsEnable=entity.IsEnable, - IsQCQuestionConfirmed= entity.IsConfirm, + }, new + { + QuestionName = entity.QuestionName, + Type = entity.Type, + TypeValue = entity.TypeValue, + ShowOrder = entity.ShowOrder, + IsRequired = entity.IsRequired, + ParentName = paretName, + ParentTriggerValue = entity.ParentTriggerValue, + IsEnable = entity.IsEnable, + IsQCQuestionConfirmed = entity.IsConfirm, }); } @@ -438,12 +444,12 @@ namespace IRaCIS.Core.Infra.EFCore.Common foreach (var item in entitys.Where(x => x.Entity.GetType() == typeof(Subject))) { 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(); + 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() { SubjectId = x.Id, - SubjectCode=x.Code, + SubjectCode = x.Code, }, new { FinalSubjectVisitName = FinalSubjectVisitName, @@ -577,9 +583,9 @@ namespace IRaCIS.Core.Infra.EFCore.Common switch (GetRequestUrl().ToLower()) { case "qcoperation/obtainorcancelqctask": - type = type +"/"+ entity.IsTake.ToString(); + type = type + "/" + entity.IsTake.ToString(); break; - // 设置通过一致性核查 + // 设置通过一致性核查 case "qcoperation/setcheckpass": reason = entity.ManualPassReason; break; @@ -591,21 +597,21 @@ namespace IRaCIS.Core.Infra.EFCore.Common catch (Exception) { - + } - + break; } var subjectCode = entity.Subject?.Code; await InsertInspection(item, type, x => new DataInspection() { - SubjectCode= subjectCode, - SubjectId=x.SubjectId, + SubjectCode = subjectCode, + SubjectId = x.SubjectId, SubjectVisitId = x.Id, - SubjectVisitName=x.VisitName, - BlindName=x.BlindName, - Reason= reason, + SubjectVisitName = x.VisitName, + BlindName = x.BlindName, + Reason = reason, }); } @@ -671,7 +677,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; + type = _userInfo.UserTypeShortName + "/" + type; var subjectvisit = await _dbContext.SubjectVisit.Where(x => x.Id == entity.SubjectVisitId).FirstOrDefaultAsync(); subjectvisit = subjectvisit ?? new SubjectVisit(); var content = string.Empty; @@ -682,17 +688,18 @@ namespace IRaCIS.Core.Infra.EFCore.Common await InsertInspection(item, type, x => new DataInspection() { GeneralId = x.Id, - TrialId=x.TrialId, - SubjectVisitId=x.SubjectVisitId, - SiteId= subjectvisit.SiteId, - SubjectId= subjectvisit.SubjectId, - SubjectVisitName= subjectvisit.VisitName, - BlindName= subjectvisit.BlindName, - },new { - ChallengeCode= "Q" + entity.ChallengeCode.ToString("D5"), - AuditState= subjectvisit.AuditState, - TalkContent= content, - IsOverTime= entity.IsClosed ? entity.ClosedTime > entity.DeadlineTime : DateTime.Now > entity.DeadlineTime, + TrialId = x.TrialId, + SubjectVisitId = x.SubjectVisitId, + SiteId = subjectvisit.SiteId, + SubjectId = subjectvisit.SubjectId, + SubjectVisitName = subjectvisit.VisitName, + BlindName = subjectvisit.BlindName, + }, new + { + ChallengeCode = "Q" + entity.ChallengeCode.ToString("D5"), + AuditState = subjectvisit.AuditState, + TalkContent = content, + IsOverTime = entity.IsClosed ? entity.ClosedTime > entity.DeadlineTime : DateTime.Now > entity.DeadlineTime, }); } @@ -721,15 +728,16 @@ namespace IRaCIS.Core.Infra.EFCore.Common SubjectId = subjectvisit.SubjectId, SubjectVisitName = subjectvisit.VisitName, BlindName = subjectvisit.BlindName, - Reason= reason, - }, new { - AuditState= subjectvisit.AuditState, + Reason = reason, + }, new + { + AuditState = subjectvisit.AuditState, ChallengeCode = "Q" + qCChallenge.ChallengeCode.ToString("D5"), - ReuploadEnum= qCChallenge.ReuploadEnum, - Content= qCChallenge.Content, - DeadlineTime= qCChallenge.DeadlineTime, + ReuploadEnum = qCChallenge.ReuploadEnum, + Content = qCChallenge.Content, + DeadlineTime = qCChallenge.DeadlineTime, IsOverTime = qCChallenge.IsClosed ? qCChallenge.ClosedTime > qCChallenge.DeadlineTime : DateTime.Now > qCChallenge.DeadlineTime, - IsClosed= qCChallenge.IsClosed + IsClosed = qCChallenge.IsClosed }); } @@ -741,7 +749,7 @@ namespace IRaCIS.Core.Infra.EFCore.Common var subjectvisit = await _dbContext.SubjectVisit.Where(x => x.Id == entity.SubjectVisitId).FirstOrDefaultAsync(); subjectvisit = subjectvisit ?? new SubjectVisit(); var reason = string.Empty; - + switch (GetRequestUrl().ToLower()) { case "qcoperation/closecheckchallenge": @@ -757,11 +765,12 @@ namespace IRaCIS.Core.Infra.EFCore.Common SubjectId = subjectvisit.SubjectId, SubjectVisitName = subjectvisit.VisitName, BlindName = subjectvisit.BlindName, - Reason= reason, - },new { - CheckState= subjectvisit.CheckState, + Reason = reason, + }, new + { + CheckState = subjectvisit.CheckState, RequestBackState = subjectvisit.RequestBackState, - CheckChallengeState= subjectvisit.CheckChallengeState, + CheckChallengeState = subjectvisit.CheckChallengeState, }); } @@ -789,8 +798,8 @@ namespace IRaCIS.Core.Infra.EFCore.Common Identification = $"{_userInfo.RequestUrl}/{ firstentity.GetType().Name}/{type}", SubjectId = subjectvisit.SubjectId, SubjectVisitName = subjectvisit.VisitName, - TrialId= subjectvisit.TrialId, - SubjectVisitId= subjectvisit.Id, + TrialId = subjectvisit.TrialId, + SubjectVisitId = subjectvisit.Id, GeneralId = subjectvisit.Id, }, new { @@ -818,18 +827,18 @@ namespace IRaCIS.Core.Infra.EFCore.Common }); } - async Task> Getdata(List questionAnswers) + async Task> Getdata(List questionAnswers) { var ids = questionAnswers.Select(x => x.TrialQCQuestionConfigureId).ToList(); var trialQCQuestionConfigureDatas = await _dbContext.TrialQCQuestionConfigure.Where(x => ids.Contains(x.Id)).ToListAsync(); var collect = questionAnswers.GroupJoin(trialQCQuestionConfigureDatas, one => one.TrialQCQuestionConfigureId, two => two.Id, (x, y) => new { one = x, two = y }) - .SelectMany( a => a.two.DefaultIfEmpty(),(c, d) => new { c = c.one, d }) + .SelectMany(a => a.two.DefaultIfEmpty(), (c, d) => new { c = c.one, d }) .Select(o => new AnswerDto() { - QuestionName = o.d.QuestionName, - Answer = o.c.Answer, - }).ToList(); - return collect; + QuestionName = o.d.QuestionName, + Answer = o.c.Answer, + }).ToList(); + return collect; } } @@ -866,7 +875,7 @@ namespace IRaCIS.Core.Infra.EFCore.Common /// 实体对象 /// 实体名称 /// - public async Task InsertInspection(EntityEntry data, string type, Expression> expression = null,object otherItem=null,T entityData=null, string? entityTypeName=null) where T:class + public async Task InsertInspection(EntityEntry data, string type, Expression> expression = null, object otherItem = null, T entityData = null, string? entityTypeName = null) where T : class { object entityobj = entityData == null ? data.Entity : entityData; DataInspection inspection = new DataInspection(); @@ -900,8 +909,8 @@ namespace IRaCIS.Core.Infra.EFCore.Common await AddInspectionRecordAsync(inspection, entityobj, otherItem); } - - + + @@ -921,13 +930,13 @@ namespace IRaCIS.Core.Infra.EFCore.Common /// 要赋值的对象 public void MapData(dynamic data, dynamic mapData) { - List column = new List() { "TrialId", "SiteId", "SubjectId", "SubjectVisitId", "CreateUserName", "TrialName", "SiteName", "SubjectCode", "VisitName","SubjectVisitName", "RoleName", "SiteCode", "ResearchProgramNo" }; + List column = new List() { "TrialId", "SiteId", "SubjectId", "SubjectVisitId", "CreateUserName", "TrialName", "SiteName", "SubjectCode", "VisitName", "SubjectVisitName", "RoleName", "SiteCode", "ResearchProgramNo" }; foreach (var item in column) { try { var i = mapData.GetType().GetProperty(item).GetValue(mapData); - if (i == null|| i==default(Guid)) + if (i == null || i == default(Guid)) { var value = data.GetType().GetProperty(item).GetValue(data); mapData.GetType().GetProperty(item).SetValue(mapData, value); @@ -983,7 +992,7 @@ namespace IRaCIS.Core.Infra.EFCore.Common Data = AddJsonItem(data, otherItem), Inspection = generalData }; - add.JsonDetail = inspectionData.ToJcJson(); + add.JsonDetail = inspectionData.ToJsonStr(); await _dbContext.DataInspection.AddAsync(add); } @@ -996,17 +1005,17 @@ namespace IRaCIS.Core.Infra.EFCore.Common /// json /// 字典 /// - public IDictionary AddJsonItem(dynamic json, object otherItem=null) + public IDictionary AddJsonItem(dynamic json, object otherItem = null) { - - var JsonData = JsonConvert.DeserializeObject>((json as object).ToJcJson()); + + var JsonData = JsonConvert.DeserializeObject>((json as object).ToJsonStr()); if (otherItem == null) { return JsonData; } - var other = JsonConvert.DeserializeObject>(otherItem.ToJcJson()); + var other = JsonConvert.DeserializeObject>(otherItem.ToJsonStr()); foreach (var item in other) { @@ -1056,26 +1065,36 @@ namespace IRaCIS.Core.Infra.EFCore.Common if (generalData.TrialId != null) { - var trialdata = (await _dbContext.Trial.Select(x => new { x.Id, x.ResearchProgramNo, x.ExperimentName, }).FirstOrDefaultAsync(x => x.Id == generalData.TrialId)).IfNullThrowException(); - generalData.ResearchProgramNo = trialdata.ResearchProgramNo; + //项目添加哪里 直接会带信息过来,不用查询数据库 其他的地方需要查询数据库 + if (string.IsNullOrEmpty(generalData.ResearchProgramNo) || string.IsNullOrEmpty(generalData.TrialName)) + { + var trialdata = (await _dbContext.Trial.Select(x => new { x.Id, x.ResearchProgramNo, x.ExperimentName, }).FirstOrDefaultAsync(x => x.Id == generalData.TrialId)).IfNullThrowException(); + + generalData.ResearchProgramNo = trialdata.ResearchProgramNo; + + generalData.TrialName = trialdata.ExperimentName; + } - generalData.TrialName = trialdata.ExperimentName; } #endregion #region 测试中心名称 - - if(generalData.TrialId != null && generalData.SiteId != null) + + if (generalData.TrialId != null && generalData.SiteId != null) { - generalData.SiteCode = (await _dbContext.TrialSite.IgnoreQueryFilters().Where(x => x.TrialId == generalData.TrialId && x.SiteId == generalData.SiteId).Select(t=>t.TrialSiteCode).FirstOrDefaultAsync()).IfNullThrowException(); + generalData.SiteCode = (await _dbContext.TrialSite.IgnoreQueryFilters().Where(x => x.TrialId == generalData.TrialId && x.SiteId == generalData.SiteId).Select(t => t.TrialSiteCode).FirstOrDefaultAsync()).IfNullThrowException(); - generalData.SiteName =( await _dbContext.Site.Where(x => x.Id == generalData.SiteId).Select(x => x.SiteName ).FirstOrDefaultAsync()).IfNullThrowException(); + // 添加Site 哪里会带信息过来 + if (string.IsNullOrEmpty(generalData.SiteName)) + { + generalData.SiteName = (await _dbContext.Site.Where(x => x.Id == generalData.SiteId).Select(x => x.SiteName).FirstOrDefaultAsync()).IfNullThrowException(); + } } @@ -1083,33 +1102,40 @@ namespace IRaCIS.Core.Infra.EFCore.Common #region 受试者 - - if (IsNullOrEmpty(generalData.SubjectCode) && generalData.SubjectId != null) + if (generalData.SubjectId != null) { - generalData.SubjectCode = (await _dbContext.Subject.Where(x => x.Id == generalData.SubjectId).Select(x => new { x.Code }).FirstOrDefaultAsync())?.Code; + // 添加Subject 哪里会带信息过来 + if (string.IsNullOrEmpty(generalData.SubjectCode)) + { + generalData.SubjectCode = (await _dbContext.Subject.Where(x => x.Id == generalData.SubjectId).Select(x => x.Code).FirstOrDefaultAsync()).IfNullThrowException(); + + } } + + + #endregion #region 访视 - if (IsNullOrEmpty(generalData.SubjectVisitName)) + + if (generalData.SubjectVisitId != null) { - generalData.SubjectVisitName = (await _dbContext.SubjectVisit.Where(x => x.Id == generalData.SubjectVisitId).Select(x => new { x.VisitName }).FirstOrDefaultAsync())?.VisitName; + //添加访视的时候,会带信息过来 + if (string.IsNullOrEmpty(generalData.SubjectVisitName)) + { + generalData.SubjectVisitName = (await _dbContext.SubjectVisit.Where(x => x.Id == generalData.SubjectVisitId).Select(x => x.VisitName).FirstOrDefaultAsync()).IfNullThrowException(); + } } + + #endregion - #region 创建者 - if (IsNullOrEmpty(generalData.CreateUserName)) - { - generalData.CreateUserName = _userInfo.RealName; - } + generalData.CreateUserName = _userInfo.RealName; + + generalData.RoleName = _userInfo.UserTypeShortName; - if (IsNullOrEmpty(generalData.RoleName)) - { - generalData.RoleName = _userInfo.UserTypeShortName; - } - #endregion } } diff --git a/IRaCIS.Core.Infra.EFCore/Repository/Repository.cs b/IRaCIS.Core.Infra.EFCore/Repository/Repository.cs index 75032fd0d..2e2346165 100644 --- a/IRaCIS.Core.Infra.EFCore/Repository/Repository.cs +++ b/IRaCIS.Core.Infra.EFCore/Repository/Repository.cs @@ -1,6 +1,5 @@ using System; using System.Collections.Generic; -using System.ComponentModel.DataAnnotations; using System.Linq; using System.Linq.Expressions; using System.Reflection; @@ -18,7 +17,6 @@ using IRaCIS.Core.Infrastructure.Extention; using Microsoft.Data.SqlClient; using Newtonsoft.Json; using Newtonsoft.Json.Linq; -using IRaCIS.Core.Domain.Common; using IRaCIS.Core.Infra.EFCore.Common.Dto; namespace IRaCIS.Core.Infra.EFCore diff --git a/IRaCIS.Core.Infrastructure/Extention/CloneExtension.cs b/IRaCIS.Core.Infrastructure/Extention/ObjectExtension.cs similarity index 61% rename from IRaCIS.Core.Infrastructure/Extention/CloneExtension.cs rename to IRaCIS.Core.Infrastructure/Extention/ObjectExtension.cs index 31145efc3..184da9cc6 100644 --- a/IRaCIS.Core.Infrastructure/Extention/CloneExtension.cs +++ b/IRaCIS.Core.Infrastructure/Extention/ObjectExtension.cs @@ -3,7 +3,7 @@ using System; namespace IRaCIS.Core.Infrastructure.Extention { - public static class CloneExtension + public static class ObjectExtension { public static T Clone(this T source) @@ -18,5 +18,16 @@ namespace IRaCIS.Core.Infrastructure.Extention var serializeSettings = new JsonSerializerSettings { ReferenceLoopHandling = ReferenceLoopHandling.Ignore }; return JsonConvert.DeserializeObject(JsonConvert.SerializeObject(source, serializeSettings), deserializeSettings); } + + /// + /// 将对象序列化成稽查需要的Json字符串 + /// + /// + /// + public static string ToJsonStr(this object obj) + { + + return JsonConvert.SerializeObject(obj, new JsonSerializerSettings { DateFormatString = "yyyy-MM-dd HH:mm:ss", ReferenceLoopHandling = ReferenceLoopHandling.Ignore }); + } } }