分配算法简单完成
This commit is contained in:
@@ -319,7 +319,7 @@ namespace IRaCIS.Core.Application.Service
|
||||
{
|
||||
//自动分配的话,需要把手动分配的给删掉
|
||||
|
||||
throw new BusinessValidationFailedException("自动分配算法正在开发,还未完成");
|
||||
//throw new BusinessValidationFailedException("自动分配算法正在开发,还未完成");
|
||||
|
||||
var trialId = autoSubjectAssignCommand.TrialId;
|
||||
|
||||
@@ -384,7 +384,19 @@ namespace IRaCIS.Core.Application.Service
|
||||
//eg : 10个Sujbect 都是1/4 先分配整数 再分配 10%4=2个
|
||||
|
||||
//特殊: 不够分的subject数量 适用于 2个Subject 4个医生 这种
|
||||
var specialSubjectCount = subjectCount % waitAllocationDoctorList.Count();
|
||||
|
||||
|
||||
var integerPlan = 0;
|
||||
|
||||
waitAllocationDoctorList.ForEach(doctor =>
|
||||
{
|
||||
|
||||
integerPlan += (int)Math.Floor((double)(subjectCount * doctor.PlanReadingRatio ) / 100);
|
||||
|
||||
});
|
||||
|
||||
|
||||
var specialSubjectCount = subjectCount - integerPlan;
|
||||
|
||||
//按照医生维度 分配Subject
|
||||
foreach (var doctor in waitAllocationDoctorList)
|
||||
@@ -401,7 +413,7 @@ namespace IRaCIS.Core.Application.Service
|
||||
var planSubjectCount = (int)Math.Ceiling((double)(subjectCount * doctor.PlanReadingRatio) / 100);
|
||||
|
||||
//权重大的,将特殊的分配
|
||||
if (doctor.Weight >= 50)
|
||||
if (doctor.Weight != 50)
|
||||
{
|
||||
if (specialSubjectCount > 0)
|
||||
{
|
||||
@@ -443,8 +455,17 @@ namespace IRaCIS.Core.Application.Service
|
||||
}
|
||||
if (trialConfig.ReadingType == ReadingMethod.Double)
|
||||
{
|
||||
var integerPlan = 0;
|
||||
|
||||
var specialSubjectCount = subjectCount % waitAllocationDoctorList.Count();
|
||||
waitAllocationDoctorList.ForEach(doctor =>
|
||||
{
|
||||
|
||||
integerPlan += (int)Math.Floor((double)(subjectCount * doctor.PlanReadingRatio * 2) / 100);
|
||||
|
||||
});
|
||||
|
||||
|
||||
var specialSubjectCount = (subjectCount * 2) - integerPlan;
|
||||
|
||||
//按照医生维度 分配Subject
|
||||
foreach (var doctor in waitAllocationDoctorList)
|
||||
@@ -458,10 +479,13 @@ namespace IRaCIS.Core.Application.Service
|
||||
var hasAssignedSubjectCount = hasAssignedSubjectIdList.Count();
|
||||
|
||||
//该医生计划分配到的Subject 最接近的整数数量
|
||||
var planSubjectCount = (int)Math.Floor((double)(subjectCount * doctor.PlanReadingRatio *2) / 100);
|
||||
var planSubjectCount = (int)Math.Floor((double)(subjectCount * doctor.PlanReadingRatio * 2) / 100);
|
||||
|
||||
//权重大的,将特殊的分配
|
||||
if (doctor.Weight >= 50)
|
||||
//判断是否能整除
|
||||
|
||||
var yuShu = (subjectCount * doctor.PlanReadingRatio * 2) % 100;
|
||||
|
||||
if ( yuShu != 0)
|
||||
{
|
||||
if (specialSubjectCount > 0)
|
||||
{
|
||||
@@ -469,14 +493,11 @@ namespace IRaCIS.Core.Application.Service
|
||||
planSubjectCount++;
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
planSubjectCount++;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
//如果计划的数量 大于已经分配的数量 那么该医生 可以分配新的Subject
|
||||
if (planSubjectCount > hasAssignedSubjectCount)
|
||||
{
|
||||
@@ -488,13 +509,13 @@ namespace IRaCIS.Core.Application.Service
|
||||
|
||||
//取需要分配的数量 并且没有分配给其他医生的包括自己
|
||||
var assignSubjectIdList = subjectList.Where(t => !hasAssignedSubjectIdList.Contains(t.SubjectId) && !otherExceptDoctorIdList.Contains(t.SubjectId))
|
||||
.Select(t => t.SubjectId).Take((planSubjectCount - hasAssignedSubjectCount) * 2).ToList();
|
||||
.Select(t => t.SubjectId).Take((planSubjectCount - hasAssignedSubjectCount) ).ToList();
|
||||
|
||||
foreach (var assignSubjectId in assignSubjectIdList)
|
||||
{
|
||||
|
||||
|
||||
var otherHaveAssignedSubject= assignedSubjectDoctorList.Where(t => t.SubjectId == assignSubjectId).FirstOrDefault();
|
||||
var otherHaveAssignedSubject = assignedSubjectDoctorList.Where(t => t.SubjectId == assignSubjectId).FirstOrDefault();
|
||||
|
||||
if (otherHaveAssignedSubject != null)
|
||||
{
|
||||
@@ -506,7 +527,7 @@ namespace IRaCIS.Core.Application.Service
|
||||
await _subjectUserRepository.AddAsync(new SubjectUser() { TrialId = trialId, SubjectId = assignSubjectId, DoctorUserId = doctor.DoctorUserId, ArmEnum = 2, AssignTime = DateTime.Now });
|
||||
|
||||
}
|
||||
else if(otherHaveAssignedSubject.ArmEnum == 2)
|
||||
else if (otherHaveAssignedSubject.ArmEnum == 2)
|
||||
{
|
||||
assignedSubjectDoctorList.Add(new { SubjectId = assignSubjectId, DoctorUserId = doctor.DoctorUserId, ArmEnum = 1 });
|
||||
|
||||
@@ -521,7 +542,7 @@ namespace IRaCIS.Core.Application.Service
|
||||
await _subjectUserRepository.AddAsync(new SubjectUser() { TrialId = trialId, SubjectId = assignSubjectId, DoctorUserId = doctor.DoctorUserId, ArmEnum = 1, AssignTime = DateTime.Now });
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user