//--------------------------------------------------------------------
// 此代码由T4模板自动生成 byzhouhang 20210918
// 生成时间 2022-07-01 15:33:04
// 对此文件的更改可能会导致不正确的行为,并且如果重新生成代码,这些更改将会丢失。
//--------------------------------------------------------------------
using IRaCIS.Core.Domain.Models;
using Microsoft.AspNetCore.Mvc;
using IRaCIS.Core.Application.Interfaces;
using IRaCIS.Core.Application.ViewModel;
using IRaCIS.Core.Infrastructure;
namespace IRaCIS.Core.Application.Service
{
///
/// 一致性分析配置表
///
[ApiExplorerSettings(GroupName = "Trial")]
public class TaskConsistentRuleService : BaseService, ITaskConsistentRuleService
{
private readonly IRepository _taskConsistentRuleRepository;
private readonly IRepository _visitTaskRepository;
public TaskConsistentRuleService(IRepository visitTaskRepository, IRepository taskConsistentRuleRepository)
{
_taskConsistentRuleRepository = taskConsistentRuleRepository;
_visitTaskRepository = visitTaskRepository;
}
[HttpPost]
public async Task> GetTaskConsistentRuleList(TaskConsistentRuleQuery inQuery)
{
var taskConsistentRuleQueryable = _taskConsistentRuleRepository.Where(t => t.TrialId == inQuery.TrialId)
.WhereIf(inQuery.IsSelfAnalysis, t => t.CompareDoctorUserId != null)
.WhereIf(inQuery.IsSelfAnalysis == false, t => t.CompareDoctorUserId == null)
.ProjectTo(_mapper.ConfigurationProvider);
return await taskConsistentRuleQueryable.ToListAsync();
}
public async Task AddOrUpdateTaskConsistentRule(TaskConsistentRuleAddOrEdit addOrEditTaskConsistentRule)
{
var verifyExp1 = new EntityVerifyExp()
{
VerifyExp = t => t.AnalysisDoctorUserId == addOrEditTaskConsistentRule.AnalysisDoctorUserId && t.CompareDoctorUserId == addOrEditTaskConsistentRule.CompareDoctorUserId && t.TrialId == addOrEditTaskConsistentRule.TrialId,
VerifyMsg = "已有该医生配置,不允许继续增加"
};
var entity = await _taskConsistentRuleRepository.InsertOrUpdateAsync(addOrEditTaskConsistentRule, true, verifyExp1);
return ResponseOutput.Ok(entity.Id.ToString());
}
[HttpDelete("{taskConsistentRuleId:guid}")]
public async Task DeleteTaskConsistentRule(Guid taskConsistentRuleId)
{
var config = await _taskConsistentRuleRepository.FirstOrDefaultAsync(t => t.Id == taskConsistentRuleId);
//自身一致性分析
if (config.CompareDoctorUserId == null)
{
if (await _visitTaskRepository.AnyAsync(t => t.IsAnalysisCreate && t.DoctorUserId == config.AnalysisDoctorUserId && t.TrialId == config.TrialId))
{
throw new BusinessValidationFailedException("已产生一致性分析任务,不允许删除");
}
}
//组内一致性分析
else
{
if (await _visitTaskRepository.AnyAsync(t => t.IsAnalysisCreate && t.DoctorUserId == config.CompareDoctorUserId && t.TrialId == config.TrialId))
{
throw new BusinessValidationFailedException("已产生一致性分析任务,不允许删除");
}
}
var success = await _taskConsistentRuleRepository.DeleteFromQueryAsync(t => t.Id == taskConsistentRuleId, true);
return ResponseOutput.Ok();
}
}
}