新火炬后端单体项目初始化代码
zhangherong
8 天以前 9825ca9fb40954a2a4044b4c224486a2f813d243
src/main/java/org/jeecg/modules/sap/service/impl/SAPServiceImpl.java
@@ -1,44 +1,53 @@
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 com.sap.conn.jco.JCoRepository;
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();
        JCoRepository repository = destination.getRepository();
        JCoFunction function = repository.getFunction("ZPPF_022");
        if (function == null) {
            throw new RuntimeException("RFC 函数模块 ZPPF_022 未找到!");
        }
        // 设置输入参数
//        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 "";
    }
}
//package org.jeecg.modules.sap.service.impl;
//
//import com.sap.conn.jco.*;
//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;
//
//import java.util.Arrays;
//import java.util.Collections;
//
//@Service
//@Slf4j
//public class SAPServiceImpl implements SAPService {
//    @Autowired
//    private SapRfcConnectionManager connectionManager;
//
//    @Override
//    public String test()  {
//        JCoDestination destination = connectionManager.getDestination();
//        try {
//            JCoRepository repository = destination.getRepository();
//            JCoFunction function = repository.getFunction("ZPPF_022");
//
//            if (function == null) {
//                throw new RuntimeException("RFC 函数模块 ZPPF_022 未找到!");
//            }
//
//            // 设置输入参数
//            JCoTable inputTable = function.getTableParameterList().getTable("ZTAB_WERKS");
//            inputTable.appendRow();
//            inputTable.setValue("WERKS", "2301"); //参数名需与 SAP 函数定义一致
//
//            // 执行调用
//            function.execute(destination);
//
//            // 获取输出参数
//            JCoTable outputTable = function.getTableParameterList().getTable("ZTAB_AUFNR");
//            int numRows = outputTable.getNumRows();
//            for (int i = 0; i < numRows; i++) {
//                outputTable.setRow(i);
//                log.info("Row {} : {}", i, outputTable.getString("AUFNR"));
//            }
//
//            return String.valueOf(numRows);
//        } catch (JCoException e) {
//            log.error(e.getMessage(), e);
//        }
//        return null;
//    }
//}