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 (如果已报名) + + + 上级项目类型名称 + + 用户端赛事限制输出