优化自动费用模板

dev
嵇文龙 1 month ago
parent 753647082a
commit f2430a08fb

@ -38,7 +38,7 @@ public interface IFeeRecordService
/// <param name="excludeZeroFee">是否排除总价为零的费用默认为false</param>
/// <param name="useTransaction">是否使用事务默认为true</param>
/// <returns></returns>
Task<DataResult> SaveAsync(IEnumerable<FeeRecord> items, bool excludeZeroFee = false, bool useTransaction = true);
Task<DataResult> SaveAsync(List<FeeRecord> items, bool excludeZeroFee = false, bool useTransaction = true);
/// <summary>
/// 费用保存后提交审核
@ -47,7 +47,7 @@ public interface IFeeRecordService
/// <param name="excludeZeroFee">是否排除总价为零的费用</param>
/// <param name="useTransaction">是否使用事务</param>
/// <returns></returns>
Task<DataResult> SaveAndSubmitAsync(IEnumerable<FeeRecord> items, bool excludeZeroFee = false, bool useTransaction = true);
Task<DataResult> SaveAndSubmitAsync(List<FeeRecord> items, bool excludeZeroFee = false, bool useTransaction = true);
/// <summary>
/// 根据费用模板引入

@ -75,7 +75,14 @@ namespace DS.WMS.Core.Fee.Method
var tids = list.Select(x => x.Id);
var orders = await TenantDb.Queryable<SeaExport>().Where(x => SqlFunc.DateIsSame(x.ETD, etd) &&
SqlFunc.Subqueryable<FeeCustTemplateRecord>().Where(y => y.BusinessId == x.Id && y.BusinessType == BusinessType.OceanShippingExport && tids.Contains(y.TemplateId)).NotAny())
.Select<SeaExportRes>().ToListAsync();
.Select(x => new SeaExportRes
{
CtnInfo = SqlFunc.Subqueryable<OpCtn>().Where(y => y.BSNO == x.Id.ToString()).ToList(y => new OpCtnRes
{
Ctn = y.Ctn,
CtnNum = SqlFunc.IsNull(y.CtnNum.Value, 0)
})
}, true).ToListAsync();
if (orders.Count == 0)
return;
@ -83,23 +90,25 @@ namespace DS.WMS.Core.Fee.Method
await TenantDb.Ado.BeginTranAsync();
try
{
var localCurrecy = await Db.Queryable<SysOrg>().Where(x => x.Id == User.OrgId).Select(x => x.LocalCurrency).FirstAsync();
foreach (var order in orders)
{
var custList = list.Where(x => x.CustomerId == order.CustomerId).OrderBy(x => x.Priority);
foreach (var template in custList) //遍历客户费用模板,查找匹配项
{
var fees = await CreateFeesIfMatchAsync(order, template);
var fees = await CreateFeesIfMatchAsync(order, template, localCurrecy);
if (fees != null)
{
feeList.AddRange(fees);
var record = new FeeCustTemplateRecord
{
BusinessId = order.CustomerId,
BusinessId = order.Id,
BusinessType = BusinessType.OceanShippingExport,
CreateBy = long.Parse(User.UserId),
CreateTime = dt,
FeeCategoryId = template.FeeCategoryId,
FeeCategoryId = string.IsNullOrEmpty(template.FeeCategoryId) ? null : template.FeeCategoryId,
FeeType = template.FeeType,
TemplateId = template.Id
};
@ -113,18 +122,18 @@ namespace DS.WMS.Core.Fee.Method
var sharedList = list.Where(x => x.IsShared).OrderBy(x => x.Priority).ToList();
foreach (var template in sharedList)
{
var fees = await CreateFeesIfMatchAsync(order, template);
var fees = await CreateFeesIfMatchAsync(order, template, localCurrecy);
if (fees != null)
{
feeList.AddRange(fees);
var record = new FeeCustTemplateRecord
{
BusinessId = order.CustomerId,
BusinessId = order.Id,
BusinessType = BusinessType.OceanShippingExport,
CreateBy = long.Parse(User.UserId),
CreateTime = dt,
FeeCategoryId = template.FeeCategoryId,
FeeCategoryId = string.IsNullOrEmpty(template.FeeCategoryId) ? null : template.FeeCategoryId,
FeeType = template.FeeType,
TemplateId = template.Id
};
@ -157,7 +166,7 @@ namespace DS.WMS.Core.Fee.Method
}
}
private async Task<List<FeeRecord>?> CreateFeesIfMatchAsync(SeaExportRes order, FeeCustTemplate template)
private async Task<List<FeeRecord>?> CreateFeesIfMatchAsync(SeaExportRes order, FeeCustTemplate template, string localCurrecy)
{
if (!string.IsNullOrEmpty(template.POLCode) && template.POLCode != order.LoadPortCode)
return null;
@ -165,7 +174,7 @@ namespace DS.WMS.Core.Fee.Method
if (!string.IsNullOrEmpty(template.PODCode) && template.PODCode != order.DischargePortCode)
return null;
if (!string.IsNullOrEmpty(template.MBLFrtCode) && template.MBLFrtCode != order.MBLFrtCode)
if (!string.IsNullOrEmpty(template.MBLFrtCode) && template.MBLFrtCode != order.MBLFrt)
return null;
if (template.LaneId.HasValue && template.LaneId != order.LaneId)
@ -191,38 +200,62 @@ namespace DS.WMS.Core.Fee.Method
x.FeeType == template.FeeType && x.FeeCategoryId == template.FeeCategoryId))
return null;
var details = await TenantDb.Queryable<FeeCustTemplateDetail>().Where(y => y.TemplateId == template.Id)
.Select(x => new FeeRecord
var templateDetails = await TenantDb.Queryable<FeeCustTemplateDetail>().Where(y => y.TemplateId == template.Id).ToListAsync();
var groups = templateDetails.GroupBy(x => new
{
x.FeeId,
x.Unit
}).ToList();
List<FeeRecord> fees = new(groups.Count);
foreach (var g in groups)
{
FeeCustTemplateDetail? detail = null;
int qty = 0;
if (string.Equals(g.Key.Unit, "P", StringComparison.OrdinalIgnoreCase))
{
detail = g.FirstOrDefault()!;
qty = detail.IsCtn ? 0 : 1;
}
else
{
var ctn = order.CtnInfo?.Find(x => x.Ctn == g.Key.Unit);
if (ctn == null)
continue;
detail = g.FirstOrDefault(x => x.Unit == ctn.Ctn);
qty = ctn.CtnNum;
}
var fee = new FeeRecord
{
BusinessId = order.Id,
BusinessType = BusinessType.OceanShippingExport,
FeeType = template.FeeType,
FeeId = x.FeeId,
FeeCode = x.FeeCode,
FeeName = x.FeeName,
CustomerId = x.CustomerId,
CustomerName = x.CustomerName,
CustomerType = x.CustomerType,
Unit = x.Unit,
UnitPrice = SqlFunc.IsNull(x.UnitPrice.Value, 0),
//Quantity = x.IsCtn ? 1 : 0,
Currency = x.Currency,
ExchangeRate = x.ExchangeRate,
TaxRate = SqlFunc.IsNull(x.TaxRate.Value, 0),
AccTaxRate = SqlFunc.IsNull(x.AccTaxRate.Value, 0),
Tax = SqlFunc.IsNull(x.Tax.Value, 0),
TaxUnitPrice = SqlFunc.IsNull(x.TaxUnitPrice.Value, 0),
IsInvoice = x.IsInvoice,
IsAdvancedPay = x.IsAdvancedPay,
FeeId = g.Key.FeeId,
Unit = g.Key.Unit,
Remark = template.FeeCategoryName,
TemplateId = x.TemplateId,
InputMethod = InputMethod.Automatic
}).ToListAsync();
TemplateId = template.Id,
CustomerId = detail.CustomerId,
CustomerName = detail.CustomerName,
CustomerType = detail.CustomerType,
InputMethod = InputMethod.Automatic,
Quantity = qty,
FeeCode = detail.FeeCode,
FeeName = detail.FeeName,
UnitPrice = detail.UnitPrice.GetValueOrDefault(),
Currency = detail.Currency,
ExchangeRate = detail.ExchangeRate,
TaxRate = detail.TaxRate.GetValueOrDefault(),
AccTaxRate = detail.AccTaxRate.GetValueOrDefault(),
Tax = detail.Tax.GetValueOrDefault(),
TaxUnitPrice = detail.TaxUnitPrice.GetValueOrDefault(),
IsInvoice = detail.IsInvoice,
IsAdvancedPay = detail.IsAdvancedPay
};
var localCurrecy = await Db.Queryable<SysOrg>().Where(x => x.Id == User.OrgId).Select(x => x.LocalCurrency).FirstAsync();
foreach (var detail in details)
{
if (detail.ExchangeRate.GetValueOrDefault() == 0 && detail.Currency != localCurrecy)
if (fee.ExchangeRate.GetValueOrDefault() == 0 && fee.Currency != localCurrecy)
{
var er = await exchangeService.Value.GetExchangeRateAsync(new ExchangeRate
{
@ -230,76 +263,74 @@ namespace DS.WMS.Core.Fee.Method
CurrencyTo = localCurrecy,
FeeType = template.FeeType
});
fee.ExchangeRate = er.Data?.Rate;
}
if (detail.CustomerId == 0)
if (fee.CustomerId == 0)
{
switch (detail.CustomerType)
switch (fee.CustomerType)
{
case "controller":
detail.CustomerId = order.CustomerId;
detail.CustomerName = order.CustomerName;
fee.CustomerId = order.CustomerId;
fee.CustomerName = order.CustomerName;
break;
case "yard":
detail.CustomerId = order.YardId;
detail.CustomerName = order.Yard;
fee.CustomerId = order.YardId;
fee.CustomerName = order.Yard;
break;
case "custom":
detail.CustomerId = order.CustomserId;
detail.CustomerName = order.Customser;
fee.CustomerId = order.CustomserId;
fee.CustomerName = order.Customser;
break;
case "contract":
detail.CustomerId = order.ContractClientId;
detail.CustomerName = order.ContractClientName;
fee.CustomerId = order.ContractClientId;
fee.CustomerName = order.ContractClientName;
break;
case "shipagency":
detail.CustomerId = order.ShipAgencyId;
detail.CustomerName = order.ShipAgency;
fee.CustomerId = order.ShipAgencyId;
fee.CustomerName = order.ShipAgency;
break;
case "shipper":
detail.CustomerId = order.ShipperId.GetValueOrDefault();
detail.CustomerName = order.Shipper;
fee.CustomerId = order.ShipperId.GetValueOrDefault();
fee.CustomerName = order.Shipper;
break;
case "truck":
detail.CustomerId = order.TruckerId;
detail.CustomerName = order.Trucker;
fee.CustomerId = order.TruckerId;
fee.CustomerName = order.Trucker;
break;
case "booking":
detail.CustomerId = order.ForwarderId;
detail.CustomerName = order.Forwarder;
break;
case "carrier":
detail.CustomerId = order.CarrierId;
detail.CustomerName = order.Carrier;
fee.CustomerId = order.ForwarderId;
fee.CustomerName = order.Forwarder;
break;
case "wareHouse":
detail.CustomerId = order.WareHouseId;
detail.CustomerName = order.WareHouse;
fee.CustomerId = order.WareHouseId;
fee.CustomerName = order.WareHouse;
break;
case "shippercn":
detail.CustomerId = order.ShipperCnId.GetValueOrDefault();
detail.CustomerName = order.ShipperCn;
fee.CustomerId = order.ShipperCnId.GetValueOrDefault();
fee.CustomerName = order.ShipperCn;
break;
case "agent":
detail.CustomerId = order.AgentId.GetValueOrDefault();
detail.CustomerName = order.Agent;
fee.CustomerId = order.AgentId.GetValueOrDefault();
fee.CustomerName = order.Agent;
break;
}
}
fees.Add(fee);
}
return details;
return fees;
}
/// <summary>

@ -24,6 +24,9 @@ namespace DS.WMS.Core.Fee.Method
/// </summary>
public class FeeRecordService : FeeServiceBase, IFeeRecordService
{
const int BATCH_SIZE = 300;
const TaskBaseTypeEnum BIZ_TASK_TYPE = TaskBaseTypeEnum.FEE_BUSINESS_AUDIT;
readonly IClientFlowInstanceService flowService;
readonly ITaskService taskService;
@ -151,7 +154,7 @@ namespace DS.WMS.Core.Fee.Method
/// <param name="excludeZeroFee">是否排除总价为零的费用</param>
/// <param name="useTransaction">是否使用事务</param>
/// <returns></returns>
public async Task<DataResult> SaveAsync(IEnumerable<FeeRecord> items, bool excludeZeroFee = false, bool useTransaction = true)
public async Task<DataResult> SaveAsync(List<FeeRecord> items, bool excludeZeroFee = false, bool useTransaction = true)
{
ArgumentNullException.ThrowIfNull(items, nameof(items));
@ -245,7 +248,7 @@ namespace DS.WMS.Core.Fee.Method
}
if (excludeZeroFee) //过滤掉数量为0的费用
items = items.Where(x => x.Amount != 0);
items = items.FindAll(x => x.Amount != 0);
DateTime dtNow = DateTime.Now;
if (useTransaction)
@ -317,7 +320,16 @@ namespace DS.WMS.Core.Fee.Method
var createList = items.Where(x => x.Id == 0).ToList();
if (createList.Count > 0)
await TenantDb.Insertable(createList).ExecuteCommandAsync();
{
if (createList.Count >= BATCH_SIZE)
{
await TenantDb.Fastest<FeeRecord>().BulkCopyAsync(createList);
}
else
{
await TenantDb.Insertable(createList).ExecuteCommandAsync();
}
}
if (useTransaction)
await TenantDb.Ado.CommitTranAsync();
@ -345,7 +357,7 @@ namespace DS.WMS.Core.Fee.Method
/// <param name="excludeZeroFee">是否排除总价为零的费用</param>
/// <param name="useTransaction">是否使用事务</param>
/// <returns></returns>
public async Task<DataResult> SaveAndSubmitAsync(IEnumerable<FeeRecord> items, bool excludeZeroFee = false, bool useTransaction = true)
public async Task<DataResult> SaveAndSubmitAsync(List<FeeRecord> items, bool excludeZeroFee = false, bool useTransaction = true)
{
var result = await SaveAsync(items, excludeZeroFee, useTransaction);
if (!result.Succeeded)
@ -806,7 +818,7 @@ namespace DS.WMS.Core.Fee.Method
{
BusinessId = item.Item2,
TaskTypeName = item.Item1.ToString(),
ExtraData = fees.Find(x=>x.Id == item.Item2)
ExtraData = fees.Find(x => x.Id == item.Item2)
}, false);
if (!result.Succeeded)
@ -841,7 +853,6 @@ namespace DS.WMS.Core.Fee.Method
}
const TaskBaseTypeEnum BIZ_TASK_TYPE = TaskBaseTypeEnum.FEE_BUSINESS_AUDIT;
/// <summary>
/// 整票审核
/// </summary>

@ -14,7 +14,6 @@ using DS.WMS.Core.TaskInteraction.Dtos;
using DS.WMS.Core.TaskInteraction.Interface;
using Masuit.Tools.Systems;
using Microsoft.Extensions.DependencyInjection;
using Org.BouncyCastle.Ocsp;
using SqlSugar;
namespace DS.WMS.Core.Info.Method
@ -303,11 +302,11 @@ namespace DS.WMS.Core.Info.Method
stakeholders.Add(stakeholder);
}
if (sb.Length > 0)
{
sb.Remove(0, 1);
return DataResult.Failed("下列数据匹配不到客户/供应商或干系人信息:" + sb.ToString());
}
//if (sb.Length > 0)
//{
// sb.Remove(0, 1);
// return DataResult.Failed("下列数据匹配不到客户/供应商或干系人信息:" + sb.ToString());
//}
await TenantDb.Ado.BeginTranAsync();
try

@ -97,6 +97,7 @@ namespace DS.WMS.FeeApi.Controllers
item.BusinessId = recordSubmit.BusinessId;
item.BusinessType = recordSubmit.BusinessType;
item.FeeStatus = FeeStatus.Entering;
item.InputMethod = InputMethod.Manual;
}
return await _feeService.SaveAsync(recordSubmit.Items);
}
@ -120,6 +121,7 @@ namespace DS.WMS.FeeApi.Controllers
item.BusinessId = recordSubmit.BusinessId;
item.BusinessType = recordSubmit.BusinessType;
item.FeeStatus = FeeStatus.Entering;
item.InputMethod = InputMethod.Manual;
}
return await _feeService.SaveAndSubmitAsync(recordSubmit.Items);
}

Loading…
Cancel
Save