From b370d7f4aba6bf6b211a63a667fba926efaa68cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=A9=AC=E6=A2=93=E5=BD=AD?= Date: Mon, 19 Oct 2026 09:03:00 +0800 Subject: [PATCH] =?UTF-8?q?=E9=A1=B9=E7=9B=AE=EF=BC=8C=E4=B8=AA=E4=BA=BA?= =?UTF-8?q?=E9=80=9F=E5=BA=A6=E5=92=8C=E5=9B=A2=E9=98=9F=E9=80=9F=E5=BA=A6?= =?UTF-8?q?=EF=BC=8C=E8=AE=A1=E5=88=86=E8=A7=84=E5=88=99=E9=9D=9E=E5=BF=85?= =?UTF-8?q?=E5=A1=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- YD_Event.Application/Project/Dtos/ProjectDtos.cs | 3 +-- YD_Event.Application/Project/ProjectService.cs | 16 ++++++++++++---- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/YD_Event.Application/Project/Dtos/ProjectDtos.cs b/YD_Event.Application/Project/Dtos/ProjectDtos.cs index d33fde0..0c5814f 100644 --- a/YD_Event.Application/Project/Dtos/ProjectDtos.cs +++ b/YD_Event.Application/Project/Dtos/ProjectDtos.cs @@ -23,8 +23,7 @@ public class ProjectQueryInput : Pagination public class AddProjectInput { - /// 计分规则ID。 - [Required(ErrorMessage = "请选择计分规则")] + /// 计分规则ID(速度项目可为空,花样项目必填)。 public long? ScoreRuleId { get; set; } /// /// 项目名称 diff --git a/YD_Event.Application/Project/ProjectService.cs b/YD_Event.Application/Project/ProjectService.cs index 76f298d..3134095 100644 --- a/YD_Event.Application/Project/ProjectService.cs +++ b/YD_Event.Application/Project/ProjectService.cs @@ -104,7 +104,7 @@ public class ProjectService : BaseService, ITran [UnitOfWork] public async Task Add(AddProjectInput input) { - await ValidateScoreRule(input.ScoreRuleId); + await ValidateScoreRule(input.ScoreRuleId, (ProjectTypeEnum)input.ProjectType); // 验证完成人数字段 if (input.CompletionCountType == 0) { @@ -158,7 +158,7 @@ public class ProjectService : BaseService, ITran [UnitOfWork] public async Task Update(UpdateProjectInput input) { - await ValidateScoreRule(input.ScoreRuleId); + await ValidateScoreRule(input.ScoreRuleId, (ProjectTypeEnum)input.ProjectType); var entity = await _repository.GetByIdAsync(input.Id); if (entity == null) throw new InvalidOperationException("项目不存在"); @@ -281,9 +281,17 @@ public class ProjectService : BaseService, ITran return dto; } - private async Task ValidateScoreRule(long? scoreRuleId) + private async Task ValidateScoreRule(long? scoreRuleId, ProjectTypeEnum projectType) { - if (!scoreRuleId.HasValue || !await _scoreRuleRepository.IsAnyAsync(x => x.Id == scoreRuleId.Value && x.Status == AvailabilityStatus.Enable)) + var isSpeedProject = projectType is ProjectTypeEnum.PersonalSpeed or ProjectTypeEnum.TeamSpeed; + if (!scoreRuleId.HasValue) + { + if (isSpeedProject) return; + + throw Oops.Bah("请选择有效的计分规则"); + } + + if (!await _scoreRuleRepository.IsAnyAsync(x => x.Id == scoreRuleId.Value && x.Status == AvailabilityStatus.Enable)) throw Oops.Bah("请选择有效的计分规则"); }