fix(获取sap批次):调用增加字段

This commit is contained in:
liaohechuan 2025-04-01 11:02:33 +08:00
parent 9d1e3cd7ae
commit 81114ed676
4 changed files with 95 additions and 6 deletions

View File

@ -1,13 +1,11 @@
package com.foreverwin.iep.integration.feign;
import com.alibaba.fastjson.JSONObject;
import com.foreverwin.mom.common.core.util.R;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import java.util.List;
/**
* @program: mom-wms-biz
* @description: 获取SAP批次号
@ -20,7 +18,11 @@ public interface RemoteGetSapBatchNoService {
@PostMapping("/shopOrderStatisticTransCallErp/api/getSapBatchNo")
R<String> getSapBatchNo(@RequestBody String erpItem);
// @PostMapping("/shopOrderStatisticTransCallErp/api/getSapBatchNo/{num}")
// List<R> getSapBatchNo(@RequestBody String erpItem, @PathVariable int num);
/**
* 获取SAP批次号新
* @param jsonObject
* @return
*/
@PostMapping("/shopOrderStatisticTransCallErp/api/getSapBatchNoNew")
R<String> getSapBatchNoNew(@RequestBody JSONObject jsonObject);
}

View File

@ -329,6 +329,14 @@ public class ShopOrderStatisticTransController {
return R.ok(sapBatchNo);
}
@ApiOperation(value = "生产管理报工平台-批次完工入库获取SAP批次号", notes = "生产管理报工平台-批次完工入库获取SAP批次号")
@SysLog("生产管理报工平台-批次完工入库获取SAP批次号")
@PostMapping("/api/getSapBatchNoNew")
public R<String> getSapBatchNoNew(@RequestBody JSONObject jsonObject) {
String sapBatchNo = registerDocumentService.getSapBatchNoNew(jsonObject);
return R.ok(sapBatchNo);
}
@ApiOperation(value = "生产管理报工平台-批次完工入库报工", notes = "生产管理报工平台-批次完工入库报工")
@SysLog("生产管理报工平台-批次完工入库报工")
@PostMapping("/callErpLot")

View File

@ -1,5 +1,6 @@
package com.foreverwin.iep.integration.service;
import com.alibaba.fastjson.JSONObject;
import com.foreverwin.iep.integration.domain.InvokeResponse;
import com.foreverwin.mom.wms.entity.Document;
import com.foreverwin.mom.wms.entity.DocumentDetailed;
@ -15,4 +16,6 @@ public interface RegisterDocumentService {
void cancelDocumentNo(Document document);
String getSapBatchNo(String erpItem);
String getSapBatchNoNew(JSONObject jsonObject);
}

View File

@ -1,5 +1,6 @@
package com.foreverwin.iep.integration.service.impl;
import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
@ -263,6 +264,29 @@ public class RegisterDocumentServiceImpl implements RegisterDocumentService {
return result;
}
@Override
public String getSapBatchNoNew(JSONObject jsonObject) {
String result = "";
String site = TenantContextHolder.getTenantId();
InvokeResponse invokeResponse = new InvokeResponse();
InvokeRequest invokeRequest = new InvokeRequest();
Map itemMap = new HashMap();
itemMap.put(jsonObject.getString("item"), 1);
try {
invokeResponse = assembleInvokeRequestNew(site, itemMap, invokeRequest, jsonObject.getString("shopOrder"), jsonObject.getString("qcGrade"));
if ("E".equals(invokeResponse.getResult())) {
throw BusinessException.build("获取物料的sap批次失败");
} else {
JSONArray jsonArray = JSONArray.parseArray(invokeResponse.getMessageContent());
JSONObject minJson = jsonArray.getJSONObject(0);
result = minJson.getString("CHARG");
}
} catch (Exception e) {
throw BusinessException.build(e.getMessage());
}
return result;
}
@Override
public List<String> getSapBatchNo(String erpItem, int num) {
String site = TenantContextHolder.getTenantId();
@ -323,6 +347,32 @@ public class RegisterDocumentServiceImpl implements RegisterDocumentService {
return invokeResponse;
}
public InvokeResponse assembleInvokeRequestNew(String site, Map<String, Integer> items, InvokeRequest invokeRequest, String shopOrder, String qcGrade) {
InvokeResponse invokeResponse = new InvokeResponse(invokeRequest);
if (items.size() > 0) {
// 呼叫ERP获取批次号
LocalDateTime nowLocalDateTime = LocalDateTime.now();
String nowTime = nowLocalDateTime.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
invokeRequest.setTransSid(SapUtil.generateReqId());
invokeRequest.setTransTime(nowTime);
invokeRequest.setFromSystem("IEP");
invokeRequest.setToSystem("ERP");
invokeRequest.setSite(site);
invokeRequest.setMessageId("ZMM_MES_CHARG_CREATE1");
// 组装抛送的报完呢
String jsonObjectStr = SapUtil.appendHead(assembleMsgBodyNew(items, shopOrder, qcGrade));
invokeRequest.setMessageContent(jsonObjectStr);
invokeRequest.setStart(nowTime);
invokeRequest.setKeyValue(items.toString());
invokeRequest.setRetry(false);
invokeResponse = zmmMesChargCreate1Service.call(invokeRequest);
} else {
invokeResponse.setResult("X");
}
return invokeResponse;
}
private String assembleMsgBody(Map<String, Integer> items) {
JSONObject jsonObject = new JSONObject();
jsonObject.put("RFC_FUNCTION", "ZMM_MES_CHARG_CREATE1");
@ -345,6 +395,32 @@ public class RegisterDocumentServiceImpl implements RegisterDocumentService {
return jsonObject.toJSONString();
}
private String assembleMsgBodyNew(Map<String, Integer> items, String shopOrder, String qcGrade) {
JSONObject jsonObject = new JSONObject();
if (StrUtil.isBlank(qcGrade)) {
qcGrade = "N";
}
jsonObject.put("RFC_FUNCTION", "ZMM_MES_CHARG_CREATE1");
JSONObject headRe = new JSONObject();
headRe.put("EXCHANGE_SYSTEM", "MES");
headRe.put("EXCHANGE_ID", SapUtil.generateReqId());
headRe.put("EXCHANGE_DOC", "iMES_Call_SAP");
jsonObject.put("REQUEST_CONTEXT", headRe);
JSONObject bodyRe = new JSONObject();
// 遍历map
JSONArray itemList = new JSONArray();
for (Map.Entry<String, Integer> entry : items.entrySet()) {
JSONObject item = new JSONObject();
item.put("MATNR", entry.getKey());
item.put("Z_GS", entry.getValue());
item.put("AUFNR", shopOrder);
item.put("Z_GRADE", qcGrade);
itemList.add(item);
}
bodyRe.put("IT_INPUT", itemList);
jsonObject.put("REQUEST_BODY", bodyRe);
return jsonObject.toJSONString();
}
// 冲销
@Override