From 1ee0b1a27899d03f946a86c70c4df4c6388fb160 Mon Sep 17 00:00:00 2001
From: zhangherong <571457620@qq.com>
Date: 星期二, 12 八月 2025 18:16:27 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/master'

---
 src/main/java/org/jeecg/modules/sap/service/impl/OrderMaterialRequestServiceImpl.java |   96 ++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 96 insertions(+), 0 deletions(-)

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;
+    }
+}

--
Gitblit v1.9.3