package com.steering.pss.plnsaleord.planStove;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.text.DecimalFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import com.steering.comm.db.DBCommon;
import com.steering.comm.tools.EntityTool;
import com.steering.pss.plnsaleord.planStove.entity.MatBcTrackEntity;
import com.steering.pss.plnsaleord.steelMarkingPlan.FrmSteelMakingPlanChange;
import com.steering.pss.plnsaleord.stove.corePlanFurnProM;
import com.steering.pss.plnsaleord.stove.entity.*;
import com.steering.pss.sale.order.qualityDesign.QualityDesignTool;
import CoreFS.SA06.CoreReturnObject;
import CoreFS.SA08.CoreXmlSqlParsersFactory;
import CoreFS.SC01.CoreConstantData;

/**
 * 管坯材料信息
 * 
 * @author teng 2017.11.21
 */
public class FrmPlanMaterialDbk extends DBCommon {
	/**
	 * 查询管坯库存信息
	 * 
	 * @return
	 */
	public CoreReturnObject queryMaterial(String materialNo,
			String processCode, String wholeBacklogDesc,String plineCode) {
		String sql = CoreXmlSqlParsersFactory
				.getSql("FrmPlanMaterialDbk.queryMaterial");
		if (processCode.equals("E")) {
			sql += "   AND (CASE  WHEN '" + wholeBacklogDesc
					+ "' LIKE '%轧制%' THEN 'D'  ELSE '' END) = T.PROCESS_CDOE";
		} else if (processCode.equals("F")) {
			sql += "   AND (CASE  WHEN '" + wholeBacklogDesc
					+ "' LIKE '%镦拔扩%' THEN 'E' " + " WHEN '" + wholeBacklogDesc
					+ "' LIKE '%轧制%' THEN 'D'  ELSE '' END) = T.PROCESS_CDOE";
		}
		/*if(!plineCode.equals("C072")&& !plineCode.equals("C091") && !plineCode.equals("C092")&& !plineCode.equals("C102"))
		{
			sql += " AND T.BELONG_CODE = '002001001'";
		}else
		{
			sql += " AND T.BELONG_CODE = '002023005'";
		}*/
		sql += " GROUP BY T.MATERIAL_NO, T.MATERIAL_NAME,T.JUDGE_STOVE_NO,T.BATCH_NO, T.BATCH_GROUD_NO,  T.STOVE_NO, T.PRO_ORDER_ID,"
				+ " T.GX_PLAN_NO, T.HEAT_PLAN_NO, T.PRO_PLAN_ID_NEXT, T.GX_PLAN_NO_NEXT,  T.PRODUCNAME,  T.GRADENAME, T.STEELNAME, T.PLINE_CODE, "
				+ " S.STORAGE_NO,T.SPEC_NAME, T.MODEL_DESC,  T.STD_NAME,T.STD_STYLE_DESC,T.NEXT_PROCESS_CDOE,  T.PLINE_NAME, T.ACT_DIMATER, "
				+ " T.ACT_HEIGHT,T.ACT_LEN_MIN,  T.ACT_LEN_MAX,T.PRODUCT_FLAG, T.MAT_STATUS,  T.BELONG_NAME,  T.ORDER_NO,  "
				+ " T.ORDER_SEQ,  T.PRO_ORDER_NO,t.cic,T.JUDGE_RESULT_CODE,T.JUDGE_RESULT,T.MEMO";
		return this.getData(sql, new Object[] { materialNo });
	}

	/**
	 * 查询库存重量
	 * 
	 * @return
	 */
	public CoreReturnObject queryMatWeigth(String judgNo, String batchNo,
			String groudNo, String inMaterialNo, String num) {
		String sql = CoreXmlSqlParsersFactory
				.getSql("FrmPlanMaterialDbk.queryMatWeigth");
		return this.getData(sql, new Object[] { judgNo, batchNo, groudNo,
				inMaterialNo, num });
	}

	/**
	 * 根据轧管投入产出信息
	 * 
	 * @return
	 */
	public CoreReturnObject queryBaseMaterialDPl(String inwlId, String outwlId,
			String plineCode) {
		String sql = CoreXmlSqlParsersFactory
				.getSql("FrmPlanMaterialDbk.queryBaseMaterialDPl");
		return this.getData(sql, new Object[] { inwlId, outwlId, plineCode });
	}

	/**
	 * 查询Bom投入物料
	 * 
	 * @return
	 */
	public CoreReturnObject queryBaseMaterial(String ordLnDlyPk,
			String indexSeq, String carftSeq, String processCode) {
		String sql = "";
		if (processCode.equals("D")) {
			sql = CoreXmlSqlParsersFactory
					.getSql("FrmPlanMaterialDbk.queryBaseMaterialDPl");
		} else if (processCode.equals("E")) {
			sql = CoreXmlSqlParsersFactory
					.getSql("FrmPlanMaterialDbk.queryBaseMaterialEPl");
		} else if (processCode.equals("F")) {
			sql = CoreXmlSqlParsersFactory
					.getSql("FrmPlanMaterialDbk.queryBaseMaterialFPl");
		} else if (processCode.equals("G")) {
			sql = CoreXmlSqlParsersFactory
					.getSql("FrmPlanMaterialDbk.queryBaseMaterialGPl");
		}
		return this.getData(sql,
				new Object[] { ordLnDlyPk, indexSeq, carftSeq });
	}

	/**
	 * 查询排产信息
	 * 
	 * @param con
	 * @param proPlanId
	 *            订单编号
	 * @param gxPlanNo
	 *            排产序号
	 * @return PlnOrderCastSEntity
	 * @throws SQLException
	 */
	public static <T> T getPlanOrderS(Connection con, String proPlanId,
			String gxPlanNo, Class<T> cls, String processCode)
			throws SQLException {
		String sql = "";
		if (processCode.equals("E")) {
			sql = CoreXmlSqlParsersFactory
					.getSql("PlanFurnProduction.queryPlnOrderDbk");
		} else if (processCode.equals("F")) {
			sql = CoreXmlSqlParsersFactory
					.getSql("PlanFurnProduction.queryPlnOrdeRcl");
		} else if (processCode.equals("G")) {
			sql = CoreXmlSqlParsersFactory
					.getSql("PlanFurnProduction.queryPlnOrderJgx");
		}
		sql += " AND T.PRO_PLAN_ID = ?  AND T.GX_PLAN_NO = ?";
		PreparedStatement ps = con.prepareStatement(sql);
		ps.setObject(1, proPlanId);
		ps.setObject(2, gxPlanNo);
		ResultSet rs = ps.executeQuery();
		T t = EntityTool.getEntityByRs(rs, cls);
		rs.close();
		ps.close();
		return t;
	}

