From ad609915890d5d3c87d12c94f0da002f978380b0 Mon Sep 17 00:00:00 2001 From: he <10978375@qq.com> Date: Mon, 9 May 2022 16:41:30 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=B8=80=E7=89=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Common/AuditingData.cs | 19 +++++--- .../Repository/IRepository.cs | 21 -------- .../Repository/Repository.cs | 48 +++++++++++++++---- 3 files changed, 52 insertions(+), 36 deletions(-) diff --git a/IRaCIS.Core.Infra.EFCore/Common/AuditingData.cs b/IRaCIS.Core.Infra.EFCore/Common/AuditingData.cs index b258cf72..22997f1b 100644 --- a/IRaCIS.Core.Infra.EFCore/Common/AuditingData.cs +++ b/IRaCIS.Core.Infra.EFCore/Common/AuditingData.cs @@ -47,15 +47,15 @@ namespace IRaCIS.Core.Infra.EFCore.Common /// 传入实体对象 /// public async Task IncomingEntitys(List entitys) - { - // 新增 - await InsertAddEntitys(entitys.Where(x => x.State == EntityState.Added).ToList(), "Add"); - + { // 修改 - await InsertAddEntitys(entitys.Where(x => x.State == EntityState.Modified&&(!typeof(ISoftDelete).IsAssignableFrom(x.Entity.GetType()) + await InsertAddEntitys(entitys.Where(x => x.State == EntityState.Modified && (!typeof(ISoftDelete).IsAssignableFrom(x.Entity.GetType()) || !(bool)x.Entity.GetType().GetProperty("IsDeleted").GetValue(x.Entity)) ).ToList(), "Update"); + // 新增 + await InsertAddEntitys(entitys.Where(x => x.State == EntityState.Added).ToList(), "Add"); + // 删除 await InsertAddEntitys(entitys.Where(x => x.State == EntityState.Deleted ||((typeof(ISoftDelete).IsAssignableFrom(x.Entity.GetType())&& (bool)x.Entity.GetType().GetProperty("IsDeleted").GetValue(x.Entity))) @@ -116,10 +116,16 @@ 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(); + await InsertInspection(item, type, x => new DataInspection() { SubjectId = x.Id, SubjectCode=x.Code, + }, new + { + FinalSubjectVisitName = FinalSubjectVisitName, }); } // 访视 @@ -154,6 +160,7 @@ namespace IRaCIS.Core.Infra.EFCore.Common SubjectId=x.SubjectId, SubjectVisitId = x.Id, SubjectVisitName=x.VisitName, + BlindName=x.BlindName, }); } @@ -205,7 +212,7 @@ namespace IRaCIS.Core.Infra.EFCore.Common var entity = item.Entity as DicomSeries; if (entity.DicomStudy == null) { - entity.DicomStudy =await _dbContext.DicomStudys.FirstOrDefaultAsync(x=>x.Id== entity.StudyId); + entity.DicomStudy =await _dbContext.DicomStudys.AsNoTracking().FirstOrDefaultAsync(x=>x.Id== entity.StudyId); } await InsertInspection(item, type, x => new DataInspection() { diff --git a/IRaCIS.Core.Infra.EFCore/Repository/IRepository.cs b/IRaCIS.Core.Infra.EFCore/Repository/IRepository.cs index 358100db..4d1e81cc 100644 --- a/IRaCIS.Core.Infra.EFCore/Repository/IRepository.cs +++ b/IRaCIS.Core.Infra.EFCore/Repository/IRepository.cs @@ -43,27 +43,6 @@ namespace IRaCIS.Core.Infra.EFCore /// Task SetDataInspectionDateType(DataInspection Data); - /// - /// 处理枚举 - /// - /// 标识 - /// json对象 - /// - - Task SetEnum(Guid trial, string Identification, string json); - - - /// - /// 获取外键表数据 - /// - /// 表名称 - /// 外键value - /// 要查询的外键值 - /// 传入的纸 - /// - Task GetInspectionEnumValue(string Identification, string json); - - /// /// 翻译稽查数据 /// diff --git a/IRaCIS.Core.Infra.EFCore/Repository/Repository.cs b/IRaCIS.Core.Infra.EFCore/Repository/Repository.cs index 481158b9..f0048ec8 100644 --- a/IRaCIS.Core.Infra.EFCore/Repository/Repository.cs +++ b/IRaCIS.Core.Infra.EFCore/Repository/Repository.cs @@ -584,11 +584,16 @@ namespace IRaCIS.Core.Infra.EFCore /// public async Task> SetInspectionEnumValue(SetInspectionEnumValueDto dto) { + var listIdentification = dto.Items.Select(x => x.Identification).ToList() ; foreach (var item in dto.Items) { - item.Json = await GetInspectionEnumValue(item.Identification, item.Json); - item.Json = await SetEnum(dto.TrialId, item.Identification, item.Json); - item.Json = await SetDataInspectionDateType(item.Identification, item.Json); + if (item.Identification == string.Empty || item.Json == string.Empty) + { + continue; + } + item.Json = await GetInspectionEnumValue(listIdentification, item.Json); + item.Json = await SetEnum(dto.TrialId, listIdentification, item.Json); + item.Json = await SetDataInspectionDateType(listIdentification, item.Json); } return dto.Items.Select(x => x.Json).ToList(); } @@ -602,9 +607,9 @@ namespace IRaCIS.Core.Infra.EFCore /// /// 稽查数据 /// - public async Task SetDataInspectionDateType(string identification, string json) + public async Task SetDataInspectionDateType(List identification, string json) { - var list = await (from parent in _dbContext.FrontAuditConfig.AsQueryable().Where(x => x.Identification == identification) + var list = await (from parent in _dbContext.FrontAuditConfig.AsQueryable().Where(x => identification.Contains(x.Identification)) join child in _dbContext.FrontAuditConfig.AsQueryable().Where(x => x.EnumType == "Date" && x.IsEnable.HasValue && x.IsEnable.Value) on parent.Id equals child.ParentId select new DateDto() { @@ -612,6 +617,12 @@ namespace IRaCIS.Core.Infra.EFCore DateType = child.DateType, }).ToListAsync(); + list = list.GroupBy(x => new { x.Code }, (key, lst) => new DateDto() + { + Code = key.Code, + DateType = lst.Max(x => x.DateType), + }).ToList(); + var JsonData = JsonConvert.DeserializeObject>(json); if (JsonData == null) @@ -657,9 +668,9 @@ namespace IRaCIS.Core.Infra.EFCore /// 要查询的外键值 /// 传入的纸 /// - public async Task GetInspectionEnumValue(string identification, string json) + public async Task GetInspectionEnumValue(List identification, string json) { - var list = await (from u in _dbContext.FrontAuditConfig.Where(x => x.Identification == identification) + var list = await (from u in _dbContext.FrontAuditConfig.Where(x => identification.Contains(x.Identification)) join p in _dbContext.FrontAuditConfig.Where(x => x.EnumType == "Foreign" && x.IsEnable.HasValue && x.IsEnable.Value) on u.Id equals p.ParentId select new { @@ -668,6 +679,17 @@ namespace IRaCIS.Core.Infra.EFCore ForeignKeyText = p.ForeignKeyText, ForeignKeyTable = p.ForeignKeyTable }).ToListAsync(); + + list= list.GroupBy(x => new { x.Key }, (key, lst) => new + { + Key=key.Key, + ForeignKeyValue=lst.Max(x=>x.ForeignKeyValue), + ForeignKeyText = lst.Max(x => x.ForeignKeyText), + ForeignKeyTable = lst.Max(x => x.ForeignKeyTable), + + }).ToList(); + + var JsonDataValue = JsonConvert.DeserializeObject>(json); foreach (var item in list) @@ -713,13 +735,13 @@ namespace IRaCIS.Core.Infra.EFCore /// Json对象 /// /// - public async Task SetEnum(Guid trilaid, string identification, string json) + public async Task SetEnum(Guid trilaid, List identification, string json) { if (json == null||json=="null") { return null; } - var list = await (from u in _dbContext.FrontAuditConfig.Where(x => x.Identification == identification) + var list = await (from u in _dbContext.FrontAuditConfig.Where(x => identification.Contains(x.Identification)) join p in _dbContext.FrontAuditConfig.Where(x => x.Code != "AuditState" && x.EnumType == "Dictionary"&&x.IsEnable.HasValue&& x.IsEnable.Value) on u.Id equals p.ParentId select new { @@ -739,6 +761,14 @@ namespace IRaCIS.Core.Infra.EFCore Type = "Code", }); + + list = list.GroupBy(x => new { x.Key }, (key, lst) => new + { + Key = key.Key, + Code = lst.Max(x => x.Code), + Type = lst.Max(x => x.Type), + }).ToList(); + var JsonData = JsonConvert.DeserializeObject>(json); foreach (var item in list) {