diff --git a/IRaCIS.Core.Application/Service/Allocation/TaskConsistentRuleService.cs b/IRaCIS.Core.Application/Service/Allocation/TaskConsistentRuleService.cs index 9288ccde6..460acd914 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); @@ -300,7 +301,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 }); } @@ -829,8 +835,15 @@ 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 }); @@ -838,6 +851,8 @@ namespace IRaCIS.Core.Application.Service 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.Replace(oldCode, inCommand.VirtualSiteCode))); + await _trialVirtualSiteCodeUpdateRepository.AddAsync(new TrialVirtualSiteCodeUpdate() { VirturalSiteCode = inCommand.VirtualSiteCode, TrialId = inCommand.TrialId }); await _trialRepository.SaveChangesAsync(); 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"]); } 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 7a2ca31a5..25059eb64 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, SetPropertyCalls>> setPropertyCalls) where T : Entity + { + + 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);