	/**
	 * 查询坯子库存信息
	 * 
	 * @param con
	 * @param
	 *
	 * @param judgeStoveNo
	 *            判定炉号
	 * @throws SQLException
	 */
	public static List<MatBcMEntityPln> getQureyMatGpM(Connection con,
			String judgeStoveNo, String batchNo, String batchGroupBy,
			String materialNo, int takeCount, String proPlanIdNo,
			String proessCode,String actLen,String lenFalg,String storageNo,String plineCode) throws SQLException {
		String sql = CoreXmlSqlParsersFactory
				.getSql("FrmPlanMaterialDbk.QueryMatGp");
		if (!proPlanIdNo.equals("")) {
			sql += " AND T.PRO_PLAN_ID_NEXT||'/'||T.GX_PLAN_NO_NEXT ='"
					+ proPlanIdNo + "'";
		} else {
			sql += " AND T.PRO_PLAN_ID_NEXT IS NULL";
		}
		if(lenFalg.equals("1")){
			sql+=" AND NVL(T.ACT_LEN,'0')=NVL('"+actLen+"','0')";
		}
		sql += "  ORDER BY T.MAT_NO ASC) where rownum<=?";
		PreparedStatement ps = con.prepareStatement(sql);
		ps.setObject(1, judgeStoveNo);
		ps.setObject(2, batchNo);
		ps.setObject(3, batchGroupBy);
		ps.setObject(4, storageNo);
		ps.setObject(5,plineCode);
		ps.setObject(6, materialNo);
		ps.setObject(7, takeCount);
		ResultSet rs = ps.executeQuery();
		List<MatBcMEntityPln> list = EntityTool.getEntitysByRs(rs,
				MatBcMEntityPln.class);
		ps.close();
		rs.close();
		if (list == null || list.size() == 0) {
			return null;
		} else {
			for (MatBcMEntityPln listL : list) {
				QualityDesignTool.nullConverNullString(listL);
			}
			return list;
		}
	}
	
	/**
	 * 查询坯子库存信息
	 * 
	 * @param con
	 * @param
	 *
	 * @param judgeStoveNo
	 *            判定炉号
	 * @throws SQLException
	 */
	public static List<MatBcMEntityPln> getQureyMatGpMB(Connection con,
			String judgeStoveNo, String batchNo, String batchGroupBy,
			String materialNo, int takeCount, String proPlanIdNo,
			String proessCode,String actLen,String lenFalg,String storageNo) throws SQLException {
		String sql = CoreXmlSqlParsersFactory
				.getSql("FrmPlanMaterialDbk.QueryMatGpB");
		if (!proPlanIdNo.equals("")) {
			sql += " AND T.PRO_PLAN_ID_NEXT||'/'||T.GX_PLAN_NO_NEXT ='"
					+ proPlanIdNo + "'";
		} else {
			sql += " AND T.PRO_PLAN_ID_NEXT IS NULL";
		}
		if(lenFalg.equals("1")){
			sql+=" AND NVL(T.ACT_LEN,'0')=NVL('"+actLen+"','0')";
		}
		sql += "  ORDER BY T.MAT_NO ASC) where rownum<=?";
		PreparedStatement ps = con.prepareStatement(sql);
		ps.setObject(1, judgeStoveNo);
		ps.setObject(2, batchNo);
		ps.setObject(3, batchGroupBy);
		ps.setObject(4, storageNo);
		ps.setObject(5, takeCount);
		ResultSet rs = ps.executeQuery();
		List<MatBcMEntityPln> list = EntityTool.getEntitysByRs(rs,
				MatBcMEntityPln.class);
		ps.close();
		rs.close();
		if (list == null || list.size() == 0) {
			return null;
		} else {
			for (MatBcMEntityPln listL : list) {
				QualityDesignTool.nullConverNullString(listL);
			}
			return list;
		}
	}


	// 查询库存信息赋值履历表
	public static <T> T getQureyMatTrack(Connection con, String judgeStoveNo,
			String batchNo, String batchGroupBy, int takeCount,
			String hangingflag, String proPlanIdNo, Class<T> cls, String flag,String actLen,String lenFalg)
			throws SQLException {
		String sql = CoreXmlSqlParsersFactory
				.getSql("FrmPlanMaterialDbk.getQureyMatTrack");
		if (!proPlanIdNo.equals("")) {
			sql += " AND PRO_PLAN_ID_NEXT||'/'||GX_PLAN_NO_NEXT ='"
					+ proPlanIdNo + "'";
		} else {
			sql += " AND PRO_PLAN_ID_NEXT IS NULL";
		}
		if (flag.equals("add")) {
			sql += " AND (MAT_STATUS ='80150102'  AND INSTOCK_FLAG='1' AND JUDGE_RESULT_CODE IN ('40740701','40740709') OR MAT_STATUS ='80150101'AND INSTANCY_FLAG='1')";
		}
		if(lenFalg.equals("1")){
			sql+=" AND NVL(ACT_LEN,'0')=NVL('"+actLen+"','0')"; 
		}
		sql += " AND HANGING_FLAG = '" + hangingflag + "'";
		sql += " AND rownum<=?";
		sql += " GROUP BY PRODUCT_FLAG,MAT_STATUS,LOT_NO,STOVE_NO,JUDGE_STOVE_NO,BATCH_NO,BATCH_GROUD_NO,"
				+ "MATERIAL_NO, MATERIAL_NAME,PRODUCCODE,PRODUCNAME,STEELCODE,STEELNAME,STD_CODE,STD_NAME,"
				+ "STD_STYLE,STD_STYLE_DESC,SPEC_CODE,SPEC_NAME,MODEL_CODE,MODEL_DESC,ACT_LEN,ACT_LEN_MIN,"
				+ "ACT_LEN_MAX,PRO_ORDER_NO,PRO_ORDER_ID,ORD_PK,ORD_LN_PK,ORD_LN_DLY_PK,ORDER_NO,ORDER_SEQ,"
				+ "ORDER_SEQ_NO, BELONG_CODE,BELONG_NAME, PROCESS_CDOE, GRADECODE, GRADENAME";
		PreparedStatement ps = con.prepareStatement(sql);
		ps.setObject(1, judgeStoveNo);
		ps.setObject(2, batchNo);
		ps.setObject(3, batchGroupBy);
		ps.setObject(4, takeCount);
		ResultSet rs = ps.executeQuery();
		T t = EntityTool.getEntityByRs(rs, cls);
		rs.close();
		ps.close();
		return t;
	}

