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 { /// /// 生成预任务通用帮助类 /// public class BuildPreTaskHelper { private static Lazy<(IUserManager userManager, IBillRullService billRullService, IWareHouseService wareHouseService, ISqlSugarRepository repository)> lazy; static BuildPreTaskHelper() { lazy = new Lazy<(IUserManager userManager, IBillRullService billRullService, IWareHouseService wareHouseService, ISqlSugarRepository repository)>(() => { var userManager = App.GetRequiredService(); var billRullService = App.GetRequiredService(); var warehouseService = App.GetRequiredService(); var repository = App.GetRequiredService>(); return (userManager, billRullService, warehouseService, repository); }); } public static Func> GenPretaskCurried(TEntity? entity, string bizType, string taskType, List? codes = default) where TEntity : BaseEntity, 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() { 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 { preTask.startlocation_id, preTask.endlocation_id }; preTaskUpInput.PreTaskRecords = preTasks.Adapt>(); preTaskUpInput.PreTaskRecords.ForEach(x => x.id = SnowflakeIdHelper.NextId()); WmsHandleH handleH = preTask.Adapt(); handleH.id = SnowflakeIdHelper.NextId(); handleH.create_time = DateTime.Now; preTaskUpInput.PreTaskRecord = handleH; if (codes?.Count > 0) { var handleCodes = codes.Adapt>(); handleCodes.ForEach(c => { c.id = SnowflakeIdHelper.NextId(); c.bill_id = handleH.id; c.create_time = DateTime.Now; }); preTaskUpInput.PreTaskHandleCodes = handleCodes; } } return preTaskUpInput; }; } } }