package com.cim.idm.mwmsextend.materialpackingoqaresult.service;

import java.sql.Timestamp;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import com.cim.idm.wmsextend.generic.GenericServiceProxy;
import org.jdom.Document;
import org.jdom.Element;

import com.cim.idm.framework.IDMFrameServiceProxy;
import com.cim.idm.framework.data.EventInfo;
import com.cim.idm.framework.exception.IDMFrameDBErrorSignal;
import com.cim.idm.framework.util.time.TimeStampUtil;
import com.cim.idm.framework.util.xml.JdomUtils;
import com.cim.idm.mwmsextend.erpinterface.service.ERPInterfaceServiceImpl;
import com.cim.idm.wmsextend.generic.errorHandler.CustomException;
import com.cim.idm.mwmsextend.generic.util.CommonValidation;
import com.cim.idm.wmsextend.generic.util.SMessageUtil;
import com.cim.idm.mwmsextend.materialpacking.service.MaterialPackingServiceImpl;
import com.cim.idm.mwmsextend.materialpacking.service.MaterialPackingServiceUtil;
import com.cim.idm.mwmsextend.materialpackingstockin.service.MaterialPackingStockInImpl;
import com.cim.idm.mwmsextend.materialpackingstockin.service.MaterialStockInClass;
import com.cim.idm.wmspackage.materialpacking.MaterialPackingServiceProxy;
import com.cim.idm.wmspackage.materialpacking.management.data.MaterialPacking;
import com.cim.idm.wmspackage.materialpacking.management.data.MaterialPackingFromTQMS;
import com.cim.idm.wmspackage.materialpacking.management.data.MaterialPackingKey;
import com.cim.idm.wmspackage.materialpacking.management.data.MaterialPackingToTQMS;
import com.cim.idm.wmspackage.materialpacking.management.info.SetEventInfo;
import com.cim.idm.wmspackage.materialprocessgroup.MaterialProcessGroupServiceProxy;
import com.cim.idm.wmspackage.materialprocessgroup.management.data.MaterialProcessGroupKey;
import com.cim.idm.wmspackage.materialprocessgroup.management.info.MaterialProcessGroupSetEventInfo;
import com.cim.idm.wmspackage.materialundo.info.MaterialUnDoinfo;
import com.fasterxml.jackson.databind.ObjectMapper;


public class OQAResultImpl {
	static String factory = System.getProperty("factory");
	public String OQAResultConfirm(String mpgroupName,String okquantity,String ngquantity,String charge){

		String result = "false";
		double okresult = 0;
		double ngresult = 0;
		if(okquantity.equals("0.0") && ngquantity.equals("0.0")){
			
			result = "false";
		}
		List<MaterialPacking> mplist = new OQAResultUtil().GetOQAPackingList(mpgroupName);
		if(mplist.size()>0){
			for(MaterialPacking mp:mplist){
					if(mp.getOqaResultState().equals(GenericServiceProxy.getConstantMap().OQA_State_Continue)&&mp.getOqaResult().equals("OK")){
						okresult = okresult+mp.getMaterialQuantity();
					}else if(mp.getOqaResultState().equals(GenericServiceProxy.getConstantMap().OQA_State_Continue)&&mp.getOqaResult().equals("NG")){
						ngresult = ngresult+mp.getMaterialQuantity();
					}else{
						return result;
					}
			}
			if(okresult==Double.parseDouble(okquantity) && ngresult==Double.parseDouble(ngquantity)){
				result = "OK";
			}
				
		}else{
			mplist = new OQAResultUtil().GetNPOQAPackingList(mpgroupName);
			for(MaterialPacking mp:mplist){
				if(mp.getOqaResultState().equals(GenericServiceProxy.getConstantMap().OQA_State_End)&&mp.getOqaResult().equals("OK")){
					okresult = okresult+mp.getMaterialQuantity();
				}else if(mp.getOqaResultState().equals(GenericServiceProxy.getConstantMap().OQA_State_End)&&mp.getOqaResult().equals("NG")){
					ngresult = ngresult+mp.getMaterialQuantity();
				}else{
					return result;
				}
			}
			if(okresult==Double.parseDouble(okquantity) && ngresult==Double.parseDouble(ngquantity)){
				result = "NPOK";
			}
		}
				
				
		
		return result;
	}
/*
	public String OQAResultConfirm(String erpfactory,String mpgroupName,int okquantity,int ngquantity){
		String result = "Error";
		int okresult = new OQAResultUtil().GetOQAOKResult(erpfactory, mpgroupName);
		int ngresult = new OQAResultUtil().GetOQANGResult(erpfactory, mpgroupName);
		
		if(okresult==okquantity && ngresult==ngquantity){
			result = "NoError";
		}
		return result;
	}
*/	
	public void UpdateOQAState(String mpgroupName,EventInfo eventInfo)throws Exception{
		
		try {
			List<MaterialPacking> mplist = new OQAResultUtil().GetOQAPackingList(mpgroupName);
			List<MaterialPackingKey> mpklist = new ArrayList<MaterialPackingKey>();

			for(MaterialPacking mp:mplist){
				MaterialPackingKey mpkey = new MaterialPackingKey();
				mpkey.setSiteName(mp.getKey().getSiteName());
				mpkey.setMaterialPackingName(mp.getKey().getMaterialPackingName());
				mpklist.add(mpkey);	
				//mp.setOqaResultState(GenericServiceProxy.getConstantMap().OQA_State_End);
			}
				
				SetEventInfo setevent = new SetEventInfo();
				Map<String, Object> bindset = new HashMap<String, Object>();
				bindset.put("oqaResultState", GenericServiceProxy.getConstantMap().OQA_State_End);
				setevent.setUserColumns(bindset);
				MaterialPackingServiceProxy.getMaterialPackingService().setEvent(mpklist, eventInfo, setevent);
				
				
				//更新质检批的状态
				MaterialProcessGroupKey mpgk = new MaterialProcessGroupKey();
				mpgk.setMaterialProcessGroupName(mpgroupName);
				mpgk.setSiteName(mpklist.get(0).getSiteName());		
				MaterialProcessGroupSetEventInfo setEventInfo = new MaterialProcessGroupSetEventInfo();
				Map<String, Object> bindMap = new HashMap<String, Object>();
				bindMap.put("processGroupState",GenericServiceProxy.getConstantMap().OQA_State_End);//以后改成可传参的
				setEventInfo.setUserColumns(bindMap);
				MaterialProcessGroupServiceProxy.getMaterialProcessGroupService().setEvent(mpgk, eventInfo, setEventInfo);
				
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			throw e;
		} 
	}
	
	
	public List<MaterialPacking> PDAGetOQAList(org.jdom.Document doc)throws Exception{
		List<MaterialPacking> mplist = new ArrayList<MaterialPacking>();
		try{
		Element root = doc.getDocument().getRootElement();
		Element bodyElement = root.getChild("Body");
		Element elementList = bodyElement.getChild("OQAJUDGE");		//原来MaterialPackingList，改为OQAJUDGE
		CommonValidation cv=new CommonValidation();		
		//List<MaterialPackingKey> mpklist = new ArrayList<MaterialPackingKey>();
		//String oqaResult = bodyElement.getChild("OQARESULT").toString();		
		//String receiveTime =cv.getDate(bodyElement.getChild("OQAEVENTTIME").getText());//原来RECEIVETIME，改为OQAEVENTTIME
		//if(!cv.checkTime(receiveTime)){
		//	Exception e = new Exception("Stock In Date more than system Date !");
		//}			
		if(elementList != null){
			
				String sitename = elementList.getChild("SITENAME").getText();
				String materialpacking = elementList.getChild("MATERIALPACKINGNAME").getText();
				//String oqaresult = mpelement.getChild("OQARESULT").getText();
				
				MaterialPackingKey mpkey = new MaterialPackingKey();
				mpkey.setSiteName(sitename);
				mpkey.setMaterialPackingName(materialpacking);
				MaterialPacking mp = MaterialPackingServiceProxy.getMaterialPackingService().selectByKey(mpkey);
				//mp.setOqaResult(oqaResult);
				//mp.setOqaResultState(GenericServiceProxy.getConstantMap().OQA_State_Continue);
				mplist.add(mp);
				//mpklist.add(mpkey);
		}
			
			
		}catch(Exception e){
			e.getMessage();
			e.printStackTrace();
			throw e;
		}
		
		return mplist;
	}
	public void UpdateNPOQAInfo(String mpgroupName,EventInfo eventInfo){
		
		List<MaterialPacking> mplist = new OQAResultUtil().GetOQAPackingList(mpgroupName);

		String sql_UndoBoxInfo="UPDATE BS_MATERIALPACKINGUNDOINFO SET UNDOIDSTATE='N' WHERE MATERIALPACKINGNAME IN "
				+ "(SELECT MATERIALPACKINGNAME FROM materialpacking BS "
				+ "WHERE BS.MATERIALPROCESSGROUPNAME =:MATERIALPROCESSGROUPNAME "
				+ "AND BS.SITENAME=:SITENAME) "
				+ "AND UNDOIDSTATE<>'N' "
				+ "AND LASTEVENTNAME='OQAResult'";
						
			Map<String, Object> bindMap_UndoBoxInfo = new HashMap<String, Object>();
			bindMap_UndoBoxInfo.put("SITENAME", mplist.get(0).getKey().getSiteName());
			bindMap_UndoBoxInfo.put("MATERIALPROCESSGROUPNAME", mpgroupName);	
			IDMFrameServiceProxy.getSqlTemplate().update(sql_UndoBoxInfo, bindMap_UndoBoxInfo);
			
	}
	
