单位名称

This commit is contained in:
马梓彭 2026-04-28 00:25:09 +08:00
parent d9de064fc4
commit 1042e7a0a6
5 changed files with 83 additions and 48 deletions

View File

@ -120,6 +120,11 @@ public class RegistrationListOutput
/// </summary>
public long CreatedUserId { get; set; }
/// <summary>
/// 单位认证 ID(用于获取单位名称)
/// </summary>
public long? MerchantCertificationId { get; set; }
/// <summary>
/// 单位名称
/// </summary>

View File

@ -322,15 +322,14 @@ namespace YD_Event.Application.Event;
// 获取参赛人员,并关联用户和单位认证信息
var persons = await _personRepository.AsQueryable()
.InnerJoin<EventRegistration>((p, r) => p.RegistrationId == r.Id)
.LeftJoin<YD_Event.Core.Entities.AppUser>((p, r, u) => p.UserId == u.Id)
.LeftJoin<MerchantCertification>((p, r, u, m) => u.MerchantCertificationId == m.Id)
.Where((p, r, u, m) => p.ProjectId == eventProj.Id
.LeftJoin<MerchantCertification>((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();

View File

@ -82,6 +82,7 @@ public class EventRegistrationService : BaseService<EventRegistration>, 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<EventRegistration>, 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<long, string> merchantNameDict = new Dictionary<long, string>();
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<EventRegistration>, ITransie
var eventProjectToProjectDict = eventProjects.ToDictionary(x => x.Id, x => x.ProjectId);
Dictionary<long, YD_Event.Core.Entities.Project> 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<long, string> merchantNameDict = new Dictionary<long, string>();
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<long, string> userIdToUnitNameDict = new Dictionary<long, string>();
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<EventRegistration>, 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
{

View File

@ -58,6 +58,7 @@ public class EventScoreService : BaseService<EventResult>, ITransient
private readonly ISqlSugarRepository<PointsRuleDetail> _pointsRuleDetailRepository;
private readonly ISqlSugarRepository<PointsRecord> _pointsRecordRepository;
private readonly ISqlSugarRepository<YD_Event.Core.Entities.AppUser> _appUserRepository;
private readonly ISqlSugarRepository<MerchantCertification> _merchantCertificationRepository;
private readonly CertificateGenerateService _certificateGenerateService;
private readonly IIdGenerator _idGenerator;
private readonly ILogger<EventScoreService> _logger;
@ -78,6 +79,7 @@ public class EventScoreService : BaseService<EventResult>, ITransient
ISqlSugarRepository<PointsRuleDetail> pointsRuleDetailRepository,
ISqlSugarRepository<PointsRecord> pointsRecordRepository,
ISqlSugarRepository<YD_Event.Core.Entities.AppUser> appUserRepository,
ISqlSugarRepository<MerchantCertification> merchantCertificationRepository,
CertificateGenerateService certificateGenerateService,
IIdGenerator idGenerator,
ILogger<EventScoreService> logger) : base(resultRepository)
@ -97,6 +99,7 @@ public class EventScoreService : BaseService<EventResult>, ITransient
_pointsRuleDetailRepository = pointsRuleDetailRepository;
_pointsRecordRepository = pointsRecordRepository;
_appUserRepository = appUserRepository;
_merchantCertificationRepository = merchantCertificationRepository;
_certificateGenerateService = certificateGenerateService;
_idGenerator = idGenerator;
_logger = logger;
@ -159,6 +162,27 @@ public class EventScoreService : BaseService<EventResult>, ITransient
baseQuery = baseQuery.Where((p, r, res, c) => p.Gender == input.Gender.Value);
}
// 步骤1.5:获取所有相关的单位认证信息
var merchantCertIds = new List<long>();
// 先查找所有可能的 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<long, string> merchantNameDict = new Dictionary<long, string>();
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<EventResult>, 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<EventResult>, 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<EventResult>, 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,

View File

@ -5754,6 +5754,11 @@
创建用户ID(用于获取单位名称)
</summary>
</member>
<member name="P:YD_Event.Application.Event.Dtos.RegistrationListOutput.MerchantCertificationId">
<summary>
单位认证 ID(用于获取单位名称)
</summary>
</member>
<member name="P:YD_Event.Application.Event.Dtos.RegistrationListOutput.UnitName">
<summary>
单位名称