package com.cim.idm.service.impl;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.cim.idm.data.ErpMessageLog;
import com.cim.idm.framework.IDMFrameServiceProxy;
import com.cim.idm.framework.util.time.TimeStampUtil;
import com.cim.idm.service.MESService;
import com.cim.idm.util.MESHttpUtil;
import com.cim.idm.util.MessageLogUtil;
import com.cim.idm.wmsextend.generic.errorHandler.CustomException;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.*;

/**
 * QMS接口实现类
 * @author ZXYGY17
 *
 */
public class MESServiceImpl implements MESService{
	
	@Autowired
	MESHttpUtil mesHttpUtil;

	private static String  baseUrl = "http://172.22.10.213:8190";
	
	/*
	 * 领料单出库信息发送MES
	 */
	@Override
	public String OutMaterialInfoSend(String shipRequestName, String siteName, String receiveActNo, String wo,
			String erpReceiveLocation,String erpReceiveFactory) throws CustomException{

		//根据单据获取要发送MES的信息
		String sql="SELECT m.CHARGE,m.MATERIALPACKINGNAME,m.MATERIALSPECNAME,to_char(m.EXPIRINGDATE,'YYYY-MM-DD HH24:MI')EXPIRINGDATE,m.PHASE, \r\n" + 
				"				 m.TRUEGG ,m.MATERIALQUANTITY ,m.FQTY ,m.FUNIT ,m.LASTEVENTUSER ,m.REMARK , \r\n" + 
				"				 m3.SHIPREQUESTDETAILTYPE ,m2.MATERIALUNIT ,bm.DENOMINATOR/bm.MODULECULE CONVERSIONSCALE, \r\n" + 
				"				 m4.DESCRIPTION ,m2.MATERIALTYPE  ,(SELECT RECEIVEPRODUCTIONORDERNUMBER FROM MATERIALSHIPREQUESTDETAIL m5\r\n" + 
				"				 WHERE m5.SHIPREQUESTNAME=:SHIPREQUESTNAME AND m5.MATERIALSPECNAME=m.MATERIALSPECNAME \r\n" + 
				"				 ORDER BY m5.USEDATE,m5.SHIPREQUESTDETAILNAME FETCH FIRST ROW ONLY)WO\r\n" + 
				"				 FROM MATERIALPACKING m ,MATERIALSPEC m2 ,MATERIALSHIPREQUEST m3 ,BS_MATERIALDESCRIPTION m4 ,BS_MATERIALUNIT bm  \r\n" + 
				"				 WHERE m.SITENAME =:SITENAME  \r\n" + 
				"				 AND m.SHIPREQUESTNAME =:SHIPREQUESTNAME \r\n" + 
				"				 AND (m.RECEIVEACTNO =:RECEIVEACTNO OR :RECEIVEACTNO IS NULL ) \r\n" + 
				"				 AND m.MATERIALSPECNAME =m2.MATERIALSPECNAME  \r\n" + 
				"				 AND m.SHIPREQUESTNAME =m3.SHIPREQUESTNAME  \r\n" + 
				"				 AND m.MATERIALSPECNAME =m4.MATERIALSPECNAME  \r\n" + 
				"				 AND m.MATERIALSPECNAME =bm.MATERIALSPECNAME(+) \r\n" + 
				"				 AND m.FUNIT =bm.ADDITIONALUNIT(+)";
		
		Map<String, Object> hashMap = new HashMap<String, Object> ();
		hashMap.put("RECEIVEACTNO", receiveActNo);
		hashMap.put("SITENAME", siteName);
		hashMap.put("SHIPREQUESTNAME", shipRequestName);
		hashMap.put("ERPFACTORY", erpReceiveFactory);
		hashMap.put("ERPLOCATION", erpReceiveLocation);
		hashMap.put("EVENTNAME", "StockOut");
		//hashMap.put("WO", wo);
		List<Map<String, Object>> queryForList = IDMFrameServiceProxy.getSqlTemplate().queryForList(sql.toString(), hashMap);
		String makeOutMaterialInfoSendJson = MakeOutMaterialInfoSendJson(queryForList,shipRequestName);
		System.out.println("JSON=================:"+makeOutMaterialInfoSendJson);
		String httpPost = mesHttpUtil.httpPost(baseUrl + "/wms/consumableReceive", makeOutMaterialInfoSendJson);
		org.json.JSONObject jsonObject = new org.json.JSONObject(httpPost);
		String code = jsonObject.getString("code");
		
//		if (!"00000".equals(code)) {
//			throw new CustomException("ACTSTATEERROR","","");
//		}
		String msg = jsonObject.getString("msg");
		//JSONObject object = (JSONObject) jsonObject.get("data");

		// 写log
		ErpMessageLog erplog = new ErpMessageLog();
		erplog.setEventUser("");
		erplog.setServerName("WmsToMES");
		erplog.setEventName("OutMaterialInfoSend");
		erplog.setInterfaceTime(TimeStampUtil.getCurrentTime(TimeStampUtil.FORMAT_DEFAULT));
		erplog.setMessageId(UUID.randomUUID().toString());
		erplog.setSendMsg(makeOutMaterialInfoSendJson);
		erplog.setReturnMsg2(httpPost.toString());
		erplog.setResultCode(code);
		MessageLogUtil.writeMessageLog(erplog);
		
		//插入MATERIALPCKINGMDC表
		String sqli="INSERT INTO MATERIALPACKINGMDC(MATERIALPACKINGNAME,CHARGE,MATERIALSPECNAME,EXPIRINGDATE,PHASE, \r\n" + 
				"				 TRUEGG ,MATERIALQUANTITY ,FQTY ,FUNIT ,LASTEVENTUSER ,REMARK , \r\n" + 
				"				 SHIPREQUESTDETAILTYPE ,MATERIALUNIT ,CONVERSIONSCALE, \r\n" + 
				"				 DESCRIPTION ,MATERIALTYPE, ERPFACTORY,ERPLOCATION,OUTTIME,EVENTNAME,EVENTTIME,WO,SHIPREQUESTNAME) \r\n" + 
				"				 SELECT m.MATERIALPACKINGNAME,m.CHARGE,m.MATERIALSPECNAME,m.EXPIRINGDATE,m.PHASE, \r\n" + 
				"				 m.TRUEGG ,m.MATERIALQUANTITY ,m.FQTY ,m.FUNIT ,m.LASTEVENTUSER ,m.REMARK , \r\n" + 
				"				 m3.SHIPREQUESTDETAILTYPE ,m2.MATERIALUNIT ,bm.DENOMINATOR/bm.MODULECULE CONVERSIONSCALE, \r\n" + 
				"				 m4.DESCRIPTION ,m2.MATERIALTYPE ,:ERPFACTORY,:ERPLOCATION,SYSDATE,:EVENTNAME,SYSDATE ,\r\n" + 
				"				 (SELECT RECEIVEPRODUCTIONORDERNUMBER FROM MATERIALSHIPREQUESTDETAIL m5\r\n" + 
				"				 WHERE m5.SHIPREQUESTNAME=:SHIPREQUESTNAME AND m5.MATERIALSPECNAME=m.MATERIALSPECNAME \r\n" + 
				"				 ORDER BY m5.USEDATE,m5.SHIPREQUESTDETAILNAME FETCH FIRST ROW ONLY)WO,:SHIPREQUESTNAME \r\n" + 
				"				 FROM MATERIALPACKING m ,MATERIALSPEC m2 ,MATERIALSHIPREQUEST m3 ,BS_MATERIALDESCRIPTION m4 ,BS_MATERIALUNIT bm  \r\n" + 
				"				 WHERE m.SITENAME =:SITENAME  \r\n" + 
				"				 AND m.SHIPREQUESTNAME =:SHIPREQUESTNAME \r\n" + 
				"				 AND (m.RECEIVEACTNO =:RECEIVEACTNO OR :RECEIVEACTNO IS NULL ) \r\n" + 
				"				 AND m.MATERIALSPECNAME =m2.MATERIALSPECNAME  \r\n" + 
				"				 AND m.SHIPREQUESTNAME =m3.SHIPREQUESTNAME  \r\n" + 
				"				 AND m.MATERIALSPECNAME =m4.MATERIALSPECNAME  \r\n" + 
				"				 AND m.MATERIALSPECNAME =bm.MATERIALSPECNAME(+) \r\n" + 
				"				 AND m.FUNIT =bm.ADDITIONALUNIT(+)";
		IDMFrameServiceProxy.getSqlTemplate().update(sqli, hashMap);
		
		return code;
		
	}
	