	//弃用
	public List<MaterialStockInClass> GetOQAGroupInfo(org.jdom.Document doc)throws Exception{
		List<MaterialStockInClass> msalist = new ArrayList<MaterialStockInClass>();
		List<MaterialPacking> mplist = new ArrayList<MaterialPacking>();
		CommonValidation cv=new CommonValidation();
		Element root = doc.getDocument().getRootElement();
		Element bodyElement = root.getChild("Body");
		DecimalFormat df=new DecimalFormat("#.##");
		Element elementList = bodyElement.getChild("MaterialPackingList");		
		//List<MaterialPackingKey> mpklist = new ArrayList<MaterialPackingKey>();
		String oqaResult = bodyElement.getChild("OQARESULT").toString();
		String shiptype = bodyElement.getChild("DESCRIPTION").toString();
		String receivetime =cv.getDate(bodyElement.getChild("RECEIVETIME").toString());
		double materialquantity = 0;
		try{
			if(elementList != null){
				for(Iterator<?> iterator = elementList.getChildren().iterator();iterator.hasNext();){
					Element mpelement = (Element)iterator.next();
					String sitename = mpelement.getChild("SITENAME").getText();
					String materialpacking = mpelement.getChild("MATERIALPACKINGNAME").getText();
					//String oqaresult = mpelement.getChild("OQARESULT").getText();
					
					MaterialPackingKey mpkey = new MaterialPackingKey();
					mpkey.setSiteName(sitename);
					mpkey.setMaterialPackingName(materialpacking);
					MaterialPacking mp = MaterialPackingServiceProxy.getMaterialPackingService().selectByKey(mpkey);
					materialquantity = materialquantity+mp.getMaterialQuantity();
					mp.setOqaResult(oqaResult);
					mp.setOqaResultState(GenericServiceProxy.getConstantMap().OQA_State_Continue);
					mplist.add(mp);
					//mpklist.add(mpkey);
				}

			}
			MaterialStockInClass msa = new MaterialStockInClass();
			msa.setCharge(mplist.get(0).getCharge());
			msa.setErpfactory(mplist.get(0).getErpFactory());
			msa.setErplocation(mplist.get(0).getErpLocation());
			msa.setReceiveTime(receivetime);
			msa.setShipRequestDetailType(shiptype);
			msa.setReceiveQuantity(df.format(materialquantity));
			msa.setGroupName(mplist.get(0).getMaterialProcessGroupName());
			msa.setMaterialSpecName(mplist.get(0).getMaterialSpecName());
			msa.setReceiveActNo(mplist.get(0).getReceiveActNo());
			msa.setReceiveRequestDetailName(mplist.get(0).getReceiveRequestDetailName());
			msa.setReceiveRequestName(mplist.get(0).getReceiveRequestName());
			msalist.add(msa);
			
			
		}catch(Exception e){
			e.getMessage();
			throw e;
		}
		
		return msalist;
	}
	


