From 8d1fa52a6637a17652de782d4ba40676d44f5996 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E5=B8=85?= <3115919733@qq.com> Date: Tue, 27 May 2025 15:22:58 +0800 Subject: [PATCH] =?UTF-8?q?=E8=BD=AC=E5=B7=A5=E5=8D=95-=E6=B2=A1=E5=81=9A?= =?UTF-8?q?=E5=AE=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../idm/service/impl/ToSAPServiceImpl.java | 123 +++++++++++++++++- .../idm/controller/MESToWMSController.java | 2 +- .../idm/service/Impl/MESToWMSServiceImpl.java | 63 +++++++-- .../com/cim/idm/service/MESToWMSService.java | 7 + 4 files changed, 181 insertions(+), 14 deletions(-) diff --git a/zi-wms-inf/src/main/java/com/cim/idm/service/impl/ToSAPServiceImpl.java b/zi-wms-inf/src/main/java/com/cim/idm/service/impl/ToSAPServiceImpl.java index eab96bb..fee5501 100644 --- a/zi-wms-inf/src/main/java/com/cim/idm/service/impl/ToSAPServiceImpl.java +++ b/zi-wms-inf/src/main/java/com/cim/idm/service/impl/ToSAPServiceImpl.java @@ -6472,7 +6472,8 @@ public class ToSAPServiceImpl { } - public String StockOutByOrder(List materialPackingList, String mes) {{ + public String StockOutByOrder(List materialPackingList, String mes, + String bwart) {{ String rcode; String undoId = ""; @@ -6535,7 +6536,7 @@ public class ToSAPServiceImpl { // //GRUND 移动原因 (201,202回传) // item.put("GRUND", mm.get("SHIPREQUESTDETAILTYPE")); - item.put("BWART", "261"); + item.put("BWART", bwart); //ZLLORDER 自定义领料单号 // item.put("ZLLORDER", "LL1010250408001"); item.put("ZLLORDER", mm.getZLLORDER()); @@ -6583,6 +6584,124 @@ public class ToSAPServiceImpl { return undoId; } } + + + /** + * 转工单-新 + * @param materialPackingList + * @param mes + * @param bwart + * @return + */ + public String StockOutByOrder_new(List> mapList, String mes, + String bwart) { + + String rcode; + String undoId = ""; + String rmsg = null; + + try { + + JSONObject sendData = new JSONObject(true); + JSONObject header = new JSONObject(true); + sendData.put("HEAD", header); + JSONObject body = new JSONObject(true); + sendData.put("BODY", body); + JSONArray itemArray = new JSONArray(); + + /* + HEAD + */ + header.put("INTF_ID", "MM067"); + String uniqueID = UUID.randomUUID().toString(); + header.put("REQ_KEYID", uniqueID); + header.put("SRC_MSGID", uniqueID); + header.put("SRC_SYSTEM", "WMS"); + header.put("DEST_SYSTEM", "SAP"); + header.put("REQUSER", mes); + + /* + BODY + */ + body.put("ITEM", mapList); + body.put("ITEMID", uniqueID); + //过账日期 + body.put("BUDAT", TimeStampUtil.getCurrentTime("yyyyMMdd")); + //凭证日期 + body.put("BLDAT", TimeStampUtil.getCurrentTime("yyyyMMdd")); + //凭证抬头文本 + body.put("BKTXT", uniqueID); + //用户名 + body.put("USNAM", mes); + + + if (mapList == null || mapList.size() < 1) { + throw new RuntimeException("不存在需要发送的数据"); + } + for (Map mm : mapList) { + mm.put("BWART", bwart); + JSONObject item = new JSONObject(true); + /*if(materialPackingList.size()>0) { + // MATNR 发货物料号 + item.put("MATNR", mm.getMATNR()); + + // WERKS 发货工厂 + item.put("WERKS", mm.getWERKS()); + // LGORT 发货库存地点 + item.put("LGORT", mm.getLGORT()); + //MENGE 数量 + item.put("MENGE",mm.getMENGE()); + //MENGE 单位 + item.put("MEINS",mm.getMEINS()); + item.put("BWART", bwart); + //ZLLORDER 自定义领料单号 +// item.put("ZLLORDER", "LL1010250408001"); + item.put("ZLLORDER", mm.getZLLORDER()); + //ZLLITEM 自定义领料单行号 + +// item.put("ZLLITEM", "0001"); + item.put("ZLLITEM", mm.getZLLITEM()); + //AUFNR 订单号 + item.put("AUFNR", mm.getAUFNR()); + + } + itemArray.add(item);*/ + } + + System.out.println(mapList); + /*log.info("SendTOSAP >>>>" + sendData); + String sendDatas = sendData.toJSONString(); + String sapreturn = toSAPMessageUtil.sendHttpPost(toSAPMessageUtil.materialChangeLocationUrl, "", sendDatas); + org.json.JSONObject receiveJsonObject = new org.json.JSONObject(sapreturn); + org.json.JSONObject returnJsonObject = (org.json.JSONObject) receiveJsonObject.get("RETURN"); + rcode = returnJsonObject.get("STATUS").toString(); + rmsg = returnJsonObject.get("MSGTXT").toString(); + + if ("S".equals(rcode)) { + undoId = returnJsonObject.get("MBLNR").toString()+"_"+returnJsonObject.get("MJAHR").toString();//将物料凭证号与凭证年度拼在一起 + } + //将log写到表里 + ErpMessageLog erplog = new ErpMessageLog(); + erplog.setEventUser(""); + erplog.setServerName("WmsToErp"); + erplog.setEventName("MES物料消耗261和转工单"); + erplog.setInterfaceTime(TimeStampUtil.getCurrentTime(TimeStampUtil.FORMAT_DEFAULT)); + erplog.setMessageId(UUID.randomUUID().toString()); + erplog.setSendMsg(sendData.toJSONString()); + erplog.setSendMsg2(sendData.toJSONString()); + erplog.setReturnMsg2(sapreturn); + erplog.setResultCode(rcode); + MessageLogUtil.writeMessageLog(erplog);*/ + } catch (Exception e) { + log.info(e.getMessage(), e); +// throw new RuntimeException("SAP返回" + e.toString()); + } + /* if (!"S".equals(rcode)) { + throw new RuntimeException("SAP返回" + rmsg); + }*/ + return null; + } + /** * 成品入库 * diff --git a/zi-wms-pda/src/main/java/com/cim/idm/controller/MESToWMSController.java b/zi-wms-pda/src/main/java/com/cim/idm/controller/MESToWMSController.java index 1e64e3a..f6cd056 100644 --- a/zi-wms-pda/src/main/java/com/cim/idm/controller/MESToWMSController.java +++ b/zi-wms-pda/src/main/java/com/cim/idm/controller/MESToWMSController.java @@ -34,7 +34,7 @@ public class MESToWMSController { public AjaxResult workOrder_Request(@RequestBody JSONArray in) { log.info("Received work order request: {}", in.toJSONString()); try { - return mesToWMSService.workOrder_Request(in); + return mesToWMSService.workOrder_Request_new(in); } catch (Exception e) { throw new RuntimeException(e); } diff --git a/zi-wms-pda/src/main/java/com/cim/idm/service/Impl/MESToWMSServiceImpl.java b/zi-wms-pda/src/main/java/com/cim/idm/service/Impl/MESToWMSServiceImpl.java index 17498ba..6edf335 100644 --- a/zi-wms-pda/src/main/java/com/cim/idm/service/Impl/MESToWMSServiceImpl.java +++ b/zi-wms-pda/src/main/java/com/cim/idm/service/Impl/MESToWMSServiceImpl.java @@ -660,6 +660,45 @@ public class MESToWMSServiceImpl implements MESToWMSService { return result; } + @Override + @Transactional + public AjaxResult workOrder_Request_new(JSONArray in) throws Exception { + log.info("Received work order request: {}", in.toJSONString()); + List> mapList = new ArrayList<>(); + for (int i = 0; i < in.size(); i++) { + JSONObject jsonObject = in.getJSONObject(i); + Map map = new HashMap<>(); + // 料号 + String materialSpecname = jsonObject.getString("materialSpecname"); + // 组织 + String WERKS = jsonObject.getString("WERKS"); + // 仓库 + String LGORT = jsonObject.getString("LGORT"); + // 数量 + String MENGE = jsonObject.getString("MENGE"); + // 单位 + String MEINS = jsonObject.getString("MEINS"); + // 自定义领料单号 + String ZLLORDER = jsonObject.getString("ZLLORDER"); + // 自定义领料单行号 + String ZLLITEM = jsonObject.getString("ZLLITEM"); + // 工单 + String AUFNR = jsonObject.getString("AUFNR"); + + map.put("MATNR", materialSpecname); + map.put("WERKS", WERKS); + map.put("LGORT", LGORT); + map.put("MENGE", MENGE); + map.put("MEINS", MEINS); + map.put("ZLLORDER", ZLLORDER); + map.put("ZLLITEM", ZLLITEM); + map.put("AUFNR", AUFNR); + mapList.add(map); + } + // 出库 + String undoid = toSAPService.StockOutByOrder_new(mapList, "MES", "262"); + return AjaxResult.me().setResultObj(null).setSuccess(true).setErrorCode(200).setMessage("执行成功,物料凭证 " + undoid); + } /** * 接收MES请求工单请求 * @@ -701,6 +740,15 @@ public class MESToWMSServiceImpl implements MESToWMSService { String s = materialOutByMES(materialSpecnameList, chargeList); //调用入库方法 String s1 = materialIntoByMES(materialSpecnameList, chargeList,wo); + if (StringUtils.isEmpty(s1)) { + // 冲销 + String undo = invoiceService.cancelShipInter(s, "MES"); + if (undo == null || undo.isEmpty()) { + throw new GlobalException("下发mes失败后冲销失败!"); + } else { + throw new GlobalException("发送到mes失败!"); + } + } String message = "工单转换成功 物料凭证 {}"; return AjaxResult.me().setResultObj(null).setSuccess(true).setErrorCode(200).setMessage("执行成功,物料凭证 " + s1); } @@ -716,17 +764,9 @@ public class MESToWMSServiceImpl implements MESToWMSService { //出库过账 String undoid = toSAPService.StockOutByOrder( materialPackingList, - "MES" + "MES", + "262" ); - if (undoid != null) { - // 冲销 - String undo = invoiceService.cancelShipInter(undoid, "MES"); - if (undo == null || undo.isEmpty()) { - throw new GlobalException("下发mes失败后冲销失败!"); - } else { - throw new GlobalException("发送到mes失败!"); - } - } //更新MDC表状态 mesToWmsDao.updateMDCFlag(materialSpecnameList, chargeList, "T"); return undoid; @@ -743,7 +783,8 @@ public class MESToWMSServiceImpl implements MESToWMSService { //入库过账 String undoid = toSAPService.StockOutByOrder( materialPackingListByRK, - "MES" + "MES", + "261" ); mesToWmsDao.updateMDCFlag(materialSpecnameList, chargeList, "S"); return undoid; diff --git a/zi-wms-pda/src/main/java/com/cim/idm/service/MESToWMSService.java b/zi-wms-pda/src/main/java/com/cim/idm/service/MESToWMSService.java index fbccc71..72ab4e2 100644 --- a/zi-wms-pda/src/main/java/com/cim/idm/service/MESToWMSService.java +++ b/zi-wms-pda/src/main/java/com/cim/idm/service/MESToWMSService.java @@ -35,6 +35,13 @@ public interface MESToWMSService { */ AjaxResult shipByMES(JSONArray in) throws Exception; + /** + * 接收MES请求工单请求 + * @param in + * @return + */ + AjaxResult workOrder_Request_new(JSONArray in) throws Exception; + /** * 接收MES请求工单请求 * @param in