	//zd.2024.8.4重写发送MES方法
	public String OutMaterialInfoSend_NEW(String shipRequestName, String siteName, String receiveActNo, String wo,
			String erpReceiveLocation,String erpReceiveFactory,List<String> boxList) throws CustomException{

		//根据单据获取要发送MES的信息
		String sql="SELECT * from(\r\n" + 
				" SELECT m.CHARGE,m.MATERIALPACKINGNAME,m.MATERIALSPECNAME,to_char(m.EXPIRINGDATE,'YYYY-MM-DD HH24:MI')EXPIRINGDATE,m.PHASE,  \r\n" +
				"		m.TRUEGG ,m.FQTY ,m.FUNIT ,m.GXID,m.LASTEVENTUSER ,m.REMARK , m3.SHIPREQUESTTYPE, \r\n" +
				"		m3.SHIPREQUESTDETAILTYPE ,m2.MATERIALUNIT ,bm.DENOMINATOR/bm.MODULECULE CONVERSIONSCALE,  \r\n" + 
				"		m4.DESCRIPTION ,m2.MATERIALTYPE ,(SELECT RECEIVEPRODUCTIONORDERNUMBER FROM MATERIALSHIPREQUESTDETAIL m5 \r\n" + 
				"		WHERE m5.SHIPREQUESTNAME=:SHIPREQUESTNAME AND m5.MATERIALSPECNAME=m.MATERIALSPECNAME  \r\n" + 
				"		ORDER BY m5.USEDATE,m5.SHIPREQUESTDETAILNAME FETCH FIRST ROW ONLY)WO \r\n" + 
				"		FROM MATERIALPACKING m , MATERIALSPEC m2 ,MATERIALSHIPREQUEST m3 ,BS_MATERIALDESCRIPTION m4 ,BS_MATERIALUNIT bm   \r\n" + 
				"		WHERE m.SITENAME =:SITENAME   \r\n" + 
				"		AND m.SHIPREQUESTNAME =:SHIPREQUESTNAME\r\n" + 
				"		AND m.MATERIALPACKINGNAME in(:BOXLIST)  \r\n" + 
				"		AND m.MATERIALSPECNAME =m2.MATERIALSPECNAME   \r\n" + 
				"		AND m.SHIPREQUESTNAME =m3.SHIPREQUESTNAME   \r\n" + 
				"		AND m.MATERIALSPECNAME =m4.MATERIALSPECNAME   \r\n" + 
				"		AND m.MATERIALSPECNAME =bm.MATERIALSPECNAME(+)  \r\n" + 
				"		AND m.FUNIT =bm.ADDITIONALUNIT(+))A\r\n" + 
				"		LEFT JOIN (\r\n" + 
				"	SELECT m.MATERIALPACKINGNAME MPS,sum(m.QTY)MATERIALQUANTITY FROM MATERIALPACKINGSUB m \r\n" + 
				"	WHERE m.MATERIALPACKINGNAME in(:BOXLIST)\r\n" + 
				"	AND m.RECEIVEREQUESTNAME =:SHIPREQUESTNAME\r\n" + 
				"	GROUP BY m.MATERIALPACKINGNAME)B\r\n" + 
				"	ON A.MATERIALPACKINGNAME=b.MPS";
		
		Map<String, Object> hashMap = new HashMap<String, Object> ();
		hashMap.put("RECEIVEACTNO", receiveActNo);
		hashMap.put("SITENAME", siteName);
		hashMap.put("SHIPREQUESTNAME", shipRequestName);
		hashMap.put("ERPFACTORY", erpReceiveFactory);
		hashMap.put("ERPLOCATION", erpReceiveLocation);
		hashMap.put("BOXLIST", boxList);
		hashMap.put("EVENTNAME", "StockOut");
		//hashMap.put("WO", wo);
		List<Map<String, Object>> queryForList = IDMFrameServiceProxy.getSqlTemplate().queryForList(sql.toString(), hashMap);
		String makeOutMaterialInfoSendJson = MakeOutMaterialInfoSendJson(queryForList,shipRequestName);
		System.out.println("JSON=================:"+makeOutMaterialInfoSendJson);
		String httpPost = mesHttpUtil.httpPost(baseUrl + "/wms/consumableReceive", makeOutMaterialInfoSendJson);

		org.json.JSONObject jsonObject = new org.json.JSONObject(httpPost);
		String code = jsonObject.getString("code");



		boolean success = jsonObject.getBoolean("success");

		// 写log
		ErpMessageLog erplog = new ErpMessageLog();
		erplog.setEventUser("");
		erplog.setServerName("WmsToMES");
		erplog.setEventName("OutMaterialInfoSend");
		erplog.setInterfaceTime(TimeStampUtil.getCurrentTime(TimeStampUtil.FORMAT_DEFAULT));
		erplog.setMessageId(UUID.randomUUID().toString());
		erplog.setSendMsg(makeOutMaterialInfoSendJson);
		erplog.setReturnMsg2(httpPost.toString());
		erplog.setResultCode(code);
		MessageLogUtil.writeMessageLog(erplog);

		if (!success) {
			String msg = jsonObject.getString("msg");
			throw new CustomException("发送MES失败！");
		}
		
		//插入MATERIALPCKINGMDC表
		for(int i=0;i<boxList.size();i++) 
		{
			String boxid=boxList.get(i);
			String sqls="SELECT m.MATERIALPACKINGNAME FROM MATERIALPACKINGMDC m \r\n" + 
					" WHERE m.CHARGE =(SELECT m.CHARGE FROM MATERIALPACKING m \r\n" + 
					" WHERE m.MATERIALPACKINGNAME =:MATERIALPACKINGNAME)";
			Map<String, Object> bps = new HashMap<String, Object> ();
			bps.put("MATERIALPACKINGNAME", boxid);
			bps.put("SHIPREQUESTNAME", shipRequestName);
			List<Map<String, Object>> srs=IDMFrameServiceProxy.getSqlTemplate().queryForList(sqls, bps);
			
			String sql2="SELECT nvl(sum(qty),0)QTY FROM MATERIALPACKINGSUB  m \r\n" + 
					"WHERE m.RECEIVEREQUESTNAME =:SHIPREQUESTNAME\r\n" + 
					"AND m.MATERIALPACKINGNAME =:MATERIALPACKINGNAME";
			List<Map<String, Object>> sr2=IDMFrameServiceProxy.getSqlTemplate().queryForList(sql2, bps);
			String qty=sr2.get(0).get("QTY").toString();
			bps.put("QTY", qty);
			if(srs.size()>0) 
			{
//				String sqlu="UPDATE MATERIALPACKINGMDC m SET m.MATERIALQUANTITY =m.MATERIALQUANTITY + :QTY \r\n" + 
//						" WHERE m.CHARGE =(SELECT m.CHARGE FROM MATERIALPACKING m \r\n" + 
//						" WHERE m.MATERIALPACKINGNAME =:MATERIALPACKINGNAME)";
				String sqlu="DELETE FROM MATERIALPACKINGMDC m "+
						" WHERE m.CHARGE =(SELECT m.CHARGE FROM MATERIALPACKING m \r\n" + 
						" WHERE m.MATERIALPACKINGNAME =:MATERIALPACKINGNAME)";
				IDMFrameServiceProxy.getSqlTemplate().update(sqlu, bps);
			}

			String sqli = "INSERT INTO MATERIALPACKINGMDC(MATERIALPACKINGNAME,CHARGE,MATERIALSPECNAME,EXPIRINGDATE,PHASE, \r\n"
					+ "				 TRUEGG ,MATERIALQUANTITY ,FQTY ,FUNIT ,LASTEVENTUSER ,REMARK , \r\n"
					+ "				 SHIPREQUESTDETAILTYPE ,MATERIALUNIT ,CONVERSIONSCALE, \r\n"
					+ "				 DESCRIPTION ,MATERIALTYPE, ERPFACTORY,ERPLOCATION,OUTTIME,EVENTNAME,EVENTTIME,WO,SHIPREQUESTNAME) \r\n"
					+ "				 SELECT m.MATERIALPACKINGNAME,m.CHARGE,m.MATERIALSPECNAME,m.EXPIRINGDATE,m.PHASE, \r\n"
					+ "				 m.TRUEGG ,:QTY ,m.FQTY ,m.FUNIT ,m.LASTEVENTUSER ,m.REMARK , \r\n"
					+ "				 m3.SHIPREQUESTDETAILTYPE ,m2.MATERIALUNIT ,bm.DENOMINATOR/bm.MODULECULE CONVERSIONSCALE, \r\n"
					+ "				 m4.DESCRIPTION ,m2.MATERIALTYPE ,:ERPFACTORY,:ERPLOCATION,SYSDATE,:EVENTNAME,SYSDATE ,\r\n"
					+ "				 (SELECT RECEIVEPRODUCTIONORDERNUMBER FROM MATERIALSHIPREQUESTDETAIL m5\r\n"
					+ "				 WHERE m5.SHIPREQUESTNAME=:SHIPREQUESTNAME AND m5.MATERIALSPECNAME=m.MATERIALSPECNAME \r\n"
					+ "				 ORDER BY m5.USEDATE,m5.SHIPREQUESTDETAILNAME FETCH FIRST ROW ONLY)WO,:SHIPREQUESTNAME \r\n"
					+ "				 FROM MATERIALPACKING m ,MATERIALSPEC m2 ,MATERIALSHIPREQUEST m3 ,BS_MATERIALDESCRIPTION m4 ,BS_MATERIALUNIT bm  \r\n"
					+ "				 WHERE m.SITENAME =:SITENAME  \r\n"
					+ "				 AND m.SHIPREQUESTNAME =:SHIPREQUESTNAME \r\n"
					+ "				 AND (m.RECEIVEACTNO =:RECEIVEACTNO OR :RECEIVEACTNO IS NULL ) \r\n"
					+ "				 AND m.MATERIALSPECNAME =m2.MATERIALSPECNAME  \r\n"
					+ "				 AND m.SHIPREQUESTNAME =m3.SHIPREQUESTNAME  \r\n"
					+ "				 AND m.MATERIALSPECNAME =m4.MATERIALSPECNAME  \r\n"
					+ "				 AND m.MATERIALSPECNAME =bm.MATERIALSPECNAME(+) \r\n"
					+ "				 AND m.FUNIT =bm.ADDITIONALUNIT(+) AND m.STOCKSTATE = 'Stocked'";

			hashMap.put("QTY", qty);
			IDMFrameServiceProxy.getSqlTemplate().update(sqli, hashMap);
			
		}
		return code;
		
	}

