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

import CoreFS.SA06.CoreReturnObject;
import CoreFS.SA08.CoreXmlSqlParsersFactory;
import CoreFS.SC01.CoreConstantData;

import com.steering.comm.converter.CoreConverter;
import com.steering.comm.data.ComBaseInfo;
import com.steering.comm.db.DBCommon;
import com.steering.comm.tools.EntityTool;
import com.steering.pss.plnsaleord.planStove.FrmPlanStoveE;
import com.steering.pss.plnsaleord.planStove.StoveHelper;
import com.steering.pss.plnsaleord.processOrder.entity.*;
import com.steering.pss.plnsaleord.processOrder.tmsDemand.writeDemand;
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.stove.entity.PlnOrderJgxSEntity;
import com.steering.pss.plnsaleord.stove.entity.PlnZyDbkMEntity;
import com.steering.pss.plnsaleord.stove.entity.PlnZyRclMEntity;
//import com.steering.pss.plnsaleord.GpOptimize.model.PlnOrderZgSEntity;


import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.UUID;

import com.steering.comm.tools.SqlBuilder;
import com.steering.comm.tools.StringTool;








import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

import org.apache.commons.beanutils.BeanUtils;
import org.apache.commons.lang.StringUtils;







import java.io.IOException;
import java.io.InputStream;
import java.lang.reflect.InvocationTargetException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;




/**
 * 排产公共方法类(用于界面)
 * 
 * @author peng
 */
public class ProducHelper extends DBCommon {

	/**
	 * 查询数据库服务器当前时间
	 * 
	 * @return
	 */
	public CoreReturnObject selectSystemTime() {
		CoreReturnObject cro = null;
		cro = this.getDataBySqlID("ProducHelperBean.selectSystemTime");
		return cro;
	}
	
	public CoreReturnObject doQuery(String order)
	{
		String sql = CoreXmlSqlParsersFactory.getSql("FrmRedChong.doQuery");
		sql += " AND T.BAL_YEAR_MONTH = '"+order+"'";
        return this.getData(sql);
	}
	/**
	 * 查询合同状态
	 * @param ordLnDlyPk
	 * @return
	 */
	public CoreReturnObject doQueryPorderstatus(String ordLnDlyPk)
	{
        return this.getDataBySqlID("ProducHelperBean.doQueryPorderstatus", new Object[] {
        		ordLnDlyPk });
	}

