添加 报废

This commit is contained in:
郭飞 2025-05-12 17:44:37 +08:00
parent 8e29bdb184
commit 42f52b9c4e
7 changed files with 187 additions and 24 deletions

View File

@ -22,6 +22,8 @@ public class CustomException extends Exception
* @uml.associationEnd
*/
public ErrorDef errorDef;
private String errorCode;
private static Log log = LogFactory.getLog(CustomException.class);
@ -171,4 +173,13 @@ public class CustomException extends Exception
// TODO Auto-generated constructor stub
}
public CustomException(String errorCode, String message) {
super(message); // 重要必须传递 message 给父类
this.errorCode = errorCode;
}
public String getErrorCode() {
return errorCode;
}
}

View File

@ -4957,7 +4957,7 @@ public class ToSAPServiceImpl {
}
//物料报废/降级品出库 (Z07)
public String MaterialScrapStockOut(List<MaterialPackingKey> all, String siteName, String user) throws Exception {
public String MaterialScrapStockOut(List<MaterialPackingKey> all, String siteName, String user,String commitDate,String opCode) throws Exception {
String rcode;
String undoId = "";
String rmsg = null;
@ -5013,10 +5013,15 @@ public class ToSAPServiceImpl {
*/
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", TimeStampUtil.getCurrentTime("yyyyMMdd"));
body.put("BUDAT", outputDate);
//凭证日期
body.put("BLDAT", TimeStampUtil.getCurrentTime("yyyyMMdd"));
body.put("BLDAT", outputDate);
//凭证抬头文本
body.put("BKTXT", uniqueID);
//用户名
@ -5759,7 +5764,106 @@ public class ToSAPServiceImpl {
}
public String qtcrNoInvoiceForCheckPlan(List<Map<String, Object>> srPk, String qtc, String user, String commitDate, String opCode) {
return "";
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", 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", TimeStampUtil.getCurrentTime("yyyyMMdd"));
//凭证日期
body.put("BLDAT", TimeStampUtil.getCurrentTime("yyyyMMdd"));
//凭证抬头文本
body.put("BKTXT", uniqueID);
//用户名
body.put("USNAM", user);
for (Map<String, Object> auditBox : srPk) {
JSONObject item = new JSONObject(true);
//BWART 移动类型 Z05盘亏, Z06盘盈(入口条件)
// if(auditBox.getMaterialQuantity() > 0) {
if ("qtr".equals(qtc)){
item.put("BWART", "Z06");
}else {
item.put("BWART", "Z05");
}
// MATNR 发货物料号
item.put("MATNR", auditBox.get("MaterialSpecName"));
// WERKS 发货工厂
item.put("WERKS", auditBox.get("ERPFACTORY"));
// LGORT 发货库存地点
item.put("LGORT", auditBox.get("SYSLOCATION"));
//MENGE 数量
item.put("MENGE", auditBox.get("MATERIALQUANTITY"));
//MENGE 单位
item.put("MEINS", auditBox.get("UNIT"));
//KOSTL 成本中心
// item.put("KOSTL", auditBox.get("CostCenterName"));
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写到表里
ErpMessageLog erplog = new ErpMessageLog();
erplog.setEventUser("");
erplog.setServerName("WmsToErp");
erplog.setEventName("盘点");
erplog.setInterfaceTime(TimeStampUtil.getCurrentTime(TimeStampUtil.FORMAT_DEFAULT));
erplog.setMessageId(UUID.randomUUID().toString());
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 StockOutByOrder(List<com.cim.idm.data.changeOrder.changeOrderDto> materialPackingList, String mes) {{

View File

@ -140,7 +140,7 @@ public class CheckMarkController {
bindMap.put("ERPLOCATION", erpLocation);
//查找盘亏的批次
String sql_pk = " SELECT a.*,ABS(DifferenceQuantity)NUM FROM (\r\n" +
" SELECT c.MATERIALPACKINGNAME,c.MATERIALSPECNAME,c.ERPLOCATION,c.SYSLOCATION,m.ERPFACTORY,\r\n" +
" SELECT c.MATERIALPACKINGNAME,c.MATERIALSPECNAME,m.UNIT,c.ERPLOCATION,c.SYSLOCATION,m.ERPFACTORY,\r\n" +
" NVL( c.MATERIALQUANTITY,0) AS MATERIALQUANTITY,NVL(c2.MATERIALQUANTITY, 0) AS MATERIALACTQUANTITY, \r\n" +
" (NVL(c2.MATERIALQUANTITY, 0) -c.MATERIALQUANTITY) AS DifferenceQuantity,c.CHECKPLATATE,c.CHECKPLANSTATE,\r\n" +
" m.CHARGE ,m.SDK_ID ,m.PHASE ,TO_CHAR(m.EXPIRINGDATE, 'YYYY-MM-DD HH24:MI:SS') expdate,\r\n" +
@ -154,7 +154,7 @@ public class CheckMarkController {
List<Map<String, Object>> sr_pk = IDMFrameServiceProxy.getSqlTemplate().queryForList(sql_pk, bindMap);
if(sr_pk.size()>0)
{
//调用NC接口
//调用SAP接口
billCode=toSAPServiceImpl.qtcrNoInvoiceForCheckPlan(sr_pk, "qtc", user, commitDate,opCode);
//更新盘点计划状态
String sql = "UPDATE CHECKPLAN c SET CHECKPLANSTATE = 'Approved' WHERE PLANDATE = :PLANDATE AND CHECKPLANNAME = :CHECKPLANNAME AND ERPLOCATION=:ERPLOCATION";
@ -212,7 +212,7 @@ public class CheckMarkController {
" WHERE DifferenceQuantity>0 AND nvl(CHECKPLATATE,'是')='是' AND nvl(CHECKPLANSTATE,'N')<>'Approved' ";
List<Map<String, Object>> sr_pk = IDMFrameServiceProxy.getSqlTemplate().queryForList(sql_py, bindMap);
if (sr_pk.size() > 0) {
// 调用NC接口
// 调用SAP接口
billCode = toSAPServiceImpl.qtcrNoInvoiceForCheckPlan(sr_pk, "qtr", user, commitDate,opCode);
// 更新盘点计划状态
String sql = "UPDATE CHECKRECORD c SET CHECKPLANSTATE = 'Approved' WHERE PLANDATE = :PLANDATE AND CHECKPLANNAME = :CHECKPLANNAME AND ERPLOCATION=:ERPLOCATION";

View File

@ -257,7 +257,7 @@ public class NoChargeStockIn {
Map<String,Object> args = new HashMap<>();
billcode = toSAPServiceImpl.PurStockIn(request.getReceiveRequestName(), siteName, user, args,commitDate);
}else {
billcode = toSAPServiceImpl.SaleReturn(request.getReceiveRequestName(), siteName, user, commitDate, opCode);
}
// @TODO 其他类型
if (billcode == null || "".equals(billcode)) {

View File

@ -9,11 +9,19 @@ import java.util.List;
import java.util.Map;
import java.util.Objects;
import com.cim.idm.constants.receive.ReceiveTypeEnums;
import com.cim.idm.exception.GlobalException;
import com.cim.idm.framework.data.EventInfo;
import com.cim.idm.model.po.MaterialReceiveRequest;
import com.cim.idm.model.ShelfDto;
import com.cim.idm.service.Impl.SDKMaterialPackingServiceImpl;
import com.cim.idm.service.impl.ToSAPServiceImpl;
import com.cim.idm.utils.AjaxResult;
import com.cim.idm.utils.CommonUtils;
import com.cim.idm.utils.EventInfoUtil;
import com.cim.idm.wmspackage.materialpacking.MaterialPackingServiceProxy;
import com.cim.idm.wmspackage.materialpacking.management.data.MaterialPackingKey;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
@ -38,6 +46,14 @@ public class NoInvoiceManagerContoller {
// @Autowired
// NoInvoiceManagerServiceImpl NoInvoiceManagerServiceImpl;
@Autowired
private ToSAPServiceImpl toSAPService;
private EventInfo makeEventInfo;
@Autowired
private com.cim.idm.service.Impl.SDKMaterialPackingServiceImpl SDKMaterialPackingServiceImpl;
CommonUtils untils=new CommonUtils();
/**
* 获取其他待入集合
@ -123,14 +139,17 @@ public class NoInvoiceManagerContoller {
" CASE\r\n" +
" WHEN M.MATURATIONINTIME IS NOT NULL THEN SYSDATE - M.MATURATIONINTIME - m2.MATURATIONTIME\r\n" +
" ELSE 1\r\n" +
" END FLAG\r\n" +
" END FLAG,\r\n" +
" bsn.DESCRIPTION\r\n" +
"FROM\r\n" +
" MATERIALPACKING M\r\n" +
"LEFT JOIN MATERIALSPEC m2 ON\r\n" +
" M.MATERIALSPECNAME = m2.MATERIALSPECNAME\r\n" +
"LEFT JOIN BS_ERPLOCATION bsn ON\r\n" +
" bsn.ERPLOCATIONNAME = M.ERPLOCATION\r\n" +
"WHERE\r\n" +
" M.STOCKSTATE = 'Stocked'\r\n" +
" AND M.MATERIALPACKINGNAME = :MATERIALPACKINGNAME ";
" AND M.MATERIALPACKINGNAME = :MATERIALPACKINGNAME";
Map<String, Object> bindMap = new HashMap<String, Object>();
bindMap.put("MATERIALPACKINGNAME", materialPacking.getMaterialPackingName());
@ -140,21 +159,26 @@ public class NoInvoiceManagerContoller {
throw new GlobalException("未找到对应的数据!");
}
if(!Objects.isNull(list) && !list.isEmpty()) {
String string = list.get(0).get("FLAG").toString();
float parseFloat = Float.parseFloat(string);
float abs = Math.abs(parseFloat);
if (parseFloat < 0) {
throw new GlobalException("还差" + abs + "天才能熟化出库!");
}
// if(!Objects.isNull(list) && !list.isEmpty()) {
// String string = list.get(0).get("FLAG").toString();
// float parseFloat = Float.parseFloat(string);
// float abs = Math.abs(parseFloat);
// if (parseFloat < 0) {
// throw new GlobalException("还差" + abs + "天才能熟化出库!");
// }
// }
String description = list.get(0).get("DESCRIPTION") == null ? "" : list.get(0).get("DESCRIPTION").toString();
if(!description.contains("半成品-B")) {
throw new GlobalException("该产品不是报废材料,不允许出库!");
}
// 过账Z07
return AjaxResult.me().setResultObj(list);
}
/**
* 其他出提交
* 报废出提交
* @param in
* @return
*/
@ -169,10 +193,30 @@ public class NoInvoiceManagerContoller {
String commitDatesString = sl.getCommitDate();
String commitDate = commitDatesString + " 00:00:00";
String opCode = sl.getOpCode();
// MaterialPacking selectByKey = MaterialPackingServiceProxy.getMaterialPackingService().selectByKey(new MaterialPackingKey("SDK", "311110026|1|C|75mm*1000m|3111100268001421|20230524|11|75"));
// ArrayList<MaterialPacking> arrayList = new ArrayList<>();
// arrayList.add(selectByKey);
// NoInvoiceManagerServiceImpl.QTC(boxList,user,siteName,commitDate,opCode);
ArrayList<MaterialPackingKey> arrayList = new ArrayList<>();
for(MaterialPacking map : boxList) {
// String supplierCharge = map.get("SUPPLIERCHARGE") == null ? "" : map.get("SUPPLIERCHARGE").toString();
MaterialPackingKey MaterialPackingKey = new MaterialPackingKey("SDK", map.getMaterialPackingName());
arrayList.add(MaterialPackingKey);
}
String undoId = "";
try {
// NoInvoiceManagerServiceImpl.QTC(boxList,user,siteName,commitDate,opCode);
undoId = toSAPService.MaterialScrapStockOut(arrayList,siteName,user,commitDate,opCode);
} catch (Exception e) {
e.printStackTrace();
return AjaxResult.me().setSuccess(false).setMessage(e.toString());
}
// 发送过账
EventInfoUtil util = new EventInfoUtil();
makeEventInfo = util.makeEventInfo("报废出库", user, "报废出库");
// 更新库存状态
SDKMaterialPackingServiceImpl.SaveUnDoInfo( undoId,commitDate);
// SDKMaterialPackingServiceImpl.updateStockState( makeEventInfo, undoId,opCode);
// 更新入库凭证和库存状态
SDKMaterialPackingServiceImpl.updateUndoIdByList(boxList, undoId, makeEventInfo,opCode);
return AjaxResult.me().setResultObj(null);

View File

@ -2148,7 +2148,7 @@ public class SAPToWMSController {
try {
ArrayList<Map<String,Object>> datas = request.getBODY();
String sitename = System.getProperty("company");
String sitename = "SDK";
for (Map<String, Object> data : datas) {
String shipRequestName = MapUtils.getString(data, "ZDNUM"); // 生产单据编号
String shipRequestDetailName = MapUtils.getString(data, "ZITEM"); // 单据行号
@ -2211,6 +2211,7 @@ public class SAPToWMSController {
IDMFrameServiceProxy.getTransactionManager().rollbackTransaction();
Map<String, Object> errorReturn = new HashMap<>();
errorReturn.put("STATUS", "E");
log.error("发生异常:{}", e.getMessage(), e); // 完整
errorReturn.put("MSGTXT", "生产单据关闭失败" + e.getMessage());
// errorReturn.put("HEAD", request.getHEAD());
//errorReturn.put("BODY", request.getBODY());

View File

@ -365,11 +365,14 @@ public class SDKMaterialPackingServiceImpl extends CommonServiceDAO<MaterialPack
}
public void updateUndoIdByList (List<MaterialPacking> list,String UNDOID,EventInfo eventInfo) {
public void updateUndoIdByList (List<MaterialPacking> list,String UNDOID,EventInfo eventInfo, String opCode) {
for (MaterialPacking mp : list) {
SetEventInfo setEventInfo = new SetEventInfo();
Map<String, Object> bindMap = new HashMap<String, Object>();
bindMap.put("unDoID",UNDOID);
bindMap.put("packingState","Released");
bindMap.put("stockState","StockOut");
bindMap.put("messageId",opCode);
setEventInfo.setUserColumns(bindMap);
MaterialPackingKey materialPackingKey = new MaterialPackingKey("SDK", mp.getMaterialPackingName().toString());
MaterialPackingServiceProxy.getMaterialPackingService().setEvent(materialPackingKey, eventInfo, setEventInfo);