|
|
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.Entity;
|
|
|
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 = "FeeRecord", Order = 1)]
|
|
|
public class FeeRecordService : IDynamicApiController, ITransient
|
|
|
{
|
|
|
private readonly SqlSugarRepository<FeeRecord> _repRecord;
|
|
|
|
|
|
|
|
|
private readonly ILogger<FeeRecordService> _logger;
|
|
|
private readonly ISysCacheService _cache;
|
|
|
private readonly ISysUserRoleService _sysUserRoleService;
|
|
|
private readonly IDjyCustomerService _customerService;
|
|
|
|
|
|
private readonly IEventPublisher _publisher;
|
|
|
|
|
|
public FeeRecordService(ILogger<FeeRecordService> logger,
|
|
|
ISysCacheService cache,
|
|
|
IEventPublisher publisher,
|
|
|
SqlSugarRepository<FeeRecord> repRecord,
|
|
|
ISysUserRoleService sysUserRoleService,
|
|
|
IDjyCustomerService customerService)
|
|
|
{
|
|
|
_logger = logger;
|
|
|
_cache = cache;
|
|
|
_sysUserRoleService = sysUserRoleService;
|
|
|
_customerService = customerService;
|
|
|
|
|
|
_publisher = publisher;
|
|
|
|
|
|
_repRecord = repRecord;
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 费用记录查询
|
|
|
/// </summary>
|
|
|
[HttpGet("/FeeRecord/Query")]
|
|
|
public async Task<List<FeeRecordDto>> Query([FromQuery] FeeRecordInputDto input)
|
|
|
{
|
|
|
List<FeeRecord> feeRecords = await _repRecord.AsQueryable()
|
|
|
.Where(r => r.BussId == input.BussId)
|
|
|
.OrderBy(r => new { r.FeeType, r.Sort, r.CreatedTime })
|
|
|
.ToListAsync();
|
|
|
|
|
|
// 如果费用中含有机密费用,再判断是否有查询的权限
|
|
|
if (feeRecords.Any(r => !r.IsOpen))
|
|
|
{
|
|
|
bool canReviewSecretFee = await _sysUserRoleService.IsUserInRole(UserManager.UserId, CommonConst.SECRET_FEE_REVIEW);
|
|
|
if (!canReviewSecretFee)
|
|
|
{
|
|
|
feeRecords.RemoveAll(r => !r.IsOpen && r.CreatedUserId != UserManager.UserId);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
var result = feeRecords.Adapt<List<FeeRecordDto>>();
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 费用录入保存
|
|
|
/// </summary>
|
|
|
[HttpPost("/FeeRecord/Save")]
|
|
|
[SqlSugarUnitOfWork]
|
|
|
public async Task Save(FeeRecordSaveDto input)
|
|
|
{
|
|
|
input.SaveList ??= new List<FeeRecordDto>();
|
|
|
input.DeleteList ??= new List<FeeRecordDto>();
|
|
|
|
|
|
var waitInsertList = input.SaveList.Where(r => r.Id == 0).ToList();
|
|
|
var waitUpdateList = input.SaveList.Where(r => r.Id != 0 && r.MarkModify).ToList();
|
|
|
|
|
|
#region 校验
|
|
|
foreach (var item in waitInsertList.Concat(waitUpdateList))
|
|
|
{
|
|
|
// 人民币汇率必须为1,其它外币汇率不能为空
|
|
|
if (item.ExchangeRate == 0) throw Oops.Bah("汇率不能为空或0,请调整");
|
|
|
|
|
|
if (string.IsNullOrEmpty(item.Currency)) throw Oops.Bah("币别不能为空");
|
|
|
|
|
|
if (item.Currency?.ToUpper() == "RMB")
|
|
|
{
|
|
|
if (item.ExchangeRate != 1) throw Oops.Bah("币别为人民币时,汇率需为1,请调整");
|
|
|
}
|
|
|
}
|
|
|
#endregion
|
|
|
|
|
|
// 删除
|
|
|
if (input.DeleteList.Any())
|
|
|
{
|
|
|
var waitDeleteListTemp = input.DeleteList.Select(r => r.Id).ToList();
|
|
|
await _repRecord.UpdateAsync(r => waitDeleteListTemp.Contains(r.Id), r => new FeeRecord() { IsDeleted = true });
|
|
|
}
|
|
|
|
|
|
// 新增
|
|
|
if (waitInsertList.Any())
|
|
|
{
|
|
|
var waitInsertListTemp = waitInsertList.Adapt<List<FeeRecord>>();
|
|
|
await _repRecord.InsertAsync(waitInsertListTemp);
|
|
|
}
|
|
|
|
|
|
// 更新
|
|
|
if (waitUpdateList.Any())
|
|
|
{
|
|
|
await _repRecord.AsUpdateable(waitUpdateList).UpdateColumns(r => new
|
|
|
{
|
|
|
r.FeeCode,
|
|
|
r.FeeName,
|
|
|
r.CustomerType,
|
|
|
r.CustomerCode,
|
|
|
r.CustomerName,
|
|
|
r.FeeDescription,
|
|
|
r.Currency,
|
|
|
r.ExchangeRate,
|
|
|
r.TaxRate,
|
|
|
r.Tax,
|
|
|
r.Unit,
|
|
|
r.UnitPrice,
|
|
|
r.Quantity,
|
|
|
r.Amount,
|
|
|
r.NoTaxAmount,
|
|
|
r.Remark,
|
|
|
r.IsOpen,
|
|
|
r.IsAdvancedPay,
|
|
|
r.Sort,
|
|
|
r.IsInvoice
|
|
|
}).ExecuteCommandAsync();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 根据类型获取结算对象列表
|
|
|
/// </summary>
|
|
|
/// <returns></returns>
|
|
|
[HttpGet("/FeeRecord/GetFeeCustomerList")]
|
|
|
public async Task<List<FeeCustomerDto>> GetFeeCustomerList(string code)
|
|
|
{
|
|
|
List<FeeCustomerDto> result = new();
|
|
|
switch (code)
|
|
|
{
|
|
|
// 船司
|
|
|
case "carrier":
|
|
|
{
|
|
|
List<CodeCarrier> list = await _cache.GetAllCodeCarrier();
|
|
|
return list.Select(x => new FeeCustomerDto()
|
|
|
{
|
|
|
Code = x.Code,
|
|
|
Name = x.CnName
|
|
|
}).ToList();
|
|
|
}
|
|
|
// 船代
|
|
|
case "shipagency":
|
|
|
{
|
|
|
List<CodeForwarder> list = await _cache.GetAllCodeForwarder();
|
|
|
return list.Select(x => new FeeCustomerDto()
|
|
|
{
|
|
|
Code = x.Code,
|
|
|
Name = x.Name
|
|
|
}).ToList();
|
|
|
}
|
|
|
// 场站
|
|
|
case "yard":
|
|
|
{
|
|
|
List<CodeYard> list = await _cache.GetAllCodeYard();
|
|
|
return list.Select(x => new FeeCustomerDto()
|
|
|
{
|
|
|
Code = x.Code,
|
|
|
Name = x.Name
|
|
|
}).ToList();
|
|
|
}
|
|
|
// 往来单位
|
|
|
default:
|
|
|
{
|
|
|
List<(string codeName, string shortName)> list = await _customerService.QueryDjyCustomerByProp(code);
|
|
|
return list.Select(x => new FeeCustomerDto()
|
|
|
{
|
|
|
Code = x.codeName,
|
|
|
Name = x.shortName
|
|
|
}).ToList();
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 获取费用单位列表
|
|
|
/// </summary>
|
|
|
[HttpGet("/FeeRecord/GetFeeUnitList")]
|
|
|
public async Task<List<FeeUnitDto>> GetFeeUnitList()
|
|
|
{
|
|
|
var codeCtnList = (await _cache.GetAllCodeCtn()).Select(x => new FeeUnitDto(x.Code, x.Name)).ToList();
|
|
|
|
|
|
var feeUnitList = (await _cache.GetAllDictData()).Where(d => d.TypeCode == "FeeUnit")
|
|
|
.Select(x => new FeeUnitDto(x.Code, x.Value))
|
|
|
.ToList();
|
|
|
|
|
|
var result = codeCtnList.Concat(feeUnitList).ToList();
|
|
|
return result;
|
|
|
}
|
|
|
}
|
|
|
}
|