From cb24d13fff12abf1f16dd216462ce6891ebe7e80 Mon Sep 17 00:00:00 2001 From: majian <780924089@qq.com> Date: Mon, 12 Aug 2024 09:12:56 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=87=BA=E5=85=A5=E5=BA=93?= =?UTF-8?q?=E8=AE=B0=E5=BD=95=E9=80=BB=E8=BE=91=EF=BC=8C=E9=87=87=E8=B4=AD?= =?UTF-8?q?=E6=94=B6=E8=B4=A7=E8=B0=83=E6=8B=A8=E6=89=93=E5=8D=B0=E3=80=81?= =?UTF-8?q?=E7=BB=91=E5=AE=9A=E6=9D=A1=E7=A0=81=E6=9B=B4=E6=8E=A5=E5=8F=A3?= =?UTF-8?q?=E5=8F=98=E6=9B=B4=E7=AD=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Tnb.ProductionMgr/RedisBackGround.cs | 2 +- .../Consts/ModuleConsts.cs | 4 + .../Dto/Inputs/AddOutinStockDetailInput.cs | 14 ++ .../Dto/Inputs/BarCodeInput.cs | 4 + .../Dto/Inputs/CarryMaterialBindInput.cs | 2 +- .../Entity/WmsOutinStockCode.cs | 133 +++++++++++ .../Entity/WmsOutinStockDetail.cs | 162 +++++++++++++ .../IWmsOutinStockDetailService.cs | 17 ++ .../Tnb.WarehouseMgr/BaseWareHouseService.cs | 2 + .../Tnb.WarehouseMgr/ErpToWmsService.cs | 38 +++- .../Tnb.WarehouseMgr/WareHouseService.cs | 17 +- .../Tnb.WarehouseMgr/WmsCarryBindService.cs | 4 +- .../WmsMaterialTransferService.cs | 4 +- .../WmsOutinStockDetailService.cs | 212 ++++++++++++++++++ .../Tnb.WarehouseMgr/WmsPurchaseService.cs | 24 +- .../WmsRawmatTransferinstockService.cs | 22 +- .../Tnb.WarehouseMgr/WmsStockReportService.cs | 52 +++++ 17 files changed, 688 insertions(+), 25 deletions(-) create mode 100644 WarehouseMgr/Tnb.WarehouseMgr.Entities/Dto/Inputs/AddOutinStockDetailInput.cs create mode 100644 WarehouseMgr/Tnb.WarehouseMgr.Entities/Entity/WmsOutinStockCode.cs create mode 100644 WarehouseMgr/Tnb.WarehouseMgr.Entities/Entity/WmsOutinStockDetail.cs create mode 100644 WarehouseMgr/Tnb.WarehouseMgr.Interfaces/IWmsOutinStockDetailService.cs create mode 100644 WarehouseMgr/Tnb.WarehouseMgr/WmsOutinStockDetailService.cs diff --git a/ProductionMgr/Tnb.ProductionMgr/RedisBackGround.cs b/ProductionMgr/Tnb.ProductionMgr/RedisBackGround.cs index 3aefd58c..9d4d1358 100644 --- a/ProductionMgr/Tnb.ProductionMgr/RedisBackGround.cs +++ b/ProductionMgr/Tnb.ProductionMgr/RedisBackGround.cs @@ -453,7 +453,7 @@ where carry_code = '{coderesult}' and status = '{WmsWareHouseConst.TASK_BILL_STA if (WmsCarryCode != null) { - LoggerBGWCarrySupplement.LogInformation($"【ScanInStock】 八工位 {key} 查找到托盘{carry.carry_code}在WmsCarryCode中存在"); + LoggerBGWCarrySupplement.LogInformation($"【ScanInStock】 八工位 {key} 查找到托盘{carry.carry_code}在WmsCarryCode中存在"); VisualDevModelDataCrInput input = new VisualDevModelDataCrInput(); input.data = new Dictionary(); diff --git a/WarehouseMgr/Tnb.WarehouseMgr.Entities/Consts/ModuleConsts.cs b/WarehouseMgr/Tnb.WarehouseMgr.Entities/Consts/ModuleConsts.cs index 7e8ba40d..a9576987 100644 --- a/WarehouseMgr/Tnb.WarehouseMgr.Entities/Consts/ModuleConsts.cs +++ b/WarehouseMgr/Tnb.WarehouseMgr.Entities/Consts/ModuleConsts.cs @@ -121,6 +121,10 @@ public class ModuleConsts /// public const string MODULE_WMSCARRYREPLACE_ID = "26188532491557";//26188532491557 /// + /// 模块标识-出入库流水记录 todo + /// + public const string MODULE_WMSOUTINSTOCKDETAIL_ID = "MODULE_WMSOUTINSTOCKDETAIL_ID"; + /// /// 模块标识-人工空载具入库 todo /// public const string MODULE_WMSEMPTYCARRYINSTOCK_ID = "MODULE_WMSEMPTYCARRYINSTOCK_ID";// diff --git a/WarehouseMgr/Tnb.WarehouseMgr.Entities/Dto/Inputs/AddOutinStockDetailInput.cs b/WarehouseMgr/Tnb.WarehouseMgr.Entities/Dto/Inputs/AddOutinStockDetailInput.cs new file mode 100644 index 00000000..1b8c38e7 --- /dev/null +++ b/WarehouseMgr/Tnb.WarehouseMgr.Entities/Dto/Inputs/AddOutinStockDetailInput.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Tnb.WarehouseMgr.Entities.Dto.Inputs +{ + public class AddOutinStockDetailInput + { + public WmsDistaskH disTask { get; set; } + public string? warehouse_id { get; set; } + } +} diff --git a/WarehouseMgr/Tnb.WarehouseMgr.Entities/Dto/Inputs/BarCodeInput.cs b/WarehouseMgr/Tnb.WarehouseMgr.Entities/Dto/Inputs/BarCodeInput.cs index ce299495..ffa148e2 100644 --- a/WarehouseMgr/Tnb.WarehouseMgr.Entities/Dto/Inputs/BarCodeInput.cs +++ b/WarehouseMgr/Tnb.WarehouseMgr.Entities/Dto/Inputs/BarCodeInput.cs @@ -9,5 +9,9 @@ namespace Tnb.WarehouseMgr.Entities.Dto.Inputs public class BarCodeInput { public string? BillId { get; set; } + /// + /// 条码的张数 + /// + public int barcode_qty { get; set; } } } diff --git a/WarehouseMgr/Tnb.WarehouseMgr.Entities/Dto/Inputs/CarryMaterialBindInput.cs b/WarehouseMgr/Tnb.WarehouseMgr.Entities/Dto/Inputs/CarryMaterialBindInput.cs index 223ccca6..2f56d492 100644 --- a/WarehouseMgr/Tnb.WarehouseMgr.Entities/Dto/Inputs/CarryMaterialBindInput.cs +++ b/WarehouseMgr/Tnb.WarehouseMgr.Entities/Dto/Inputs/CarryMaterialBindInput.cs @@ -18,7 +18,7 @@ namespace Tnb.WarehouseMgr.Entities.Dto.Inputs public string? material_code { get; set; } public string? barcode { get; set; } public string? code_batch { get; set; } - public string? codeqty { get; set; } + public decimal codeqty { get; set; } public int is_out { get; set; } public string? unit_id { get; set; } diff --git a/WarehouseMgr/Tnb.WarehouseMgr.Entities/Entity/WmsOutinStockCode.cs b/WarehouseMgr/Tnb.WarehouseMgr.Entities/Entity/WmsOutinStockCode.cs new file mode 100644 index 00000000..5326168f --- /dev/null +++ b/WarehouseMgr/Tnb.WarehouseMgr.Entities/Entity/WmsOutinStockCode.cs @@ -0,0 +1,133 @@ +using JNPF.Common.Contracts; +using JNPF.Common.Security; +using SqlSugar; + +namespace Tnb.WarehouseMgr.Entities.Entity; + +/// +/// 出入库流水明细条码表 +/// +[SugarTable("wms_outin_stock_code")] +public partial class WmsOutinStockCode : BaseEntity +{ + public WmsOutinStockCode() + { + id = SnowflakeIdHelper.NextId(); + } + /// + /// 所属组织ID + /// + public string org_id { get; set; } = string.Empty; + + /// + /// 出入库流水明细ID + /// + public string bill_d_id { get; set; } = string.Empty; + + /// + /// 物品ID + /// + public string material_id { get; set; } = string.Empty; + + /// + /// 物料编码 + /// + public string material_code { get; set; } = string.Empty; + + /// + /// 物料名称 + /// + public string material_name { get; set; } = string.Empty; + + + /// + /// 条码编号 + /// + public string barcode { get; set; } = string.Empty; + + /// + /// 批次 + /// + public string? code_batch { get; set; } + + /// + /// 条码数量 + /// + public decimal codeqty { get; set; } + + /// + /// 单位ID + /// + public string unit_id { get; set; } = string.Empty; + + /// + /// 单位代码 + /// + public string? unit_code { get; set; } + + /// + /// 备注 + /// + public string? remark { get; set; } + + /// + /// 扩展字段 + /// + public string? extras { get; set; } + + /// + /// 时间戳 + /// + public DateTime? time_stamp { get; set; } + + /// + /// 创建用户 + /// + public string? create_id { get; set; } + + /// + /// 创建时间 + /// + public DateTime? create_time { get; set; } + + /// + /// 修改用户 + /// + public string? modify_id { get; set; } + + /// + /// 修改时间 + /// + public DateTime? modify_time { get; set; } + + /// + /// 流程任务Id + /// + public string? f_flowtaskid { get; set; } + + /// + /// 流程引擎Id + /// + public string? f_flowid { get; set; } + + /// + /// 规格型号 + /// + public string? material_specification { get; set; } + + /// + /// 箱号 + /// + public string? container_no { get; set; } + + /// + /// 期初数量 + /// + public decimal? start_qty { get; set; } + + /// + /// 期末数量 + /// + public decimal? end_qty { get; set; } + +} diff --git a/WarehouseMgr/Tnb.WarehouseMgr.Entities/Entity/WmsOutinStockDetail.cs b/WarehouseMgr/Tnb.WarehouseMgr.Entities/Entity/WmsOutinStockDetail.cs new file mode 100644 index 00000000..086723cc --- /dev/null +++ b/WarehouseMgr/Tnb.WarehouseMgr.Entities/Entity/WmsOutinStockDetail.cs @@ -0,0 +1,162 @@ +using JNPF.Common.Contracts; +using JNPF.Common.Security; +using SqlSugar; + +namespace Tnb.WarehouseMgr.Entities.Entity; + +/// +/// 出入库流水明细表 +/// +[SugarTable("wms_outin_stock_detail")] +public partial class WmsOutinStockDetail : BaseEntity +{ + public WmsOutinStockDetail() + { + id = SnowflakeIdHelper.NextId(); + } + /// + /// 所属组织ID + /// + public string? org_id { get; set; } + + /// + /// 执行状态 + /// + public string line_status { get; set; } = string.Empty; + + /// + /// 入库仓库ID + /// + public string? warehouse_id { get; set; } + + /// + /// 来源单据ID + /// + public string? source_id { get; set; } + + /// + /// 来源单据代码 + /// + public string? source_code { get; set; } + + /// + /// 源单单据类型 + /// + public int? source_type { get; set; } + + /// + /// 来源单据行号 + /// + public int? source_line { get; set; } + + /// + /// 来源单据明细ID + /// + public string? source_detail_id { get; set; } + + /// + /// 备注 + /// + public string? remark { get; set; } + + /// + /// 扩展字段 + /// + public string? extras { get; set; } + + /// + /// 时间戳 + /// + public DateTime? time_stamp { get; set; } + + /// + /// 创建用户 + /// + public string? create_id { get; set; } + + /// + /// 创建时间 + /// + public DateTime? create_time { get; set; } + + /// + /// 修改用户 + /// + public string? modify_id { get; set; } + + /// + /// 修改时间 + /// + public DateTime? modify_time { get; set; } + + /// + /// 打印模板ID + /// + public string? print_id { get; set; } + + /// + /// 流程任务Id + /// + public string? f_flowtaskid { get; set; } + + /// + /// 流程引擎Id + /// + public string? f_flowid { get; set; } + + /// + /// 载具id + /// + public string? carry_id { get; set; } + + /// + /// 载具编码 + /// + public string? carry_code { get; set; } + + /// + /// 任务执行编码 + /// + public string? distask_code { get; set; } + + /// + /// 预任务编码 + /// + public string? pretask_code { get; set; } + + /// + /// 任务开始时间 + /// + public DateTime? act_start_date { get; set; } + + /// + /// 任务结束时间 + /// + public DateTime? act_end_date { get; set; } + + /// + /// 起点库位id + /// + public string? startlocation_id { get; set; } + + /// + /// 终点库位id + /// + public string? endlocation_id { get; set; } + + /// + /// 起点库位编码 + /// + public string? startlocation_code { get; set; } + + /// + /// 终点库位编码 + /// + public string? endlocation_code { get; set; } + + /// + /// 出入库类型 + /// + public string? type { get; set; } + +} diff --git a/WarehouseMgr/Tnb.WarehouseMgr.Interfaces/IWmsOutinStockDetailService.cs b/WarehouseMgr/Tnb.WarehouseMgr.Interfaces/IWmsOutinStockDetailService.cs new file mode 100644 index 00000000..f13e8ad9 --- /dev/null +++ b/WarehouseMgr/Tnb.WarehouseMgr.Interfaces/IWmsOutinStockDetailService.cs @@ -0,0 +1,17 @@ +using SqlSugar; +using Tnb.WarehouseMgr.Entities; +using Tnb.WarehouseMgr.Entities.Dto.Inputs; + +namespace Tnb.WarehouseMgr.Interfaces +{ + public interface IWmsOutinStockDetailService + { + /// + /// 插入出入库明细记录 + /// + /// + /// + /// + public Task AddOutinStockDetail(AddOutinStockDetailInput input, ISqlSugarClient dbConn = null); + } +} \ No newline at end of file diff --git a/WarehouseMgr/Tnb.WarehouseMgr/BaseWareHouseService.cs b/WarehouseMgr/Tnb.WarehouseMgr/BaseWareHouseService.cs index 1bbe0997..cfabad9e 100644 --- a/WarehouseMgr/Tnb.WarehouseMgr/BaseWareHouseService.cs +++ b/WarehouseMgr/Tnb.WarehouseMgr/BaseWareHouseService.cs @@ -62,6 +62,8 @@ namespace Tnb.WarehouseMgr public static SemaphoreSlim _s_taskExecuteSemaphore_F4DMJCInstock = new(1); public static SemaphoreSlim _s_taskExecuteSemaphore_F4DMJCOutstock = new(1); + public static SemaphoreSlim _s_taskExecuteSemaphore_AddOutinStockDetail = new(1); + protected static Dictionary _s_eleUseStatusDic; protected IEventPublisher? EventPublisher { set; get; } diff --git a/WarehouseMgr/Tnb.WarehouseMgr/ErpToWmsService.cs b/WarehouseMgr/Tnb.WarehouseMgr/ErpToWmsService.cs index 029d0687..6ac0fc87 100644 --- a/WarehouseMgr/Tnb.WarehouseMgr/ErpToWmsService.cs +++ b/WarehouseMgr/Tnb.WarehouseMgr/ErpToWmsService.cs @@ -362,6 +362,18 @@ namespace Tnb.WarehouseMgr wmsPurchaseOrderD.fk_wms_purchase_order_id = wmsPurchaseOrderH.id; wmsPurchaseOrderD.matcode = detail.material_code; wmsPurchaseOrderD.unit = detail.unit_code; + var erpExtendField = await db.Queryable().InnerJoin((a, b) => a.table_id == b.Id).Where((a, b) => a.cunitid == detail.unit_code).Select((a, b) => b).FirstAsync(); + if (erpExtendField != null) + { + wmsPurchaseOrderD.unit = erpExtendField.EnCode; + } + else + { + _LoggerErp2Mes.LogWarning($@"【PurchaseOrder】表体明细中单位{detail.unit_code}在wms系统中未找到!"); + throw new AppFriendlyException($@"表体明细中单位{detail.unit_code}在wms系统中未找到!", 500); + } + + wmsPurchaseOrderD.purchase_quantity = detail.purchase_quantity; wmsPurchaseOrderD.stock_location = detail.stock_location; wmsPurchaseOrderD.code_batch = detail.code_batch; @@ -468,7 +480,18 @@ namespace Tnb.WarehouseMgr wmsOutsourceOrderD.fk_wms_outsource_order_id = wmsOutsourceOrderH.id; wmsOutsourceOrderD.matcode = detail.material_code; - wmsOutsourceOrderD.unit = detail.unit_code; + + var erpExtendField = await db.Queryable().InnerJoin((a, b) => a.table_id == b.Id).Where((a, b) => a.cunitid == detail.unit_code).Select((a, b) => b).FirstAsync(); + if (erpExtendField != null) + { + wmsOutsourceOrderD.unit = erpExtendField.EnCode; + } + else + { + _LoggerErp2Mes.LogWarning($@"【OutsourceOrder】表体明细中单位{detail.unit_code}在wms系统中未找到!"); + throw new AppFriendlyException($@"表体明细中单位{detail.unit_code}在wms系统中未找到!", 500); + } + wmsOutsourceOrderD.outsource_quantity = detail.outsource_quantity; wmsOutsourceOrderD.stock_location = detail.stock_location; wmsOutsourceOrderD.code_batch = detail.code_batch; @@ -869,7 +892,18 @@ namespace Tnb.WarehouseMgr msRawmatTransferinstockD.bill_id = wmsRawmatTransferinstockH.id; msRawmatTransferinstockD.matcode = detail.material_code; - msRawmatTransferinstockD.unit = detail.unit_code; + + + var erpExtendField = await db.Queryable().InnerJoin((a, b) => a.table_id == b.Id).Where((a, b) => a.cunitid == detail.unit_code).Select((a, b) => b).FirstAsync(); + if (erpExtendField != null) + { + msRawmatTransferinstockD.unit = erpExtendField.EnCode; + } + else + { + _LoggerErp2Mes.LogWarning($@"【TransferOutstock】表体明细中单位{detail.unit_code}在wms系统中未找到!"); + throw new AppFriendlyException($@"表体明细中单位{detail.unit_code}在wms系统中未找到!", 500); + } msRawmatTransferinstockD.qty = detail.qty; msRawmatTransferinstockD.stock_location = detail.stock_location; msRawmatTransferinstockD.code_batch = detail.code_batch; diff --git a/WarehouseMgr/Tnb.WarehouseMgr/WareHouseService.cs b/WarehouseMgr/Tnb.WarehouseMgr/WareHouseService.cs index 09e0198e..47d10cda 100644 --- a/WarehouseMgr/Tnb.WarehouseMgr/WareHouseService.cs +++ b/WarehouseMgr/Tnb.WarehouseMgr/WareHouseService.cs @@ -73,6 +73,10 @@ namespace Tnb.WarehouseMgr private readonly IElevatorControlService _elevatorControlService; private readonly IWmsCarryBindService _wmsCarryBindService; private readonly IWmsCarryUnbindService _wmsCarryUnbindService; + private readonly IWmsOutinStockDetailService _wmsOutinStockDetailService; + + + private static readonly Dictionary _elevatorAgvCtlStatusMap = new(StringComparer.OrdinalIgnoreCase); private readonly ElevatorControlConfiguration _eleCtlCfg = App.Configuration.Build(); private static Dictionary locMap = new Dictionary(StringComparer.OrdinalIgnoreCase); @@ -86,6 +90,7 @@ namespace Tnb.WarehouseMgr public static SemaphoreSlim s_taskGenPreTask = new(1); public static SemaphoreSlim s_GenTaskExecute = new(1); + public Func AddUnExecuteTask { get; set; } @@ -126,7 +131,8 @@ namespace Tnb.WarehouseMgr IWmsCarryBindService wmsCarryBindService, IWmsCarryUnbindService wmsCarryUnbindService, IRunService runService, - IVisualDevService visualDevService + IVisualDevService visualDevService, + IWmsOutinStockDetailService wmsOutinStockDetailService //IConfiguration configuration ) : base(repository.AsSugarClient()) { @@ -141,6 +147,7 @@ namespace Tnb.WarehouseMgr _wmsCarryUnbindService = wmsCarryUnbindService; _runService = runService; _visualDevService = visualDevService; + _wmsOutinStockDetailService = wmsOutinStockDetailService; //_configuration = configuration; } @@ -2537,15 +2544,21 @@ namespace Tnb.WarehouseMgr _ = await _db.Updateable(carryIts).UpdateColumns(it => new { it.is_lock, it.location_id, it.location_code, it.instock_time }).ExecuteCommandAsync(); Logger.Information($"【TaskComplate】 更新载具 {JsonConvert.SerializeObject(carryIts)}"); //更新条码的库位和仓库信息 - _ = await _db.Updateable(carryCodeIts).UpdateColumns(it => new { it.warehouse_id, it.location_id, it.location_code }).ExecuteCommandAsync(); + _ = await _db.Updateable(carryCodeIts).UpdateColumns(it => new { it.warehouse_id, it.location_id, it.location_code }).Where(it => multiList.Select(x => x.carry_id).Contains(it.carry_id)).ExecuteCommandAsync(); //更新库位信息,使用状态为 使用,锁定状态为未锁定 _ = await _db.Updateable(locIts).UpdateColumns(it => new { it.is_use, it.is_lock }).ExecuteCommandAsync(); Logger.Information($"【TaskComplate】 更新库位 {JsonConvert.SerializeObject(locIts)}"); /* var loginType= _userManager?.LoginType ?? "web"; Log.Information($"_userManager.LoginType={loginType}"); */ //更新业务主表的单据状态 + foreach (WmsDistaskH? dt in disTasks) { + AddOutinStockDetailInput addOutinStockDetailInput = new AddOutinStockDetailInput(); + addOutinStockDetailInput.disTask = dt; + addOutinStockDetailInput.warehouse_id = carryCodeIts[0].warehouse_id; + await _wmsOutinStockDetailService.AddOutinStockDetail(addOutinStockDetailInput, _db); + #region todo 移到service中 // 销售出库 if (dt.biz_type == WmsWareHouseConst.BIZTYPE_WMSSALERELEASE_ID) diff --git a/WarehouseMgr/Tnb.WarehouseMgr/WmsCarryBindService.cs b/WarehouseMgr/Tnb.WarehouseMgr/WmsCarryBindService.cs index 6703d5e7..ba9b8ffe 100644 --- a/WarehouseMgr/Tnb.WarehouseMgr/WmsCarryBindService.cs +++ b/WarehouseMgr/Tnb.WarehouseMgr/WmsCarryBindService.cs @@ -1,4 +1,5 @@ using System.Dynamic; +using Aop.Api.Domain; using JNPF.Common.Core.Manager; using JNPF.Common.Dtos.VisualDev; using JNPF.Common.Enums; @@ -194,6 +195,7 @@ namespace Tnb.WarehouseMgr WmsCarryCode.id = SnowflakeIdHelper.NextId(); WmsCarryCode.carry_id = carry.id; WmsCarryCode.is_out = 0; + WmsCarryCode.codeqty = detail.codeqty; WmsCarryCode.create_id = input.create_id; WmsCarryCode.create_time = DateTime.Now; WmsCarryCodes.Add(WmsCarryCode); @@ -284,7 +286,7 @@ namespace Tnb.WarehouseMgr /// /// [NonAction] - public async Task CarryBind(CarryBindInput input, ISqlSugarClient dbConn = null) + public async Task CarryBind(CarryBindInput input, ISqlSugarClient dbConn = null) { bool isOk = false; diff --git a/WarehouseMgr/Tnb.WarehouseMgr/WmsMaterialTransferService.cs b/WarehouseMgr/Tnb.WarehouseMgr/WmsMaterialTransferService.cs index 022b8892..14dc182d 100644 --- a/WarehouseMgr/Tnb.WarehouseMgr/WmsMaterialTransferService.cs +++ b/WarehouseMgr/Tnb.WarehouseMgr/WmsMaterialTransferService.cs @@ -535,7 +535,7 @@ namespace Tnb.WarehouseMgr CarryMaterialDetail carryMaterialDetail = new CarryMaterialDetail(); carryMaterialDetail.material_id = wmsMaterialTransferD.material_id; carryMaterialDetail.material_code = wmsMaterialTransferD.material_code; - carryMaterialDetail.codeqty = wmsCarryH.qty.ToString(); + carryMaterialDetail.codeqty = wmsCarryH.qty; carryMaterialDetail.code_batch = wmsMaterialTransferD.code_batch; carryMaterialDetail.barcode = wmsCarryHs[index].carry_code; carryMaterialDetail.unit_id = wmsMaterialTransferD.unit_id; @@ -1491,7 +1491,7 @@ namespace Tnb.WarehouseMgr CarryMaterialDetail carryMaterialDetail = new CarryMaterialDetail(); carryMaterialDetail.material_id = wmsMaterialTransferD.material_id; carryMaterialDetail.material_code = wmsMaterialTransferD.material_code; - carryMaterialDetail.codeqty = input.qty.ToString(); + carryMaterialDetail.codeqty = input.qty; carryMaterialDetail.code_batch = wmsMaterialTransferD.code_batch; carryMaterialDetail.barcode = wmsCarryH.carry_code; carryMaterialDetail.unit_id = wmsMaterialTransferD.unit_id; diff --git a/WarehouseMgr/Tnb.WarehouseMgr/WmsOutinStockDetailService.cs b/WarehouseMgr/Tnb.WarehouseMgr/WmsOutinStockDetailService.cs new file mode 100644 index 00000000..66cfa4ad --- /dev/null +++ b/WarehouseMgr/Tnb.WarehouseMgr/WmsOutinStockDetailService.cs @@ -0,0 +1,212 @@ +using System.Text; +using System.Text.RegularExpressions; +using JNPF.Common.Contracts; +using JNPF.Common.Core.Manager; +using JNPF.Common.Dtos.VisualDev; +using JNPF.Common.Enums; +using JNPF.Common.Extension; +using JNPF.Common.Security; +using JNPF.FriendlyException; +using JNPF.Logging; +using JNPF.Systems.Interfaces.System; +using JNPF.VisualDev; +using JNPF.VisualDev.Interfaces; +using Mapster; +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Mvc; +using Microsoft.Extensions.Logging; +using Npgsql; +using SqlSugar; +using Tnb.BasicData.Entities; +using Tnb.Common.Utils; +using Tnb.WarehouseMgr.Entities; +using Tnb.WarehouseMgr.Entities.Consts; +using Tnb.WarehouseMgr.Entities.Dto; +using Tnb.WarehouseMgr.Entities.Dto.Inputs; +using Tnb.WarehouseMgr.Entities.Dto.Outputs; +using Tnb.WarehouseMgr.Entities.Entity; +using Tnb.WarehouseMgr.Entities.Enums; +using Tnb.WarehouseMgr.Interfaces; + +namespace Tnb.WarehouseMgr +{ + [OverideVisualDev(ModuleConsts.MODULE_WMSOUTINSTOCKDETAIL_ID)] + public class WmsOutinStockDetailService : BaseWareHouseService, IWmsOutinStockDetailService + { + private readonly ISqlSugarClient _db; + private readonly IUserManager _userManager; + private readonly IBillRullService _billRullService; + private readonly IRunService _runService; + private readonly IVisualDevService _visualDevService; + public WmsOutinStockDetailService( + ISqlSugarRepository repository, + IUserManager userManager, + IBillRullService billRullService, + IRunService runService, + IVisualDevService visualDevService) + { + _db = repository.AsSugarClient(); + _userManager = userManager; + _billRullService = billRullService; + _runService = runService; + _visualDevService = visualDevService; + } + + /// + /// 根据任务单获取出入库类型 + /// + string GetOutinStockTypeByTask(string task_type, string biz_type) + { + //if (biz_type == WmsWareHouseConst.BIZTYPE_WMSINSTOCK_ID) + // return ""; + + string type = ""; + + switch (task_type) + { + case WmsWareHouseConst.WMS_PRETASK_INSTOCK_TYPE_ID: + { + type = "入库"; + break; + } + case WmsWareHouseConst.WMS_PRETASK_OUTSTOCK_TYPE_ID: + { + type = "转移"; + break; + } + } + + + + return type; + } + + /// + /// 根据任务单获取操作员 + /// + string GetUserIdByTask() + { + string create_id = WmsWareHouseConst.AdministratorUserId; + return create_id; + } + + /// + /// 插入出入库明细记录 + /// + /// + /// + /// + /// + [NonAction] + public async Task AddOutinStockDetail(AddOutinStockDetailInput input, ISqlSugarClient dbConn = null) + { + var db = _db; + if (dbConn != null) + db = dbConn; + try + { + if (string.IsNullOrEmpty(input.disTask.carry_id)) + { + return; + } + + await _s_taskExecuteSemaphore_AddOutinStockDetail.WaitAsync(); + + string type = GetOutinStockTypeByTask(input.disTask.task_type, input.disTask.biz_type); + if (string.IsNullOrEmpty(type)) + { + return; + } + + List wmsCarryCodes = await db.Queryable().Where(r => r.carry_id == input.disTask.carry_id).ToListAsync(); + + //await db.Ado.BeginTranAsync(); + + WmsOutinStockDetail wmsOutinStockDetail = new WmsOutinStockDetail(); + wmsOutinStockDetail.warehouse_id = input.warehouse_id; + wmsOutinStockDetail.carry_id = input.disTask.carry_id; + wmsOutinStockDetail.carry_code = input.disTask.carry_code; + wmsOutinStockDetail.create_id = GetUserIdByTask(); + wmsOutinStockDetail.startlocation_id = input.disTask.startlocation_id; + wmsOutinStockDetail.startlocation_code = input.disTask.startlocation_code; + wmsOutinStockDetail.endlocation_id = input.disTask.endlocation_id; + wmsOutinStockDetail.endlocation_code = input.disTask.endlocation_code; + wmsOutinStockDetail.act_start_date = input.disTask.act_start_date; + wmsOutinStockDetail.act_end_date = input.disTask.act_end_date; + wmsOutinStockDetail.pretask_code = input.disTask.pretask_code; + wmsOutinStockDetail.distask_code = input.disTask.bill_code; + wmsOutinStockDetail.type = type; + + List mats = await db.Queryable().Where(r => wmsCarryCodes.Select(x => x.material_id).Distinct().Contains(r.id)).ToListAsync(); + + List wmsOutinStockCodes = new List(); + + + foreach (var itGroup in wmsCarryCodes.GroupBy(g => new { g.warehouse_id, g.location_id, g.material_id, g.code_batch })) + { + dynamic key = itGroup.Key; + + List curCarryCodes = itGroup.ToList().FindAll(x => x.warehouse_id == itGroup.Key.warehouse_id && x.location_id == itGroup.Key.location_id + && x.material_id == itGroup.Key.material_id && x.code_batch == itGroup.Key.code_batch); + + decimal start_qty = db.Queryable().Where(r => r.warehouse_id == itGroup.Key.warehouse_id + && r.code_batch == itGroup.Key.code_batch).Sum(r => r.codeqty); + + curCarryCodes.ForEach(x => + { + WmsOutinStockCode wmsOutinStockCode = new WmsOutinStockCode(); + BasMaterial mat = mats.Where(r => r.id == x.material_id).First(); + wmsOutinStockCode.bill_d_id = wmsOutinStockDetail.id; + wmsOutinStockCode.barcode = x.barcode; + wmsOutinStockCode.material_id = mat.id; + wmsOutinStockCode.material_code = mat.code; + wmsOutinStockCode.material_specification = mat.material_specification; + wmsOutinStockCode.code_batch = x.code_batch; + wmsOutinStockCode.codeqty = x.codeqty; + wmsOutinStockCode.start_qty = start_qty; + if (type == "入库") + wmsOutinStockCode.end_qty = start_qty + x.codeqty; + else if (type == "出库") + wmsOutinStockCode.end_qty = start_qty - x.codeqty; + wmsOutinStockCode.container_no = mat.container_no; + wmsOutinStockCode.unit_id = mat.unit_id; + + wmsOutinStockCodes.Add(wmsOutinStockCode); + }); + + } + + int rows = await db.Insertable(wmsOutinStockDetail).ExecuteCommandAsync(); + if (rows == 0) + { + throw new Exception($"插入入库明细失败!"); + } + rows = await db.Insertable(wmsOutinStockCodes).ExecuteCommandAsync(); + if (rows == 0) + { + throw new Exception($"插入入库明细条码失败!"); + } + await db.Ado.CommitTranAsync(); + } + catch (PostgresException ex) + { + ////await db.Ado.RollbackTranAsync(); + Logger.LogError(ex.Message); + Logger.LogError(ex.StackTrace); + throw new AppFriendlyException($"插入入库明细失败 {ex.Message}", 500); + } + catch (Exception ex) + { + //await db.Ado.RollbackTranAsync(); + Logger.LogError(ex.Message); + Logger.LogError(ex.StackTrace); + throw new AppFriendlyException($"插入入库明细失败 {ex.Message}", 500); + } + finally + { + _s_taskExecuteSemaphore_AddOutinStockDetail.Release(); + } + } + + } +} \ No newline at end of file diff --git a/WarehouseMgr/Tnb.WarehouseMgr/WmsPurchaseService.cs b/WarehouseMgr/Tnb.WarehouseMgr/WmsPurchaseService.cs index 66ef258b..262e4909 100644 --- a/WarehouseMgr/Tnb.WarehouseMgr/WmsPurchaseService.cs +++ b/WarehouseMgr/Tnb.WarehouseMgr/WmsPurchaseService.cs @@ -87,8 +87,6 @@ namespace Tnb.WarehouseMgr var blFlag = true; try { - - await _db.Ado.BeginTranAsync(); WmsInstockH? instock = null; var purchaseDs = await PurchaseAndSaleUpdate(input); @@ -330,8 +328,16 @@ namespace Tnb.WarehouseMgr if (minPacking.HasValue && minPacking.Value > 0) { - int mod = (int)(WmsPurchaseD.purchase_arriveqty % minPacking.Value); - codeNum = (int)(mod > 0 ? (WmsPurchaseD.purchase_arriveqty / minPacking.Value) + 1 : WmsPurchaseD.purchase_arriveqty / minPacking.Value); + codeNum = input.barcode_qty; + + decimal qty = (int)(codeNum * minPacking); + + decimal mod = 0; + decimal extra = qty - WmsPurchaseD.purchase_arriveqty; + if (extra > 0 && extra < minPacking) + { + mod = minPacking.Value - extra; + } for (int j = 0; j < codeNum; j++) { @@ -367,11 +373,11 @@ namespace Tnb.WarehouseMgr } await _db.Ado.CommitTranAsync(); barcodes.AddRange(wmsTempCodes.Select(p => p.barcode).ToList()); - if (barcodes?.Count > 0) - { - var ip= _db.Queryable().Where(p=>p.key== "printerip").FirstAsync().Result.value; - base.BarCodePrint(barcodes, 1, ip); - } + //if (barcodes?.Count > 0) + //{ + // var ip= _db.Queryable().Where(p=>p.key== "printerip").FirstAsync().Result.value; + // base.BarCodePrint(barcodes, 1, ip); + //} } diff --git a/WarehouseMgr/Tnb.WarehouseMgr/WmsRawmatTransferinstockService.cs b/WarehouseMgr/Tnb.WarehouseMgr/WmsRawmatTransferinstockService.cs index 5697026c..cc9e55eb 100644 --- a/WarehouseMgr/Tnb.WarehouseMgr/WmsRawmatTransferinstockService.cs +++ b/WarehouseMgr/Tnb.WarehouseMgr/WmsRawmatTransferinstockService.cs @@ -101,8 +101,16 @@ namespace Tnb.WarehouseMgr if (minPacking.HasValue && minPacking.Value > 0) { - int mod = (int)(WmsRawmatTransferinstockD.actual_qty % minPacking.Value); - codeNum = (int)(mod > 0 ? (WmsRawmatTransferinstockD.actual_qty / minPacking.Value) + 1 : WmsRawmatTransferinstockD.actual_qty / minPacking.Value); + codeNum = input.barcode_qty; + + decimal qty = (int)(codeNum * minPacking); + + decimal mod = 0; + decimal extra = (qty - WmsRawmatTransferinstockD.actual_qty).Value; + if (extra > 0 && extra < minPacking) + { + mod = minPacking.Value - extra; + } for (int j = 0; j < codeNum; j++) { @@ -137,11 +145,11 @@ namespace Tnb.WarehouseMgr } await _db.Ado.CommitTranAsync(); barcodes.AddRange(wmsTempCodes.Select(p => p.barcode).ToList()); - if (barcodes?.Count > 0) - { - var ip = _db.Queryable().Where(p => p.key == "printerip").FirstAsync().Result.value; - base.BarCodePrint(barcodes, 1, ip); - } + //if (barcodes?.Count > 0) + //{ + // var ip = _db.Queryable().Where(p => p.key == "printerip").FirstAsync().Result.value; + // base.BarCodePrint(barcodes, 1, ip); + //} } diff --git a/WarehouseMgr/Tnb.WarehouseMgr/WmsStockReportService.cs b/WarehouseMgr/Tnb.WarehouseMgr/WmsStockReportService.cs index 12aae692..5cda53c2 100644 --- a/WarehouseMgr/Tnb.WarehouseMgr/WmsStockReportService.cs +++ b/WarehouseMgr/Tnb.WarehouseMgr/WmsStockReportService.cs @@ -11,6 +11,7 @@ using SqlSugar; using Tnb.BasicData.Entities; using Tnb.WarehouseMgr.Entities; using Tnb.WarehouseMgr.Entities.Dto; +using Tnb.WarehouseMgr.Entities.Entity; using Tnb.WarehouseMgr.Entities.Enums; namespace Tnb.WarehouseMgr @@ -161,5 +162,56 @@ namespace Tnb.WarehouseMgr }; return PageResult.SqlSugarPageResult(pagedList); } + + + [HttpPost] + public async Task OutinStockDetail(VisualDevModelListQueryInput input) + { + var code_batch = ""; + var material_specification = ""; + if (!input.queryJson.IsNullOrWhiteSpace()) + { + code_batch = JObject.Parse(input.queryJson).Value(nameof(WmsCarryCode.code_batch)); + material_specification = JObject.Parse(input.queryJson).Value(nameof(WmsCarryCode.material_specification)); + } + + IEnumerable result = null; + + result = await _db.Queryable() + .InnerJoin((a, b) => a.id == b.bill_d_id) + .InnerJoin((a, b, c) => a.warehouse_id == c.id) + .Select((a,b,c) => new + { + act_start_date = a.act_start_date, + act_end_date = a.act_end_date, + whname = c.whname, + material_id = b.material_id, + material_code = b.material_code, + material_name = b.material_name, + material_specification = b.material_specification, + container_no = b.container_no, + code_batch = b.code_batch, + location_id = a.endlocation_id, + location_code = a.endlocation_code, + unit_id = b.unit_id, + unit_code = b.unit_code, + start_qty = b.start_qty, + end_qty = b.end_qty, + type = a.type + }).ToListAsync(); + + List pages = result.Skip((input.currentPage - 1) * input.pageSize).Take(input.pageSize).ToList(); + SqlSugarPagedList pagedList = new() + { + list = pages, + pagination = new() + { + CurrentPage = input.currentPage, + PageSize = input.pageSize, + Total = result.Count() + } + }; + return PageResult.SqlSugarPageResult(pagedList); + } } }