From 3a7a0dd5720e64cf1dda26ee6d62c9035f10a3fe Mon Sep 17 00:00:00 2001 From: qianjiawei <1184704771@qq.com> Date: Fri, 8 Dec 2023 17:05:10 +0800 Subject: [PATCH] =?UTF-8?q?ERP=E5=AF=B9=E6=8E=A5WMS=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Dto/ErpInputs/AllotInput.cs | 36 +++ .../Dto/ErpInputs/PurchaseArriveInput.cs | 74 ++++++ .../Dto/ErpInputs/PurchaseReturnInput.cs | 73 ++++++ .../Dto/ErpInputs/SaleOutInput.cs | 77 +++++++ .../Entity/WmsAllot.cs | 115 ++++++++++ .../Tnb.WarehouseMgr/ErpToWmsService.cs | 212 ++++++++++++++++++ 6 files changed, 587 insertions(+) create mode 100644 WarehouseMgr/Tnb.WarehouseMgr.Entities/Dto/ErpInputs/AllotInput.cs create mode 100644 WarehouseMgr/Tnb.WarehouseMgr.Entities/Dto/ErpInputs/PurchaseArriveInput.cs create mode 100644 WarehouseMgr/Tnb.WarehouseMgr.Entities/Dto/ErpInputs/PurchaseReturnInput.cs create mode 100644 WarehouseMgr/Tnb.WarehouseMgr.Entities/Dto/ErpInputs/SaleOutInput.cs create mode 100644 WarehouseMgr/Tnb.WarehouseMgr.Entities/Entity/WmsAllot.cs create mode 100644 WarehouseMgr/Tnb.WarehouseMgr/ErpToWmsService.cs diff --git a/WarehouseMgr/Tnb.WarehouseMgr.Entities/Dto/ErpInputs/AllotInput.cs b/WarehouseMgr/Tnb.WarehouseMgr.Entities/Dto/ErpInputs/AllotInput.cs new file mode 100644 index 00000000..cfa0d206 --- /dev/null +++ b/WarehouseMgr/Tnb.WarehouseMgr.Entities/Dto/ErpInputs/AllotInput.cs @@ -0,0 +1,36 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Tnb.WarehouseMgr.Entities.Dto.ErpInputs +{ + public class AllotInput + { + /// + /// 起始库位ID + /// + public string startlocation { get; set; } = string.Empty; + + /// + /// 目标库位ID + /// + public string endlocation { get; set; } = string.Empty; + + /// + /// 单据状态 + /// + public string status { get; set; } = string.Empty; + + /// + /// 业务类型: + /// + public string biz_type { get; set; } = string.Empty; + + /// + /// 所属仓库 + /// + public string warehouse { get; set; } = string.Empty; + } +} diff --git a/WarehouseMgr/Tnb.WarehouseMgr.Entities/Dto/ErpInputs/PurchaseArriveInput.cs b/WarehouseMgr/Tnb.WarehouseMgr.Entities/Dto/ErpInputs/PurchaseArriveInput.cs new file mode 100644 index 00000000..fac481e7 --- /dev/null +++ b/WarehouseMgr/Tnb.WarehouseMgr.Entities/Dto/ErpInputs/PurchaseArriveInput.cs @@ -0,0 +1,74 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Tnb.WarehouseMgr.Entities.Dto.ErpInputs +{ + public class PurchaseArriveInput + { + /// + /// 入库仓库 + /// + public string? warehouse { get; set; } + + /// + /// 供应商代码 + /// + public string? supplier_code { get; set; } + + /// + /// 来源单据ID + /// + public string? source_id { get; set; } + + /// + /// 来源单据代码 + /// + public string? source_code { get; set; } + + /// + /// 供货日期 + /// + public DateTime delivery_date { get; set; } = DateTime.Now; + + /// + /// 运输方式 + /// + public string? shipping_method { get; set; } + public List details { get; set; } + } + public class PurchaseArriveDetail + { + /// + /// 物品代码 + /// + public string material_code { get; set; } = string.Empty; + + /// + /// 采购数量 + /// + public decimal purchase_qty { get; set; } + + /// + /// 已到货数量 + /// + public decimal purchase_prqty { get; set; } + + /// + /// 批次 + /// + public string? code_batch { get; set; } + + /// + /// 本次到货数量 + /// + public decimal purchase_arriveqty { get; set; } + + /// + /// 箱号 + /// + public string? container_no { get; set; } + } +} diff --git a/WarehouseMgr/Tnb.WarehouseMgr.Entities/Dto/ErpInputs/PurchaseReturnInput.cs b/WarehouseMgr/Tnb.WarehouseMgr.Entities/Dto/ErpInputs/PurchaseReturnInput.cs new file mode 100644 index 00000000..5fc4f80f --- /dev/null +++ b/WarehouseMgr/Tnb.WarehouseMgr.Entities/Dto/ErpInputs/PurchaseReturnInput.cs @@ -0,0 +1,73 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Tnb.WarehouseMgr.Entities.Dto.ErpInputs +{ + public class PurchaseReturnInput + { /// + /// 入库仓库 + /// + public string? warehouse { get; set; } + + /// + /// 供应商代码 + /// + public string? supplier_code { get; set; } + + /// + /// 来源单据ID + /// + public string? source_id { get; set; } + + /// + /// 来源单据代码 + /// + public string? source_code { get; set; } + + /// + /// 供货日期 + /// + public DateTime delivery_date { get; set; } = DateTime.Now; + + /// + /// 运输方式 + /// + public string? shipping_method { get; set; } + public List details { get; set; } + } + public class PurchaseReturnDetail + { + /// + /// 物品代码 + /// + public string material_code { get; set; } = string.Empty; + + /// + /// 采购数量 + /// + public decimal purchase_qty { get; set; } + + /// + /// 已到货数量 + /// + public decimal purchase_prqty { get; set; } + + /// + /// 批次 + /// + public string? code_batch { get; set; } + + /// + /// 本次到货数量 + /// + public decimal purchase_arriveqty { get; set; } + + /// + /// 箱号 + /// + public string? container_no { get; set; } + } +} diff --git a/WarehouseMgr/Tnb.WarehouseMgr.Entities/Dto/ErpInputs/SaleOutInput.cs b/WarehouseMgr/Tnb.WarehouseMgr.Entities/Dto/ErpInputs/SaleOutInput.cs new file mode 100644 index 00000000..9aa224aa --- /dev/null +++ b/WarehouseMgr/Tnb.WarehouseMgr.Entities/Dto/ErpInputs/SaleOutInput.cs @@ -0,0 +1,77 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Org.BouncyCastle.Crypto; +using SqlSugar; + +namespace Tnb.WarehouseMgr.Entities.Dto.ErpInputs +{ + public class SaleOutInput + { + /// + /// 仓库 + /// + public string? warehouse { get; set; } + + /// + /// 客户代码 + /// + public string? customer_code { get; set; } + + /// + /// 来源单据ID + /// + public string? source_id { get; set; } + + /// + /// 来源单据代码 + /// + public string? source_code { get; set; } + + /// + /// 供货日期 + /// + public DateTime ship_date { get; set; } = DateTime.Now; + + /// + /// 运输方式 + /// + public string? shipping_method { get; set; } + + public List details { get; set; } + } + public class SaleOutDetail + { + /// + /// 物品代码 + /// + public string material_code { get; set; } = string.Empty; + + /// + /// 批次 + /// + public string? code_batch { get; set; } + + /// + /// 箱号 + /// + public string? container_no { get; set; } + + /// + /// 本次发货数量 + /// + public decimal purchase_arriveqty { get; set; } + + /// + ///已 发货数量 + /// + public decimal purchase_prqty { get; set; } + + /// + /// 发货数量 + /// + public decimal purchase_qty { get; set; } + } +} diff --git a/WarehouseMgr/Tnb.WarehouseMgr.Entities/Entity/WmsAllot.cs b/WarehouseMgr/Tnb.WarehouseMgr.Entities/Entity/WmsAllot.cs new file mode 100644 index 00000000..47e04c0a --- /dev/null +++ b/WarehouseMgr/Tnb.WarehouseMgr.Entities/Entity/WmsAllot.cs @@ -0,0 +1,115 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using JNPF.Common.Contracts; +using JNPF.Common.Security; +using SqlSugar; + +namespace Tnb.WarehouseMgr.Entities +{ + + /// + /// 库内转移 + /// + [SugarTable("wms_allot")] + public partial class WmsAllot : BaseEntity + { + public WmsAllot() + { + id = SnowflakeIdHelper.NextId(); + } + /// + /// 租户ID + /// + public string? tenant_id { get; set; } + + /// + /// 所属组织ID + /// + public string? org_id { get; set; } + + /// + /// 起始库位ID + /// + public string startlocation_id { get; set; } = string.Empty; + + /// + /// 目标库位ID + /// + public string endlocation_id { get; set; } = string.Empty; + + /// + /// 单号 + /// + public string bill_code { get; set; } = string.Empty; + + /// + /// 单据状态 + /// + public string status { get; set; } = string.Empty; + + /// + /// 业务类型: + /// + public string biz_type { get; set; } = string.Empty; + + /// + /// 载具ID + /// + public string carry_id { get; set; } = string.Empty; + + /// + /// 载具编号 + /// + public string carry_code { get; set; } = string.Empty; + + /// + /// 所属仓库 + /// + public string warehouse_id { get; set; } = string.Empty; + + /// + /// 创建用户 + /// + public string create_id { get; set; } = string.Empty; + + /// + /// 创建时间 + /// + public DateTime create_time { get; set; } = DateTime.Now; + + /// + /// 最后修改人员ID + /// + public string? modify_id { get; set; } + + /// + /// 最后修改时间 + /// + public DateTime? modify_time { get; set; } + + /// + /// 扩展字段 + /// + public string? extras { get; set; } + + /// + /// 时间戳(用于并发控制) + /// + public DateTime? timestamp { get; set; } + + /// + /// 流程任务Id + /// + public string? f_flowtaskid { get; set; } + + /// + /// 流程引擎Id + /// + public string? f_flowid { get; set; } + + } + +} diff --git a/WarehouseMgr/Tnb.WarehouseMgr/ErpToWmsService.cs b/WarehouseMgr/Tnb.WarehouseMgr/ErpToWmsService.cs new file mode 100644 index 00000000..b0e0f8c8 --- /dev/null +++ b/WarehouseMgr/Tnb.WarehouseMgr/ErpToWmsService.cs @@ -0,0 +1,212 @@ +using JNPF.DependencyInjection; +using JNPF.DynamicApiController; +using JNPF.Systems.Interfaces.System; +using Microsoft.AspNetCore.Mvc; +using SqlSugar; +using Tnb.BasicData.Entities; +using Tnb.WarehouseMgr.Entities; +using Tnb.WarehouseMgr.Entities.Dto.ErpInputs; + +namespace Tnb.WarehouseMgr +{ + /// + /// erp接口模块 + /// + [ApiDescriptionSettings(Tag = ModuleConsts.Tag, Area = ModuleConsts.Area, Order = 800)] + public class ErpToWmsService : IDynamicApiController, ITransient + { + private readonly ISqlSugarRepository _repository; + private readonly IBillRullService _billRuleService; + public ErpToWmsService(ISqlSugarRepository repository, IBillRullService billRuleService) + { + _repository = repository; + _billRuleService = billRuleService; + } + /// + /// 采购到货单 + /// + public async Task PurchaseArrive(PurchaseArriveInput input) + { + //主表 create_time 采购收货单号 bill_code 单据类型 bill_type 单据状态 status 业务类型 biz_type 入库仓库ID warehouse_id 供应商ID supplier_id 供应商名称supplier_name 生成类型 generate_type + //子表 主表id bill_id 执行状态line_status 单位id unit_id 物料id material_id + var db = _repository.AsSugarClient(); + WmsPurchaseH wmsPurchaseH = new WmsPurchaseH(); + string Code = await _billRuleService.GetBillNumber("WmsPurchase"); + wmsPurchaseH.bill_code = Code; + wmsPurchaseH.bill_type = "25103333373205";//收料通知单(到货单) + wmsPurchaseH.biz_type = "26191496816421";//一般入库 + wmsPurchaseH.status = "25065138925589";//新增 + wmsPurchaseH.generate_type = "1";//0人工 1自动 + wmsPurchaseH.create_time = DateTime.Now; + wmsPurchaseH.source_id = input.source_id; + wmsPurchaseH.source_code = input.source_code; + wmsPurchaseH.delivery_date = input.delivery_date; + wmsPurchaseH.shipping_method = input.shipping_method; + var warehouse = await db.Queryable().Where(p => p.whcode == input.warehouse).FirstAsync(); + if (warehouse != null) + wmsPurchaseH.warehouse_id = warehouse.id; + wmsPurchaseH.supplier_code = input.supplier_code; + var supplier = await db.Queryable().Where(p => p.supplier_code == input.supplier_code).FirstAsync(); + if (supplier != null) + { + wmsPurchaseH.supplier_id = supplier.id; + wmsPurchaseH.supplier_name = supplier.supplier_name; + } + List WmsPurchaseDs = new List(); + foreach (var detail in input.details) + { + WmsPurchaseD wmsPurchased = new WmsPurchaseD(); + wmsPurchased.bill_id = wmsPurchaseH.id; + wmsPurchased.line_status = "25065138925589";//新增 + wmsPurchased.purchase_qty = detail.purchase_qty; + wmsPurchased.purchase_prqty = detail.purchase_prqty; + wmsPurchased.code_batch = detail.code_batch; + wmsPurchased.purchase_arriveqty = detail.purchase_arriveqty; + wmsPurchased.container_no = detail.container_no; + wmsPurchased.material_code = detail.material_code; + var material = await db.Queryable().Where(p => p.code == detail.material_code).FirstAsync(); + if (material != null) + { + wmsPurchased.material_id = material.id; + // wmsPurchased.material_name = material.name; + wmsPurchased.unit_id = material.unit_id; + } + WmsPurchaseDs.Add(wmsPurchased); + } + await db.Insertable(wmsPurchaseH).ExecuteCommandAsync(); + await db.Insertable(WmsPurchaseDs).ExecuteCommandAsync(); + + } + /// + /// 采购退货单 + /// + public async Task PurchaseReturn(PurchaseReturnInput input) + { + //主表 create_time 采购收货单号 bill_code 单据类型 bill_type 单据状态 status 业务类型 biz_type 入库仓库ID warehouse_id 供应商ID supplier_id 供应商名称supplier_name 生成类型 generate_type + //子表 主表id bill_id 执行状态line_status 单位id unit_id 物料id material_id + var db = _repository.AsSugarClient(); + WmsPurchaseH wmsPurchaseH = new WmsPurchaseH(); + string Code = await _billRuleService.GetBillNumber("WmsPurchase"); + wmsPurchaseH.bill_code = Code; + wmsPurchaseH.bill_type = "25103345478421";//采购退料单 + wmsPurchaseH.biz_type = "26191522660645";//一般出库 + wmsPurchaseH.status = "25065138925589";//新增 + wmsPurchaseH.generate_type = "1";//0人工 1自动 + wmsPurchaseH.create_time = DateTime.Now; + wmsPurchaseH.source_id = input.source_id; + wmsPurchaseH.source_code = input.source_code; + wmsPurchaseH.delivery_date = input.delivery_date; + wmsPurchaseH.shipping_method = input.shipping_method; + var warehouse = await db.Queryable().Where(p => p.whcode == input.warehouse).FirstAsync(); + if (warehouse != null) + wmsPurchaseH.warehouse_id = warehouse.id; + wmsPurchaseH.supplier_code = input.supplier_code; + var supplier = await db.Queryable().Where(p => p.supplier_code == input.supplier_code).FirstAsync(); + if (supplier != null) + { + wmsPurchaseH.supplier_id = supplier.id; + + wmsPurchaseH.supplier_name = supplier.supplier_name; + } + List WmsPurchaseDs = new List(); + foreach (var detail in input.details) + { + WmsPurchaseD wmsPurchased = new WmsPurchaseD(); + wmsPurchased.bill_id = wmsPurchaseH.id; + wmsPurchased.line_status = "25065138925589";//新增 + wmsPurchased.purchase_qty = detail.purchase_qty; + wmsPurchased.purchase_prqty = detail.purchase_prqty; + wmsPurchased.code_batch = detail.code_batch; + wmsPurchased.purchase_arriveqty = detail.purchase_arriveqty; + wmsPurchased.container_no = detail.container_no; + wmsPurchased.material_code = detail.material_code; + var material = await db.Queryable().Where(p => p.code == detail.material_code).FirstAsync(); + if (material != null) + { + wmsPurchased.material_id = material.id; + // wmsPurchased.material_name = material.name; + wmsPurchased.unit_id = material.unit_id; + } + WmsPurchaseDs.Add(wmsPurchased); + } + await db.Insertable(wmsPurchaseH).ExecuteCommandAsync(); + await db.Insertable(WmsPurchaseDs).ExecuteCommandAsync(); + + } + /// + /// 仓库调拨 + /// + public async Task Allot(AllotInput input) + { + var db = _repository.AsSugarClient(); + WmsAllot wmsAllot = new WmsAllot(); + string Code = await _billRuleService.GetBillNumber("WmsTransfer"); + wmsAllot.bill_code = Code; + wmsAllot.biz_type = "25044010525205";//仓库调拨 + wmsAllot.status = "25065138925589";//新增 + var warehouse = await db.Queryable().Where(p => p.whcode == input.warehouse).FirstAsync(); + if (warehouse != null) + wmsAllot.warehouse_id = warehouse.id; + var startloc = await db.Queryable().Where(p => p.location_code == input.startlocation).FirstAsync(); + if (startloc != null) + wmsAllot.startlocation_id = startloc.id; + var endloc = await db.Queryable().Where(p => p.location_code == input.endlocation).FirstAsync(); + if (endloc != null) + wmsAllot.endlocation_id = endloc.id; + wmsAllot.create_time = DateTime.Now; + await db.Insertable(wmsAllot).ExecuteCommandAsync(); + } + /// + /// 销售出库单 + /// + public async Task SaleOut(SaleOutInput input) + { + var db = _repository.AsSugarClient(); + WmsSaleH WmsSaleH = new WmsSaleH(); + string Code = await _billRuleService.GetBillNumber("WmsSale"); + WmsSaleH.bill_code = Code; + WmsSaleH.bill_type = "25103439022357";//销售出库单 + WmsSaleH.biz_type = "26191522660645";//一般出库 + WmsSaleH.status = "25065138925589";//新增 + WmsSaleH.generate_type = "1";//0人工 1自动 + WmsSaleH.create_time = DateTime.Now; + WmsSaleH.source_id = input.source_id; + WmsSaleH.source_code = input.source_code; + WmsSaleH.ship_date = input.ship_date; + WmsSaleH.shipping_method = input.shipping_method; + var warehouse = await db.Queryable().Where(p => p.whcode == input.warehouse).FirstAsync(); + if (warehouse != null) + WmsSaleH.warehouse_id = warehouse.id; + WmsSaleH.customer_code = input.customer_code; + var customer = await db.Queryable().Where(p => p.customer_code == input.customer_code).FirstAsync(); + if (customer != null) + { + WmsSaleH.customer_id = customer.id; + WmsSaleH.customer_name = customer.customer_name; + } + List WmsSaleDs = new List(); + foreach (var detail in input.details) + { + WmsSaleD WmsSaleD = new WmsSaleD(); + WmsSaleD.bill_id = WmsSaleH.id; + WmsSaleD.line_status = "25065138925589";//新增 + WmsSaleD.purchase_qty = detail.purchase_qty; + WmsSaleD.purchase_prqty = detail.purchase_prqty; + WmsSaleD.code_batch = detail.code_batch; + WmsSaleD.purchase_arriveqty = detail.purchase_arriveqty; + WmsSaleD.container_no = detail.container_no; + WmsSaleD.material_code = detail.material_code; + var material = await db.Queryable().Where(p => p.code == detail.material_code).FirstAsync(); + if (material != null) + { + WmsSaleD.material_id = material.id; + // WmsSaleD.material_name = material.name; + WmsSaleD.unit_id = material.unit_id; + } + WmsSaleDs.Add(WmsSaleD); + } + await db.Insertable(WmsSaleH).ExecuteCommandAsync(); + await db.Insertable(WmsSaleDs).ExecuteCommandAsync(); + } + } +}