218 lines
10 KiB
C#
218 lines
10 KiB
C#
using IRaCIS.Application.Contracts;
|
|
using IRaCIS.Core.Application.Filter;
|
|
using IRaCIS.Core.Domain.Share;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using IRaCIS.Core.Application.Contracts.DTO;
|
|
using IRaCIS.Application.Interfaces;
|
|
using IRaCIS.Core.Application.Service;
|
|
|
|
using Microsoft.AspNetCore.Authorization;
|
|
|
|
namespace IRaCIS.Application.Services
|
|
{
|
|
[ApiExplorerSettings(GroupName = "Trial")]
|
|
public class TrialMaintenanceService : BaseService, ITrialMaintenanceService
|
|
{
|
|
private readonly IRepository<TrialUser> _trialUseRepository;
|
|
private readonly IRepository<Trial> _trialRepository;
|
|
|
|
public TrialMaintenanceService(IRepository<TrialUser> trialUseRepository, IRepository<Trial> trialRepository)
|
|
{
|
|
_trialUseRepository = trialUseRepository;
|
|
_trialRepository = trialRepository;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 项目参与人员导出
|
|
/// </summary>
|
|
/// <param name="param"></param>
|
|
/// <param name="_commonDocumentRepository"></param>
|
|
/// <returns></returns>
|
|
/// <exception cref="Exception"></exception>
|
|
[HttpPost]
|
|
[AllowAnonymous]
|
|
public async Task<IActionResult> TrialUserListExport(TrialMaintenanceExportQuery param, [FromServices] IRepository<CommonDocument> _commonDocumentRepository)
|
|
{
|
|
|
|
var exportInfo = (await _trialRepository.Where(t => t.Id == param.TrialId).IgnoreQueryFilters().ProjectTo<TrialUserExportDTO>(_mapper.ConfigurationProvider).FirstOrDefaultAsync()).IfNullThrowException();
|
|
|
|
exportInfo.TrialUserList = await _trialUseRepository.Where(t => t.TrialId == param.TrialId).IgnoreQueryFilters()
|
|
.WhereIf(param.UserTypeId != null, t => t.User.UserTypeId == param.UserTypeId)
|
|
.WhereIf(!string.IsNullOrWhiteSpace(param.UserName), t => t.User.UserName.Contains(param.UserName))
|
|
|
|
.WhereIf(param.IsDeleted != null, t => t.IsDeleted == param.IsDeleted)
|
|
.WhereIf(!string.IsNullOrWhiteSpace(param.OrganizationName),
|
|
t => t.User.OrganizationName.Contains(param.OrganizationName))
|
|
.WhereIf(!string.IsNullOrWhiteSpace(param.UserRealName),
|
|
t => (t.User.LastName + " / " + t.User.FirstName).Contains(param.UserRealName))
|
|
.ProjectTo<TrialMaintenanceDTO>(_mapper.ConfigurationProvider).ToListAsync();
|
|
|
|
var no = 1;
|
|
exportInfo.TrialUserList.ForEach(t => t.No = no++);
|
|
|
|
return await ExcelExportHelper.DataExportAsync(StaticData.TrialUserList_Export, exportInfo, exportInfo.TrialCode, _commonDocumentRepository, _hostEnvironment);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
/// Setting页面 获取项目参与人员列表
|
|
/// </summary>
|
|
/// <param name="param"></param>
|
|
/// <returns></returns>
|
|
[HttpPost]
|
|
public async Task<PageOutput<TrialMaintenanceDTO>> GetMaintenanceUserList(TrialMaintenanceQuery param)
|
|
{
|
|
|
|
var query = _trialUseRepository.Where(t => t.TrialId == param.TrialId).IgnoreQueryFilters()
|
|
.WhereIf(param.UserTypeId != null, t => t.User.UserTypeId == param.UserTypeId)
|
|
.WhereIf(!string.IsNullOrWhiteSpace(param.UserName), t => t.User.UserName.Contains(param.UserName))
|
|
|
|
.WhereIf(param.IsDeleted != null, t => t.IsDeleted == param.IsDeleted)
|
|
.WhereIf(!string.IsNullOrWhiteSpace(param.OrganizationName), t => t.User.OrganizationName.Contains(param.OrganizationName))
|
|
.WhereIf(!string.IsNullOrWhiteSpace(param.UserRealName), t => (t.User.LastName + " / " + t.User.FirstName).Contains(param.UserRealName))
|
|
.ProjectTo<TrialMaintenanceDTO>(_mapper.ConfigurationProvider);
|
|
|
|
return await query.ToPagedListAsync(param.PageIndex, param.PageSize, string.IsNullOrWhiteSpace(param.SortField) ? "UpdateTime" : param.SortField, param.Asc);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary> Setting页面 为 site 勾选CRC用户列表</summary>
|
|
[HttpPost]
|
|
public async Task<PageOutput<AssginSiteCRCListDTO>> GetSiteCRCScreeningList(SiteCRCQuery param)
|
|
{
|
|
// 最开始过滤site已经选择的用户 现在又改回去。。。
|
|
|
|
var query = _trialUseRepository.Where(t => t.TrialId == param.TrialId)
|
|
.Where(t => t.User.UserTypeEnum == UserTypeEnum.ClinicalResearchCoordinator)
|
|
.WhereIf(param.UserTypeId != null, t => t.User.UserTypeId == param.UserTypeId)
|
|
.WhereIf(!string.IsNullOrWhiteSpace(param.UserRealName), t => (t.User.LastName + " / " + t.User.FirstName).Contains(param.UserRealName))
|
|
.ProjectTo<AssginSiteCRCListDTO>(_mapper.ConfigurationProvider, new { siteId = param.SiteId });
|
|
|
|
return await query.ToPagedListAsync(param.PageIndex,
|
|
param.PageSize, string.IsNullOrWhiteSpace(param.SortField) ? "UpdateTime" : param.SortField, param.Asc);
|
|
|
|
}
|
|
|
|
|
|
/// <summary> Setting页面 项目参与人员勾选列表 </summary>
|
|
[HttpPost]
|
|
public async Task<PageOutput<TrialUserScreeningDTO>> GetTrialUserScreeningList(TrialUserQuery trialUserQuery)
|
|
{
|
|
//之前已经选择的用户 不放在列表中,现在又要改回去 废弃
|
|
var query = _repository.Where<User>(t => t.UserTypeEnum != UserTypeEnum.SuperAdmin)
|
|
.WhereIf(!string.IsNullOrWhiteSpace(trialUserQuery.UserRealName), t => (t.LastName + " / " + t.FirstName).Contains(trialUserQuery.UserRealName))
|
|
.WhereIf(!string.IsNullOrWhiteSpace(trialUserQuery.UserName), t => t.UserName.Contains(trialUserQuery.UserName))
|
|
//.WhereIf(!string.IsNullOrWhiteSpace(trialUserQuery.OrganizationName), t => t.OrganizationName.Contains(trialUserQuery.OrganizationName))
|
|
.WhereIf(trialUserQuery.UserTypeEnum != null, t => t.UserTypeEnum == trialUserQuery.UserTypeEnum)
|
|
//.WhereIf(_userInfo.IsAdmin, t => t.UserTypeRole.Type == UserTypeGroup.TrialUser)
|
|
//.WhereIf(!_userInfo.IsAdmin, t => t.UserTypeRole.Type == UserTypeGroup.TrialUser || t.UserTypeEnum != UserTypeEnum.ProjectManager)
|
|
.ProjectTo<TrialUserScreeningDTO>(_mapper.ConfigurationProvider, new { trialId = trialUserQuery.TrialId });
|
|
|
|
return await query.ToPagedListAsync(trialUserQuery.PageIndex,
|
|
trialUserQuery.PageSize, string.IsNullOrWhiteSpace(trialUserQuery.SortField) ? "UserRealName" : trialUserQuery.SortField, trialUserQuery.Asc);
|
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// Setting页面 批量添加项目参与人员
|
|
/// </summary>
|
|
/// <param name="userTrialCommands"></param>
|
|
/// <returns></returns>
|
|
//[TrialAudit(AuditType.TrialAudit, AuditOptType.AddTrialStaff)]
|
|
[HttpPost]
|
|
[TypeFilter(typeof(TrialResourceFilter))]
|
|
public async Task<IResponseOutput> AddTrialUsers(TrialUserAddCommand[] userTrialCommands)
|
|
{
|
|
var addArray = _mapper.Map<TrialUser[]>(userTrialCommands);
|
|
|
|
var trialUsers = await _trialUseRepository.AddRangeAsync(addArray);
|
|
|
|
foreach (var item in trialUsers)
|
|
{
|
|
item.JoinTime = DateTime.Now;
|
|
}
|
|
|
|
|
|
var success = await _repository.SaveChangesAsync();
|
|
|
|
return ResponseOutput.Result(success);
|
|
}
|
|
|
|
|
|
|
|
[TypeFilter(typeof(TrialResourceFilter))]
|
|
[HttpPut]
|
|
public async Task<IResponseOutput> UpdateTrialUser(UpdateTrialUserCommand updateTrialUserCommand)
|
|
{
|
|
var trialUser = await _trialUseRepository.Where(t => t.Id == updateTrialUserCommand.Id, true, true).FirstOrDefaultAsync();
|
|
|
|
if (trialUser == null) return Null404NotFound(trialUser);
|
|
|
|
|
|
if (updateTrialUserCommand.IsDeleted)
|
|
{
|
|
if (await _repository.AnyAsync<TrialSiteUser>(t => t.UserId == trialUser.UserId && t.TrialId == trialUser.TrialId))
|
|
{
|
|
return ResponseOutput.NotOk("Participant has participated in site maintenance");
|
|
}
|
|
|
|
if (_userInfo.UserTypeEnumInt == (int)UserTypeEnum.IQC)
|
|
{
|
|
await _repository.BatchUpdateAsync<SubjectVisit>(t => t.CurrentActionUserId == trialUser.UserId && t.TrialId == trialUser.TrialId && t.IsTake, u => new SubjectVisit() { CurrentActionUserId = null, CurrentActionUserExpireTime = null, IsTake = false });
|
|
}
|
|
|
|
}
|
|
|
|
_mapper.Map(updateTrialUserCommand, trialUser);
|
|
|
|
await _repository.SaveChangesAsync();
|
|
|
|
return ResponseOutput.Ok();
|
|
|
|
|
|
}
|
|
|
|
|
|
/// <summary> 项目参与人员退出 其中IQC退出 回去释放工作量 </summary>
|
|
//[TrialAudit(AuditType.TrialAudit, AuditOptType.DeleteTrailStaff)]
|
|
[HttpDelete, Route("{id:guid}/{trialId:guid}/{isDelete:bool}")]
|
|
[TypeFilter(typeof(TrialResourceFilter))]
|
|
[UnitOfWork]
|
|
[Obsolete]
|
|
public async Task<IResponseOutput> DeleteMaintenanceUser(Guid id, bool isDelete)
|
|
{
|
|
|
|
var trialUser = await _trialUseRepository.AsQueryable().IgnoreQueryFilters().FirstOrDefaultAsync(t => t.Id == id);
|
|
|
|
if (trialUser == null) return Null404NotFound(trialUser);
|
|
|
|
if (await _repository.AnyAsync<TrialSiteUser>(t => t.UserId == trialUser.UserId && t.TrialId == trialUser.TrialId))
|
|
{
|
|
return ResponseOutput.NotOk("Participant has participated in site maintenance");
|
|
}
|
|
|
|
if (_userInfo.UserTypeEnumInt == (int)UserTypeEnum.IQC && isDelete)
|
|
{
|
|
await _repository.BatchUpdateAsync<SubjectVisit>(t => t.CurrentActionUserId == trialUser.UserId && t.TrialId == trialUser.TrialId && t.IsTake, u => new SubjectVisit() { CurrentActionUserId = null, CurrentActionUserExpireTime = null, IsTake = false });
|
|
}
|
|
|
|
await _trialUseRepository.BatchUpdateAsync(t => t.Id == id, u => new TrialUser() { IsDeleted = isDelete, RemoveTime = isDelete ? DateTime.Now : null });
|
|
|
|
await _repository.SaveChangesAsync();
|
|
|
|
return ResponseOutput.Ok();
|
|
}
|
|
|
|
|
|
|
|
}
|
|
}
|