From afb71a0770acc36a6e062aecf2dfc1c92d2d80a7 Mon Sep 17 00:00:00 2001
From: zhangherong <571457620@qq.com>
Date: 星期二, 12 八月 2025 11:59:09 +0800
Subject: [PATCH] art: SAP 物料请求预留号接口调试

---
 src/main/java/org/jeecg/modules/sap/controller/SAPTestController.java                 |   12 +++
 src/main/java/org/jeecg/modules/sap/request/MaterialRequest.java                      |   16 ++++
 src/main/java/org/jeecg/modules/base/service/IFactoryService.java                     |    6 +
 src/main/java/org/jeecg/modules/sap/service/OrderMaterialRequestService.java          |   21 +++++
 src/main/java/org/jeecg/modules/base/model/FactoryModel.java                          |   21 ----
 src/main/java/org/jeecg/modules/sap/dto/MaterialRequestDTO.java                       |   13 +++
 src/main/java/org/jeecg/modules/base/service/impl/FactoryServiceImpl.java             |    9 ++
 src/main/java/org/jeecg/modules/sap/FunctionConst.java                                |    2 
 src/main/java/org/jeecg/modules/sap/service/impl/OrderLoadServiceImpl.java            |    1 
 src/main/java/org/jeecg/modules/sap/service/impl/OrderProcessSyncImpl.java            |   11 ++
 src/main/java/org/jeecg/modules/base/controller/FactoryController.java                |   27 ++----
 src/main/java/org/jeecg/modules/sap/service/impl/OrderMaterialRequestServiceImpl.java |   96 ++++++++++++++++++++++++
 12 files changed, 194 insertions(+), 41 deletions(-)

diff --git a/src/main/java/org/jeecg/modules/base/controller/FactoryController.java b/src/main/java/org/jeecg/modules/base/controller/FactoryController.java
index dc46151..cfb5a5a 100644
--- a/src/main/java/org/jeecg/modules/base/controller/FactoryController.java
+++ b/src/main/java/org/jeecg/modules/base/controller/FactoryController.java
@@ -221,25 +221,14 @@
 		 return result;
 	 }
 
-	 @ApiOperation(value = "浜х嚎琛ㄩ泦鍚�", notes = "浜х嚎琛ㄩ泦鍚�")
-	 @GetMapping(value = "/queryTreeAppList")
-	 public Result<List<FactoryModel>> queryTreeAppList() {
-		 Result<List<FactoryModel>> result = new Result<>();
-		 try {
-			 List<Factory> factoryList = factoryService.list(new LambdaQueryWrapper<Factory>()
-					 .eq(Factory::getDelFlag, CommonConstant.DEL_FLAG_0)
-					 .orderByAsc(Factory::getSorter));
-
-			 List<FactoryModel> factoryModels = factoryList.stream()
-					 .map(factory -> new FactoryModel(factory.getId(), factory.getFactoryName()))
-					 .collect(Collectors.toList());
-
-			 result.setSuccess(true);
-			 result.setResult(factoryModels);
-		 } catch (Exception e) {
-			 log.error(e.getMessage(), e);
-		 }
-		 return result;
+	 @ApiOperation(value = "鑾峰彇鎵�鏈変骇绾垮垪琛�", notes = "鑾峰彇鎵�鏈変骇绾垮垪琛�")
+	 @GetMapping(value = "/queryProductionLineList")
+	 public Result<List<FactoryModel>> queryProductionLineList() {
+		 List<Factory> factoryList = factoryService.queryProductionLineList();
+		 List<FactoryModel> factoryModels = factoryList.stream()
+				 .map(factory -> new FactoryModel(factory.getId(), factory.getFactoryName()))
+				 .collect(Collectors.toList());
+		 return Result.ok(factoryModels);
 	 }
 
 
diff --git a/src/main/java/org/jeecg/modules/base/model/FactoryModel.java b/src/main/java/org/jeecg/modules/base/model/FactoryModel.java
index dbef147..89c62fa 100644
--- a/src/main/java/org/jeecg/modules/base/model/FactoryModel.java
+++ b/src/main/java/org/jeecg/modules/base/model/FactoryModel.java
@@ -4,30 +4,15 @@
 
 @Data
 public class FactoryModel {
+    // getter鍜宻etter鏂规硶
     private String value;  // 浜х嚎ID
     private String text;   // 浜х嚎鍚嶇О
 
-    public FactoryModel() {}
+    public FactoryModel() {
+    }
 
     public FactoryModel(String value, String text) {
         this.value = value;
-        this.text = text;
-    }
-
-    // getter鍜宻etter鏂规硶
-    public String getValue() {
-        return value;
-    }
-
-    public void setValue(String value) {
-        this.value = value;
-    }
-
-    public String getText() {
-        return text;
-    }
-
-    public void setText(String text) {
         this.text = text;
     }
 }
diff --git a/src/main/java/org/jeecg/modules/base/service/IFactoryService.java b/src/main/java/org/jeecg/modules/base/service/IFactoryService.java
index e89a234..0f2a799 100644
--- a/src/main/java/org/jeecg/modules/base/service/IFactoryService.java
+++ b/src/main/java/org/jeecg/modules/base/service/IFactoryService.java
@@ -45,4 +45,10 @@
     List<Factory> queryFacByPid(String pid);
 
     List<String> recursionChildren(String factoryId);
+
+    /**
+     * 鏌ヨ鏌ヨ鍒楄〃
+     * @return
+     */
+    List<Factory> queryProductionLineList();
 }
