package com.cim.idm.service.Impl;

import com.cim.idm.exception.GlobalException;
import com.cim.idm.framework.IDMFrameServiceProxy;
import com.cim.idm.framework.data.EventInfo;
import com.cim.idm.framework.exception.ext.NotFoundSignal;
import com.cim.idm.model.ReceiveInstockDto;
import com.cim.idm.service.IMaterialReceiveService;
import com.cim.idm.wmsextend.generic.errorHandler.CustomException;
import com.cim.idm.wmspackage.material.MaterialServiceProxy;
import com.cim.idm.wmspackage.material.management.data.MaterialSpec;
import com.cim.idm.wmspackage.material.management.data.MaterialSpecKey;
import com.cim.idm.wmspackage.materialpacking.MaterialPackingServiceProxy;
import com.cim.idm.wmspackage.materialpacking.management.data.MaterialPacking;
import com.cim.idm.wmspackage.materialpacking.management.data.MaterialPackingKey;
import com.cim.idm.wmspackage.materialpacking.management.info.CreateInfo;
import com.cim.idm.wmspackage.materialpacking.management.info.SetEventInfo;
import com.cim.idm.wmspackage.product.ProductServiceProxy;
import com.cim.idm.wmspackage.product.management.data.Product;
import com.cim.idm.wmspackage.product.management.data.ProductKey;
import com.cim.idm.wmspackage.product.management.info.RemoveInfo;
import com.cim.idm.wmspackage.receiverequestdetail.ReceiveRequestDetailServiceProxy;
import com.cim.idm.wmspackage.receiverequestdetail.management.data.MaterialReceiveRequestDetail;
import com.cim.idm.wmspackage.receiverequestdetail.management.data.MaterialReceiveRequestDetailKey;
import com.cim.idm.wmspackage.receiverequestdetail.management.info.MakeDetailIncreaseReceivedInfo;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;

import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.util.*;

@Service
public class MaterialReceiveServiceImpl implements IMaterialReceiveService {
	
	
	@Override
	public Map<String, Object> materialDbIntostock(ReceiveInstockDto receiveInstockDto) throws Throwable{
		String barCode = receiveInstockDto.getBarCode();
		String detailNo = receiveInstockDto.getDetailNo();
		String userId = receiveInstockDto.getUserId();
		String billNo = receiveInstockDto.getBillNo();
		String site = receiveInstockDto.getSiteName();
		if(Objects.isNull(barCode)) {
			throw new GlobalException("条码不能为空！");
		}
		if(Objects.isNull(detailNo)) {
			throw new GlobalException("明细行号能为空！");
		}
		if(Objects.isNull(userId)) {
			throw new GlobalException("用户名不能为空！");
		}
		Map<String, Object> map = new HashMap<String, Object>();
		// 将前端传入的参数和存储过程中的参数相对应起来
				map.put("V_BARCODE",barCode);
				map.put("V_DETAILROWNO",detailNo);
				map.put("V_USERID",userId);
				map.put("V_SITE",site);
				map.put("V_BILLNO",billNo);
				String procedureName = "RECEIVE_TRANSFERSL";//数据库中存储过程的名字
				return doProcedure(procedureName,map);//调用存储过程，返回map
	}
	

	/**
	 * 调用入库绑定存储过程 RECEIVE_SLNOTICE_INSTOCK_DIRECT 收料入库
	 */
	@Override
	public Map<String, Object> receiveInstock(ReceiveInstockDto receiveInstockDto) throws Throwable {
		String barCode = receiveInstockDto.getBarCode();
		String storageName = receiveInstockDto.getStorageName();
		String userId = receiveInstockDto.getUserId();
		String result = receiveInstockDto.getResult();
		if (Objects.isNull(barCode)) {
			throw new GlobalException("barCode不能为空！");
		}
		if (Objects.isNull(storageName)) {
			throw new GlobalException("storageName能为空！");
		}
		if (Objects.isNull(userId)) {
			throw new GlobalException("userId不能为空！");
		}
		Map<String, Object> map = new HashMap<String, Object>();
		// 将前端传入的参数和存储过程中的参数对应起来
		map.put("V_BARCODE", barCode);
		map.put("V_KW", storageName);
		map.put("V_USERID", userId);
		map.put("V_RESULT", "");
		/*
		 * String procedureName = "RECEIVE_SLNOTICE_INSTOCK_DIRECT"; return
		 * doProcedure(procedureName, map);
		 */

		String procedureName ="CALL RECEIVE_SLNOTICE_INSTOCK_DIRECT(:V_BARCODE, :V_KW ,:V_USERID, :V_RESULT)";
		return IDMFrameServiceProxy.getSqlTemplate().queryForMap(procedureName, map);
	}

