赛事成绩导入
This commit is contained in:
parent
63be3e0144
commit
ef20efdfe1
@ -206,7 +206,11 @@ public class EventScoreService : BaseService<EventResult>, ITransient
|
|||||||
var teamItems = teamGroup.ToList();
|
var teamItems = teamGroup.ToList();
|
||||||
var names = string.Join(", ", teamItems.Select(x => x.Name).Distinct().OrderBy(x => x));
|
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
|
processedData.Add(new ScoreListOutput
|
||||||
{
|
{
|
||||||
Id = representative.Id,
|
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;
|
foreach (var teamMember in teamMembers)
|
||||||
existingResult.Rank = row.Rank;
|
|
||||||
existingResult.Remark = row.RankText;
|
|
||||||
existingResult.ProjectTypeName = projectTypeName;
|
|
||||||
// 对于团队项目,更新 ParticipantName 为团队所有成员姓名
|
|
||||||
if (isTeamProject)
|
|
||||||
{
|
{
|
||||||
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
|
else
|
||||||
{
|
{
|
||||||
// 从 EventRegistration 获取归属单位 ID
|
// 个人项目:只处理当前这个人
|
||||||
long? merchantCertId = null;
|
if (resultDict.TryGetValue(person.Id, out var existingResult))
|
||||||
if (registrationDict.TryGetValue(person.RegistrationId, out var reg))
|
|
||||||
{
|
{
|
||||||
merchantCertId = reg.MerchantCertificationId;
|
// 更新现有记录
|
||||||
|
existingResult.Score = row.Score;
|
||||||
|
existingResult.Rank = row.Rank;
|
||||||
|
existingResult.Remark = row.RankText;
|
||||||
|
existingResult.ProjectTypeName = projectTypeName;
|
||||||
|
existingResult.UpdatedTime = now;
|
||||||
|
resultsToUpdate.Add(existingResult);
|
||||||
}
|
}
|
||||||
|
else
|
||||||
// 插入新记录
|
|
||||||
var newResult = new EventResult
|
|
||||||
{
|
{
|
||||||
Id = _idGenerator.NewLong(),
|
// 从 EventRegistration 获取归属单位 ID
|
||||||
EventId = eventId,
|
long? merchantCertId = null;
|
||||||
RegistrationPersonId = person.Id,
|
if (registrationDict.TryGetValue(person.RegistrationId, out var reg))
|
||||||
RegistrationId = person.RegistrationId,
|
{
|
||||||
ProjectId = person.ProjectId,
|
merchantCertId = reg.MerchantCertificationId;
|
||||||
ParticipantName = isTeamProject ? combinedNames : person.Name,
|
}
|
||||||
GroupName = person.GroupName,
|
|
||||||
MerchantCertificationId = merchantCertId,
|
// 插入新记录
|
||||||
ProjectTypeName = projectTypeName,
|
var newResult = new EventResult
|
||||||
Score = row.Score,
|
{
|
||||||
Rank = row.Rank,
|
Id = _idGenerator.NewLong(),
|
||||||
Remark = row.RankText,
|
EventId = eventId,
|
||||||
CreatedTime = now,
|
RegistrationPersonId = person.Id,
|
||||||
UpdatedTime = now
|
RegistrationId = person.RegistrationId,
|
||||||
};
|
ProjectId = person.ProjectId,
|
||||||
resultsToInsert.Add(newResult);
|
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