package org.jeecg.modules.sap.service.impl;
|
|
import com.sap.conn.jco.*;
|
import lombok.extern.slf4j.Slf4j;
|
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.OrderLoadDTO;
|
import org.jeecg.modules.sap.request.OrderLoadRequest;
|
import org.jeecg.modules.sap.service.OrderLoadService;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.stereotype.Service;
|
|
import java.util.HashMap;
|
import java.util.Map;
|
|
@Service
|
@Slf4j
|
public class OrderLoadServiceImpl implements OrderLoadService {
|
@Autowired
|
private SapRfcConnectionManager connectionManager;
|
|
@Override
|
@ApiLog(apiName = "生产订单投料(ZMES_GOODSMVT_CREATE_2301)", apiCategory = ApiLogCategoryEnum.SAP)
|
public Map<String, Object> productionOrderLoad(OrderLoadRequest request) throws Exception {
|
Map<String, Object> resultMap = new HashMap<>();
|
JCoDestination destination = connectionManager.getDestination();
|
JCoRepository repository = destination.getRepository();
|
JCoFunction function = repository.getFunction(FunctionConst.ZMES_GOODSMVT_CREATE_2301);
|
if (function == null) {
|
throw new RuntimeException("RFC 函数 ZMES_GOODSMVT_CREATE_2301 未找到!");
|
}
|
//设置请求参数
|
JCoParameterList importParameterList = function.getImportParameterList();
|
importParameterList.setValue("I_WERKS", request.getFactoryCode());
|
importParameterList.setValue("I_AUFNR", request.getOrderCode());
|
importParameterList.setValue("I_SGTXT", request.getItemContent());
|
JCoTable table = function.getTableParameterList().getTable("T_ITEM");
|
table.appendRow();
|
table.setValue("MATNR", request.getMaterialNumber());
|
table.setValue("WERKS", request.getFactoryCode());
|
table.setValue("LGORT", request.getWarehouseCode());
|
table.setValue("CHARG", request.getBatchNumber());
|
table.setValue("BWART", request.getMoveType());
|
table.setValue("MENGE", request.getQuantity());
|
table.setValue("MEINS", request.getProductionUnit());
|
table.setValue("AUFNR", request.getOrderCode());
|
table.setValue("SGTXT", request.getItemContent());
|
table.setValue("SOBKZ", request.getSpecialStockFlag());
|
table.setValue("LIFNR", request.getSupplierCode());
|
|
// 执行调用
|
function.execute(destination);
|
//获取返回结果
|
Object eReturn1 = function.getExportParameterList().getValue("E_RETURN");
|
OrderLoadDTO reportDTO1 = null;
|
if (eReturn1 != null) {
|
JCoStructure eReturn = (JCoStructure) eReturn1;
|
//E Return
|
reportDTO1 = new OrderLoadDTO();
|
reportDTO1.setTYPE(eReturn.getString("TYPE"));
|
reportDTO1.setID(eReturn.getString("ID"));
|
reportDTO1.setNUMBER(eReturn.getString("NUMBER"));
|
reportDTO1.setMESSAGE(eReturn.getString("MESSAGE"));
|
reportDTO1.setLOG_NO(eReturn.getString("LOG_NO"));
|
reportDTO1.setLOG_MSG_NO(eReturn.getString("LOG_MSG_NO"));
|
reportDTO1.setMESSAGE_V1(eReturn.getString("MESSAGE_V1"));
|
reportDTO1.setMESSAGE_V2(eReturn.getString("MESSAGE_V2"));
|
reportDTO1.setMESSAGE_V3(eReturn.getString("MESSAGE_V3"));
|
reportDTO1.setMESSAGE_V4(eReturn.getString("MESSAGE_V4"));
|
reportDTO1.setPARAMETER(eReturn.getString("PARAMETER"));
|
reportDTO1.setROW(eReturn.getString("ROW"));
|
reportDTO1.setFIELD(eReturn.getString("FIELD"));
|
reportDTO1.setSYSTEM(eReturn.getString("SYSTEM"));
|
}
|
JCoTable tReturn1 = function.getTableParameterList().getTable("T_RETURN");
|
OrderLoadDTO reportDTO2 = null;
|
if (tReturn1.getNumRows() > 0) {
|
tReturn1.setRow(0);
|
reportDTO2 = new OrderLoadDTO();
|
reportDTO2.setTYPE(tReturn1.getString("TYPE"));
|
reportDTO2.setID(tReturn1.getString("ID"));
|
reportDTO2.setNUMBER(tReturn1.getString("NUMBER"));
|
reportDTO2.setMESSAGE(tReturn1.getString("MESSAGE"));
|
reportDTO2.setLOG_NO(tReturn1.getString("LOG_NO"));
|
reportDTO2.setLOG_MSG_NO(tReturn1.getString("LOG_MSG_NO"));
|
reportDTO2.setMESSAGE_V1(tReturn1.getString("MESSAGE_V1"));
|
reportDTO2.setMESSAGE_V2(tReturn1.getString("MESSAGE_V2"));
|
reportDTO2.setMESSAGE_V3(tReturn1.getString("MESSAGE_V3"));
|
reportDTO2.setMESSAGE_V4(tReturn1.getString("MESSAGE_V4"));
|
reportDTO2.setPARAMETER(tReturn1.getString("PARAMETER"));
|
reportDTO2.setROW(tReturn1.getString("ROW"));
|
reportDTO2.setFIELD(tReturn1.getString("FIELD"));
|
reportDTO2.setSYSTEM(tReturn1.getString("SYSTEM"));
|
}
|
|
String zmess = reportDTO1 == null ? (reportDTO2 == null ? "" : reportDTO2.getMESSAGE()) : reportDTO1.getMESSAGE();
|
String ztype = reportDTO1 == null ? (reportDTO2 == null ? "" : reportDTO2.getTYPE()) : reportDTO1.getTYPE(); //S 标识 成功
|
|
resultMap.put("zmess", zmess);
|
resultMap.put("ztype", ztype);
|
resultMap.put("importParameters", request);
|
resultMap.put("result", reportDTO1 == null ? reportDTO2 : reportDTO1);
|
return resultMap;
|
}
|
}
|