定时任务
parent
3ddbd59995
commit
38fc05e0d9
|
@ -27,10 +27,13 @@ namespace IRaCIS.Core.API
|
|||
q.AddTrigger(t => t
|
||||
.WithIdentity("TrialStatusTrigger")
|
||||
.ForJob(jobKey)
|
||||
|
||||
.WithCronSchedule("0 0 * * * ?")
|
||||
.WithDescription("My regular trial work trigger")
|
||||
);
|
||||
|
||||
|
||||
|
||||
|
||||
});
|
||||
|
||||
// ASP.NET Core hosting
|
||||
|
|
|
@ -0,0 +1,69 @@
|
|||
using System;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using EasyCaching.Core;
|
||||
using IRaCIS.Core.Domain;
|
||||
using IRaCIS.Core.Infra.EFCore;
|
||||
using IRaCIS.Core.Domain.Models;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Quartz;
|
||||
using IRaCIS.Core.Domain.Share;
|
||||
using IRaCIS.Core.Application.ViewModel;
|
||||
|
||||
namespace IRaCIS.Application.Services.BackGroundJob
|
||||
{
|
||||
|
||||
public class CancelTaskQuartZJob : IJob
|
||||
{
|
||||
|
||||
private readonly IRepository<Subject> _subjectRepository;
|
||||
private readonly ILogger<CancelTaskQuartZJob> _logger;
|
||||
private readonly IRepository<VisitTask> _visitTaskRepository;
|
||||
|
||||
public CancelTaskQuartZJob(IRepository<Subject> subjectRepository, IEasyCachingProvider provider, ILogger<CancelTaskQuartZJob> logger, IRepository<VisitTask> visitTaskRepository)
|
||||
{
|
||||
_subjectRepository = subjectRepository;
|
||||
_logger = logger;
|
||||
_visitTaskRepository = visitTaskRepository;
|
||||
}
|
||||
|
||||
public async Task Execute(IJobExecutionContext context)
|
||||
|
||||
{
|
||||
_logger.LogInformation($"开始执行QuartZ定时取消任务作业");
|
||||
|
||||
try
|
||||
{
|
||||
JobDataMap dataMap = context.JobDetail.JobDataMap;
|
||||
|
||||
bool isInOrder = (bool)dataMap.Get("IsInOrder");
|
||||
|
||||
if (isInOrder)
|
||||
{
|
||||
Guid id = (Guid)dataMap.Get("SubjectId");
|
||||
|
||||
await _subjectRepository.UpdatePartialFromQueryAsync(t => t.Id ==id, u => new Subject() { ClaimUserId = null }, true);
|
||||
}
|
||||
else
|
||||
{
|
||||
Guid id = (Guid)dataMap.Get("VisitTaskId");
|
||||
|
||||
await _visitTaskRepository.UpdatePartialFromQueryAsync(t => t.Id == id, u => new VisitTask() { ClaimUserId = null }, true);
|
||||
}
|
||||
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
_logger.LogError($"QuartZ定时取消任务异常" + e.Message);
|
||||
}
|
||||
_logger.LogInformation("QuartZ定时取消任务作业结束");
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
|
@ -259,6 +259,9 @@ namespace IRaCIS.Core.Application.ViewModel
|
|||
public Guid SubjectId { get; set; }
|
||||
public string SubjectCode { get; set; } = String.Empty;
|
||||
|
||||
public Guid? ClaimUserId { get;set; }
|
||||
|
||||
|
||||
public bool IsUrgent => UnReadTaskList.Any(t => t.IsUrgent);
|
||||
|
||||
public int UnReadTaskCount { get; set; }
|
||||
|
@ -417,15 +420,15 @@ namespace IRaCIS.Core.Application.ViewModel
|
|||
/// </summary>
|
||||
public int FinishTaskCount { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 未完成裁判任务数量
|
||||
/// </summary>
|
||||
public int UnReadJudgeTaskCount { get; set; }
|
||||
///// <summary>
|
||||
///// 未完成裁判任务数量
|
||||
///// </summary>
|
||||
//public int UnReadJudgeTaskCount { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 完成裁判任务数量
|
||||
/// </summary>
|
||||
public int FinishJudgeTaskCount { get; set; }
|
||||
///// <summary>
|
||||
///// 完成裁判任务数量
|
||||
///// </summary>
|
||||
//public int FinishJudgeTaskCount { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 建议完成时间
|
||||
|
@ -798,6 +801,17 @@ namespace IRaCIS.Core.Application.ViewModel
|
|||
CancelAssign = 4,
|
||||
}
|
||||
|
||||
public class ClaimSubjectDto
|
||||
{
|
||||
public bool IsInOrder { get; set; }
|
||||
|
||||
public Guid? VisitTaskId { get; set; }
|
||||
|
||||
public Guid SubejctId { get; set; }
|
||||
|
||||
public bool IsClaim { get; set; }
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -21,6 +21,8 @@ using System.Linq;
|
|||
using DocumentFormat.OpenXml.Bibliography;
|
||||
using Org.BouncyCastle.Crypto;
|
||||
using IRaCIS.Core.Domain.Share.Reading;
|
||||
using Quartz;
|
||||
using IRaCIS.Application.Services.BackGroundJob;
|
||||
|
||||
namespace IRaCIS.Core.Application.Service.Allocation
|
||||
{
|
||||
|
@ -914,10 +916,10 @@ namespace IRaCIS.Core.Application.Service.Allocation
|
|||
|
||||
var trialReadingCriterionId = iRUnReadSubjectQuery.TrialReadingCriterionId;
|
||||
|
||||
var criterionConfig = await _trialReadingCriterionRepository.Where(x => x.Id == iRUnReadSubjectQuery.TrialReadingCriterionId).FirstNotNullAsync();
|
||||
var critrion = await _trialReadingCriterionRepository.Where(x => x.Id == iRUnReadSubjectQuery.TrialReadingCriterionId).FirstNotNullAsync();
|
||||
|
||||
var readingTool = criterionConfig.ReadingTool;
|
||||
var isReadingTaskViewInOrder = criterionConfig.IsReadingTaskViewInOrder;
|
||||
var readingTool = critrion.ReadingTool;
|
||||
var isReadingTaskViewInOrder = critrion.IsReadingTaskViewInOrder;
|
||||
|
||||
#region 按照Subject 维度
|
||||
if (isReadingTaskViewInOrder)
|
||||
|
@ -961,87 +963,61 @@ namespace IRaCIS.Core.Application.Service.Allocation
|
|||
RandomReadInfo = new IRUnReadOutDto(),
|
||||
IsReadingTaskViewInOrder = isReadingTaskViewInOrder,
|
||||
ReadingTool = readingTool,
|
||||
IseCRFShowInDicomReading = criterionConfig.IseCRFShowInDicomReading,
|
||||
IsReadingShowSubjectInfo = criterionConfig.IsReadingShowSubjectInfo,
|
||||
IsReadingShowPreviousResults = criterionConfig.IsReadingShowPreviousResults,
|
||||
DigitPlaces = criterionConfig.DigitPlaces,
|
||||
CriterionType = criterionConfig.CriterionType,
|
||||
IseCRFShowInDicomReading = critrion.IseCRFShowInDicomReading,
|
||||
IsReadingShowSubjectInfo = critrion.IsReadingShowSubjectInfo,
|
||||
IsReadingShowPreviousResults = critrion.IsReadingShowPreviousResults,
|
||||
DigitPlaces = critrion.DigitPlaces,
|
||||
CriterionType = critrion.CriterionType,
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
var taskQuery = _visitTaskRepository.Where(x => x.TrialId == iRUnReadSubjectQuery.TrialId && x.DoctorUserId == _userInfo.Id && x.TaskState == TaskState.Effect && x.TrialReadingCriterionId == trialReadingCriterionId)
|
||||
// .Where(x=>x.Subject.ClinicalDataList.Any(c => c.IsSign && (c.ReadingId == x.SouceReadModuleId || c.ReadingId == x.SourceSubjectVisitId)))
|
||||
.Where(x => !x.Subject.IsDeleted).Where(x => (x.IsNeedClinicalDataSign && x.IsClinicalDataSign) || !x.IsNeedClinicalDataSign);
|
||||
|
||||
var readingDivisionEnum = critrion.ReadingDivisionEnum;
|
||||
|
||||
var piReadingScopenEnum = critrion.PIReadingScopenEnum;
|
||||
|
||||
var taskQuery = _visitTaskRepository.Where(x => x.TrialId == iRUnReadSubjectQuery.TrialId /*&& x.DoctorUserId == _userInfo.Id*/ && x.TaskState == TaskState.Effect && x.TrialReadingCriterionId == trialReadingCriterionId)
|
||||
|
||||
.Where(x => (x.IsNeedClinicalDataSign && x.IsClinicalDataSign) || !x.IsNeedClinicalDataSign)
|
||||
.WhereIf(_userInfo.UserTypeEnumInt == (int)UserTypeEnum.SR, t => t.Subject.TrialSite.CRCUserList.Any(u => u.UserId == _userInfo.Id))
|
||||
// 仅仅SR阅片 PI 没有任务列表
|
||||
.WhereIf(readingDivisionEnum == ReadingDivisionEnum.OnlySR && _userInfo.UserTypeEnumInt == (int)UserTypeEnum.PI, t => t.TrialId == Guid.Empty)
|
||||
|
||||
|
||||
.WhereIf(readingDivisionEnum == ReadingDivisionEnum.PIandSR && _userInfo.UserTypeEnumInt == (int)UserTypeEnum.PI && piReadingScopenEnum == PIReadingScopenEnum.AllBaseline,
|
||||
t => t.SourceSubjectVisit.IsBaseLine == true)
|
||||
|
||||
//PI 阅片所有
|
||||
.WhereIf(readingDivisionEnum == ReadingDivisionEnum.PIandSR && _userInfo.UserTypeEnumInt == (int)UserTypeEnum.PI && piReadingScopenEnum == PIReadingScopenEnum.AllBaselineandVisit,
|
||||
t => true)
|
||||
|
||||
.WhereIf(readingDivisionEnum == ReadingDivisionEnum.PIandSR && _userInfo.UserTypeEnumInt == (int)UserTypeEnum.PI && piReadingScopenEnum == PIReadingScopenEnum.AllVisit,
|
||||
t => t.SourceSubjectVisit.IsBaseLine == false)
|
||||
|
||||
.WhereIf(readingDivisionEnum == ReadingDivisionEnum.PIandSR && _userInfo.UserTypeEnumInt == (int)UserTypeEnum.SR && piReadingScopenEnum == PIReadingScopenEnum.AllBaseline,
|
||||
t => t.SourceSubjectVisit.IsBaseLine == false)
|
||||
|
||||
//SR 不阅片
|
||||
.WhereIf(readingDivisionEnum == ReadingDivisionEnum.PIandSR && _userInfo.UserTypeEnumInt == (int)UserTypeEnum.SR && piReadingScopenEnum == PIReadingScopenEnum.AllBaselineandVisit,
|
||||
t => t.TrialId == Guid.Empty)
|
||||
|
||||
.WhereIf(readingDivisionEnum == ReadingDivisionEnum.PIandSR && _userInfo.UserTypeEnumInt == (int)UserTypeEnum.SR && piReadingScopenEnum == PIReadingScopenEnum.AllVisit,
|
||||
t => t.SourceSubjectVisit.IsBaseLine == true);
|
||||
|
||||
IRUnReadOutDto iRUnReadOut = new IRUnReadOutDto()
|
||||
{
|
||||
FinishJudgeTaskCount = await taskQuery.Where(x => x.ReadingCategory == ReadingCategory.Judge && x.ReadingTaskState == ReadingTaskState.HaveSigned).CountAsync(),
|
||||
FinishTaskCount = await taskQuery.Where(x => x.ReadingCategory != ReadingCategory.Judge && x.ReadingTaskState == ReadingTaskState.HaveSigned).CountAsync(),
|
||||
SuggesteFinishedTime = await taskQuery.Where(x => x.ReadingTaskState != ReadingTaskState.HaveSigned).MaxAsync(x => x.SuggesteFinishedTime),
|
||||
UnReadJudgeTaskCount = await taskQuery.Where(x => x.ReadingCategory == ReadingCategory.Judge && x.ReadingTaskState != ReadingTaskState.HaveSigned).CountAsync(),
|
||||
|
||||
|
||||
UnReadTaskCount = await taskQuery.Where(x => x.ReadingCategory != ReadingCategory.Judge && x.ReadingTaskState != ReadingTaskState.HaveSigned).CountAsync(),
|
||||
};
|
||||
|
||||
|
||||
|
||||
var visitGroupQuery = taskQuery.GroupBy(x => new { x.SubjectId, x.Subject.Code, x.BlindSubjectCode });
|
||||
|
||||
|
||||
|
||||
var visitTaskQuery = visitGroupQuery.Select(x => new IRUnReadSubjectView()
|
||||
{
|
||||
SubjectId = x.Key.SubjectId,
|
||||
SubjectCode = x.Key.BlindSubjectCode == string.Empty ? x.Key.Code : x.Key.BlindSubjectCode,
|
||||
|
||||
SuggesteFinishedTime = x.Where(y => y.TrialReadingCriterionId == trialReadingCriterionId && y.ReadingTaskState != ReadingTaskState.HaveSigned).Min(x => x.SuggesteFinishedTime),
|
||||
|
||||
//未读任务量
|
||||
UnReadTaskCount = x.Where(y => y.TrialReadingCriterionId == trialReadingCriterionId && y.ReadingTaskState != ReadingTaskState.HaveSigned).Count(),
|
||||
|
||||
//未读 里可读任务量
|
||||
UnReadCanReadTaskCount = x.Where(y => y.TrialReadingCriterionId == trialReadingCriterionId && y.ReadingTaskState != ReadingTaskState.HaveSigned && y.IsFrontTaskNeedSignButNotSign == false && (y.IsNeedClinicalDataSign == false || y.IsClinicalDataSign == true)
|
||||
//不能对包含聚合或子查询的表达式执行聚合函数
|
||||
//&& !x.Any(t => t.ReadingTaskState != ReadingTaskState.HaveSigned && t.IsNeedClinicalDataSign == true && t.IsClinicalDataSign == false && t.VisitTaskNum<y.VisitTaskNum )
|
||||
).Count(),
|
||||
|
||||
|
||||
//已读任务量
|
||||
HaveReadTaskCount = x.Where(y => y.TrialReadingCriterionId == trialReadingCriterionId && y.ReadingTaskState == ReadingTaskState.HaveSigned).Count(),
|
||||
|
||||
ExistReadingApply = x.Any(y => (y.ReReadingApplyState == ReReadingApplyState.DocotorHaveApplyed && y.TrialReadingCriterionId == trialReadingCriterionId) || y.ReReadingApplyState == ReReadingApplyState.TrialGroupHaveApplyed),
|
||||
|
||||
//查出所有未读的 未读的可读的 在这个列表基础上 过滤下 y.IsFrontTaskNeedSignButNotSign==false && (y.IsNeedClinicalDataSign == false || y.IsClinicalDataSign == true) 这样容易排错 确认这三个字段是否维护有误
|
||||
UnReadTaskList = x.Where(y => y.TrialReadingCriterionId == trialReadingCriterionId && y.ReadingTaskState != ReadingTaskState.HaveSigned).OrderBy(x => x.VisitTaskNum)
|
||||
.Select(u => new IRUnreadTaskView()
|
||||
{
|
||||
Id = u.Id,
|
||||
IsUrgent = u.IsUrgent,
|
||||
VisitNum = u.VisitTaskNum,
|
||||
TaskBlindName = u.TaskBlindName,
|
||||
VisistId = u.SourceSubjectVisitId,
|
||||
SuggesteFinishedTime = u.SuggesteFinishedTime,
|
||||
ReadingCategory = u.ReadingCategory,
|
||||
IsAnalysisCreate = u.IsAnalysisCreate,
|
||||
ArmEnum = u.ArmEnum,
|
||||
TrialReadingCriterionId = u.TrialReadingCriterionId,
|
||||
IsNeedClinicalDataSign = u.IsNeedClinicalDataSign,
|
||||
IsClinicalDataSign = u.IsClinicalDataSign,
|
||||
IsFrontTaskNeedSignButNotSign = u.IsFrontTaskNeedSignButNotSign
|
||||
})
|
||||
.ToList(),
|
||||
}).Where(x => x.UnReadCanReadTaskCount > 0);
|
||||
|
||||
|
||||
var totalCount = await visitGroupQuery.CountAsync();
|
||||
var currentPageData = await visitTaskQuery.ToListAsync();
|
||||
|
||||
var result = new PageOutput<IRUnReadSubjectView>()
|
||||
{
|
||||
PageSize = iRUnReadSubjectQuery.PageSize,
|
||||
PageIndex = iRUnReadSubjectQuery.PageIndex,
|
||||
TotalCount = totalCount,
|
||||
CurrentPageData = currentPageData,
|
||||
};
|
||||
|
||||
return (result, new
|
||||
|
@ -1049,11 +1025,11 @@ namespace IRaCIS.Core.Application.Service.Allocation
|
|||
IsReadingTaskViewInOrder = isReadingTaskViewInOrder,
|
||||
RandomReadInfo = iRUnReadOut,
|
||||
ReadingTool = readingTool,
|
||||
IseCRFShowInDicomReading = criterionConfig.IseCRFShowInDicomReading,
|
||||
IsReadingShowSubjectInfo = criterionConfig.IsReadingShowSubjectInfo,
|
||||
IsReadingShowPreviousResults = criterionConfig.IsReadingShowPreviousResults,
|
||||
DigitPlaces = criterionConfig.DigitPlaces,
|
||||
CriterionType = criterionConfig.CriterionType,
|
||||
IseCRFShowInDicomReading = critrion.IseCRFShowInDicomReading,
|
||||
IsReadingShowSubjectInfo = critrion.IsReadingShowSubjectInfo,
|
||||
IsReadingShowPreviousResults = critrion.IsReadingShowPreviousResults,
|
||||
DigitPlaces = critrion.DigitPlaces,
|
||||
CriterionType = critrion.CriterionType,
|
||||
});
|
||||
|
||||
}
|
||||
|
@ -1119,12 +1095,13 @@ namespace IRaCIS.Core.Application.Service.Allocation
|
|||
.WhereIf(!string.IsNullOrEmpty(inDto.SubjectCode), t => (t.Subject.Code.Contains(inDto.SubjectCode) && t.IsAnalysisCreate == false) || (t.BlindSubjectCode.Contains(inDto.SubjectCode) && t.IsAnalysisCreate));
|
||||
|
||||
|
||||
var visitGroupQuery = visitQuery.GroupBy(x => new { x.SubjectId, x.Subject.Code, x.BlindSubjectCode });
|
||||
var visitGroupQuery = visitQuery.GroupBy(x => new { x.SubjectId, x.Subject.Code, x.BlindSubjectCode, x.Subject.ClaimUserId });
|
||||
|
||||
var visitTaskQuery = visitGroupQuery.Select(x => new IRUnReadSubjectView()
|
||||
{
|
||||
SubjectId = x.Key.SubjectId,
|
||||
SubjectCode = x.Key.BlindSubjectCode == string.Empty ? x.Key.Code : x.Key.BlindSubjectCode,
|
||||
ClaimUserId = x.Key.ClaimUserId,
|
||||
|
||||
SuggesteFinishedTime = x.Where(y => y.TrialReadingCriterionId == trialReadingCriterionId && y.ReadingTaskState != ReadingTaskState.HaveSigned).Min(x => x.SuggesteFinishedTime),
|
||||
|
||||
|
@ -3061,228 +3038,5 @@ namespace IRaCIS.Core.Application.Service.Allocation
|
|||
}
|
||||
|
||||
|
||||
#region 暂时废弃
|
||||
|
||||
|
||||
///// <summary>
|
||||
///// 自动一次性分配所有未分配的 Subject 给医生 暂时废弃
|
||||
///// </summary>
|
||||
///// <param name="autoSubjectAssignCommand"></param>
|
||||
///// <returns></returns>
|
||||
//[HttpPost]
|
||||
//[UnitOfWork]
|
||||
//[Obsolete]
|
||||
//public async Task<IResponseOutput> AutoSubjectAssignDoctor(AutoSubjectAssignCommand autoSubjectAssignCommand)
|
||||
//{
|
||||
// //自动分配的话,需要把手动分配的给删掉
|
||||
|
||||
|
||||
// var trialId = autoSubjectAssignCommand.TrialId;
|
||||
// var isJudge = autoSubjectAssignCommand.IsJudgeDoctor;
|
||||
|
||||
|
||||
// //获取项目配置 判断应该分配几个医生
|
||||
// var trialConfig = (await _trialRepository.Where(t => t.Id == trialId).Select(t => new { TrialId = t.Id/*, t.ReadingType*/, t.IsFollowVisitAutoAssign, t.IsFollowGlobalVisitAutoAssign, t.FollowGlobalVisitAutoAssignDefaultState, t.TaskAllocateObjEnum }).FirstOrDefaultAsync()).IfNullThrowException();
|
||||
|
||||
|
||||
// //获取 已产生任务的Subject 目前分配情况
|
||||
// var subjectList = _subjectRepository.Where(t => t.TrialId == trialId)
|
||||
// .WhereIf(isJudge == false, t => t.SubjectVisitTaskList.Where(t => t.ArmEnum != Arm.JudgeArm).Any())
|
||||
// .WhereIf(isJudge, t => t.SubjectVisitTaskList.Where(t => t.ArmEnum == Arm.JudgeArm).Any())
|
||||
// ////过滤掉 那些回退的subject
|
||||
// //.Where(t => !t.SubjectVisitList.Any(t => t.IsPMBackOrReReading))
|
||||
// .Select(t => new
|
||||
// {
|
||||
// SubjectId = t.Id,
|
||||
|
||||
// //给Subject分配医生的时候, 未确认绑定关系的
|
||||
// DoctorUserList = t.SubjectDoctorList.Where(t => isJudge ? t.ArmEnum == Arm.JudgeArm : t.ArmEnum != Arm.JudgeArm).Where(t => t.OrignalSubjectUserId == null).Select(t => new { t.DoctorUserId, t.ArmEnum }),
|
||||
// //IsApplyed = t.SubjectDoctorList.Where(t => isJudge ? t.ArmEnum == Arm.JudgeArm : t.ArmEnum != Arm.JudgeArm).Where(t => t.OrignalSubjectUserId == null).SelectMany(t => t.SubjectArmVisitTaskList).Any(c => c.DoctorUserId != null)
|
||||
// IsApplyed = false
|
||||
// }).ToList();
|
||||
|
||||
// //已产生任务的Subject数量(裁判情况下,就是产生裁判任务Subject 的数量)
|
||||
// var subjectCount = subjectList.Count;
|
||||
|
||||
// //获取医生列表(裁判是裁判的医生列表)
|
||||
// var waitAllocationDoctorList = _taskAllocationRuleRepository.Where(t => t.TrialId == trialId && t.IsEnable)
|
||||
// .Where(t => t.IsJudgeDoctor == isJudge)
|
||||
// .Select(t => new AutoAssignResultDTO() { DoctorUserId = t.DoctorUserId, PlanReadingRatio = t.PlanReadingRatio, SubjectCount = subjectCount })
|
||||
// .ToList();
|
||||
|
||||
// if (waitAllocationDoctorList.Count == 0)
|
||||
// {
|
||||
// throw new BusinessValidationFailedException("启用的医生数量为0");
|
||||
// }
|
||||
|
||||
|
||||
// //已分配的 医生的情况
|
||||
// var haveAssignedSubjectDoctorList = subjectList.Clone().SelectMany(t => t.DoctorUserList.Select(c => new { t.SubjectId, c.DoctorUserId, c.ArmEnum })).ToList();
|
||||
|
||||
// //将目前已分配的情况 换到医生的维度
|
||||
// foreach (var waitAllocationDoctor in waitAllocationDoctorList)
|
||||
// {
|
||||
// waitAllocationDoctor.SubjectArmList = haveAssignedSubjectDoctorList.Where(t => t.DoctorUserId == waitAllocationDoctor.DoctorUserId)
|
||||
// .Select(g => new SubjectArm()
|
||||
// {
|
||||
// SubjectId = g.SubjectId,
|
||||
// ArmEnum = g.ArmEnum
|
||||
// }).ToList();
|
||||
// }
|
||||
|
||||
|
||||
// #region 完全按照Subject 遍历去分
|
||||
|
||||
|
||||
// //仅仅分配未应用的 而且 没有分配医生的
|
||||
// foreach (var subject in subjectList.Where(t => t.IsApplyed == false && !t.DoctorUserList.Any()))
|
||||
// {
|
||||
// //该Subject 已经分配的医生数量
|
||||
// var hasAssignDoctorCount = subject.DoctorUserList.Count();
|
||||
|
||||
// if (isJudge)
|
||||
// {
|
||||
// if (hasAssignDoctorCount > 1)
|
||||
// {
|
||||
// throw new BusinessValidationFailedException("当前有Subject裁判绑定医生数量大于1");
|
||||
|
||||
// }
|
||||
|
||||
// var allocateDoctor = waitAllocationDoctorList.OrderByDescending(t => t.Weight).ThenByDescending(t => t.PlanReadingRatio).FirstOrDefault();
|
||||
|
||||
// //将分配结果记录
|
||||
// waitAllocationDoctorList.FirstOrDefault(t => t.DoctorUserId == allocateDoctor.DoctorUserId).SubjectArmList.Add(new SubjectArm()
|
||||
// {
|
||||
// SubjectId = subject.SubjectId,
|
||||
// ArmEnum = Arm.JudgeArm
|
||||
// });
|
||||
|
||||
// await _subjectUserRepository.AddAsync(new SubjectUser() { TrialId = trialId, SubjectId = subject.SubjectId, DoctorUserId = allocateDoctor.DoctorUserId, ArmEnum = Arm.JudgeArm, AssignTime = DateTime.Now });
|
||||
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
|
||||
// //分配两个医生
|
||||
// if (trialConfig.ReadingType == ReadingMethod.Double)
|
||||
// {
|
||||
|
||||
|
||||
// if (hasAssignDoctorCount > 2)
|
||||
// {
|
||||
// throw new BusinessValidationFailedException("双重阅片当前有Subject绑定医生数量大于2");
|
||||
|
||||
// }
|
||||
|
||||
// var allocateDoctorList = waitAllocationDoctorList.OrderByDescending(t => t.Weight).ThenByDescending(t => t.PlanReadingRatio).Take(2).ToList();
|
||||
|
||||
|
||||
// #region 看阅片人之前在Subject哪个组做的多
|
||||
|
||||
// var preferredDoctor1Arm = waitAllocationDoctorList.Where(t => t.DoctorUserId == allocateDoctorList[0].DoctorUserId)
|
||||
// .SelectMany(t => t.SubjectArmList).GroupBy(t => t.ArmEnum)
|
||||
// .Select(g => new { ArmEnum = g.Key, SubjectCount = g.Count() })
|
||||
// .OrderByDescending(t => t.SubjectCount).FirstOrDefault()?.ArmEnum;
|
||||
|
||||
// var preferredDoctor2Arm = waitAllocationDoctorList.Where(t => t.DoctorUserId == allocateDoctorList[1].DoctorUserId)
|
||||
// .SelectMany(t => t.SubjectArmList).GroupBy(t => t.ArmEnum)
|
||||
// .Select(g => new { ArmEnum = g.Key, SubjectCount = g.Count() })
|
||||
// .OrderByDescending(t => t.SubjectCount).FirstOrDefault()?.ArmEnum;
|
||||
|
||||
// //存放医生分配的Arm
|
||||
// var doctor1Arm = Arm.DoubleReadingArm1;
|
||||
// var doctor2Arm = Arm.DoubleReadingArm2;
|
||||
|
||||
// if (preferredDoctor1Arm == null && preferredDoctor2Arm == null ||
|
||||
// preferredDoctor1Arm == null && preferredDoctor2Arm == Arm.DoubleReadingArm2 ||
|
||||
// preferredDoctor1Arm == Arm.DoubleReadingArm1 && preferredDoctor2Arm == null ||
|
||||
// preferredDoctor1Arm == Arm.DoubleReadingArm1 && preferredDoctor2Arm == Arm.DoubleReadingArm2
|
||||
// )
|
||||
// {
|
||||
// doctor1Arm = Arm.DoubleReadingArm1;
|
||||
// doctor2Arm = Arm.DoubleReadingArm2;
|
||||
// }
|
||||
// else if (preferredDoctor1Arm == null && preferredDoctor2Arm == Arm.DoubleReadingArm1 ||
|
||||
// preferredDoctor1Arm == Arm.DoubleReadingArm2 && preferredDoctor2Arm == Arm.DoubleReadingArm1 ||
|
||||
// preferredDoctor1Arm == Arm.DoubleReadingArm2 && preferredDoctor2Arm == null)
|
||||
// {
|
||||
// doctor1Arm = Arm.DoubleReadingArm2;
|
||||
// doctor2Arm = Arm.DoubleReadingArm1;
|
||||
// }
|
||||
|
||||
// else if (preferredDoctor1Arm == Arm.DoubleReadingArm1 && preferredDoctor2Arm == Arm.DoubleReadingArm1)
|
||||
// {
|
||||
// doctor1Arm = Arm.DoubleReadingArm1;
|
||||
// doctor2Arm = Arm.DoubleReadingArm2;
|
||||
// }
|
||||
// else if (preferredDoctor1Arm == Arm.DoubleReadingArm2 && preferredDoctor2Arm == Arm.DoubleReadingArm2)
|
||||
// {
|
||||
// doctor1Arm = Arm.DoubleReadingArm2;
|
||||
// doctor2Arm = Arm.DoubleReadingArm1;
|
||||
// }
|
||||
|
||||
// #endregion
|
||||
|
||||
|
||||
// await _subjectUserRepository.AddAsync(new SubjectUser() { TrialId = trialId, SubjectId = subject.SubjectId, DoctorUserId = allocateDoctorList[0].DoctorUserId, ArmEnum = doctor1Arm, AssignTime = DateTime.Now });
|
||||
|
||||
|
||||
// //将分配结果记录
|
||||
// waitAllocationDoctorList.FirstOrDefault(t => t.DoctorUserId == allocateDoctorList[0].DoctorUserId).SubjectArmList.Add(new SubjectArm()
|
||||
// {
|
||||
// SubjectId = subject.SubjectId,
|
||||
// ArmEnum = doctor1Arm
|
||||
// });
|
||||
|
||||
|
||||
// await _subjectUserRepository.AddAsync(new SubjectUser() { TrialId = trialId, SubjectId = subject.SubjectId, DoctorUserId = allocateDoctorList[1].DoctorUserId, ArmEnum = doctor2Arm, AssignTime = DateTime.Now });
|
||||
|
||||
// //将分配结果记录
|
||||
// waitAllocationDoctorList.FirstOrDefault(t => t.DoctorUserId == allocateDoctorList[1].DoctorUserId).SubjectArmList.Add(new SubjectArm()
|
||||
// {
|
||||
// SubjectId = subject.SubjectId,
|
||||
// ArmEnum = doctor2Arm
|
||||
// });
|
||||
// }
|
||||
// else if (trialConfig.ReadingType == ReadingMethod.Single)
|
||||
// {
|
||||
// if (hasAssignDoctorCount > 1)
|
||||
// {
|
||||
// throw new BusinessValidationFailedException("单重阅片当前有Subject绑定医生数量大于1");
|
||||
// }
|
||||
|
||||
// var allocateDoctor = waitAllocationDoctorList.OrderByDescending(t => t.Weight).ThenByDescending(t => t.PlanReadingRatio).FirstOrDefault();
|
||||
|
||||
// //将分配结果记录
|
||||
// waitAllocationDoctorList.FirstOrDefault(t => t.DoctorUserId == allocateDoctor.DoctorUserId).SubjectArmList.Add(new SubjectArm()
|
||||
// {
|
||||
// SubjectId = subject.SubjectId,
|
||||
// ArmEnum = Arm.SingleReadingArm
|
||||
// });
|
||||
|
||||
// await _subjectUserRepository.AddAsync(new SubjectUser() { TrialId = trialId, SubjectId = subject.SubjectId, DoctorUserId = allocateDoctor.DoctorUserId, ArmEnum = Arm.SingleReadingArm, AssignTime = DateTime.Now });
|
||||
|
||||
// }
|
||||
|
||||
// }
|
||||
|
||||
// }
|
||||
|
||||
|
||||
// #endregion
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// await _subjectUserRepository.SaveChangesAsync();
|
||||
// return ResponseOutput.Ok();
|
||||
|
||||
//}
|
||||
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,6 +15,8 @@ using Newtonsoft.Json.Linq;
|
|||
using Microsoft.Extensions.Caching.Memory;
|
||||
using IRaCIS.Core.Application.Filter;
|
||||
using DocumentFormat.OpenXml.Drawing;
|
||||
using Quartz;
|
||||
using IRaCIS.Application.Services.BackGroundJob;
|
||||
|
||||
namespace IRaCIS.Application.Services
|
||||
{
|
||||
|
@ -57,7 +59,7 @@ namespace IRaCIS.Application.Services
|
|||
private readonly IRepository<ReadingQuestionSystem> _readingQuestionSystem;
|
||||
private readonly IRepository<NoneDicomStudyFile> _noneDicomStudyFileSystem;
|
||||
private readonly IRepository<ReadingQuestionTrial> _readingQuestionTrialRepository;
|
||||
|
||||
private readonly IScheduler _scheduler;
|
||||
private readonly IMemoryCache _cache;
|
||||
private readonly ITrialEmailNoticeConfigService _trialEmailNoticeConfigService;
|
||||
|
||||
|
@ -97,9 +99,11 @@ namespace IRaCIS.Application.Services
|
|||
IRepository<ReadingQuestionSystem> ReadingQuestionSystem,
|
||||
ITrialEmailNoticeConfigService trialEmailNoticeConfigService,
|
||||
IRepository<NoneDicomStudyFile> noneDicomStudyFileSystem,
|
||||
IRepository<ReadingQuestionTrial> readingQuestionTrialRepository
|
||||
IRepository<ReadingQuestionTrial> readingQuestionTrialRepository,
|
||||
IScheduler scheduler
|
||||
)
|
||||
{
|
||||
_scheduler = scheduler;
|
||||
base._mapper = mapper;
|
||||
this._noneDicomStudyRepository = noneDicomStudyRepository;
|
||||
this._visitTaskRepository = visitTaskRepository;
|
||||
|
@ -1436,7 +1440,8 @@ namespace IRaCIS.Application.Services
|
|||
if (tumorAnswer != null)
|
||||
{
|
||||
var isConvertedTask = await _visitTaskRepository.Where(x => x.Id == inDto.VisitTaskId).Select(x => x.IsConvertedTask).FirstOrDefaultAsync();
|
||||
var reportVerify = await _readingCalculateService.GetReportVerify(new GetReportVerifyInDto() {
|
||||
var reportVerify = await _readingCalculateService.GetReportVerify(new GetReportVerifyInDto()
|
||||
{
|
||||
BeforeConvertedTaskId = taskInfo.BeforeConvertedTaskId,
|
||||
IsConvertTask = isConvertedTask,
|
||||
VisitTaskId = inDto.VisitTaskId
|
||||
|
@ -2266,6 +2271,7 @@ namespace IRaCIS.Application.Services
|
|||
throw new BusinessValidationFailedException(_localizer["ReadingImage_IDMust"]);
|
||||
}
|
||||
|
||||
//看已阅的任务
|
||||
if (inDto.VisitTaskId != null)
|
||||
{
|
||||
task = await _visitTaskRepository.Where(x => x.Id == inDto.VisitTaskId).Select(x => new GetReadingTaskDto()
|
||||
|
@ -2327,13 +2333,20 @@ namespace IRaCIS.Application.Services
|
|||
}).FirstOrDefault();
|
||||
|
||||
|
||||
|
||||
if (task != null)
|
||||
{
|
||||
// 有序 自动领取该Subject
|
||||
await ClaimOrCancelSubjectAsync(new ClaimSubjectDto() { IsClaim = true, SubejctId = task.SubjectId, IsInOrder = true }, _scheduler);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
task = await _visitTaskRepository.Where(x => x.TrialId == inDto.TrialId && x.TrialReadingCriterionId == trialReadingCriterionId && x.ReadingTaskState != ReadingTaskState.HaveSigned && x.DoctorUserId == _userInfo.Id
|
||||
//无序取数据
|
||||
task = await _visitTaskRepository.Where(x => x.TrialId == inDto.TrialId && x.TrialReadingCriterionId == trialReadingCriterionId && x.ReadingTaskState != ReadingTaskState.HaveSigned /*&& x.DoctorUserId == _userInfo.Id*/
|
||||
&& x.TrialReadingCriterionId == trialReadingCriterionId
|
||||
&& x.TaskState == TaskState.Effect).Select(x => new GetReadingTaskDto()
|
||||
&& x.TaskState == TaskState.Effect)
|
||||
.Where(x => (x.IsNeedClinicalDataSign && x.IsClinicalDataSign) || !x.IsNeedClinicalDataSign)
|
||||
.Select(x => new GetReadingTaskDto()
|
||||
{
|
||||
VisitTaskId = x.Id,
|
||||
ArmEnum = x.ArmEnum,
|
||||
|
@ -2344,8 +2357,13 @@ namespace IRaCIS.Application.Services
|
|||
SubjectId = x.SubjectId,
|
||||
SubjectCode = x.Subject.Code,
|
||||
TrialReadingCriterionId = x.TrialReadingCriterionId,
|
||||
}).FirstOrDefaultAsync();
|
||||
}).OrderByDescending(t => t.TaskBlindName).FirstOrDefaultAsync();
|
||||
|
||||
if (task != null)
|
||||
{
|
||||
// 有序 自动领取该Subject
|
||||
await ClaimOrCancelSubjectAsync(new ClaimSubjectDto() { IsClaim = true, VisitTaskId = task.VisitTaskId, IsInOrder = false }, _scheduler);
|
||||
}
|
||||
}
|
||||
|
||||
if (task == null)
|
||||
|
@ -2474,6 +2492,70 @@ namespace IRaCIS.Application.Services
|
|||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
[HttpPost]
|
||||
public async Task ClaimOrCancelSubjectAsync(ClaimSubjectDto claimSubjectDto, IScheduler _scheduler)
|
||||
{
|
||||
if (claimSubjectDto.IsInOrder)
|
||||
{
|
||||
if (claimSubjectDto.IsClaim)
|
||||
{
|
||||
await _subjectRepository.UpdatePartialFromQueryAsync(t => t.Id == claimSubjectDto.SubejctId, u => new Subject() { ClaimUserId = _userInfo.Id }, true);
|
||||
|
||||
//定时任务24h取消
|
||||
|
||||
// 创建一个任务
|
||||
IJobDetail job = JobBuilder.Create<CancelTaskQuartZJob>()
|
||||
.WithIdentity($"CancelTaskQuartZJob_{_userInfo.Id}", "group")
|
||||
.UsingJobData("SubjectId", claimSubjectDto.SubejctId) // 传递GUID参数给任务
|
||||
.UsingJobData("IsInOrder", claimSubjectDto.IsInOrder)
|
||||
.Build();
|
||||
|
||||
// 创建一个触发器,设置任务执行时间为24小时后
|
||||
ITrigger trigger = TriggerBuilder.Create()
|
||||
.WithIdentity("CancelTaskQuartZJob", "group1")
|
||||
.StartAt(DateTimeOffset.UtcNow.AddHours(24))
|
||||
.Build();
|
||||
|
||||
// 将任务和触发器关联起来,将任务安排到调度器中
|
||||
await _scheduler.ScheduleJob(job, trigger);
|
||||
|
||||
//BackgroundJob.Schedule<IObtainTaskAutoCancelJob>(t => t.CancelQCObtaion(subjectVisitId, DateTime.Now), TimeSpan.FromHours(1));
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
await _subjectRepository.UpdatePartialFromQueryAsync(t => t.Id == claimSubjectDto.SubejctId, u => new Subject() { ClaimUserId = null }, true);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (claimSubjectDto.IsClaim)
|
||||
{
|
||||
await _visitTaskRepository.UpdatePartialFromQueryAsync(t => t.Id == claimSubjectDto.VisitTaskId, u => new VisitTask() { ClaimUserId = _userInfo.Id }, true);
|
||||
|
||||
IJobDetail job = JobBuilder.Create<CancelTaskQuartZJob>()
|
||||
.WithIdentity($"CancelTaskQuartZJob_{_userInfo.Id}", "group")
|
||||
.UsingJobData("VisitTaskId",(Guid) claimSubjectDto.VisitTaskId) // 传递GUID参数给任务
|
||||
.UsingJobData("IsInOrder", claimSubjectDto.IsInOrder).Build();
|
||||
|
||||
// 创建一个触发器,设置任务执行时间为24小时后
|
||||
ITrigger trigger = TriggerBuilder.Create()
|
||||
.WithIdentity($"CancelTaskQuartZJob_{_userInfo.Id}", "group")
|
||||
.StartAt(DateTimeOffset.UtcNow.AddHours(24))
|
||||
.Build();
|
||||
|
||||
// 将任务和触发器关联起来,将任务安排到调度器中
|
||||
await _scheduler.ScheduleJob(job, trigger);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
|
@ -736,14 +736,14 @@ namespace IRaCIS.Core.Application.Contracts
|
|||
|
||||
var trialSiteSurvey = (await _trialSiteSurveyRepository.Where(t => t.Id == trialSiteSurveyId).FirstOrDefaultAsync()).IfNullThrowException();
|
||||
|
||||
var siteUserList = await _trialSiteUserSurveyRepository.Where(t => t.TrialSiteSurvey.SiteId == trialSiteSurvey.SiteId).Select(t => new { t.TrialSiteSurveyId, t.IsGenerateAccount, t.UserTypeId, t.UserTypeRole.UserTypeEnum, t.TrialRoleName.Code }).ToListAsync();
|
||||
var siteUserList = await _trialSiteUserSurveyRepository.Where(t => t.TrialSiteSurvey.SiteId == trialSiteSurvey.SiteId).Select(t => new { t.TrialSiteSurveyId, t.IsGenerateAccount, t.IsGenerateSuccess, t.UserTypeId, t.UserTypeRole.UserTypeEnum, t.TrialRoleName.Code }).ToListAsync();
|
||||
|
||||
|
||||
|
||||
if (_userInfo.UserTypeEnumInt == (int)UserTypeEnum.Undefined)
|
||||
{
|
||||
//是第一次
|
||||
if(!siteUserList.Any(t=>t.IsGenerateAccount))
|
||||
if(!siteUserList.Any(t=>t.IsGenerateSuccess))
|
||||
{
|
||||
var currentUserList = siteUserList.Where(t => t.TrialSiteSurveyId == trialSiteSurveyId).ToList();
|
||||
|
||||
|
@ -760,7 +760,7 @@ namespace IRaCIS.Core.Application.Contracts
|
|||
|
||||
|
||||
//是第一次
|
||||
if (!siteUserList.Any(t => t.IsGenerateAccount))
|
||||
if (!siteUserList.Any(t => t.IsGenerateSuccess))
|
||||
{
|
||||
var currentUserList = siteUserList.Where(t => t.TrialSiteSurveyId == trialSiteSurveyId).ToList();
|
||||
|
||||
|
|
|
@ -426,6 +426,8 @@ namespace IRaCIS.Core.Domain.Models
|
|||
}
|
||||
}
|
||||
|
||||
public Guid? ClaimUserId { get; set; }
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
|
@ -123,6 +123,9 @@ namespace IRaCIS.Core.Domain.Models
|
|||
public bool IsReReadingOrBackInfluenceAnalysis { get; set; }
|
||||
|
||||
|
||||
public Guid? ClaimUserId { get; set; }
|
||||
|
||||
|
||||
//是否分配了读片医生
|
||||
//public bool IsAssignDoctorUser{get;set;}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue