From a27f1b573fc5cf9a3b78e2eacb56e44310f83456 Mon Sep 17 00:00:00 2001
From: zhangherong <571457620@qq.com>
Date: 星期三, 27 八月 2025 12:17:01 +0800
Subject: [PATCH] art: 添加入库逻辑,SAP订单同步参数动态配置

---
 src/main/java/org/jeecg/modules/wms/service/impl/MESWebServiceSoapImpl.java         |   66 ++++++++++++++-
 /dev/null                                                                           |   34 --------
 src/main/java/org/jeecg/modules/lsw/entity/LswMaterialInventory.java                |   12 +++
 src/main/java/org/jeecg/modules/lsw/service/ILswMaterialInboundService.java         |    7 +
 src/main/java/org/jeecg/modules/lsw/service/impl/LswMaterialInboundServiceImpl.java |   37 +++++++++
 src/main/java/org/jeecg/modules/mes/job/ProductionOrderSyncCreationJob.java         |   13 ++-
 src/main/java/org/jeecg/modules/lsw/enums/MaterialInventoryStatusEnum.java          |    7 +
 src/main/resources/application-dev.yml                                              |    7 +
 src/main/resources/application-prod.yml                                             |    7 +
 src/main/java/org/jeecg/modules/wms/request/WMSWebServiceSendItem.java              |    3 
 src/main/java/org/jeecg/modules/mes/job/ProductionOrderSyncUpdateJob.java           |   13 ++-
 11 files changed, 154 insertions(+), 52 deletions(-)

diff --git a/src/main/java/org/jeecg/modules/lsw/entity/LswMaterialInventory.java b/src/main/java/org/jeecg/modules/lsw/entity/LswMaterialInventory.java
index 2c8c6b7..73d6730 100644
--- a/src/main/java/org/jeecg/modules/lsw/entity/LswMaterialInventory.java
+++ b/src/main/java/org/jeecg/modules/lsw/entity/LswMaterialInventory.java
@@ -9,6 +9,7 @@
 import io.swagger.annotations.ApiModelProperty;
 import lombok.Data;
 import org.jeecg.common.aspect.annotation.Dict;
+import org.jeecg.modules.lsw.enums.MaterialInventoryStatusEnum;
 import org.jeecgframework.poi.excel.annotation.Excel;
 import org.springframework.format.annotation.DateTimeFormat;
 
@@ -76,4 +77,15 @@
 	@Excel(name = "搴撳瓨鐘舵��", width = 15)
     @ApiModelProperty(value = "搴撳瓨鐘舵��")
     private String inventoryStatus;
+
+    public LswMaterialInventory(){}
+
+    public LswMaterialInventory(LswMaterialInbound inbound, String materialId, String inventoryCategory) {
+        this.warehouseId = inbound.getWarehouseId();
+        this.quantity = inbound.getQuantity();
+        this.batchNumber = inbound.getBatchNumber();
+        this.inventoryStatus = MaterialInventoryStatusEnum.NORMAL.name();
+        this.inventoryCategory = inventoryCategory;
+        this.materialId = materialId;
+    }
 }
diff --git a/src/main/java/org/jeecg/modules/lsw/enums/MaterialCategory.java b/src/main/java/org/jeecg/modules/lsw/enums/MaterialCategory.java
deleted file mode 100644
index 9e1a112..0000000
--- a/src/main/java/org/jeecg/modules/lsw/enums/MaterialCategory.java
+++ /dev/null
@@ -1,34 +0,0 @@
-package org.jeecg.modules.lsw.enums;
-
-
-public enum MaterialCategory {
-    /**
-     * 鎴愬搧
-     */
-    FINISHED,
-    /**
-     * 鍗婃垚鍝�
-     */
-    HALF,
-    /**
-     * 姣涘澂
-     */
-    RAW,
-    /**
-     * 閰嶄欢
-     */
-    PARTS;
-
-    /**
-     * @param name 鏋氫妇鐨勫悕绉�
-     * @return 瀵瑰簲鐨� MaterialCategory 鏋氫妇绫诲瀷锛屽鏋滄湭鎵惧埌鍒欒繑鍥� null
-     */
-    public static MaterialCategory fromName(String name) {
-        for (MaterialCategory category : MaterialCategory.values()) {
-            if (category.name().equals(name)) {
-                return category;
-            }
-        }
-        return null;
-    }
-}
diff --git a/src/main/java/org/jeecg/modules/lsw/enums/MaterialInventoryStatusEnum.java b/src/main/java/org/jeecg/modules/lsw/enums/MaterialInventoryStatusEnum.java
new file mode 100644
index 0000000..62be8a4
--- /dev/null
+++ b/src/main/java/org/jeecg/modules/lsw/enums/MaterialInventoryStatusEnum.java
@@ -0,0 +1,7 @@
+package org.jeecg.modules.lsw.enums;
+
+public enum MaterialInventoryStatusEnum {
+    NORMAL, //姝e父
+    OUTBOUND, //宸插嚭搴�
+    ;
+}
diff --git a/src/main/java/org/jeecg/modules/lsw/service/ILswMaterialInboundService.java b/src/main/java/org/jeecg/modules/lsw/service/ILswMaterialInboundService.java
index 17f3cdd..ed3af60 100644
--- a/src/main/java/org/jeecg/modules/lsw/service/ILswMaterialInboundService.java
+++ b/src/main/java/org/jeecg/modules/lsw/service/ILswMaterialInboundService.java
@@ -15,4 +15,11 @@
  */
 public interface ILswMaterialInboundService extends IService<LswMaterialInbound> {
     IPage<Map<String, Object>> getlswMaterialInboundListData(Integer pageNo, Integer pageSize, HttpServletRequest req);
+
+    /**
+     * 鐗╂枡鍏ュ簱
+     * @param materialInbound 鍏ュ簱淇℃伅
+     * @return
+     */
+    boolean inboundMaterial(LswMaterialInbound materialInbound);
 }
diff --git a/src/main/java/org/jeecg/modules/lsw/service/impl/LswMaterialInboundServiceImpl.java b/src/main/java/org/jeecg/modules/lsw/service/impl/LswMaterialInboundServiceImpl.java
index ae750d2..3c2899e 100644
--- a/src/main/java/org/jeecg/modules/lsw/service/impl/LswMaterialInboundServiceImpl.java
+++ b/src/main/java/org/jeecg/modules/lsw/service/impl/LswMaterialInboundServiceImpl.java
@@ -4,12 +4,20 @@
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import org.apache.commons.lang.StringUtils;
+import org.jeecg.common.constant.CommonConstant;
+import org.jeecg.modules.lsw.entity.LswMaterial;
 import org.jeecg.modules.lsw.entity.LswMaterialInbound;
+import org.jeecg.modules.lsw.entity.LswMaterialInventory;
 import org.jeecg.modules.lsw.mapper.LswMaterialInboundMapper;
 import org.jeecg.modules.lsw.service.ILswMaterialInboundService;
+import org.jeecg.modules.lsw.service.ILswMaterialInventoryService;
+import org.jeecg.modules.lsw.service.ILswMaterialService;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
 
 import javax.servlet.http.HttpServletRequest;
+import java.util.Date;
 import java.util.HashMap;
 import java.util.Map;
 
@@ -21,6 +29,10 @@
  */
 @Service
 public class LswMaterialInboundServiceImpl extends ServiceImpl<LswMaterialInboundMapper, LswMaterialInbound> implements ILswMaterialInboundService {
+    @Autowired
+    private ILswMaterialInventoryService inventoryService;
+    @Autowired
+    private ILswMaterialService materialService;
 
     @Override
     public IPage<Map<String, Object>> getlswMaterialInboundListData(Integer pageNo, Integer pageSize, HttpServletRequest req) {
@@ -40,4 +52,29 @@
         }
         return super.getBaseMapper().getlswMaterialInboundListData(pageData, paramMap);
     }
+
+    @Override
+    @Transactional(rollbackFor = Exception.class)
+    public boolean inboundMaterial(LswMaterialInbound materialInbound) {
+        if (StringUtils.isBlank(materialInbound.getMaterialNumber())
+                || StringUtils.isBlank(materialInbound.getFactoryId())
+                || StringUtils.isBlank(materialInbound.getWarehouseId())
+                || materialInbound.getQuantity() == null
+                || materialInbound.getQuantity().intValue() > 0
+                || StringUtils.isBlank(materialInbound.getBatchNumber())) {
+            return false;
+        }
+        LswMaterial material = materialService.queryByMaterialNumber(materialInbound.getMaterialNumber());
+        if(material == null) {
+            return false;
+        }
+        //淇濆瓨鍏ュ簱淇℃伅
+        materialInbound.setDelFlag(CommonConstant.DEL_FLAG_0);
+        materialInbound.setReceiveTime(new Date());
+        super.save(materialInbound);
+        //淇濆瓨搴撳瓨淇℃伅
+        LswMaterialInventory lswMaterialInventory = new LswMaterialInventory(materialInbound, material.getId(), material.getMaterialCategory());
+        inventoryService.save(lswMaterialInventory);
+        return true;
+    }
 }
