From ef20efdfe1733a6ec8759da4727cd077603366b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=A9=AC=E6=A2=93=E5=BD=AD?= Date: Wed, 22 Apr 2026 16:22:55 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B5=9B=E4=BA=8B=E6=88=90=E7=BB=A9=E5=AF=BC?= =?UTF-8?q?=E5=85=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Event/EventScoreService.cs | 123 +++++++++++++----- 1 file changed, 88 insertions(+), 35 deletions(-) diff --git a/YD_Event.Application/Event/EventScoreService.cs b/YD_Event.Application/Event/EventScoreService.cs index dce6e8f..2e03b8b 100644 --- a/YD_Event.Application/Event/EventScoreService.cs +++ b/YD_Event.Application/Event/EventScoreService.cs @@ -206,7 +206,11 @@ public class EventScoreService : BaseService, ITransient var teamItems = teamGroup.ToList(); var names = string.Join(", ", teamItems.Select(x => x.Name).Distinct().OrderBy(x => x)); - var representative = teamItems.OrderBy(x => x.Rank).First(); + // 优先选择有成绩的人(Rank>0),然后按Rank排序 + var representative = teamItems + .OrderByDescending(x => x.Rank > 0) // 有成绩的排在前面 + .ThenBy(x => x.Rank > 0 ? x.Rank : int.MaxValue) // 有成绩的按Rank排序 + .First(); processedData.Add(new ScoreListOutput { Id = representative.Id, @@ -484,49 +488,98 @@ public class EventScoreService : BaseService, ITransient } // 处理成绩记录 - if (resultDict.TryGetValue(person.Id, out var existingResult)) + if (isTeamProject && teamMembers != null && teamMembers.Count > 0) { - // 更新现有记录 - existingResult.Score = row.Score; - existingResult.Rank = row.Rank; - existingResult.Remark = row.RankText; - existingResult.ProjectTypeName = projectTypeName; - // 对于团队项目,更新 ParticipantName 为团队所有成员姓名 - if (isTeamProject) + // 团队项目:为团队中的所有成员创建/更新成绩记录 + foreach (var teamMember in teamMembers) { - existingResult.ParticipantName = combinedNames; + var memberId = (long)teamMember.Id; + var memberRegistrationId = (long)teamMember.RegistrationId; + + if (resultDict.TryGetValue(memberId, out var existingResult)) + { + // 更新现有记录 + existingResult.Score = row.Score; + existingResult.Rank = row.Rank; + existingResult.Remark = row.RankText; + existingResult.ProjectTypeName = projectTypeName; + existingResult.ParticipantName = combinedNames; + existingResult.UpdatedTime = now; + resultsToUpdate.Add(existingResult); + } + else + { + // 从 EventRegistration 获取归属单位 ID + long? merchantCertId = null; + if (registrationDict.TryGetValue(memberRegistrationId, out var reg)) + { + merchantCertId = reg.MerchantCertificationId; + } + + // 插入新记录 + var newResult = new EventResult + { + Id = _idGenerator.NewLong(), + EventId = eventId, + RegistrationPersonId = memberId, + RegistrationId = memberRegistrationId, + ProjectId = person.ProjectId, + ParticipantName = combinedNames, + GroupName = person.GroupName, + MerchantCertificationId = merchantCertId, + ProjectTypeName = projectTypeName, + Score = row.Score, + Rank = row.Rank, + Remark = row.RankText, + CreatedTime = now, + UpdatedTime = now + }; + resultsToInsert.Add(newResult); + } } - existingResult.UpdatedTime = now; - resultsToUpdate.Add(existingResult); } else { - // 从 EventRegistration 获取归属单位 ID - long? merchantCertId = null; - if (registrationDict.TryGetValue(person.RegistrationId, out var reg)) + // 个人项目:只处理当前这个人 + if (resultDict.TryGetValue(person.Id, out var existingResult)) { - merchantCertId = reg.MerchantCertificationId; + // 更新现有记录 + existingResult.Score = row.Score; + existingResult.Rank = row.Rank; + existingResult.Remark = row.RankText; + existingResult.ProjectTypeName = projectTypeName; + existingResult.UpdatedTime = now; + resultsToUpdate.Add(existingResult); } - - // 插入新记录 - var newResult = new EventResult + else { - Id = _idGenerator.NewLong(), - EventId = eventId, - RegistrationPersonId = person.Id, - RegistrationId = person.RegistrationId, - ProjectId = person.ProjectId, - ParticipantName = isTeamProject ? combinedNames : person.Name, - GroupName = person.GroupName, - MerchantCertificationId = merchantCertId, - ProjectTypeName = projectTypeName, - Score = row.Score, - Rank = row.Rank, - Remark = row.RankText, - CreatedTime = now, - UpdatedTime = now - }; - resultsToInsert.Add(newResult); + // 从 EventRegistration 获取归属单位 ID + long? merchantCertId = null; + if (registrationDict.TryGetValue(person.RegistrationId, out var reg)) + { + merchantCertId = reg.MerchantCertificationId; + } + + // 插入新记录 + var newResult = new EventResult + { + Id = _idGenerator.NewLong(), + EventId = eventId, + RegistrationPersonId = person.Id, + RegistrationId = person.RegistrationId, + ProjectId = person.ProjectId, + ParticipantName = person.Name, + GroupName = person.GroupName, + MerchantCertificationId = merchantCertId, + ProjectTypeName = projectTypeName, + Score = row.Score, + Rank = row.Rank, + Remark = row.RankText, + CreatedTime = now, + UpdatedTime = now + }; + resultsToInsert.Add(newResult); + } } }