90 lines
2.7 KiB
C#
90 lines
2.7 KiB
C#
using YD_Event.Application.Certificate.Dtos;
|
||
using YD_Event.Core.Entities;
|
||
|
||
namespace YD_Event.Application.Certificate;
|
||
|
||
/// <summary>
|
||
/// 证书管理服务
|
||
/// </summary>
|
||
public class CertificateService : BaseService<YD_Event.Core.Entities.Certificate>, ITransient
|
||
{
|
||
private readonly ISqlSugarRepository<YD_Event.Core.Entities.Certificate> _repository;
|
||
private readonly IIdGenerator _idGenerator;
|
||
|
||
public CertificateService(ISqlSugarRepository<YD_Event.Core.Entities.Certificate> repository,
|
||
IIdGenerator idGenerator) : base(repository)
|
||
{
|
||
_repository = repository;
|
||
_idGenerator = idGenerator;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 证书分页查询
|
||
/// </summary>
|
||
[DisplayName("证书分页查询")]
|
||
[HttpGet]
|
||
public async Task<PageResult<CertificateListOutput>> Page([FromQuery] CertificateQueryInput input)
|
||
{
|
||
return await _repository.AsQueryable()
|
||
.WhereIF(!string.IsNullOrWhiteSpace(input.Name), x => x.Name.Contains(input.Name))
|
||
.OrderBy(x => x.Sort)
|
||
.OrderByDescending(x => x.CreatedTime)
|
||
.Select(x => new CertificateListOutput
|
||
{
|
||
Id = x.Id,
|
||
Name = x.Name,
|
||
Issuer = x.Issuer,
|
||
TemplateContent = x.TemplateContent,
|
||
Sort = x.Sort,
|
||
CreatedTime = x.CreatedTime
|
||
})
|
||
.ToPagedListAsync(input);
|
||
}
|
||
|
||
/// <summary>
|
||
/// 添加证书
|
||
/// </summary>
|
||
[DisplayName("添加证书")]
|
||
[HttpPost("add")]
|
||
public async Task Add(AddCertificateInput input)
|
||
{
|
||
var entity = input.Adapt<YD_Event.Core.Entities.Certificate>();
|
||
entity.Id = _idGenerator.NextId();
|
||
await _repository.InsertAsync(entity);
|
||
}
|
||
|
||
/// <summary>
|
||
/// 更新证书
|
||
/// </summary>
|
||
[DisplayName("更新证书")]
|
||
[HttpPut("edit")]
|
||
public async Task Update(UpdateCertificateInput input)
|
||
{
|
||
var entity = await _repository.GetByIdAsync(input.Id);
|
||
if (entity == null) throw Oops.Bah("证书不存在");
|
||
|
||
input.Adapt(entity);
|
||
await _repository.UpdateAsync(entity);
|
||
}
|
||
|
||
/// <summary>
|
||
/// 删除证书
|
||
/// </summary>
|
||
[DisplayName("删除证书")]
|
||
public async Task Delete(List<long> ids)
|
||
{
|
||
if (ids == null || !ids.Any()) return;
|
||
await _repository.DeleteAsync(x => ids.Contains(x.Id));
|
||
}
|
||
|
||
/// <summary>
|
||
/// 获取证书详情
|
||
/// </summary>
|
||
[DisplayName("获取证书详情")]
|
||
[HttpGet("detail")]
|
||
public async Task<YD_Event.Core.Entities.Certificate> Detail([FromQuery] long id)
|
||
{
|
||
return await _repository.GetByIdAsync(id);
|
||
}
|
||
}
|