	/**
	 * 坯子利库
	 * 
	 * @param proPlanId
	 *            订单号
	 * @param gxPlanNo
	 *            排产序号
	 * @throws ParseException
	 */
	public CoreReturnObject doAddLibrary(ArrayList<ArrayList<String>> jslist,
			String userName, String proPlanId, String gxPlanNo)
			throws ParseException {
		CoreReturnObject cro = new CoreReturnObject();
		Connection conn = null;
		try {
			conn = this.getDao(CoreConstantData.sysbeanstr).getConnection();
			conn.setAutoCommit(false);
			PreparedStatement ps = null;
			ResultSet rs = null;
			// SimpleDateFormat dFormat = new SimpleDateFormat("yyyyMMdd");
			// SimpleDateFormat dfMonth = new SimpleDateFormat("yyyyMM");

			// 获取数据库当前时间
			String dateTime = FrmSteelMakingPlanChange.getSystemTime(conn);
			// 查询镦拔扩信息
			PlnOrderDbkSEntity plnOrderS = getPlanOrderS(conn, proPlanId,
					gxPlanNo, PlnOrderDbkSEntity.class, "E");
			if (plnOrderS == null) {
				cro.setV_errMsg("未找到镦拔扩订单(" + proPlanId + "/" + gxPlanNo
						+ ")信息!");
				return cro;
			}
			// 判断是否排产订单下发
			// if (plnOrderS.getIfStoveIssued().equals("1")) {
			// cro.setV_errMsg("轧管订单(" + proPlanId + "/" + gxPlanNo
			// + ")已下发,不能利该轧管订单,如需利该轧管订单,请拆分订单!");
			// return cro;
			// }
			// int lkNum = 0;
			// double lkWt = 0;
			int seq = 1;
			// 循环库存信息
			for (int i = 0; i < jslist.size(); i++) {
				Date now = new Date();
				SimpleDateFormat dateFormat = new SimpleDateFormat(
						"yyyyMMddHHmmss");
				DecimalFormat df = new DecimalFormat("0000000000");
				ArrayList<String> list = (ArrayList<String>) jslist.get(i);
				String judgeStoveNo = list.get(0);
				String batchNo = list.get(1);
				String batchGroupBy = list.get(2);
				String materialNo = list.get(3);
				int takeCount = Integer.parseInt(list.get(4));// 利库支
				// String proPlanIdNo = list.get(5);// 本工序订单号
				String UpproPlanIdNo = list.get(6);// 上工序订单号

				String specCic = list.get(7);
				String storageNo = list.get(8);
				String plineCode = list.get(9);
				List<MatBcMEntityPln> matGpMlist = getQureyMatGpM(conn,
						judgeStoveNo, batchNo, batchGroupBy, materialNo,
						takeCount, "", "E","","",storageNo,plineCode);
				if (matGpMlist == null) {
					cro.setV_errMsg("管坯物料已发生改变,请刷新!");
					return cro;
				}
				MatBcTrackEntity matTrack = getQureyMatTrack(conn,
						judgeStoveNo, batchNo, batchGroupBy, takeCount, "0",
						"", MatBcTrackEntity.class, "add","","");
				if (matTrack == null) {
					cro.setV_errMsg("管坯物料已发生改变,请刷新!");
					return cro;
				}
				double actWt = 0;
				String jugdeApplyCode = "";// 是否有申请判定单号
				int countAppCode = 0;
				String stoveNo = "";
				String inwlId = "";
				String inwlDesc = "";
				String lengthIn = "";
				String lengthmaxIn = "";
				String lengthminIn = "";
				String outdiameterIn = "";
				String wallthickIn = "";
				String upperHeatplanId = "";
				String flagStoveNo = "";
				String gradeName = "";
				for (MatBcMEntityPln matGpM : matGpMlist) {
					countAppCode++;
					gradeName = matGpM.getGradecode();
					jugdeApplyCode = matGpM.getJugdeApplyCode();
					stoveNo = matGpM.getStoveNo();
					inwlId = matGpM.getMaterialNo();
					inwlDesc = matGpM.getMaterialName();
					lengthIn = matGpM.getActLen();
					lengthmaxIn = matGpM.getActLenMax();
					lengthminIn = matGpM.getActLenMin();
					outdiameterIn = matGpM.getActDimater();
					wallthickIn = matGpM.getActHeight();
					upperHeatplanId = matGpM.getHeatPlanNo();
					actWt += Double.parseDouble(matGpM.getActWeight());
					flagStoveNo = matGpM.getFlagStoveNoZg();
					if (!matGpM.getProductFlag().equals("801401")) {
						cro.setV_errMsg("材料类别不是在制品,不能利库!");
						return cro;
					}
					if (!matGpM.getMatStatus().equals("80150102")
							&& !matGpM.getInstancyFlag().equals("1")) {
						cro.setV_errMsg("材料状态不是产出已判定状态并且不是紧急放行状态,不能利库");
						return cro;
					}
					if (!matGpM.getQcmStaus().equals("00")) {
						cro.setV_errMsg("交库状态不是合格状态,不能利库!");
						return cro;
					}
					// if
					// (matGpM.getMatStatus().equals("80150102")&&!matGpM.getJudgeResultCode().equals("40740701"))
					// {
					// cro.setV_errMsg("判定结果不是合格状态,不能利库!");
					// return cro;
					// }
					// if (matGpM.getHangingFlag().equals("1")) {
					// cro.setV_errMsg("你选择的管坯物料已生成实际炉计划不能利库。如需利库,请先删除炉计划!");
					// return cro;
					// // }
					// }
					// if(!matGpM.getMngLockFlag().equals("0")){
					// cro.setV_errMsg("你选择的管坯物料已管理封锁,不能利库!");
					// return cro;
					// }
					// if(!matGpM.getLockFlag().equals("0")){
					// cro.setV_errMsg("你选择的管坯物料已质量封锁,不能利库!");
					// return cro;
					// }
					// String proPlanZg = matGpM.getProPlanIdZg() + "/"
					// + matGpM.getGxPlanNoZg();
					// if (!proPlanZg.equals("/")
					// && !proPlanZg.equals(proPlanId + "/" + gxPlanNo)) {
					// cro.setV_errMsg("你选择的管坯物料已分配其他轧管订单不能利库。如需利库,请先脱单!");
					// return cro;
					// }

					// 修改坯子库存信息
					String sqlUpdateMat = CoreXmlSqlParsersFactory
							.getSql("FrmPlanMaterialDbk.UpdateMatGp");
					ps = conn.prepareStatement(sqlUpdateMat);
					ps.setObject(1, "80150103");
					ps.setObject(2, proPlanId);
					ps.setObject(3, gxPlanNo);
					ps.setObject(4, "1");
					ps.setObject(5, "1");
					ps.setObject(6, "E");
					ps.setObject(7, "镦拔扩");
					ps.setObject(8, matGpM.getMatNo());
					ps.executeUpdate();
					ps.close();
				}
				String resumeSeq = dateFormat.format(now) + df.format(seq);
				// 生成利库日志
				matTrack.setResumeSeq(resumeSeq);
				matTrack.setEventId("900102");
				matTrack.setEventDesc("利库");
				matTrack.setFormName("com.steering.pss.plnsaleord.planStove.FrmPlanMaterialDbk");
				matTrack.setCallFuncCoding("doAddLibrary");
				matTrack.setKeyvalue1("List<MatBcMEntityPln> matGpMlist");
				matTrack.setKeyvalue1Desc("物料主表关键字实体类集合");
				matTrack.setKeyvalue2("String userName");
				matTrack.setKeyvalue2Desc2("操作人");
				matTrack.setProcessCdoe("E");
				matTrack.setMemo("");
				matTrack.setCreateName(userName);
				matTrack.setCreateTime(dateTime);
				seq++;
				// 新增利库记录
				String sqlAddTrack = EntityTool.fillSqlByEntity(
						CoreXmlSqlParsersFactory
								.getSql("FrmPlanMaterialDbk.addMatBcTrack"),
						matTrack);
				ps = conn.prepareStatement(sqlAddTrack);
				ps.executeUpdate();
				ps.close();

				int countM = 0;
				String heatPlanNo = "";
				String planStatus = "00";
				// 根据判定炉号，订单号查询是否存在虚拟炉计划
				String sqlQuery = "SELECT COUNT(*) COUNT,T.HEAT_PLAN_NO,T.PLANSTATUS,T.IF_MATCH_ODD FROM PLN_ZY_DBK_M T WHERE T.FEED_HEAT_NO=? "
						+ " AND T.PRO_PLAN_ID=? AND T.GX_PLAN_NO=? GROUP BY T.HEAT_PLAN_NO,T.PLANSTATUS,T.IF_MATCH_ODD";
				ps = conn.prepareStatement(sqlQuery);
				ps.setObject(1, judgeStoveNo);
				ps.setObject(2, proPlanId);
				ps.setObject(3, gxPlanNo);
				rs = ps.executeQuery();
				while (rs.next()) {
					heatPlanNo = rs.getString("HEAT_PLAN_NO");
					planStatus = rs.getString("PLANSTATUS");
					if (rs.getString("IF_MATCH_ODD").equals("1")) {
						if (planStatus.equals("20") || planStatus.equals("30")
								|| planStatus.equals("40")) {
							cro.setV_errMsg("该镦拔扩订单(" + proPlanId + "/"
									+ gxPlanNo + "),判定炉号(" + judgeStoveNo
									+ ")已存在炉计划,并已上料,如需利库,请先撤销上料或拆分订单!");
							return cro;
						} else {
							countM = rs.getInt("COUNT");
						}
					} else {
						cro.setV_errMsg("该镦拔扩订单(" + proPlanId + "/" + gxPlanNo
								+ "),(" + judgeStoveNo
								+ ")已存在不是利库炉计划,如需利库,请先撤销炉计划!");
						return cro;
					}
				}
				rs.close();
				ps.close();

				// 如果存在同炉,同订单号只执行一次新增虚拟炉计划
				if (countM == 0) {
					PlnZyDbkMEntity plnDbkM = new PlnZyDbkMEntity();
					heatPlanNo = corePlanFurnProM.getMaxHeatPlanNo(conn,
							plnOrderS.getProPlanId(), plnOrderS.getProPlanId(),
							"E");
					// 获取炉计划顺序号
					int gxProSeq = corePlanFurnProM.getMaxGxPlnSeq(conn,
							plnDbkM.getPlineCode(), "E");
					plnDbkM.setPassCode(plnOrderS.getPassCode());
					plnDbkM.setPassName(plnOrderS.getPassName());
					plnDbkM.setDecision(plnOrderS.getDecision());
					plnDbkM.setStoveNo(stoveNo);
					plnDbkM.setFeedHeatNo(judgeStoveNo);
					plnDbkM.setJudgeStoveNo(judgeStoveNo);
					plnDbkM.setFlagStoveNo(judgeStoveNo);
					plnDbkM.setPlanstatus("00");
					plnDbkM.setUpperProcessCode("D");
					plnDbkM.setPlineCode(plnOrderS.getPlineCode());
					plnDbkM.setPlineName(plnOrderS.getPlineName());
					plnDbkM.setProcessCodeC(plnOrderS.getProcessCodeC());
					plnDbkM.setProcessDescC(plnOrderS.getProcessDescC());

					String outwlId = "";
					String outwlDesc = "";
					String materialNocp = "";
					String materialdesccp = "";
					// 根据投入物料，制程号，交货行pK,工艺序号查询本工序产出物料
					String sqlBom = CoreXmlSqlParsersFactory
							.getSql("FrmPlanMaterialDbk.queryBaseMaterialEPl");
					sqlBom += " AND T.E_IN_MATERIAL_NO=?";
					ps = conn.prepareStatement(sqlBom);
					ps.setObject(1, plnOrderS.getOrdLnDlyPk());
					ps.setObject(2, plnOrderS.getIndexSeq());
					ps.setObject(3, plnOrderS.getCraftSeq());
					ps.setObject(4, inwlId);
					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");
						// plnDbkM.setSpecCode(rs.getString("SPEC_CODE_C"));
						// plnDbkM.setSpecName(rs.getString("SPEC_NAME_C"));
						plnDbkM.setBom(rs.getString("BOM"));
						plnDbkM.setWholeBacklog(rs.getString("WHOLE_BACKLOG"));
					} else {
						outwlId = plnOrderS.getOutwlId();
						outwlDesc = plnOrderS.getOutwlDesc();

						plnDbkM.setBom(plnOrderS.getBom());
						// cro.setV_errMsg("未找到判定炉号(" + judgeStoveNo
						// + ")在镦拔扩的产出物料!");
						// return cro;
					}
					rs.close();
					ps.close();
					// 通过制程判定镦拔扩是否末工序
					if (!plnOrderS.getDecision().equals("A")) {
						if (plnOrderS.getWholeBacklogDesc().contains("热处理")) {
							plnDbkM.setNextProcessCode("F");
						} else if (plnOrderS.getWholeBacklogDesc().contains(
								"加工")) {
							plnDbkM.setNextProcessCode("G");
						} else if (plnOrderS.getWholeBacklogDesc().contains(
								"接箍")) {
							plnDbkM.setNextProcessCode("H");
						} else {
							if (plnOrderS.getOrdLnDlyPk().contains("ZZBY-J")) {
								plnDbkM.setNextProcessCode("H");
							} else if (plnOrderS.getOrdLnDlyPk().contains(
									"ZZBY-D")) {
								plnDbkM.setNextProcessCode("G");
							} else {
								plnDbkM.setNextProcessCode("");
							}
						}
						plnDbkM.setIsendgx("0");
						plnDbkM.setOutwlId(outwlId);
						plnDbkM.setOutwlDesc(outwlDesc);
					} else {
						plnDbkM.setNextProcessCode("");
						plnDbkM.setIsendgx("1");
						plnDbkM.setOutwlId(materialNocp);
						plnDbkM.setOutwlDesc(materialdesccp);
					}
					// String gowWhere =
					// corePlanFurnProM.getPlineCodeGroup(conn,
					// plnOrderS.getPlineCode(), plnOrderS.getProPlanId(),
					// plnOrderS.getGxPlanNo(), "E");
					// if (gowWhere != null) {
					// // 查询去向
					// String sqlGroup =
					// "SELECT T.STORAGE_NO,T.STORAGE_NAME FROM COM_BASE_PLINE_R_GROUP T WHERE T.PLINE_CODE_M=? AND T.PLINE_NAME_C=?";
					// ps = conn.prepareStatement(sqlGroup);
					// ps.setObject(1, plnOrderS.getPlineCode());
					// ps.setObject(2, gowWhere);
					// rs = ps.executeQuery();
					// if (rs.next()) {
					// plnDbkM
					// .setGowhereName(rs
					// .getString("STORAGE_NAME"));
					// plnDbkM.setGowhereCode(rs.getString("STORAGE_NO"));
					// }
					// rs.close();
					// ps.close();
					// }
					plnDbkM.setIfMatchOdd("1");
					plnDbkM.setIfDoHeatPlan("1");
					plnDbkM.setProPlanId(plnOrderS.getProPlanId());
					plnDbkM.setGxPlanNo(plnOrderS.getGxPlanNo());
					plnDbkM.setSpecCode(plnOrderS.getSpecCode());
					plnDbkM.setSpecName(plnOrderS.getSpecName());
					plnDbkM.setGradecode(matTrack.getGradecode());
					plnDbkM.setGradename(matTrack.getGradename());
					plnDbkM.setSteelcode(plnOrderS.getSteelcode());
					plnDbkM.setSteelname(plnOrderS.getSteelname());
					plnDbkM.setProduccode(plnOrderS.getProduccode());
					plnDbkM.setProducname(plnOrderS.getProducname());
					plnDbkM.setInwlId(inwlId);
					plnDbkM.setInwlDesc(inwlDesc);

					plnDbkM.setModelCode(plnOrderS.getModelCode());
					plnDbkM.setModelDesc(plnOrderS.getModelDesc());
					// 单倍支吨
					plnDbkM.setPlnInsingleNum(String.valueOf(takeCount));
					plnDbkM.setPlnInsingleWt(String.valueOf(actWt));
					plnDbkM.setPlnOutsingleNum(String.valueOf(takeCount));
					double burnoutRate = 0;
					// 查询产线烧损
					String sql = "SELECT NVL(T.BURNOUT_RATE,0)/100 BURNOUT_RATE FROM COM_BASE_PLINE T WHERE T.PLINE_CODE='"
							+ plnOrderS.getPlineCode() + "'";
					ps = conn.prepareStatement(sql);
					rs = ps.executeQuery();
					if (rs.next()) {
						burnoutRate = rs.getDouble("BURNOUT_RATE");
					}
					rs.close();
					ps.close();
					double cLenCut = Double.parseDouble(plnOrderS
							.getLenCuthead())
							+ Double.parseDouble(plnOrderS.getLenCutend());
					double yjWt = actWt - actWt * burnoutRate - cLenCut / 1000;
					plnDbkM.setPlnOutsingleW(String.valueOf(yjWt));
					// 倍尺支吨
					// int plnIndoubNum = 0;
					// double plnIndoubWt = 0;
					// String sqlCl =
					// "SELECT SUM(NVL(T.REAL_INDOUBLE_NUM,0)) PLAN_INDOUBLE_NUM,SUM(NVL(T.REAL_INDOUBLE_WT,0)) PLAN_INDOUBLE_WT FROM PLN_ZY_ZG_C T WHERE T.PRO_PLAN_ID||'/'||T.GX_PLAN_NO=? AND T.FEED_HEAT_NO=?";
					// ps = conn.prepareStatement(sqlCl);
					// ps.setObject(1, UpproPlanIdNo);
					// ps.setObject(2, judgeStoveNo);
					// rs = ps.executeQuery();
					// if (rs.next()) {
					// plnIndoubWt = rs.getDouble("PLAN_INDOUBLE_WT");
					// plnIndoubNum = rs.getInt("PLAN_INDOUBLE_NUM");
					// }
					// rs.close();
					// ps.close();
					// plnDbkM.setPlnIndoubleNum(String.valueOf(plnIndoubNum));
					// plnDbkM.setPlnIndoubleWt(String.valueOf(plnIndoubWt));
					// plnDbkM.setPlnOutdoubleNum(String.valueOf(plnIndoubNum));
					// plnDbkM.setPlnOutdoubleW(String.valueOf(plnIndoubWt));

					plnDbkM.setUpperHeatplanId(upperHeatplanId);
					// 查询轧管排产信息
					// String sqlZg = CoreXmlSqlParsersFactory
					// .getSql("PlanFurnProduction.QueryWgZg");
					// String sqlZg
					// ="SELECT T.PROD_STANDARD,T.OUTPUT_STANDARD,T.ZY_BATCH_ID FROM PLN_ORDER_ZG_S T WHERE T.ORD_LN_DLY_PK=?";
					String sqlZg = CoreXmlSqlParsersFactory
							.getSql("PlanFurnProduction.QueryWgZg");
					ps = conn.prepareStatement(sqlZg);
					ps.setObject(1, plnOrderS.getOrdLnDlyPk());
					rs = ps.executeQuery();
					if (rs.next()) {
						plnDbkM.setProdStandard(rs.getString("PROD_STANDARD"));
						plnDbkM.setOutputStandard(rs
								.getString("OUTPUT_STANDARD"));
						plnDbkM.setSecCraftFileNo(rs
								.getString("SEC_CRAFT_FILE_NO"));
						plnDbkM.setZyBatchIdZg(rs.getString("ZY_BATCH_ID"));
					}
					rs.close();
					ps.close();
					plnDbkM.setLengthIn(lengthIn);
					plnDbkM.setLengthmaxIn(lengthmaxIn);
					plnDbkM.setLengthminIn(lengthminIn);

					plnDbkM.setStdCode(plnOrderS.getStdCode());
					plnDbkM.setStdName(plnOrderS.getStdName());
					plnDbkM.setStdStyle(plnOrderS.getStdStyle());
					plnDbkM.setStdStyleDesc(plnOrderS.getStdStyleDesc());
					plnDbkM.setOrderSource(plnOrderS.getOrderSource());
					plnDbkM.setOrderNo(plnOrderS.getOrderNo());
					plnDbkM.setOrderSeq(plnOrderS.getOrderSeq());
					plnDbkM.setDeliveryNo(plnOrderS.getDeliveryNo());
					plnDbkM.setOrdLnDlyPk(plnOrderS.getOrdLnDlyPk());
					plnDbkM.setReqBlId(plnOrderS.getReqBlId());
					plnDbkM.setIfExport(plnOrderS.getIfExport());
					plnDbkM.setPriority(plnOrderS.getPriority());
					plnDbkM.setPriorityMemo(plnOrderS.getPriorityMemo());
					plnDbkM.setProMonth(plnOrderS.getProMonth());
					plnDbkM.setIfMonitor(plnOrderS.getIfMonitorDbk());
					plnDbkM.setPrdcrNo(plnOrderS.getPrdcrNo());
					plnDbkM.setMonitorPoint(plnOrderS.getMonitorPoint());
					plnDbkM.setWholeBacklogDesc(plnOrderS.getWholeBacklogDesc());
					plnDbkM.setStationRoad(plnOrderS.getStationRoad());
					// //获取炼钢CIC
					// String sqlCic=CoreXmlSqlParsersFactory
					// .getSql("FrmPlanMaterialDbk.queryCic");
					// ps=conn.prepareStatement(sqlCic);
					// ps.setObject(1, gradeName);
					// ps.setObject(2, plnOrderS.getProPlanId());
					// ps.setObject(3, plnOrderS.getGxPlanNo());
					// rs=ps.executeQuery();
					// if(rs.next()){
					// plnDbkM.setCic(rs.getString("CIC"));
					// }
					// else{
					// if (plnOrderS.getCic() == null ||
					// plnOrderS.getCic().equals("")) {
					// plnDbkM.setCic(plnOrderS.getCic());
					// } else {
					// plnDbkM.setCic(plnOrderS.getCic().split(",")[0]);
					// }
					// }
					// rs.close();
					// ps.close();
					plnDbkM.setCic(specCic);

					if (plnOrderS.getSic() == null
							|| plnOrderS.getSic().equals("")) {
						plnDbkM.setSic(plnOrderS.getSic());
					} else {
						plnDbkM.setSic(plnOrderS.getSic().split(",")[0]);
					}
					if (plnOrderS.getDic() == null
							|| plnOrderS.getDic().equals("")) {
						plnDbkM.setDic(plnOrderS.getDic());
					} else {
						plnDbkM.setDic(plnOrderS.getDic().split(",")[0]);
					}
					if (plnOrderS.getPic() == null
							|| plnOrderS.getPic().equals("")) {
						plnDbkM.setPic(plnOrderS.getPic());
					} else {
						plnDbkM.setPic(plnOrderS.getPic().split(",")[0]);
					}
					plnDbkM.setCraftFileMan(plnOrderS.getCraftFileMan());
					plnDbkM.setCraftFileNo(plnOrderS.getCraftFileNo());
					plnDbkM.setCraftSeq(plnOrderS.getCraftSeq());
					plnDbkM.setOutdiameterIn(outdiameterIn);
					plnDbkM.setWallthickIn(wallthickIn);
					plnDbkM.setAimlength(plnOrderS.getAimlength());
					plnDbkM.setAimoutdiameter(plnOrderS.getAimoutdiameter());
					plnDbkM.setAimwallthick(plnOrderS.getAimwallthick());
					// 查询合同最大最小长度
					double lenMax = 0;
					double lenMin = 0;
					String ordLen = "SELECT T.LENGTHMAX,T.LENGTHMIN FROM PLN_SALEORD T WHERE T.ORD_LN_DLY_PK=?";
					ps = conn.prepareStatement(ordLen);
					ps.setObject(1, plnOrderS.getOrdLnDlyPk());
					rs = ps.executeQuery();
					if (rs.next()) {
						lenMax = rs.getDouble("LENGTHMAX");
						lenMin = rs.getDouble("LENGTHMIN");
					}
					rs.close();
					ps.close();
					plnDbkM.setAimlengthMax(String.valueOf(lenMax));
					plnDbkM.setAimlengthMin(String.valueOf(lenMin));
					plnDbkM.setLenCutend(plnOrderS.getLenCutend());
					plnDbkM.setLenCuthead(plnOrderS.getLenCuthead());
					plnDbkM.setCreateName(userName);
					plnDbkM.setCreateTime(dateTime);
					plnDbkM.setProDay(dateTime.substring(0, 10)
							.replace("-", ""));
					plnDbkM.setBalYearMonth(dateTime.substring(0, 7).replace(
							"-", ""));
					plnDbkM.setIndexSeq(plnOrderS.getIndexSeq());
					plnDbkM.setHeatPlanNo(heatPlanNo);
					plnDbkM.setGxProSeq(String.valueOf(gxProSeq));

					// 新增
					String addPlnGxZg = EntityTool.fillSqlByEntity(
							CoreXmlSqlParsersFactory
									.getSql("PlanFurnProduction.addPlnZyDbk"),
							plnDbkM);
					ps = conn.prepareStatement(addPlnGxZg);
					ps.executeUpdate();
					ps.close();
				}
				int countC = 0;
				String heatPlanSqe = "";
				// 判定是否存在判定炉号，判定单号，同炉计划ID数据
				String sqlC = "SELECT COUNT(*) COUNT1,T.HEAT_PLAN_SQE FROM PLN_ZY_DBK_C T WHERE "
						+ "T.HEAT_PLAN_NO=? AND NVL(T.JUGDE_APPLY_CODE,'/')=NVL(?,'/') AND T.JUDGE_STOVE_NO=? AND T.BATCH_NO=? AND T.BATCH_GROUD_NO=?"
						+ " GROUP BY T.HEAT_PLAN_SQE";
				ps = conn.prepareStatement(sqlC);
				ps.setObject(1, heatPlanNo);
				ps.setObject(2, jugdeApplyCode);
				ps.setObject(3, judgeStoveNo);
				ps.setObject(4, batchNo);
				ps.setObject(5, batchGroupBy);
				rs = ps.executeQuery();
				if (rs.next()) {
					countC = rs.getInt("COUNT1");
					heatPlanSqe = rs.getString("HEAT_PLAN_SQE");
				}
				rs.close();
				ps.close();

				if (countC == 0) {
					PlnZyDbkCEntity plnDbkC = new PlnZyDbkCEntity();
					// 获取炉计划顺序号
					heatPlanSqe = corePlanFurnProM.getHeatPlanSeq(conn,
							heatPlanNo, "E");
					plnDbkC.setHeatPlanNo(heatPlanNo);
					plnDbkC.setJugdeApplyCode(jugdeApplyCode);
					plnDbkC.setFeedHeatNo(judgeStoveNo);
					plnDbkC.setJudgeStoveNo(judgeStoveNo);
					plnDbkC.setFlagStoveNo(judgeStoveNo);
					plnDbkC.setBatchNo(batchNo);
					plnDbkC.setBatchGroudNo(batchGroupBy);
					plnDbkC.setStoveNo(stoveNo);
					plnDbkC.setProPlanId(plnOrderS.getProPlanId());
					plnDbkC.setGxPlanNo(plnOrderS.getGxPlanNo());
					plnDbkC.setPlineCode(plnOrderS.getPlineCode());
					plnDbkC.setPlineName(plnOrderS.getPlineName());
					plnDbkC.setOutdiameterIn(plnOrderS.getOutdiameterIn());
					plnDbkC.setWallthickIn(plnOrderS.getWallthickIn());
					plnDbkC.setLengthIn(lengthIn);
					plnDbkC.setLengthmaxIn(lengthmaxIn);
					plnDbkC.setLengthminIn(lengthminIn);
					plnDbkC.setPlanIndoubleNum(String.valueOf(takeCount));
					plnDbkC.setPlanIndoubleWt(String.valueOf(actWt));
					plnDbkC.setOutnumCut("1");
					plnDbkC.setHeatPlanSqe(heatPlanSqe);
					// 新增
					String addPlnGxZg = EntityTool.fillSqlByEntity(
							CoreXmlSqlParsersFactory
									.getSql("PlanFurnProduction.addPlnZyDbkC"),
							plnDbkC);
					ps = conn.prepareStatement(addPlnGxZg);
					ps.executeUpdate();
					ps.close();
				} else {
					// 修改炉计划实表
					String updateC = "UPDATE PLN_ZY_DBK_C T SET T.PLAN_INDOUBLE_NUM=T.PLAN_INDOUBLE_NUM+TO_NUMBER(?),"
							+ "T.PLAN_INDOUBLE_WT=T.PLAN_INDOUBLE_WT+TO_NUMBER(?) ";
					updateC += " WHERE T.HEAT_PLAN_NO=? AND T.HEAT_PLAN_SQE=?";
					ps = conn.prepareStatement(updateC);
					ps.setObject(1, takeCount);
					ps.setObject(2, actWt);
					ps.setObject(3, heatPlanNo);
					ps.setObject(4, heatPlanSqe);
					ps.executeUpdate();
					ps.close();
				}

				if (countM > 0) {
					// 修改炉计划主表量
					String sqlUpdate = CoreXmlSqlParsersFactory
							.getSql("FrmPlanMaterialDbk.updatePlnZgM");
					ps = conn.prepareStatement(sqlUpdate);
					ps.setObject(1, heatPlanNo);
					ps.setObject(2, heatPlanNo);
					ps.executeUpdate();
					ps.close();
				}
				// 修改坯子库存下工序炉计划ID
				String sqlUpdateMat = "UPDATE MAT_BC_M T SET T.HEAT_PLAN_NO_NEXT=? WHERE T.PRO_PLAN_ID_NEXT=? AND T.GX_PLAN_NO_NEXT=? AND T.JUDGE_STOVE_NO=?";
				ps = conn.prepareStatement(sqlUpdateMat);
				ps.setObject(1, heatPlanNo);
				ps.setObject(2, proPlanId);
				ps.setObject(3, gxPlanNo);
				ps.setObject(4, judgeStoveNo);
				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 jslist
	 * @param userName
	 *            脱单人
	 * @return
	 * @throws ParseException
	 */
	public CoreReturnObject doDeleteMonomer(
			ArrayList<ArrayList<String>> jslist, String userName)
			throws ParseException {
		CoreReturnObject cro = new CoreReturnObject();
		Connection conn = null;
		try {
			conn = this.getDao(CoreConstantData.sysbeanstr).getConnection();
			conn.setAutoCommit(false);
			PreparedStatement ps = null;
			// ResultSet rs = null;
			SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMddHHmmss");
			DecimalFormat df = new DecimalFormat("0000000000");
			// 获取数据库当前时间
			String dateTime = FrmSteelMakingPlanChange.getSystemTime(conn);
			// 循环库存信息
			int seq = 1;
			for (int i = 0; i < jslist.size(); i++) {

				Date now = new Date();
				ArrayList<String> list = (ArrayList<String>) jslist.get(i);
				String judgeStoveNo = list.get(0);
				String batchNo = list.get(1);
				String batchGroupBy = list.get(2);
				String materialNo = list.get(3);
				int takeCount = Integer.parseInt(list.get(4));// 利库支
				String proPlanIdNo = list.get(5);

				String plineCode = list.get(6);
				List<MatBcMEntityPln> matGpMlist = getQureyMatGpM(conn,
						judgeStoveNo, batchNo, batchGroupBy, materialNo,
						takeCount, proPlanIdNo, "E","","","",plineCode);
				if (matGpMlist == null) {
					cro.setV_errMsg("管坯物料已发生改变,请刷新!");
					return cro;
				}
				MatBcTrackEntity matTrack = getQureyMatTrack(conn,
						judgeStoveNo, batchNo, batchGroupBy, takeCount, "0",
						proPlanIdNo, MatBcTrackEntity.class, "delete","","");

				for (MatBcMEntityPln matGpM : matGpMlist) {
					String proPlanZg = matGpM.getProPlanIdNext() + "/"
							+ matGpM.getGxPlanNoNext();
					if (proPlanZg.equals("/")) {
						cro.setV_errMsg("你选择的管坯物料未分配其他镦拔扩订单,不能脱单!");
						return cro;
					}
					String sqlUpdateMat = CoreXmlSqlParsersFactory
							.getSql("FrmPlanMaterialDbk.UpdateMatGp");
					ps = conn.prepareStatement(sqlUpdateMat);
					ps.setObject(1, "80150102");
					ps.setObject(2, "");
					ps.setObject(3, "");
					ps.setObject(4, "0");
					ps.setObject(5, "0");
					ps.setObject(6, "");
					ps.setObject(7, "");
					ps.setObject(8, matGpM.getMatNo());
					ps.executeUpdate();
					ps.close();
				}
				String resumeSeq = dateFormat.format(now) + df.format(seq);
				// 生成利库日志
				matTrack.setResumeSeq(resumeSeq);
				matTrack.setEventId("900101");
				matTrack.setEventDesc("镦拔扩脱单");
				matTrack.setFormName("com.steering.pss.plnsaleord.planStove.FrmPlanMaterialDbk");
				matTrack.setCallFuncCoding("doDeleteMonomer");
				matTrack.setKeyvalue1("List<MatBcMEntityPln> matGpMlist");
				matTrack.setKeyvalue1Desc("物料主表关键字实体类集合");
				matTrack.setKeyvalue2("String userName");
				matTrack.setKeyvalue2Desc2("操作人");
				matTrack.setKeyvalue3("doDeleteMonomer");
				matTrack.setKeyvalue3Desc3("删除订单号");
				matTrack.setProcessCdoe("E");
				matTrack.setMemo("");
				matTrack.setCreateName(userName);
				matTrack.setCreateTime(dateTime);
				seq++;
				String sqlAddTrack = EntityTool.fillSqlByEntity(
						CoreXmlSqlParsersFactory
								.getSql("FrmPlanMaterialDbk.addMatBcTrack"),
						matTrack);
				ps = conn.prepareStatement(sqlAddTrack);
				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;
	}

	/**
	 * 手动关闭炉计划
	 */
	public CoreReturnObject doLuClose(ArrayList<ArrayList<String>> jslist,
			String userName) throws ParseException {
		CoreReturnObject cro = new CoreReturnObject();
		Connection conn = null;
		try {
			conn = this.getDao(CoreConstantData.sysbeanstr).getConnection();
			conn.setAutoCommit(false);
			PreparedStatement ps = null;
			// 循环炉计划信息
			for (int i = 0; i < jslist.size(); i++) {
				ArrayList<String> list = (ArrayList<String>) jslist.get(i);
				String heatPlanNo = list.get(0);
				// 查询炉计信息
				PlnZyDbkMEntity listM = FrmPlanStoveE.getQureyZyM(conn,
						heatPlanNo, "E", PlnZyDbkMEntity.class);
				if (listM == null) {
					cro.setV_errMsg("炉计划已发生变化,请重新查询!");
					return cro;
				}
				if (listM.getPlanstatus().equals("关闭")) {
					cro.setV_errMsg("选择的镦拔扩炉计划状态是关闭状态,不能重复关闭!");
					return cro;
				}

				// 关闭炉计划
				String deleteZgC = "UPDATE PLN_ZY_DBK_M T SET T.IS_CLOSE='1',T.PLANSTATUS='40' WHERE HEAT_PLAN_NO = ?";
				ps = conn.prepareStatement(deleteZgC);
				ps.setObject(1, heatPlanNo);
				ps.executeUpdate();
				ps.close();
			}
			cro.setV_errMsg("关闭成功!");
			conn.commit();
		} catch (SQLException sqle) {
			try {
				if (conn != null) {
					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;
	}
}
