package com.steering.pss.plnsaleord.processOrder.base;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;

import CoreFS.SA08.CoreXmlSqlParsersFactory;

import com.steering.comm.tools.EntityTool;
import com.steering.pss.plnsaleord.base.PlnHelper;
import com.steering.pss.plnsaleord.planStove.StoveHelper;
import com.steering.pss.plnsaleord.steelMarkingPlan.FrmSteelMakingPlanChange;
import com.steering.pss.plnsaleord.stove.PlanFurnProduction;
import com.steering.pss.plnsaleord.stove.corePlanFurnProM;
import com.steering.pss.plnsaleord.processOrder.entity.PlnGxJgPropSEntity;
import com.steering.pss.plnsaleord.processOrder.entity.PlnOrderCastSEntity;
import com.steering.pss.plnsaleord.processOrder.entity.PlnOrderDbkSEntity;
import com.steering.pss.plnsaleord.processOrder.entity.PlnOrderDzSEntity;
import com.steering.pss.plnsaleord.processOrder.entity.PlnOrderJgxSEntity;
import com.steering.pss.plnsaleord.processOrder.entity.PlnOrderRclSEntity;
import com.steering.pss.plnsaleord.processOrder.entity.PlnOrderZgSEntity;
import com.steering.pss.plnsaleord.processOrder.entity.TimeEntity;
import com.steering.pss.plnsaleord.stove.entity.PlnZyDbkMEntity;

/**
 * 排产公共方法类(用于数据库操作)
 * 
 * @author peng
 */
public class ProducHelperBean {
	public static String StringPattern(String date, String oldPattern,
			String newPattern) {
		if (date == null || oldPattern == null || newPattern == null)
			return "";
		SimpleDateFormat sdf1 = new SimpleDateFormat(oldPattern); // 实例化模板对象
		SimpleDateFormat sdf2 = new SimpleDateFormat(newPattern); // 实例化模板对象
		Date d = null;
		try {
			d = sdf1.parse(date); // 将给定的字符串中的日期提取出来
		} catch (Exception e) { // 如果提供的字符串格式有错误，则进行异常处理
			e.printStackTrace(); // 打印异常信息
		}
		return sdf2.format(d);
	}

	/**
	 * 生成公共数据
	 * 
	 * @param con
	 * @param jsonStr
	 * @param processCode
	 * @return
	 * @throws SQLException
	 * @throws Exception
	 */
	public ProducEntity genertionProEntity(Connection con, String jsonStr,
			String processCode) throws SQLException, Exception {
		ProducEntity ducEntity = new ProducEntity();

		if (processCode.equals("B")) {
			// 铸造
			PlnOrderCastSEntity entity = BaseHelper.jsonToEntity(
					PlnOrderCastSEntity.class, jsonStr);
			PlnOrderCastSEntity entity1 = ProducHelperBean.getPlanOrder(con,
					entity.getProPlanId(), entity.getGxPlanNo(), processCode,
					PlnOrderCastSEntity.class);
			if (entity1 != null) {
				if (!(entity.getCic().equals(entity1.getCic())
						&& entity.getPlineCodeA().equals(
								entity1.getPlineCodeA())
						&& entity.getGradecode().equals(entity.getGradecode()) && entity
						.getStationDesc().equals(entity.getStationDesc()))) {

					entity1.setCraftNo(FrmSteelMakingPlanChange
							.queryFurnNoCraftNo(con, entity.getCic(),
									entity.getPlineCodeA(),
									entity.getGradecode(),
									entity.getStationDesc()));
				}

				ducEntity.setProPlanId(entity1.getProPlanId());
				ducEntity.setGxPlanNo(entity1.getGxPlanNo());
				ducEntity.setExeStatus(entity1.getExeStatus());
				ducEntity.setGxProSeq(Integer.parseInt(entity1.getGxProSeq()));
				ducEntity.setInwlId(entity1.getWlidIn());
				ducEntity.setOutwlId(entity1.getMaterialNo());
				ducEntity.setIsPlanOk(entity1.getIsPlanOk());
				ducEntity.setIsRepairPlan(entity1.getIsRepairPln());
				ducEntity.setRepairType(entity1.getRepairType());
				ducEntity.setObjEntity(entity1);
				ducEntity.setNumS(Integer.parseInt(entity1.getPlanNumS()));
				ducEntity.setWeigthS(Double.parseDouble(entity1.getPlanWtS()));
				ducEntity.setPlineName(entity1.getPlineName());
				ducEntity.setPlineCode(entity1.getPlineCode());
				ducEntity.setPlanTimeB(entity1.getPlanTimeB());
				ducEntity.setPlanTimeE(entity1.getPlanTimeE());
				ducEntity.setPlanUserTime(entity1.getPlanUsetime());
				ducEntity.setIssuedMan(entity1.getIssuedMan());
				ducEntity.setIssuedTime(entity1.getIssuedTime());
				ducEntity.setLastUndownMan(entity1.getLastUndownMan());
				ducEntity.setLastUndownTime(entity1.getLastUndownTime());
				ducEntity.setMemo(entity1.getMemo());
				ducEntity
						.setOrglgxProSeq(Integer.parseInt(entity.getGxProSeq()));
				ducEntity
						.setOrglPlanNum(Integer.parseInt(entity.getPlanNumS()));
				ducEntity
						.setOrglplanWgt(Double.parseDouble(entity.getPlanWtS()));
				ducEntity.setOrglPlineCode(entity.getPlineCode());
				ducEntity.setOrglPlineName(entity.getPlineName());
				ducEntity.setOrglPlanUserTime(entity.getPlanUsetime());
				ducEntity.setOrglPlanTimeB(StringPattern(entity.getPlanTimeB(),
						"yyyy-MM-dd HH:mm:ss", "yyyy-MM-dd HH:mm:ss"));
				ducEntity.setOrglRepairType(entity.getRepairType());

				ducEntity.setIfStoveIssued("");// 炉计划是否下发
				ducEntity.setProMonth(entity1.getProMonth());
				ducEntity.setInNumS(Integer.parseInt(entity1.getPlanNumS())
						- Integer.parseInt(entity1.getPlanedNum()));
				ducEntity.setInWeightS(Double.parseDouble(entity1.getPlanWtS())
						- Double.parseDouble(entity1.getPlanedWt()));
				ducEntity.setPlineCodeA(entity.getPlineCodeA());
				ducEntity.setPlineNameA(entity.getPlineNameA());
				ducEntity.setWeigthSMin(Double.parseDouble(entity1
						.getPlanWtMin()));
				ducEntity.setGowhereCode(entity1.getGowhereCode());
				ducEntity.setGowhereName(entity1.getGowhereName());
				ducEntity.setIfConfirm(entity1.getIfConfirm());
				ducEntity.setIfAmount(entity1.getIfAmount());
				ducEntity.setSteelJudgement(entity1.getSteelJudgement());
				ducEntity.setCraftPath(entity1.getCraftPath());
				ducEntity.setIfCraftLocked(entity1.getIfCraftLocked());
			}
		} else if (processCode.equals("C")) {
			// 锻造
			PlnOrderDzSEntity entity = BaseHelper.jsonToEntity(
					PlnOrderDzSEntity.class, jsonStr);
			PlnOrderDzSEntity entity1 = ProducHelperBean.getPlanOrder(con,
					entity.getProPlanId(), entity.getGxPlanNo(), processCode,
					PlnOrderDzSEntity.class);
			if (entity1 != null) {
				ducEntity.setProPlanId(entity1.getProPlanId());
				ducEntity.setGxPlanNo(entity1.getGxPlanNo());
				ducEntity.setExeStatus(entity1.getExeStatus());
				ducEntity.setGxProSeq(Integer.parseInt(entity1.getGxProSeq()));
				ducEntity.setInwlId(entity1.getWlidIn());
				ducEntity.setOutwlId(entity1.getOutwlId());
				ducEntity.setIsPlanOk(entity1.getIsPlanOk());
				ducEntity.setIsRepairPlan(entity1.getIsRepairPln());
				ducEntity.setRepairType(entity1.getRepairType());
				ducEntity.setObjEntity(entity1);
				ducEntity.setNumS(Integer.parseInt(entity1.getNumS()));
				ducEntity.setWeigthS(Double.parseDouble(entity1.getWeigthS()));
				ducEntity.setPlineName(entity1.getPlineName());
				ducEntity.setPlineCode(entity1.getPlineCode());
				ducEntity.setPlanTimeB(entity1.getPlanTimeB());
				ducEntity.setPlanTimeE(entity1.getPlanTimeE());
				ducEntity.setPlanUserTime(entity1.getPlanUsetime());
				ducEntity.setIssuedMan(entity1.getIssuedMan());
				ducEntity.setIssuedTime(entity1.getIssuedTime());
				ducEntity.setLastUndownMan(entity1.getLastUndownMan());
				ducEntity.setLastUndownTime(entity1.getLastUndownTime());
				ducEntity.setMemo("");
				ducEntity
						.setOrglgxProSeq(Integer.parseInt(entity.getGxProSeq()));
				ducEntity.setOrglPlanNum(Integer.parseInt(entity.getNumS()));
				ducEntity
						.setOrglplanWgt(Double.parseDouble(entity.getWeigthS()));
				ducEntity.setOrglPlineCode(entity.getPlineCode());
				ducEntity.setOrglPlineName(entity.getPlineName());
				ducEntity.setOrglPlanUserTime(entity.getPlanUsetime());
				ducEntity.setOrglPlanTimeB(entity.getPlanTimeB());
				ducEntity.setOrglRepairType(entity.getRepairType());
				ducEntity.setIfStoveIssued("");// 炉计划是否下发
				ducEntity.setProMonth(entity1.getProMonth());
				ducEntity.setInNumS(Integer.parseInt(entity.getNumS()));
				ducEntity.setInWeightS(Double.parseDouble(entity.getWeigthS()));
			}
		} else if (processCode.equals("D")) {
			// 轧管
			PlnOrderZgSEntity entity = BaseHelper.jsonToEntity(
					PlnOrderZgSEntity.class, jsonStr);
			PlnOrderZgSEntity entity1 = ProducHelperBean.getPlanOrder(con,
					entity.getProPlanId(), entity.getGxPlanNo(), processCode,
					PlnOrderZgSEntity.class);
			if (entity1 != null) {
				ducEntity.setPassCode(entity1.getPassCode());
				ducEntity.setPassName(entity1.getPassName());
				ducEntity.setMemo(entity.getMemo());
				ducEntity.setProPlanId(entity1.getProPlanId());
				ducEntity.setGxPlanNo(entity1.getGxPlanNo());
				ducEntity.setExeStatus(entity1.getExeStatus());
				ducEntity.setGxProSeq(Integer.parseInt(entity1.getGxProSeq()));
				ducEntity.setInwlId(entity1.getInwlId());
				ducEntity.setOutwlId(entity1.getOutwlId());
				ducEntity.setIsPlanOk(entity1.getIsPlanOk());
				ducEntity.setIsRepairPlan(entity1.getIsRepairPln());
				ducEntity.setRepairType(entity1.getRepairType());
				ducEntity.setObjEntity(entity1);
				ducEntity.setNumS(Integer.parseInt(entity1.getNumS()));
				ducEntity.setWeigthS(Double.parseDouble(entity1.getWeigthS()));
				ducEntity.setPlineName(entity1.getPlineName());
				ducEntity.setPlineCode(entity1.getPlineCode());
				ducEntity.setPlanTimeB(entity1.getPlanTimeB());
				ducEntity.setPlanTimeE(entity1.getPlanTimeE());
				ducEntity.setPlanUserTime(entity1.getPlanUsetime());
				ducEntity.setIssuedMan(entity1.getIssuedMan());
				ducEntity.setIssuedTime(entity1.getIssuedTime());
				ducEntity.setLastUndownMan(entity1.getLastUndownMan());
				ducEntity.setLastUndownTime(entity1.getLastUndownTime());
				ducEntity
						.setOrglgxProSeq(Integer.parseInt(entity.getGxProSeq()));
				ducEntity.setOrglPlanNum(Integer.parseInt(entity.getNumS()));
				ducEntity
						.setOrglplanWgt(Double.parseDouble(entity.getWeigthS()));
				ducEntity.setOrglPlineCode(entity.getPlineCode());
				ducEntity.setOrglPlineName(entity.getPlineName());
				ducEntity.setOrglPlanUserTime(entity.getPlanUsetime());
				ducEntity.setProOrderNo(entity1.getProOrderNo());
				ducEntity.setOrdLnDlyPk(entity1.getOrdLnDlyPk());
				ducEntity.setPlnDivideId(entity1.getPlnDivideId());
				ducEntity.setOrglPlanTimeB(entity.getPlanTimeB());
				ducEntity.setOrglRepairType(entity.getRepairType());
				ducEntity.setGpreqId(entity1.getGpreqId());
				ducEntity.setGpreqIfOk(entity1.getGpreqIfOk());
				ducEntity.setIfStoveIssued(entity1.getIfStoveIssued());// 炉计划是否下发
				ducEntity.setStoveIssuedMan(entity1.getStoveIssuedMan());
				ducEntity.setStoveIssuedTime(entity1.getStoveIssuedTime());
				ducEntity.setGpreqIfDz(entity1.getGpreqIfDz());
				ducEntity.setProMonth(entity1.getProMonth());
				if (!entity.getInNumS().equals("")) {
					ducEntity.setInNumS(Integer.parseInt(entity.getInNumS()));
				}
				if (!entity.getInWeightS().equals("")) {
					ducEntity.setInWeightS(Double.parseDouble(entity
							.getInWeightS()));
				}
				if (!entity.getAddNumIn().equals("")) {
					ducEntity
							.setAddNumIn(Integer.parseInt(entity.getAddNumIn()));
				}
				if (!entity.getAddWtIn().equals("")) {
					ducEntity
							.setAddWtIn(Double.parseDouble(entity.getAddWtIn()));
				}
				if (!entity.getMatchNumIn().equals("")) {
					ducEntity.setMatchNumIn(Integer.parseInt(entity
							.getMatchNumIn()));
				}
				if (!entity.getMatchWtIn().equals("")) {
					ducEntity.setMatchWtIn(Double.parseDouble(entity
							.getMatchWtIn()));
				}
				if (!entity.getBatchedNum().equals("")) {
					ducEntity.setBatchedNum(Integer.parseInt(entity
							.getBatchedNum()));
				}
				if (!entity.getBatchedWt().equals("")) {
					ducEntity.setBatchedWt(Double.parseDouble(entity
							.getBatchedWt()));
				}
				ducEntity.setMsc(entity1.getMsc());
				ducEntity.setIndexSeq(entity1.getIndexSeq());
				ducEntity.setBom(entity1.getBom());
				ducEntity.setWholeBacklogDesc(entity1.getWholeBacklogDesc());
				ducEntity.setPriority(entity1.getPriority());
				ducEntity.setPriorityMemo(entity1.getPriorityMemo());
				ducEntity.setIfLenControl(entity1.getIfLenControl());
				ducEntity.setIfMinusSicRoll(entity1.getIfMinusSicRoll());
				ducEntity.setTubeEndRatio(entity1.getTubeEndRatio());
				ducEntity.setGpreqNum(Integer.parseInt(entity1.getGpreqNum()));
				ducEntity.setGpreqWeight(Double.parseDouble(entity1
						.getGpreqWeight()));
				ducEntity.setWeigthSMin(Double.parseDouble(entity1
						.getWeigthSMin()));
				ducEntity.setPlansNum(Integer.parseInt(entity1.getPlansNum()));
				ducEntity.setVerify1(entity1.getVerify1());
				ducEntity.setVerify2(entity1.getVerify2());
				ducEntity.setVerify3(entity1.getVerify3());
				ducEntity.setPlansNum(Integer.parseInt(entity1.getPlansNum()));
				ducEntity.setOriginalNumber(entity1.getOriginalNumber());
				ducEntity.setProdStandard(entity1.getProdStandard());
				ducEntity.setOutputStandard(entity1.getOutputStandard());
				ducEntity.setDecision(entity1.getDecision());
				ducEntity.setThicknessWall(entity1.getThicknessWall());
				ducEntity.setProcessCodeC(entity1.getProcessCodeC());
				ducEntity.setProcessDescC(entity1.getProcessDescC());
				ducEntity.setOutsBilletFl(entity1.getOutsBilletFl());
				ducEntity.setApplyNo(entity1.getApplyNo());
				ducEntity.setApplyStatus(entity1.getApplyStatus());
				ducEntity.setIssuedMemo(entity1.getIssuedMemo());
				ducEntity.setActualWeight(entity1.getActualWeight());
				ducEntity.setProgyMemo(entity1.getProgyMemo());
				ducEntity.setPlineCodeZz(entity1.getPlineCodeZz());
				ducEntity.setPlineNameZz(entity1.getPlineNameZz());
				ducEntity.setGpreqWeightMin(Double.parseDouble(entity1
						.getGpreqWeightMin()));
				ducEntity.setGradecodeLk(entity1.getGradecodeLk());
				ducEntity.setGradenameLk(entity1.getGradenameLk());
				ducEntity.setCicGroupLk(entity1.getCicGroupLk());
				ducEntity.setZyBatchId(entity1.getZyBatchId());
				ducEntity.setGradename(entity1.getGradename());
				ducEntity.setGradecode(entity1.getGradecode());
				ducEntity.setDiameterGp(entity1.getDiameterGp());
			}
		} else if (processCode.equals("E")) {
			// 镦拔扩
			PlnOrderDbkSEntity entity = BaseHelper.jsonToEntity(
					PlnOrderDbkSEntity.class, jsonStr);
			PlnOrderDbkSEntity entity1 = ProducHelperBean.getPlanOrder(con,
					entity.getProPlanId(), entity.getGxPlanNo(), processCode,
					PlnOrderDbkSEntity.class);
			if (entity1 != null) {
				ducEntity.setPassCode(entity1.getPassCode());
				ducEntity.setPassName(entity1.getPassName());
				ducEntity.setFinalUserDesc(entity1.getFinalUserDesc());
				ducEntity.setDecision(entity1.getDecision());
				ducEntity.setProPlanId(entity1.getProPlanId());
				ducEntity.setGxPlanNo(entity1.getGxPlanNo());
				ducEntity.setExeStatus(entity1.getExeStatus());
				ducEntity.setGxProSeq(Integer.parseInt(entity1.getGxProSeq()));
				ducEntity.setInwlId(entity1.getInwlId());
				ducEntity.setOutwlId(entity1.getOutwlId());
				ducEntity.setIsPlanOk(entity1.getIsPlanOk());
				ducEntity.setIsRepairPlan(entity1.getIsRepairPln());
				ducEntity.setRepairType(entity1.getRepairType());
				ducEntity.setObjEntity(entity1);
				ducEntity.setNumS(Integer.parseInt(entity1.getNumS()));
				ducEntity.setWeigthS(Double.parseDouble(entity1.getWeigthS()));
				ducEntity.setPlineName(entity1.getPlineName());
				ducEntity.setPlineCode(entity1.getPlineCode());
				ducEntity.setPlanTimeB(entity1.getPlanTimeB());
				ducEntity.setPlanTimeE(entity1.getPlanTimeE());
				ducEntity.setPlanUserTime(entity1.getPlanUsetime());
				ducEntity.setIssuedMan(entity1.getIssuedMan());
				ducEntity.setIssuedTime(entity1.getIssuedTime());
				ducEntity.setLastUndownMan(entity1.getLastUndownMan());
				ducEntity.setLastUndownTime(entity1.getLastUndownTime());
				ducEntity.setMemo(entity1.getMemo());
				ducEntity.setOrglMemo(entity.getMemo());
				ducEntity
						.setOrglgxProSeq(Integer.parseInt(entity.getGxProSeq()));
				ducEntity.setOrglPlanNum(Integer.parseInt(entity.getNumS()));
				ducEntity
						.setOrglplanWgt(Double.parseDouble(entity.getWeigthS()));
				ducEntity.setOrglPlineCode(entity.getPlineCode());
				ducEntity.setOrglPlineName(entity.getPlineName());
				ducEntity.setOrglPlanUserTime(entity.getPlanUsetime());
				ducEntity.setProOrderNo(entity1.getProOrderNo());
				ducEntity.setOrdLnDlyPk(entity1.getOrdLnDlyPk());
				ducEntity.setPlnDivideId(entity1.getPlnDivideId());
				ducEntity.setOrglPlanTimeB(entity.getPlanTimeB());
				ducEntity.setOrglRepairType(entity.getRepairType());
				ducEntity.setProMonth(entity1.getProMonth());
				ducEntity.setIfStoveIssued(entity1.getIfStoveIssued());// 炉计划是否下发
				if (!entity.getInNumS().equals("")) {
					ducEntity.setInNumS(Integer.parseInt(entity.getInNumS()));
				}
				if (!entity.getInWeightS().equals("")) {
					ducEntity.setInWeightS(Double.parseDouble(entity
							.getInWeightS()));
				}
				if (!entity.getAddNumIn().equals("")) {
					ducEntity
							.setAddNumIn(Integer.parseInt(entity.getAddNumIn()));
				}
				if (!entity.getAddWtIn().equals("")) {
					ducEntity
							.setAddWtIn(Double.parseDouble(entity.getAddWtIn()));
				}
				if (!entity.getMatchNumIn().equals("")) {
					ducEntity.setMatchNumIn(Integer.parseInt(entity
							.getMatchNumIn()));
				}
				if (!entity.getMatchWtIn().equals("")) {
					ducEntity.setMatchWtIn(Double.parseDouble(entity
							.getMatchWtIn()));
				}
				if (!entity.getBatchedNum().equals("")) {
					ducEntity.setBatchedNum(Integer.parseInt(entity
							.getBatchedNum()));
				}
				if (!entity.getBatchedWt().equals("")) {
					ducEntity.setBatchedWt(Double.parseDouble(entity
							.getBatchedWt()));
				}
				if (!entity.getRealBatchNum().equals("")) {
					ducEntity.setRealBatchNum(Integer.parseInt(entity
							.getRealBatchNum()));
				}
				if (!entity.getRealBatchWt().equals("")) {
					ducEntity.setRealBatchWt(Double.parseDouble(entity
							.getRealBatchWt()));
				}
				ducEntity.setMsc(entity1.getMsc());
				ducEntity.setIndexSeq(entity1.getIndexSeq());
				ducEntity.setBom(entity1.getBom());
				ducEntity.setWholeBacklogDesc(entity1.getWholeBacklogDesc());
				ducEntity.setPriority(entity1.getPriority());
				ducEntity.setPriorityMemo(entity1.getPriorityMemo());
				ducEntity.setWeigthSMin(Double.parseDouble(entity1
						.getWeigthSMin()));
				ducEntity.setProcessCodeC(entity1.getProcessCodeC());
				ducEntity.setProcessDescC(entity1.getProcessDescC());
				ducEntity.setZyBatchId(entity1.getZyBatchId());
			}
		} else if (processCode.equals("F")) {
			// 热处理
			PlnOrderRclSEntity entity = BaseHelper.jsonToEntity(
					PlnOrderRclSEntity.class, jsonStr);
			PlnOrderRclSEntity entity1 = ProducHelperBean.getPlanOrder(con,
					entity.getProPlanId(), entity.getGxPlanNo(), processCode,
					PlnOrderRclSEntity.class);
			if (entity1 != null) {
				ducEntity.setDecision(entity1.getDecision());
				ducEntity.setProPlanId(entity1.getProPlanId());
				ducEntity.setGxPlanNo(entity1.getGxPlanNo());
				ducEntity.setExeStatus(entity1.getExeStatus());
				ducEntity.setGxProSeq(Integer.parseInt(entity1.getGxProSeq()));
				ducEntity.setInwlId(entity1.getInwlId());
				ducEntity.setOutwlId(entity1.getOutwlId());
				ducEntity.setIsPlanOk(entity1.getIsPlanOk());
				ducEntity.setIsRepairPlan(entity1.getIsRepairPln());
				ducEntity.setRepairType(entity1.getRepairType());
				ducEntity.setObjEntity(entity1);
				ducEntity.setNumS(Integer.parseInt(entity1.getNumS()));
				ducEntity.setWeigthS(Double.parseDouble(entity1.getWeigthS()));
				ducEntity.setPlineName(entity1.getPlineName());
				ducEntity.setPlineCode(entity1.getPlineCode());
				ducEntity.setPlanTimeB(entity1.getPlanTimeB());
				ducEntity.setPlanTimeE(entity1.getPlanTimeE());
				ducEntity.setPlanUserTime(entity1.getPlanUsetime());
				ducEntity.setIssuedMan(entity1.getIssuedMan());
				ducEntity.setIssuedTime(entity1.getIssuedTime());
				ducEntity.setLastUndownMan(entity1.getLastUndownMan());
				ducEntity.setLastUndownTime(entity1.getLastUndownTime());
				ducEntity.setMemo(entity1.getMemo());
				ducEntity.setOrglMemo(entity.getMemo());
				ducEntity
						.setOrglgxProSeq(Integer.parseInt(entity.getGxProSeq()));
				ducEntity.setOrglPlanNum(Integer.parseInt(entity.getNumS()));
				ducEntity
						.setOrglplanWgt(Double.parseDouble(entity.getWeigthS()));
				ducEntity.setOrglPlineCode(entity.getPlineCode());
				ducEntity.setOrglPlineName(entity.getPlineName());
				ducEntity.setOrglPlanUserTime(entity.getPlanUsetime());
				ducEntity.setPlanGroup(entity1.getGroupRcl());
				ducEntity.setOrglPlanGroup(entity.getGroupRcl());
				ducEntity.setProOrderNo(entity1.getProOrderNo());
				ducEntity.setOrdLnDlyPk(entity1.getOrdLnDlyPk());
				ducEntity.setPlnDivideId(entity1.getPlnDivideId());
				ducEntity.setOrglPlanTimeB(entity.getPlanTimeB());
				ducEntity.setOrglRepairType(entity.getRepairType());
				ducEntity.setProcessCodeC(entity1.getProcessCodeC());
				ducEntity.setProcessDescC(entity1.getProcessDescC());
				ducEntity.setIfStoveIssued("");// 炉计划是否下发
				ducEntity.setProMonth(entity1.getProMonth());
				if (!entity.getInNumS().equals("")) {
					ducEntity.setInNumS(Integer.parseInt(entity.getInNumS()));
				}
				if (!entity.getInWeightS().equals("")) {
					ducEntity.setInWeightS(Double.parseDouble(entity
							.getInWeightS()));
				}
				if (!entity.getAddNumIn().equals("")) {
					ducEntity
							.setAddNumIn(Integer.parseInt(entity.getAddNumIn()));
				}
				if (!entity.getAddWtIn().equals("")) {
					ducEntity
							.setAddWtIn(Double.parseDouble(entity.getAddWtIn()));
				}
				if (!entity.getMatchNumIn().equals("")) {
					ducEntity.setMatchNumIn(Integer.parseInt(entity
							.getMatchNumIn()));
				}
				if (!entity.getMatchWtIn().equals("")) {
					ducEntity.setMatchWtIn(Double.parseDouble(entity
							.getMatchWtIn()));
				}
				if (!entity.getBatchedNum().equals("")) {
					ducEntity.setBatchedNum(Integer.parseInt(entity
							.getBatchedNum()));
				}
				if (!entity.getBatchedWt().equals("")) {
					ducEntity.setBatchedWt(Double.parseDouble(entity
							.getBatchedWt()));
				}
				ducEntity.setMsc(entity1.getMsc());
				ducEntity.setIndexSeq(entity1.getIndexSeq());
				ducEntity.setBom(entity1.getBom());
				ducEntity.setWholeBacklogDesc(entity1.getWholeBacklogDesc());
				ducEntity.setPriority(entity1.getPriority());
				ducEntity.setPriorityMemo(entity1.getPriorityMemo());
				ducEntity.setWeigthSMin(Double.parseDouble(entity1
						.getWeigthSMin()));
				ducEntity.setPrdcrAdvcDay(entity1.getPrdcrAdvcDay());
				ducEntity.setZyBatchId(entity1.getZyBatchId());
			}
		} else if (processCode.equals("G")) {
			// 加工
			PlnOrderJgxSEntity entity = BaseHelper.jsonToEntity(
					PlnOrderJgxSEntity.class, jsonStr);
			PlnOrderJgxSEntity entity1 = ProducHelperBean.getPlanOrder(con,
					entity.getProPlanId(), entity.getGxPlanNo(), processCode,
					PlnOrderJgxSEntity.class);
			if (entity1 != null) {
				ducEntity.setDecision(entity1.getDecision());
				ducEntity.setProPlanId(entity1.getProPlanId());
				ducEntity.setGxPlanNo(entity1.getGxPlanNo());
				ducEntity.setExeStatus(entity1.getExeStatus());
				ducEntity.setGxProSeq(Integer.parseInt(entity1.getGxProSeq()));
				ducEntity.setInwlId(entity1.getInwlId());
				ducEntity.setOutwlId(entity1.getOutwlId());
				ducEntity.setIsPlanOk(entity1.getIsPlanOk());
				ducEntity.setIsRepairPlan(entity1.getIsRepairPln());
				ducEntity.setRepairType(entity1.getRepairType());
				ducEntity.setObjEntity(entity1);
				ducEntity.setNumS(Integer.parseInt(entity1.getNumS()));
				ducEntity.setWeigthS(Double.parseDouble(entity1.getWeigthS()));
				ducEntity.setPlineName(entity1.getPlineName());
				ducEntity.setPlineCode(entity1.getPlineCode());
				ducEntity.setPlanTimeB(entity1.getPlanTimeB());
				ducEntity.setPlanTimeE(entity1.getPlanTimeE());
				ducEntity.setPlanUserTime(entity1.getPlanUsetime());
				ducEntity.setIssuedMan(entity1.getIssuedMan());
				ducEntity.setIssuedTime(entity1.getIssuedTime());
				ducEntity.setLastUndownMan(entity1.getLastUndownMan());
				ducEntity.setLastUndownTime(entity1.getLastUndownTime());
				ducEntity.setMemo(entity1.getMemo());
				ducEntity.setOrglMemo(entity.getMemo());
				ducEntity
						.setOrglgxProSeq(Integer.parseInt(entity.getGxProSeq()));
				ducEntity.setOrglPlanNum(Integer.parseInt(entity.getNumS()));
				ducEntity
						.setOrglplanWgt(Double.parseDouble(entity.getWeigthS()));
				ducEntity.setOrglPlineCode(entity.getPlineCode());
				ducEntity.setOrglPlineName(entity.getPlineName());
				ducEntity.setOrglPlanUserTime(entity.getPlanUsetime());
				ducEntity.setPlanGroup(entity1.getGroupJgx());
				ducEntity.setOrglPlanGroup(entity.getGroupJgx());
				ducEntity.setProOrderNo(entity1.getProOrderNo());
				ducEntity.setOrdLnDlyPk(entity1.getOrdLnDlyPk());
				ducEntity.setPlnDivideId(entity1.getPlnDivideId());
				ducEntity.setOrglPlanTimeB(entity.getPlanTimeB());
				ducEntity.setOrglRepairType(entity.getRepairType());
				ducEntity.setProcessCodeC(entity1.getProcessCodeC());
				ducEntity.setProcessDescC(entity1.getProcessDescC());
				ducEntity.setIfStoveIssued("");// 炉计划是否下发
				ducEntity.setProMonth(entity1.getProMonth());
				if (!entity.getInNumS().equals("")) {
					ducEntity.setInNumS(Integer.parseInt(entity.getInNumS()));
				}
				if (!entity.getInWeightS().equals("")) {
					ducEntity.setInWeightS(Double.parseDouble(entity
							.getInWeightS()));
				}
				if (!entity.getAddNumIn().equals("")) {
					ducEntity
							.setAddNumIn(Integer.parseInt(entity.getAddNumIn()));
				}
				if (!entity.getAddWtIn().equals("")) {
					ducEntity
							.setAddWtIn(Double.parseDouble(entity.getAddWtIn()));
				}
				if (!entity.getMatchNumIn().equals("")) {
					ducEntity.setMatchNumIn(Integer.parseInt(entity
							.getMatchNumIn()));
				}
				if (!entity.getMatchWtIn().equals("")) {
					ducEntity.setMatchWtIn(Double.parseDouble(entity
							.getMatchWtIn()));
				}
				if (!entity.getBatchedNum().equals("")) {
					ducEntity.setBatchedNum(Integer.parseInt(entity
							.getBatchedNum()));
				}
				if (!entity.getBatchedWt().equals("")) {
					ducEntity.setBatchedWt(Double.parseDouble(entity
							.getBatchedWt()));
				}
				ducEntity.setMsc(entity1.getMsc());
				ducEntity.setIndexSeq(entity1.getIndexSeq());
				ducEntity.setBom(entity1.getBom());
				ducEntity.setPriority(entity1.getPriority());
				ducEntity.setPriorityMemo(entity1.getPriorityMemo());
				ducEntity.setZyBatchId(entity1.getZyBatchId());
			}
		} else if (processCode.equals("H")) {
			// 接箍
			PlnGxJgPropSEntity entity = BaseHelper.jsonToEntity(
					PlnGxJgPropSEntity.class, jsonStr);
			PlnGxJgPropSEntity entity1 = ProducHelperBean.getPlanOrder(con,
					entity.getProPlanId(), entity.getGxPlanNo(), processCode,
					PlnGxJgPropSEntity.class);
			if (entity1 != null) {
				ducEntity.setOrdLnDlyPk(entity1.getOrdLnDlyPk());
				ducEntity.setPlnDivideId(entity1.getPlnDivideId());
				ducEntity.setJgGroupId(entity1.getJgGroupId());
				ducEntity.setProPlanId(entity1.getProPlanId());
				ducEntity.setGxPlanNo(entity1.getGxPlanNo());
				ducEntity.setExeStatus(entity1.getExeStatus());
				ducEntity.setGxProSeq(Integer.parseInt(entity1.getGxProSeq()));
				ducEntity.setInwlId(entity1.getBlWlId());
				ducEntity.setOutwlId(entity1.getOutwlId());
				ducEntity.setIsPlanOk(entity1.getIsPlanOk());
				ducEntity.setIsRepairPlan(entity1.getIsRepairPln());
				ducEntity.setRepairType(entity1.getRepairType());
				ducEntity.setObjEntity(entity1);
				ducEntity.setNumS(Integer.parseInt(entity1.getGroupNumS()));
				ducEntity.setWeigthS(Double.parseDouble(entity1.getGroupWtS()));// 接箍排产重量
				ducEntity.setPlineName(entity1.getPlineName());
				ducEntity.setPlineCode(entity1.getPlineCode());
				ducEntity.setPlanTimeB(entity1.getPlanTimeB());
				ducEntity.setPlanTimeE(entity1.getPlanTimeE());
				ducEntity.setPlanUserTime(entity1.getPlanUsetime());
				ducEntity.setIssuedMan(entity1.getIssuedMan());
				ducEntity.setIssuedTime(entity1.getIssuedTime());
				ducEntity.setLastUndownMan(entity1.getLastUndownMan());
				ducEntity.setLastUndownTime(entity1.getLastUndownTime());
				ducEntity.setMemo("");// 备注
				ducEntity.setOrglMemo("");
				ducEntity
						.setOrglgxProSeq(Integer.parseInt(entity.getGxProSeq()));
				// ducEntity.setOrglPlanNum(Integer
				// .parseInt(entity.getGroupNumS()));
				// ducEntity.setOrglplanWgt(Double.parseDouble(entity.getGroupWtS()));
				ducEntity.setOrglPlineCode(entity.getPlineCode());
				ducEntity.setOrglPlineName(entity.getPlineName());
				ducEntity.setOrglPlanUserTime(entity1.getPlanUsetime());
				ducEntity.setOrglPlanTimeB(entity.getPlanTimeB());
				ducEntity.setOrglRepairType(entity.getRepairType());
				ducEntity.setIfStoveIssued(entity.getIsStoveIssued());// 炉计划是否下发
				ducEntity.setProMonth(entity1.getProMonth());
				if (!entity.getGroupBlNumS().equals("")) {
					ducEntity.setInNumS(Integer.parseInt(entity1
							.getGroupBlNumS()));
				}
				if (!entity.getGroupBlWtS().equals("")) {
					ducEntity.setInWeightS(Double.parseDouble(entity1
							.getGroupBlWtS()));
				}

				// if (!entity.getMatchnumBl().equals("")) {
				// ducEntity.setMatchNumIn(Integer.parseInt(entity1
				// .getMatchnumBl()));
				// }
				// if (!entity.getMatchwtBl().equals("")) {
				// ducEntity.setMatchWtIn(Double.parseDouble(entity1
				// .getMatchwtBl()));
				// }
				// if (!entity.getBatchedNum().equals("")) {
				// ducEntity.setBatchedNum(Integer.parseInt(entity1
				// .getBatchedNum()));
				// }
				// if (!entity.getBatchedWt().equals("")) {
				// ducEntity.setBatchedWt(Double.parseDouble(entity1
				// .getBatchedWt()));
				// }
				// if (!entity.getRealBatchedNum().equals("")) {
				// ducEntity.setRealBatchNum(Integer.parseInt(entity1
				// .getRealBatchedNum()));
				// }
				// if (!entity.getRealBatchedWt().equals("")) {
				// ducEntity.setRealBatchWt(Double.parseDouble(entity1
				// .getRealBatchedWt()));
				// }
				ducEntity.setSingleCutNun(entity1.getSingleCutNun());
			}
		}
		return ducEntity;
	}

