From a09be1975dae479827da2927cb2eb80d373233ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=A9=AC=E6=A2=93=E5=BD=AD?= Date: Wed, 10 Jun 2026 13:25:53 +0800 Subject: [PATCH] =?UTF-8?q?=E9=A1=B9=E7=9B=AE=E5=AE=8C=E6=88=90=E4=BA=BA?= =?UTF-8?q?=E6=95=B0=E6=94=B9=E4=B8=BA=E8=8C=83=E5=9B=B4=E5=80=BC=E5=92=8C?= =?UTF-8?q?=E5=8D=95=E5=80=BC=E5=9D=87=E5=8F=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Client/Dtos/EventClientDtos.cs | 25 ++++ .../Client/EventClientController.cs | 28 +++- YD_Event.Application/Event/Dtos/EventDtos.cs | 25 ++++ .../Event/Dtos/UserCompetitionDtos.cs | 20 +++ YD_Event.Application/Event/EventService.cs | 18 ++- .../Event/UnifiedRegistrationService.cs | 92 ++++++++++--- .../Event/UserEventRegistrationService.cs | 129 ++++++++++++++++-- YD_Event.Application/Order/OrderService.cs | 45 ++++-- .../Project/Dtos/ProjectDtos.cs | 43 +++++- .../Project/ProjectService.cs | 82 ++++++++++- YD_Event.Application/YD_Event.Application.xml | 109 ++++++++++++++- YD_Event.Core/Entities/Project.cs | 17 ++- YD_Event.Core/YD_Event.Core.xml | 17 ++- 13 files changed, 593 insertions(+), 57 deletions(-) diff --git a/YD_Event.Application/Client/Dtos/EventClientDtos.cs b/YD_Event.Application/Client/Dtos/EventClientDtos.cs index e5687a7..5b3fba9 100644 --- a/YD_Event.Application/Client/Dtos/EventClientDtos.cs +++ b/YD_Event.Application/Client/Dtos/EventClientDtos.cs @@ -451,6 +451,31 @@ public class EventProjectDto /// public int? ProjectLimitCount { get; set; } + /// + /// 完成人数模式(0=单一值,1=范围值) + /// + public int CompletionCountType { get; set; } + + /// + /// 完成人数(单一值模式时有效) + /// + public int? CompletionCount { get; set; } + + /// + /// 完成人数最小值(范围值模式时有效) + /// + public int? CompletionCountMin { get; set; } + + /// + /// 完成人数最大值(范围值模式时有效) + /// + public int? CompletionCountMax { get; set; } + + /// + /// 完成人数显示文本(如"5人"或"3-7人") + /// + public string? CompletionCountDisplay { get; set; } + /// /// 组别列表 /// diff --git a/YD_Event.Application/Client/EventClientController.cs b/YD_Event.Application/Client/EventClientController.cs index 4920c94..853b4c9 100644 --- a/YD_Event.Application/Client/EventClientController.cs +++ b/YD_Event.Application/Client/EventClientController.cs @@ -342,7 +342,11 @@ public class EventClientController : IDynamicApiController .Select(p => new { p.Id, p.Name, - p.ProjectType + p.ProjectType, + p.CompletionCountType, + p.CompletionCount, + p.CompletionCountMin, + p.CompletionCountMax }) .ToListAsync(); @@ -496,6 +500,23 @@ public class EventClientController : IDynamicApiController var bp = baseProjects.FirstOrDefault(b => b.Id == ep.ProjectId); var pl = projectLimits.FirstOrDefault(x => x.ProjectId == ep.Id); var epGroups = eventProjectGroups.Where(g => g.EventProjectId == ep.Id).ToList(); + + // 生成完成人数显示文本 + string completionCountDisplay = ""; + if (bp != null) + { + if (bp.CompletionCountType == 1) + { + var min = bp.CompletionCountMin ?? 0; + var max = bp.CompletionCountMax ?? 0; + completionCountDisplay = $"{min}-{max}人"; + } + else + { + completionCountDisplay = $"{bp.CompletionCount}人"; + } + } + return new EventProjectDto { Id = ep.Id, @@ -504,6 +525,11 @@ public class EventClientController : IDynamicApiController ProjectType = (long)(bp?.ProjectType ?? 0), Fee = ep.Price, ProjectLimitCount = pl?.LimitCount, + CompletionCountType = bp?.CompletionCountType ?? 0, + CompletionCount = bp?.CompletionCount, + CompletionCountMin = bp?.CompletionCountMin, + CompletionCountMax = bp?.CompletionCountMax, + CompletionCountDisplay = completionCountDisplay, Groups = epGroups.Select(eg => { var baseGroup = baseGroups.FirstOrDefault(bg => bg.Id == eg.ProjectGroupId); diff --git a/YD_Event.Application/Event/Dtos/EventDtos.cs b/YD_Event.Application/Event/Dtos/EventDtos.cs index 7eea00f..9548f00 100644 --- a/YD_Event.Application/Event/Dtos/EventDtos.cs +++ b/YD_Event.Application/Event/Dtos/EventDtos.cs @@ -364,6 +364,31 @@ public class EventProjectInput /// 比赛时长(秒) (显示用) /// public int? DurationSeconds { get; set; } + + /// + /// 完成人数模式 (显示用) 0=单一值, 1=范围值 + /// + public int CompletionCountType { get; set; } + + /// + /// 完成人数 (显示用) 单一值模式时有效 + /// + public int? CompletionCount { get; set; } + + /// + /// 完成人数最小值 (显示用) 范围值模式时有效 + /// + public int? CompletionCountMin { get; set; } + + /// + /// 完成人数最大值 (显示用) 范围值模式时有效 + /// + public int? CompletionCountMax { get; set; } + + /// + /// 完成人数显示文本 (显示用) 如:5人 或 3-5人 + /// + public string? CompletionCountDisplay { get; set; } /// /// 项目费用(Step 4) diff --git a/YD_Event.Application/Event/Dtos/UserCompetitionDtos.cs b/YD_Event.Application/Event/Dtos/UserCompetitionDtos.cs index e7001e5..a1f20e0 100644 --- a/YD_Event.Application/Event/Dtos/UserCompetitionDtos.cs +++ b/YD_Event.Application/Event/Dtos/UserCompetitionDtos.cs @@ -397,6 +397,26 @@ public class UserEventProjectListOutput /// public int CompletionCount { get; set; } + /// + /// 完成人数模式 (0=单一值, 1=范围值) + /// + public int CompletionCountType { get; set; } + + /// + /// 完成人数最小值(范围值模式) + /// + public int? CompletionCountMin { get; set; } + + /// + /// 完成人数最大值(范围值模式) + /// + public int? CompletionCountMax { get; set; } + + /// + /// 完成人数显示文本(如"5人"或"3-7人") + /// + public string? CompletionCountDisplay { get; set; } + /// /// 项目类型 /// diff --git a/YD_Event.Application/Event/EventService.cs b/YD_Event.Application/Event/EventService.cs index 5f828c8..1b83acc 100644 --- a/YD_Event.Application/Event/EventService.cs +++ b/YD_Event.Application/Event/EventService.cs @@ -207,12 +207,28 @@ public class EventService : BaseService, ITransient Name = baseProj?.Name, ProjectTypeId = (long?)baseProj?.ProjectType, DurationMinutes = baseProj?.DurationMinutes, - DurationSeconds = baseProj?.DurationSeconds + DurationSeconds = baseProj?.DurationSeconds, + // 填充完成人数相关字段 + CompletionCountType = baseProj?.CompletionCountType ?? 0, + CompletionCount = baseProj?.CompletionCount, + CompletionCountMin = baseProj?.CompletionCountMin, + CompletionCountMax = baseProj?.CompletionCountMax }; if (baseProj != null) { dto.ProjectTypeName = baseProj.ProjectType.Description(); + // 生成完成人数显示文本 + if (baseProj.CompletionCountType == 0) + { + dto.CompletionCountDisplay = baseProj.CompletionCount > 0 ? $"{baseProj.CompletionCount}人" : "0人"; + } + else + { + var min = baseProj.CompletionCountMin ?? 0; + var max = baseProj.CompletionCountMax ?? 0; + dto.CompletionCountDisplay = $"{min}-{max}人"; + } } var epGroups = eventProjectGroups.Where(g => g.EventProjectId == ep.Id).ToList(); diff --git a/YD_Event.Application/Event/UnifiedRegistrationService.cs b/YD_Event.Application/Event/UnifiedRegistrationService.cs index ba61945..8793e27 100644 --- a/YD_Event.Application/Event/UnifiedRegistrationService.cs +++ b/YD_Event.Application/Event/UnifiedRegistrationService.cs @@ -1543,7 +1543,8 @@ public class UnifiedRegistrationService : ITransient // 获取项目限报配置 var projectLimit = projectLimits.FirstOrDefault(pl => pl.ProjectId == eventProject.Id); - if (projectLimit == null) continue; + // 限报数量 <= 0 表示不限制,跳过验证 + if (projectLimit == null || projectLimit.LimitCount <= 0) continue; if (isTeamProject) { @@ -2026,19 +2027,36 @@ public class UnifiedRegistrationService : ITransient var project = projects.FirstOrDefault(p => p.Id == eventProject.ProjectId); if (project == null) continue; - // 判断是否为团队项目 - var isTeamProject = project.IsTeamProject(); - - // ==================== 项目组别条件判断逻辑 ==================== - // 当且仅当某个项目组别中已选择至少一名人员时,才对该项目组别执行后续条件判断流程 - // 个人项目不进行完成人数限制,仅适用项目报名限制规则 - if (!isTeamProject) + // ==================== 项目完成人数验证 ==================== + // 只要项目配置了完成人数(单一值或范围值),就进行验证 + // 不再依赖 isTeamProject 判断,确保所有类型的项目都能正确验证 + bool hasValidCompletionConfig = false; + int completionMin = 0; + int completionMax = 0; + + if (project.CompletionCountType == 0) { - continue; + // 单一值模式 + if (project.CompletionCount > 0) + { + hasValidCompletionConfig = true; + completionMin = project.CompletionCount; + completionMax = project.CompletionCount; + } } - - // ==================== 团队项目完成人数验证 ==================== - if (project.CompletionCount <= 0) + else + { + // 范围值模式 + if (project.CompletionCountMin.HasValue && project.CompletionCountMax.HasValue && + project.CompletionCountMin.Value > 0 && project.CompletionCountMax.Value > 0) + { + hasValidCompletionConfig = true; + completionMin = project.CompletionCountMin.Value; + completionMax = project.CompletionCountMax.Value; + } + } + + if (!hasValidCompletionConfig) { continue; } @@ -2047,20 +2065,36 @@ public class UnifiedRegistrationService : ITransient if (teams.Count > 0) { // ========== 多团队模式 ========== - // 对每个团队单独验证人数是否等于 CompletionCount + // 对每个团队单独验证人数是否在范围内(或等于单一值) foreach (var team in teams) { var teamMemberCount = team.Persons?.Count ?? 0; - if (teamMemberCount != project.CompletionCount) + if (teamMemberCount < completionMin || teamMemberCount > completionMax) { string errorMessage; - if (teamMemberCount < project.CompletionCount) + if (completionMin == completionMax) { - errorMessage = $"{project.Name}{GetTeamNumber(team.TeamIndex)}参赛人数错误(少{project.CompletionCount - teamMemberCount}人)"; + // 单一值模式 + if (teamMemberCount < completionMin) + { + errorMessage = $"{project.Name}{GetTeamNumber(team.TeamIndex)}参赛人数错误(少{completionMin - teamMemberCount}人)"; + } + else + { + errorMessage = $"{project.Name}{GetTeamNumber(team.TeamIndex)}参赛人数错误(多{teamMemberCount - completionMax}人)"; + } } else { - errorMessage = $"{project.Name}{GetTeamNumber(team.TeamIndex)}参赛人数错误(多{teamMemberCount - project.CompletionCount}人)"; + // 范围值模式 + if (teamMemberCount < completionMin) + { + errorMessage = $"{project.Name}{GetTeamNumber(team.TeamIndex)}参赛人数错误(最少{completionMin}人,当前{teamMemberCount}人)"; + } + else + { + errorMessage = $"{project.Name}{GetTeamNumber(team.TeamIndex)}参赛人数错误(最多{completionMax}人,当前{teamMemberCount}人)"; + } } result.HasLimit = true; @@ -2082,16 +2116,32 @@ public class UnifiedRegistrationService : ITransient .Distinct() .Count(); - if (totalAssignedMembers != project.CompletionCount) + if (totalAssignedMembers < completionMin || totalAssignedMembers > completionMax) { string errorMessage; - if (totalAssignedMembers < project.CompletionCount) + if (completionMin == completionMax) { - errorMessage = $"{project.Name}参赛人数错误(少{project.CompletionCount - totalAssignedMembers}人)"; + // 单一值模式 + if (totalAssignedMembers < completionMin) + { + errorMessage = $"{project.Name}参赛人数错误(少{completionMin - totalAssignedMembers}人)"; + } + else + { + errorMessage = $"{project.Name}参赛人数错误(多{totalAssignedMembers - completionMax}人)"; + } } else { - errorMessage = $"{project.Name}参赛人数错误(多{totalAssignedMembers - project.CompletionCount}人)"; + // 范围值模式 + if (totalAssignedMembers < completionMin) + { + errorMessage = $"{project.Name}参赛人数错误(最少{completionMin}人,当前{totalAssignedMembers}人)"; + } + else + { + errorMessage = $"{project.Name}参赛人数错误(最多{completionMax}人,当前{totalAssignedMembers}人)"; + } } result.HasLimit = true; diff --git a/YD_Event.Application/Event/UserEventRegistrationService.cs b/YD_Event.Application/Event/UserEventRegistrationService.cs index 45b2192..3233362 100644 --- a/YD_Event.Application/Event/UserEventRegistrationService.cs +++ b/YD_Event.Application/Event/UserEventRegistrationService.cs @@ -330,12 +330,32 @@ public class UserEventRegistrationService : IDynamicApiController, ITransient { var p = baseProjects.FirstOrDefault(b => b.Id == ep.ProjectId); + // 生成完成人数显示文本 + string completionCountDisplay = ""; + if (p != null) + { + if (p.CompletionCountType == 1) + { + var min = p.CompletionCountMin ?? 0; + var max = p.CompletionCountMax ?? 0; + completionCountDisplay = $"{min}-{max}人"; + } + else + { + completionCountDisplay = $"{p.CompletionCount}人"; + } + } + var dto = new UserEventProjectListOutput { Id = ep.Id, Name = p?.Name ?? "", Fee = ep.Price, - CompletionCount = p?.CompletionCount ?? 0 + CompletionCount = p?.CompletionCount ?? 0, + CompletionCountType = p?.CompletionCountType ?? 0, + CompletionCountMin = p?.CompletionCountMin, + CompletionCountMax = p?.CompletionCountMax, + CompletionCountDisplay = completionCountDisplay }; if (p != null) @@ -399,13 +419,33 @@ public class UserEventRegistrationService : IDynamicApiController, ITransient { var p = baseProjects.FirstOrDefault(b => b.Id == ep.ProjectId); + // 生成完成人数显示文本 + string completionCountDisplay = ""; + if (p != null) + { + if (p.CompletionCountType == 1) + { + var min = p.CompletionCountMin ?? 0; + var max = p.CompletionCountMax ?? 0; + completionCountDisplay = $"{min}-{max}人"; + } + else + { + completionCountDisplay = $"{p.CompletionCount}人"; + } + } + var dto = new UserEventProjectListOutput { Id = ep.Id, Name = p?.Name ?? "", Fee = ep.Price, TeamSize = 1, - CompletionCount = p?.CompletionCount ?? 0 + CompletionCount = p?.CompletionCount ?? 0, + CompletionCountType = p?.CompletionCountType ?? 0, + CompletionCountMin = p?.CompletionCountMin, + CompletionCountMax = p?.CompletionCountMax, + CompletionCountDisplay = completionCountDisplay }; if (p != null) @@ -1350,10 +1390,37 @@ public class UserEventRegistrationService : IDynamicApiController, ITransient // 检查是多团队模式还是单团队模式 var hasMultipleTeams = groupMemberAssignment.Teams != null && groupMemberAssignment.Teams.Count > 0; + // ========== 获取完成人数配置 ========== + int completionMin = 0; + int completionMax = 0; + bool hasValidCompletionConfig = false; + + if (project.CompletionCountType == 0) + { + // 单一值模式 + if (project.CompletionCount > 0) + { + hasValidCompletionConfig = true; + completionMin = project.CompletionCount; + completionMax = project.CompletionCount; + } + } + else + { + // 范围值模式 + if (project.CompletionCountMin.HasValue && project.CompletionCountMax.HasValue && + project.CompletionCountMin.Value > 0 && project.CompletionCountMax.Value > 0) + { + hasValidCompletionConfig = true; + completionMin = project.CompletionCountMin.Value; + completionMax = project.CompletionCountMax.Value; + } + } + if (hasMultipleTeams && isTeamProject) { // ========== 多团队模式验证 ========== - // 验证每个团队的人数是否等于 CompletionCount + // 验证每个团队的人数是否在范围内(或等于单一值) foreach (var team in groupMemberAssignment.Teams) { var teamMemberCount = team.MemberIds?.Distinct().Count() ?? 0; @@ -1361,17 +1428,33 @@ public class UserEventRegistrationService : IDynamicApiController, ITransient // 如果该团队没有选择任何人员,跳过验证 if (teamMemberCount == 0) continue; - // 验证该团队的人数是否等于 CompletionCount - if (project.CompletionCount > 0 && teamMemberCount != project.CompletionCount) + // 验证该团队的人数是否在有效范围内 + if (hasValidCompletionConfig && (teamMemberCount < completionMin || teamMemberCount > completionMax)) { string errorMessage; - if (teamMemberCount < project.CompletionCount) + if (completionMin == completionMax) { - errorMessage = $"团队{team.TeamIndex}参赛人数错误(少{project.CompletionCount - teamMemberCount}人)"; + // 单一值模式 + if (teamMemberCount < completionMin) + { + errorMessage = $"团队{team.TeamIndex}参赛人数错误(少{completionMin - teamMemberCount}人)"; + } + else + { + errorMessage = $"团队{team.TeamIndex}参赛人数错误(多{teamMemberCount - completionMax}人)"; + } } else { - errorMessage = $"团队{team.TeamIndex}参赛人数错误(多{teamMemberCount - project.CompletionCount}人)"; + // 范围值模式 + if (teamMemberCount < completionMin) + { + errorMessage = $"团队{team.TeamIndex}参赛人数错误(最少{completionMin}人,当前{teamMemberCount}人)"; + } + else + { + errorMessage = $"团队{team.TeamIndex}参赛人数错误(最多{completionMax}人,当前{teamMemberCount}人)"; + } } result.HasError = true; @@ -1379,7 +1462,7 @@ public class UserEventRegistrationService : IDynamicApiController, ITransient { ProjectId = eventProject.Id, ProjectName = project.Name ?? "未知项目", - ErrorType = teamMemberCount < project.CompletionCount ? "Insufficient" : "Excessive", + ErrorType = teamMemberCount < completionMin ? "Insufficient" : "Excessive", ErrorMessage = errorMessage }); } @@ -1394,17 +1477,33 @@ public class UserEventRegistrationService : IDynamicApiController, ITransient // 如果该组别没有选择任何人员,跳过验证 if (assignedCount == 0) continue; - // 只对团队项目进行完成人数验证 - if (isTeamProject && project.CompletionCount > 0 && assignedCount != project.CompletionCount) + // 验证人数是否在有效范围内 + if (isTeamProject && hasValidCompletionConfig && (assignedCount < completionMin || assignedCount > completionMax)) { string errorMessage; - if (assignedCount < project.CompletionCount) + if (completionMin == completionMax) { - errorMessage = $"{project.Name}参赛人数错误(少{project.CompletionCount - assignedCount}人)"; + // 单一值模式 + if (assignedCount < completionMin) + { + errorMessage = $"{project.Name}参赛人数错误(少{completionMin - assignedCount}人)"; + } + else + { + errorMessage = $"{project.Name}参赛人数错误(多{assignedCount - completionMax}人)"; + } } else { - errorMessage = $"{project.Name}参赛人数错误(多{assignedCount - project.CompletionCount}人)"; + // 范围值模式 + if (assignedCount < completionMin) + { + errorMessage = $"{project.Name}参赛人数错误(最少{completionMin}人,当前{assignedCount}人)"; + } + else + { + errorMessage = $"{project.Name}参赛人数错误(最多{completionMax}人,当前{assignedCount}人)"; + } } result.HasError = true; @@ -1412,7 +1511,7 @@ public class UserEventRegistrationService : IDynamicApiController, ITransient { ProjectId = eventProject.Id, ProjectName = project.Name ?? "未知项目", - ErrorType = assignedCount < project.CompletionCount ? "Insufficient" : "Excessive", + ErrorType = assignedCount < completionMin ? "Insufficient" : "Excessive", ErrorMessage = errorMessage }); } diff --git a/YD_Event.Application/Order/OrderService.cs b/YD_Event.Application/Order/OrderService.cs index 4b0271b..02fc50c 100644 --- a/YD_Event.Application/Order/OrderService.cs +++ b/YD_Event.Application/Order/OrderService.cs @@ -194,10 +194,19 @@ public class OrderService : BaseService, ITransien .WhereIF(input.EndTime.HasValue, (o, e, m, r, ro) => o.PaymentTime <= input.EndTime) .OrderByDescending((o, e, m, r, ro) => o.CreatedTime); - // 权限判断:如果是单位认证用户,只能查看自己单位认证的订单 - if (certification != null && !_authManager.IsSuperAdmin) + // 权限判断:非超级管理员必须过滤订单 + if (!_authManager.IsSuperAdmin) { - query = query.Where((o, e, m, r, ro) => o.MerchantCertificationId == certification.Id); + if (certification != null) + { + // 有单位认证的用户,按单位认证ID过滤(只能看自己单位的订单) + query = query.Where((o, e, m, r, ro) => o.MerchantCertificationId == certification.Id); + } + else + { + // 无单位认证的用户(包括新注册用户),只能查看自己创建的订单 + query = query.Where((o, e, m, r, ro) => o.CreatedUserId == userId); + } } var result = await query.Select((o, e, m, r, ro) => new OrderListOutput @@ -593,10 +602,19 @@ public class OrderService : BaseService, ITransien .WhereIF(input.EndTime.HasValue, (o, e, m, r, ro) => o.CreatedTime <= input.EndTime) .OrderByDescending((o, e, m, r, ro) => o.CreatedTime); - // 权限判断:如果是单位认证用户,只能查看自己单位认证的订单 - if (certification != null && !_authManager.IsSuperAdmin) + // 权限判断:非超级管理员必须过滤订单 + if (!_authManager.IsSuperAdmin) { - query = query.Where((o, e, m, r, ro) => o.MerchantCertificationId == certification.Id); + if (certification != null) + { + // 有单位认证的用户,按单位认证ID过滤(只能看自己单位的订单) + query = query.Where((o, e, m, r, ro) => o.MerchantCertificationId == certification.Id); + } + else + { + // 无单位认证的用户(包括新注册用户),只能查看自己创建的订单 + query = query.Where((o, e, m, r, ro) => o.CreatedUserId == userId); + } } var list = await query.Select((o, e, m, r, ro) => new OrderListOutput @@ -846,10 +864,19 @@ public class OrderService : BaseService, ITransien .WhereIF(input.StartTime.HasValue, (o, e, m, r, ro) => o.CreatedTime >= input.StartTime) .WhereIF(input.EndTime.HasValue, (o, e, m, r, ro) => o.CreatedTime <= input.EndTime); - // 权限判断:如果是单位认证用户,只能查看自己单位认证的订单 - if (certification != null && !_authManager.IsSuperAdmin) + // 权限判断:非超级管理员必须过滤订单 + if (!_authManager.IsSuperAdmin) { - query = query.Where((o, e, m, r, ro) => o.MerchantCertificationId == certification.Id); + if (certification != null) + { + // 有单位认证的用户,按单位认证ID过滤(只能看自己单位的订单) + query = query.Where((o, e, m, r, ro) => o.MerchantCertificationId == certification.Id); + } + else + { + // 无单位认证的用户(包括新注册用户),只能查看自己创建的订单 + query = query.Where((o, e, m, r, ro) => o.CreatedUserId == userId); + } } var list = await query.Select((o, e, m, r, ro) => new OrderListOutput diff --git a/YD_Event.Application/Project/Dtos/ProjectDtos.cs b/YD_Event.Application/Project/Dtos/ProjectDtos.cs index 7667aee..474f854 100644 --- a/YD_Event.Application/Project/Dtos/ProjectDtos.cs +++ b/YD_Event.Application/Project/Dtos/ProjectDtos.cs @@ -36,9 +36,24 @@ public class AddProjectInput public long ProjectType { get; set; } /// - /// 完成人数 + /// 完成人数模式(0=单一值, 1=范围值) /// - public int CompletionCount { get; set; } + public int CompletionCountType { get; set; } = 0; + + /// + /// 完成人数(单一值模式时必填) + /// + public int? CompletionCount { get; set; } + + /// + /// 完成人数最小值(范围值模式时必填) + /// + public int? CompletionCountMin { get; set; } + + /// + /// 完成人数最大值(范围值模式时必填) + /// + public int? CompletionCountMax { get; set; } /// /// 费用(元) @@ -130,9 +145,29 @@ public class ProjectDto public string ProjectTypeName { get; set; } /// - /// 完成人数 + /// 完成人数模式(0=单一值, 1=范围值) /// - public int CompletionCount { get; set; } + public int CompletionCountType { get; set; } + + /// + /// 完成人数(单一值模式时有效) + /// + public int? CompletionCount { get; set; } + + /// + /// 完成人数最小值(范围值模式时有效) + /// + public int? CompletionCountMin { get; set; } + + /// + /// 完成人数最大值(范围值模式时有效) + /// + public int? CompletionCountMax { get; set; } + + /// + /// 完成人数显示文本(用于前端显示,如 "5人" 或 "3-5人") + /// + public string CompletionCountDisplay { get; set; } /// /// 费用(元) diff --git a/YD_Event.Application/Project/ProjectService.cs b/YD_Event.Application/Project/ProjectService.cs index 61a0f9c..fa1243c 100644 --- a/YD_Event.Application/Project/ProjectService.cs +++ b/YD_Event.Application/Project/ProjectService.cs @@ -52,7 +52,10 @@ public class ProjectService : BaseService, ITran Id = p.Id, Name = p.Name, ProjectType = (long)p.ProjectType, + CompletionCountType = p.CompletionCountType, CompletionCount = p.CompletionCount, + CompletionCountMin = p.CompletionCountMin, + CompletionCountMax = p.CompletionCountMax, Fee = p.Fee, DurationMinutes = p.DurationMinutes, DurationSeconds = p.DurationSeconds, @@ -70,6 +73,17 @@ public class ProjectService : BaseService, ITran foreach (var item in list.Rows) { item.ProjectTypeName = ((ProjectTypeEnum)item.ProjectType).Description(); + // 生成完成人数显示文本 + if (item.CompletionCountType == 0) + { + item.CompletionCountDisplay = item.CompletionCount.HasValue ? $"{item.CompletionCount.Value}人" : "0人"; + } + else + { + var min = item.CompletionCountMin ?? 0; + var max = item.CompletionCountMax ?? 0; + item.CompletionCountDisplay = $"{min}-{max}人"; + } } return list; @@ -82,11 +96,37 @@ public class ProjectService : BaseService, ITran [UnitOfWork] public async Task Add(AddProjectInput input) { + // 验证完成人数字段 + if (input.CompletionCountType == 0) + { + // 单一值模式 + if (!input.CompletionCount.HasValue || input.CompletionCount.Value < 0) + { + throw Oops.Bah("请填写有效的完成人数"); + } + } + else + { + // 范围值模式 + if (!input.CompletionCountMin.HasValue || !input.CompletionCountMax.HasValue) + { + throw Oops.Bah("请填写完成人数最小值和最大值"); + } + if (input.CompletionCountMin.Value < 0 || input.CompletionCountMax.Value < 0) + { + throw Oops.Bah("完成人数不能为负数"); + } + if (input.CompletionCountMin.Value > input.CompletionCountMax.Value) + { + throw Oops.Bah("完成人数最小值不能大于最大值"); + } + } + var entity = input.Adapt(); entity.Id = _idGenerator.NewLong(); entity.CreatedTime = DateTime.Now; entity.Status = Core.Enum.AvailabilityStatus.Enable; - + await _repository.InsertAsync(entity); if (input.Groups != null && input.Groups.Any()) @@ -112,6 +152,32 @@ public class ProjectService : BaseService, ITran var entity = await _repository.GetByIdAsync(input.Id); if (entity == null) throw new InvalidOperationException("项目不存在"); + // 验证完成人数字段 + if (input.CompletionCountType == 0) + { + // 单一值模式 + if (!input.CompletionCount.HasValue || input.CompletionCount.Value < 0) + { + throw Oops.Bah("请填写有效的完成人数"); + } + } + else + { + // 范围值模式 + if (!input.CompletionCountMin.HasValue || !input.CompletionCountMax.HasValue) + { + throw Oops.Bah("请填写完成人数最小值和最大值"); + } + if (input.CompletionCountMin.Value < 0 || input.CompletionCountMax.Value < 0) + { + throw Oops.Bah("完成人数不能为负数"); + } + if (input.CompletionCountMin.Value > input.CompletionCountMax.Value) + { + throw Oops.Bah("完成人数最小值不能大于最大值"); + } + } + input.Adapt(entity); entity.UpdatedTime = DateTime.Now; await _repository.UpdateAsync(entity); @@ -185,7 +251,19 @@ public class ProjectService : BaseService, ITran var dto = p.Adapt(); dto.ProjectType = (long)p.ProjectType; dto.ProjectTypeName = p.ProjectType.Description(); - + + // 生成完成人数显示文本 + if (dto.CompletionCountType == 0) + { + dto.CompletionCountDisplay = dto.CompletionCount.HasValue ? $"{dto.CompletionCount.Value}人" : "0人"; + } + else + { + var min = dto.CompletionCountMin ?? 0; + var max = dto.CompletionCountMax ?? 0; + dto.CompletionCountDisplay = $"{min}-{max}人"; + } + var groups = await _groupRepository.GetListAsync(x => x.ProjectId == id); dto.Groups = groups.Adapt>(); diff --git a/YD_Event.Application/YD_Event.Application.xml b/YD_Event.Application/YD_Event.Application.xml index 9a399b7..c8cefa4 100644 --- a/YD_Event.Application/YD_Event.Application.xml +++ b/YD_Event.Application/YD_Event.Application.xml @@ -2204,6 +2204,31 @@ 项目限报数量 + + + 完成人数模式(0=单一值,1=范围值) + + + + + 完成人数(单一值模式时有效) + + + + + 完成人数最小值(范围值模式时有效) + + + + + 完成人数最大值(范围值模式时有效) + + + + + 完成人数显示文本(如"5人"或"3-7人") + + 组别列表 @@ -4795,6 +4820,31 @@ 比赛时长(秒) (显示用) + + + 完成人数模式 (显示用) 0=单一值, 1=范围值 + + + + + 完成人数 (显示用) 单一值模式时有效 + + + + + 完成人数最小值 (显示用) 范围值模式时有效 + + + + + 完成人数最大值 (显示用) 范围值模式时有效 + + + + + 完成人数显示文本 (显示用) 如:5人 或 3-5人 + + 项目费用(Step 4) @@ -7688,6 +7738,26 @@ 完成人数 + + + 完成人数模式 (0=单一值, 1=范围值) + + + + + 完成人数最小值(范围值模式) + + + + + 完成人数最大值(范围值模式) + + + + + 完成人数显示文本(如"5人"或"3-7人") + + 项目类型 @@ -11979,9 +12049,24 @@ 项目类型 + + + 完成人数模式(0=单一值, 1=范围值) + + - 完成人数 + 完成人数(单一值模式时必填) + + + + + 完成人数最小值(范围值模式时必填) + + + + + 完成人数最大值(范围值模式时必填) @@ -12064,9 +12149,29 @@ 项目类型名称 + + + 完成人数模式(0=单一值, 1=范围值) + + - 完成人数 + 完成人数(单一值模式时有效) + + + + + 完成人数最小值(范围值模式时有效) + + + + + 完成人数最大值(范围值模式时有效) + + + + + 完成人数显示文本(用于前端显示,如 "5人" 或 "3-5人") diff --git a/YD_Event.Core/Entities/Project.cs b/YD_Event.Core/Entities/Project.cs index 64e3d3a..5e6ed73 100644 --- a/YD_Event.Core/Entities/Project.cs +++ b/YD_Event.Core/Entities/Project.cs @@ -22,10 +22,25 @@ public class Project : Entity, ISoftDelete, ICreatedUserId, ICreatedTime, public ProjectTypeEnum ProjectType { get; set; } /// - /// 完成人数 + /// 完成人数模式(0=单一值, 1=范围值) + /// + public int CompletionCountType { get; set; } = 0; + + /// + /// 完成人数(单一值模式时有效) /// public int CompletionCount { get; set; } + /// + /// 完成人数最小值(范围值模式时有效) + /// + public int? CompletionCountMin { get; set; } + + /// + /// 完成人数最大值(范围值模式时有效) + /// + public int? CompletionCountMax { get; set; } + /// /// 费用(元) /// diff --git a/YD_Event.Core/YD_Event.Core.xml b/YD_Event.Core/YD_Event.Core.xml index 906f7bf..2b1cc8e 100644 --- a/YD_Event.Core/YD_Event.Core.xml +++ b/YD_Event.Core/YD_Event.Core.xml @@ -3043,9 +3043,24 @@ 项目类型(枚举) + + + 完成人数模式(0=单一值, 1=范围值) + + - 完成人数 + 完成人数(单一值模式时有效) + + + + + 完成人数最小值(范围值模式时有效) + + + + + 完成人数最大值(范围值模式时有效)