EI-Image-Viewer-Api/IRaCIS.Core.Application/Service/Allocation/TaskAllocationRuleService.cs

93 lines
3.7 KiB
C#

//--------------------------------------------------------------------
// 此代码由T4模板自动生成 byzhouhang 20210918
// 生成时间 2022-06-07 13:14:38
// 对此文件的更改可能会导致不正确的行为,并且如果重新生成代码,这些更改将会丢失。
//--------------------------------------------------------------------
using IRaCIS.Core.Domain.Models;
using Microsoft.AspNetCore.Mvc;
using IRaCIS.Core.Application.Interfaces;
using IRaCIS.Core.Application.ViewModel;
using IRaCIS.Core.Application.Contracts;
namespace IRaCIS.Core.Application.Service
{
/// <summary>
/// 分配规则
/// </summary>
[ApiExplorerSettings(GroupName = "Trial")]
public class TaskAllocationRuleService : BaseService, ITaskAllocationRuleService
{
private readonly IRepository<TaskAllocationRule> _taskAllocationRuleRepository;
private readonly IRepository<User> _userRepository;
private readonly IRepository<Trial> _trialRepository;
public TaskAllocationRuleService(IRepository<TaskAllocationRule> taskAllocationRuleRepository, IRepository<User> userRepository, IRepository<Trial> trialRepository)
{
_taskAllocationRuleRepository = taskAllocationRuleRepository;
_userRepository = userRepository;
_trialRepository= trialRepository;
}
[HttpPost]
public async Task<(List<TaskAllocationRuleView>,object)> GetTaskAllocationRuleList(TaskAllocationRuleQuery queryTaskAllocationRule)
{
var taskAllocationRuleQueryable = _taskAllocationRuleRepository.Where(t=>t.TrialId== queryTaskAllocationRule.TrialId)
.ProjectTo<TaskAllocationRuleView>(_mapper.ConfigurationProvider);
var trialTaskConfig= _trialRepository.Where(t=>t.Id==queryTaskAllocationRule.TrialId).ProjectTo<TrialTaskConfig>(_mapper.ConfigurationProvider);
return (await taskAllocationRuleQueryable.ToListAsync(), trialTaskConfig);
}
public async Task<IResponseOutput> AddOrUpdateTaskAllocationRule(TaskAllocationRuleAddOrEdit addOrEditTaskAllocationRule)
{
var verifyExp1 = new EntityVerifyExp<TaskAllocationRule>()
{
VerifyExp = t => t.DoctorUserId == addOrEditTaskAllocationRule.DoctorUserId,
VerifyMsg = "已有该医生配置,不允许继续增加"
};
var entity = await _taskAllocationRuleRepository.InsertOrUpdateAsync(addOrEditTaskAllocationRule, true, verifyExp1);
return ResponseOutput.Ok(entity.Id.ToString());
}
[HttpDelete("{taskAllocationRuleId:guid}")]
public async Task<IResponseOutput> DeleteTaskAllocationRule(Guid taskAllocationRuleId)
{
var success = await _taskAllocationRuleRepository.DeleteFromQueryAsync(t => t.Id == taskAllocationRuleId, true);
return ResponseOutput.Ok();
}
/// <summary>
/// 获取项目下 医生账户信息下拉
/// </summary>
/// <param name="trialId"></param>
/// <param name="_enrollRepository"></param>
/// <returns></returns>
[HttpGet("{trialId:guid}")]
public async Task<List<TrialDoctorUserSelectView>> GetDoctorUserSelectList(Guid trialId,[FromServices] IRepository<Enroll> _enrollRepository)
{
var query = from enroll in _enrollRepository.Where(t => t.TrialId == trialId)
join user in _userRepository.AsQueryable() on enroll.DoctorId equals user.DoctorId
select user;
return query.ProjectTo<TrialDoctorUserSelectView>(_mapper.ConfigurationProvider).ToList();
}
}
}