	/**
	 * 查询排产信息
	 * 
	 * @param con
	 * @param proPlanId
	 *            订单编号
	 * @param gxPlanNo
	 *            排产序号
	 * @return PlnOrderCastSEntity
	 * @throws SQLException
	 */
	public static <T> T getPlanOrder(Connection con, String proPlanId,
			String gxPlanNo, String processCode, Class<T> cls)
			throws SQLException {
		String sql = "";
		if (processCode.equals("B")) {
			sql = CoreXmlSqlParsersFactory
					.getSql("ProducHelperBean.getPlanOrderB");
		} else if (processCode.equals("C")) {
			sql = CoreXmlSqlParsersFactory
					.getSql("ProducHelperBean.getPlanOrderC");
		} else if (processCode.equals("D")) {
			sql = CoreXmlSqlParsersFactory
					.getSql("ProducHelperBean.getPlanOrderD");
		} else if (processCode.equals("E")) {
			sql = CoreXmlSqlParsersFactory
					.getSql("ProducHelperBean.getPlanOrderE");
		} else if (processCode.equals("F")) {
			sql = CoreXmlSqlParsersFactory
					.getSql("ProducHelperBean.getPlanOrderF");
		} else if (processCode.equals("G")) {
			sql = CoreXmlSqlParsersFactory
					.getSql("ProducHelperBean.getPlanOrderG");
		} else if (processCode.equals("H")) {
			sql = CoreXmlSqlParsersFactory
					.getSql("ProducHelperBean.getPlanOrderH");
		}
		sql += " AND T.PRO_PLAN_ID = ?  AND T.GX_PLAN_NO = ?";
		PreparedStatement ps = con.prepareStatement(sql);
		ps.setObject(1, proPlanId);
		ps.setObject(2, gxPlanNo);
		ResultSet rs = ps.executeQuery();
		T t = EntityTool.getEntityByRs(rs, cls);
		rs.close();
		ps.close();
		return t;
	}

	/**
	 * 修改排产
	 * 
	 * @param con
	 * @param
	 * @throws SQLException
	 */
	public void updatePlanOrder(Connection con, ProducEntity proEntity,
			String processCode, String proMonth) throws SQLException {
		String sql = "";
		if (processCode.equals("B")) {
			sql = CoreXmlSqlParsersFactory
					.getSql("ProducHelperBean.updatePlanOrderB");
			PlnOrderCastSEntity entity = (PlnOrderCastSEntity) proEntity
					.getObjEntity();
			entity.setPlineCode(proEntity.getPlineCode());
			entity.setPlineName(proEntity.getPlineName());
			entity.setPlanNumS(String.valueOf(proEntity.getNumS()));
			entity.setPlanWtS(String.valueOf(proEntity.getWeigthS()));
			entity.setPlanUsetime(proEntity.getPlanUserTime());
			entity.setPlanTimeB(proEntity.getPlanTimeB());
			entity.setPlanTimeE(proEntity.getPlanTimeE());
			entity.setGxProSeq(String.valueOf(proEntity.getGxProSeq()));
			entity.setIsPlanOk(proEntity.getIsPlanOk());
			entity.setIsRepairPln(proEntity.getIsRepairPlan());
			entity.setRepairType(proEntity.getRepairType());
			entity.setIssuedMan(proEntity.getIssuedMan());
			entity.setIssuedTime(proEntity.getIssuedTime());
			entity.setLastUndownMan(proEntity.getLastUndownMan());
			entity.setLastUndownTime(proEntity.getLastUndownTime());
			entity.setMemo(proEntity.getMemo());
			entity.setProMonth(proMonth);
			entity.setPlineCodeA(proEntity.getPlineCodeA());
			entity.setPlineNameA(proEntity.getPlineNameA());
			entity.setGxPlanNo(proEntity.getGxPlanNo());
			entity.setExeStatus(proEntity.getExeStatus());
			entity.setPlanWtMin(String.valueOf(proEntity.getWeigthSMin()));

			sql = EntityTool.fillSqlByEntity(sql, entity);
		} else if (processCode.equals("C")) {
			sql = CoreXmlSqlParsersFactory
					.getSql("ProducHelperBean.updatePlanOrderC");
			PlnOrderDzSEntity entity = (PlnOrderDzSEntity) proEntity
					.getObjEntity();
			entity.setPlineCode(proEntity.getPlineCode());
			entity.setPlineName(proEntity.getPlineName());
			entity.setNumS(String.valueOf(proEntity.getNumS()));
			entity.setWeigthS(String.valueOf(proEntity.getWeigthS()));
			entity.setPlanUsetime(proEntity.getPlanUserTime());
			entity.setPlanTimeB(proEntity.getPlanTimeB());
			entity.setPlanTimeE(proEntity.getPlanTimeE());
			entity.setGxProSeq(String.valueOf(proEntity.getGxProSeq()));
			entity.setIsPlanOk(proEntity.getIsPlanOk());
			entity.setIsRepairPln(proEntity.getIsRepairPlan());
			entity.setRepairType(proEntity.getRepairType());
			entity.setIssuedMan(proEntity.getIssuedMan());
			entity.setIssuedTime(proEntity.getIssuedTime());
			entity.setLastUndownMan(proEntity.getLastUndownMan());
			entity.setLastUndownTime(proEntity.getLastUndownTime());
			entity.setProMonth(proMonth);
			sql = EntityTool.fillSqlByEntity(sql, entity);
		} else if (processCode.equals("D")) {
			sql = CoreXmlSqlParsersFactory
					.getSql("ProducHelperBean.updatePlanOrderD");
			PlnOrderZgSEntity entity = (PlnOrderZgSEntity) proEntity
					.getObjEntity();
			entity.setPlineCode(proEntity.getPlineCode());
			entity.setPlineName(proEntity.getPlineName());
			entity.setNumS(String.valueOf(proEntity.getNumS()));
			entity.setWeigthS(String.valueOf(proEntity.getWeigthS()));
			entity.setPlanUsetime(proEntity.getPlanUserTime());
			entity.setPlanTimeB(proEntity.getPlanTimeB());
			entity.setPlanTimeE(proEntity.getPlanTimeE());
			entity.setGxProSeq(String.valueOf(proEntity.getGxProSeq()));
			entity.setIsPlanOk(proEntity.getIsPlanOk());
			entity.setIsRepairPln(proEntity.getIsRepairPlan());
			entity.setRepairType(proEntity.getRepairType());
			entity.setIssuedMan(proEntity.getIssuedMan());
			entity.setIssuedTime(proEntity.getIssuedTime());
			entity.setLastUndownMan(proEntity.getLastUndownMan());
			entity.setLastUndownTime(proEntity.getLastUndownTime());
			// entity.setMemo(proEntity.getMemo());
			entity.setProMonth(proMonth);
			entity.setAddNumIn(String.valueOf(proEntity.getAddNumIn()));
			entity.setAddWtIn(String.valueOf(proEntity.getAddWtIn()));
			entity.setInNumS(String.valueOf(proEntity.getInNumS()));
			entity.setInWeightS(String.valueOf(proEntity.getInWeightS()));
			entity.setBatchedNum(String.valueOf(proEntity.getBatchedNum()));
			entity.setBatchedWt(String.valueOf(proEntity.getBatchedWt()));
			entity.setMatchNumIn(String.valueOf(proEntity.getMatchNumIn()));
			entity.setMatchWtIn(String.valueOf(proEntity.getMatchWtIn()));
			entity.setGpreqNum(String.valueOf(proEntity.getGpreqNum()));
			entity.setGpreqWeight(String.valueOf(proEntity.getGpreqWeight()));
			entity.setWeigthSMin(String.valueOf(proEntity.getWeigthSMin()));
			entity.setPlansNum(String.valueOf(proEntity.getPlansNum()));
			entity.setOriginalNumber(proEntity.getOriginalNumber());
			entity.setActualWeight(proEntity.getActualWeight());
			entity.setGpreqWeightMin(String.valueOf(proEntity
					.getGpreqWeightMin()));
			sql = EntityTool.fillSqlByEntity(sql, entity);
		} else if (processCode.equals("E")) {
			sql = CoreXmlSqlParsersFactory
					.getSql("ProducHelperBean.updatePlanOrderE");
			PlnOrderDbkSEntity entity = (PlnOrderDbkSEntity) proEntity
					.getObjEntity();
			entity.setPlineCode(proEntity.getPlineCode());
			entity.setPlineName(proEntity.getPlineName());
			entity.setNumS(String.valueOf(proEntity.getNumS()));
			entity.setWeigthS(String.valueOf(proEntity.getWeigthS()));
			entity.setPlanUsetime(proEntity.getPlanUserTime());
			entity.setPlanTimeB(proEntity.getPlanTimeB());
			entity.setPlanTimeE(proEntity.getPlanTimeE());
			entity.setGxProSeq(String.valueOf(proEntity.getGxProSeq()));
			entity.setIsPlanOk(proEntity.getIsPlanOk());
			entity.setIsRepairPln(proEntity.getIsRepairPlan());
			entity.setRepairType(proEntity.getRepairType());
			entity.setIssuedMan(proEntity.getIssuedMan());
			entity.setIssuedTime(proEntity.getIssuedTime());
			entity.setLastUndownMan(proEntity.getLastUndownMan());
			entity.setLastUndownTime(proEntity.getLastUndownTime());
			entity.setMemo(proEntity.getMemo());
			entity.setAddNumIn(String.valueOf(proEntity.getAddNumIn()));
			entity.setAddWtIn(String.valueOf(proEntity.getAddWtIn()));
			entity.setInNumS(String.valueOf(proEntity.getInNumS()));
			entity.setInWeightS(String.valueOf(proEntity.getInWeightS()));
			entity.setBatchedNum(String.valueOf(proEntity.getBatchedNum()));
			entity.setBatchedWt(String.valueOf(proEntity.getBatchedWt()));
			entity.setRealBatchNum(String.valueOf(proEntity.getRealBatchNum()));
			entity.setRealBatchWt(String.valueOf(proEntity.getRealBatchWt()));
			entity.setMatchNumIn(String.valueOf(proEntity.getMatchNumIn()));
			entity.setMatchWtIn(String.valueOf(proEntity.getMatchWtIn()));
			entity.setProMonth(proMonth);
			entity.setWeigthSMin(String.valueOf(proEntity.getWeigthSMin()));
			sql = EntityTool.fillSqlByEntity(sql, entity);
		} else if (processCode.equals("F")) {
			sql = CoreXmlSqlParsersFactory
					.getSql("ProducHelperBean.updatePlanOrderF");
			PlnOrderRclSEntity entity = (PlnOrderRclSEntity) proEntity
					.getObjEntity();
			entity.setPlineCode(proEntity.getPlineCode());
			entity.setPlineName(proEntity.getPlineName());
			entity.setNumS(String.valueOf(proEntity.getNumS()));
			entity.setWeigthS(String.valueOf(proEntity.getWeigthS()));
			entity.setPlanUsetime(proEntity.getPlanUserTime());
			entity.setPlanTimeB(proEntity.getPlanTimeB());
			entity.setPlanTimeE(proEntity.getPlanTimeE());
			entity.setGxProSeq(String.valueOf(proEntity.getGxProSeq()));
			entity.setIsPlanOk(proEntity.getIsPlanOk());
			entity.setIsRepairPln(proEntity.getIsRepairPlan());
			entity.setRepairType(proEntity.getRepairType());
			entity.setIssuedMan(proEntity.getIssuedMan());
			entity.setIssuedTime(proEntity.getIssuedTime());
			entity.setLastUndownMan(proEntity.getLastUndownMan());
			entity.setLastUndownTime(proEntity.getLastUndownTime());
			entity.setMemo(proEntity.getMemo());
			entity.setProMonth(proMonth);
			entity.setAddNumIn(String.valueOf(proEntity.getAddNumIn()));
			entity.setAddWtIn(String.valueOf(proEntity.getAddWtIn()));
			entity.setInNumS(String.valueOf(proEntity.getInNumS()));
			entity.setInWeightS(String.valueOf(proEntity.getInWeightS()));
			entity.setBatchedNum(String.valueOf(proEntity.getBatchedNum()));
			entity.setBatchedWt(String.valueOf(proEntity.getBatchedWt()));
			entity.setMatchNumIn(String.valueOf(proEntity.getMatchNumIn()));
			entity.setMatchWtIn(String.valueOf(proEntity.getMatchWtIn()));
			entity.setWeigthSMin(String.valueOf(proEntity.getWeigthSMin()));
			entity.setGroupRcl(proEntity.getOrglPlanGroup());
			sql = EntityTool.fillSqlByEntity(sql, entity);
		} else if (processCode.equals("G")) {
			sql = CoreXmlSqlParsersFactory
					.getSql("ProducHelperBean.updatePlanOrderG");
			PlnOrderJgxSEntity entity = (PlnOrderJgxSEntity) proEntity
					.getObjEntity();
			entity.setPlineCode(proEntity.getPlineCode());
			entity.setPlineName(proEntity.getPlineName());
			entity.setNumS(String.valueOf(proEntity.getNumS()));
			entity.setWeigthS(String.valueOf(proEntity.getWeigthS()));
			entity.setPlanUsetime(proEntity.getPlanUserTime());
			entity.setPlanTimeB(proEntity.getPlanTimeB());
			entity.setPlanTimeE(proEntity.getPlanTimeE());
			entity.setGxProSeq(String.valueOf(proEntity.getGxProSeq()));
			entity.setIsPlanOk(proEntity.getIsPlanOk());
			entity.setIsRepairPln(proEntity.getIsRepairPlan());
			entity.setRepairType(proEntity.getRepairType());
			entity.setIssuedMan(proEntity.getIssuedMan());
			entity.setIssuedTime(proEntity.getIssuedTime());
			entity.setLastUndownMan(proEntity.getLastUndownMan());
			entity.setLastUndownTime(proEntity.getLastUndownTime());
			entity.setMemo(proEntity.getMemo());
			entity.setProMonth(proMonth);
			entity.setAddNumIn(String.valueOf(proEntity.getAddNumIn()));
			entity.setAddWtIn(String.valueOf(proEntity.getAddWtIn()));
			entity.setInNumS(String.valueOf(proEntity.getInNumS()));
			entity.setInWeightS(String.valueOf(proEntity.getInWeightS()));
			entity.setBatchedNum(String.valueOf(proEntity.getBatchedNum()));
			entity.setBatchedWt(String.valueOf(proEntity.getBatchedWt()));
			entity.setMatchNumIn(String.valueOf(proEntity.getMatchNumIn()));
			entity.setMatchWtIn(String.valueOf(proEntity.getMatchWtIn()));
			entity.setGroupJgx(proEntity.getOrglPlanGroup());
			sql = EntityTool.fillSqlByEntity(sql, entity);
		} else if (processCode.equals("H")) {
			sql = CoreXmlSqlParsersFactory
					.getSql("ProducHelperBean.updatePlanOrderH");
			PlnGxJgPropSEntity entity = (PlnGxJgPropSEntity) proEntity
					.getObjEntity();
			entity.setPlineCode(proEntity.getPlineCode());
			entity.setPlineName(proEntity.getPlineName());
			entity.setGroupNumS(String.valueOf(proEntity.getNumS()));
			entity.setPlanUsetime(proEntity.getPlanUserTime());
			entity.setPlanTimeB(proEntity.getPlanTimeB());
			entity.setPlanTimeE(proEntity.getPlanTimeE());
			entity.setGxProSeq(String.valueOf(proEntity.getGxProSeq()));
			entity.setIsPlanOk(proEntity.getIsPlanOk());
			entity.setIsRepairPln(proEntity.getIsRepairPlan());
			entity.setRepairType(proEntity.getRepairType());
			entity.setIssuedMan(proEntity.getIssuedMan());
			entity.setIssuedTime(proEntity.getIssuedTime());
			entity.setLastUndownMan(proEntity.getLastUndownMan());
			entity.setLastUndownTime(proEntity.getLastUndownTime());
			// entity.setMemo(proEntity.getMemo());
			entity.setProMonth(proMonth);
			entity.setGroupBlNumS(String.valueOf(proEntity.getInNumS()));
			entity.setGroupBlWtS(String.valueOf(proEntity.getInWeightS()));
			entity.setGroupWtS(String.valueOf(proEntity.getWeigthS()));
			sql = EntityTool.fillSqlByEntity(sql, entity);
		}
		PreparedStatement ps = con.prepareStatement(sql);
		ps.executeUpdate();
		ps.close();
	}

	/**
	 * 删除排产
	 * 
	 * @param con
	 * @param entity
	 * @param processCode
	 * @throws SQLException
	 */
	public void deletePlanOrder(Connection con, ProducEntity entity,
			String processCode) throws SQLException {
		String sql = "";
		if (processCode.equals("B")) {
			sql = CoreXmlSqlParsersFactory
					.getSql("ProducHelperBean.deletePlanOrderB");
		} else if (processCode.equals("C")) {
			sql = CoreXmlSqlParsersFactory
					.getSql("ProducHelperBean.deletePlanOrderC");
		} else if (processCode.equals("D")) {
			sql = CoreXmlSqlParsersFactory
					.getSql("ProducHelperBean.deletePlanOrderD");
		} else if (processCode.equals("E")) {
			sql = CoreXmlSqlParsersFactory
					.getSql("ProducHelperBean.deletePlanOrderE");
		} else if (processCode.equals("F")) {
			sql = CoreXmlSqlParsersFactory
					.getSql("ProducHelperBean.deletePlanOrderF");
		} else if (processCode.equals("G")) {
			sql = CoreXmlSqlParsersFactory
					.getSql("ProducHelperBean.deletePlanOrderG");
		} else if (processCode.equals("H")) {
			sql = CoreXmlSqlParsersFactory
					.getSql("ProducHelperBean.deletePlanOrderH");
		}
		PreparedStatement ps = con.prepareStatement(sql);
		ps.setObject(1, entity.getProPlanId());
		ps.setObject(2, entity.getGxPlanNo());
		ps.executeUpdate();
		ps.close();
	}

	/**
	 * 新增排产
	 * 
	 * @param con
	 * @param proEntity
	 * @param processCode
	 * @throws SQLException
	 */
	public void addPlanOrder(Connection con, ProducEntity proEntity,
			String processCode, String proMonth) throws SQLException {
		String sql = "";
		if (processCode.equals("B")) {
			sql = CoreXmlSqlParsersFactory
					.getSql("ProducHelperBean.addPlanOrderB");
			PlnOrderCastSEntity entity = (PlnOrderCastSEntity) proEntity
					.getObjEntity();
			if (entity == null) {
				entity = new PlnOrderCastSEntity();
			}
			entity.setPlineCode(proEntity.getPlineCode());
			entity.setPlineName(proEntity.getPlineName());
			entity.setPlanNumS(String.valueOf(proEntity.getNumS()));
			entity.setPlanWtS(String.valueOf(proEntity.getWeigthS()));
			entity.setPlanUsetime(proEntity.getPlanUserTime());
			entity.setPlanTimeB(proEntity.getPlanTimeB());
			entity.setPlanTimeE(proEntity.getPlanTimeE());
			entity.setGxProSeq(String.valueOf(proEntity.getGxProSeq()));
			entity.setIsPlanOk(proEntity.getIsPlanOk());
			entity.setIsRepairPln(proEntity.getIsRepairPlan());
			entity.setRepairType(proEntity.getRepairType());
			entity.setIssuedMan(proEntity.getIssuedMan());
			entity.setIssuedTime(proEntity.getIssuedTime());
			entity.setLastUndownMan(proEntity.getLastUndownMan());
			entity.setLastUndownTime(proEntity.getLastUndownTime());
			entity.setGxPlanNo(proEntity.getGxPlanNo());
			entity.setMemo(proEntity.getMemo());
			entity.setProPlanId(proEntity.getProPlanId());
			entity.setGxProSeq(String.valueOf(proEntity.getGxProSeq()));
			entity.setExeStatus(proEntity.getExeStatus());
			entity.setProMonth(proMonth);
			entity.setPlanedNum("");
			entity.setPlanedWt("");
			entity.setIssuedMan("");
			entity.setIssuedTime("");
			entity.setLastUndownMan("");
			entity.setLastUndownTime("");
			entity.setPlanWtMin(String.valueOf(proEntity.getWeigthSMin()));
			entity.setIfAmount(proEntity.getIfAmount());
			entity.setCraftPath(proEntity.getCraftPath());
			entity.setIfConfirm(proEntity.getIfConfirm());
			entity.setSteelJudgement(proEntity.getSteelJudgement());
			entity.setProgyMemo(proEntity.getProgyMemo());
			sql = EntityTool.fillSqlByEntity(sql, entity);
		} else if (processCode.equals("C")) {
			sql = CoreXmlSqlParsersFactory
					.getSql("ProducHelperBean.addPlanOrderC");
			PlnOrderDzSEntity entity = (PlnOrderDzSEntity) proEntity
					.getObjEntity();
			if (entity == null) {
				entity = new PlnOrderDzSEntity();
			}
			entity.setPlineCode(proEntity.getPlineCode());
			entity.setPlineName(proEntity.getPlineName());
			entity.setNumS(String.valueOf(proEntity.getNumS()));
			entity.setWeigthS(String.valueOf(proEntity.getWeigthS()));
			entity.setPlanUsetime(proEntity.getPlanUserTime());
			entity.setPlanTimeB(proEntity.getPlanTimeB());
			entity.setPlanTimeE(proEntity.getPlanTimeE());
			entity.setGxProSeq(String.valueOf(proEntity.getGxProSeq()));
			entity.setIsPlanOk(proEntity.getIsPlanOk());
			entity.setIsRepairPln(proEntity.getIsRepairPlan());
			entity.setRepairType(proEntity.getRepairType());
			entity.setIssuedMan(proEntity.getIssuedMan());
			entity.setIssuedTime(proEntity.getIssuedTime());
			entity.setLastUndownMan(proEntity.getLastUndownMan());
			entity.setLastUndownTime(proEntity.getLastUndownTime());
			entity.setGxPlanNo(proEntity.getGxPlanNo());
			entity.setGxProSeq(String.valueOf(proEntity.getGxProSeq()));
			entity.setProPlanId(proEntity.getProPlanId());
			entity.setExeStatus(proEntity.getExeStatus());
			entity.setProMonth(proMonth);
			sql = EntityTool.fillSqlByEntity(sql, entity);
		} else if (processCode.equals("D")) {
			sql = CoreXmlSqlParsersFactory
					.getSql("ProducHelperBean.addPlanOrderD");
			PlnOrderZgSEntity entity = (PlnOrderZgSEntity) proEntity
					.getObjEntity();
			if (entity == null) {
				entity = new PlnOrderZgSEntity();
			}
			entity.setPlineCode(proEntity.getPlineCode());
			entity.setPlineName(proEntity.getPlineName());
			entity.setNumS(String.valueOf(proEntity.getNumS()));
			entity.setWeigthS(String.valueOf(proEntity.getWeigthS()));
			entity.setPlanUsetime(proEntity.getPlanUserTime());
			entity.setPlanTimeB(proEntity.getPlanTimeB());
			entity.setPlanTimeE(proEntity.getPlanTimeE());
			entity.setGxProSeq(String.valueOf(proEntity.getGxProSeq()));
			entity.setIsPlanOk(proEntity.getIsPlanOk());
			entity.setIsRepairPln(proEntity.getIsRepairPlan());
			entity.setRepairType(proEntity.getRepairType());
			entity.setIssuedMan(proEntity.getIssuedMan());
			entity.setIssuedTime(proEntity.getIssuedTime());
			entity.setLastUndownMan(proEntity.getLastUndownMan());
			entity.setLastUndownTime(proEntity.getLastUndownTime());
			entity.setGxPlanNo(proEntity.getGxPlanNo());
			entity.setProPlanId(proEntity.getProPlanId());
			entity.setMemo(proEntity.getMemo());
			entity.setAddNumIn(String.valueOf(proEntity.getAddNumIn()));
			entity.setAddWtIn(String.valueOf(proEntity.getAddWtIn()));
			entity.setInNumS(String.valueOf(proEntity.getInNumS()));
			entity.setInWeightS(String.valueOf(proEntity.getInWeightS()));
			entity.setBatchedNum(String.valueOf(proEntity.getBatchedNum()));
			entity.setBatchedWt(String.valueOf(proEntity.getBatchedWt()));
			entity.setMatchNumIn(String.valueOf(proEntity.getMatchNumIn()));
			entity.setMatchWtIn(String.valueOf(proEntity.getMatchWtIn()));
			entity.setExeStatus(proEntity.getExeStatus());
			entity.setProMonth(proMonth);
			entity.setGpreqNum(String.valueOf(proEntity.getGpreqNum()));
			entity.setGpreqWeight(String.valueOf(proEntity.getGpreqWeight()));
			entity.setPlansNum(String.valueOf(proEntity.getPlansNum()));
			entity.setWeigthSMin(String.valueOf(proEntity.getWeigthSMin()));
			entity.setVerify1(proEntity.getVerify1());
			entity.setVerify2(proEntity.getVerify2());
			entity.setVerify3(proEntity.getVerify3());
			entity.setProcessCodeC(proEntity.getProcessCodeC());
			entity.setProcessDescC(proEntity.getProcessDescC());
			entity.setDecision(proEntity.getDecision());
			entity.setThicknessWall(proEntity.getThicknessWall());
			entity.setProdStandard(proEntity.getProdStandard());
			entity.setOutputStandard(proEntity.getOutputStandard());
			entity.setZyBatchId("");
			entity.setOutsBilletFl(proEntity.getOutsBilletFl());
			entity.setApplyNo(proEntity.getApplyNo());
			entity.setApplyStatus(proEntity.getApplyStatus());
			entity.setIssuedMemo(proEntity.getIssuedMemo());
			entity.setGpreqId(proEntity.getGpreqId());
			entity.setGpreqIfOk(proEntity.getGpreqIfOk());
			entity.setGpreqIfDz(proEntity.getGpreqIfDz());
			entity.setActualWeight("");
			entity.setProgyMemo(proEntity.getProgyMemo());
			entity.setIfStoveIssued(proEntity.getIfStoveIssued());
			entity.setStoveIssuedMan(proEntity.getStoveIssuedMan());
			entity.setStoveIssuedTime(proEntity.getStoveIssuedTime());
			entity.setPlineCodeZz(proEntity.getPlineCodeZz());
			entity.setPlineNameZz(proEntity.getPlineNameZz());
			entity.setGradecodeLk(proEntity.getGradecodeLk());
			entity.setGradenameLk(proEntity.getGradenameLk());
			entity.setCicGroupLk(proEntity.getCicGroupLk());
			entity.setGpreqWeightMin(String.valueOf(proEntity
					.getGpreqWeightMin()));
			entity.setPassCode(proEntity.getPassCode());
			entity.setPassName(proEntity.getPassName());
			sql = EntityTool.fillSqlByEntity(sql, entity);
		} else if (processCode.equals("E")) {
			sql = CoreXmlSqlParsersFactory
					.getSql("ProducHelperBean.addPlanOrderE");
			PlnOrderDbkSEntity entity = (PlnOrderDbkSEntity) proEntity
					.getObjEntity();
			if (entity == null) {
				entity = new PlnOrderDbkSEntity();
			}
			entity.setDecision(proEntity.getDecision());
			entity.setPlineCode(proEntity.getPlineCode());
			entity.setPlineName(proEntity.getPlineName());
			entity.setNumS(String.valueOf(proEntity.getNumS()));
			entity.setWeigthS(String.valueOf(proEntity.getWeigthS()));
			entity.setPlanUsetime(proEntity.getPlanUserTime());
			entity.setPlanTimeB(proEntity.getPlanTimeB());
			entity.setPlanTimeE(proEntity.getPlanTimeE());
			entity.setGxProSeq(String.valueOf(proEntity.getGxProSeq()));
			entity.setIsPlanOk(proEntity.getIsPlanOk());
			entity.setIsRepairPln(proEntity.getIsRepairPlan());
			entity.setRepairType(proEntity.getRepairType());
			entity.setIssuedMan(proEntity.getIssuedMan());
			entity.setIssuedTime(proEntity.getIssuedTime());
			entity.setLastUndownMan(proEntity.getLastUndownMan());
			entity.setLastUndownTime(proEntity.getLastUndownTime());
			entity.setGxPlanNo(proEntity.getGxPlanNo());
			entity.setGxProSeq(String.valueOf(proEntity.getGxProSeq()));
			entity.setMemo(proEntity.getMemo());
			entity.setExeStatus(proEntity.getExeStatus());
			entity.setProPlanId(proEntity.getProPlanId());
			entity.setAddNumIn(String.valueOf(proEntity.getAddNumIn()));
			entity.setAddWtIn(String.valueOf(proEntity.getAddWtIn()));
			entity.setInNumS(String.valueOf(proEntity.getInNumS()));
			entity.setInWeightS(String.valueOf(proEntity.getInWeightS()));
			entity.setBatchedNum(String.valueOf(proEntity.getBatchedNum()));
			entity.setBatchedWt(String.valueOf(proEntity.getBatchedWt()));
			entity.setRealBatchNum(String.valueOf(proEntity.getRealBatchNum()));
			entity.setRealBatchWt(String.valueOf(proEntity.getRealBatchWt()));
			entity.setMatchNumIn(String.valueOf(proEntity.getMatchNumIn()));
			entity.setMatchWtIn(String.valueOf(proEntity.getMatchWtIn()));
			entity.setProMonth(proMonth);
			entity.setWeigthSMin(String.valueOf(proEntity.getWeigthSMin()));
			entity.setProcessCodeC(proEntity.getProcessCodeC());
			entity.setProcessDescC(proEntity.getProcessDescC());
			entity.setZyBatchId("");
			entity.setPassCode(proEntity.getPassCode());
			entity.setPassName(proEntity.getPassName());
			entity.setFinalUserDesc(proEntity.getFinalUserDesc());
			entity.setIfStoveIssued("0");
			entity.setStoveIssuedMan("");
			entity.setStoveIssuedTime("");
			sql = EntityTool.fillSqlByEntity(sql, entity);
		} else if (processCode.equals("F")) {
			sql = CoreXmlSqlParsersFactory
					.getSql("ProducHelperBean.addPlanOrderF");
			PlnOrderRclSEntity entity = (PlnOrderRclSEntity) proEntity
					.getObjEntity();
			if (entity == null) {
				entity = new PlnOrderRclSEntity();
			}
			entity.setDecision(proEntity.getDecision());
			entity.setPlineCode(proEntity.getPlineCode());
			entity.setPlineCode(proEntity.getPlineCode());
			entity.setPlineName(proEntity.getPlineName());
			entity.setNumS(String.valueOf(proEntity.getNumS()));
			entity.setWeigthS(String.valueOf(proEntity.getWeigthS()));
			entity.setPlanUsetime(proEntity.getPlanUserTime());
			entity.setPlanTimeB(proEntity.getPlanTimeB());
			entity.setPlanTimeE(proEntity.getPlanTimeE());
			entity.setGxProSeq(String.valueOf(proEntity.getGxProSeq()));
			entity.setIsPlanOk(proEntity.getIsPlanOk());
			entity.setIsRepairPln(proEntity.getIsRepairPlan());
			entity.setRepairType(proEntity.getRepairType());
			entity.setIssuedMan(proEntity.getIssuedMan());
			entity.setIssuedTime(proEntity.getIssuedTime());
			entity.setLastUndownMan(proEntity.getLastUndownMan());
			entity.setLastUndownTime(proEntity.getLastUndownTime());
			entity.setGxPlanNo(proEntity.getGxPlanNo());
			entity.setGxProSeq(String.valueOf(proEntity.getGxProSeq()));
			entity.setMemo(proEntity.getMemo());
			entity.setExeStatus(proEntity.getExeStatus());
			entity.setProPlanId(proEntity.getProPlanId());
			entity.setProMonth(proMonth);
			entity.setAddNumIn(String.valueOf(proEntity.getAddNumIn()));
			entity.setAddWtIn(String.valueOf(proEntity.getAddWtIn()));
			entity.setInNumS(String.valueOf(proEntity.getInNumS()));
			entity.setInWeightS(String.valueOf(proEntity.getInWeightS()));
			entity.setBatchedNum(String.valueOf(proEntity.getBatchedNum()));
			entity.setBatchedWt(String.valueOf(proEntity.getBatchedWt()));
			entity.setMatchNumIn(String.valueOf(proEntity.getMatchNumIn()));
			entity.setMatchWtIn(String.valueOf(proEntity.getMatchWtIn()));
			entity.setWeigthSMin(String.valueOf(proEntity.getWeigthSMin()));
			entity.setProcessCodeC(proEntity.getProcessCodeC());
			entity.setProcessDescC(proEntity.getProcessDescC());
			entity.setZyBatchId("");
			entity.setPrdcrAdvcDay(proEntity.getPrdcrAdvcDay());
			entity.setProgyMemo(proEntity.getProgyMemo());
			sql = EntityTool.fillSqlByEntity(sql, entity);
		} else if (processCode.equals("G")) {
			sql = CoreXmlSqlParsersFactory
					.getSql("ProducHelperBean.addPlanOrderG");
			PlnOrderJgxSEntity entity = (PlnOrderJgxSEntity) proEntity
					.getObjEntity();
			if (entity == null) {
				entity = new PlnOrderJgxSEntity();
			}
			entity.setDecision(proEntity.getDecision());
			entity.setPlineCode(proEntity.getPlineCode());
			entity.setPlineName(proEntity.getPlineName());
			entity.setNumS(String.valueOf(proEntity.getNumS()));
			entity.setWeigthS(String.valueOf(proEntity.getWeigthS()));
			entity.setPlanUsetime(proEntity.getPlanUserTime());
			entity.setPlanTimeB(proEntity.getPlanTimeB());
			entity.setPlanTimeE(proEntity.getPlanTimeE());
			entity.setGxProSeq(String.valueOf(proEntity.getGxProSeq()));
			entity.setIsPlanOk(proEntity.getIsPlanOk());
			entity.setIsRepairPln(proEntity.getIsRepairPlan());
			entity.setRepairType(proEntity.getRepairType());
			entity.setIssuedMan(proEntity.getIssuedMan());
			entity.setIssuedTime(proEntity.getIssuedTime());
			entity.setLastUndownMan(proEntity.getLastUndownMan());
			entity.setLastUndownTime(proEntity.getLastUndownTime());
			entity.setGxPlanNo(proEntity.getGxPlanNo());
			// entity.setGxProSeq(String.valueOf(proEntity.getGxProSeq()));
			entity.setMemo(proEntity.getMemo());
			entity.setExeStatus(proEntity.getExeStatus());
			entity.setProPlanId(proEntity.getProPlanId());
			entity.setAddNumIn(String.valueOf(proEntity.getAddNumIn()));
			entity.setAddWtIn(String.valueOf(proEntity.getAddWtIn()));
			entity.setInNumS(String.valueOf(proEntity.getInNumS()));
			entity.setInWeightS(String.valueOf(proEntity.getInWeightS()));
			entity.setBatchedNum(String.valueOf(proEntity.getBatchedNum()));
			entity.setBatchedWt(String.valueOf(proEntity.getBatchedWt()));
			entity.setMatchNumIn(String.valueOf(proEntity.getMatchNumIn()));
			entity.setMatchWtIn(String.valueOf(proEntity.getMatchWtIn()));
			entity.setProMonth(proMonth);
			entity.setProcessCodeC(proEntity.getProcessCodeC());
			entity.setProcessDescC(proEntity.getProcessDescC());
			entity.setZyBatchId("");
			entity.setProgyMemo(proEntity.getProgyMemo());
			sql = EntityTool.fillSqlByEntity(sql, entity);
		} else if (processCode.equals("H")) {
			sql = CoreXmlSqlParsersFactory
					.getSql("ProducHelperBean.addPlanOrderH");
			PlnGxJgPropSEntity entity = (PlnGxJgPropSEntity) proEntity
					.getObjEntity();
			if (entity == null) {
				entity = new PlnGxJgPropSEntity();
			}
			entity.setJgGroupId(proEntity.getJgGroupId());
			entity.setPlineCode(proEntity.getPlineCode());
			entity.setPlineName(proEntity.getPlineName());
			entity.setGroupNumS(String.valueOf(proEntity.getNumS()));
			entity.setGroupWtS(String.valueOf(proEntity.getWeigthS()));
			entity.setPlanUsetime(proEntity.getPlanUserTime());
			entity.setPlanTimeB(proEntity.getPlanTimeB());
			entity.setPlanTimeE(proEntity.getPlanTimeE());
			entity.setGxProSeq(String.valueOf(proEntity.getGxProSeq()));
			entity.setIsPlanOk(proEntity.getIsPlanOk());
			entity.setIsRepairPln(proEntity.getIsRepairPlan());
			entity.setRepairType(proEntity.getRepairType());
			entity.setIssuedMan(proEntity.getIssuedMan());
			entity.setIssuedTime(proEntity.getIssuedTime());
			entity.setLastUndownMan(proEntity.getLastUndownMan());
			entity.setLastUndownTime(proEntity.getLastUndownTime());
			entity.setGxPlanNo(proEntity.getGxPlanNo());
			// entity.setMemo(proEntity.getMemo());
			entity.setExeStatus(proEntity.getExeStatus());
			entity.setProPlanId(proEntity.getProPlanId());
			entity.setGroupBlNumS(String.valueOf(proEntity.getInNumS()));
			entity.setGroupBlWtS(String.valueOf(proEntity.getInWeightS()));
			entity.setBatchedNum(String.valueOf(proEntity.getBatchedNum()));
			entity.setBatchedWt(String.valueOf(proEntity.getBatchedWt()));
			entity.setRealBatchedNum(String.valueOf(proEntity.getRealBatchNum()));
			entity.setRealBatchedWt(String.valueOf(proEntity.getRealBatchWt()));
			entity.setMatchnumBl(String.valueOf(proEntity.getMatchNumIn()));
			entity.setMatchwtBl(String.valueOf(proEntity.getMatchWtIn()));
			entity.setProMonth(proMonth);
			entity.setOrdLnDlyPk(proEntity.getOrdLnDlyPk());
			entity.setPlnDivideId(proEntity.getPlnDivideId());
			entity.setReqBlId(proEntity.getOrdLnDlyPk());
			entity.setBlWlId(proEntity.getInwlId());
			// entity.setBlWlDesc(proEntity.GETIN);
			// entity.setIfMonitorBl(proEntity.getif)
			sql = EntityTool.fillSqlByEntity(sql, entity);
		}
		PreparedStatement ps = con.prepareStatement(sql);
		ps.executeUpdate();
		ps.close();
	}