	public void SaveOQAGroupInfo(EventInfo eventInfo,String sitename,String groupname,int state){
		MaterialProcessGroupKey mpgk = new MaterialProcessGroupKey();
		mpgk.setMaterialProcessGroupName(groupname);
		mpgk.setSiteName(sitename);		
		MaterialProcessGroupSetEventInfo setEventInfo = new MaterialProcessGroupSetEventInfo();
		Map<String, Object> bindMap = new HashMap<String, Object>();
		if(state==1){
			bindMap.put("processGroupState",GenericServiceProxy.getConstantMap().OQA_State_Pre);//以后改成可传参的
		}else if(state==2){
			bindMap.put("processGroupState",GenericServiceProxy.getConstantMap().OQA_State_End);
		}else{
			bindMap.put("processGroupState",GenericServiceProxy.getConstantMap().OQA_State_NO);
		}
		setEventInfo.setUserColumns(bindMap);
		MaterialProcessGroupServiceProxy.getMaterialProcessGroupService().setEvent(mpgk, eventInfo, setEventInfo);
	}
	
	public void PDASaveOQAResult(EventInfo eventInfo, org.jdom.Document doc,String oqaResult,String oqaResultState) throws Exception  
	{			
		  Element root = doc.getDocument().getRootElement();
		  Element materialPackingListElement = root.getChild("Body");
		  String oqaresult="";
		  String oqaresultstate="";
		  try {  
			  SetEventInfo setEventInfo = new SetEventInfo();
				List<MaterialPackingKey> keyList = new ArrayList<MaterialPackingKey>();
				if (materialPackingListElement != null)
				{
					for (Iterator<?> iterator = materialPackingListElement.getChildren().iterator(); iterator.hasNext();)
					{
						Element panelE = (Element) iterator.next();
						MaterialPackingKey materialPackingKey = new MaterialPackingKey();
						materialPackingKey.setSiteName(panelE.getChild("SITENAME").getText());
						materialPackingKey.setMaterialPackingName(panelE.getChild("MATERIALPACKINGNAME").getText());
						oqaresult = panelE.getChild("OQARESULT").getText();
						oqaresultstate = panelE.getChild("OQARESULTSTATE").getText();
						keyList.add(materialPackingKey);
					}
				}

				Map<String, Object> bindMap = new HashMap<String, Object>();
				bindMap.put("oqaResult", oqaresult);
				bindMap.put("oqaResultState", oqaresultstate);
				setEventInfo.setUserColumns(bindMap);
				MaterialPackingServiceProxy.getMaterialPackingService().setEvent(keyList, eventInfo, setEventInfo);
				//doc = PDASearchByBoxList(doc);
		  }
		  catch (IDMFrameDBErrorSignal ex) {
			ex.printStackTrace();
			throw ex;
		}
	}
	public Document PDASearchByBoxList(Document doc) throws Exception  
	{
		Element root = doc.getDocument().getRootElement();
		Element materialPackingListElement = root.getChild("Body");
	  try {
		  
		List<MaterialPackingKey> keyList = new ArrayList<MaterialPackingKey>();
		if (materialPackingListElement != null)
		{
			for (Iterator<?> iterator = materialPackingListElement.getChildren().iterator(); iterator.hasNext();)
			{
				Element panelE = (Element) iterator.next();
				MaterialPackingKey materialPackingKey = new MaterialPackingKey();
				materialPackingKey.setSiteName(panelE.getChild("SITENAME").getText());
				materialPackingKey.setMaterialPackingName(panelE.getChild("MATERIALPACKINGNAME").getText());
				keyList.add(materialPackingKey);	
			}
			
		}
		List<MaterialPacking> boxList = new MaterialPackingServiceUtil().getMaterialPackingListByKeyList(keyList);
		doc = new MaterialPackingServiceUtil().writeDocWithMaterialPackingList(doc,boxList);
		
		return doc;
		}
		 catch (IDMFrameDBErrorSignal ex) {
			ex.printStackTrace();
			throw ex;
		}
	}
	
	public boolean GetUnDoOQAValidation(String mpgroupName,String okquantity,String ngquantity,String allquantity)throws Exception{
				
		boolean result = false;
		double okresult = 0;
		double ngresult = 0;
		try {
			List<MaterialPacking> mplist = new OQAResultUtil().GetOQAPackingList(mpgroupName);
			for(MaterialPacking mp:mplist){
				if(mp.getEtcState() != null && mp.getEtcState().equals("EtcOut")){
					Exception e = new Exception("物料已借出");
					return result;
				}
				if(mp.getOqaResultState().equals("END")){
					
						if(mp.getOqaResult().equals("OK")){
							okresult = okresult +mp.getMaterialQuantity();
						}else if(mp.getOqaResult().equals("NG")){
							ngresult = ngresult +mp.getMaterialQuantity();
						}
										
				}else{
					Exception e = new Exception("物料尚未过账，不能冲销！");
					return result;
				}
											
				}
			if(okresult==Double.parseDouble(okquantity) && ngresult==Double.parseDouble(ngquantity) && okresult+ngresult == Double.parseDouble(allquantity)){
				result = true;
			}
				
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			throw e;
		}
		return result;
	}
	
	
	public void UnDoOQA(List<MaterialPacking> undolist,String undoId,String oldundoId, EventInfo eventinfo){
		for(MaterialPacking mp:undolist){
			mp.setOqaResult("");
			mp.setOqaResultState(GenericServiceProxy.getConstantMap().OQA_State_Pre);
			mp.setUnDoID(undoId);
		}
		MaterialPackingServiceProxy.getMaterialPackingService().update(undolist);
		
		String sql=new MaterialPackingServiceImpl().insertUnDOMaterialPackingInfo_v2;
		
		Map<String, Object> bindMap = new HashMap<String, Object>();
		bindMap.put("undoId", undoId);
		bindMap.put("oldundoId",oldundoId );

		int resultCount	= IDMFrameServiceProxy.getSqlTemplate().update(sql, bindMap);
	}
	
