You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
BookingHeChuan/Myshipping.Application/Service/Fee/FeeCustTemplateService.cs

116 lines
4.2 KiB
C#

using Furion.DependencyInjection;
using Furion.DynamicApiController;
using Furion.EventBus;
using Furion.FriendlyException;
using Mapster;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using Myshipping.Application.Entity;
using Myshipping.Application.Service.Fee.Dto;
using Myshipping.Core;
using Myshipping.Core.Service;
using System;
using System.Linq;
using System.Threading.Tasks;
namespace Myshipping.Application
{
/// <summary>
/// 往来单位固定费用
/// </summary>
[ApiDescriptionSettings("Application", Name = "FeeTemplate", Order = 1)]
public class FeeCustTemplateService : IDynamicApiController, ITransient
{
private readonly SqlSugarRepository<FeeCustTemplateDetail> _repCustTemplete;
private readonly ILogger<FeeCustTemplateService> _logger;
private readonly ISysCacheService _cache;
private readonly IEventPublisher _publisher;
public FeeCustTemplateService(ILogger<FeeCustTemplateService> logger,
ISysCacheService cache,
IEventPublisher publisher,
SqlSugarRepository<FeeCustTemplateDetail> repCustTemplete)
{
_logger = logger;
_cache = cache;
_publisher = publisher;
_repCustTemplete = repCustTemplete;
}
/// <summary>
/// 分页查询往来单位固定费用列表
/// </summary>
[HttpGet("/FeeCustTemplate/Page")]
public async Task<dynamic> Page([FromQuery] FeeCustTemplatePageInput input)
{
var entities = await _repCustTemplete.AsQueryable()
.ToPagedListAsync(input.PageNo, input.PageSize);
var result = entities.Adapt<SqlSugarPagedList<FeeCustTemplateDto>>();
return result.XnPagedResult();
}
/// <summary>
/// 根据往来单位名称及费用名称查询固定费用
/// </summary>
/// <param name="feeName">费用名称</param>
/// <param name="customerName">往来单位名称</param>
[HttpGet("/FeeCustTemplate/Get")]
public async Task<FeeCustTemplateDto> Get(string feeName, string customerName)
{
var detail = await _repCustTemplete.AsQueryable(c => c.FeeName == feeName && c.CustomerName == customerName)
.FirstAsync();
return detail?.Adapt<FeeCustTemplateDto>();
}
/// <summary>
/// 往来单位固定费用保存
/// </summary>
[HttpPost("/FeeCustTemplate/Save")]
public async Task Save(FeeCustTemplateDto input)
{
var entity = input.Adapt<FeeCustTemplateDetail>();
if (input.Id == 0)
{
// 判断是否已经存在同单位、同费用的记录
if (await _repCustTemplete.IsExistsAsync(c => c.FeeName == input.FeeName && c.CustomerName == input.CustomerName))
{
throw Oops.Bah("此往来单位下已存在此费用项");
}
await _repCustTemplete.InsertAsync(entity);
}
else
{
// 判断是否已经存在同单位、同费用的记录
if (await _repCustTemplete.IsExistsAsync(c => c.FeeName == input.FeeName && c.CustomerName == input.CustomerName && c.Id != input.Id))
{
throw Oops.Bah("此往来单位下已存在此费用项");
}
await _repCustTemplete.AsUpdateable(entity).IgnoreColumns(c => new { c.TenantId, c.TenantName }).ExecuteCommandAsync();
}
}
/// <summary>
/// 往来单位固定费用删除
/// </summary>
[HttpPost("/FeeCustTemplate/Delete")]
public async Task Delete([FromBody] long[] ids)
{
await _repCustTemplete.UpdateAsync(c => ids.Contains(c.Id), c => new FeeCustTemplateDetail
{
IsDeleted = true,
UpdatedTime = DateTime.Now,
UpdatedUserId = UserManager.UserId,
UpdatedUserName = UserManager.Name
});
}
}
}