diff --git a/src/main/java/org/jeecg/modules/mes/job/ProductionOrderSyncCreationJob.java b/src/main/java/org/jeecg/modules/mes/job/ProductionOrderSyncCreationJob.java
index 42bd30d..1d0c9fa 100644
--- a/src/main/java/org/jeecg/modules/mes/job/ProductionOrderSyncCreationJob.java
+++ b/src/main/java/org/jeecg/modules/mes/job/ProductionOrderSyncCreationJob.java
@@ -23,6 +23,7 @@
 import org.quartz.JobExecutionContext;
 import org.quartz.JobExecutionException;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Component;
 
 import java.time.LocalDateTime;
@@ -34,7 +35,8 @@
 @Slf4j
 public class ProductionOrderSyncCreationJob implements Job {
     //宸ュ巶缂栫爜(鏂扮伀鐐� 2301)
-    private static final String FACTORY_CODE = "2301";
+    @Value("${xhj.factoryCode:2301}")
+    private String FACTORY_CODE;
     /**
      * 璁㈠崟绫诲瀷
      * 鏍囧噯鐢熶骇璁㈠崟 Z001
@@ -43,7 +45,8 @@
      * 璇曞埗鐢熶骇璁㈠崟(鏂扮伀鐐�)  Z011
      * 鎷嗛浂鐢熶骇璁㈠崟(鏂扮伀鐐�)  2012
      */
-    private static final String ORDER_TYPE_CODE = "Z001";
+    @Value("${xhj.orderType:Z001}")
+    private String ORDER_TYPE_CODE;
     /**
      * 鐢熶骇璋冨害鍛�
      * 001 涓�鍒嗗巶璋冨害鍛�
@@ -58,14 +61,16 @@
      * 010 鍏巶璋冨害鍛�
      * 012 鍏垎鍘傝皟搴﹀憳
      */
-    private static final String PRODUCTION_MANAGER = "010";
+    @Value("${xhj.productionManager:012}")
+    private String PRODUCTION_MANAGER;
     /**
      * 鐢熶骇璁㈠崟鐘舵�侊紝瀹為檯涓婏紝鍙湁REL鐘舵�佺殑宸ュ崟鎵嶅彲浠ヨ繘琛屾搷浣�
      * CRTD 鏂板缓
      * REL 涓嬭揪
      * TECO 鍏抽棴
      */
-    private static final String ORDER_STATUS = "REL";
+    @Value("${xhj.orderStatus:REL}")
+    private String ORDER_STATUS;
 
     /**
      * 璇锋眰鎴愬姛缂栫爜
diff --git a/src/main/java/org/jeecg/modules/mes/job/ProductionOrderSyncUpdateJob.java b/src/main/java/org/jeecg/modules/mes/job/ProductionOrderSyncUpdateJob.java
index 24ad443..35ac0a3 100644
--- a/src/main/java/org/jeecg/modules/mes/job/ProductionOrderSyncUpdateJob.java
+++ b/src/main/java/org/jeecg/modules/mes/job/ProductionOrderSyncUpdateJob.java
@@ -23,6 +23,7 @@
 import org.quartz.JobExecutionContext;
 import org.quartz.JobExecutionException;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Component;
 
 import java.time.LocalDateTime;
@@ -34,7 +35,8 @@
 @Slf4j
 public class ProductionOrderSyncUpdateJob implements Job {
     //宸ュ巶缂栫爜(鏂扮伀鐐� 2301)
-    private static final String FACTORY_CODE = "2301";
+    @Value("${xhj.factoryCode:2301}")
+    private String FACTORY_CODE;
     /**
      * 璁㈠崟绫诲瀷
      * 鏍囧噯鐢熶骇璁㈠崟 Z001
@@ -43,7 +45,8 @@
      * 璇曞埗鐢熶骇璁㈠崟(鏂扮伀鐐�)  Z011
      * 鎷嗛浂鐢熶骇璁㈠崟(鏂扮伀鐐�)  2012
      */
-    private static final String ORDER_TYPE_CODE = "Z001";
+    @Value("${xhj.orderType:Z001}")
+    private String ORDER_TYPE_CODE;
     /**
      * 鐢熶骇璋冨害鍛�
      * 001 涓�鍒嗗巶璋冨害鍛�
@@ -58,14 +61,16 @@
      * 010 鍏巶璋冨害鍛�
      * 012 鍏垎鍘傝皟搴﹀憳
      */
-    private static final String PRODUCTION_MANAGER = "010";
+    @Value("${xhj.productionManager:012}")
+    private String PRODUCTION_MANAGER;
     /**
      * 鐢熶骇璁㈠崟鐘舵�侊紝瀹為檯涓婏紝鍙湁REL鐘舵�佺殑宸ュ崟鎵嶅彲浠ヨ繘琛屾搷浣�
      * CRTD 鏂板缓
      * REL 涓嬭揪
      * TECO 鍏抽棴
      */
-    private static final String ORDER_STATUS = "REL";
+    @Value("${xhj.orderStatus:REL}")
+    private String ORDER_STATUS;
 
     /**
      * 璇锋眰鎴愬姛缂栫爜
diff --git a/src/main/java/org/jeecg/modules/wms/request/WMSWebServiceSendItem.java b/src/main/java/org/jeecg/modules/wms/request/WMSWebServiceSendItem.java
index 0e491a8..99a8010 100644
--- a/src/main/java/org/jeecg/modules/wms/request/WMSWebServiceSendItem.java
+++ b/src/main/java/org/jeecg/modules/wms/request/WMSWebServiceSendItem.java
@@ -8,6 +8,7 @@
 import javax.xml.bind.annotation.XmlAccessorType;
 import javax.xml.bind.annotation.XmlElement;
 import javax.xml.bind.annotation.XmlType;
+import java.math.BigDecimal;
 
 @Getter
 @Setter
@@ -63,7 +64,7 @@
     private String mesStockID;
     /** 鏁伴噺 */
     @XmlElement(name = "Quantity")
-    private String quantity;
+    private BigDecimal quantity;
     /** SAP鎵规鍙� */
     @XmlElement(name = "SapTrackLot")
     private String sapTrackLot;
diff --git a/src/main/java/org/jeecg/modules/wms/service/impl/MESWebServiceSoapImpl.java b/src/main/java/org/jeecg/modules/wms/service/impl/MESWebServiceSoapImpl.java
index ff68abc..8e69a64 100644
--- a/src/main/java/org/jeecg/modules/wms/service/impl/MESWebServiceSoapImpl.java
+++ b/src/main/java/org/jeecg/modules/wms/service/impl/MESWebServiceSoapImpl.java
@@ -5,7 +5,12 @@
 import org.apache.commons.lang3.StringUtils;
 import org.jeecg.common.aspect.annotation.ApiLog;
 import org.jeecg.common.constant.ApiLogCategoryEnum;
+import org.jeecg.modules.base.entity.LineSideWarehouse;
+import org.jeecg.modules.base.service.ILineSideWarehouseService;
+import org.jeecg.modules.lsw.entity.LswMaterialInbound;
+import org.jeecg.modules.lsw.service.ILswMaterialInboundService;
 import org.jeecg.modules.mes.entity.MesMaterialTransferRequest;
+import org.jeecg.modules.mes.enums.MaterialTransferRequestStatus;
 import org.jeecg.modules.mes.service.IMesMaterialTransferRequestService;
 import org.jeecg.modules.wms.dto.WSResponse;
 import org.jeecg.modules.wms.request.ReceiveWMSScanItemList;
@@ -21,6 +26,7 @@
 import javax.jws.WebService;
 import javax.xml.ws.RequestWrapper;
 import javax.xml.ws.ResponseWrapper;
+import java.math.BigDecimal;
 
 
 @Slf4j
@@ -30,6 +36,10 @@
 
     @Autowired
     private IMesMaterialTransferRequestService materialTransferRequestService;
+    @Autowired
+    private ILineSideWarehouseService lineSideWarehouseService;
+    @Autowired
+    private ILswMaterialInboundService materialInboundService;
 
     @Override
     @Transactional(rollbackFor = Exception.class)
@@ -45,16 +55,58 @@
             response.setErrorDesc("浼犲叆鐨勫弬鏁颁负绌猴紒");
             return response;
         }
