From c2066b44772a1516bb8bc0cf25873f2aff902f5b Mon Sep 17 00:00:00 2001 From: xs Date: Fri, 30 Aug 2024 16:04:55 +0800 Subject: [PATCH] =?UTF-8?q?3.0.3=20WMS:=20=E5=AE=8C=E5=96=84=E5=90=8C?= =?UTF-8?q?=E6=AD=A5=E5=8E=9F=E6=9D=90=E6=96=99=E5=85=A5=E5=BA=93=E4=BF=A1?= =?UTF-8?q?=E6=81=AF=E7=BB=99ERP=E3=80=81=E5=90=8C=E6=AD=A5=E5=8E=9F?= =?UTF-8?q?=E6=9D=90=E6=96=99=E5=87=BA=E5=BA=93=E4=BF=A1=E6=81=AF=E7=BB=99?= =?UTF-8?q?ERP=E3=80=81=E5=90=8C=E6=AD=A5=E6=88=90=E5=93=81=E5=85=A5?= =?UTF-8?q?=E5=BA=93=E4=BF=A1=E6=81=AF=E7=BB=99ERP=E5=92=8C=E5=90=8C?= =?UTF-8?q?=E6=AD=A5=E6=88=90=E5=93=81=E5=87=BA=E5=BA=93=E4=BF=A1=E6=81=AF?= =?UTF-8?q?=E7=BB=99ERP?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../hw/wms/controller/WmsApiController.java | 2 +- .../java/com/hw/wms/domain/WmsRawInstock.java | 10 +++ .../impl/WmsErpScheduledTaskServiceImpl.java | 79 +++++++++++-------- .../mapper/wms/WmsProductOutstockMapper.xml | 3 +- .../mapper/wms/WmsRawInstockMapper.xml | 10 ++- .../mapper/wms/WmsRawOutstockMapper.xml | 2 - 6 files changed, 64 insertions(+), 42 deletions(-) diff --git a/hw-modules/hw-wms/src/main/java/com/hw/wms/controller/WmsApiController.java b/hw-modules/hw-wms/src/main/java/com/hw/wms/controller/WmsApiController.java index 08328b6..f1acaee 100644 --- a/hw-modules/hw-wms/src/main/java/com/hw/wms/controller/WmsApiController.java +++ b/hw-modules/hw-wms/src/main/java/com/hw/wms/controller/WmsApiController.java @@ -221,7 +221,7 @@ public class WmsApiController extends BaseController { /** - * 定时同步入库信息给ERP + * 定时同步原材料入库信息给ERP * @return */ @PostMapping(("/synchronizeInventoryInformationToERP")) diff --git a/hw-modules/hw-wms/src/main/java/com/hw/wms/domain/WmsRawInstock.java b/hw-modules/hw-wms/src/main/java/com/hw/wms/domain/WmsRawInstock.java index 900d4b5..0e7249e 100644 --- a/hw-modules/hw-wms/src/main/java/com/hw/wms/domain/WmsRawInstock.java +++ b/hw-modules/hw-wms/src/main/java/com/hw/wms/domain/WmsRawInstock.java @@ -134,6 +134,8 @@ public class WmsRawInstock extends BaseEntity /** 规格参数 */ private String specificationParameter; + private String srcBillNo; + public String getSpecificationParameter() { return specificationParameter; } @@ -399,6 +401,14 @@ public class WmsRawInstock extends BaseEntity this.materialName = materialName; } + public String getSrcBillNo() { + return srcBillNo; + } + + public void setSrcBillNo(String srcBillNo) { + this.srcBillNo = srcBillNo; + } + @Override public String toString() { return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE) diff --git a/hw-modules/hw-wms/src/main/java/com/hw/wms/service/impl/WmsErpScheduledTaskServiceImpl.java b/hw-modules/hw-wms/src/main/java/com/hw/wms/service/impl/WmsErpScheduledTaskServiceImpl.java index 471afaf..56de50f 100644 --- a/hw-modules/hw-wms/src/main/java/com/hw/wms/service/impl/WmsErpScheduledTaskServiceImpl.java +++ b/hw-modules/hw-wms/src/main/java/com/hw/wms/service/impl/WmsErpScheduledTaskServiceImpl.java @@ -3,6 +3,7 @@ package com.hw.wms.service.impl; import com.alibaba.fastjson2.JSONObject; import com.hw.common.core.constant.SecurityConstants; import com.hw.common.core.domain.R; +import com.hw.common.core.exception.ServiceException; import com.hw.common.core.utils.DateUtils; import com.hw.common.core.web.domain.AjaxResult; import com.hw.jindie.api.RemoteJindieService; @@ -62,20 +63,22 @@ public class WmsErpScheduledTaskServiceImpl implements IWmsErpScheduledTaskServi * @return */ @Override + @Transactional public int synchronizeInventoryInformationToERP() { WmsRawInstock wmsRawInstock = new WmsRawInstock(); int result = 0; List inStockList = wmsRawInstockMapper.selectWmsRawInstockERPNotSynchronized(wmsRawInstock); - Map> materialIdMap = inStockList.stream().collect(Collectors.groupingBy(WmsRawInstock::getMaterialId)); - for (Long materialId : materialIdMap.keySet()) { - syncInventoryInformation(materialIdMap, materialId, result); + Map> purchaseOrderIdMap = inStockList.stream().collect(Collectors.groupingBy(WmsRawInstock::getPurchaseOrderId)); + + for (Long purchaseOrderId : purchaseOrderIdMap.keySet()) { + syncInventoryInformation(purchaseOrderIdMap, purchaseOrderId, result); } return result; } @Transactional(propagation = Propagation.REQUIRES_NEW) - void syncInventoryInformation(Map> materialIdMap, Long materialId, int result) { - List wmsRawInstockList = materialIdMap.get(materialId); + public void syncInventoryInformation(Map> purchaseOrderIdMap, Long purchaseOrderId, int result) { + List wmsRawInstockList = purchaseOrderIdMap.get(purchaseOrderId); JSONObject data = new JSONObject(); double FRealQty = wmsRawInstockList.stream().mapToDouble(item -> item.getInstockAmount().subtract(item.getErpAmount()).doubleValue()).sum(); WmsRawInstock instock = wmsRawInstockList.get(0); @@ -88,7 +91,7 @@ public class WmsErpScheduledTaskServiceImpl implements IWmsErpScheduledTaskServi data.put("FDate", DateUtils.getTime()); data.put("FMaterialId", instock.getMaterialCode()); data.put("FAuxPropId", instock.getSpecificationParameter()); - data.put("FSrcBillNo", instock.getPoNo()); + data.put("FSrcBillNo", instock.getSrcBillNo()); data.put("FUnitID", instock.getUnitCode()); data.put("FRealQty", FRealQty); data.put("FStockId", FStockId); @@ -99,9 +102,10 @@ public class WmsErpScheduledTaskServiceImpl implements IWmsErpScheduledTaskServi Boolean isSuccess = (Boolean) jsonObject.get("IsSuccess"); if (isSuccess) { result++; - log.info("synchronizeInventoryInformationToERP成功:" + paramsResult.toString()); + log.info("synchronizeInventoryInformationToERP同步原材料入库成功:" + paramsResult.toString()); } else { - log.error("synchronizeInventoryInformationToERP失败:" + paramsResult.toString()); + log.error("synchronizeInventoryInformationToERP同步原材料入库失败:" + paramsResult.toString()); + throw new RuntimeException("同步原材料入库失败"+paramsResult.toString()); } } @@ -111,6 +115,7 @@ public class WmsErpScheduledTaskServiceImpl implements IWmsErpScheduledTaskServi * @return */ @Override + @Transactional public int synchronizeRawMaterialDeliveryInformationToERP() { WmsRawOutstock rawOutstock = new WmsRawOutstock(); int result = 0; @@ -123,11 +128,22 @@ public class WmsErpScheduledTaskServiceImpl implements IWmsErpScheduledTaskServi } @Transactional(propagation = Propagation.REQUIRES_NEW) - void syncOutstockInformation(Map> materialIdMap, Long materialId, int result) { + public void syncOutstockInformation(Map> materialIdMap, Long materialId, int result) { List wmsRawOutstockList = materialIdMap.get(materialId); JSONObject data = new JSONObject(); double FRealQty = wmsRawOutstockList.stream().mapToDouble(item -> item.getRealOutstockAmount().subtract(item.getErpAmount()).doubleValue()).sum(); WmsRawOutstock outstock = wmsRawOutstockList.get(0); + for (WmsRawOutstock wmsRawOutstock : wmsRawOutstockList) { + if (wmsRawOutstock.getRealOutstockAmount().equals(wmsRawOutstock.getOutstockAmount())) { + wmsRawOutstock.setErpStatus("1");//同步ERP状态(0:失败,1成功,2同步中) + } else { + wmsRawOutstock.setErpStatus("2");//同步ERP状态(0:失败,1成功,2同步中) + } + wmsRawOutstock.setErpAmount(wmsRawOutstock.getRealOutstockAmount()); + wmsRawOutstock.setUpdateDate(DateUtils.getNowDate()); + wmsRawOutstockMapper.updateWmsRawOutstock(wmsRawOutstock); + } + data.put("FDate", DateUtils.getTime()); data.put("FMaterialId", outstock.getMaterialCode()); data.put("FAuxPropId", outstock.getSpecificationParameter()); @@ -142,19 +158,10 @@ public class WmsErpScheduledTaskServiceImpl implements IWmsErpScheduledTaskServi Boolean isSuccess = (Boolean) jsonObject.get("IsSuccess"); if (isSuccess) { result++; - for (WmsRawOutstock wmsRawOutstock : wmsRawOutstockList) { - if (wmsRawOutstock.getRealOutstockAmount().equals(wmsRawOutstock.getOutstockAmount())) { - wmsRawOutstock.setErpStatus("1");//同步ERP状态(0:失败,1成功,2同步中) - } else { - wmsRawOutstock.setErpStatus("2");//同步ERP状态(0:失败,1成功,2同步中) - } - wmsRawOutstock.setErpAmount(wmsRawOutstock.getRealOutstockAmount()); - wmsRawOutstock.setUpdateDate(DateUtils.getNowDate()); - wmsRawOutstockMapper.updateWmsRawOutstock(wmsRawOutstock); - } log.info("synchronizeRawMaterialDeliveryInformationToERP成功:" + paramsResult.toString()); } else { log.error("synchronizeRawMaterialDeliveryInformationToERP失败:" + paramsResult.toString()); + throw new RuntimeException("synchronizeRawMaterialDeliveryInformationToERP失败:" + paramsResult.toString()); } } @@ -164,6 +171,7 @@ public class WmsErpScheduledTaskServiceImpl implements IWmsErpScheduledTaskServi * @return */ @Override + @Transactional public int synchronizeProductInstockInformationToERP(Integer days) { int result = 0; WmsProductInstock wmsProductInstock = new WmsProductInstock(); @@ -181,11 +189,18 @@ public class WmsErpScheduledTaskServiceImpl implements IWmsErpScheduledTaskServi } @Transactional(propagation = Propagation.REQUIRES_NEW) - void syncProductInstockInformation(Map> productIdMap, Long productId, int result) { + public void syncProductInstockInformation(Map> productIdMap, Long productId, int result) { List wmsProductInstockList = productIdMap.get(productId); JSONObject data = new JSONObject(); double FRealQty = wmsProductInstockList.stream().mapToDouble(item -> item.getInstockAmount().subtract(item.getErpAmount()).doubleValue()).sum(); WmsProductInstock instock = wmsProductInstockList.get(0); + for (WmsProductInstock wmsProductInstock : wmsProductInstockList) { + wmsProductInstock.setErpStatus("1");//同步ERP状态(0:失败,1成功) + wmsProductInstock.setErpAmount(wmsProductInstock.getInstockAmount()); + wmsProductInstock.setUpdateDate(DateUtils.getNowDate()); + wmsProductInstockMapper.updateWmsProductInstock(wmsProductInstock); + } + data.put("FDate", DateUtils.getTime()); data.put("FMaterialId", instock.getMaterialCode()); data.put("FAuxPropId", instock.getSpecificationParameter()); @@ -200,15 +215,10 @@ public class WmsErpScheduledTaskServiceImpl implements IWmsErpScheduledTaskServi Boolean isSuccess = (Boolean) jsonObject.get("IsSuccess"); if (isSuccess) { result++; - for (WmsProductInstock wmsProductInstock : wmsProductInstockList) { - wmsProductInstock.setErpStatus("1");//同步ERP状态(0:失败,1成功) - wmsProductInstock.setErpAmount(wmsProductInstock.getInstockAmount()); - wmsProductInstock.setUpdateDate(DateUtils.getNowDate()); - wmsProductInstockMapper.updateWmsProductInstock(wmsProductInstock); - } log.info("synchronizeProductInstockInformationToERP成功:" + paramsResult.toString()); } else { log.error("synchronizeProductInstockInformationToERP失败:" + paramsResult.toString()); + throw new RuntimeException("synchronizeProductInstockInformationToERP失败:" + paramsResult.toString()); } } @@ -218,6 +228,7 @@ public class WmsErpScheduledTaskServiceImpl implements IWmsErpScheduledTaskServi * @return */ @Override + @Transactional public int synchronizeProductOutstockInformationToERP(Integer days) { int result = 0; WmsProductOutstock wmsProductOutstock = new WmsProductOutstock(); @@ -235,11 +246,17 @@ public class WmsErpScheduledTaskServiceImpl implements IWmsErpScheduledTaskServi } @Transactional(propagation = Propagation.REQUIRES_NEW) - void syncProductOutstockInformation(Map> productIdMap, Long productId, int result) { + public void syncProductOutstockInformation(Map> productIdMap, Long productId, int result) { List wmsProductOutstockList = productIdMap.get(productId); JSONObject data = new JSONObject(); double FRealQty = wmsProductOutstockList.stream().mapToDouble(item -> item.getOutstockQty().subtract(item.getErpAmount()).doubleValue()).sum(); WmsProductOutstock outstock = wmsProductOutstockList.get(0); + for (WmsProductOutstock wmsProductOutstock : wmsProductOutstockList) { + wmsProductOutstock.setErpStatus("1");//同步ERP状态(0:失败,1成功) + wmsProductOutstock.setErpAmount(wmsProductOutstock.getOutstockQty()); + wmsProductOutstock.setUpdateDate(DateUtils.getNowDate()); + wmsProductOutstockMapper.updateWmsProductOutstock(wmsProductOutstock); + } data.put("FDate", DateUtils.getTime()); data.put("FMaterialId", outstock.getMaterialCode()); data.put("FAuxPropId", outstock.getSpecificationParameter()); @@ -254,15 +271,11 @@ public class WmsErpScheduledTaskServiceImpl implements IWmsErpScheduledTaskServi Boolean isSuccess = (Boolean) jsonObject.get("IsSuccess"); if (isSuccess) { result++; - for (WmsProductOutstock wmsProductOutstock : wmsProductOutstockList) { - wmsProductOutstock.setErpStatus("1");//同步ERP状态(0:失败,1成功) - wmsProductOutstock.setErpAmount(wmsProductOutstock.getOutstockQty()); - wmsProductOutstock.setUpdateDate(DateUtils.getNowDate()); - wmsProductOutstockMapper.updateWmsProductOutstock(wmsProductOutstock); - } + log.info("synchronizeProductOutstockInformationToERP成功:" + paramsResult.toString()); } else { log.error("synchronizeProductOutstockInformationToERP失败:" + paramsResult.toString()); + throw new RuntimeException("synchronizeProductOutstockInformationToERP失败:" + paramsResult.toString()); } } diff --git a/hw-modules/hw-wms/src/main/resources/mapper/wms/WmsProductOutstockMapper.xml b/hw-modules/hw-wms/src/main/resources/mapper/wms/WmsProductOutstockMapper.xml index 50eddeb..4b64658 100644 --- a/hw-modules/hw-wms/src/main/resources/mapper/wms/WmsProductOutstockMapper.xml +++ b/hw-modules/hw-wms/src/main/resources/mapper/wms/WmsProductOutstockMapper.xml @@ -314,8 +314,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" from wms_product_outstock wpo left join mes_base_material_info mbmi on mbmi.material_id = wpo.product_id left join mes_base_unit_info mbui on mbui.erp_id = mbmi.material_unit_id - left join mes_product_plan mpp on mpp.plan_code = wpo.plan_code - left join mes_sale_order mso on mso.sale_order_id = mpp.sale_order_id + left join mes_sale_order mso on mso.sale_order_id = wpo.sale_order_id where wpo.outstock_type = '1' and wpo.outstock_qty > 0 and wpo.apply_qty >= wpo.outstock_qty diff --git a/hw-modules/hw-wms/src/main/resources/mapper/wms/WmsRawInstockMapper.xml b/hw-modules/hw-wms/src/main/resources/mapper/wms/WmsRawInstockMapper.xml index 3c3f3f1..f22d62d 100644 --- a/hw-modules/hw-wms/src/main/resources/mapper/wms/WmsRawInstockMapper.xml +++ b/hw-modules/hw-wms/src/main/resources/mapper/wms/WmsRawInstockMapper.xml @@ -38,6 +38,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" + @@ -211,7 +212,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" wri.instock_type, wri.material_id, wri.po_no, + wri.purchase_order_id, mpo.specification_parameter, + mpo.src_bill_no, mbmi.material_code, mbui.unit_code, wri.instock_amount, @@ -221,13 +224,12 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" left join wms_base_warehouse wbw on wbw.warehouse_id = wri.warehouse_id left join mes_base_material_info mbmi on mbmi.material_id = wri.material_id left join mes_base_unit_info mbui on mbui.erp_id = mbmi.material_unit_id - join (select po_no, material_id, max(specification_parameter) specification_parameter - from mes_purchase_order - group by po_no, material_id) mpo on mpo.po_no = wri.po_no and mpo.material_id = wri.material_id + left join mes_purchase_order mpo on wri.purchase_order_id = mpo.purchase_order_id where wri.execute_status = 2 and (wri.erp_status != 1 or wri.erp_status is null) and wri.instock_type in (1, 3) - and wri.instock_amount > if(wri.erp_amount is null, 0, wri.erp_amount) + and wri.instock_amount > if(wri.erp_amount is null, 0, wri.erp_amount) + and wri.purchase_order_id is not null and wri.purchase_order_id !=0 diff --git a/hw-modules/hw-wms/src/main/resources/mapper/wms/WmsRawOutstockMapper.xml b/hw-modules/hw-wms/src/main/resources/mapper/wms/WmsRawOutstockMapper.xml index ac080ba..139de25 100644 --- a/hw-modules/hw-wms/src/main/resources/mapper/wms/WmsRawOutstockMapper.xml +++ b/hw-modules/hw-wms/src/main/resources/mapper/wms/WmsRawOutstockMapper.xml @@ -357,7 +357,6 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" select wro.raw_outstock_id, wro.task_code, wro.warehouse_id, - wbw.warehouse_code, wro.operation_type, wro.material_id, mbmi.material_code, @@ -369,7 +368,6 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" mso.price, mso.specification_parameter from wms_raw_outstock wro - left join wms_base_warehouse wbw on wbw.warehouse_id = wro.warehouse_id left join mes_base_material_info mbmi on mbmi.material_id = wro.material_id left join mes_base_unit_info mbui on mbui.erp_id = mbmi.material_unit_id left join mes_product_plan mpp on mpp.plan_code = wro.plan_code