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

import java.sql.Timestamp;
import java.text.DateFormat;
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.Locale;
import java.util.Map;

import org.jdom.Document;
import org.jdom.Element;

import com.cim.idm.framework.data.EventInfo;
import com.cim.idm.framework.exception.IDMFrameDBErrorSignal;
import com.cim.idm.framework.orm.service.CommonServiceDAO;
import com.cim.idm.mwmsextend.checkrecord.CheckRecordServiceProxy;
import com.cim.idm.mwmsextend.checkrecord.management.data.CheckRecord;
import com.cim.idm.mwmsextend.checkrecord.management.data.CheckRecordKey;
import com.cim.idm.mwmsextend.checkrecord.management.info.CreateInfo;
import com.cim.idm.mwmsextend.checkrecord.management.info.SetEventInfo;

public class CheckRecordSolutionServiceImpl extends CommonServiceDAO<CheckRecordKey,CheckRecord>{
	
	public void PDACreateCheckRecord(EventInfo eventInfo,String planDate,String checkPlanName,
			String materialPackingName,String actLocation,String sysLocation,String siteName,String erpLocation,
			String materialQuantity,String materialActQuantity,String checkTimeKey,String checkState,String lastAction,String materialSpecName,String checkMaterialType,String checkPackingType)throws Exception{
		
 
		
		try {
			
			SetEventInfo setEventInfo = new SetEventInfo();
			List<CheckRecordKey> keyList = new ArrayList<CheckRecordKey>();
			List<CreateInfo> createInfoList = new ArrayList<CreateInfo>();
			if (checkPlanName != null)
			{
				CreateInfo createInfo = new CreateInfo();

				Map<String, Object> bindMap = new HashMap<String, Object>();

				createInfo.setPlanDate(planDate);
				createInfo.setCheckPlanName(checkPlanName);
				createInfo.setSiteName(siteName);
				createInfo.setMaterialPackingName(materialPackingName);
				createInfo.setActLocation(actLocation);
				//createInfo.setCheckMaterialType(checkMaterialType);
				//createInfo.setCheckPackingType(checkPackingType);

				bindMap.put("sysLocation", sysLocation);
				bindMap.put("operatorId", eventInfo.getEventUser());
			 	bindMap.put("checkTimeKey", checkTimeKey);
			 	bindMap.put("checkState", checkState);
			 	bindMap.put("lastAction", lastAction);
				bindMap.put("materialQuantity", materialQuantity);
				bindMap.put("materialActQuantity", materialActQuantity);
				bindMap.put("erpLocation", erpLocation);
			 	bindMap.put("materialSpecName", materialSpecName);		
				bindMap.put("actLocation", actLocation);	
				bindMap.put("lastEventName", "PDACreate");
				bindMap.put("lastEventUser", eventInfo.getEventUser());
				bindMap.put("lastEventComment", eventInfo.getEventComment());
				bindMap.put("lastEventTime", eventInfo.getEventTime()); //新加最后时间
				//新增盘点类型和打包信息
				//bindMap.put("checkMaterialType", checkMaterialType);	
				//bindMap.put("checkPackingType", checkPackingType);	
				createInfo.setUserColumns(bindMap);

				createInfoList.add(createInfo);
			}
			CheckRecordServiceProxy.getCheckRecordService().create(eventInfo, createInfoList);
		}
		catch (Exception ex) {
			ex.printStackTrace();
			throw ex;
		}
	}
	
}
