报名年龄限制
This commit is contained in:
parent
a5df8efa17
commit
ad2a792a51
@ -717,25 +717,49 @@ public class UnifiedRegistrationService : ITransient
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
private static RegistrationValidationResult? ValidatePersonAges(List<UnifiedPersonInput> persons, EventProjectGroup group, bool isTeamProject, RegistrationValidationResult result)
|
private static RegistrationValidationResult? ValidatePersonAges(List<UnifiedPersonInput> persons, EventProjectGroup group, bool isTeamProject, RegistrationValidationResult result)
|
||||||
{
|
{
|
||||||
// 检查是否有超过最大年龄限制的队员
|
// 组别未配置年龄限制时,跳过年龄检查(避免 DateTime.MinValue 造成的误判)
|
||||||
var aboveAgePerson = persons.FirstOrDefault(p => p.BirthDate > group.BirthDateEnd);
|
bool hasEndLimit = group.BirthDateEnd != DateTime.MinValue;
|
||||||
if (aboveAgePerson != null)
|
bool hasStartLimit = group.BirthDateStart != DateTime.MinValue;
|
||||||
|
|
||||||
|
// ① 检查是否有超过最大年龄限制的队员(出生日期晚于 BirthDateEnd → 太小)
|
||||||
|
if (hasEndLimit)
|
||||||
{
|
{
|
||||||
result.IsValid = false;
|
var aboveAgePerson = persons.FirstOrDefault(p => p.BirthDate > group.BirthDateEnd);
|
||||||
result.ErrorMessage = $"队员{aboveAgePerson.Name}的年龄超过组别最大限制。要求出生日期不晚于:{group.BirthDateEnd:yyyy-MM-dd},实际:{aboveAgePerson.BirthDate:yyyy-MM-dd}";
|
if (aboveAgePerson != null)
|
||||||
result.Details.Add(CreateValidationDetail("年龄验证", false, result.ErrorMessage));
|
{
|
||||||
return result;
|
result.IsValid = false;
|
||||||
|
result.ErrorMessage = $"队员{aboveAgePerson.Name}的年龄低于组别最小年龄要求。要求出生日期不晚于:{group.BirthDateEnd:yyyy-MM-dd},实际:{aboveAgePerson.BirthDate:yyyy-MM-dd}";
|
||||||
|
result.Details.Add(CreateValidationDetail("年龄验证", false, result.ErrorMessage));
|
||||||
|
return result;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 统计年龄状态
|
// ② 检查是否有年龄超过最小年龄限制的队员(出生日期早于 BirthDateStart → 超龄 / 年龄太大)
|
||||||
var inTargetCount = persons.Count(p => p.BirthDate >= group.BirthDateStart && p.BirthDate <= group.BirthDateEnd);
|
if (hasStartLimit)
|
||||||
var belowTargetCount = persons.Count(p => p.BirthDate < group.BirthDateStart);
|
|
||||||
bool hasBelow = belowTargetCount > 0;
|
|
||||||
bool allBelow = belowTargetCount == persons.Count;
|
|
||||||
|
|
||||||
// 团队项目跨组验证
|
|
||||||
if (isTeamProject && hasBelow && inTargetCount == 0)
|
|
||||||
{
|
{
|
||||||
|
var belowAgePerson = persons.FirstOrDefault(p => p.BirthDate < group.BirthDateStart);
|
||||||
|
if (belowAgePerson != null)
|
||||||
|
{
|
||||||
|
result.IsValid = false;
|
||||||
|
result.ErrorMessage = $"队员{belowAgePerson.Name}的年龄超过组别最大年龄限制。要求出生日期不早于:{group.BirthDateStart:yyyy-MM-dd},实际:{belowAgePerson.BirthDate:yyyy-MM-dd}";
|
||||||
|
result.Details.Add(CreateValidationDetail("年龄验证", false, result.ErrorMessage));
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ③ 统计年龄状态(仅用于详情展示)
|
||||||
|
int inTargetCount = 0;
|
||||||
|
int belowTargetCount = 0;
|
||||||
|
if (hasStartLimit && hasEndLimit)
|
||||||
|
{
|
||||||
|
inTargetCount = persons.Count(p => p.BirthDate >= group.BirthDateStart && p.BirthDate <= group.BirthDateEnd);
|
||||||
|
belowTargetCount = persons.Count(p => p.BirthDate < group.BirthDateStart);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 团队项目跨组验证(仅当配置了年龄区间时才需要):保留原有业务规则——团队中至少需要有一名成员属于目标年龄段
|
||||||
|
if (hasStartLimit && hasEndLimit && isTeamProject && belowTargetCount > 0 && inTargetCount == 0)
|
||||||
|
{
|
||||||
|
bool allBelow = belowTargetCount == persons.Count;
|
||||||
string errorMessage = allBelow
|
string errorMessage = allBelow
|
||||||
? "跨组报名时,团队中所有成员年龄均小于目标年龄段,团队中至少需要有一名成员属于目标年龄段"
|
? "跨组报名时,团队中所有成员年龄均小于目标年龄段,团队中至少需要有一名成员属于目标年龄段"
|
||||||
: "跨组报名时,团队中至少需要有一名成员属于目标年龄段";
|
: "跨组报名时,团队中至少需要有一名成员属于目标年龄段";
|
||||||
@ -751,9 +775,12 @@ public class UnifiedRegistrationService : ITransient
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 添加验证通过的详情
|
// 添加验证通过的详情
|
||||||
result.Details.Add(hasBelow
|
if (hasStartLimit || hasEndLimit)
|
||||||
? CreateValidationDetail("年龄跨组", true, "符合年龄跨组报名要求")
|
{
|
||||||
: CreateValidationDetail("年龄验证", true, "所有队员均在目标年龄段内"));
|
result.Details.Add(belowTargetCount > 0
|
||||||
|
? CreateValidationDetail("年龄跨组", true, "符合年龄跨组报名要求")
|
||||||
|
: CreateValidationDetail("年龄验证", true, "所有队员均在目标年龄段内"));
|
||||||
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user