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

101 lines
3.6 KiB
C#

using Furion.DatabaseAccessor;
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 SqlSugar;
using System.Collections.Generic;
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;
}
[HttpGet("/FeeCustTemplate/Page")]
public async Task<dynamic> Page(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>();
}
[HttpPost("/FeeCustTemplate/Save")]
public async Task Save(FeeCustTemplateDto input)
{
if (input.Id == 0)
{
// 判断是否已经存在同单位、同费用的记录
if (await _repCustTemplete.IsExistsAsync(c => c.FeeName == input.FeeName && c.CustomerName == input.CustomerName))
{
throw Oops.Bah("此往来单位下已存在此费用项");
}
await _repCustTemplete.InsertAsync(input);
}
else
{
// 判断是否已经存在同单位、同费用的记录
if (await _repCustTemplete.IsExistsAsync(c => c.FeeName == input.FeeName && c.CustomerName == input.CustomerName && c.Id != input.Id))
{
throw Oops.Bah("此往来单位下已存在此费用项");
}
await _repCustTemplete.AsUpdateable(input).IgnoreColumns(c => new { c.TenantId, c.TenantName }).ExecuteCommandAsync();
}
}
//[HttpPost("/FeeCustTemplate/Delete")]
//public async Task Delete()
//{
//}
}
}