YD_Event.Admin/YD_Event.Application/Client/EventClientController.Scores.cs
ltx 25830581d2 feat(api): 完善小程序赛事角色与秩序册检录接口
新增成绩查询、裁判认证及检录员账号管理接口,并统一小程序角色登录与个人中心数据。

检录任务绑定赛事秩序册场次,按项目、组别、场地和场次顺序执行;支持最多三名检录员、分配检录轮次及前序检录校验。

补充检录任务、检录记录、裁判申请实体及四份数据库迁移,包含表字段备注、秩序册绑定和检录序号。
2026-08-07 14:59:15 +08:00

99 lines
3.9 KiB
C#

using YD_Event.Application.Client.Dtos;
namespace YD_Event.Application.Client;
public partial class EventClientController
{
/// <summary>
/// 获取已有成绩的赛事。
/// </summary>
[HttpGet("scores/events")]
[AllowAnonymous]
[DisplayName("获取成绩赛事")]
public async Task<List<ScoreEventDto>> GetScoreEvents(
[FromServices] ISqlSugarRepository<EventResult> resultRepository,
[FromServices] ISqlSugarRepository<EventInfo> eventRepository)
{
var eventIds = await resultRepository.AsQueryable()
.Where(x => x.Status == AvailabilityStatus.Enable)
.Select(x => x.EventId)
.Distinct()
.ToListAsync();
if (eventIds.Count == 0) return new List<ScoreEventDto>();
var events = await eventRepository.AsQueryable()
.Where(x => eventIds.Contains(x.Id) && x.Status == AvailabilityStatus.Enable)
.OrderByDescending(x => x.MatchStartTime)
.ToListAsync();
return events.Select(x => new ScoreEventDto { Id = x.Id, Name = x.EventName }).ToList();
}
/// <summary>
/// 按赛事、姓名或报名人员ID查询成绩。
/// </summary>
[HttpGet("scores/query")]
[AllowAnonymous]
[DisplayName("查询赛事成绩")]
public async Task<ScoreQueryOutput> QueryScores(
[FromQuery] ScoreQueryInput input,
[FromServices] ISqlSugarRepository<EventResult> resultRepository,
[FromServices] ISqlSugarRepository<EventInfo> eventRepository,
[FromServices] ISqlSugarRepository<YD_Event.Core.Entities.Project> projectRepository)
{
var query = resultRepository.AsQueryable()
.Where(x => x.Status == AvailabilityStatus.Enable)
.WhereIF(input.EventId.HasValue, x => x.EventId == input.EventId.Value);
if (!string.IsNullOrWhiteSpace(input.Keyword))
{
var keyword = input.Keyword.Trim();
if (long.TryParse(keyword, out var personId))
{
query = query.Where(x => x.ParticipantName.Contains(keyword) || x.RegistrationPersonId == personId);
}
else
{
query = query.Where(x => x.ParticipantName.Contains(keyword) || x.GroupName.Contains(keyword));
}
}
var results = await query.OrderBy(x => x.Rank).OrderByDescending(x => x.CreatedTime).ToListAsync();
if (results.Count == 0) return new ScoreQueryOutput();
var eventIds = results.Select(x => x.EventId).Distinct().ToList();
var projectIds = results.Select(x => x.ProjectId).Distinct().ToList();
var events = await eventRepository.AsQueryable().Where(x => eventIds.Contains(x.Id)).ToListAsync();
var projects = await projectRepository.AsQueryable().Where(x => projectIds.Contains(x.Id)).ToListAsync();
var eventMap = events.ToDictionary(x => x.Id, x => x.EventName);
var projectMap = projects.ToDictionary(x => x.Id, x => x.Name);
var rows = results.Select(x => new ClientScoreDto
{
Id = x.Id,
EventId = x.EventId,
EventName = eventMap.GetValueOrDefault(x.EventId, string.Empty),
AthleteName = x.ParticipantName,
AthleteNo = FormatBibNo(x.RegistrationPersonId),
Category = projectMap.GetValueOrDefault(x.ProjectId, x.ProjectTypeName ?? string.Empty),
GroupName = x.GroupName,
Rank = x.Rank,
TotalScore = x.Score,
Status = "成绩有效",
JudgeScores = new List<JudgeScoreDto>
{
new() { Label = "最终成绩", Score = x.Score }
}
}).ToList();
return new ScoreQueryOutput { Rows = rows, Total = rows.Count };
}
private static string FormatBibNo(long personId)
{
var value = personId.ToString();
return value.Length > 6 ? value[^6..] : value.PadLeft(6, '0');
}
}