diff --git a/src/main/java/org/jeecg/modules/base/service/impl/FactoryServiceImpl.java b/src/main/java/org/jeecg/modules/base/service/impl/FactoryServiceImpl.java
index 1464018..2307edd 100644
--- a/src/main/java/org/jeecg/modules/base/service/impl/FactoryServiceImpl.java
+++ b/src/main/java/org/jeecg/modules/base/service/impl/FactoryServiceImpl.java
@@ -175,6 +175,15 @@
         return this.baseMapper.recursionChildren(factoryId);
     }
 
+    @Override
+    public List<Factory> queryProductionLineList() {
+        LambdaQueryWrapper<Factory> queryWrapper = new LambdaQueryWrapper<>();
+        queryWrapper.eq(Factory::getDelFlag, CommonConstant.DEL_FLAG_0);
+        queryWrapper.eq(Factory::getFactoryCategory, "PRODUCTION_LINE");
+        queryWrapper.orderByAsc(Factory::getSorter);
+        return super.list(queryWrapper);
+    }
+
     /**
      * 鎵撳紑 鐖惰妭鐐� 鍙� 浠ヤ笂鐨刴dc鏍囪
      * @param parentId
diff --git a/src/main/java/org/jeecg/modules/sap/FunctionConst.java b/src/main/java/org/jeecg/modules/sap/FunctionConst.java
index 68929c6..538be8f 100644
--- a/src/main/java/org/jeecg/modules/sap/FunctionConst.java
+++ b/src/main/java/org/jeecg/modules/sap/FunctionConst.java
@@ -13,4 +13,6 @@
     public static final String ZMES_GOODSMVT_CREATE_2301 = "ZMES_GOODSMVT_CREATE_2301";
     //6.鐢熶骇璁㈠崟鍏抽棴鎺ュ彛
     public static final String ZPPF_019 = "ZPPF_019";
+    //7.SAP棰勭暀鍙峰垱寤烘帴鍙�
+    public static final String ZMES_RESERVATION_CREATE = "ZMES_RESERVATION_CREATE";
 }
diff --git a/src/main/java/org/jeecg/modules/sap/controller/SAPTestController.java b/src/main/java/org/jeecg/modules/sap/controller/SAPTestController.java
index 1b42841..8331808 100644
--- a/src/main/java/org/jeecg/modules/sap/controller/SAPTestController.java
+++ b/src/main/java/org/jeecg/modules/sap/controller/SAPTestController.java
@@ -4,6 +4,7 @@
 import io.swagger.annotations.ApiOperation;
 import lombok.extern.slf4j.Slf4j;
 import org.jeecg.common.api.vo.Result;
+import org.jeecg.modules.sap.request.MaterialRequest;
 import org.jeecg.modules.sap.request.OrderLoadRequest;
 import org.jeecg.modules.sap.request.OrderReportRequest;
 import org.jeecg.modules.sap.request.ProductionOrderSyncRequest;
@@ -11,6 +12,7 @@
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.*;
 
+import java.util.List;
 import java.util.Map;
 
 @Api(tags = "SAP闆嗘垚娴嬭瘯")
@@ -46,6 +48,8 @@
     private OrderLoadService orderLoadService;
     @Autowired
     private OrderCloseService orderCloseService;
+    @Autowired
+    private OrderMaterialRequestService orderMaterialRequestService;
 
     @ApiOperation(value = "SAP闆嗘垚娴嬭瘯-鐢熶骇璁㈠崟鍚屾鎺ュ彛", notes = "SAP闆嗘垚娴嬭瘯-鐢熶骇璁㈠崟鍚屾鎺ュ彛")
     @PostMapping("/syncProductionOrder")
@@ -113,4 +117,12 @@
         Map<String, Object> resultMap = orderCloseService.productionOrderClose(orderCode);
         return Result.ok(resultMap);
     }
+
+    @ApiOperation(value = "SAP闆嗘垚娴嬭瘯-鐗╂枡鎷夊姩", notes = "SAP闆嗘垚娴嬭瘯-鐗╂枡鎷夊姩")
+    @PostMapping("/orderMaterialRequest")
+    public Result<?> orderMaterialRequest(@RequestParam(value = "factoryCode") String factoryCode, @RequestParam(value = "warehouseCode") String warehouseCode, @RequestBody List<MaterialRequest> request) throws Exception {
+//        String orderCode = "10698749";
+        Map<String, Object> resultMap = orderMaterialRequestService.orderMaterialRequest(factoryCode, warehouseCode, request);
+        return Result.ok(resultMap);
+    }
 }
diff --git a/src/main/java/org/jeecg/modules/sap/dto/MaterialRequestDTO.java b/src/main/java/org/jeecg/modules/sap/dto/MaterialRequestDTO.java
new file mode 100644
index 0000000..10ce42c
--- /dev/null
+++ b/src/main/java/org/jeecg/modules/sap/dto/MaterialRequestDTO.java
@@ -0,0 +1,13 @@
+package org.jeecg.modules.sap.dto;
+
+import lombok.Data;
+
+@Data
+public class MaterialRequestDTO {
+    /** 鎴愬姛鏍囪 Y-OK N-NG */
+    private String O_IS_OK;
+    /** 棰勭暀/鐩稿叧闇�姹傜殑缂栧彿 */
+    private String O_SAP_RESV;
+    /** 娑堟伅鏂囨湰 */
+    private String O_MESSAGE;
+}
diff --git a/src/main/java/org/jeecg/modules/sap/request/MaterialRequest.java b/src/main/java/org/jeecg/modules/sap/request/MaterialRequest.java
new file mode 100644
index 0000000..9b66962
--- /dev/null
+++ b/src/main/java/org/jeecg/modules/sap/request/MaterialRequest.java
@@ -0,0 +1,16 @@
+package org.jeecg.modules.sap.request;
+
+import lombok.Data;
+
+import java.io.Serializable;
+import java.math.BigDecimal;
+
+@Data
+public class MaterialRequest implements Serializable {
+    /** 鐗╂枡鍙� */
+    private String materialNumber;
+    /** 鏁伴噺 */
+    private BigDecimal quantity;
+    /** 鍙戣揣搴撳瓨鍦扮偣 */
+    private String warehouseCode;
+}
diff --git a/src/main/java/org/jeecg/modules/sap/service/OrderMaterialRequestService.java b/src/main/java/org/jeecg/modules/sap/service/OrderMaterialRequestService.java
new file mode 100644
index 0000000..dddf041
--- /dev/null
+++ b/src/main/java/org/jeecg/modules/sap/service/OrderMaterialRequestService.java
@@ -0,0 +1,21 @@
+package org.jeecg.modules.sap.service;
+
+import org.jeecg.modules.sap.request.MaterialRequest;
+
+import java.util.List;
+import java.util.Map;
+
+/**
+ * 鐗╂枡鎷夊姩锛岄鐣欏彿璇锋眰
+ */
+public interface OrderMaterialRequestService {
+    /**
+     * 鐗╂枡鎷夊姩璇锋眰
+     * @param factoryCode 宸ュ巶缂栫爜
+     * @param receiveWarehouseCode 鎺ユ敹搴撳瓨鍦扮偣
+     * @param request 鐗╂枡鎷夊姩淇℃伅
+     * @return
+     * @throws Exception
+     */
+    Map<String, Object> orderMaterialRequest(String factoryCode, String receiveWarehouseCode, List<MaterialRequest> request) throws Exception;
+}
diff --git a/src/main/java/org/jeecg/modules/sap/service/impl/OrderLoadServiceImpl.java b/src/main/java/org/jeecg/modules/sap/service/impl/OrderLoadServiceImpl.java
index 747876f..d2ee015 100644
--- a/src/main/java/org/jeecg/modules/sap/service/impl/OrderLoadServiceImpl.java
+++ b/src/main/java/org/jeecg/modules/sap/service/impl/OrderLoadServiceImpl.java
@@ -7,7 +7,6 @@
 import org.jeecg.config.sap.SapRfcConnectionManager;
 import org.jeecg.modules.sap.FunctionConst;
 import org.jeecg.modules.sap.dto.OrderLoadDTO;
