feat(查询sap库存接口):新增api接口
This commit is contained in:
parent
7b8b3e5626
commit
060fbb33ce
@ -0,0 +1,70 @@
|
||||
package com.foreverwin.iep.integration.dto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
/**
|
||||
* 查询sap库存响应DTO
|
||||
*
|
||||
* @author hechuan.liao
|
||||
* @date 2024-07-31 09:47:44
|
||||
*/
|
||||
@Data
|
||||
public class MesReferSapInvResponseDTO {
|
||||
|
||||
/**
|
||||
* 物料编号
|
||||
*/
|
||||
private String matnr;
|
||||
|
||||
/**
|
||||
* 工厂
|
||||
*/
|
||||
private String werks;
|
||||
|
||||
/**
|
||||
* 存储地点
|
||||
*/
|
||||
private String lgort;
|
||||
|
||||
/**
|
||||
* 批次编号
|
||||
*/
|
||||
private String charg;
|
||||
|
||||
/**
|
||||
* 特殊库存标识
|
||||
*/
|
||||
private String sobkz;
|
||||
|
||||
/**
|
||||
* 销售和分销凭证号
|
||||
*/
|
||||
private String vbeln;
|
||||
|
||||
/**
|
||||
* 销售和分销凭证的项目号
|
||||
*/
|
||||
private String posnr;
|
||||
|
||||
/**
|
||||
* 非限制库存数量
|
||||
*/
|
||||
private BigDecimal labst;
|
||||
|
||||
/**
|
||||
* 质检库存
|
||||
*/
|
||||
private BigDecimal insme;
|
||||
|
||||
/**
|
||||
* 冻结库存
|
||||
*/
|
||||
private BigDecimal speme;
|
||||
|
||||
/**
|
||||
* 单位
|
||||
*/
|
||||
private String meins;
|
||||
}
|
||||
@ -0,0 +1,132 @@
|
||||
package com.foreverwin.iep.integration.controller;
|
||||
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
|
||||
import com.foreverwin.iep.integration.constant.Msg;
|
||||
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.log.annotation.SysLog;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 查询sap库存
|
||||
*
|
||||
* @author hechuan.liao
|
||||
* @date 2025-03-04 09:59:18
|
||||
*/
|
||||
@RestController
|
||||
@RequiredArgsConstructor
|
||||
@RequestMapping("/mesReferSapInv")
|
||||
@Api(value = "mesReferSapInv", tags = "查询sap库存")
|
||||
public class MesReferSapInvController {
|
||||
|
||||
@ApiOperation(value = "查询sap库存", notes = "查询sap库存")
|
||||
@SysLog("查询sap库存")
|
||||
@GetMapping("/api/mesReferSapInv")
|
||||
public JSONObject mesReferSapInv(@RequestParam(name = "matnr", required = false) String matnr,
|
||||
@RequestParam(name = "werks", required = false) String werks,
|
||||
@RequestParam(name = "lgort", required = false) String lgort,
|
||||
@RequestParam(name = "charg", required = false) String charg,
|
||||
@RequestParam(name = "sobkz", required = false) String sobkz,
|
||||
@RequestParam(name = "vbeln", required = false) String vbeln,
|
||||
@RequestParam(name = "posnr", required = false) String posnr) {
|
||||
// 封装请求报文
|
||||
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", werks);
|
||||
if (StrUtil.isBlank(matnr)) {
|
||||
inputJsonObject.put("MATNR", "");
|
||||
} else {
|
||||
inputJsonObject.put("MATNR", matnr);
|
||||
}
|
||||
if (StrUtil.isBlank(lgort)) {
|
||||
inputJsonObject.put("LGORT", "");
|
||||
} else {
|
||||
inputJsonObject.put("LGORT", lgort);
|
||||
}
|
||||
if (StrUtil.isBlank(charg)) {
|
||||
inputJsonObject.put("CHARG", "");
|
||||
} else {
|
||||
inputJsonObject.put("CHARG", charg);
|
||||
}
|
||||
if (StrUtil.isBlank(sobkz)) {
|
||||
inputJsonObject.put("SOBKZ", "");
|
||||
} else {
|
||||
inputJsonObject.put("SOBKZ", sobkz);
|
||||
}
|
||||
if (StrUtil.isBlank(vbeln)) {
|
||||
inputJsonObject.put("VBELN", "");
|
||||
} else {
|
||||
inputJsonObject.put("VBELN", vbeln);
|
||||
}
|
||||
if (StrUtil.isBlank(posnr)) {
|
||||
inputJsonObject.put("POSNR", "");
|
||||
} else {
|
||||
inputJsonObject.put("POSNR", posnr);
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
JSONObject resutJsonObject = new JSONObject();
|
||||
resutJsonObject.put("data", mesReferSapInvResponseDTOList);
|
||||
|
||||
return resutJsonObject;
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user