From d7f212d555f92959666ce5a02060ac085531b99b Mon Sep 17 00:00:00 2001
From: zhangherong <571457620@qq.com>
Date: 星期五, 13 六月 2025 17:48:20 +0800
Subject: [PATCH] art:sap接口集成调试,不通,下周一找股司的李冰荣

---
 src/main/java/org/jeecg/config/sap/CustomDestinationDataProvider.java |   31 +++++++
 src/main/java/org/jeecg/modules/sap/controller/SAPTestController.java |   27 ++++++
 src/main/resources/lib/sapjco3.dll                                    |    0 
 src/main/java/org/jeecg/modules/sap/service/impl/SAPServiceImpl.java  |   42 ++++++++++
 src/main/resources/lib/libsapjco3.so                                  |    0 
 src/main/resources/lib/sapjco3.pdb                                    |    0 
 src/main/resources/application-dev.yml                                |    9 ++
 src/main/resources/lib/sapjco3.jar                                    |    0 
 src/main/java/org/jeecg/modules/sap/service/SAPService.java           |    5 +
 pom.xml                                                               |    9 ++
 src/main/java/org/jeecg/config/sap/SapRfcConnectionManager.java       |   88 ++++++++++++++++++++++
 11 files changed, 211 insertions(+), 0 deletions(-)

diff --git a/pom.xml b/pom.xml
index 7fe01c7..748bf31 100644
--- a/pom.xml
+++ b/pom.xml
@@ -521,6 +521,15 @@
             <artifactId>xercesImpl</artifactId>
             <version>2.12.0</version>
         </dependency>
+
+        <!--寮曞叆sap渚濊禆-->
+        <dependency>
+            <groupId>com.sap</groupId>
+            <artifactId>sapjco3</artifactId>
+            <version>3.1.0</version>
+            <scope>system</scope>
+            <systemPath>${project.basedir}/src/main/resources/lib/sapjco3.jar</systemPath>
+        </dependency>
     </dependencies>
 
     <build>
