759 lines
		
	
	
		
			37 KiB
		
	
	
	
		
			C#
		
	
	
			
		
		
	
	
			759 lines
		
	
	
		
			37 KiB
		
	
	
	
		
			C#
		
	
	
| using IRaCIS.Application.Interfaces;
 | |
| using IRaCIS.Core.Infra.EFCore;
 | |
| using IRaCIS.Core.Domain.Share;
 | |
| using IRaCIS.Core.Application.Filter;
 | |
| using Microsoft.AspNetCore.Mvc;
 | |
| using IRaCIS.Core.Application.Service.WorkLoad.DTO;
 | |
| using Microsoft.AspNetCore.Authorization;
 | |
| using IRaCIS.Core.Application.Auth;
 | |
| using IRaCIS.Core.Application.Service.Reading.Dto;
 | |
| using MassTransit;
 | |
| using IRaCIS.Core.Application.Service.Reading;
 | |
| using IRaCIS.Core.Infra.EFCore.Common;
 | |
| using Panda.DynamicWebApi.Attributes;
 | |
| using IRaCIS.Core.Application.Contracts;
 | |
| using IRaCIS.Core.Infrastructure;
 | |
| 
 | |
| namespace IRaCIS.Application.Services
 | |
| {
 | |
|     /// <summary>
 | |
|     /// 阅片问题.标准
 | |
|     /// </summary>
 | |
|     [ApiExplorerSettings(GroupName = "Reading")]
 | |
|     public class ReadingQuestionService : BaseService, IReadingQuestionService
 | |
|     {
 | |
| 
 | |
|         private readonly IRepository<SubjectVisit> _subjectVisitRepository;
 | |
|         private readonly IRepository<ReadingQuestionCriterionSystem> _readingQuestionCriterionSystemRepository;
 | |
|         private readonly IRepository<ReadingQuestionCriterionTrial> _readingQuestionCriterionTrialRepository;
 | |
|         private readonly IRepository<ReadingQuestionSystem> _readingQuestionSystemRepository;
 | |
|         private readonly IRepository<ReadingQuestionTrial> _readingQuestionTrialRepository;
 | |
|         private readonly IRepository<ClinicalDataTrialSet> _clinicalDataTrialSetRepository;
 | |
|         private readonly IRepository<ClinicalDataSystemSet> _clinicalDataSystemSetRepository;
 | |
|         private readonly IRepository<Dictionary> _dictionaryRepository;
 | |
|         private readonly IRepository<Trial> _trialRepository;
 | |
|         private readonly IReadingImageTaskService _readingImageTaskService;
 | |
|         private readonly IRepository<ReadingTaskQuestionAnswer> _readingTaskQuestionAnswer;
 | |
|         private readonly IRepository<PreviousPDF> _previousPDFRepository;
 | |
| 
 | |
|         public ReadingQuestionService(
 | |
|             IRepository<SubjectVisit> subjectVisitRepository,
 | |
|             IRepository<ReadingQuestionCriterionSystem> readingQuestionCriterionSystemRepository,
 | |
|             IRepository<ReadingQuestionCriterionTrial> readingQuestionCriterionTrialRepository,
 | |
|             IRepository<ReadingQuestionSystem> readingQuestionSystemRepository,
 | |
|             IRepository<ReadingQuestionTrial> readingQuestionTrialRepository,
 | |
|             IRepository<ClinicalDataTrialSet> ClinicalDataTrialSetRepository,
 | |
|             IRepository<ClinicalDataSystemSet> ClinicalDataSystemSetRepository,
 | |
|             IRepository<Dictionary> dictionaryRepository,
 | |
|                IRepository<Trial> trialRepository,
 | |
|             IReadingImageTaskService readingImageTaskService,
 | |
|               IRepository<ReadingTaskQuestionAnswer> readingTaskQuestionAnswer,
 | |
|             IRepository<PreviousPDF> previousPDFRepository
 | |
|           )
 | |
|         {
 | |
|             this._subjectVisitRepository = subjectVisitRepository;
 | |
|             this._readingQuestionCriterionSystemRepository = readingQuestionCriterionSystemRepository;
 | |
|             this._readingQuestionCriterionTrialRepository = readingQuestionCriterionTrialRepository;
 | |
|             this._readingQuestionSystemRepository = readingQuestionSystemRepository;
 | |
|             this._readingQuestionTrialRepository = readingQuestionTrialRepository;
 | |
|             this._clinicalDataTrialSetRepository = ClinicalDataTrialSetRepository;
 | |
|             this._clinicalDataSystemSetRepository = ClinicalDataSystemSetRepository;
 | |
|             this._dictionaryRepository = dictionaryRepository;
 | |
|             this._trialRepository = trialRepository;
 | |
|             this._readingImageTaskService = readingImageTaskService;
 | |
|             this._readingTaskQuestionAnswer = readingTaskQuestionAnswer;
 | |
|             this._previousPDFRepository = previousPDFRepository;
 | |
|         }
 | |
| 
 | |
|         ///// <summary>
 | |
|         ///// 新增修改系统问题标准
 | |
|         ///// </summary>
 | |
|         ///// <param name="indto"></param>
 | |
|         ///// <returns></returns>
 | |
|         //[HttpPost]
 | |
|         //public async Task<IResponseOutput> AddOrUpdateReadingQuestionCriterionSystem(AddOrUpdateReadingQuestionCriterionSystemInDto indto)
 | |
|         //{
 | |
|         //    var entity = await _readingQuestionCriterionSystemRepository.InsertOrUpdateAsync(indto,true);
 | |
|         //    return ResponseOutput.Ok(entity.Id.ToString());
 | |
|         //}
 | |
| 
 | |
|         /// <summary>
 | |
|         /// 获取系统问题标准
 | |
|         /// </summary>
 | |
|         /// <returns></returns>
 | |
|         [HttpPost]
 | |
|         public async Task<PageOutput<ReadingQuestionCriterionSystemView>> GetReadingQuestionCriterionSystemList(ReadingQuestionCriterionSystemViewInDto inDto)
 | |
|         {
 | |
|             await AddSystemQuestionCriterion();
 | |
|             var query=  _readingQuestionCriterionSystemRepository.AsQueryable()
 | |
|                  .WhereIf(!inDto.CriterionName.IsNullOrEmpty(), x => x.CriterionName.Contains(inDto.CriterionName))
 | |
|                  .ProjectTo<ReadingQuestionCriterionSystemView>(_mapper.ConfigurationProvider)
 | |
|                  .Where(x=>x.IsEnable);
 | |
|              return  await query.ToPagedListAsync(inDto.PageIndex, inDto.PageSize, inDto.SortField.IsNullOrEmpty() ? nameof(ReadingQuestionCriterionSystemView.ShowOrder) : inDto.SortField,
 | |
|               inDto.Asc);
 | |
|         }
 | |
| 
 | |
| 
 | |
|         /// <summary>
 | |
|         /// 设置系统标准被禁用
 | |
|         /// </summary>
 | |
|         /// <returns></returns>
 | |
|         [NonDynamicMethod]
 | |
|         public async Task<IResponseOutput> SetSystemCriterionDisable(Guid dictionaryId, Guid? parentId)
 | |
|         {
 | |
|             // 判断是否是阅片
 | |
|             if (await _dictionaryRepository.AnyAsync(x => x.Id == parentId && x.Code == "ReadingStandard"))
 | |
|             {
 | |
|                 // 判断当前阅片是否在项目里面存在
 | |
|                 var systemCriterion = await _readingQuestionCriterionSystemRepository.FirstOrDefaultAsync(x => x.CriterionId == dictionaryId);
 | |
|                 if (systemCriterion != null)
 | |
|                 {
 | |
|                     var trialCriterionIds = await _readingQuestionCriterionTrialRepository.Where(x => x.ReadingQuestionCriterionSystemId == systemCriterion.Id).Select(x=>x.ReadingQuestionCriterionSystemId).ToListAsync();
 | |
|                     await _readingQuestionCriterionTrialRepository.BatchDeleteNoTrackingAsync(x => x.ReadingQuestionCriterionSystemId == systemCriterion.Id);
 | |
|                     await _readingQuestionTrialRepository.BatchDeleteNoTrackingAsync(x => trialCriterionIds.Contains(x.ReadingQuestionCriterionTrialId));
 | |
|                     return ResponseOutput.Ok();
 | |
|                 }
 | |
|             }
 | |
| 
 | |
|             return ResponseOutput.Ok();
 | |
|         }
 | |
| 
 | |
|       
 | |
|         /// <summary>
 | |
|         /// 设置系统问题标准是否完成配置
 | |
|         /// </summary>
 | |
|         /// <param name="inDto"></param>
 | |
|         /// <returns></returns>
 | |
|         public async Task<IResponseOutput> SetSystemReadingQuestionCriterionIsCompleteConfig(SetSystemReadingQuestionCriterionIsIsCompleteConfig inDto)
 | |
|         {
 | |
| 
 | |
|             if (!inDto.IsCompleteConfig)
 | |
|             {
 | |
|                 var trialCriterionIds =await _readingQuestionCriterionTrialRepository.Where(x => x.ReadingQuestionCriterionSystemId == inDto.Id).Select(x => x.Id).ToListAsync();
 | |
|                 if (await _readingTaskQuestionAnswer.AnyAsync(x => trialCriterionIds.Contains(x.ReadingQuestionCriterionTrialId)))
 | |
|                 {
 | |
|                     return ResponseOutput.NotOk("此标准在项目里面已被使用,操作失败");
 | |
|                 }
 | |
|             }
 | |
| 
 | |
|             await _readingQuestionCriterionSystemRepository.UpdatePartialFromQueryAsync(inDto.Id, x => new ReadingQuestionCriterionSystem()
 | |
|             {
 | |
|                 IsCompleteConfig = inDto.IsCompleteConfig
 | |
|             });
 | |
| 
 | |
|             if (inDto.IsCompleteConfig)
 | |
|             {
 | |
|                await SynchronizeSystemCriterion(inDto.Id);
 | |
|             }else
 | |
|             {
 | |
|                 await _readingQuestionCriterionTrialRepository.BatchUpdateNoTrackingAsync(x=>x.ReadingQuestionCriterionSystemId== inDto.Id, x => new ReadingQuestionCriterionTrial()
 | |
|                 {
 | |
|                     IsCompleteConfig = inDto.IsCompleteConfig
 | |
|                 });
 | |
|             }
 | |
|             var result = await _readingQuestionCriterionSystemRepository.SaveChangesAsync();
 | |
| 
 | |
|             return ResponseOutput.Ok(result);
 | |
|         }
 | |
| 
 | |
|         /// <summary>
 | |
|         /// 更改项目标准(老)
 | |
|         /// </summary>
 | |
|         /// <param name="systemCriterionId"></param>
 | |
|         /// <returns></returns>
 | |
|         private async Task UpdateTrialCriterion(Guid systemCriterionId)
 | |
|         {
 | |
|             await _readingQuestionCriterionTrialRepository.BatchUpdateNoTrackingAsync(x => x.ReadingQuestionCriterionSystemId == systemCriterionId, x => new ReadingQuestionCriterionTrial()
 | |
|             {
 | |
|                 IsCompleteConfig = true,
 | |
|             });
 | |
|             var systemCriterionQuestionList = await _readingQuestionSystemRepository.Where(x => x.ReadingQuestionCriterionSystemId == systemCriterionId).ToListAsync();
 | |
|             var trialCriterionList = await _readingQuestionCriterionTrialRepository.Where(x => x.ReadingQuestionCriterionSystemId == systemCriterionId).Select(x => new { 
 | |
|             x.Id,
 | |
|             x.TrialId,
 | |
|             }).ToListAsync();
 | |
|             var trialCriterionIdList = trialCriterionList.Select(x => x.Id).ToList();
 | |
|             List<ReadingQuestionTrial> needAddQuestionList = new List<ReadingQuestionTrial>();
 | |
|             foreach (var item in trialCriterionList)
 | |
|             {
 | |
|                 await _readingQuestionTrialRepository.BatchDeleteNoTrackingAsync(x => trialCriterionIdList.Contains(x.ReadingQuestionCriterionTrialId));
 | |
|                 List<ReadingQuestionTrial> trialQuestionList = new List<ReadingQuestionTrial>();
 | |
|                 SetChildParentQuestion(item.Id, item.TrialId, systemCriterionQuestionList, trialQuestionList);
 | |
|                 needAddQuestionList.AddRange(trialQuestionList);
 | |
|             }
 | |
|             await _readingQuestionTrialRepository.AddRangeAsync(needAddQuestionList);
 | |
|         }
 | |
| 
 | |
| 
 | |
|         /// <summary>
 | |
|         /// 更改项目标准(新)
 | |
|         /// </summary>
 | |
|         /// <param name="systemCriterionId"></param>
 | |
|         /// <returns></returns>
 | |
|         private async Task SynchronizeSystemCriterion(Guid systemCriterionId)
 | |
|         {
 | |
|             var systemCriterion = await _readingQuestionCriterionSystemRepository.FirstOrDefaultAsync(x=>x.Id== systemCriterionId);
 | |
| 
 | |
|             var trialCriterionList = await _readingQuestionCriterionTrialRepository.Where(x => x.ReadingQuestionCriterionSystemId == systemCriterionId).Select(x => new {
 | |
|                 x.Id,
 | |
|                 x.TrialId,
 | |
|             }).ToListAsync();
 | |
| 
 | |
|             var trialCriterionIds= trialCriterionList.Select(x => x.Id).ToList();
 | |
|             var systemQuestionList = await _readingQuestionSystemRepository.Where(x => x.ReadingQuestionCriterionSystemId == systemCriterionId).ToListAsync();
 | |
|             var trialQuestions = await _readingQuestionTrialRepository.Where(x => trialCriterionIds.Contains(x.ReadingQuestionCriterionTrialId)).Select(x => new TrialQuestion
 | |
|             {
 | |
|                 AnswerCombination = x.AnswerCombination,
 | |
|                 AnswerGroup = x.AnswerGroup,
 | |
|                 Id = x.Id,
 | |
|                 JudgeType = x.JudgeType,
 | |
|                 ParentId = x.ParentId,
 | |
|                 ReadingQuestionCriterionTrialId = x.ReadingQuestionCriterionTrialId,
 | |
|                 ReadingQuestionSystemId = x.ReadingQuestionSystemId,
 | |
|                 SystemParentId = x.SystemParentId
 | |
|             }).ToListAsync();
 | |
| 
 | |
|             List<ReadingQuestionTrial> trialQuestionList = new List<ReadingQuestionTrial>();
 | |
|             foreach (var item in trialCriterionList)
 | |
|             {
 | |
| 
 | |
|                 var thistrialQuestions = trialQuestions.Where(x => x.ReadingQuestionCriterionTrialId == item.Id).ToList();
 | |
| 
 | |
|                 var query = systemQuestionList.GroupJoin(thistrialQuestions, a => a.Id, b => b.ReadingQuestionSystemId, (a, b) => new
 | |
|                 {
 | |
|                    a,
 | |
|                    trialQuestion = b
 | |
|                 }).SelectMany(a => a.trialQuestion, (m, n) => new ReadingQuestionTrial
 | |
|                 {
 | |
|                    Id=n.Id,
 | |
|                    
 | |
|                 });
 | |
|              var needAddQuestionList = systemQuestionList.GroupJoin(thistrialQuestions, a => a.Id, b => b.ReadingQuestionSystemId, (x, y) => new { system = x, trial = y })
 | |
|                .SelectMany(
 | |
|                a => a.trial.DefaultIfEmpty(),
 | |
|                (c,d) => new ReadingQuestionTrial
 | |
|                {
 | |
|                    Id=(c.trial.FirstOrDefault()?.Id)??NewId.NextGuid(),
 | |
|                    ShowOrder=c.system.ShowOrder,
 | |
|                    SystemParentId=c.system.ParentId,
 | |
|                    ReadingQuestionSystemId=c.system.Id,
 | |
|                    AnswerCombination = (c.trial.FirstOrDefault()?.AnswerCombination)??string.Empty,
 | |
|                    AnswerGroup= (c.trial.FirstOrDefault()?.AnswerGroup) ?? string.Empty,
 | |
|                    GroupName=c.system.GroupName,
 | |
|                    IsEnable=c.system.IsEnable,
 | |
|                    IsJudgeQuestion=c.system.IsJudgeQuestion,
 | |
|                    IsRequired=c.system.IsRequired,
 | |
|                    JudgeType = (c.trial.FirstOrDefault()?.JudgeType)??JudgeTypeEnum.None,
 | |
|                    ParentId = c.trial.FirstOrDefault()?.ParentId,
 | |
|                    ParentTriggerValue=c.system.ParentTriggerValue,
 | |
|                    QuestionName=c.system.QuestionName,
 | |
|                    ReadingQuestionCriterionTrialId = item.Id,
 | |
|                    Remark=c.system.Remark,
 | |
|                    TrialId=item.TrialId,
 | |
|                    Type=c.system.Type,
 | |
|                    TypeValue=c.system.TypeValue,
 | |
|                }).ToList();
 | |
|                var copydata = needAddQuestionList.Clone();
 | |
|                 needAddQuestionList.ForEach(x =>
 | |
|                 {
 | |
|                     if (x.SystemParentId == null)
 | |
|                     {
 | |
|                         x.ParentId = null;
 | |
|                     }
 | |
|                     else
 | |
|                     {
 | |
|                         x.ParentId = copydata.FirstOrDefault(y => y.ReadingQuestionSystemId == x.SystemParentId).Id;
 | |
|                     }
 | |
|                 });
 | |
| 
 | |
|                 trialQuestionList.AddRange(needAddQuestionList);
 | |
|             }
 | |
|             await _readingQuestionTrialRepository.BatchDeleteNoTrackingAsync(x => trialCriterionIds.Contains(x.ReadingQuestionCriterionTrialId));
 | |
|             await _readingQuestionCriterionTrialRepository.BatchUpdateNoTrackingAsync(x => trialCriterionIds.Contains(x.Id), x => new ReadingQuestionCriterionTrial()
 | |
|             {
 | |
|                 IsEnable = systemCriterion.IsEnable,
 | |
|                 CriterionName = systemCriterion.CriterionName,
 | |
|                 ShowOrder = systemCriterion.ShowOrder,
 | |
|                 IsCompleteConfig = systemCriterion.IsCompleteConfig,
 | |
| 
 | |
|             });
 | |
| 
 | |
|             await _readingQuestionTrialRepository.AddRangeAsync(trialQuestionList);
 | |
|             await _readingQuestionTrialRepository.SaveChangesAsync();
 | |
|         }
 | |
| 
 | |
| 
 | |
|         /// <summary>
 | |
|         /// 添加系统qc问题标准
 | |
|         /// </summary>
 | |
|         /// <returns></returns>
 | |
|         [NonDynamicMethod]
 | |
|         private async Task AddSystemQuestionCriterion()
 | |
|         {
 | |
|             var useSystemQuestionCriterionIds = _readingQuestionCriterionSystemRepository.Select(x => x.CriterionId);
 | |
|             var dictionaryParentId =await _dictionaryRepository.Where(x => x.Code == "ReadingStandard").Select(x => x.Id).FirstOrDefaultAsync();
 | |
|             var criterionList = await _dictionaryRepository.Where(x => x.ParentId == dictionaryParentId && !useSystemQuestionCriterionIds.Contains(x.Id))
 | |
|                 .Select(x => new CriterionList()
 | |
|                 {
 | |
|                     Id = x.Id,
 | |
|                     Value = x.Value,
 | |
|                     ShowOrder=x.ShowOrder,
 | |
|                 }).ToListAsync();
 | |
|             List<ReadingQuestionCriterionSystem> needAddCriterionList = new List<ReadingQuestionCriterionSystem>();
 | |
|             criterionList.ForEach(x =>
 | |
|             {
 | |
|                 needAddCriterionList.Add(new ReadingQuestionCriterionSystem()
 | |
|                 {
 | |
|                     CriterionId = x.Id,
 | |
|                     ShowOrder=x.ShowOrder,
 | |
|                     CriterionName = x.Value,
 | |
|                     IsEnable = false,
 | |
|                 });
 | |
|             });
 | |
|            await  _readingQuestionCriterionSystemRepository.AddRangeAsync(needAddCriterionList);
 | |
|            await _readingQuestionCriterionSystemRepository.SaveChangesAsync();
 | |
|         }
 | |
| 
 | |
|         ///// <summary>
 | |
|         ///// 删除系统问题标准
 | |
|         ///// </summary>
 | |
|         ///// <param name="readingQuestionCriterionSystemId"></param>
 | |
|         ///// <returns></returns>
 | |
|         //[HttpDelete("{readingQuestionCriterionSystemId:guid}")]
 | |
|         //public async Task<IResponseOutput> DeleteReadingQuestionCriterionSystem(Guid readingQuestionCriterionSystemId)
 | |
|         //{
 | |
|         //     await _readingQuestionCriterionSystemRepository.DeleteFromQueryAsync(t => t.Id == readingQuestionCriterionSystemId);
 | |
|         //    var success = await _readingQuestionCriterionSystemRepository.SaveChangesAsync();
 | |
|         //    return ResponseOutput.Result(success);
 | |
|         //}
 | |
| 
 | |
| 
 | |
| 
 | |
|         /// <summary>
 | |
|         /// 新增修改系统问题
 | |
|         /// </summary>
 | |
|         /// <param name="indto"></param>
 | |
|         /// <returns></returns>
 | |
|         [HttpPost]
 | |
|         public async Task<IResponseOutput> AddOrUpdateReadingQuestionSystem(AddOrUpdateReadingQuestionSystemInDto indto)
 | |
|         {
 | |
|             if (indto.Id != null)
 | |
|             {
 | |
|                 var trialIdList = await _readingQuestionTrialRepository.Where(x => x.ReadingQuestionSystemId == indto.Id && x.IsJudgeQuestion && x.JudgeType != JudgeTypeEnum.None)
 | |
|                     .Select(x => x.TrialId).ToListAsync();
 | |
| 
 | |
|                 if (trialIdList.Count>0)
 | |
|                 {
 | |
|                     var trialNames = await _trialRepository.Where(x => trialIdList.Contains(x.Id)).Select(x => x.ExperimentName).ToListAsync();
 | |
|                     throw new BusinessValidationFailedException("当前问题在项目"+ string.Join(',', trialNames)  + "设置了裁判标准了,修改失败");
 | |
|                 }
 | |
|             }
 | |
| 
 | |
|             if (await _readingQuestionSystemRepository.AnyAsync(x => x.Id != indto.Id && x.ShowOrder == indto.ShowOrder))
 | |
|             {
 | |
|                 throw new BusinessValidationFailedException("问题编号重复");
 | |
|             }
 | |
|             var entity = await _readingQuestionSystemRepository.InsertOrUpdateAsync(indto, true);
 | |
|             return ResponseOutput.Ok(entity.Id.ToString());
 | |
|         }
 | |
| 
 | |
|         /// <summary>
 | |
|         /// 获取系统问题
 | |
|         /// </summary>
 | |
|         /// <returns></returns>
 | |
|         [HttpPost]
 | |
|         public async Task<PageOutput<ReadingQuestionSystemView>> GetReadingQuestionSystemList(ReadingQuestionSystemViewInDto inDto)
 | |
|         {
 | |
|             var query = _readingQuestionSystemRepository.AsQueryable()
 | |
|                 .Where(x=>x.ReadingQuestionCriterionSystemId==inDto.ReadingQuestionCriterionSystemId)
 | |
|                  .WhereIf(!inDto.QuestionName.IsNullOrEmpty(), x => x.QuestionName.Contains(inDto.QuestionName))
 | |
|                   .WhereIf(!inDto.Type.IsNullOrEmpty(), x => x.Type.Contains(inDto.Type))
 | |
|                  .ProjectTo<ReadingQuestionSystemView>(_mapper.ConfigurationProvider);
 | |
|             return await query.ToPagedListAsync(inDto.PageIndex, inDto.PageSize, inDto.SortField.IsNullOrEmpty() ? nameof(ReadingQuestionSystemView.ShowOrder) : inDto.SortField,
 | |
|              inDto.Asc);
 | |
|         }
 | |
| 
 | |
|         /// <summary>
 | |
|         /// 获取系统标准的其他问题
 | |
|         /// </summary>
 | |
|         /// <param name="inDto"></param>
 | |
|         /// <returns></returns>
 | |
|         [HttpPost]
 | |
|         public async Task<List<CriterionOtherQuestionOutDto>> GetSystemCriterionOtherQuestion(GetSystemCriterionOtherQuestionInDto inDto)
 | |
|         {
 | |
|             var types = new List<string>()
 | |
|             {
 | |
|                 "select","radio"
 | |
|             };
 | |
|             var questionList =await _readingQuestionSystemRepository.Where(x => x.ReadingQuestionCriterionSystemId == inDto.ReadingQuestionCriterionSystemId)
 | |
|                 .Where(x=> types.Contains(x.Type))
 | |
|                 .WhereIf(inDto.Id != null, x => x.Id != inDto.Id&&x.ParentId!= inDto.Id)
 | |
|                 .Select(x => new CriterionOtherQuestionOutDto()
 | |
|                 {
 | |
|                     QuestionId = x.Id,
 | |
|                     QuestionName = x.QuestionName,
 | |
|                     TypeValue=x.TypeValue,
 | |
|                     GroupName = x.GroupName,
 | |
|                 }).ToListAsync();
 | |
| 
 | |
|             return questionList;
 | |
|         }
 | |
| 
 | |
|         /// <summary>
 | |
|         /// 删除系统问题
 | |
|         /// </summary>
 | |
|         /// <param name="id"></param>
 | |
|         /// <returns></returns>
 | |
|         [HttpDelete("{id:guid}")]
 | |
|         public async Task<IResponseOutput> DeleteReadingQuestionSystem(Guid id)
 | |
|         {
 | |
|             if (await _readingQuestionSystemRepository.AnyAsync(x => x.ParentId == id))
 | |
|             {
 | |
|                 return ResponseOutput.NotOk("此问题存在子问题,请先删除子问题");
 | |
|             }
 | |
|             await _readingQuestionSystemRepository.DeleteFromQueryAsync(t => t.Id == id);
 | |
|             var success = await _readingQuestionSystemRepository.SaveChangesAsync();
 | |
|             return ResponseOutput.Result(success);
 | |
|         }
 | |
| 
 | |
|         /// <summary>
 | |
|         /// 添加系统数据到项目里面
 | |
|         /// </summary>
 | |
|         /// <returns></returns>  
 | |
|         [NonDynamicMethod]
 | |
|         private async Task AddSystemDataToTrila(Guid trialId)
 | |
|         {
 | |
|             var trialUsrSystemIds = _readingQuestionCriterionTrialRepository.Where(x => x.TrialId == trialId && x.ReadingQuestionCriterionSystemId != null)
 | |
|                 .Select(x => x.ReadingQuestionCriterionSystemId);
 | |
|             var needAddSystemDataList = await _readingQuestionCriterionSystemRepository.Where(x => !trialUsrSystemIds.Contains(x.Id)&&x.Dictionary.IsEnable).Include(x=>x.ReadingQuestionSystemList).ToListAsync();
 | |
|             List<ReadingQuestionCriterionTrial> needAddCriterionList = new List<ReadingQuestionCriterionTrial>();
 | |
|             List<ReadingQuestionTrial> needAddQuestionList = new List<ReadingQuestionTrial>();
 | |
|             needAddSystemDataList.ForEach(x =>
 | |
|             {
 | |
|                 var criterion = new ReadingQuestionCriterionTrial()
 | |
|                 {
 | |
|                     CriterionName = x.CriterionName,
 | |
|                     IsEnable = false,
 | |
|                     ReadingQuestionCriterionSystemId = x.Id,
 | |
|                     TrialId = trialId,
 | |
|                     IsCompleteConfig=x.IsCompleteConfig,
 | |
|                     Id = NewId.NextGuid(),
 | |
|                 };
 | |
|                 List<ReadingQuestionSystem> systemQuestionList = x.ReadingQuestionSystemList.Clone();
 | |
|                 List<ReadingQuestionTrial> readingQuestionTrialList = new List<ReadingQuestionTrial>();
 | |
|                 SetChildParentQuestion(criterion.Id, trialId, systemQuestionList, readingQuestionTrialList);
 | |
|                 needAddCriterionList.Add(criterion);
 | |
|                 needAddQuestionList.AddRange(readingQuestionTrialList);
 | |
|             });
 | |
|             await _readingQuestionCriterionTrialRepository.AddRangeAsync(needAddCriterionList);
 | |
|             await _readingQuestionTrialRepository.AddRangeAsync(needAddQuestionList);
 | |
|             await _readingQuestionTrialRepository.SaveChangesAsync();
 | |
|         }
 | |
| 
 | |
|         /// <summary>
 | |
|         /// 设置父子关系
 | |
|         /// </summary>
 | |
|         /// <param name="ReadingQuestionCriterionTrialId">项目标准ID</param>
 | |
|         /// <param name="trialId">项目Id</param>
 | |
|         /// <param name="systemQuesitonList">系统问题</param>
 | |
|         /// <param name="needQuestionList">需要添加list</param>
 | |
|         private void SetChildParentQuestion(Guid ReadingQuestionCriterionTrialId, Guid trialId, List<ReadingQuestionSystem> systemQuesitonList,List<ReadingQuestionTrial> needQuestionList)
 | |
|         {
 | |
|             var parentIdIsNullList = systemQuesitonList.Where(x => x.ParentId == null).ToList();
 | |
|             parentIdIsNullList.ForEach(x =>
 | |
|             {
 | |
|                 var quesiton = x.Clone();
 | |
|                 var oldId = quesiton.Id;
 | |
|                 var newId = NewId.NextGuid();
 | |
|                 needQuestionList.Add(new ReadingQuestionTrial()
 | |
|                 {
 | |
|                     Id = newId,
 | |
|                     ShowOrder = quesiton.ShowOrder,
 | |
|                     IsEnable = quesiton.IsEnable,
 | |
|                     IsRequired = quesiton.IsRequired,
 | |
|                     ParentTriggerValue = quesiton.ParentTriggerValue,
 | |
|                     QuestionName = quesiton.QuestionName,
 | |
|                     ReadingQuestionCriterionTrialId = ReadingQuestionCriterionTrialId,
 | |
|                     ReadingQuestionSystemId= quesiton.Id,
 | |
|                     SystemParentId=quesiton.ParentId,
 | |
|                     TrialId = trialId,
 | |
|                     AnswerGroup = string.Empty,
 | |
|                     Type = quesiton.Type,
 | |
|                     GroupName=quesiton.GroupName,
 | |
|                     IsJudgeQuestion =quesiton.IsJudgeQuestion,
 | |
|                     Remark=quesiton.Remark,
 | |
|                     TypeValue = quesiton.TypeValue,
 | |
|                 });
 | |
| 
 | |
|                 CreateQuestionRelation(ReadingQuestionCriterionTrialId, trialId, oldId, newId, systemQuesitonList, needQuestionList);
 | |
|             });
 | |
|         }
 | |
| 
 | |
|         /// <summary>
 | |
|         /// 递归处理父子关系
 | |
|         /// </summary>
 | |
|         /// <param name="ReadingQuestionCriterionTrialId"></param>
 | |
|         /// <param name="trialId"></param>
 | |
|         /// <param name="oldParentId"></param>
 | |
|         /// <param name="newParentId"></param>
 | |
|         /// <param name="systemQuesitonList"></param>
 | |
|         /// <param name="needQuestionList"></param>
 | |
|         private void CreateQuestionRelation(Guid ReadingQuestionCriterionTrialId, Guid trialId,Guid oldParentId,Guid newParentId, List<ReadingQuestionSystem> systemQuesitonList, List<ReadingQuestionTrial> needQuestionList)
 | |
|         {
 | |
|             var childList = systemQuesitonList.Where(x => x.ParentId == oldParentId).ToList();
 | |
|             childList.ForEach(x =>
 | |
|             {
 | |
|                 var quesiton = x.Clone();
 | |
|                 var oldId = quesiton.Id;
 | |
|                 var newId = NewId.NextGuid();
 | |
|                 needQuestionList.Add(new ReadingQuestionTrial()
 | |
|                 {
 | |
|                     Id = newId,
 | |
|                     ShowOrder = quesiton.ShowOrder,
 | |
|                     IsEnable = quesiton.IsEnable,
 | |
|                     IsRequired = quesiton.IsRequired,
 | |
|                     ParentId = newParentId,
 | |
|                     SystemParentId = quesiton.ParentId,
 | |
|                     ReadingQuestionSystemId = x.Id,
 | |
|                     AnswerGroup = string.Empty,
 | |
|                     ParentTriggerValue = quesiton.ParentTriggerValue,
 | |
|                     QuestionName = quesiton.QuestionName,
 | |
|                     ReadingQuestionCriterionTrialId = ReadingQuestionCriterionTrialId,
 | |
|                     TrialId = trialId,
 | |
|                     GroupName = quesiton.GroupName,
 | |
|                     Type = quesiton.Type,
 | |
|                     IsJudgeQuestion = quesiton.IsJudgeQuestion,
 | |
|                     Remark = quesiton.Remark,
 | |
|                     TypeValue = quesiton.TypeValue,
 | |
|                 }) ;
 | |
| 
 | |
|                 CreateQuestionRelation(ReadingQuestionCriterionTrialId, trialId, oldId, newId, systemQuesitonList, needQuestionList);
 | |
|             });
 | |
| 
 | |
|         }
 | |
| 
 | |
|         /// <summary>
 | |
|         /// 新增修改项目问题标准(项目)
 | |
|         /// </summary>
 | |
|         /// <param name="indto"></param>
 | |
|         /// <returns></returns>
 | |
|         [HttpPost]
 | |
|         public async Task<IResponseOutput> AddOrUpdateReadingQuestionCriterionTrial(AddOrUpdateReadingQuestionCriterionTrialInDto indto)
 | |
|         {
 | |
| 
 | |
|             var entity = await _readingQuestionCriterionTrialRepository.InsertOrUpdateAsync(indto, true);
 | |
|             return ResponseOutput.Ok(entity.Id.ToString());
 | |
|         }
 | |
| 
 | |
|         /// <summary>
 | |
|         /// 获取预览问题信息
 | |
|         /// </summary>
 | |
|         /// <param name="inDto"></param>
 | |
|         /// <returns></returns>
 | |
|         [HttpPost]
 | |
|         public async Task<List<GetTrialReadingQuestionOutDto>> GetPreviewTheQuestion(GetPreviewTheQuestionInDto inDto)
 | |
|         {
 | |
|             var trialQuestionQuery = from trialQuestion in _readingQuestionTrialRepository.Where(x=>x.ReadingQuestionCriterionTrialId== inDto.Id)
 | |
|                             select new GetTrialReadingQuestionOutDto()
 | |
|                             {
 | |
|                                 ReadingQuestionTrialId = trialQuestion.Id,
 | |
|                                 ReadingQuestionCriterionTrialId = trialQuestion.ReadingQuestionCriterionTrialId,
 | |
|                                 TrialId = trialQuestion.TrialId,
 | |
|                                 Type = trialQuestion.Type,
 | |
|                                 ParentTriggerValue = trialQuestion.ParentTriggerValue,
 | |
|                                 GroupName = trialQuestion.GroupName,
 | |
|                                 QuestionName = trialQuestion.QuestionName,
 | |
|                                 IsRequired = trialQuestion.IsRequired,
 | |
|                                 ShowOrder = trialQuestion.ShowOrder,
 | |
|                                 ParentId = trialQuestion.ParentId,
 | |
|                                 TypeValue = trialQuestion.TypeValue,
 | |
|                                 Answer = string.Empty
 | |
|                             };
 | |
|             var qusetionList = await trialQuestionQuery.OrderBy(x => x.ShowOrder).ToListAsync();
 | |
|             List<GetTrialReadingQuestionOutDto> readingQuestionList = qusetionList.Where(x => x.ParentId == null).ToList();
 | |
|             readingQuestionList.ForEach(x =>
 | |
|             {
 | |
|                 _readingImageTaskService.FindChildQuestion(x, qusetionList);
 | |
|             });
 | |
| 
 | |
|             return readingQuestionList;
 | |
|         }
 | |
| 
 | |
|         ///// <summary>
 | |
|         ///// 设置项目标准是否生效
 | |
|         ///// </summary>
 | |
|         ///// <param name="inDto"></param>
 | |
|         ///// <returns></returns>
 | |
|         //public async Task<IResponseOutput> SetTrialReadingQuestionCriterionIsIsEnable(SetSystemReadingQuestionCriterionIsIsEnable inDto)
 | |
|         //{
 | |
|         //    await _readingQuestionCriterionTrialRepository.UpdatePartialFromQueryAsync(inDto.Id, x => new ReadingQuestionCriterionTrial()
 | |
|         //    {
 | |
|         //        IsEnable = inDto.IsEnable
 | |
|         //    });
 | |
| 
 | |
|         //    var result = await _readingQuestionCriterionTrialRepository.SaveChangesAsync();
 | |
| 
 | |
|         //    return ResponseOutput.Ok(result);
 | |
|         //}
 | |
| 
 | |
|         /// <summary>
 | |
|         /// 设置项目标准是否完成配置
 | |
|         /// </summary>
 | |
|         /// <param name="inDto"></param>
 | |
|         /// <returns></returns>
 | |
|         public async Task<IResponseOutput> SetTrialReadingQuestionCriterionIsIsCompleteConfig(SetSystemReadingQuestionCriterionIsIsCompleteConfig inDto)
 | |
|         {
 | |
|             await _readingQuestionCriterionTrialRepository.UpdatePartialFromQueryAsync(inDto.Id, x => new ReadingQuestionCriterionTrial()
 | |
|             {
 | |
|                 IsCompleteConfig = inDto.IsCompleteConfig
 | |
|             });
 | |
| 
 | |
|             var result = await _readingQuestionCriterionTrialRepository.SaveChangesAsync();
 | |
| 
 | |
|             return ResponseOutput.Ok(result);
 | |
|         }
 | |
| 
 | |
|         /// <summary>
 | |
|         /// 获取项目问题标准(项目)
 | |
|         /// </summary>
 | |
|         /// <returns></returns>
 | |
|         [HttpPost]
 | |
|         public async Task<PageOutput<ReadingQuestionCriterionTrialView>> GetReadingQuestionCriterionTrialList(ReadingQuestionCriterionTrialViewInDto inDto)
 | |
|         {
 | |
|             await AddSystemDataToTrila(inDto.TrialId);
 | |
|             var query = _readingQuestionCriterionTrialRepository.AsQueryable()
 | |
|                 .Where(x=>x.TrialId==inDto.TrialId)
 | |
|                  .WhereIf(!inDto.CriterionName.IsNullOrEmpty(), x => x.CriterionName.Contains(inDto.CriterionName))
 | |
|                  .ProjectTo<ReadingQuestionCriterionTrialView>(_mapper.ConfigurationProvider);
 | |
|             return await query.ToPagedListAsync(inDto.PageIndex, inDto.PageSize, inDto.SortField == null ? nameof(ReadingQuestionCriterionTrialView.CriterionName) : inDto.SortField,
 | |
|              inDto.Asc);
 | |
|         }
 | |
| 
 | |
|         /// <summary>
 | |
|         /// 删除项目问题标准(项目)
 | |
|         /// </summary>
 | |
|         /// <param name="id"></param>
 | |
|         /// <returns></returns>
 | |
|         [HttpDelete("{id:guid}")]
 | |
|         public async Task<IResponseOutput> DeleteReadingQuestionCriterionTrial(Guid id)
 | |
|         {
 | |
|             await _readingQuestionCriterionTrialRepository.DeleteFromQueryAsync(t => t.Id == id);
 | |
|             var success = await _readingQuestionCriterionTrialRepository.SaveChangesAsync();
 | |
|             return ResponseOutput.Result(success);
 | |
|         }
 | |
| 
 | |
|         /// <summary>
 | |
|         /// 新增修改项目问题(项目)
 | |
|         /// </summary>
 | |
|         /// <param name="indto"></param>
 | |
|         /// <returns></returns>
 | |
|         [HttpPost]
 | |
|         public async Task<IResponseOutput> AddOrUpdateReadingQuestionTrial(AddOrUpdateReadingQuestionTrialInDto indto)
 | |
|         {
 | |
|             if (indto.Id != null)
 | |
|             {
 | |
|                 if (await _readingQuestionTrialRepository.AnyAsync(x => x.Id == indto.Id && x.IsJudgeQuestion && x.JudgeType != JudgeTypeEnum.None))
 | |
|                 {
 | |
|                     throw new BusinessValidationFailedException("当前问题已经设置了裁判标准了,修改失败");
 | |
|                 }
 | |
|             }
 | |
| 
 | |
|             if (await _readingQuestionTrialRepository.AnyAsync(x => x.Id != indto.Id && x.ShowOrder == indto.ShowOrder))
 | |
|             {
 | |
|                 throw new BusinessValidationFailedException("问题编号重复");
 | |
|             }
 | |
|             var entity = await _readingQuestionTrialRepository.InsertOrUpdateAsync(indto, true);
 | |
|             return ResponseOutput.Ok(entity.Id.ToString());
 | |
|         }
 | |
| 
 | |
|         /// <summary>
 | |
|         /// 获取项目问题(项目)
 | |
|         /// </summary>
 | |
|         /// <returns></returns>
 | |
|         [HttpPost]
 | |
|         public async Task<PageOutput<ReadingQuestionTrialView>> GetReadingQuestionTrialList(ReadingQuestionTrialViewInDto inDto)
 | |
|         {
 | |
|             var query = _readingQuestionTrialRepository.AsQueryable()
 | |
|                 .Where(x => x.ReadingQuestionCriterionTrialId == inDto.ReadingQuestionCriterionTrialId)
 | |
|                  .WhereIf(!inDto.QuestionName.IsNullOrEmpty(), x => x.QuestionName.Contains(inDto.QuestionName))
 | |
|                   .WhereIf(!inDto.Type.IsNullOrEmpty(), x => x.Type.Contains(inDto.Type))
 | |
|                  .ProjectTo<ReadingQuestionTrialView>(_mapper.ConfigurationProvider);
 | |
|             return await query.ToPagedListAsync(inDto.PageIndex, inDto.PageSize, inDto.SortField.IsNullOrEmpty() ? nameof(ReadingQuestionTrialView.ShowOrder) : inDto.SortField,
 | |
|              inDto.Asc);
 | |
|         }
 | |
| 
 | |
|         /// <summary>
 | |
|         /// 获取项目标准的其他问题(项目)
 | |
|         /// </summary>
 | |
|         /// <param name="inDto"></param>
 | |
|         /// <returns></returns>
 | |
|         [HttpPost]
 | |
|         public async Task<List<CriterionOtherQuestionOutDto>> GetTrialCriterionOtherQuestion(GetTrialCriterionOtherQuestionInDto inDto)
 | |
|         {
 | |
|             var types = new List<string>()
 | |
|             {
 | |
|                 "select","radio"
 | |
|             };
 | |
|             var questionList = await _readingQuestionTrialRepository.Where(x => x.ReadingQuestionCriterionTrialId == inDto.ReadingQuestionCriterionTrialId)
 | |
|                    .Where(x => types.Contains(x.Type))
 | |
|                 .WhereIf(inDto.Id != null, x => x.Id != inDto.Id && x.ParentId != inDto.Id)
 | |
|                 .Select(x => new CriterionOtherQuestionOutDto()
 | |
|                 {
 | |
|                     QuestionId = x.Id,
 | |
|                     QuestionName = x.QuestionName,
 | |
|                     TypeValue = x.TypeValue,
 | |
|                     GroupName=x.GroupName,
 | |
|                 }).ToListAsync();
 | |
| 
 | |
|             return questionList;
 | |
|         }
 | |
| 
 | |
|         /// <summary>
 | |
|         /// 删除项目问题(项目)
 | |
|         /// </summary>
 | |
|         /// <param name="id"></param>
 | |
|         /// <returns></returns>
 | |
|         [HttpDelete("{id:guid}")]
 | |
|         public async Task<IResponseOutput> DeleteReadingQuestionTrial(Guid id)
 | |
|         {
 | |
|             if (await _readingQuestionTrialRepository.AnyAsync(x => x.ParentId == id))
 | |
|             {
 | |
|                 return ResponseOutput.NotOk("此问题存在子问题,请先删除子问题");
 | |
|             }
 | |
|             await _readingQuestionTrialRepository.DeleteFromQueryAsync(t => t.Id == id);
 | |
|             var success = await _readingQuestionTrialRepository.SaveChangesAsync();
 | |
|             return ResponseOutput.Result(success);
 | |
|         }
 | |
| 
 | |
|         /// <summary>
 | |
|         /// 获取项目问题分组
 | |
|         /// </summary>
 | |
|         /// <param name="inDto"></param>
 | |
|         /// <returns></returns>
 | |
|         [HttpPost]
 | |
|         public async Task<List<string>> GetTrialGroupNameList(GetTrialGroupNameListInDto inDto)
 | |
|         {
 | |
|             var result = await _readingQuestionTrialRepository.Where(x => x.ReadingQuestionCriterionTrialId == inDto.CriterionId && x.Type == "group")
 | |
|                   .Select(x => x.GroupName).ToListAsync();
 | |
| 
 | |
|             return result;
 | |
| 
 | |
|         }
 | |
| 
 | |
| 
 | |
|         /// <summary>
 | |
|         /// 获取系统问题分组
 | |
|         /// </summary>
 | |
|         /// <param name="inDto"></param>
 | |
|         /// <returns></returns>
 | |
|         [HttpPost]
 | |
|         public async Task<List<string>> GetSystemGroupNameList(GetTrialGroupNameListInDto inDto)
 | |
|         {
 | |
|             var result = await _readingQuestionSystemRepository.Where(x => x.ReadingQuestionCriterionSystemId == inDto.CriterionId && x.Type == "group")
 | |
|                   .Select(x => x.GroupName).ToListAsync();
 | |
|             return result;
 | |
| 
 | |
|         }
 | |
|     }
 | |
| }
 |