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.

131 lines
5.1 KiB
C#

using DS.Module.Core;
using DS.Module.Core.Extensions;
using DS.Module.SqlSugar;
using DS.Module.UserModule;
using DS.WMS.Core.Fee.Dtos;
using DS.WMS.Core.Fee.Entity;
using DS.WMS.Core.Flow.Dtos;
using DS.WMS.Core.Info.Entity;
using DS.WMS.Core.Invoice.Dtos;
using DS.WMS.Core.Op.Dtos;
using DS.WMS.Core.Op.Dtos.TaskInteraction;
using DS.WMS.Core.Op.Entity;
using DS.WMS.Core.Op.Interface;
using DS.WMS.Core.Op.Interface.TaskInteraction;
using DS.WMS.Core.Op.Method.TaskInteraction;
using LanguageExt.Common;
using LanguageExt.Pipes;
using Mapster;
using Microsoft.Extensions.DependencyInjection;
using NPOI.SS.Formula.Functions;
using Org.BouncyCastle.Ocsp;
using SqlSugar;
using System.Drawing;
namespace DS.WMS.Core.Op.Method
{
/// <summary>
/// 海运出口退仓接口
/// </summary>
public class SeaExportChangeETDService : ISeaExportChangeETDService
{
private readonly IServiceProvider _serviceProvider;
private readonly ISqlSugarClient db;
private readonly IUser user;
private readonly ISaasDbService saasService;
readonly ITaskService taskService;
private readonly ISeaExportCommonService seaComService;
/// <summary>
///
/// </summary>
/// <param name="serviceProvider"></param>
public SeaExportChangeETDService(IServiceProvider serviceProvider)
{
_serviceProvider = serviceProvider;
db = _serviceProvider.GetRequiredService<ISqlSugarClient>();
user = _serviceProvider.GetRequiredService<IUser>();
saasService = _serviceProvider.GetRequiredService<ISaasDbService>();
seaComService = _serviceProvider.GetRequiredService<ISeaExportCommonService>();
taskService = serviceProvider.GetRequiredService<ITaskService>();
}
#region 发起改配
public async Task<DataResult> CreateChangeETDTaskAsync(RefundTaskReq req)
{
var tenantDb = saasService.GetBizDbScopeById(user.TenantId);
var info = await tenantDb.Queryable<SeaExport>().Where(x => x.Id == req.Id).FirstAsync();
if (info.IsNull())
return await Task.FromResult(DataResult.Failed("不存在的海运出口信息!", MultiLanguageConst.SeaExportExist));
if (!req.IsReserveFee && tenantDb.Queryable<FeeRecord>().Where(x => x.BusinessId == req.Id).Any())
{
return await Task.FromResult(DataResult.Failed("存在业务相关费用,是否保留费用?"));
}
if (req.IsReserveFee && tenantDb.Queryable<FeeRecord>().Where(x => x.BusinessId == req.Id && x.FeeStatus == FeeStatus.Entering).Any())
{
return await Task.FromResult(DataResult.Failed("存在录入状态的费用!"));
}
var taskReq = new TaskCreationRequest()
{
BusinessId = req.Id,
BusinessType = BusinessType.OceanShippingExport,
TaskTypeName = TaskBaseTypeEnum.RETURN_CABIN.ToString(),
};
var result = await taskService.CreateTaskAsync(taskReq, false);
if (!result.Succeeded)
{
return await Task.FromResult(DataResult.Failed(result.Message));
}
else {
await seaComService.SetGoodsStatus("YFTC", req.Id, tenantDb);
return await Task.FromResult(DataResult.Successed(result.Message));
}
}
#endregion
/// <summary>
/// 改配审核完成回调
/// </summary>
/// <param name="callback">回调信息</param>
/// <returns></returns>
public async Task<DataResult> ChangeETDAuditCallbackAsync(FlowCallback callback)
{
var tenantDb = saasService.GetBizDbScopeById(user.TenantId);
if (callback.AuditType != TaskBaseTypeEnum.RETURN_CABIN)
return DataResult.FailedWithDesc(nameof(MultiLanguageConst.NoAuditItems));
var info = await tenantDb.Queryable<SeaExport>().Where(x => x.Id == callback.BusinessId).FirstAsync();
if (info.IsNull())
return await Task.FromResult(DataResult.Failed("不存在的海运出口信息!", MultiLanguageConst.SeaExportExist));
var oldOrder = info.Adapt<SeaExport>();
info.IsRefund = callback.FlowStatus == FlowStatusEnum.Approve ? true : false;
int rows = await tenantDb.Updateable(info).UpdateColumns(x => new
{
x.IsRefund,
}).ExecuteCommandAsync();
await seaComService.SetGoodsStatus("YTC", callback.BusinessId, tenantDb);
await seaComService.SaveSeaExportLogAsync(new SeaExportSaveLog()
{
OperateType = "Update",
OldOrder = oldOrder,
NewOrder = info,
SourceCode = "ChangeETDAuditCallbackAsync",
SourceName = "改配审核完成回调",
}, tenantDb);
return rows > 0 ? DataResult.Success : DataResult.FailedWithDesc(nameof(MultiLanguageConst.Operation_Failed));
}
}
}