新火炬后端单体项目初始化代码
zhangherong
8 天以前 9825ca9fb40954a2a4044b4c224486a2f813d243
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
package org.jeecg.modules.sap.service.impl;
 
import com.alibaba.fastjson.JSONObject;
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.OrderBomDTO;
import org.jeecg.modules.sap.service.OrderBomSync;
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 OrderBomSyncImpl implements OrderBomSync {
    @Autowired
    private SapRfcConnectionManager connectionManager;
 
    @Override
    @ApiLog(apiName = "订单BOM同步(ZPPF_033_3)", apiCategory = ApiLogCategoryEnum.SAP)
    public Map<String, Object> syncOrderBom(String factoryCode, String orderCode) throws Exception {
        Map<String, Object> resultMap = new HashMap<>();
        JCoDestination destination = connectionManager.getDestination();
        JCoRepository repository = destination.getRepository();
        JCoFunction function = repository.getFunction(FunctionConst.ZPPF_033_3);
        if (function == null) {
            throw new RuntimeException("RFC 函数 ZPPF_033_3 未找到!");
        }
        // 设置输入参数
        List<JSONObject> items = new ArrayList<>();
        if(StringUtils.isNotBlank(factoryCode)){
            //新火炬
            JCoParameterList importParameterList = function.getImportParameterList();
            importParameterList.setValue("WERKS", factoryCode);
            //组装请求参数
            JSONObject item = new JSONObject();
            item.put("WERKS", factoryCode);
            items.add(item);
        }
        if(StringUtils.isNotBlank(orderCode)) {
            //新火炬
            JCoTable AUFNRTable = function.getTableParameterList().getTable("ZTAB_AUFNR");
            String[] split = orderCode.split(",");
            for(String code : split){
                AUFNRTable.appendRow();
                AUFNRTable.setValue("AUFNR", code);
            }
            //组装请求参数
            JSONObject item = new JSONObject();
            item.put("AUFNR", orderCode);
            items.add(item);
        }
        // 执行调用
        function.execute(destination);
        //获取返回结果
        String zmess = function.getExportParameterList().getValue("ZMESS").toString();
        String ztype = function.getExportParameterList().getValue("ZTYPE").toString();//S 标识 成功
        // 获取输出参数
        JCoTable outputTable = function.getTableParameterList().getTable("ZTAB_OUT");
        int numRows = outputTable.getNumRows();
        List<OrderBomDTO> resultList = new ArrayList<>();
        OrderBomDTO dto;
        for (int i = 0; i < numRows; i++) {
            outputTable.setRow(i);
            dto = new OrderBomDTO();
            dto.setAUFNR(outputTable.getString("AUFNR"));
            dto.setMATNR(outputTable.getString("MATNR"));
            dto.setWERKS(outputTable.getString("WERKS"));
            dto.setMAKTX(outputTable.getString("MAKTX"));
            dto.setBDMNG(outputTable.getString("BDMNG"));
            dto.setMEINS(outputTable.getString("MEINS"));
 
            //添加结果集
            resultList.add(dto);
            log.info(dto.toString());
        }
        resultMap.put("zmess", zmess);
        resultMap.put("ztype", ztype);
        resultMap.put("importParameters", items);
        resultMap.put("result", resultList);
        return resultMap;
    }
}