发料接口源代码如下:
public Map<String, Map<Integer, Map<String, Object>>> sendOutStorageMtrReq(List<Map<String, Object>> rows) throws Throwable{
ProdOrdGetDetail prodSap = new ProdOrdGetDetail();
Map<String,Map<String, List<Map<String, Object>>>> pbomDetailMap=new HashMap<>();
Map<String, Map<Integer, Map<String, Object>>> returnMap = new HashMap<>();
Map<Integer, Map<String, Object>> returnMap_1 = new HashMap<Integer, Map<String, Object>>();
Map<Integer, Map<String, Object>> returnMap_2 = new HashMap<Integer, Map<String, Object>>();
Map<String, Object> subMap = null;
SapBapiInvoker sap = null;
JCoDestination destination = null;
JCoFunction function = null;
JCoTable returntable = null;
JCoTable goodsmvt_item = null;
JCoTable goodsmvt_items = null;
try {
//根据生产订单号来查询SAP中的BOM明细 生产订单号只有一个
Map<String, List<Map<String, Object>>> pbomMap = prodSap.queryPbom(rows.get(0).get("workOrderNo").toString());
//将查询结果放MAP里 生产订单作为KEY
pbomDetailMap.put(rows.get(0).get("workOrderNo").toString(), pbomMap);
if(pbomMap.isEmpty()){
subMap = new HashMap<String, Object>();
subMap.put("type", "E");
subMap.put("message", "未获取到订单:" + rows.get(0).get("workOrderNo") + "BOM信息!");
returnMap_1.put(0, subMap);
returnMap.put("returntable", returnMap_1);
return returnMap;
}
sap = new SapBapiInvoker();
destination = sap.connectSAPserver(propPath);
function = destination.getRepository().getFunction("Z_SAP_PP_MTRRSM");
if(function == null){
throw new RuntimeException("Z_SAP_PP_MTRRSM not found in SAP.");
}
goodsmvt_item = function.getTableParameterList().getTable("GOODSMVT_ITEM");
for(Map<String, Object> row : rows){
Map<String, List<Map<String, Object>>> pbomItmMap = pbomDetailMap.get(rows.get(0).get("workOrderNo").toString());
String mtrErpCod = row.get("matnr").toString();
if(!pbomItmMap.containsKey(mtrFormat(mtrErpCod))){
continue;
}
String mtr = mtrFormat(mtrErpCod);
List<Map<String, Object>> pbomItmList = pbomItmMap.get(mtr);
String reservNo = "";
String resItem = "";
for (Map<String, Object> map : pbomItmList) {
reservNo = map.get("RESERVATION_NUMBER").toString();
resItem = map.get("RESERVATION_ITEM").toString();
}
goodsmvt_item.appendRow();
String orderid = this.autoGenericCode(row.get("workOrderNo").toString(), 12);//12位 不足12位补0
goodsmvt_item.setValue("ORDERID", orderid);//批次号
goodsmvt_item.setValue("MATERIAL", mtr);//物料编号
goodsmvt_item.setValue("ENTRY_QNT", Double.valueOf(row.get("qty").toString()));//领料数量
goodsmvt_item.setValue("ENTRY_UOM", row.get("qtyunit"));//物料的单位
goodsmvt_item.setValue("PLANT", row.get("werks"));//工厂
goodsmvt_item.setValue("STGE_LOC", row.get("lineLgortSapCod"));//库存地 线边仓的对应SAP编号
goodsmvt_item.setValue("MOVE_TYPE", 261);//移动类型
goodsmvt_item.setValue("RESERV_NO", reservNo);
goodsmvt_item.setValue("RES_ITEM", resItem);
}
function.execute(destination);
goodsmvt_items = function.getTableParameterList().getTable("GOODSMVT_ITEMS");
for(int i=0; i<goodsmvt_items.getNumRows(); i++){
subMap = new HashMap<String, Object>();
for(int j=0; j<goodsmvt_items.getMetaData().getFieldCount(); j++){
subMap.put(goodsmvt_items.getMetaData().getName(j).toLowerCase(), goodsmvt_items.getString(j));
}
returnMap_1.put(i, subMap);
goodsmvt_items.nextRow();
}
if(!returnMap_1.isEmpty()){
returnMap.put("goodsmvt_items", returnMap_1);
}
returntable = function.getTableParameterList().getTable("RETURN"); //失败时才会有,而且是一条,也就是i=0,放到returnMap的第一个(下标0)
for(int i=0; i<returntable.getNumRows(); i++){
subMap = new HashMap<String, Object>();
for(int j=0; j<returntable.getMetaData().getFieldCount(); j++){
subMap.put(returntable.getMetaData().getName(j).toLowerCase(), returntable.getString(j));
}
returnMap_2.put(i, subMap);
returntable.nextRow();
}
if(!returnMap_2.isEmpty()){
returnMap.put("returntable", returnMap_2);
}
} finally {
goodsmvt_items = null;
goodsmvt_item = null;
returntable = null;
function = null;
destination = null;
sap = null;
}
return returnMap;
}