Compare commits

...

2 Commits

3 changed files with 190 additions and 40 deletions

View File

@ -111,7 +111,7 @@ public class MESServiceImpl implements MESService{
}
//zd.2024.8.4重写发送MES方法
public String OutMaterialInfoSend_NEW(String shipRequestName, String siteName, String receiveActNo, String wo,
public Boolean OutMaterialInfoSend_NEW(String shipRequestName, String siteName, String receiveActNo, String wo,
String erpReceiveLocation,String erpReceiveFactory,List<String> boxList) throws CustomException{
//根据单据获取要发送MES的信息
@ -172,10 +172,10 @@ public class MESServiceImpl implements MESService{
erplog.setResultCode(code);
MessageLogUtil.writeMessageLog(erplog);
if (!success) {
String msg = jsonObject.getString("msg");
throw new CustomException("发送MES失败");
}
// if (!success) {
// String msg = jsonObject.getString("msg");
// throw new CustomException("发送MES失败");
// }
//插入MATERIALPCKINGMDC表
for(int i=0;i<boxList.size();i++)
@ -232,11 +232,11 @@ public class MESServiceImpl implements MESService{
IDMFrameServiceProxy.getSqlTemplate().update(sqli, hashMap);
}
return code;
return success;
}
public String OutMaterialInfoSend_NEW2(String shipRequestName, String siteName, String receiveActNo, String wo,
public Boolean OutMaterialInfoSend_NEW2(String shipRequestName, String siteName, String receiveActNo, String wo,
String erpReceiveLocation,String erpReceiveFactory,List<String> boxList) throws CustomException{
//根据单据获取要发送MES的信息
@ -297,10 +297,10 @@ public class MESServiceImpl implements MESService{
erplog.setResultCode(code);
MessageLogUtil.writeMessageLog(erplog);
if (!success) {
String msg = jsonObject.getString("msg");
throw new CustomException("发送MES失败");
}
// if (!success) {
// String msg = jsonObject.getString("msg");
// throw new CustomException("发送MES失败");
// }
//插入MATERIALPCKINGMDC表
for(int i=0;i<boxList.size();i++)
@ -360,7 +360,7 @@ public class MESServiceImpl implements MESService{
}
return code;
return success;
}
// mes生产退料删除批次

View File

@ -36,6 +36,8 @@ import com.cim.idm.wmspackage.materialreceiverequestactdetail.MaterialReceiveReq
import com.cim.idm.wmspackage.materialreceiverequestactdetail.management.info.ActDetailIncreaseInfo;
import com.cim.idm.wmspackage.materialreceiverequestactdetail.management.info.CreateActDetailInfo;
import com.cim.idm.wmspackage.materialreceivetactdetail.management.data.MaterialReceiveActDetailKey;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonMappingException;
import groovy.lang.Lazy;
import org.apache.commons.collections4.MapUtils;
import org.springframework.beans.factory.annotation.Autowired;
@ -69,6 +71,10 @@ public class InvoiceServiceImpl implements InvoiceService {
private CommonValidation comm = new CommonValidation ();
private CommonUtils untils=new CommonUtils();
public InvoiceServiceImpl() {
}
/**
* 创建入库单
* @param eventInfo
@ -3344,21 +3350,40 @@ public class InvoiceServiceImpl implements InvoiceService {
setEventInfo.setUserColumns(hashMapPack);
MaterialPackingServiceProxy.getMaterialPackingService().setEvent(mpKeyList, makeEventInfo, setEventInfo);
//抛送MES数据
untils.sendMaterialInfoToMES_NEW2(shipRequestName, "", materialPackingKeyList,billCode,eventUser);
Boolean success = untils.sendMaterialInfoToMES_NEW2(shipRequestName, "", materialPackingKeyList,billCode,eventUser);
if (!success) {
String undo = cancelShipInter(billCode, eventUser);
if (undo == null || undo.isEmpty()) {
throw new GlobalException("下发mes失败后冲销失败");
}
throw new GlobalException("发送到mes失败");
}
WlySaveUnDoInfo( billCode,commitDate);
}
else
{
// billCode=toSAPService.ProductionStockOut_NEW(shipRequestName, "SDK", eventUser,materialPackingKeyList);
billCode=ProductionStockOut_NEW(shipRequestName, "SDK", eventUser,materialPackingKeyList,commitDate);
if (billCode.isEmpty()) {
throw new CustomException("SAP过账异常");
}
// billCode=toSAPService.ProductionStockOut_NEW(shipRequestName, "SDK", eventUser,materialPackingKeyList);
//
//抛送MES数据
untils.sendMaterialInfoToMES_NEW(shipRequestName, "", materialPackingKeyList,billCode,eventUser);
Boolean success = untils.sendMaterialInfoToMES_NEW(shipRequestName, "", materialPackingKeyList,billCode,eventUser);
//billCode = NCWServiceImpl.SaleOut2(shipRequestName, "SDK", eventUser,materialPackingKeyList,"");
// 如果mes发送失败则进行sap过账冲销
if (!success) {
String undo = cancelShipInter(billCode, eventUser);
if (undo == null || undo.isEmpty()) {
throw new GlobalException("下发mes失败后冲销失败");
}
throw new GlobalException("发送到mes失败");
}
untils.SaveUnDoInfo_ForSap(materialPackingKeyList, billCode, makeEventInfo);
}
}
@ -3368,7 +3393,17 @@ public class InvoiceServiceImpl implements InvoiceService {
// billCode=toSAPService.orderStockOut(shipRequestName, "SDK", eventUser,materialPackingKeyList);
billCode=orderStockOut(shipRequestName, "SDK", eventUser,materialPackingKeyList,commitDate);
//抛送MES数据
untils.sendMaterialInfoToMES_NEW(shipRequestName, "", materialPackingKeyList,billCode,eventUser);
Boolean success = untils.sendMaterialInfoToMES_NEW(shipRequestName, "", materialPackingKeyList,billCode,eventUser);
if (!success) {
String undo = cancelShipInter(billCode, eventUser);
if (undo == null || undo.isEmpty()) {
throw new GlobalException("下发mes失败后冲销失败");
}
throw new GlobalException("发送到mes失败");
}
//更新MES管芯数据
new MESServiceImpl().updateDurable_ByCostcenter(shipRequestName, "SDK", eventUser, materialPackingKeyList);
//billCode = NCWServiceImpl.SaleOut2(shipRequestName, "SDK", eventUser,materialPackingKeyList,"");
@ -3408,4 +3443,127 @@ public class InvoiceServiceImpl implements InvoiceService {
}
return billCode;
}
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.materilUndoUrl, "",
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)) {
String MBLNR1 = returnJsonObject.get("MBLNR1") == null ? "" : returnJsonObject.get("MBLNR1").toString();
String MJAHR1 = returnJsonObject.get("MJAHR1") == null ? "" : returnJsonObject.get("MJAHR1").toString();
undoId2 = MBLNR1+"_"+MJAHR1;//将物料凭证号与凭证年度拼在一起
}
} 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("WmsToSAP");
erplog.setEventName("冲销");
erplog.setInterfaceTime(TimeStampUtil.getCurrentTime(TimeStampUtil.FORMAT_DEFAULT));
// erplog.setMessageId(undoId);
erplog.setMessageId(undoId);
erplog.setSendMsg(makeFGStockIn);
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 matailInReverse(String user, String undoId) throws JsonMappingException, JsonProcessingException {
// if (list == null || list.size() < 1) {
// return "";
// }
//
// Map<String,Object> bodyData = new HashMap<>();
// List<Map<String,Object>> itemsData = new ArrayList<>();
//
// for (Map<String, Object> mm : list) {
// Map<String,Object> 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);
String[] parts = undoId.split("_");
String MBLNR = parts[0];
String MJAHR = parts[1];
String uniqueID = UUID.randomUUID().toString();
JSONObject MainData = new JSONObject(true);
Map<String,String> headJSonData = new HashMap<>();
Map<String,String> bodyJSonData = new HashMap<>();
MainData.put("HEAD",headJSonData);
MainData.put("BODY",bodyJSonData);
headJSonData.put("INTF_ID","MM068");
headJSonData.put("SRC_SYSTEM","WMS");
headJSonData.put("DEST_SYSTEM","SAP");
headJSonData.put("SRC_MSGID",uniqueID);
headJSonData.put("BACKUP1","");
headJSonData.put("BACKUP2","");
bodyJSonData.put("MBLNR", MBLNR);
bodyJSonData.put("MJAHR", MJAHR);
//过账日期
bodyJSonData.put("BUDAT", "20250430");
//凭证日期
bodyJSonData.put("BLDAT", "20250430");
String sendData = MainData.toJSONString();
return sendData;
}
}

View File

@ -673,7 +673,7 @@ public void SaveUnDoInfo_ForSap(List<String> list, String undoid, EventInfo mak
* @param receiveActNo 收货活动编号用于指定收货活动
* @param boxList 箱号列表包含所有需要发送的物料箱号
*/
public void sendMaterialInfoToMES_NEW(String invoiceNo,String receiveActNo,List<String> boxList,String billCode,String user){
public Boolean sendMaterialInfoToMES_NEW(String invoiceNo,String receiveActNo,List<String> boxList,String billCode,String user){
// 定义SQL查询语句用于获取物料接收位置和接收工厂信息
String sql="SELECT m.ERPRECEIVELOCATION,m.ERPRECEIVEFACTORY FROM MATERIALSHIPREQUEST a,MATERIALSHIPREQUESTDETAIL m \r\n" +
" WHERE m.SHIPREQUESTNAME =:SHIPREQUESTNAME and m.SHIPREQUESTNAME=a.SHIPREQUESTNAME "
@ -681,6 +681,7 @@ public void SaveUnDoInfo_ForSap(List<String> list, String undoid, EventInfo mak
// 创建参数映射用于执行SQL查询
Map<String, Object> bp=new HashMap<>();
bp.put("SHIPREQUESTNAME", invoiceNo);
Boolean success = true;
try {
// 执行SQL查询获取查询结果列表
List<Map<String, Object>> sr=IDMFrameServiceProxy.getSqlTemplate().queryForList(sql, bp);
@ -690,27 +691,20 @@ public void SaveUnDoInfo_ForSap(List<String> list, String undoid, EventInfo mak
// 创建MESServiceImpl实例用于调用发送物料信息到MES系统的方法
MESServiceImpl mesService=new MESServiceImpl() ;
// 调用MESServiceImpl的OutMaterialInfoSend_NEW方法发送物料信息到MES系统
String code = mesService.OutMaterialInfoSend_NEW(invoiceNo, "SDK", receiveActNo, "",
success = mesService.OutMaterialInfoSend_NEW(invoiceNo, "SDK", receiveActNo, "",
sr.get(0).get("ERPRECEIVELOCATION")==null?"":sr.get(0).get("ERPRECEIVELOCATION").toString()
,sr.get(0).get("ERPRECEIVEFACTORY")==null?"":sr.get(0).get("ERPRECEIVEFACTORY").toString(),boxList );
if("1".equals(code)) {
String undo = toSAPService.cancelShipInter(billCode, user);
if (undo == null ) {
throw new GlobalException("报送ERP失败,请联系IT处理");
}
}
}
} catch (CustomException e) {
// 异常处理打印异常堆栈跟踪信息
e.printStackTrace();
} catch (Exception e) {
throw new RuntimeException(e);
}
return success;
}
public void sendMaterialInfoToMES_NEW2(String invoiceNo,String receiveActNo,List<String> boxList, String billCode, String user){
public Boolean sendMaterialInfoToMES_NEW2(String invoiceNo,String receiveActNo,List<String> boxList, String billCode, String user){
// 定义SQL查询语句用于获取物料接收位置和接收工厂信息
String sql="SELECT m.ERPRECEIVELOCATION,m.ERPRECEIVEFACTORY FROM MATERIALSHIPREQUEST a,MATERIALSHIPREQUESTDETAIL m \r\n" +
" WHERE m.SHIPREQUESTNAME =:SHIPREQUESTNAME and m.SHIPREQUESTNAME=a.SHIPREQUESTNAME "
@ -718,6 +712,7 @@ public void SaveUnDoInfo_ForSap(List<String> list, String undoid, EventInfo mak
// 创建参数映射用于执行SQL查询
Map<String, Object> bp=new HashMap<>();
bp.put("SHIPREQUESTNAME", invoiceNo);
Boolean success = true;
try {
// 执行SQL查询获取查询结果列表
List<Map<String, Object>> sr=IDMFrameServiceProxy.getSqlTemplate().queryForList(sql, bp);
@ -727,23 +722,16 @@ public void SaveUnDoInfo_ForSap(List<String> list, String undoid, EventInfo mak
// 创建MESServiceImpl实例用于调用发送物料信息到MES系统的方法
MESServiceImpl mesService=new MESServiceImpl() ;
// 调用MESServiceImpl的OutMaterialInfoSend_NEW方法发送物料信息到MES系统
String code = mesService.OutMaterialInfoSend_NEW2(invoiceNo, "SDK", receiveActNo, "",
success = mesService.OutMaterialInfoSend_NEW2(invoiceNo, "SDK", receiveActNo, "",
sr.get(0).get("ERPRECEIVELOCATION")==null?"":sr.get(0).get("ERPRECEIVELOCATION").toString()
,sr.get(0).get("ERPRECEIVEFACTORY")==null?"":sr.get(0).get("ERPRECEIVEFACTORY").toString(),boxList );
if("1".equals(code)) {
String undo = toSAPService.cancelShipInter(billCode, user);
if (undo == null ) {
throw new GlobalException("报送ERP失败,请联系IT处理");
}
}
}
} catch (CustomException e) {
// 异常处理打印异常堆栈跟踪信息
e.printStackTrace();
} catch (Exception e) {
throw new RuntimeException(e);
}
return success;
}
/**
@ -860,9 +848,13 @@ public void SaveUnDoInfo_ForSap(List<String> list, String undoid, EventInfo mak
,sr.get(0).get("ERPRECEIVEFACTORY")==null?"":sr.get(0).get("ERPRECEIVEFACTORY").toString(),boxList );
*/
mesService.sendMESAndInsertMaterialPackingMDC(invoiceNo, "SDK", receiveActNo, "",
String code = mesService.sendMESAndInsertMaterialPackingMDC(invoiceNo, "SDK", receiveActNo, "",
sr.get(0).get("ERPRECEIVELOCATION")==null?"":sr.get(0).get("ERPRECEIVELOCATION").toString()
,sr.get(0).get("ERPRECEIVEFACTORY")==null?"":sr.get(0).get("ERPRECEIVEFACTORY").toString(),boxList );
if("1".equals(code)) {
throw new GlobalException("下发到mes失败");
}
}
} catch (CustomException e) {
// 异常处理打印异常堆栈跟踪信息