	public String OutMaterialInfoSend_NEW2(String shipRequestName, String siteName, String receiveActNo, String wo,
										  String erpReceiveLocation,String erpReceiveFactory,List<String> boxList) throws CustomException{

		//根据单据获取要发送MES的信息
		String sql="SELECT * from(\r\n" +
				" SELECT m.CHARGE,m.MATERIALPACKINGNAME,m.MATERIALSPECNAME,to_char(m.EXPIRINGDATE,'YYYY-MM-DD HH24:MI')EXPIRINGDATE,m.PHASE,  \r\n" +
				"		m.TRUEGG ,m.FQTY ,m.FUNIT ,m.GXID,m.LASTEVENTUSER ,m.REMARK , m3.SHIPREQUESTTYPE, \r\n" +
				"		m3.SHIPREQUESTDETAILTYPE ,m2.MATERIALUNIT ,bm.DENOMINATOR/bm.MODULECULE CONVERSIONSCALE,  \r\n" +
				"		m4.DESCRIPTION ,m2.MATERIALTYPE ,(SELECT RECEIVEPRODUCTIONORDERNUMBER FROM MATERIALSHIPREQUESTDETAIL m5 \r\n" +
				"		WHERE m5.SHIPREQUESTNAME=:SHIPREQUESTNAME AND m5.MATERIALSPECNAME=m.MATERIALSPECNAME  \r\n" +
				"		ORDER BY m5.USEDATE,m5.SHIPREQUESTDETAILNAME FETCH FIRST ROW ONLY)WO \r\n" +
				"		FROM MATERIALPACKING m , MATERIALSPEC m2 ,MATERIALSHIPREQUEST m3 ,BS_MATERIALDESCRIPTION m4 ,BS_MATERIALUNIT bm   \r\n" +
				"		WHERE m.SITENAME =:SITENAME   \r\n" +
				"		AND m.SHIPREQUESTNAME =:SHIPREQUESTNAME\r\n" +
				"		AND m.MATERIALPACKINGNAME in(:BOXLIST)  \r\n" +
				"		AND m.MATERIALSPECNAME =m2.MATERIALSPECNAME   \r\n" +
				"		AND m.SHIPREQUESTNAME =m3.SHIPREQUESTNAME   \r\n" +
				"		AND m.MATERIALSPECNAME =m4.MATERIALSPECNAME   \r\n" +
				"		AND m.MATERIALSPECNAME =bm.MATERIALSPECNAME(+)  \r\n" +
				"		AND m.FUNIT =bm.ADDITIONALUNIT(+))A\r\n" +
				"		LEFT JOIN (\r\n" +
				"	SELECT m.MATERIALPACKINGNAME MPS,sum(m.QTY)MATERIALQUANTITY FROM MATERIALPACKINGSUB m \r\n" +
				"	WHERE m.MATERIALPACKINGNAME in(:BOXLIST)\r\n" +
				"	AND m.RECEIVEREQUESTNAME =:SHIPREQUESTNAME\r\n" +
				"	GROUP BY m.MATERIALPACKINGNAME)B\r\n" +
				"	ON A.MATERIALPACKINGNAME=b.MPS";

		Map<String, Object> hashMap = new HashMap<String, Object> ();
		hashMap.put("RECEIVEACTNO", receiveActNo);
		hashMap.put("SITENAME", siteName);
		hashMap.put("SHIPREQUESTNAME", shipRequestName);
		hashMap.put("ERPFACTORY", erpReceiveFactory);
		hashMap.put("ERPLOCATION", erpReceiveLocation);
		hashMap.put("BOXLIST", boxList);
		hashMap.put("EVENTNAME", "StockOut");
		//hashMap.put("WO", wo);
		List<Map<String, Object>> queryForList = IDMFrameServiceProxy.getSqlTemplate().queryForList(sql.toString(), hashMap);
		String makeOutMaterialInfoSendJson = MakeOutMaterialInfoSendJson(queryForList,shipRequestName);
		System.out.println("JSON=================:"+makeOutMaterialInfoSendJson);
		String httpPost = mesHttpUtil.httpPost(baseUrl + "/wms/consumableReceive", makeOutMaterialInfoSendJson);

		org.json.JSONObject jsonObject = new org.json.JSONObject(httpPost);
		String code = jsonObject.getString("code");



		boolean success = jsonObject.getBoolean("success");

		// 写log
		ErpMessageLog erplog = new ErpMessageLog();
		erplog.setEventUser("");
		erplog.setServerName("WmsToMES");
		erplog.setEventName("OutMaterialInfoSend");
		erplog.setInterfaceTime(TimeStampUtil.getCurrentTime(TimeStampUtil.FORMAT_DEFAULT));
		erplog.setMessageId(UUID.randomUUID().toString());
		erplog.setSendMsg(makeOutMaterialInfoSendJson);
		erplog.setReturnMsg2(httpPost.toString());
		erplog.setResultCode(code);
		MessageLogUtil.writeMessageLog(erplog);

		if (!success) {
			String msg = jsonObject.getString("msg");
			throw new CustomException("发送MES失败！");
		}

		//插入MATERIALPCKINGMDC表
		for(int i=0;i<boxList.size();i++)
		{
			String boxid=boxList.get(i);
			String sqls="SELECT m.MATERIALPACKINGNAME FROM MATERIALPACKINGMDC m \r\n" +
					" WHERE m.CHARGE =(SELECT m.CHARGE FROM MATERIALPACKING m \r\n" +
					" WHERE m.MATERIALPACKINGNAME =:MATERIALPACKINGNAME)";
			Map<String, Object> bps = new HashMap<String, Object> ();
			bps.put("MATERIALPACKINGNAME", boxid);
			bps.put("SHIPREQUESTNAME", shipRequestName);
			List<Map<String, Object>> srs=IDMFrameServiceProxy.getSqlTemplate().queryForList(sqls, bps);

			String sql2="SELECT nvl(sum(qty),0)QTY FROM MATERIALPACKINGSUB  m \r\n" +
					"WHERE m.RECEIVEREQUESTNAME =:SHIPREQUESTNAME\r\n" +
					"AND m.MATERIALPACKINGNAME =:MATERIALPACKINGNAME";
			List<Map<String, Object>> sr2=IDMFrameServiceProxy.getSqlTemplate().queryForList(sql2, bps);
			String qty=sr2.get(0).get("QTY").toString();
			bps.put("QTY", qty);
			if(srs.size()>0)
			{
//				String sqlu="UPDATE MATERIALPACKINGMDC m SET m.MATERIALQUANTITY =m.MATERIALQUANTITY + :QTY \r\n" +
//						" WHERE m.CHARGE =(SELECT m.CHARGE FROM MATERIALPACKING m \r\n" +
//						" WHERE m.MATERIALPACKINGNAME =:MATERIALPACKINGNAME)";
				String sqlu="DELETE FROM MATERIALPACKINGMDC m "+
						" WHERE m.CHARGE =(SELECT m.CHARGE FROM MATERIALPACKING m \r\n" +
						" WHERE m.MATERIALPACKINGNAME =:MATERIALPACKINGNAME)";
				IDMFrameServiceProxy.getSqlTemplate().update(sqlu, bps);
			}
			hashMap.put("QTY", qty);

		}
		String sqli = "INSERT INTO MATERIALPACKINGMDC(MATERIALPACKINGNAME,CHARGE,MATERIALSPECNAME,EXPIRINGDATE,PHASE, \r\n"
				+ "				 TRUEGG ,MATERIALQUANTITY ,FQTY ,FUNIT ,LASTEVENTUSER ,REMARK , \r\n"
				+ "				 SHIPREQUESTDETAILTYPE ,MATERIALUNIT ,CONVERSIONSCALE, \r\n"
				+ "				 DESCRIPTION ,MATERIALTYPE, ERPFACTORY,ERPLOCATION,OUTTIME,EVENTNAME,EVENTTIME,WO,SHIPREQUESTNAME) \r\n"
				+ "				 SELECT m.MATERIALPACKINGNAME,m.CHARGE,m.MATERIALSPECNAME,m.EXPIRINGDATE,m.PHASE, \r\n"
				+ "				 m.TRUEGG ,:QTY ,m.FQTY ,m.FUNIT ,m.LASTEVENTUSER ,m.REMARK , \r\n"
				+ "				 m3.SHIPREQUESTDETAILTYPE ,m2.MATERIALUNIT ,bm.DENOMINATOR/bm.MODULECULE CONVERSIONSCALE, \r\n"
				+ "				 m4.DESCRIPTION ,m2.MATERIALTYPE ,:ERPFACTORY,:ERPLOCATION,SYSDATE,:EVENTNAME,SYSDATE ,\r\n"
				+ "				 (SELECT RECEIVEPRODUCTIONORDERNUMBER FROM MATERIALSHIPREQUESTDETAIL m5\r\n"
				+ "				 WHERE m5.SHIPREQUESTNAME=:SHIPREQUESTNAME AND m5.MATERIALSPECNAME=m.MATERIALSPECNAME \r\n"
				+ "				 ORDER BY m5.USEDATE,m5.SHIPREQUESTDETAILNAME FETCH FIRST ROW ONLY)WO,:SHIPREQUESTNAME \r\n"
				+ "				 FROM MATERIALPACKING m ,MATERIALSPEC m2 ,MATERIALSHIPREQUEST m3 ,BS_MATERIALDESCRIPTION m4 ,BS_MATERIALUNIT bm  \r\n"
				+ "				 WHERE m.SITENAME =:SITENAME  \r\n"
				+ "				 AND m.SHIPREQUESTNAME =:SHIPREQUESTNAME \r\n"
				+ "				 AND (m.RECEIVEACTNO =:RECEIVEACTNO OR :RECEIVEACTNO IS NULL ) \r\n"
				+ "				 AND m.MATERIALSPECNAME =m2.MATERIALSPECNAME  \r\n"
				+ "				 AND m.SHIPREQUESTNAME =m3.SHIPREQUESTNAME  \r\n"
				+ "				 AND m.MATERIALSPECNAME =m4.MATERIALSPECNAME  \r\n"
				+ "				 AND m.MATERIALSPECNAME =bm.MATERIALSPECNAME(+) \r\n"
				+ "				 AND m.FUNIT =bm.ADDITIONALUNIT(+) AND m.STOCKSTATE = 'Stocked'";


		IDMFrameServiceProxy.getSqlTemplate().update(sqli, hashMap);
		return code;

	}
	
