From 3e47923e8490d282a062a73cf059a03039601d3f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=83=AD=E9=A3=9E?= Date: Mon, 24 Mar 2025 08:41:44 +0800 Subject: [PATCH] =?UTF-8?q?fix:=E4=BF=AE=E6=94=B9=E4=BA=A7=E6=88=90?= =?UTF-8?q?=E5=93=81=E5=85=A5=E5=BA=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../idm/service/impl/ToSAPServiceImpl.java | 120 +++++++++++++++++- .../idm/controller/FGStockInController.java | 13 +- .../idm/controller/MESToWMSController.java | 9 +- .../idm/service/Impl/MESToWMSServiceImpl.java | 94 +++++++++++++- .../service/Impl/MaterialUndoServiceImpl.java | 2 + .../service/Impl/ProductIntoServiceImpl.java | 18 ++- .../com/cim/idm/service/MESToWMSService.java | 5 + 7 files changed, 247 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 8ad59ec..4946f2b 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 @@ -16,8 +16,6 @@ import com.fasterxml.jackson.databind.JsonMappingException; import lombok.extern.slf4j.Slf4j; import org.apache.commons.collections4.MapUtils; import org.apache.commons.lang3.StringUtils; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -335,6 +333,48 @@ public class ToSAPServiceImpl { return undoId; } + // 取消物料入库凭证冲销 + public String cancelShipInter(String undoId, String user) throws Exception { + + String makeFGStockIn = matailInReverse(user, undoId); + String sapreturn = ""; + String rcode = ""; + String rmsg = ""; + String undoId2 = ""; + try { + sapreturn = toSAPMessageUtil.sendHttpPost(toSAPMessageUtil.materialChangeLocationUrl, "", + makeFGStockIn); + 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)) { + undoId2 = returnJsonObject.get("MBLNR").toString()+"_"+returnJsonObject.get("MJAHR").toString();//将物料凭证号与凭证年度拼在一起 + } + } catch (Exception e) { + log.error("WMS请求SAP异常:" + e.getMessage(), e); + throw new RuntimeException("WMS请求SAP异常:" + rmsg); + } finally { + // 将消息记录log表 + ErpMessageLog erplog = new ErpMessageLog(); + erplog.setEventUser(user); + erplog.setServerName("WmsToErp"); + erplog.setEventName("FGStockIn"); + erplog.setInterfaceTime(TimeStampUtil.getCurrentTime(TimeStampUtil.FORMAT_DEFAULT)); + erplog.setMessageId(RECEIVEACTNO); + erplog.setSendMsg2(makeFGStockIn); + erplog.setSendMsg(makeFGStockIn); + erplog.setReturnMsg2(sapreturn); + erplog.setResultCode(rcode); + MessageLogUtil.writeMessageLog(erplog); + } + if (!"S".equals(rcode)) { + throw new RuntimeException("SAP返回" + rmsg); + } + return undoId2; + } + public String FGStockIn2(String RECEIVEACTNO, String user) throws Exception { StringBuffer sql = new StringBuffer(); sql.append(SystemPropHelper.CR) @@ -565,6 +605,82 @@ public class ToSAPServiceImpl { return sendData; } + /** + * 取消物料入库冲销 + * + * @param + * @param + * @return + * @throws JsonMappingException + * @throws JsonProcessingException + */ + public String matailInReverse(String user, String undoId) throws JsonMappingException, JsonProcessingException { + +// if (list == null || list.size() < 1) { +// return ""; +// } +// +// Map bodyData = new HashMap<>(); +// List> itemsData = new ArrayList<>(); +// +// for (Map mm : list) { +// Map item = new HashMap<>(); +// //UMWRK 收货工厂 +// //LGORT 发货库存地点 +// //UMLOG 收货库存地点 +// //MATNR 发货物料号 +// //UMMAT 收货物料 +// +// item.put("MATNR", mm.get("MATERIALSPECNAME")); +// item.put("LGORT", mm.get("ERPLOCATION")); +// item.put("WERKS", mm.get("ERPFACTORY")); +// if("FG".equals((String)mm.get("MATERIALSPECTYPE")) ) { +// item.put("BWART", "101"); //产成品,移动类型 101 +// }else if("BFG".equals((String)mm.get("MATERIALSPECTYPE")) ) { +// item.put("BWART", "531"); //副产品, 移动类型 531 +// }else if("FGDEV".equals((String)mm.get("MATERIALSPECTYPE")) ) { +// item.put("BWART", "511"); //研发品, 移动类型 511 +// }else { +// item.put("BWART", "101"); //为了兼容之前的未提到的成品,统一暂用 101 +// } +// +// item.put("MENGE", mm.get("MATERIALQUANTITY")); +// item.put("MEINS", mm.get("UNIT")); +// item.put("AUFNR", mm.get("PRODUCTORDER")); +// item.put("BPMNG", ""); +// item.put("BPRME", ""); +// item.put("SGTXT", mm.get("REMARK")); +// String insmk = ""; +// if (StringUtils.isEmpty((String)mm.get("PACKINGGRADE"))) { +// insmk = "2"; +// }else if ("NG".equals((String)mm.get("PACKINGGRADE"))) { +// insmk = "3"; +// } +//// String insmk = StringUtils.equals(mm.get("OQARESULTSTATE").toString(),"END")?"":"X"; +// item.put("INSMK", insmk); +// itemsData.add(item); +// +// } +// String sendData = ToSAPMessageUtil.mm067(eventUser, bodyData, itemsData); + + Map headData = new HashMap<>(); + Map bodyData = new HashMap<>(); + Map headJSonData = new HashMap<>(); + Map bodyJSonData = new HashMap<>(); + headData.put("HEAD",headJSonData); + bodyData.put("BODY",bodyJSonData); + headJSonData.put("INTF_ID",""); + headJSonData.put("SRC_SYSTEM",""); + headJSonData.put("SRC_MSGID",""); + headJSonData.put("BACKUP1",""); + headJSonData.put("BACKUP2",""); + + bodyJSonData.put("MBLNR", ""); + bodyJSonData.put("MJAHR", ""); + + String sendData = ""; + return sendData; + } public String qtrNoInvoice(String receiveRequestName, String siteName, String reActo, String user) { String rcode; diff --git a/zi-wms-pda/src/main/java/com/cim/idm/controller/FGStockInController.java b/zi-wms-pda/src/main/java/com/cim/idm/controller/FGStockInController.java index bebaf36..e533873 100644 --- a/zi-wms-pda/src/main/java/com/cim/idm/controller/FGStockInController.java +++ b/zi-wms-pda/src/main/java/com/cim/idm/controller/FGStockInController.java @@ -52,8 +52,17 @@ public class FGStockInController { String erpLocation = materialPacking.getErpLocation(); String locationName = materialPacking.getLocationName(); String materialSpecName = materialPacking.getMaterialSpecName(); - //判断条码是否存在且状态是在库 - String sql = "SELECT M.STOCKSTATE,M.RECEIVEACTNO FROM MATERIALPACKING M WHERE M.MATERIALPACKINGNAME = :MATERIALPACKINGNAME"; + //判断条码是否存在且状态是在库,且仓库只能为线边仓(MDC_FLAG = 'Y') + String sql = "SELECT\n" + + "\tM.STOCKSTATE,\n" + + "\tM.RECEIVEACTNO\n" + + "FROM\n" + + "\tMATERIALPACKING M\n" + + "LEFT JOIN BS_ERPLOCATION be ON\n" + + "\tM.ERPLOCATION = be.ERPLOCATIONNAME\n" + + "WHERE\n" + + "\tbe.MDC_FLAG = 'Y'\n" + + "\tAND M.MATERIALPACKINGNAME = :MATERIALPACKINGNAME"; Map bindMap = new HashMap(); bindMap.put("MATERIALPACKINGNAME",materialPackingName); 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 a508c1d..8848f05 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 @@ -1,6 +1,7 @@ package com.cim.idm.controller; import com.alibaba.fastjson.JSONArray; +import com.cim.idm.service.Impl.MaterialUndoServiceImpl; import com.cim.idm.service.MESToWMSService; import com.cim.idm.service.Impl.MESToWMSServiceImpl; import com.cim.idm.utils.AjaxResult; @@ -22,6 +23,7 @@ public class MESToWMSController { @Autowired private MESToWMSServiceImpl mesToWMSService; + @ApiOperation(value = "物料消耗请求") @RequestMapping(value = "/meswms_materialconsume_request", method = RequestMethod.POST) public AjaxResult materialConsume_Request(@RequestBody JSONArray in) { @@ -46,9 +48,12 @@ public class MESToWMSController { @ApiOperation(value = "取消物料入库请求") @RequestMapping(value = "/meswms_cancelship_request", method = RequestMethod.POST) - public AjaxResult cancelShipByMES(@RequestBody JSONArray in) { + public AjaxResult cancelShipByMES(@RequestBody JSONArray in) throws Exception { log.info("Received cancel ship request: {}", in.toJSONString()); - return mesToWMSService.cancelShipByMES(in); + String undoId = in.getJSONObject(0).getString("undoId"); + String userId = in.getJSONObject(0).getString("userId"); +// return mesToWMSService.cancelShipByMES(in); + return mesToWMSService.sapcprkUndo(undoId, userId); } @ApiOperation(value = "物料入库请求") 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 7df5089..4a44e2f 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 @@ -10,8 +10,6 @@ import com.cim.idm.framework.orm.SqlTemplate; import com.cim.idm.framework.util.sys.SystemPropHelper; import com.cim.idm.framework.util.time.TimeStampUtil; import com.cim.idm.mwmsextend.materialpacking.service.MaterialPackingServiceImpl; -import com.cim.idm.service.Impl.ProductIntoServiceImpl; -import com.cim.idm.service.Impl.ReturnStockIntoServiceImpl; import com.cim.idm.service.MESToWMSService; import com.cim.idm.service.QMSService; import com.cim.idm.service.impl.ToSAPServiceImpl; @@ -19,19 +17,18 @@ import com.cim.idm.util.MessageLogUtil; import com.cim.idm.utils.AjaxResult; import com.cim.idm.utils.CommonUtils; import com.cim.idm.utils.EventInfoUtil; -import com.cim.idm.wmsextend.generic.errorHandler.CustomException; +import com.cim.idm.wmspackage.materialpacking.MaterialPackingServiceProxy; import com.cim.idm.wmspackage.materialpacking.management.data.MaterialPackingKey; +import com.cim.idm.wmspackage.materialpacking.management.info.RemoveInfo; +import com.cim.idm.wmspackage.materialpacking.management.info.SetEventInfo; import com.cim.idm.wmspackage.name.NameServiceProxy; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import java.sql.Timestamp; -import java.text.ParseException; import java.util.*; @Service("MESToWMS") @@ -175,6 +172,91 @@ public class MESToWMSServiceImpl implements MESToWMSService { return result; } + /** + * 成品入库SAP冲销 + * @param undoId + * @param user + */ + @Override + @Transactional + public AjaxResult sapcprkUndo(String undoId, String user) throws Exception { + + String billCode = toSAPService.cancelShipInter(undoId, user); + if (billCode == null) { + throw new GlobalException("报送ERP失败,请联系IT处理!"); + } + + + AjaxResult result = new AjaxResult(); + + EventInfo makeEventInfo = new EventInfoUtil ().makeEventInfo("MakeUndo", user, "MakeUndo"); + String condition="SELECT MATERIALPACKINGNAME FROM MATERIALPACKING WHERE UNDOID = :UNDOID "; +// String[] bindSet={undoId}; + Map hashMap = new HashMap (); + hashMap.put("UNDOID", undoId); + //根据物料凭证找到所有的待冲销数据,更新库存状态为创建 + List> MPlIST = IDMFrameServiceProxy.getSqlTemplate().queryForList(condition, hashMap); + SetEventInfo setEventInfo = new SetEventInfo(); + setEventInfo.setUserColumns(hashMap); + RemoveInfo removeInfo = new RemoveInfo(); + for (Map MP : MPlIST) { + //根据当前的数据跟新完工报告且删除入库表的数据 + String sql = "SELECT M.RECEIVEREQUESTNAME,M.RECEIVEREQUESTDETAILNAME,M.QTY FROM MATERIALPACKINGSUB M WHERE M.MATERIALPACKINGNAME = :MATERIALPACKINGNAME\r\n" + + "UNION \r\n" + + "SELECT M.RECEIVEREQUESTNAME,M.RECEIVEREQUESTDETAILNAME,M.QTY FROM MATERIALPACKINGSUBHISTORY M WHERE M.MATERIALPACKINGNAME = :MATERIALPACKINGNAME"; + String MATERIALPACKINGNAME = MP.get("MATERIALPACKINGNAME").toString(); + hashMap.put("MATERIALPACKINGNAME", MATERIALPACKINGNAME); + List> queryForList = IDMFrameServiceProxy.getSqlTemplate().queryForList(sql, hashMap); + for (int i = 0; i < queryForList.size(); i++) { + String dh = queryForList.get(i).get("RECEIVEREQUESTNAME").toString(); + hashMap.put("RECEIVEREQUESTNAME", dh); + String hh = queryForList.get(i).get("RECEIVEREQUESTDETAILNAME").toString(); + hashMap.put("RECEIVEREQUESTDETAILNAME", hh); +// String sl = queryForList.get(i).get("QTY").toString(); + String updateSql = "UPDATE MATERIALRECEIVEREQUESTDETAIL T \r\n" + + "SET T.RECEIVEDQUANTITY = T.RECEIVEDQUANTITY - ( \r\n" + + " SELECT NVL(SUM(M.QTY),0) \r\n" + + " FROM MATERIALPACKINGSUB M \r\n" + + " WHERE M.MATERIALPACKINGNAME = :MATERIALPACKINGNAME \r\n" + + " AND M.RECEIVEREQUESTNAME = T.RECEIVEREQUESTNAME \r\n" + + " AND M.RECEIVEREQUESTDETAILNAME = T.RECEIVEREQUESTDETAILNAME \r\n" + + ") \r\n" + + "WHERE T.RECEIVEREQUESTNAME = :RECEIVEREQUESTNAME \r\n" + + " AND T.RECEIVEREQUESTDETAILNAME = :RECEIVEREQUESTDETAILNAME"; + IDMFrameServiceProxy.getSqlTemplate().update(updateSql, hashMap); + + + String updateSql2 = "UPDATE MATERIALRECEIVEREQUESTDETAIL T \r\n" + + "SET T.RECEIVEDQUANTITY = T.RECEIVEDQUANTITY - ( \r\n" + + " SELECT NVL(SUM(M.QTY),0) \r\n" + + " FROM MATERIALPACKINGSUBHISTORY M \r\n" + + " WHERE M.MATERIALPACKINGNAME = :MATERIALPACKINGNAME \r\n" + + " AND M.RECEIVEREQUESTNAME = T.RECEIVEREQUESTNAME \r\n" + + " AND M.RECEIVEREQUESTDETAILNAME = T.RECEIVEREQUESTDETAILNAME \r\n" + + ") \r\n" + + "WHERE T.RECEIVEREQUESTNAME = :RECEIVEREQUESTNAME \r\n" + + " AND T.RECEIVEREQUESTDETAILNAME = :RECEIVEREQUESTDETAILNAME"; + IDMFrameServiceProxy.getSqlTemplate().update(updateSql2, hashMap); + + String deleteSql = " DELETE FROM MATERIALPACKINGSUB T WHERE T.RECEIVEREQUESTNAME = :RECEIVEREQUESTNAME AND " + + "T.RECEIVEREQUESTDETAILNAME = :RECEIVEREQUESTDETAILNAME AND T.MATERIALPACKINGNAME = :MATERIALPACKINGNAME"; + IDMFrameServiceProxy.getSqlTemplate().update(deleteSql, hashMap); + + String MESsQL = " UPDATE BS_MES_SHIPPED T SET T.RECEIVE_FLAG = 'N' WHERE T.LOTNAME = :MATERIALPACKINGNAME "; + IDMFrameServiceProxy.getSqlTemplate().update(MESsQL, hashMap); + } + MaterialPackingServiceProxy.getMaterialPackingService().remove(new MaterialPackingKey("SDK", MATERIALPACKINGNAME), makeEventInfo, removeInfo); + } + + String sql = "UPDATE IF_ERPUNDO T SET T.FLAG = 'Y' WHERE T.UNDOID = :UNDOID "; + Map hashMap2 = new HashMap (); + hashMap2.put("UNDOID", undoId); + IDMFrameServiceProxy.getSqlTemplate().update(sql, hashMap2); + + result = AjaxResult.me().setSuccess(true).setErrorCode(200).setMessage("执行成功"); + return result; + } + @Override @Transactional public AjaxResult shipByMES(JSONArray in) throws Exception { diff --git a/zi-wms-pda/src/main/java/com/cim/idm/service/Impl/MaterialUndoServiceImpl.java b/zi-wms-pda/src/main/java/com/cim/idm/service/Impl/MaterialUndoServiceImpl.java index 9a2ba9e..16ed571 100644 --- a/zi-wms-pda/src/main/java/com/cim/idm/service/Impl/MaterialUndoServiceImpl.java +++ b/zi-wms-pda/src/main/java/com/cim/idm/service/Impl/MaterialUndoServiceImpl.java @@ -1,8 +1,10 @@ package com.cim.idm.service.Impl; +import com.alibaba.fastjson.JSONArray; import com.cim.idm.framework.IDMFrameServiceProxy; import com.cim.idm.framework.data.EventInfo; import com.cim.idm.service.IMaterialUndoService; +import com.cim.idm.utils.AjaxResult; import com.cim.idm.utils.EventInfoUtil; import com.cim.idm.wmspackage.materialpacking.MaterialPackingServiceProxy; import com.cim.idm.wmspackage.materialpacking.management.data.MaterialPacking; diff --git a/zi-wms-pda/src/main/java/com/cim/idm/service/Impl/ProductIntoServiceImpl.java b/zi-wms-pda/src/main/java/com/cim/idm/service/Impl/ProductIntoServiceImpl.java index b67b8b5..99eaa84 100644 --- a/zi-wms-pda/src/main/java/com/cim/idm/service/Impl/ProductIntoServiceImpl.java +++ b/zi-wms-pda/src/main/java/com/cim/idm/service/Impl/ProductIntoServiceImpl.java @@ -128,8 +128,11 @@ public class ProductIntoServiceImpl implements FGStockInService { @Transactional public void fgStockInNew (List boxList, String user, String ReceiveRequestActNo, String commitDate, String opCode) throws Exception { - + + List arrayList = new ArrayList (); + String pc = "("; + for (MaterialPacking materialPacking : boxList) { String materialPackingName = materialPacking.getMaterialPackingName(); pc += "'" + materialPackingName + "', "; @@ -244,13 +247,23 @@ public class ProductIntoServiceImpl implements FGStockInService { continue; } } + + MaterialPackingKey materialPackingKey = new MaterialPackingKey("SDK",materialPackingName); + arrayList.add(materialPackingKey); + receiveMesShippInfo(makeEventInfo, "SDK", materialPackingName, "", user, materialPackingName, ReceiveRequestActNo, erpLocation, erpFactory, locationName,queryForList.get(0).get("RECEIVEREQUESTNAME").toString(), "",""); } pc += "'')"; // boolean fgStockIn = fgStockInBySplitCharge(pc, user,commitDate,opCode); + +// boolean fgStockInBySplitCharge20241118 = fgStockInBySplitCharge20241118(pc, user, commitDate, opCode); + String aimErpFactory = boxList.get(0).getErpFactory(); + String aimErpLocation = boxList.get(0).getErpLocation(); + String aimLOcationName = boxList.get(0).getLocationName(); boolean fgStockInBySplitCharge20241118 = fgStockInBySplitCharge20241118(pc, user, commitDate, opCode); - + String billCode = toSAPService.NoSourceChangeLocation(arrayList,aimErpFactory, + aimErpLocation, aimLOcationName, user ); } /** @@ -510,6 +523,7 @@ public class ProductIntoServiceImpl implements FGStockInService { String erpLocation = queryForList2.get(i).get("ERPLOCATION").toString(); String billCode = toSAPService.FGStockIn(pc, eventUser,commitDate,opCode + i); + if (billCode == null) { throw new GlobalException("报送ERP失败,请联系IT处理!"); } 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 35e3ae3..3798cf5 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 @@ -2,6 +2,7 @@ package com.cim.idm.service; import com.alibaba.fastjson.JSONArray; import com.cim.idm.utils.AjaxResult; +import org.springframework.transaction.annotation.Transactional; public interface MESToWMSService { @@ -23,6 +24,10 @@ public interface MESToWMSService { * @return */ AjaxResult cancelShipByMES(JSONArray in); + + @Transactional + AjaxResult sapcprkUndo(String undoId, String user) throws Exception; + /** * 接收MES请求物料入库请求 * @param in