|
|
|
|
using DS.Module.Core;
|
|
|
|
|
using DS.Module.Core.Condition;
|
|
|
|
|
using DS.Module.Core.Data;
|
|
|
|
|
using DS.Module.Core.Extensions;
|
|
|
|
|
using DS.WMS.Core.Fee.Entity;
|
|
|
|
|
using DS.WMS.Core.Fee.Interface;
|
|
|
|
|
using DS.WMS.Core.Op.Entity;
|
|
|
|
|
using DS.WMS.Core.Op.Interface.TaskInteraction;
|
|
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
|
using Newtonsoft.Json;
|
|
|
|
|
using SqlSugar;
|
|
|
|
|
|
|
|
|
|
namespace DS.WMS.Core.Fee.Method
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 往来单位费用模板
|
|
|
|
|
/// </summary>
|
|
|
|
|
public class FeeCustTemplateService : FeeServiceBase
|
|
|
|
|
{
|
|
|
|
|
Lazy<IActionManagerService> actionService;
|
|
|
|
|
Lazy<IFeeRecordService> feeService;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 初始化
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="serviceProvider"></param>
|
|
|
|
|
public FeeCustTemplateService(IServiceProvider serviceProvider) : base(serviceProvider)
|
|
|
|
|
{
|
|
|
|
|
actionService = new Lazy<IActionManagerService>(serviceProvider.GetRequiredService<IActionManagerService>());
|
|
|
|
|
feeService = new Lazy<IFeeRecordService>(serviceProvider.GetRequiredService<IFeeRecordService>());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 根据业务ID与类型生成费用
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="bsId">业务ID</param>
|
|
|
|
|
/// <param name="businessType">业务类型</param>
|
|
|
|
|
/// <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
|
|
|
|
|
{
|
|
|
|
|
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();
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
|
|
List<FeeRecord> feeList = [];
|
|
|
|
|
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
|
|
|
|
|
{
|
|
|
|
|
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()
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
feeList.AddRange(fees);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (feeList.Count > 0)
|
|
|
|
|
{
|
|
|
|
|
var result = await feeService.Value.SaveAsync(feeList);
|
|
|
|
|
if (!result.Succeeded)
|
|
|
|
|
{
|
|
|
|
|
//记录失败日志
|
|
|
|
|
await new ApplicationException(result.Message).LogAsync(Db);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 列表
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="request"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public async Task<DataResult<List<FeeCustTemplate>>> GetListAsync(PageRequest request)
|
|
|
|
|
{
|
|
|
|
|
var whereList = request.GetConditionalModels(Db);
|
|
|
|
|
return await TenantDb.Queryable<FeeCustTemplate>().Select(x => new FeeCustTemplate
|
|
|
|
|
{
|
|
|
|
|
Id = x.Id,
|
|
|
|
|
BusinessType = x.BusinessType,
|
|
|
|
|
FeeType = x.FeeType,
|
|
|
|
|
Name = x.Name,
|
|
|
|
|
IsShared = x.IsShared,
|
|
|
|
|
Note = x.Note,
|
|
|
|
|
CreateBy = x.CreateBy,
|
|
|
|
|
CreateTime = x.CreateTime
|
|
|
|
|
}).Where(whereList).ToQueryPageAsync(request.PageCondition);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 详情
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="id"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public async Task<DataResult<FeeCustTemplate>> GetAsync(long id)
|
|
|
|
|
{
|
|
|
|
|
var data = await TenantDb.Queryable<FeeCustTemplate>().Where(x => x.Id == id)
|
|
|
|
|
.Includes(x => x.Details).FirstAsync();
|
|
|
|
|
return DataResult<FeeCustTemplate>.Success(data, MultiLanguageConst.DataQuerySuccess);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 编辑
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="model"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public async Task<DataResult> EditAsync(FeeCustTemplate model)
|
|
|
|
|
{
|
|
|
|
|
if (model.Details.Count > 0)
|
|
|
|
|
{
|
|
|
|
|
long userId = long.Parse(User.UserId);
|
|
|
|
|
DateTime dt = DateTime.Now;
|
|
|
|
|
foreach (var item in model.Details)
|
|
|
|
|
{
|
|
|
|
|
item.TemplateId = model.Id;
|
|
|
|
|
item.CreateBy = userId;
|
|
|
|
|
item.CreateTime = dt;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool flag;
|
|
|
|
|
if (model.Id == 0)
|
|
|
|
|
{
|
|
|
|
|
flag = await TenantDb.InsertNav(model).Include(x => x.Details).ExecuteCommandAsync();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
flag = await TenantDb.Updateable(model).ExecuteCommandAsync() > 0;
|
|
|
|
|
flag = await TenantDb.Storageable(model.Details).DefaultAddElseUpdate().ExecuteCommandAsync() > 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return flag ? DataResult.Successed("添加成功!", model.Id, MultiLanguageConst.DataCreateSuccess)
|
|
|
|
|
: DataResult.FailedWithDesc(MultiLanguageConst.Operation_Failed);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 根据ID批量删除
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="model"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public async Task<DataResult> DeleteAsync(IdModel model)
|
|
|
|
|
{
|
|
|
|
|
bool flag = await TenantDb.DeleteNav<FeeCustTemplate>(x => model.Ids.Contains(x.Id))
|
|
|
|
|
.Include(x => x.Details).ExecuteCommandAsync();
|
|
|
|
|
return flag ? DataResult.Success : DataResult.FailedWithDesc(nameof(MultiLanguageConst.Operation_Failed));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|