	//zd.2024.8.23 需MES接收的数据发送MES并更新SENDMESFLAG为Y
	public String NeedReceiveMaterialInfoSend_NEW(String shipRequestName, String siteName, List<String> boxList)
			throws CustomException {

		// 根据单据获取要发送MES的信息
		String sql = " SELECT m.CHARGE,m.MATERIALPACKINGNAME,m.MATERIALSPECNAME,to_char(m.EXPIRINGDATE,'YYYY-MM-DD')EXPIRINGDATE,m.PHASE,m.MATERIALQUANTITY,   \r\n"
				+ "							m.TRUEGG ,m.FQTY ,m.FUNIT ,m.LASTEVENTUSER ,m.GXID,m.REMARK , m3.SHIPREQUESTTYPE,  \r\n"
				+ "							m3.SHIPREQUESTDETAILTYPE ,m2.MATERIALUNIT ,bm.DENOMINATOR/bm.MODULECULE CONVERSIONSCALE,   \r\n"
				+ "							m4.DESCRIPTION ,m2.MATERIALTYPE ,(SELECT RECEIVEPRODUCTIONORDERNUMBER FROM MATERIALSHIPREQUESTDETAIL m5  \r\n"
				+ "							WHERE m5.SHIPREQUESTNAME=:SHIPREQUESTNAME AND m5.MATERIALSPECNAME=m.MATERIALSPECNAME   \r\n"
				+ "							ORDER BY m5.USEDATE,m5.SHIPREQUESTDETAILNAME FETCH FIRST ROW ONLY)WO  \r\n"
				+ "							FROM MATERIALPACKING m , MATERIALSPEC m2 ,MATERIALSHIPREQUEST m3 ,BS_MATERIALDESCRIPTION m4 ,BS_MATERIALUNIT bm    \r\n"
				+ "							WHERE m.SITENAME =:SITENAME    \r\n"
				+ "							AND m.SHIPREQUESTNAME =:SHIPREQUESTNAME \r\n"
				+ "							AND m.MATERIALPACKINGNAME in(:BOXLIST) \r\n"
				+ "							AND m.STOCKSTATE='Stocked'\r\n"
				+ "							AND nvl(m.SENDMESFLAG,'N')='N'\r\n"
				+ "							AND m.MATERIALSPECNAME =m2.MATERIALSPECNAME    \r\n"
				+ "							AND m.SHIPREQUESTNAME =m3.SHIPREQUESTNAME    \r\n"
				+ "							AND m.MATERIALSPECNAME =m4.MATERIALSPECNAME    \r\n"
				+ "							AND m.MATERIALSPECNAME =bm.MATERIALSPECNAME(+)   \r\n"
				+ "							AND m.FUNIT =bm.ADDITIONALUNIT(+)";

		Map<String, Object> hashMap = new HashMap<String, Object>();
		hashMap.put("SITENAME", siteName);
		hashMap.put("SHIPREQUESTNAME", shipRequestName);
		hashMap.put("BOXLIST", boxList);
		// hashMap.put("EVENTNAME", "StockOut");
		// hashMap.put("WO", wo);
		List<Map<String, Object>> queryForList = IDMFrameServiceProxy.getSqlTemplate().queryForList(sql.toString(),
				hashMap);
		String makeOutMaterialInfoSendJson = MakeOutMaterialInfoSendJson(queryForList, shipRequestName);
		System.out.println("JSON=================:" + makeOutMaterialInfoSendJson);
		String httpPost = mesHttpUtil.httpPost(baseUrl + "/wms/consumableReceive", makeOutMaterialInfoSendJson);
		org.json.JSONObject jsonObject = new org.json.JSONObject(httpPost);
		String code = jsonObject.getString("code");

//			if (!"00000".equals(code)) {
//				throw new CustomException("ACTSTATEERROR","","");
//			}
		String msg = jsonObject.getString("msg");
		// JSONObject object = (JSONObject) jsonObject.get("data");

		// 写log
		ErpMessageLog erplog = new ErpMessageLog();
		erplog.setEventUser("");
		erplog.setServerName("WmsToMES");
		erplog.setEventName("needReceiveMaterialInfoSend");
		erplog.setInterfaceTime(TimeStampUtil.getCurrentTime(TimeStampUtil.FORMAT_DEFAULT));
		erplog.setMessageId(UUID.randomUUID().toString());
		erplog.setSendMsg(makeOutMaterialInfoSendJson);
		erplog.setReturnMsg2(httpPost.toString());
		erplog.setResultCode(code);
		MessageLogUtil.writeMessageLog(erplog);

		// 更新SENDMESFLAG
		updateSendMesFlag(boxList, "Y", siteName);

		return code;

	}
		
