From 139e9daec0e5cbfc43aafc5781b8e5d223cded90 Mon Sep 17 00:00:00 2001 From: hang <872297557@qq.com> Date: Wed, 13 Mar 2024 15:37:09 +0800 Subject: [PATCH 1/4] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=B8=80=E8=87=B4?= =?UTF-8?q?=E6=80=A7=E5=88=86=E6=9E=90=E9=99=90=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Service/Allocation/TaskConsistentRuleService.cs | 8 +++++++- .../Repository/IRaCISContextExtension.cs | 6 ++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/IRaCIS.Core.Application/Service/Allocation/TaskConsistentRuleService.cs b/IRaCIS.Core.Application/Service/Allocation/TaskConsistentRuleService.cs index 9288ccde6..c08ca427e 100644 --- a/IRaCIS.Core.Application/Service/Allocation/TaskConsistentRuleService.cs +++ b/IRaCIS.Core.Application/Service/Allocation/TaskConsistentRuleService.cs @@ -300,7 +300,12 @@ namespace IRaCIS.Core.Application.Service var pagedList = await query.ToPagedListAsync(inQuery.PageIndex, inQuery.PageSize, string.IsNullOrWhiteSpace(inQuery.SortField) ? nameof(DoctorSelfConsistentSubjectView.SubjectCode) : inQuery.SortField, inQuery.Asc); var rule = await _taskConsistentRuleRepository.Where(t => t.TrialId == inQuery.TrialId && t.IsSelfAnalysis == false && t.TrialReadingCriterionId == inQuery.TrialReadingCriterionId).ProjectTo(_mapper.ConfigurationProvider).FirstOrDefaultAsync(); - return ResponseOutput.Ok(pagedList, rule); + + var list = await GetGroupConsistentRuleMatchSubjectIdListAsync(new GroupConsistentSimpleQuery() { TrialId = inQuery.TrialId, TrialReadingCriterionId = inQuery.TrialReadingCriterionId }); + + var isAllowAutoAllocate = !list.Any(t => t.IsHaveGeneratedTask) && list.Count() > 2*(rule?.PlanSubjectCount??0); + + return ResponseOutput.Ok(pagedList, new {Rule=rule, IsAllowAutoAllocate = isAllowAutoAllocate }); } @@ -837,6 +842,7 @@ namespace IRaCIS.Core.Application.Service await _taskConsistentRuleRepository.BatchUpdateNoTrackingAsync(t => t.TrialId == trial.Id, u => new TaskConsistentRule() { BlindTrialSiteCode = inCommand.VirtualSiteCode }); + //await _visitTaskRepository.BatchUpdateNoTrackingAsync(t => t.TrialId == trial.Id, u => new VisitTask() { BlindSubjectCode = inCommand.VirtualSiteCode }); await _trialVirtualSiteCodeUpdateRepository.AddAsync(new TrialVirtualSiteCodeUpdate() { VirturalSiteCode = inCommand.VirtualSiteCode, TrialId = inCommand.TrialId }); diff --git a/IRaCIS.Core.Infra.EFCore/Repository/IRaCISContextExtension.cs b/IRaCIS.Core.Infra.EFCore/Repository/IRaCISContextExtension.cs index 7a2ca31a5..1f0074074 100644 --- a/IRaCIS.Core.Infra.EFCore/Repository/IRaCISContextExtension.cs +++ b/IRaCIS.Core.Infra.EFCore/Repository/IRaCISContextExtension.cs @@ -232,6 +232,12 @@ namespace IRaCIS.Core.Infra.EFCore } + //public static async Task ExecuteUpdateAsync(this IRaCISDBContext _dbContext, Expression> where, Expression> updateFactory, Guid updateUserId) where T : Entity + //{ + + // return await _dbContext.Set().Where(where).ExecuteUpdateAsync(, ); + + //} #endregion From 86fd9ddc0e1aad63f1270f892dfb4defd03de3f5 Mon Sep 17 00:00:00 2001 From: hang <872297557@qq.com> Date: Wed, 13 Mar 2024 15:57:18 +0800 Subject: [PATCH 2/4] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E8=A7=84=E5=88=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Service/Allocation/TaskConsistentRuleService.cs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/IRaCIS.Core.Application/Service/Allocation/TaskConsistentRuleService.cs b/IRaCIS.Core.Application/Service/Allocation/TaskConsistentRuleService.cs index c08ca427e..9682d2067 100644 --- a/IRaCIS.Core.Application/Service/Allocation/TaskConsistentRuleService.cs +++ b/IRaCIS.Core.Application/Service/Allocation/TaskConsistentRuleService.cs @@ -291,7 +291,8 @@ namespace IRaCIS.Core.Application.Service if (filterObj == null) { - return ResponseOutput.Ok(new PageOutput()) ; + object tt = null; + return ResponseOutput.Ok(new PageOutput(), new { Rule = tt, IsAllowAutoAllocate = false }) ; } var query = await GetGroupConsistentQueryAsync(filterObj); @@ -836,13 +837,14 @@ namespace IRaCIS.Core.Application.Service var trial = await _trialRepository.FirstOrDefaultAsync(t => t.Id == inCommand.TrialId); + var oldCode = trial.VitrualSiteCode; trial.VitrualSiteCode = inCommand.VirtualSiteCode; await _visitTaskRepository.BatchUpdateNoTrackingAsync(t => t.TrialId == trial.Id, u => new VisitTask() { BlindTrialSiteCode = inCommand.VirtualSiteCode }); await _taskConsistentRuleRepository.BatchUpdateNoTrackingAsync(t => t.TrialId == trial.Id, u => new TaskConsistentRule() { BlindTrialSiteCode = inCommand.VirtualSiteCode }); - //await _visitTaskRepository.BatchUpdateNoTrackingAsync(t => t.TrialId == trial.Id, u => new VisitTask() { BlindSubjectCode = inCommand.VirtualSiteCode }); + //await _visitTaskRepository.ExecuteUpdateAsync(t => t.TrialId == trial.Id, s=> s.SetProperty(e=>e.BlindSubjectCode,u=>u.BlindSubjectCode)); await _trialVirtualSiteCodeUpdateRepository.AddAsync(new TrialVirtualSiteCodeUpdate() { VirturalSiteCode = inCommand.VirtualSiteCode, TrialId = inCommand.TrialId }); From 54dea66f5f1cd9df8d731e57476eac09f8a676f3 Mon Sep 17 00:00:00 2001 From: hang <872297557@qq.com> Date: Wed, 13 Mar 2024 16:12:56 +0800 Subject: [PATCH 3/4] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=B8=80=E8=87=B4?= =?UTF-8?q?=E6=80=A7=E5=88=86=E6=9E=90=E6=8F=90=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Service/Allocation/TaskConsistentRuleService.cs | 9 ++++++++- .../Service/TrialSiteUser/TrialSiteService.cs | 2 +- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/IRaCIS.Core.Application/Service/Allocation/TaskConsistentRuleService.cs b/IRaCIS.Core.Application/Service/Allocation/TaskConsistentRuleService.cs index 9682d2067..460acd914 100644 --- a/IRaCIS.Core.Application/Service/Allocation/TaskConsistentRuleService.cs +++ b/IRaCIS.Core.Application/Service/Allocation/TaskConsistentRuleService.cs @@ -835,16 +835,23 @@ namespace IRaCIS.Core.Application.Service public async Task UpdateTrialVirtualSiteCode(UpdateTrialSiteCodeCommand inCommand) { + if (_trialSiteRepository.Where(t => t.TrialId == inCommand.TrialId, false, true).Any(t => t.TrialSiteCode == inCommand.VirtualSiteCode)) + { + return ResponseOutput.NotOk(_localizer["TaskConsistent_SiteCodeExists"]); + } + var trial = await _trialRepository.FirstOrDefaultAsync(t => t.Id == inCommand.TrialId); var oldCode = trial.VitrualSiteCode; + trial.VitrualSiteCode = inCommand.VirtualSiteCode; await _visitTaskRepository.BatchUpdateNoTrackingAsync(t => t.TrialId == trial.Id, u => new VisitTask() { BlindTrialSiteCode = inCommand.VirtualSiteCode }); await _taskConsistentRuleRepository.BatchUpdateNoTrackingAsync(t => t.TrialId == trial.Id, u => new TaskConsistentRule() { BlindTrialSiteCode = inCommand.VirtualSiteCode }); - //await _visitTaskRepository.ExecuteUpdateAsync(t => t.TrialId == trial.Id, s=> s.SetProperty(e=>e.BlindSubjectCode,u=>u.BlindSubjectCode)); + + await _visitTaskRepository.ExecuteUpdateAsync(t => t.TrialId == trial.Id, s => s.SetProperty(e => e.BlindSubjectCode, u => u.BlindSubjectCode.Replace(oldCode, inCommand.VirtualSiteCode))); await _trialVirtualSiteCodeUpdateRepository.AddAsync(new TrialVirtualSiteCodeUpdate() { VirturalSiteCode = inCommand.VirtualSiteCode, TrialId = inCommand.TrialId }); diff --git a/IRaCIS.Core.Application/Service/TrialSiteUser/TrialSiteService.cs b/IRaCIS.Core.Application/Service/TrialSiteUser/TrialSiteService.cs index dcdddd581..4ce4e99b1 100644 --- a/IRaCIS.Core.Application/Service/TrialSiteUser/TrialSiteService.cs +++ b/IRaCIS.Core.Application/Service/TrialSiteUser/TrialSiteService.cs @@ -274,7 +274,7 @@ namespace IRaCIS.Core.Application.Services return ResponseOutput.NotOk(_localizer["TrialSite_CodeDuplicate"]); } - if(!string.IsNullOrEmpty(editTrialSiteCommand.TrialSiteCode) && await _trialRepository.AnyAsync(t=>t.Id==trialId && t.VitrualSiteCode == editTrialSiteCommand.TrialSiteCode) ) + if(!string.IsNullOrEmpty(editTrialSiteCommand.TrialSiteCode) && await _trialRepository.AnyAsync(t=>t.Id==trialId && t.VitrualSiteCode == editTrialSiteCommand.TrialSiteCode,true) ) { return ResponseOutput.NotOk(_localizer["TrialSite_CodeDuplicate2"]); } From 39a5e8eade7d938b994bd399b567efe415d2ee01 Mon Sep 17 00:00:00 2001 From: hang <872297557@qq.com> Date: Wed, 13 Mar 2024 16:13:24 +0800 Subject: [PATCH 4/4] =?UTF-8?q?=E5=A2=9E=E5=8A=A0efcore=20=E5=AE=98?= =?UTF-8?q?=E6=96=B9=E6=89=B9=E9=87=8F=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- IRaCIS.Core.Infra.EFCore/Repository/ICommandRepository.cs | 3 +++ .../Repository/IRaCISContextExtension.cs | 8 ++++---- IRaCIS.Core.Infra.EFCore/Repository/Repository.cs | 8 +++++++- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/IRaCIS.Core.Infra.EFCore/Repository/ICommandRepository.cs b/IRaCIS.Core.Infra.EFCore/Repository/ICommandRepository.cs index 20a7c1836..de9cad4e7 100644 --- a/IRaCIS.Core.Infra.EFCore/Repository/ICommandRepository.cs +++ b/IRaCIS.Core.Infra.EFCore/Repository/ICommandRepository.cs @@ -6,6 +6,7 @@ using System.Threading; using System.Threading.Tasks; using IRaCIS.Core.Domain.Models; using Microsoft.EntityFrameworkCore.ChangeTracking; +using Microsoft.EntityFrameworkCore.Query; namespace IRaCIS.Core.Infra.EFCore { @@ -82,6 +83,8 @@ namespace IRaCIS.Core.Infra.EFCore /// 批量更新,相当于原生sql, 没用EF跟踪方式(所有查询出来,再更新 浪费性能) Task BatchUpdateNoTrackingAsync(Expression> where, Expression> updateFactory); + Task ExecuteUpdateAsync(Expression> where, Expression, SetPropertyCalls>> setPropertyCalls); + #endregion diff --git a/IRaCIS.Core.Infra.EFCore/Repository/IRaCISContextExtension.cs b/IRaCIS.Core.Infra.EFCore/Repository/IRaCISContextExtension.cs index 1f0074074..25059eb64 100644 --- a/IRaCIS.Core.Infra.EFCore/Repository/IRaCISContextExtension.cs +++ b/IRaCIS.Core.Infra.EFCore/Repository/IRaCISContextExtension.cs @@ -232,12 +232,12 @@ namespace IRaCIS.Core.Infra.EFCore } - //public static async Task ExecuteUpdateAsync(this IRaCISDBContext _dbContext, Expression> where, Expression> updateFactory, Guid updateUserId) where T : Entity - //{ + public static async Task ExecuteUpdateAsync(this IRaCISDBContext _dbContext, Expression> where, Expression, SetPropertyCalls>> setPropertyCalls) where T : Entity + { - // return await _dbContext.Set().Where(where).ExecuteUpdateAsync(, ); + return await _dbContext.Set().Where(where).ExecuteUpdateAsync(setPropertyCalls)>0; - //} + } #endregion diff --git a/IRaCIS.Core.Infra.EFCore/Repository/Repository.cs b/IRaCIS.Core.Infra.EFCore/Repository/Repository.cs index 7901a0a84..32f2520c4 100644 --- a/IRaCIS.Core.Infra.EFCore/Repository/Repository.cs +++ b/IRaCIS.Core.Infra.EFCore/Repository/Repository.cs @@ -14,6 +14,7 @@ using IRaCIS.Core.Domain.Share; using IRaCIS.Core.Infrastructure; using IRaCIS.Core.Infrastructure.Extention; using Microsoft.Extensions.Localization; +using Microsoft.EntityFrameworkCore.Query; namespace IRaCIS.Core.Infra.EFCore { @@ -369,12 +370,17 @@ namespace IRaCIS.Core.Infra.EFCore } + public async Task ExecuteUpdateAsync(Expression> where, Expression, SetPropertyCalls>> setPropertyCalls) + { + return await _dbContext.ExecuteUpdateAsync(where, setPropertyCalls); + } + #endregion - #region 保存 、忽略 、验证 + #region 保存 、忽略 、验证 public async Task InsertOrUpdateAsync(TFrom from, bool autoSave = false, params EntityVerifyExp[] verify) { var entity = _mapper.Map(from);