102 lines
3.4 KiB
C#
102 lines
3.4 KiB
C#
using YD_Event.Application.EventRecord.Dtos;
|
|
using YD_Event.Core.Entities;
|
|
using YD_Event.Core.Enum;
|
|
|
|
namespace YD_Event.Application.EventRecord;
|
|
|
|
/// <summary>
|
|
/// 参赛记录管理
|
|
/// </summary>
|
|
[ApiDescriptionSettings("用户管理", Name = "EventRecord", Order = 102)]
|
|
public class EventRecordService : IDynamicApiController, ITransient
|
|
{
|
|
private readonly ISqlSugarRepository<EventRegistration> _registrationRep;
|
|
private readonly ISqlSugarRepository<EventInfo> _eventRep;
|
|
private readonly ISqlSugarRepository<EventCertificate> _certificateRep;
|
|
|
|
public EventRecordService(ISqlSugarRepository<EventRegistration> registrationRep,
|
|
ISqlSugarRepository<EventInfo> eventRep,
|
|
ISqlSugarRepository<EventCertificate> certificateRep)
|
|
{
|
|
_registrationRep = registrationRep;
|
|
_eventRep = eventRep;
|
|
_certificateRep = certificateRep;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 分页查询参赛记录
|
|
/// </summary>
|
|
[HttpGet("page")]
|
|
public async Task<PageResult<EventRecordOutput>> Page([FromQuery] EventRecordPageInput input)
|
|
{
|
|
if (!input.UserId.HasValue) return new PageResult<EventRecordOutput>();
|
|
|
|
// Join EventRegistration and EventInfo
|
|
var query = _registrationRep.AsQueryable()
|
|
.LeftJoin<EventInfo>((r, e) => r.EventId == e.Id)
|
|
.Where((r, e) => r.CreatedUserId == input.UserId)
|
|
.WhereIF(!string.IsNullOrWhiteSpace(input.EventName), (r, e) => e.EventName.Contains(input.EventName))
|
|
.WhereIF(input.StartTime.HasValue, (r, e) => e.MatchStartTime >= input.StartTime)
|
|
.WhereIF(input.EndTime.HasValue, (r, e) => e.MatchStartTime <= input.EndTime)
|
|
.OrderByDescending((r, e) => r.CreatedTime)
|
|
.Select((r, e) => new EventRecordOutput
|
|
{
|
|
Id = r.Id,
|
|
EventName = e.EventName,
|
|
EventType = e.EventType.ToString(),
|
|
StartTime = e.MatchStartTime,
|
|
EndTime = e.MatchEndTime,
|
|
RegistrationStatus = r.RegistrationStatus,
|
|
EventId = e.Id
|
|
});
|
|
|
|
return await query.ToPagedListAsync(input);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取证书列表
|
|
/// </summary>
|
|
[HttpGet("{registrationId}/certificates")]
|
|
public async Task<List<CertificateOutput>> GetCertificates([FromRoute] long registrationId)
|
|
{
|
|
var certs = await _certificateRep.AsQueryable()
|
|
.Where(c => c.RegistrationId == registrationId)
|
|
.ToListAsync();
|
|
|
|
return certs.Select(c => new CertificateOutput
|
|
{
|
|
Id = c.Id,
|
|
Name = c.ParticipantName,
|
|
AwardLevel = GetAwardLevelName(c.AwardLevel),
|
|
CertificateType = GetCertificateTypeName(c.CertificateType),
|
|
ImageUrl = c.CertificateUrl
|
|
}).ToList();
|
|
}
|
|
|
|
private string GetAwardLevelName(int level)
|
|
{
|
|
return level switch
|
|
{
|
|
1 => "特等奖",
|
|
2 => "一等奖",
|
|
3 => "二等奖",
|
|
4 => "三等奖",
|
|
5 => "优秀奖",
|
|
_ => "未知"
|
|
};
|
|
}
|
|
|
|
private string GetCertificateTypeName(int type)
|
|
{
|
|
return type switch
|
|
{
|
|
1 => "冠军证书",
|
|
2 => "亚军证书",
|
|
3 => "季军证书",
|
|
4 => "优胜证书",
|
|
5 => "参与证书",
|
|
_ => "未知"
|
|
};
|
|
}
|
|
}
|