	/**
	 * 调用入库绑定存储过程 RECEIVE_SLNOTICE_INSTOCK_DIRECT 收料入库
	 */
	@Override
	public Map<String, Object> InitialInstock(ReceiveInstockDto receiveInstockDto) throws Throwable {
		String billno = receiveInstockDto.getBillNo();
		String barCode = receiveInstockDto.getBarCode();
		String storageName = receiveInstockDto.getStorageName();
		String userId = receiveInstockDto.getUserId();
		String result = receiveInstockDto.getResult();
		if (Objects.isNull(barCode)) {
			throw new GlobalException("barCode不能为空！");
		}
		if (Objects.isNull(storageName)) {
			throw new GlobalException("storageName能为空！");
		}
		if (Objects.isNull(userId)) {
			throw new GlobalException("userId不能为空！");
		}
		Map<String, Object> map = new HashMap<String, Object>();
		// 将前端传入的参数和存储过程中的参数对应起来
		map.put("V_BILLNO", billno);
		map.put("V_BARCODE", barCode);
		map.put("V_KW", storageName);
		map.put("V_USERID", userId);
		map.put("V_RESULT", "");
		//		String procedureName = "RECEIVE_INITIAL_INSTOCK_DIRECT";
		//		//
		//
		//		return doProcedure(procedureName, map);
		String procedureName = "CALL RECEIVE_INITIAL_INSTOCK_DIRECT(:V_BILLNO, :V_BARCODE ,:V_KW, :V_USERID, :V_RESULT)";
		return IDMFrameServiceProxy.getSqlTemplate().queryForMap(procedureName, map);

	}

	@Override
	public Map<String, Object> materialReceiveInstock(ReceiveInstockDto receiveInstockDto) throws Throwable {

		String billno = receiveInstockDto.getBillNo();
		String siteName = receiveInstockDto.getSiteName();
		String barCode = receiveInstockDto.getBarCode();
		String storageName = receiveInstockDto.getStorageName();
		String userId = receiveInstockDto.getUserId();
		String result = receiveInstockDto.getResult();

		Map<String, Object> map = new HashMap<String, Object>();
		// 将前端传入的参数和存储过程中的参数对应起来
		map.put("V_SITE", siteName);
		map.put("V_BILLNO", billno);
		map.put("V_BARCODE", barCode);
		map.put("V_KW", storageName);
		map.put("V_USERID", userId);
		map.put("V_RESULT", "");

		//		 String procedureName = "RECEIVE_INSTOCK"; 
		//		 return doProcedure(procedureName,map);

		String procedureName = "CALL RECEIVE_INSTOCK(:V_SITE, :V_BILLNO ,:V_BARCODE, :V_KW, :V_USERID,:V_RESULT)";
		return IDMFrameServiceProxy.getSqlTemplate().queryForMap(procedureName, map);
	}

	//调拨申请出库
	@Override
	public	Map<String, Object> materialDbOutstock(ReceiveInstockDto receiveInstockDto,String detailRowNo) throws Throwable{
		String billno = receiveInstockDto.getBillNo();//获取单号
		String siteName = receiveInstockDto.getSiteName();//获取工厂
		String barCode = receiveInstockDto.getBarCode();//获取条码
		String userId = receiveInstockDto.getUserId();//用户id
		String detailrowNo = detailRowNo;//明细行号
		Map<String, Object> map = new HashMap<String, Object>();
		// 将前端传入的参数和存储过程中的参数对应起来
		map.put("V_SITE",siteName);
		map.put("V_BILLNO",billno);
		map.put("V_BARCODE",barCode);
		map.put("V_DETAILROWNO",detailrowNo);
		map.put("V_USERID",userId);
		map.put("V_RESULT", "");
		String procedureName = "CALL RECEIVE_TRANSFER_OUT(:V_SITE, :V_BILLNO ,:V_DETAILROWNO,:V_BARCODE,  :V_USERID,:V_RESULT)";
		return IDMFrameServiceProxy.getSqlTemplate().queryForMap(procedureName, map);
	}
		
