多组别设置
This commit is contained in:
parent
52c3c9ecca
commit
e06422ab06
@ -472,7 +472,7 @@ public class UnifiedRegistrationService : ITransient
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 验证项目选择(一阶段:单选机制)
|
/// 验证项目选择(一阶段:支持同一项目选择多个组别)
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private async Task<RegistrationValidationResult> ValidateProjectSelectionAsync(UnifiedRegistrationInput input)
|
private async Task<RegistrationValidationResult> ValidateProjectSelectionAsync(UnifiedRegistrationInput input)
|
||||||
{
|
{
|
||||||
@ -482,25 +482,47 @@ public class UnifiedRegistrationService : ITransient
|
|||||||
Details = new List<ValidationDetail>()
|
Details = new List<ValidationDetail>()
|
||||||
};
|
};
|
||||||
|
|
||||||
// 1. 检查是否有重复选择的项目(每个项目只能选择一个组别)
|
// 1. 检查是否存在重复选择的同一项目下的同一组别(同一项目下的不同组别是允许的)
|
||||||
var duplicateProjects = input.Items
|
var duplicateGroupIds = input.Items
|
||||||
.GroupBy(i => i.ProjectId)
|
.Where(i => i.GroupId.HasValue)
|
||||||
|
.GroupBy(i => i.GroupId!.Value)
|
||||||
.Where(g => g.Count() > 1)
|
.Where(g => g.Count() > 1)
|
||||||
.Select(g => g.Key)
|
.Select(g => g.Key)
|
||||||
.ToList();
|
.ToList();
|
||||||
|
|
||||||
if (duplicateProjects.Any())
|
if (duplicateGroupIds.Any())
|
||||||
{
|
{
|
||||||
var eventProjects = await _eventProjectRepository.GetListAsync(x => duplicateProjects.Contains(x.Id));
|
var duplicateGroups = await _eventProjectGroupRepository.GetListAsync(x => duplicateGroupIds.Contains(x.Id));
|
||||||
var projectNames = eventProjects.Select(ep => $"{ep.ProjectId}").ToList();
|
var groupNames = duplicateGroups.Select(g => $"{g.GroupName ?? g.Id.ToString()}").ToList();
|
||||||
|
|
||||||
result.IsValid = false;
|
result.IsValid = false;
|
||||||
result.ErrorMessage = $"以下项目被重复选择,请确保每个项目只选择一个组别:{string.Join(", ", projectNames)}";
|
result.ErrorMessage = $"同一组别被重复选择:{string.Join(", ", groupNames)},同一项目下的不同组别可以重复选择,但同一组别不能选择两次";
|
||||||
result.Details.Add(CreateValidationDetail("项目选择", false, result.ErrorMessage));
|
result.Details.Add(CreateValidationDetail("组别选择", false, result.ErrorMessage));
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
result.Details.Add(CreateValidationDetail("项目单选机制", true, "每个项目仅选择一个组别,符合要求"));
|
// 2. 验证每个 item 的 ProjectId 与 GroupId 的对应关系
|
||||||
|
var groupIds = input.Items.Where(i => i.GroupId.HasValue).Select(i => i.GroupId!.Value).Distinct().ToList();
|
||||||
|
if (groupIds.Any())
|
||||||
|
{
|
||||||
|
var eventProjectGroups = await _eventProjectGroupRepository.GetListAsync(x => groupIds.Contains(x.Id));
|
||||||
|
foreach (var item in input.Items)
|
||||||
|
{
|
||||||
|
if (!item.GroupId.HasValue) continue;
|
||||||
|
var epg = eventProjectGroups.FirstOrDefault(g => g.Id == item.GroupId.Value);
|
||||||
|
if (epg == null) continue;
|
||||||
|
|
||||||
|
if (item.ProjectId != epg.EventProjectId)
|
||||||
|
{
|
||||||
|
result.IsValid = false;
|
||||||
|
result.ErrorMessage = $"组别 {item.GroupId.Value} 不属于项目 {item.ProjectId},请检查选择";
|
||||||
|
result.Details.Add(CreateValidationDetail("组别-项目匹配", false, result.ErrorMessage));
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
result.Details.Add(CreateValidationDetail("项目组别选择", true, "同一项目可以选择多个组别,符合要求"));
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@ -1614,9 +1636,17 @@ public class UnifiedRegistrationService : ITransient
|
|||||||
int individualProjectCount = 0;
|
int individualProjectCount = 0;
|
||||||
int teamProjectCount = 0;
|
int teamProjectCount = 0;
|
||||||
|
|
||||||
// 统计已存在的报名项目
|
// 已统计过的项目ID(同一项目下的多个组别不会重复统计)
|
||||||
|
var countedProjectIds = new HashSet<long>();
|
||||||
|
|
||||||
|
// 统计已存在的报名项目(去重:同一项目下的多个组别仅统计一次)
|
||||||
foreach (var item in personRegistrationItems)
|
foreach (var item in personRegistrationItems)
|
||||||
{
|
{
|
||||||
|
if (!countedProjectIds.Add(item.ProjectId))
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
var eventProject = eventProjects.FirstOrDefault(ep => ep.Id == item.ProjectId);
|
var eventProject = eventProjects.FirstOrDefault(ep => ep.Id == item.ProjectId);
|
||||||
if (eventProject == null) continue;
|
if (eventProject == null) continue;
|
||||||
|
|
||||||
@ -1634,8 +1664,6 @@ public class UnifiedRegistrationService : ITransient
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 统计本次提交的项目,确保不重复统计
|
// 统计本次提交的项目,确保不重复统计
|
||||||
var existingProjectIds = new HashSet<long>(personRegistrationItems.Select(x => x.ProjectId));
|
|
||||||
|
|
||||||
foreach (var item in input.Items)
|
foreach (var item in input.Items)
|
||||||
{
|
{
|
||||||
// 检查该成员是否在本次提交的项目中
|
// 检查该成员是否在本次提交的项目中
|
||||||
@ -1645,8 +1673,8 @@ public class UnifiedRegistrationService : ITransient
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 检查是否已经统计过该项目
|
// 检查是否已经统计过该项目(包含已有报名或本次提交中已统计过的项目)
|
||||||
if (existingProjectIds.Contains(item.ProjectId))
|
if (!countedProjectIds.Add(item.ProjectId))
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -1665,9 +1693,6 @@ public class UnifiedRegistrationService : ITransient
|
|||||||
{
|
{
|
||||||
teamProjectCount++;
|
teamProjectCount++;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 标记该项目已统计
|
|
||||||
existingProjectIds.Add(item.ProjectId);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return (individualProjectCount, teamProjectCount);
|
return (individualProjectCount, teamProjectCount);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user