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.
148 lines
5.8 KiB
C#
148 lines
5.8 KiB
C#
using System.Linq.Expressions;
|
|
using DS.Module.Core;
|
|
using DS.Module.Core.Extensions;
|
|
using DS.WMS.Core.Fee.Dtos;
|
|
using DS.WMS.Core.Fee.Entity;
|
|
using DS.WMS.Core.Fee.Interface;
|
|
using DS.WMS.Core.Flow.Entity;
|
|
using DS.WMS.Core.Op.Entity;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using SqlSugar;
|
|
|
|
namespace DS.WMS.Core.Fee.Method
|
|
{
|
|
/// <summary>
|
|
/// 费用服务基类
|
|
/// </summary>
|
|
public class FeeServiceBase : ServiceBase
|
|
{
|
|
readonly Lazy<IFeeCurrencyExchangeService> exchangeService;
|
|
|
|
/// <summary>
|
|
/// 初始化
|
|
/// </summary>
|
|
/// <param name="serviceProvider">服务提供程序</param>
|
|
public FeeServiceBase(IServiceProvider serviceProvider) : base(serviceProvider)
|
|
{
|
|
exchangeService = new Lazy<IFeeCurrencyExchangeService>(serviceProvider.GetRequiredService<IFeeCurrencyExchangeService>);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 返回针对费用及其关联业务的查询对象
|
|
/// </summary>
|
|
/// <param name="expr1">关联条件1</param>
|
|
/// <returns>查询对象</returns>
|
|
public ISugarQueryable<BusinessFeeDto> CreateFeeQuery(
|
|
Expression<Func<SeaExport, FeeRecord, bool>>? expr1 = null)
|
|
{
|
|
//海运出口
|
|
var query1 = TenantDb.Queryable<SeaExport>()
|
|
.InnerJoin<FeeRecord>((s, f) => s.Id == f.BusinessId && f.BusinessType == BusinessType.OceanShippingExport)
|
|
.WhereIF(expr1 != null, expr1)
|
|
.Select((s, f) => new BusinessFeeDto
|
|
{
|
|
BusinessId = s.Id,
|
|
BusinessType = BusinessType.OceanShippingExport,
|
|
AccountDate = s.AccountDate,
|
|
CntrTotal = s.CntrTotal,
|
|
CreateBy = s.CreateBy,
|
|
CustomerNo = s.CustomerNo,
|
|
ClientName = s.CustomerName, //委托单位
|
|
ETD = s.ETD,
|
|
HBLNO = s.HBLNO,
|
|
MBLNO = s.MBLNO,
|
|
LoadPort = s.LoadPort,
|
|
DischargePort = s.DischargePort,
|
|
|
|
OperatorId = s.OperatorId,
|
|
SaleDeptId = s.SaleDeptId,
|
|
SaleId = s.SaleId,
|
|
Sale = s.Sale,//揽货人
|
|
Vessel = s.Vessel,//船名
|
|
Voyage = s.Voyno,//航次
|
|
BookingNo = s.BookingNo,
|
|
CustomerNum = s.CustomerNum,
|
|
StlName = s.StlName,
|
|
InvoiceNo = s.InvoiceNo,
|
|
|
|
RecordId = f.Id,
|
|
FeeType = f.FeeType,
|
|
FeeStatus = f.FeeStatus,
|
|
CustomerId = f.CustomerId,//费用对象
|
|
CustomerName = f.CustomerName,
|
|
FeeId = f.FeeId,
|
|
FeeName = f.FeeName,
|
|
Currency = f.Currency,
|
|
Amount = f.Amount,
|
|
ExchangeRate = f.ExchangeRate,
|
|
OrderAmount = f.OrderAmount,
|
|
InvoiceAmount = f.InvoiceAmount,
|
|
SettlementAmount = f.SettlementAmount,
|
|
OrderSettlementAmount = f.OrderSettlementAmount,
|
|
OrderInvSettlementAmount = f.OrderInvSettlementAmount,
|
|
TaxRate = f.TaxRate,
|
|
AccTaxRate = f.AccTaxRate,
|
|
IsDebit = f.IsDebit,
|
|
DebitNo = f.DebitNo,
|
|
IsInvoice = f.IsInvoice,
|
|
SaleOrgId = f.SaleOrgId,
|
|
});
|
|
|
|
//海运进口
|
|
|
|
|
|
return TenantDb.UnionAll(new List<ISugarQueryable<BusinessFeeDto>> { query1 });
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取汇率
|
|
/// </summary>
|
|
/// <param name="items"></param>
|
|
/// <returns></returns>
|
|
protected internal async Task FetchExchangeRateAsync(IEnumerable<FeeRecord> items)
|
|
{
|
|
var exRecords = items.Where(x => x.Currency != x.LocalCurrency && x.ExchangeRate == null);
|
|
if (exRecords.Any())
|
|
{
|
|
var exchanges = exRecords.GroupBy(x => new
|
|
{
|
|
x.Currency,
|
|
x.LocalCurrency,
|
|
x.FeeType,
|
|
}).Select(x => new ExchangeRate
|
|
{
|
|
CurrencyFrom = x.Key.Currency,
|
|
CurrencyTo = x.Key.LocalCurrency,
|
|
FeeType = x.Key.FeeType
|
|
});
|
|
|
|
List<ExchangeRate> exchangeRates = [];
|
|
foreach (var item in exchanges)
|
|
{
|
|
var result = await exchangeService.Value.GetExchangeRateAsync(item);
|
|
if (result.Succeeded && result.Data != null)
|
|
exchangeRates.Add(result.Data);
|
|
}
|
|
|
|
foreach (var item in items)
|
|
{
|
|
item.ExchangeRate = exchangeRates.Find(x => x.CurrencyFrom == item.Currency &&
|
|
x.CurrencyTo == item.LocalCurrency && x.FeeType == item.FeeType)?.Rate;
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取当前登录用户的待审批工作流的查询对象
|
|
/// </summary>
|
|
/// <param name="auditTypes">审核类型</param>
|
|
/// <returns></returns>
|
|
protected internal ISugarQueryable<FlowInstance> GetCurrentFlowsQuery(params TaskBaseTypeEnum[] auditTypes)
|
|
{
|
|
return Db.Queryable<FlowInstance>().Where(x => x.FlowStatus == FlowStatusEnum.Running
|
|
&& SqlFunc.SplitIn(x.MakerList, User.UserId) && auditTypes.Contains(x.AuditType.Value))
|
|
.Select(x => new FlowInstance { Id = x.Id, BusinessId = x.BusinessId, BusinessType = x.BusinessType });
|
|
}
|
|
}
|
|
}
|