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 { /// /// 往来单位固定费用 /// [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) { var entity = input.Adapt(); 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(); } } /// /// 往来单位固定费用删除 /// [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 }); } } }