	public void UpdateUnDoOQA(String mpgroupname,String charge, EventInfo eventinfo){
		
		List<MaterialPackingKey> mpklist = new ArrayList<MaterialPackingKey>();
		//List<SetEventInfo> bindlist = new ArrayList<SetEventInfo>();
		List<MaterialPacking> mplist = new OQAResultUtil().GetOQAPackingList(mpgroupname);
		for(MaterialPacking mp:mplist){
			
			MaterialPackingKey mpk = new MaterialPackingKey();
			mpk.setMaterialPackingName(mp.getKey().getMaterialPackingName());
			mpk.setSiteName(mp.getKey().getSiteName());
			mpklist.add(mpk);
			
		}	
		SetEventInfo setevent = new SetEventInfo();
		Map<String, Object> bindset = new HashMap<String, Object>();
		bindset.put("oqaResult", "");
		bindset.put("oqaResultState", GenericServiceProxy.getConstantMap().OQA_State_Pre);
		bindset.put("packingState","G");
		setevent.setUserColumns(bindset);
		
		MaterialPackingServiceProxy.getMaterialPackingService().setEvent(mpklist, eventinfo, setevent);
		
		//更新质检批的状态
		MaterialProcessGroupKey mpgk = new MaterialProcessGroupKey();
		mpgk.setMaterialProcessGroupName(mpgroupname);
		mpgk.setSiteName(mpklist.get(0).getSiteName());		
		MaterialProcessGroupSetEventInfo setEventInfo = new MaterialProcessGroupSetEventInfo();
		Map<String, Object> bindMap = new HashMap<String, Object>();
		bindMap.put("processGroupState",GenericServiceProxy.getConstantMap().OQA_State_Pre);//以后改成可传参的
		setEventInfo.setUserColumns(bindMap);
		MaterialProcessGroupServiceProxy.getMaterialProcessGroupService().setEvent(mpgk, eventinfo, setEventInfo);

	}
	