	//调拨申请--入库
	@Override
	public Map<String, Object> materialDbInstock(ReceiveInstockDto receiveInstockDto) throws Throwable{
		String billno = receiveInstockDto.getBillNo();//获取单号
		String siteName = receiveInstockDto.getSiteName();//获取工厂
		String barCode = receiveInstockDto.getBarCode();//获取条码
		String userId = receiveInstockDto.getUserId();//用户id		
		String storageName=receiveInstockDto.getStorageName();//库位
		
		Map<String, Object> map = new HashMap<String, Object>();
		// 将前端传入的参数和存储过程中的参数对应起来
		map.put("V_SITE",siteName);
		map.put("V_BILLNO",billno);
		map.put("V_BARCODE",barCode);
		map.put("V_USERID",userId);
		map.put("V_KW",storageName);
		map.put("V_RESULT", "");
		String procedureName = "CALL RECEIVE_INSTOCK(:V_SITE, :V_BILLNO ,:V_BARCODE,:V_KW,  :V_USERID, :V_RESULT)";
		return IDMFrameServiceProxy.getSqlTemplate().queryForMap(procedureName, map);
	}
	
	/**
	 * 调用存储过程的方法
	 * 
	 * @param procedure
	 * @param map
	 * @return
	 */
	private Map<String, Object> doProcedure(String procedure, Map<String, Object> map) {
		String procedureName = procedure;
		try {
			// 调用存储过程返回参数
			Map<String, Object> queryResult = IDMFrameServiceProxy.getSqlTemplate().executeProcedure(procedureName,
					map);

			if (Objects.nonNull(queryResult)) {
				return queryResult;
			}
			throw new GlobalException("未查询到对应参数");

		} catch (Throwable e) {
			throw e;
		}
	}


	@Override
	public Map<String, Object> oemReceiveInstock(ReceiveInstockDto receiveInstockDto, String erplocation) throws Throwable {
		return null;
		
	}

	/**
	 * 获取OEM产品面板信息
	 * @param siteName
	 * @param boxName
	 * @return
	 */
	public List<String> getBOE_ETC_PanelList(String siteName, String boxName) {
		JdbcTemplate jdbcTemplate = IDMFrameServiceProxy.getSqlTemplate().getJdbcTemplate();
		String sql = "SELECT  PANELNAME"+
		"  FROM BOE_ETC_PANEL "+
		" WHERE boxName = ? and oemSiteName = ?";
		List<String> panelList = jdbcTemplate.queryForList(sql, new Object[]{boxName,siteName},String.class);
				
		return panelList;
	}
	
