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 { /// /// 往来单位固定费用 /// [ApiDescriptionSettings("Application", Name = "FeeTemplate", Order = 1)] public class FeeCustTemplateService : IDynamicApiController, ITransient { private readonly SqlSugarRepository _repCustTemplete; private readonly ILogger _logger; private readonly ISysCacheService _cache; private readonly IEventPublisher _publisher; public FeeCustTemplateService(ILogger logger, ISysCacheService cache, IEventPublisher publisher, SqlSugarRepository repCustTemplete) { _logger = logger; _cache = cache; _publisher = publisher; _repCustTemplete = repCustTemplete; } [HttpGet("/FeeCustTemplate/Page")] public async Task Page(FeeCustTemplatePageInput input) { var entities = await _repCustTemplete.AsQueryable() .ToPagedListAsync(input.PageNo, input.PageSize); var result = entities.Adapt>(); return result.XnPagedResult(); } /// /// 根据往来单位名称及费用名称查询固定费用 /// /// 费用名称 /// 往来单位名称 [HttpGet("/FeeCustTemplate/Get")] public async Task Get(string feeName, string customerName) { var detail = await _repCustTemplete.AsQueryable(c => c.FeeName == feeName && c.CustomerName == customerName) .FirstAsync(); return detail?.Adapt(); } [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() //{ //} } }