	public List<MaterialPacking> GetOQAList(org.jdom.Document doc)throws Exception{
		List<MaterialPacking> mplist = new ArrayList<MaterialPacking>();
		try{
		Element root = doc.getDocument().getRootElement();
		Element bodyElement = root.getChild("Body");
		Element elementList = bodyElement.getChild("MaterialPackingList");		
		CommonValidation cv=new CommonValidation();
		//List<MaterialPackingKey> mpklist = new ArrayList<MaterialPackingKey>();
		//String oqaResult = bodyElement.getChild("OQARESULT").toString();
		String receiveTime =cv.getDate(bodyElement.getChild("RECEIVETIME").getText());
		if(!cv.checkTime(receiveTime)){
			Exception e = new Exception("Stock In Date more than system Date !");
		}
				
		if(elementList != null){
			
			for(Iterator<?> iterator = elementList.getChildren().iterator();iterator.hasNext();){
				Element mpelement = (Element)iterator.next();
				String sitename = mpelement.getChild("SITENAME").getText();
				String materialpacking = mpelement.getChild("MATERIALPACKINGNAME").getText();
				//String oqaresult = mpelement.getChild("OQARESULT").getText();
				
				MaterialPackingKey mpkey = new MaterialPackingKey();
				mpkey.setSiteName(sitename);
				mpkey.setMaterialPackingName(materialpacking);
				MaterialPacking mp = MaterialPackingServiceProxy.getMaterialPackingService().selectByKey(mpkey);
				//mp.setOqaResult(oqaResult);
				//mp.setOqaResultState(GenericServiceProxy.getConstantMap().OQA_State_Continue);
				mplist.add(mp);
				//mpklist.add(mpkey);
			}

		}
			
			
		}catch(Exception e){
			e.getMessage();
			throw e;
		}
		
		return mplist;
	}
	//防止重复发送
	public void checkOQAResult(String type, List<MaterialPacking> mpList,String sitename) throws CustomException
	{
		try
		{
			
			StringBuilder sb=new StringBuilder();
			sb.append("SELECT OQARESULT,MATERIALPACKINGNAME FROM  MATERIALPACKING " 
						+" WHERE MATERIALPACKINGNAME IN ( ");				
			for (MaterialPacking mp : mpList) {
				sb.append("'"+mp.getKey().getMaterialPackingName()+"',");					
			}
			sb.deleteCharAt(sb.length()-1);
			sb.append(" ) AND SITENAME=:SITENAME GROUP BY OQARESULT,MATERIALPACKINGNAME  ");
			Map<String, Object> map=new HashMap<String, Object>();
			map.put("SITENAME", sitename);
			List<Map<String,Object>> sortList=IDMFrameServiceProxy.getSqlTemplate().queryForList(sb.toString(), map);
			
		for (Map<String,Object> mp : sortList) 
		{
			 if(type.equals("NoValueChangeOQAResult")||type.equals("NoValueCancelOQA"))
			   {
				 if(mp.get("OQARESULT")!=""&&mp.get("OQARESULT")!=null)
					 continue;
				  else
				 {	
					
					throw new CustomException("质检结果不能为空，请确认！", "");
				}
			  }else if(type.equals("NoValueOQAResult"))
			  {
				 if(mp.get("OQARESULT")==""||mp.get("OQARESULT")==null)
					 continue;
				 else
				 {	
					throw new CustomException("质检结果不为空，请确认", "");
				 }
			}
		}
		}catch(CustomException ce){
			ce.printStackTrace();			
			throw new CustomException("质检结果与质检行为不符，请确认", "");
		}		
	}


	
	public void SaveChangeOQAResult(List<MaterialPacking> mplist,List<MaterialUnDoinfo> undolist,String shiptype,String result,String receivetime,EventInfo eventInfo)
			throws Exception{
		
		try {
			CommonValidation cv=new CommonValidation();
			if(mplist!=null && undolist!=null){
				
				if(mplist.size()==undolist.size()){
					List<MaterialPackingKey> mpklist = new ArrayList<MaterialPackingKey>();
					List<SetEventInfo> setlist = new ArrayList<SetEventInfo>();
					Date date = new Date();
					SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
					String systemdate = df.format(date);
					for(int i=0;i<mplist.size();i++){
						MaterialPacking mp = mplist.get(i);
						MaterialUnDoinfo undo = undolist.get(i);
						MaterialPackingKey mpkey = new MaterialPackingKey();
						mpkey.setSiteName(mp.getKey().getSiteName());
						mpkey.setMaterialPackingName(mp.getKey().getMaterialPackingName());
						mpklist.add(mpkey);	
						if(mp.getMaterialPackingType().equals("Pallet"))
						{
							String queryPallet="SELECT MATERIALPACKINGNAME FROM MATERIALPACKING WHERE SUPERMATERIALPACKINGNAME=:SUPERMATERIALPACKINGNAME";
							Map<String,Object> map=new HashMap<String, Object>();
							map.put("SUPERMATERIALPACKINGNAME", mpkey.getMaterialPackingName());
							List<Map<String,Object>> boxList=IDMFrameServiceProxy.getSqlTemplate().queryForList(queryPallet, map);
							if(boxList.size()>0)
							{ 							
								//获取该pallet下所有box
								for(int m= 0;m<boxList.size();m++)
								{
									mpkey.setMaterialPackingName(boxList.get(m).get("MATERIALPACKINGNAME").toString());								
									mpklist.add(mpkey);
								}							
							}	
						}
						SetEventInfo setevent = new SetEventInfo();
						Map<String, Object> bindMap = new HashMap<String, Object>();
						if(mp.getOqaResultState()!=null && mp.getOqaResultState().equals("END")){
							bindMap.put("oqaResult",result);
							bindMap.put("oqaResultState",GenericServiceProxy.getConstantMap().OQA_State_End);
							bindMap.put("packingGrade", result);
							bindMap.put("erpEventTime", Timestamp.valueOf(cv.getDate(receivetime) +" 00:00:00"));							
							//bindMap.put("receiveTime", systemdate);
							bindMap.put("unDoID", undo.getUnDoID());
							bindMap.put("unDoDetailName", undo.getUnDoDetailName());
							bindMap.put("erpState", "SUCCESS");
						}else{
							bindMap.put("packingGrade", result);
							bindMap.put("erpEventTime", Timestamp.valueOf(receivetime+" 00:00:00"));							
							//bindMap.put("receiveTime", systemdate);
							bindMap.put("unDoID", undo.getUnDoID());
							bindMap.put("unDoDetailName", undo.getUnDoDetailName());
							bindMap.put("erpState", "SUCCESS");
							//bindMap.put(key, undo.getUnDoIdDate());
						}
							
												
						setevent.setUserColumns(bindMap);
						setlist.add(setevent);
						
					}
					
					MaterialPackingServiceProxy.getMaterialPackingService().setEvent(mpklist, eventInfo, setlist);
				}
				new MaterialPackingStockInImpl().SaveUnDoInfo(mplist.get(0).getReceiveActNo(),undolist.get(0).getUnDoIdDate(),undolist.get(0).getUnDoID());
			}
					
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			throw e;
		}
	
	}
	
	
	public void SaveNoValueOQAResult(List<MaterialPacking> mplist,List<MaterialUnDoinfo> undolist,String shiptype,String result,String receivetime,String type,EventInfo eventInfo)
			throws Exception{
		
		try {
			CommonValidation cv=new CommonValidation();
			if(mplist!=null && undolist!=null){
					List<MaterialPackingKey> mpklist = new ArrayList<MaterialPackingKey>();
					List<SetEventInfo> setlist = new ArrayList<SetEventInfo>();
					Date date = new Date();
					SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
					String systemdate = df.format(date);
					for(int i=0;i<mplist.size();i++){
						MaterialPacking mp = mplist.get(i);
						MaterialUnDoinfo undo = undolist.get(0);
						MaterialPackingKey mpkey = new MaterialPackingKey();
						mpkey.setSiteName(mp.getKey().getSiteName());
						mpkey.setMaterialPackingName(mp.getKey().getMaterialPackingName());
						mpklist.add(mpkey);	
						if(mp.getMaterialPackingType().equals("Pallet"))
						{
							String queryPallet="SELECT MATERIALPACKINGNAME FROM MATERIALPACKING WHERE SUPERMATERIALPACKINGNAME=:SUPERMATERIALPACKINGNAME";
							Map<String,Object> map=new HashMap<String, Object>();
							map.put("SUPERMATERIALPACKINGNAME", mpkey.getMaterialPackingName());
							List<Map<String,Object>> boxList=IDMFrameServiceProxy.getSqlTemplate().queryForList(queryPallet, map);
							if(boxList.size()>0)
							{ 							
								//获取该pallet下所有box
								for(int m= 0;m<boxList.size();m++)
								{
									mpkey.setMaterialPackingName(boxList.get(m).get("MATERIALPACKINGNAME").toString());								
									mpklist.add(mpkey);
								}							
							}	
						}
						SetEventInfo setevent = new SetEventInfo();
						Map<String, Object> bindMap = new HashMap<String, Object>();
						if(type.equals("NoValueOQAResult")){
								if(result.equals("OKEY"))
								{
									result="OK";
									bindMap.put("oqaMethod","MRB");
								}
								bindMap.put("oqaResult",result);
								bindMap.put("oqaResultState",GenericServiceProxy.getConstantMap().OQA_State_End);	
								bindMap.put("packingGrade", result);								
						}else if(type.equals("NoValueCancelOQA")){
							if(mp.getMaterialProcessGroupName().equals("OICOQA")){
								bindMap.put("oqaResult","");
								bindMap.put("oqaResultState",GenericServiceProxy.getConstantMap().OQA_State_Pre);
								bindMap.put("packingGrade", "");
								bindMap.put("oqaMethod","");
							}else if(mp.getMaterialProcessGroupName() ==null ||mp.getMaterialProcessGroupName().equals("")){
								bindMap.put("oqaResult","");
								bindMap.put("oqaResultState",GenericServiceProxy.getConstantMap().OQA_State_Pre);
								bindMap.put("packingGrade", "");
								bindMap.put("materialProcessGroupName", "OICOQA");
								bindMap.put("oqaMethod","");
							}else if(mp.getMaterialProcessGroupName().startsWith("BOE-IQC")){
								bindMap.put("oqaResult","");
								bindMap.put("oqaResultState",GenericServiceProxy.getConstantMap().OQA_State_Pre);
								bindMap.put("packingGrade", "");
								bindMap.put("materialProcessGroupName", "OICOQA");
								bindMap.put("oqaMethod","");
							}
							
						}else if(type.equals("NoValueChangeOQAResult")){	
							if(result.equals("OKEY"))
							{
								result="OK";
								bindMap.put("oqaMethod","MRB");
							}
							bindMap.put("oqaResult",result);
							bindMap.put("packingGrade", result);
							
						}
							
							bindMap.put("erpEventTime", Timestamp.valueOf(cv.getDate(receivetime) +" 00:00:00"));							
							//bindMap.put("receiveTime", systemdate);
							bindMap.put("unDoID", undo.getUnDoID());
							bindMap.put("unDoDetailName", undo.getUnDoDetailName());
							bindMap.put("erpState","SUCCESS");
							//bindMap.put(key, undo.getUnDoIdDate());
												
						setevent.setUserColumns(bindMap);
						setlist.add(setevent);
						
					MaterialPackingServiceProxy.getMaterialPackingService().setEvent(mpklist, eventInfo, setlist);
				}
				new MaterialPackingStockInImpl().SaveUnDoInfo(mplist.get(0).getReceiveActNo(),undolist.get(0).getUnDoIdDate(),undolist.get(0).getUnDoID());
			}
					
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			throw e;
		}
	
	}