	/**
	 * 修改生产顺序号
	 * 
	 * @param con
	 * @param proEntity
	 * @param processCode
	 * @throws SQLException
	 */
	public void updatePlanGxsqe(Connection con, ProducEntity proEntity,
			String processCode, String proMonth) throws SQLException {
		String sql = "";
		if (processCode.equals("B")) {
			sql = CoreXmlSqlParsersFactory
					.getSql("ProducHelperBean.addPlanOrderB");
			PlnOrderCastSEntity entity = (PlnOrderCastSEntity) proEntity
					.getObjEntity();
			if (entity == null) {
				entity = new PlnOrderCastSEntity();
			}
			entity.setPlineCode(proEntity.getPlineCode());
			entity.setPlineName(proEntity.getPlineName());
			entity.setPlanNumS(String.valueOf(proEntity.getNumS()));
			entity.setPlanWtS(String.valueOf(proEntity.getWeigthS()));
			entity.setPlanUsetime(proEntity.getPlanUserTime());
			entity.setPlanTimeB(proEntity.getPlanTimeB());
			entity.setPlanTimeE(proEntity.getPlanTimeE());
			entity.setGxProSeq(String.valueOf(proEntity.getGxProSeq()));
			entity.setIsPlanOk(proEntity.getIsPlanOk());
			entity.setIsRepairPln(proEntity.getIsRepairPlan());
			entity.setRepairType(proEntity.getRepairType());
			entity.setIssuedMan(proEntity.getIssuedMan());
			entity.setIssuedTime(proEntity.getIssuedTime());
			entity.setLastUndownMan(proEntity.getLastUndownMan());
			entity.setLastUndownTime(proEntity.getLastUndownTime());
			entity.setGxPlanNo(proEntity.getGxPlanNo());
			entity.setMemo(proEntity.getMemo());
			entity.setProPlanId(proEntity.getProPlanId());
			entity.setGxProSeq(String.valueOf(proEntity.getGxProSeq()));
			entity.setExeStatus(proEntity.getExeStatus());
			entity.setProMonth(proMonth);
			sql = EntityTool.fillSqlByEntity(sql, entity);
		} else if (processCode.equals("C")) {
			sql = CoreXmlSqlParsersFactory
					.getSql("ProducHelperBean.addPlanOrderC");
			PlnOrderDzSEntity entity = (PlnOrderDzSEntity) proEntity
					.getObjEntity();
			if (entity == null) {
				entity = new PlnOrderDzSEntity();
			}
			entity.setPlineCode(proEntity.getPlineCode());
			entity.setPlineName(proEntity.getPlineName());
			entity.setNumS(String.valueOf(proEntity.getNumS()));
			entity.setWeigthS(String.valueOf(proEntity.getWeigthS()));
			entity.setPlanUsetime(proEntity.getPlanUserTime());
			entity.setPlanTimeB(proEntity.getPlanTimeB());
			entity.setPlanTimeE(proEntity.getPlanTimeE());
			entity.setGxProSeq(String.valueOf(proEntity.getGxProSeq()));
			entity.setIsPlanOk(proEntity.getIsPlanOk());
			entity.setIsRepairPln(proEntity.getIsRepairPlan());
			entity.setRepairType(proEntity.getRepairType());
			entity.setIssuedMan(proEntity.getIssuedMan());
			entity.setIssuedTime(proEntity.getIssuedTime());
			entity.setLastUndownMan(proEntity.getLastUndownMan());
			entity.setLastUndownTime(proEntity.getLastUndownTime());
			entity.setGxPlanNo(proEntity.getGxPlanNo());
			entity.setGxProSeq(String.valueOf(proEntity.getGxProSeq()));
			entity.setProPlanId(proEntity.getProPlanId());
			entity.setExeStatus(proEntity.getExeStatus());
			entity.setProMonth(proMonth);
			sql = EntityTool.fillSqlByEntity(sql, entity);
		} else if (processCode.equals("D")) {
			sql = CoreXmlSqlParsersFactory
					.getSql("ProducHelperBean.updatePlanGxSeqD");
			PlnOrderZgSEntity entity = (PlnOrderZgSEntity) proEntity
					.getObjEntity();
			if (entity == null) {
				entity = new PlnOrderZgSEntity();
			}
			entity.setPlineCode(proEntity.getPlineCode());
			entity.setPlanUsetime(proEntity.getPlanUserTime());
			entity.setPlanTimeB(proEntity.getPlanTimeB());
			entity.setPlanTimeE(proEntity.getPlanTimeE());
			entity.setGxProSeq(String.valueOf(proEntity.getGxProSeq()));
			entity.setGxPlanNo(proEntity.getGxPlanNo());
			entity.setProPlanId(proEntity.getProPlanId());
			entity.setProMonth(proMonth);
			sql = EntityTool.fillSqlByEntity(sql, entity);
		} else if (processCode.equals("E")) {
			sql = CoreXmlSqlParsersFactory
					.getSql("ProducHelperBean.addPlanOrderE");
			PlnOrderDbkSEntity entity = (PlnOrderDbkSEntity) proEntity
					.getObjEntity();
			if (entity == null) {
				entity = new PlnOrderDbkSEntity();
			}
			entity.setPlineCode(proEntity.getPlineCode());
			entity.setPlineName(proEntity.getPlineName());
			entity.setNumS(String.valueOf(proEntity.getNumS()));
			entity.setWeigthS(String.valueOf(proEntity.getWeigthS()));
			entity.setPlanUsetime(proEntity.getPlanUserTime());
			entity.setPlanTimeB(proEntity.getPlanTimeB());
			entity.setPlanTimeE(proEntity.getPlanTimeE());
			entity.setGxProSeq(String.valueOf(proEntity.getGxProSeq()));
			entity.setIsPlanOk(proEntity.getIsPlanOk());
			entity.setIsRepairPln(proEntity.getIsRepairPlan());
			entity.setRepairType(proEntity.getRepairType());
			entity.setIssuedMan(proEntity.getIssuedMan());
			entity.setIssuedTime(proEntity.getIssuedTime());
			entity.setLastUndownMan(proEntity.getLastUndownMan());
			entity.setLastUndownTime(proEntity.getLastUndownTime());
			entity.setGxPlanNo(proEntity.getGxPlanNo());
			entity.setGxProSeq(String.valueOf(proEntity.getGxProSeq()));
			entity.setMemo(proEntity.getMemo());
			entity.setExeStatus(proEntity.getExeStatus());
			entity.setProPlanId(proEntity.getProPlanId());
			entity.setAddNumIn(String.valueOf(proEntity.getAddNumIn()));
			entity.setAddWtIn(String.valueOf(proEntity.getAddWtIn()));
			entity.setInNumS(String.valueOf(proEntity.getInNumS()));
			entity.setInWeightS(String.valueOf(proEntity.getInWeightS()));
			entity.setBatchedNum(String.valueOf(proEntity.getBatchedNum()));
			entity.setBatchedWt(String.valueOf(proEntity.getBatchedWt()));
			entity.setRealBatchNum(String.valueOf(proEntity.getRealBatchNum()));
			entity.setRealBatchWt(String.valueOf(proEntity.getRealBatchWt()));
			entity.setMatchNumIn(String.valueOf(proEntity.getMatchNumIn()));
			entity.setMatchWtIn(String.valueOf(proEntity.getMatchWtIn()));
			entity.setProMonth(proMonth);
			sql = EntityTool.fillSqlByEntity(sql, entity);
		} else if (processCode.equals("F")) {
			sql = CoreXmlSqlParsersFactory
					.getSql("ProducHelperBean.addPlanOrderF");
			PlnOrderRclSEntity entity = (PlnOrderRclSEntity) proEntity
					.getObjEntity();
			if (entity == null) {
				entity = new PlnOrderRclSEntity();
			}
			entity.setPlineCode(proEntity.getPlineCode());
			entity.setPlineCode(proEntity.getPlineCode());
			entity.setPlineName(proEntity.getPlineName());
			entity.setNumS(String.valueOf(proEntity.getNumS()));
			entity.setWeigthS(String.valueOf(proEntity.getWeigthS()));
			entity.setPlanUsetime(proEntity.getPlanUserTime());
			entity.setPlanTimeB(proEntity.getPlanTimeB());
			entity.setPlanTimeE(proEntity.getPlanTimeE());
			entity.setGxProSeq(String.valueOf(proEntity.getGxProSeq()));
			entity.setIsPlanOk(proEntity.getIsPlanOk());
			entity.setIsRepairPln(proEntity.getIsRepairPlan());
			entity.setRepairType(proEntity.getRepairType());
			entity.setIssuedMan(proEntity.getIssuedMan());
			entity.setIssuedTime(proEntity.getIssuedTime());
			entity.setLastUndownMan(proEntity.getLastUndownMan());
			entity.setLastUndownTime(proEntity.getLastUndownTime());
			entity.setGxPlanNo(proEntity.getGxPlanNo());
			entity.setGxProSeq(String.valueOf(proEntity.getGxProSeq()));
			entity.setMemo(proEntity.getMemo());
			entity.setExeStatus(proEntity.getExeStatus());
			entity.setProPlanId(proEntity.getProPlanId());
			entity.setProMonth(proMonth);
			entity.setAddNumIn(String.valueOf(proEntity.getAddNumIn()));
			entity.setAddWtIn(String.valueOf(proEntity.getAddWtIn()));
			entity.setInNumS(String.valueOf(proEntity.getInNumS()));
			entity.setInWeightS(String.valueOf(proEntity.getInWeightS()));
			entity.setBatchedNum(String.valueOf(proEntity.getBatchedNum()));
			entity.setBatchedWt(String.valueOf(proEntity.getBatchedWt()));
			entity.setMatchNumIn(String.valueOf(proEntity.getMatchNumIn()));
			entity.setMatchWtIn(String.valueOf(proEntity.getMatchWtIn()));
			sql = EntityTool.fillSqlByEntity(sql, entity);
		} else if (processCode.equals("G")) {
			sql = CoreXmlSqlParsersFactory
					.getSql("ProducHelperBean.addPlanOrderG");
			PlnOrderJgxSEntity entity = (PlnOrderJgxSEntity) proEntity
					.getObjEntity();
			if (entity == null) {
				entity = new PlnOrderJgxSEntity();
			}
			entity.setPlineCode(proEntity.getPlineCode());
			entity.setPlineName(proEntity.getPlineName());
			entity.setNumS(String.valueOf(proEntity.getNumS()));
			entity.setWeigthS(String.valueOf(proEntity.getWeigthS()));
			entity.setPlanUsetime(proEntity.getPlanUserTime());
			entity.setPlanTimeB(proEntity.getPlanTimeB());
			entity.setPlanTimeE(proEntity.getPlanTimeE());
			entity.setGxProSeq(String.valueOf(proEntity.getGxProSeq()));
			entity.setIsPlanOk(proEntity.getIsPlanOk());
			entity.setIsRepairPln(proEntity.getIsRepairPlan());
			entity.setRepairType(proEntity.getRepairType());
			entity.setIssuedMan(proEntity.getIssuedMan());
			entity.setIssuedTime(proEntity.getIssuedTime());
			entity.setLastUndownMan(proEntity.getLastUndownMan());
			entity.setLastUndownTime(proEntity.getLastUndownTime());
			entity.setGxPlanNo(proEntity.getGxPlanNo());
			entity.setGxProSeq(String.valueOf(proEntity.getGxProSeq()));
			entity.setMemo(proEntity.getMemo());
			entity.setExeStatus(proEntity.getExeStatus());
			entity.setProPlanId(proEntity.getProPlanId());
			entity.setAddNumIn(String.valueOf(proEntity.getAddNumIn()));
			entity.setAddWtIn(String.valueOf(proEntity.getAddWtIn()));
			entity.setInNumS(String.valueOf(proEntity.getInNumS()));
			entity.setInWeightS(String.valueOf(proEntity.getInWeightS()));
			entity.setBatchedNum(String.valueOf(proEntity.getBatchedNum()));
			entity.setBatchedWt(String.valueOf(proEntity.getBatchedWt()));
			entity.setMatchNumIn(String.valueOf(proEntity.getMatchNumIn()));
			entity.setMatchWtIn(String.valueOf(proEntity.getMatchWtIn()));
			entity.setProMonth(proMonth);
			sql = EntityTool.fillSqlByEntity(sql, entity);
		} else if (processCode.equals("H")) {
			sql = CoreXmlSqlParsersFactory
					.getSql("ProducHelperBean.addPlanOrderH");
			PlnGxJgPropSEntity entity = (PlnGxJgPropSEntity) proEntity
					.getObjEntity();
			if (entity == null) {
				entity = new PlnGxJgPropSEntity();
			}
			entity.setJgGroupId(proEntity.getJgGroupId());
			entity.setPlineCode(proEntity.getPlineCode());
			entity.setPlineName(proEntity.getPlineName());
			entity.setGroupNumS(String.valueOf(proEntity.getNumS()));
			// entity.setWeigthS(String.valueOf(proEntity.getPlanWgt()));
			entity.setPlanUsetime(proEntity.getPlanUserTime());
			entity.setPlanTimeB(proEntity.getPlanTimeB());
			entity.setPlanTimeE(proEntity.getPlanTimeE());
			entity.setGxProSeq(String.valueOf(proEntity.getGxProSeq()));
			entity.setIsPlanOk(proEntity.getIsPlanOk());
			entity.setIsRepairPln(proEntity.getIsRepairPlan());
			entity.setRepairType(proEntity.getRepairType());
			entity.setIssuedMan(proEntity.getIssuedMan());
			entity.setIssuedTime(proEntity.getIssuedTime());
			entity.setLastUndownMan(proEntity.getLastUndownMan());
			entity.setLastUndownTime(proEntity.getLastUndownTime());
			entity.setGxPlanNo(proEntity.getGxPlanNo());
			// entity.setMemo(proEntity.getMemo());
			entity.setExeStatus(proEntity.getExeStatus());
			entity.setProPlanId(proEntity.getProPlanId());
			entity.setGroupBlNumS(String.valueOf(proEntity.getInNumS()));
			entity.setGroupBlWtS(String.valueOf(proEntity.getInWeightS()));
			entity.setBatchedNum(String.valueOf(proEntity.getBatchedNum()));
			entity.setBatchedWt(String.valueOf(proEntity.getBatchedWt()));
			entity.setRealBatchedNum(String.valueOf(proEntity.getRealBatchNum()));
			entity.setRealBatchedWt(String.valueOf(proEntity.getRealBatchWt()));
			entity.setMatchnumBl(String.valueOf(proEntity.getMatchNumIn()));
			entity.setMatchwtBl(String.valueOf(proEntity.getMatchWtIn()));
			entity.setProMonth(proMonth);
			sql = EntityTool.fillSqlByEntity(sql, entity);
		}
		PreparedStatement ps = con.prepareStatement(sql);
		ps.executeUpdate();
		ps.close();
	}

	/**
	 * 查询产线能力
	 * 
	 * @param con
	 * @param inMaterialNo
	 *            投入物料
	 * @param outMaterialNo
	 *            产出物料
	 * @param plineCode
	 *            产线
	 * @param processCode
	 *            工序
	 * @return double
	 * @throws SQLException
	 */
	public double[] getPlineCapacity(Connection con, String inMaterialNo,
			String outMaterialNo, String plineCode, String processCode)
			throws SQLException {
		double[] param = new double[2];
		double capacity = 0;
		double count = 0;
		String sql = "";
		if (processCode.equals("B")) {
			sql = CoreXmlSqlParsersFactory
					.getSql("ProducHelperBean.getPlineCapacityB");
		} else if (processCode.equals("C")) {
			sql = CoreXmlSqlParsersFactory
					.getSql("ProducHelperBean.getPlineCapacityC");
		} else if (processCode.equals("D")) {
			sql = CoreXmlSqlParsersFactory
					.getSql("ProducHelperBean.getPlineCapacityD");
		} else if (processCode.equals("E")) {
			sql = CoreXmlSqlParsersFactory
					.getSql("ProducHelperBean.getPlineCapacityE");
		} else if (processCode.equals("F")) {
			sql = CoreXmlSqlParsersFactory
					.getSql("ProducHelperBean.getPlineCapacityF");
		} else if (processCode.equals("G")) {
			sql = CoreXmlSqlParsersFactory
					.getSql("ProducHelperBean.getPlineCapacityG");
		} else if (processCode.equals("H")) {
			sql = CoreXmlSqlParsersFactory
					.getSql("ProducHelperBean.getPlineCapacityH");
		}
		PreparedStatement ps = con.prepareStatement(sql);
		ps.setObject(1, inMaterialNo);
		ps.setObject(2, outMaterialNo);
		ps.setObject(3, plineCode);
		ResultSet rs = ps.executeQuery();
		if (rs.next()) {
			if (rs.getString("HR_CAPCTY") != null
					&& !rs.getString("HR_CAPCTY").equals("")) {
				capacity = Double.parseDouble(rs.getString("HR_CAPCTY"));
			}
			count = 1;
		}
		rs.close();
		ps.close();
		param[0] = capacity;
		param[1] = count;
		return param;
	}

	/**
	 * 根据产线能力与重量计算时长
	 * 
	 * @param
	 * @param capacity
	 * @param beginTime
	 * @return TimeEntity
	 * @throws ParseException
	 */
	public TimeEntity calculateTime(int num, double capacity, String beginTime)
			throws ParseException {
		TimeEntity time = new TimeEntity();
		SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		int userMinute = 0;
		if (capacity <= 0) {
			userMinute = 0;
		} else {
			userMinute = (int) Math.ceil((num / capacity * 60));
		}
		int userSecond = (int) userMinute * 60;
		String endTime = df.format(BaseHelper.dateAddSecond(
				df.parse(beginTime), userSecond));
		time.setBeginTime(beginTime);
		time.setEndTime(endTime);
		time.setUserTime(String.valueOf(userMinute));
		return time;
	}

	/**
	 * 根据产线能力与重量计算时长(铸造)
	 * 
	 * @param
	 * @param capacity
	 * @param beginTime
	 * @return TimeEntity
	 * @throws ParseException
	 */
	public TimeEntity calculateTimeZz(double wt, double capacity,
			String beginTime, double standSteel) throws ParseException {
		TimeEntity time = new TimeEntity();
		SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		int userMinute = 0;
		if (capacity <= 0) {
			userMinute = 0;
		} else {
			userMinute = (int) Math.ceil((capacity) * (wt / standSteel));
		}
		int userSecond = (int) userMinute * 60;
		String endTime = df.format(BaseHelper.dateAddSecond(
				df.parse(beginTime), userSecond));
		time.setBeginTime(beginTime);
		time.setEndTime(endTime);
		time.setUserTime(String.valueOf(userMinute));
		return time;
	}

	/**
	 * 时间自动调整
	 * 
	 * @param con
	 * @param gxProSeq
	 * @param plineCode
	 * @param planTimeE
	 * @param processCode
	 * @throws SQLException
	 * @throws ParseException
	 */
	public void timeIncrease(Connection con, int gxProSeq, String plineCode,
			String planTimeE, String processCode) throws SQLException,
			ParseException {
		String sql = "";
		String updateSql = "";
		if (processCode.equals("B")) {
			sql = "select t.pro_plan_id,t.gx_plan_no,t.plan_usetime,t.pro_month from PLN_ORDER_CAST_S t ";
			updateSql = "UPDATE PLN_ORDER_CAST_S T SET T.PLAN_TIME_B = TO_DATE(?, 'YYYY-MM-DD HH24:MI:SS'), T.PLAN_TIME_E = TO_DATE(?, 'YYYY-MM-DD HH24:MI:SS') WHERE T.PRO_PLAN_ID = ? AND T.GX_PLAN_NO = ?";
		} else if (processCode.equals("C")) {
			sql = "select t.pro_plan_id,t.gx_plan_no,t.plan_usetime,t.pro_month from PLN_ORDER_DZ_S t";
			updateSql = "UPDATE PLN_ORDER_DZ_S T SET T.PLAN_TIME_B = TO_DATE(?, 'YYYY-MM-DD HH24:MI:SS'), T.PLAN_TIME_E = TO_DATE(?, 'YYYY-MM-DD HH24:MI:SS') WHERE T.PRO_PLAN_ID = ? AND T.GX_PLAN_NO = ?";
		} else if (processCode.equals("D")) {
			sql = "select t.pro_plan_id,t.gx_plan_no,t.plan_usetime,t.pro_month from PLN_ORDER_ZG_S t";
			updateSql = "UPDATE PLN_ORDER_ZG_S T SET T.PLAN_TIME_B = TO_DATE(?, 'YYYY-MM-DD HH24:MI:SS'), T.PLAN_TIME_E = TO_DATE(?, 'YYYY-MM-DD HH24:MI:SS') WHERE T.PRO_PLAN_ID = ? AND T.GX_PLAN_NO = ?";
		} else if (processCode.equals("E")) {
			sql = "select t.pro_plan_id,t.gx_plan_no,t.plan_usetime,t.pro_month from PLN_ORDER_DBK_S t";
			updateSql = "UPDATE PLN_ORDER_DBK_S T SET T.PLAN_TIME_B = TO_DATE(?, 'YYYY-MM-DD HH24:MI:SS'), T.PLAN_TIME_E = TO_DATE(?, 'YYYY-MM-DD HH24:MI:SS') WHERE T.PRO_PLAN_ID = ? AND T.GX_PLAN_NO = ?";
		} else if (processCode.equals("F")) {
			sql = "select t.pro_plan_id,t.gx_plan_no,t.plan_usetime,t.pro_month from PLN_ORDER_RCL_S t";
			updateSql = "UPDATE PLN_ORDER_RCL_S T SET T.PLAN_TIME_B = TO_DATE(?, 'YYYY-MM-DD HH24:MI:SS'), T.PLAN_TIME_E = TO_DATE(?, 'YYYY-MM-DD HH24:MI:SS') WHERE T.PRO_PLAN_ID = ? AND T.GX_PLAN_NO = ?";
		} else if (processCode.equals("G")) {
			sql = "select t.pro_plan_id,t.gx_plan_no,t.plan_usetime,t.pro_month from pln_order_jgx_s t";
			updateSql = "UPDATE PLN_ORDER_JGX_S T SET T.PLAN_TIME_B = TO_DATE(?, 'YYYY-MM-DD HH24:MI:SS'), T.PLAN_TIME_E = TO_DATE(?, 'YYYY-MM-DD HH24:MI:SS') WHERE T.PRO_PLAN_ID = ? AND T.GX_PLAN_NO = ?";
		} else if (processCode.equals("H")) {
			sql = "select t.pro_plan_id,t.gx_plan_no,t.plan_usetime,t.pro_month from PLN_GX_JG_PROP_S t ";
			updateSql = "UPDATE PLN_GX_JG_PROP_S T SET T.PLAN_TIME_B = TO_DATE(?, 'YYYY-MM-DD HH24:MI:SS'), T.PLAN_TIME_E = TO_DATE(?, 'YYYY-MM-DD HH24:MI:SS') WHERE T.PRO_PLAN_ID = ? AND T.GX_PLAN_NO = ?";
		}
		sql += " where t.pline_code=? and to_number(t.gx_pro_seq)>to_number(?) and t.exe_status in('0','1')order by to_number(t.gx_pro_seq)";
		List<String[]> strArrList = new ArrayList<String[]>();
		PreparedStatement ps = con.prepareStatement(sql);
		ps.setObject(1, plineCode);
		ps.setObject(2, gxProSeq);
		ResultSet rs = ps.executeQuery();
		while (rs.next()) {
			String[] strArr = new String[4];
			strArr[0] = rs.getString("plan_usetime");
			strArr[1] = rs.getString("pro_plan_id");
			strArr[2] = rs.getString("gx_plan_no");
			strArr[3] = rs.getString("pro_month");
			strArrList.add(strArr);
		}
		rs.close();
		ps.close();
		if (strArrList == null || strArrList.size() == 0) {
			return;
		}
		// 修改时间
		ps = con.prepareStatement(updateSql);
		final int batchSize = 1000;
		int count = 0;
		int m = 0;
		DateFormat df = new SimpleDateFormat("yyyy-MM");
		DateFormat df1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		String planTimeB = planTimeE;
		for (int i = 0; i < strArrList.size(); i++) {
			String[] strArr = strArrList.get(i);
			if (processCode.equals("D")) {
//				int moth = (df.parse(strArr[3]).getYear()-df.parse(planTimeB).getYear())*12 + df.parse(strArr[3]).getMonth() - df.parse(planTimeB).getMonth();
//				if(moth > 0 && (df1.parse(planTimeB).before(df1.parse(df.format(df.parse(planTimeB)) + "-25 21:00:00"))))
//				{
//					m = 0;
//				}
//				if(m ==0)
//				{
					if (df.parse(strArr[3]).getTime() > df.parse(planTimeB)
							.getTime() && (df1.parse(planTimeB).before(df1.parse(getForMoth(df.parse(strArr[3])) + "-25 12:00:00")))) {
						planTimeB = getForMoth(df.parse(strArr[3])) + "-25 12:00:00";
						//planTimeB = strArr[3] + "-01 00:00:00";
						m = m+1;
					}
				//}

			}
			String planTimeE1 = BaseHelper.addTime(planTimeB, strArr[0]);
			ps.setObject(1, planTimeB);
			ps.setObject(2, planTimeE1);
			ps.setObject(3, strArr[1]);
			ps.setObject(4, strArr[2]);
			ps.addBatch();
			if (++count % batchSize == 0) {
				ps.executeBatch();
			}
			planTimeB = planTimeE1;
		}
		ps.executeBatch();
		ps.close();
	}


