zhangherong
2025-06-13 d7f212d555f92959666ce5a02060ac085531b99b
art:sap接口集成调试,不通,下周一找股司的李冰荣
已添加9个文件
已修改2个文件
211 ■■■■■ 文件已修改
pom.xml 9 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/org/jeecg/config/sap/CustomDestinationDataProvider.java 31 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/org/jeecg/config/sap/SapRfcConnectionManager.java 88 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/org/jeecg/modules/sap/controller/SAPTestController.java 27 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/org/jeecg/modules/sap/service/SAPService.java 5 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/org/jeecg/modules/sap/service/impl/SAPServiceImpl.java 42 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/resources/application-dev.yml 9 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/resources/lib/libsapjco3.so 补丁 | 查看 | 原始文档 | blame | 历史
src/main/resources/lib/sapjco3.dll 补丁 | 查看 | 原始文档 | blame | 历史
src/main/resources/lib/sapjco3.jar 补丁 | 查看 | 原始文档 | blame | 历史
src/main/resources/lib/sapjco3.pdb 补丁 | 查看 | 原始文档 | blame | 历史
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>
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;
    }
}
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;
        }
    }
}
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);
    }
}
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();
}
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 "";
    }
}
src/main/resources/application-dev.yml
@@ -315,3 +315,12 @@
    secretFolder: D:\\hy_test\\a
    #工控网监控nc文件夹
    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                  # è¯­è¨€
src/main/resources/lib/libsapjco3.so
Binary files differ
src/main/resources/lib/sapjco3.dll
Binary files differ
src/main/resources/lib/sapjco3.jar
Binary files differ
src/main/resources/lib/sapjco3.pdb
Binary files differ