	// 上线物料临时表 过滤
		public String isTempMaterialTrue(String mpgroupName,String siteName,String materialSpecName){
			// List<MaterialPacking> mplist = new OQAResultUtil().GetOQAPackingList(mpgroupName);
			String sql = "select MATERIALSPECNAME from BS_TMP_MATERIAL_FORRELASE where SITENAME=? AND MATERIALSPECNAME=?";
			  
			 List<Map<String, Object>> list = IDMFrameServiceProxy.getSqlTemplate().queryForList(sql, siteName,materialSpecName);
			 
			 if(list != null && list.size()>0){
				 return "true";
			 }
			
			 //return "true";
			return "false";
		}
		
	public void SaveOQAResultInfo(org.jdom.Document doc,EventInfo eventInfo,MaterialUnDoinfo undoinfo,String groupname)throws Exception{
		
		try {
			Element root = doc.getDocument().getRootElement();
			Element bodyElement = root.getChild("Body");
			Element elementList = bodyElement.getChild("MaterialPackingList");
			List<MaterialPackingKey> keyList = new ArrayList<MaterialPackingKey>();
			List<SetEventInfo> setList = new ArrayList<SetEventInfo>();
			
				if(elementList != null){
					for(Iterator<?> iterator = elementList.getChildren().iterator();iterator.hasNext();){
						Element mpelement = (Element)iterator.next();
						String sitename = mpelement.getChild("SITENAME").getText();
						String materialpacking = mpelement.getChild("MATERIALPACKINGNAME").getText();	
						MaterialPackingKey mpkey = new MaterialPackingKey();
						mpkey.setSiteName(sitename);
						mpkey.setMaterialPackingName(materialpacking);
						keyList.add(mpkey);			
						MaterialPacking mp=MaterialPackingServiceProxy.getMaterialPackingService().selectByKey(mpkey);
						if(mp.getMaterialPackingType().equals("Pallet"))
						{
							String queryPallet="SELECT MATERIALPACKINGNAME FROM MATERIALPACKING WHERE SUPERMATERIALPACKINGNAME=:SUPERMATERIALPACKINGNAME";
							Map<String,Object> map=new HashMap<String, Object>();
							map.put("SUPERMATERIALPACKINGNAME", mpkey.getMaterialPackingName());
							List<Map<String,Object>> boxList=IDMFrameServiceProxy.getSqlTemplate().queryForList(queryPallet, map);
							if(boxList.size()>0)
							{ 							
								//获取该pallet下所有box
								for(int m= 0;m<boxList.size();m++)
								{
									mpkey.setMaterialPackingName(boxList.get(m).get("MATERIALPACKINGNAME").toString());								
									keyList.add(mpkey);
								}							
							}	
						}
					}
				}
			//存储BOX信息
			SetEventInfo setevent = new SetEventInfo();
			Map<String, Object> bindMap = new HashMap<String, Object>();
			bindMap.put("oqaResultState",GenericServiceProxy.getConstantMap().OQA_State_End);//以后改成可传参的
			bindMap.put("unDoID", undoinfo.getUnDoID());
			bindMap.put("unDoDetailName", undoinfo.getUnDoDetailName());
			bindMap.put("erpState", "SUCCESS");

			setevent.setUserColumns(bindMap);
			MaterialPackingServiceProxy.getMaterialPackingService().setEvent(keyList, eventInfo, setevent);
			//存储undo信息
			new MaterialPackingStockInImpl().SaveOQAUnDoInfo(undoinfo.getUnDoIdDate(), undoinfo.getUnDoID());
//			String condition = "select * from MaterialProcessGroup where materialProcessGroupName=? and siteName='TM1'";
//			Object[] bindSet={groupname};
//			String[][] resultList  = IDMFrameServiceProxy.getSqlTemplate().queryForStringArray(condition,bindSet); 
			
			//更新质检批信息
			SaveOQAGroupInfo(eventInfo,keyList.get(0).getSiteName(),groupname,2);
		
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			throw e;
		}
	}
	
	public void SaveCancelOQAInfo(String sitename,EventInfo eventInfo,MaterialUnDoinfo undoinfo,String groupname)throws Exception{
		
		try {
			
			List<MaterialPackingKey> keyList = new ArrayList<MaterialPackingKey>();
			List<MaterialPacking> mpList = new OQAResultUtil().GetOQAPackingList(groupname);
				if(mpList.size()>0){
					for(MaterialPacking mp:mpList){
						keyList.add(mp.getKey());	
						if(mp.getMaterialPackingType().equals("Pallet"))
						{
							String queryPallet="SELECT MATERIALPACKINGNAME FROM MATERIALPACKING WHERE SUPERMATERIALPACKINGNAME=:SUPERMATERIALPACKINGNAME";
							Map<String,Object> map=new HashMap<String, Object>();
							map.put("SUPERMATERIALPACKINGNAME", mp.getKey().getMaterialPackingName());
							List<Map<String,Object>> boxList=IDMFrameServiceProxy.getSqlTemplate().queryForList(queryPallet, map);
							if(boxList.size()>0)
							{ 							
								//获取该pallet下所有box
								for(int m= 0;m<boxList.size();m++)
								{
									mp.getKey().setMaterialPackingName(boxList.get(m).get("MATERIALPACKINGNAME").toString());								
									keyList.add(mp.getKey());
								}							
							}	
						}
					}
				}else{
					throw new Exception("NO MaterailPacking in the OQAGroup !");
				}
			//存储BOX信息
			SetEventInfo setevent = new SetEventInfo();
			Map<String, Object> bindMap = new HashMap<String, Object>();
			bindMap.put("oqaResultState",GenericServiceProxy.getConstantMap().OQA_State_Pre);//以后改成可传参的
			bindMap.put("packingGrade","");
			bindMap.put("oqaResult","");
			bindMap.put("unDoID", undoinfo.getUnDoID());
			bindMap.put("unDoDetailName", undoinfo.getUnDoDetailName());
			bindMap.put("erpState", "SUCCESS");
			setevent.setUserColumns(bindMap);
			MaterialPackingServiceProxy.getMaterialPackingService().setEvent(keyList, eventInfo, setevent);
			//存储undo信息
			new MaterialPackingStockInImpl().SaveOQAUnDoInfo(undoinfo.getUnDoIdDate(), undoinfo.getUnDoID());
			//更新质检批信息
			SaveOQAGroupInfo(eventInfo,sitename,groupname,1);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			throw e;
		}
	}
	
