赛事成绩导入
This commit is contained in:
parent
63be3e0144
commit
ef20efdfe1
@ -206,7 +206,11 @@ public class EventScoreService : BaseService<EventResult>, 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<EventResult>, 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user