新火炬后端单体项目初始化代码
cuilei
2 天以前 c71714508fbe3ace3543423c7700d7bbcca90056
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
package org.jeecg.modules.sap.service.impl;
 
import com.sap.conn.jco.JCoDestination;
import com.sap.conn.jco.JCoFunction;
import com.sap.conn.jco.JCoRepository;
import com.sap.conn.jco.JCoTable;
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.ProductionOrderDTO;
import org.jeecg.modules.sap.request.ProductionOrderSyncRequest;
import org.jeecg.modules.sap.service.ProductionOrderSync;
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 ProductionOrderSyncImpl implements ProductionOrderSync {
 
    @Autowired
    private SapRfcConnectionManager connectionManager;
 
    @Override
    @ApiLog(apiName = "生产订单同步(ZPPF_033_1)", apiCategory = ApiLogCategoryEnum.SAP)
    public Map<String, Object> syncProductionOrder(ProductionOrderSyncRequest request) throws Exception {
        Map<String, Object> resultMap = new HashMap<>();
        JCoDestination destination = connectionManager.getDestination();
        JCoRepository repository = destination.getRepository();
        JCoFunction function = repository.getFunction(FunctionConst.ZPPF_033_1);
        if (function == null) {
            throw new RuntimeException("RFC 函数 ZPPF_033_1 未找到!");
        }
        // 设置输入参数
        //订单号查询条件
        if (StringUtils.isNotBlank(request.getOrderCode())) {
            JCoTable AUFNRTable = function.getTableParameterList().getTable("ZTAB_AUFNR");
            String[] split = request.getOrderCode().split(",");
            for (String code : split) {
                AUFNRTable.appendRow();
                AUFNRTable.setValue("AUFNR", code);
            }
        }
        //订单类型 标准生产订单
        if (StringUtils.isNotBlank(request.getOrderTypeCode())) {
            JCoTable AUARTTable = function.getTableParameterList().getTable("ZTAB_AUART");
            String[] split = request.getOrderTypeCode().split(",");
            for (String code : split) {
                AUARTTable.appendRow();
                AUARTTable.setValue("AUART", code);
            }
        }
        if (StringUtils.isNotBlank(request.getProductionManager())) {
            JCoTable FEVORTable = function.getTableParameterList().getTable("ZTAB_FEVOR");
            String[] split = request.getProductionManager().split(",");
            for (String code : split) {
                FEVORTable.appendRow();
                FEVORTable.setValue("FEVOR", code);
            }
        }
        if (StringUtils.isNotBlank(request.getFactoryCode())) {
            //新火炬
            JCoTable WERKSTable = function.getTableParameterList().getTable("ZTAB_WERKS");
            String[] split = request.getFactoryCode().split(",");
            for (String code : split) {
                WERKSTable.appendRow();
                WERKSTable.setValue("WERKS", code);
            }
        }
        if (StringUtils.isNotBlank(request.getOrderStatus())) {
            //新火炬
            JCoTable TXT04Table = function.getTableParameterList().getTable("ZTAB_TXT04");
            String[] split = request.getOrderStatus().split(",");
            for (String code : split) {
                TXT04Table.appendRow();
                TXT04Table.setValue("TXT04", code);
            }
        }
        if (StringUtils.isNotBlank(request.getCreateTimeLow())) {
            JCoTable UDATETable = function.getTableParameterList().getTable("ZTAB_UDATE");
            UDATETable.appendRow();
            UDATETable.setValue("LOW", request.getCreateTimeLow());
        }
        if (StringUtils.isNotBlank(request.getCreateTimeHigh())) {
            JCoTable UDATETable = function.getTableParameterList().getTable("ZTAB_UDATE");
            UDATETable.appendRow();
            UDATETable.setValue("HIGH", request.getCreateTimeHigh());
        }
        if (StringUtils.isNotBlank(request.getUpdateTimeLow())) {
            JCoTable LAEDATable = function.getTableParameterList().getTable("ZTAB_LAEDA");
            LAEDATable.appendRow();
            LAEDATable.setValue("LOW", request.getUpdateTimeLow());
        }
        if (StringUtils.isNotBlank(request.getUpdateTimeHigh())) {
            JCoTable LAEDATable = function.getTableParameterList().getTable("ZTAB_LAEDA");
            LAEDATable.appendRow();
            LAEDATable.setValue("HIGH", request.getUpdateTimeHigh());
        }
        // 执行调用
        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<ProductionOrderDTO> resultList = new ArrayList<>();
        ProductionOrderDTO dto;
        for (int i = 0; i < numRows; i++) {
            outputTable.setRow(i);
            dto = new ProductionOrderDTO();
            dto.setKDPOS(outputTable.getString("KDPOS"));
            dto.setCHARG(outputTable.getString("CHARG"));
            dto.setMAKTX(outputTable.getString("MAKTX"));
            dto.setMATNR(outputTable.getString("MATNR"));
            dto.setKDAUF(outputTable.getString("KDAUF"));
            dto.setAUFNR(outputTable.getString("AUFNR"));
            dto.setDAUAT(outputTable.getString("DAUAT"));
            dto.setGAMNG(outputTable.getString("GAMNG"));
            dto.setGMEIN(outputTable.getString("GMEIN"));
            dto.setAPRIO(outputTable.getString("APRIO"));
            dto.setAUFPL(outputTable.getString("AUFPL"));
            dto.setSTLNR(outputTable.getString("STLNR"));
            dto.setDWERK(outputTable.getString("DWERK"));
            dto.setNAME1(outputTable.getString("NAME1"));
            dto.setFEVOR(outputTable.getString("FEVOR"));
            dto.setTXT(outputTable.getString("TXT"));
            dto.setUSNAM(outputTable.getString("USNAM"));
            dto.setUDATE(outputTable.getString("UDATE"));
            dto.setLAEDA(outputTable.getString("LAEDA"));
            dto.setTIMES(outputTable.getString("TIMES"));
            dto.setTXT04(outputTable.getString("TXT04"));
            dto.setTXT30(outputTable.getString("TXT30"));
            dto.setGSTRP(outputTable.getString("GSTRP"));
            dto.setGLTRP(outputTable.getString("GLTRP"));
 
            //添加结果集
            resultList.add(dto);
            log.info(dto.toString());
        }
        resultMap.put("zmess", zmess);
        resultMap.put("ztype", ztype);
        resultMap.put("importParameters", request);
        resultMap.put("result", resultList);
        return resultMap;
    }
}