diff --git a/src/main/java/org/jeecg/config/sap/CustomDestinationDataProvider.java b/src/main/java/org/jeecg/config/sap/CustomDestinationDataProvider.java
new file mode 100644
index 0000000..fccedd8
--- /dev/null
+++ b/src/main/java/org/jeecg/config/sap/CustomDestinationDataProvider.java
@@ -0,0 +1,31 @@
+package org.jeecg.config.sap;
+
+import com.sap.conn.jco.ext.*;
+
+import java.util.Properties;
+
+public class CustomDestinationDataProvider implements DestinationDataProvider {
+
+    private final Properties properties = new Properties();
+
+    public void addDestination(String destinationName, Properties connectProperties) {
+        properties.put(destinationName, connectProperties);
+    }
+
+    @Override
+    public boolean supportsEvents() {
+        return false;
+    }
+
+    @Override
+    public void setDestinationDataEventListener(DestinationDataEventListener destinationDataEventListener) {
+
+    }
+
+    @Override
+    public Properties getDestinationProperties(String destinationName) {
+        return properties.getProperty(destinationName) != null
+                ? (Properties) properties.get(destinationName)
+                : null;
+    }
+}
diff --git a/src/main/java/org/jeecg/config/sap/SapRfcConnectionManager.java b/src/main/java/org/jeecg/config/sap/SapRfcConnectionManager.java
new file mode 100644
index 0000000..e120d4f
--- /dev/null
+++ b/src/main/java/org/jeecg/config/sap/SapRfcConnectionManager.java
@@ -0,0 +1,88 @@
+package org.jeecg.config.sap;
+
+import com.sap.conn.jco.*;
+import com.sap.conn.jco.ext.DestinationDataProvider;
+import com.sap.conn.jco.ext.Environment;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.stereotype.Component;
+
+import javax.annotation.PostConstruct;
+import java.util.Properties;
+
+@Component
+public class SapRfcConnectionManager {
+
+    @Value("${sap.rfc.destination}")
+    private String destinationName;
+
+    @Value("${sap.rfc.ashost}")
+    private String ashost;
+
+    @Value("${sap.rfc.sysnr}")
+    private String sysnr;
+
+    @Value("${sap.rfc.client}")
+    private String client;
+
+    @Value("${sap.rfc.user}")
+    private String user;
+
+    @Value("${sap.rfc.passwd}")
+    private String passwd;
+
+    @Value("${sap.rfc.lang}")
+    private String lang;
+
+    private String poolSize = "5";
+
+    private String idleTimeout = "10000";
+
+    private String peekLimit = "10";
+
+    private JCoDestination destination;
+
+    /**
+     *
+     * @throws JCoException
+     */
+    @PostConstruct
+    public void init() throws JCoException {
+        Properties connectProperties = new Properties();
+        connectProperties.setProperty(DestinationDataProvider.JCO_ASHOST, ashost);
+        connectProperties.setProperty(DestinationDataProvider.JCO_SYSNR, sysnr);
+        connectProperties.setProperty(DestinationDataProvider.JCO_CLIENT, client);
+        connectProperties.setProperty(DestinationDataProvider.JCO_USER, user);
+        connectProperties.setProperty(DestinationDataProvider.JCO_PASSWD, passwd);
+        connectProperties.setProperty(DestinationDataProvider.JCO_LANG, lang);
+        connectProperties.setProperty(DestinationDataProvider.JCO_PEAK_LIMIT, peekLimit);
+        connectProperties.setProperty(DestinationDataProvider.JCO_POOL_CAPACITY, poolSize);
+        connectProperties.setProperty(DestinationDataProvider.JCO_EXPIRATION_TIME, idleTimeout);
+
+        // 鍒涘缓鍔ㄦ�佺洰鐨勫湴锛堥伩鍏嶄緷璧� SM59 閰嶇疆锛�
+        CustomDestinationDataProvider provider = new CustomDestinationDataProvider();
+        provider.addDestination(destinationName, connectProperties);
+
+        // 璁剧疆鍏ㄥ眬鐩殑鍦版彁渚涜��
+        Environment.registerDestinationDataProvider(provider);
+
+        // 鑾峰彇鐩殑鍦�
+        this.destination = JCoDestinationManager.getDestination(destinationName);
+    }
+
+    /**
+     *
+     * @return
+     */
+    public JCoDestination getDestination() {
+        return destination;
+    }
+
+    /**
+     *
+     */
+    public void destroy() {
+        if (destination != null) {
+//            destination;
+        }
+    }
+}
\ No newline at end of file
diff --git a/src/main/java/org/jeecg/modules/sap/controller/SAPTestController.java b/src/main/java/org/jeecg/modules/sap/controller/SAPTestController.java
new file mode 100644
index 0000000..d563780
--- /dev/null
+++ b/src/main/java/org/jeecg/modules/sap/controller/SAPTestController.java
@@ -0,0 +1,27 @@
+package org.jeecg.modules.sap.controller;
+
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import lombok.extern.slf4j.Slf4j;
+import org.jeecg.common.api.vo.Result;
+import org.jeecg.modules.sap.service.SAPService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+@Api(tags = "SAP闆嗘垚娴嬭瘯")
+@RestController
+@RequestMapping("/sap/client")
+@Slf4j
+public class SAPTestController {
+    @Autowired
+    private SAPService sapService;
+
+    @ApiOperation(value = "SAP闆嗘垚娴嬭瘯-娴嬭瘯鎺ュ彛", notes = "SAP闆嗘垚娴嬭瘯-娴嬭瘯鎺ュ彛")
+    @GetMapping("/test")
+    public Result<?> test() {
+        String test = sapService.test();
+        return Result.ok(test);
+    }
+}
diff --git a/src/main/java/org/jeecg/modules/sap/service/SAPService.java b/src/main/java/org/jeecg/modules/sap/service/SAPService.java
new file mode 100644
index 0000000..d8bd863
--- /dev/null
+++ b/src/main/java/org/jeecg/modules/sap/service/SAPService.java
@@ -0,0 +1,5 @@
+package org.jeecg.modules.sap.service;
+
+public interface SAPService {
+    String test();
+}
diff --git a/src/main/java/org/jeecg/modules/sap/service/impl/SAPServiceImpl.java b/src/main/java/org/jeecg/modules/sap/service/impl/SAPServiceImpl.java
new file mode 100644
index 0000000..d87e15f
--- /dev/null
+++ b/src/main/java/org/jeecg/modules/sap/service/impl/SAPServiceImpl.java
@@ -0,0 +1,42 @@
+package org.jeecg.modules.sap.service.impl;
+
+import com.sap.conn.jco.JCoDestination;
+import com.sap.conn.jco.JCoFunction;
+import com.sap.conn.jco.JCoParameterList;
+import lombok.SneakyThrows;
+import lombok.extern.slf4j.Slf4j;
+import org.jeecg.config.sap.SapRfcConnectionManager;
+import org.jeecg.modules.sap.service.SAPService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+@Service
+@Slf4j
+public class SAPServiceImpl implements SAPService {
+    @Autowired
+    private SapRfcConnectionManager connectionManager;
+    @SneakyThrows
+    @Override
+    public String test() {
+        JCoDestination destination = connectionManager.getDestination();
+        JCoFunction function = destination.getRepository().getFunction("ZPPF_022");
+
+        if (function == null) {
+            throw new RuntimeException("RFC 鍑芥暟妯″潡 Z_GET_MATERIAL_INFO 鏈壘鍒帮紒");
+        }
+
+        // 璁剧疆杈撳叆鍙傛暟
+//        JCoParameterList input = function.getImportParameterList();
+//        input.setValue("MATERIAL_ID", materialId); // 鍙傛暟鍚嶉渶涓� SAP 鍑芥暟瀹氫箟涓�鑷�
+//        function.getImportParameterList().setValue("MATERIAL_ID", 0);
+
+        // 鎵ц璋冪敤
+        function.execute(destination);
+
+        // 鑾峰彇杈撳嚭鍙傛暟
+        JCoParameterList output = function.getExportParameterList();
+//        String materialName = output.getString("MATERIAL_NAME"); // 鍙傛暟鍚嶉渶涓� SAP 鍑芥暟瀹氫箟涓�鑷�
+
+        return "";
+    }
+}
diff --git a/src/main/resources/application-dev.yml b/src/main/resources/application-dev.yml
index a0ce195..526044e 100644
--- a/src/main/resources/application-dev.yml
+++ b/src/main/resources/application-dev.yml
@@ -315,3 +315,12 @@
     secretFolder: D:\\hy_test\\a
     #宸ユ帶缃戠洃鎺c鏂囦欢澶�
     workFolder: D:\\hy_test\\b
