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.IDMFrameDBErrorSignal;
import com.cim.idm.framework.util.time.TimeStampUtil;
import com.cim.idm.model.BSLabel;
import com.cim.idm.model.BSLabelKey;
import com.cim.idm.model.StorageSpec;
import com.cim.idm.service.ChargeSplitService;
import com.cim.idm.utils.EventInfoUtil;
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 org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class ChargeSplitServiceImpl implements ChargeSplitService {
	
	private EventInfo makeEventInfo;

	@Transactional
	public boolean ChargeSplit(List<MaterialPacking> boxList, String user) {
		
		String condition="";
		String newBoxId1 = boxList.get(1).getMaterialPackingName();
		String newBoxId2 = boxList.get(2).getMaterialPackingName();
		if(newBoxId1.equals(newBoxId2)) {
			throw new GlobalException("拆分后的2个新标签不能相同(数量不能相等)");
		}
//		String pc = "('" + materialpackingname + "')";
		String sql = "SELECT 1 FROM MATERIALPACKING WHERE MATERIALPACKINGNAME IN (:MATERIALPACKINGNAME1, :MATERIALPACKINGNAME2)";
		Map<String, Object> hashMap2 = new HashMap<String,Object> ();
		hashMap2.put("MATERIALPACKINGNAME1", newBoxId1);
		hashMap2.put("MATERIALPACKINGNAME2", newBoxId2);
		List<Map<String, Object>> queryForList = IDMFrameServiceProxy.getSqlTemplate().queryForList(sql, hashMap2);
		List<MaterialPacking> MaterialPackingList = null;
		if (queryForList != null && queryForList.size() > 0) {
			String[] bindSet={newBoxId1, newBoxId2};
			condition="WHERE MATERIALPACKINGNAME IN (?,?)";
			MaterialPackingList = MaterialPackingServiceProxy.getMaterialPackingService().select(condition, bindSet);
		}
		//解析条码,根据远条码信息更新目标条码数量和库存状态
		SetEventInfo setEventInfo = new SetEventInfo();
		EventInfoUtil eventInfoUtil = new EventInfoUtil();
		makeEventInfo = eventInfoUtil.makeEventInfo("ChargeSplit", user, "ChargeSplit" );
		//找到原来标签的相关信息
//		String receiveTime = "";
//		String makeDate = "";
//		String expireDate = "";
		String holdState = "";
		String oqaResult = "";
		String oqaResultState = "";
		String packingGrade = "";
		String trueGg = "";
		String erpFactory = "";
		String erpLocation = "";
		String locationName = "";
		String shelfName = "";
		String areaName = "";
		String durableName = "";;
		String CAREER_ASSISTANCE = "";
	    String SALESPERSON = "";
	    String CUSTOMNO = "";
	    String DEVIATION = "";
	    String DIAMETER = "";
	    String WIDTH = "";
	    String WEIGHT = "";
	    String PRODUCTLINE = "";
	    String UNIT = "";
	    String MJPC = "";
	    String BUSINESS_UNIT = "";
	    
	    String MATERIALSPECNAME = "";
//	    String SUBPACKINGQUANTITY = "";
//	    String MATERIALCREATEQUANTITY = "";
	    String CHARGE = "";
	    String SDK_ID = "";
	    String PHASE = "";
	    String RECEIVEREQUESTNAME = "";
	    String RECEIVEREQUESTDETAILNAME = "";
	    String REMARK = "";
	    
		String ypcSql = "SELECT M.RECEIVETIME,M.MAKEDATE,M.EXPIRINGDATE,M.HOLDSTATE,M.OQARESULTSTATE ,\r\n" + 
				"		M.OQARESULT ,M.PACKINGGRADE ,M.TRUEGG ,M.ERPFACTORY ,M.ERPLOCATION ,M.LOCATIONNAME ,\r\n" + 
				"		M.SHELFNAME ,M.AREANAME ,M.DURABLENAME ,M.CAREER_ASSISTANCE ,M.SALESPERSON ,M.CUSTOMNO,M.SDK_ID,M.PHASE,M.RECEIVEREQUESTNAME,M.RECEIVEREQUESTDETAILNAME,"
				+ "     M.DEVIATION ,M.DIAMETER ,M.WIDTH ,M.WEIGHT ,M.PRODUCTLINE,UNIT ,MJPC,BUSINESS_UNIT,M.MATERIALSPECNAME, M.SUBPACKINGQUANTITY, M.MATERIALCREATEQUANTITY, M.MATERIALQUANTITY, M.CHARGE, M.REMARK" + 
				"		FROM MATERIALPACKING M WHERE M.MATERIALPACKINGNAME  = :MATERIALPACKINGNAME AND M.CHARGE  = :CHARGE ";
		Map<String, Object> hashMap4 = new HashMap<String,Object> ();
		hashMap4.put("MATERIALPACKINGNAME", boxList.get(0).getMaterialPackingName());
		hashMap4.put("CHARGE", boxList.get(0).getCharge());
		List<Map<String, Object>> queryForList3 = IDMFrameServiceProxy.getSqlTemplate().queryForList(ypcSql, hashMap4);
		
		if (queryForList3 != null && queryForList3.size() > 0) {
			Map<String, Object> map = queryForList3.get(0);
			 holdState = map.get("HOLDSTATE") == null ? "N" : map.get("HOLDSTATE").toString();
			 oqaResult = map.get("OQARESULT") == null ? "" : map.get("OQARESULT").toString();
			 oqaResultState = map.get("OQARESULTSTATE") == null ? "END" : map.get("OQARESULTSTATE").toString();
			 packingGrade = map.get("PACKINGGRADE") == null ? "" : map.get("PACKINGGRADE").toString();
			 trueGg = map.get("TRUEGG") == null ? "" : map.get("TRUEGG").toString();
			 erpFactory = map.get("ERPFACTORY") == null ? "" : map.get("ERPFACTORY").toString();
			 erpLocation = map.get("ERPLOCATION") == null ? "" : map.get("ERPLOCATION").toString();
			 locationName = map.get("LOCATIONNAME") == null ? "" : map.get("LOCATIONNAME").toString();
			 shelfName = map.get("SHELFNAME") == null ? "" : map.get("SHELFNAME").toString();
			 areaName = map.get("AREANAME") == null ? "" : map.get("AREANAME").toString();
			 durableName = map.get("DURABLENAME") == null ? "" : map.get("DURABLENAME").toString();
			 CAREER_ASSISTANCE = map.get("CAREER_ASSISTANCE") == null ? "" : map.get("CAREER_ASSISTANCE").toString();
	         SALESPERSON = map.get("SALESPERSON") == null ? "" : map.get("SALESPERSON").toString();
	         CUSTOMNO = map.get("CUSTOMNO") == null ? "" : map.get("CUSTOMNO").toString();
	         DEVIATION = map.get("DEVIATION") == null ? "" : map.get("DEVIATION").toString();
	         DIAMETER = map.get("DIAMETER") == null ? "" : map.get("DIAMETER").toString();
	         WIDTH = map.get("WIDTH") == null ? "" : map.get("WIDTH").toString();
	         WEIGHT = map.get("WEIGHT") == null ? "" : map.get("WEIGHT").toString();
	         PRODUCTLINE = map.get("PRODUCTLINE") == null ? "" : map.get("PRODUCTLINE").toString();
	         UNIT = map.get("UNIT") == null ? "" : map.get("UNIT").toString();
	         MJPC = map.get("MJPC") == null ? "" : map.get("MJPC").toString();
	         BUSINESS_UNIT = map.get("BUSINESS_UNIT") == null ? "" : map.get("BUSINESS_UNIT").toString();
	         MATERIALSPECNAME = map.get("MATERIALSPECNAME") == null ? "" : map.get("MATERIALSPECNAME").toString();
//	         SUBPACKINGQUANTITY = map.get("SUBPACKINGQUANTITY") == null ? "" : map.get("SUBPACKINGQUANTITY").toString();
//	         MATERIALCREATEQUANTITY = map.get("MATERIALCREATEQUANTITY") == null ? "" : map.get("MATERIALCREATEQUANTITY").toString();
	         CHARGE = map.get("CHARGE") == null ? "" : map.get("CHARGE").toString();
	         SDK_ID = map.get("SDK_ID") == null ? "" : map.get("SDK_ID").toString();
	         PHASE = map.get("PHASE") == null ? "" : map.get("PHASE").toString();
	         REMARK = map.get("REMARK") == null ? "" : map.get("REMARK").toString();
	         
		}
		
		if (MaterialPackingList != null && MaterialPackingList.size() > 0) {
			throw new RuntimeException("拆分批次的标签已存在！");
		}else {
//			创建标签1
			CreateInfo createInfo1 = new CreateInfo();
			createInfo1.setSiteName("SDK");
			createInfo1.setMaterialPackingName(newBoxId1);// 新生成的box id
			createInfo1.setMaterialPackingType("Box");
			createInfo1.setContentMaterialType("");

			Map<String, Object> bindMap = new HashMap<String, Object>();
			bindMap.put("MaterialSpecName", MATERIALSPECNAME);
			bindMap.put("PackingGrade", packingGrade);
			bindMap.put("oqaResult", oqaResult);
			bindMap.put("oqaResultState", oqaResultState);
			bindMap.put("SubPackingQuantity",boxList.get(1).getMaterialQuantity());
			bindMap.put("MaterialCreateQuantity",boxList.get(1).getMaterialQuantity());
			bindMap.put("MaterialQuantity", boxList.get(1).getMaterialQuantity());// 数量
			bindMap.put("PackingState", "Released");
			bindMap.put("OldPackingState", "Released");
			bindMap.put("stockState", "Stocked");
			bindMap.put("OldStockState", "Created");
			bindMap.put("HoldState", holdState);
			bindMap.put("LocationName", locationName);
			bindMap.put("charge",CHARGE);
			bindMap.put("MaterialProcessGroupName","");
			bindMap.put("LastEventTimeKey",TimeStampUtil.getCurrentEventTimeKey());
			
			bindMap.put("MakeDate", queryForList3.get(0).get("MAKEDATE"));
			bindMap.put("expiringDate", queryForList3.get(0).get("EXPIRINGDATE"));
			bindMap.put("ReceiveTime", queryForList3.get(0).get("RECEIVETIME"));
			bindMap.put("unit", queryForList3.get(0).get("UNIT"));
			
			bindMap.put("ReceiveUser", makeEventInfo.getEventUser());
			bindMap.put("ErpLocation", erpLocation);
			bindMap.put("ErpFactory", erpFactory);
			bindMap.put("locationName", locationName);
			bindMap.put("StockInType", "Normal");
			bindMap.put("SDK_ID", SDK_ID);
			bindMap.put("PHASE", PHASE);
			bindMap.put("remark", REMARK);
			bindMap.put("ReceiveRequestName", RECEIVEREQUESTNAME);
			bindMap.put("ReceiveRequestDetailName",RECEIVEREQUESTDETAILNAME);

			
			bindMap.put("CAREER_ASSISTANCE", CAREER_ASSISTANCE);//业助信息
			bindMap.put("BUSINESS_UNIT", BUSINESS_UNIT);//业务
			bindMap.put("SALESPERSON", SALESPERSON);//事业部
			bindMap.put("MJPC", MJPC);//母卷批次
			bindMap.put("truegg", trueGg);
			bindMap.put("durableName", durableName);
			bindMap.put("areaName", areaName);
			bindMap.put("PRODUCTLINE", PRODUCTLINE);
			bindMap.put("WIDTH", WIDTH);
			bindMap.put("DEVIATION", DEVIATION);
			bindMap.put("WEIGHT", WEIGHT);
			bindMap.put("DIAMETER", DIAMETER);
			bindMap.put("shelfName", shelfName);
			createInfo1.setUserColumns(bindMap);
			
			// 新标签2
			CreateInfo createInfo2 = new CreateInfo();
			createInfo2.setSiteName("SDK");
			createInfo2.setMaterialPackingName(newBoxId2);// 新生成的box id
			createInfo2.setMaterialPackingType("Box");
			createInfo2.setContentMaterialType("");
			Map<String, Object> bindMap2 = new HashMap<String, Object>();
			bindMap2.putAll(bindMap);
			bindMap2.put("SubPackingQuantity",boxList.get(2).getMaterialQuantity());
			bindMap2.put("MaterialCreateQuantity",boxList.get(2).getMaterialQuantity());
			bindMap2.put("MaterialQuantity", boxList.get(2).getMaterialQuantity());// 数量
			createInfo2.setUserColumns(bindMap2);
			
			MaterialPackingServiceProxy.getMaterialPackingService().create(makeEventInfo, createInfo1);
			MaterialPackingServiceProxy.getMaterialPackingService().create(makeEventInfo, createInfo2);
		
			//更新原标签批次的库位状态为出库
			MaterialPackingKey materialPackingKey = new MaterialPackingKey("SDK",boxList.get(0).getMaterialPackingName());
			Map<String, Object> hashMap3 = new HashMap<String,Object> ();
			hashMap3.put("stockState", "StockOut");
			setEventInfo.setUserColumns(hashMap3);
			MaterialPackingServiceProxy.getMaterialPackingService().setEvent(materialPackingKey, makeEventInfo, setEventInfo);
		}
		return true;
	}
	
	//无来源转库拆分
	@Transactional
	public boolean NoLYChargeSplit(StorageSpec StorageSpec, String user, String locationNameCr) throws Exception {
		
		String condition="";
		String newBoxId1 = StorageSpec.getMATERIALPACKINGNAME1();
		String newBoxId2 = StorageSpec.getMATERIALPACKINGNAME2();
		if(newBoxId1.equals(newBoxId2)) {
			throw new GlobalException("拆分后的2个新标签不能相同(数量不能相等)");
		}
//		String pc = "('" + materialpackingname + "')";
		String sql = "SELECT 1 FROM MATERIALPACKING WHERE MATERIALPACKINGNAME IN (:MATERIALPACKINGNAME1, :MATERIALPACKINGNAME2)";
		Map<String, Object> hashMap2 = new HashMap<String,Object> ();
		hashMap2.put("MATERIALPACKINGNAME1", newBoxId1);
		hashMap2.put("MATERIALPACKINGNAME2", newBoxId2);
		List<Map<String, Object>> queryForList = IDMFrameServiceProxy.getSqlTemplate().queryForList(sql, hashMap2);
		List<MaterialPacking> MaterialPackingList = null;
		if (queryForList != null && queryForList.size() > 0) {
			String[] bindSet={newBoxId1, newBoxId2};
			condition="WHERE MATERIALPACKINGNAME IN (?,?)";
			MaterialPackingList = MaterialPackingServiceProxy.getMaterialPackingService().select(condition, bindSet);
		}
		//解析条码,根据远条码信息更新目标条码数量和库存状态
		SetEventInfo setEventInfo = new SetEventInfo();
		EventInfoUtil eventInfoUtil = new EventInfoUtil();
		makeEventInfo = eventInfoUtil.makeEventInfo("NoLYChargeSplit", user, "ChargeSplit" );
		//找到原来标签的相关信息
//		String receiveTime = "";
//		String makeDate = "";
//		String expireDate = "";
		String holdState = "";
		String oqaResult = "";
		String oqaResultState = "";
		String packingGrade = "";
		String trueGg = "";
		String erpFactory = "";
		String erpLocation = "";
		String locationName = "";
		String shelfName = "";
		String areaName = "";
		String durableName = "";;
		String CAREER_ASSISTANCE = "";
	    String SALESPERSON = "";
	    String CUSTOMNO = "";
	    String DEVIATION = "";
	    String DIAMETER = "";
	    String WIDTH = "";
	    String WEIGHT = "";
	    String PRODUCTLINE = "";
	    String UNIT = "";
	    String MJPC = "";
	    String BUSINESS_UNIT = "";
	    
	    String MATERIALSPECNAME = "";
//	    String SUBPACKINGQUANTITY = "";
//	    String MATERIALCREATEQUANTITY = "";
	    String CHARGE = "";
	    String SDK_ID = "";
	    String PHASE = "";
	    String RECEIVEREQUESTNAME = "";
	    String RECEIVEREQUESTDETAILNAME = "";
	    String REMARK = "";
	    
		String ypcSql = "SELECT M.RECEIVETIME,M.MAKEDATE,M.EXPIRINGDATE,M.HOLDSTATE,M.OQARESULTSTATE ,\r\n" + 
				"		M.OQARESULT ,M.PACKINGGRADE ,M.TRUEGG ,M.ERPFACTORY ,M.ERPLOCATION ,M.LOCATIONNAME ,\r\n" + 
				"		M.SHELFNAME ,M.AREANAME ,M.DURABLENAME ,M.CAREER_ASSISTANCE ,M.SALESPERSON ,M.CUSTOMNO,M.SDK_ID,M.PHASE,M.RECEIVEREQUESTNAME,M.RECEIVEREQUESTDETAILNAME,"
				+ "     M.DEVIATION ,M.DIAMETER ,M.WIDTH ,M.WEIGHT ,M.PRODUCTLINE,UNIT ,MJPC,BUSINESS_UNIT,M.MATERIALSPECNAME, M.SUBPACKINGQUANTITY, M.MATERIALCREATEQUANTITY, M.MATERIALQUANTITY, M.CHARGE, M.REMARK" + 
				"		FROM MATERIALPACKING M WHERE M.MATERIALPACKINGNAME  = :MATERIALPACKINGNAME AND M.CHARGE  = :CHARGE ";
		Map<String, Object> hashMap4 = new HashMap<String,Object> ();
		hashMap4.put("MATERIALPACKINGNAME", StorageSpec.getMaterialPackingName());
		hashMap4.put("CHARGE", StorageSpec.getCHARGE());
		List<Map<String, Object>> queryForList3 = IDMFrameServiceProxy.getSqlTemplate().queryForList(ypcSql, hashMap4);
		
		if (queryForList3 != null && queryForList3.size() > 0) {
			Map<String, Object> map = queryForList3.get(0);
			 holdState = map.get("HOLDSTATE") == null ? "N" : map.get("HOLDSTATE").toString();
			 oqaResult = map.get("OQARESULT") == null ? "" : map.get("OQARESULT").toString();
			 oqaResultState = map.get("OQARESULTSTATE") == null ? "END" : map.get("OQARESULTSTATE").toString();
			 packingGrade = map.get("PACKINGGRADE") == null ? "" : map.get("PACKINGGRADE").toString();
			 trueGg = map.get("TRUEGG") == null ? "" : map.get("TRUEGG").toString();
			 erpFactory = map.get("ERPFACTORY") == null ? "" : map.get("ERPFACTORY").toString();
			 erpLocation = map.get("ERPLOCATION") == null ? "" : map.get("ERPLOCATION").toString();
			 locationName = map.get("LOCATIONNAME") == null ? "" : map.get("LOCATIONNAME").toString();
			 shelfName = map.get("SHELFNAME") == null ? "" : map.get("SHELFNAME").toString();
			 areaName = map.get("AREANAME") == null ? "" : map.get("AREANAME").toString();
			 durableName = map.get("DURABLENAME") == null ? "" : map.get("DURABLENAME").toString();
			 CAREER_ASSISTANCE = map.get("CAREER_ASSISTANCE") == null ? "" : map.get("CAREER_ASSISTANCE").toString();
	         SALESPERSON = map.get("SALESPERSON") == null ? "" : map.get("SALESPERSON").toString();
	         CUSTOMNO = map.get("CUSTOMNO") == null ? "" : map.get("CUSTOMNO").toString();
	         DEVIATION = map.get("DEVIATION") == null ? "" : map.get("DEVIATION").toString();
	         DIAMETER = map.get("DIAMETER") == null ? "" : map.get("DIAMETER").toString();
	         WIDTH = map.get("WIDTH") == null ? "" : map.get("WIDTH").toString();
	         WEIGHT = map.get("WEIGHT") == null ? "" : map.get("WEIGHT").toString();
	         PRODUCTLINE = map.get("PRODUCTLINE") == null ? "" : map.get("PRODUCTLINE").toString();
	         UNIT = map.get("UNIT") == null ? "" : map.get("UNIT").toString();
	         MJPC = map.get("MJPC") == null ? "" : map.get("MJPC").toString();
	         BUSINESS_UNIT = map.get("BUSINESS_UNIT") == null ? "" : map.get("BUSINESS_UNIT").toString();
	         MATERIALSPECNAME = map.get("MATERIALSPECNAME") == null ? "" : map.get("MATERIALSPECNAME").toString();
//	         SUBPACKINGQUANTITY = map.get("SUBPACKINGQUANTITY") == null ? "" : map.get("SUBPACKINGQUANTITY").toString();
//	         MATERIALCREATEQUANTITY = map.get("MATERIALCREATEQUANTITY") == null ? "" : map.get("MATERIALCREATEQUANTITY").toString();
	         CHARGE = map.get("CHARGE") == null ? "" : map.get("CHARGE").toString();
	         SDK_ID = map.get("SDK_ID") == null ? "" : map.get("SDK_ID").toString();
	         PHASE = map.get("PHASE") == null ? "" : map.get("PHASE").toString();
	         REMARK = map.get("REMARK") == null ? "" : map.get("REMARK").toString();
	         
		}
		
		if (MaterialPackingList != null && MaterialPackingList.size() > 0) {
			throw new RuntimeException("拆分批次的标签已存在！");
		}else {
//			创建标签1
			CreateInfo createInfo1 = new CreateInfo();
			createInfo1.setSiteName("SDK");
			createInfo1.setMaterialPackingName(newBoxId1);// 新生成的box id
			createInfo1.setMaterialPackingType("Box");
			createInfo1.setContentMaterialType("");

			Map<String, Object> bindMap = new HashMap<String, Object>();
			bindMap.put("MaterialSpecName", MATERIALSPECNAME);
			bindMap.put("PackingGrade", packingGrade);
			bindMap.put("oqaResult", oqaResult);
			bindMap.put("oqaResultState", oqaResultState);
			bindMap.put("SubPackingQuantity",StorageSpec.getMATERIALQUANTITY1());
			bindMap.put("MaterialCreateQuantity",StorageSpec.getMATERIALQUANTITY1());
			bindMap.put("MaterialQuantity", StorageSpec.getMATERIALQUANTITY1());// 数量
			bindMap.put("PackingState", "Released");
			bindMap.put("OldPackingState", "Released");
			bindMap.put("stockState", "Stocked");
			bindMap.put("OldStockState", "Created");
			bindMap.put("HoldState", holdState);
			bindMap.put("LocationName", locationName);
			bindMap.put("charge",CHARGE);
			bindMap.put("MaterialProcessGroupName","");
			bindMap.put("LastEventTimeKey",TimeStampUtil.getCurrentEventTimeKey());
			
			bindMap.put("MakeDate", queryForList3.get(0).get("MAKEDATE"));
			bindMap.put("expiringDate", queryForList3.get(0).get("EXPIRINGDATE"));
			bindMap.put("ReceiveTime", queryForList3.get(0).get("RECEIVETIME"));
			bindMap.put("unit", queryForList3.get(0).get("UNIT"));
			
			bindMap.put("ReceiveUser", makeEventInfo.getEventUser());
			bindMap.put("ErpLocation", erpLocation);
			bindMap.put("ErpFactory", erpFactory);
			bindMap.put("locationName", locationName);
			bindMap.put("StockInType", "Normal");
			bindMap.put("SDK_ID", SDK_ID);
			bindMap.put("PHASE", PHASE);
			bindMap.put("remark", REMARK);
			bindMap.put("ReceiveRequestName", RECEIVEREQUESTNAME);
			bindMap.put("ReceiveRequestDetailName",RECEIVEREQUESTDETAILNAME);

			
			bindMap.put("CAREER_ASSISTANCE", CAREER_ASSISTANCE);//业助信息
			bindMap.put("BUSINESS_UNIT", BUSINESS_UNIT);//业务
			bindMap.put("SALESPERSON", SALESPERSON);//事业部
			bindMap.put("MJPC", MJPC);//母卷批次
			bindMap.put("truegg", trueGg);
			bindMap.put("durableName", durableName);
			bindMap.put("areaName", areaName);
			bindMap.put("PRODUCTLINE", PRODUCTLINE);
			bindMap.put("WIDTH", WIDTH);
			bindMap.put("DEVIATION", DEVIATION);
			bindMap.put("WEIGHT", WEIGHT);
			bindMap.put("DIAMETER", DIAMETER);
			bindMap.put("shelfName", shelfName);
			createInfo1.setUserColumns(bindMap);
			
			// 新标签2
			CreateInfo createInfo2 = new CreateInfo();
			createInfo2.setSiteName("SDK");
			createInfo2.setMaterialPackingName(newBoxId2);// 新生成的box id
			createInfo2.setMaterialPackingType("Box");
			createInfo2.setContentMaterialType("");
			Map<String, Object> bindMap2 = new HashMap<String, Object>();
			bindMap2.putAll(bindMap);
			bindMap2.put("SubPackingQuantity",StorageSpec.getMATERIALQUANTITY2());
			bindMap2.put("MaterialCreateQuantity",StorageSpec.getMATERIALQUANTITY2());
			bindMap2.put("MaterialQuantity", StorageSpec.getMATERIALQUANTITY2());// 数量
			
			if(!locationNameCr.isEmpty() && locationNameCr.contains("现场仓")) {
				bindMap2.put("stockState", "StockOut");
			}

			createInfo2.setUserColumns(bindMap2);
			
			MaterialPackingServiceProxy.getMaterialPackingService().create(makeEventInfo, createInfo1);
			MaterialPackingServiceProxy.getMaterialPackingService().create(makeEventInfo, createInfo2);
		
			//更新原标签批次的库位状态为出库
			MaterialPackingKey materialPackingKey = new MaterialPackingKey("SDK",StorageSpec.getMaterialPackingName());
			Map<String, Object> hashMap3 = new HashMap<String,Object> ();
			hashMap3.put("stockState", "StockOut");
			setEventInfo.setUserColumns(hashMap3);
			MaterialPackingServiceProxy.getMaterialPackingService().setEvent(materialPackingKey, makeEventInfo, setEventInfo);
		}
		return true;
	}


	@Override
	public List<BSLabel> select(String s, Object[] objects, Class<?> aClass) throws IDMFrameDBErrorSignal {
		return Collections.emptyList();
	}

	@Override
	public List<BSLabel> selectNotThrow(String s, Object[] objects, Class<?> aClass) throws IDMFrameDBErrorSignal {
		return Collections.emptyList();
	}

	@Override
	public BSLabel selectByKey(BSLabelKey bsLabelKey) throws IDMFrameDBErrorSignal {
		return null;
	}

	@Override
	public BSLabel[] selectByKeyForBatch(BSLabelKey[] bsLabelKeys) throws IDMFrameDBErrorSignal {
		return new BSLabel[0];
	}

	@Override
	public List<BSLabel> selectByKey(List<BSLabelKey> list) throws IDMFrameDBErrorSignal {
		return Collections.emptyList();
	}

	@Override
	public BSLabel selectByKeyForUpdate(BSLabelKey bsLabelKey) throws IDMFrameDBErrorSignal {
		return null;
	}

	@Override
	public BSLabel[] selectByKeyForUpdateForBatch(BSLabelKey[] bsLabelKeys) throws IDMFrameDBErrorSignal {
		return new BSLabel[0];
	}

	@Override
	public int update(BSLabel bsLabel) throws IDMFrameDBErrorSignal {
		return 0;
	}

	@Override
	public int[] update(List<BSLabel> list) throws IDMFrameDBErrorSignal {
		return new int[0];
	}

	@Override
	public int[] update(BSLabel[] bsLabels) throws IDMFrameDBErrorSignal {
		return new int[0];
	}

	@Override
	public int update(BSLabel bsLabel, String s, Object[] objects) throws IDMFrameDBErrorSignal {
		return 0;
	}

	@Override
	public int insert(BSLabel bsLabel) throws IDMFrameDBErrorSignal {
		return 0;
	}

	@Override
	public int[] insert(List<BSLabel> list) throws IDMFrameDBErrorSignal {
		return new int[0];
	}

	@Override
	public int[] insert(BSLabel[] bsLabels) throws IDMFrameDBErrorSignal {
		return new int[0];
	}

	@Override
	public int delete(BSLabelKey bsLabelKey) throws IDMFrameDBErrorSignal {
		return 0;
	}

	@Override
	public int[] delete(List<BSLabelKey> list) throws IDMFrameDBErrorSignal {
		return new int[0];
	}

	@Override
	public int[] delete(BSLabelKey[] bsLabelKeys) throws IDMFrameDBErrorSignal {
		return new int[0];
	}

	@Override
	public int delete(String s, Object[] objects, Class<?> aClass) throws IDMFrameDBErrorSignal {
		return 0;
	}
}