	public Map<String, Object> CreateOemBox(EventInfo eventInfo, String siteName, String receiveRequestName,
			String materialPackingName, String poDetailName, String makeDate, String receiveQuantity,
			String materialSpecName, String supplierName,  String expiringDate, String erpLocation,
			String supermaterialpackingname,String charge,String locationName,String ower, String owerType,String unit) throws Exception {
		// 获取MaterialSpec信息
		MaterialSpec materialSpec = new MaterialSpec();
		MaterialSpecKey materialSpecKey = new MaterialSpecKey();
		materialSpecKey.setMaterialSpecName(materialSpecName);
		materialSpecKey.setSiteName(siteName);
		materialSpec = MaterialServiceProxy.getMaterialSpecService().selectByKey(materialSpecKey);

		MaterialReceiveRequestDetail materialReceiveRequestDetail = new MaterialReceiveRequestDetail();
		MaterialReceiveRequestDetailKey matetialReceiveRequestDetailKey = new MaterialReceiveRequestDetailKey();
		matetialReceiveRequestDetailKey.setReceiveRequestName(receiveRequestName);
		matetialReceiveRequestDetailKey.setSiteName(siteName);
		matetialReceiveRequestDetailKey.setReceiveRequestDetailName(poDetailName);

		materialReceiveRequestDetail = ReceiveRequestDetailServiceProxy.getReceiveRequestDetailService()
				.selectByKey(matetialReceiveRequestDetailKey);

		String sql2 = "SELECT * FROM MATERIALPACKING WHERE MATERIALPACKINGNAME=:materialPackingNmae  AND SITENAME=:siteName";
		Map<String, Object> bindMap2 = new HashMap<String, Object>();
		bindMap2.put("materialPackingNmae", materialPackingName);
		bindMap2.put("siteName", siteName);
		List<Map<String, Object>> sqlResult = IDMFrameServiceProxy.getSqlTemplate().queryForList(sql2, bindMap2);
		if (!(sqlResult.size() == 0 || sqlResult.get(0).get("MATERIALPACKINGNAME").toString().equals(""))) {
			MaterialPackingKey materialPackingKey = new MaterialPackingKey();
			materialPackingKey.setMaterialPackingName(materialPackingName);
			materialPackingKey.setSiteName(siteName);
			MaterialPacking mp = MaterialPackingServiceProxy.getMaterialPackingService()
					.selectByKey(materialPackingKey);
			Map<String, Object> bindMap = new HashMap<String, Object>();
			bindMap.put("receiveRequestName", receiveRequestName);
			bindMap.put("receiveRequestDetailName", poDetailName);
			bindMap.put("shipRequestName", "");
			bindMap.put("shipRequestDetailName", "");
			bindMap.put("shipTime", "");
			bindMap.put("shipUser", "");
			bindMap.put("materialQuantity", receiveQuantity);
			bindMap.put("materialCreateQuantity", receiveQuantity);
			bindMap.put("packingState", "Created");// 标记Box是刚创建的
			bindMap.put("materialType", materialSpec.getMaterialType());
			bindMap.put("materialSpecName", materialSpecName);
			bindMap.put("stockState", "Created");
			bindMap.put("holdState", "N");
			bindMap.put("areaName", "");
			bindMap.put("superMaterialPackingName", supermaterialpackingname);
			bindMap.put("createUser", eventInfo.getEventUser());
			bindMap.put("createTime", eventInfo.getEventTime());
			SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyMMdd");
			Date makeDateD = simpleDateFormat.parse(makeDate);
			
			Date expiringDateD = simpleDateFormat.parse(expiringDate);
			bindMap.put("makeDate", new Timestamp(makeDateD.getTime()).toString());
			bindMap.put("expiringDate", new Timestamp(expiringDateD.getTime()).toString());
//					}
			bindMap.put("erpLocation", erpLocation);
			bindMap.put("stockInType", "");
			bindMap.put("oqaResult", "OK");
			bindMap.put("oqaResultState", "END");
			bindMap.put("charge", charge);
			bindMap.put("supplierName", supplierName);
			bindMap.put("isRelease", 0);
			bindMap.put("lasteventbillno", "");
			bindMap.put("ower", ower);
			bindMap.put("owerType", owerType);
			bindMap.put("unit", unit);
			SetEventInfo setEventInfo = new SetEventInfo();
			setEventInfo.setUserColumns(bindMap);
			MaterialPackingServiceProxy.getMaterialPackingService().setEvent(materialPackingKey, eventInfo,
					setEventInfo);
		} else {
			// 创建Box
			CreateInfo materialPacking = new CreateInfo();
			materialPacking.setMaterialPackingName(materialPackingName);
			materialPacking.setSiteName(siteName);
			materialPacking.setContentMaterialType("");
			materialPacking.setMaterialPackingType("Box");
			Map<String, Object> bindMap = new HashMap<String, Object>();
			bindMap.put("receiveRequestName", receiveRequestName);
			bindMap.put("receiveRequestDetailName", poDetailName);

			bindMap.put("materialQuantity", receiveQuantity);
			bindMap.put("materialCreateQuantity", receiveQuantity);
			bindMap.put("packingState", "Created");
			bindMap.put("materialType", materialSpec.getMaterialType());
			bindMap.put("materialSpecName", materialSpecName);
			bindMap.put("stockState", "Created");
			bindMap.put("holdState", "N");
			bindMap.put("areaName", "");
			bindMap.put("materialDescription", getMaterialDescription(materialSpecName));
			bindMap.put("oqaResult", "OK");
			bindMap.put("oqaResultState", "END");
			
			bindMap.put("superMaterialPackingName", supermaterialpackingname);
			bindMap.put("createUser", eventInfo.getEventUser());
			bindMap.put("createTime", eventInfo.getEventTime());
			SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyMMdd");
			Date makeDateD = simpleDateFormat.parse(makeDate);
			
			Date expiringDateD = simpleDateFormat.parse(expiringDate);
			bindMap.put("makeDate", new Timestamp(makeDateD.getTime()).toString());
			bindMap.put("expiringDate", new Timestamp(expiringDateD.getTime()).toString());
			bindMap.put("stockInType", "");
			bindMap.put("charge", charge);
			bindMap.put("supplierName", supplierName);
			bindMap.put("isRelease", 0);
			bindMap.put("lasteventbillno", "");
			
			bindMap.put("ower", ower);
			bindMap.put("owerType", owerType);
			bindMap.put("unit", unit);
			materialPacking.setUserColumns(bindMap);
			MaterialPackingServiceProxy.getMaterialPackingService().create(eventInfo, materialPacking);
		}

		MakeDetailIncreaseReceivedInfo makeDetailIncreaseReceivedInfo = new MakeDetailIncreaseReceivedInfo();
		MaterialReceiveRequestDetailKey materialReceiveRequestDetailKey = new MaterialReceiveRequestDetailKey();
		materialReceiveRequestDetailKey.setReceiveRequestName(receiveRequestName);
		materialReceiveRequestDetailKey.setSiteName(siteName);
		materialReceiveRequestDetailKey.setReceiveRequestDetailName(poDetailName);

		makeDetailIncreaseReceivedInfo.setIncreaseQuantity(Float.parseFloat(receiveQuantity));
		Map<String, Object> bindMap = new HashMap<String, Object>();
		bindMap.put("owerType", owerType);
		makeDetailIncreaseReceivedInfo.setObjectValueUserColumns(bindMap);
		

		ReceiveRequestDetailServiceProxy.getReceiveRequestDetailService()
				.increaseReceivedQuantity(materialReceiveRequestDetailKey, eventInfo, makeDetailIncreaseReceivedInfo);
		
		
//		
//		
//		Map<String, Object> subdetailMap = new HashMap<String, Object>();
//		subdetailMap.put("SITENAME", siteName);
//		subdetailMap.put("RECEIVEREQUESTNAME", receiveRequestName);
//
//		String sqlqry = "SELECT  max(ROWNO)  MAXROWNO from MATERIALRECEIVEREQUESTSUBDETAIL WHERE  SITENAME=:SITENAME AND RECEIVEREQUESTNAME=:RECEIVEREQUESTNAME";
//		List<Map<String, Object>> list = IDMFrameServiceProxy.getSqlTemplate().queryForList(sqlqry, subdetailMap);
//		
//		if (list.size() > 0) {					
//			Object maxrowno = list.get(0).get("MAXROWNO");
//			if (maxrowno==null)
//				maxrowno = "0001";
//			else
//				maxrowno = String.format("%0" + 4 + "d", Integer.parseInt(maxrowno.toString()) + 1);
//
//			// 向MATERIALRECEIVEREQUESTSUBDETAIL插入条码;
//			String sqlsubdetail = "INSERT INTO MATERIALRECEIVEREQUESTSUBDETAIL(SITENAME,RECEIVEREQUESTNAME,ROWNO,DETAILROWNO,PACKINGCODE,MATERIALSPECNAME,DESCRIPTION,QTY,MAKEDATE,CHARGE,EVENTUSER,EVENTTIME,WAREHOUSE,LOCATION)\r\n"
//					+ "VALUES (:SITENAME,:RECEIVEREQUESTNAME,:ROWNO,:DETAILROWNO,:PACKINGCODE,:MATERIALSPECNAME,:DESCRIPTION,:QTY,:MAKEDATE,:CHARGE,:EVENTUSER,:EVENTTIME,:ERPLOCATION,:LOCATION)";
//
//			MaterialSpecKey materialKey = new MaterialSpecKey();
//			materialKey.setMaterialSpecName(materialSpecName);
//			materialKey.setSiteName(siteName);
//			MaterialSpec material = MaterialServiceProxy.getMaterialSpecService().selectByKey(materialKey);
//			subdetailMap.put("ROWNO", maxrowno);
//			subdetailMap.put("DETAILROWNO", poDetailName);
//			subdetailMap.put("PACKINGCODE", materialPackingName);
//			subdetailMap.put("MATERIALSPECNAME", materialSpecName);
//			subdetailMap.put("DESCRIPTION", material.getDescription());
//			subdetailMap.put("QTY", receiveQuantity);
//			SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");	// 使用给定模式yyyy-MM-dd
//	        java.util.Date umakeDate = format.parse(makeDate);
//	        java.sql.Date sdate = new java.sql.Date(umakeDate.getTime());
//	        
//	        
//			subdetailMap.put("MAKEDATE", sdate);
//			
////			umakeDate.
////			subdetailMap.put("EXPIRINGDATE", sexpiringDate);
//			subdetailMap.put("CHARGE", charge);
//			subdetailMap.put("EVENTUSER", eventInfo.getEventUser());
//			subdetailMap.put("EVENTTIME", eventInfo.getEventTime());
//			subdetailMap.put("ERPLOCATION", erpLocation);
//			subdetailMap.put("LOCATION", locationName);
//			IDMFrameServiceProxy.getSqlTemplate().update(sqlsubdetail, subdetailMap);
			
			
		Map<String, Object> map = new HashMap<String, Object>();
		// 将前端传入的参数和存储过程中的参数对应起来
		map.put("V_BARCODE", materialPackingName);
		map.put("V_KW", locationName);
		map.put("V_USERID", eventInfo.getEventUser());
		map.put("V_RESULT", "");
		/*
		 * String procedureName = "RECEIVE_SLNOTICE_INSTOCK_DIRECT"; return
		 * doProcedure(procedureName, map);
		 */

		String procedureName ="CALL RECEIVE_SLNOTICE_INSTOCK_DIRECT(:V_BARCODE, :V_KW ,:V_USERID, :V_RESULT)";
		Map<String, Object> queryForMap = IDMFrameServiceProxy.getSqlTemplate().queryForMap(procedureName, map);
		return queryForMap;

	}
	