	public static String  getForMoth(Date time)
	{
		SimpleDateFormat dateFormat = new SimpleDateFormat(
				"yyyy-MM");
		Calendar cal = Calendar.getInstance();
		cal.setTime(time);
		cal.add(Calendar.MONTH , -1);
		return dateFormat.format(cal.getTime());
	}
	/**
	 * 序号自增减
	 * 
	 * @param con
	 * @param plineCode
	 * @param gxProSeqB
	 * @param gxProSeqE
	 *            (如果没有上限，请设为负数)
	 * @param num
	 * @param processCode
	 * @throws SQLException
	 */
	public void seqIncrease(Connection con, String plineCode, int gxProSeqB,
			int gxProSeqE, int num, String processCode) throws SQLException {
		String sql = "";
		if (processCode.equals("B")) {
			sql = "update  PLN_ORDER_CAST_S T ";
		} else if (processCode.equals("C")) {
			sql = "update PLN_ORDER_DZ_S T ";
		} else if (processCode.equals("D")) {
			sql = "update  PLN_ORDER_ZG_S T ";
		} else if (processCode.equals("E")) {
			sql = "update  PLN_ORDER_DBK_S T ";
		} else if (processCode.equals("F")) {
			sql = "update  PLN_ORDER_RCL_S T ";
		} else if (processCode.equals("G")) {
			sql = "update PLN_ORDER_JGX_S T";
		} else if (processCode.equals("H")) {
			sql = "update PLN_GX_JG_PROP_S T";
		}
		sql += " SET T.GX_PRO_SEQ = TO_NUMBER(T.GX_PRO_SEQ) + TO_NUMBER(?) WHERE T.PLINE_CODE = ? AND TO_NUMBER(T.GX_PRO_SEQ) >= TO_NUMBER(?)";
		if (gxProSeqE > 0) {
			sql += "  AND TO_NUMBER(T.GX_PRO_SEQ) < TO_NUMBER(?) ";
		}
		PreparedStatement ps = con.prepareStatement(sql);
		ps.setObject(1, num);
		ps.setObject(2, plineCode);
		ps.setObject(3, gxProSeqB);
		if (gxProSeqE > 0) {
			ps.setObject(4, gxProSeqE);
		}
		ps.executeUpdate();
		ps.close();
	}

