辅材盘盈盘亏

This commit is contained in:
王帅 2025-05-28 10:06:01 +08:00
parent c813948dbe
commit b31a0876a0
3 changed files with 162 additions and 16 deletions

View File

@ -5425,6 +5425,116 @@ public class ToSAPServiceImpl {
return undoId; return undoId;
} }
//盘盈出库--pc
public String MaterialScrapStockOutPc(List<Map<String, Object>> queryForList, String siteName, String user,String commitDate,
String opCode,String qtc,String costName) throws Exception {
String rcode;
String undoId = "";
String rmsg = null;
if (queryForList == null || queryForList.size() < 1) {
return "";
}
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", user);
/*
BODY
*/
body.put("ITEM", itemArray);
body.put("ITEMID", uniqueID);
SimpleDateFormat inputFormat = new SimpleDateFormat("yyyy-MM-dd");
SimpleDateFormat outputFormat = new SimpleDateFormat("yyyyMMdd");
Date date = inputFormat.parse(commitDate);
String outputDate = outputFormat.format(date);
//过账日期
body.put("BUDAT", outputDate);
//凭证日期
body.put("BLDAT", outputDate);
//凭证抬头文本
body.put("BKTXT", uniqueID);
//用户名
body.put("USNAM", user);
for (Map<String, Object> mm : queryForList) {
JSONObject item = new JSONObject(true);
// MATNR 发货物料号
item.put("MATNR", mm.get("MATERIALSPECNAME"));
// WERKS 发货工厂
item.put("WERKS", mm.get("ERPFACTORY"));
// LGORT 发货库存地点
item.put("LGORT", mm.get("ERPLOCATION"));
//BWART 移动类型
item.put("BWART", qtc);
item.put("KOSTL", costName);
//MENGE 数量
item.put("MENGE", mm.get("MATERIALQUANTITY"));
//MENGE 单位
item.put("MEINS", mm.get("UNIT"));
//需要SAP改动Z07,Z08目前都需要返单号
//ZLLORDER 自定义领料单号
// item.put("ZLLORDER", mm.get("SHIPREQUESTNAME"));
// //ZLLITEM 自定义领料单行号
// item.put("ZLLITEM", mm.get("SHIPREQUESTDETAILNAME"));
itemArray.add(item);
}
log.info("SendTOSAP >>>>" + sendData);
String sapreturn = toSAPMessageUtil.sendHttpPost(toSAPMessageUtil.materialChangeLocationUrl, "", sendData.toJSONString());
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写到表里
UUID uuid = UUID.randomUUID();
ErpMessageLog erplog = new ErpMessageLog();
erplog.setEventUser("");
erplog.setServerName("WmsToErp");
if ("Z05".equals(qtc)) {
erplog.setEventName("盘亏出库");
} else {
erplog.setEventName("报废出库");
}
erplog.setId(uuid.toString());
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;
}
/** /**
* 退料入库 * 退料入库
* *
@ -5527,6 +5637,7 @@ public class ToSAPServiceImpl {
} }
public String makeReturnStockIn(List<Map<String, Object>> list, String eventUser, String commitDate) throws JsonMappingException, JsonProcessingException { public String makeReturnStockIn(List<Map<String, Object>> list, String eventUser, String commitDate) throws JsonMappingException, JsonProcessingException {
if (list == null || list.size() < 1) { if (list == null || list.size() < 1) {
return ""; return "";

View File

@ -7,6 +7,7 @@ import com.cim.idm.constants.delivery.DeliveryStateEnums;
import com.cim.idm.constants.receive.ReceiveTypeEnums; import com.cim.idm.constants.receive.ReceiveTypeEnums;
import com.cim.idm.framework.IDMFrameServiceProxy; import com.cim.idm.framework.IDMFrameServiceProxy;
import com.cim.idm.framework.data.EventInfo; import com.cim.idm.framework.data.EventInfo;
import com.cim.idm.model.MaterialReceiveParam;
import com.cim.idm.model.dto.AuxiliaryOutIn; import com.cim.idm.model.dto.AuxiliaryOutIn;
import com.cim.idm.model.dto.delivery.DeliveryEditDto; import com.cim.idm.model.dto.delivery.DeliveryEditDto;
import com.cim.idm.model.dto.delivery.StoreDetailDto; import com.cim.idm.model.dto.delivery.StoreDetailDto;
@ -33,6 +34,7 @@ import com.cim.idm.wmspackage.materialpacking.management.data.MaterialPackingKey
import com.cim.idm.wmspackage.materialpacking.management.info.CreateInfo; import com.cim.idm.wmspackage.materialpacking.management.info.CreateInfo;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.json.JSONArray;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
@ -350,7 +352,7 @@ public class MaterialReceiveActController {
String descCn = materialInfo.getDescCn(); String descCn = materialInfo.getDescCn();
List<String> boxIds = MaterialPackingServiceImpl.generateBoxID("LabelId", siteName, List<String> boxIds = MaterialPackingServiceImpl.generateBoxID("LabelId", siteName,
"1", DateUtil.now(), "WL", erpFactory); "1", DateUtil.now(), "WL", erpFactory);
//470110856|1|C|75mm*1000m|SHBP01JT1202305240009|20230524|11|75 //470110856|1||75mm*1000m|SHBP01JT1202305240009|20230524|11|75
String newBoxId = materialSpecName + "|1|" + "|" + width + "|" + boxIds.get(0) + "|" String newBoxId = materialSpecName + "|1|" + "|" + width + "|" + boxIds.get(0) + "|"
+ makeDate.replace("-", "").substring(0, 8) + "|" + materialUnit + "|" + nums; + makeDate.replace("-", "").substring(0, 8) + "|" + materialUnit + "|" + nums;
EventInfo makeEventInfo = new EventInfoUtil().makeEventInfo("TrackOutBox", user, "TrackOutBox"); EventInfo makeEventInfo = new EventInfoUtil().makeEventInfo("TrackOutBox", user, "TrackOutBox");
@ -381,7 +383,6 @@ public class MaterialReceiveActController {
List<HashMap<String, Object>> maps = costCenterService.getByMaterialPackingName(newBoxId); List<HashMap<String, Object>> maps = costCenterService.getByMaterialPackingName(newBoxId);
return AjaxResult.me().setResultObj(maps); return AjaxResult.me().setResultObj(maps);
} else { } else {
// todo
List<LinkedHashMap<String, Object>> maps = costCenterService.getMaterialPacking(materialSpecName,siteName,erpFactory, List<LinkedHashMap<String, Object>> maps = costCenterService.getMaterialPacking(materialSpecName,siteName,erpFactory,
erpLocation, location, nums); erpLocation, location, nums);
if (maps == null || maps.size() <= 0) { if (maps == null || maps.size() <= 0) {
@ -419,7 +420,6 @@ public class MaterialReceiveActController {
for (LinkedHashMap<String, Object> item : maps) { for (LinkedHashMap<String, Object> item : maps) {
// 获取当前记录的数量 // 获取当前记录的数量
Integer materialQuantity = Integer.parseInt(item.get("MATERIALQUANTITY").toString()); Integer materialQuantity = Integer.parseInt(item.get("MATERIALQUANTITY").toString());
// Integer materialQuantity = (Integer) item.get("MATERIALQUANTITY");
if (materialQuantity == null || materialQuantity <= 0 || remaining <= 0) { if (materialQuantity == null || materialQuantity <= 0 || remaining <= 0) {
continue; // 跳过无效或已满足的情况 continue; // 跳过无效或已满足的情况
} }
@ -437,12 +437,6 @@ public class MaterialReceiveActController {
// 更新剩余数量 // 更新剩余数量
remaining -= take; remaining -= take;
// 如果还有剩余但当前记录未完全使用可以在这里做拆分处理可选
if (remaining > 0 && materialQuantity > take) {
// 可以选择修改原列表中的数量如果需要保留原库存信息
// ((HashMap<String, Object>) item).put("materialQuantity", materialQuantity - take);
}
// 如果已经满足需求退出循环 // 如果已经满足需求退出循环
if (remaining == 0) { if (remaining == 0) {
break; break;
@ -483,9 +477,10 @@ public class MaterialReceiveActController {
@RequestMapping(value = "/QTCCommit", method = RequestMethod.POST) @RequestMapping(value = "/QTCCommit", method = RequestMethod.POST)
@Transactional @Transactional
public AjaxResult QTCCommit(@RequestBody JSONObject in ){ public AjaxResult QTCCommit(@RequestBody JSONObject in ){
// List<MaterialPacking> object = (List<MaterialPacking>) in.get("boxList");
MaterialReceiveRequest sl = JSON.toJavaObject(in, MaterialReceiveRequest.class); MaterialReceiveRequest sl = JSON.toJavaObject(in, MaterialReceiveRequest.class);
MaterialReceiveParam slParam = JSON.toJavaObject(in, MaterialReceiveParam.class);
List<MaterialPacking> boxList = sl.getBoxList(); List<MaterialPacking> boxList = sl.getBoxList();
List<Map<String, Object>> boxListParam = slParam.getBoxList();
String siteName = sl.getSiteName(); String siteName = sl.getSiteName();
String user = in.get("user").toString(); String user = in.get("user").toString();
String commitDatesString = sl.getCommitDate(); String commitDatesString = sl.getCommitDate();
@ -495,14 +490,9 @@ public class MaterialReceiveActController {
String qtc = sl.getQtc(); String qtc = sl.getQtc();
// 成本中心 // 成本中心
String costName = sl.getCostName(); String costName = sl.getCostName();
ArrayList<MaterialPackingKey> arrayList = new ArrayList<>();
for(MaterialPacking map : boxList) {
MaterialPackingKey MaterialPackingKey = new MaterialPackingKey("SDK", map.getMaterialPackingName());
arrayList.add(MaterialPackingKey);
}
String undoId = ""; String undoId = "";
try { try {
undoId = toSAPService.MaterialScrapStockOut(arrayList,siteName,user,commitDate,opCode,qtc,costName); undoId = toSAPService.MaterialScrapStockOutPc(boxListParam,siteName,user,commitDate,opCode,qtc,costName);
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
return AjaxResult.me().setSuccess(false).setMessage(e.toString()); return AjaxResult.me().setSuccess(false).setMessage(e.toString());

View File

@ -0,0 +1,45 @@
package com.cim.idm.model;
import lombok.Data;
import java.util.List;
import java.util.Map;
/**
* @Description
* @Author admin
* @Date 2025/5/28 9:32
*/
@Data
public class MaterialReceiveParam {
private String receiveRequestName;
private String siteName;
private String barCode;
private String user;
private String eventName;
private String receiveRequestType;
private String RECEIVEACTNO;
private String erpFactory;
private String erpLocation;
private String remark; //备注
private String commitDate;
private String opCode;
private String type;
private String STOCKORGNO;
private String MaterialPackingName;
private String materialSpecName;
private String materialQuantity;
private String materialQuantity2;
private String sdk_id;
private String phase;
private String CUSTOMNO;
private String truegg;
private String costName;
private String lifnr;
private String qtc;
/**销售订单*/
private String SALESHIPREQUESTNAME;
/**销售订单行号*/
private String SALESHIPREQUESTDETAILNAME;
private List<Map<String, Object>> boxList;
}