修复年龄段跨组问题

This commit is contained in:
马梓彭 2026-06-22 12:16:23 +08:00
parent 0041776c98
commit dcd3414c54
2 changed files with 23 additions and 31 deletions

View File

@ -40,9 +40,9 @@ public class AppUserService : BaseService<AppUserEntity>, ITransient
{ {
var query = _appUserRep.AsQueryable() var query = _appUserRep.AsQueryable()
.Where(u => u.PersonType == PersonType.Athlete) .Where(u => u.PersonType == PersonType.Athlete)
// 排除:仅由单位添加、但用户本人尚未通过小程序提交认证的运动员 // 仅显示真正在小程序端自主注册/登录过的用户:有密码、或有微信昵称/头像
// 保留:自主注册的用户(MerchantCertificationId == null)+ 单位添加但自己已提交认证的用户(AuditStatus != PendingSubmission) // 单位后台添加后被移除的运动员(无密码、无微信信息)不应出现在此列表
.Where(u => u.MerchantCertificationId == null || u.AuditStatus != AuditStatus.PendingSubmission) .Where(u => u.Password != null || u.NickName != null || u.Avatar != null)
.WhereIF(!string.IsNullOrWhiteSpace(input.Name), u => u.Name.Contains(input.Name)) .WhereIF(!string.IsNullOrWhiteSpace(input.Name), u => u.Name.Contains(input.Name))
.WhereIF(input.Gender.HasValue, u => u.Gender == input.Gender) .WhereIF(input.Gender.HasValue, u => u.Gender == input.Gender)
.WhereIF(!string.IsNullOrWhiteSpace(input.Mobile), u => u.Mobile.Contains(input.Mobile)) .WhereIF(!string.IsNullOrWhiteSpace(input.Mobile), u => u.Mobile.Contains(input.Mobile))

View File

@ -707,50 +707,42 @@ public class UnifiedRegistrationService : ITransient
bool hasEndLimit = group.BirthDateEnd != DateTime.MinValue; bool hasEndLimit = group.BirthDateEnd != DateTime.MinValue;
bool hasStartLimit = group.BirthDateStart != DateTime.MinValue; bool hasStartLimit = group.BirthDateStart != DateTime.MinValue;
// ① 检查是否有超过最大年龄限制的队员(出生日期晚于 BirthDateEnd → 太小) // ① 超龄检查(大年龄段报小年龄段 → 拒绝)
if (hasEndLimit) // BirthDate < BirthDateStart → 出生太早 → 年龄偏大 → 不允许报小年龄组
{
var aboveAgePerson = persons.FirstOrDefault(p => p.BirthDate > group.BirthDateEnd);
if (aboveAgePerson != null)
{
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 → 超龄 / 年龄太大)
if (hasStartLimit) if (hasStartLimit)
{ {
var belowAgePerson = persons.FirstOrDefault(p => p.BirthDate < group.BirthDateStart); var tooOldPerson = persons.FirstOrDefault(p => p.BirthDate < group.BirthDateStart);
if (belowAgePerson != null) if (tooOldPerson != null)
{ {
result.IsValid = false; result.IsValid = false;
result.ErrorMessage = $"队员{belowAgePerson.Name}的年龄超过组别最大年龄限制。要求出生日期不早于:{group.BirthDateStart:yyyy-MM-dd},实际:{belowAgePerson.BirthDate:yyyy-MM-dd}"; result.ErrorMessage = $"队员{tooOldPerson.Name}的年龄超过组别最大年龄限制。要求出生日期不早于:{group.BirthDateStart:yyyy-MM-dd},实际:{tooOldPerson.BirthDate:yyyy-MM-dd}";
result.Details.Add(CreateValidationDetail("年龄验证", false, result.ErrorMessage)); result.Details.Add(CreateValidationDetail("年龄验证", false, result.ErrorMessage));
return result; return result;
} }
} }
// ③ 统计年龄状态(仅用于详情展示) // ② 统计年龄状态
// inTargetCount:在目标年龄段内(BirthDateStart ≤ BirthDate ≤ BirthDateEnd)
// aboveTargetCount:小年龄段报大年龄段(BirthDate > BirthDateEnd,年龄偏小)→ 允许跨组
int inTargetCount = 0; int inTargetCount = 0;
int belowTargetCount = 0; int aboveTargetCount = 0;
if (hasStartLimit && hasEndLimit) if (hasStartLimit || hasEndLimit)
{ {
inTargetCount = persons.Count(p => p.BirthDate >= group.BirthDateStart && p.BirthDate <= group.BirthDateEnd); inTargetCount = persons.Count(p =>
belowTargetCount = persons.Count(p => p.BirthDate < group.BirthDateStart); (!hasStartLimit || p.BirthDate >= group.BirthDateStart) &&
(!hasEndLimit || p.BirthDate <= group.BirthDateEnd));
aboveTargetCount = persons.Count(p => hasEndLimit && p.BirthDate > group.BirthDateEnd);
} }
// 团队项目跨组验证(仅当配置了年龄区间时才需要):保留原有业务规则——团队中至少需要有一名成员属于目标年龄段 // ③ 团队项目跨组验证:允许小年龄段报大年龄段,但团队中至少需要有一人属于目标年龄段
if (hasStartLimit && hasEndLimit && isTeamProject && belowTargetCount > 0 && inTargetCount == 0) if (hasEndLimit && isTeamProject && aboveTargetCount > 0 && inTargetCount == 0)
{ {
bool allBelow = belowTargetCount == persons.Count; bool allAbove = aboveTargetCount == persons.Count;
string errorMessage = allBelow string errorMessage = allAbove
? "跨组报名时,团队中所有成员年龄均小于目标年龄段,团队中至少需要有一名成员属于目标年龄段" ? "跨组报名时,团队中所有成员年龄均小于目标年龄段,团队中至少需要有一名成员属于目标年龄段"
: "跨组报名时,团队中至少需要有一名成员属于目标年龄段"; : "跨组报名时,团队中至少需要有一名成员属于目标年龄段";
string itemName = allBelow string itemName = allAbove
? "年龄跨组验证(全部小于目标年龄)" ? "年龄跨组验证(全部小于目标年龄)"
: "年龄跨组验证"; : "年龄跨组验证";
@ -763,7 +755,7 @@ public class UnifiedRegistrationService : ITransient
// 添加验证通过的详情 // 添加验证通过的详情
if (hasStartLimit || hasEndLimit) if (hasStartLimit || hasEndLimit)
{ {
result.Details.Add(belowTargetCount > 0 result.Details.Add(aboveTargetCount > 0
? CreateValidationDetail("年龄跨组", true, "符合年龄跨组报名要求") ? CreateValidationDetail("年龄跨组", true, "符合年龄跨组报名要求")
: CreateValidationDetail("年龄验证", true, "所有队员均在目标年龄段内")); : CreateValidationDetail("年龄验证", true, "所有队员均在目标年龄段内"));
} }