	public String getMaterialDescription(String materialSpecName) {
		String sql = "SELECT M.DESCRIPTION  FROM MATERIALSPEC  M WHERE M.MATERIALSPECNAME = :MATERIALSPECNAME ";
		
		Map<String, Object> hashMap = new HashMap<String,Object> ();
		hashMap.put("MATERIALSPECNAME", materialSpecName);
		
		List<Map<String, Object>> list = IDMFrameServiceProxy.getSqlTemplate().queryForList(sql, hashMap);
		if (list != null && list.size() > 0) {
			return list.get(0).get("DESCRIPTION").toString();
		}
		return null;
	}
	
	
	
	/**
	 *
	 * @param SiteName
	 * @param panelName
	 * @param eventInfo
	 * @throws CustomException
	 */
	private void checkProductExistAndDelete(String SiteName,String panelName,EventInfo eventInfo) throws CustomException {
		ProductKey key = new ProductKey();
		key.setProductName(panelName);
		key.setSiteName(SiteName);
		Product fgmspanel =null;
		try{
			fgmspanel = ProductServiceProxy.getProductService().selectByKey(key);
		}catch(NotFoundSignal e){}
		
		if(fgmspanel!=null){
			if(true){
				
				
			RemoveInfo removeInfo = new RemoveInfo();
			
			
			EventInfo removeProductEventInfo = new EventInfo();
			removeProductEventInfo.setBehaviorName("");
			removeProductEventInfo.setCheckTimekeyValidation(false);
			removeProductEventInfo.setEventComment("Product["+fgmspanel.getKey().getProductName()+"] already exist and productstate is "+fgmspanel.getProductState()+". should remove it firstly and then create a new one");
			removeProductEventInfo.setEventName(eventInfo.getEventName()+"_Remove");
			removeProductEventInfo.setEventTime(eventInfo.getEventTime());
			removeProductEventInfo.setEventTimeKey(eventInfo.getEventTimeKey());
			removeProductEventInfo.setEventUser(eventInfo.getEventUser());
			removeProductEventInfo.setReasonCode(eventInfo.getReasonCode());
			removeProductEventInfo.setReasonCodeType(eventInfo.getReasonCodeType());
			
			ProductServiceProxy.getProductService().delete(key);
			}else{
				throw new CustomException("Panel-0005",panelName,fgmspanel.getProductState());
			}
		}
	}	
	
	
	
	
	/**
	 * 接收Panel信息
	 * @param eventInfo
	 * @param panelCreateInfoList
	 */
	public void receivePanels(EventInfo eventInfo, List<com.cim.idm.wmspackage.product.management.info.CreateInfo> panelCreateInfoList){
		ProductServiceProxy.getProductService().create(eventInfo, panelCreateInfoList);
	}
	
	
	/***********************************************************************************************************************/
	/***********************************************************************************************************************/
	/**************************************************公共方法*************************************************************/
	/***********************************************************************************************************************/
	public static EventInfo makeEventInfo( String eventName, String eventUser, String eventComment,
			String reasonCodeType, String reasonCode )
	{
		EventInfo eventInfo = new EventInfo();
		
		eventInfo.setBehaviorName( "" );
		eventInfo.setEventName( eventName );
		eventInfo.setEventUser( eventUser );
		
		if ( eventComment == null )
			eventComment = "";
		
		eventInfo.setEventComment( eventComment );		
		// Do Not Check TimeKey Validation
		eventInfo.setCheckTimekeyValidation(false);
		if ( reasonCodeType == null )
			reasonCodeType = "";
		
		eventInfo.setReasonCodeType( reasonCodeType );
		
		if ( reasonCode == null )
			reasonCode = "";
		
		eventInfo.setReasonCode( reasonCode );
		
		return eventInfo;
	}

}