	// zd.2024.8.23  取消数据发送MES并更新SENDMESFLAG为N
	public String cancelMaterialInfoSend_NEW(String shipRequestName, String siteName, List<String> boxList)
			throws CustomException {

		String code="";
		String sql="SELECT m.CHARGE FROM  MATERIALPACKING m WHERE m.SITENAME =:SITENAME AND m.MATERIALPACKINGNAME in(:BOXLIST)";
		Map<String,Object> bp=new HashMap<>();
		bp.put("SITENAME", siteName);
		bp.put("BOXLIST", boxList);
		List<Map<String,Object>> sr=IDMFrameServiceProxy.getSqlTemplate().queryForList(sql, bp);
		if(sr.size()>0) 
		{
			JSONArray jsonArray = new JSONArray();
			for (int i = 0; i < sr.size(); i++) 
			{
				JSONObject jsonObject = new JSONObject(true);
				jsonObject.put("consumableName", sr.get(i).get("CHARGE"));
				
				jsonArray.add(jsonObject);
			}
			String cancelMaterialInfoSend = jsonArray.toJSONString();
			System.out.println("JSON=================:" + cancelMaterialInfoSend);
			String httpPost = mesHttpUtil.httpPost(baseUrl + "/wms/consumableReceive", cancelMaterialInfoSend);
			org.json.JSONObject jsonObject = new org.json.JSONObject(httpPost);
			code = jsonObject.getString("code");
	
	//					if (!"00000".equals(code)) {
	//						throw new CustomException("ACTSTATEERROR","","");
	//					}
			String msg = jsonObject.getString("msg");
			// JSONObject object = (JSONObject) jsonObject.get("data");
	
			// 写log
			ErpMessageLog erplog = new ErpMessageLog();
			erplog.setEventUser("");
			erplog.setServerName("WmsToMES");
			erplog.setEventName("needReceiveMaterialInfoSend");
			erplog.setInterfaceTime(TimeStampUtil.getCurrentTime(TimeStampUtil.FORMAT_DEFAULT));
			erplog.setMessageId(UUID.randomUUID().toString());
			erplog.setSendMsg(cancelMaterialInfoSend);
			erplog.setReturnMsg2(httpPost.toString());
			erplog.setResultCode(code);
			MessageLogUtil.writeMessageLog(erplog);
	
			// 更新SENDMESFLAG
			updateSendMesFlag(boxList, "Y", siteName);
		}

		return code;

	}
		//更新标记
		public void updateSendMesFlag (List<String> boxList,String flag,String siteName) 
		{
			String sql="UPDATE MATERIALPACKING m SET m.SENDMESFLAG =:SENDMESFLAG WHERE m.SITENAME =:SITENAME AND m.MATERIALPACKINGNAME in(:BOXLIST)";
			Map<String,Object> bp=new HashMap<>();
			bp.put("SENDMESFLAG", flag);
			bp.put("BOXLIST", boxList);
			bp.put("SITENAME", siteName);
			IDMFrameServiceProxy.getSqlTemplate().update(sql, bp);
		}
	/*
	 * 转换发料Json
	 */
	public String MakeOutMaterialInfoSendJson (List<Map<String, Object>> list,String shipRequestName) {
	
		if (list == null || list.size() < 1) {
			return null;
		}
		JSONArray jsonArray = new JSONArray();
		for (int i = 0; i < list.size(); i++) {
			JSONObject jsonObject = new JSONObject(true);
	
//			"CONSUMABLENAME": "物料批次号123",
//			  "QRCODE": "QR123456789",
//			  "CONSUMABLESPECNAME": "物料料号001",
//			  "CONSUMABLETYPE": "原料",
//			  "PRODUCTREQUESTNAME": "工单0001",
//			  "EXPIRINGDATE": "2023-12-31",
//			  "PRODUCTNAME": "产品A",
//			  "PRODUCTSTAGE": "生产阶段",
//			  "PRACTICALSPEC": "规格尺寸",
//			  "PRODUCTQUANTITY": "100",
//			  "PRODUCTQUANTITYUNIT": "件",
//			  "AUXILIARYUNIT": "箱",
//			  "AUXILIARYQUANTITY": "5",
//			  "USERID": "user123",
//			  "CONVERSIONSCALE": "10",
//			  "FDESCRIPTION": "特殊批次",
//			  "SHIPTYPE": "261",
//			  "RECEIVEFLAG": "Y"
			jsonObject.put("consumableName", list.get(i).get("CHARGE"));
			jsonObject.put("qrCode", list.get(i).get("MATERIALPACKINGNAME"));
			jsonObject.put("consumableSpecName", list.get(i).get("MATERIALSPECNAME"));
			jsonObject.put("consumableType", list.get(i).get("MATERIALTYPE"));
			String product = list.get(i).get("WO").toString();
			jsonObject.put("productRequestName", product.substring(4));
			jsonObject.put("expiringDate", list.get(i).get("EXPIRINGDATE"));
			jsonObject.put("productName", list.get(i).get("DESCRIPTION"));
			jsonObject.put("productStage", list.get(i).get("PHASE"));
			jsonObject.put("practicalSpec", list.get(i).get("TRUEGG"));
			jsonObject.put("productQuantity", list.get(i).get("MATERIALQUANTITY"));
			jsonObject.put("productQuantityUnit", list.get(i).get("MATERIALUNIT"));
			jsonObject.put("auxiliaryUnit", list.get(i).get("FUNIT"));
			jsonObject.put("auxiliaryQuantity", list.get(i).get("FQTY"));
			jsonObject.put("userId", list.get(i).get("LASTEVENTUSER"));
			jsonObject.put("conversionScale", list.get(i).get("CONVERSIONSCALE"));
			jsonObject.put("fdescription", list.get(i).get("REMARK"));
			jsonObject.put("shipType", list.get(i).get("SHIPREQUESTDETAILTYPE"));
			jsonObject.put("shipRequestType", list.get(i).get("SHIPREQUESTTYPE"));
			jsonObject.put("shipRequestName", shipRequestName);
			jsonObject.put("gxId", list.get(i).get("GXID"));
			jsonObject.put("receiveFlag", "N");			
		    
			jsonArray.add(jsonObject);
		}
		
		return jsonArray.toJSONString();
	
	}

