82 lines
2.4 KiB
C#
82 lines
2.4 KiB
C#
|
|
using YD_Event.Application.Merchant.Dtos;
|
||
|
|
using YD_Event.Core.Entities;
|
||
|
|
|
||
|
|
namespace YD_Event.Application.Merchant;
|
||
|
|
|
||
|
|
/// <summary>
|
||
|
|
/// 商户管理
|
||
|
|
/// </summary>
|
||
|
|
public class MerchantService : BaseService<YD_Event.Core.Entities.Merchant>, ITransient
|
||
|
|
{
|
||
|
|
private readonly ISqlSugarRepository<YD_Event.Core.Entities.Merchant> _repository;
|
||
|
|
private readonly IIdGenerator _idGenerator;
|
||
|
|
|
||
|
|
public MerchantService(ISqlSugarRepository<YD_Event.Core.Entities.Merchant> repository,
|
||
|
|
IIdGenerator idGenerator) : base(repository)
|
||
|
|
{
|
||
|
|
_repository = repository;
|
||
|
|
_idGenerator = idGenerator;
|
||
|
|
}
|
||
|
|
|
||
|
|
/// <summary>
|
||
|
|
/// 商户分页查询
|
||
|
|
/// </summary>
|
||
|
|
[DisplayName("商户分页查询")]
|
||
|
|
[HttpGet]
|
||
|
|
public async Task<PageResult<YD_Event.Core.Entities.Merchant>> Page([FromQuery] MerchantQueryInput input)
|
||
|
|
{
|
||
|
|
return await _repository.AsQueryable()
|
||
|
|
.WhereIF(!string.IsNullOrWhiteSpace(input.MerchantName), x => x.MerchantName.Contains(input.MerchantName))
|
||
|
|
.OrderByDescending(x => x.CreatedTime)
|
||
|
|
.ToPagedListAsync(input);
|
||
|
|
}
|
||
|
|
|
||
|
|
/// <summary>
|
||
|
|
/// 添加商户
|
||
|
|
/// </summary>
|
||
|
|
[DisplayName("添加商户")]
|
||
|
|
[HttpPost("add")]
|
||
|
|
public async Task Add(AddMerchantInput input)
|
||
|
|
{
|
||
|
|
var entity = input.Adapt<YD_Event.Core.Entities.Merchant>();
|
||
|
|
entity.Id = _idGenerator.NextId();
|
||
|
|
await _repository.InsertAsync(entity);
|
||
|
|
}
|
||
|
|
|
||
|
|
/// <summary>
|
||
|
|
/// 更新商户
|
||
|
|
/// </summary>
|
||
|
|
[DisplayName("更新商户")]
|
||
|
|
[HttpPut("edit")]
|
||
|
|
public async Task Update(UpdateMerchantInput input)
|
||
|
|
{
|
||
|
|
var entity = await _repository.GetByIdAsync(input.Id);
|
||
|
|
if (entity == null) throw Oops.Bah("商户不存在");
|
||
|
|
|
||
|
|
input.Adapt(entity);
|
||
|
|
await _repository.UpdateAsync(entity);
|
||
|
|
}
|
||
|
|
|
||
|
|
/// <summary>
|
||
|
|
/// 删除商户
|
||
|
|
/// </summary>
|
||
|
|
[DisplayName("删除商户")]
|
||
|
|
[HttpPost("delete")]
|
||
|
|
public async Task Delete([FromBody] List<long> ids)
|
||
|
|
{
|
||
|
|
await _repository.DeleteAsync(x => ids.Contains(x.Id));
|
||
|
|
}
|
||
|
|
|
||
|
|
/// <summary>
|
||
|
|
/// 获取商户详情
|
||
|
|
/// </summary>
|
||
|
|
[DisplayName("获取商户详情")]
|
||
|
|
[HttpGet("detail")]
|
||
|
|
public async Task<YD_Event.Core.Entities.Merchant> Detail([FromQuery] long id)
|
||
|
|
{
|
||
|
|
var entity = await _repository.GetByIdAsync(id);
|
||
|
|
if (entity == null) throw Oops.Bah("商户不存在");
|
||
|
|
return entity;
|
||
|
|
}
|
||
|
|
}
|