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