	//管芯收货时插入MES的durable表
	public void createDurable (String recieveRequestName, String siteName, String receiveActNo,String user) {
		
		String timeKey=TimeStampUtil.getCurrentEventTimeKey();
		String sql="INSERT INTO MES_DURABLE(DURABLENAME,DURABLETYPE,DURABLESPECNAME,MATERIALLOCATIONNAME,LASTEVENTNAME,LASTEVENTTIMEKEY,\r\n" + 
				" LASTEVENTTIME,LASTEVENTUSER,LASTEVENTCOMMENT,CREATEUSER,CREATETIME)\r\n" + 
				" SELECT m.CHARGE,p.TUBECORETYPE, m.MATERIALSPECNAME,'物流部',:LASTEVENTNAME,:LASTEVENTTIMEKEY,SYSDATE ,:LASTEVENTUSER,\r\n" + 
				" :LASTEVENTCOMMENT,:LASTEVENTUSER,SYSDATE FROM MATERIALPACKING m ,MES_PRODUCTSPEC p \r\n" + 
				" WHERE m.SITENAME =:SITENAME \r\n" + 
				" AND m.RECEIVEREQUESTNAME =:RECEIVEREQUESTNAME\r\n" + 
				" AND m.RECEIVEACTNO =:RECEIVEACTNO\r\n" + 
				" AND m.MATERIALSPECNAME =p.PRODUCTSPECNAME \r\n" + 
				" AND nvl(p.TUBECOREFLAG,'N')='Y'";
		Map<String,Object> bp=new HashMap<>();
		bp.put("SITENAME", siteName);
		bp.put("RECEIVEREQUESTNAME", recieveRequestName);
		bp.put("RECEIVEACTNO", receiveActNo);
		bp.put("LASTEVENTNAME", "durableCreate");
		bp.put("LASTEVENTTIMEKEY", timeKey);
		bp.put("LASTEVENTUSER", user);
		bp.put("LASTEVENTCOMMENT", "");
		IDMFrameServiceProxy.getSqlTemplate().update(sql, bp);
		
		//写入history
		insertDurableHistory(timeKey);
	}
	