-import org.jeecg.modules.sap.dto.OrderReportDTO;
 import org.jeecg.modules.sap.request.OrderLoadRequest;
 import org.jeecg.modules.sap.service.OrderLoadService;
 import org.springframework.beans.factory.annotation.Autowired;
diff --git a/src/main/java/org/jeecg/modules/sap/service/impl/OrderMaterialRequestServiceImpl.java b/src/main/java/org/jeecg/modules/sap/service/impl/OrderMaterialRequestServiceImpl.java
new file mode 100644
index 0000000..1bf9282
--- /dev/null
+++ b/src/main/java/org/jeecg/modules/sap/service/impl/OrderMaterialRequestServiceImpl.java
@@ -0,0 +1,96 @@
+package org.jeecg.modules.sap.service.impl;
+
+import cn.hutool.core.collection.CollectionUtil;
+import com.alibaba.fastjson.JSONObject;
+import com.alibaba.fastjson.parser.Feature;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.sap.conn.jco.*;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang3.StringUtils;
+import org.jeecg.common.aspect.annotation.ApiLog;
+import org.jeecg.common.constant.ApiLogCategoryEnum;
+import org.jeecg.config.sap.SapRfcConnectionManager;
+import org.jeecg.modules.sap.FunctionConst;
+import org.jeecg.modules.sap.dto.MaterialRequestDTO;
+import org.jeecg.modules.sap.request.MaterialRequest;
+import org.jeecg.modules.sap.service.OrderMaterialRequestService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+@Service
+@Slf4j
+public class OrderMaterialRequestServiceImpl implements OrderMaterialRequestService {
+    @Autowired
+    private SapRfcConnectionManager connectionManager;
+    @Autowired
+    private ObjectMapper objectMapper;
+
+    @Override
+    @ApiLog(apiName = "SAP棰勭暀鍙峰垱寤�(ZMES_RESERVATION_CREATE)", apiCategory = ApiLogCategoryEnum.SAP)
+    public Map<String, Object> orderMaterialRequest(String factoryCode, String receiveWarehouseCode, List<MaterialRequest> request) throws Exception {
+        Map<String, Object> resultMap = new HashMap<>();
+        JCoDestination destination = connectionManager.getDestination();
+        JCoRepository repository = destination.getRepository();
+        JCoFunction function = repository.getFunction(FunctionConst.ZMES_RESERVATION_CREATE);
+        if (function == null) {
+            throw new RuntimeException("RFC 鍑芥暟 ZMES_RESERVATION_CREATE 鏈壘鍒帮紒");
+        }
+        if (StringUtils.isBlank(factoryCode) || StringUtils.isBlank(receiveWarehouseCode) || CollectionUtil.isEmpty(request)) {
+            resultMap.put("zmess", "宸ュ巶缂栫爜銆佹帴鏀跺簱瀛樺湴涓虹┖鎴栫墿鏂欎俊鎭负绌�");
+            resultMap.put("ztype", "-1");
+            resultMap.put("importParameters", factoryCode + "|" + receiveWarehouseCode + "|" + (request == null ? 0 : request.size()));
+            resultMap.put("result", null);
+            return resultMap;
+        }
+        // 璁剧疆杈撳叆鍙傛暟
+        List<JSONObject> items = new ArrayList<>();
+        //鏂扮伀鐐�
+        JCoParameterList importParameterList = function.getImportParameterList();
+        importParameterList.setValue("I_SITE", factoryCode);
+        //缁勮璇锋眰鍙傛暟
+        JSONObject item = new JSONObject();
+        item.put("I_SITE", factoryCode);
+        items.add(item);
+
+        //鎺ユ敹搴撳瓨鍦�
+        importParameterList.setValue("I_TO_STORGE_LOC", receiveWarehouseCode);
+        //缁勮璇锋眰鍙傛暟
+        item = new JSONObject();
+        item.put("I_TO_STORGE_LOC", factoryCode);
+        items.add(item);
+
+        JCoTable itemTable = function.getTableParameterList().getTable("T_ITEMS");
+        for (MaterialRequest itemReq : request) {
+            itemTable.appendRow();
+            itemTable.setValue("ITEM", itemReq.getMaterialNumber());
+            itemTable.setValue("PULL_QTY", itemReq.getQuantity());
+            itemTable.setValue("FROM_STORGE_LOC", itemReq.getWarehouseCode());
+            //缁勮璇锋眰鍙傛暟
+            String json = objectMapper.writeValueAsString(itemReq);
+            item = JSONObject.parseObject(json, Feature.OrderedField);
+            items.add(item);
+        }
+
+        // 鎵ц璋冪敤
+        function.execute(destination);
+        //鑾峰彇杩斿洖缁撴灉
+        MaterialRequestDTO response = new MaterialRequestDTO();
+        String zmess = function.getExportParameterList().getValue("O_IS_OK").toString();
+        String ztype = function.getExportParameterList().getValue("O_MESSAGE").toString();//S 鏍囪瘑 鎴愬姛
+        String resv = function.getExportParameterList().getValue("O_SAP_RESV").toString();//S 鏍囪瘑 鎴愬姛
+        response.setO_IS_OK(ztype);
+        response.setO_MESSAGE(zmess);
+        response.setO_SAP_RESV(resv);
+        //杩斿洖缁撴灉
+        resultMap.put("zmess", zmess);
+        resultMap.put("ztype", ztype);
+        resultMap.put("importParameters", items);
+        resultMap.put("result", response);
+        return resultMap;
+    }
+}
diff --git a/src/main/java/org/jeecg/modules/sap/service/impl/OrderProcessSyncImpl.java b/src/main/java/org/jeecg/modules/sap/service/impl/OrderProcessSyncImpl.java
index 2fdd666..722bdc1 100644
--- a/src/main/java/org/jeecg/modules/sap/service/impl/OrderProcessSyncImpl.java
+++ b/src/main/java/org/jeecg/modules/sap/service/impl/OrderProcessSyncImpl.java
@@ -1,20 +1,25 @@
 package org.jeecg.modules.sap.service.impl;
 
 import com.alibaba.fastjson.JSONObject;
-import com.sap.conn.jco.*;
+import com.sap.conn.jco.JCoDestination;
+import com.sap.conn.jco.JCoFunction;
+import com.sap.conn.jco.JCoRepository;
+import com.sap.conn.jco.JCoTable;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang3.StringUtils;
 import org.jeecg.common.aspect.annotation.ApiLog;
 import org.jeecg.common.constant.ApiLogCategoryEnum;
 import org.jeecg.config.sap.SapRfcConnectionManager;
 import org.jeecg.modules.sap.FunctionConst;
-import org.jeecg.modules.sap.dto.OrderBomDTO;
 import org.jeecg.modules.sap.dto.OrderProcessDTO;
 import org.jeecg.modules.sap.service.OrderProcessSync;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
-import java.util.*;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
 
 @Service
 @Slf4j

--
Gitblit v1.9.3