|
|
|
@ -15,7 +15,7 @@ namespace DS.WMS.Core.Fee.Method
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 往来单位费用模板
|
|
|
|
|
/// </summary>
|
|
|
|
|
public class FeeCustTemplateService : FeeServiceBase
|
|
|
|
|
public class FeeCustTemplateService : FeeServiceBase, IFeeCustTemplateService
|
|
|
|
|
{
|
|
|
|
|
Lazy<IActionManagerService> actionService;
|
|
|
|
|
Lazy<IFeeRecordService> feeService;
|
|
|
|
@ -38,91 +38,100 @@ namespace DS.WMS.Core.Fee.Method
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public async Task GenerateFeesAsync(long bsId, BusinessType businessType = BusinessType.OceanShippingExport)
|
|
|
|
|
{
|
|
|
|
|
var list = await TenantDb.Queryable<FeeCustTemplate>().Where(x => x.BusinessType == businessType &&
|
|
|
|
|
!SqlFunc.IsNullOrEmpty(x.Condition)).Select(x => new
|
|
|
|
|
{
|
|
|
|
|
x.Id,
|
|
|
|
|
x.FeeType,
|
|
|
|
|
x.Condition,
|
|
|
|
|
Details = x.Details.Select(y => new
|
|
|
|
|
var model = await actionService.Value.GetBusinessDataAsync(bsId, businessType, nameof(SeaExport.CustomerId));
|
|
|
|
|
long custId = model.CustomerId;
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var list = await TenantDb.Queryable<FeeCustTemplate>()
|
|
|
|
|
.Where(x => x.BusinessType == businessType && x.CustomerId == custId && !SqlFunc.IsNullOrEmpty(x.Condition))
|
|
|
|
|
.Select(x => new
|
|
|
|
|
{
|
|
|
|
|
y.FeeId,
|
|
|
|
|
y.FeeCode,
|
|
|
|
|
y.FeeName,
|
|
|
|
|
y.FeeType,
|
|
|
|
|
y.CustomerId,
|
|
|
|
|
y.CustomerName,
|
|
|
|
|
y.CustomerType,
|
|
|
|
|
y.Unit,
|
|
|
|
|
y.IsCtn,
|
|
|
|
|
y.Currency,
|
|
|
|
|
y.UnitPrice,
|
|
|
|
|
y.ExchangeRate,
|
|
|
|
|
y.TaxRate,
|
|
|
|
|
y.AccTaxRate,
|
|
|
|
|
y.Tax,
|
|
|
|
|
y.TaxUnitPrice,
|
|
|
|
|
y.IsInvoice,
|
|
|
|
|
y.IsAdvancedPay
|
|
|
|
|
})
|
|
|
|
|
}).ToListAsync();
|
|
|
|
|
x.Id,
|
|
|
|
|
x.CustomerId,
|
|
|
|
|
x.CustomerName,
|
|
|
|
|
x.CustomerType,
|
|
|
|
|
x.Condition,
|
|
|
|
|
Details = SqlFunc.Subqueryable<FeeCustTemplateDetail>().Where(y => y.TemplateId == x.Id).ToList(y => new
|
|
|
|
|
{
|
|
|
|
|
y.FeeId,
|
|
|
|
|
y.FeeCode,
|
|
|
|
|
y.FeeName,
|
|
|
|
|
y.FeeType,
|
|
|
|
|
y.Unit,
|
|
|
|
|
y.IsCtn,
|
|
|
|
|
y.Currency,
|
|
|
|
|
y.UnitPrice,
|
|
|
|
|
y.ExchangeRate,
|
|
|
|
|
y.TaxRate,
|
|
|
|
|
y.AccTaxRate,
|
|
|
|
|
y.Tax,
|
|
|
|
|
y.TaxUnitPrice,
|
|
|
|
|
y.IsInvoice,
|
|
|
|
|
y.IsAdvancedPay
|
|
|
|
|
})
|
|
|
|
|
}).ToListAsync();
|
|
|
|
|
|
|
|
|
|
if (list.Count == 0)
|
|
|
|
|
return;
|
|
|
|
|
if (list.Count == 0)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
var conditionModels = list.Select(x => new
|
|
|
|
|
{
|
|
|
|
|
x.Id,
|
|
|
|
|
ConditionModel = JsonConvert.DeserializeObject<ConditionContent>(x.Condition)
|
|
|
|
|
}).ToList();
|
|
|
|
|
var data = actionService.Value.GetBusinessDataAsync(bsId, businessType, conditionModels.Select(x => x.ConditionModel));
|
|
|
|
|
if (data == null)
|
|
|
|
|
return;
|
|
|
|
|
var conditionModels = list.Select(x => new
|
|
|
|
|
{
|
|
|
|
|
x.Id,
|
|
|
|
|
ConditionModel = JsonConvert.DeserializeObject<ConditionContent>(x.Condition)
|
|
|
|
|
}).ToList();
|
|
|
|
|
var data = await actionService.Value.GetBusinessDataAsync(bsId, businessType, conditionModels.Select(x => x.ConditionModel));
|
|
|
|
|
if (data == null)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
List<FeeRecord> feeList = [];
|
|
|
|
|
foreach (var item in list)
|
|
|
|
|
{
|
|
|
|
|
var conditionModel = conditionModels.Find(x => x.Id == item.Id)?.ConditionModel;
|
|
|
|
|
if (actionService.Value.IsMatch(data, conditionModel))
|
|
|
|
|
List<FeeRecord> feeList = [];
|
|
|
|
|
foreach (var item in list)
|
|
|
|
|
{
|
|
|
|
|
var fees = item.Details.Select(x => new FeeRecord
|
|
|
|
|
var conditionModel = conditionModels.Find(x => x.Id == item.Id)?.ConditionModel;
|
|
|
|
|
if (actionService.Value.IsMatch(data, conditionModel))
|
|
|
|
|
{
|
|
|
|
|
BusinessId = bsId,
|
|
|
|
|
BusinessType = businessType,
|
|
|
|
|
FeeType = x.FeeType,
|
|
|
|
|
FeeId = x.FeeId,
|
|
|
|
|
FeeCode = x.FeeCode,
|
|
|
|
|
FeeName = x.FeeName,
|
|
|
|
|
CustomerId = x.CustomerId,
|
|
|
|
|
CustomerName = x.CustomerName,
|
|
|
|
|
CustomerType = x.CustomerType?.ToString(),
|
|
|
|
|
Unit = x.Unit,
|
|
|
|
|
UnitPrice = x.UnitPrice.GetValueOrDefault(),
|
|
|
|
|
Currency = x.Currency,
|
|
|
|
|
//IsCtn = x.IsCtn,
|
|
|
|
|
ExchangeRate = x.ExchangeRate,
|
|
|
|
|
TaxRate = x.TaxRate.GetValueOrDefault(),
|
|
|
|
|
AccTaxRate = x.AccTaxRate.GetValueOrDefault(),
|
|
|
|
|
Tax = x.Tax.GetValueOrDefault(),
|
|
|
|
|
TaxUnitPrice = x.TaxUnitPrice.GetValueOrDefault(),
|
|
|
|
|
IsInvoice = x.IsInvoice,
|
|
|
|
|
IsAdvancedPay = x.IsAdvancedPay,
|
|
|
|
|
Amount = x.UnitPrice.GetValueOrDefault()
|
|
|
|
|
});
|
|
|
|
|
var fees = item.Details.Select(x => new FeeRecord
|
|
|
|
|
{
|
|
|
|
|
BusinessId = bsId,
|
|
|
|
|
BusinessType = businessType,
|
|
|
|
|
FeeType = x.FeeType,
|
|
|
|
|
FeeId = x.FeeId,
|
|
|
|
|
FeeCode = x.FeeCode,
|
|
|
|
|
FeeName = x.FeeName,
|
|
|
|
|
CustomerId = item.CustomerId,
|
|
|
|
|
CustomerName = item.CustomerName,
|
|
|
|
|
CustomerType = item.CustomerType?.ToString(),
|
|
|
|
|
Unit = x.Unit,
|
|
|
|
|
UnitPrice = x.UnitPrice.GetValueOrDefault(),
|
|
|
|
|
Currency = x.Currency,
|
|
|
|
|
//IsCtn = x.IsCtn,
|
|
|
|
|
ExchangeRate = x.ExchangeRate,
|
|
|
|
|
TaxRate = x.TaxRate.GetValueOrDefault(),
|
|
|
|
|
AccTaxRate = x.AccTaxRate.GetValueOrDefault(),
|
|
|
|
|
Tax = x.Tax.GetValueOrDefault(),
|
|
|
|
|
TaxUnitPrice = x.TaxUnitPrice.GetValueOrDefault(),
|
|
|
|
|
IsInvoice = x.IsInvoice,
|
|
|
|
|
IsAdvancedPay = x.IsAdvancedPay,
|
|
|
|
|
Amount = x.UnitPrice.GetValueOrDefault()
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
feeList.AddRange(fees);
|
|
|
|
|
feeList.AddRange(fees);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (feeList.Count > 0)
|
|
|
|
|
{
|
|
|
|
|
var result = await feeService.Value.SaveAsync(feeList);
|
|
|
|
|
if (!result.Succeeded)
|
|
|
|
|
if (feeList.Count > 0)
|
|
|
|
|
{
|
|
|
|
|
//记录失败日志
|
|
|
|
|
await new ApplicationException(result.Message).LogAsync(Db);
|
|
|
|
|
var result = await feeService.Value.SaveAsync(feeList);
|
|
|
|
|
if (!result.Succeeded)
|
|
|
|
|
{
|
|
|
|
|
//记录失败日志
|
|
|
|
|
await new ApplicationException(result.Message).LogAsync(Db);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
await ex.LogAsync(Db);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
@ -172,6 +181,7 @@ namespace DS.WMS.Core.Fee.Method
|
|
|
|
|
foreach (var item in model.Details)
|
|
|
|
|
{
|
|
|
|
|
item.TemplateId = model.Id;
|
|
|
|
|
item.FeeType = model.FeeType;
|
|
|
|
|
item.CreateBy = userId;
|
|
|
|
|
item.CreateTime = dt;
|
|
|
|
|
}
|
|
|
|
|