diff --git a/YD_Event.Application/Event/Dtos/ScoreDtos.cs b/YD_Event.Application/Event/Dtos/ScoreDtos.cs
index 97864c0..3ef0a68 100644
--- a/YD_Event.Application/Event/Dtos/ScoreDtos.cs
+++ b/YD_Event.Application/Event/Dtos/ScoreDtos.cs
@@ -20,7 +20,12 @@ public class ScoreQueryInput : Pagination
public long? ProjectId { get; set; }
///
- /// 组别名称
+ /// 赛事项目组别ID (优先使用)
+ ///
+ public long? EventProjectGroupId { get; set; }
+
+ ///
+ /// 组别名称 (备用,当没有EventProjectGroupId时使用)
///
public string? GroupName { get; set; }
@@ -184,9 +189,10 @@ public class IssueCertificateInput
public long EventId { get; set; }
///
- /// 证书模板ID(可选)
+ /// 证书ID(必选)
///
- public long? TemplateId { get; set; }
+ [Required(ErrorMessage = "请选择证书")]
+ public long CertificateId { get; set; }
}
///
diff --git a/YD_Event.Application/Event/EventRegistrationService.cs b/YD_Event.Application/Event/EventRegistrationService.cs
index 784023e..3a2cc1a 100644
--- a/YD_Event.Application/Event/EventRegistrationService.cs
+++ b/YD_Event.Application/Event/EventRegistrationService.cs
@@ -166,7 +166,7 @@ public class EventRegistrationService : BaseService, ITransie
{
var myPersons = persons.Where(p => p.RegistrationItemId == item.Id).ToList();
- // 构造参与人信息字符串,可以使用关联的 User 信息
+ // 构造参与人信息字符串,统一格式为:姓名/性别/年龄/手机号
var personInfo = string.Join(";", myPersons.Select(p =>
{
// 将性别转换为中文显示
@@ -177,12 +177,11 @@ public class EventRegistrationService : BaseService, ITransie
_ => "未知"
};
- // 如果有关联的用户信息,可以使用更完整的信息
- if (p.User != null)
- {
- return $"{p.Name}({p.User.Mobile})/{genderText}/{p.Age}";
- }
- return $"{p.Name}/{genderText}/{p.Age}/{p.IdCard}";
+ // 获取手机号,优先使用关联用户信息,否则使用自身的 Phone 字段
+ var mobile = p.User?.Mobile ?? p.Phone ?? "";
+
+ // 统一格式:姓名/性别/年龄/手机号
+ return $"{p.Name}/{genderText}/{p.Age}/{mobile}";
}));
if (personInfo.Length > 100) personInfo = personInfo.Substring(0, 97) + "..."; // 截断
diff --git a/YD_Event.Application/Event/EventScoreService.cs b/YD_Event.Application/Event/EventScoreService.cs
index d6f0a98..04215f9 100644
--- a/YD_Event.Application/Event/EventScoreService.cs
+++ b/YD_Event.Application/Event/EventScoreService.cs
@@ -47,6 +47,7 @@ public class EventScoreService : BaseService, ITransient
private readonly ISqlSugarRepository _certificateRepository;
private readonly ISqlSugarRepository _registrationRepository;
private readonly ISqlSugarRepository _templateRepository;
+ private readonly ISqlSugarRepository _certificateMasterRepository;
private readonly ISqlSugarRepository _projectRepository;
private readonly ISqlSugarRepository _teamMemberRepository;
private readonly ISqlSugarRepository _eventRepository;
@@ -54,6 +55,7 @@ public class EventScoreService : BaseService, ITransient
private readonly ISqlSugarRepository _pointsRuleDetailRepository;
private readonly ISqlSugarRepository _pointsRecordRepository;
private readonly ISqlSugarRepository _appUserRepository;
+ private readonly CertificateGenerateService _certificateGenerateService;
private readonly IIdGenerator _idGenerator;
private readonly ILogger _logger;
@@ -63,6 +65,7 @@ public class EventScoreService : BaseService, ITransient
ISqlSugarRepository certificateRepository,
ISqlSugarRepository registrationRepository,
ISqlSugarRepository templateRepository,
+ ISqlSugarRepository certificateMasterRepository,
ISqlSugarRepository projectRepository,
ISqlSugarRepository teamMemberRepository,
ISqlSugarRepository eventRepository,
@@ -70,6 +73,7 @@ public class EventScoreService : BaseService, ITransient
ISqlSugarRepository pointsRuleDetailRepository,
ISqlSugarRepository pointsRecordRepository,
ISqlSugarRepository appUserRepository,
+ CertificateGenerateService certificateGenerateService,
IIdGenerator idGenerator,
ILogger logger) : base(resultRepository)
{
@@ -78,6 +82,7 @@ public class EventScoreService : BaseService, ITransient
_certificateRepository = certificateRepository;
_registrationRepository = registrationRepository;
_templateRepository = templateRepository;
+ _certificateMasterRepository = certificateMasterRepository;
_projectRepository = projectRepository;
_teamMemberRepository = teamMemberRepository;
_eventRepository = eventRepository;
@@ -85,6 +90,7 @@ public class EventScoreService : BaseService, ITransient
_pointsRuleDetailRepository = pointsRuleDetailRepository;
_pointsRecordRepository = pointsRecordRepository;
_appUserRepository = appUserRepository;
+ _certificateGenerateService = certificateGenerateService;
_idGenerator = idGenerator;
_logger = logger;
}
@@ -95,8 +101,8 @@ public class EventScoreService : BaseService, ITransient
[DisplayName("运动员成绩列表")]
public async Task> PageAthlete(ScoreQueryInput input)
{
- _logger.LogInformation("开始查询运动员成绩列表,赛事ID={EventId}, 项目ID={ProjectId}, 组别={GroupName}",
- input.EventId, input.ProjectId, input.GroupName);
+ _logger.LogInformation("开始查询运动员成绩列表,赛事ID={EventId}, 项目ID={ProjectId}, 赛事项目组别ID={EventProjectGroupId}, 组别名称={GroupName}",
+ input.EventId, input.ProjectId, input.EventProjectGroupId, input.GroupName);
var query = _personRepository.AsQueryable()
.LeftJoin((p, r) => p.RegistrationId == r.Id)
@@ -110,7 +116,12 @@ public class EventScoreService : BaseService, ITransient
query = query.Where(p => p.ProjectId == input.ProjectId.Value);
}
- if (!string.IsNullOrWhiteSpace(input.GroupName))
+ // 优先使用 EventProjectGroupId,如果没有则使用 GroupName
+ if (input.EventProjectGroupId.HasValue)
+ {
+ query = query.Where(p => p.EventProjectGroupId == input.EventProjectGroupId.Value);
+ }
+ else if (!string.IsNullOrWhiteSpace(input.GroupName))
{
query = query.Where(p => p.GroupName == input.GroupName);
}
@@ -383,18 +394,27 @@ public class EventScoreService : BaseService, ITransient
var result = new IssueCertificateResult();
var now = DateTime.Now;
- // 如果指定了模板,验证模板是否存在
- CertificateTemplate? template = null;
- if (input.TemplateId.HasValue)
+ // 验证证书是否存在并获取证书信息
+ var certificate = await _certificateMasterRepository.GetFirstAsync(x =>
+ x.Id == input.CertificateId &&
+ x.Status == AvailabilityStatus.Enable &&
+ !x.DeleteMark);
+ if (certificate == null)
{
- template = await _templateRepository.GetFirstAsync(x =>
- x.Id == input.TemplateId.Value &&
- x.Status == AvailabilityStatus.Enable &&
- !x.DeleteMark);
- if (template == null)
- {
- throw Oops.Bah("指定的证书模板不存在或不可用");
- }
+ throw Oops.Bah("指定的证书不存在或不可用");
+ }
+
+ // 根据证书获取对应的模板ID
+ var templateId = certificate.TemplateId;
+
+ // 验证模板是否存在
+ var template = await _templateRepository.GetFirstAsync(x =>
+ x.Id == templateId &&
+ x.Status == AvailabilityStatus.Enable &&
+ !x.DeleteMark);
+ if (template == null)
+ {
+ throw Oops.Bah("证书关联的模板不存在或不可用");
}
// 批量预加载所有需要的数据
@@ -450,7 +470,8 @@ public class EventScoreService : BaseService, ITransient
GeneratedTime = now,
CertificateNo = $"C{now:yyyyMMdd}{person.Id}",
CreatedTime = now,
- TemplateId = input.TemplateId
+ TemplateId = templateId,
+ CertificateUrl = string.Empty // 暂时设置为空字符串,避免 null
};
certsToInsert.Add(cert);
}
@@ -475,7 +496,8 @@ public class EventScoreService : BaseService, ITransient
GeneratedTime = now,
CertificateNo = $"CC{now:yyyyMMdd}{person.Id}",
CreatedTime = now,
- TemplateId = input.TemplateId
+ TemplateId = templateId,
+ CertificateUrl = string.Empty // 暂时设置为空字符串,避免 null
};
certsToInsert.Add(cert);
}
@@ -485,6 +507,11 @@ public class EventScoreService : BaseService, ITransient
cert.CertificateStatus = 2;
cert.IssuedTime = now;
cert.UpdatedTime = now;
+ // 确保 CertificateUrl 不为 null
+ if (string.IsNullOrEmpty(cert.CertificateUrl))
+ {
+ cert.CertificateUrl = string.Empty;
+ }
result.SuccessCount++;
}