-        for(WMSWebServiceSendItem item : request.getWmsWebServiceSendItemList()) {
-            if(StringUtils.isNotBlank(item.getReservationOrder())) {
+        String errorCode = "N";
+        int errorCount = 0;
+        int successCount = 0;
+        StringBuilder errorMsg = new StringBuilder();
+        for (WMSWebServiceSendItem item : request.getWmsWebServiceSendItemList()) {
+            if (StringUtils.isNotBlank(item.getReservationOrder())) {
                 //鐗╂枡鎷夊姩鍥炶皟
                 MesMaterialTransferRequest transferRequest = materialTransferRequestService.queryByReservationCode(item.getReservationOrder());
-                if(transferRequest == null) {
-                    response.setErrorCode("N");
-                    response.setErrorDesc("鏍规嵁棰勭暀鍙锋湭鎵惧埌鐗╂枡鎷夊姩鍗曪紒");
-                    return response;
+                if (transferRequest == null) {
+                    errorCount++;
+                    errorMsg.append("鏍规嵁棰勭暀鍙穂").append(item.getReservationOrder()).append("]鏈壘鍒扮墿鏂欐媺鍔ㄥ崟锛�");
+                    continue;
                 }
-            }else if(StringUtils.isNotBlank(item.getAlign())){
+                LineSideWarehouse warehouse = lineSideWarehouseService.getById(transferRequest.getTargetWarehouseId());
+                if(warehouse == null || !warehouse.getWarehouseCode().equals(item.getDestSection())) {
+                    errorCount++;
+                    errorMsg.append("绾胯竟搴揫").append(item.getDestSection()).append("]鏈壘鍒帮紒");
+                    continue;
+                }
+                if(!transferRequest.getMaterialNumber().equals(item.getSkuCode())) {
+                    errorCount++;
+                    errorMsg.append("鐗╂枡缂栧彿[").append(item.getSkuCode()).append("]涓嶅尮閰嶏紒");
+                    continue;
+                }
+                if(StringUtils.isBlank(item.getTrackLot())) {
+                    errorCount++;
+                    errorMsg.append("鎵规鍙穂").append(item.getTrackLot()).append("]涓嶈兘涓虹┖锛�");
+                    continue;
+                }
+                transferRequest.setRequestStatus(MaterialTransferRequestStatus.CHECKED_IN.name());
+                //璁$畻瀹為檯鎷夊姩鏁伴噺
+                BigDecimal actualQuantity = transferRequest.getActualQuantity() == null ? item.getQuantity() : transferRequest.getActualQuantity().add(item.getQuantity());
+                transferRequest.setActualQuantity(actualQuantity);
+
+                //娣诲姞鍏ュ簱淇℃伅
+                LswMaterialInbound inbound = new LswMaterialInbound();
+                inbound.setWarehouseId(transferRequest.getTargetWarehouseId());
+                inbound.setReceiver("WMS");
+                inbound.setMaterialNumber(transferRequest.getMaterialNumber());
+                inbound.setMaterialName(transferRequest.getMaterialName());
+                inbound.setBatchNumber(item.getTrackLot());
+                inbound.setQuantity(item.getQuantity());
+                inbound.setFactoryId(warehouse.getFactoryId());
+                boolean b = materialInboundService.inboundMaterial(inbound);
+                if(!b) {
+                    errorCount++;
+                    errorMsg.append("棰勭暀鍙穂").append(item.getReservationOrder()).append("]鍏ュ簱澶辫触锛�");
+                    continue;
+                }
+                //鏇存柊鐗╂枡鎷夊姩鍗�
+                materialTransferRequestService.updateById(transferRequest);
+            } else if (StringUtils.isNotBlank(item.getAlign())) {
                 //绉诲簱鍗曞洖璋�
             }
         }
diff --git a/src/main/resources/application-dev.yml b/src/main/resources/application-dev.yml
index c83b1ec..1d17f58 100644
--- a/src/main/resources/application-dev.yml
+++ b/src/main/resources/application-dev.yml
@@ -303,4 +303,9 @@
   appId: cli_a74aab6353b7d00e
   appSecret: mx5wm7X9S8WSzZCOYlxcggXTFL8iujIT
   sync:
-    departmentId: od-47692f32e6b66cc3985d317fee780a8b
\ No newline at end of file
+    departmentId: od-47692f32e6b66cc3985d317fee780a8b
+xhj:
+  factoryCode: 2301
+  orderType: Z001
+  productionManager: 010
+  orderStatus: REL
\ No newline at end of file
diff --git a/src/main/resources/application-prod.yml b/src/main/resources/application-prod.yml
index ecd52bc..39078aa 100644
--- a/src/main/resources/application-prod.yml
+++ b/src/main/resources/application-prod.yml
@@ -302,4 +302,9 @@
   appId: cli_a74aab6353b7d00e
   appSecret: mx5wm7X9S8WSzZCOYlxcggXTFL8iujIT
   sync:
-    departmentId: od-47692f32e6b66cc3985d317fee780a8b
\ No newline at end of file
+    departmentId: od-47692f32e6b66cc3985d317fee780a8b
+xhj:
+  factoryCode: 2301
+  orderType: Z001
+  productionManager: 010
+  orderStatus: REL
\ No newline at end of file

--
Gitblit v1.9.3