164 lines
7.0 KiB
C#
164 lines
7.0 KiB
C#
using YD_Event.Application.Event.Dtos;
|
|
using YD_Event.Core.Entities;
|
|
using MiniExcelLibs;
|
|
|
|
namespace YD_Event.Application.Event;
|
|
|
|
/// <summary>
|
|
/// 报名管理服务
|
|
/// </summary>
|
|
public class EventRegistrationService : BaseService<EventRegistration>, ITransient
|
|
{
|
|
private readonly ISqlSugarRepository<EventRegistration> _repository;
|
|
private readonly ISqlSugarRepository<EventRegistrationItem> _itemRepository;
|
|
private readonly ISqlSugarRepository<EventRegistrationPerson> _personRepository;
|
|
private readonly ISqlSugarRepository<EventRegistrationPayment> _paymentRepository;
|
|
|
|
public EventRegistrationService(
|
|
ISqlSugarRepository<EventRegistration> repository,
|
|
ISqlSugarRepository<EventRegistrationItem> itemRepository,
|
|
ISqlSugarRepository<EventRegistrationPerson> personRepository,
|
|
ISqlSugarRepository<EventRegistrationPayment> paymentRepository) : base(repository)
|
|
{
|
|
_repository = repository;
|
|
_itemRepository = itemRepository;
|
|
_personRepository = personRepository;
|
|
_paymentRepository = paymentRepository;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 分页查询报名
|
|
/// </summary>
|
|
[DisplayName("分页查询报名")]
|
|
public async Task<PageResult<RegistrationListOutput>> Page(RegistrationQueryInput input)
|
|
{
|
|
var query = _repository.AsQueryable()
|
|
.WhereIF(input.EventId.HasValue, x => x.EventId == input.EventId)
|
|
.WhereIF(input.RegistrationMode.HasValue, x => x.RegistrationMode == input.RegistrationMode)
|
|
.WhereIF(!string.IsNullOrWhiteSpace(input.UnitName), x => x.TeamName.Contains(input.UnitName))
|
|
.WhereIF(!string.IsNullOrWhiteSpace(input.UserName), x => x.ContactName.Contains(input.UserName))
|
|
.WhereIF(!string.IsNullOrWhiteSpace(input.ContactPhone), x => x.ContactPhone.Contains(input.ContactPhone))
|
|
.WhereIF(input.IsUploadMaterial.HasValue, x => (input.IsUploadMaterial.Value ? !string.IsNullOrEmpty(x.MaterialUrl) : string.IsNullOrEmpty(x.MaterialUrl)))
|
|
.WhereIF(input.PaymentMethod.HasValue, x => x.PaymentMethod == input.PaymentMethod)
|
|
.WhereIF(input.PaymentStatus.HasValue, x => x.PaymentStatus == input.PaymentStatus)
|
|
.WhereIF(input.RegistrationTimeStart.HasValue, x => x.RegistrationTime >= input.RegistrationTimeStart)
|
|
.WhereIF(input.RegistrationTimeEnd.HasValue, x => x.RegistrationTime <= input.RegistrationTimeEnd)
|
|
.OrderByDescending(x => x.RegistrationTime)
|
|
.Select(x => new RegistrationListOutput
|
|
{
|
|
Id = x.Id,
|
|
RegistrationMode = x.RegistrationMode,
|
|
UnitName = x.TeamName,
|
|
ContactName = x.ContactName,
|
|
ContactPhone = x.ContactPhone,
|
|
TotalPersonCount = x.TotalPersonCount,
|
|
IsUploadMaterial = !string.IsNullOrEmpty(x.MaterialUrl),
|
|
PaymentMethod = x.PaymentMethod,
|
|
OrderNo = x.OrderNo,
|
|
TotalAmount = x.TotalAmount,
|
|
PaymentStatus = x.PaymentStatus,
|
|
PaymentProofUrl = x.PaymentProofUrl,
|
|
RegistrationTime = x.RegistrationTime,
|
|
RegistrationStatus = x.RegistrationStatus
|
|
});
|
|
|
|
var result = await query.ToPagedListAsync(input);
|
|
|
|
// 填充下拉详情
|
|
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.GetListAsync(x => regIds.Contains(x.RegistrationId));
|
|
|
|
foreach (var dto in result.Rows)
|
|
{
|
|
var myItems = items.Where(x => x.RegistrationId == dto.Id).ToList();
|
|
dto.Items = new List<RegistrationItemDetailDto>();
|
|
|
|
foreach (var item in myItems)
|
|
{
|
|
var myPersons = persons.Where(p => p.RegistrationItemId == item.Id).ToList();
|
|
|
|
// 构造参与人信息字符串
|
|
var personInfo = string.Join(";", myPersons.Select(p => $"{p.Name}/{p.Gender}/{p.Age}/{p.IdCard}"));
|
|
if (personInfo.Length > 100) personInfo = personInfo.Substring(0, 97) + "..."; // 截断
|
|
|
|
var detail = new RegistrationItemDetailDto
|
|
{
|
|
ProjectName = item.ProjectName,
|
|
GroupName = item.GroupName,
|
|
ParticipantInfo = personInfo
|
|
};
|
|
dto.Items.Add(detail);
|
|
}
|
|
}
|
|
}
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 批量审核
|
|
/// </summary>
|
|
[UnitOfWork]
|
|
[DisplayName("批量审核")]
|
|
public async Task BatchAudit(BatchAuditInput input)
|
|
{
|
|
if (input.Ids == null || !input.Ids.Any()) return;
|
|
|
|
await _repository.UpdateAsync(x => new EventRegistration
|
|
{
|
|
RegistrationStatus = input.RegistrationStatus,
|
|
ReviewRemark = input.ReviewRemark,
|
|
ReviewTime = DateTime.Now
|
|
}, x => input.Ids.Contains(x.Id));
|
|
}
|
|
|
|
/// <summary>
|
|
/// 导出报名
|
|
/// </summary>
|
|
[DisplayName("导出报名")]
|
|
public async Task<byte[]> Export(RegistrationQueryInput input)
|
|
{
|
|
var list = await _repository.AsQueryable()
|
|
.WhereIF(input.EventId.HasValue, x => x.EventId == input.EventId)
|
|
.WhereIF(input.RegistrationMode.HasValue, x => x.RegistrationMode == input.RegistrationMode)
|
|
.WhereIF(!string.IsNullOrWhiteSpace(input.UnitName), x => x.TeamName.Contains(input.UnitName))
|
|
.WhereIF(!string.IsNullOrWhiteSpace(input.UserName), x => x.ContactName.Contains(input.UserName))
|
|
.WhereIF(!string.IsNullOrWhiteSpace(input.ContactPhone), x => x.ContactPhone.Contains(input.ContactPhone))
|
|
.WhereIF(input.PaymentStatus.HasValue, x => x.PaymentStatus == input.PaymentStatus)
|
|
.Select(x => new
|
|
{
|
|
x.RegistrationMode,
|
|
x.TeamName,
|
|
x.ContactName,
|
|
x.ContactPhone,
|
|
x.TotalPersonCount,
|
|
x.PaymentMethod,
|
|
x.TotalAmount,
|
|
x.PaymentStatus,
|
|
x.RegistrationTime,
|
|
x.RegistrationStatus
|
|
})
|
|
.ToListAsync();
|
|
|
|
using var stream = new MemoryStream();
|
|
stream.SaveAs(list);
|
|
return stream.ToArray();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取素材下载链接
|
|
/// </summary>
|
|
[DisplayName("获取素材下载链接")]
|
|
public async Task<List<string>> GetMaterialUrls(List<long> ids)
|
|
{
|
|
if (ids == null || !ids.Any()) return new List<string>();
|
|
|
|
return await _repository.AsQueryable()
|
|
.Where(x => ids.Contains(x.Id) && !string.IsNullOrEmpty(x.MaterialUrl))
|
|
.Select(x => x.MaterialUrl)
|
|
.ToListAsync();
|
|
}
|
|
}
|