+sap:
+  rfc:
+    destination: ZPPF_022     # SM59 涓厤缃殑 RFC 鐩爣鍚嶇О
+    ashost: 10.101.0.188      # SAP 涓绘満鍦板潃
+    sysnr: 00                 # 绯荤粺缂栧彿
+    client: 800               # 瀹㈡埛绔紪鍙�
+    user: SLSAP_JK            # 鐢ㄦ埛鍚�
+    passwd: 112233            # 瀵嗙爜
+    lang: ZH                  # 璇█
\ No newline at end of file
diff --git a/src/main/resources/lib/libsapjco3.so b/src/main/resources/lib/libsapjco3.so
new file mode 100644
index 0000000..26493e9
--- /dev/null
+++ b/src/main/resources/lib/libsapjco3.so
Binary files differ
diff --git a/src/main/resources/lib/sapjco3.dll b/src/main/resources/lib/sapjco3.dll
new file mode 100644
index 0000000..20da90d
--- /dev/null
+++ b/src/main/resources/lib/sapjco3.dll
Binary files differ
diff --git a/src/main/resources/lib/sapjco3.jar b/src/main/resources/lib/sapjco3.jar
new file mode 100644
index 0000000..8f12391
--- /dev/null
+++ b/src/main/resources/lib/sapjco3.jar
Binary files differ
diff --git a/src/main/resources/lib/sapjco3.pdb b/src/main/resources/lib/sapjco3.pdb
new file mode 100644
index 0000000..b5283b3
--- /dev/null
+++ b/src/main/resources/lib/sapjco3.pdb
Binary files differ

--
Gitblit v1.9.3