编排导出按照项目组别排序

This commit is contained in:
马梓彭 2026-06-29 15:37:25 +08:00
parent 64ac037bc1
commit 86d2d349a9

View File

@ -331,8 +331,6 @@ namespace YD_Event.Application.Event;
&& ((r.PaymentMethod == 2 && r.PaymentStatus == 1) || (r.PaymentMethod == 1 && (r.PaymentStatus == 0 || r.PaymentStatus == 1))) && ((r.PaymentMethod == 2 && r.PaymentStatus == 1) || (r.PaymentMethod == 1 && (r.PaymentStatus == 0 || r.PaymentStatus == 1)))
&& !p.DeleteMark && !p.DeleteMark
&& p.PersonType == PersonType.Athlete) && p.PersonType == PersonType.Athlete)
.OrderBy(p => p.GroupName)
.OrderBy(p => p.Id)
.Select((p, r) => new { .Select((p, r) => new {
Id = p.Id, Id = p.Id,
RegistrationItemId = p.RegistrationItemId, RegistrationItemId = p.RegistrationItemId,
@ -379,16 +377,15 @@ namespace YD_Event.Application.Event;
if (!persons.Any()) continue; if (!persons.Any()) continue;
// 计算项目总时长 var projGroups = groups.Where(g => g.ProjectId == proj.Id).OrderBy(g => g.Id).ToList();
int totalParticipants = 0; int totalParticipants = 0;
var projGroups = groups.Where(g => g.ProjectId == proj.Id).ToList(); int totalTeams = 0;
foreach (var group in projGroups) foreach (var group in projGroups)
{ {
var countObj = counts.FirstOrDefault(c => c.ProjectId == eventProj.Id && c.GroupName == group.GroupName); var countObj = counts.FirstOrDefault(c => c.ProjectId == eventProj.Id && c.GroupName == group.GroupName);
totalParticipants += countObj?.Count ?? 0; totalParticipants += countObj?.Count ?? 0;
} }
int totalTeams = 0;
if (proj.IsTeamProject()) if (proj.IsTeamProject())
{ {
totalTeams = teamCounts totalTeams = teamCounts
@ -412,81 +409,81 @@ namespace YD_Event.Application.Event;
string projectTotalDuration = FormatDurationSymbol(projectTotalDurationSeconds); string projectTotalDuration = FormatDurationSymbol(projectTotalDurationSeconds);
// 分组逻辑
int currentRound = 1; int currentRound = 1;
int currentVenue = 1; int currentVenue = 1;
if (proj.IsTeamProject()) foreach (var group in projGroups)
{ {
// 团队项目:按团队分组,同一团队的运动员姓名用逗号分隔 var groupPersons = persons.Where(p => p.GroupName == group.GroupName).ToList();
// 增加 RegistrationItemId 作为分组条件,确保同一条报名记录的多个小组被正确区分 if (!groupPersons.Any()) continue;
var teamsGroup = persons
.GroupBy(p => new { p.GroupName, p.TeamName, p.RegistrationItemId })
.OrderBy(g => g.Key.GroupName)
.ThenBy(g => g.Key.TeamName)
.ThenBy(g => g.Key.RegistrationItemId);
foreach (var teamGroup in teamsGroup) if (proj.IsTeamProject())
{ {
var athleteNames = teamGroup.Select(p => p.Name).Distinct().OrderBy(n => n).ToList(); var teamsGroup = groupPersons
string combinedAthleteNames = string.Join(", ", athleteNames); .GroupBy(p => new { p.TeamName, p.RegistrationItemId })
.OrderBy(g => g.Key.TeamName)
.ThenBy(g => g.Key.RegistrationItemId);
// 获取团队中第一个人的认证信息作为团队单位信息 foreach (var teamGroup in teamsGroup)
var firstPerson = teamGroup.First();
string displayUnitName = GetDisplayUnitName(firstPerson);
result.Add(new ArrangementPreviewOutput
{ {
RegistrationItemId = firstPerson.RegistrationItemId, // 团队项目保持使用 EventRegistrationItem.Id var athleteNames = teamGroup.Select(p => p.Name).Distinct().OrderBy(n => n).ToList();
TimeRange = $"{proj.GetTotalDurationInSeconds()}''", string combinedAthleteNames = string.Join(", ", athleteNames);
ProjectName = proj.Name,
ProjectType = proj.ProjectType.Description(),
GroupName = teamGroup.Key.GroupName,
TeamName = teamGroup.Key.TeamName,
AthleteName = combinedAthleteNames,
UnitName = displayUnitName,
SessionIndex = currentRound,
VenueIndex = currentVenue,
ProjectTotalDurationSeconds = projectTotalDurationSeconds,
ProjectTotalDuration = projectTotalDuration
});
currentVenue++; var firstPerson = teamGroup.First();
if (currentVenue > venueCount) string displayUnitName = GetDisplayUnitName(firstPerson);
{
currentVenue = 1; result.Add(new ArrangementPreviewOutput
currentRound++; {
RegistrationItemId = firstPerson.RegistrationItemId,
TimeRange = $"{proj.GetTotalDurationInSeconds()}''",
ProjectName = proj.Name,
ProjectType = proj.ProjectType.Description(),
GroupName = group.GroupName,
TeamName = teamGroup.Key.TeamName,
AthleteName = combinedAthleteNames,
UnitName = displayUnitName,
SessionIndex = currentRound,
VenueIndex = currentVenue,
ProjectTotalDurationSeconds = projectTotalDurationSeconds,
ProjectTotalDuration = projectTotalDuration
});
currentVenue++;
if (currentVenue > venueCount)
{
currentVenue = 1;
currentRound++;
}
} }
} }
} else
else
{
// 个人项目:根据认证状态显示单位信息
foreach (var person in persons)
{ {
string displayUnitName = GetDisplayUnitName(person); foreach (var person in groupPersons.OrderBy(p => p.TeamName).ThenBy(p => p.Name).ThenBy(p => p.Id))
result.Add(new ArrangementPreviewOutput
{ {
RegistrationItemId = person.Id, // 个人项目使用 EventRegistrationPerson.Id string displayUnitName = GetDisplayUnitName(person);
TimeRange = $"{proj.GetTotalDurationInSeconds()}''",
ProjectName = proj.Name,
ProjectType = proj.ProjectType.Description(),
GroupName = person.GroupName,
TeamName = person.TeamName,
AthleteName = person.Name,
UnitName = displayUnitName,
SessionIndex = currentRound,
VenueIndex = currentVenue,
ProjectTotalDurationSeconds = projectTotalDurationSeconds,
ProjectTotalDuration = projectTotalDuration
});
currentVenue++; result.Add(new ArrangementPreviewOutput
if (currentVenue > venueCount) {
{ RegistrationItemId = person.Id,
currentVenue = 1; TimeRange = $"{proj.GetTotalDurationInSeconds()}''",
currentRound++; ProjectName = proj.Name,
ProjectType = proj.ProjectType.Description(),
GroupName = person.GroupName,
TeamName = person.TeamName,
AthleteName = person.Name,
UnitName = displayUnitName,
SessionIndex = currentRound,
VenueIndex = currentVenue,
ProjectTotalDurationSeconds = projectTotalDurationSeconds,
ProjectTotalDuration = projectTotalDuration
});
currentVenue++;
if (currentVenue > venueCount)
{
currentVenue = 1;
currentRound++;
}
} }
} }
} }