MES物料转工单
This commit is contained in:
parent
f5d105e40b
commit
d273cd1818
@ -0,0 +1,44 @@
|
||||
package com.cim.idm.data.changeOrder;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class changeOrderDto {
|
||||
// MATNR 发货物料号
|
||||
// item.put("MATNR", maps.get(i).get("MATERIALSPECNAME"));
|
||||
// // WERKS 发货工厂
|
||||
// item.put("WERKS", maps.get(i).get("ERPFACTORY"));
|
||||
// // LGORT 发货库存地点
|
||||
// item.put("LGORT", maps.get(i).get("ERPLOCATION"));
|
||||
// //MENGE 数量
|
||||
// item.put("MENGE", maps.get(i).get("QTY"));
|
||||
// //MENGE 单位
|
||||
// item.put("MEINS", maps.get(i).get("UNIT"));
|
||||
// // //KOSTL 成本中心
|
||||
// // item.put("KOSTL", mm.get("COSTCENTER"));
|
||||
// // //GRUND 移动原因 (201,202回传)
|
||||
// // item.put("GRUND", mm.get("SHIPREQUESTDETAILTYPE"));
|
||||
//
|
||||
// item.put("BWART", "261");
|
||||
// //ZLLORDER 自定义领料单号
|
||||
//// item.put("ZLLORDER", "LL1010250408001");
|
||||
// item.put("ZLLORDER", maps.get(i).get("SHIPREQUESTNAME"));
|
||||
// //ZLLITEM 自定义领料单行号
|
||||
//
|
||||
//// item.put("ZLLITEM", "0001");
|
||||
// item.put("ZLLITEM", maps.get(i).get("RESERVEDPROJECTNUMB"));
|
||||
// //AUFNR 订单号
|
||||
// item.put("AUFNR", maps.get(i).get("WO"));
|
||||
private String MATNR;
|
||||
private String WERKS;
|
||||
private String LGORT;
|
||||
private String MENGE;
|
||||
private String MEINS;
|
||||
private String KOSTL;
|
||||
private String GRUND;
|
||||
private String BWART;
|
||||
private String ZLLORDER;
|
||||
private String ZLLITEM;
|
||||
private String AUFNR;
|
||||
|
||||
}
|
@ -5676,4 +5676,116 @@ public class ToSAPServiceImpl {
|
||||
public String qtcrNoInvoiceForCheckPlan(List<Map<String, Object>> srPk, String qtc, String user, String commitDate, String opCode) {
|
||||
return "";
|
||||
}
|
||||
|
||||
public String StockOutByOrder(List<com.cim.idm.data.changeOrder.changeOrderDto> materialPackingList, String mes) {{
|
||||
|
||||
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", mes);
|
||||
|
||||
/*
|
||||
BODY
|
||||
*/
|
||||
body.put("ITEM", itemArray);
|
||||
body.put("ITEMID", uniqueID);
|
||||
//过账日期
|
||||
body.put("BUDAT", TimeStampUtil.getCurrentTime("yyyyMMdd"));
|
||||
//凭证日期
|
||||
body.put("BLDAT", TimeStampUtil.getCurrentTime("yyyyMMdd"));
|
||||
//凭证抬头文本
|
||||
body.put("BKTXT", uniqueID);
|
||||
//用户名
|
||||
body.put("USNAM", mes);
|
||||
|
||||
|
||||
if (materialPackingList == null || materialPackingList.size() < 1) {
|
||||
throw new RuntimeException("不存在需要发送的数据");
|
||||
}
|
||||
for (com.cim.idm.data.changeOrder.changeOrderDto mm : materialPackingList) {
|
||||
JSONObject item = new JSONObject(true);
|
||||
if(materialPackingList.size()>0) {
|
||||
// MATNR 发货物料号
|
||||
item.put("MATNR", mm.getMATNR());
|
||||
|
||||
// WERKS 发货工厂
|
||||
item.put("WERKS", mm.getWERKS());
|
||||
// LGORT 发货库存地点
|
||||
item.put("LGORT", mm.getLGORT());
|
||||
//MENGE 数量
|
||||
item.put("MENGE",mm.getMENGE());
|
||||
//MENGE 单位
|
||||
item.put("MEINS",mm.getMEINS());
|
||||
// //KOSTL 成本中心
|
||||
// item.put("KOSTL", mm.get("COSTCENTER"));
|
||||
// //GRUND 移动原因 (201,202回传)
|
||||
// item.put("GRUND", mm.get("SHIPREQUESTDETAILTYPE"));
|
||||
|
||||
item.put("BWART", "261");
|
||||
//ZLLORDER 自定义领料单号
|
||||
// item.put("ZLLORDER", "LL1010250408001");
|
||||
item.put("ZLLORDER", mm.getZLLORDER());
|
||||
//ZLLITEM 自定义领料单行号
|
||||
|
||||
// item.put("ZLLITEM", "0001");
|
||||
item.put("ZLLITEM", mm.getZLLITEM());
|
||||
//AUFNR 订单号
|
||||
item.put("AUFNR", mm.getAUFNR());
|
||||
|
||||
}
|
||||
itemArray.add(item);
|
||||
}
|
||||
|
||||
log.info("SendTOSAP >>>>" + sendData);
|
||||
String sendDatas = sendData.toJSONString();
|
||||
String sapreturn = toSAPMessageUtil.sendHttpPost(toSAPMessageUtil.materialChangeLocationUrl, "", sendDatas);
|
||||
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("MES物料消耗261");
|
||||
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返回" + e.toString());
|
||||
}
|
||||
if (!"S".equals(rcode)) {
|
||||
throw new RuntimeException("SAP返回" + rmsg);
|
||||
}
|
||||
return undoId;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -23,6 +23,19 @@ public class MESToWMSController {
|
||||
@Autowired
|
||||
private MESToWMSServiceImpl mesToWMSService;
|
||||
|
||||
/**
|
||||
* 转工单接口
|
||||
*/
|
||||
@ApiOperation(value = "物料转工单请求")
|
||||
@RequestMapping(value = "/meswms_workorder_request", method = RequestMethod.POST)
|
||||
public AjaxResult workOrder_Request(@RequestBody JSONArray in) {
|
||||
log.info("Received work order request: {}", in.toJSONString());
|
||||
try {
|
||||
return mesToWMSService.workOrder_Request(in);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@ApiOperation(value = "物料消耗请求")
|
||||
@RequestMapping(value = "/meswms_materialconsume_request", method = RequestMethod.POST)
|
||||
|
@ -1,13 +1,13 @@
|
||||
package com.cim.idm.dao;
|
||||
|
||||
import com.cim.idm.model.MaterialPackingSubDto;
|
||||
import com.cim.idm.wmspackage.materialpacking.management.data.MaterialPacking;
|
||||
import com.cim.idm.data.changeOrder.changeOrderDto;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.apache.ibatis.annotations.Select;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@Component
|
||||
@Mapper
|
||||
@ -24,4 +24,13 @@ public interface MesToWmsDao {
|
||||
public void updateBsMesShipped(@Param("materialPackingName") String materialPackingName) throws Exception;
|
||||
|
||||
public void updateUnDoId(@Param("undoId") String undoId) throws Exception;
|
||||
|
||||
List<changeOrderDto> getMaterialPackingList(@Param("materialSpecnameList") List<String> materialSpecnameList, @Param("chargeList") List<String> chargeList);
|
||||
|
||||
|
||||
void updateMDCFlag(@Param("materialSpecnameList") List<String> materialSpecnameList, @Param("chargeList") List<String> chargeList, @Param("t") String t);
|
||||
|
||||
List<changeOrderDto> getMaterialPackingListByRK(@Param("materialSpecnameList") List<String> materialSpecnameList, @Param("chargeList") List<String> chargeList);
|
||||
|
||||
void updateWO(@Param("materialSpecnameList") List<String> materialSpecnameList, @Param("chargeList") List<String> chargeList, @Param("t") String t);
|
||||
}
|
||||
|
@ -2,7 +2,6 @@ package com.cim.idm.service.Impl;
|
||||
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.cim.idm.dao.FgStockInDao;
|
||||
import com.cim.idm.dao.MesToWmsDao;
|
||||
import com.cim.idm.data.ErpMessageLog;
|
||||
import com.cim.idm.exception.GlobalException;
|
||||
@ -11,7 +10,7 @@ import com.cim.idm.framework.data.EventInfo;
|
||||
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.model.MaterialPackingSubDto;
|
||||
import com.cim.idm.data.changeOrder.changeOrderDto;
|
||||
import com.cim.idm.mwmsextend.materialpacking.service.MaterialPackingServiceImpl;
|
||||
import com.cim.idm.service.MESToWMSService;
|
||||
import com.cim.idm.service.QMSService;
|
||||
@ -553,4 +552,102 @@ public class MESToWMSServiceImpl implements MESToWMSService {
|
||||
MessageLogUtil.writeMessageLog(loginfo);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 接收MES请求工单请求
|
||||
*
|
||||
* @param in
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
@Transactional
|
||||
public AjaxResult workOrder_Request(JSONArray in) {
|
||||
//转工单,按照批次先传MDC消耗请求SAP出库,再生成入库信息传SAP入库
|
||||
log.info("Received work order request: {}", in.toJSONString());
|
||||
//转换前工单formOrder,转换后工单toOrder,料号 materialSpecname,批次 charge
|
||||
//先判断Array里面的批次和料号库存是否都存在,如果不存在不执行作业
|
||||
//将料号和批次分别放到集合里面从mybatis里面取数据和SAP过账,出库成功后更新changeOrderFlag状态为T,入库成功后更新状态为S
|
||||
List<String> materialSpecnameList = new ArrayList<>();
|
||||
List<String> chargeList = new ArrayList<>();
|
||||
String wo = "";
|
||||
for (int i = 0; i < in.size(); i++) {
|
||||
JSONObject jsonObject = in.getJSONObject(i);
|
||||
String materialSpecname = jsonObject.getString("materialSpecname");
|
||||
String charge = jsonObject.getString("charge");
|
||||
wo = jsonObject.getString("toOrder");
|
||||
materialSpecnameList.add(materialSpecname);
|
||||
chargeList.add(charge);
|
||||
if (StringUtils.isNotBlank(materialSpecname) && StringUtils.isNotBlank(charge)) {
|
||||
//判断批次和料号MDC表是否存在
|
||||
if (!checkMaterialPackingExist(materialSpecname, charge)) {
|
||||
log.error("工单转换失败,批次和料号不存在 {} {} ", materialSpecname, charge);
|
||||
//String占位符
|
||||
String message = "工单转换失败,批次和料号不存在 {} {} ";
|
||||
|
||||
return AjaxResult.me().setResultObj(null).setSuccess(false).setErrorCode(500).setMessage(message);
|
||||
}
|
||||
} else {
|
||||
return AjaxResult.me().setResultObj(null).setSuccess(false).setErrorCode(500).setMessage("工单转换失败,库存不存在");
|
||||
}
|
||||
}
|
||||
//调用出库方法
|
||||
String s = materialOutByMES(materialSpecnameList, chargeList);
|
||||
//调用入库方法
|
||||
String s1 = materialIntoByMES(materialSpecnameList, chargeList,wo);
|
||||
String message = "工单转换成功 物料凭证 {}";
|
||||
return AjaxResult.me().setResultObj(null).setSuccess(true).setErrorCode(200).setMessage("执行成功,物料凭证 " + s1);
|
||||
}
|
||||
|
||||
/**
|
||||
* 出库方法
|
||||
*/
|
||||
@Transactional
|
||||
public String materialOutByMES(List<String> materialSpecnameList, List<String> chargeList) {
|
||||
String result = "";
|
||||
//调用Mybatis方法查询当前可出库存
|
||||
List<changeOrderDto> materialPackingList = mesToWmsDao.getMaterialPackingList(materialSpecnameList, chargeList);
|
||||
//出库过账
|
||||
String undoid = toSAPService.StockOutByOrder(
|
||||
materialPackingList,
|
||||
"MES"
|
||||
);
|
||||
//更新MDC表状态
|
||||
mesToWmsDao.updateMDCFlag(materialSpecnameList, chargeList, "T");
|
||||
return undoid;
|
||||
}
|
||||
|
||||
/**
|
||||
* 入库方法
|
||||
*/
|
||||
@Transactional
|
||||
public String materialIntoByMES(List<String> materialSpecnameList, List<String> chargeList, String wo) {
|
||||
//更新工单号
|
||||
mesToWmsDao.updateWO(materialSpecnameList, chargeList, wo);
|
||||
List<changeOrderDto> materialPackingListByRK = mesToWmsDao.getMaterialPackingListByRK(materialSpecnameList, chargeList);
|
||||
//入库过账
|
||||
String undoid = toSAPService.StockOutByOrder(
|
||||
materialPackingListByRK,
|
||||
"MES"
|
||||
);
|
||||
mesToWmsDao.updateMDCFlag(materialSpecnameList, chargeList, "S");
|
||||
return undoid;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 判断MDC表是否有库存
|
||||
*/
|
||||
public static boolean checkMaterialPackingExist(String materialSpecName,String charge) {
|
||||
String sql = "SELECT COUNT(1) FROM MATERIALPACKINGMDC WHERE MATERIALSPECNAME = :MATERIALSPECNAME AND CHARGE = :CHARGE";
|
||||
Map<String, Object> bindMap = new HashMap<>();
|
||||
bindMap.put("MATERIALSPECNAME", materialSpecName);
|
||||
bindMap.put("CHARGE", charge);
|
||||
List<Map<String, Object>> maps = IDMFrameServiceProxy.getSqlTemplate().queryForList(sql, bindMap);
|
||||
if (maps != null && maps.size() > 0) {
|
||||
if (maps.get(0).get("COUNT(1)") != null && Integer.parseInt(maps.get(0).get("COUNT(1)").toString()) > 0) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
@ -34,4 +34,11 @@ public interface MESToWMSService {
|
||||
* @return
|
||||
*/
|
||||
AjaxResult shipByMES(JSONArray in) throws Exception;
|
||||
|
||||
/**
|
||||
* 接收MES请求工单请求
|
||||
* @param in
|
||||
* @return
|
||||
*/
|
||||
AjaxResult workOrder_Request(JSONArray in);
|
||||
}
|
@ -4,7 +4,7 @@
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
|
||||
<mapper namespace="com.cim.idm.dao.MesToWmsDao">
|
||||
<!-- 查询完工报告-->
|
||||
<!-- 查询完工报告-->
|
||||
<select id="getEndReportList" resultType="com.cim.idm.model.MaterialPackingSubDto">
|
||||
SELECT
|
||||
M.RECEIVEREQUESTNAME,
|
||||
@ -24,7 +24,45 @@
|
||||
WHERE
|
||||
M.MATERIALPACKINGNAME = #{materialPackingName}
|
||||
</select>
|
||||
<!-- 更新-->
|
||||
<select id="getMaterialPackingList"
|
||||
resultType="com.cim.idm.data.changeOrder.changeOrderDto"
|
||||
parameterType="arraylist">
|
||||
SELECT
|
||||
T.MATERIALSPECNAME MATNR, T.ERPFACTORY WERKS,T.ERPLOCATION LGORT,
|
||||
T.MATERIALQUANTITY MENGE,T.MATERIALUNIT MEINS, '' KOSTL, '' GRUND, '261' BWART,
|
||||
'' ZLLORDER, '' ZLLITEM, T.WO AUFNR
|
||||
FROM
|
||||
MATERIALPACKINGMDC T
|
||||
WHERE
|
||||
T.MATERIALSPECNAME IN
|
||||
<foreach collection="materialSpecnameList" item="item" open="(" separator="," close=")">
|
||||
#{item}
|
||||
</foreach>
|
||||
AND T.CHARGE IN
|
||||
<foreach collection="chargeList" item="item" open="(" separator="," close=")">
|
||||
#{item}
|
||||
</foreach>
|
||||
AND (CHANGEORDERFLAG != 'T' OR CHANGEORDERFLAG IS NULL)
|
||||
</select>
|
||||
<select id="getMaterialPackingListByRK" resultType="com.cim.idm.data.changeOrder.changeOrderDto">
|
||||
SELECT
|
||||
T.MATERIALSPECNAME MATNR, T.ERPFACTORY WERKS,T.ERPLOCATION LGORT,
|
||||
T.MATERIALQUANTITY MENGE,T.MATERIALUNIT MEINS, '' KOSTL, '' GRUND, '261' BWART,
|
||||
'' ZLLORDER, '' ZLLITEM, T.WO AUFNR
|
||||
FROM
|
||||
MATERIALPACKINGMDC T
|
||||
WHERE
|
||||
T.MATERIALSPECNAME IN
|
||||
<foreach collection="materialSpecnameList" item="item" open="(" separator="," close=")">
|
||||
#{item}
|
||||
</foreach>
|
||||
AND T.CHARGE IN
|
||||
<foreach collection="chargeList" item="item" open="(" separator="," close=")">
|
||||
#{item}
|
||||
</foreach>
|
||||
AND CHANGEORDERFLAG = 'T'
|
||||
</select>
|
||||
<!-- 更新-->
|
||||
<update id="updateEndReport" parameterType="map">
|
||||
UPDATE
|
||||
MATERIALRECEIVEREQUESTDETAIL T
|
||||
@ -77,4 +115,26 @@
|
||||
UPDATE IF_ERPUNDO T SET T.FLAG = 'Y' WHERE T.UNDOID = #{undoId}
|
||||
</update>
|
||||
|
||||
<update id="updateMDCFlag">
|
||||
UPDATE MATERIALPACKINGMDC T SET T.CHANGEORDERFLAG = 'T' WHERE T.MATERIALSPECNAME in
|
||||
<foreach collection="materialSpecnameList" item="item" open="(" separator="," close=")">
|
||||
#{item}
|
||||
</foreach>
|
||||
AND T.CHARGE in
|
||||
<foreach collection="chargeList" item="item" open="(" separator="," close=")">
|
||||
#{item}
|
||||
</foreach>
|
||||
|
||||
</update>
|
||||
<update id="updateWO">
|
||||
UPDATE MATERIALPACKINGMDC T SET T.WO = #{t} WHERE T.MATERIALSPECNAME in
|
||||
<foreach collection="materialSpecnameList" item="item" open="(" separator="," close=")">
|
||||
#{item}
|
||||
</foreach>
|
||||
AND T.CHARGE in
|
||||
<foreach collection="chargeList" item="item" open="(" separator="," close=")">
|
||||
#{item}
|
||||
</foreach>
|
||||
</update>
|
||||
|
||||
</mapper>
|
Loading…
x
Reference in New Issue
Block a user