fix:添加调拨出库、销售发货冲销

This commit is contained in:
郭飞 2025-05-22 15:03:59 +08:00
parent e84fc2f3f9
commit e873887b32
10 changed files with 186 additions and 10 deletions

View File

@ -137,6 +137,8 @@ public class MaterialPacking extends FieldAccessor implements DataInfo<MaterialP
private String saleShipRequestName; // 销售订单号
private String saleShipRequestDetailName; // 销售订单号行项
private String split; // 是否是拆分
public String getLastHoldUser() {
return lastHoldUser;
}
@ -1030,6 +1032,14 @@ public class MaterialPacking extends FieldAccessor implements DataInfo<MaterialP
this.saleShipRequestDetailName = saleShipRequestDetailName;
}
public String getSplit() {
return split;
}
public void setSplit(String split) {
this.split = split;
}
public static class Field {
public static final String messageID = "messageId";
}

View File

@ -347,6 +347,153 @@ public class ToSAPServiceImpl {
return undoId;
}
// 调拨出库销售出库冲销过账
public String outOrderChancel(String shipRequestName, String siteName, String user,List<String> boxList,String commitDate) throws Exception {
String rcode;
String undoId = "";
String key01 = "";
String rmsg = null;
String sql=" SELECT \r\n" +
" count(*) AS ZROL, \r\n" +
" m1.SHIPREQUESTDETAILNAME , \r\n" +
" t.ERPLOCATION, \r\n" +
" sum(m.QTY)MATERIALQUANTITY \r\n" +
" FROM \r\n" +
" MATERIALPACKINGSUB m \r\n" +
" LEFT JOIN MATERIALPACKING T ON \r\n" +
" m.MATERIALPACKINGNAME = T.MATERIALPACKINGNAME AND m.RECEIVEREQUESTNAME = T.SHIPREQUESTNAME \r\n" +
" LEFT JOIN MATERIALSHIPREQUESTDETAIL M1 \r\n" +
" ON \r\n" +
" m.RECEIVEREQUESTNAME = M1.SHIPREQUESTNAME \r\n" +
" AND m.RECEIVEREQUESTDETAILNAME = M1.SHIPREQUESTDETAILNAME \r\n" +
" LEFT JOIN MATERIALSHIPREQUEST M2 \r\n" +
" ON \r\n" +
" M1.SHIPREQUESTNAME = M2.SHIPREQUESTNAME \r\n" +
" WHERE \r\n" +
" T.SHIPREQUESTNAME = :SHIPREQUESTNAME \r\n" +
" AND T.SITENAME = :SITENAME \r\n" +
" AND T.STOCKSTATE = 'StockOut' AND T.MATERIALPACKINGNAME IN (:BOXLIST)\r\n" +
" GROUP BY m1.SHIPREQUESTDETAILNAME , t.ERPLOCATION";
Map<String, Object> hashMap = new HashMap<String, Object>();
hashMap.put("SHIPREQUESTNAME", shipRequestName);
hashMap.put("SITENAME", siteName);
hashMap.put("BOXLIST", boxList);
List<Map<String, Object>> queryForList = IDMFrameServiceProxy.getSqlTemplate().queryForList(sql.toString(), hashMap);
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("DEST_SYSTEM", "SAP");
header.put("INTF_ID", "SD023");
header.put("SRC_SYSTEM", "WMS");
String uniqueID = UUID.randomUUID().toString();
header.put("SRC_MSGID", uniqueID);
header.put("BACKUP1", uniqueID);
header.put("BACKUP2", uniqueID);
/*
BODY
*/
//交货单号
body.put("VBELN", shipRequestName);
SimpleDateFormat inputFormat = new SimpleDateFormat("yyyy-MM-dd");
SimpleDateFormat outputFormat = new SimpleDateFormat("yyyyMMdd");
Date date = inputFormat.parse(commitDate);
String outputDate = outputFormat.format(date);
//实际过账日期
body.put("WADAT_IST", outputDate);//yyyyMMddhhmmss
//发送日期
body.put("Z_SENDDATE", outputDate);
//操作类型过账 1过账 2冲销
body.put("Z_OPTION", "2");
if (queryForList.size() >= 1) {
for (Map<String, Object> mm : queryForList) {
JSONObject item = new JSONObject(true);
//交货单行号
item.put("POSNR", mm.get("SHIPREQUESTDETAILNAME"));
//交货数量
item.put("PIKMG", mm.get("MATERIALQUANTITY"));
//库存地点
item.put("LGORT", mm.get("ERPLOCATION"));
//实际发货卷数
item.put("Z_ROL", mm.get("ZROL"));
//实际发货平方米
item.put("Z_SQUE", mm.get("MATERIALQUANTITY"));
itemArray.add(item);
}
body.put("ITEMS", itemArray);
}else {
for (Map<String, Object> mm : queryForList) {
//交货单行号
body.put("POSNR", mm.get("SHIPREQUESTDETAILNAME"));
//交货数量
body.put("PIKMG", mm.get("MATERIALQUANTITY")); //SUM
//库存地点
body.put("LGORT", mm.get("ERPLOCATION"));
//实际发货卷数
body.put("Z_ROL", mm.get("ZROL")); //COUNT
//实际发货平方米
body.put("Z_SQUE", mm.get("MATERIALQUANTITY"));
}
}
// log.info("SendTOSAP >>>>" + sendData);
String sapreturn = toSAPMessageUtil.sendHttpPost(toSAPMessageUtil.DNUrl, "", sendData.toJSONString());
org.json.JSONObject receiveJsonObject = new org.json.JSONObject(sapreturn);
//销售交货单过账不返回物料凭证,且RETURN为JsonArray
org.json.JSONObject returnJsonObject = (org.json.JSONObject) receiveJsonObject.get("RETURN");
rcode = returnJsonObject.get("STATUS").toString();
rmsg = returnJsonObject.get("MSGTXT").toString();
key01 = returnJsonObject.get("KEY01") == null ? "" : returnJsonObject.get("KEY01").toString(); // 返回单号后面用单号冲销
if ("S".equals(rcode)) {
if(key01.isEmpty()) {
undoId = "S";
}else {
undoId = key01;
}
}
//将log写到表里
ErpMessageLog erplog = new ErpMessageLog();
erplog.setEventUser(user);
erplog.setServerName("WmsToErp");
erplog.setEventName("调拨出库和销售出库冲销");
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返回" + rmsg);
}
if (!"S".equals(rcode)) {
throw new RuntimeException("SAP返回" + rmsg);
}
return undoId;
}
// 取消物料入库凭证冲销
public String cancelShipInter(String undoId, String user) throws Exception {

View File

@ -62,7 +62,7 @@ public class MESToWMSController {
}
}
@ApiOperation(value = "取消物料入库请求")
@ApiOperation(value = "物料冲销接口请求")
@RequestMapping(value = "/meswms_cancelship_request", method = RequestMethod.POST)
public AjaxResult cancelShipByMES(@RequestBody JSONArray in) {
log.info("Received cancel ship request: {}", in.toJSONString());

View File

@ -37,6 +37,7 @@ public class MaterialUndoController {
String flag = undoDto.getFlag();
String inv_TYPE = undoDto.getINV_TYPE();
String lastEventName = undoDto.getLastEventName();
String commitDate = undoDto.getCommitDate();
//根据物料凭证校验物料状态是否一致
try {
Boolean checkUndoCondition = untils.CheckUndoCondition(undoId);
@ -74,7 +75,7 @@ public class MaterialUndoController {
}else if(inv_TYPE.contains("ZK")) { // 转库
materialUndoServiceImpl.zkUndo(undoId, userId);
}else if(inv_TYPE.contains("NLCC") && lastEventName.contains("调拨出库")) { // 调拨出库
materialUndoServiceImpl.orderUndo(undoId, userId);
materialUndoServiceImpl.orderUndo(undoId, userId,commitDate);
}else {
return AjaxResult.me().setSuccess(false).setMessage("单据类型不支持冲销");
}

View File

@ -1,12 +1,15 @@
package com.cim.idm.dao;
import com.cim.idm.framework.IDMFrameServiceProxy;
import com.cim.idm.wmspackage.materialpacking.management.data.MaterialPacking;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Component;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Component
@Mapper
@ -14,6 +17,10 @@ public interface MaterialReversalDao {
//更新冲销凭证为已冲销
public static void updateReversalUnDoId(@Param("undoId") String undoId) throws Exception {
// String sql = "UPDATE IF_ERPUNDO T SET T.FLAG = 'Y' WHERE T.UNDOID = :UNDOID ";
String sql = "UPDATE BS_MATERIALPACKINGUNDOINFO T SET T.FLAG = 'Y' WHERE T.UNDOID = :UNDOID ";
Map<String, Object> hashMap2 = new HashMap<String, Object>();
hashMap2.put("UNDOID", undoId);
IDMFrameServiceProxy.getSqlTemplate().update(sql, hashMap2);
}
}

View File

@ -14,5 +14,6 @@ public class MaterialUndoDto {
private String userId;
private String lastEventName;
private String commitDate;
}

View File

@ -801,6 +801,7 @@ public class InvoiceServiceImpl implements InvoiceService {
bindMap.put("WEIGHT", WEIGHT);
bindMap.put("DIAMETER", DIAMETER);
bindMap.put("shelfName", shelfName);
bindMap.put("split", "Y");
createInfo1.setUserColumns(bindMap);
MaterialPackingServiceProxy.getMaterialPackingService().create(makeEventInfo, createInfo1);

View File

@ -1153,7 +1153,7 @@ public class MaterialShipServiceImpl implements IMaterialShipService {
}
//将log写到表里
ErpMessageLog erplog = new ErpMessageLog();
erplog.setEventUser("");
erplog.setEventUser(user);
erplog.setServerName("WmsToErp");
erplog.setEventName("辅材出库-调拨出库(NLCC)");
erplog.setInterfaceTime(TimeStampUtil.getCurrentTime(TimeStampUtil.FORMAT_DEFAULT));

View File

@ -18,6 +18,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@ -263,18 +264,24 @@ public class MaterialUndoServiceImpl implements IMaterialUndoService {
}
@Transactional
public void orderUndo (String undoId, String user) throws Exception {
public void orderUndo (String undoId, String user, String commitDate) throws Exception {
String billCode = toSAPService.cancelShipInter(undoId, user);
if (billCode == null) {
throw new GlobalException("报送ERP失败,请联系IT处理");
}
List<String> materialPackingKeyList = new ArrayList<>();
EventInfo makeEventInfo = new EventInfoUtil ().makeEventInfo("MakeUndo", user, "MakeUndo");
String condition="WHERE UNDOID =? ";
String[] bindSet={undoId};
//根据物料凭证找到所有的待冲销数据更新库存状态为创建
List<MaterialPacking> list = MaterialPackingServiceProxy.getMaterialPackingService().select(condition, bindSet);
for (int i = 0; i < list.size(); ++ i) {
String materialPackingName = list.get(i).getMaterialPackingName();
materialPackingKeyList.add(materialPackingName);
}
String billCode = toSAPService.outOrderChancel(undoId, "SKD",user, materialPackingKeyList,commitDate);
if (billCode == null) {
throw new GlobalException("报送ERP失败,请联系IT处理");
}
Map<String, Object> hashMap = new HashMap<String, Object> ();
hashMap.put("stockState", "Stocked");
hashMap.put("shipRequestName", "");

View File

@ -99,6 +99,8 @@ public class CodeGenerator {
Collections.sort(chargeNoList);
int max = Integer.parseInt(chargeNoList.get(chargeNoList.size() - 1));
sequence = max + 1;
} else if (Charge.isEmpty()) {
}
// 3. 遍历结果集生成新条码并更新数据库