From d9de064fc4d619c606a43df6fd8947ce048cef4d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=A9=AC=E6=A2=93=E5=BD=AD?= Date: Tue, 28 Apr 2026 00:02:01 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B5=9B=E4=BA=8B=E7=BC=96=E6=8E=92=EF=BC=9A?= =?UTF-8?q?=E5=AF=BC=E5=87=BA=E7=BC=96=E6=8E=92=EF=BC=8C=E6=8A=A5=E5=90=8D?= =?UTF-8?q?ID=E4=B8=8D=E9=87=8D=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Event/Dtos/ArrangementDtos.cs | 5 + .../Event/Dtos/RegistrationDtos.cs | 2 +- .../Event/EventArrangementService.cs | 6 +- .../Event/EventRegistrationService.cs | 99 ++++++++++++++----- .../Event/EventScoreService.cs | 31 +++++- YD_Event.Application/YD_Event.Application.xml | 9 +- 6 files changed, 119 insertions(+), 33 deletions(-) diff --git a/YD_Event.Application/Event/Dtos/ArrangementDtos.cs b/YD_Event.Application/Event/Dtos/ArrangementDtos.cs index 73d37d0..ebb75d8 100644 --- a/YD_Event.Application/Event/Dtos/ArrangementDtos.cs +++ b/YD_Event.Application/Event/Dtos/ArrangementDtos.cs @@ -49,6 +49,11 @@ public class ArrangementProjectListOutput /// 总时长(分钟,向上取整) /// public int TotalDurationMinutes { get; set; } + + /// + /// 团队总数(仅团队项目有效) + /// + public int TotalTeams { get; set; } } /// diff --git a/YD_Event.Application/Event/Dtos/RegistrationDtos.cs b/YD_Event.Application/Event/Dtos/RegistrationDtos.cs index 355a001..7fe04e0 100644 --- a/YD_Event.Application/Event/Dtos/RegistrationDtos.cs +++ b/YD_Event.Application/Event/Dtos/RegistrationDtos.cs @@ -202,7 +202,7 @@ public class RegistrationListOutput public class RegistrationItemDetailDto { /// - /// 报名项目ID(EventRegistrationItem的ID) + /// 报名项目ID(EventRegistrationItem的ID 或 EventRegistrationPerson的ID,根据项目类型决定) /// public long Id { get; set; } diff --git a/YD_Event.Application/Event/EventArrangementService.cs b/YD_Event.Application/Event/EventArrangementService.cs index 031f881..ae24e2b 100644 --- a/YD_Event.Application/Event/EventArrangementService.cs +++ b/YD_Event.Application/Event/EventArrangementService.cs @@ -230,6 +230,7 @@ namespace YD_Event.Application.Event; // 设置总时长秒数和分钟数 dto.TotalDurationSeconds = totalDurationSeconds; dto.TotalDurationMinutes = (int)Math.Ceiling((double)totalDurationSeconds / 60); + dto.TotalTeams = totalTeams; result.Add(dto); } @@ -330,6 +331,7 @@ namespace YD_Event.Application.Event; .OrderBy(p => p.GroupName) .OrderBy(p => p.Id) .Select((p, r, u, m) => new { + Id = p.Id, // 添加 Id 属性 RegistrationItemId = p.RegistrationItemId, p.UserId, p.Name, @@ -401,7 +403,7 @@ namespace YD_Event.Application.Event; result.Add(new ArrangementPreviewOutput { - RegistrationItemId = firstPerson.RegistrationItemId, + RegistrationItemId = firstPerson.RegistrationItemId, // 团队项目保持使用 EventRegistrationItem.Id TimeRange = $"{proj.GetTotalDurationInSeconds()}''", ProjectName = proj.Name, ProjectType = proj.ProjectType.Description(), @@ -432,7 +434,7 @@ namespace YD_Event.Application.Event; result.Add(new ArrangementPreviewOutput { - RegistrationItemId = person.RegistrationItemId, + RegistrationItemId = person.Id, // 个人项目使用 EventRegistrationPerson.Id TimeRange = $"{proj.GetTotalDurationInSeconds()}''", ProjectName = proj.Name, ProjectType = proj.ProjectType.Description(), diff --git a/YD_Event.Application/Event/EventRegistrationService.cs b/YD_Event.Application/Event/EventRegistrationService.cs index 840c28e..aa72afa 100644 --- a/YD_Event.Application/Event/EventRegistrationService.cs +++ b/YD_Event.Application/Event/EventRegistrationService.cs @@ -21,6 +21,8 @@ public class EventRegistrationService : BaseService, ITransie private readonly ISqlSugarRepository _appUserRepository; private readonly ISqlSugarRepository _merchantCertificationRepository; private readonly ISqlSugarRepository _eventInfoRepository; + private readonly ISqlSugarRepository _eventProjectRepository; + private readonly ISqlSugarRepository _projectRepository; private readonly IIdGenerator _idGenerator; private readonly OrderNoGeneratorService _orderNoGeneratorService; private readonly AuthManager _authManager; @@ -35,6 +37,8 @@ public class EventRegistrationService : BaseService, ITransie ISqlSugarRepository appUserRepository, ISqlSugarRepository merchantCertificationRepository, ISqlSugarRepository eventInfoRepository, + ISqlSugarRepository eventProjectRepository, + ISqlSugarRepository projectRepository, IIdGenerator idGenerator, OrderNoGeneratorService orderNoGeneratorService, AuthManager authManager) : base(repository) @@ -48,6 +52,8 @@ public class EventRegistrationService : BaseService, ITransie _appUserRepository = appUserRepository; _merchantCertificationRepository = merchantCertificationRepository; _eventInfoRepository = eventInfoRepository; + _eventProjectRepository = eventProjectRepository; + _projectRepository = projectRepository; _idGenerator = idGenerator; _orderNoGeneratorService = orderNoGeneratorService; _authManager = authManager; @@ -102,6 +108,16 @@ public class EventRegistrationService : BaseService, ITransie .Includes(p => p.User) // 关联查询用户信息 .Where(x => regIds.Contains(x.RegistrationId)) .ToListAsync(); + + // 获取所有赛事项目和项目信息,用于判断项目类型 + var eventProjectIds = items.Select(x => x.ProjectId).Distinct().ToList(); + var eventProjects = await _eventProjectRepository.GetListAsync(x => eventProjectIds.Contains(x.Id)); + var projectIds = eventProjects.Select(x => x.ProjectId).Distinct().ToList(); + var projects = await _projectRepository.GetListAsync(x => projectIds.Contains(x.Id)); + + // 创建映射字典 + var eventProjectToProjectDict = eventProjects.ToDictionary(x => x.Id, x => x.ProjectId); + Dictionary projectDict = projects.ToDictionary(x => x.Id, x => x); // 获取所有报名记录的 CreatedUserId var createdUserIds = result.Rows.Select(x => x.CreatedUserId).Distinct().ToList(); @@ -230,33 +246,70 @@ public class EventRegistrationService : BaseService, ITransie { var myPersons = persons.Where(p => p.RegistrationItemId == item.Id).ToList(); - // 构造参与人信息字符串,统一格式为:姓名/性别/年龄/手机号 - var personInfo = string.Join(";", myPersons.Select(p => + // 判断项目类型 + bool isIndividualProject = false; + if (eventProjectToProjectDict.TryGetValue(item.ProjectId, out var projectId) && + projectDict.TryGetValue(projectId, out var project)) { - // 将性别转换为中文显示 - var genderText = p.Gender switch + isIndividualProject = YD_Event.Core.Extensions.ProjectTypeExtensions.IsIndividualProject(project); + } + + if (isIndividualProject) + { + // 个人项目:为每个运动员创建一个条目,使用 EventRegistrationPerson.Id + foreach (var person in myPersons.Where(p => p.PersonType == PersonType.Athlete)) { - YD_Event.Core.Enum.Gender.Male => "男", - YD_Event.Core.Enum.Gender.Female => "女", - _ => "未知" - }; - - // 获取手机号,优先使用关联用户信息,否则使用自身的 Phone 字段 - var mobile = p.User?.Mobile ?? p.Phone ?? ""; - - // 统一格式:姓名/性别/年龄/手机号 - return $"{p.Name}/{genderText}/{p.Age}/{mobile}"; - })); - if (personInfo.Length > 100) personInfo = personInfo.Substring(0, 97) + "..."; // 截断 + // 构造参与人信息字符串 + var genderText = person.Gender switch + { + YD_Event.Core.Enum.Gender.Male => "男", + YD_Event.Core.Enum.Gender.Female => "女", + _ => "未知" + }; + var mobile = person.User?.Mobile ?? person.Phone ?? ""; + var personInfo = $"{person.Name}/{genderText}/{person.Age}/{mobile}"; - var detail = new RegistrationItemDetailDto + var detail = new RegistrationItemDetailDto + { + Id = person.Id, // 使用 EventRegistrationPerson.Id + ProjectName = item.ProjectName, + GroupName = item.GroupName, + ParticipantInfo = personInfo + }; + dto.Items.Add(detail); + } + } + else { - Id = item.Id, - ProjectName = item.ProjectName, - GroupName = item.GroupName, - ParticipantInfo = personInfo - }; - dto.Items.Add(detail); + // 团队项目:保持原有逻辑,使用 EventRegistrationItem.Id + // 构造参与人信息字符串,统一格式为:姓名/性别/年龄/手机号 + var personInfo = string.Join(";", myPersons.Select(p => + { + // 将性别转换为中文显示 + var genderText = p.Gender switch + { + YD_Event.Core.Enum.Gender.Male => "男", + YD_Event.Core.Enum.Gender.Female => "女", + _ => "未知" + }; + + // 获取手机号,优先使用关联用户信息,否则使用自身的 Phone 字段 + var mobile = p.User?.Mobile ?? p.Phone ?? ""; + + // 统一格式:姓名/性别/年龄/手机号 + return $"{p.Name}/{genderText}/{p.Age}/{mobile}"; + })); + if (personInfo.Length > 100) personInfo = personInfo.Substring(0, 97) + "..."; // 截断 + + var detail = new RegistrationItemDetailDto + { + Id = item.Id, // 使用 EventRegistrationItem.Id + ProjectName = item.ProjectName, + GroupName = item.GroupName, + ParticipantInfo = personInfo + }; + dto.Items.Add(detail); + } } // 设置领队信息和教练信息 - 从团队中获取 diff --git a/YD_Event.Application/Event/EventScoreService.cs b/YD_Event.Application/Event/EventScoreService.cs index e5f95f7..a12a679 100644 --- a/YD_Event.Application/Event/EventScoreService.cs +++ b/YD_Event.Application/Event/EventScoreService.cs @@ -47,6 +47,7 @@ public class EventScoreService : BaseService, ITransient private readonly ISqlSugarRepository _resultRepository; private readonly ISqlSugarRepository _certificateRepository; private readonly ISqlSugarRepository _registrationRepository; + private readonly ISqlSugarRepository _itemRepository; private readonly ISqlSugarRepository _templateRepository; private readonly ISqlSugarRepository _certificateMasterRepository; private readonly ISqlSugarRepository _projectRepository; @@ -66,6 +67,7 @@ public class EventScoreService : BaseService, ITransient ISqlSugarRepository resultRepository, ISqlSugarRepository certificateRepository, ISqlSugarRepository registrationRepository, + ISqlSugarRepository itemRepository, ISqlSugarRepository templateRepository, ISqlSugarRepository certificateMasterRepository, ISqlSugarRepository projectRepository, @@ -84,6 +86,7 @@ public class EventScoreService : BaseService, ITransient _resultRepository = resultRepository; _certificateRepository = certificateRepository; _registrationRepository = registrationRepository; + _itemRepository = itemRepository; _templateRepository = templateRepository; _certificateMasterRepository = certificateMasterRepository; _projectRepository = projectRepository; @@ -275,7 +278,7 @@ public class EventScoreService : BaseService, ITransient /// 教练/领队列表 /// /// - /// 通过运动员报名记录 -> TeamMember团队关联 -> 找到同团队的教练/领队 + /// 通过运动员报名记录 -> TeamMember团队关联 -> 找到同团队的教练/领队 /// [DisplayName("教练领队列表")] public async Task> PageCoachLeader(CoachLeaderQueryInput input) @@ -515,12 +518,21 @@ public class EventScoreService : BaseService, ITransient var allProjects = await _projectRepository.GetListAsync(x => allProjectIds.Contains(x.Id)); var allProjectDict = allProjects.ToDictionary(p => p.Id, p => p); - // 步骤4:使用字典建立人员索引(按RegistrationItemId索引,取第一个人作为代表) - // 注意:团队项目中一个 RegistrationItemId 可能对应多个运动员,但只需要第一个作为代表 + // 步骤4:使用字典建立人员索引 + // 1. 按 EventRegistrationPerson.Id 索引(用于个人项目) + var personByIdDict = allPersonsWithTeam + .ToDictionary(p => p.Id, p => p); + + // 2. 按 RegistrationItemId 索引(用于团队项目) var personByItemIdDict = allPersonsWithTeam .GroupBy(p => p.RegistrationItemId) .ToDictionary(g => g.Key, g => g.First()); + // 同时预加载所有 EventRegistrationItem 信息 + var registrationItemIds = allPersonsWithTeam.Select(p => p.RegistrationItemId).Distinct().ToList(); + var registrationItems = await _itemRepository.GetListAsync(x => registrationItemIds.Contains(x.Id)); + var registrationItemDict = registrationItems.ToDictionary(x => x.Id, x => x); + // 预加载 EventRegistration 信息,用于获取归属单位 ID var registrationIdsList = allPersonsWithTeam.Select(p => p.RegistrationId).Distinct().ToList(); var registrations = await _registrationRepository.GetListAsync(r => registrationIdsList.Contains(r.Id)); @@ -541,8 +553,17 @@ public class EventScoreService : BaseService, ITransient foreach(var row in validationResult.ValidRows) { - // 使用报名ID进行匹配 - if (!personByItemIdDict.TryGetValue(row.RegistrationItemId.Value, out var person)) + // 首先尝试用 ID 查找 EventRegistrationPerson(用于个人项目) + if (personByIdDict.TryGetValue(row.RegistrationItemId.Value, out var person)) + { + // 找到了个人项目的记录,继续处理 + } + // 如果没找到,再尝试用 RegistrationItemId 查找(用于团队项目) + else if (personByItemIdDict.TryGetValue(row.RegistrationItemId.Value, out person)) + { + // 找到了团队项目的记录,继续处理 + } + else { notFoundPersons.Add($"报名ID:{row.RegistrationItemId.Value}"); continue; diff --git a/YD_Event.Application/YD_Event.Application.xml b/YD_Event.Application/YD_Event.Application.xml index e8a720f..a795439 100644 --- a/YD_Event.Application/YD_Event.Application.xml +++ b/YD_Event.Application/YD_Event.Application.xml @@ -4189,6 +4189,11 @@ 总时长(分钟,向上取整) + + + 团队总数(仅团队项目有效) + + 编排组别DTO @@ -5831,7 +5836,7 @@ - 报名项目ID(EventRegistrationItem的ID) + 报名项目ID(EventRegistrationItem的ID 或 EventRegistrationPerson的ID,根据项目类型决定) @@ -8040,7 +8045,7 @@ 教练/领队列表 - 通过运动员报名记录 -> TeamMember团队关联 -> 找到同团队的教练/领队 + 通过运动员报名记录 -> TeamMember团队关联 -> 找到同团队的教练/领队