	public String sendStockInformation(List<MaterialPackingFromTQMS> mpList,EventInfo eventInfo) throws Exception
	{
		String querySql="SELECT MP.SITENAME,MP.RECEIVEACTNO,MP.MATERIALSPECNAME,MS.DESC_CN,MP.SUPPLIERNAME AS SUPPLIERNO,S.SUPPLIERNAME,MP.MATERIALPROCESSGROUPNAME,MP.MATERIALPACKINGNAME,MP.OQARESULT,MP.OQAMETHOD,MP.HOLDSTATE,MP.PROCESSSTATE,MP.MATERIALQUANTITY,MP.STOCKSTATE,MP.REASONCODE,MP.REMARK" 
                             +" FROM MATERIALPACKING MP"  
                             +" LEFT JOIN SUPPLIER S ON S.SUPPLIERNO=MP.SUPPLIERNAME" 
                             +" LEFT JOIN MATERIALSPEC MS ON MS.SITENAME=MP.SITENAME AND MS.MATERIALSPECNAME=MP.MATERIALSPECNAME"                             
                             +" WHERE (:SITENAME IS NULL OR MP.SITENAME=:SITENAME)"
                             +" AND (:MATERIALPROCESSGROUPNAME IS NULL OR MP.MATERIALPROCESSGROUPNAME=:MATERIALPROCESSGROUPNAME)"
                             +" AND (:SUPPLIERNO IS NULL OR MP.SUPPLIERNAME=:SUPPLIERNO)"
                             +" AND (:MATERIALPACKINGNAME IS NULL OR MP.MATERIALPACKINGNAME LIKE :MATERIALPACKINGNAME)"
                             +" AND (:MATERIALSPECNAME IS NULL OR MP.MATERIALSPECNAME=:MATERIALSPECNAME)"
                             +" AND (:RECEIVEACTNO IS NULL OR MP.RECEIVEACTNO=:RECEIVEACTNO)"
                             +" AND PACKINGSTATE <> 'Empty'"
                             +" GROUP BY MP.SITENAME,MP.RECEIVEACTNO,MP.MATERIALSPECNAME,MS.DESC_CN,MP.SUPPLIERNAME,S.SUPPLIERNAME,MP.MATERIALPROCESSGROUPNAME,MP.MATERIALPACKINGNAME,MP.OQARESULT,MP.OQAMETHOD,MP.HOLDSTATE,MP.PROCESSSTATE,MP.MATERIALQUANTITY,MP.STOCKSTATE,MP.REASONCODE,MP.REMARK";
		Map<String,Object> map=new HashMap<String, Object>();
		map.put("SITENAME", mpList.get(0).getSiteName());
		map.put("MATERIALPROCESSGROUPNAME", mpList.get(0).getMaterialProcessGroupName());
		map.put("SUPPLIERNO", mpList.get(0).getSupplierNO());
		if(!mpList.get(0).getMaterialPackingName().isEmpty())
			map.put("MATERIALPACKINGNAME", mpList.get(0).getMaterialPackingName()+"%");
		else
			map.put("MATERIALPACKINGNAME", null);
		map.put("MATERIALSPECNAME", mpList.get(0).getMaterialSpecName());
		map.put("RECEIVEACTNO", mpList.get(0).getReceiveActNO());
		List<Map<String,Object>> result=IDMFrameServiceProxy.getSqlTemplate().queryForList(querySql, map);
		List<MaterialPackingToTQMS> toList=new ArrayList<MaterialPackingToTQMS>();		
		for(int i=0;i<result.size();i++)
		{
			MaterialPackingToTQMS mp=new MaterialPackingToTQMS();
			mp.setSiteName(result.get(i).get("SITENAME").toString());
			mp.setReceiveActNo(result.get(i).get("RECEIVEACTNO")!=null?result.get(i).get("RECEIVEACTNO").toString():"");
			mp.setMaterialSpecName(result.get(i).get("MATERIALSPECNAME")!=null?result.get(i).get("MATERIALSPECNAME").toString():"");
			mp.setDesc_cn(result.get(i).get("DESC_CN")!=null?result.get(i).get("DESC_CN").toString():"");
			mp.setSupplierNO(result.get(i).get("SUPPLIERNO")!=null?result.get(i).get("SUPPLIERNO").toString():"");
			mp.setSupplierName(result.get(i).get("SUPPLIERNAME")!=null?result.get(i).get("SUPPLIERNAME").toString():"");
			mp.setMaterialProcessGroupName(result.get(i).get("MATERIALPROCESSGROUPNAME")!=null?result.get(i).get("MATERIALPROCESSGROUPNAME").toString():"");
			mp.setMaterialPackingName(result.get(i).get("MATERIALPACKINGNAME").toString());
			mp.setOqaMethod(result.get(i).get("OQAMETHOD")!=null?result.get(i).get("OQAMETHOD").toString():"");
		    map.put("MATERIALPACKINGNAME", mpList.get(0).getMaterialPackingName()+"%");
            mp.setProcessState((result.get(i).get("HOLDSTATE")!=null?result.get(i).get("HOLDSTATE").toString():"").equals("Y")?"Holding":"Release");
			mp.setMaterialQuantity(result.get(i).get("MATERIALQUANTITY")!=null?result.get(i).get("MATERIALQUANTITY").toString():"");
			mp.setStockState(result.get(i).get("STOCKSTATE")!=null?result.get(i).get("STOCKSTATE").toString():"");
			mp.setOqaResult(result.get(i).get("OQARESULT")!=null?result.get(i).get("OQARESULT").toString():"");
			mp.setReasonCode(result.get(i).get("REASONCODE")!=null?result.get(i).get("REASONCODE").toString():"");
			mp.setRemark(result.get(i).get("REMARK")!=null?result.get(i).get("REMARK").toString():"");
			toList.add(mp);			
		}
		
//		String interfaceName="INT_WMB008";
		ObjectMapper objectMapper=new ObjectMapper(); 				
//		Document doc=SMessageUtil.createTQMSXmlDocument(interfaceName,objectMapper.writeValueAsString(toList));						
//		String replyMSG=JdomUtils.toString(doc);									
////		String replyMSG=objectMapper.writeValueAsString(totalList);
//		String eventTimeKey=TimeStampUtil.getCurrentEventTimeKey();
//		MaterialPackingFromTQMS  pireturn=ERPInterfaceServiceImpl.saveBSMEssageLogByTQMS(interfaceName, eventTimeKey, eventInfo.getEventUser(),objectMapper.writeValueAsString(toList).toString().substring(1,objectMapper.writeValueAsString(toList).length()-1 ));
		return objectMapper.writeValueAsString(toList).toString();
		
	}
	
