169 lines
		
	
	
		
			7.1 KiB
		
	
	
	
		
			C#
		
	
	
			
		
		
	
	
			169 lines
		
	
	
		
			7.1 KiB
		
	
	
	
		
			C#
		
	
	
| //--------------------------------------------------------------------
 | ||
| //     此代码由T4模板自动生成  byzhouhang 20210918
 | ||
| //	   生成时间 2021-11-11 11:04:54 
 | ||
| //     对此文件的更改可能会导致不正确的行为,并且如果重新生成代码,这些更改将会丢失。
 | ||
| //--------------------------------------------------------------------
 | ||
| 
 | ||
| using IRaCIS.Core.Infra.EFCore;
 | ||
| using Microsoft.AspNetCore.Mvc;
 | ||
| 
 | ||
| namespace IRaCIS.Core.Application.Contracts
 | ||
| {
 | ||
|     /// <summary>
 | ||
|     /// 项目QC 问题 管理
 | ||
|     /// </summary>	
 | ||
|     [ApiExplorerSettings(GroupName = "Image")]
 | ||
|     public class TrialQCQuestionConfigureService : BaseService, ITrialQCQuestionConfigureService
 | ||
|     {
 | ||
|         private readonly IRepository<TrialQCQuestion> _trialQcQuestionRepository;
 | ||
| 
 | ||
|         public TrialQCQuestionConfigureService(IRepository<TrialQCQuestion> trialQcQuestionRepository)
 | ||
|         {
 | ||
|             _trialQcQuestionRepository = trialQcQuestionRepository;
 | ||
|         }
 | ||
| 
 | ||
| 
 | ||
|         [HttpPost]
 | ||
|         public async Task<(List<TrialQCQuestionConfigureView>, object)> GetTrialQCQuestionConfigureList(TrialQCQuestionQuery queryTrialQCQuestionConfigure)
 | ||
|         {
 | ||
| 
 | ||
| 
 | ||
|             var trialQCQuestionQueryable = _trialQcQuestionRepository.Where(t => t.TrialId == queryTrialQCQuestionConfigure.TrialId)
 | ||
|                .WhereIf(!string.IsNullOrWhiteSpace(queryTrialQCQuestionConfigure.QuestionName), t => t.QuestionName.Contains(queryTrialQCQuestionConfigure.QuestionName))
 | ||
|                .WhereIf(!string.IsNullOrWhiteSpace(queryTrialQCQuestionConfigure.Type), t => t.Type.Contains(queryTrialQCQuestionConfigure.Type))
 | ||
|             .ProjectTo<TrialQCQuestionConfigureView>(_mapper.ConfigurationProvider);
 | ||
| 
 | ||
|             var list = await trialQCQuestionQueryable.OrderBy(t => t.ShowOrder).ToListAsync();
 | ||
| 
 | ||
|             var isHaveQCQuestion = _repository.Where<TrialQCQuestion>(t => t.TrialId == queryTrialQCQuestionConfigure.TrialId).Any();
 | ||
| 
 | ||
| 
 | ||
|             var signInfo = await _repository.Where<Trial>(t => t.Id == queryTrialQCQuestionConfigure.TrialId)
 | ||
|                 .Select(trial => new {trial.QCProcessEnum,   trial.QCQuestionConfirmedTime, trial.QCQuestionConfirmedUserId,
 | ||
|                     RealName = trial.QCQuestionConfirmedUser.FullName, trial.QCQuestionConfirmedUser.UserName,
 | ||
|                     IsHaveQCQuestion= isHaveQCQuestion
 | ||
|                 }).FirstOrDefaultAsync();
 | ||
| 
 | ||
|             return (list, signInfo!);
 | ||
|         }
 | ||
| 
 | ||
| 
 | ||
|         /// <summary>
 | ||
|         /// 父问题  下拉框选项  需要排除自己  、把自己设置为父亲 (互为父亲) 、是自己孙辈的(明明是自己子孙,却设置为自己父亲)
 | ||
|         /// </summary>
 | ||
|         /// <param name="trialQCQuestionFilterSelect"></param>
 | ||
|         /// <returns></returns>
 | ||
|         [HttpPost]
 | ||
|         public async Task<List<TrialQCQuestionSelect>> GetTrialQCQuestionSelectList(TrialQCQuestionFilterSelect trialQCQuestionFilterSelect)
 | ||
|         {
 | ||
| 
 | ||
|             //设置父亲的时候,不允许设置为自己的孙子   这种会形成环
 | ||
| 
 | ||
|             var initList = await _trialQcQuestionRepository.Where(t => t.TrialId == trialQCQuestionFilterSelect.TrialId)
 | ||
|                  .WhereIf(trialQCQuestionFilterSelect.TypeArray.Count() > 0, t => trialQCQuestionFilterSelect.TypeArray.Contains(t.Type))
 | ||
|                 //.WhereIf(trialQCQuestionFilterSelect.Id != null, t => t.Id != trialQCQuestionFilterSelect.Id /*&& t.ParentId != trialQCQuestionFilterSelect.Id*/)
 | ||
|                 .OrderBy(t => t.ShowOrder).ProjectTo<TrialQCQuestionSelect>(_mapper.ConfigurationProvider).ToListAsync();
 | ||
| 
 | ||
|             //父亲的序号肯定要比自己小
 | ||
|             if (trialQCQuestionFilterSelect.Id != null)
 | ||
|             {
 | ||
|                 var selectItem = initList.FirstOrDefault(t => t.Id == trialQCQuestionFilterSelect.Id);
 | ||
| 
 | ||
|                 initList = initList.WhereIf(selectItem != null, t => t.Id != selectItem!.Id && t.ShowOrder < selectItem.ShowOrder).ToList();
 | ||
|             }
 | ||
| 
 | ||
| 
 | ||
|             var exceptList = GetChildId(trialQCQuestionFilterSelect.Id ?? Guid.Empty, initList);
 | ||
| 
 | ||
| 
 | ||
|             return initList.Where(t => !exceptList.Contains(t.Id)).ToList();
 | ||
|         }
 | ||
| 
 | ||
| 
 | ||
|         private List<Guid> GetChildId(Guid parentId, List<TrialQCQuestionSelect> list)
 | ||
|         {
 | ||
| 
 | ||
|             var ids = new List<Guid>();
 | ||
| 
 | ||
|             var childIds = list.Where(t => t.ParentId == parentId).Select(t => t.Id).ToList();
 | ||
| 
 | ||
|             foreach (var childId in childIds)
 | ||
|             {
 | ||
|                 ids.AddRange(childId);
 | ||
| 
 | ||
|                 var childs = GetChildId(childId, list);
 | ||
| 
 | ||
|                 ids.AddRange(childs);
 | ||
| 
 | ||
|             }
 | ||
| 
 | ||
|             return ids;
 | ||
|         }
 | ||
| 
 | ||
|         /// <summary>
 | ||
|         /// 批量添加 QC 问题
 | ||
|         /// </summary>
 | ||
|         /// <param name="batchList"></param>
 | ||
|         /// <param name="trialId"></param>
 | ||
|         /// <returns></returns>
 | ||
|         [HttpPost("{trialId:guid}")]
 | ||
|         public async Task<IResponseOutput> BatchAddTrialQCQuestionConfigure(List<TrialQCQuestionConfigureBatchAdd> batchList, Guid trialId)
 | ||
|         {
 | ||
|             if (!await _repository.AnyAsync<Trial>(t => t.Id == trialId && t.QCQuestionConfirmedUserId == null))
 | ||
|             {
 | ||
|                 return ResponseOutput.NotOk("QC已确认,不允许操作");
 | ||
|             }
 | ||
| 
 | ||
|             var batchConfigList = _mapper.Map<List<TrialQCQuestion>>(batchList);
 | ||
|             batchConfigList.ForEach(t => t.TrialId = trialId);
 | ||
| 
 | ||
|             await _trialQcQuestionRepository.AddRangeAsync(batchConfigList);
 | ||
| 
 | ||
|             var success = await _repository.SaveChangesAsync();
 | ||
| 
 | ||
|             return ResponseOutput.Result(success);
 | ||
|         }
 | ||
| 
 | ||
| 
 | ||
|         public async Task<IResponseOutput> AddOrUpdateTrialQCQuestionConfigure(TrialQCQuestionAddOrEdit addOrEditTrialQCQuestionConfigure)
 | ||
|         {
 | ||
|             if (!await _repository.AnyAsync<Trial>(t => t.Id == addOrEditTrialQCQuestionConfigure.TrialId && t.QCQuestionConfirmedUserId == null))
 | ||
|             {
 | ||
|                 return ResponseOutput.NotOk("QC已确认,不允许操作");
 | ||
|             }
 | ||
| 
 | ||
|             var entity = await _trialQcQuestionRepository.InsertOrUpdateAsync(addOrEditTrialQCQuestionConfigure, true);
 | ||
| 
 | ||
|             return ResponseOutput.Ok(entity.Id.ToString());
 | ||
|         }
 | ||
| 
 | ||
| 
 | ||
|         [HttpDelete("{trialQCQuestionConfigureId:guid}")]
 | ||
|         public async Task<IResponseOutput> DeleteTrialQCQuestionConfigure(Guid trialQCQuestionConfigureId)
 | ||
|         {
 | ||
| 
 | ||
|             if (await _trialQcQuestionRepository.AnyAsync(t => t.ParentId == trialQCQuestionConfigureId))
 | ||
|             {
 | ||
|                 return ResponseOutput.NotOk("清除子问题 才允许删除父问题");
 | ||
|             }
 | ||
| 
 | ||
|             if (!await _trialQcQuestionRepository.AnyAsync(t => t.Id == trialQCQuestionConfigureId && t.Trial.QCQuestionConfirmedUserId == null))
 | ||
|             {
 | ||
|                 return ResponseOutput.NotOk("QC已确认,不允许操作");
 | ||
|             }
 | ||
| 
 | ||
|             if (await _repository.AnyAsync<TrialQCQuestionAnswer>(t => t.TrialQCQuestionConfigureId == trialQCQuestionConfigureId))
 | ||
|             {
 | ||
|                 return ResponseOutput.NotOk("已有QC审核记录,不允许删除问题项");
 | ||
|             }
 | ||
| 
 | ||
|             var success = await _trialQcQuestionRepository.BatchDeleteNoTrackingAsync(t => t.Id == trialQCQuestionConfigureId);
 | ||
|             return ResponseOutput.Result(success);
 | ||
|         }
 | ||
| 
 | ||
| 
 | ||
| 
 | ||
| 
 | ||
|     }
 | ||
| }
 |