From 95d991fe51bfaaa332417fffc0ea680525d40c90 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=A9=AC=E6=A2=93=E5=BD=AD?= Date: Tue, 31 Mar 2026 22:18:53 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B5=9B=E4=BA=8B=E6=8A=A5=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Event/Dtos/UserCompetitionDtos.cs | 5 +++ .../Event/UserEventRegistrationService.cs | 35 +++++++++++++++++-- YD_Event.Application/YD_Event.Application.xml | 5 +++ 3 files changed, 43 insertions(+), 2 deletions(-) diff --git a/YD_Event.Application/Event/Dtos/UserCompetitionDtos.cs b/YD_Event.Application/Event/Dtos/UserCompetitionDtos.cs index 9354807..732165a 100644 --- a/YD_Event.Application/Event/Dtos/UserCompetitionDtos.cs +++ b/YD_Event.Application/Event/Dtos/UserCompetitionDtos.cs @@ -212,6 +212,11 @@ public class UserEventDetailOutput /// 报名ID (如果已报名) /// public long? RegistrationId { get; set; } + + /// + /// 上级项目类型名称 + /// + public string? ParentProjectTypeName { get; set; } } /// diff --git a/YD_Event.Application/Event/UserEventRegistrationService.cs b/YD_Event.Application/Event/UserEventRegistrationService.cs index 003d42e..ffdf119 100644 --- a/YD_Event.Application/Event/UserEventRegistrationService.cs +++ b/YD_Event.Application/Event/UserEventRegistrationService.cs @@ -34,6 +34,7 @@ public class UserEventRegistrationService : IDynamicApiController, ITransient private readonly ISqlSugarRepository _unitRepository; private readonly ISqlSugarRepository _eventProjectRepository; private readonly ISqlSugarRepository _projectRepository; + private readonly ISqlSugarRepository _projectTypeRepository; private readonly ISqlSugarRepository _registrationRepository; private readonly ISqlSugarRepository _registrationItemRepository; private readonly ISqlSugarRepository _registrationPersonRepository; @@ -57,6 +58,7 @@ public class UserEventRegistrationService : IDynamicApiController, ITransient ISqlSugarRepository unitRepository, ISqlSugarRepository eventProjectRepository, ISqlSugarRepository projectRepository, + ISqlSugarRepository projectTypeRepository, ISqlSugarRepository registrationRepository, ISqlSugarRepository registrationItemRepository, ISqlSugarRepository registrationPersonRepository, @@ -79,6 +81,7 @@ public class UserEventRegistrationService : IDynamicApiController, ITransient _unitRepository = unitRepository; _eventProjectRepository = eventProjectRepository; _projectRepository = projectRepository; + _projectTypeRepository = projectTypeRepository; _registrationRepository = registrationRepository; _registrationItemRepository = registrationItemRepository; _registrationPersonRepository = registrationPersonRepository; @@ -190,7 +193,32 @@ public class UserEventRegistrationService : IDynamicApiController, ITransient var eventProjects = await _eventProjectRepository.GetListAsync(x => x.EventId == id); var projectIds = eventProjects.Select(x => x.ProjectId).Distinct().ToList(); - var baseProjects = await _projectRepository.GetListAsync(x => projectIds.Contains(x.Id) && x.Status == AvailabilityStatus.Enable); + var baseProjects = await _projectRepository.AsQueryable() + .LeftJoin((p, t) => p.ProjectTypeId == t.Id) + .Where(p => projectIds.Contains(p.Id) && p.Status == AvailabilityStatus.Enable) + .Select((p, t) => new { p.Id, ProjectTypeId = t.Id }) + .ToListAsync(); + + // 获取所有项目类型 + var allProjectTypes = await _projectTypeRepository.AsQueryable() + .Where(t => !t.DeleteMark && t.Status == AvailabilityStatus.Enable) + .ToListAsync(); + + // 获取上级项目类型名称(如果有项目,取第一个项目的上级类型名称) + string? parentProjectTypeName = null; + if (baseProjects.Any()) + { + var firstProject = baseProjects.First(); + var currentProjectType = allProjectTypes.FirstOrDefault(t => t.Id == firstProject.ProjectTypeId); + if (currentProjectType != null && currentProjectType.ParentId > 0) + { + var parentProjectType = allProjectTypes.FirstOrDefault(t => t.Id == currentProjectType.ParentId); + parentProjectTypeName = parentProjectType?.Name; + } + } + + // 获取完整的基础项目信息 + var fullBaseProjects = await _projectRepository.GetListAsync(x => projectIds.Contains(x.Id) && x.Status == AvailabilityStatus.Enable); var completionStats = await _projectService.GetProjectStatisticsBatchAsync( projectIds, @@ -198,7 +226,7 @@ public class UserEventRegistrationService : IDynamicApiController, ITransient output.Projects = eventProjects.Select(ep => { - var p = baseProjects.FirstOrDefault(b => b.Id == ep.ProjectId); + var p = fullBaseProjects.FirstOrDefault(b => b.Id == ep.ProjectId); var completionCount = 0; if (p != null && completionStats.TryGetValue(p.Id, out var count)) { @@ -212,6 +240,9 @@ public class UserEventRegistrationService : IDynamicApiController, ITransient CompletionCount = completionCount }; }).Where(x => !string.IsNullOrEmpty(x.Name)).ToList(); + + // 添加上级项目类型名称 + output.ParentProjectTypeName = parentProjectTypeName; var userId = _authManager.UserId; var registration = await _registrationRepository.GetFirstAsync(x => x.EventId == id && x.CreatedUserId == userId && !x.DeleteMark); diff --git a/YD_Event.Application/YD_Event.Application.xml b/YD_Event.Application/YD_Event.Application.xml index 310114b..e88f4fe 100644 --- a/YD_Event.Application/YD_Event.Application.xml +++ b/YD_Event.Application/YD_Event.Application.xml @@ -4385,6 +4385,11 @@ 报名ID (如果已报名) + + + 上级项目类型名称 + + 用户端赛事限制输出