From e92797e449c2805e0693439390aee225b1e5b444 Mon Sep 17 00:00:00 2001 From: majian <780924089@qq.com> Date: Thu, 25 Jul 2024 16:18:22 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A7=94=E5=A4=96=E8=AE=A2=E5=8D=95=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3=EF=BC=8C=E5=8E=9F=E6=9D=90=E6=96=99=E7=A7=BB=E5=BA=93?= =?UTF-8?q?=E7=AD=96=E7=95=A5=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Tnb.ProductionMgr/RedisBackGround.cs | 2 +- .../Consts/WmsWareHouseConst.cs | 5 + .../Dto/ErpInputs/OutsourceOrderInput.cs | 90 +++++++++++++ .../Dto/Queries/InStockStrategyQuery.cs | 3 + .../Entity/WmsOutsourceOrderD.cs | 122 ++++++++++++++++++ .../Entity/WmsOutsourceOrderH.cs | 122 ++++++++++++++++++ .../Entity/WmsPurchaseOrderD.cs | 4 +- .../Tnb.WarehouseMgr/ErpToWmsService.cs | 110 +++++++++++++++- .../Tnb.WarehouseMgr/WareHouseService.cs | 3 +- 9 files changed, 455 insertions(+), 6 deletions(-) create mode 100644 WarehouseMgr/Tnb.WarehouseMgr.Entities/Dto/ErpInputs/OutsourceOrderInput.cs create mode 100644 WarehouseMgr/Tnb.WarehouseMgr.Entities/Entity/WmsOutsourceOrderD.cs create mode 100644 WarehouseMgr/Tnb.WarehouseMgr.Entities/Entity/WmsOutsourceOrderH.cs diff --git a/ProductionMgr/Tnb.ProductionMgr/RedisBackGround.cs b/ProductionMgr/Tnb.ProductionMgr/RedisBackGround.cs index b68c8076..f8875a3f 100644 --- a/ProductionMgr/Tnb.ProductionMgr/RedisBackGround.cs +++ b/ProductionMgr/Tnb.ProductionMgr/RedisBackGround.cs @@ -664,7 +664,7 @@ where carry_code = '{coderesult}' and status = '{WmsWareHouseConst.TASK_BILL_STA foreach (WmsCarryH wmsCarryH in items) { BasLocation startlocation = await db_YCLInternalTransfer.Queryable().Where(r => r.id == wmsCarryH.location_id).FirstAsync(); - InStockStrategyQuery inStockStrategyInput = new() { warehouse_id = "1", Size = 1, passage = startlocation.passage, AvoidBusyPassage = true, Region_id = WmsWareHouseConst.REGION_Purchase_ID }; + InStockStrategyQuery inStockStrategyInput = new() { warehouse_id = "1", Size = 1, passage = startlocation.passage, AvoidBusyPassage = true, Region_id = WmsWareHouseConst.REGION_Purchase_ID, PolicyCode = WmsWareHouseConst.POLICY_YCLINSTOCK }; List endLocations = await _wareHouseService.InStockStrategy(inStockStrategyInput); if (endLocations.Count() == 0) diff --git a/WarehouseMgr/Tnb.WarehouseMgr.Entities/Consts/WmsWareHouseConst.cs b/WarehouseMgr/Tnb.WarehouseMgr.Entities/Consts/WmsWareHouseConst.cs index 49eccbbd..a9da74b0 100644 --- a/WarehouseMgr/Tnb.WarehouseMgr.Entities/Consts/WmsWareHouseConst.cs +++ b/WarehouseMgr/Tnb.WarehouseMgr.Entities/Consts/WmsWareHouseConst.cs @@ -537,5 +537,10 @@ /// 原材料八工位待入库 /// public const string LOCATION_YCLBGWDRK = "35750287617301"; + + /// + /// 原材料仓内转移策略 + /// + public const string POLICY_YCLINSTOCK = "WISP202407250001"; } } diff --git a/WarehouseMgr/Tnb.WarehouseMgr.Entities/Dto/ErpInputs/OutsourceOrderInput.cs b/WarehouseMgr/Tnb.WarehouseMgr.Entities/Dto/ErpInputs/OutsourceOrderInput.cs new file mode 100644 index 00000000..7671ad91 --- /dev/null +++ b/WarehouseMgr/Tnb.WarehouseMgr.Entities/Dto/ErpInputs/OutsourceOrderInput.cs @@ -0,0 +1,90 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Tnb.WarehouseMgr.Entities.Dto.ErpInputs +{ + public class OutsourceOrderInput + { + /// + /// 单号 + /// + public string? outsource_order { get; set; } + + /// + /// 联系人 + /// + public string? contact_person { get; set; } + + /// + /// 电话 + /// + public string? tel { get; set; } + + /// + /// 供应商编号 + /// + public string? supplier_code { get; set; } + + /// + /// 凭证日期 + /// + public DateTime? certificate_date { get; set; } + + /// + /// 供货日期 + /// + public DateTime? ship_date { get; set; } + + /// + /// 主表pk + /// + public string? erp_pk { get; set; } + + public List details { get; set; } + } + public class OutsourceOrderDetail + { + /// + /// 行号 + /// + public string? lineno { get; set; } + + /// + /// 物品代码 + /// + public string? material_code { get; set; } + + /// + /// 单位代码 + /// + public string? unit_code { get; set; } + + /// + /// 委外数量 + /// + public decimal? outsource_quantity { get; set; } + + /// + /// 库存地点编号 + /// + public string? stock_location { get; set; } + + /// + /// 批次 + /// + public string? code_batch { get; set; } + + /// + /// 交货日期 + /// + public DateTime? delivery_date { get; set; } + + /// + /// 子表主键 + /// + public string erp_line_pk { get; set; } + } +} diff --git a/WarehouseMgr/Tnb.WarehouseMgr.Entities/Dto/Queries/InStockStrategyQuery.cs b/WarehouseMgr/Tnb.WarehouseMgr.Entities/Dto/Queries/InStockStrategyQuery.cs index db68848f..9aa362b4 100644 --- a/WarehouseMgr/Tnb.WarehouseMgr.Entities/Dto/Queries/InStockStrategyQuery.cs +++ b/WarehouseMgr/Tnb.WarehouseMgr.Entities/Dto/Queries/InStockStrategyQuery.cs @@ -31,5 +31,8 @@ // 巷道 public string passage { get; set; } + + // 策略编号 + public string PolicyCode { get; set; } } } diff --git a/WarehouseMgr/Tnb.WarehouseMgr.Entities/Entity/WmsOutsourceOrderD.cs b/WarehouseMgr/Tnb.WarehouseMgr.Entities/Entity/WmsOutsourceOrderD.cs new file mode 100644 index 00000000..f26f149e --- /dev/null +++ b/WarehouseMgr/Tnb.WarehouseMgr.Entities/Entity/WmsOutsourceOrderD.cs @@ -0,0 +1,122 @@ +using JNPF.Common.Contracts; +using JNPF.Common.Security; +using SqlSugar; + +namespace Tnb.WarehouseMgr.Entities.Entity; + +/// +/// 委外订单表子表 +/// +[SugarTable("wms_outsource_order_d")] +public partial class WmsOutsourceOrderD : BaseEntity +{ + public WmsOutsourceOrderD() + { + id = SnowflakeIdHelper.NextId(); + } + /// + /// 主表id + /// + public string? fk_wms_outsource_order_id { get; set; } + + /// + /// 物料id + /// + public string? matcode_id { get; set; } + + /// + /// 物料编号 + /// + public string? matcode { get; set; } + + /// + /// 物料描述 + /// + public string? matspecification { get; set; } + + /// + /// 单位 + /// + public string? unit { get; set; } + + /// + /// 采购数量 + /// + public decimal? outsource_quantity { get; set; } + + /// + /// 实收数量 + /// + public decimal? actual_quantity { get; set; } + + /// + /// 库存地点ID + /// + public string? stock_location_id { get; set; } + + /// + /// 库存地点 + /// + public string? stock_location { get; set; } + + /// + /// 批次 + /// + public string? code_batch { get; set; } + + /// + /// 备注 + /// + public string? remark { get; set; } + + /// + /// 扩展字段 + /// + public string? extras { get; set; } + + /// + /// 交货日期 + /// + public string? delivery_date { get; set; } + + /// + /// 净价 + /// + public string? net_price { get; set; } + + /// + /// 货币 + /// + public string? currency { get; set; } + + /// + /// 工厂 + /// + public string? factory { 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; } + + /// + /// erp_line_pk + /// + public string? erp_line_pk { get; set; } + +} diff --git a/WarehouseMgr/Tnb.WarehouseMgr.Entities/Entity/WmsOutsourceOrderH.cs b/WarehouseMgr/Tnb.WarehouseMgr.Entities/Entity/WmsOutsourceOrderH.cs new file mode 100644 index 00000000..d1bc0bac --- /dev/null +++ b/WarehouseMgr/Tnb.WarehouseMgr.Entities/Entity/WmsOutsourceOrderH.cs @@ -0,0 +1,122 @@ +using JNPF.Common.Contracts; +using JNPF.Common.Security; +using SqlSugar; + +namespace Tnb.WarehouseMgr.Entities.Entity; + +/// +/// 委外订单 +/// +[SugarTable("wms_outsource_order_h")] +public partial class WmsOutsourceOrderH : BaseEntity +{ + public WmsOutsourceOrderH() + { + id = SnowflakeIdHelper.NextId(); + } + /// + /// 采购订单号 + /// + public string? outsource_order { get; set; } + + /// + /// 联系人 + /// + public string? contact_person { get; set; } + + /// + /// 电话 + /// + public string? tel { get; set; } + + /// + /// 供应商ID + /// + public string? supplier_id { get; set; } + + /// + /// 供应商编号 + /// + public string? supplier_code { get; set; } + + /// + /// 供应商名称 + /// + public string? supplier_name { get; set; } + + /// + /// 备注 + /// + public string? remark { get; set; } + + /// + /// 扩展字段 + /// + public string? extras { get; set; } + + /// + /// 时间戳 + /// + public string? time_stamp { get; set; } + + /// + /// 单据类型 + /// + public string? document_type { get; set; } + + /// + /// 凭证日期 + /// + public string? certificate_date { 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; } + + /// + /// 所属组织 + /// + public string? org_id { get; set; } + + /// + /// 流程任务Id + /// + public string? f_flowtaskid { get; set; } + + /// + /// 流程引擎Id + /// + public string? f_flowid { get; set; } + + /// + /// erp_pk + /// + public string? erp_pk { get; set; } + + /// + /// erp_bill_code + /// + public string? erp_bill_code { get; set; } + + /// + /// 供货日期 + /// + public DateTime? ship_date { get; set; } + +} diff --git a/WarehouseMgr/Tnb.WarehouseMgr.Entities/Entity/WmsPurchaseOrderD.cs b/WarehouseMgr/Tnb.WarehouseMgr.Entities/Entity/WmsPurchaseOrderD.cs index 9144ed1c..ec64dfcb 100644 --- a/WarehouseMgr/Tnb.WarehouseMgr.Entities/Entity/WmsPurchaseOrderD.cs +++ b/WarehouseMgr/Tnb.WarehouseMgr.Entities/Entity/WmsPurchaseOrderD.cs @@ -42,12 +42,12 @@ public partial class WmsPurchaseOrderD : BaseEntity /// /// 采购数量 /// - public string? purchase_quantity { get; set; } + public decimal? purchase_quantity { get; set; } /// /// 实收数量 /// - public string? actual_quantity { get; set; } + public decimal? actual_quantity { get; set; } /// /// 库存地点ID diff --git a/WarehouseMgr/Tnb.WarehouseMgr/ErpToWmsService.cs b/WarehouseMgr/Tnb.WarehouseMgr/ErpToWmsService.cs index 8cce4593..77e7d5b9 100644 --- a/WarehouseMgr/Tnb.WarehouseMgr/ErpToWmsService.cs +++ b/WarehouseMgr/Tnb.WarehouseMgr/ErpToWmsService.cs @@ -362,14 +362,14 @@ namespace Tnb.WarehouseMgr wmsPurchaseOrderD.fk_wms_purchase_order_id = wmsPurchaseOrderH.id; wmsPurchaseOrderD.matcode = detail.material_code; wmsPurchaseOrderD.unit = detail.unit_code; - wmsPurchaseOrderD.purchase_quantity = detail.purchase_quantity.ToString(); + wmsPurchaseOrderD.purchase_quantity = detail.purchase_quantity; wmsPurchaseOrderD.stock_location = detail.stock_location; wmsPurchaseOrderD.code_batch = detail.code_batch; wmsPurchaseOrderD.delivery_date = detail.delivery_date.Value.ToString("yyyy-MM-dd HH:mm:ss"); wmsPurchaseOrderD.erp_line_pk = detail.erp_line_pk; wmsPurchaseOrderD.create_id = WmsWareHouseConst.ErpUserId; wmsPurchaseOrderD.create_time = DateTime.Now; - wmsPurchaseOrderD.actual_quantity = "0"; + wmsPurchaseOrderD.actual_quantity = 0; var material = await db.Queryable().Where(p => p.code == detail.material_code).FirstAsync(); if (material != null) @@ -401,6 +401,112 @@ namespace Tnb.WarehouseMgr } } + /// + /// 委外订单 + /// + [HttpPost, NonUnify, AllowAnonymous] + public async Task OutsourceOrder(OutsourceOrderInput input) + { + LoggerErp2Mes.LogInformation($"【OutsourceOrderInput】ERP传入数据:{JsonConvert.SerializeObject(input)}"); + var db = _repository.AsSugarClient(); + + if (string.IsNullOrEmpty(input.erp_pk)) + { + _LoggerErp2Mes.LogWarning($"【OutsourceOrderInput】主表主键不能为空!"); + return await ToApiResult(HttpStatusCode.InternalServerError, $"主表主键不能为空!"); + } + + int count_erp_line_pk = input.details.Where(r => string.IsNullOrEmpty(r.erp_line_pk)).Count(); + if (count_erp_line_pk > 0) + { + _LoggerErp2Mes.LogWarning($@"【OutsourceOrderInput】子表主键不能为空!"); + throw new AppFriendlyException($@"子表主键不能为空!", 500); + } + + var wmsPurchaseOrdersDistinct = input.details.Select(r => new + { + material_id = r.material_code, + code_batch = r.code_batch, + }).Distinct(); + if (wmsPurchaseOrdersDistinct.Count() < input.details.Count) + { + _LoggerErp2Mes.LogWarning($@"【OutsourceOrderInput】表体存在物料和批号重复的明细!"); + throw new AppFriendlyException($@"表体存在物料和批号重复的明细!", 500); + } + + try + { + await db.Ado.BeginTranAsync(); + WmsOutsourceOrderH wmsOutsourceOrderH = new WmsOutsourceOrderH(); + string Code = await _billRuleService.GetBillNumber("Purchase"); + + wmsOutsourceOrderH.outsource_order = Code; + wmsOutsourceOrderH.erp_bill_code = input.outsource_order; + wmsOutsourceOrderH.contact_person = input.contact_person; + wmsOutsourceOrderH.tel = input.tel; + wmsOutsourceOrderH.supplier_code = input.supplier_code; + wmsOutsourceOrderH.certificate_date = input.certificate_date.Value.ToString("yyyy-MM-dd HH:mm:ss"); + wmsOutsourceOrderH.ship_date = input.ship_date; + wmsOutsourceOrderH.erp_pk = input.erp_pk; + wmsOutsourceOrderH.create_id = WmsWareHouseConst.ErpUserId; + wmsOutsourceOrderH.create_time = DateTime.Now; + var supplier = await db.Queryable().Where(p => p.supplier_code == input.supplier_code).FirstAsync(); + if (supplier != null) + { + wmsOutsourceOrderH.supplier_id = supplier.id; + wmsOutsourceOrderH.supplier_name = supplier.supplier_name; + } + + await db.Insertable(wmsOutsourceOrderH).ExecuteCommandAsync(); + + + List wmsOutsourceOrderDs = new List(); + foreach (var detail in input.details) + { + WmsOutsourceOrderD wmsOutsourceOrderD = new WmsOutsourceOrderD(); + + wmsOutsourceOrderD.fk_wms_outsource_order_id = wmsOutsourceOrderH.id; + wmsOutsourceOrderD.matcode = detail.material_code; + wmsOutsourceOrderD.unit = detail.unit_code; + wmsOutsourceOrderD.outsource_quantity = detail.outsource_quantity; + wmsOutsourceOrderD.stock_location = detail.stock_location; + wmsOutsourceOrderD.code_batch = detail.code_batch; + wmsOutsourceOrderD.delivery_date = detail.delivery_date.Value.ToString("yyyy-MM-dd HH:mm:ss"); + wmsOutsourceOrderD.erp_line_pk = detail.erp_line_pk; + wmsOutsourceOrderD.create_id = WmsWareHouseConst.ErpUserId; + wmsOutsourceOrderD.create_time = DateTime.Now; + wmsOutsourceOrderD.actual_quantity = 0; + + var material = await db.Queryable().Where(p => p.code == detail.material_code).FirstAsync(); + if (material != null) + { + wmsOutsourceOrderD.matcode_id = material.id; + wmsOutsourceOrderD.matspecification = material.material_specification; + } + + wmsOutsourceOrderDs.Add(wmsOutsourceOrderD); + } + + await db.Insertable(wmsOutsourceOrderDs).ExecuteCommandAsync(); + + await db.Ado.CommitTranAsync(); + + LoggerErp2Mes.LogInformation($"【OutsourceOrderInput】成功生成单据:{Code}"); + return await ToApiResult(HttpStatusCode.OK, "成功"); + } + catch (Exception ex) + { + LoggerErp2Mes.LogError($"【OutsourceOrderInput】{ex.Message}"); + LoggerErp2Mes.LogError($"【OutsourceOrderInput】{ex.StackTrace}"); + await db.Ado.RollbackTranAsync(); + return await ToApiResult(HttpStatusCode.InternalServerError, ex.Message); + } + finally + { + + } + } + /// /// 转库单 /// diff --git a/WarehouseMgr/Tnb.WarehouseMgr/WareHouseService.cs b/WarehouseMgr/Tnb.WarehouseMgr/WareHouseService.cs index a945e867..005854d2 100644 --- a/WarehouseMgr/Tnb.WarehouseMgr/WareHouseService.cs +++ b/WarehouseMgr/Tnb.WarehouseMgr/WareHouseService.cs @@ -216,7 +216,8 @@ namespace Tnb.WarehouseMgr try { var db = _db.CopyNew(); - WmsInstockPolicies policy = await db.Queryable().Where(it => it.status == 1).FirstAsync(); + WmsInstockPolicies policy = await db.Queryable().Where(it => it.status == 1 && (string.IsNullOrEmpty(input.PolicyCode)|| + it.bill_code == input.PolicyCode)).FirstAsync(); if (policy == null) { throw new AppFriendlyException("没有可用的策略", 500);