	//成本中心领管芯时更新MES的durable表
	public void updateDurable_ByCostcenter(String shipRequestName, String siteName, String user,List<String> boxList) {

		String sql = "SELECT D.DURABLENAME,C.DESCRIPTION FROM MES_DURABLE d \r\n" + 
				" LEFT JOIN MATERIALSHIPREQUESTDETAIL  ms \r\n" + 
				" ON ms.SHIPREQUESTNAME=:SHIPREQUESTNAME\r\n" + 
				" AND ROWNUM=1\r\n" + 
				" LEFT JOIN COSTCENTER c \r\n" + 
				" ON MS.COSTCENTER=C.COSTCENTERNAME\r\n" + 
				" WHERE d.DURABLENAME in(SELECT M.CHARGE FROM MATERIALPACKING m \r\n" + 
				" WHERE m.SITENAME=:SITENAME AND M.MATERIALPACKINGNAME IN(:BOXLIST))";
		Map<String, Object> bp = new HashMap<>();
		bp.put("SITENAME", siteName);
		bp.put("SHIPREQUESTNAME", shipRequestName);
		bp.put("BOXLIST", boxList);
		List<Map<String, Object>> sr=IDMFrameServiceProxy.getSqlTemplate().queryForList(sql, bp);
		
		if(sr.size()>0) 
		{
			List<String> durableList=new ArrayList<String>();
			String location="";
			for(int i=0;i<sr.size();i++) 
			{
				location=sr.get(i).get("DESCRIPTION")==null?"":sr.get(i).get("DESCRIPTION").toString();
				durableList.add(sr.get(i).get("DURABLENAME").toString());
			}
			
			updateDurable(user,location,"durableStockOut",durableList);
		}
		
	}
	
