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 = "FeeCustTemplate", 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([FromQuery] 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 feeCode, string feeName, string customerCode, string customerName) { var detail = await _repCustTemplete.AsQueryable(c => c.FeeName == feeName && c.FeeCode == feeCode && c.CustomerCode == customerCode && 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.FeeCode == input.FeeCode && c.FeeName == input.FeeName && c.CustomerCode == input.CustomerCode && c.CustomerName == input.CustomerName)) { throw Oops.Bah("此往来单位下已存在此费用项"); } await _repCustTemplete.InsertAsync(entity); } else { // 判断是否已经存在同单位、同费用的记录 if (await _repCustTemplete.IsExistsAsync(c => c.FeeCode == input.FeeCode && c.FeeName == input.FeeName && c.CustomerCode == input.CustomerCode && 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 }); } } }