diff --git a/YD_Event.Application/Event/Dtos/RegistrationDtos.cs b/YD_Event.Application/Event/Dtos/RegistrationDtos.cs
index 7fe04e0..9db8807 100644
--- a/YD_Event.Application/Event/Dtos/RegistrationDtos.cs
+++ b/YD_Event.Application/Event/Dtos/RegistrationDtos.cs
@@ -120,6 +120,11 @@ public class RegistrationListOutput
///
public long CreatedUserId { get; set; }
+ ///
+ /// 单位认证 ID(用于获取单位名称)
+ ///
+ public long? MerchantCertificationId { get; set; }
+
///
/// 单位名称
///
diff --git a/YD_Event.Application/Event/EventArrangementService.cs b/YD_Event.Application/Event/EventArrangementService.cs
index ae24e2b..bde6ea7 100644
--- a/YD_Event.Application/Event/EventArrangementService.cs
+++ b/YD_Event.Application/Event/EventArrangementService.cs
@@ -322,15 +322,14 @@ namespace YD_Event.Application.Event;
// 获取参赛人员,并关联用户和单位认证信息
var persons = await _personRepository.AsQueryable()
.InnerJoin((p, r) => p.RegistrationId == r.Id)
- .LeftJoin((p, r, u) => p.UserId == u.Id)
- .LeftJoin((p, r, u, m) => u.MerchantCertificationId == m.Id)
- .Where((p, r, u, m) => p.ProjectId == eventProj.Id
+ .LeftJoin((p, r, m) => r.MerchantCertificationId == m.Id)
+ .Where((p, r, m) => p.ProjectId == eventProj.Id
&& r.PaymentStatus != 4
&& !p.DeleteMark
&& p.PersonType == PersonType.Athlete)
.OrderBy(p => p.GroupName)
.OrderBy(p => p.Id)
- .Select((p, r, u, m) => new {
+ .Select((p, r, m) => new {
Id = p.Id, // 添加 Id 属性
RegistrationItemId = p.RegistrationItemId,
p.UserId,
@@ -338,7 +337,7 @@ namespace YD_Event.Application.Event;
p.GroupName,
r.TeamName,
MerchantName = m.MerchantName ?? "",
- //m.AuditStatus,
+ m.AuditStatus,
Duration = projTotalDuration
})
.ToListAsync();
diff --git a/YD_Event.Application/Event/EventRegistrationService.cs b/YD_Event.Application/Event/EventRegistrationService.cs
index aa72afa..5aa560d 100644
--- a/YD_Event.Application/Event/EventRegistrationService.cs
+++ b/YD_Event.Application/Event/EventRegistrationService.cs
@@ -82,6 +82,7 @@ public class EventRegistrationService : BaseService, ITransie
Id = x.Id,
RegistrationMode = x.RegistrationMode,
CreatedUserId = x.CreatedUserId, // 保存创建用户ID以便后续查询单位名称
+ MerchantCertificationId = x.MerchantCertificationId, // 保存单位认证ID以便后续查询单位名称
UnitName = null, // 不初始化为 TeamName,只从单位认证信息中获取
ContactName = x.ContactName,
ContactPhone = x.ContactPhone,
@@ -97,11 +98,28 @@ public class EventRegistrationService : BaseService, ITransie
});
var result = await query.ToPagedListAsync(input);
+
+ // 获取所有报名记录的 MerchantCertificationId
+ var regIds = result.Rows.Select(x => x.Id).ToList();
+ var merchantCertIds = result.Rows
+ .Where(r => r.MerchantCertificationId.HasValue)
+ .Select(r => r.MerchantCertificationId.Value)
+ .Distinct()
+ .ToList();
+
+ // 获取单位认证信息
+ Dictionary merchantNameDict = new Dictionary();
+ if (merchantCertIds.Any())
+ {
+ var merchantCerts = await _merchantCertificationRepository.AsQueryable()
+ .Where(mc => merchantCertIds.Contains(mc.Id) && !mc.DeleteMark)
+ .ToListAsync();
+ merchantNameDict = merchantCerts.ToDictionary(mc => mc.Id, mc => mc.MerchantName);
+ }
// 填充下拉详情
if (result.Rows.Any())
{
- var regIds = result.Rows.Select(x => x.Id).ToList();
var items = await _itemRepository.GetListAsync(x => regIds.Contains(x.RegistrationId));
// 使用关联查询获取报名人员及其关联的用户信息
var persons = await _personRepository.AsQueryable()
@@ -119,42 +137,6 @@ public class EventRegistrationService : BaseService, ITransie
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();
-
- // 获取这些创建用户的信息
- var createdUsers = await _appUserRepository.AsQueryable()
- .Where(u => createdUserIds.Contains(u.Id) && !u.DeleteMark)
- .ToListAsync();
-
- // 获取这些用户的 MerchantCertificationId
- var merchantCertIds = createdUsers
- .Where(u => u.MerchantCertificationId.HasValue)
- .Select(u => u.MerchantCertificationId.Value)
- .Distinct()
- .ToList();
-
- // 获取单位认证信息
- Dictionary merchantNameDict = new Dictionary();
- if (merchantCertIds.Any())
- {
- var merchantCerts = await _merchantCertificationRepository.AsQueryable()
- .Where(mc => merchantCertIds.Contains(mc.Id) && !mc.DeleteMark)
- .ToListAsync();
- merchantNameDict = merchantCerts.ToDictionary(mc => mc.Id, mc => mc.MerchantName);
- }
-
- // 创建 CreatedUserId 到单位名称的映射
- Dictionary userIdToUnitNameDict = new Dictionary();
- foreach (var user in createdUsers)
- {
- if (user.MerchantCertificationId.HasValue &&
- merchantNameDict.TryGetValue(user.MerchantCertificationId.Value, out var unitName))
- {
- userIdToUnitNameDict[user.Id] = unitName;
- }
- }
-
// 获取所有报名人员的 UserId
var allAthleteUserIds = persons
.Where(p => p.PersonType == YD_Event.Core.Enum.PersonType.Athlete && p.UserId > 0)
@@ -229,10 +211,11 @@ public class EventRegistrationService : BaseService, ITransie
// 获取当前报名的所有人员
var regPersons = persons.Where(p => p.RegistrationId == dto.Id).ToList();
- // 根据报名记录的 CreatedUserId 获取单位名称
- if (userIdToUnitNameDict.TryGetValue(dto.CreatedUserId, out var unitNameFromUser))
+ // 根据报名记录的 MerchantCertificationId 获取单位名称
+ if (dto.MerchantCertificationId.HasValue &&
+ merchantNameDict.TryGetValue(dto.MerchantCertificationId.Value, out var unitName))
{
- dto.UnitName = unitNameFromUser;
+ dto.UnitName = unitName;
}
else
{
diff --git a/YD_Event.Application/Event/EventScoreService.cs b/YD_Event.Application/Event/EventScoreService.cs
index a12a679..87834de 100644
--- a/YD_Event.Application/Event/EventScoreService.cs
+++ b/YD_Event.Application/Event/EventScoreService.cs
@@ -58,6 +58,7 @@ public class EventScoreService : BaseService, ITransient
private readonly ISqlSugarRepository _pointsRuleDetailRepository;
private readonly ISqlSugarRepository _pointsRecordRepository;
private readonly ISqlSugarRepository _appUserRepository;
+ private readonly ISqlSugarRepository _merchantCertificationRepository;
private readonly CertificateGenerateService _certificateGenerateService;
private readonly IIdGenerator _idGenerator;
private readonly ILogger _logger;
@@ -78,6 +79,7 @@ public class EventScoreService : BaseService, ITransient
ISqlSugarRepository pointsRuleDetailRepository,
ISqlSugarRepository pointsRecordRepository,
ISqlSugarRepository appUserRepository,
+ ISqlSugarRepository merchantCertificationRepository,
CertificateGenerateService certificateGenerateService,
IIdGenerator idGenerator,
ILogger logger) : base(resultRepository)
@@ -97,6 +99,7 @@ public class EventScoreService : BaseService, ITransient
_pointsRuleDetailRepository = pointsRuleDetailRepository;
_pointsRecordRepository = pointsRecordRepository;
_appUserRepository = appUserRepository;
+ _merchantCertificationRepository = merchantCertificationRepository;
_certificateGenerateService = certificateGenerateService;
_idGenerator = idGenerator;
_logger = logger;
@@ -159,6 +162,27 @@ public class EventScoreService : BaseService, ITransient
baseQuery = baseQuery.Where((p, r, res, c) => p.Gender == input.Gender.Value);
}
+ // 步骤1.5:获取所有相关的单位认证信息
+ var merchantCertIds = new List();
+
+ // 先查找所有可能的 MerchantCertificationId
+ var registrationIds = await _registrationRepository.AsQueryable()
+ .Where(r => r.EventId == input.EventId)
+ .Select(r => r.MerchantCertificationId)
+ .ToListAsync();
+
+ merchantCertIds.AddRange(registrationIds.Where(id => id.HasValue).Select(id => id.Value).Distinct());
+
+ // 获取单位认证信息字典
+ Dictionary merchantNameDict = new Dictionary();
+ if (merchantCertIds.Any())
+ {
+ var merchantCerts = await _merchantCertificationRepository.AsQueryable()
+ .Where(mc => merchantCertIds.Contains(mc.Id) && !mc.DeleteMark)
+ .ToListAsync();
+ merchantNameDict = merchantCerts.ToDictionary(mc => mc.Id, mc => mc.MerchantName);
+ }
+
// 查询基本数据到内存
var baseData = await baseQuery
.OrderBy((p, r, res, c) => res.Rank)
@@ -166,7 +190,9 @@ public class EventScoreService : BaseService, ITransient
{
Id = p.Id,
Name = p.Name,
- UnitName = r.TeamName ?? string.Empty,
+ RegistrationId = r.Id, // 保存报名ID用于后续查找单位名称
+ MerchantCertificationId = r.MerchantCertificationId, // 保存单位认证ID
+ UnitName = r.TeamName ?? string.Empty, // 暂时保留TeamName作为后备
Gender = (int)p.Gender,
Score = res.Score,
Rank = res.Rank,
@@ -214,11 +240,20 @@ public class EventScoreService : BaseService, ITransient
.OrderByDescending(x => x.Rank > 0) // 有成绩的排在前面
.ThenBy(x => x.Rank > 0 ? x.Rank : int.MaxValue) // 有成绩的按Rank排序
.First();
+
+ // 获取正确的单位名称
+ string unitName = string.Empty;
+ if (representative.MerchantCertificationId.HasValue &&
+ merchantNameDict.TryGetValue(representative.MerchantCertificationId.Value, out var merchantName))
+ {
+ unitName = merchantName;
+ }
+
processedData.Add(new ScoreListOutput
{
Id = representative.Id,
Name = names,
- UnitName = representative.UnitName,
+ UnitName = unitName,
Gender = representative.Gender,
Score = representative.Score,
Rank = representative.Rank,
@@ -233,11 +268,19 @@ public class EventScoreService : BaseService, ITransient
// 个人项目:直接添加
foreach (var item in eventProjectGroup)
{
+ // 获取正确的单位名称
+ string unitName = string.Empty;
+ if (item.MerchantCertificationId.HasValue &&
+ merchantNameDict.TryGetValue(item.MerchantCertificationId.Value, out var merchantName))
+ {
+ unitName = merchantName;
+ }
+
processedData.Add(new ScoreListOutput
{
Id = item.Id,
Name = item.Name,
- UnitName = item.UnitName,
+ UnitName = unitName,
Gender = item.Gender,
Score = item.Score,
Rank = item.Rank,
diff --git a/YD_Event.Application/YD_Event.Application.xml b/YD_Event.Application/YD_Event.Application.xml
index a795439..f61da97 100644
--- a/YD_Event.Application/YD_Event.Application.xml
+++ b/YD_Event.Application/YD_Event.Application.xml
@@ -5754,6 +5754,11 @@
创建用户ID(用于获取单位名称)
+
+
+ 单位认证 ID(用于获取单位名称)
+
+
单位名称