diff --git a/int-api/src/main/java/com/foreverwin/iep/integration/feign/RemoteGetSapBatchNoService.java b/int-api/src/main/java/com/foreverwin/iep/integration/feign/RemoteGetSapBatchNoService.java index 9a013d0..c1eec91 100644 --- a/int-api/src/main/java/com/foreverwin/iep/integration/feign/RemoteGetSapBatchNoService.java +++ b/int-api/src/main/java/com/foreverwin/iep/integration/feign/RemoteGetSapBatchNoService.java @@ -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 getSapBatchNo(@RequestBody String erpItem); -// @PostMapping("/shopOrderStatisticTransCallErp/api/getSapBatchNo/{num}") -// List getSapBatchNo(@RequestBody String erpItem, @PathVariable int num); - + /** + * 获取SAP批次号新 + * @param jsonObject + * @return + */ + @PostMapping("/shopOrderStatisticTransCallErp/api/getSapBatchNoNew") + R getSapBatchNoNew(@RequestBody JSONObject jsonObject); } \ No newline at end of file diff --git a/int-core/src/main/java/com/foreverwin/iep/integration/controller/ShopOrderStatisticTransController.java b/int-core/src/main/java/com/foreverwin/iep/integration/controller/ShopOrderStatisticTransController.java index 72e5b35..5133578 100644 --- a/int-core/src/main/java/com/foreverwin/iep/integration/controller/ShopOrderStatisticTransController.java +++ b/int-core/src/main/java/com/foreverwin/iep/integration/controller/ShopOrderStatisticTransController.java @@ -329,6 +329,14 @@ public class ShopOrderStatisticTransController { return R.ok(sapBatchNo); } + @ApiOperation(value = "生产管理报工平台-批次完工入库获取SAP批次号", notes = "生产管理报工平台-批次完工入库获取SAP批次号") + @SysLog("生产管理报工平台-批次完工入库获取SAP批次号") + @PostMapping("/api/getSapBatchNoNew") + public R getSapBatchNoNew(@RequestBody JSONObject jsonObject) { + String sapBatchNo = registerDocumentService.getSapBatchNoNew(jsonObject); + return R.ok(sapBatchNo); + } + @ApiOperation(value = "生产管理报工平台-批次完工入库报工", notes = "生产管理报工平台-批次完工入库报工") @SysLog("生产管理报工平台-批次完工入库报工") @PostMapping("/callErpLot") diff --git a/int-core/src/main/java/com/foreverwin/iep/integration/service/RegisterDocumentService.java b/int-core/src/main/java/com/foreverwin/iep/integration/service/RegisterDocumentService.java index 1d8b49f..8819e80 100644 --- a/int-core/src/main/java/com/foreverwin/iep/integration/service/RegisterDocumentService.java +++ b/int-core/src/main/java/com/foreverwin/iep/integration/service/RegisterDocumentService.java @@ -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); } diff --git a/int-core/src/main/java/com/foreverwin/iep/integration/service/impl/RegisterDocumentServiceImpl.java b/int-core/src/main/java/com/foreverwin/iep/integration/service/impl/RegisterDocumentServiceImpl.java index c9864d8..6c748ff 100644 --- a/int-core/src/main/java/com/foreverwin/iep/integration/service/impl/RegisterDocumentServiceImpl.java +++ b/int-core/src/main/java/com/foreverwin/iep/integration/service/impl/RegisterDocumentServiceImpl.java @@ -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 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 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 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 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 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