新火炬后端单体项目初始化代码
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
package org.jeecg.modules.sap.service.impl;
 
import cn.hutool.core.collection.CollectionUtil;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.parser.Feature;
import com.fasterxml.jackson.databind.ObjectMapper;
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.MaterialRequestDTO;
import org.jeecg.modules.sap.request.MaterialRequest;
import org.jeecg.modules.sap.service.OrderMaterialRequestService;
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 OrderMaterialRequestServiceImpl implements OrderMaterialRequestService {
    @Autowired
    private SapRfcConnectionManager connectionManager;
    @Autowired
    private ObjectMapper objectMapper;
 
    @Override
    @ApiLog(apiName = "SAP预留号创建(ZMES_RESERVATION_CREATE)", apiCategory = ApiLogCategoryEnum.SAP)
    public Map<String, Object> orderMaterialRequest(String factoryCode, String receiveWarehouseCode, List<MaterialRequest> request) throws Exception {
        Map<String, Object> resultMap = new HashMap<>();
        JCoDestination destination = connectionManager.getDestination();
        JCoRepository repository = destination.getRepository();
        JCoFunction function = repository.getFunction(FunctionConst.ZMES_RESERVATION_CREATE);
        if (function == null) {
            throw new RuntimeException("RFC 函数 ZMES_RESERVATION_CREATE 未找到!");
        }
        if (StringUtils.isBlank(factoryCode) || StringUtils.isBlank(receiveWarehouseCode) || CollectionUtil.isEmpty(request)) {
            resultMap.put("zmess", "工厂编码、接收库存地为空或物料信息为空");
            resultMap.put("ztype", "-1");
            resultMap.put("importParameters", factoryCode + "|" + receiveWarehouseCode + "|" + (request == null ? 0 : request.size()));
            resultMap.put("result", null);
            return resultMap;
        }
        // 设置输入参数
        List<JSONObject> items = new ArrayList<>();
        //新火炬
        JCoParameterList importParameterList = function.getImportParameterList();
        importParameterList.setValue("I_SITE", factoryCode);
        //组装请求参数
        JSONObject item = new JSONObject();
        item.put("I_SITE", factoryCode);
        items.add(item);
 
        //接收库存地
        importParameterList.setValue("I_TO_STORGE_LOC", receiveWarehouseCode);
        //组装请求参数
        item = new JSONObject();
        item.put("I_TO_STORGE_LOC", factoryCode);
        items.add(item);
 
        JCoTable itemTable = function.getTableParameterList().getTable("T_ITEMS");
        for (MaterialRequest itemReq : request) {
            itemTable.appendRow();
            itemTable.setValue("ITEM", itemReq.getMaterialNumber());
            itemTable.setValue("PULL_QTY", itemReq.getQuantity());
            itemTable.setValue("FROM_STORGE_LOC", itemReq.getWarehouseCode());
            //组装请求参数
            String json = objectMapper.writeValueAsString(itemReq);
            item = JSONObject.parseObject(json, Feature.OrderedField);
            items.add(item);
        }
 
        // 执行调用
        function.execute(destination);
        //获取返回结果
        MaterialRequestDTO response = new MaterialRequestDTO();
        String zmess = function.getExportParameterList().getValue("O_IS_OK").toString();
        String ztype = function.getExportParameterList().getValue("O_MESSAGE").toString();//S 标识 成功
        String resv = function.getExportParameterList().getValue("O_SAP_RESV").toString();//S 标识 成功
        response.setO_IS_OK(ztype);
        response.setO_MESSAGE(zmess);
        response.setO_SAP_RESV(resv);
        //返回结果
        resultMap.put("zmess", zmess);
        resultMap.put("ztype", ztype);
        resultMap.put("importParameters", items);
        resultMap.put("result", response);
        return resultMap;
    }
}