	//通用的更新管芯位置方法
	public void updateDurable(String user,String locationName,String eventName,List<String> durableList) {

		String timeKey = TimeStampUtil.getCurrentEventTimeKey();
		String sql = " UPDATE MES_DURABLE d SET d.MATERIALLOCATIONNAME =:MATERIALLOCATIONNAME,\r\n" + 
				" d.LASTEVENTNAME=:LASTEVENTNAME,d.LASTEVENTTIMEKEY=:LASTEVENTTIMEKEY,LASTEVENTTIME=SYSDATE ,\r\n" + 
				" d.LASTEVENTUSER=:LASTEVENTUSER,LASTEVENTCOMMENT=:LASTEVENTCOMMENT\r\n" + 
				" WHERE d.DURABLENAME in(:DURABLELIST)";
		Map<String, Object> bp = new HashMap<>();
		bp.put("MATERIALLOCATIONNAME", locationName);
		bp.put("DURABLELIST", durableList);
		bp.put("LASTEVENTNAME", eventName);
		bp.put("LASTEVENTTIMEKEY", timeKey);
		bp.put("LASTEVENTUSER", user);
		bp.put("LASTEVENTCOMMENT", "");
		IDMFrameServiceProxy.getSqlTemplate().update(sql, bp);

		// 写入history
		insertDurableHistory(timeKey);
	}
	//插入DurableHistory表
	public void insertDurableHistory (String timekey) 
	{
		String sql="INSERT INTO MES_DURABLEHISTORY\r\n" + 
				" (DURABLENAME, TIMEKEY, EVENTTIME, EVENTNAME, OLDDURABLESPECNAME, DURABLESPECNAME, MATERIALLOCATIONNAME, TIMEUSEDLIMIT, \r\n" + 
				" TIMEUSED, DURATIONUSEDLIMIT, DURATIONUSED, CAPACITY, LOTQUANTITY, OLDFACTORYNAME, FACTORYNAME, OLDAREANAME, AREANAME, \r\n" + 
				" DURABLESTATE, DURABLECLEANSTATE, EVENTUSER, EVENTCOMMENT, REASONCODETYPE, REASONCODE, CONSUMERLOTNAME, CONSUMERPRODUCTNAME,\r\n" + 
				" CONSUMERTIMEKEY, CONSUMERPONAME, TRANSFERSTATE, DURABLEHOLDSTATE, PITCH, MACHINENAME, ZONENAME, PORTNAME, LASTCLEANTIMEKEY,\r\n" + 
				" TOTALTIMEUSED, CLEANDEGREE, CLEANTIME, PRINTCOUNT, RETICLESTATE, LASTLOADTIMEKEY, RETICLESLOT, CLEANFLAG, CLEANSTARTTIMEKEY,\r\n" + 
				" CLEANENDTIMEKEY, CLEANNECESSARY, INSPECTFLAG, INSPECTSTARTTIMEKEY, INSPECTENDTIMEKEY, INSPECTNECESSARY, INSPECTRESULT, POSITIONNAME,\r\n" + 
				" EMPTYSHELFCOUNT, LOTINFOSENDFLAG, TRANSFERTYPE, TENSIONFLAG, TENSIONSTARTTIMEKEY, TENSIONENDTIMEKEY, TENSIONNECESSARY, TENSIONRESULT, \r\n" + 
				" TRANSFERTIMEUSED, TRANSPORTJOBSTATUS, DURABLESIZE, TRANSFERDURABLESPEC, TRANSPORTJOBNAME, MASKUSETYPE, CLEANPRIORITY, RESERVETRANSFERMACHINE, \r\n" + 
				" DURABLEHOLDSTATEBYMCS, REASONCODEBYMCS, REQUESTPITCHSPEC, REQUESTPITCHSPECTIME, MASKCLEANRECIPE, DURABLENOTE, DURABLEHOLDREASONCODE,\r\n" + 
				" CREATETIME, CREATEUSER, DURABLETYPE)\r\n" + 
				" SELECT d.DURABLENAME,d.LASTEVENTTIMEKEY,d.LASTEVENTTIME,d.LASTEVENTNAME,'',d.DURABLESPECNAME,d.MATERIALLOCATIONNAME,\r\n" + 
				" d.TIMEUSEDLIMIT ,TIMEUSED, DURATIONUSEDLIMIT, DURATIONUSED, CAPACITY, LOTQUANTITY, FACTORYNAME, FACTORYNAME, '', AREANAME, \r\n" + 
				" DURABLESTATE, DURABLECLEANSTATE, LASTEVENTUSER, LASTEVENTCOMMENT, REASONCODETYPE, REASONCODE, '', '',\r\n" + 
				" '', '', TRANSFERSTATE, DURABLEHOLDSTATE, PITCH, MACHINENAME, ZONENAME, PORTNAME, LASTCLEANTIMEKEY,\r\n" + 
				" TOTALTIMEUSED, CLEANDEGREE, CLEANTIME, PRINTCOUNT, RETICLESTATE, LASTLOADTIMEKEY, RETICLESLOT, CLEANFLAG, CLEANSTARTTIMEKEY,\r\n" + 
				" CLEANENDTIMEKEY, CLEANNECESSARY, INSPECTFLAG, INSPECTSTARTTIMEKEY, INSPECTENDTIMEKEY, INSPECTNECESSARY, INSPECTRESULT, POSITIONNAME,\r\n" + 
				" EMPTYSHELFCOUNT, LOTINFOSENDFLAG, TRANSFERTYPE, TENSIONFLAG, TENSIONSTARTTIMEKEY, TENSIONENDTIMEKEY, TENSIONNECESSARY, TENSIONRESULT, \r\n" + 
				" TRANSFERTIMEUSED, TRANSPORTJOBSTATUS, DURABLESIZE, TRANSFERDURABLESPEC, TRANSPORTJOBNAME, MASKUSETYPE, CLEANPRIORITY, RESERVETRANSFERMACHINE, \r\n" + 
				" DURABLEHOLDSTATEBYMCS, REASONCODEBYMCS, REQUESTPITCHSPEC, REQUESTPITCHSPECTIME, MASKCLEANRECIPE, DURABLENOTE, DURABLEHOLDREASONCODE,\r\n" + 
				" CREATETIME, CREATEUSER, DURABLETYPE\r\n" + 
				" FROM MES_DURABLE d WHERE d.LASTEVENTTIMEKEY =:LASTEVENTTIMEKEY";
		Map<String,Object> bp=new HashMap<>();
		bp.put("LASTEVENTTIMEKEY", timekey);
		IDMFrameServiceProxy.getSqlTemplate().update(sql, bp);
	}
}