	/**
	 * 查询最大结束时间
	 * 
	 * @param con
	 * @param plineCode
	 * @param processCode
	 * @param proMonth
	 *            排产月
	 * @param gxProSeq
	 *            生产顺序号
	 * @param
	 *
	 * @return
	 * @throws SQLException
	 */
	public String getMaxPlanTimeE(Connection con, String plineCode,
			String processCode, String proMonth, int gxProSeq)
			throws SQLException {
		String sql = "";
		if (processCode.equals("B")) {
			sql = "SELECT TO_CHAR(NVL(MAX(T.PLAN_TIME_E), SYSDATE), 'YYYY-MM-DD HH24:MI:SS') PLAN_TIME_E FROM PLN_ORDER_CAST_S T WHERE T.PLINE_CODE = ? ";
		} else if (processCode.equals("C")) {
			sql = "SELECT TO_CHAR(NVL(MAX(T.PLAN_TIME_E), SYSDATE), 'YYYY-MM-DD HH24:MI:SS') PLAN_TIME_E FROM PLN_ORDER_DZ_S T WHERE T.PLINE_CODE = ? ";
		} else if (processCode.equals("D")) {
			sql = "SELECT TO_CHAR(MAX(T.PLAN_TIME_E), 'YYYY-MM-DD HH24:MI:SS') PLAN_TIME_E FROM PLN_ORDER_ZG_S T WHERE T.PLINE_CODE = ? AND T.PRO_MONTH=?  AND T.EXE_STATUS IN ('0','1')";
		} else if (processCode.equals("E")) {
			sql = "SELECT TO_CHAR(NVL(MAX(T.PLAN_TIME_E), SYSDATE), 'YYYY-MM-DD HH24:MI:SS') PLAN_TIME_E FROM PLN_ORDER_DBK_S T WHERE T.PLINE_CODE = ? ";
		} else if (processCode.equals("F")) {
			sql = "SELECT TO_CHAR(NVL(MAX(T.PLAN_TIME_E), SYSDATE), 'YYYY-MM-DD HH24:MI:SS') PLAN_TIME_E FROM PLN_ORDER_RCL_S T WHERE T.PLINE_CODE = ? ";
		} else if (processCode.equals("G")) {
			sql = "SELECT TO_CHAR(NVL(MAX(T.PLAN_TIME_E), SYSDATE), 'YYYY-MM-DD HH24:MI:SS') PLAN_TIME_E FROM PLN_ORDER_JGX_S T WHERE T.PLINE_CODE = ? ";
		} else if (processCode.equals("H")) {
			sql = "SELECT TO_CHAR(NVL(MAX(T.PLAN_TIME_E), SYSDATE), 'YYYY-MM-DD HH24:MI:SS') PLAN_TIME_E FROM PLN_GX_JG_PROP_S T WHERE T.PLINE_CODE = ? ";
		}
		PreparedStatement ps = con.prepareStatement(sql);
		ps.setObject(1, plineCode);
		if (processCode.equals("D")) {
			ps.setObject(2, proMonth);
			// ps.setObject(2, String.valueOf(gxProSeq));
		}
		ResultSet rs = ps.executeQuery();
		String maxPlanTimeE = "";
		if (rs.next()) {
			maxPlanTimeE = rs.getString("PLAN_TIME_E");
			if (maxPlanTimeE == null || maxPlanTimeE.equals("")) {
				maxPlanTimeE = proMonth + "-01 00:00:00";
			}
		}
		rs.close();
		ps.close();
		DateFormat df = new SimpleDateFormat("yyyy-MM");
		try {
			if (processCode.equals("D")) {
				sql = "SELECT T.PRO_MONTH FROM PLN_ORDER_ZG_S T WHERE T.PLINE_CODE = ? AND T.PRO_MONTH=?";
				ps = con.prepareStatement(sql);
				ps.setObject(1, plineCode);
				ps.setObject(2, proMonth);
				rs = ps.executeQuery();
				String downMonth = "";
				if (rs.next()) {
					downMonth = rs.getString("PRO_MONTH");
				}
				rs.close();
				ps.close();
				if (df.parse(proMonth).getTime() > df.parse(maxPlanTimeE)
						.getTime() && !proMonth.equals(downMonth)) {
					maxPlanTimeE = proMonth + "-01 00:00:00";
				}
			}
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return maxPlanTimeE;
	}

	/**
	 * 查询当前生产序号上条记录结束时间
	 * 
	 * @param con
	 * @param plineCode
	 * @param processCode
	 * @param proMonth
	 *            排产月
	 * @param gxProSeq
	 *            生产顺序号
	 * @param
	 *
	 * @return
	 * @throws SQLException
	 */
	public String getMaxPlanTimeEX(Connection con, String plineCode,
			String processCode, String proMonth, int gxProSeq)
			throws SQLException {
		String sql = "";
		if (processCode.equals("B")) {
			sql = "SELECT TO_CHAR(NVL(MAX(T.PLAN_TIME_E), SYSDATE), 'YYYY-MM-DD HH24:MI:SS') PLAN_TIME_E FROM PLN_ORDER_CAST_S T WHERE T.PLINE_CODE = ? ";
		} else if (processCode.equals("C")) {
			sql = "SELECT TO_CHAR(NVL(MAX(T.PLAN_TIME_E), SYSDATE), 'YYYY-MM-DD HH24:MI:SS') PLAN_TIME_E FROM PLN_ORDER_DZ_S T WHERE T.PLINE_CODE = ? ";
		} else if (processCode.equals("D")) {
			sql = "SELECT TO_CHAR(NVL(MAX(T.PLAN_TIME_E), SYSDATE), 'YYYY-MM-DD HH24:MI:SS') PLAN_TIME_E FROM PLN_ORDER_ZG_S T WHERE T.PLINE_CODE = ? AND TO_NUMBER(T.GX_PRO_SEQ)<TO_NUMBER(?)";
		} else if (processCode.equals("E")) {
			sql = "SELECT TO_CHAR(NVL(MAX(T.PLAN_TIME_E), SYSDATE), 'YYYY-MM-DD HH24:MI:SS') PLAN_TIME_E FROM PLN_ORDER_DBK_S T WHERE T.PLINE_CODE = ? ";
		} else if (processCode.equals("F")) {
			sql = "SELECT TO_CHAR(NVL(MAX(T.PLAN_TIME_E), SYSDATE), 'YYYY-MM-DD HH24:MI:SS') PLAN_TIME_E FROM PLN_ORDER_RCL_S T WHERE T.PLINE_CODE = ? ";
		} else if (processCode.equals("G")) {
			sql = "SELECT TO_CHAR(NVL(MAX(T.PLAN_TIME_E), SYSDATE), 'YYYY-MM-DD HH24:MI:SS') PLAN_TIME_E FROM PLN_ORDER_JGX_S T WHERE T.PLINE_CODE = ? ";
		} else if (processCode.equals("H")) {
			sql = "SELECT TO_CHAR(NVL(MAX(T.PLAN_TIME_E), SYSDATE), 'YYYY-MM-DD HH24:MI:SS') PLAN_TIME_E FROM PLN_GX_JG_PROP_S T WHERE T.PLINE_CODE = ? ";
		}
		PreparedStatement ps = con.prepareStatement(sql);
		ps.setObject(1, plineCode);
		if (processCode.equals("D")) {
			ps.setObject(2, String.valueOf(gxProSeq));
		}
		ResultSet rs = ps.executeQuery();
		String maxPlanTimeE = "";
		if (rs.next()) {
			maxPlanTimeE = rs.getString("PLAN_TIME_E");
			if (maxPlanTimeE == null || maxPlanTimeE.equals("")) {
				maxPlanTimeE = proMonth + "-01 00:00:00";
			}
		}
		rs.close();
		ps.close();
		return maxPlanTimeE;
	}

	/**
	 * 查询最大排产序号
	 * 
	 * @param con
	 * @param proPlanId
	 * @param processCode
	 * @return
	 * @throws SQLException
	 */
	public String getMaxGxPlanNo(Connection con, String proPlanId,
			String processCode) throws SQLException {
		String sql = "";
		if (processCode.equals("B")) {
			sql = "SELECT NVL(MAX(TO_NUMBER(T.GX_PLAN_NO)), 0) + 1 GX_PLAN_NO FROM PLN_ORDER_CAST_S T WHERE T.PRO_PLAN_ID =?";
		} else if (processCode.equals("C")) {
			sql = "SELECT NVL(MAX(TO_NUMBER(T.GX_PLAN_NO)), 0) + 1 GX_PLAN_NO FROM PLN_ORDER_DZ_S T WHERE T.PRO_PLAN_ID =?";
		} else if (processCode.equals("D")) {
			sql = "SELECT NVL(MAX(TO_NUMBER(T.GX_PLAN_NO)), 0) + 1 GX_PLAN_NO FROM PLN_ORDER_ZG_S T WHERE T.PRO_PLAN_ID =?";
		} else if (processCode.equals("E")) {
			sql = "SELECT NVL(MAX(TO_NUMBER(T.GX_PLAN_NO)), 0) + 1 GX_PLAN_NO FROM PLN_ORDER_DBK_S T WHERE T.PRO_PLAN_ID =?";
		} else if (processCode.equals("F")) {
			sql = "SELECT NVL(MAX(TO_NUMBER(T.GX_PLAN_NO)), 0) + 1 GX_PLAN_NO FROM PLN_ORDER_RCL_S T WHERE T.PRO_PLAN_ID =?";
		} else if (processCode.equals("G")) {
			sql = "SELECT NVL(MAX(TO_NUMBER(T.GX_PLAN_NO)), 0) + 1 GX_PLAN_NO FROM PLN_ORDER_JGX_S T WHERE T.PRO_PLAN_ID =?";
		} else if (processCode.equals("H")) {
			sql = "SELECT NVL(MAX(TO_NUMBER(T.GX_PLAN_NO)), 0) + 1 GX_PLAN_NO FROM PLN_GX_JG_PROP_S T WHERE T.PRO_PLAN_ID =?";
		}
		PreparedStatement ps = con.prepareStatement(sql);
		ps.setObject(1, proPlanId);
		ResultSet rs = ps.executeQuery();
		String gxPlanNo = "";
		if (rs.next()) {
			gxPlanNo = rs.getString("GX_PLAN_NO");
		}
		rs.close();
		ps.close();
		return gxPlanNo;
	}

	/**
	 * 查询最大生产顺序
	 * 
	 * @param con
	 * @param plineCode
	 * @param processCode
	 * @return
	 * @throws SQLException
	 */
	public int getMaxGxProSeq(Connection con, String plineCode,
			String processCode, String proMonth) throws SQLException {
		String sql = "";
		if (processCode.equals("B")) {
			sql = "SELECT NVL(MAX(TO_NUMBER(T.GX_PRO_SEQ)), 0) + 1 GX_PRO_SEQ FROM PLN_ORDER_CAST_S T WHERE T.PLINE_CODE =?";
		} else if (processCode.equals("C")) {
			sql = "SELECT NVL(MAX(TO_NUMBER(T.GX_PRO_SEQ)), 0) + 1 GX_PRO_SEQ FROM PLN_ORDER_DZ_S T WHERE T.PLINE_CODE =? ";
		} else if (processCode.equals("D")) {
			sql = "SELECT NVL(MAX(TO_NUMBER(T.GX_PRO_SEQ)), 0) + 1 GX_PRO_SEQ FROM PLN_ORDER_ZG_S T WHERE T.PLINE_CODE =? AND T.PRO_MONTH = ?  AND T.EXE_STATUS IN ('0','1')";
		} else if (processCode.equals("E")) {
			sql = "SELECT NVL(MAX(TO_NUMBER(T.GX_PRO_SEQ)), 0) + 1 GX_PRO_SEQ FROM PLN_ORDER_DBK_S T WHERE T.PLINE_CODE =? ";
		} else if (processCode.equals("F")) {
			sql = "SELECT NVL(MAX(TO_NUMBER(T.GX_PRO_SEQ)), 0) + 1 GX_PRO_SEQ FROM PLN_ORDER_RCL_S T WHERE T.PLINE_CODE =? ";
		} else if (processCode.equals("G")) {
			sql = "SELECT NVL(MAX(TO_NUMBER(T.GX_PRO_SEQ)), 0) + 1 GX_PRO_SEQ FROM PLN_ORDER_JGX_S T WHERE T.PLINE_CODE =?";
		} else if (processCode.equals("H")) {
			sql = "SELECT NVL(MAX(TO_NUMBER(T.GX_PRO_SEQ)), 0) + 1 GX_PRO_SEQ FROM PLN_GX_JG_PROP_S T WHERE T.PLINE_CODE =?";
		}
		PreparedStatement ps = con.prepareStatement(sql);
		ps.setObject(1, plineCode);
		if (processCode.equals("D")) {
			ps.setObject(2, proMonth);
		}
		ResultSet rs = ps.executeQuery();
		int gxProSeq = 1;
		if (rs.next()) {
			gxProSeq = rs.getInt("GX_PRO_SEQ");
		}
		rs.close();
		ps.close();
		if (gxProSeq == 1) {
			if (processCode.equals("D")) {
				SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM");
				try {
					Date date = sdf.parse(proMonth);
					Calendar calendar = Calendar.getInstance();
					calendar.setTime(date);
					calendar.add(Calendar.MONTH, -1);// 当前时间前去一个月
					String monthtime = String.valueOf(sdf.format(calendar
							.getTime()));// 最佳年月
					sql = "SELECT NVL(MAX(TO_NUMBER(T.GX_PRO_SEQ)), 0) + 1 GX_PRO_SEQ FROM PLN_ORDER_ZG_S T WHERE T.PLINE_CODE =?";
					ps = con.prepareStatement(sql);
					ps.setObject(1, plineCode);
					rs = ps.executeQuery();
					if (rs.next()) {
						gxProSeq = rs.getInt("GX_PRO_SEQ");
					}
					rs.close();
					ps.close();
//					if (gxProSeq != 1) {
//						gxProSeq = getMaxGxProSeq(con, plineCode, "D",
//								monthtime);
//					}
				} catch (ParseException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
		}
		return gxProSeq;
	}

	/**
	 * 状态调整
	 * 
	 * @param con
	 * @param plineCode
	 * @param gxProSeq
	 * @param processCode
	 * @throws Exception
	 */
	public void statusChange(Connection con, String plineCode, int gxProSeq,
			String processCode) throws Exception {
		String message = "";
		PreparedStatement ps = null;
		ResultSet rs = null;
		PreparedStatement ps1 = null;
		ResultSet rs1 = null;
		String sql = "";
		ArrayList<ArrayList<String>> list = new ArrayList<ArrayList<String>>();
		if (processCode.equals("B")) {
			// 查询当前产线顺序号小于当前选择顺序号
			String sqlxh = "SELECT T.PRO_PLAN_ID FROM PLN_ORDER_CAST_S T WHERE T.PLINE_CODE=? "
					+ " AND To_NUMBER(T.GX_PRO_SEQ)<? AND T.EXE_STATUS IN ('0','1')";
			ps = con.prepareStatement(sqlxh);
			ps.setObject(1, plineCode);
			ps.setObject(2, gxProSeq);
			rs = ps.executeQuery();
			while (rs.next()) {
				// 修改管坯需求状态
				String sqlupdate = CoreXmlSqlParsersFactory
						.getSql("FrmSteelMakingPlanChange.updateReqinfGp");
				ps1 = con.prepareStatement(sqlupdate);
				ps1.setObject(1, "2");
				ps1.setObject(2, rs.getString("PRO_PLAN_ID"));
				ps1.executeUpdate();
				ps1.close();
			}
			rs.close();
			ps.close();

			// 查询当前产线顺序号小于当前选择顺序号
			sqlxh = "SELECT T.PRO_PLAN_ID FROM PLN_ORDER_CAST_S T WHERE T.PLINE_CODE=? "
					+ " AND To_NUMBER(T.GX_PRO_SEQ)>=? AND T.EXE_STATUS IN ('2')";
			ps = con.prepareStatement(sqlxh);
			ps.setObject(1, plineCode);
			ps.setObject(2, gxProSeq);
			rs = ps.executeQuery();
			while (rs.next()) {
				// 修改管坯需求状态
				String sqlupdate = CoreXmlSqlParsersFactory
						.getSql("FrmSteelMakingPlanChange.updateReqinfGp");
				ps1 = con.prepareStatement(sqlupdate);
				ps1.setObject(1, "1");
				ps1.setObject(2, rs.getString("PRO_PLAN_ID"));
				ps1.executeUpdate();
				ps1.close();
			}
			rs.close();
			ps.close();

			sql = "update  PLN_ORDER_CAST_S T ";
		} else if (processCode.equals("C")) {
			sql = "update  PLN_ORDER_DZ_S T ";
		} else if (processCode.equals("D")) {
			// 查询调整订单
			String sqlProPlanNo = "SELECT T.PRO_PLAN_ID, T.GX_PLAN_NO, T.EXE_STATUS FROM PLN_ORDER_ZG_S T "
					+ " WHERE T.PLINE_CODE = ? AND T.EXE_STATUS IN ('0', '1') AND TO_NUMBER(T.GX_PRO_SEQ) < TO_NUMBER(?)";
			ps = con.prepareStatement(sqlProPlanNo);
			ps.setObject(1, plineCode);
			ps.setObject(2, gxProSeq);
			rs = ps.executeQuery();
			while (rs.next()) {
				// 查询订单向下炉计划是否全部生产中或生产完成
				String sqlZyStatr = "SELECT DECODE(MIN(T.PLANSTATUS),'','20',MIN(T.PLANSTATUS)) PLANSTATUS FROM PLN_ZY_ZG_M T WHERE T.PRO_PLAN_ID=? AND T.GX_PLAN_NO=?";
				ps1 = con.prepareStatement(sqlZyStatr);
				ps1.setObject(1, rs.getString("PRO_PLAN_ID"));
				ps1.setObject(2, rs.getString("GX_PLAN_NO"));
				rs1 = ps1.executeQuery();
				if (rs1.next()) {
					if (rs1.getInt("PLANSTATUS") < 20) {
						message = "订单号" + rs.getString("PRO_PLAN_ID") + "/"
								+ rs.getString("GX_PLAN_NO")
								+ "向下炉计划有计划/下发状态,不能状态调整!";
						throw new Exception(message);
					}
				}
				rs1.close();
				ps1.close();

				// 查询订单向下炉计划是否存剩余炉计划
				sqlZyStatr = CoreXmlSqlParsersFactory
						.getSql("ProducHelper.QueryRemaZg");
				ps1 = con.prepareStatement(sqlZyStatr);
				ps1.setObject(1, rs.getString("PRO_PLAN_ID"));
				ps1.setObject(2, rs.getString("GX_PLAN_NO"));
				rs1 = ps1.executeQuery();
				while (rs1.next()) {
					if (rs1.getInt("ACT_COUNT") > 0) {
						message = "订单号" + rs.getString("PRO_PLAN_ID") + "/"
								+ rs.getString("GX_PLAN_NO") + "向下炉计划判定炉号("
								+ rs1.getString("FEED_HEAT_NO")
								+ ")未上料完,不能状态调整,请先删除剩余炉计划!";
						throw new Exception(message);
					}
				}
				rs1.close();
				ps1.close();
			}
			rs.close();
			ps.close();
			sql = "update PLN_ORDER_ZG_S T ";
		} else if (processCode.equals("E")) {
			// 查询调整订单
			String sqlProPlanNo = "SELECT T.PRO_PLAN_ID, T.GX_PLAN_NO, T.EXE_STATUS,T.ORD_LN_DLY_PK,T.PLN_DIVIDE_ID FROM PLN_ORDER_DBK_S T "
					+ " WHERE T.PLINE_CODE = ? AND T.EXE_STATUS IN ('0', '1') AND TO_NUMBER(T.GX_PRO_SEQ) < TO_NUMBER(?)";
			ps = con.prepareStatement(sqlProPlanNo);
			ps.setObject(1, plineCode);
			ps.setObject(2, gxProSeq);
			rs = ps.executeQuery();
			while (rs.next()) {
				// 查询上工序是否全部生产完成
				String sqlExeStatus = CoreXmlSqlParsersFactory
						.getSql("ProducHelper.QueryExeStatusDbk");
				ps1 = con.prepareStatement(sqlExeStatus);
				ps1.setObject(1, rs.getString("PRO_PLAN_ID"));
				ps1.setObject(2, rs.getString("GX_PLAN_NO"));
				rs1 = ps1.executeQuery();
				if (rs1.next()) {
					if (rs1.getInt("BEFORE_STATE") < 2) {
						if (rs1.getInt("GX_PRO_SEQ_MAX") <= rs1
								.getInt("GX_PRO_SEQ")
								&& rs1.getInt("EXE_STATUS_DBK") >= 2) {
							message = "订单号" + rs.getString("PRO_PLAN_ID") + "/"
									+ rs.getString("GX_PLAN_NO")
									+ "前工序订单有计划/生产中状态并且本工序订单("
									+ rs.getString("PRO_PLAN_ID")
									+ ")没有计划状态,不能状态调整!";
							throw new Exception(message);
						}
					}
				}
				rs1.close();
				ps1.close();
				// 查询订单向下炉计划是否全部生产中或生产完成
				String sqlZyStatr = "SELECT DECODE(MIN(T.PLANSTATUS),'','20',MIN(T.PLANSTATUS)) PLANSTATUS FROM PLN_ZY_DBK_M T WHERE T.PRO_PLAN_ID=? AND T.GX_PLAN_NO=?";
				ps1 = con.prepareStatement(sqlZyStatr);
				ps1.setObject(1, rs.getString("PRO_PLAN_ID"));
				ps1.setObject(2, rs.getString("GX_PLAN_NO"));
				rs1 = ps1.executeQuery();
				if (rs1.next()) {
					if (rs1.getInt("PLANSTATUS") < 20) {
						message = "订单号" + rs.getString("PRO_PLAN_ID") + "/"
								+ rs.getString("GX_PLAN_NO")
								+ "向下炉计划有计划/下发状态,不能状态调整!";
						throw new Exception(message);
					}
				}
				rs1.close();
				ps1.close();
				// 查询订单向下炉计划是否存剩余炉计划
				sqlZyStatr = CoreXmlSqlParsersFactory
						.getSql("FrmPlanStoveD.QueryRemaDbk");
				ps1 = con.prepareStatement(sqlZyStatr);
				ps1.setObject(1, rs.getString("PRO_PLAN_ID"));
				ps1.setObject(2, rs.getString("GX_PLAN_NO"));
				rs1 = ps1.executeQuery();
				while (rs1.next()) {
					if (rs1.getInt("ACT_COUNT") > 0) {
						message = "订单号" + rs.getString("PRO_PLAN_ID") + "/"
								+ rs.getString("GX_PLAN_NO") + "向下炉计划上料炉号("
								+ rs1.getString("FEED_HEAT_NO")
								+ ")未上料完,不能状态调整,请先删除剩余炉计划!";
						throw new Exception(message);
					}
				}
				rs1.close();
				ps1.close();
			}
			rs.close();
			ps.close();
			sql = "update PLN_ORDER_DBK_S T ";
		} else if (processCode.equals("F")) {
			// 查询调整订单
			String sqlProPlanNo = "SELECT T.PRO_PLAN_ID, T.GX_PLAN_NO, T.EXE_STATUS,T.ORD_LN_DLY_PK,T.PLN_DIVIDE_ID FROM PLN_ORDER_RCL_S T "
					+ " WHERE T.PLINE_CODE = ? AND T.EXE_STATUS IN ('0', '1') AND TO_NUMBER(T.GX_PRO_SEQ) < TO_NUMBER(?)";
			ps = con.prepareStatement(sqlProPlanNo);
			ps.setObject(1, plineCode);
			ps.setObject(2, gxProSeq);
			rs = ps.executeQuery();
			while (rs.next()) {
				// 查询上工序是否全部生产完成
				String sqlExeStatus = CoreXmlSqlParsersFactory
						.getSql("ProducHelper.QueryExeStatusRcl");
				ps1 = con.prepareStatement(sqlExeStatus);
				ps1.setObject(1, rs.getString("PRO_PLAN_ID"));
				ps1.setObject(2, rs.getString("GX_PLAN_NO"));
				rs1 = ps1.executeQuery();
				if (rs1.next()) {
					if (rs1.getInt("BEFORE_STATE") < 2) {
						if (rs1.getInt("GX_PRO_SEQ_MAX") <= rs1
								.getInt("GX_PRO_SEQ")
								&& rs1.getInt("EXE_STATUS_RCL") >= 2) {
							message = "订单号" + rs.getString("PRO_PLAN_ID") + "/"
									+ rs.getString("GX_PLAN_NO")
									+ "前工序订单有计划/生产中状态并且本工序订单("
									+ rs.getString("PRO_PLAN_ID")
									+ ")没有计划状态,不能状态调整!";
							throw new Exception(message);
						}
					}
				}
				rs1.close();
				ps1.close();
				// 查询订单向下炉计划是否全部生产中或生产完成
				String sqlZyStatr = "SELECT DECODE(MIN(T.PLANSTATUS),'','20',MIN(T.PLANSTATUS)) PLANSTATUS FROM PLN_ZY_RCL_M T WHERE T.PRO_PLAN_ID=? AND T.GX_PLAN_NO=?";
				ps1 = con.prepareStatement(sqlZyStatr);
				ps1.setObject(1, rs.getString("PRO_PLAN_ID"));
				ps1.setObject(2, rs.getString("GX_PLAN_NO"));
				rs1 = ps1.executeQuery();
				if (rs1.next()) {
					if (rs1.getInt("PLANSTATUS") < 20) {
						message = "订单号" + rs.getString("PRO_PLAN_ID") + "/"
								+ rs.getString("GX_PLAN_NO")
								+ "向下炉计划有计划/下发状态,不能状态调整!";
						throw new Exception(message);
					}
				}
				rs1.close();
				ps1.close();

				// 查询订单向下炉计划是否存剩余炉计划
				sqlZyStatr = CoreXmlSqlParsersFactory
						.getSql("FrmPlanStoveD.QueryRemaRcl");
				ps1 = con.prepareStatement(sqlZyStatr);
				ps1.setObject(1, rs.getString("PRO_PLAN_ID"));
				ps1.setObject(2, rs.getString("GX_PLAN_NO"));
				rs1 = ps1.executeQuery();
				while (rs1.next()) {
					if (rs1.getInt("ACT_COUNT") > 0) {
						message = "订单号" + rs.getString("PRO_PLAN_ID") + "/"
								+ rs.getString("GX_PLAN_NO") + "向下炉计划判定炉号("
								+ rs1.getString("JUDGE_STOVE_NO")
								+ ")未上料完,不能状态调整,请先删除剩余炉计划!";
						throw new Exception(message);
					}
				}
				rs1.close();
				ps1.close();
			}
			rs.close();
			ps.close();
			sql = "update PLN_ORDER_RCL_S T ";
		} else if (processCode.equals("G")) {

			// 查询调整订单
			String sqlProPlanNo = "SELECT T.PRO_PLAN_ID, T.GX_PLAN_NO, T.EXE_STATUS,T.ORD_LN_DLY_PK,T.PLN_DIVIDE_ID FROM PLN_ORDER_JGX_S T "
					+ " WHERE T.PLINE_CODE = ? AND T.EXE_STATUS IN ('0', '1') AND TO_NUMBER(T.GX_PRO_SEQ) < TO_NUMBER(?)";
			ps = con.prepareStatement(sqlProPlanNo);
			ps.setObject(1, plineCode);
			ps.setObject(2, gxProSeq);
			rs = ps.executeQuery();
			while (rs.next()) {
				// 查询
				// 查询上工序是否全部生产完成
				String sqlExeStatus = CoreXmlSqlParsersFactory
						.getSql("ProducHelper.QueryExeStatusJgx");
				ps1 = con.prepareStatement(sqlExeStatus);
				ps1.setObject(1, rs.getString("PRO_PLAN_ID"));
				ps1.setObject(2, rs.getString("GX_PLAN_NO"));
				rs1 = ps1.executeQuery();
				if (rs1.next()) {
					if (rs1.getInt("BEFORE_STATE") < 2) {
						if (rs1.getInt("GX_PRO_SEQ_MAX") <= rs1
								.getInt("GX_PRO_SEQ")
								&& rs1.getInt("EXE_STATUS_JGX") >= 2) {
							message = "订单号" + rs.getString("PRO_PLAN_ID") + "/"
									+ rs.getString("GX_PLAN_NO")
									+ "前工序订单有计划/生产中状态并且本工序订单("
									+ rs.getString("PRO_PLAN_ID")
									+ ")没有计划状态,不能状态调整!";
							throw new Exception(message);
						}
					}
				}
				rs1.close();
				ps1.close();
				// 查询订单向下炉计划是否全部生产中或生产完成
				String sqlZyStatr = "SELECT DECODE(MIN(T.PLANSTATUS),'','20',MIN(T.PLANSTATUS)) PLANSTATUS FROM PLN_ZY_JGX_M T WHERE T.PRO_PLAN_ID=? AND T.GX_PLAN_NO=?";
				ps1 = con.prepareStatement(sqlZyStatr);
				ps1.setObject(1, rs.getString("PRO_PLAN_ID"));
				ps1.setObject(2, rs.getString("GX_PLAN_NO"));
				rs1 = ps1.executeQuery();
				if (rs1.next()) {
					if (rs1.getInt("PLANSTATUS") < 20) {
						message = "订单号" + rs.getString("PRO_PLAN_ID") + "/"
								+ rs.getString("GX_PLAN_NO")
								+ "向下炉计划有计划/下发状态,不能状态调整!";
						throw new Exception(message);
					}
				}
				rs1.close();
				ps1.close();

				// 查询订单向下炉计划是否存剩余炉计划
				sqlZyStatr = CoreXmlSqlParsersFactory
						.getSql("FrmPlanStoveD.QueryRemaJgx");
				ps1 = con.prepareStatement(sqlZyStatr);
				ps1.setObject(1, rs.getString("PRO_PLAN_ID"));
				ps1.setObject(2, rs.getString("GX_PLAN_NO"));
				rs1 = ps1.executeQuery();
				while (rs1.next()) {
					if (rs1.getInt("ACT_COUNT") > 0) {
						message = "订单号" + rs.getString("PRO_PLAN_ID") + "/"
								+ rs.getString("GX_PLAN_NO") + "向下炉计划判定炉号("
								+ rs1.getString("JUDGE_STOVE_NO")
								+ ")未上料完,不能状态调整,请先删除剩余炉计划!";
						throw new Exception(message);
					}
				}
				rs1.close();
				ps1.close();

				// // 查询成品合同对应接箍备料码信息
				// String sqlBl =
				// "SELECT T.REQ_BL_ID FROM PLN_JG_AND_BL T, PLN_ORDER_JG T1 WHERE T.PRO_PLAN_ID = T1.PRO_PLAN_ID AND T1.ORD_LN_DLY_PK = ?";
				// ps1 = con.prepareStatement(sqlBl);
				// ps1.setObject(1, rs.getString("ORD_LN_DLY_PK"));
				// rs1 = ps1.executeQuery();
				// while (rs1.next()) {
				// ArrayList<String> list1 = new ArrayList<String>();
				// list1.add(rs1.getString("REQ_BL_ID"));
				// list.add(list1);
				// }
				// rs1.close();
				// ps1.close();
			}
			rs.close();
			ps.close();
			sql = "update PLN_ORDER_JGX_S T ";
		} else if (processCode.equals("H")) {

			// 查询调整订单
			String sqlProPlanNo = "SELECT T.PRO_PLAN_ID, T.GX_PLAN_NO, T.EXE_STATUS,T.ORD_LN_DLY_PK,T.PLN_DIVIDE_ID FROM PLN_GX_JG_PROP_S T "
					+ " WHERE T.PLINE_CODE = ? AND T.EXE_STATUS IN ('0', '1') AND TO_NUMBER(T.GX_PRO_SEQ) < TO_NUMBER(?)";
			ps = con.prepareStatement(sqlProPlanNo);
			ps.setObject(1, plineCode);
			ps.setObject(2, gxProSeq);
			rs = ps.executeQuery();
			while (rs.next()) {
				// 查询订单向下炉计划是否全部生产中或生产完成
				String sqlZyStatr = "SELECT DECODE(MIN(T.PLANSTATUS),'','20',MIN(T.PLANSTATUS)) PLANSTATUS FROM PLN_ZY_JG_M T WHERE T.PRO_PLAN_ID=? AND T.GX_PLAN_NO=?";
				ps1 = con.prepareStatement(sqlZyStatr);
				ps1.setObject(1, rs.getString("PRO_PLAN_ID"));
				ps1.setObject(2, rs.getString("GX_PLAN_NO"));
				rs1 = ps1.executeQuery();
				if (rs1.next()) {
					if (rs1.getInt("PLANSTATUS") < 20) {
						message = "订单号" + rs.getString("PRO_PLAN_ID") + "/"
								+ rs.getString("GX_PLAN_NO")
								+ "向下炉计划有计划/下发状态,不能状态调整!";
						throw new Exception(message);
					}
				}
				rs1.close();
				ps1.close();

				// 查询订单向下炉计划是否存剩余炉计划
				sqlZyStatr = CoreXmlSqlParsersFactory
						.getSql("ProducHelper.QueryRemaJg");
				ps1 = con.prepareStatement(sqlZyStatr);
				ps1.setObject(1, rs.getString("PRO_PLAN_ID"));
				ps1.setObject(2, rs.getString("GX_PLAN_NO"));
				rs1 = ps1.executeQuery();
				while (rs1.next()) {
					if (rs1.getInt("ACT_COUNT") > 0) {
						message = "订单号" + rs.getString("PRO_PLAN_ID") + "/"
								+ rs.getString("GX_PLAN_NO") + "向下炉计划判定炉号("
								+ rs1.getString("JUDGE_STOVE_NO")
								+ ")未上料完,不能状态调整,请先删除剩余炉计划!";
						throw new Exception(message);
					}
				}
				rs1.close();
				ps1.close();
			}
			rs.close();
			ps.close();
			sql = "update PLN_GX_JG_PROP_S T ";
		}
		if(!processCode.equals("B") && !processCode.equals("H")) {
			String messCrm = ProducCrm.insertCrmSetStaus(con, plineCode, gxProSeq, processCode);
			if (!messCrm.equals("")) {
				message = "新增CRM接口表异常!";
				throw new Exception(message);
			}
		}
		sql += CoreXmlSqlParsersFactory.getSql("ProducHelperBean.statusChange");
		ps = con.prepareStatement(sql);
		ps.setObject(1, gxProSeq);
		ps.setObject(2, gxProSeq);
		ps.setObject(3, gxProSeq);
		ps.setObject(4, gxProSeq);
		ps.setObject(5, plineCode);
		ps.executeUpdate();
		ps.close();
		// if (processCode.equals("G")) {
		// for (int i = 0; i < list.size(); i++) {
		// String exeStatus = "";
		// // 查询备料需求对应成品合同是否全部生产完成或关闭
		// String sqlCp =
		// "SELECT MIN(S.EXE_STATUS) EXE_STATUS FROM PLN_ORDER_JGX_S S,PLN_ORDER_JG T, PLN_JG_AND_BL T1 WHERE T.PRO_PLAN_ID = T1.PRO_PLAN_ID AND S.ORD_LN_DLY_PK=T.ORD_LN_DLY_PK AND T1.REQ_BL_ID = ?";
		// ps = con.prepareStatement(sqlCp);
		// ps.setObject(1, list.get(i).get(0));
		// rs = ps.executeQuery();
		// if (rs.next()) {
		// exeStatus = rs.getString("EXE_STATUS");
		// }
		// rs.close();
		// ps.close();
		//
		// if (exeStatus.equals("2") || exeStatus.equals("3")) {
		// ProducHelperBean helperBean = new ProducHelperBean();
		// // 查询接箍排产订单
		// String sqlJgOrder =
		// "SELECT T.PLINE_CODE,T.GX_PRO_SEQ,T.EXE_STATUS,T.PRO_PLAN_ID,T.GX_PLAN_NO FROM PLN_GX_JG_PROP_S T WHERE T.ORD_LN_DLY_PK=? AND T.EXE_STATUS<>'3'";
		// ps = con.prepareStatement(sqlJgOrder);
		// ps.setObject(1, list.get(i).get(0));
		// rs = ps.executeQuery();
		// while (rs.next()) {
		// // 修改接箍订单状态
		// int seq = 0;// 最小生产顺序
		// String planTimeE = "";
		// String groPlanIdH = rs.getString("PRO_PLAN_ID");
		// String gxPlanNoH = rs.getString("GX_PLAN_NO");
		// int gxProSeqH = Integer.parseInt(rs
		// .getString("GX_PRO_SEQ"));
		// PlnGxJgPropSEntity entity = PlnHelper.getEntityData(
		// con, new String[] { groPlanIdH, gxPlanNoH },
		// "ProducHelperBean.getPlanOrderH",
		// "and t.pro_plan_id=? and t.gx_plan_no=?",
		// PlnGxJgPropSEntity.class);
		// if (entity == null) {
		// message = "数据发生变化,请刷新数据!";
		// throw new Exception(message);
		// }
		// if (seq == 0) {
		// seq = gxProSeqH;
		// }
		// if (seq >= gxProSeqH) {
		// seq = gxProSeqH;
		// planTimeE = entity.getPlanTimeB();
		// plineCode = entity.getPlineCode();
		// }
		//
		// entity.setPlanTimeB("");
		// entity.setPlanTimeE("");
		// entity.setPlanUsetime("0");
		// entity.setGxProSeq("-1");
		// entity.setExeStatus("3");
		// PlnHelper.deleteOrUpdateByEntity(con,
		// "ProducHelperBean.updatePlanOrderH", entity);
		// // 生产顺序调整
		// helperBean.seqIncrease(con, entity.getPlineCode(),
		// gxProSeqH, -1, -1, processCode);
		//
		// // 时间调整
		// helperBean.timeIncrease(con, seq - 1, plineCode,
		// planTimeE, processCode);
		// }
		// rs.close();
		// ps.close();
		//
		// }
		// }
		// }
	}

	public void groupChange(Connection con, ProducEntity entity,
			String processCode) throws SQLException {
		// 调整分组序号(加工)
		if (processCode.equals("G")
				&& !entity.getPlanGroup().equals(entity.getOrglPlanGroup())) {
			String sql = " UPDATE PLN_GX_JGX_M T SET T.GROUP_JGX=? WHERE T.PRO_PLAN_ID=?";
			PreparedStatement ps = con.prepareStatement(sql);
			ps.setObject(1, entity.getOrglPlanGroup());
			ps.setObject(2, entity.getProPlanId());
			ps.executeUpdate();
			ps.close();
			ps = con.prepareStatement("update PLN_ORDER_JGX t set t.GROUP_JGX=? where t.PRO_ORDER_NO=?");
			ps.setObject(1, entity.getOrglPlanGroup());
			ps.setObject(2, entity.getProOrderNo());
			ps.executeUpdate();
			ps.close();
			ps = con.prepareStatement("update PLN_SALEORD_PROC t set t.GROUP_JGX=? where t.ORD_LN_DLY_PK=? and t.PLN_DIVIDE_ID=?");
			ps.setObject(1, entity.getOrglPlanGroup());
			ps.setObject(2, entity.getOrdLnDlyPk());
			ps.setObject(3, entity.getPlnDivideId());
			ps.executeUpdate();
			ps.close();
		}
		// 热处理(特殊处理)
		if (processCode.equals("F")
				&& !entity.getPlanGroup().equals(entity.getOrglPlanGroup())) {
			String sql = " UPDATE PLN_GX_RCL_M T SET T.GROUP_RCL=? WHERE T.PRO_PLAN_ID=?";
			PreparedStatement ps = con.prepareStatement(sql);
			ps.setObject(1, entity.getOrglPlanGroup());
			ps.setObject(2, entity.getProPlanId());
			ps.executeUpdate();
			ps.close();
			ps = con.prepareStatement("update PLN_ORDER_RCL t set t.GROUP_RCL=? where t.PRO_ORDER_NO=?");
			ps.setObject(1, entity.getOrglPlanGroup());
			ps.setObject(2, entity.getProOrderNo());
			ps.executeUpdate();
			ps.close();
			ps = con.prepareStatement("update PLN_SALEORD_PROC t set t.GROUP_RCL=? where t.ORD_LN_DLY_PK=? and t.PLN_DIVIDE_ID=?");
			ps.setObject(1, entity.getOrglPlanGroup());
			ps.setObject(2, entity.getOrdLnDlyPk());
			ps.setObject(3, entity.getPlnDivideId());
			ps.executeUpdate();
			ps.close();
		}
	}

	public static QuantiEntity getQuantity(Object obj, String processCode) {
		QuantiEntity entity1 = new QuantiEntity();
		if (processCode.equals("E")) {
			PlnOrderDbkSEntity entity = (PlnOrderDbkSEntity) obj;
			if (!entity.getMinWgt().equals("")) {
				entity1.setMinWgt(Double.parseDouble(entity.getMinWgt()));
			}
			// 排产支数
			if (!entity.getNumS().equals("")) {
				entity1.setNumS(Integer.parseInt(entity.getNumS()));
			}
			// 排产重量
			if (!entity.getWeigthS().equals("")) {
				entity1.setWeigthS(Double.parseDouble(entity.getWeigthS()));
			}
			// 待投入支数
			if (!entity.getInNumS().equals("")) {
				entity1.setInNumS(Integer.parseInt(entity.getInNumS()));
			}
			// 待投入重量
			if (!entity.getInWeightS().equals("")) {
				entity1.setInWeightS(Double.parseDouble(entity.getInWeightS()));
			}
			// 加投支数
			if (!entity.getAddNumIn().equals("")) {
				entity1.setAddNumIn(Integer.parseInt(entity.getAddNumIn()));
			}
			// 加投重量
			if (!entity.getAddWtIn().equals("")) {
				entity1.setAddWtIn(Double.parseDouble(entity.getAddWtIn()));
			}
			// 虚拟挂料支
			if (!entity.getBatchedNum().equals("")) {
				entity1.setBatchedNum(Integer.parseInt(entity.getBatchedNum()));
			}
			// 虚拟挂料重量
			if (!entity.getBatchedWt().equals("")) {
				entity1.setBachedWt(Double.parseDouble(entity.getBatchedWt()));
			}
			// 实际挂料支
			if (!entity.getRealBatchNum().equals("")) {
				entity1.setRealNum(Integer.parseInt(entity.getRealBatchNum()));
			}
			// 实际挂料吨
			if (!entity.getRealBatchWt().equals("")) {
				entity1.setRealWgt(Double.parseDouble(entity.getRealBatchWt()));
			}
			if (!entity.getMatchNumIn().equals("")) {
				entity1.setMatchNum(Integer.parseInt(entity.getMatchNumIn()));
			}
			if (!entity.getMatchWtIn().equals("")) {
				entity1.setMatchWgt(Double.parseDouble(entity.getMatchWtIn()));
			}
			entity1.setWeigthSMin(Double.parseDouble(entity.getWeigthSMin()));
		}
		return entity1;
	}

	/**
	 * 生成生产批次号
	 * 
	 * @param con
	 * @param plineCode
	 *            产线
	 * @param processCode
	 *            工序
	 * @throws SQLException
	 */
	public void generateZyBatchId(Connection con, String plineCode,
			String processCode) throws SQLException {
		if (processCode.equals("B") || processCode.equals("H")) {
			return;
		} else if (processCode.equals("C")) {
			String supSql = "  AND to_CHAR(T.PLAN_TIME_B, 'yyyy-mm') >= to_CHAR((SELECT T.PLAN_TIME_E FROM PLN_ORDER_DZ_S T WHERE TO_NUMBER(T.GX_PRO_SEQ) = NVL((SELECT MAX(TO_NUMBER(T.GX_PRO_SEQ))"
					+ "  FROM PLN_ORDER_DZ_S T WHERE T.EXE_STATUS = '1' AND T.PLINE_CODE = ?), (SELECT MIN(TO_NUMBER(T.GX_PRO_SEQ)) FROM PLN_ORDER_DZ_S T WHERE T.EXE_STATUS = '0' AND T.PLINE_CODE = ?))"
					+ " ANd T.PLINE_CODE = ?), 'YYYY-MM') AND T.PLINE_CODE = ?  AND TO_NUMBER(T.GX_PRO_SEQ) > 0 ORDER BY TO_NUMBER(T.GX_PRO_SEQ)";
			List<PlnOrderDzSEntity> list = PlnHelper
					.getEntityDatas(con, new String[] { plineCode, plineCode,
							plineCode, plineCode },
							"ProducHelperBean.getPlanOrderC", supSql,
							PlnOrderDzSEntity.class);
			if (list == null || list.size() == 0) {
				return;
			}
			List<String[]> arrList = ProducHelperBean.generateParam(list,
					processCode);
			List<Object[]> paramList = ProducHelperBean.generateUpdateParma(
					arrList, plineCode, processCode, null, con, "");
			PlnHelper.batchDeleteOrUpdate(con,
					"ProducHelperBean.generateZyBatchNoC", "", paramList);
		} else if (processCode.equals("D")) {
			// String supSql =
			// "  AND to_CHAR(T.PLAN_TIME_B, 'yyyy-mm') >= to_CHAR((SELECT T.PLAN_TIME_E FROM PLN_ORDER_ZG_S T WHERE TO_NUMBER(T.GX_PRO_SEQ) = NVL((SELECT MAX(TO_NUMBER(T.GX_PRO_SEQ))"
			// +
			// "  FROM PLN_ORDER_ZG_S T WHERE T.EXE_STATUS = '1' AND T.PLINE_CODE = ?), (SELECT MIN(TO_NUMBER(T.GX_PRO_SEQ)) FROM PLN_ORDER_ZG_S T WHERE T.EXE_STATUS = '0' AND T.PLINE_CODE = ?))"
			// +
			// " ANd T.PLINE_CODE = ?), 'YYYY-MM') AND T.PLINE_CODE = ?  AND TO_NUMBER(T.GX_PRO_SEQ) > 0 ORDER BY TO_NUMBER(T.GX_PRO_SEQ)";
			String supSql = " AND T.EXE_STATUS ='0' AND T.PLINE_CODE = ?  AND TO_NUMBER(T.GX_PRO_SEQ) > 0 ORDER BY TO_NUMBER(T.GX_PRO_SEQ)";
			List<PlnOrderZgSEntity> list = PlnHelper.getEntityDatas(con,
					new String[] { plineCode },
					"ProducHelperBean.getPlanOrderD", supSql,
					PlnOrderZgSEntity.class);
			if (list == null || list.size() == 0) {
				return;
			}

			List<String[]> arrList = ProducHelperBean.generateParam(list,
					processCode);
			String zyBatch = "";
			for (int i = 0; i < list.size(); i++) {
				String[] arr = arrList.get(i);
				zyBatch = arr[10];
				if (!zyBatch.equals("")) {
					break;
				}
			}
			// 查询已确认轧批号
			List<String> paramBaId = new ArrayList<String>();
			String sqlzYid = CoreXmlSqlParsersFactory
					.getSql("ProducHelperBean.selectPlanZyBatchIf");
			PreparedStatement ps = con.prepareStatement(sqlzYid);
			ps.setObject(1, plineCode);
			ResultSet rs = ps.executeQuery();
			while (rs.next()) {
				paramBaId.add(rs.getString("ZY_BATCH_ID"));
			}
			rs.close();
			ps.close();

			String plinE = "";
			if (plineCode.equals("C008")) {
				plinE = "Z";
			} else if (plineCode.equals("C009")) {
				plinE = "E";
			} else if (plineCode.equals("C010")) {
				plinE = "A";
			} else if (plineCode.equals("C012")) {
				plinE = "S";
			} else if (plineCode.equals("C017")) {
				plinE = "H";
			}else if(plineCode.equals("C072"))
			{
				plinE = "G";
			}
			else {
				plinE = "W";
			}
			String zyBatchIda = "";
			String partTime2 = list.get(0).getPlanTimeB().substring(2, 4)
					+ list.get(0).getPlanTimeB().substring(5, 7);
			// 查询生产完成，关闭，生产中 年月最大的轧批号
			String sql = CoreXmlSqlParsersFactory
					.getSql("ProducHelperBean.selectPlanZyBatchMax");
			ps = con.prepareStatement(sql);
			ps.setObject(1, plineCode);
			// ps.setObject(2, partTime2);
			ps.setObject(2, plinE + partTime2);
			rs = ps.executeQuery();
			if (rs.next()) {
				zyBatchIda = rs.getString("ZY_BATCH_ID");
			}
			rs.close();
			ps.close();
			int num = 1;
			if (zyBatchIda != null) {
				if (!zyBatchIda.equals("")) {
					if(zyBatchIda.length() == 8)
					{
						num = Integer.parseInt(zyBatchIda.substring(
								zyBatchIda.length() - 3, zyBatchIda.length())) + 1;
					}else
					{
						num = Integer.parseInt(zyBatchIda.substring(
								zyBatchIda.length() - 4, zyBatchIda.length())) + 1;
					}

				}
			}
			zyBatchIda = plinE + partTime2 + String.format("%04d", num);
			List<Object[]> paramList = ProducHelperBean
					.generateUpdateParma(arrList, plineCode, processCode,
							paramBaId, con, zyBatchIda);

			PlnHelper.batchDeleteOrUpdate(con,
					"ProducHelperBean.generateZyBatchNoD", "", paramList);
		} else if (processCode.equals("E")) {
			// String supSql =
			// "  AND to_CHAR(T.PLAN_TIME_B, 'yyyy-mm') >= to_CHAR((SELECT T.PLAN_TIME_E FROM PLN_ORDER_DBK_S T WHERE TO_NUMBER(T.GX_PRO_SEQ) = NVL((SELECT MAX(TO_NUMBER(T.GX_PRO_SEQ))"
			// +
			// "  FROM PLN_ORDER_DBK_S T WHERE T.EXE_STATUS = '1' AND T.PLINE_CODE = ?), (SELECT MIN(TO_NUMBER(T.GX_PRO_SEQ)) FROM PLN_ORDER_DBK_S T WHERE T.EXE_STATUS = '0' AND T.PLINE_CODE = ?))"
			// +
			// " ANd T.PLINE_CODE = ?), 'YYYY-MM') AND T.PLINE_CODE = ?  AND TO_NUMBER(T.GX_PRO_SEQ) > 0 ORDER BY TO_NUMBER(T.GX_PRO_SEQ)";
			String supSql = " AND T.EXE_STATUS ='0' AND T.PLINE_CODE = ?  AND TO_NUMBER(T.GX_PRO_SEQ) > 0 ORDER BY TO_NUMBER(T.GX_PRO_SEQ)";
			List<PlnOrderDbkSEntity> list = PlnHelper.getEntityDatas(con,
					new String[] { plineCode },
					"ProducHelperBean.getPlanOrderE", supSql,
					PlnOrderDbkSEntity.class);// , plineCode,plineCode,
			// plineCode
			if (list == null || list.size() == 0) {
				return;
			}
			List<String[]> arrList = ProducHelperBean.generateParam(list,
					processCode);
			List<Object[]> paramList = ProducHelperBean.generateUpdateParma(
					arrList, plineCode, processCode, null, con, "");
			// 镦拔扩生成作业批次号
			PlnHelper.batchDeleteOrUpdate(con,
					"ProducHelperBean.generateZyBatchNoE", "", paramList);
			// // 镦拔扩实际炉计划修改作业批次号
			// PlnHelper.batchDeleteOrUpdate(con,
			// "ProducHelperBean.updateZyBatchNoEM", "", paramList);
			// // 镦拔扩虚拟炉计划修改作业批次号
			// PlnHelper.batchDeleteOrUpdate(con,
			// "ProducHelperBean.updateZyBatchNoER", "", paramList);
		} else if (processCode.equals("F")) {
			// String supSql =
			// "  AND to_CHAR(T.PLAN_TIME_B, 'yyyy-mm') >= to_CHAR((SELECT MAX(T.PLAN_TIME_E) FROM PLN_ORDER_RCL_S T WHERE TO_NUMBER(T.GX_PRO_SEQ) = NVL((SELECT MAX(TO_NUMBER(T.GX_PRO_SEQ))"
			// +
			// "  FROM PLN_ORDER_RCL_S T WHERE T.EXE_STATUS = '1' AND T.PLINE_CODE = ?), (SELECT MIN(TO_NUMBER(T.GX_PRO_SEQ)) FROM PLN_ORDER_RCL_S T WHERE T.EXE_STATUS = '0' AND T.PLINE_CODE = ?))"
			// +
			// " ANd T.PLINE_CODE = ?), 'YYYY-MM') AND T.PLINE_CODE = ?  AND TO_NUMBER(T.GX_PRO_SEQ) > 0 ORDER BY TO_NUMBER(T.GX_PRO_SEQ)";
			String supSql = " AND T.EXE_STATUS ='0' AND T.PLINE_CODE = ?  AND TO_NUMBER(T.GX_PRO_SEQ) > 0 ORDER BY TO_NUMBER(T.GX_PRO_SEQ)";
			List<PlnOrderRclSEntity> list = PlnHelper.getEntityDatas(con,
					new String[] { plineCode },
					"ProducHelperBean.getPlanOrderF", supSql,
					PlnOrderRclSEntity.class);// plineCode, plineCode,plineCode,
			if (list == null || list.size() == 0) {
				return;
			}

			List<String[]> arrList = ProducHelperBean.generateParam(list,
					processCode);
			String zyBatch = "";
			for (int i = 0; i < list.size(); i++) {
				String[] arr = arrList.get(i);
				zyBatch = arr[10];
				if (!zyBatch.equals("")) {
					break;
				}
			}
			// 查询已下发生产批号
			List<String> paramBaId = new ArrayList<String>();
			String sqlzYid = "SELECT T.ZY_BATCH_ID FROM PLN_ORDER_RCL_S T WHERE T.EXE_STATUS IN ('0') AND T.PLINE_CODE = ? AND T.IF_STOVE_ISSUED = '1'  AND TO_NUMBER(T.GX_PRO_SEQ) > 0";
			PreparedStatement ps = con.prepareStatement(sqlzYid);
			ps.setObject(1, plineCode);
			ResultSet rs = ps.executeQuery();
			while (rs.next()) {
				paramBaId.add(rs.getString("ZY_BATCH_ID"));
			}
			rs.close();
			ps.close();

			String zyBatchIda = "";
			String partTime2 = list.get(0).getPlanTimeB().substring(0, 4)
					+ list.get(0).getPlanTimeB().substring(5, 7);
			// 查询生产完成，关闭，生产中 年月最大的轧批号
			String sql = "SELECT MAX(T.ZY_BATCH_ID) ZY_BATCH_ID  FROM PLN_ORDER_RCL_S T WHERE T.EXE_STATUS IN ('1', '2', '3')  AND T.PLINE_CODE = ?  AND T.ZY_BATCH_ID LIKE '%' || ? || '%'";
			ps = con.prepareStatement(sql);
			ps.setObject(1, plineCode);
			ps.setObject(2, plineCode + partTime2);
			rs = ps.executeQuery();
			if (rs.next()) {
				zyBatchIda = rs.getString("ZY_BATCH_ID");
			}
			rs.close();
			ps.close();
			int num = 1;
			if (zyBatchIda != null) {
				if (!zyBatchIda.equals("")) {
					num = Integer.parseInt(zyBatchIda.substring(
							zyBatchIda.length() - 4, zyBatchIda.length())) + 1;
				}
			}
			zyBatchIda = plineCode + partTime2 + String.format("%04d", num);
			List<Object[]> paramList = ProducHelperBean
					.generateUpdateParma(arrList, plineCode, processCode,
							paramBaId, con, zyBatchIda);
			PlnHelper.batchDeleteOrUpdate(con,
					"ProducHelperBean.generateZyBatchNoF", "", paramList);
		} else if (processCode.equals("G")) {
			// String supSql =
			// "  AND to_CHAR(T.PLAN_TIME_B, 'yyyy-mm') >= to_CHAR((SELECT MAX(T.PLAN_TIME_E) FROM PLN_ORDER_JGX_S T WHERE TO_NUMBER(T.GX_PRO_SEQ) = NVL((SELECT MAX(TO_NUMBER(T.GX_PRO_SEQ))"
			// +
			// "  FROM PLN_ORDER_JGX_S T WHERE T.EXE_STATUS = '1' AND T.PLINE_CODE = ?), (SELECT MIN(TO_NUMBER(T.GX_PRO_SEQ)) FROM PLN_ORDER_JGX_S T WHERE T.EXE_STATUS = '0' AND T.PLINE_CODE = ?))"
			// +
			// " ANd T.PLINE_CODE = ?), 'YYYY-MM') AND T.PLINE_CODE = ?  AND TO_NUMBER(T.GX_PRO_SEQ) > 0 ORDER BY TO_NUMBER(T.GX_PRO_SEQ)";
			String supSql = " AND T.EXE_STATUS ='0' AND T.PLINE_CODE = ?  AND TO_NUMBER(T.GX_PRO_SEQ) > 0 ORDER BY TO_NUMBER(T.GX_PRO_SEQ)";
			List<PlnOrderJgxSEntity> list = PlnHelper.getEntityDatas(con,
					new String[] { plineCode },
					"ProducHelperBean.getPlanOrderG", supSql,
					PlnOrderJgxSEntity.class);// plineCode, plineCode,
			// plineCode,
			if (list == null || list.size() == 0) {
				return;
			}
			List<String[]> arrList = ProducHelperBean.generateParam(list,
					processCode);
			String zyBatch = "";
			for (int i = 0; i < list.size(); i++) {
				String[] arr = arrList.get(i);
				zyBatch = arr[10];
				if (!zyBatch.equals("")) {
					break;
				}
			}
			// 查询已下发生产批号
			List<String> paramBaId = new ArrayList<String>();
			String sqlzYid = "SELECT T.ZY_BATCH_ID FROM PLN_ORDER_JGX_S T WHERE T.EXE_STATUS IN ('0') AND T.PLINE_CODE = ? AND T.IF_STOVE_ISSUED = '1'  AND TO_NUMBER(T.GX_PRO_SEQ) > 0";
			PreparedStatement ps = con.prepareStatement(sqlzYid);
			ps.setObject(1, plineCode);
			ResultSet rs = ps.executeQuery();
			while (rs.next()) {
				paramBaId.add(rs.getString("ZY_BATCH_ID"));
			}
			rs.close();
			ps.close();

			String zyBatchIda = "";
			String partTime2 = list.get(0).getPlanTimeB().substring(0, 4)
					+ list.get(0).getPlanTimeB().substring(5, 7);
			// 查询生产完成，关闭，生产中 年月最大的轧批号
			String sql = "SELECT MAX(T.ZY_BATCH_ID) ZY_BATCH_ID  FROM PLN_ORDER_JGX_S T WHERE T.EXE_STATUS IN ('1', '2', '3')  AND T.PLINE_CODE = ?  AND T.ZY_BATCH_ID LIKE '%' || ? || '%'";
			ps = con.prepareStatement(sql);
			ps.setObject(1, plineCode);
			ps.setObject(2, plineCode + partTime2);
			rs = ps.executeQuery();
			if (rs.next()) {
				zyBatchIda = rs.getString("ZY_BATCH_ID");
			}
			rs.close();
			ps.close();
			int num = 1;
			if (zyBatchIda != null) {
				if (!zyBatchIda.equals("")) {
					num = Integer.parseInt(zyBatchIda.substring(
							zyBatchIda.length() - 4, zyBatchIda.length())) + 1;
				}
			}
			zyBatchIda = plineCode + partTime2 + String.format("%04d", num);
			List<Object[]> paramList = ProducHelperBean
					.generateUpdateParma(arrList, plineCode, processCode,
							paramBaId, con, zyBatchIda);
			PlnHelper.batchDeleteOrUpdate(con,
					"ProducHelperBean.generateZyBatchNoG", "", paramList);
		}

	}

	/**
	 * 生产批次号参数
	 * 
	 * @param list
	 * @param processCode
	 * @return
	 */
	public static <T> List<String[]> generateParam(List<T> list,
			String processCode) {
		List<String[]> params = new ArrayList<String[]>();
		if (processCode.equals("C")) {
			for (Object obj : list) {
				PlnOrderDzSEntity entity = (PlnOrderDzSEntity) obj;
				String[] param = new String[] { entity.getProPlanId(),
						entity.getGxPlanNo(), entity.getPlanTimeB(),
						entity.getWlidIn(), entity.getOutwlId(), "" };
				params.add(param);
			}
		} else if (processCode.equals("D")) {
			for (Object obj : list) {
				PlnOrderZgSEntity entity = (PlnOrderZgSEntity) obj;
				String[] param = new String[] { entity.getProPlanId(),
						entity.getGxPlanNo(), entity.getPlanTimeB(),
						entity.getInwlId(), entity.getOutwlId(),
						entity.getCraftFileNo(), entity.getAimoutdiameter(),
						entity.getAimwallthick(), entity.getGradecode(),
						entity.getGxProSeq(), entity.getZyBatchId(),
						entity.getIsPlanOk(), entity.getExeStatus(),
						entity.getIfStoveIssued(), entity.getIsRepairPln() };
				params.add(param);
			}
		} else if (processCode.equals("E")) {
			for (Object obj : list) {
				PlnOrderDbkSEntity entity = (PlnOrderDbkSEntity) obj;
				String[] param = new String[] { entity.getProPlanId(),
						entity.getGxPlanNo(), entity.getPlanTimeB(),
						entity.getInwlId(), entity.getOutwlId(),
						entity.getCraftFileNo(), "", "", "",
						entity.getGxProSeq(), entity.getZyBatchId(),
						entity.getIsPlanOk(), entity.getExeStatus(),
						entity.getIfStoveIssued(), entity.getIsRepairPln() };
				params.add(param);
			}
		} else if (processCode.equals("F")) {
			for (Object obj : list) {
				PlnOrderRclSEntity entity = (PlnOrderRclSEntity) obj;
				String[] param = new String[] { entity.getProPlanId(),
						entity.getGxPlanNo(), entity.getPlanTimeB(),
						entity.getInwlId(), entity.getOutwlId(),
						entity.getCraftFileNo(), "", "", "",
						entity.getGxProSeq(), entity.getZyBatchId(),
						entity.getIsPlanOk(), entity.getExeStatus(),
						entity.getIfStoveIssued(), entity.getIsRepairPln() };
				params.add(param);
			}
		} else if (processCode.equals("G")) {
			for (Object obj : list) {
				PlnOrderJgxSEntity entity = (PlnOrderJgxSEntity) obj;
				String[] param = new String[] { entity.getProPlanId(),
						entity.getGxPlanNo(), entity.getPlanTimeB(),
						entity.getInwlId(), entity.getOutwlId(),
						entity.getCraftFileNo(), "", "", "",
						entity.getGxProSeq(), entity.getZyBatchId(),
						entity.getIsPlanOk(), entity.getExeStatus(),
						entity.getIfStoveIssued(), entity.getIsRepairPln() };
				params.add(param);
			}
		}
		return params;
	}

	/**
	 * 生成生产批次号修改参数
	 * 
	 * @param list
	 * @param plineCode
	 * @param processCode
	 * @return
	 * @throws SQLException
	 */
	@SuppressWarnings("null")
	public static List<Object[]> generateUpdateParma(List<String[]> list,
			String plineCode, String processCode, List<String> zyBatchIfId,
			Connection con, String zyBatchIda) throws SQLException {
		List<Object[]> paramList = new ArrayList<Object[]>();
		int num = 1;// 序号
		String zyBatchId = "";// 生产批次号
		String partTime = "";// 时间年月
		String inMaterialNo = "";// 投入物料
		String outMaterialNo = "";// 产出物料
		String craftNo = "";// 工艺文件号
		String aimoutdiameter = "";// 控制外径
		String aimwallthick = "";// 控制壁厚
		String gradecode = "";// 钢种
		String exeStatus = "";// 计划状态
		String isPlanOk = "";// 炉计划下发状态
		String isRepairPln = "";// 是否检修计划
		for (int i = 0; i < list.size(); i++) {
			String[] arr = list.get(i);
			String planTimeB = arr[2];

			if (processCode.equals("D")) {// 轧管
				String plinE = "";
				if (plineCode.equals("C008")) {
					plinE = "Z";
				} else if (plineCode.equals("C009")) {
					plinE = "E";
				} else if (plineCode.equals("C010")) {
					plinE = "A";
				} else if (plineCode.equals("C012")) {
					plinE = "S";
				} else if (plineCode.equals("C017")) {
					plinE = "H";
				} else if (plineCode.equals("C072")) {
					plinE = "G";
				}
				else {
					plinE = "W";
				}
				exeStatus = arr[12];
				isPlanOk = arr[13];
				isRepairPln = arr[14];
				if (isPlanOk.equals("1") || isRepairPln.equals("1")) {
					zyBatchId = arr[10];
					Object[] param = new Object[] { zyBatchId, arr[0], arr[1] };
					paramList.add(param);
					// num++;
				} else {
					String partTime1 = planTimeB.substring(2, 4)
							+ planTimeB.substring(5, 7);
					// 同年同月下
					if (partTime1.equals(partTime)) {
						// // 相同投入、产出物料、工艺文件号，控制外径壁厚，钢种，顺序号连续
						// if (arr[3].equals(inMaterialNo)
						// && arr[4].equals(outMaterialNo)
						// && arr[5].equals(craftNo)
						// && arr[6].equals(aimoutdiameter)
						// && arr[7].equals(aimwallthick)
						// && arr[8].equals(gradecode)) {
						// Object[] param = new Object[] { zyBatchId,
						// arr[0], arr[1] };
						// paramList.add(param);
						// }
						// else {
						//
						if (zyBatchId.equals("") && num == 1) {
							zyBatchId = zyBatchIda;
						} else {
							zyBatchId = plinE + partTime1
									+ String.format("%04d", num);
						}
						if (zyBatchIfId != null && zyBatchIfId.size() > 0) {
							// String[] arry = sum(zyBatchIfId, zyBatchId,
							// num, plinE, partTime1);
							// zyBatchId = arry[0];
							// num = Integer.parseInt(arry[1]);
							do {
								if (zyBatchIfId.contains(zyBatchId)) {
									num++;
									zyBatchId = plinE + partTime1
											+ String.format("%04d", num);
								}
							} while (zyBatchIfId.contains(zyBatchId) == true);

						}

						Object[] param = new Object[] { zyBatchId, arr[0],
								arr[1] };
						paramList.add(param);
						num++;
						// }
					} else {
						String partTime2 = planTimeB.substring(2, 4)
								+ planTimeB.substring(5, 7);
						// 查询生产完成，关闭，生产中 年月最大的轧批号
						String sql = CoreXmlSqlParsersFactory
								.getSql("ProducHelperBean.selectPlanZyBatchMax");
						PreparedStatement ps = con.prepareStatement(sql);
						ps.setObject(1, plineCode);
						// ps.setObject(2, partTime2);
						ps.setObject(2, plinE + partTime2);
						ResultSet rs = ps.executeQuery();
						if (rs.next()) {
							zyBatchIda = rs.getString("ZY_BATCH_ID");
						}
						rs.close();
						ps.close();
						if (zyBatchIda != null) {
							if (!zyBatchIda.equals("")) {
								if(zyBatchIda.length() == 8)
								{
									num = Integer.parseInt(zyBatchIda.substring(5,
											8)) + 1;
								}else
								{
									num = Integer.parseInt(zyBatchIda.substring(5,
											9)) + 1;
								}

							} else {
								// 不是同年同月下，则重新从1 开始
								num = 1;
							}
						} else {
							// 不是同年同月下，则重新从1 开始
							num = 1;
						}
						zyBatchId = plinE + partTime1
								+ String.format("%04d", num);
						if (zyBatchIfId != null && zyBatchIfId.size() > 0) {
							// String[] arry = sum(zyBatchIfId, zyBatchId,
							// num, plinE, partTime1);
							// zyBatchId = arry[0];
							// num = Integer.parseInt(arry[1]);
							do {
								if (zyBatchIfId.contains(zyBatchId)) {
									num++;
									zyBatchId = plinE + partTime1
											+ String.format("%04d", num);
								}
							} while (zyBatchIfId.contains(zyBatchId) == true);
						}

						partTime = partTime1;
						Object[] param = new Object[] { zyBatchId, arr[0],
								arr[1] };
						paramList.add(param);
						num++;
					}

				}
				// }
				// 最后赋值
				inMaterialNo = arr[3];
				outMaterialNo = arr[4];
				craftNo = arr[5];
				aimoutdiameter = arr[6];
				aimwallthick = arr[7];
				gradecode = arr[8];
				// aimoutdiameter= arr[6];
				// aimoutdiameter= arr[6];
			} else if (processCode.equals("E")) {
				exeStatus = arr[12];
				isPlanOk = arr[13];
				isRepairPln = arr[14];
				if (isPlanOk.equals("1") || isRepairPln.equals("1")) {
					zyBatchId = arr[10];
					Object[] param = new Object[] { zyBatchId, arr[0], arr[1] };
					paramList.add(param);
					num++;
				} else {
					// 1.形成初始生产批次号
					if (i == 0) {
						partTime = planTimeB.substring(0, 4)
								+ planTimeB.substring(5, 7);
						zyBatchId = plineCode + partTime
								+ String.format("%04d", num);
						Object[] param = new Object[] { zyBatchId, arr[0],
								arr[1] };
						paramList.add(param);

					} else {
						String partTime1 = planTimeB.substring(0, 4)
								+ planTimeB.substring(5, 7);
						// 同年同月下
						if (partTime1.equals(partTime)) {
							// 相同投入、产出物料、工艺文件号
							if (arr[3].equals(inMaterialNo)
									&& arr[4].equals(outMaterialNo)
									&& arr[5].equals(craftNo)) {
								Object[] param = new Object[] { zyBatchId,
										arr[0], arr[1] };
								paramList.add(param);
							} else {
								num++;
								zyBatchId = plineCode + partTime1
										+ String.format("%04d", num);
								Object[] param = new Object[] { zyBatchId,
										arr[0], arr[1] };
								paramList.add(param);
							}
						} else {
							// 不是同年同月下，则重新从1 开始
							num = 1;
							zyBatchId = plineCode + partTime1
									+ String.format("%04d", num);
							partTime = partTime1;
							Object[] param = new Object[] { zyBatchId, arr[0],
									arr[1] };
							paramList.add(param);
						}

					}
					// 最后赋值
					inMaterialNo = arr[3];
					outMaterialNo = arr[4];
					craftNo = arr[5];
				}

			} else {
				exeStatus = arr[12];
				isPlanOk = arr[13];
				isRepairPln = arr[14];
				if (isPlanOk.equals("1") || isRepairPln.equals("1")) {
					zyBatchId = arr[10];
					Object[] param = new Object[] { zyBatchId, arr[0], arr[1] };
					paramList.add(param);
					// num++;
				} else {
					String partTime1 = planTimeB.substring(0, 4)
							+ planTimeB.substring(5, 7);
					// 同年同月下
					if (partTime1.equals(partTime)) {
						if (zyBatchId.equals("") && num == 1) {
							zyBatchId = zyBatchIda;
						} else {
							zyBatchId = plineCode + partTime1
									+ String.format("%04d", num);
						}
						if (zyBatchIfId != null && zyBatchIfId.size() > 0) {
							do {
								if (zyBatchIfId.contains(zyBatchId)) {
									num++;
									zyBatchId = plineCode + partTime1
											+ String.format("%04d", num);
								}
							} while (zyBatchIfId.contains(zyBatchId) == true);

						}

						Object[] param = new Object[] { zyBatchId, arr[0],
								arr[1] };
						paramList.add(param);
						num++;
						// }
					} else {
						String partTime2 = planTimeB.substring(0, 4)
								+ planTimeB.substring(5, 7);
						String sql = "";
						// 查询生产完成，关闭，生产中 年月最大的轧批号
						if (processCode.equals("F")) {
							sql = "SELECT MAX(T.ZY_BATCH_ID) ZY_BATCH_ID  FROM PLN_ORDER_RCL_S T WHERE T.EXE_STATUS IN ('1', '2', '3')  AND T.PLINE_CODE = ?  AND T.ZY_BATCH_ID LIKE '%' || ? || '%'";
						} else if (processCode.equals("G")) {
							sql = "SELECT MAX(T.ZY_BATCH_ID) ZY_BATCH_ID  FROM PLN_ORDER_JGX_S T WHERE T.EXE_STATUS IN ('1', '2', '3')  AND T.PLINE_CODE = ?  AND T.ZY_BATCH_ID LIKE '%' || ? || '%'";
						}
						PreparedStatement ps = con.prepareStatement(sql);
						ps.setObject(1, plineCode);
						ps.setObject(2, plineCode + partTime2);
						ResultSet rs = ps.executeQuery();
						if (rs.next()) {
							zyBatchIda = rs.getString("ZY_BATCH_ID");
						}
						rs.close();
						ps.close();
						if (zyBatchIda != null) {
							if (!zyBatchIda.equals("")) {
								num = Integer.parseInt(zyBatchIda.substring(
										zyBatchIda.length() - 4,
										zyBatchIda.length())) + 1;
							} else {
								// 不是同年同月下，则重新从1 开始
								num = 1;
							}
						} else {
							// 不是同年同月下，则重新从1 开始
							num = 1;
						}
						zyBatchId = plineCode + partTime1
								+ String.format("%04d", num);
						if (zyBatchIfId != null && zyBatchIfId.size() > 0) {
							do {
								if (zyBatchIfId.contains(zyBatchId)) {
									num++;
									zyBatchId = plineCode + partTime1
											+ String.format("%04d", num);
								}
							} while (zyBatchIfId.contains(zyBatchId) == true);
						}

						partTime = partTime1;
						Object[] param = new Object[] { zyBatchId, arr[0],
								arr[1] };
						paramList.add(param);
						num++;
					}
					// 最后赋值
					inMaterialNo = arr[3];
					outMaterialNo = arr[4];
					craftNo = arr[5];
				}
			}
		}
		return paramList;
	}

	/**
	 * 比较是否有重复轧批号
	 * 
	 * @param zyBatchIfId
	 * @param zyBatchId
	 * @param num
	 * @param plinE
	 * @param partTime1
	 * @return
	 */
	public static String[] sumZg(List<String> zyBatchIfId, String zyBatchId,
			int num, String plinE, String partTime1) {
		String[] arr = new String[2];
		String zyBatchIda = zyBatchId;
		if (zyBatchIfId.contains(zyBatchId)) {
			num++;
			zyBatchIda = plinE + partTime1 + String.format("%03d", num);
			sumZg(zyBatchIfId, zyBatchIda, num, plinE, partTime1);
		}

		arr[0] = zyBatchIda;
		arr[1] = String.valueOf(num);
		return arr;

	}

	/**
	 * 递归计算
	 * 
	 * @param zyBatchIfId
	 * @param zyBatchId
	 * @param num
	 * @param plinE
	 * @param partTime1
	 * @return
	 */
	public static String[] sum(List<String> zyBatchIfId, String zyBatchId,
			int num, String plinE, String partTime1) {
		String[] arr = new String[2];
		for (int j = 0; j < zyBatchIfId.size(); j++) {
			if (zyBatchId.equals(zyBatchIfId.get(j))) {
				num++;
				zyBatchId = plinE + partTime1 + String.format("%03d", num);
				sum(zyBatchIfId, zyBatchId, num, plinE, partTime1);
			}

		}
		arr[0] = zyBatchId;
		arr[1] = String.valueOf(num);
		return arr;

	}

	/**
	 * 排产下发
	 * 
	 * @param con
	 * @param jsonList
	 * @param processCode
	 * @param userName
	 */
	public String stoveIssued(Connection con, List<String> jsonList,
			String processCode, String userName, String userTime)
			throws SQLException, ParseException {
		PreparedStatement ps = null;
		ResultSet rs = null;
		if (processCode.equals("E")) {
			List<PlnOrderDbkSEntity> entityList = PlnHelper.jsonsToEntityList(
					PlnOrderDbkSEntity.class, jsonList);
			for (PlnOrderDbkSEntity entity1 : entityList) {
				PlnOrderDbkSEntity entity = PlnHelper.getEntityData(
						con,
						new String[] { entity1.getProPlanId(),
								entity1.getGxPlanNo() },
						"ProducHelperBean.getPlanOrderE",
						"and t.pro_plan_id=? and t.gx_plan_no=?",
						PlnOrderDbkSEntity.class);
				if (entity == null) {
					return "数据已发生变化,请刷新数据!";
				}
				if (entity.getIsRepairPln().equals("1")) {
					// 下发排产行
					PlnHelper
							.deleteOrUpdate(con,
									"ProducHelperBean.stoveIssuedE",
									new Object[] { "1", "", "", userTime,
											userName, entity.getProPlanId(),
											entity.getGxPlanNo() });
					continue;
				} else {
					if (!entity.getIsPlanOk().equals("1")) {
						return "订单编号(" + entity.getProPlanId() + ")/ 排产序号("
								+ entity.getGxPlanNo() + ") 未确认!";
					}
					String gowhereName = "";
					String gowhereCode = "";
					String ifProduct = "0";
					String gowWhere = corePlanFurnProM.getPlineCodeGroup(con,
							entity.getPlineCode(), entity.getProPlanId(),
							entity.getGxPlanNo(), "E");
					if (gowWhere != null) {
						// 查询去向
						String sqlGroup = "SELECT T.STORAGE_NO,T.STORAGE_NAME FROM COM_BASE_PLINE_R_GROUP T WHERE T.PLINE_CODE_M=? AND T.PLINE_NAME_C=?";
						ps = con.prepareStatement(sqlGroup);
						ps.setObject(1, entity.getPlineCode());
						ps.setObject(2, gowWhere);
						rs = ps.executeQuery();
						if (rs.next()) {
							gowhereName = rs.getString("STORAGE_NAME");
							gowhereCode = rs.getString("STORAGE_NO");
						}
						rs.close();
						ps.close();
					}
					int counnum = StoveHelper.getQueryStation(con,
							entity.getProPlanId(), entity.getGxPlanNo(), "E");
					if (counnum > 0) {
						ifProduct = "1";
					}

					// 下发排产行
					PlnHelper
							.deleteOrUpdate(
									con,
									"ProducHelperBean.stoveIssuedE",
									new Object[] { "1", userTime, userName,
											entity.getProPlanId(),
											entity.getGxPlanNo() });
					List<String> juList = new ArrayList<String>();
					String heatPlanNo = "";
					int countGz = 0;
					String gradenameM = "";
					// 查询订单对应炉计划状态
					String sqlDbk = "SELECT T.GRADENAME,T.PLANSTATUS,T.HEAT_PLAN_NO,T.FEED_HEAT_NO,T.JUDGE_STOVE_NO,T.PLINE_CODE FROM PLN_ZY_DBK_M T WHERE T.PRO_PLAN_ID=? AND T.GX_PLAN_NO=?";
					PreparedStatement ps1 = con.prepareStatement(sqlDbk);
					ps1.setObject(1, entity.getProPlanId());
					ps1.setObject(2, entity.getGxPlanNo());
					ResultSet rs1 = ps1.executeQuery();
					while (rs1.next()) {
						if (!rs1.getString("PLANSTATUS").equals("00")) {
							continue;
						}
						heatPlanNo = rs1.getString("HEAT_PLAN_NO");
						String feedHeatNo = rs1.getString("FEED_HEAT_NO");
						String judgeStoveNo = rs1.getString("JUDGE_STOVE_NO");
						String plineCode = rs1.getString("PLINE_CODE");
						//暂停使用，现在无天淮内倒本部的情况
						/*if(feedHeatNo.length() > 6 && judgeStoveNo == null)
						{
							judgeStoveNo = StoveHelper.queryMaxJudgeNoWg(con);
							PlnZyDbkMEntity plnEntity = new PlnZyDbkMEntity();
							plnEntity.setHeatPlanNo(heatPlanNo);
							plnEntity.setJudgeStoveNo(judgeStoveNo);
							String updateDbkSql  = CoreXmlSqlParsersFactory.getSql("FrmPlanStoveE.updateDbkJudgeStoveNo");
							updateDbkSql = EntityTool.fillSqlByEntity(updateDbkSql,plnEntity);
							ps = con.prepareStatement(updateDbkSql);
							ps.executeUpdate();
							ps.close();
						}else
						{
							if (judgeStoveNo == null || judgeStoveNo.equals("")) {
								return "镦拔扩订单(" + entity.getProPlanId() + "/"
										+ entity.getGxPlanNo() + ")判定炉号为空,不能下发!";
							}
						}*/
						
						if (judgeStoveNo == null || judgeStoveNo.equals("")) {
							return "镦拔扩订单(" + entity.getProPlanId() + "/"
									+ entity.getGxPlanNo() + ")判定炉号为空,不能下发!";
						}

						// 判断上料炉号是否重复下发
						String queryMjud = CoreXmlSqlParsersFactory
								.getSql("FrmPlanStoveE.QueryPlnZYStatus");
						ps = con.prepareStatement(queryMjud);
						ps.setObject(1, judgeStoveNo);
						ps.setObject(2, entity.getProPlanId());
						ps.setObject(3, entity.getGxPlanNo());
						rs = ps.executeQuery();
						if (rs.next()) {
							if (!rs.getString("PLANSTATUS").equals("00")) {
								return "判定炉号(" + judgeStoveNo + ")在镦拔扩订单("
										+ rs.getString("PRO_PLAN_ID")
										+ ")下已下发,不能重复下发,请修改判定炉号!";
							}
						}
						rs.close();
						ps.close();
						if (gradenameM.equals("")) {
							gradenameM = rs1.getString("GRADENAME");
						}
						if (!gradenameM.equals(rs1.getString("GRADENAME"))) {
							countGz++;
						}
						if (countGz > 0) {
							return "镦拔扩订单(" + entity.getProPlanId() + "/"
									+ entity.getGxPlanNo() + ")对应上料炉号("
									+ feedHeatNo + ")钢种不同,请先拆分镦拔扩订单!";
						}

						if (entity.getZyBatchId().equals("")) {
							return "生产批次不能为空,请确认!";
						}
						// 下发实际炉计划
						PlnHelper.deleteOrUpdate(
								con,
								"ProducHelperBean.stoveIssuedEM",
								new Object[] { "10", gowhereCode, gowhereName,
										userName, userTime,
										entity.getZyBatchId(),
										entity.getCraftFileNo(),
										entity.getCraftFileMan(),
										entity.getCraftSeq(), ifProduct,
										heatPlanNo });
						PlnHelper.deleteOrUpdate(con,
								"ProducHelperBean.stoveIssuedEC", new Object[] {
										entity.getZyBatchId(), heatPlanNo });
						// 新增下工序虚拟炉计划
						String messeGx = PlanFurnProduction.addPlnFurnRcl(
								entity.getProPlanId(), entity.getGxPlanNo(),
								userName, userTime, heatPlanNo,
								entity.getPlnDivideId(), con);
						if (!messeGx.equals("")) {
							return messeGx;
						}
					}
					rs1.close();
					ps1.close();

					QuantiEntity qEntity = ProducHelperBean.getQuantity(entity,
							processCode);
					// 逻辑
					/**
					 * 如果(待投入重量+加投重量)/排产重量*最低量<虚拟挂料量,则不拆分排产行,直接 下发
					 */
					if ((qEntity.getInWeightS() + qEntity.getAddWtIn())
							/ qEntity.getWeigthS() * qEntity.getMinWgt() > qEntity
								.getBachedWt()) {
						// 1.1 下发原始记录的待投入重量1 =虚拟挂料量 待投入支1=虚拟挂料支
						// 排产重量1=虚拟挂料量*排产重量/加投重量+待投入重量 排产支数1=排产重量1/单坯重量*长度/1000
						double aimLength = Double.parseDouble(entity
								.getAimlength());// 目标长度
						double inWeightS1 = qEntity.getBachedWt();
						int inNumS1 = qEntity.getBatchedNum();
						double weigthS1 = qEntity.getBachedWt()
								* qEntity.getWeigthS()
								/ (qEntity.getAddWtIn() + qEntity
										.getInWeightS());
						double singleWgt = StoveHelper.caculatePipeSimgleWgt(
								entity.getAimoutdiameter(),
								entity.getAimwallthick());
						int numS1 = (int) Math.ceil(weigthS1
								/ (singleWgt * aimLength / 1000));
						double weigthSMin = qEntity.getBachedWt()
								* qEntity.getWeigthSMin()
								/ (qEntity.getAddWtIn() + qEntity
										.getInWeightS());
						// PlnHelper.deleteOrUpdate(con,
						// "ProducHelperBean.updateStoveIssuedNum",
						// new Object[] { numS1, weigthS1, inNumS1,
						// inWeightS1,weigthSMin, entity.getProPlanId(),
						// entity.getGxPlanNo() });
						// 1.2新增排产行
						// 待投入重量2=待投入重量-虚拟挂料量； 待投入支=待投入支-虚拟挂料支
						// 排产重量 2=排产重量-排产重量1；排产支数1=排产重量2/单坯重量/长度/1000
						double inWeightS2 = qEntity.getInWeightS()
								- qEntity.getBachedWt();
						int inNumS2 = qEntity.getInNumS()
								- qEntity.getBatchedNum();
						double weigthS2 = inWeightS2
								* qEntity.getWeigthS()
								/ (qEntity.getAddWtIn() + qEntity
										.getInWeightS());
						int numS2 = (int) Math.ceil(weigthS2
								/ (singleWgt * aimLength / 1000));
						entity.setInWeightS(String.valueOf(inWeightS2));
						entity.setInNumS(String.valueOf(inNumS2));
						entity.setWeigthS(String.valueOf(weigthS2));
						entity.setNumS(String.valueOf(numS2));
						entity.setAddNumIn("0");
						entity.setAddWtIn("0");
						entity.setBatchedNum("0");
						entity.setBatchedWt("0");
						entity.setRealBatchNum("0");
						entity.setRealBatchWt("0");
						entity.setMatchNumIn("0");
						entity.setMatchWtIn("0");
						entity.setWeigthSMin(String.valueOf(qEntity
								.getWeigthSMin() - weigthSMin));
						ProducHelperBean helperBean = new ProducHelperBean();
						double[] capacity = helperBean.getPlineCapacity(con,
								entity.getInwlId(), entity.getOutwlId(),
								entity.getPlineCode(), processCode);
						// 排产序号
						String gxPlanNo = helperBean.getMaxGxPlanNo(con,
								entity.getProPlanId(), processCode);
						// 生产顺序
						int gxProSeq = Integer.parseInt(entity.getGxProSeq()) + 1;
						// int gxProSeq = helperBean.getMaxGxProSeq(con, entity
						// .getPlineCode(), processCode, entity
						// .getProMonth());
						String planTimeB = helperBean.getMaxPlanTimeE(con,
								entity.getPlineCode(), processCode,
								entity.getProMonth(), gxProSeq);
						TimeEntity TimeEntiy = helperBean.calculateTime(numS2,
								capacity[0], planTimeB);
						// 计划结束时间
						String planTimeE = TimeEntiy.getEndTime();
						String planUserTime = TimeEntiy.getUserTime();
						entity.setPlanTimeB(planTimeB);
						entity.setPlanTimeE(planTimeE);
						entity.setExeStatus("0");
						entity.setIsPlanOk("0");
						entity.setPlanUsetime(planUserTime);
						entity.setGxPlanNo(gxPlanNo);
						entity.setStoveIssuedMan("");
						entity.setLastUndownMan("");
						entity.setIssuedMan("");
						entity.setGxProSeq(String.valueOf(gxProSeq));
						// PlnHelper.addEntityData(con,
						// "ProducHelperBean.addPlanOrderE", entity);
					}
				}
				String messCrm = ProducCrm.insertCrmE(con, entity, userName,userTime);
			}
		}
		return "";
	}

	/**
	 * 取消下发
	 * 
	 * @param con
	 * @param jsonList
	 * @param processCode
	 * @param userName
	 * @return
	 * @throws SQLException
	 */
	public String cancelStoveIssued(Connection con, List<String> jsonList,
			String processCode, String userName, String userTime)
			throws SQLException {
		PreparedStatement ps = null;
		ResultSet rs = null;
		if (processCode.equals("E")) {
			List<PlnOrderDbkSEntity> entityList = PlnHelper.jsonsToEntityList(
					PlnOrderDbkSEntity.class, jsonList);
			for (PlnOrderDbkSEntity entity1 : entityList) {
				PlnOrderDbkSEntity entity = PlnHelper.getEntityData(
						con,
						new String[] { entity1.getProPlanId(),
								entity1.getGxPlanNo() },
						"ProducHelperBean.getPlanOrderE",
						"and t.pro_plan_id=? and t.gx_plan_no=?",
						PlnOrderDbkSEntity.class);
				if (entity == null) {
					return "数据已发生变化,请刷新数据!";
				}
				if (!entity.getIfStoveIssued().equals("1")) {
					return "订单编号 " + entity.getProPlanId() + " 未下发!";
				}
				// int count = Integer.parseInt(PlnHelper.getParam(con,
				// "ProducHelperBean.getCountBySeqCancel", new String[] {
				// entity.getGxProSeq(), entity.getPlineCode() },
				// "COUNT"));
				// if (count > 0) {
				// return "生产顺序" + entity.getGxProSeq() + " 之后有订单未取消下发!";
				// }
				String heatPlanNo = "";
				// 查询订单对应炉计划状态
				String sqlDbk = "SELECT T.PLANSTATUS,T.HEAT_PLAN_NO FROM PLN_ZY_DBK_M T WHERE T.PRO_PLAN_ID=? AND T.GX_PLAN_NO=?";
				ps = con.prepareStatement(sqlDbk);
				ps.setObject(1, entity.getProPlanId());
				ps.setObject(2, entity.getGxPlanNo());
				rs = ps.executeQuery();
				while (rs.next()) {
					if (rs.getInt("PLANSTATUS") >= 20) {
						return "订单编号" + entity.getProPlanId()
								+ "下的炉计划不是下发状态,不能撤销!";
					}
					heatPlanNo = rs.getString("HEAT_PLAN_NO");
					// 取消下发实际炉计划
					PlnHelper.deleteOrUpdate(
							con,
							"ProducHelperBean.stoveIssuedEM",
							new Object[] { "00", "", "", userName, userTime,
									"", entity.getCraftFileNo(),
									entity.getCraftFileMan(),
									entity.getCraftSeq(), "0", heatPlanNo });
					PlnHelper.deleteOrUpdate(con,
							"ProducHelperBean.stoveIssuedEC", new Object[] {
									"", heatPlanNo });
					// 撤销下工序虚拟炉计划
					String messeGx = PlanFurnProduction.deletePlnFurnRcl(
							entity.getProPlanId(), entity.getGxPlanNo(),
							userName, userTime, heatPlanNo,
							entity.getPlnDivideId(), con);
					if (!messeGx.equals("")) {
						return messeGx;
					}
				}
				rs.close();
				ps.close();
				// 取消下发排产行
				PlnHelper.deleteOrUpdate(
						con,
						"ProducHelperBean.stoveIssuedE",
						new Object[] { "0", userTime, userName,
								entity.getProPlanId(), entity.getGxPlanNo() });


				String messCrm = ProducCrm.insertCrmECancel(con, entity,userName,userTime);
			}
		}
		return "";
	}

	/**
	 * 确认(修改前工序的排产量)
	 * 
	 * @param con
	 * @param proEntity
	 * @param processCode
	 * @throws SQLException
	 */
	public void confirm(Connection con, ProducEntity proEntity,
			String processCode) throws SQLException {
		if (processCode.equals("E")) {
			List<PlnOrderDbkSEntity> dbkEntityList = PlnHelper.getEntityDatas(
					con, new String[] { proEntity.getProPlanId() },
					"ProducHelperBean.getPlanOrderE", "and t.pro_plan_id=?",
					PlnOrderDbkSEntity.class);
			if (dbkEntityList == null || dbkEntityList.size() == 0) {
				return;
			}
			String preGx = "";// 前工序
			String preProPlanId = "";// 前工序订单编号
			double wgt = 0;// 镦拔扩重量(E待投入重量+E加投重量-E利库量)
			for (PlnOrderDbkSEntity dbkEntity : dbkEntityList) {
				double inWeigthS = 0;
				if (!dbkEntity.getInWeightS().equals("")) {
					inWeigthS = Double.parseDouble(dbkEntity.getInWeightS());
				}
				double addWgt = 0;
				if (!dbkEntity.getAddWtIn().equals("")) {
					addWgt = Double.parseDouble(dbkEntity.getAddWtIn());
				}
				double matchWgt = 0;
				if (!dbkEntity.getMatchWtIn().equals("")) {
					matchWgt = Double.parseDouble(dbkEntity.getMatchWtIn());
				}
				wgt = wgt + inWeigthS + addWgt - matchWgt;
				preGx = dbkEntity.getPreviousGx();
				preProPlanId = dbkEntity.getPrevGxplanId();
			}
			if (preGx.equals("轧制")) {

			}
		}
	}

	public static void updatePreGxD(Connection con, String preProPlanId,
			double wgt) throws SQLException {
		List<PlnOrderZgSEntity> zgList = PlnHelper.getEntityDatas(con,
				new String[] {}, "ProducHelperBean.getPlanOrderD",
				"and t.pro_plan_id=? order by to_number(t.gx_pro_seq)",
				PlnOrderZgSEntity.class);
		if (zgList == null || zgList.size() == 0) {
			return;
		}
	}

	/**
	 * 设置上料行
	 * 
	 * @param con
	 * @param jsonStr
	 * @param processCode
	 * @throws SQLException
	 */
	public String setOnloadLine(Connection con, String jsonStr,
			String processCode) throws SQLException {
		if (processCode.equals("E")) {
			PlnOrderDbkSEntity entity1 = PlnHelper.jsonToEntity(
					PlnOrderDbkSEntity.class, jsonStr);
			PlnOrderDbkSEntity entity = PlnHelper.getEntityData(
					con,
					new String[] { entity1.getProPlanId(),
							entity1.getGxPlanNo() },
					"ProducHelperBean.getPlanOrderE",
					"and t.pro_plan_id=? and t.gx_plan_no=?",
					PlnOrderDbkSEntity.class);
			if (entity == null) {
				return "数据异常,请刷新数据!";
			}
			if (!entity.getIfStoveIssued().equals("1")) {
				return "订单编号( " + entity.getProPlanId() + ")/排产序号( "
						+ entity.getGxPlanNo() + ") 未下发!";
			}
			PlnHelper.deleteOrUpdate(con, "ProducHelperBean.setOnloadLineA",
					new String[] { entity.getPlineCode() });
			PlnHelper.deleteOrUpdate(
					con,
					"ProducHelperBean.setOnloadLineB",
					new String[] { "1", entity.getProPlanId(),
							entity.getGxPlanNo() });
		}

		return "";
	}

	/**
	 * 虚拟炉计划拆分
	 * 
	 * @param con
	 * @param jsonList
	 * @param processCode
	 * @return
	 * @throws SQLException
	 * @throws ParseException
	 */
	public String stoveSpit(Connection con, ArrayList<String> jsonList,
			String userName, String processCode) throws SQLException,
			ParseException {
		// if (processCode.equals("E")) {
		// List<PlnZyDbkReadyEntity> entityList = PlnHelper.jsonsToEntityList(
		// PlnZyDbkReadyEntity.class, jsonList);
		// String proPlanId = entityList.get(0).getProPlanId();
		// String gxPlanNo = entityList.get(0).getGxPlanNo();
		// List<PlnZyDbkReadyEntity> entityList1 = PlnHelper.getEntityDatas(
		// con, new String[] { proPlanId, gxPlanNo },
		// "ProducHelperBean.getDbkReadyById",
		// PlnZyDbkReadyEntity.class);
		// if (entityList.size() >= entityList1.size()) {
		// return "数据发生变化,请刷新数据!";
		// }
		// // 排产行
		// PlnOrderDbkSEntity dbkentity = PlnHelper.getEntityData(con,
		// new String[] { proPlanId, gxPlanNo },
		// "ProducHelperBean.getPlanOrderE",
		// "and t.pro_plan_id=? and t.gx_plan_no=?",
		// PlnOrderDbkSEntity.class);
		// if (dbkentity == null) {
		// return "数据异常,请刷新数据!";
		// }
		// // 量
		// QuantiEntity quantity = ProducHelperBean.getQuantity(dbkentity,
		// processCode);
		// int matchNumInSum = 0;// 利库支
		// double matchWtInSum = 0;// 利库量
		// int batchedNumSum = 0;// 虚拟挂料支
		// double bachedWtSum = 0;// 虚拟挂料重量
		// int realNumSum = 0;// 实际挂料支
		// double realWgtSum = 0;// 实际挂料吨
		// // 拆分虚拟炉计划
		// for (PlnZyDbkReadyEntity entity : entityList) {
		// int batchedNum = Integer.parseInt(entity.getAllotNum());// 虚拟挂料支
		// double bachedWt = Double.parseDouble(entity.getAllotWt());// 虚拟挂料重量
		// if (entity.getIfMatchOdd().equals("Y")) {
		// matchWtInSum += bachedWt;
		// matchNumInSum += batchedNum;
		// }
		// if (!entity.getRealAllotNum().equals("")) {
		// realNumSum += Integer.parseInt(entity.getRealAllotNum());
		// }
		// if (!entity.getRealAllotWt().equals("")) {
		// realWgtSum += Double.parseDouble(entity.getRealAllotWt());
		// }
		// batchedNumSum += batchedNum;
		// bachedWtSum += bachedWt;
		// }
		// // 排产序号
		// ProducHelperBean helperBean = new ProducHelperBean();
		// // 3.1计划开始时间(这个时间应该从数据库里查)
		// double[] capacity = helperBean.getPlineCapacity(con, dbkentity
		// .getInwlId(), dbkentity.getOutwlId(), dbkentity
		// .getPlineCode(), processCode);
		// // 比例
		// double ratio = bachedWtSum / quantity.getBachedWt();
		// /**
		// * 1.原排产行(待投入重量、排产重量、加投重量都按比例去拆分) 利库量按是否利库虚拟炉计划加
		// */
		// double weigthS1 = quantity.getWeigthS() * (1 - ratio);
		// int numS1 = (int) Math.ceil(quantity.getNumS() * (1 - ratio));
		// double inWeigthS1 = quantity.getInWeightS() * (1 - ratio);
		// int inNumS1 = (int) Math.ceil(quantity.getInNumS() * (1 - ratio));
		// double addWtIn1 = quantity.getAddWtIn() * (1 - ratio);
		// int addNumIn1 = (int) Math.ceil(quantity.getAddNumIn()
		// * (1 - ratio));
		// dbkentity.setWeigthS(String.valueOf(weigthS1));
		// dbkentity.setNumS(String.valueOf(numS1));
		// dbkentity.setInWeightS(String.valueOf(inWeigthS1));
		// dbkentity.setInNumS(String.valueOf(inNumS1));
		// dbkentity.setAddWtIn(String.valueOf(addWtIn1));
		// dbkentity.setAddNumIn(String.valueOf(addNumIn1));
		// dbkentity.setBatchedNum(String.valueOf(quantity.getBatchedNum()
		// - batchedNumSum));
		// dbkentity.setBatchedWt(String.valueOf(quantity.getBachedWt()
		// - bachedWtSum));
		// dbkentity.setRealBatchNum(String.valueOf(quantity.getRealNum()
		// - realNumSum));
		// dbkentity.setRealBatchWt(String.valueOf(quantity.getRealWgt()
		// - realWgtSum));
		// dbkentity.setMatchNumIn(String.valueOf(quantity.getMatchNum()
		// - matchNumInSum));
		// dbkentity.setMatchWtIn(String.valueOf(quantity.getMatchWgt()
		// - matchWtInSum));
		// TimeEntity TimeEntiy1 = helperBean.calculateTime(numS1,
		// capacity[0], dbkentity.getPlanTimeB());
		// // 空出一个序号
		// helperBean.seqIncrease(con, dbkentity.getPlineCode(), Integer
		// .parseInt(dbkentity.getGxProSeq()), -1, 1, processCode);
		// // 计划结束时间
		// String planTimeE1 = TimeEntiy1.getEndTime();
		// String planUserTime1 = TimeEntiy1.getUserTime();
		// dbkentity.setPlanTimeB(dbkentity.getPlanTimeB());
		// dbkentity.setPlanTimeE(planTimeE1);
		// dbkentity.setPlanUsetime(planUserTime1);
		// // 修改原记录
		// PlnHelper.deleteOrUpdateByEntity(con,
		// "ProducHelperBean.updatePlanOrderE", dbkentity);
		//
		// /**
		// * 2.新排产行(生产序号为原排产行序号加1)
		// */
		// double weigthS2 = quantity.getWeigthS() - weigthS1;
		// int numS2 = quantity.getNumS() - numS1;
		// double inWeigthS2 = quantity.getInWeightS() - inWeigthS1;
		// int inNumS2 = quantity.getInNumS() - inNumS1;
		// double addWtIn2 = quantity.getAddWtIn() - addWtIn1;
		// int addNumIn2 = quantity.getAddNumIn() - addNumIn1;
		// String planTimeB2 = dbkentity.getPlanTimeE();// 时间为序号的结束时间
		// TimeEntity TimeEntiy = helperBean.calculateTime(numS2, capacity[0],
		// planTimeB2);
		// // 计划结束时间
		// String planTimeE2 = TimeEntiy.getEndTime();
		// String planUserTime2 = TimeEntiy.getUserTime();
		// // 排产序号
		// String gxPlanNo2 = helperBean.getMaxGxPlanNo(con, dbkentity
		// .getProPlanId(), processCode);
		// // 生产顺序
		// int gxProSeq2 = Integer.parseInt(dbkentity.getGxProSeq()) + 1;
		// dbkentity.setWeigthS(String.valueOf(weigthS2));
		// dbkentity.setNumS(String.valueOf(numS2));
		// dbkentity.setInWeightS(String.valueOf(inWeigthS2));
		// dbkentity.setInNumS(String.valueOf(inNumS2));
		// dbkentity.setAddWtIn(String.valueOf(addWtIn2));
		// dbkentity.setAddNumIn(String.valueOf(addNumIn2));
		// dbkentity.setBatchedNum(String.valueOf(batchedNumSum));
		// dbkentity.setBatchedWt(String.valueOf(bachedWtSum));
		// dbkentity.setRealBatchNum(String.valueOf(realNumSum));
		// dbkentity.setRealBatchWt(String.valueOf(realWgtSum));
		// dbkentity.setMatchNumIn(String.valueOf(matchNumInSum));
		// dbkentity.setMatchWtIn(String.valueOf(matchWtInSum));
		// dbkentity.setPlanTimeB(planTimeB2);
		// dbkentity.setPlanTimeE(planTimeE2);
		// dbkentity.setPlanUsetime(planUserTime2);
		// dbkentity.setGxPlanNo(gxPlanNo2);
		// dbkentity.setGxProSeq(String.valueOf(gxProSeq2));
		// dbkentity.setExeStatus("0");
		// dbkentity.setIfStoveIssued("1");
		// dbkentity.setIsPlanOk("1");
		// PlnHelper.addEntityData(con, "ProducHelperBean.addPlanOrderE",
		// dbkentity);
		// // 调整时间
		// helperBean.timeIncrease(con, gxProSeq2, dbkentity.getPlineCode(),
		// planTimeE2, processCode);
		// // 修改炉计划的所属排产行
		// for (PlnZyDbkReadyEntity entity : entityList) {
		// // 修改虚拟炉计划
		// PlnHelper
		// .deleteOrUpdate(con,
		// "ProducHelperBean.updatePlanEDById",
		// new String[] { dbkentity.getGxPlanNo(),
		// entity.getProPlanId(),
		// entity.getGxPlanNo(),
		// entity.getReadyPlanNo() });
		// // 查询实际炉计划
		// List<PlnZyDbkMEntity> mEntityList = PlnHelper
		// .getEntityDatas(con, new String[] {
		// entity.getProPlanId(), entity.getGxPlanNo(),
		// entity.getReadyPlanNo() },
		// "ProducHelperBean.getDbkMById",
		// PlnZyDbkMEntity.class);
		// if (mEntityList != null && mEntityList.size() > 0) {
		// PlnHelper.deleteOrUpdate(con,
		// "ProducHelperBean.updatePlanERById", new String[] {
		// dbkentity.getGxPlanNo(),
		// entity.getProPlanId(),
		// entity.getGxPlanNo(),
		// entity.getReadyPlanNo() });
		// for (PlnZyDbkMEntity mEntity : mEntityList) {
		// // 修改库存数据
		// PlnHelper.deleteOrUpdate(con,
		// "ProducHelperBean.updateMatMData",
		// new String[] { dbkentity.getGxPlanNo(),
		// mEntity.getHeatPlanNo(),
		// entity.getProPlanId(),
		// entity.getGxPlanNo() });
		// }
		// }
		//
		// }
		// }
		return "";
	}

	/**
	 * 合并排产行时合并虚拟炉计划和实际炉计划
	 * 
	 * @param con
	 * @param proPlanId
	 * @param gxPlanNo
	 * @param proEntityList
	 * @param processCode
	 * @throws SQLException
	 */
	public void mergePlan(Connection con, String proPlanId, String gxPlanNo,
			List<ProducEntity> proEntityList, String processCode)
			throws SQLException {
		// if (processCode.equals("E")) {
		// for (ProducEntity entity : proEntityList) {
		// if (entity.getProPlanId().equals(proPlanId)
		// && entity.getGxPlanNo().equals(gxPlanNo)) {
		// continue;
		// }
		// List<PlnZyDbkReadyEntity> entityList = PlnHelper
		// .getEntityDatas(con, new String[] {
		// entity.getProPlanId(), entity.getGxPlanNo() },
		// "ProducHelperBean.getDbkReadyById",
		// PlnZyDbkReadyEntity.class);
		// // 1. 如果有虚拟炉计划
		// if (entityList != null && entityList.size() > 0) {
		// for (PlnZyDbkReadyEntity rEntity : entityList) {
		// // 1.1修改虚拟炉计划
		// PlnHelper.deleteOrUpdate(con,
		// "ProducHelperBean.updatePlanEDById",
		// new String[] { gxPlanNo, entity.getProPlanId(),
		// entity.getGxPlanNo(),
		// rEntity.getReadyPlanNo() });
		// // 1.2 查询实际炉计划
		// List<PlnZyDbkMEntity> mEntityList = PlnHelper
		// .getEntityDatas(con, new String[] {
		// entity.getProPlanId(),
		// entity.getGxPlanNo(),
		// rEntity.getReadyPlanNo() },
		// "ProducHelperBean.getDbkMById",
		// PlnZyDbkMEntity.class);
		// // 1.3如果有实际炉计划
		// if (mEntityList != null && mEntityList.size() > 0) {
		// // 1.3.1修改实际炉计划
		// PlnHelper.deleteOrUpdate(con,
		// "ProducHelperBean.updatePlanERById",
		// new String[] { gxPlanNo,
		// entity.getProPlanId(),
		// entity.getGxPlanNo(),
		// rEntity.getReadyPlanNo() });
		// for (PlnZyDbkMEntity mEntity : mEntityList) {
		// // 1.3.3修改库存数据
		// PlnHelper.deleteOrUpdate(con,
		// "ProducHelperBean.updateMatMData",
		// new String[] { gxPlanNo,
		// mEntity.getHeatPlanNo(),
		// entity.getProPlanId(),
		// entity.getGxPlanNo() });
		// }
		// }
		// }
		// }
		//
		// }
		// }

	}

	/**
	 * 根据管坯需求号查询
	 * 
	 * @param <T>
	 * @throws SQLException
	 */
	public static <T> ArrayList<T> getPlnOrderDz(Connection con,
			String proPlanId, String processCode, Class<T> cls)
			throws SQLException {
		String sql = "";
		if (processCode.equals("B")) {
			sql = "SELECT T.* FROM PLN_ORDER_CAST_S T WHERE T.PRO_PLAN_ID=?";
		} else if (processCode.equals("C")) {
			sql = "SELECT T.* FROM PLN_ORDER_DZ_S T WHERE T.PRO_PLAN_ID=?";
		}
		PreparedStatement ps = con.prepareStatement(sql);
		ps.setObject(1, proPlanId);
		ResultSet rs = ps.executeQuery();
		ArrayList<T> t = EntityTool.getEntitysByRs(rs, cls);
		rs.close();
		ps.close();
		return t;
	}

	/**
	 * 后工序订单生产完成驱动前工序订单关闭
	 * 
	 * @param con
	 * @param ordLnDlyPk
	 * @param plnDivideId
	 * @param gpreqId
	 * @param processCode
	 * @throws SQLException
	 */
	public static void setCloseBeforeProcess(Connection con, String ordLnDlyPk,
			String plnDivideId, String gpreqId, String processCode)
			throws SQLException {
		PreparedStatement ps = null;
		ResultSet rs = null;
		PreparedStatement ps1 = null;
		if (processCode.equals("D")) {
			int count = 0;
			// 根据管坯需求号查询轧管订单是否全部生产完成
			String sqlZg = "SELECT MIN(T.EXE_STATUS) EXE_STATUS FROM PLN_ORDER_ZG_S T WHERE T.GPREQ_ID=?";
			ps = con.prepareStatement(sqlZg);
			ps.setObject(1, gpreqId);
			rs = ps.executeQuery();
			if (rs.next()) {
				count = rs.getInt("EXE_STATUS");
			}
			rs.close();
			ps.close();
			ProducHelperBean helperBean = new ProducHelperBean();
			if (gpreqId != null && !gpreqId.equals("")) {
				String updateReqGp = "UPDATE PLN_REQINF_GP T SET T.REQ_DONESTATUS=? WHERE T.GPREQ_ID=?";
				if (count >= 2) {
					// 如果轧管最小状态大于生产中,则关闭前工序订单
					// 修改管坯需求号关闭
					ps = con.prepareStatement(updateReqGp);
					ps.setObject(1, "3");
					ps.setObject(2, gpreqId);
					ps.executeUpdate();
					ps.close();
					// 通过管坯需求号查询锻造订单信息
					List<PlnOrderDzSEntity> orderDz = getPlnOrderDz(con,
							gpreqId, "C", PlnOrderDzSEntity.class);
					if (orderDz.size() > 0) {
						for (PlnOrderDzSEntity entity : orderDz) {
							// 查询锻造订单是否生产中
							String sqlQz = "SELECT T.EXE_STATUS,T.GX_PRO_SEQ,T.PLINE_CODE FROM PLN_ORDER_DZ_S T WHERE T.PRO_PLAN_ID =? AND T.GX_PLAN_NO=?";
							ps = con.prepareStatement(sqlQz);
							ps.setObject(1, entity.getProPlanId());
							ps.setObject(2, entity.getGxPlanNo());
							rs = ps.executeQuery();
							if (rs.next()) {
								if (rs.getString("EXE_STATUS").equals("1")) {
									int gxProSeq = rs.getInt("GX_PRO_SEQ") + 1;
									String updateStatr = "update PLN_ORDER_DZ_S T ";
									updateStatr += CoreXmlSqlParsersFactory
											.getSql("ProducHelperBean.statusChange");
									ps1 = con.prepareStatement(updateStatr);
									ps1.setObject(1, gxProSeq);
									ps1.setObject(2, gxProSeq);
									ps1.setObject(3, gxProSeq);
									ps1.setObject(4, gxProSeq);
									ps1.setObject(5, rs.getString("PLINE_CODE"));
									ps1.executeUpdate();
									ps1.close();
								}
							}
							rs.close();
							ps.close();
							String updateDz = "UPDATE PLN_ORDER_DZ_S T SET T.EXE_STATUS=?,T.GX_PRO_SEQ=? WHERE T.PRO_PLAN_ID=? AND T.GX_PLAN_NO=?";
							// 修改锻造订单关闭
							ps = con.prepareStatement(updateDz);
							ps.setObject(1, "3");
							ps.setObject(2, "-2");
							ps.setObject(3, entity.getProPlanId());
							ps.setObject(4, entity.getGxPlanNo());
							ps.executeUpdate();
							ps.close();
							// 生产顺序调整
							helperBean.seqIncrease(con, entity.getPlineCode(),
									Integer.parseInt(entity.getGxProSeq()), -1,
									-1, "C");
						}
					}
					// 通过管坯需求号查询铸造订单信息
					List<PlnOrderCastSEntity> orderZz = getPlnOrderDz(con,
							gpreqId, "B", PlnOrderCastSEntity.class);
					if (orderZz.size() > 0) {
						for (PlnOrderCastSEntity entity : orderZz) {
							// 查询铸造订单是否生产中
							String sqlQz = "SELECT T.EXE_STATUS,T.GX_PRO_SEQ,T.PLINE_CODE FROM PLN_ORDER_CAST_S T WHERE T.PRO_PLAN_ID =? AND T.GX_PLAN_NO=?";
							ps = con.prepareStatement(sqlQz);
							ps.setObject(1, entity.getProPlanId());
							ps.setObject(2, entity.getGxPlanNo());
							rs = ps.executeQuery();
							if (rs.next()) {
								if (rs.getString("EXE_STATUS").equals("1")) {
									int gxProSeq = rs.getInt("GX_PRO_SEQ") + 1;
									String updateStatr = "update PLN_ORDER_CAST_S T ";
									updateStatr += CoreXmlSqlParsersFactory
											.getSql("ProducHelperBean.statusChange");
									ps1 = con.prepareStatement(updateStatr);
									ps1.setObject(1, gxProSeq);
									ps1.setObject(2, gxProSeq);
									ps1.setObject(3, gxProSeq);
									ps1.setObject(4, gxProSeq);
									ps1.setObject(5, rs.getString("PLINE_CODE"));
									ps1.executeUpdate();
									ps1.close();
								}
							}
							rs.close();
							ps.close();
							// 修改铸造订单关闭
							String updateZz = "UPDATE PLN_ORDER_CAST_S T SET T.EXE_STATUS=?,T.GX_PRO_SEQ=? WHERE T.PRO_PLAN_ID=? AND T.GX_PLAN_NO=?";
							ps = con.prepareStatement(updateZz);
							ps.setObject(1, "3");
							ps.setObject(2, "-2");
							ps.setObject(3, entity.getProPlanId());
							ps.setObject(4, entity.getGxPlanNo());
							ps.executeUpdate();
							ps.close();
							// 生产顺序调整
							helperBean.seqIncrease(con, entity.getPlineCode(),
									Integer.parseInt(entity.getGxProSeq()), -1,
									-1, "B");
						}
					}
				} else {

					// 如果轧管最小状态小于,等于生产中,则前工序订单置完成

					// 修改管坯需求置生产
					ps = con.prepareStatement(updateReqGp);
					ps.setObject(1, "2");
					ps.setObject(2, gpreqId);
					ps.executeUpdate();
					ps.close();
					// 更新锻造订单
					String updateDz = "UPDATE PLN_ORDER_DZ_S T SET T.EXE_STATUS=? WHERE T.PRO_PLAN_ID=? AND T.EXE_STATUS ='3'";
					ps = con.prepareStatement(updateDz);
					ps.setObject(1, "2");
					ps.setObject(2, gpreqId);
					ps.executeUpdate();
					ps.close();
					// 更新铸造订单
					String updateZz = "UPDATE PLN_ORDER_CAST_S T SET T.EXE_STATUS=? WHERE T.PRO_PLAN_ID=? AND T.EXE_STATUS ='3'";
					ps = con.prepareStatement(updateZz);
					ps.setObject(1, "2");
					ps.setObject(2, gpreqId);
					ps.executeUpdate();
					ps.close();
				}
			}
		}

	}

	/**
	 * 设置排产完成
	 * 
	 * @param con
	 * @param jsonStrList
	 * @param userName
	 * @param processCode
	 * @return
	 * @throws Exception
	 */
	public static void setPlanFinish(Connection con,
			ArrayList<String> jsonStrList, String userName, String processCode)
			throws Exception {
		PreparedStatement ps = null;
		ResultSet rs = null;
		PreparedStatement ps1 = null;
		ResultSet rs1 = null;
		String planTimeB = "2016-01-01 00:00:00";
		Date nowTime = new Date();
		SimpleDateFormat sf = new SimpleDateFormat("yyyyMMdd");
		String timeStr = sf.format(nowTime);
		String message = "";
		String memo = "手动设置合同完成  操作人:[" + userName + "] 操作时间:[ " + timeStr
				+ "]";
		ProducHelperBean helperBean = new ProducHelperBean();
		if (processCode.equals("D")) {
			List<PlnOrderZgSEntity> entityList = PlnHelper.jsonsToEntityList(
					PlnOrderZgSEntity.class, jsonStrList);

			int seq = 0;// 最小生产顺序
			String planTimeE = "";
			String plineCode = "";
			for (PlnOrderZgSEntity entity1 : entityList) {
				PlnOrderZgSEntity entity = PlnHelper.getEntityData(
						con,
						new String[] { entity1.getProPlanId(),
								entity1.getGxPlanNo() },
						"ProducHelperBean.getPlanOrderD",
						"and t.pro_plan_id=? and t.gx_plan_no=?",
						PlnOrderZgSEntity.class);
				if (entity == null) {
					message = "数据发生变化,请刷新数据!";
					throw new Exception(message);
				}
				if (entity.getIsRepairPln().equals("1")) {
					throw new Exception("检修计划不能设置完成!");
				}
				int gxProSeq = Integer.parseInt(entity.getGxProSeq());
				if (gxProSeq == 0) {
					throw new Exception("排产订单已经设置完成!");
				}

				if (seq == 0) {
					seq = gxProSeq;
				}
				if (seq >= gxProSeq) {
					seq = gxProSeq;
					planTimeE = entity.getPlanTimeB();
					plineCode = entity.getPlineCode();
				}
				// 查询调整订单
				// String sqlProPlanNo =
				// "SELECT T.PRO_PLAN_ID, T.GX_PLAN_NO, T.EXE_STATUS FROM PLN_ORDER_ZG_S T "
				// +
				// " WHERE T.PLINE_CODE = ? AND T.EXE_STATUS IN ('0', '1') AND TO_NUMBER(T.GX_PRO_SEQ) = TO_NUMBER(?)";
				// ps = con.prepareStatement(sqlProPlanNo);
				// ps.setObject(1, entity.getPlineCode());
				// ps.setObject(2, gxProSeq);
				// rs = ps.executeQuery();
				// while (rs.next()) {
				// // 查询订单向下炉计划是否全部生产中或生产完成
				// String sqlZyStatr =
				// "SELECT DECODE(MIN(T.PLANSTATUS),'','20',MIN(T.PLANSTATUS)) PLANSTATUS FROM PLN_ZY_ZG_M T WHERE T.PRO_PLAN_ID=? AND T.GX_PLAN_NO=?";
				// ps1 = con.prepareStatement(sqlZyStatr);
				// ps1.setObject(1, rs.getString("PRO_PLAN_ID"));
				// ps1.setObject(2, rs.getString("GX_PLAN_NO"));
				// rs1 = ps1.executeQuery();
				// if (rs1.next()) {
				// if (rs1.getInt("PLANSTATUS") < 20) {
				// message = "订单号" + rs.getString("PRO_PLAN_ID") + "/"
				// + rs.getString("GX_PLAN_NO")
				// + "向下炉计划有计划/下发状态,不能状态调整!";
				// throw new Exception(message);
				// }
				// }
				// rs1.close();
				// ps1.close();
				// }
				// rs.close();
				// ps.close();
				entity.setPlanTimeB(planTimeB);
				entity.setPlanTimeE(planTimeB);
				entity.setPlanUsetime("0");
				entity.setGxProSeq("-1");
				entity.setExeStatus("2");
				if (entity.getMemo() != null && !entity.getMemo().equals("")) {
					memo = "," + memo;
				}
				entity.setMemo(entity.getMemo() + memo);
				if (entity.getIfStoveIssued() != null
						&& entity.getIfStoveIssued().equals("")
						|| entity.getIfStoveIssued().equals("0")) {
					entity.setZyBatchId("");
				}

				PlnHelper.deleteOrUpdateByEntity(con,
						"ProducHelperBean.updatePlanOrderDStratFin", entity);
				// 生产顺序调整
				helperBean.seqIncrease(con, entity.getPlineCode(), gxProSeq,
						-1, -1, processCode);
				// 轧管订单生产完成同管坯需求号的铸造订单,锻造订单,管坯需求关闭
				setCloseBeforeProcess(con, entity.getOrdLnDlyPk(),
						entity.getPlnDivideId(), entity.getGpreqId(), "D");
			}
			// 时间调整
			helperBean.timeIncrease(con, seq - 1, plineCode, planTimeE,
					processCode);
		} else if (processCode.equals("E")) {
			List<PlnOrderDbkSEntity> entityList = PlnHelper.jsonsToEntityList(
					PlnOrderDbkSEntity.class, jsonStrList);
			int seq = 0;// 最小生产顺序
			String planTimeE = "";
			String plineCode = "";
			for (PlnOrderDbkSEntity entity1 : entityList) {
				PlnOrderDbkSEntity entity = PlnHelper.getEntityData(
						con,
						new String[] { entity1.getProPlanId(),
								entity1.getGxPlanNo() },
						"ProducHelperBean.getPlanOrderE",
						"and t.pro_plan_id=? and t.gx_plan_no=?",
						PlnOrderDbkSEntity.class);
				if (entity == null) {
					message = "数据发生变化,请刷新数据!";
					throw new Exception(message);
				}
				if (entity.getIsRepairPln().equals("1")) {
					throw new Exception("检修计划不能设置完成!");
				}
				int gxProSeq = Integer.parseInt(entity.getGxProSeq());
				if (gxProSeq == 0) {
					throw new Exception("排产订单已经设置完成!");
				}
				if (seq == 0) {
					seq = gxProSeq;
				}
				if (seq >= gxProSeq) {
					seq = gxProSeq;
					planTimeE = entity.getPlanTimeB();
					plineCode = entity.getPlineCode();
				}
				// 查询调整订单
				String sqlProPlanNo = "SELECT T.PRO_PLAN_ID, T.GX_PLAN_NO, T.EXE_STATUS,T.ORD_LN_DLY_PK,T.PLN_DIVIDE_ID FROM PLN_ORDER_DBK_S T "
						+ " WHERE T.PLINE_CODE = ? AND T.EXE_STATUS IN ('0', '1') AND TO_NUMBER(T.GX_PRO_SEQ) = TO_NUMBER(?)";
				ps = con.prepareStatement(sqlProPlanNo);
				ps.setObject(1, entity.getPlineCode());
				ps.setObject(2, gxProSeq);
				rs = ps.executeQuery();
				while (rs.next()) {
					// 查询上工序是否全部生产完成
					String sqlExeStatus = CoreXmlSqlParsersFactory
							.getSql("ProducHelper.QueryExeStatusDbk");
					ps1 = con.prepareStatement(sqlExeStatus);
					ps1.setObject(1, rs.getString("PRO_PLAN_ID"));
					ps1.setObject(2, rs.getString("GX_PLAN_NO"));
					rs1 = ps1.executeQuery();
					if (rs1.next()) {
						if (rs1.getInt("BEFORE_STATE") < 2) {
							if (rs1.getInt("GX_PRO_SEQ_MAX") <= rs1
									.getInt("GX_PRO_SEQ")
									&& rs1.getInt("EXE_STATUS_DBK") >= 2) {
								message = "订单号" + rs.getString("PRO_PLAN_ID")
										+ "/" + rs.getString("GX_PLAN_NO")
										+ "前工序订单有计划/生产中状态并且本工序订单("
										+ rs.getString("PRO_PLAN_ID")
										+ ")没有计划状态,不能状态调整!";
								throw new Exception(message);
							}
						}
					}
					rs1.close();
					ps1.close();
					// 查询订单向下炉计划是否全部生产中或生产完成
					String sqlZyStatr = "SELECT DECODE(MIN(T.PLANSTATUS),'','20',MIN(T.PLANSTATUS)) PLANSTATUS FROM PLN_ZY_DBK_M T WHERE T.PRO_PLAN_ID=? AND T.GX_PLAN_NO=?";
					ps1 = con.prepareStatement(sqlZyStatr);
					ps1.setObject(1, rs.getString("PRO_PLAN_ID"));
					ps1.setObject(2, rs.getString("GX_PLAN_NO"));
					rs1 = ps1.executeQuery();
					if (rs1.next()) {
						if (rs1.getInt("PLANSTATUS") < 20) {
							message = "订单号" + rs.getString("PRO_PLAN_ID") + "/"
									+ rs.getString("GX_PLAN_NO")
									+ "向下炉计划有计划/下发状态,不能状态调整!";
							throw new Exception(message);
						}
					}
					rs1.close();
					ps1.close();
					// 查询订单向下炉计划是否存剩余炉计划
					sqlZyStatr = CoreXmlSqlParsersFactory
							.getSql("FrmPlanStoveD.QueryRemaDbk");
					ps1 = con.prepareStatement(sqlZyStatr);
					ps1.setObject(1, rs.getString("PRO_PLAN_ID"));
					ps1.setObject(2, rs.getString("GX_PLAN_NO"));
					rs1 = ps1.executeQuery();
					while (rs1.next()) {
						if (rs1.getInt("ACT_COUNT") > 0) {
							message = "订单号" + rs.getString("PRO_PLAN_ID") + "/"
									+ rs.getString("GX_PLAN_NO") + "向下炉计划上料炉号("
									+ rs1.getString("FEED_HEAT_NO")
									+ ")未上料完,不能状态调整,请先删除剩余炉计划!";
							throw new Exception(message);
						}
					}
					rs1.close();
					ps1.close();
				}
				rs.close();
				ps.close();
				entity.setPlanTimeB(planTimeB);
				entity.setPlanTimeE(planTimeB);
				entity.setPlanUsetime("0");
				entity.setGxProSeq("-1");
				entity.setExeStatus("2");
				entity.setMemo(entity.getMemo() + memo);
				PlnHelper.deleteOrUpdateByEntity(con,
						"ProducHelperBean.updatePlanOrderE", entity);
				// 生产顺序调整
				helperBean.seqIncrease(con, entity.getPlineCode(), gxProSeq,
						-1, -1, processCode);

			}
			// 时间调整
			helperBean.timeIncrease(con, seq - 1, plineCode, planTimeE,
					processCode);
		} else if (processCode.equals("F")) {
			List<PlnOrderRclSEntity> entityList = PlnHelper.jsonsToEntityList(
					PlnOrderRclSEntity.class, jsonStrList);
			int seq = 0;// 最小生产顺序
			String planTimeE = "";
			String plineCode = "";
			for (PlnOrderRclSEntity entity1 : entityList) {
				PlnOrderRclSEntity entity = PlnHelper.getEntityData(
						con,
						new String[] { entity1.getProPlanId(),
								entity1.getGxPlanNo() },
						"ProducHelperBean.getPlanOrderF",
						"and t.pro_plan_id=? and t.gx_plan_no=?",
						PlnOrderRclSEntity.class);
				if (entity == null) {
					message = "数据发生变化,请刷新数据!";
					throw new Exception(message);
				}
				if (entity.getIsRepairPln().equals("1")) {
					throw new Exception("检修计划不能设置完成!");
				}
				int gxProSeq = Integer.parseInt(entity.getGxProSeq());
				if (gxProSeq == 0) {
					throw new Exception("排产订单已经设置完成!");
				}

				if (seq == 0) {
					seq = gxProSeq;
				}
				if (seq >= gxProSeq) {
					seq = gxProSeq;
					planTimeE = entity.getPlanTimeB();
					plineCode = entity.getPlineCode();
				}
				// 查询调整订单
				String sqlProPlanNo = "SELECT T.PRO_PLAN_ID, T.GX_PLAN_NO, T.EXE_STATUS,T.ORD_LN_DLY_PK,T.PLN_DIVIDE_ID FROM PLN_ORDER_RCL_S T "
						+ " WHERE T.PLINE_CODE = ? AND T.EXE_STATUS IN ('0', '1') AND TO_NUMBER(T.GX_PRO_SEQ) = TO_NUMBER(?)";
				ps = con.prepareStatement(sqlProPlanNo);
				ps.setObject(1, entity.getPlineCode());
				ps.setObject(2, gxProSeq);
				rs = ps.executeQuery();
				while (rs.next()) {
					// 查询上工序是否全部生产完成
					String sqlExeStatus = CoreXmlSqlParsersFactory
							.getSql("ProducHelper.QueryExeStatusRcl");
					ps1 = con.prepareStatement(sqlExeStatus);
					ps1.setObject(1, rs.getString("PRO_PLAN_ID"));
					ps1.setObject(2, rs.getString("GX_PLAN_NO"));
					rs1 = ps1.executeQuery();
					if (rs1.next()) {
						if (rs1.getInt("BEFORE_STATE") < 2) {
							if (rs1.getInt("GX_PRO_SEQ_MAX") <= rs1
									.getInt("GX_PRO_SEQ")
									&& rs1.getInt("EXE_STATUS_RCL") >= 2) {
								message = "订单号" + rs.getString("PRO_PLAN_ID")
										+ "/" + rs.getString("GX_PLAN_NO")
										+ "前工序订单有计划/生产中状态并且本工序订单("
										+ rs.getString("PRO_PLAN_ID")
										+ ")没有计划状态,不能状态调整!";
								throw new Exception(message);
							}
						}
					}
					rs1.close();
					ps1.close();
					// 查询订单向下炉计划是否全部生产中或生产完成
					String sqlZyStatr = "SELECT DECODE(MIN(T.PLANSTATUS),'','20',MIN(T.PLANSTATUS)) PLANSTATUS FROM PLN_ZY_RCL_M T WHERE T.PRO_PLAN_ID=? AND T.GX_PLAN_NO=?";
					ps1 = con.prepareStatement(sqlZyStatr);
					ps1.setObject(1, rs.getString("PRO_PLAN_ID"));
					ps1.setObject(2, rs.getString("GX_PLAN_NO"));
					rs1 = ps1.executeQuery();
					if (rs1.next()) {
						if (rs1.getInt("PLANSTATUS") < 20) {
							message = "订单号" + rs.getString("PRO_PLAN_ID") + "/"
									+ rs.getString("GX_PLAN_NO")
									+ "向下炉计划有计划/下发状态,不能状态调整!";
							throw new Exception(message);
						}
					}
					rs1.close();
					ps1.close();
					// 查询订单向下炉计划是否存剩余炉计划
					sqlZyStatr = CoreXmlSqlParsersFactory
							.getSql("FrmPlanStoveD.QueryRemaRcl");
					ps1 = con.prepareStatement(sqlZyStatr);
					ps1.setObject(1, rs.getString("PRO_PLAN_ID"));
					ps1.setObject(2, rs.getString("GX_PLAN_NO"));
					rs1 = ps1.executeQuery();
					while (rs1.next()) {
						if (rs1.getInt("ACT_COUNT") > 0) {
							message = "订单号" + rs.getString("PRO_PLAN_ID") + "/"
									+ rs.getString("GX_PLAN_NO") + "向下炉计划判定炉号("
									+ rs1.getString("JUDGE_STOVE_NO")
									+ ")未上料完,不能状态调整,请先删除剩余炉计划!";
							throw new Exception(message);
						}
					}
					rs1.close();
					ps1.close();
				}
				rs.close();
				ps.close();
				entity.setPlanTimeB(planTimeB);
				entity.setPlanTimeE(planTimeB);
				entity.setPlanUsetime("0");
				entity.setGxProSeq("-1");
				entity.setExeStatus("2");
				entity.setMemo(entity.getMemo() + memo);
				PlnHelper.deleteOrUpdateByEntity(con,
						"ProducHelperBean.updatePlanOrderF", entity);
				// 生产顺序调整
				helperBean.seqIncrease(con, entity.getPlineCode(), gxProSeq,
						-1, -1, processCode);
			}
			// 时间调整
			helperBean.timeIncrease(con, seq - 1, plineCode, planTimeE,
					processCode);
		} else if (processCode.equals("G")) {
			List<PlnOrderJgxSEntity> entityList = PlnHelper.jsonsToEntityList(
					PlnOrderJgxSEntity.class, jsonStrList);
			int seq = 0;// 最小生产顺序
			String planTimeE = "";
			String plineCode = "";
			for (PlnOrderJgxSEntity entity1 : entityList) {
				PlnOrderJgxSEntity entity = PlnHelper.getEntityData(
						con,
						new String[] { entity1.getProPlanId(),
								entity1.getGxPlanNo() },
						"ProducHelperBean.getPlanOrderG",
						"and t.pro_plan_id=? and t.gx_plan_no=?",
						PlnOrderJgxSEntity.class);
				if (entity == null) {
					message = "数据发生变化,请刷新数据!";
					throw new Exception(message);
				}
				if (entity.getIsRepairPln().equals("1")) {
					throw new Exception("检修计划不能设置完成!");
				}
				int gxProSeq = Integer.parseInt(entity.getGxProSeq());
				if (gxProSeq == 0) {
					throw new Exception("排产订单已经设置完成!");
				}
				if (seq == 0) {
					seq = gxProSeq;
				}
				if (seq >= gxProSeq) {
					seq = gxProSeq;
					planTimeE = entity.getPlanTimeB();
					plineCode = entity.getPlineCode();
				}
				// 查询调整订单
				String sqlProPlanNo = "SELECT T.PRO_PLAN_ID, T.GX_PLAN_NO, T.EXE_STATUS,T.ORD_LN_DLY_PK,T.PLN_DIVIDE_ID FROM PLN_ORDER_JGX_S T "
						+ " WHERE T.PLINE_CODE = ? AND T.EXE_STATUS IN ('0', '1') AND TO_NUMBER(T.GX_PRO_SEQ) = TO_NUMBER(?)";
				ps = con.prepareStatement(sqlProPlanNo);
				ps.setObject(1, entity.getPlineCode());
				ps.setObject(2, gxProSeq);
				rs = ps.executeQuery();
				while (rs.next()) {
					// 查询上工序是否全部生产完成
					String sqlExeStatus = CoreXmlSqlParsersFactory
							.getSql("ProducHelper.QueryExeStatusJgx");
					ps1 = con.prepareStatement(sqlExeStatus);
					ps1.setObject(1, rs.getString("PRO_PLAN_ID"));
					ps1.setObject(2, rs.getString("GX_PLAN_NO"));
					rs1 = ps1.executeQuery();
					if (rs1.next()) {
						if (rs1.getInt("BEFORE_STATE") < 2) {
							if (rs1.getInt("GX_PRO_SEQ_MAX") <= rs1
									.getInt("GX_PRO_SEQ")
									&& rs1.getInt("EXE_STATUS_JGX") >= 2) {
								message = "订单号" + rs.getString("PRO_PLAN_ID")
										+ "/" + rs.getString("GX_PLAN_NO")
										+ "前工序订单有计划/生产中状态并且本工序订单("
										+ rs.getString("PRO_PLAN_ID")
										+ ")没有计划状态,不能状态调整!";
								throw new Exception(message);
							}
						}
					}
					rs1.close();
					ps1.close();
					// 查询订单向下炉计划是否全部生产中或生产完成
					String sqlZyStatr = "SELECT DECODE(MIN(T.PLANSTATUS),'','20',MIN(T.PLANSTATUS)) PLANSTATUS FROM PLN_ZY_JGX_M T WHERE T.PRO_PLAN_ID=? AND T.GX_PLAN_NO=?";
					ps1 = con.prepareStatement(sqlZyStatr);
					ps1.setObject(1, rs.getString("PRO_PLAN_ID"));
					ps1.setObject(2, rs.getString("GX_PLAN_NO"));
					rs1 = ps1.executeQuery();
					if (rs1.next()) {
						if (rs1.getInt("PLANSTATUS") < 20) {
							message = "订单号" + rs.getString("PRO_PLAN_ID") + "/"
									+ rs.getString("GX_PLAN_NO")
									+ "向下炉计划有计划/下发状态,不能状态调整!";
							throw new Exception(message);
						}
					}
					rs1.close();
					ps1.close();
					// 查询订单向下炉计划是否存剩余炉计划
					sqlZyStatr = CoreXmlSqlParsersFactory
							.getSql("FrmPlanStoveD.QueryRemaJgx");
					ps1 = con.prepareStatement(sqlZyStatr);
					ps1.setObject(1, rs.getString("PRO_PLAN_ID"));
					ps1.setObject(2, rs.getString("GX_PLAN_NO"));
					rs1 = ps1.executeQuery();
					while (rs1.next()) {
						if (rs1.getInt("ACT_COUNT") > 0) {
							message = "订单号" + rs.getString("PRO_PLAN_ID") + "/"
									+ rs.getString("GX_PLAN_NO") + "向下炉计划判定炉号("
									+ rs1.getString("JUDGE_STOVE_NO")
									+ ")未上料完,不能状态调整,请先删除剩余炉计划!";
							throw new Exception(message);
						}
					}
					rs1.close();
					ps1.close();
				}
				rs.close();
				ps.close();
				entity.setPlanTimeB(planTimeB);
				entity.setPlanTimeE(planTimeB);
				entity.setPlanUsetime("0");
				entity.setGxProSeq("-1");
				entity.setExeStatus("2");
				entity.setMemo(entity.getMemo() + memo);
				PlnHelper.deleteOrUpdateByEntity(con,
						"ProducHelperBean.updatePlanOrderG", entity);
				// 生产顺序调整
				helperBean.seqIncrease(con, entity.getPlineCode(), gxProSeq,
						-1, -1, processCode);
			}
			// 时间调整
			helperBean.timeIncrease(con, seq - 1, plineCode, planTimeE,
					processCode);
		} else if (processCode.equals("H")) {

			List<PlnGxJgPropSEntity> entityList = PlnHelper.jsonsToEntityList(
					PlnGxJgPropSEntity.class, jsonStrList);
			int seq = 0;// 最小生产顺序
			String planTimeE = "";
			String plineCode = "";
			for (PlnGxJgPropSEntity entity1 : entityList) {
				PlnGxJgPropSEntity entity = PlnHelper.getEntityData(
						con,
						new String[] { entity1.getProPlanId(),
								entity1.getGxPlanNo() },
						"ProducHelperBean.getPlanOrderH",
						"and t.pro_plan_id=? and t.gx_plan_no=?",
						PlnGxJgPropSEntity.class);
				if (entity == null) {
					message = "数据发生变化,请刷新数据!";
					throw new Exception(message);
				}
				if (entity.getIsRepairPln().equals("1")) {
					throw new Exception("检修计划不能设置完成!");
				}
				int gxProSeq = Integer.parseInt(entity.getGxProSeq());
				if (gxProSeq == 0) {
					throw new Exception("排产订单已经设置完成!");
				}
				if (seq == 0) {
					seq = gxProSeq;
				}
				if (seq >= gxProSeq) {
					seq = gxProSeq;
					planTimeE = entity.getPlanTimeB();
					plineCode = entity.getPlineCode();
				}

				// 查询调整订单
				String sqlProPlanNo = "SELECT T.PRO_PLAN_ID, T.GX_PLAN_NO, T.EXE_STATUS,T.ORD_LN_DLY_PK,T.PLN_DIVIDE_ID FROM PLN_GX_JG_PROP_S T "
						+ " WHERE T.PLINE_CODE = ? AND T.EXE_STATUS IN ('0', '1') AND TO_NUMBER(T.GX_PRO_SEQ) = TO_NUMBER(?)";
				ps = con.prepareStatement(sqlProPlanNo);
				ps.setObject(1, plineCode);
				ps.setObject(2, gxProSeq);
				rs = ps.executeQuery();
				while (rs.next()) {
					// 查询订单向下炉计划是否全部生产中或生产完成
					String sqlZyStatr = "SELECT DECODE(MIN(T.PLANSTATUS),'','20',MIN(T.PLANSTATUS)) PLANSTATUS FROM PLN_ZY_JG_M T WHERE T.PRO_PLAN_ID=? AND T.GX_PLAN_NO=?";
					ps1 = con.prepareStatement(sqlZyStatr);
//					ps1.setObject(1, rs.getString("PRO_PLAN_ID"));
//					ps1.setObject(2, rs.getString("GX_PLAN_NO"));

					ps1.setObject(1, entity.getProPlanId());
					ps1.setObject(2, entity.getGxPlanNo());
					rs1 = ps1.executeQuery();
					if (rs1.next()) {
						if (rs1.getInt("PLANSTATUS") < 20) {
							message = "订单号" + rs.getString("PRO_PLAN_ID") + "/"
									+ rs.getString("GX_PLAN_NO")
									+ "向下炉计划有计划/下发状态,不能设置完成!";
							throw new Exception(message);
						}
					}
					rs1.close();
					ps1.close();

					// 查询订单向下炉计划是否存剩余炉计划
					sqlZyStatr = CoreXmlSqlParsersFactory
							.getSql("ProducHelper.QueryRemaJg");
					ps1 = con.prepareStatement(sqlZyStatr);
//					ps1.setObject(1, rs.getString("PRO_PLAN_ID"));
//					ps1.setObject(2, rs.getString("GX_PLAN_NO"));
					ps1.setObject(1, entity.getProPlanId());
					ps1.setObject(2, entity.getGxPlanNo());
					rs1 = ps1.executeQuery();
					while (rs1.next()) {
						if (rs1.getInt("ACT_COUNT") > 0) {
							message = "订单号" + rs.getString("PRO_PLAN_ID") + "/"
									+ rs.getString("GX_PLAN_NO") + "向下炉计划判定炉号("
									+ rs1.getString("JUDGE_STOVE_NO")
									+ ")未上料完,不能设置完成,请先删除剩余炉计划!";
							throw new Exception(message);
						}
					}
					rs1.close();
					ps1.close();
				}
				rs.close();
				ps.close();
				entity.setPlanTimeB(planTimeB);
				entity.setPlanTimeE(planTimeB);
				entity.setPlanUsetime("0");
				entity.setGxProSeq("-1");
				entity.setExeStatus("2");
				entity.setMemo(entity.getMemo() + memo);
				PlnHelper.deleteOrUpdateByEntity(con,
						"ProducHelperBean.updatePlanOrderH", entity);
				// 生产顺序调整
				helperBean.seqIncrease(con, entity.getPlineCode(), gxProSeq,
						-1, -1, processCode);
			}
			// 时间调整
			helperBean.timeIncrease(con, seq - 1, plineCode, planTimeE,
					processCode);

		}
	}

	/**
	 * 查询订单内炉顺序号
	 * 
	 * @param con
	 * @return
	 * @throws SQLException
	 */
	public static int getMaxLotNoSqe(Connection con, String proPlanId,
			String gxPlanNo) throws SQLException {
		int gxPlnSeq = 1;
		String sql = "SELECT TO_NUMBER(NVL(MAX(T.LOT_NO_SQE),0))+1 AS LOT_NO_SQE FROM PLN_ZY_RCL_M T WHERE T.PRO_PLAN_ID=? AND T.GX_PLAN_NO=?";
		PreparedStatement ps = con.prepareStatement(sql);
		ps.setObject(1, proPlanId);
		ps.setObject(2, gxPlanNo);
		ResultSet rs = ps.executeQuery();
		if (rs.next()) {
			gxPlnSeq = rs.getInt("LOT_NO_SQE");
		}
		rs.close();
		ps.close();
		return gxPlnSeq;
	}

	/**
	 * 订单拆分修改炉计划炉计划,材料表,判定表,申请判定表,炉计划接收表排产序号
	 */
	public String updateSpit(Connection con, String heatPlanNo,
			String gxPlanNo, String processCode, ProducEntity proEntity)
			throws SQLException, ParseException {
		String mess = "";
		PreparedStatement ps = null;
		ResultSet rs = null;

		String[] heatPlanNoA = heatPlanNo.split(",");
		String judgeStoveNo = "";
		String oldProPlanId = "";
		String odlGxPlanNo = "";
		String feedHeatNo = "";// 上料炉号
		String planstatus = "";
		int count = 0;
		if (processCode.equals("D")) {
			for (int i = 0; i < heatPlanNoA.length; i++) {

				// 查询虚拟炉计划原订单序号，炉号
				String sqlPlanM = CoreXmlSqlParsersFactory
						.getSql("ProducHelper.QueryPlanM");
				ps = con.prepareStatement(sqlPlanM);
				ps.setObject(1, heatPlanNoA[i]);
				rs = ps.executeQuery();
				if (rs.next()) {
					judgeStoveNo = rs.getString("JUDGE_STOVE_NO");
					oldProPlanId = rs.getString("PRO_PLAN_ID");
					odlGxPlanNo = rs.getString("GX_PLAN_NO");
					feedHeatNo = rs.getString("FEED_HEAT_NO");
					planstatus = rs.getString("PLANSTATUS");
				}
				rs.close();
				ps.close();
				// 判断状态是否生成
				if (!planstatus.equals("00")) {
					mess = "选中上料炉号:" + feedHeatNo + "已不是计划状态";
					return mess;
				}
				// 炉计划是下发状态拆分修改成计划状态
				if (planstatus.equals("10")) {
					// 删除炉计划接收表
					String deletePlanMil = "DELETE MIL_PLAN WHERE ID = ?";
					ps = con.prepareStatement(deletePlanMil);
					ps.setObject(1, heatPlanNoA[i]);
					ps.executeUpdate();
					ps.close();
					// 修改虚拟炉计划状态
					String deletePlanZgM = "UPDATE PLN_ZY_ZG_M T SET T.PLANSTATUS='00',T.ZY_BATCH_ID='' WHERE T.HEAT_PLAN_NO=?";
					ps = con.prepareStatement(deletePlanZgM);
					ps.setObject(1, heatPlanNoA[i]);
					ps.executeUpdate();
					ps.close();
					String heatPlanSqe = "";
					// 查询是否存在实际炉计划
					String sqlPlanC = "SELECT T.HEAT_PLAN_SQE FROM PLN_ZY_ZG_C T WHERE T.HEAT_PLAN_NO = ?";
					ps = con.prepareStatement(sqlPlanC);
					ps.setObject(1, heatPlanNoA[i]);
					rs = ps.executeQuery();
					while (rs.next()) {
						heatPlanSqe = rs.getString("HEAT_PLAN_SQE");
						if (!heatPlanSqe.equals("")) {
							// 删除炉计划上料行表
							String deleteFeedMil = "DELETE MIL_FEED_PLAN WHERE FEED_ROW_NO = ?";
							PreparedStatement ps1 = con
									.prepareStatement(deleteFeedMil);
							ps1.setObject(1, heatPlanSqe);
							ps1.executeUpdate();
							ps1.close();
						}
					}
					rs.close();
					ps.close();
				}
				if (!planstatus.equals("00")) {
					count++;
				}
				// 修改虚拟炉计划订单序号
				String updateZgM = "UPDATE PLN_ZY_ZG_M T SET T.GX_PLAN_NO=? WHERE T.HEAT_PLAN_NO=?";
				ps = con.prepareStatement(updateZgM);
				ps.setObject(1, gxPlanNo);
				ps.setObject(2, heatPlanNoA[i]);
				ps.executeUpdate();
				ps.close();
				// 修改实际炉计划订单序号
				String updateZgC = "UPDATE PLN_ZY_ZG_C T SET T.GX_PLAN_NO=? WHERE T.HEAT_PLAN_NO=?";
				ps = con.prepareStatement(updateZgC);
				ps.setObject(1, gxPlanNo);
				ps.setObject(2, heatPlanNoA[i]);
				ps.executeUpdate();
				ps.close();
				// // 修改炉计划接收订单序号
				// String updatePlan =
				// "UPDATE MIL_PLAN T SET T.GX_PLAN_NO=? WHERE T.ID=?";
				// ps = con.prepareStatement(updatePlan);
				// ps.setObject(1, gxPlanNo);
				// ps.setObject(2, heatPlanNoA[i]);
				// ps.executeUpdate();
				// ps.close();
				// // 修改炉计划上料行订单序号
				// String updateFeed =
				// "UPDATE MIL_FEED_PLAN T SET T.GX_PLAN_NO=? WHERE T.JUDGE_STOVE_NO=? AND T.PRO_PLAN_ID=? AND T.GX_PLAN_NO=?";
				// ps = con.prepareStatement(updateFeed);
				// ps.setObject(1, gxPlanNo);
				// ps.setObject(2, feedHeatNo + "-01");
				// ps.setObject(3, oldProPlanId);
				// ps.setObject(4, odlGxPlanNo);
				// ps.executeUpdate();
				// ps.close();
				// 修改库存订单序号
				String updateMat = "UPDATE MAT_GP_M T SET T.GX_PLAN_NO_ZG=? WHERE T.JUDGE_STOVE_NO=? AND T.PRO_PLAN_ID_ZG=? AND T.GX_PLAN_NO_ZG=?";
				ps = con.prepareStatement(updateMat);
				ps.setObject(1, gxPlanNo);
				ps.setObject(2, judgeStoveNo);
				ps.setObject(3, oldProPlanId);
				ps.setObject(4, odlGxPlanNo);
				ps.executeUpdate();
				// 修改申请判定表
				String updateApply = "UPDATE QCM_GP_JUDGE_APPLY T SET T.GX_PLAN_NO_NEXT=? WHERE T.JUDGE_STOVE_NO=? AND T.PRO_PLAN_ID_NEXT=? AND T.GX_PLAN_NO_NEXT=?";
				ps = con.prepareStatement(updateApply);
				ps.setObject(1, gxPlanNo);
				ps.setObject(2, judgeStoveNo);
				ps.setObject(3, oldProPlanId);
				ps.setObject(4, odlGxPlanNo);
				ps.executeUpdate();
			}
			// 如果存在不是计划状态的炉计划则，轧管炉计划下发标识是下发状态
			// if (count > 0) {
			// proEntity.setIfStoveIssued("1");
			// }
			// else {
			// }
		} else if (processCode.equals("E")) {
			for (int i = 0; i < heatPlanNoA.length; i++) {
				// 查询虚拟炉计划原订单序号，炉号
				String sqlPlanM = "SELECT T.PRO_PLAN_ID, T.GX_PLAN_NO,T.FEED_HEAT_NO,T.JUDGE_STOVE_NO,T.PLANSTATUS  FROM PLN_ZY_DBK_M T WHERE T.HEAT_PLAN_NO = ?";
				ps = con.prepareStatement(sqlPlanM);
				ps.setObject(1, heatPlanNoA[i]);
				rs = ps.executeQuery();
				if (rs.next()) {
					judgeStoveNo = rs.getString("JUDGE_STOVE_NO");
					oldProPlanId = rs.getString("PRO_PLAN_ID");
					odlGxPlanNo = rs.getString("GX_PLAN_NO");
					feedHeatNo = rs.getString("FEED_HEAT_NO");
					planstatus = rs.getString("PLANSTATUS");
				}
				rs.close();
				ps.close();
				// 判断状态是否生成
				if (!planstatus.equals("00")) {
					mess = "选中上料炉号:" + feedHeatNo + "已不是计划状态";
					return mess;
				}
				// 炉计划是下发状态拆分修改成计划状态
				if (planstatus.equals("10")) {
					// 修改虚拟炉计划状态
					String deletePlanZgM = "UPDATE PLN_ZY_DBK_M T SET T.ZY_BATCH_ID='"
							+ proEntity.getZyBatchId()
							+ "' WHERE T.HEAT_PLAN_NO=?";
					ps = con.prepareStatement(deletePlanZgM);
					ps.setObject(1, heatPlanNoA[i]);
					ps.executeUpdate();
					ps.close();
				}
				// if (!planstatus.equals("00")) {
				// count++;
				// }
				// 修改虚拟炉计划订单序号
				String updateZgM = "UPDATE PLN_ZY_DBK_M T SET T.GX_PLAN_NO=? WHERE T.HEAT_PLAN_NO=?";
				ps = con.prepareStatement(updateZgM);
				ps.setObject(1, gxPlanNo);
				ps.setObject(2, heatPlanNoA[i]);
				ps.executeUpdate();
				ps.close();
				// 修改实际炉计划订单序号
				String updateZgC = "UPDATE PLN_ZY_DBK_C T SET T.GX_PLAN_NO=? WHERE T.HEAT_PLAN_NO=?";
				ps = con.prepareStatement(updateZgC);
				ps.setObject(1, gxPlanNo);
				ps.setObject(2, heatPlanNoA[i]);
				ps.executeUpdate();
				ps.close();

				// 修改库存订单序号
				String updateMat = "UPDATE MAT_BC_M T SET T.GX_PLAN_NO_NEXT=? WHERE T.JUDGE_STOVE_NO=? AND T.PRO_PLAN_ID_NEXT=? AND T.GX_PLAN_NO_NEXT=? AND T.NEXT_PROCESS_CDOE=?";
				ps = con.prepareStatement(updateMat);
				ps.setObject(1, gxPlanNo);
				ps.setObject(2, feedHeatNo);
				ps.setObject(3, oldProPlanId);
				ps.setObject(4, odlGxPlanNo);
				ps.setObject(5, processCode);
				ps.executeUpdate();
				// 修改申请判定表
				String updateApply = "UPDATE QCM_ZG_JUGDE_APPLY T SET T.GX_PLAN_NO_NEXT=? WHERE T.JUDGE_STOVE_NO=? AND T.PRO_PLAN_ID_NEXT=? AND T.GX_PLAN_NO_NEXT=? AND T.NEXT_PROCESS_CDOE=?";
				ps = con.prepareStatement(updateApply);
				ps.setObject(1, gxPlanNo);
				ps.setObject(2, feedHeatNo);
				ps.setObject(3, oldProPlanId);
				ps.setObject(4, odlGxPlanNo);
				ps.setObject(5, processCode);
				ps.executeUpdate();
			}
		} else if (processCode.equals("F")) {
			for (int i = 0; i < heatPlanNoA.length; i++) {
				// 查询虚拟炉计划原订单序号，炉号
				int lotNo = 0;
				String pic = "";
				String sqlPlanM = "SELECT T.PRO_PLAN_ID, T.GX_PLAN_NO,T.JUDGE_STOVE_NO,T.LOT_NO_SQE,T.PIC,T.PLANSTATUS  FROM PLN_ZY_RCL_M T WHERE T.HEAT_PLAN_NO = ?";
				ps = con.prepareStatement(sqlPlanM);
				ps.setObject(1, heatPlanNoA[i]);
				rs = ps.executeQuery();
				if (rs.next()) {
					judgeStoveNo = rs.getString("JUDGE_STOVE_NO");
					oldProPlanId = rs.getString("PRO_PLAN_ID");
					odlGxPlanNo = rs.getString("GX_PLAN_NO");
					planstatus = rs.getString("PLANSTATUS");
					lotNo = rs.getInt("LOT_NO_SQE");
					pic = rs.getString("PIC");
				}
				rs.close();
				ps.close();
				// 判断状态是否生成
				if (!planstatus.equals("00")) {
					mess = "选中判定炉号:" + judgeStoveNo + "已不是计划状态";
					return mess;
				}
				// 炉计划是下发状态拆分修改成计划状态
				if (planstatus.equals("10")) {
					// 修改虚拟炉计划状态
					String deletePlanZgM = "UPDATE PLN_ZY_RCL_M T SET T.ZY_BATCH_ID='"
							+ proEntity.getZyBatchId()
							+ "' WHERE T.HEAT_PLAN_NO=?";
					ps = con.prepareStatement(deletePlanZgM);
					ps.setObject(1, heatPlanNoA[i]);
					ps.executeUpdate();
					ps.close();
				}
				// if (!planstatus.equals("00")) {
				// count++;
				// }
				// 订单内炉顺序号
				int lotNoNew = getMaxLotNoSqe(con, oldProPlanId, gxPlanNo);
				// 修改虚拟炉计划订单序号
				String updateZgM = "UPDATE PLN_ZY_RCL_M T SET T.GX_PLAN_NO=?,T.LOT_NO_SQE=? WHERE T.HEAT_PLAN_NO=?";
				ps = con.prepareStatement(updateZgM);
				ps.setObject(1, gxPlanNo);
				ps.setObject(2, lotNoNew);
				ps.setObject(3, heatPlanNoA[i]);
				ps.executeUpdate();
				ps.close();
				// 新增生产批号
				StoveHelper.updatePlnRclGroup(con, oldProPlanId, gxPlanNo, pic);
				// 删除修改炉内顺序号
				String sql = "UPDATE PLN_ZY_RCL_M T SET T.LOT_NO_SQE = TO_NUMBER(T.LOT_NO_SQE) + TO_NUMBER(-1)"
						+ " WHERE T.PRO_PLAN_ID=? AND T.GX_PLAN_NO=? AND TO_NUMBER(T.LOT_NO_SQE) >= TO_NUMBER(?)";
				ps = con.prepareStatement(sql);
				ps.setObject(1, oldProPlanId);
				ps.setObject(2, odlGxPlanNo);
				ps.setObject(3, lotNo);
				ps.executeUpdate();
				ps.close();
				// 新增生产批号
				StoveHelper.updatePlnRclGroup(con, oldProPlanId, odlGxPlanNo,
						pic);
				// 修改实际炉计划订单序号
				String updateZgC = "UPDATE PLN_ZY_RCL_C T SET T.GX_PLAN_NO=? WHERE T.HEAT_PLAN_NO=?";
				ps = con.prepareStatement(updateZgC);
				ps.setObject(1, gxPlanNo);
				ps.setObject(2, heatPlanNoA[i]);
				ps.executeUpdate();
				ps.close();

				// 修改库存订单序号
				String updateMat = "UPDATE MAT_BC_M T SET T.GX_PLAN_NO_NEXT=? WHERE T.JUDGE_STOVE_NO=? AND T.PRO_PLAN_ID_NEXT=? AND T.GX_PLAN_NO_NEXT=? AND T.NEXT_PROCESS_CDOE=?";
				ps = con.prepareStatement(updateMat);
				ps.setObject(1, gxPlanNo);
				ps.setObject(2, judgeStoveNo);
				ps.setObject(3, oldProPlanId);
				ps.setObject(4, odlGxPlanNo);
				ps.setObject(5, processCode);
				ps.executeUpdate();
				// 修改申请判定表
				String updateApply = "UPDATE QCM_ZG_JUGDE_APPLY T SET T.GX_PLAN_NO_NEXT=? WHERE T.JUDGE_STOVE_NO=? AND T.PRO_PLAN_ID_NEXT=? AND T.GX_PLAN_NO_NEXT=? AND T.NEXT_PROCESS_CDOE=?";
				ps = con.prepareStatement(updateApply);
				ps.setObject(1, gxPlanNo);
				ps.setObject(2, judgeStoveNo);
				ps.setObject(3, oldProPlanId);
				ps.setObject(4, odlGxPlanNo);
				ps.setObject(5, processCode);
				ps.executeUpdate();
			}
		} else if (processCode.equals("G")) {
			for (int i = 0; i < heatPlanNoA.length; i++) {
				// 查询虚拟炉计划原订单序号，炉号
				String sqlPlanM = "SELECT T.PRO_PLAN_ID, T.GX_PLAN_NO,T.JUDGE_STOVE_NO,T.PLANSTATUS  FROM PLN_ZY_JGX_M T WHERE T.HEAT_PLAN_NO = ?";
				ps = con.prepareStatement(sqlPlanM);
				ps.setObject(1, heatPlanNoA[i]);
				rs = ps.executeQuery();
				if (rs.next()) {
					judgeStoveNo = rs.getString("JUDGE_STOVE_NO");
					oldProPlanId = rs.getString("PRO_PLAN_ID");
					odlGxPlanNo = rs.getString("GX_PLAN_NO");
					planstatus = rs.getString("PLANSTATUS");
				}
				rs.close();
				ps.close();
				// 判断状态是否生成
				if (!planstatus.equals("00")) {
					mess = "选中判定炉号:" + judgeStoveNo + "已不是计划状态";
					return mess;
				}
				// 炉计划是下发状态拆分修改成计划状态
				if (planstatus.equals("10")) {
					// 修改虚拟炉计划状态
					String deletePlanZgM = "UPDATE PLN_ZY_JGX_M T SET T.ZY_BATCH_ID='"
							+ proEntity.getZyBatchId()
							+ "' WHERE T.HEAT_PLAN_NO=?";
					ps = con.prepareStatement(deletePlanZgM);
					ps.setObject(1, heatPlanNoA[i]);
					ps.executeUpdate();
					ps.close();
				}
				// if (!planstatus.equals("00")) {
				// count++;
				// }
				// 修改虚拟炉计划订单序号
				String updateZgM = "UPDATE PLN_ZY_JGX_M T SET T.GX_PLAN_NO=? WHERE T.HEAT_PLAN_NO=?";
				ps = con.prepareStatement(updateZgM);
				ps.setObject(1, gxPlanNo);
				ps.setObject(2, heatPlanNoA[i]);
				ps.executeUpdate();
				ps.close();
				// 修改实际炉计划订单序号
				String updateZgC = "UPDATE PLN_ZY_JGX_C T SET T.GX_PLAN_NO=? WHERE T.HEAT_PLAN_NO=?";
				ps = con.prepareStatement(updateZgC);
				ps.setObject(1, gxPlanNo);
				ps.setObject(2, heatPlanNoA[i]);
				ps.executeUpdate();
				ps.close();

				// 修改库存订单序号
				String updateMat = "UPDATE MAT_BC_M T SET T.GX_PLAN_NO_NEXT=? WHERE T.JUDGE_STOVE_NO=? AND T.PRO_PLAN_ID_NEXT=? AND T.GX_PLAN_NO_NEXT=? AND T.NEXT_PROCESS_CDOE=?";
				ps = con.prepareStatement(updateMat);
				ps.setObject(1, gxPlanNo);
				ps.setObject(2, judgeStoveNo);
				ps.setObject(3, oldProPlanId);
				ps.setObject(4, odlGxPlanNo);
				ps.setObject(5, processCode);
				ps.executeUpdate();
				// 修改申请判定表
				String updateApply = "UPDATE QCM_ZG_JUGDE_APPLY T SET T.GX_PLAN_NO_NEXT=? WHERE T.JUDGE_STOVE_NO=? AND T.PRO_PLAN_ID_NEXT=? AND T.GX_PLAN_NO_NEXT=? AND T.NEXT_PROCESS_CDOE=?";
				ps = con.prepareStatement(updateApply);
				ps.setObject(1, gxPlanNo);
				ps.setObject(2, judgeStoveNo);
				ps.setObject(3, oldProPlanId);
				ps.setObject(4, odlGxPlanNo);
				ps.setObject(5, processCode);
				ps.executeUpdate();
			}
		} else if (processCode.equals("H")) {

			for (int i = 0; i < heatPlanNoA.length; i++) {
				// 查询虚拟炉计划原订单序号，炉号
				String sqlPlanM = "SELECT T.PRO_PLAN_ID, T.GX_PLAN_NO,T.JUDGE_STOVE_NO,T.PLANSTATUS  FROM PLN_ZY_JG_M T WHERE T.HEAT_PLAN_NO = ?";
				ps = con.prepareStatement(sqlPlanM);
				ps.setObject(1, heatPlanNoA[i]);
				rs = ps.executeQuery();
				if (rs.next()) {
					judgeStoveNo = rs.getString("JUDGE_STOVE_NO");
					oldProPlanId = rs.getString("PRO_PLAN_ID");
					odlGxPlanNo = rs.getString("GX_PLAN_NO");
					planstatus = rs.getString("PLANSTATUS");
				}
				rs.close();
				ps.close();
				// 判断状态是否生成
				if (!planstatus.equals("00")) {
					mess = "选中判定炉号:" + judgeStoveNo + "已不是计划状态";
					return mess;
				}
				// 炉计划是下发状态拆分修改成计划状态
				// if (planstatus.equals("10")) {
				// // 修改虚拟炉计划状态
				// String deletePlanZgM =
				// "UPDATE PLN_ZY_JG_M T SET T.PLANSTATUS='00' WHERE T.HEAT_PLAN_NO=?";
				// ps = con.prepareStatement(deletePlanZgM);
				// ps.setObject(1, heatPlanNoA[i]);
				// ps.executeUpdate();
				// ps.close();
				// }
				// if (!planstatus.equals("00")) {
				// count++;
				// }
				// 修改虚拟炉计划订单序号
				String updateZgM = "UPDATE PLN_ZY_JG_M T SET T.GX_PLAN_NO=? WHERE T.HEAT_PLAN_NO=?";
				ps = con.prepareStatement(updateZgM);
				ps.setObject(1, gxPlanNo);
				ps.setObject(2, heatPlanNoA[i]);
				ps.executeUpdate();
				ps.close();
				// 修改实际炉计划订单序号
				String updateZgC = "UPDATE PLN_ZY_JG_C T SET T.GX_PLAN_NO=? WHERE T.HEAT_PLAN_NO=?";
				ps = con.prepareStatement(updateZgC);
				ps.setObject(1, gxPlanNo);
				ps.setObject(2, heatPlanNoA[i]);
				ps.executeUpdate();
				ps.close();

				// // 修改库存订单序号
				// String updateMat =
				// "UPDATE MAT_BC_M T SET T.GX_PLAN_NO_NEXT=? WHERE T.JUDGE_STOVE_NO=? AND T.PRO_PLAN_ID_NEXT=? AND T.GX_PLAN_NO_NEXT=? AND T.NEXT_PROCESS_CDOE=?";
				// ps = con.prepareStatement(updateMat);
				// ps.setObject(1, gxPlanNo);
				// ps.setObject(2, judgeStoveNo);
				// ps.setObject(3, oldProPlanId);
				// ps.setObject(4, odlGxPlanNo);
				// ps.setObject(5, processCode);
				// ps.executeUpdate();
				// // 修改申请判定表
				// String updateApply =
				// "UPDATE QCM_ZG_JUGDE_APPLY T SET T.GX_PLAN_NO_NEXT=? WHERE T.JUDGE_STOVE_NO=? AND T.PRO_PLAN_ID_NEXT=? AND T.GX_PLAN_NO_NEXT=? AND T.NEXT_PROCESS_CDOE=?";
				// ps = con.prepareStatement(updateApply);
				// ps.setObject(1, gxPlanNo);
				// ps.setObject(2, judgeStoveNo);
				// ps.setObject(3, oldProPlanId);
				// ps.setObject(4, odlGxPlanNo);
				// ps.setObject(5, processCode);
				// ps.executeUpdate();
			}

		}
		proEntity.setIfStoveIssued("0");
		proEntity.setStoveIssuedMan("");
		proEntity.setStoveIssuedTime("");
		return mess;
	}
}
