fix(查询sap库存接口):新增前端调用接口
This commit is contained in:
parent
825c85fc19
commit
35b1b6668f
@ -10,6 +10,7 @@ import com.foreverwin.iep.integration.domain.InvokeResponse;
|
||||
import com.foreverwin.iep.integration.dto.MesReferSapInvResponseDTO;
|
||||
import com.foreverwin.iep.integration.handler.def.sap.SapUtil;
|
||||
import com.foreverwin.iep.integration.utils.JS;
|
||||
import com.foreverwin.mom.common.core.util.R;
|
||||
import com.foreverwin.mom.common.log.annotation.SysLog;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
@ -129,4 +130,97 @@ public class MesReferSapInvController {
|
||||
|
||||
return resutJsonObject;
|
||||
}
|
||||
|
||||
@ApiOperation(value = "查询sap库存", notes = "查询sap库存")
|
||||
@SysLog("查询sap库存")
|
||||
@GetMapping("/readMesReferSapInv")
|
||||
public R<List<MesReferSapInvResponseDTO>> readMesReferSapInv(MesReferSapInvResponseDTO mesReferSapInvDTO) {
|
||||
// 封装请求报文
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
jsonObject.put("RFC_FUNCTION", "ZMM_MES_GET_STOCK");
|
||||
JSONObject conTextJsonObject = new JSONObject();
|
||||
conTextJsonObject.put("EXCHANGE_SYSTEM", "MES");
|
||||
conTextJsonObject.put("EXCHANGE_ID", StrUtil.uuid());
|
||||
conTextJsonObject.put("EXCHANGE_DOC", "");
|
||||
jsonObject.put("REQUEST_CONTEXT", conTextJsonObject);
|
||||
JSONObject bodyJsonObject = new JSONObject();
|
||||
JSONObject inputJsonObject = new JSONObject();
|
||||
JSONArray inputJsonArray = new JSONArray();
|
||||
inputJsonObject.put("WERKS", mesReferSapInvDTO.getWerks());
|
||||
if (StrUtil.isBlank(mesReferSapInvDTO.getMatnr())) {
|
||||
inputJsonObject.put("MATNR", "");
|
||||
} else {
|
||||
inputJsonObject.put("MATNR", mesReferSapInvDTO.getMatnr());
|
||||
}
|
||||
if (StrUtil.isBlank(mesReferSapInvDTO.getLgort())) {
|
||||
inputJsonObject.put("LGORT", "");
|
||||
} else {
|
||||
inputJsonObject.put("LGORT", mesReferSapInvDTO.getLgort());
|
||||
}
|
||||
if (StrUtil.isBlank(mesReferSapInvDTO.getCharg())) {
|
||||
inputJsonObject.put("CHARG", "");
|
||||
} else {
|
||||
inputJsonObject.put("CHARG", mesReferSapInvDTO.getCharg());
|
||||
}
|
||||
if (StrUtil.isBlank(mesReferSapInvDTO.getSobkz())) {
|
||||
inputJsonObject.put("SOBKZ", "");
|
||||
} else {
|
||||
inputJsonObject.put("SOBKZ", mesReferSapInvDTO.getSobkz());
|
||||
}
|
||||
if (StrUtil.isBlank(mesReferSapInvDTO.getVbeln())) {
|
||||
inputJsonObject.put("VBELN", "");
|
||||
} else {
|
||||
inputJsonObject.put("VBELN", mesReferSapInvDTO.getVbeln());
|
||||
}
|
||||
if (StrUtil.isBlank(mesReferSapInvDTO.getPosnr())) {
|
||||
inputJsonObject.put("POSNR", "");
|
||||
} else {
|
||||
inputJsonObject.put("POSNR", mesReferSapInvDTO.getPosnr());
|
||||
}
|
||||
inputJsonArray.add(inputJsonObject);
|
||||
bodyJsonObject.put("IT_INPUT", inputJsonArray);
|
||||
jsonObject.put("REQUEST_BODY", bodyJsonObject);
|
||||
// messageContent内容
|
||||
JSONObject messageContentJson = SapUtil.appendHead(jsonObject);
|
||||
List<MesReferSapInvResponseDTO> mesReferSapInvResponseDTOList = new ArrayList<>();
|
||||
|
||||
// 调用 SAP 接口
|
||||
InvokeResponse invokeResponse = SapUtil.sendSap(messageContentJson.toString());
|
||||
if(!Msg.E.equals(invokeResponse.getResult())){
|
||||
// 请求处理成功
|
||||
JSONObject resJsonObject = JS.parseObject(invokeResponse.getMessageContent());
|
||||
JSONObject responseContextJson = resJsonObject.getJSONObject("RESPONSE_CONTEXT");
|
||||
if ("200".equals(responseContextJson.getString("RFC_CODE"))) {
|
||||
JSONObject responseBodyJson = resJsonObject.getJSONObject("RESPONSE_BODY");
|
||||
if (ObjectUtil.isNotEmpty(responseBodyJson)) {
|
||||
JSONArray etOutputJsonArray = responseBodyJson.getJSONArray("ET_OUTPUT");
|
||||
if (CollectionUtils.isNotEmpty(etOutputJsonArray)) {
|
||||
for (int i = 0; i < etOutputJsonArray.size(); i++) {
|
||||
MesReferSapInvResponseDTO mesReferSapInvResponseDTO = new MesReferSapInvResponseDTO();
|
||||
mesReferSapInvResponseDTO.setMatnr(etOutputJsonArray.getJSONObject(i).getString("MATNR"));
|
||||
mesReferSapInvResponseDTO.setWerks(etOutputJsonArray.getJSONObject(i).getString("WERKS"));
|
||||
mesReferSapInvResponseDTO.setLgort(etOutputJsonArray.getJSONObject(i).getString("LGORT"));
|
||||
mesReferSapInvResponseDTO.setCharg(etOutputJsonArray.getJSONObject(i).getString("CHARG"));
|
||||
mesReferSapInvResponseDTO.setSobkz(etOutputJsonArray.getJSONObject(i).getString("SOBKZ"));
|
||||
mesReferSapInvResponseDTO.setVbeln(etOutputJsonArray.getJSONObject(i).getString("VBELN"));
|
||||
mesReferSapInvResponseDTO.setPosnr(etOutputJsonArray.getJSONObject(i).getString("POSNR"));
|
||||
mesReferSapInvResponseDTO.setLabst(etOutputJsonArray.getJSONObject(i).getBigDecimal("LABST"));
|
||||
mesReferSapInvResponseDTO.setInsme(etOutputJsonArray.getJSONObject(i).getBigDecimal("INSME"));
|
||||
mesReferSapInvResponseDTO.setSpeme(etOutputJsonArray.getJSONObject(i).getBigDecimal("SPEME"));
|
||||
mesReferSapInvResponseDTO.setMeins(etOutputJsonArray.getJSONObject(i).getString("MEINS"));
|
||||
mesReferSapInvResponseDTOList.add(mesReferSapInvResponseDTO);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// 请求处理失败
|
||||
return R.failed("sap返回异常:"+responseContextJson.getString("RFC_REASON"));
|
||||
}
|
||||
} else {
|
||||
// 请求处理失败
|
||||
return R.failed("sap返回异常:"+invokeResponse.getMessageContent());
|
||||
}
|
||||
|
||||
return R.ok(mesReferSapInvResponseDTOList);
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user