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