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;
|
}
|
}
|