	/**
	 * 确认(取消)
	 * 
	 * @param jsonList
	 *            json字符串
	 * @param isFlag
	 *            确认标识(0 确认 1取消确认)
	 * @param processCode
	 *            工序
	 * @return
	 */
	public CoreReturnObject issued(ArrayList<String> jsonList, String isFlag,
			String username, String processCode) {
		CoreReturnObject core = new CoreReturnObject();
		core.setResult(false);
		Connection con = null;
		//Connection tmsCon = null;
		try {
			con = this.getDao(CoreConstantData.sysbeanstr).getConnection();
			//tmsCon = this.getDao("TmsDao").getConnection();
			con.setAutoCommit(false);
			//tmsCon.setAutoCommit(false);
			ProducHelperBean helperBean = new ProducHelperBean();
			PreparedStatement psta = null;
			// PreparedStatement ps = null;
			String sqlupdate = "";
			String isStoveIssue = "";

			String insertCrmSql = "";//排产下发修改CRM

			if (processCode.equals("D")) {
				//轧管
				sqlupdate = CoreXmlSqlParsersFactory
						.getSql("ProducHelperBean.updatePlanOrderDIss");
			} else if (processCode.equals("F")) {
				//热处理
				sqlupdate = CoreXmlSqlParsersFactory
						.getSql("ProducHelperBean.updatePlanOrderDIssRcl");
			} else if (processCode.equals("G")) {
				//加工
				sqlupdate = CoreXmlSqlParsersFactory
						.getSql("ProducHelperBean.updatePlanOrderDIssJgx");
			} else if (processCode.equals("E")) {
				//
				sqlupdate = CoreXmlSqlParsersFactory
						.getSql("ProducHelperBean.updatePlanOrderDIssDbk");
			} else if (processCode.equals("H")) {
				//
				sqlupdate = CoreXmlSqlParsersFactory
						.getSql("ProducHelperBean.updatePlanOrderDIssJg");
			}
			psta = con.prepareStatement(sqlupdate);

		
			for (String jsonStr : jsonList) {
				PreparedStatement ps = null;
				ResultSet rs = null;
				String sqlOrderGl = CoreXmlSqlParsersFactory.getSql("ProducHelperBean.selectOrderZs");
				ProducEntity proEntity = helperBean.genertionProEntity(con,
						jsonStr, processCode);
				if (proEntity == null) {
					core.setV_errMsg("数据异常,请刷新数据!");
					return core;
				}
				int acount = 0;
				if (!processCode.equals("B")) {
					if (proEntity.getIfStoveIssued().equals("1")
							&& isFlag.equals("2")) {
						core.setV_errMsg("订单编号(" + proEntity.getProPlanId()
								+ ") 炉计划已经下发!");
						return core;
					}

					if (isFlag.equals("0")
							&& proEntity.getIsPlanOk().equals("1")) {
						core.setV_errMsg("订单编号(" + proEntity.getProPlanId()
								+ ")已经确认!");
						return core;
					}
					if (isFlag.equals("1")
							&& !proEntity.getIsPlanOk().equals("1")) {
						core.setV_errMsg("订单编号(" + proEntity.getProPlanId()
								+ ")未确认!");
						return core;
					}
					if (processCode.equals("D")) {
						//TZH 24.8.27 
//						if (isFlag.equals("1")
//								&& !proEntity.getGpreqId().equals("")) {
//							core.setV_errMsg("订单编号(" + proEntity.getProPlanId()
//									+ ")已生成管坯需求,请先删除管坯需求!");
//							return core;
//						}
					}
				} else {
					if (isFlag.equals("0")
							&& proEntity.getIsPlanOk().equals("1")) {
						core.setV_errMsg("订单编号(" + proEntity.getProPlanId()
								+ ")已经下发!");
						return core;
					}
					if (isFlag.equals("1")
							&& !proEntity.getIsPlanOk().equals("1")) {
						core.setV_errMsg("订单编号(" + proEntity.getProPlanId()
								+ ")未下发!");
						return core;
					}
				}

				String strTime = FrmSteelMakingPlanChange.getSystemTime(con);
				if (isFlag.equals("0")) {
					proEntity.setIsPlanOk("1");
					proEntity.setIssuedMan(username);
					proEntity.setIssuedTime(strTime);

					psta.setObject(1, proEntity.getIsPlanOk());
					psta.setObject(2, proEntity.getIssuedMan());
					psta.setObject(3, proEntity.getIssuedTime());
					psta.setObject(4, "");
					psta.setObject(5, "");
					psta.setObject(6, "");
					psta.setObject(7, "");
					psta.setObject(8, "");
					psta.setObject(9, proEntity.getProPlanId());
					psta.setObject(10, proEntity.getGxPlanNo());
					psta.addBatch();


				} else if (isFlag.equals("1")) {
					proEntity.setIsPlanOk("0");
					proEntity.setLastUndownMan(username);
					proEntity.setLastUndownTime(strTime);

					psta.setObject(1, proEntity.getIsPlanOk());
					psta.setObject(2, proEntity.getIssuedMan());
					psta.setObject(3, proEntity.getIssuedTime());
					psta.setObject(4, proEntity.getLastUndownMan());
					psta.setObject(5, proEntity.getLastUndownTime());
					psta.setObject(6, "");
					psta.setObject(7, "");
					psta.setObject(8, "");
					psta.setObject(9, proEntity.getProPlanId());
					psta.setObject(10, proEntity.getGxPlanNo());
					psta.addBatch();

					ps = con.prepareStatement(sqlOrderGl);
					ps.setString(1,proEntity.getProPlanId());
					ps.setString(2,proEntity.getGxPlanNo());
					rs = ps.executeQuery();
					if(rs.next())
					{
						isStoveIssue = rs.getString("IF_STOVE_ISSUED");
					}
					rs.close();
					ps.close();
					if(isStoveIssue.equals("1"))
					{
						core.setV_errMsg("此订单下发,不允许撤销确认!");
						return core;
					}

				} else if (isFlag.equals("2")) {

					proEntity.setIfStoveIssued("1");
					psta.setObject(1, proEntity.getIsPlanOk());
					psta.setObject(2, proEntity.getIssuedMan());
					psta.setObject(3, proEntity.getIssuedTime());
					psta.setObject(4, proEntity.getLastUndownMan());
					psta.setObject(5, proEntity.getLastUndownTime());
					psta.setObject(6, proEntity.getIfStoveIssued());
					psta.setObject(7, username);
					psta.setObject(8, strTime);
					psta.setObject(9, proEntity.getProPlanId());
					psta.setObject(10, proEntity.getGxPlanNo());
					psta.addBatch();
					if (processCode.equals("D")) {
						// 下发轧管订单同时下发炉计划
						String messe = StoveHelper.updateMilPlan(
								proEntity.getProPlanId(),
								proEntity.getGxPlanNo(), username, strTime,
								"0", con, proEntity.getZyBatchId(),
								proEntity.getPlineCode() /*,tmsCon*/);
						if (!messe.equals("")) {
							core.setV_errMsg(messe);
							return core;
						}
						// 炉计划下发生成下工序虚拟炉计划
						String messeGx = PlanFurnProduction.addPlnFurn(
								proEntity.getProPlanId(),
								proEntity.getGxPlanNo(), username, strTime, "",
								proEntity.getPlnDivideId(), con);
						if (!messeGx.equals("")) {
							core.setV_errMsg(messeGx);
							return core;
						}

					} else if (processCode.equals("F")) {
						// 修改热处理炉计划状态
						String messe = StoveHelper.updatePlanRcl(
								proEntity.getProPlanId(),
								proEntity.getGxPlanNo(), username, strTime,
								"0", con, proEntity.getZyBatchId(),
								proEntity.getPlnDivideId(),
								proEntity.getPlineCode());
						if (!messe.equals("")) {
							core.setV_errMsg(messe);
							return core;
						}
					} else if (processCode.equals("G")) {
						// 修改加工线炉计划状态
						String messe = StoveHelper.updatePlanJgx(
								proEntity.getProPlanId(),
								proEntity.getGxPlanNo(), username, strTime,
								"0", con, proEntity.getZyBatchId(),
								proEntity.getPlnDivideId(),
								proEntity.getPlineCode());
						if (!messe.equals("")) {
							core.setV_errMsg(messe);
							return core;
						}
					} else if (processCode.equals("H")) {
						// 修改接箍炉计划状态
						String messe = StoveHelper.updatePlanJgM(
								proEntity.getProPlanId(),
								proEntity.getGxPlanNo(), username, strTime,
								"0", con, proEntity.getZyBatchId(),
								proEntity.getPlnDivideId());
						if (!messe.equals("")) {
							core.setV_errMsg(messe);
							return core;
						}
					}
					if(!processCode.equals("H")) {
						//新增CRM表
						String messCrm = ProducCrm.insertCrmD(con, proEntity, processCode, username,strTime);
						if (!messCrm.equals("")) {
							core.setV_errMsg(messCrm);
							return core;
						}
					}

				} else {
					proEntity.setIfStoveIssued("0");

					psta.setObject(1, proEntity.getIsPlanOk());
					psta.setObject(2, proEntity.getIssuedMan());
					psta.setObject(3, proEntity.getIssuedTime());
					psta.setObject(4, proEntity.getLastUndownMan());
					psta.setObject(5, proEntity.getLastUndownTime());
					psta.setObject(6, proEntity.getIfStoveIssued());
					psta.setObject(7, "");
					psta.setObject(8, "");
					psta.setObject(9, proEntity.getProPlanId());
					psta.setObject(10, proEntity.getGxPlanNo());
					psta.addBatch();
					if (processCode.equals("D")) {
						// 撤销下发轧管订单同时撤销下发炉计划
						String messe = StoveHelper.updateMilPlan(
								proEntity.getProPlanId(),
								proEntity.getGxPlanNo(), username, strTime,
								"1", con, proEntity.getZyBatchId(),
								proEntity.getPlineCode() /*,tmsCon*/);
						if (!messe.equals("")) {
							core.setV_errMsg(messe);
							return core;
						}
						// 炉计划撤销下工序虚拟炉计划
						String messeGx = PlanFurnProduction.deletePlnFurn(
								proEntity.getProPlanId(),
								proEntity.getGxPlanNo(), username, strTime, "",
								proEntity.getPlnDivideId(), con);
						if (!messeGx.equals("")) {
							core.setV_errMsg(messeGx);
							return core;
						}
					} else if (processCode.equals("F")) {
						// 修改热处理炉计划状态
						String messe = StoveHelper.updatePlanRcl(
								proEntity.getProPlanId(),
								proEntity.getGxPlanNo(), username, strTime,
								"1", con, proEntity.getZyBatchId(),
								proEntity.getPlnDivideId(),
								proEntity.getPlineCode());
						if (!messe.equals("")) {
							core.setV_errMsg(messe);
							return core;
						}
					} else if (processCode.equals("G")) {
						// 修改加工线炉计划状态
						String messe = StoveHelper.updatePlanJgx(
								proEntity.getProPlanId(),
								proEntity.getGxPlanNo(), username, strTime,
								"1", con, proEntity.getZyBatchId(),
								proEntity.getPlnDivideId(),
								proEntity.getPlineCode());
						if (!messe.equals("")) {
							core.setV_errMsg(messe);
							return core;
						}
					} else if (processCode.equals("H")) {
						// 修改接箍炉计划状态
						String messe = StoveHelper.updatePlanJgM(
								proEntity.getProPlanId(),
								proEntity.getGxPlanNo(), username, strTime,
								"1", con, proEntity.getZyBatchId(),
								proEntity.getPlnDivideId());
						if (!messe.equals("")) {
							core.setV_errMsg(messe);
							return core;
						}
					}
					if(!processCode.equals("H")) {


						//撤销下发新增CRM表
						String messCrm = ProducCrm.insertCrmDcancel(con, proEntity, processCode,username,strTime);
						if (!messCrm.equals("")) {
							core.setV_errMsg(messCrm);
							return core;
						}
					}
				}

  //tzh 24.10.23
				//TZH 24.10.31  没有连接新产销接口  暂时注释  等产销通了后开启
				//TZH 24.10.23  调用新增委托信息
//				if (isFlag.equals("0")) {
//
//					 
//					String  XX =proEntity.getObjEntity().toString();
//					JSONObject ObjEntity = JSONObject.fromObject(proEntity.getObjEntity());
//					
//					PlnOrderZgSEntity OrderZgSEntity = BaseHelper.jsonToEntity(
//							PlnOrderZgSEntity.class, ObjEntity.toString());
//
//					
//					
//					String	sql =  "select DESGIN_KEY,ORD_LN_PK from CRAFT_ORD_DESIGN_MSC t where t.ord_ln_pk = "
//							+ "(select ord_ln_pk from slm_order_line r where r.ord_pk "
//							+ " =(select ord_pk from slm_order_head where  order_no = '"+OrderZgSEntity.getOrderNo()+"')"
//									+ " and r.order_seq = '"+OrderZgSEntity.getOrderSeq()+"')";
//					String  s_desgin = "";
//					String  s_ln = "";
//					
//					PreparedStatement psM = con.prepareStatement(sql);
//					ResultSet rsM = psM.executeQuery();
//					if (rsM.next()) {
//						s_desgin = rsM.getString("DESGIN_KEY");
//						s_ln = rsM.getString("ORD_LN_PK");
//					}
//					rsM.close();
//					psM.close();
//					
//
//					
//					//TZH 24.10.31  没有连接新产销接口  暂时注释  等产销通了后开启
//				/////SaveCraftSamplingDetail(con,OrderZgSEntity.getCraftFileNo(),"D",s_desgin,s_ln,OrderZgSEntity.getOutnumCut());
//				}
			}
			psta.executeBatch();
			if (!processCode.equals("B")) {
				if (isFlag.equals("0")) {
					core.setV_errMsg("确认成功!");
				} else if (isFlag.equals("1")) {
					core.setV_errMsg("取消确认成功!");
				} else if (isFlag.equals("2")) {
					this.saveMesRclPlan(jsonList, true, con);
					core.setV_errMsg("炉计划下发成功!");
				} else {
					 this.saveMesRclPlan(jsonList, false, con);
					core.setV_errMsg("取消炉计划下发成功!");
				}
			} else {
				if (isFlag.equals("0")) {
					core.setV_errMsg("下发成功!");
				} else if (isFlag.equals("1")) {
					core.setV_errMsg("取消下发成功!");
				}
			}

			if(isFlag.equals("2") && !processCode.equals("H"))
			{
				//生成运输需求
				/*String msg = writeDemand.writeDemandPln(jsonList,processCode,username,tmsCon,con);
				if(!msg.equals(""))
				{
					core.setV_errMsg("炉计划下发时,生成运输需求出错!");
					return  core;
				}*/
			}
//			else if(isFlag.equals("3"))
//			{
//                //删除运输需求
//				String msg = writeDemand.cancelWriteDemandPln(jsonList,processCode,username,tmsCon,con);
//				if(!msg.equals(""))
//				{
//					core.setV_errMsg("炉计划撤销时,撤销运输需求出错!");
//					return  core;
//				}
//			}


			core.setResult(true);
			//测试暂时注销 24。10.23 tzh
			con.commit();
			//tmsCon.commit();;
			
		
			
		} catch (Exception e) {
			e.printStackTrace();
			try {
				if (con != null /*&& tmsCon !=null*/) {
					con.rollback();
					//tmsCon.rollback();;
				}
			} catch (Exception e1) {
				e1.printStackTrace();
			}
			core.setV_errMsg(e.getMessage());
		} finally {
			try {
				if (con != null && !con.isClosed())
					con.close();
				/*if (tmsCon != null && !tmsCon.isClosed())
					tmsCon.close();*/
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
		return core;
	}

	//TZH 24.10.23 新增委托信息在轧制二级排产下发
	public static void SaveCraftSamplingDetail(Connection con,String craft_no,String whole_backlog,String design_key,String ord_ln_pk,String num_cut) throws Exception{
    	PreparedStatement ps = null;
    	ResultSet rs = null;
    	int count = 0;
    	if(whole_backlog.contains("D")){
    		count = 0;
    		//先清空 
    		String sqlDM = XsSql.DeleteCraftSamplingTotal;
    		ps = new LoggableStatement(con, sqlDM);
    		ps.setString(1, craft_no);
    		rs = ps.executeQuery();
    		rs.close();
    		ps.close();
    		
    		
    		String sqlDD = XsSql.DeleteCraftSamplingDetail;
    		ps = new LoggableStatement(con, sqlDD);
    		ps.setString(1, craft_no);
    		rs = ps.executeQuery();
    		rs.close();
    		ps.close();
    		
    		String sql =  XsSql.getCraftPicSmpGroup;
    		ps = new LoggableStatement(con, sql);
    		ps.setString(1, craft_no);
    		ps.setString(2, "D");
    		ps.setString(3, design_key);
    		ps.setString(4, design_key);
    		ps.setString(5, "D");
    		ps.setString(6, ord_ln_pk);
    		ps.setString(7, design_key);
    		ps.setString(8, design_key);
    		ps.setString(9, "D");	    		
    		ps.setString(10, craft_no);
    		ps.setString(11, design_key);
    		ps.setString(12, "D");
    		ps.setString(13, design_key);
    		ps.setString(14, "D");
    		ps.setString(15, ord_ln_pk);
    		ps.setString(16, design_key);
    		ps.setString(17, "D");
    		System.out.println("Executing SQL:　"+((LoggableStatement)ps).getQueryString());
    		rs = ps.executeQuery();
    		JSONArray jacbc = Tools.resultSetToJsonArry(rs);
    		rs.close();
    		ps.close();
    		for(int i= 0;i<jacbc.size();i++){
	    		String Sql1 = XsSql.InsertCraftSamplingDetail;
				ps = new LoggableStatement(con,Sql1);
				ps.setString(1, jacbc.getJSONObject(i).getString("ORD_LN_PK"));
				ps.setString(2, jacbc.getJSONObject(i).getString("CRAFT_SEQ"));
				ps.setString(3, jacbc.getJSONObject(i).getString("CRAFT_NO"));
				ps.setString(4, jacbc.getJSONObject(i).getString("PROCESS_CODE"));
				ps.setString(5, jacbc.getJSONObject(i).getString("TYPE"));
				ps.setString(6,jacbc.getJSONObject(i).getString("SPLINE_NO"));
				ps.setString(7,jacbc.getJSONObject(i).getString("PHY_CODE_MIN"));
				ps.setString(8,jacbc.getJSONObject(i).getString("PHY_NAME_MIN"));
				ps.setString(9,jacbc.getJSONObject(i).getString("RATE"));
				ps.setString(10,jacbc.getJSONObject(i).getString("DESC_RATE"));
				ps.setString(11,jacbc.getJSONObject(i).getString("BATCH_UNIT"));
				ps.setString(12,jacbc.getJSONObject(i).getString("BATCH_CNT"));
				ps.setString(13,jacbc.getJSONObject(i).getString("BATCH_CNT"));
				ps.setString(14,jacbc.getJSONObject(i).getString("DESC_COUNT"));
				ps.setString(15,jacbc.getJSONObject(i).getString("SAMPLE_COUNT"));
				ps.setString(16,jacbc.getJSONObject(i).getString("POSITION"));
				ps.setString(17,jacbc.getJSONObject(i).getString("DESC_POSITION"));
				ps.setString(18,jacbc.getJSONObject(i).getString("LENGTH"));
				ps.setString(19,jacbc.getJSONObject(i).getString("WIDTH"));
				ps.setString(20,jacbc.getJSONObject(i).getString("SAMPLE_STYLE"));
				ps.setString(21,jacbc.getJSONObject(i).getString("SAMPLE_STYLE_DESC"));
				ps.setString(22,jacbc.getJSONObject(i).getString("PHY_CODE_GROUP"));
				ps.setString(23,jacbc.getJSONObject(i).getString("PHY_NAME_GROUP"));
				ps.setString(24,jacbc.getJSONObject(i).getString("ATTACH_PERCENT"));
				ps.setString(25,jacbc.getJSONObject(i).getString("ATTACH_COUNT"));
				ps.setString(26,jacbc.getJSONObject(i).getString("TOP_STOVE"));
				ps.setString(27,jacbc.getJSONObject(i).getString("LOOP_VALUE"));
				ps.setString(28,jacbc.getJSONObject(i).getString("PIC"));
				System.out.println("Executing SQL:　"+((LoggableStatement)ps).getQueryString());
				ps.execute();
			
				ps.close();
    		}
			sql = XsSql.getCraftPicSmpGroup1;
			ps = con.prepareStatement(sql);
			ps.setString(1, craft_no);
			ps.setString(2, "D");
			ps.setString(3, design_key);
			ps.setString(4, "D");
			ps.setString(5, design_key);
			ps.setString(6, "D");
			ps.setString(7, ord_ln_pk);
			ps.setString(8, ord_ln_pk);
			rs = ps.executeQuery();
    		jacbc = Tools.resultSetToJsonArry(rs);
    		rs.close();
    		ps.close();
    		for(int i= 0;i<jacbc.size();i++){
    			if(count ==0){
    				String Sql1 = XsSql.InsertCraftSamplingTotal;
		    		ps = new LoggableStatement(con,Sql1);
					ps.setString(1, jacbc.getJSONObject(i).getString("ORD_LN_PK"));
					ps.setString(2, jacbc.getJSONObject(i).getString("CRAFT_SEQ"));
					ps.setString(3, jacbc.getJSONObject(i).getString("CRAFT_NO"));
					ps.setString(4, jacbc.getJSONObject(i).getString("PROCESS_CODE"));
					ps.setString(5, jacbc.getJSONObject(i).getString("BATCH_NUM"));
					ps.setString(6, jacbc.getJSONObject(i).getString("BATCH_NO"));
					ps.setString(7, jacbc.getJSONObject(i).getString("SAMPLE_LENGTH"));
					ps.setString(8, jacbc.getJSONObject(i).getString("POSITION"));
					ps.setString(9, jacbc.getJSONObject(i).getString("DESC_POSITION"));
					ps.setString(10, num_cut); //取分切数 
					//ps.setString(10, jacbc.getJSONObject(i).getString("SAMPLE_COUNT"));
					ps.setString(11, jacbc.getJSONObject(i).getString("REMARK"));
					ps.setString(12, jacbc.getJSONObject(i).getString("PHY_NAME_GROUP"));
					ps.setString(13, jacbc.getJSONObject(i).getString("PHY_CODE_GROUP"));
					ps.setString(14, jacbc.getJSONObject(i).getString("STOVE_NUM"));
					ps.execute();
					System.out.println("Executing SQL:　"+((LoggableStatement)ps).getQueryString());
					ps.close();
    			}else{
    				String Sql1 = XsSql.InsertCraftSamplingTotal;
		    		ps = new LoggableStatement(con,Sql1);
					ps.setString(1, jacbc.getJSONObject(i).getString("ORD_LN_PK"));
					ps.setString(2, jacbc.getJSONObject(i).getString("CRAFT_SEQ"));
					ps.setString(3, jacbc.getJSONObject(i).getString("CRAFT_NO"));
					ps.setString(4, jacbc.getJSONObject(i).getString("PROCESS_CODE"));
					ps.setString(5, "1");
					ps.setString(6, "1");
					ps.setString(7, jacbc.getJSONObject(i).getString("SAMPLE_LENGTH"));
					ps.setString(8, jacbc.getJSONObject(i).getString("POSITION"));
					ps.setString(9, jacbc.getJSONObject(i).getString("DESC_POSITION"));
					ps.setString(10, "2");
					ps.setString(11, jacbc.getJSONObject(i).getString("REMARK"));
					ps.setString(12, jacbc.getJSONObject(i).getString("PHY_NAME_GROUP"));
					ps.setString(13, jacbc.getJSONObject(i).getString("PHY_CODE_GROUP"));
					ps.setString(14, jacbc.getJSONObject(i).getString("STOVE_NUM"));
					ps.execute();
					System.out.println("Executing SQL:　"+((LoggableStatement)ps).getQueryString());
					ps.close();
					Sql1 = XsSql.InsertCraftSamplingTotal;
		    		ps = new LoggableStatement(con,Sql1);
					ps.setString(1, jacbc.getJSONObject(i).getString("ORD_LN_PK"));
					ps.setString(2, jacbc.getJSONObject(i).getString("CRAFT_SEQ"));
					ps.setString(3, jacbc.getJSONObject(i).getString("CRAFT_NO"));
					ps.setString(4, jacbc.getJSONObject(i).getString("PROCESS_CODE"));
					ps.setString(5, "2");
					ps.setString(6, "1");
					ps.setString(7, jacbc.getJSONObject(i).getString("SAMPLE_LENGTH"));
					ps.setString(8, jacbc.getJSONObject(i).getString("POSITION"));
					ps.setString(9, jacbc.getJSONObject(i).getString("DESC_POSITION"));
					ps.setString(10, "2");
					ps.setString(11, jacbc.getJSONObject(i).getString("REMARK"));
					ps.setString(12, jacbc.getJSONObject(i).getString("PHY_NAME_GROUP"));
					ps.setString(13, jacbc.getJSONObject(i).getString("PHY_CODE_GROUP"));
					ps.setString(14, jacbc.getJSONObject(i).getString("STOVE_NUM"));
					ps.execute();
					System.out.println("Executing SQL:　"+((LoggableStatement)ps).getQueryString());
					ps.close();
					sql = XsSql.getCraftPicSmpGroup2;
					ps = new LoggableStatement(con,sql);
					ps.setString(1, craft_no);
					ps.setString(2, "D");
					ps.setString(3, design_key);
					ps.setString(4, "D");
					ps.setString(5, ord_ln_pk);
					ps.setString(6, "408602");
					ps.setString(7, design_key);
					ps.setString(8, "D");
					ps.setString(9, ord_ln_pk);
					ps.setString(10, "408602");
					ps.setString(11, ord_ln_pk);
					ps.setString(12, ord_ln_pk);
					System.out.println("Executing SQL:　"+((LoggableStatement)ps).getQueryString());
					rs = ps.executeQuery();
		    		jacbc = Tools.resultSetToJsonArry(rs);
		    		rs.close();
		    		ps.close();
		    		for(int j= 0;j<jacbc.size();j++){
		    			Sql1 = XsSql.InsertCraftSamplingTotal;
			    		ps = new LoggableStatement(con,Sql1);
						ps.setString(1, jacbc.getJSONObject(j).getString("ORD_LN_PK"));
						ps.setString(2, jacbc.getJSONObject(j).getString("CRAFT_SEQ"));
						ps.setString(3, jacbc.getJSONObject(j).getString("CRAFT_NO"));
						ps.setString(4, jacbc.getJSONObject(j).getString("PROCESS_CODE"));
						ps.setString(5, "2");
						ps.setString(6, "2");
						ps.setString(7, jacbc.getJSONObject(j).getString("SAMPLE_LENGTH"));
						ps.setString(8, jacbc.getJSONObject(j).getString("POSITION"));
						ps.setString(9, jacbc.getJSONObject(j).getString("DESC_POSITION"));
						ps.setString(10, "2");
						ps.setString(11, jacbc.getJSONObject(j).getString("REMARK"));
						ps.setString(12, jacbc.getJSONObject(j).getString("PHY_NAME_GROUP"));
						ps.setString(13, jacbc.getJSONObject(j).getString("PHY_CODE_GROUP"));
						ps.setString(14, jacbc.getJSONObject(j).getString("STOVE_NUM"));
						ps.execute();
						System.out.println("Executing SQL:　"+((LoggableStatement)ps).getQueryString());
						ps.close();
		    		}
    			}
    		}
    		con.commit();
    	}
    	/////////////////////
    	if(whole_backlog.contains("E")){
    		count = 0;
    		String sql =  XsSql.getCraftPicSmpGroup;
    		ps = con.prepareStatement(sql);
    		ps.setString(1, craft_no);
    		ps.setString(2, "E");
    		ps.setString(3, design_key);
    		ps.setString(4, design_key);
    		ps.setString(5, "E");
    		ps.setString(6, ord_ln_pk);
    		ps.setString(7, design_key);
    		ps.setString(8, design_key);
    		ps.setString(9, "E");	    		
    		ps.setString(10, craft_no);
    		ps.setString(11, design_key);
    		ps.setString(12, "E");
    		ps.setString(13, design_key);
    		ps.setString(14, "E");
    		ps.setString(15, ord_ln_pk);
    		ps.setString(16, design_key);
    		ps.setString(17, "E");
    		rs = ps.executeQuery();
    		JSONArray jacbc = Tools.resultSetToJsonArry(rs);
    		rs.close();
    		ps.close();
    		for(int i= 0;i<jacbc.size();i++){
	    		String Sql1 = XsSql.InsertCraftSamplingDetail;
				ps = new LoggableStatement(con,Sql1);
				ps.setString(1, jacbc.getJSONObject(i).getString("ORD_LN_PK"));
				ps.setString(2, jacbc.getJSONObject(i).getString("CRAFT_SEQ"));
				ps.setString(3, jacbc.getJSONObject(i).getString("CRAFT_NO"));
				ps.setString(4, jacbc.getJSONObject(i).getString("PROCESS_CODE"));
				ps.setString(5, jacbc.getJSONObject(i).getString("TYPE"));
				ps.setString(6,jacbc.getJSONObject(i).getString("SPLINE_NO"));
				ps.setString(7,jacbc.getJSONObject(i).getString("PHY_CODE_MIN"));
				ps.setString(8,jacbc.getJSONObject(i).getString("PHY_NAME_MIN"));
				ps.setString(9,jacbc.getJSONObject(i).getString("RATE"));
				ps.setString(10,jacbc.getJSONObject(i).getString("DESC_RATE"));
				ps.setString(11,jacbc.getJSONObject(i).getString("BATCH_UNIT"));
				ps.setString(12,jacbc.getJSONObject(i).getString("BATCH_CNT"));
				ps.setString(13,jacbc.getJSONObject(i).getString("BATCH_CNT"));
				ps.setString(14,jacbc.getJSONObject(i).getString("DESC_COUNT"));
				ps.setString(15,jacbc.getJSONObject(i).getString("SAMPLE_COUNT"));
				ps.setString(16,jacbc.getJSONObject(i).getString("POSITION"));
				ps.setString(17,jacbc.getJSONObject(i).getString("DESC_POSITION"));
				ps.setString(18,jacbc.getJSONObject(i).getString("LENGTH"));
				ps.setString(19,jacbc.getJSONObject(i).getString("WIDTH"));
				ps.setString(20,jacbc.getJSONObject(i).getString("SAMPLE_STYLE"));
				ps.setString(21,jacbc.getJSONObject(i).getString("SAMPLE_STYLE_DESC"));
				ps.setString(22,jacbc.getJSONObject(i).getString("PHY_CODE_GROUP"));
				ps.setString(23,jacbc.getJSONObject(i).getString("PHY_NAME_GROUP"));
				ps.setString(24,jacbc.getJSONObject(i).getString("ATTACH_PERCENT"));
				ps.setString(25,jacbc.getJSONObject(i).getString("ATTACH_COUNT"));
				ps.setString(26,jacbc.getJSONObject(i).getString("TOP_STOVE"));
				ps.setString(27,jacbc.getJSONObject(i).getString("LOOP_VALUE"));
				ps.setString(28,jacbc.getJSONObject(i).getString("PIC"));
				System.out.println("Executing SQL:　"+((LoggableStatement)ps).getQueryString());
				ps.execute();
				ps.close();
    		}
			sql = XsSql.getCraftPicSmpGroup1;
			ps = con.prepareStatement(sql);
			ps.setString(1, craft_no);
			ps.setString(2, "E");
			ps.setString(3, design_key);
			ps.setString(4, "E");
			ps.setString(5, design_key);
			ps.setString(6, "E");
			ps.setString(7, ord_ln_pk);
			ps.setString(8, ord_ln_pk);
			rs = ps.executeQuery();
    		jacbc = Tools.resultSetToJsonArry(rs);
    		rs.close();
    		ps.close();
    		for(int i= 0;i<jacbc.size();i++){
    			if(count ==0){
    				String Sql1 = XsSql.InsertCraftSamplingTotal;
		    		ps = new LoggableStatement(con,Sql1);
					ps.setString(1, jacbc.getJSONObject(i).getString("ORD_LN_PK"));
					ps.setString(2, jacbc.getJSONObject(i).getString("CRAFT_SEQ"));
					ps.setString(3, jacbc.getJSONObject(i).getString("CRAFT_NO"));
					ps.setString(4, jacbc.getJSONObject(i).getString("PROCESS_CODE"));
					ps.setString(5, jacbc.getJSONObject(i).getString("BATCH_NUM"));
					ps.setString(6, jacbc.getJSONObject(i).getString("BATCH_NO"));
					ps.setString(7, jacbc.getJSONObject(i).getString("SAMPLE_LENGTH"));
					ps.setString(8, jacbc.getJSONObject(i).getString("POSITION"));
					ps.setString(9, jacbc.getJSONObject(i).getString("DESC_POSITION"));
					ps.setString(10, jacbc.getJSONObject(i).getString("SAMPLE_COUNT"));
					ps.setString(11, jacbc.getJSONObject(i).getString("REMARK"));
					ps.setString(12, jacbc.getJSONObject(i).getString("PHY_NAME_GROUP"));
					ps.setString(13, jacbc.getJSONObject(i).getString("PHY_CODE_GROUP"));
					ps.setString(14, jacbc.getJSONObject(i).getString("STOVE_NUM"));
					ps.execute();
					System.out.println("Executing SQL:　"+((LoggableStatement)ps).getQueryString());
					ps.close();
    			}else{
    				String Sql1 = XsSql.InsertCraftSamplingTotal;
		    		ps = new LoggableStatement(con,Sql1);
					ps.setString(1, jacbc.getJSONObject(i).getString("ORD_LN_PK"));
					ps.setString(2, jacbc.getJSONObject(i).getString("CRAFT_SEQ"));
					ps.setString(3, jacbc.getJSONObject(i).getString("CRAFT_NO"));
					ps.setString(4, jacbc.getJSONObject(i).getString("PROCESS_CODE"));
					ps.setString(5, "1");
					ps.setString(6, "1");
					ps.setString(7, jacbc.getJSONObject(i).getString("SAMPLE_LENGTH"));
					ps.setString(8, jacbc.getJSONObject(i).getString("POSITION"));
					ps.setString(9, jacbc.getJSONObject(i).getString("DESC_POSITION"));
					ps.setString(10, "2");
					ps.setString(11, jacbc.getJSONObject(i).getString("REMARK"));
					ps.setString(12, jacbc.getJSONObject(i).getString("PHY_NAME_GROUP"));
					ps.setString(13, jacbc.getJSONObject(i).getString("PHY_CODE_GROUP"));
					ps.setString(14, jacbc.getJSONObject(i).getString("STOVE_NUM"));
					ps.execute();
					System.out.println("Executing SQL:　"+((LoggableStatement)ps).getQueryString());
					ps.close();
					Sql1 = XsSql.InsertCraftSamplingTotal;
		    		ps = new LoggableStatement(con,Sql1);
					ps.setString(1, jacbc.getJSONObject(i).getString("ORD_LN_PK"));
					ps.setString(2, jacbc.getJSONObject(i).getString("CRAFT_SEQ"));
					ps.setString(3, jacbc.getJSONObject(i).getString("CRAFT_NO"));
					ps.setString(4, jacbc.getJSONObject(i).getString("PROCESS_CODE"));
					ps.setString(5, "2");
					ps.setString(6, "1");
					ps.setString(7, jacbc.getJSONObject(i).getString("SAMPLE_LENGTH"));
					ps.setString(8, jacbc.getJSONObject(i).getString("POSITION"));
					ps.setString(9, jacbc.getJSONObject(i).getString("DESC_POSITION"));
					ps.setString(10, "2");
					ps.setString(11, jacbc.getJSONObject(i).getString("REMARK"));
					ps.setString(12, jacbc.getJSONObject(i).getString("PHY_NAME_GROUP"));
					ps.setString(13, jacbc.getJSONObject(i).getString("PHY_CODE_GROUP"));
					ps.setString(14, jacbc.getJSONObject(i).getString("STOVE_NUM"));
					ps.execute();
					System.out.println("Executing SQL:　"+((LoggableStatement)ps).getQueryString());
					ps.close();
					sql = XsSql.getCraftPicSmpGroup2;
					ps = new LoggableStatement(con,sql);
					ps.setString(1, craft_no);
					ps.setString(2, "E");
					ps.setString(3, design_key);
					ps.setString(4, "E");
					ps.setString(5, ord_ln_pk);
					ps.setString(6, "408602");
					ps.setString(7, design_key);
					ps.setString(8, "E");
					ps.setString(9, ord_ln_pk);
					ps.setString(10, "408602");
					ps.setString(11, ord_ln_pk);
					ps.setString(12, ord_ln_pk);
					System.out.println("Executing SQL:　"+((LoggableStatement)ps).getQueryString());
					rs = ps.executeQuery();
		    		jacbc = Tools.resultSetToJsonArry(rs);
		    		rs.close();
		    		ps.close();
		    		for(int j= 0;j<jacbc.size();j++){
		    			Sql1 = XsSql.InsertCraftSamplingTotal;
			    		ps = new LoggableStatement(con,Sql1);
						ps.setString(1, jacbc.getJSONObject(j).getString("ORD_LN_PK"));
						ps.setString(2, jacbc.getJSONObject(j).getString("CRAFT_SEQ"));
						ps.setString(3, jacbc.getJSONObject(j).getString("CRAFT_NO"));
						ps.setString(4, jacbc.getJSONObject(j).getString("PROCESS_CODE"));
						ps.setString(5, "2");
						ps.setString(6, "2");
						ps.setString(7, jacbc.getJSONObject(j).getString("SAMPLE_LENGTH"));
						ps.setString(8, jacbc.getJSONObject(j).getString("POSITION"));
						ps.setString(9, jacbc.getJSONObject(j).getString("DESC_POSITION"));
						ps.setString(10, "2");
						ps.setString(11, jacbc.getJSONObject(j).getString("REMARK"));
						ps.setString(12, jacbc.getJSONObject(j).getString("PHY_NAME_GROUP"));
						ps.setString(13, jacbc.getJSONObject(j).getString("PHY_CODE_GROUP"));
						ps.setString(14, jacbc.getJSONObject(j).getString("STOVE_NUM"));
						ps.execute();
						System.out.println("Executing SQL:　"+((LoggableStatement)ps).getQueryString());
						ps.close();
		    		}
    			}
    		}
    	}
    	if(whole_backlog.contains("F")){
    		count = 0;
    		String sql =  XsSql.getCraftPicSmpGroup;
    		ps = new LoggableStatement(con,sql);
    		ps.setString(1, craft_no);
    		ps.setString(2, "F");
    		ps.setString(3, design_key);
    		ps.setString(4, design_key);
    		ps.setString(5, "F");
    		ps.setString(6, ord_ln_pk);
    		ps.setString(7, design_key);
    		ps.setString(8, design_key);
    		ps.setString(9, "F");	    		
    		ps.setString(10, craft_no);
    		ps.setString(11, design_key);
    		ps.setString(12, "F");
    		ps.setString(13, design_key);
    		ps.setString(14, "F");
    		ps.setString(15, ord_ln_pk);
    		ps.setString(16, design_key);
    		ps.setString(17, "F");
    		rs = ps.executeQuery();
    		System.out.println("Executing SQL:　"+((LoggableStatement)ps).getQueryString());
    		JSONArray jacbc = Tools.resultSetToJsonArry(rs);
    		rs.close();
    		ps.close();
    		for(int i= 0;i<jacbc.size();i++){
	    		String Sql1 = XsSql.InsertCraftSamplingDetail;
				ps = new LoggableStatement(con,Sql1);
				ps.setString(1, jacbc.getJSONObject(i).getString("ORD_LN_PK"));
				ps.setString(2, jacbc.getJSONObject(i).getString("CRAFT_SEQ"));
				ps.setString(3, jacbc.getJSONObject(i).getString("CRAFT_NO"));
				ps.setString(4, jacbc.getJSONObject(i).getString("PROCESS_CODE"));
				ps.setString(5, jacbc.getJSONObject(i).getString("TYPE"));
				ps.setString(6,jacbc.getJSONObject(i).getString("SPLINE_NO"));
				ps.setString(7,jacbc.getJSONObject(i).getString("PHY_CODE_MIN"));
				ps.setString(8,jacbc.getJSONObject(i).getString("PHY_NAME_MIN"));
				ps.setString(9,jacbc.getJSONObject(i).getString("RATE"));
				ps.setString(10,jacbc.getJSONObject(i).getString("DESC_RATE"));
				ps.setString(11,jacbc.getJSONObject(i).getString("BATCH_UNIT"));
				ps.setString(12,jacbc.getJSONObject(i).getString("BATCH_CNT"));
				ps.setString(13,jacbc.getJSONObject(i).getString("BATCH_CNT"));
				ps.setString(14,jacbc.getJSONObject(i).getString("DESC_COUNT"));
				ps.setString(15,jacbc.getJSONObject(i).getString("SAMPLE_COUNT"));
				ps.setString(16,jacbc.getJSONObject(i).getString("POSITION"));
				ps.setString(17,jacbc.getJSONObject(i).getString("DESC_POSITION"));
				ps.setString(18,jacbc.getJSONObject(i).getString("LENGTH"));
				ps.setString(19,jacbc.getJSONObject(i).getString("WIDTH"));
				ps.setString(20,jacbc.getJSONObject(i).getString("SAMPLE_STYLE"));
				ps.setString(21,jacbc.getJSONObject(i).getString("SAMPLE_STYLE_DESC"));
				ps.setString(22,jacbc.getJSONObject(i).getString("PHY_CODE_GROUP"));
				ps.setString(23,jacbc.getJSONObject(i).getString("PHY_NAME_GROUP"));
				ps.setString(24,jacbc.getJSONObject(i).getString("ATTACH_PERCENT"));
				ps.setString(25,jacbc.getJSONObject(i).getString("ATTACH_COUNT"));
				ps.setString(26,jacbc.getJSONObject(i).getString("TOP_STOVE"));
				ps.setString(27,jacbc.getJSONObject(i).getString("LOOP_VALUE"));
				ps.setString(28,jacbc.getJSONObject(i).getString("PIC"));
				if(jacbc.getJSONObject(i).getString("DESC_RATE").equals("炉")){
					count++;
				}
				System.out.println("Executing SQL:　"+((LoggableStatement)ps).getQueryString());
				ps.execute();
				ps.close();
    		}
			sql = XsSql.getCraftPicSmpGroup1;
			ps = new LoggableStatement(con,sql);
			ps.setString(1, craft_no);
			ps.setString(2, "F");
			ps.setString(3, design_key);
			ps.setString(4, "F");
			ps.setString(5, design_key);
			ps.setString(6, "F");
			ps.setString(7, ord_ln_pk);
			ps.setString(8, ord_ln_pk);
			System.out.println("Executing SQL:　"+((LoggableStatement)ps).getQueryString());
			rs = ps.executeQuery();
    		jacbc = Tools.resultSetToJsonArry(rs);
    		rs.close();
    		ps.close();
    		for(int i= 0;i<jacbc.size();i++){
    			if(count ==0){
    				String Sql1 = XsSql.InsertCraftSamplingTotal;
		    		ps = new LoggableStatement(con,Sql1);
					ps.setString(1, jacbc.getJSONObject(i).getString("ORD_LN_PK"));
					ps.setString(2, jacbc.getJSONObject(i).getString("CRAFT_SEQ"));
					ps.setString(3, jacbc.getJSONObject(i).getString("CRAFT_NO"));
					ps.setString(4, jacbc.getJSONObject(i).getString("PROCESS_CODE"));
					ps.setString(5, jacbc.getJSONObject(i).getString("BATCH_NUM"));
					ps.setString(6, jacbc.getJSONObject(i).getString("BATCH_NO"));
					ps.setString(7, jacbc.getJSONObject(i).getString("SAMPLE_LENGTH"));
					ps.setString(8, jacbc.getJSONObject(i).getString("POSITION"));
					ps.setString(9, jacbc.getJSONObject(i).getString("DESC_POSITION"));
					ps.setString(10, jacbc.getJSONObject(i).getString("SAMPLE_COUNT"));
					ps.setString(11, jacbc.getJSONObject(i).getString("REMARK"));
					ps.setString(12, jacbc.getJSONObject(i).getString("PHY_NAME_GROUP"));
					ps.setString(13, jacbc.getJSONObject(i).getString("PHY_CODE_GROUP"));
					ps.setString(14, jacbc.getJSONObject(i).getString("STOVE_NUM"));
					ps.execute();
					System.out.println("Executing SQL:　"+((LoggableStatement)ps).getQueryString());
					ps.close();
    			}else{
    				String Sql1 = XsSql.InsertCraftSamplingTotal;
		    		ps = new LoggableStatement(con,Sql1);
					ps.setString(1, jacbc.getJSONObject(i).getString("ORD_LN_PK"));
					ps.setString(2, jacbc.getJSONObject(i).getString("CRAFT_SEQ"));
					ps.setString(3, jacbc.getJSONObject(i).getString("CRAFT_NO"));
					ps.setString(4, jacbc.getJSONObject(i).getString("PROCESS_CODE"));
					ps.setString(5, "1");
					ps.setString(6, "1");
					ps.setString(7, jacbc.getJSONObject(i).getString("SAMPLE_LENGTH"));
					ps.setString(8, jacbc.getJSONObject(i).getString("POSITION"));
					ps.setString(9, jacbc.getJSONObject(i).getString("DESC_POSITION"));
					ps.setString(10, "2");
					ps.setString(11, jacbc.getJSONObject(i).getString("REMARK"));
					ps.setString(12, jacbc.getJSONObject(i).getString("PHY_NAME_GROUP"));
					ps.setString(13, jacbc.getJSONObject(i).getString("PHY_CODE_GROUP"));
					ps.setString(14, jacbc.getJSONObject(i).getString("STOVE_NUM"));
					ps.execute();
					System.out.println("Executing SQL:　"+((LoggableStatement)ps).getQueryString());
					ps.close();
					Sql1 = XsSql.InsertCraftSamplingTotal;
		    		ps = new LoggableStatement(con,Sql1);
					ps.setString(1, jacbc.getJSONObject(i).getString("ORD_LN_PK"));
					ps.setString(2, jacbc.getJSONObject(i).getString("CRAFT_SEQ"));
					ps.setString(3, jacbc.getJSONObject(i).getString("CRAFT_NO"));
					ps.setString(4, jacbc.getJSONObject(i).getString("PROCESS_CODE"));
					ps.setString(5, "2");
					ps.setString(6, "1");
					ps.setString(7, jacbc.getJSONObject(i).getString("SAMPLE_LENGTH"));
					ps.setString(8, jacbc.getJSONObject(i).getString("POSITION"));
					ps.setString(9, jacbc.getJSONObject(i).getString("DESC_POSITION"));
					ps.setString(10, "2");
					ps.setString(11, jacbc.getJSONObject(i).getString("REMARK"));
					ps.setString(12, jacbc.getJSONObject(i).getString("PHY_NAME_GROUP"));
					ps.setString(13, jacbc.getJSONObject(i).getString("PHY_CODE_GROUP"));
					ps.setString(14, jacbc.getJSONObject(i).getString("STOVE_NUM"));
					ps.execute();
					//System.out.println("Executing SQL:　"+((LoggableStatement)ps).getQueryString());
					ps.close();
					sql = XsSql.getCraftPicSmpGroup2;
					ps = new LoggableStatement(con,sql);
					ps.setString(1, craft_no);
					ps.setString(2, "F");
					ps.setString(3, design_key);
					ps.setString(4, "F");
					ps.setString(5, ord_ln_pk);
					ps.setString(6, "408602");
					ps.setString(7, design_key);
					ps.setString(8, "F");
					ps.setString(9, ord_ln_pk);
					ps.setString(10, "408602");
					ps.setString(11, ord_ln_pk);
					ps.setString(12, ord_ln_pk);
					//System.out.println("Executing SQL:　"+((LoggableStatement)ps).getQueryString());
					rs = ps.executeQuery();
		    		jacbc = Tools.resultSetToJsonArry(rs);
		    		rs.close();
		    		ps.close();
		    		for(int j= 0;j<jacbc.size();j++){
		    			Sql1 = XsSql.InsertCraftSamplingTotal;
			    		ps = new LoggableStatement(con,Sql1);
						ps.setString(1, jacbc.getJSONObject(j).getString("ORD_LN_PK"));
						ps.setString(2, jacbc.getJSONObject(j).getString("CRAFT_SEQ"));
						ps.setString(3, jacbc.getJSONObject(j).getString("CRAFT_NO"));
						ps.setString(4, jacbc.getJSONObject(j).getString("PROCESS_CODE"));
						ps.setString(5, "2");
						ps.setString(6, "2");
						ps.setString(7, jacbc.getJSONObject(j).getString("SAMPLE_LENGTH"));
						ps.setString(8, jacbc.getJSONObject(j).getString("POSITION"));
						ps.setString(9, jacbc.getJSONObject(j).getString("DESC_POSITION"));
						ps.setString(10, "2");
						ps.setString(11, jacbc.getJSONObject(j).getString("REMARK"));
						ps.setString(12, jacbc.getJSONObject(j).getString("PHY_NAME_GROUP"));
						ps.setString(13, jacbc.getJSONObject(j).getString("PHY_CODE_GROUP"));
						ps.setString(14, jacbc.getJSONObject(j).getString("STOVE_NUM"));
						ps.execute();
						//System.out.println("Executing SQL:　"+((LoggableStatement)ps).getQueryString());
						ps.close();
		    		}
    			}
	    		
    		}
    		
    	}
    	
    }
	/**
	 * 查询炼轧系统数据
	 * 
	 * @return
	 */
	public CoreReturnObject queryLZData() {
		String sql = CoreXmlSqlParsersFactory
				.getSql("ProducHelperBean.queryLZData");
		return this.getDao("MSSQL2Dao").ExcuteSortResultByQuery(sql);
	}

	/**
	 * 查询轧管炼轧系统数据
	 * 
	 * @return
	 */
	public CoreReturnObject queryLZDataZg() {
		String sql = CoreXmlSqlParsersFactory
				.getSql("ProducHelperBean.queryLZDataZg");
		return this.getDao("MSSQL2Dao").ExcuteSortResultByQuery(sql);
	}

	/**
	 * 查询管坯对应锻造排产信息
	 * 
	 * @param
	 *            　
	 * @return CoreReturnObject
	 */
	public CoreReturnObject queryPlanOrderCGP(String gpreqId) {
		String sql = CoreXmlSqlParsersFactory
				.getSql("ProducHelperBean.queryPlanOrderC");
		if (!gpreqId.equals("")) {
			sql += " AND T.PRO_PLAN_ID='" + gpreqId + "'";
		}
		sql += "  ORDER BY TO_NUMBER(T.GX_PRO_SEQ)";
		return this.getData(sql);
	}

	/**
	 * 查询管坯对应铸造排产信息
	 * 
	 * @param
	 *            　
	 * @return CoreReturnObject
	 */
	public CoreReturnObject queryPlanOrderBGP(String gpreqId) {
		String sql = CoreXmlSqlParsersFactory
				.getSql("ProducHelperBean.queryPlanOrderB");
		if (!gpreqId.equals("")) {
			sql += " AND T.PRO_PLAN_ID='" + gpreqId + "'";
		}
		sql += "  ORDER BY TO_NUMBER(T.GX_PRO_SEQ)";
		return this.getData(sql);
	}

	/**
	 * 查询备料需求与成品合同对应关系
	 * 
	 * @return
	 */
	public CoreReturnObject queryOrderBlReq(String proPlanId, String orderNo,String jgOrderNo) {
		String sql = CoreXmlSqlParsersFactory
				.getSql("ProducHelperBean.queryOrderBlReq");
		if (!orderNo.equals("")) {
			sql += " AND T.ORDER_NO || '/' || T.ORDER_SEQ like '%'||'"
					+ orderNo + "'||'%'";
		}
		if (!proPlanId.equals("")) {
			sql += " AND T.REQ_BL_ID LIKE '%'||'" + proPlanId + "'||'%'";
		}
		if (!jgOrderNo.equals("")) {
			sql += " AND T.JG_ORDERNO LIKE '%'||'" + jgOrderNo + "'||'%'";
		}
		sql += "  ORDER BY T.CREATE_TIME DESC";
		return this.getData(sql);

	}

	/**
	 * 查询铸造排产(界面)
	 * 
	 * @param plineCode
	 * @param proPlanId
	 * @param statusArr
	 * @return
	 */
	public CoreReturnObject queryPlanOrderB(String plineCode, String proPlanId,
			String[] statusArr) {
		String sql = CoreXmlSqlParsersFactory
				.getSql("ProducHelperBean.queryPlanOrderB");
		List<String> params = new ArrayList<String>();
		if (!plineCode.equals("")) {
			params.add(plineCode);
			sql += " AND T.PLINE_CODE=? ";
		}
		if (!proPlanId.equals("")) {
			params.add(proPlanId);
			sql += " AND T.PRO_PLAN_ID LIKE '%'||?||'%'";
		}
		if (statusArr.length > 0) {
			sql += CoreConverter
					.toSqlConditionString("T.EXE_STATUS", statusArr);
		}
		sql += "  ORDER BY  T.PLINE_CODE,TO_NUMBER(T.GX_PRO_SEQ)";
		return this.getData(sql, params.toArray());

	}

	/**
	 * 查询锻造排产信息(界面展示)
	 * 
	 * @param plineCode
	 *            产线
	 * @param proPlanId
	 *            　订单编号
	 * @param
	 *            　
	 * @return CoreReturnObject
	 */
	public CoreReturnObject queryPlanOrderC(String plineCode, String proPlanId,
			String[] statusArr) {
		String sql = CoreXmlSqlParsersFactory
				.getSql("ProducHelperBean.queryPlanOrderC");
		List<String> params = new ArrayList<String>();
		if (!plineCode.equals("")) {
			params.add(plineCode);
			sql += " AND T.PLINE_CODE=? ";
		}
		if (!proPlanId.equals("")) {
			params.add(proPlanId);
			sql += " AND T.PRO_PLAN_ID = ?";
		}
		if (statusArr.length > 0) {
			sql += CoreConverter
					.toSqlConditionString("T.EXE_STATUS", statusArr);
		}
		sql += "  ORDER BY  T.PLINE_CODE,TO_NUMBER(T.GX_PRO_SEQ)";
		return this.getData(sql, params.toArray());
	}

	/**
	 * 查询产线余与去向仓库分组
	 * 
	 * @return CoreReturnObject
	 */
	public CoreReturnObject queryPlinCodeGroup() {
		String sql = CoreXmlSqlParsersFactory
				.getSql("ProducHelperBean.queryPlinCodeGroup");
		return this.getData(sql);
	}



	/**
	 * 查询轧管排产(界面展示)
	 * 
	 * @param plineCode
	 *            产线
	 * @param proPlanId
	 *            　订单编号
	 * @param orderNo
	 *            　合同号
	 * @param statusArray
	 *            　生产状态
	 * @return CoreReturnObject
	 */
	public CoreReturnObject queryPlanOrderD(String[] plineCode,
			String proPlanId, String orderNo, String[] statusArray,
			String planTimeB1, String planTimeB2, String planTimeE1,
			String planTimeE2, String comPlineCode,String lotNoStart,String lotNoEnd) {
		String sql = CoreXmlSqlParsersFactory
				.getSql("ProducHelperBean.queryPlanOrderD");
		List<String> params = new ArrayList<String>();
		if (!comPlineCode.equals("")) {
			params.add(comPlineCode);
			sql += " AND T.PLINE_CODE=? ";
		} else {
			sql += CoreConverter.toSqlConditionString("PLINE_CODE", plineCode);
		}
		if (!proPlanId.equals("")) {
			params.add(proPlanId);
			sql += " AND T.PRO_PLAN_ID LIKE '%'||?||'%'";
		}
		if (!orderNo.equals("")) {
			params.add(orderNo);
			sql += " AND T.ORDER_NO||'/'||T.ORDER_SEQ LIKE '%'||?||'%'";
		}
		if (!planTimeB1.equals("") && !planTimeB2.equals("")) {
			params.add(planTimeB1);
			params.add(planTimeB2);
			sql += " AND T.PLAN_TIME_B BETWEEN TO_DATE(?,'YYYY-MM-DD HH24:MI:SS') AND TO_DATE(?,'YYYY-MM-DD HH24:MI:SS') ";
		}
		if (!planTimeE1.equals("") && !planTimeE2.equals("")) {
			params.add(planTimeE1);
			params.add(planTimeE2);
			sql += " AND T.PLAN_TIME_E BETWEEN TO_DATE(?,'YYYY-MM-DD HH24:MI:SS') AND TO_DATE(?,'YYYY-MM-DD HH24:MI:SS') ";
		}
		if(!lotNoStart.equals("") && !lotNoEnd.equals(""))
		{
			sql += " AND T.ZY_BATCH_ID >= '"+lotNoStart+"' AND T.ZY_BATCH_ID <='"+lotNoEnd+"'";
		}
		if (statusArray.length > 0) {
			sql += CoreConverter.toSqlConditionString("T.EXE_STATUS",
					statusArray);
		}
		sql += "  ORDER BY  T.PLINE_CODE,TO_NUMBER(T.GX_PRO_SEQ)";
		System.out.print(sql);
		return this.getData(sql, params.toArray());
	}

	/*
	 * tzh 2024.8.7 add  
	 */
	public CoreReturnObject queryPlanOrderCxMes(String orderNo) {
		String sql = CoreXmlSqlParsersFactory
				.getSql("ProducHelperBean.queryPlanOrderCxMes");
		List<String> params = new ArrayList<String>();

		if (!orderNo.equals("")) {
			params.add(orderNo);
			sql += " AND PLAN_NO like '%'||?||'%' ";
		}
		
	//	sql += "  ORDER BY  T.PLINE_CODE,TO_NUMBER(T.GX_PRO_SEQ)";
		
		return this.getData(sql, params.toArray());
	}
	
	/*
	 * tzh 2024.8.7 add  
	 */
	public CoreReturnObject queryMandrelSpec(String No) {
		String sql =" ";
		List<String> params = new ArrayList<String>();
		if (No.equals("1")) {
			sql += " select distinct  t.diameter_mandrel AS XX from Com_Base_Mandrel_Spec t where t.pline_name = '天淮508机组' ";
		}
		if (No.equals("2")) {
			sql += " select distinct pass_name AS XX  from Com_Base_Mandrel_Spec t where t.pline_name = '天淮508机组' ";
		}
		if (No.equals("3")) {
			sql += " select distinct wg_d AS XX  from Com_Base_Mandrel_Spec t where t.pline_name = '天淮508机组' ";
		}
		if (No.equals("4")) {
			sql += " select distinct wg_h AS XX  from Com_Base_Mandrel_Spec t where t.pline_name = '天淮508机组' ";
		}
		return this.getData(sql, params.toArray());
	}
	
	/*
	 * tzh 2024.8.7 add  
	 */
	public CoreReturnObject queryMandrelSpec(String Pass,String Xbzj) {
		String sql =" ";
		List<String> params = new ArrayList<String>();
		if (!Pass.equals("")&&!Xbzj.equals("")) {
			params.add(Pass);
			params.add(Xbzj);
			sql += " select  wg_d,wg_h from Com_Base_Mandrel_Spec t where t.pline_name = '天淮508机组' and pass_name = ? and diameter_mandrel = ?  and rownum =1 ";
		}
		
		return this.getData(sql, params.toArray());
	}
	
	public CoreReturnObject queryPlanOrderDEasy(String[] plineCode,
											String proPlanId, String orderNo, String[] statusArray,
											String planTimeB1, String planTimeB2, String planTimeE1,
											String planTimeE2, String comPlineCode) {
		String sql = CoreXmlSqlParsersFactory
				.getSql("ProducHelperBean.queryPlanOrderDEasy");
		List<String> params = new ArrayList<String>();
		if (!comPlineCode.equals("")) {
			params.add(comPlineCode);
			sql += " AND T.PLINE_CODE=? ";
		} else {
			sql += CoreConverter.toSqlConditionString("PLINE_CODE", plineCode);
		}
		if (!proPlanId.equals("")) {
			params.add(proPlanId);
			sql += " AND T.PRO_PLAN_ID LIKE '%'||?||'%'";
		}
		if (!orderNo.equals("")) {
			params.add(orderNo);
			sql += " AND T.ORDER_NO||'/'||T.ORDER_SEQ LIKE '%'||?||'%'";
		}
		if (!planTimeB1.equals("") && !planTimeB2.equals("")) {
			params.add(planTimeB1);
			params.add(planTimeB2);
			sql += " AND T.PLAN_TIME_B BETWEEN TO_DATE(?,'YYYY-MM-DD HH24:MI:SS') AND TO_DATE(?,'YYYY-MM-DD HH24:MI:SS') ";
		}
		if (!planTimeE1.equals("") && !planTimeE2.equals("")) {
			params.add(planTimeE1);
			params.add(planTimeE2);
			sql += " AND T.PLAN_TIME_E BETWEEN TO_DATE(?,'YYYY-MM-DD HH24:MI:SS') AND TO_DATE(?,'YYYY-MM-DD HH24:MI:SS') ";
		}
		if (statusArray.length > 0) {
			sql += CoreConverter.toSqlConditionString("T.EXE_STATUS",
					statusArray);
		}
		sql += "  ORDER BY  T.PLINE_CODE,TO_NUMBER(T.GX_PRO_SEQ)";
		return this.getData(sql, params.toArray());
	}

	/**
	 * 查询镦拔扩排产(界面展示)
	 * 
	 * @param plineCode
	 * @param
	 * @param
	 * @return
	 */
	public CoreReturnObject queryPlanOrderE(String plineCode, String orderNo,
			String proPlanId, String[] statusArray, String[] plinePower,
			String flag, String planTimeB1, String planTimeB2,
			String planTimeE1, String planTimeE2) {
		String sql = CoreXmlSqlParsersFactory
				.getSql("ProducHelperBean.queryPlanOrderE");
		List<String> params = new ArrayList<String>();
		if (!plineCode.equals("")) {
			sql += " AND T.PLINE_CODE=? ";
			params.add(plineCode);
		} else {
			sql += CoreConverter.toSqlConditionString("T.PLINE_CODE",
					plinePower);

		}
		if (!proPlanId.equals("")) {
			params.add(proPlanId);
			sql += " AND T.PRO_PLAN_ID LIKE '%'||?||'%'";
		}
		if (!orderNo.equals("")) {
			params.add(orderNo);
			sql += " AND T.ORDER_NO||'/'||T.ORDER_SEQ LIKE '%'||?||'%'";
		}
		sql += CoreConverter.toSqlConditionString("T.EXE_STATUS", statusArray);

		if (flag.equals("1")) {
			sql += " AND T.IF_STOVE_ISSUED='1' ";
		}
		if (!planTimeB1.equals("") && !planTimeB2.equals("")) {
			params.add(planTimeB1);
			params.add(planTimeB2);
			sql += " AND T.PLAN_TIME_B BETWEEN TO_DATE(?,'YYYY-MM-DD HH24:MI:SS') AND TO_DATE(?,'YYYY-MM-DD HH24:MI:SS') ";
		}
		if (!planTimeE1.equals("") && !planTimeE2.equals("")) {
			params.add(planTimeE1);
			params.add(planTimeE2);
			sql += " AND T.PLAN_TIME_E BETWEEN TO_DATE(?,'YYYY-MM-DD HH24:MI:SS') AND TO_DATE(?,'YYYY-MM-DD HH24:MI:SS') ";
		}
		sql += " ORDER BY T.PLINE_CODE,TO_NUMBER(T.GX_PRO_SEQ)";
		return this.getData(sql, params.toArray());
	}

	/**
	 * 查询热处理排产(界面展示)
	 * 
	 * @param plineCode
	 *            产线代码
	 * @param
	 *
	 * @param orderNo
	 *            合同号
	 * @return
	 */
	public CoreReturnObject queryPlanOrderF(String plineCode, String proPlanId,
			String orderNo, String group, String[] statusArray,
			String planTimeB1, String planTimeB2, String planTimeE1,
			String planTimeE2) {
		String sql = CoreXmlSqlParsersFactory
				.getSql("ProducHelperBean.queryPlanOrderF");
		List<String> params = new ArrayList<String>();
		if (!plineCode.equals("")) {
			params.add(plineCode);
			sql += " AND T.PLINE_CODE=? ";
		}
		if (!proPlanId.equals("")) {
			params.add(proPlanId);
			sql += " AND T.PRO_PLAN_ID LIKE '%'||?||'%' ";
		}
		if (!orderNo.equals("")) {
			params.add(orderNo);
			sql += " AND T.ORDER_NO||'/'||T.ORDER_SEQ LIKE '%'||?||'%' ";
		}
		if (!group.equals("")) {
			params.add(group);
			sql += " AND T3.GROUP_RCL=? ";
		}
		if (statusArray.length > 0) {
			sql += CoreConverter.toSqlConditionString("T.EXE_STATUS",
					statusArray);
		}
		if (!planTimeB1.equals("") && !planTimeB2.equals("")) {
			params.add(planTimeB1);
			params.add(planTimeB2);
			sql += " AND T.PLAN_TIME_B BETWEEN TO_DATE(?,'YYYY-MM-DD HH24:MI:SS') AND TO_DATE(?,'YYYY-MM-DD HH24:MI:SS') ";
		}
		if (!planTimeE1.equals("") && !planTimeE2.equals("")) {
			params.add(planTimeE1);
			params.add(planTimeE2);
			sql += " AND T.PLAN_TIME_E BETWEEN TO_DATE(?,'YYYY-MM-DD HH24:MI:SS') AND TO_DATE(?,'YYYY-MM-DD HH24:MI:SS') ";
		}
		sql += " order by t.pline_code,to_number(t.gx_pro_seq)";
		return this.getData(sql, params.toArray());
	}

	/**
	 * 查询加工排产(界面展示)
	 * 
	 * @param plineCode
	 *            产线代码
	 * @param proPlanId
	 *            　订单编号
	 * @param orderNo
	 *            　合同号
	 * @param statusArray
	 *            　状态
	 * @return CoreReturnObject
	 */
	public CoreReturnObject queryPlanOrderG(String plineCode, String proPlanId,
			String orderNo, String group, String[] statusArray,
			String planTimeB1, String planTimeB2, String planTimeE1,
			String planTimeE2,String proName) {
		String sql = CoreXmlSqlParsersFactory
				.getSql("ProducHelperBean.queryPlanOrderG");
		List<String> params = new ArrayList<String>();
		if (!plineCode.equals("")) {
			params.add(plineCode);
			sql += " AND T.PLINE_CODE=? ";
		}
		if (!proPlanId.equals("")) {
			params.add(proPlanId);
			sql += " AND T.PRO_PLAN_ID LIKE '%'||?||'%' ";
		}
		if (!orderNo.equals("")) {
			params.add(orderNo);
			sql += " AND T.ORDER_NO||'/'||T.ORDER_SEQ LIKE '%'||?||'%'";
		}
		if (!group.equals("")) {
			params.add(group);
			sql += " AND T1.GROUP_JGX=? ";
		}
		if (statusArray.length > 0) {
			sql += CoreConverter.toSqlConditionString("T.EXE_STATUS",
					statusArray);
		}
		if (!planTimeB1.equals("") && !planTimeB2.equals("")) {
			params.add(planTimeB1);
			params.add(planTimeB2);
			sql += " AND T.PLAN_TIME_B BETWEEN TO_DATE(?,'YYYY-MM-DD HH24:MI:SS') AND TO_DATE(?,'YYYY-MM-DD HH24:MI:SS') ";
		}
		if (!planTimeE1.equals("") && !planTimeE2.equals("")) {
			params.add(planTimeE1);
			params.add(planTimeE2);
			sql += " AND T.PLAN_TIME_E BETWEEN TO_DATE(?,'YYYY-MM-DD HH24:MI:SS') AND TO_DATE(?,'YYYY-MM-DD HH24:MI:SS') ";
		}
		if(proName.equals("1"))
		{
			sql += " AND S.PRODUCNAME = '短节管体料'";
		}
		sql += "  ORDER BY T.PLINE_CODE, TO_NUMBER(T.GX_PRO_SEQ)";
		return this.getData(sql, params.toArray());
	}
	/**
	 * 查询加工排产(界面展示)
	 * 
	 * @param plineCode
	 *            产线代码
	 * @param proPlanId
	 *            　订单编号
	 * @param orderNo
	 *            　合同号
	 * @param statusArray
	 *            　状态
	 * @return CoreReturnObject
	 */
	public CoreReturnObject queryPlanOrderG1(String plineCode, String proPlanId,
			String orderNo, String group, String[] statusArray,
			String planTimeB1, String planTimeB2, String planTimeE1,
			String planTimeE2) {
		String sql = CoreXmlSqlParsersFactory
				.getSql("ProducHelperBean.queryPlanOrderG");
		List<String> params = new ArrayList<String>();
		if (!plineCode.equals("")) {
			params.add(plineCode);
			sql += " AND T.PLINE_CODE=? ";
		}
		if (!proPlanId.equals("")) {
			params.add(proPlanId);
			sql += " AND T.PRO_PLAN_ID LIKE '%'||?||'%' ";
		}
		if (!orderNo.equals("")) {
			params.add(orderNo);
			sql += " AND T.ORDER_NO||'/'||T.ORDER_SEQ LIKE '%'||?||'%'";
		}
		if (!group.equals("")) {
			params.add(group);
			sql += " AND T1.GROUP_JGX=? ";
		}
		if (statusArray.length > 0) {
			sql += CoreConverter.toSqlConditionString("T.EXE_STATUS",
					statusArray);
		}
		if (!planTimeB1.equals("") && !planTimeB2.equals("")) {
			params.add(planTimeB1);
			params.add(planTimeB2);
			sql += " AND T.PLAN_TIME_B BETWEEN TO_DATE(?,'YYYY-MM-DD HH24:MI:SS') AND TO_DATE(?,'YYYY-MM-DD HH24:MI:SS') ";
		}
		if (!planTimeE1.equals("") && !planTimeE2.equals("")) {
			params.add(planTimeE1);
			params.add(planTimeE2);
			sql += " AND T.PLAN_TIME_E BETWEEN TO_DATE(?,'YYYY-MM-DD HH24:MI:SS') AND TO_DATE(?,'YYYY-MM-DD HH24:MI:SS') ";
		}
		
		sql += "  ORDER BY T.PLINE_CODE, TO_NUMBER(T.GX_PRO_SEQ)";
		return this.getData(sql, params.toArray());
	}

	/**
	 * 查询接箍排产(界面展示)
	 * 
	 * @param plineCode
	 *            产线代码
	 * @param
	 *
	 * @param
	 *
	 * @return
	 */
	public CoreReturnObject queryPlanOrderH(String plineCode, String proPlanId,
			String jgCode, String[] statusArray, String planTimeB1,
			String planTimeB2, String planTimeE1, String planTimeE2,String orderSeq) {
		String sql = CoreXmlSqlParsersFactory
				.getSql("ProducHelperBean.queryPlanOrderH");
		List<String> params = new ArrayList<String>();
		if (!plineCode.equals("")) {
			params.add(plineCode);
			sql += " AND T.PLINE_CODE=? ";
		}
		if (!proPlanId.equals("")) {
			params.add(proPlanId);
			sql += " AND T.PRO_PLAN_ID LIKE '%'||?||'%' ";
		}
		if (!jgCode.equals("")) {
			params.add(jgCode);
			sql += " AND T.CODE_JG=? ";
		}
		if (statusArray.length > 0) {
			sql += CoreConverter.toSqlConditionString("T.EXE_STATUS",
					statusArray);
		}
		if (!planTimeB1.equals("") && !planTimeB2.equals("")) {
			params.add(planTimeB1);
			params.add(planTimeB2);
			sql += " AND T.PLAN_TIME_B BETWEEN TO_DATE(?,'YYYY-MM-DD HH24:MI:SS') AND TO_DATE(?,'YYYY-MM-DD HH24:MI:SS') ";
		}
		if (!planTimeE1.equals("") && !planTimeE2.equals("")) {
			params.add(planTimeE1);
			params.add(planTimeE2);
			sql += " AND T.PLAN_TIME_E BETWEEN TO_DATE(?,'YYYY-MM-DD HH24:MI:SS') AND TO_DATE(?,'YYYY-MM-DD HH24:MI:SS') ";
		}
		if(!orderSeq.equals("")){
			sql += " AND T.ORD_LN_DLY_PK LIKE '%'||'"+orderSeq+"'||'%' ";
		}
		sql += " order by t.pline_code,to_number(t.GX_pro_seq)";
		return this.getData(sql, params.toArray());
	}

	/**
	 * 排产拆分
	 * 
	 * @param jsonStr
	 * @param
	 *
	 * @param
	 *
	 * @param processCode
	 *            工序
	 * @return
	 */
	public CoreReturnObject spitPlanOrder(String jsonStr, String spitWgtStr,
			String spitNumStr, String processCode) {
		CoreReturnObject core = new CoreReturnObject();
		core.setResult(false);
		Connection con = null;
		try {
			double spitWgt = Double.parseDouble(spitWgtStr);
			int spitNum = Integer.parseInt(spitNumStr);
			con = this.getDao(CoreConstantData.sysbeanstr).getConnection();
			con.setAutoCommit(false);
			ProducHelperBean helperBean = new ProducHelperBean();
			ProducEntity proEntity = helperBean.genertionProEntity(con,
					jsonStr, processCode);
			/**
			 * 1.验证数据
			 */
			if (proEntity == null) {
				core.setV_errMsg("数据异常,请刷新数据!");
				return core;
			}
			if (!processCode.equals("D")) {
				// if (proEntity.getIfStoveIssued().equals("1")) {
				// core.setV_errMsg("订单编号(" + proEntity.getProPlanId()
				// + ") 炉计划已经下发!");
				// return core;
				// }
			}
			if (!proEntity.getExeStatus().equals("0")
					&& !proEntity.getExeStatus().equals("1")) {
				core.setV_errMsg("订单编号(" + proEntity.getProPlanId()
						+ ")/不是 (计划/生产中)执行状态!");
				return core;
			}
			// if (proEntity.getIsPlanOk().equals("1")) {
			// core.setV_errMsg("订单编号(" + proEntity.getProPlanId() + ") 已确认!");
			// return core;
			// }
			// 1.2验证产线能力
			double[] capacity = helperBean.getPlineCapacity(con,
					proEntity.getInwlId(), proEntity.getOutwlId(),
					proEntity.getPlineCode(), processCode);

			if (capacity[0] <= 0) {
				if (!processCode.equals("B")) {
					core.setV_errMsg("订单编号(" + proEntity.getProPlanId()
							+ ")/产线(" + proEntity.getPlineName() + ")没有维护产线能力!");
					return core;
				} else {
					capacity[0] = 0;
				}
			}
			double orglWgtMin = 0;// 剩余重量Min
			double orglWgt = 0;// 剩余重量
			int orglNum = 0;// 剩余支数
			int numS1 = 0;// 产出剩余支数
			double weigthS1 = 0;// 产出剩余重量
			double weigthSMin = 0;// 产出剩余重量MIN
			int plnNum1 = 0; // 计划产出支剩余
			double weigthS = 0;// 总产出重量
			double weigthMin1 = 0;// 总产出重量
			int numS = 0;// 总产出支数
			int plnNum = 0;// 计划总产出支数
			double gpreqWeightMin = 0;
			String originalNumber = "";// 原始量
			if (processCode.equals("D")) {
				int gpreqNum = proEntity.getGpreqNum();// 需坯支
				double gpreqWeight = proEntity.getGpreqWeight();
				gpreqWeightMin = proEntity.getGpreqWeightMin();
				// 1.1验证重量
				if (gpreqWeight <= spitWgt) {
					core.setV_errMsg("订单编号(" + proEntity.getProPlanId()
							+ ")总重量大于、等于分配重量!");
					return core;
				}
				weigthMin1 = proEntity.getWeigthSMin();
				// 总产出重量
				weigthS = proEntity.getWeigthS();
				// 总产出支数
				numS = proEntity.getNumS();
				// 计划总产出支数
				plnNum = proEntity.getPlansNum();
				// 产出剩余重量
				weigthS1 = (gpreqWeight - spitWgt) * weigthS / gpreqWeight;
				// double weigthS1 = (inWegths - spitWgt) * weigthS / inWegths;
				// 产出剩余重量MIN
				weigthSMin = (gpreqWeight - spitWgt)
						* proEntity.getWeigthSMin() / gpreqWeight;
				// 产出剩余支数
				// int numS1 = (int) Math.ceil((inNums - spitNum) * numS /
				// inNums);
				numS1 = (gpreqNum - spitNum) * numS / gpreqNum;
				// 计划产出支剩余
				plnNum1 = (gpreqNum - spitNum) * plnNum / gpreqNum;
				// 原始量
				originalNumber = "计划产出支:" + plnNum + ",排产支:" + numS + ",排产重量:"
						+ weigthS + ",需求支:" + gpreqNum + ",需求重量:" + gpreqWeight
						+ "。";
				/**
				 * 2. 原记录数据
				 */
				// 2.1 计算时间
				orglWgt = gpreqWeight - spitWgt;// 需坯剩余重量
				orglNum = gpreqNum - spitNum;// 需坯剩余支数
				orglWgtMin = (gpreqWeight - spitWgt) * gpreqWeightMin
						/ gpreqWeight;
			} else {
				double inWegths = 0;
				int inNums = 0;
				inWegths = proEntity.getInWeightS();// 总投入重量
				inNums = proEntity.getInNumS();// 总投入支数

				// 1.1验证重量
				if (inWegths <= spitWgt) {
					core.setV_errMsg("订单编号(" + proEntity.getProPlanId()
							+ ")总重量大于、等于分配重量!");
					return core;
				}
				weigthMin1 = proEntity.getWeigthSMin();
				// 总产出重量
				weigthS = proEntity.getWeigthS();
				// 总产出支数
				numS = proEntity.getNumS();
				// 产出剩余重量
				weigthS1 = (inWegths - spitWgt) * weigthS / inWegths;
				// 产出剩余支数
				numS1 = (inNums - spitNum) * numS / inNums;
				// 产出剩余重量MIN
				weigthSMin = (inWegths - spitWgt) * proEntity.getWeigthSMin()
						/ inWegths;
				/**
				 * 2. 原记录数据
				 */
				// 2.1 计算时间
				orglWgt = inWegths - spitWgt;// 需坯剩余重量
				orglNum = inNums - spitNum;// 需坯剩余支数
			}
			String orglplanTimeB = proEntity.getPlanTimeB(); // 计划开始时间
			TimeEntity orgltimeEntity = new TimeEntity();
			if (!processCode.equals("B")) {
				// 重算用时与结束时间
				orgltimeEntity = helperBean.calculateTime(orglNum, capacity[0],
						orglplanTimeB);
			} else {
				double[] steelArr = FrmSteelMakingPlanChange.getPlineLgParams(
						con, proEntity.getPlineCodeA());
				if (steelArr == null) {
					core.setV_errMsg("电炉(" + proEntity.getPlineNameA()
							+ ")没有排产基础数据!");
					return core;
				}
				double standSteel = steelArr[0];// 标准出钢量
				orgltimeEntity = helperBean.calculateTimeZz(orglWgt,
						capacity[0], orglplanTimeB, standSteel);
			}
			String orglplanTimeE = orgltimeEntity.getEndTime();// 计划结束时间
			String orglplanUserTime = orgltimeEntity.getUserTime(); // 计划用时

			// 2.2修改原始记录
			proEntity.setWeigthS(weigthS1);
			proEntity.setNumS(numS1);
			proEntity.setPlanTimeB(orglplanTimeB);
			proEntity.setPlanTimeE(orglplanTimeE);
			proEntity.setPlanUserTime(orglplanUserTime);
			if (processCode.equals("D")) {
				proEntity.setWeigthSMin(weigthSMin);
				proEntity.setGpreqNum(orglNum);
				proEntity.setGpreqWeight(orglWgt);//
				proEntity.setGpreqWeightMin(orglWgtMin);
				proEntity.setPlansNum(plnNum1);
				proEntity.setOriginalNumber(originalNumber);
			} else if (processCode.equals("E")) {
				proEntity.setWeigthSMin(weigthSMin);
				proEntity.setInWeightS(orglWgt);
				proEntity.setInNumS(orglNum);
			} else if (processCode.equals("F")) {
				proEntity.setWeigthSMin(weigthSMin);
				proEntity.setInWeightS(orglWgt);
				proEntity.setInNumS(orglNum);
			} else {
				proEntity.setInWeightS(orglWgt);
				proEntity.setInNumS(orglNum);
			}
			helperBean.updatePlanOrder(con, proEntity, processCode,
					proEntity.getProMonth());
			// 2.3自动调整时间
			// helperBean.timeIncrease(con, proEntity.getGxProSeq(), proEntity
			// .getPlineCode(), orglplanTimeE, processCode);
			/**
			 * 3.新增记录
			 */

			// 排产序号
			String gxPlanNo = helperBean.getMaxGxPlanNo(con,
					proEntity.getProPlanId(), processCode);
			// 生产顺序
			int gxProSeq = proEntity.getGxProSeq() + 1;
			// helperBean.getMaxGxProSeq(con, proEntity
			// .getPlineCode(), processCode, proEntity.getProMonth());
			// 3.1计划开始时间(这个时间应该从数据库里查)
			// String planTimeB = helperBean.getMaxPlanTimeE(con, proEntity
			// .getPlineCode(), processCode, proEntity.getProMonth(),
			// gxProSeq);
			String planTimeB = orglplanTimeE;
			if (planTimeB.equals("")) {
				core.setV_errMsg("计划开始时间为空,拆分失败!");
				return core;

			}
			TimeEntity TimeEntiy = new TimeEntity();
			if (!processCode.equals("B")) {
				// 重算用时与结束时间
				TimeEntiy = helperBean.calculateTime(spitNum, capacity[0],
						planTimeB);
			} else {
				double[] steelArr = FrmSteelMakingPlanChange.getPlineLgParams(
						con, proEntity.getPlineCodeA());
				if (steelArr == null) {
					core.setV_errMsg("电炉(" + proEntity.getPlineNameA()
							+ ")没有排产基础数据!");
					return core;
				}
				double standSteel = steelArr[0];// 标准出钢量
				TimeEntiy = helperBean.calculateTimeZz(spitWgt, capacity[0],
						orglplanTimeB, standSteel);
			}
			// 计划结束时间
			String planTimeE = TimeEntiy.getEndTime();
			String planUserTime = TimeEntiy.getUserTime();
			// 3.2新增新记录
			proEntity.setGxPlanNo(gxPlanNo);
			proEntity.setGxProSeq(gxProSeq);
			double weigthS2 = weigthS - weigthS1;
			int numS2 = numS - numS1;
			double gpreqWeightMin2 = gpreqWeightMin - orglWgtMin;
			proEntity.setWeigthS(weigthS2);
			proEntity.setNumS(numS2);
			proEntity.setPlanTimeB(planTimeB);
			proEntity.setPlanTimeE(planTimeE);
			proEntity.setPlanUserTime(planUserTime);
			proEntity.setExeStatus("0");
			proEntity.setIsRepairPlan("0");
			if (processCode.equals("D")) {
				proEntity.setWeigthSMin(weigthMin1 - weigthSMin);
				proEntity.setGpreqNum(spitNum);
				proEntity.setGpreqWeight(spitWgt);//
				proEntity.setGpreqWeightMin(gpreqWeightMin2);
				proEntity.setPlansNum(plnNum - plnNum1);
			} else if (processCode.equals("E")) {
				proEntity.setWeigthSMin(weigthMin1 - weigthSMin);
				proEntity.setInWeightS(spitWgt);
				proEntity.setInNumS(spitNum);
			} else if (processCode.equals("F")) {
				proEntity.setWeigthSMin(weigthMin1 - weigthSMin);
				proEntity.setInWeightS(spitWgt);
				proEntity.setInNumS(spitNum);
			} else {
				proEntity.setInWeightS(spitWgt);
				proEntity.setInNumS(spitNum);
			}
			proEntity.setAddNumIn(0);
			proEntity.setAddWtIn(0);
			proEntity.setBatchedNum(0);
			proEntity.setBatchedWt(0);
			proEntity.setRealBatchNum(0);
			proEntity.setRealBatchWt(0);
			proEntity.setMatchNumIn(0);
			proEntity.setMatchWtIn(0);
			proEntity.setMatchWtIn(0);
			proEntity.setIfStoveIssued("0");
			// proEntity.setIsPlanOk("0");
			// proEntity.setIssuedMan("");
			// proEntity.setIssuedTime("");
			// proEntity.setLastUndownMan("");
			// proEntity.setLastUndownTime("");
			helperBean.seqIncrease(con, proEntity.getPlineCode(), gxProSeq, -1,
					1, processCode);
			// 订单编号以及排产序号
			helperBean.addPlanOrder(con, proEntity, processCode,
					proEntity.getProMonth());
			// 时间自动调整
			// helperBean.timeIncrease(con, proEntity.getGxProSeq(), proEntity
			// .getPlineCode(), planTimeE, processCode);
			// helperBean.generateZyBatchId(con, proEntity.getPlineCode(),
			// processCode);
			core.setResult(true);
			core.setV_errMsg("拆分成功!");
			con.commit();
		} catch (Exception e) {
			e.printStackTrace();
			try {
				if (con != null) {
					con.rollback();
				}
			} catch (SQLException e1) {
				e1.printStackTrace();
			}
		} finally {
			try {
				if (con != null && !con.isClosed()) {
					con.close();
				}
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
		return core;
	}

	/**
	 * 轧管排产拆分
	 * 
	 * @param jsonStr
	 * @param
	 *
	 * @param
	 *
	 * @return
	 */
	public CoreReturnObject spitPlanOrderZg(String jsonStr, String spitWgtStr,
			String spitNumStr, String heatPlanNo) {
		CoreReturnObject core = new CoreReturnObject();
		core.setResult(false);
		Connection con = null;
		try {
			double spitWgt = Double.parseDouble(spitWgtStr);
			int spitNum = Integer.parseInt(spitNumStr);
			con = this.getDao(CoreConstantData.sysbeanstr).getConnection();
			con.setAutoCommit(false);
			ProducHelperBean helperBean = new ProducHelperBean();
			ProducEntity proEntity = helperBean.genertionProEntity(con,
					jsonStr, "D");
			/**
			 * 1.验证数据
			 */
			if (proEntity == null) {
				core.setV_errMsg("数据异常,请刷新数据!");
				return core;
			}
			if (!proEntity.getExeStatus().equals("0")
					&& !proEntity.getExeStatus().equals("1")) {
				core.setV_errMsg("订单编号(" + proEntity.getProPlanId()
						+ ")/不是 (计划/生产中)执行状态!");
				return core;
			}
			// if (proEntity.getIsPlanOk().equals("1")) {
			// core.setV_errMsg("订单编号(" + proEntity.getProPlanId() + ") 已确认!");
			// return core;
			// }
			// 1.2验证产线能力
			double[] capacity = helperBean.getPlineCapacity(con,
					proEntity.getInwlId(), proEntity.getOutwlId(),
					proEntity.getPlineCode(), "D");

			if (capacity[0] <= 0) {
				core.setV_errMsg("订单编号(" + proEntity.getProPlanId() + ")/产线("
						+ proEntity.getPlineName() + ")没有维护产线能力!");
				return core;

			}
			double orglWgtMin = 0;// 剩余重量Min
			double orglWgt = 0;// 剩余重量
			int orglNum = 0;// 剩余支数
			int numS1 = 0;// 产出剩余支数
			double weigthS1 = 0;// 产出剩余重量
			double weigthSMin = 0;// 产出剩余重量MIN
			int plnNum1 = 0; // 计划产出支剩余
			double weigthS = 0;// 总产出重量
			double weigthMin1 = 0;// 总产出重量
			int numS = 0;// 总产出支数
			int plnNum = 0;// 计划总产出支数
			double gpreqWeightMin = 0;
			String originalNumber = "";// 原始量

			int gpreqNum = proEntity.getGpreqNum();// 需坯支
			double gpreqWeight = proEntity.getGpreqWeight();
			gpreqWeightMin = proEntity.getGpreqWeightMin();
			// 1.1验证重量
			if (gpreqWeight <= spitWgt) {
				core.setV_errMsg("订单编号(" + proEntity.getProPlanId()
						+ ")总重量大于、等于分配重量!");
				return core;
			}
			weigthMin1 = proEntity.getWeigthSMin();
			// 总产出重量
			weigthS = proEntity.getWeigthS();
			// 总产出支数
			numS = proEntity.getNumS();
			// 计划总产出支数
			plnNum = proEntity.getPlansNum();
			// 产出剩余重量
			weigthS1 = (gpreqWeight - spitWgt) * weigthS / gpreqWeight;
			// double weigthS1 = (inWegths - spitWgt) * weigthS / inWegths;
			// 产出剩余重量MIN
			weigthSMin = (gpreqWeight - spitWgt) * proEntity.getWeigthSMin()
					/ gpreqWeight;
			// 产出剩余支数
			// int numS1 = (int) Math.ceil((inNums - spitNum) * numS /
			// inNums);
			numS1 = (gpreqNum - spitNum) * numS / gpreqNum;
			// 计划产出支剩余
			plnNum1 = (gpreqNum - spitNum) * plnNum / gpreqNum;
			// 原始量
			originalNumber = "计划产出支:" + plnNum + ",排产支:" + numS + ",排产重量:"
					+ weigthS + ",需求支:" + gpreqNum + ",需求重量:" + gpreqWeight
					+ "。";
			/**
			 * 2. 原记录数据
			 */
			// 2.1 计算时间
			orglWgt = gpreqWeight - spitWgt;// 需坯剩余重量
			orglNum = gpreqNum - spitNum;// 需坯剩余支数
			orglWgtMin = (gpreqWeight - spitWgt) * gpreqWeightMin / gpreqWeight;

			String orglplanTimeB = proEntity.getPlanTimeB(); // 计划开始时间
			TimeEntity orgltimeEntity = new TimeEntity();

			// 重算用时与结束时间
			orgltimeEntity = helperBean.calculateTime(orglNum, capacity[0],
					orglplanTimeB);

			String orglplanTimeE = orgltimeEntity.getEndTime();// 计划结束时间
			String orglplanUserTime = orgltimeEntity.getUserTime(); // 计划用时

			// 2.2修改原始记录
			proEntity.setWeigthS(weigthS1);
			proEntity.setNumS(numS1);
			proEntity.setPlanTimeB(orglplanTimeB);
			proEntity.setPlanTimeE(orglplanTimeE);
			proEntity.setPlanUserTime(orglplanUserTime);

			proEntity.setWeigthSMin(weigthSMin);
			proEntity.setGpreqNum(orglNum);
			proEntity.setGpreqWeight(orglWgt);//
			proEntity.setGpreqWeightMin(orglWgtMin);
			proEntity.setPlansNum(plnNum1);
			proEntity.setOriginalNumber(originalNumber);

			helperBean.updatePlanOrder(con, proEntity, "D",
					proEntity.getProMonth());
			// 2.3自动调整时间
			// helperBean.timeIncrease(con, proEntity.getGxProSeq(), proEntity
			// .getPlineCode(), orglplanTimeE, "D");
			/**
			 * 3.新增记录
			 */

			// 排产序号
			String gxPlanNo = helperBean.getMaxGxPlanNo(con,
					proEntity.getProPlanId(), "D");
			// 生产顺序
			int gxProSeq = proEntity.getGxProSeq() + 1;
			// helperBean.getMaxGxProSeq(con, proEntity
			// .getPlineCode(), processCode, proEntity.getProMonth());
			// 3.1计划开始时间(这个时间应该从数据库里查)
			// String planTimeB = helperBean.getMaxPlanTimeE(con, proEntity
			// .getPlineCode(), processCode, proEntity.getProMonth(),
			// gxProSeq);
			String planTimeB = orglplanTimeE;
			if (planTimeB.equals("")) {
				core.setV_errMsg("计划开始时间为空,拆分失败!");
				return core;

			}
			TimeEntity TimeEntiy = new TimeEntity();

			// 重算用时与结束时间
			TimeEntiy = helperBean.calculateTime(spitNum, capacity[0],
					planTimeB);

			// 计划结束时间
			String planTimeE = TimeEntiy.getEndTime();
			String planUserTime = TimeEntiy.getUserTime();
			// 3.2新增新记录
			proEntity.setGxPlanNo(gxPlanNo);
			proEntity.setGxProSeq(gxProSeq);
			double weigthS2 = weigthS - weigthS1;
			int numS2 = numS - numS1;
			double gpreqWeightMin2 = gpreqWeightMin - orglWgtMin;
			proEntity.setWeigthS(weigthS2);
			proEntity.setNumS(numS2);
			proEntity.setPlanTimeB(planTimeB);
			proEntity.setPlanTimeE(planTimeE);
			proEntity.setPlanUserTime(planUserTime);
			proEntity.setExeStatus("0");
			proEntity.setIsRepairPlan("0");

			proEntity.setWeigthSMin(weigthMin1 - weigthSMin);
			proEntity.setGpreqNum(spitNum);
			proEntity.setGpreqWeight(spitWgt);//
			proEntity.setGpreqWeightMin(gpreqWeightMin2);
			proEntity.setPlansNum(plnNum - plnNum1);

			proEntity.setAddNumIn(0);
			proEntity.setAddWtIn(0);
			proEntity.setBatchedNum(0);
			proEntity.setBatchedWt(0);
			proEntity.setRealBatchNum(0);
			proEntity.setRealBatchWt(0);
			proEntity.setMatchNumIn(0);
			proEntity.setMatchWtIn(0);
			proEntity.setMatchWtIn(0);
			// proEntity.setIfStoveIssued("0");
			// proEntity.setIsPlanOk("0");
			// proEntity.setIssuedMan("");
			// proEntity.setIssuedTime("");
			// proEntity.setLastUndownMan("");
			// proEntity.setLastUndownTime("");
			if (!heatPlanNo.equals("")) {
				// 修改炉计划炉计划,材料表,判定表,申请判定表,炉计划接收表排产序号
				String messe = helperBean.updateSpit(con, heatPlanNo, gxPlanNo,
						"D", proEntity);
				if (!messe.equals("")) {
					core.setV_errMsg(messe);
					return core;
				}
			}
			helperBean.seqIncrease(con, proEntity.getPlineCode(), gxProSeq, -1,
					1, "D");
			// 订单编号以及排产序号
			helperBean.addPlanOrder(con, proEntity, "D",
					proEntity.getProMonth());
			// 时间自动调整
			// helperBean.timeIncrease(con, proEntity.getGxProSeq(), proEntity
			// .getPlineCode(), planTimeE, "D");
			// helperBean.generateZyBatchId(con, proEntity.getPlineCode(),
			// processCode);

			core.setResult(true);
			core.setV_errMsg("拆分成功!");
			con.commit();
		} catch (Exception e) {
			e.printStackTrace();
			try {
				if (con != null) {
					con.rollback();
				}
			} catch (SQLException e1) {
				e1.printStackTrace();
			}
		} finally {
			try {
				if (con != null && !con.isClosed()) {
					con.close();
				}
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
		return core;
	}

	/**
	 * 镦拔扩,热处理,加工线排产拆分
	 * 
	 * @param jsonStr
	 * @param
	 *
	 * @param
	 *
	 * @return
	 */
	public CoreReturnObject spitPlanOrderM(String jsonStr, String spitWgtStr,
			String spitNumStr, String heatPlanNo, String procesCode) {
		CoreReturnObject core = new CoreReturnObject();
		core.setResult(false);
		Connection con = null;
		try {
			double spitWgt = Double.parseDouble(spitWgtStr);
			int spitNum = Integer.parseInt(spitNumStr);
			con = this.getDao(CoreConstantData.sysbeanstr).getConnection();
			con.setAutoCommit(false);
			ProducHelperBean helperBean = new ProducHelperBean();
			ProducEntity proEntity = helperBean.genertionProEntity(con,
					jsonStr, procesCode);
			/**
			 * 1.验证数据
			 */
			if (proEntity == null) {
				core.setV_errMsg("数据异常,请刷新数据!");
				return core;
			}
			if (!proEntity.getExeStatus().equals("0")
					&& !proEntity.getExeStatus().equals("1")) {
				core.setV_errMsg("订单编号(" + proEntity.getProPlanId()
						+ ")/不是 (计划/生产中)执行状态!");
				return core;
			}
			// if (proEntity.getIsPlanOk().equals("1")) {
			// core.setV_errMsg("订单编号(" + proEntity.getProPlanId() + ") 已确认!");
			// return core;
			// }
			// 1.2验证产线能力
			double[] capacity = helperBean.getPlineCapacity(con,
					proEntity.getInwlId(), proEntity.getOutwlId(),
					proEntity.getPlineCode(), procesCode);

			if (capacity[0] <= 0) {
				core.setV_errMsg("订单编号(" + proEntity.getProPlanId() + ")/产线("
						+ proEntity.getPlineName() + ")没有维护产线能力!");
				return core;

			}
			double orglWgt = 0;// 剩余重量
			int orglNum = 0;// 剩余支数
			int numS1 = 0;// 产出剩余支数
			double weigthS1 = 0;// 产出剩余重量
			double weigthSMin = 0;// 产出剩余重量MIN
			double weigthS = 0;// 总产出重量
			double weigthMin1 = 0;// 总产出重量
			int numS = 0;// 总产出支数

			double inWegths = 0;
			int inNums = 0;
			inWegths = proEntity.getInWeightS();// 总投入重量
			inNums = proEntity.getInNumS();// 总投入支数

			// 1.1验证重量
			if (inWegths <= spitWgt) {
				core.setV_errMsg("订单编号(" + proEntity.getProPlanId()
						+ ")总重量大于、等于分配重量!");
				return core;
			}
			int singleCutNun = 0;
			if (procesCode.equals("H")) {
				singleCutNun = Integer.parseInt(proEntity.getSingleCutNun());
				// 总接箍个数
				weigthS = proEntity.getWeigthS();
				// 总接箍重量
				numS = proEntity.getNumS();
				// 剩余接箍个数
				numS1 = (inNums - spitNum) * singleCutNun;
				// 剩余接箍重量
				weigthS1 = numS1 * (weigthS / numS);

			} else {
				weigthMin1 = proEntity.getWeigthSMin();
				// 总产出重量
				weigthS = proEntity.getWeigthS();
				// 总产出支数
				numS = proEntity.getNumS();
				// 产出剩余重量
				weigthS1 = (inWegths - spitWgt) * weigthS / inWegths;
				// 产出剩余支数
				numS1 = (inNums - spitNum) * (numS / inNums);
				// 产出剩余重量MIN
				weigthSMin = (inWegths - spitWgt) * proEntity.getWeigthSMin()
						/ inWegths;
			}
			/**
			 * 2. 原记录数据
			 */
			// 2.1 计算时间
			orglWgt = inWegths - spitWgt;// 剩余重量
			orglNum = inNums - spitNum;// 剩余支数

			String orglplanTimeB = proEntity.getPlanTimeB(); // 计划开始时间
			TimeEntity orgltimeEntity = new TimeEntity();

			// 重算用时与结束时间
			orgltimeEntity = helperBean.calculateTime(orglNum, capacity[0],
					orglplanTimeB);

			String orglplanTimeE = orgltimeEntity.getEndTime();// 计划结束时间
			String orglplanUserTime = orgltimeEntity.getUserTime(); // 计划用时

			// 2.2修改原始记录
			proEntity.setWeigthS(weigthS1);
			proEntity.setNumS(numS1);
			proEntity.setPlanTimeB(orglplanTimeB);
			proEntity.setPlanTimeE(orglplanTimeE);
			proEntity.setPlanUserTime(orglplanUserTime);

			if (procesCode.equals("E")) {
				proEntity.setWeigthSMin(weigthSMin);
				proEntity.setInWeightS(orglWgt);
				proEntity.setInNumS(orglNum);
			} else if (procesCode.equals("F")) {
				proEntity.setWeigthSMin(weigthSMin);
				proEntity.setInWeightS(orglWgt);
				proEntity.setInNumS(orglNum);
			} else if (procesCode.equals("G")) {
				proEntity.setInWeightS(orglWgt);
				proEntity.setInNumS(orglNum);
			} else if (procesCode.equals("H")) {
				proEntity.setInWeightS(orglWgt);
				proEntity.setInNumS(orglNum);
			}

			helperBean.updatePlanOrder(con, proEntity, procesCode,
					proEntity.getProMonth());
			// 2.3自动调整时间
			// helperBean.timeIncrease(con, proEntity.getGxProSeq(), proEntity
			// .getPlineCode(), orglplanTimeE, procesCode);
			/**
			 * 3.新增记录
			 */

			// 排产序号
			String gxPlanNo = helperBean.getMaxGxPlanNo(con,
					proEntity.getProPlanId(), procesCode);
			// 生产顺序
			int gxProSeq = proEntity.getGxProSeq() + 1;
			// helperBean.getMaxGxProSeq(con, proEntity
			// .getPlineCode(), processCode, proEntity.getProMonth());
			// 3.1计划开始时间(这个时间应该从数据库里查)
			// String planTimeB = helperBean.getMaxPlanTimeE(con, proEntity
			// .getPlineCode(), processCode, proEntity.getProMonth(),
			// gxProSeq);
			String planTimeB = orglplanTimeE;
			if (planTimeB.equals("")) {
				core.setV_errMsg("计划开始时间为空,拆分失败!");
				return core;

			}
			TimeEntity TimeEntiy = new TimeEntity();

			// 重算用时与结束时间
			TimeEntiy = helperBean.calculateTime(spitNum, capacity[0],
					planTimeB);

			// 计划结束时间
			String planTimeE = TimeEntiy.getEndTime();
			String planUserTime = TimeEntiy.getUserTime();
			// 3.2新增新记录
			proEntity.setGxPlanNo(gxPlanNo);
			proEntity.setGxProSeq(gxProSeq);
			double weigthS2 = weigthS - weigthS1;
			int numS2 = numS - numS1;
			proEntity.setWeigthS(weigthS2);
			proEntity.setNumS(numS2);
			proEntity.setPlanTimeB(planTimeB);
			proEntity.setPlanTimeE(planTimeE);
			proEntity.setPlanUserTime(planUserTime);
			proEntity.setExeStatus("0");
			proEntity.setIsRepairPlan("0");
			if (procesCode.equals("E")) {
				proEntity.setWeigthSMin(weigthMin1 - weigthSMin);
				proEntity.setInWeightS(spitWgt);
				proEntity.setInNumS(spitNum);
			} else if (procesCode.equals("F")) {
				proEntity.setWeigthSMin(weigthMin1 - weigthSMin);
				proEntity.setInWeightS(spitWgt);
				proEntity.setInNumS(spitNum);
			} else if (procesCode.equals("G")) {
				proEntity.setInWeightS(spitWgt);
				proEntity.setInNumS(spitNum);
			} else if (procesCode.equals("H")) {
				proEntity.setInWeightS(spitWgt);
				proEntity.setInNumS(spitNum);
			}

			proEntity.setAddNumIn(0);
			proEntity.setAddWtIn(0);
			proEntity.setBatchedNum(0);
			proEntity.setBatchedWt(0);
			proEntity.setRealBatchNum(0);
			proEntity.setRealBatchWt(0);
			proEntity.setMatchNumIn(0);
			proEntity.setMatchWtIn(0);
			proEntity.setMatchWtIn(0);
			// proEntity.setIfStoveIssued("0");
			// proEntity.setIsPlanOk("0");
			// proEntity.setIssuedMan("");
			// proEntity.setIssuedTime("");
			// proEntity.setLastUndownMan("");
			// proEntity.setLastUndownTime("");

			helperBean.seqIncrease(con, proEntity.getPlineCode(), gxProSeq, -1,
					1, procesCode);
			// 订单编号以及排产序号
			helperBean.addPlanOrder(con, proEntity, procesCode,
					proEntity.getProMonth());
			// // 时间自动调整
			// helperBean.timeIncrease(con, proEntity.getGxProSeq(), proEntity
			// .getPlineCode(), planTimeE, procesCode);
			// if (procesCode.equals("F")) {
			helperBean.generateZyBatchId(con, proEntity.getPlineCode(),
					procesCode);
			// }
			if (!heatPlanNo.equals("")) {
				// 修改炉计划炉计划,材料表,判定表,申请判定表,炉计划接收表排产序号
				String messe = helperBean.updateSpit(con, heatPlanNo, gxPlanNo,
						procesCode, proEntity);
				if (!messe.equals("")) {
					core.setV_errMsg(messe);
					return core;
				}
			}
			core.setResult(true);
			core.setV_errMsg("拆分成功!");
			con.commit();
		} catch (Exception e) {
			e.printStackTrace();
			try {
				if (con != null) {
					con.rollback();
				}
			} catch (SQLException e1) {
				e1.printStackTrace();
			}
		} finally {
			try {
				if (con != null && !con.isClosed()) {
					con.close();
				}
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
		return core;
	}

	/**
	 * 合并排产
	 * 
	 * @param
	 * @return
	 */
	public CoreReturnObject mergePlanOrder(ArrayList<String> jsonList,
			String processCode) {
		CoreReturnObject core = new CoreReturnObject();
		core.setResult(false);
		Connection con = null;
		PreparedStatement ps = null;
		try {
			ProducHelperBean helperBean = new ProducHelperBean();
			con = this.getDao(CoreConstantData.sysbeanstr).getConnection();
			con.setAutoCommit(false);
			List<ProducEntity> entityList = new ArrayList<ProducEntity>();
			for (String jsonStr : jsonList) {
				ProducEntity proEntity = helperBean.genertionProEntity(con,
						jsonStr, processCode);
				entityList.add(proEntity);
			}
			String status = "0";// 初始状态
			int minGxPlanNo = 0;// 初始排产序号
			ProducEntity minEntity = null;// 初始记录
			double weights = 0;// 初始重量
			int nums = 0;// 初始支数
			int inNumS = 0;
			double inWeightS = 0;// 待投重量
			int addNumIn = 0;
			double addWtIn = 0;// 加投重量
			int batchedNum = 0;
			double batchedWt = 0;// 虚拟挂料量
			int realBatchNum = 0;
			double realBatchWt = 0;// 实际挂料量
			int matchNumIn = 0;
			double matchWtIn = 0;// 投入利库量
			int gpreqNum = 0;// 需坯支
			double gpreqWeight = 0;
			int planNum = 0;// 计划产出支
			double weightsMin = 0;
			double gpreqWeightMin = 0;
			// 用于生产批次号
			String plineCode = "";
			for (ProducEntity entity : entityList) {
				if (entity == null) {
					core.setV_errMsg("数据异常,请刷新数据!");
					return core;
				}
				plineCode = entity.getPlineCode();
				if (minEntity == null) {
					minGxPlanNo = Integer.parseInt(entity.getGxPlanNo());
					minEntity = entity;
					status = entity.getExeStatus();
				}
				// if(entity.getExeStatus()==null)return core;
				if (!entity.getExeStatus().equals("0")
						&& !entity.getExeStatus().equals("1")) {
					core.setV_errMsg("订单编号(" + entity.getProPlanId()
							+ ")不是计划/生产中状态!");
					return core;
				}
				if (!minEntity.getProPlanId().equals(entity.getProPlanId())
						|| !minEntity.getPlineCode().equals(
								entity.getPlineCode())) {
					core.setV_errMsg("不是同产线并且同订单编号!");
					return core;
				}
				if (!minEntity.getIsPlanOk().equals(entity.getIsPlanOk())) {
					core.setV_errMsg("计划确认状态不同,不允许合并!");
					return core;
				}

				// 找最小排产序号的排产行
				if (Integer.parseInt(entity.getGxPlanNo()) < minGxPlanNo) {
					minGxPlanNo = Integer.parseInt(entity.getGxPlanNo());
					minEntity = entity;
					status = entity.getExeStatus();
				}
				weights += entity.getWeigthS();
				nums += entity.getNumS();
				inNumS += entity.getInNumS();
				inWeightS += entity.getInWeightS();// 待投重量
				addNumIn += entity.getAddNumIn();
				addWtIn += entity.getAddWtIn();// 加投重量
				batchedNum += entity.getBatchedNum();
				batchedWt += entity.getBatchedWt();// 虚拟挂料量
				realBatchNum += entity.getRealBatchNum();
				realBatchWt += entity.getRealBatchWt();// 实际挂料量
				matchNumIn += entity.getMatchNumIn();
				matchWtIn += entity.getMatchWtIn();// 投入利库量
				gpreqNum += entity.getGpreqNum();
				gpreqWeight += entity.getGpreqWeight();
				planNum += entity.getPlansNum();
				weightsMin += entity.getWeigthSMin();
				gpreqWeightMin += entity.getGpreqWeightMin();
			}
			// 产线能力
			double[] capacity = helperBean.getPlineCapacity(con,
					minEntity.getInwlId(), minEntity.getOutwlId(),
					minEntity.getPlineCode(), processCode);
			if (capacity[0] <= 0) {
				core.setV_errMsg("订单编号(" + minEntity.getProPlanId() + ")/产线("
						+ minEntity.getPlineName() + ")没有维护产线能力!");
				return core;
			}
			String planTimeB = minEntity.getPlanTimeB();
			TimeEntity timeEntity = new TimeEntity();
			if (!processCode.equals("B")) {
				// 重算用时与结束时间
				timeEntity = helperBean.calculateTime(gpreqNum, capacity[0],
						planTimeB);
			} else {
				double[] steelArr = FrmSteelMakingPlanChange.getPlineLgParams(
						con, minEntity.getPlineCodeA());
				if (steelArr == null) {
					core.setV_errMsg("电炉(" + minEntity.getPlineNameA()
							+ ")没有排产基础数据!");
					return core;
				}
				double standSteel = steelArr[0];// 标准出钢量
				timeEntity = helperBean.calculateTimeZz(weights, capacity[0],
						planTimeB, standSteel);
			}

			minEntity.setPlanUserTime(timeEntity.getUserTime());
			minEntity.setPlanTimeE(timeEntity.getEndTime());
			minEntity.setExeStatus(status);
			minEntity.setGxPlanNo(String.valueOf(minGxPlanNo));
			minEntity.setWeigthS(weights);
			minEntity.setNumS(nums);
			// 赋量
			minEntity.setInWeightS(inWeightS);
			minEntity.setInNumS(inNumS);
			minEntity.setAddNumIn(addNumIn);
			minEntity.setAddWtIn(addWtIn);
			minEntity.setBatchedNum(batchedNum);
			minEntity.setBatchedWt(batchedWt);
			minEntity.setRealBatchNum(realBatchNum);
			minEntity.setRealBatchWt(realBatchWt);
			minEntity.setMatchNumIn(matchNumIn);
			minEntity.setMatchWtIn(matchWtIn);
			minEntity.setGpreqNum(gpreqNum);
			minEntity.setGpreqWeight(gpreqWeight);
			minEntity.setWeigthSMin(weightsMin);
			minEntity.setPlansNum(planNum);
			minEntity.setGpreqWeightMin(gpreqWeightMin);
			// 修改最小序号的记录
			helperBean.updatePlanOrder(con, minEntity, processCode,
					minEntity.getProMonth());

			// 删除记录
			int i = 0;
			for (ProducEntity entity : entityList) {
				if (Integer.parseInt(entity.getGxPlanNo()) != minGxPlanNo) {
					helperBean.deletePlanOrder(con, entity, processCode);
					helperBean.seqIncrease(con, entity.getPlineCode(),
							entity.getGxProSeq() - i, -1, -1, processCode);
					i++;
					if (processCode.equals("D")) {
						if (!minEntity.getGpreqId().equals(entity.getGpreqId())) {
							core.setV_errMsg("管坯需求号不同,不允许合并!");
							return core;
						}

						int countm = 0;
						String planstatus = "00";
						// 查询是否存在炉计划
						String sqlM = "SELECT COUNT(*) COUNT,MAX(T.PLANSTATUS) PLANSTATUS FROM PLN_ZY_ZG_M T WHERE T.PRO_PLAN_ID=? AND T.GX_PLAN_NO=?";
						ps = con.prepareStatement(sqlM);
						ps.setObject(1, entity.getProPlanId());
						ps.setObject(2, entity.getGxPlanNo());
						ResultSet rs = ps.executeQuery();
						if (rs.next()) {
							countm = rs.getInt("COUNT");
							planstatus = rs.getString("PLANSTATUS");
						}
						rs.close();
						ps.close();
						// if (countm > 0) {
						// core.setV_errMsg("订单编号(" + entity.getProPlanId() +
						// "/"
						// + entity.getGxPlanNo() + ")存在炉计划,不能合并!");
						// return core;
						// }
						if (countm != 0 && !planstatus.equals("00")) {
							core.setV_errMsg("订单编号(" + entity.getProPlanId()
									+ "/" + entity.getGxPlanNo()
									+ ")有炉计划已下发,不能合并!");
							return core;
						}
						// 合并修改炉计划订单序号及生产批号
						String updatePlnM = "UPDATE PLN_ZY_ZG_M T SET T.ZY_BATCH_ID=? ,T.GX_PLAN_NO=? WHERE T.PRO_PLAN_ID=? AND T.GX_PLAN_NO=?";
						ps = con.prepareStatement(updatePlnM);
						ps.setObject(1, minEntity.getZyBatchId());
						ps.setObject(2, minGxPlanNo);
						ps.setObject(3, entity.getProPlanId());
						ps.setObject(4, entity.getGxPlanNo());
						ps.executeUpdate();
						ps.close();
						String updatePlnC = "UPDATE PLN_ZY_ZG_C T SET T.ZY_BATCH_ID=? ,T.GX_PLAN_NO=? WHERE T.PRO_PLAN_ID=? AND T.GX_PLAN_NO=?";
						ps = con.prepareStatement(updatePlnC);
						ps.setObject(1, minEntity.getZyBatchId());
						ps.setObject(2, minGxPlanNo);
						ps.setObject(3, entity.getProPlanId());
						ps.setObject(4, entity.getGxPlanNo());
						ps.executeUpdate();
						ps.close();

						// if()
						// 修改库存订单序号
						String updateMat = "UPDATE MAT_GP_M T SET T.GX_PLAN_NO_ZG=? WHERE T.PRO_PLAN_ID_ZG=? AND T.GX_PLAN_NO_ZG=? ";
						ps = con.prepareStatement(updateMat);
						ps.setObject(1, minGxPlanNo);
						ps.setObject(2, entity.getProPlanId());
						ps.setObject(3, entity.getGxPlanNo());
						ps.executeUpdate();
						ps.close();
						// 修改送判订单序号
						String updateJugdeZg = "UPDATE QCM_GP_JUDGE_APPLY T SET T.GX_PLAN_NO_NEXT=? WHERE T.PRO_PLAN_ID_NEXT=? AND T.GX_PLAN_NO_NEXT=? ";
						ps = con.prepareStatement(updateJugdeZg);
						ps.setObject(1, minGxPlanNo);
						ps.setObject(2, entity.getProPlanId());
						ps.setObject(3, entity.getGxPlanNo());
						ps.executeUpdate();
						ps.close();
					} else if (processCode.equals("E")) {
						int countm = 0;
						String planstatus = "00";
						// 查询是否存在炉计划
						String sqlM = "SELECT COUNT(*) COUNT,MAX(T.PLANSTATUS) PLANSTATUS FROM PLN_ZY_DBK_M T WHERE T.PRO_PLAN_ID=? AND T.GX_PLAN_NO=?";
						ps = con.prepareStatement(sqlM);
						ps.setObject(1, entity.getProPlanId());
						ps.setObject(2, entity.getGxPlanNo());
						ResultSet rs = ps.executeQuery();
						if (rs.next()) {
							countm = rs.getInt("COUNT");
							planstatus = rs.getString("PLANSTATUS");
						}
						rs.close();
						ps.close();
						// if (countm > 0) {
						// core.setV_errMsg("订单编号(" + entity.getProPlanId() +
						// "/"
						// + entity.getGxPlanNo() + ")存在炉计划,不能合并!");
						// return core;
						// }
						if (countm != 0 && !planstatus.equals("00")) {
							core.setV_errMsg("订单编号(" + entity.getProPlanId()
									+ "/" + entity.getGxPlanNo()
									+ ")有炉计划已下发,不能合并!");
							return core;
						}
						// 合并修改炉计划订单序号及生产批号
						String updatePlnM = "UPDATE PLN_ZY_DBK_M T SET T.ZY_BATCH_ID=? ,T.GX_PLAN_NO=? WHERE T.PRO_PLAN_ID=? AND T.GX_PLAN_NO=?";
						ps = con.prepareStatement(updatePlnM);
						ps.setObject(1, minEntity.getZyBatchId());
						ps.setObject(2, minGxPlanNo);
						ps.setObject(3, entity.getProPlanId());
						ps.setObject(4, entity.getGxPlanNo());
						ps.executeUpdate();
						ps.close();
						String updatePlnC = "UPDATE PLN_ZY_DBK_C T SET T.ZY_BATCH_ID=? ,T.GX_PLAN_NO=? WHERE T.PRO_PLAN_ID=? AND T.GX_PLAN_NO=?";
						ps = con.prepareStatement(updatePlnC);
						ps.setObject(1, minEntity.getZyBatchId());
						ps.setObject(2, minGxPlanNo);
						ps.setObject(3, entity.getProPlanId());
						ps.setObject(4, entity.getGxPlanNo());
						ps.executeUpdate();
						ps.close();

						// 修改库存订单序号
						String updateMat = "UPDATE MAT_BC_M T SET T.GX_PLAN_NO_NEXT=? WHERE T.PRO_PLAN_ID_NEXT=? AND T.GX_PLAN_NO_NEXT=?  AND T.NEXT_PROCESS_CDOE='E'";
						ps = con.prepareStatement(updateMat);
						ps.setObject(1, minGxPlanNo);
						ps.setObject(2, entity.getProPlanId());
						ps.setObject(3, entity.getGxPlanNo());
						ps.executeUpdate();
						ps.close();
						// 修改送判订单序号
						String updateJugdeZg = "UPDATE QCM_ZG_JUGDE_APPLY T SET T.GX_PLAN_NO_NEXT=? WHERE T.PRO_PLAN_ID_NEXT=? AND T.GX_PLAN_NO_NEXT=?  AND T.NEXT_PROCESS_CDOE='E'";
						ps = con.prepareStatement(updateJugdeZg);
						ps.setObject(1, minGxPlanNo);
						ps.setObject(2, entity.getProPlanId());
						ps.setObject(3, entity.getGxPlanNo());
						ps.executeUpdate();
						ps.close();
					} else if (processCode.equals("F")) {
						int countm = 0;
						String planstatus = "00";
						String pic = "";
						// 查询是否存在炉计划
						String sqlM = "SELECT T.PLANSTATUS,T.PIC,t.HEAT_PLAN_NO,T.JUDGE_STOVE_NO   FROM PLN_ZY_RCL_M T WHERE T.PRO_PLAN_ID=? AND T.GX_PLAN_NO=?";
						ps = con.prepareStatement(sqlM);
						ps.setObject(1, entity.getProPlanId());
						ps.setObject(2, entity.getGxPlanNo());
						ResultSet rs = ps.executeQuery();
						while (rs.next()) {
							// countm = rs.getInt("COUNT");
							planstatus = rs.getString("PLANSTATUS");
							pic = rs.getString("PIC");
							if (!planstatus.equals("00")) {
								core.setV_errMsg("订单编号("
										+ entity.getProPlanId() + "/"
										+ entity.getGxPlanNo()
										+ ")有炉计划已下发,不能合并!");
								return core;
							}
							int lotNoNew = ProducHelperBean.getMaxLotNoSqe(con,
									minEntity.getProPlanId(),
									String.valueOf(minGxPlanNo));

							// 合并修改炉计划订单序号及生产批号
							String updatePlnM = "UPDATE PLN_ZY_RCL_M T SET T.ZY_BATCH_ID=? ,T.GX_PLAN_NO=?,T.LOT_NO_SQE=? WHERE T.HEAT_PLAN_NO=?";
							PreparedStatement ps1 = con
									.prepareStatement(updatePlnM);
							ps1.setObject(1, minEntity.getZyBatchId());
							ps1.setObject(2, minGxPlanNo);
							ps1.setObject(3, lotNoNew);
							ps1.setObject(4, rs.getString("HEAT_PLAN_NO"));
							ps1.executeUpdate();
							ps1.close();

							StoveHelper.updatePlnRclGroup(con,
									minEntity.getProPlanId(),
									minEntity.getGxPlanNo(), pic);

							String updatePlnC = "UPDATE PLN_ZY_RCL_C T SET T.ZY_BATCH_ID=? ,T.GX_PLAN_NO=? WHERE T.HEAT_PLAN_NO=?";
							ps1 = con.prepareStatement(updatePlnC);
							ps1.setObject(1, minEntity.getZyBatchId());
							ps1.setObject(2, minGxPlanNo);
							ps1.setObject(3, rs.getString("HEAT_PLAN_NO"));
							ps1.executeUpdate();
							ps1.close();

							// 修改库存订单序号
							String updateMat = "UPDATE MAT_BC_M T SET T.GX_PLAN_NO_NEXT=? WHERE T.HEAT_PLAN_NO_NEXT=?  AND T.NEXT_PROCESS_CDOE='F'";
							ps1 = con.prepareStatement(updateMat);
							ps1.setObject(1, minGxPlanNo);
							ps1.setObject(2, rs.getString("HEAT_PLAN_NO"));
							ps1.executeUpdate();
							ps1.close();
							// 修改送判订单序号
							String updateJugdeZg = "UPDATE QCM_ZG_JUGDE_APPLY T SET T.GX_PLAN_NO_NEXT=? WHERE T.HEAT_PLAN_NO_NEXT=?  AND T.NEXT_PROCESS_CDOE='F'";
							ps1 = con.prepareStatement(updateJugdeZg);
							ps1.setObject(1, minGxPlanNo);
							ps1.setObject(2, rs.getString("HEAT_PLAN_NO"));
							ps1.executeUpdate();
							ps1.close();

							// // 修改送判订单序号
							// String updateCheckZg =
							// "UPDATE QCM_ZC_CHECKCONSIGN T SET T.LOT_NO=?,T.GX_PLAN_NO=?,T.LOT_NO_GROUP=? WHERE T.PRO_ORDER_ID=? AND T.GX_PLAN_NO=? AND T.JUDGE_STOVE_NO=? AND T.PROCESS_CODE='F'";
							// ps1 = con.prepareStatement(updateCheckZg);
							// ps1.setObject(1, minEntity.getZyBatchId());
							// ps1.setObject(2, minGxPlanNo);
							// ps1.setObject(3, lotNoNew);
							// ps1.setObject(4, entity.getProPlanId());
							// ps1.setObject(5, entity.getGxPlanNo());
							// ps1.setObject(6, rs.getString("JUDGE_STOVE_NO"));
							// ps1.executeUpdate();
							// ps1.close();
						}
						rs.close();
						ps.close();
						// if (countm > 0) {
						// core.setV_errMsg("订单编号(" + entity.getProPlanId() +
						// "/"
						// + entity.getGxPlanNo() + ")存在炉计划,不能合并!");
						// return core;
						// }

					} else if (processCode.equals("G")) {
						int countm = 0;
						String planstatus = "00";
						// 查询是否存在炉计划
						String sqlM = "SELECT COUNT(*) COUNT,MAX(T.PLANSTATUS) PLANSTATUS   FROM PLN_ZY_JGX_M T WHERE T.PRO_PLAN_ID=? AND T.GX_PLAN_NO=?";
						ps = con.prepareStatement(sqlM);
						ps.setObject(1, entity.getProPlanId());
						ps.setObject(2, entity.getGxPlanNo());
						ResultSet rs = ps.executeQuery();
						if (rs.next()) {
							countm = rs.getInt("COUNT");
							planstatus = rs.getString("PLANSTATUS");
						}
						rs.close();
						ps.close();
						// if (countm > 0) {
						// core.setV_errMsg("订单编号(" + entity.getProPlanId() +
						// "/"
						// + entity.getGxPlanNo() + ")存在炉计划,不能合并!");
						// return core;
						// }
						if (countm != 0 && !planstatus.equals("00")) {
							core.setV_errMsg("订单编号(" + entity.getProPlanId()
									+ "/" + entity.getGxPlanNo()
									+ ")有炉计划已下发,不能合并!");
							return core;
						}
						// 合并修改炉计划订单序号及生产批号
						String updatePlnM = "UPDATE PLN_ZY_JGX_M T SET T.ZY_BATCH_ID=? ,T.GX_PLAN_NO=? WHERE T.PRO_PLAN_ID=? AND T.GX_PLAN_NO=?";
						ps = con.prepareStatement(updatePlnM);
						ps.setObject(1, minEntity.getZyBatchId());
						ps.setObject(2, minGxPlanNo);
						ps.setObject(3, entity.getProPlanId());
						ps.setObject(4, entity.getGxPlanNo());
						ps.executeUpdate();
						ps.close();
						String updatePlnC = "UPDATE PLN_ZY_JGX_C T SET T.ZY_BATCH_ID=? ,T.GX_PLAN_NO=? WHERE T.PRO_PLAN_ID=? AND T.GX_PLAN_NO=?";
						ps = con.prepareStatement(updatePlnC);
						ps.setObject(1, minEntity.getZyBatchId());
						ps.setObject(2, minGxPlanNo);
						ps.setObject(3, entity.getProPlanId());
						ps.setObject(4, entity.getGxPlanNo());
						ps.executeUpdate();
						ps.close();

						// 修改库存订单序号
						String updateMat = "UPDATE MAT_BC_M T SET T.GX_PLAN_NO_NEXT=? WHERE T.PRO_PLAN_ID_NEXT=? AND T.GX_PLAN_NO_NEXT=?  AND T.NEXT_PROCESS_CDOE='G'";
						ps = con.prepareStatement(updateMat);
						ps.setObject(1, minGxPlanNo);
						ps.setObject(2, entity.getProPlanId());
						ps.setObject(3, entity.getGxPlanNo());
						ps.executeUpdate();
						ps.close();
						// 修改送判订单序号
						String updateJugdeZg = "UPDATE QCM_ZG_JUGDE_APPLY T SET T.GX_PLAN_NO_NEXT=? WHERE T.PRO_PLAN_ID_NEXT=? AND T.GX_PLAN_NO_NEXT=?  AND T.NEXT_PROCESS_CDOE='G'";
						ps = con.prepareStatement(updateJugdeZg);
						ps.setObject(1, minGxPlanNo);
						ps.setObject(2, entity.getProPlanId());
						ps.setObject(3, entity.getGxPlanNo());
						ps.executeUpdate();
						ps.close();
					} else if (processCode.equals("H")) {
						int countm = 0;
						String planstatus = "00";
						// 查询是否存在炉计划
						String sqlM = "SELECT COUNT(*) COUNT,MAX(T.PLANSTATUS) PLANSTATUS FROM PLN_ZY_JG_M T WHERE T.PRO_PLAN_ID=? AND T.GX_PLAN_NO=?";
						ps = con.prepareStatement(sqlM);
						ps.setObject(1, entity.getProPlanId());
						ps.setObject(2, entity.getGxPlanNo());
						ResultSet rs = ps.executeQuery();
						if (rs.next()) {
							countm = rs.getInt("COUNT");
							planstatus = rs.getString("PLANSTATUS");
						}
						rs.close();
						ps.close();
						// if (countm > 0) {
						// core.setV_errMsg("订单编号(" + entity.getProPlanId() +
						// "/"
						// + entity.getGxPlanNo() + ")存在炉计划,不能合并!");
						// return core;
						// }
						if (countm != 0 && !planstatus.equals("00")) {
							core.setV_errMsg("订单编号(" + entity.getProPlanId()
									+ "/" + entity.getGxPlanNo()
									+ ")有炉计划已下发,不能合并!");
							return core;
						}
						// 合并修改炉计划订单序号及生产批号
						String updatePlnM = "UPDATE PLN_ZY_JG_M T SET  T.GX_PLAN_NO=? WHERE T.PRO_PLAN_ID=? AND T.GX_PLAN_NO=?";
						ps = con.prepareStatement(updatePlnM);
						ps.setObject(1, minGxPlanNo);
						ps.setObject(2, entity.getProPlanId());
						ps.setObject(3, entity.getGxPlanNo());
						ps.executeUpdate();
						ps.close();
						String updatePlnC = "UPDATE PLN_ZY_JG_C T SET T.GX_PLAN_NO=? WHERE T.PRO_PLAN_ID=? AND T.GX_PLAN_NO=?";
						ps = con.prepareStatement(updatePlnC);
						ps.setObject(1, minGxPlanNo);
						ps.setObject(2, entity.getProPlanId());
						ps.setObject(3, entity.getGxPlanNo());
						ps.executeUpdate();
						ps.close();
					}
				}
			}
			helperBean.timeIncrease(con, minEntity.getGxProSeq(),
					minEntity.getPlineCode(), minEntity.getPlanTimeE(),
					processCode);
			// 合并时修改虚拟炉计划和实际炉计划等数据
			// helperBean.mergePlan(con, minEntity.getProPlanId(), minEntity
			// .getGxPlanNo(), entityList, processCode);
			// helperBean.generateZyBatchId(con, plineCode, processCode);
			if (!processCode.equals("")) {
				helperBean.generateZyBatchId(con, minEntity.getPlineCode(),
						processCode);
			}
			core.setV_errMsg("合并成功!");
			core.setResult(true);
			con.commit();
		} catch (Exception e) {
			try {
				if (con != null) {
					con.rollback();
				}
				e.printStackTrace();
			} catch (SQLException e1) {
				e1.printStackTrace();
			}
		} finally {
			try {
				if (con != null && !con.isClosed()) {
					con.close();
				}
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
		return core;
	}

	/**
	 * 排序
	 * 
	 * @param jsonstrList
	 * @param
	 * @param processCode
	 * @return
	 */
	public CoreReturnObject sortPlanOrder(ArrayList<String> jsonstrList,
			String jsonStrM, String processCode, String customInfo) {
		CoreReturnObject core = new CoreReturnObject();
		core.setResult(false);
		Connection con = null;
		try {
			con = this.getDao(CoreConstantData.sysbeanstr).getConnection();
			con.setAutoCommit(false);
			ProducHelperBean helperBean = new ProducHelperBean();
			// 移动行
			List<ProducEntity> entityList = new ArrayList<ProducEntity>();
			for (String jsonStr : jsonstrList) {
				ProducEntity proEntity = helperBean.genertionProEntity(con,
						jsonStr, processCode);
				entityList.add(proEntity);
			}
			// 定位行
			ProducEntity entityM = helperBean.genertionProEntity(con, jsonStrM,
					processCode);
			if (entityM == null) {
				return core;
			}
			String plineCode = entityM.getPlineCode();// 用于生产批次号
			/**
			 * 1.判断数据
			 */
			// 1.1定位行数据状态
			if (!entityM.getExeStatus().equals("0")
					|| entityM.getGxProSeq() != entityM.getOrglgxProSeq()) {
				return core;
			}
			// 已下发的数据在排产界面不能调整顺序
			// if (processCode.equals("E")) {
			// if (entityM.getIfStoveIssued().equals("1")
			// && customInfo.equals("1")) {
			// return core;
			// }
			// }
			int gxProSeqM = entityM.getGxProSeq(); // 移至行序号
			int[] intArray = new int[entityList.size()];
			// 1.2移动行数据
			for (int i = 0; i < entityList.size(); i++) {
				ProducEntity entity = entityList.get(i);
				if (entity == null) {
					return core;
				}
				if (!entity.getExeStatus().equals("0")
						|| entity.getGxProSeq() != entity.getOrglgxProSeq()) {
					return core;
				}
				// if (processCode.equals("E")) {
				// if (entity.getIfStoveIssued().equals("1")
				// && customInfo.equals("1")) {
				// return core;
				// }
				// }
				intArray[i] = entity.getGxProSeq();
			}
			// 1.3必须是在调整行的序号中间
			if (gxProSeqM >= intArray[0]
					&& gxProSeqM <= intArray[entityList.size() - 1]) {
				return core;
			}
			Arrays.sort(intArray);
			// 调整行操作
			/**
			 * 2. 前移(需要操作步骤:1.)
			 */
			String planTimeB = "";
			if (gxProSeqM < intArray[0]) {
				planTimeB = entityM.getPlanTimeB();
				for (int i = 0; i < entityList.size(); i++) {
					// 2.1序号自动调整
					ProducEntity entity = entityList.get(i);
					helperBean.seqIncrease(con, entity.getPlineCode(),
							gxProSeqM, entity.getGxProSeq(), 1, processCode);
					entity.setGxProSeq(gxProSeqM);
					entity.setPlanTimeB(planTimeB);
					String planTimeE = BaseHelper.addTime(planTimeB,
							entity.getPlanUserTime());
					entity.setPlanTimeE(planTimeE);
					// 2.2修改移动数据
					helperBean.updatePlanOrder(con, entity, processCode,
							entityM.getProMonth());
					// 2.3 时间自动调整
					helperBean.timeIncrease(con, entity.getGxProSeq(),
							entity.getPlineCode(), planTimeE, processCode);
					planTimeB = planTimeE;
					gxProSeqM = gxProSeqM + 1;
				}
			} else {
				/**
				 * 3.后移
				 */
				planTimeB = entityM.getPlanTimeE();
				// 如果不是小于最小序号,那么肯定是大于最大序号,前面加以限制
				int differNum = 0;
				for (int i = 0; i < entityList.size(); i++) {
					ProducEntity entity = entityList.get(i);
					if(entity.getGxProSeq() - differNum <= 0 || gxProSeqM < 0){
						core.setV_errMsg("调整后 "+entity.getProOrderNo()+" 顺序为负数");
						return core;
					}
					// 3.1序号自动调整
					helperBean.seqIncrease(con, entity.getPlineCode(),
							entity.getGxProSeq() - differNum, gxProSeqM + 1,
							-1, processCode);

					entity.setGxProSeq(gxProSeqM);
					entity.setPlanTimeB(planTimeB);
					String planTimeE = BaseHelper.addTime(planTimeB,
							entity.getPlanUserTime());
					entity.setPlanTimeE(planTimeE);
					// 3.2 修改数据
					helperBean.updatePlanOrder(con, entity, processCode,
							entityM.getProMonth());
					// 时间自动调整
					helperBean.timeIncrease(con, gxProSeqM,
							entity.getPlineCode(), planTimeE, processCode);
					planTimeB = planTimeE;
					differNum++;
				}
			}
			helperBean.generateZyBatchId(con, plineCode, processCode);
			core.setResult(true);
			core.setV_errMsg("调整完成");
			con.commit();
		} catch (Exception e) {
			e.printStackTrace();
			try {
				if (con != null) {
					con.rollback();
				}
			} catch (Exception e1) {
				e1.printStackTrace();
			}
		} finally {
			try {
				if (con != null && !con.isClosed())
					con.close();
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
		return core;
	}

	/**
	 * 状态调整
	 * 
	 * @param
	 * @return
	 */
	public CoreReturnObject statusChange(String jsonStr, String processCode) {
		CoreReturnObject core = new CoreReturnObject();
		core.setResult(false);
		Connection con = null;
		try {
			con = this.getDao(CoreConstantData.sysbeanstr).getConnection();
			con.setAutoCommit(false);
			PreparedStatement ps = null;
			ResultSet rs = null;
			ProducHelperBean helperBean = new ProducHelperBean();
			ProducEntity entity = helperBean.genertionProEntity(con, jsonStr,
					processCode);
			if (entity == null) {
				core.setV_errMsg("数据异常,请刷新数据!");
				return core;
			}
			if (entity.getExeStatus().equals("3")) {
				core.setV_errMsg("订单编号(" + entity.getProPlanId()
						+ ")状态为关闭A,不能调整状态!");
				return core;
			}
			ArrayList<ArrayList<String>> list = new ArrayList<ArrayList<String>>();
			if (processCode.equals("D")) {
				// 判定是调生产完成还是调计划
				if (entity.getExeStatus().equals("0")) {
					// 查询调整订单
					String sqlProPlanNo = "SELECT T.PRO_PLAN_ID, T.GX_PLAN_NO, T.EXE_STATUS,T.ORD_LN_DLY_PK,T.PLN_DIVIDE_ID,T.GPREQ_ID 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(?) AND T.GPREQ_ID IS NOT NULL";
					ps = con.prepareStatement(sqlProPlanNo);
					ps.setObject(1, entity.getPlineCode());
					ps.setObject(2, entity.getGxProSeq());
					rs = ps.executeQuery();
					while (rs.next()) {
						ArrayList<String> list1 = new ArrayList<String>();
						list1.add(rs.getString("ORD_LN_DLY_PK"));
						list1.add(rs.getString("PLN_DIVIDE_ID"));
						list1.add(rs.getString("GPREQ_ID"));
						list.add(list1);
					}
					rs.close();
					ps.close();

				} else if (entity.getExeStatus().equals("2")) {
					// 查询调整订单
					String sqlProPlanNo = "SELECT T.PRO_PLAN_ID, T.GX_PLAN_NO, T.EXE_STATUS,T.ORD_LN_DLY_PK,T.PLN_DIVIDE_ID,T.GPREQ_ID FROM PLN_ORDER_ZG_S T "
							+ " WHERE T.PLINE_CODE = ? AND T.EXE_STATUS='2' AND TO_NUMBER(T.GX_PRO_SEQ) > TO_NUMBER(?) AND T.GPREQ_ID IS NOT NULL";
					ps = con.prepareStatement(sqlProPlanNo);
					ps.setObject(1, entity.getPlineCode());
					ps.setObject(2, entity.getGxProSeq());
					rs = ps.executeQuery();
					while (rs.next()) {
						ArrayList<String> list1 = new ArrayList<String>();
						list1.add(rs.getString("ORD_LN_DLY_PK"));
						list1.add(rs.getString("PLN_DIVIDE_ID"));
						list1.add(rs.getString("GPREQ_ID"));
						list.add(list1);
					}
					rs.close();
					ps.close();
				}
			}
			helperBean.statusChange(con, entity.getPlineCode(),
					entity.getGxProSeq(), processCode);
			if (processCode.equals("D")) {
				if (list != null) {
					for (int i = 0; i < list.size(); i++) {
						// 轧管订单生产完成同管坯需求号的铸造订单,锻造订单,管坯需求关闭
						ProducHelperBean.setCloseBeforeProcess(con, list.get(i)
								.get(0), list.get(i).get(1),
								list.get(i).get(2), "D");
					}
				}
			}
			// helperBean.generateZyBatchId(con, entity.getPlineCode(),
			// processCode);
			// if (processCode.equals("D")) {
			// String sql = CoreXmlSqlParsersFactory
			// .getSql("ProducHelperBean.statusChangeStr");
			// PreparedStatement ps = con.prepareStatement(sql);
			// ps.setObject(1, entity.getPlineCode());
			// ps.executeUpdate();
			// ps.close();
			// }
			core.setV_errMsg("状态调整成功!");
			core.setResult(true);
			con.commit();
		} catch (Exception e) {
			core.setV_errMsg(e.getMessage());
			// e.printStackTrace();
			try {
				if (con != null) {
					con.rollback();
				}
			} catch (Exception e1) {
				e1.printStackTrace();
			}
		} finally {
			try {
				if (con != null && !con.isClosed())
					con.close();
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
		return core;
	}

	/**
	 * 新增检修
	 * 
	 * @param plineCode
	 * @param plineName
	 * @param repairType
	 * @param hourTime
	 * @return
	 */
	public CoreReturnObject addRepairPlan(String plineCode, String plineName,
			String repairType, String hourTime, String processCode) {
		CoreReturnObject core = new CoreReturnObject();
		core.setResult(false);
		Connection con = null;
		try {
			con = this.getDao(CoreConstantData.sysbeanstr).getConnection();
			con.setAutoCommit(false);
			Date now = new Date();
			SimpleDateFormat sf = new SimpleDateFormat("yyyyMM");
			String year = sf.format(now);
			// 订单编号
			String proPlanId = processCode + "JX" + year + "-" + plineCode;
			ProducHelperBean helperBean = new ProducHelperBean();
			// 排产序号
			String gxPlanNo = helperBean.getMaxGxPlanNo(con, proPlanId,
					processCode);
			Date nowTime = new Date();

			SimpleDateFormat dFormat = new SimpleDateFormat("yyyy-MM");

			// 生产顺序
			int gxProSeq = helperBean.getMaxGxProSeq(con, plineCode,processCode,
					"C072,C091,C092,C098,C099,C100,C102,C103,C104".contains(plineCode)?ComBaseInfo.GetBalYear1_2416(new Date()):ComBaseInfo.GetBalYear1(new Date()));
			String planTimeB = helperBean.getMaxPlanTimeE(con, plineCode,
					processCode, dFormat.format(nowTime), gxProSeq);// 开始时间
			if (planTimeB.equals("")) {
				core.setV_errMsg("计划开始时间为空,新增检修失败!");
				return core;

			}
			String planUserTime = String
					.valueOf(Double.parseDouble(hourTime) * 60);// 用时分
			String planTimeE = BaseHelper.addTime(planTimeB, planUserTime);// 结束时间
			ProducEntity entity = new ProducEntity();
			entity.setProPlanId(proPlanId);
			entity.setGxPlanNo(gxPlanNo);
			entity.setJgGroupId("1");
			entity.setGxProSeq(gxProSeq);
			entity.setPlineCode(plineCode);
			entity.setPlineName(plineName);
			entity.setPlanUserTime(planUserTime);
			entity.setPlanTimeB(planTimeB);
			entity.setPlanTimeE(planTimeE);
			entity.setIsRepairPlan("1");
			entity.setRepairType(repairType);
			entity.setExeStatus("0");
			entity.setDecision("A");
			helperBean.seqIncrease(con, entity.getPlineCode(), gxProSeq, -1, 1,
					processCode);
			helperBean.addPlanOrder(con, entity, processCode,
					"C072,C091,C092,C098,C099,C100,C102,C103,C104".contains(plineCode)?ComBaseInfo.GetBalYear1_2416(new Date()):ComBaseInfo.GetBalYear1(new Date()));
			// 时间自动调整
			helperBean.timeIncrease(con, entity.getGxProSeq(),
					entity.getPlineCode(), planTimeE, processCode);
			core.setV_errMsg("新增检修成功!");
			core.setResult(true);
			con.commit();
		} catch (Exception e) {
			e.printStackTrace();
			try {
				if (con != null) {
					con.rollback();
				}
			} catch (Exception e1) {
				e1.printStackTrace();
			}
		} finally {
			try {
				if (con != null && !con.isClosed())
					con.close();
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
		return core;
	}

	/**
	 * 新增承揽
	 * 
	 * @param jsonStr
	 * @param plineCode
	 * @param plineName
	 * @param repairType
	 * @param useHour
	 * @param userName
	 * @param memo
	 * @param processCode
	 * @return
	 */
	public CoreReturnObject addCL(String jsonStr, String plineCode,
			String plineName, String repairType, String useHour,
			String userName, String memo, String processCode) {
		CoreReturnObject core = new CoreReturnObject();
		core.setResult(false);
		Connection con = null;
		try {
			con = this.getDao(CoreConstantData.sysbeanstr).getConnection();
			con.setAutoCommit(false);
			Date now = new Date();
			SimpleDateFormat sf = new SimpleDateFormat("yyyyMM");
			String YM = sf.format(now);
			// 订单编号
			String proPlanIdC = processCode + "CL" + YM + "-" + plineCode;
			ProducHelperBean helperBean = new ProducHelperBean();
			ProducEntity entity = helperBean.genertionProEntity(con, jsonStr,
					processCode);
			if (entity == null) {
				core.setV_errMsg("新增异常!");
				return core;
			}
			// 排产序号
			String gxPlanNo = helperBean.getMaxGxPlanNo(con, proPlanIdC,
					processCode);
			// 生产顺序
			int gxProSeq = helperBean.getMaxGxProSeq(con, plineCode,
					processCode, entity.getProMonth());
			String planTimeB = helperBean.getMaxPlanTimeE(con, plineCode,
					processCode, entity.getProMonth(), gxProSeq);// 开始时间
			if (planTimeB.equals("")) {
				core.setV_errMsg("计划开始时间为空,新增承揽失败!");
				return core;

			}
			String planUserTime = String
					.valueOf(Double.parseDouble(useHour) * 60);// 用时分
			String planTimeE = BaseHelper.addTime(planTimeB, planUserTime);// 结束时间

			entity.setProPlanId(proPlanIdC);
			entity.setGxPlanNo(gxPlanNo);
			entity.setGxProSeq(gxProSeq);
			entity.setPlineCode(plineCode);
			entity.setPlineName(plineName);
			entity.setPlanUserTime(planUserTime);
			entity.setPlanTimeB(planTimeB);
			entity.setPlanTimeE(planTimeE);
			entity.setIsRepairPlan("1");
			entity.setRepairType(repairType);
			entity.setExeStatus("0");
			entity.setMemo("[创建人:" + userName + " 时间:" + YM + " 原产线:"
					+ plineName + "]" + memo);
			helperBean.seqIncrease(con, entity.getPlineCode(), gxProSeq, -1, 1,
					processCode);
			helperBean.addPlanOrder(con, entity, processCode,
					entity.getProMonth());
			// 时间自动调整
			helperBean.timeIncrease(con, entity.getGxProSeq(),
					entity.getPlineCode(), planTimeE, processCode);
			core.setV_errMsg("新增承揽成功!");
			core.setResult(true);
			con.commit();
		} catch (Exception e) {
			e.printStackTrace();
			try {
				if (con != null) {
					con.rollback();
				}
			} catch (Exception e1) {
				e1.printStackTrace();
			}
		} finally {
			try {
				if (con != null && !con.isClosed())
					con.close();
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
		return core;
	}

	/**
	 * 删除检修(承揽)
	 * 
	 * @param
	 * @param
	 * @return
	 */
	public CoreReturnObject deleteRepairPlan(ArrayList<String> jsonList,
			String processCode) {
		CoreReturnObject core = new CoreReturnObject();
		core.setResult(false);
		Connection con = null;
		try {
			con = this.getDao(CoreConstantData.sysbeanstr).getConnection();
			con.setAutoCommit(false);
			ProducHelperBean helperBean = new ProducHelperBean();
			int i = 0;
			String plineCode = "";
			for (String jsonStr : jsonList) {
				ProducEntity entity = helperBean.genertionProEntity(con,
						jsonStr, processCode);
				if (entity == null) {
					continue;
				}
				plineCode = entity.getPlineCode();
				if (!entity.getIsRepairPlan().equals("1")) {
					core.setV_errMsg("不是检修,不能删除!");
					return core;
				}
				if (entity.getIfStoveIssued().equals("1")) {
					core.setV_errMsg("订单编号(" + entity.getProPlanId()
							+ ") 炉计划已经下发!");
					return core;
				}
				if (!entity.getExeStatus().equals("0")) {
					core.setV_errMsg("不是计划状态的检修,不能删除!");
					return core;
				}
				helperBean.deletePlanOrder(con, entity, processCode);
				helperBean.seqIncrease(con, entity.getPlineCode(),
						entity.getGxProSeq() - i, -1, -1, processCode);
				i++;
				helperBean.timeIncrease(con, entity.getGxProSeq(), plineCode,
						entity.getPlanTimeE(), processCode);
			}
			// helperBean.generateZyBatchId(con, plineCode, processCode);
			core.setV_errMsg("删除成功!");
			core.setResult(true);
			con.commit();
		} catch (Exception e) {
			e.printStackTrace();
			try {
				if (con != null) {
					con.rollback();
				}
			} catch (Exception e1) {
				e1.printStackTrace();
			}
		} finally {
			try {
				if (con != null && !con.isClosed())
					con.close();
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
		return core;
	}

	/**
	 * 初始化数据
	 * 
	 * @param
	 * @return
	 */
	public CoreReturnObject initData(ArrayList<String> jsonList,
			String processCode) {
		CoreReturnObject core = new CoreReturnObject();
		core.setResult(false);
		Connection con = null;

		try {
			con = this.getDao(CoreConstantData.sysbeanstr).getConnection();
			con.setAutoCommit(false);
			ProducHelperBean helperBean = new ProducHelperBean();
			String plineCode = "";// 用于生产批次号
			for (String jsonStr : jsonList) {
				ProducEntity entity = helperBean.genertionProEntity(con,
						jsonStr, processCode);
				if (entity == null) {
					core.setV_errMsg("数据异常,请刷新数据!");
					return core;
				}
				plineCode = entity.getPlineCode();
				// if (entity.getIfStoveIssued().equals("1")) {
				// core.setV_errMsg("订单编号(" + entity.getProPlanId()
				// + ") 炉计划已经下发!");
				// return core;
				// }
				// 状态
				if (Integer.parseInt(entity.getExeStatus()) > 1) {
					core.setV_errMsg("订单编号(" + entity.getProPlanId()
							+ ")不是计划或者生产中状态,不能初始化!");
					return core;
				}
				if (entity.getIsRepairPlan().equals("1")) {
					String planTimeB = entity.getPlanTimeB();
					String planUserTime = String.valueOf(Double
							.parseDouble(entity.getOrglPlanUserTime()) * 60);// 界面计划用时是小时计
					String planTimeE = BaseHelper.addTime(planTimeB,
							planUserTime);
					entity.setPlanTimeB(planTimeB);
					entity.setPlanUserTime(planUserTime);
					entity.setPlanTimeE(planTimeE);
					entity.setRepairType(entity.getOrglRepairType());
					entity.setMemo(entity.getOrglMemo());
					helperBean.updatePlanOrder(con, entity, processCode,
							entity.getProMonth());
					// 时间自动调整
					helperBean.timeIncrease(con, entity.getGxProSeq(),
							entity.getPlineCode(), planTimeE, processCode);
				} else {
					// 产线能力
					double[] capacity = helperBean.getPlineCapacity(con,
							entity.getInwlId(), entity.getOutwlId(),
							entity.getPlineCode(), processCode);
					String planTimeB = entity.getPlanTimeB();
					TimeEntity timeEntity = null;
					if (processCode.equals("D")) {
						timeEntity = helperBean.calculateTime(
								entity.getGpreqNum(), capacity[0], planTimeB);
					} else {
						if (!processCode.equals("B")) {
							// 重算用时与结束时间
							timeEntity = helperBean.calculateTime(
									entity.getNumS(), capacity[0], planTimeB);
						} else {
							double[] steelArr = FrmSteelMakingPlanChange
									.getPlineLgParams(con,
											entity.getPlineCodeA());
							if (steelArr == null) {
								core.setV_errMsg("电炉(" + entity.getPlineNameA()
										+ ")没有排产基础数据!");
								return core;
							}
							double standSteel = steelArr[0];// 标准出钢量
							timeEntity = helperBean.calculateTimeZz(
									entity.getWeigthS(), capacity[0],
									planTimeB, standSteel);
						}
					}
					// 修改数据
					entity.setPlanTimeB(planTimeB);
					entity.setPlanUserTime(timeEntity.getUserTime());
					entity.setPlanTimeE(timeEntity.getEndTime());
					entity.setMemo(entity.getOrglMemo());
					helperBean.updatePlanOrder(con, entity, processCode,
							entity.getProMonth());
					// 时间自动调整
					helperBean.timeIncrease(con, entity.getGxProSeq(),
							entity.getPlineCode(), timeEntity.getEndTime(),
							processCode);
				}
			}
			// helperBean.generateZyBatchId(con, plineCode, processCode);
			core.setV_errMsg("初始化成功!");
			core.setResult(true);
			con.commit();
		} catch (Exception e) {
			e.printStackTrace();
			try {
				if (con != null) {
					con.rollback();
				}
			} catch (Exception e1) {
				e1.printStackTrace();
			}
		} finally {
			try {
				if (con != null && !con.isClosed())
					con.close();
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
		return core;
	}

	/**
	 * 时间调整
	 * 
	 * @param jsonStr
	 * @param processCode
	 * @return
	 */
	public CoreReturnObject TimeChange(String jsonStr, String processCode) {
		CoreReturnObject core = new CoreReturnObject();
		core.setResult(false);
		Connection con = null;
		try {
			con = this.getDao(CoreConstantData.sysbeanstr).getConnection();
			con.setAutoCommit(false);
			ProducHelperBean helperBean = new ProducHelperBean();
			ProducEntity entity = helperBean.genertionProEntity(con, jsonStr,
					processCode);
			if (entity == null) {
				core.setV_errMsg("数据异常,请刷新数据!");
				return core;
			}
			// 验证状态
			if (!entity.getExeStatus().equals("1")) {
				core.setV_errMsg("只有生产中状态才能调整时间!");
				return core;
			}
			String planTimeB = entity.getOrglPlanTimeB();
			// 修改时间
			String planTimeE = BaseHelper.addTime(planTimeB,
					entity.getPlanUserTime());
			entity.setPlanTimeB(planTimeB);
			entity.setPlanTimeE(planTimeE);
			helperBean.updatePlanOrder(con, entity, processCode,
					entity.getProMonth());
			// 下个序号的时间自增
			helperBean.timeIncrease(con, entity.getGxProSeq(),
					entity.getPlineCode(), planTimeE, processCode);
			// helperBean.generateZyBatchId(con, entity.getPlineCode(),
			// processCode);
			core.setV_errMsg("时间调整成功!");
			core.setResult(true);
			con.commit();
		} catch (Exception e) {
			e.printStackTrace();
			try {
				if (con != null) {
					con.rollback();
				}
			} catch (Exception e1) {
				e1.printStackTrace();
			}
		} finally {
			try {
				if (con != null && !con.isClosed())
					con.close();
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
		return core;
	}

	/***
	 * 查询订单所在供应商
	 * @param entity
	 * @return
	 */
	public String getSuppUnitCode(ProducEntity entity,String processCode,Connection con) throws SQLException {
		String supplyCode = "";
		PreparedStatement ps = null;
		ResultSet rs = null;
		String sql = "";
		if(processCode.equals("F"))
		{
			sql = CoreXmlSqlParsersFactory.getSql("ProducHelper.getSuppUnitCodeRcl");
		}else if(processCode.equals("G"))
		{
			sql = CoreXmlSqlParsersFactory.getSql("ProducHelper.getSuppUnitCodeJgx");
		}
		sql = EntityTool.fillSqlByEntity(sql,entity);
		ps = con.prepareStatement(sql);
		rs = ps.executeQuery();
		if(rs.next())
		{
			supplyCode = rs.getString("SUPPLY_UNIT_CODE");
		}
		rs.close();
		ps.close();
		return  supplyCode;
	}
	/***
	 * 查询产线所属供应商
	 * @param entity
	 * @return
	 */
	public String getPlineSCode(ProducEntity entity,Connection con) throws SQLException {
		String supplyCode = "";
		PreparedStatement ps = null;
		ResultSet rs = null;
		String sql = CoreXmlSqlParsersFactory.getSql("ProducHelper.getPlineSCode");

		sql = EntityTool.fillSqlByEntity(sql,entity);
		ps = con.prepareStatement(sql);
		rs = ps.executeQuery();
		if(rs.next())
		{
			supplyCode = rs.getString("SUPPLY_UNIT_CODE");
		}
		rs.close();
		ps.close();
		return  supplyCode;
	}

	/**
	 * 产线调整
	 * 
	 * @param jsonStrList
	 *            json字符串集合
	 * @return
	 */
	public CoreReturnObject plineChange(ArrayList<String> jsonStrList,
			String processCode) {
		CoreReturnObject core = new CoreReturnObject();
		core.setResult(false);
		Connection con = null;
		try {
			con = this.getDao(CoreConstantData.sysbeanstr).getConnection();
			con.setAutoCommit(false);
			ProducHelperBean helperBean = new ProducHelperBean();

			String suppUnitCode = "";//供应商代码
			String plineSCode = "";//产线所属供应商
			for (String jsonStr : jsonStrList) {
				ProducEntity entity = helperBean.genertionProEntity(con,
						jsonStr, processCode);
				if (entity == null) {
					core.setV_errMsg("数据异常,请刷新数据!");
					return core;
				}
				//判断成品点、供货商
				if(entity.getDecision().equals("A"))
				{
					suppUnitCode = getSuppUnitCode(entity,processCode,con);
					plineSCode = getPlineSCode(entity,con);

					if(!suppUnitCode.equals(plineSCode))
					{
						core.setV_errMsg("成品点供应商与调整后产线所属供应商不一致,不允许做产线/分组调整!");
						return core;
					}
				}


				// 验证状态
				if (!entity.getExeStatus().equals("0")) {
					core.setV_errMsg("订单编号(" + entity.getProPlanId()
							+ ")不是计划状态!");
					return core;
				}
				if (processCode.equals("B")) {
					// 是否下发
					if (entity.getIsPlanOk().equals("1")) {
						core.setV_errMsg("订单编号(" + entity.getProPlanId()
								+ ")已经下发!");
						return core;
					}
				} else {
					// 是否下发
					if (entity.getIsPlanOk().equals("1")) {
						core.setV_errMsg("订单编号(" + entity.getProPlanId()
								+ ")已经确认!");
						return core;
					}
				}

				if (entity.getIfStoveIssued().equals("1")) {
					core.setV_errMsg("订单编号(" + entity.getProPlanId()
							+ ") 炉计划已经下发!");
					return core;
				}
				// 验证状态
				if (entity.getIsRepairPlan().equals("1")) {
					core.setV_errMsg("订单编号(" + entity.getProPlanId()
							+ ")是检修,不能调整产线!");
					return core;
				}
				String plineCode = entity.getPlineCode();
				// 调整后的产线
				String plineCodeM = entity.getOrglPlineCode();
				String plineNameM = entity.getOrglPlineName();
				// if (!processCode.equals("B")) {
				// 如果产线与数据库没有发生变化,则不作操作
				// if (plineCode.equals(plineCodeM)) {
				// continue;
				// }
				// }

				// 生产序号
				int gxProSeq = helperBean.getMaxGxProSeq(con, plineCodeM,
						processCode, entity.getProMonth());
				// 调整后的计划开始时间
				String planTimeB = helperBean.getMaxPlanTimeE(con, plineCodeM,
						processCode, entity.getProMonth(), gxProSeq);
				if (planTimeB.equals("")) {
					core.setV_errMsg("计划开始时间为空,产线调整失败!");
					return core;

				}
				// 产线能力
				double[] capacity = helperBean.getPlineCapacity(con,
						entity.getInwlId(), entity.getOutwlId(), plineCodeM,
						processCode);
				// if (!processCode.equals("B")) {
				if (capacity[0] <= 0) {
					core.setV_errMsg("订单编号(" + entity.getProPlanId() + "),产线("
							+ plineNameM + ")没有维护小时能力!");
					return core;
				}
				// }
				if (capacity[1] == 0) {
					core.setV_errMsg("订单编号(" + entity.getProPlanId() + "),产线("
							+ plineNameM + ")没有对应的投入产出物料,不能调整!");
					return core;
				}
				TimeEntity timeEntity = new TimeEntity();
				if (!processCode.equals("B")) {
					// 重算用时与结束时间
					timeEntity = helperBean.calculateTime(entity.getInNumS(),
							capacity[0], planTimeB);
				} else {
					double[] steelArr = FrmSteelMakingPlanChange
							.getPlineLgParams(con, entity.getPlineCodeA());
					if (steelArr == null) {
						core.setV_errMsg("电炉(" + entity.getPlineNameA()
								+ ")没有排产基础数据!");
						return core;
					}
					double standSteel = steelArr[0];// 标准出钢量
					timeEntity = helperBean.calculateTimeZz(
							entity.getWeigthS(), capacity[0], planTimeB,
							standSteel);
				}
				// 原始产线的数据序号减1
				helperBean.seqIncrease(con, plineCode, entity.getGxProSeq(),
						-1, -1, processCode);
				// 新产线修改数据
				entity.setPlanTimeB(planTimeB);
				entity.setPlanTimeE(timeEntity.getEndTime());
				entity.setPlanUserTime(timeEntity.getUserTime());

				entity.setExeStatus("0");
				entity.setPlineCode(plineCodeM);
				entity.setPlineName(plineNameM);
				entity.setGxProSeq(gxProSeq);
				entity.setIsPlanOk("0");
				entity.setIssuedMan("");
				entity.setIssuedTime("");
				entity.setLastUndownMan("");
				entity.setLastUndownTime("");

				/*
				 * String craftNo = FrmSteelMakingPlanChange.queryFurnNoCraftNo(
				 * con, entity.getCic(), plineCodeM, entity.getGradecode(),
				 * entity.getStationDesc());
				 */
				if (!plineCode.equals(plineCodeM)) {
					helperBean.seqIncrease(con, entity.getPlineCode(),
							gxProSeq, -1, 1, processCode);
				}
				helperBean.updatePlanOrder(con, entity, processCode,
						entity.getProMonth());
				if (!plineCode.equals(plineCodeM)) {
					// 时间自动调整
					helperBean.timeIncrease(con, entity.getGxProSeq(),
							entity.getPlineCode(), timeEntity.getEndTime(),
							processCode);
				}
				// 分组调整
				helperBean.groupChange(con, entity, processCode);
				StoveHelper.updatePlnZyMPline(con, entity.getProPlanId(),
						entity.getGxPlanNo(), processCode, plineCodeM,
						plineNameM, entity.getWholeBacklogDesc());
				if (processCode.equals("D")) {
					String ordLnPk = "";
					String craftSeq = "";
					// 修改检验计划确认标志
					String sql = "SELECT T.ORD_LN_PK,T.CRAFT_SEQ FROM CRAFT_ORD_DESIGN T,PLN_ORDER_ZG_S ZGS, PLN_SALEORD E  WHERE E.ORD_LN_PK = T.ORD_LN_PK "
							+ "AND E.ORD_LN_DLY_PK = ZGS.ORD_LN_DLY_PK  AND T.CRAFT_SEQ = ZGS.CRAFT_SEQ AND ZGS.PRO_PLAN_ID=? AND ZGS.GX_PLAN_NO=? ";
					PreparedStatement ps = con.prepareStatement(sql);
					ps.setObject(1, entity.getProPlanId());
					ps.setObject(2, entity.getGxPlanNo());
					ResultSet rs = ps.executeQuery();
					if (rs.next()) {
						ordLnPk = rs.getString("ORD_LN_PK");
						craftSeq = rs.getString("CRAFT_SEQ");
					}
					rs.close();
					ps.close();

					String deleteS = "DELETE CRAFT_SAMPLING_DETAIL WHERE ORD_LN_PK = '"
							+ ordLnPk
							+ "' AND CRAFT_SEQ='"
							+ craftSeq
							+ "' AND PROCESS_CODE ='D'";
					ps=con.prepareStatement(deleteS);
					ps.executeUpdate();
					ps.close();
					String deleteSM = "DELETE  CRAFT_SAMPLING_M WHERE ORD_LN_PK = '"
							+ ordLnPk
							+ "' AND CRAFT_SEQ='"
							+ craftSeq
							+ "' AND PROCESS_CODE ='D'";
					ps=con.prepareStatement(deleteSM);
					ps.executeUpdate();
					ps.close();
					
					String update = "UPDATE craft_ord_design T SET T.FLAG_D = '0'  WHERE T.ORD_LN_PK = '"+ordLnPk+"'  AND T.CRAFT_SEQ = '"+craftSeq+"'";
					ps=con.prepareStatement(update);
					ps.executeUpdate();
					ps.close();
				}
			}
			// helperBean.generateZyBatchId(con, plineCode1, processCode);
			core.setResult(true);
			core.setV_errMsg("产线调整成功!");
			con.commit();
		} catch (Exception e) {
			core.setV_errMsg(e.getMessage());
			try {
				if (con != null) {
					con.rollback();
				}
			} catch (Exception e1) {
				e1.printStackTrace();
			}
		} finally {
			try {
				if (con != null && !con.isClosed())
					con.close();
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
		return core;
	}

	/**
	 * 查询产线最大时间（界面）
	 * 
	 * @param plineCode
	 * @param processCode
	 * @return
	 */
	public CoreReturnObject getMaxTime(String plineCode, String processCode) {
		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 = ?";
		} 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 = ?";
		}
		Object[] params = new Object[] { plineCode };
		return this.getData(sql, params);
	}

	/**
	 * 炉计划下发
	 * 
	 * @param
	 * @param userName
	 * @param processCode
	 * @return
	 */
	public CoreReturnObject stoveIssued(ArrayList<String> jsonList,
			String userName, String processCode) {
		CoreReturnObject core = new CoreReturnObject();
		//Connection tmsCon = this.getDao("TmsDao").getConnection();注释生产物流  2024/4/24 肖沅累
		core.setResult(false);
		Connection con = null;
		try {
			con = this.getDao(CoreConstantData.sysbeanstr).getConnection();
			con.setAutoCommit(false);
			String strTime = FrmSteelMakingPlanChange.getSystemTime(con);
			ProducHelperBean helperBean = new ProducHelperBean();
			String message = helperBean.stoveIssued(con, jsonList, processCode,
					userName, strTime);

			if (message.length() > 0) {
				core.setV_errMsg(message);
				return core;
			}
			//生成运输需求
			/*String msg = writeDemand.writeDemandPln(jsonList,processCode,userName,tmsCon,con);
			if(!msg.equals(""))
			{
				core.setV_errMsg("炉计划下发时,生成运输需求出错!");
				return  core;
			}*/
			core.setResult(true);
			core.setV_errMsg("下发成功!");
			con.commit();
		} catch (Exception e) {
			e.printStackTrace();
			try {
				if (con != null /*&& tmsCon !=null*/) {
					con.rollback();
					//tmsCon.rollback();
				}
			} catch (Exception e1) {
				e1.printStackTrace();
			}
		} finally {
			try {
				if (con != null && !con.isClosed())
					con.close();
				/*if (tmsCon != null && !tmsCon.isClosed())
					tmsCon.close();*/
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
		return core;
	}

	/**
	 * 取消炉计划下发
	 * 
	 * @param
	 * @param userName
	 * @param processCode
	 * @return
	 */
	public CoreReturnObject cancelStoveIssued(ArrayList<String> jsonList,
			String userName, String processCode) {
		CoreReturnObject core = new CoreReturnObject();
		//Connection tmsCon = this.getDao("TmsDao").getConnection();
		core.setResult(false);
		Connection con = null;
		try {
			con = this.getDao(CoreConstantData.sysbeanstr).getConnection();
			con.setAutoCommit(false);
			String strTime = FrmSteelMakingPlanChange.getSystemTime(con);
			ProducHelperBean helperBean = new ProducHelperBean();
			String message = helperBean.cancelStoveIssued(con, jsonList,
					processCode, userName, strTime);
			if (message.length() > 0) {
				core.setV_errMsg(message);
				return core;
			}
			//删除运输需求
			/*String msg = writeDemand.cancelWriteDemandPln(jsonList,processCode,userName,tmsCon,con);
			if(!msg.equals(""))
			{
				core.setV_errMsg("炉计划下发时,生成运输需求出错!");
				return  core;
			}*/

			core.setResult(true);
			core.setV_errMsg("取消下发成功!");
			con.commit();
		} catch (Exception e) {
			e.printStackTrace();
			try {
				if (con != null) {
					con.rollback();
				}
			} catch (Exception e1) {
				e1.printStackTrace();
			}
		} finally {
			try {
				if (con != null && !con.isClosed())
					con.close();
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
		return core;
	}

	/**
	 * 设置上料行
	 * 
	 * @param jsonStr
	 * @param processCode
	 * @return
	 */
	public CoreReturnObject setIfOnloadLine(String jsonStr, String processCode) {
		CoreReturnObject core = new CoreReturnObject();
		core.setResult(false);
		Connection con = null;
		try {
			con = this.getDao(CoreConstantData.sysbeanstr).getConnection();
			con.setAutoCommit(false);
			ProducHelperBean helperBean = new ProducHelperBean();
			String message = helperBean
					.setOnloadLine(con, jsonStr, processCode);
			if (message.length() > 0) {
				core.setV_errMsg(message);
				return core;
			}
			core.setResult(true);
			core.setV_errMsg("设置上料行成功!");
			con.commit();
		} catch (Exception e) {
			e.printStackTrace();
			try {
				if (con != null) {
					con.rollback();
				}
			} catch (Exception e1) {
				e1.printStackTrace();
			}
		} finally {
			try {
				if (con != null && !con.isClosed())
					con.close();
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
		return core;
	}

	/**
	 * 炉计划拆分
	 * 
	 * @param jsonStr
	 * @param processCode
	 * @return
	 */
	public CoreReturnObject stoveSpit(ArrayList<String> jsonStr,
			String userName, String processCode) {
		CoreReturnObject core = new CoreReturnObject();
		core.setResult(false);
		Connection con = null;
		try {
			con = this.getDao(CoreConstantData.sysbeanstr).getConnection();
			con.setAutoCommit(false);
			ProducHelperBean helperBean = new ProducHelperBean();
			String message = helperBean.stoveSpit(con, jsonStr, userName,
					processCode);
			if (message.length() > 0) {
				core.setV_errMsg(message);
				return core;
			}
			core.setResult(true);
			core.setV_errMsg("虚拟炉计划拆分成功!");
			con.commit();
		} catch (Exception e) {
			e.printStackTrace();
			try {
				if (con != null) {
					con.rollback();
				}
			} catch (Exception e1) {
				e1.printStackTrace();
			}
		} finally {
			try {
				if (con != null && !con.isClosed())
					con.close();
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
		return core;
	}

	/**
	 * 设置完成
	 * 
	 * @param jsonStr
	 * @param processCode
	 * @return
	 */
	public CoreReturnObject setPlanFinish(ArrayList<String> jsonStr,
			String userName, String processCode) {
		CoreReturnObject core = new CoreReturnObject();
		core.setResult(false);
		Connection con = null;
		try {
			con = this.getDao(CoreConstantData.sysbeanstr).getConnection();
			con.setAutoCommit(false);
			ProducHelperBean.setPlanFinish(con, jsonStr, userName, processCode);
			// if (message.length() > 0) {
			// core.setV_errMsg(message);
			// return core;
			// }
			core.setResult(true);
			core.setV_errMsg("设置合同完成成功!");
			con.commit();
		} catch (Exception e) {
			// e.printStackTrace();
			core.setV_errMsg(e.getMessage());
			try {
				if (con != null) {
					con.rollback();
				}
			} catch (Exception e1) {
				e1.printStackTrace();
			}
		} finally {
			try {
				if (con != null && !con.isClosed())
					con.close();
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
		return core;
	}

	/**
	 * 修改切头尾数据
	 * 
	 * @param list
	 * @return
	 * @throws ParseException
	 */
	public CoreReturnObject updateCrop(ArrayList<ArrayList<String>> list,
			String username) {
		CoreReturnObject cro = new CoreReturnObject();
		Connection conn = null;
		PreparedStatement psta = null;
		String sql = "";
		try {
			conn = this.getDao(CoreConstantData.sysbeanstr).getConnection();
			conn.setAutoCommit(false);
			ArrayList<String> messageErr = new ArrayList<String>();
			String updateCrop = CoreXmlSqlParsersFactory
					.getSql("ProducHelperBean.updateCrop"); // 修改切头尾数据
			PreparedStatement pstaCrop = conn.prepareStatement(updateCrop);
			for (int i = 0; i < list.size(); i++) {
				String cancelMan = list.get(i).get(0);
				String proPlanId = list.get(i).get(1);
				String gxPlanNo = list.get(i).get(2);
				String inwlId = list.get(i).get(3);// 投入物料
				String outwlId = list.get(i).get(4);// 产出物料
				String plineCode = list.get(i).get(5);// 产线

				String isPlanOk = "";// 确认标志
				String exeStatus = "";// 计划状态
				String ifStoveIssued = "";// 下发标志
				// 查轧管排产状态
				sql = CoreXmlSqlParsersFactory
						.getSql("ProducHelperBean.selectPlnZgStatus");
				psta = conn.prepareStatement(sql);
				psta.setObject(1, proPlanId);
				psta.setObject(2, gxPlanNo);
				ResultSet rs = psta.executeQuery();
				if (rs.next()) {
					isPlanOk = rs.getString("IS_PLAN_OK");
					exeStatus = rs.getString("EXE_STATUS");
					ifStoveIssued = rs.getString("IF_STOVE_ISSUED");
				} else {
					cro.setV_errMsg("您选择的订单已撤销下发！");
					return cro;
				}
				rs.close();
				psta.close();

				if (isPlanOk != null && isPlanOk.equals("1")) {
					cro.setV_errMsg("您选择的订单已确认，不允许此操作！");
					return cro;
				}
				if (ifStoveIssued != null && ifStoveIssued.equals("1")) {
					cro.setV_errMsg("您选择的订单已下发，不允许此操作！");
					return cro;
				}
				if (!exeStatus.equals("0")) {
					cro.setV_errMsg("您选择的订单状态不是计划状态，不允许此操作！");
					return cro;
				}
				String cropHead = "";
				String cropEnd = "";
				// 查询基础数据切头尾
				sql = CoreXmlSqlParsersFactory
						.getSql("ProducHelperBean.selectCrop");
				psta = conn.prepareStatement(sql);
				psta.setObject(1, proPlanId);
				psta.setObject(2, gxPlanNo);
				psta.setObject(3, plineCode);
				ResultSet rsta = psta.executeQuery();
				if (rsta.next()) {
					cropHead = rsta.getString("CROP_HEAD");
					cropEnd = rsta.getString("CROP_END");
				}
				rsta.close();
				psta.close();

				pstaCrop.setObject(1, cropHead);
				pstaCrop.setObject(2, cropEnd);
				pstaCrop.setObject(3, proPlanId);
				pstaCrop.setObject(4, gxPlanNo);
				pstaCrop.addBatch();
			}
			pstaCrop.executeBatch();
			cro.setV_errMsg("批量获取切头尾成功！");
			conn.commit();
			// cro.setResult(EntityTool.getGsonByEntity(messageErr));
		} catch (SQLException sqle) {
			try {
				if (conn != null) {
					conn.rollback();
				}
			} catch (Exception e1) {
				e1.printStackTrace();
			}
		} finally {
			try {
				if (conn != null && !conn.isClosed())
					conn.close();
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
		return cro;
	}

	/**
	 * 修改芯棒直径
	 * 
	 * @param list
	 * @return
	 * @throws ParseException
	 */
	public CoreReturnObject updateDimaM(ArrayList<ArrayList<String>> list) {
		CoreReturnObject cro = new CoreReturnObject();
		Connection conn = null;
		PreparedStatement psta = null;
		String sql = "";
		try {
			conn = this.getDao(CoreConstantData.sysbeanstr).getConnection();
			conn.setAutoCommit(false);
			String updateCrop = CoreXmlSqlParsersFactory
					.getSql("ProducHelperBean.updateDimaM"); // 修改芯棒直径
			PreparedStatement pstaCrop = conn.prepareStatement(updateCrop);
			for (int i = 0; i < list.size(); i++) {
				String proPlanId = list.get(i).get(0);
				String gxPlanNo = list.get(i).get(1);
				String dimaM = list.get(i).get(2);

				String isPlanOk = "";// 确认标志
				String exeStatus = "";// 计划状态
				String ifStoveIssued = "";// 下发标志
				// 查轧管排产状态
				sql = CoreXmlSqlParsersFactory
						.getSql("ProducHelperBean.selectPlnZgStatus");
				psta = conn.prepareStatement(sql);
				psta.setObject(1, proPlanId);
				psta.setObject(2, gxPlanNo);
				ResultSet rs = psta.executeQuery();
				if (rs.next()) {
					isPlanOk = rs.getString("IS_PLAN_OK");
					exeStatus = rs.getString("EXE_STATUS");
					ifStoveIssued = rs.getString("IF_STOVE_ISSUED");
				} else {
					cro.setV_errMsg("您选择的订单已撤销下发！");
					return cro;
				}
				rs.close();
				psta.close();

				// if (isPlanOk != null && isPlanOk.equals("1")) {
				// cro.setV_errMsg("您选择的订单已确认，不允许此操作！");
				// return cro;
				// }
				// if (ifStoveIssued != null && ifStoveIssued.equals("1")) {
				// cro.setV_errMsg("您选择的订单已下发，不允许此操作！");
				// return cro;
				// }
				if (!exeStatus.equals("0")) {
					cro.setV_errMsg("您选择的订单状态不是计划状态，不允许此操作！");
					return cro;
				}

				pstaCrop.setObject(1, dimaM);
				pstaCrop.setObject(2, proPlanId);
				pstaCrop.setObject(3, gxPlanNo);
				pstaCrop.addBatch();
			}
			pstaCrop.executeBatch();
			cro.setV_errMsg("芯棒直径调整成功！");
			conn.commit();
			// cro.setResult(EntityTool.getGsonByEntity(messageErr));
		} catch (SQLException sqle) {
			try {
				if (conn != null) {
					conn.rollback();
				}
			} catch (Exception e1) {
				e1.printStackTrace();
			}
		} finally {
			try {
				if (conn != null && !conn.isClosed())
					conn.close();
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
		return cro;
	}

	/**
	 * 查询轧管实际炉计划
	 * 
	 * @param proPlanId
	 *            　订单编号
	 * @return CoreReturnObject
	 */
	public CoreReturnObject doQueryActual(String proPlanId, String gxPlanNo) {
		String sql = CoreXmlSqlParsersFactory
				.getSql("ProducHelper.doQueryActual");
		return this.getData(sql, new Object[] { proPlanId, gxPlanNo });
	}

	/**
	 * 查询轧管虚拟炉计划
	 * 
	 * @param proPlanId
	 *            　订单编号
	 * @return CoreReturnObject
	 */
	public CoreReturnObject doQueryActualM(String proPlanId, String gxPlanNo) {
		String sql = CoreXmlSqlParsersFactory
				.getSql("ProducHelper.doQueryActualM");
		return this.getData(sql, new Object[] { proPlanId, gxPlanNo });
	}

	/**
	 * 查询镦拔扩，热处理，加工线虚拟炉计划
	 * 
	 * @param proPlanId
	 *            　订单编号
	 * @return CoreReturnObject
	 */
	public CoreReturnObject doQueryStarM(String proPlanId, String gxPlanNo,
			String procesCode) {
		String sql = "";
		if (procesCode.equals("E")) {
			sql = CoreXmlSqlParsersFactory
					.getSql("ProducHelper.doQueryActualMDbk");
		} else if (procesCode.equals("F")) {
			sql = CoreXmlSqlParsersFactory
					.getSql("ProducHelper.doQueryActualMRcl");
		} else if (procesCode.equals("G")) {
			sql = CoreXmlSqlParsersFactory
					.getSql("ProducHelper.doQueryActualMJgx");
		} else if (procesCode.equals("H")) {
			sql = CoreXmlSqlParsersFactory
					.getSql("ProducHelper.doQueryActualMJg");
		}
		return this.getData(sql, new Object[] { proPlanId, gxPlanNo });
	}

	/**
	 * 根据工序 判断判定字头
	 * 
	 * @param wholeBacklog
	 * @param wholeBacklogDesc
	 * @param processCode
	 * @return
	 */
	public static String getDecision(String wholeBacklog,
			String wholeBacklogDesc, String processCode, String orderSour) {
		if (processCode.equals("E")) {
			// 如果制程 镦拔扩结束，返回A
			if (wholeBacklog.endsWith("E")) {
				if (orderSour.equals("备料需求")) {
					return "B";
				} else {
					return "A";
				}
			} else {
				// 如果制程经过热处理，二级工序不包含仅探伤，返回c
				if (!wholeBacklogDesc.contains("仅探伤")
						&& wholeBacklog.contains("F")) {
					return "C";
				} else {
					return "B";
				}
			}
		} else if (processCode.equals("F")) {
			// 如果制程 热处理结束，返回A
			if (wholeBacklog.endsWith("F")) {
				if (orderSour.equals("备料需求")) {
					return "B";
				} else {
					return "A";
				}
			} else {
				return "B";
			}
		} else if (processCode.equals("G")) {
			if (orderSour.equals("备料需求")) {
				return "B";
			} else {
				return "A";
			}
		}
		return "";
	}

	/**
	 * 修改判定字头
	 * 
	 * @param
	 * @return
	 */
	public CoreReturnObject doDecision(ArrayList<ArrayList<String>> jsonList,
			String processCode) {
		CoreReturnObject cro = new CoreReturnObject();
		Connection conn = null;
		try {
			conn = this.getDao(CoreConstantData.sysbeanstr).getConnection();
			conn.setAutoCommit(false);
			PreparedStatement ps = null;
			ResultSet rs = null;
			for (int i = 0; i < jsonList.size(); i++) {

				String proPlanId = jsonList.get(i).get(0);
				String gxPlanNo = jsonList.get(i).get(1);
				String decision = jsonList.get(i).get(2);
				String sql = "";// 查询订单
				String sqlupdate = "";// 修改排产订单
				String sqlupdateZy = "";// 修改炉计划
				String isendgx = "0";
				String plineCode = "";
				String wholeDesc = "";
				String sqlBom = "";
				if (decision.equals("A")) {
					isendgx = "1";
				}
				// 查询订单向下炉计划
				List<PlnZyDbkMEntity> plnDbk = null;
				List<PlnZyRclMEntity> plnRcl = null;
				if (processCode.equals("E"))// 镦拔扩
				{
					sql = CoreXmlSqlParsersFactory
							.getSql("ProducHelper.QueryPlnDbk");
					plnDbk = FrmPlanStoveE.getPlnZyM(conn, proPlanId, gxPlanNo,
							"E", PlnZyDbkMEntity.class);
					sqlBom = CoreXmlSqlParsersFactory
							.getSql("FrmPlanMaterialDbk.queryBaseMaterialEPl");
					sqlBom += " AND T.E_IN_MATERIAL_NO=?";
					sqlupdate = "UPDATE PLN_ORDER_DBK_S T SET T.DECISION=?,T.ISENDGX=? WHERE T.PRO_PLAN_ID=? AND T.GX_PLAN_NO=?";
					sqlupdateZy = "UPDATE PLN_ZY_DBK_M T SET T.GOWHERE_CODE=?,T.GOWHERE_NAME=?,T.NEXT_PROCESS_CODE=?,T.ISENDGX=?,T.DECISION=?,T.OUTWL_ID=?,T.OUTWL_DESC=?,T.SPEC_CODE=?,T.SPEC_NAME=? WHERE T.HEAT_PLAN_NO=? ";
				} else if (processCode.equals("F"))// 热处理
				{
					sql = CoreXmlSqlParsersFactory
							.getSql("ProducHelper.QueryPlnRcl");
					plnRcl = FrmPlanStoveE.getPlnZyM(conn, proPlanId, gxPlanNo,
							"F", PlnZyRclMEntity.class);
					sqlBom = CoreXmlSqlParsersFactory
							.getSql("FrmPlanMaterialDbk.queryBaseMaterialFPl");
					sqlBom += " AND T.F_IN_MATERIAL_NO=?";

					sqlupdate = "UPDATE PLN_ORDER_RCL_S T SET T.DECISION=?,T.ISENDGX=? WHERE T.PRO_PLAN_ID=? AND T.GX_PLAN_NO=?";
					sqlupdateZy = "UPDATE PLN_ZY_RCL_M T SET T.GOWHERE_CODE=?,T.GOWHERE_NAME=?,T.NEXT_PROCESS_CODE=?,T.ISENDGX=?,T.DECISION=?,T.OUTWL_ID=?,T.OUTWL_DESC=?,T.SPEC_CODE=?,T.SPEC_NAME=? WHERE T.HEAT_PLAN_NO=?";
				}
				ps = conn.prepareStatement(sql);
				ps.setObject(1, proPlanId);
				ps.setObject(2, gxPlanNo);
				rs = ps.executeQuery();
				if (rs.next()) {
					plineCode = rs.getString("PLINE_CODE");
					wholeDesc = rs.getString("WHOLE_BACKLOG_DESC");
					if (!rs.getString("EXE_STATUS").equals("0")) {
						cro.setV_errMsg("订单号：" + proPlanId + "/" + gxPlanNo
								+ ",不是计划状态,不允许修改。");
						return cro;
					}
					// if (rs.getInt("COUNTZY") > 0) {
					// cro.setV_errMsg("订单号：" + proPlanId + "/" + gxPlanNo
					// + ",已存在炉计划,不允许修改。");
					// return cro;
					// }
					if (rs.getString("IF_STOVE_ISSUED").equals("是")) {
						cro.setV_errMsg("订单号：" + proPlanId + "/" + gxPlanNo
								+ ",已炉计划下发,不允许修改。");
						return cro;
					}
				} else {
					cro.setV_errMsg("找不到订单号：" + proPlanId + "/" + gxPlanNo
							+ "。");
					return cro;
				}
				rs.close();
				ps.close();

				// 修改判定字头
				ps = conn.prepareStatement(sqlupdate);
				ps.setObject(1, decision);
				ps.setObject(2, isendgx);
				ps.setObject(3, proPlanId);
				ps.setObject(4, gxPlanNo);
				ps.executeUpdate();
				ps.close();

				String gowWhereCode = "";
				String gowWhere = "";
				gowWhere = corePlanFurnProM.getPlineCodeGroup(conn, plineCode,
						proPlanId, gxPlanNo, processCode);
				if (gowWhere != null) {
					if (gowWhere.contains("汽运")) {
						gowWhereCode = "110501";
					} else if (gowWhere.contains("铁运")) {
						gowWhereCode = "110502";
					} else {
						String sqlPln = "SELECT T.PLINE_CODE FROM COM_BASE_PLINE T WHERE T.PLINE_NAME=?";
						ps = conn.prepareStatement(sqlPln);
						ps.setObject(1, gowWhere);
						rs = ps.executeQuery();
						if (rs.next()) {
							gowWhereCode = rs.getString("PLINE_CODE");
						}
						rs.close();
						ps.close();
					}
				}
				String nextProcessCode = "";
				String outwlId = "";
				String outwlDesc = "";
				String materialNocp = "";
				String materialdesccp = "";
				String specCode = "";
				String specName = "";

				if (processCode.equals("E"))// 镦拔扩
				{
					if (plnDbk != null) {
						for (PlnZyDbkMEntity dbk : plnDbk) {
							if (!dbk.getPlanstatus().equals("00")) {
								cro.setV_errMsg("订单号：" + proPlanId + "/"
										+ gxPlanNo + ",向下炉计划已下发,不允许修改。");
								return cro;
							}
							// 根据投入物料，制程号，交货行pK,工艺序号查询本工序产出物料
							ps = conn.prepareStatement(sqlBom);
							ps.setObject(1, dbk.getOrdLnDlyPk());
							ps.setObject(2, dbk.getIndexSeq());
							ps.setObject(3, dbk.getCraftSeq());
							ps.setObject(4, dbk.getInwlId());
							rs = ps.executeQuery();
							if (rs.next()) {
								outwlId = rs.getString("OUT_MATERIAL_NO");
								outwlDesc = rs.getString("OUT_MATERIAL_DESC");
								materialNocp = rs.getString("MATERIAL_NO");
								materialdesccp = rs.getString("MATERIAL_DESC");
								specCode = rs.getString("SPEC_CODE_C");
								specName = rs.getString("SPEC_NAME_C");
							} else {
								cro.setV_errMsg("未找到物料!");
								return cro;
							}
							rs.close();
							ps.close();

							String wlId = "";
							String wlDesc = "";
							if (!decision.equals("A")) {
								if (processCode.equals("E")) {
									// 通过制程判定是否末工序
									if (wholeDesc.contains("热处理")) {
										nextProcessCode = "F";
									} else if (wholeDesc.contains("加工")) {
										nextProcessCode = "G";
									}
								}
								wlId = outwlId;
								wlDesc = outwlDesc;
							} else {
								wlId = materialNocp;
								wlDesc = materialdesccp;
							}
							// 修改炉计划判定字头
							ps = conn.prepareStatement(sqlupdateZy);
							ps.setObject(1, gowWhereCode);
							ps.setObject(2, gowWhere);
							ps.setObject(3, nextProcessCode);
							ps.setObject(4, isendgx);
							ps.setObject(5, decision);
							ps.setObject(6, wlId);
							ps.setObject(7, wlDesc);
							ps.setObject(8, specCode);
							ps.setObject(9, specName);
							ps.setObject(10, dbk.getHeatPlanNo());
							ps.executeUpdate();
							ps.close();
						}
					}
				} else if (processCode.equals("F"))// 热处理
				{
					if (plnRcl != null) {
						for (PlnZyRclMEntity rcl : plnRcl) {
							if (!rcl.getPlanstatus().equals("00")) {
								cro.setV_errMsg("订单号：" + proPlanId + "/"
										+ gxPlanNo + ",向下炉计划已下发,不允许修改。");
								return cro;
							}

							// 根据投入物料，制程号，交货行pK,工艺序号查询本工序产出物料
							ps = conn.prepareStatement(sqlBom);
							ps.setObject(1, rcl.getOrdLnDlyPk());
							ps.setObject(2, rcl.getIndexSeq());
							ps.setObject(3, rcl.getCraftSeq());
							ps.setObject(4, rcl.getInwlId());
							rs = ps.executeQuery();
							if (rs.next()) {
								outwlId = rs.getString("OUT_MATERIAL_NO");
								outwlDesc = rs.getString("OUT_MATERIAL_DESC");
								materialNocp = rs.getString("MATERIAL_NO");
								materialdesccp = rs.getString("MATERIAL_DESC");
								specCode = rs.getString("SPEC_CODE_C");
								specName = rs.getString("SPEC_NAME_C");
							} else {
								cro.setV_errMsg("未找到物料!");
								return cro;
							}
							rs.close();
							ps.close();

							String wlId = "";
							String wlDesc = "";
							if (!decision.equals("A")) {
								if (processCode.equals("F")) {
									if (wholeDesc.contains("加工")) {
										nextProcessCode = "G";
									}
								}
								wlId = outwlId;
								wlDesc = outwlDesc;
							} else {
								wlId = materialNocp;
								wlDesc = materialdesccp;
							}
							// 修改炉计划判定字头
							ps = conn.prepareStatement(sqlupdateZy);
							ps.setObject(1, gowWhereCode);
							ps.setObject(2, gowWhere);
							ps.setObject(3, nextProcessCode);
							ps.setObject(4, isendgx);
							ps.setObject(5, decision);
							ps.setObject(6, wlId);
							ps.setObject(7, wlDesc);
							ps.setObject(8, specCode);
							ps.setObject(9, specName);
							ps.setObject(10, rcl.getHeatPlanNo());
							ps.executeUpdate();
							ps.close();
						}
					}
				}

			}
			cro.setV_errMsg("修改成功!");
			conn.commit();
		} catch (SQLException sqle) {
			try {
				conn.rollback();
			} catch (SQLException e) {
				e.printStackTrace();
			}
			cro.setV_errCode(-1);
			cro.setV_errMsg(sqle.getMessage());
		} finally {
			try {
				if (conn != null && !conn.isClosed()) {
					conn.close();
				}
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
		return cro;
	}

	/**
	 * 修改生产批号
	 * 
	 * @param
	 * @return
	 */
	public CoreReturnObject doUpdateBatch(
			ArrayList<ArrayList<String>> jsonList, String processCode) {
		CoreReturnObject cro = new CoreReturnObject();
		Connection conn = null;
		try {
			conn = this.getDao(CoreConstantData.sysbeanstr).getConnection();
			conn.setAutoCommit(false);
			PreparedStatement ps = null;
			ResultSet rs = null;
			for (int i = 0; i < jsonList.size(); i++) {

				String proPlanId = jsonList.get(i).get(0);
				String gxPlanNo = jsonList.get(i).get(1);
				String ZyBatchId = jsonList.get(i).get(2);
				String sql = "";// 查询订单
				String sqlupdate = "";// 修改排产订单
				String sqlupdateZy = "";// 修改主炉计划
				String sqlupdateZyc = "";// 修改子炉计划
				// 查询订单向下炉计划
				List<PlnZyRclMEntity> plnRcl = null;
				if (processCode.equals("F"))// 热处理
				{
					sql = CoreXmlSqlParsersFactory
							.getSql("ProducHelper.QueryPlnRcl");
					plnRcl = FrmPlanStoveE.getPlnZyM(conn, proPlanId, gxPlanNo,
							"F", PlnZyRclMEntity.class);
					sqlupdate = "UPDATE PLN_ORDER_RCL_S T SET T.ZY_BATCH_ID=? WHERE T.PRO_PLAN_ID=? AND T.GX_PLAN_NO=?";
					sqlupdateZy = "UPDATE PLN_ZY_RCL_M T SET T.ZY_BATCH_ID=?  WHERE T.HEAT_PLAN_NO=?";
					sqlupdateZyc = "UPDATE PLN_ZY_RCL_C T SET T.ZY_BATCH_ID=?  WHERE T.HEAT_PLAN_NO=?";
				}
				ps = conn.prepareStatement(sql);
				ps.setObject(1, proPlanId);
				ps.setObject(2, gxPlanNo);
				rs = ps.executeQuery();
				if (rs.next()) {
					// if (!rs.getString("EXE_STATUS").equals("0")) {
					// cro.setV_errMsg("订单号：" + proPlanId + "/" + gxPlanNo
					// + ",不是计划状态,不允许修改。");
					// return cro;
					// }
					if (rs.getString("IF_STOVE_ISSUED").equals("/")) {
						cro.setV_errMsg("订单号：" + proPlanId + "/" + gxPlanNo
								+ ",未下发,不允许修改。");
						return cro;
					}
				} else {
					cro.setV_errMsg("找不到订单号：" + proPlanId + "/" + gxPlanNo
							+ "。");
					return cro;
				}
				rs.close();
				ps.close();

				// 修改订单生产批号
				ps = conn.prepareStatement(sqlupdate);
				ps.setObject(1, ZyBatchId);
				ps.setObject(2, proPlanId);
				ps.setObject(3, gxPlanNo);
				ps.executeUpdate();
				ps.close();

				if (processCode.equals("F"))// 热处理
				{
					if (plnRcl != null) {
						for (PlnZyRclMEntity rcl : plnRcl) {
							if (!rcl.getPlanstatus().equals("00")
									&& !rcl.getPlanstatus().equals("10")) {
								cro.setV_errMsg("订单号：" + proPlanId + "/"
										+ gxPlanNo + ",向下炉计划不是计划或下发状态,不允许修改。");
								return cro;
							}
							// 修改主炉计划生产批次
							ps = conn.prepareStatement(sqlupdateZy);
							ps.setObject(1, ZyBatchId);
							ps.setObject(2, rcl.getHeatPlanNo());
							ps.executeUpdate();
							ps.close();

							// 修改子炉计划生产批次
							ps = conn.prepareStatement(sqlupdateZyc);
							ps.setObject(1, ZyBatchId);
							ps.setObject(2, rcl.getHeatPlanNo());
							ps.executeUpdate();
							ps.close();
						}
					}
				}

			}
			cro.setV_errMsg("修改成功!");
			conn.commit();
		} catch (SQLException sqle) {
			try {
				conn.rollback();
			} catch (SQLException e) {
				e.printStackTrace();
			}
			cro.setV_errCode(-1);
			cro.setV_errMsg(sqle.getMessage());
		} finally {
			try {
				if (conn != null && !conn.isClosed()) {
					conn.close();
				}
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
		return cro;
	}

	/**
	 * 修改孔型
	 * 
	 * @param
	 * @return
	 */
	public CoreReturnObject UpdatePass(ArrayList<ArrayList<String>> jsonList) {
		CoreReturnObject cro = new CoreReturnObject();
		Connection conn = null;
		try {
			conn = this.getDao(CoreConstantData.sysbeanstr).getConnection();
			conn.setAutoCommit(false);
			PreparedStatement ps = null;
			ResultSet rs = null;
			for (int i = 0; i < jsonList.size(); i++) {

				String proPlanId = jsonList.get(i).get(0);
				String gxPlanNo = jsonList.get(i).get(1);
				String passCode = jsonList.get(i).get(2);
				String passName = jsonList.get(i).get(3);

				// 查询订单
				String sql = CoreXmlSqlParsersFactory
						.getSql("ProducHelper.QueryPlnDbk");
				ps = conn.prepareStatement(sql);
				ps.setObject(1, proPlanId);
				ps.setObject(2, gxPlanNo);
				rs = ps.executeQuery();
				if (rs.next()) {
					if (!rs.getString("EXE_STATUS").equals("0")) {
						cro.setV_errMsg("订单号：" + proPlanId + "/" + gxPlanNo
								+ ",不是计划状态,不允许修改。");
						return cro;
					}
					// if (rs.getInt("COUNTZY") > 0) {
					// cro.setV_errMsg("订单号：" + proPlanId + "/" + gxPlanNo
					// + ",已存在炉计划,不允许修改。");
					// return cro;
					// }
					if (rs.getString("IF_STOVE_ISSUED").equals("是")) {
						cro.setV_errMsg("订单号：" + proPlanId + "/" + gxPlanNo
								+ ",已炉计划下发,不允许修改。");
						return cro;
					}
					if (!rs.getString("PLANSTATUS").equals("00")) {
						cro.setV_errMsg("订单号：" + proPlanId + "/" + gxPlanNo
								+ ",已炉计划下发,不允许修改。");
						return cro;
					}

				} else {
					cro.setV_errMsg("找不到订单号：" + proPlanId + "/" + gxPlanNo
							+ "。");
					return cro;
				}
				rs.close();
				ps.close();

				// 修改订单孔型
				String sqlupdate = "UPDATE PLN_ORDER_DBK_S T SET T.PASS_CODE=?,T.PASS_NAME=? WHERE T.PRO_PLAN_ID=? AND T.GX_PLAN_NO=?";

				ps = conn.prepareStatement(sqlupdate);
				ps.setObject(1, passCode);
				ps.setObject(2, passName);
				ps.setObject(3, proPlanId);
				ps.setObject(4, gxPlanNo);
				ps.executeUpdate();
				ps.close();

				// 修改炉计划孔型
				String sqlupdateZy = "UPDATE PLN_ZY_DBK_M T SET T.PASS_CODE=?,T.PASS_NAME=? WHERE T.PRO_PLAN_ID=? AND T.GX_PLAN_NO=? ";
				ps = conn.prepareStatement(sqlupdateZy);
				ps.setObject(1, passCode);
				ps.setObject(2, passName);
				ps.setObject(3, proPlanId);
				ps.setObject(4, gxPlanNo);
				ps.executeUpdate();
				ps.close();

			}
			cro.setV_errMsg("修改成功!");
			conn.commit();
		} catch (SQLException sqle) {
			try {
				conn.rollback();
			} catch (SQLException e) {
				e.printStackTrace();
			}
			cro.setV_errCode(-1);
			cro.setV_errMsg(sqle.getMessage());
		} finally {
			try {
				if (conn != null && !conn.isClosed()) {
					conn.close();
				}
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
		return cro;
	}

	/***
	 * 修改备注
	 * @param parmList
	 * @return
	 */
	public CoreReturnObject updateProgyMemo(ArrayList<String> parmList)
	{
		CoreReturnObject cro = new CoreReturnObject();
		Connection conn = this.getDao(CoreConstantData.sysbeanstr).getConnection();
		try {
		ArrayList<String> sqllist = new ArrayList<String>();
		for(String str : parmList)
		{
			PlnOrderRclSEntity plnEntity = EntityTool.getEntityByJSONStr(str,PlnOrderRclSEntity.class);
			String updateProgyMemoSql = CoreXmlSqlParsersFactory.getSql("ProducHelper.updateProgyMemo");
			updateProgyMemoSql = EntityTool.fillSqlByEntity(updateProgyMemoSql,plnEntity);
			sqllist.add(updateProgyMemoSql);
		}
		cro = this.getDao(CoreConstantData.sysbeanstr).ExcuteTransction(sqllist);
		if(cro.getV_errMsg().equals(""))
		{
			cro.setV_errMsg("修改成功!");
		}
		} catch (Exception e) {
			System.out.println(e.getMessage());
			if (conn != null) {
				try {
					cro.setV_errMsg(e.getMessage());
					conn.rollback(); // 回滚事务
				} catch (Exception e2) {
				}
			}
		} finally {
			try {
				if (conn != null && !conn.isClosed()) {
					conn.close();
				}
			} catch (Exception e2) {
			}
		}
		return cro;
	}
	
	/***
	 * 修改加工计划备注 TZH 24.11.7 
	 * @param parmList
	 * @return
	 */
	public CoreReturnObject updateJGXPlanMemo(ArrayList<String> parmList)
	{
		CoreReturnObject cro = new CoreReturnObject();
		Connection conn = this.getDao(CoreConstantData.sysbeanstr).getConnection();
		try {
			ArrayList<String> sqllist = new ArrayList<String>();
			for(String str : parmList)
			{
				PlnOrderJgxSEntity plnEntity = EntityTool.getEntityByJSONStr(str,PlnOrderJgxSEntity.class);
				String updateProgyMemoSql = CoreXmlSqlParsersFactory.getSql("ProducHelper.updateJGXPlanMemo");
				updateProgyMemoSql = EntityTool.fillSqlByEntity(updateProgyMemoSql,plnEntity);
				sqllist.add(updateProgyMemoSql);
			}
			cro = this.getDao(CoreConstantData.sysbeanstr).ExcuteTransction(sqllist);
			if(cro.getV_errMsg().equals(""))
			{
				cro.setV_errMsg("修改成功!");
			}
		} catch (Exception e) {
			System.out.println(e.getMessage());
			if (conn != null) {
				try {
					cro.setV_errMsg(e.getMessage());
					conn.rollback(); // 回滚事务
				} catch (Exception e2) {
				}
			}
		} finally {
			try {
				if (conn != null && !conn.isClosed()) {
					conn.close();
				}
			} catch (Exception e2) {
			}
		}
		return cro;
	}

	
	/***
	 * 修改热处理计划备注 TZH 24.9.14 
	 * @param parmList
	 * @return
	 */
	public CoreReturnObject updatePlanMemo(ArrayList<String> parmList)
	{
		CoreReturnObject cro = new CoreReturnObject();
		Connection conn = this.getDao(CoreConstantData.sysbeanstr).getConnection();
		try {
		ArrayList<String> sqllist = new ArrayList<String>();
		for(String str : parmList)
		{
			PlnOrderRclSEntity plnEntity = EntityTool.getEntityByJSONStr(str,PlnOrderRclSEntity.class);
			String updateProgyMemoSql = CoreXmlSqlParsersFactory.getSql("ProducHelper.updatePlanMemo");
			updateProgyMemoSql = EntityTool.fillSqlByEntity(updateProgyMemoSql,plnEntity);
			sqllist.add(updateProgyMemoSql);
		}
		cro = this.getDao(CoreConstantData.sysbeanstr).ExcuteTransction(sqllist);
		if(cro.getV_errMsg().equals(""))
		{
			cro.setV_errMsg("修改成功!");
		}
		} catch (Exception e) {
			System.out.println(e.getMessage());
			if (conn != null) {
				try {
					cro.setV_errMsg(e.getMessage());
					conn.rollback(); // 回滚事务
				} catch (Exception e2) {
				}
			}
		} finally {
			try {
				if (conn != null && !conn.isClosed()) {
					conn.close();
				}
			} catch (Exception e2) {
			}
		}
		return cro;
	}

	/***
	 * 修改备注
	 * @param parmList
	 * @return
	 */
	public CoreReturnObject updateProgyMemoJgx(ArrayList<String> parmList)
	{
		CoreReturnObject cro = new CoreReturnObject();
		Connection conn = this.getDao(CoreConstantData.sysbeanstr).getConnection();
		try {
			ArrayList<String> sqllist = new ArrayList<String>();
			for(String str : parmList)
			{
				PlnOrderJgxSEntity plnEntity = EntityTool.getEntityByJSONStr(str,PlnOrderJgxSEntity.class);
				String updateProgyMemoSql = CoreXmlSqlParsersFactory.getSql("ProducHelper.updateProgyMemoJgx");
				updateProgyMemoSql = EntityTool.fillSqlByEntity(updateProgyMemoSql,plnEntity);
				sqllist.add(updateProgyMemoSql);
			}
			cro = this.getDao(CoreConstantData.sysbeanstr).ExcuteTransction(sqllist);
			if(cro.getV_errMsg().equals(""))
			{
				cro.setV_errMsg("修改成功!");
			}
		} catch (Exception e) {
			System.out.println(e.getMessage());
			if (conn != null) {
				try {
					cro.setV_errMsg(e.getMessage());
					conn.rollback(); // 回滚事务
				} catch (Exception e2) {
				}
			}
		} finally {
			try {
				if (conn != null && !conn.isClosed()) {
					conn.close();
				}
			} catch (Exception e2) {
			}
		}
		return cro;
	}

	/***
	 * 标识监制
	 * @param parmList
	 * @param userName
	 * @param proCode
	 * @return
	 */
	public CoreReturnObject tabNotice(ArrayList<String> parmList,String userName,String proCode)
	{
		CoreReturnObject cro = new CoreReturnObject();
		Connection conn = this.getDao(CoreConstantData.sysbeanstr).getConnection();
		try {
			Date now = new Date();
			SimpleDateFormat dateFormat = new SimpleDateFormat(
					"yyyy-MM-dd HH:mm:ss");
			String systime = dateFormat.format(now);
			String sql = "";
			String updateOrderSql = "";
			PreparedStatement ps = null;
			ResultSet rs = null;
			String ifMonitorZg = "";//是否监制
			String isNoticeEp = "";//监制通知标识
			ArrayList<String> sqllist = new ArrayList<String>();

			if (proCode.equals("D")) {

				for(String str : parmList)
				{
					PlnOrderZgSEntity plnOrderEntity = EntityTool.getEntityByJSONStr(str, PlnOrderZgSEntity.class);
					sql = CoreXmlSqlParsersFactory.getSql("ProducHelper.selectNoticeZg");
					sql = EntityTool.fillSqlByEntity(sql,plnOrderEntity);
					ps = conn.prepareStatement(sql);
					rs = ps.executeQuery();
					if(rs.next())
					{
						ifMonitorZg = rs.getString("IF_MONITOR_ZG");
						isNoticeEp = rs.getString("IS_NOTICE_EP");
					}
					rs.close();
					ps.close();
					if(ifMonitorZg.equals("")||ifMonitorZg.equals("0"))
					{
						cro.setV_errMsg("该订单不需要监制,不允许标记监制信息!");
						return cro;
					}

					if(isNoticeEp==null || isNoticeEp.equals("0"))
					{
						plnOrderEntity.setIsNoticeEp("1");
						plnOrderEntity.setIsNoticeUser(userName);
						plnOrderEntity.setIsNoticeTime(systime);
					}else
					{
						plnOrderEntity.setIsNoticeEp("0");
						plnOrderEntity.setIsNoticeUser("");
						plnOrderEntity.setIsNoticeTime("");
					}

					updateOrderSql = CoreXmlSqlParsersFactory.getSql("ProducHelper.tabNoticeZg");
					updateOrderSql = EntityTool.fillSqlByEntity(updateOrderSql,plnOrderEntity);
					sqllist.add(updateOrderSql);
				}
			} else if (proCode.equals("E")) {
				for(String str : parmList)
				{
					PlnOrderDbkSEntity plnOrderEntity = EntityTool.getEntityByJSONStr(str, PlnOrderDbkSEntity.class);

					sql = CoreXmlSqlParsersFactory.getSql("ProducHelper.selectNoticeDbk");
					sql = EntityTool.fillSqlByEntity(sql,plnOrderEntity);
					ps = conn.prepareStatement(sql);
					rs = ps.executeQuery();
					if(rs.next())
					{
						ifMonitorZg = rs.getString("IF_MONITOR_Dbk");
						isNoticeEp = rs.getString("IS_NOTICE_EP");
					}
					rs.close();
					ps.close();
					if(ifMonitorZg.equals("")||ifMonitorZg.equals("0"))
					{
						cro.setV_errMsg("该订单不需要监制,不允许标记监制信息!");
						return cro;
					}

					if(isNoticeEp==null || isNoticeEp.equals("0"))
					{
						plnOrderEntity.setIsNoticeEp("1");
						plnOrderEntity.setIsNoticeUser(userName);
						plnOrderEntity.setIsNoticeTime(systime);
					}else
					{
						plnOrderEntity.setIsNoticeEp("0");
						plnOrderEntity.setIsNoticeUser("");
						plnOrderEntity.setIsNoticeTime("");
					}
					updateOrderSql = CoreXmlSqlParsersFactory.getSql("ProducHelper.tabNoticeDbk");
					updateOrderSql = EntityTool.fillSqlByEntity(updateOrderSql,plnOrderEntity);
					sqllist.add(updateOrderSql);
				}
			} else if (proCode.equals("F")) {
				for(String str : parmList)
				{
					PlnOrderRclSEntity plnOrderEntity = EntityTool.getEntityByJSONStr(str, PlnOrderRclSEntity.class);

					sql = CoreXmlSqlParsersFactory.getSql("ProducHelper.selectNoticeRcl");
					sql = EntityTool.fillSqlByEntity(sql,plnOrderEntity);
					ps = conn.prepareStatement(sql);
					rs = ps.executeQuery();
					if(rs.next())
					{
						ifMonitorZg = rs.getString("IF_MONITOR_RCL");
						isNoticeEp = rs.getString("IS_NOTICE_EP");
					}
					rs.close();
					ps.close();
					if(ifMonitorZg.equals("")||ifMonitorZg.equals("0"))
					{
						cro.setV_errMsg("该订单不需要监制,不允许标记监制信息!");
						return cro;
					}

					if(isNoticeEp==null || isNoticeEp.equals("0"))
					{
						plnOrderEntity.setIsNoticeEp("1");
						plnOrderEntity.setIsNoticeUser(userName);
						plnOrderEntity.setIsNoticeTime(systime);
					}else
					{
						plnOrderEntity.setIsNoticeEp("0");
						plnOrderEntity.setIsNoticeUser("");
						plnOrderEntity.setIsNoticeTime("");
					}
					updateOrderSql = CoreXmlSqlParsersFactory.getSql("ProducHelper.tabNoticeRcl");
					updateOrderSql = EntityTool.fillSqlByEntity(updateOrderSql,plnOrderEntity);
					sqllist.add(updateOrderSql);
				}
			} else if (proCode.equals("G")) {
				for(String str : parmList)
				{
					PlnOrderJgxSEntity plnOrderEntity = EntityTool.getEntityByJSONStr(str, PlnOrderJgxSEntity.class);
					sql = CoreXmlSqlParsersFactory.getSql("ProducHelper.selectNoticeJgx");
					sql = EntityTool.fillSqlByEntity(sql,plnOrderEntity);
					ps = conn.prepareStatement(sql);
					rs = ps.executeQuery();
					if(rs.next())
					{
						ifMonitorZg = rs.getString("IF_MONITOR_JGX");
						isNoticeEp = rs.getString("IS_NOTICE_EP");
					}
					rs.close();
					ps.close();
					if(ifMonitorZg.equals("")||ifMonitorZg.equals("0"))
					{
						cro.setV_errMsg("该订单不需要监制,不允许标记监制信息!");
						return cro;
					}

					if(isNoticeEp==null || isNoticeEp.equals("0"))
					{
						plnOrderEntity.setIsNoticeEp("1");
						plnOrderEntity.setIsNoticeUser(userName);
						plnOrderEntity.setIsNoticeTime(systime);
					}else
					{
						plnOrderEntity.setIsNoticeEp("0");
						plnOrderEntity.setIsNoticeUser("");
						plnOrderEntity.setIsNoticeTime("");
					}
					updateOrderSql = CoreXmlSqlParsersFactory.getSql("ProducHelper.tabNoticeJgx");
					updateOrderSql = EntityTool.fillSqlByEntity(updateOrderSql,plnOrderEntity);
					sqllist.add(updateOrderSql);
				}
			}
			cro = this.getDao(CoreConstantData.sysbeanstr).ExcuteTransction(sqllist);
			if(cro.getV_errMsg().equals(""))
			{
				cro.setV_errMsg("标识监制成功!");
			}

		} catch (Exception e) {
			System.out.println(e.getMessage());
			if (conn != null) {
				try {
					cro.setV_errMsg(e.getMessage());
					conn.rollback(); // 回滚事务
				} catch (Exception e2) {
				}
			}
		} finally {
			try {
				if (conn != null && !conn.isClosed()) {
					conn.close();
				}
			} catch (Exception e2) {
			}
		}
		return cro;
	}


	/***
	 * 标识监制
	 * @param parmList
	 * @param userName
	 * @param proCode
	 * @return
	 */
	public CoreReturnObject tabNoticeH(ArrayList<String> parmList,String userName,String proCode)
	{
		CoreReturnObject cro = new CoreReturnObject();
		Connection conn = this.getDao(CoreConstantData.sysbeanstr).getConnection();
		try {
			Date now = new Date();
			SimpleDateFormat dateFormat = new SimpleDateFormat(
					"yyyy-MM-dd HH:mm:ss");
			String systime = dateFormat.format(now);
			String sql = "";
			String updateOrderSql = "";
			PreparedStatement ps = null;
			ResultSet rs = null;
			String ifMonitorJg = "";//是否监制
			String isNoticeEp = "";//监制通知标识
			ArrayList<String> sqllist = new ArrayList<String>();



				for(String str : parmList)
				{
					PlnGxJgPropSEntity plnOrderEntity = EntityTool.getEntityByJSONStr(str, PlnGxJgPropSEntity.class);
					sql = CoreXmlSqlParsersFactory.getSql("ProducHelper.selectNoticeH");
					sql = EntityTool.fillSqlByEntity(sql,plnOrderEntity);
					ps = conn.prepareStatement(sql);
					rs = ps.executeQuery();
					if(rs.next())
					{
						ifMonitorJg = rs.getString("IF_MONITOR_JG");
						isNoticeEp = rs.getString("IS_NOTICE_EP");
					}
					rs.close();
					ps.close();
					if(ifMonitorJg.equals("")||ifMonitorJg.equals("0"))
					{
						cro.setV_errMsg("该订单不需要监制,不允许标记监制信息!");
						return cro;
					}

					if(isNoticeEp==null || isNoticeEp.equals("0"))
					{
						plnOrderEntity.setIsNoticeEp("1");
						plnOrderEntity.setIsNoticeUser(userName);
						plnOrderEntity.setIsNoticeTime(systime);
					}else
					{
						plnOrderEntity.setIsNoticeEp("0");
						plnOrderEntity.setIsNoticeUser("");
						plnOrderEntity.setIsNoticeTime("");
					}

					updateOrderSql = CoreXmlSqlParsersFactory.getSql("ProducHelper.tabNoticeH");
					updateOrderSql = EntityTool.fillSqlByEntity(updateOrderSql,plnOrderEntity);
					sqllist.add(updateOrderSql);
				}
			cro = this.getDao(CoreConstantData.sysbeanstr).ExcuteTransction(sqllist);
			if(cro.getV_errMsg().equals(""))
			{
				cro.setV_errMsg("标识监制成功!");
			}

		} catch (Exception e) {
			System.out.println(e.getMessage());
			if (conn != null) {
				try {
					cro.setV_errMsg(e.getMessage());
					conn.rollback(); // 回滚事务
				} catch (Exception e2) {
				}
			}
		} finally {
			try {
				if (conn != null && !conn.isClosed()) {
					conn.close();
				}
			} catch (Exception e2) {
			}
		}
		return cro;
	}


	public CoreReturnObject UpdateOrderTeam(ArrayList<String> parmList,String proCode)
	{
		CoreReturnObject cro = new CoreReturnObject();
		Connection conn = this.getDao(CoreConstantData.sysbeanstr).getConnection();
		try {
			Date now = new Date();
			SimpleDateFormat dateFormat = new SimpleDateFormat(
					"yyyy-MM-dd HH:mm:ss");
			String systime = dateFormat.format(now);
			String sql = "";
			String updateOrderSql = "";
			PreparedStatement ps = null;
			ResultSet rs = null;
			String ifMonitorZg = "";//是否监制
			String isNoticeEp = "";//监制通知标识
			ArrayList<String> sqllist = new ArrayList<String>();

			if (proCode.equals("D")) {

				for(String str : parmList)
				{
					PlnOrderZgSEntity plnOrderEntity = EntityTool.getEntityByJSONStr(str, PlnOrderZgSEntity.class);

					updateOrderSql = CoreXmlSqlParsersFactory.getSql("ProducHelper.UpdateOrderTeamZg");
					updateOrderSql = EntityTool.fillSqlByEntity(updateOrderSql,plnOrderEntity);
					sqllist.add(updateOrderSql);
				}
			} else if (proCode.equals("E")) {
				for(String str : parmList)
				{
					PlnOrderDbkSEntity plnOrderEntity = EntityTool.getEntityByJSONStr(str, PlnOrderDbkSEntity.class);

					updateOrderSql = CoreXmlSqlParsersFactory.getSql("ProducHelper.UpdateOrderTeamDbk");
					updateOrderSql = EntityTool.fillSqlByEntity(updateOrderSql,plnOrderEntity);
					sqllist.add(updateOrderSql);
				}
			} else if (proCode.equals("F")) {
				for(String str : parmList)
				{
					PlnOrderRclSEntity plnOrderEntity = EntityTool.getEntityByJSONStr(str, PlnOrderRclSEntity.class);

					updateOrderSql = CoreXmlSqlParsersFactory.getSql("ProducHelper.UpdateOrderTeamRcl");
					updateOrderSql = EntityTool.fillSqlByEntity(updateOrderSql,plnOrderEntity);
					sqllist.add(updateOrderSql);
				}
			} else if (proCode.equals("G")) {
				for(String str : parmList)
				{
					PlnOrderJgxSEntity plnOrderEntity = EntityTool.getEntityByJSONStr(str, PlnOrderJgxSEntity.class);

					updateOrderSql = CoreXmlSqlParsersFactory.getSql("ProducHelper.UpdateOrderTeamJgx");
					updateOrderSql = EntityTool.fillSqlByEntity(updateOrderSql,plnOrderEntity);
					sqllist.add(updateOrderSql);
				}
			}
			cro = this.getDao(CoreConstantData.sysbeanstr).ExcuteTransction(sqllist);
			if(cro.getV_errMsg().equals(""))
			{
				cro.setV_errMsg("修改成功!");
			}

		} catch (Exception e) {
			System.out.println(e.getMessage());
			if (conn != null) {
				try {
					cro.setV_errMsg(e.getMessage());
					conn.rollback(); // 回滚事务
				} catch (Exception e2) {
				}
			}
		} finally {
			try {
				if (conn != null && !conn.isClosed()) {
					conn.close();
				}
			} catch (Exception e2) {
			}
		}
		return cro;
	}
	
	///tzh 24.10.31    新增修改轧管转移长度下限和上限
	public CoreReturnObject UpdateOrderRollLen(ArrayList<String> parmList)
	{
		CoreReturnObject cro = new CoreReturnObject();
		Connection conn = this.getDao(CoreConstantData.sysbeanstr).getConnection();
		try {
			String updateOrderSql = "";
			ArrayList<String> sqllist = new ArrayList<String>();

				for(String str : parmList)
				{
					PlnOrderZgSEntity plnOrderEntity = EntityTool.getEntityByJSONStr(str, PlnOrderZgSEntity.class);

					updateOrderSql = CoreXmlSqlParsersFactory.getSql("ProducHelper.UpdateOrderRollLen");
					updateOrderSql = EntityTool.fillSqlByEntity(updateOrderSql,plnOrderEntity);
					sqllist.add(updateOrderSql);
				}
			 
			cro = this.getDao(CoreConstantData.sysbeanstr).ExcuteTransction(sqllist);
			if(cro.getV_errMsg().equals(""))
			{
				cro.setV_errMsg("修改成功!");
			}

		} catch (Exception e) {
			System.out.println(e.getMessage());
			if (conn != null) {
				try {
					cro.setV_errMsg(e.getMessage());
					conn.rollback(); // 回滚事务
				} catch (Exception e2) {
				}
			}
		} finally {
			try {
				if (conn != null && !conn.isClosed()) {
					conn.close();
				}
			} catch (Exception e2) {
			}
		}
		return cro;
	}
	
	/**
	 * 根据proPlanId 和gxPlanNo 查询炉计划明细，写入到二级产销系统表(MES_RCL_PLAN)
	 * @param jsonList
	 * @param isAdd
	 * @param connection
	 */
	public void saveMesRclPlan(ArrayList<String> jsonList, boolean isAdd, Connection connection) {
		if (jsonList != null && !jsonList.isEmpty()) {
			PreparedStatement ps = null;
			ResultSet rs = null;
			try {
				for (String json : jsonList) {
					JSONObject plan = JSONObject.fromObject(json);
					/**
					 * "proPlanId": "RCL20240400219", "gxPlanNo": "1",
					 */
					//查询炉计划	
					String sql = CoreXmlSqlParsersFactory
							.getSql("FrmPlanStoveF.queryPlanStoveReadyE");
					sql += "  AND T.PRO_PLAN_ID ='" + plan.getString("proPlanId") + "' AND T.GX_PLAN_NO='" + plan.getString("gxPlanNo") + "'  ORDER BY T.LOT_NO_SQE ASC";

					ps = connection.prepareStatement(sql);
					rs = ps.executeQuery();
					ArrayList<String> heatPlanNoList = new ArrayList<>();
					while (rs.next()) {
						heatPlanNoList.add(rs.getString("HEAT_PLAN_NO"));
					}
					rs.close();
					ps.close();
					List<ArrayList<String>> rowList = new ArrayList<>();
					for (int i = 0; i < heatPlanNoList.size(); i++) {
						String querySql = "select C.HEAT_PLAN_SQE AS PLAN_ID,  M.GRADENAME, C.PLAN_INDOUBLE_NUM,  M.LENGTH_IN, M.OUTDIAMETER_IN, "+
	                               " (M.OUTDIAMETER_IN - M.WALLTHICK_IN) AS BORE, M.WALLTHICK_IN,M.PROCESS_DESC_C, M.JUDGE_STOVE_NO,"
	                               + " ORDER_NO ||'/'||ORDER_SEQ as ORD_NO, PROD_STANDARD,PRODUCNAME,C.PLAN_INDOUBLE_WT,M.IF_MONITOR"
							+ " FROM  PLN_ZY_RCL_C C,PLN_ZY_RCL_M M WHERE M.HEAT_PLAN_NO = C.HEAT_PLAN_NO "
							+ " AND C.HEAT_PLAN_NO=?";
						ps = connection.prepareCall(querySql);
						ps.setObject(1, heatPlanNoList.get(i));
						rs = ps.executeQuery();
						while (rs.next()) {
							ArrayList<String> row = new ArrayList<>();
							row.add(UUID.randomUUID().toString()
									.replaceAll("-", ""));// uuid
							row.add(rs.getString("PLAN_ID"));// plan_id
							row.add(rs.getString("GRADENAME"));// steel_grade
							row.add(rs.getString("PLAN_INDOUBLE_NUM"));// NUM
							row.add(rs.getString("LENGTH_IN"));// LEN
							row.add(rs.getString("OUTDIAMETER_IN"));// od
							row.add(rs.getString("BORE"));// bore
							row.add(rs.getString("WALLTHICK_IN"));// wt
							row.add(rs.getString("PROCESS_DESC_C"));// process
							if (isAdd) {
								row.add("0");// OPERATION_TYPE
							} else {
								row.add("2");// OPERATION_TYPE
							}
							row.add(rs.getString("JUDGE_STOVE_NO"));// JUDGE_STOVE_NO
							row.add(rs.getString("ORD_NO"));// ORDER_NO
							row.add(rs.getString("PROD_STANDARD"));// PROD_STANDARD
							row.add(rs.getString("PRODUCNAME"));// PRODUCNAME
							row.add(rs.getString("PLAN_INDOUBLE_WT"));
							row.add(rs.getString("IF_MONITOR"));
							rowList.add(row);
						}
						rs.close();
						ps.close();
					}

					if (!rowList.isEmpty()) {
						// 写入记录到产销系统
						String insertSql = "INSERT INTO MES_RCL_PLAN (UUID, PLAN_ID, STEEL_GRANDE, NUM, LEN, OD, BORE, WT, PROCESS,"
								+ " OPERATION_TYPE, CREATE_TIME, UPDATE_TIME, FLAGS,JUDGE_STOVE_NO,ORDER_NO,PROD_STANDARD,PRODUCNAME,PLAN_INDOUBLE_WT,IF_MONITOR) VALUES "
								+ "(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, SYSDATE, NULL, NULL,?,?,?,?,?,?)";
						ps = connection.prepareStatement(insertSql);
						for (int i = 0; i < rowList.size(); i++) {
							ArrayList<String> row = rowList.get(i);
							for (int j = 0; j < row.size(); j++) {
								ps.setObject(j + 1, row.get(j));
							}
							ps.addBatch();
						}
						ps.executeBatch();
						ps.clearBatch();
						ps.close();
					}
				}
			} catch (Exception e) {
				if (rs != null) {
					try {
						rs.close();
					} catch (SQLException e1) {
						e1.printStackTrace();
					}
				}
				if (ps != null) {
					try {
						ps.close();
					} catch (SQLException e1) {
						e1.printStackTrace();
					}
				}

				throw new RuntimeException("写入二级系统接口(MES_RCL_PLAN)数据异常", e);
			}

		}
	}
	
	
 
}
