Files
tnb.server/WarehouseMgr/Tnb.WarehouseMgr/BuildPreTaskHelper.cs
yang.lee 71c4dbd254 1、新增预任务生成帮助类
2、齐套配送接口参数调整
2023-11-23 14:13:03 +08:00

131 lines
5.9 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Tnb.WarehouseMgr.Entities.Consts;
using Tnb.WarehouseMgr.Entities;
using Tnb.WarehouseMgr.Interfaces;
using JNPF.Common.Core.Manager;
using JNPF.Systems.Interfaces.System;
using JNPF.Common.Contracts;
using JNPF.Common.Extension;
using Tnb.Common.Utils;
using Microsoft.Extensions.DependencyInjection;
using JNPF;
using Tnb.WarehouseMgr.Entities.Dto;
using Mapster;
using JNPF.Common.Security;
using NPOI.OpenXmlFormats;
using SqlSugar;
using Tnb.BasicData.Entities;
using Microsoft.AspNetCore.Mvc;
using Spire.Doc;
namespace Tnb.WarehouseMgr
{
/// <summary>
/// 生成预任务通用帮助类
/// </summary>
public class BuildPreTaskHelper
{
private static Lazy<(IUserManager userManager, IBillRullService billRullService, IWareHouseService wareHouseService, ISqlSugarRepository<WmsInstockH> repository)> lazy;
static BuildPreTaskHelper()
{
lazy = new Lazy<(IUserManager userManager, IBillRullService billRullService, IWareHouseService wareHouseService, ISqlSugarRepository<WmsInstockH> repository)>(() =>
{
var userManager = App.GetRequiredService<IUserManager>();
var billRullService = App.GetRequiredService<IBillRullService>();
var warehouseService = App.GetRequiredService<IWareHouseService>();
var repository = App.GetRequiredService<ISqlSugarRepository<WmsInstockH>>();
return (userManager, billRullService, warehouseService, repository);
});
}
public static Func<WmsCarryH, WmsPointH, WmsPointH, Task< GenPreTaskUpInput>> GenPretaskCurried<TEntity>(TEntity? entity, string bizType, string taskType, List<WmsPretaskCode>? codes = default)
where TEntity : BaseEntity<string>, new()
{
return async (carry, sPoint, ePoint) =>
{
var _db = lazy.Value.repository.AsSugarClient();
WmsPretaskH preTask = new()
{
org_id = lazy.Value.userManager.User.OrganizeId,
startlocation_id = sPoint?.location_id!,
startlocation_code = sPoint?.location_code!,
endlocation_id = ePoint?.location_id!,
endlocation_code = ePoint?.location_code!,
start_floor = sPoint?.floor.ToString(),
end_floor = ePoint?.floor.ToString(),
startpoint_id = sPoint?.id!,
startpoint_code = sPoint?.point_code!,
endpoint_id = ePoint?.id!,
endpoint_code = ePoint?.point_code!,
bill_code = lazy.Value.billRullService.GetBillNumber(WmsWareHouseConst.WMS_PRETASK_H_ENCODE).GetAwaiter().GetResult(),
status = WmsWareHouseConst.PRETASK_BILL_STATUS_DXF_ID,
biz_type = bizType,
task_type = taskType,
carry_id = carry.id,
carry_code = carry.carry_code,
area_id = sPoint?.area_id!,
area_code = sPoint!.area_code,
source_id = entity != null && ObjectPropertyChecker.HasProperty(entity, "source_id") ? entity.GetPropertyValue("source_id")?.ToString() : string.Empty,
source_code = entity != null && ObjectPropertyChecker.HasProperty(entity, "source_code") ? entity.GetPropertyValue("source_code")?.ToString() : string.Empty,
require_id = entity != null && ObjectPropertyChecker.HasProperty(entity, "id") ? entity.GetPropertyValue("id")?.ToString() : string.Empty,
require_code = entity != null && ObjectPropertyChecker.HasProperty(entity, "bill_code") ? entity.GetPropertyValue("bill_code")?.ToString() : string.Empty,
create_id = lazy.Value.userManager.UserId,
create_time = DateTime.Now,
};
if (codes?.Count > 0)
{
codes.ForEach(c =>
{
c.bill_id = preTask.id;
c.create_time = DateTime.Now;
});
}
var preTasks = new List<WmsPretaskH>() { preTask };
var isOk = await lazy.Value.wareHouseService.GenPreTask(preTasks, codes);
var preTaskUpInput = new GenPreTaskUpInput();
if (isOk)
{
preTaskUpInput.RquireId = entity?.id ?? string.Empty;
preTaskUpInput.CarryId = carry.id;
preTaskUpInput.CarryStartLocationId = preTask.startlocation_id;
preTaskUpInput.CarryStartLocationCode = preTask.startlocation_code;
preTaskUpInput.LocationIds = new List<string> { preTask.startlocation_id, preTask.endlocation_id };
preTaskUpInput.PreTaskRecords = preTasks.Adapt<List<WmsHandleH>>();
preTaskUpInput.PreTaskRecords.ForEach(x => x.id = SnowflakeIdHelper.NextId());
WmsHandleH handleH = preTask.Adapt<WmsHandleH>();
handleH.id = SnowflakeIdHelper.NextId();
handleH.create_time = DateTime.Now;
preTaskUpInput.PreTaskRecord = handleH;
if (codes?.Count > 0)
{
var handleCodes = codes.Adapt<List<WmsHandleCode>>();
handleCodes.ForEach(c =>
{
c.id = SnowflakeIdHelper.NextId();
c.bill_id = handleH.id;
c.create_time = DateTime.Now;
});
preTaskUpInput.PreTaskHandleCodes = handleCodes;
}
}
return preTaskUpInput;
};
}
}
}