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("请选择有效的计分规则"); }