	public void updatePalletOQAResult(String siteName,String processGroupName,EventInfo evetInfo) throws CustomException
	{
		try
		{
			//根据质检批查找PalletID
			String queryPalletList="SELECT DISTINCT MP.SUPERMATERIALPACKINGNAME FROM MATERIALPACKING MP" 
							       +" WHERE MP.SITENAME=:SITENAME AND MP.MATERIALPROCESSGROUPNAME=:MATERIALPROCESSGROUPNAME"
							       +" AND MP.MATERIALPACKINGTYPE='Box'";
			Map<String,Object> pMap=new HashMap<String, Object>();
			pMap.put("SITENAME", siteName);
			pMap.put("MATERIALPROCESSGROUPNAME", processGroupName);
			List<Map<String,Object>> palletList=IDMFrameServiceProxy.getSqlTemplate().queryForList(queryPalletList, pMap);
			if(palletList!=null&&palletList.size()>0&&palletList.get(0).get("SUPERMATERIALPACKINGNAME") != null)
			{
				for(int i=0;i<palletList.size();i++)
				{
					String queryPackingGrade="SELECT DISTINCT MP.PACKINGGRADE FROM MATERIALPACKING MP"
											+" WHERE MP.SITENAME=:SITENAME AND MP.SUPERMATERIALPACKINGNAME=:SUPERMATERIALPACKINGNAME AND MP.MATERIALPACKINGTYPE='Box'";
					Map<String,Object> bMap=new HashMap<String, Object>();
					bMap.put("SITENAME", siteName);
					bMap.put("SUPERMATERIALPACKINGNAME", palletList.get(i).get("SUPERMATERIALPACKINGNAME").toString());
					List<Map<String,Object>> oqaList=IDMFrameServiceProxy.getSqlTemplate().queryForList(queryPackingGrade, bMap);
					if(oqaList.size()==1&& !oqaList.get(0).get("PACKINGGRADE").toString().equals(""))
					{
						MaterialPackingKey mpKey=new MaterialPackingKey();
						mpKey.setSiteName(siteName);
						mpKey.setMaterialPackingName(palletList.get(i).get("SUPERMATERIALPACKINGNAME").toString());
						MaterialPacking mp=MaterialPackingServiceProxy.getMaterialPackingService().selectByKey(mpKey);
						mp.setPackingGrade(oqaList.get(0).get("PACKINGGRADE").toString());
						mp.setOqaResult(oqaList.get(0).get("PACKINGGRADE").toString());
						mp.setOqaResultState("END");
						mp.setLastEventName(evetInfo.getEventName());
						mp.setLastEventUser(evetInfo.getEventUser());
						mp.setLastEventTime(evetInfo.getEventTime());
						MaterialPackingServiceProxy.getMaterialPackingService().update(mp);
					}
				}
			}
		}
		catch(Exception e)
		{
			e.printStackTrace();
			throw new CustomException("PALLET-003","","");
			
		}
	}
	public void updatePalletOQAResultByBoxList(String siteName,List<MaterialPacking> mpList,EventInfo evetInfo) throws CustomException
	{
		try
		{
			if(mpList.size()>0)
			{
				for (MaterialPacking materialPacking : mpList) 
				{	
					if(!materialPacking.getSuperMaterialPackingName().equals("")&&materialPacking.getMaterialPackingType().equals("Box"))
					{
						String queryPackingGrade="SELECT DISTINCT MP.PACKINGGRADE FROM MATERIALPACKING MP"
												+" WHERE MP.SITENAME=:SITENAME AND MP.SUPERMATERIALPACKINGNAME=:SUPERMATERIALPACKINGNAME AND MP.MATERIALPACKINGTYPE='Box'";
						Map<String,Object> bMap=new HashMap<String, Object>();
						bMap.put("SITENAME", siteName);
						bMap.put("SUPERMATERIALPACKINGNAME", materialPacking.getSuperMaterialPackingName());
						List<Map<String,Object>> oqaList=IDMFrameServiceProxy.getSqlTemplate().queryForList(queryPackingGrade, bMap);
						if(oqaList.size()==1&&oqaList.get(0).get("PACKINGGRADE")!=null&& !oqaList.get(0).get("PACKINGGRADE").toString().equals(""))
						{
							MaterialPackingKey mpKey=new MaterialPackingKey();
							mpKey.setSiteName(siteName);
							mpKey.setMaterialPackingName(materialPacking.getSuperMaterialPackingName());
							MaterialPacking mp=MaterialPackingServiceProxy.getMaterialPackingService().selectByKey(mpKey);
							mp.setPackingGrade(oqaList.get(0).get("PACKINGGRADE").toString());
							mp.setOqaResult(oqaList.get(0).get("PACKINGGRADE").toString());
							mp.setOqaResultState("END");
							mp.setLastEventName(evetInfo.getEventName());
							mp.setLastEventUser(evetInfo.getEventUser());
							mp.setLastEventTime(evetInfo.getEventTime());
							MaterialPackingServiceProxy.getMaterialPackingService().update(mp);
						}
					}
				}
			}
		}
		catch(Exception e)
		{
			e.printStackTrace();
			throw new CustomException("PALLET-003","","");			
		}
	}
}
