package com.steering.mes.mcp.heatTreatment;

import CoreFS.SA06.CoreReturnObject;
import CoreFS.SA08.CoreXmlSqlParsersFactory;
import CoreFS.SC01.CoreConstantData;
import com.steering.comm.converter.EntityTool;
import com.steering.comm.db.DBCommon;
import com.steering.comm.tools.StringTool;
import com.steering.mes.mcp.Report.FrmHttControlLog;
import com.steering.mes.mcp.common.PlanService;
import com.steering.mes.mcp.entity.*;

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

/**
 * 热处理实绩服务类
 * 
 * @author lzh 2015-7-27
 */
public class HeatTreatmentService extends DBCommon {

	/**
	 * 根据计划号查询热处理高温炉实绩
	 * 
	 * @param
	 * @return
	 */
	public CoreReturnObject getHeatTreatmentResult(String heratNo) {
		Object[] params = new Object[] { heratNo };
		return this.getDataBySqlID(
				"HeatTreatmentService.GetHeatTreatmentResultByID", params);
	}

	/**
	 * 热处理低温炉实绩查询
	 * 
	 * @return
	 */
	public CoreReturnObject getLowHeatTreatmentResult(String heratNo) {
		Object[] params = new Object[] { heratNo };
		return this.getDataBySqlID(
				"HeatTreatmentService.GetLowHeatTreatmentResultByID", params);
	}

	/**
	 * 热处理淬火实绩查询
	 * 
	 * @return
	 */
	public CoreReturnObject getQuechtHeatTreatmentResult(String heratNo) {
		Object[] params = new Object[] { heratNo };
			return this
				.getDataBySqlID(
						"HeatTreatmentService.GetQuechtHeatTreatmentResultByID",
						params);
	}


	/**
	 * 淬火实绩修改录入
	 */
	public CoreReturnObject updateQuechResultByID(String json){
		HttQuenchingResultEntity httQuenchingResultEntity = EntityTool.getEntityByJSONStr(json, HttQuenchingResultEntity.class);
		String sql1=CoreXmlSqlParsersFactory
				.getSql("HeatTreatmentService.updateQuechResultByID");
		sql1=  EntityTool.fillSqlByEntity(sql1,httQuenchingResultEntity);
		return this.setData(sql1);

	}

	public CoreReturnObject getQuechResultID(String ResultNo){
		Object[] params = new Object[] { ResultNo };
		return this.getDataBySqlID(
						"HeatTreatmentService.getQuechResultID",
						params);

	}


	/**
	 * 查询高温炉合格支数的和
	 */
	public CoreReturnObject getQueryExpandResult1(String heatNo) {
		return this.getDataBySqlID(
				"HeatTreatmentService.getQueryExpandResult1",
				new Object[] { heatNo });
	}

	/**
	 * 查询低温炉合格支数的和
	 */
	public CoreReturnObject getQueryExpandResult3(String heatNo) {
		return this.getDataBySqlID(
				"HeatTreatmentService.getQueryExpandResult3",
				new Object[] { heatNo });
	}

	/**
	 * 查询淬火合格支数的和
	 */
	public CoreReturnObject getQueryExpandResult2(String heatNo) {
		return this.getDataBySqlID(
				"HeatTreatmentService.getQueryExpandResult2",
				new Object[] { heatNo });
	}

	/**
	 * 查询相同炉计划ID下高温炉
	 */
	public CoreReturnObject getQueryExpandResultStuts(String heatNo,
			String plinCode) {
		return this.getDataBySqlID(
				"HeatTreatmentService.getQueryExpandResultStuts", new Object[] {
						heatNo, plinCode });
	}

	/**
	 * 查询相同炉计划ID下淬火
	 */
	public CoreReturnObject getQueryExpandResultStuts1(String heatNo,
			String plinCode) {
		return this.getDataBySqlID(
				"HeatTreatmentService.getQueryExpandResultStuts1",
				new Object[] { heatNo, plinCode });
	}

	/**
	 * 查询相同炉计划ID下低温炉
	 */
	public CoreReturnObject getQueryExpandResultStuts2(String heatNo,
			String plinCode) {
		return this.getDataBySqlID(
				"HeatTreatmentService.getQueryExpandResultStuts2",
				new Object[] { heatNo, plinCode });
	}

	/**
	 * 查询工序点
	 * 
	 * @return
	 */
	public CoreReturnObject doQuery(String sortCode) {

		String sql = "";
		sql = CoreXmlSqlParsersFactory.getSql("HeatTreatmentService.doQuery");
		return this.getData(sql, new Object[] { sortCode });
	}

	/**
	 * 保存热处理实绩
	 * 
	 * @return
	 */
	public CoreReturnObject saveHeatTreatmentResult(String resultStr,
			String resultStr1, String resultStr2, String PlanNo, String Highgx,
			String QuenchtGx, String Lowgx, ArrayList<String> list1Str,
			ArrayList<String> list2Str, ArrayList<String> list3Str,
			ArrayList<String> list4Str, ArrayList<String> list5Str,
			ArrayList<String> list6Str) {

		CoreReturnObject core = new CoreReturnObject();
		Connection connection = this.getDao(CoreConstantData.sysbeanstr)
				.getConnection();
		PreparedStatement psta = null;
		ResultSet rs1 = null;
		Date dt = new Date();
		SimpleDateFormat matter1 = new SimpleDateFormat("yyMMdd");
		SimpleDateFormat matter = new SimpleDateFormat("yyyy-MM-dd");

		Calendar ca = Calendar.getInstance();
		ca.set(Calendar.DATE, ca.getActualMaximum(Calendar.DATE));
		Date now = new Date();
		SimpleDateFormat dateFormat = new SimpleDateFormat(
				"yyyy-MM-dd HH:mm:ss", Locale.CHINA);
		SimpleDateFormat dateFormat1 = new SimpleDateFormat("yyyy-MM-dd HH:mm",
				Locale.CHINA);
		String systime = dateFormat.format(now);
		try {
			connection.setAutoCommit(false); // 取消自动提交事务
			String sqlAdd = CoreXmlSqlParsersFactory
					.getSql("HeatTreatmentService.AddHHeatResult");// 新增高温炉实绩
			PreparedStatement patAdd = connection.prepareStatement(sqlAdd);
			String sqlAddD = CoreXmlSqlParsersFactory
					.getSql("HeatTreatmentService.AddQuechtResult");// 新增淬火炉记录
			PreparedStatement patAddD = connection.prepareStatement(sqlAddD);
			String sqlAddS = CoreXmlSqlParsersFactory
					.getSql("HeatTreatmentService.AddLHeatResult");// 新增低温炉记录
			PreparedStatement patAddS = connection.prepareStatement(sqlAddS);
			String addPlnInfo = CoreXmlSqlParsersFactory
					.getSql("HttLoadingService.AddComInfoResult");// 新增公共信息
			PreparedStatement patsPlan = connection
					.prepareStatement(addPlnInfo);
			String updatepln = CoreXmlSqlParsersFactory
					.getSql("AppearanceService.updatePlnZyRclM");// 新增时修改计划表
			PreparedStatement patsupdatepln = connection
					.prepareStatement(updatepln);
			String addPlnInfo1 = CoreXmlSqlParsersFactory
					.getSql("HeatTreatmentService.AddComInfoResult1");// 修改队列表材料，工序状态
			PreparedStatement patsPlan1 = connection
					.prepareStatement(addPlnInfo1);
			String updatePath = CoreXmlSqlParsersFactory
					.getSql("HeatTreatmentService.UpdatePath");// 修改队列表工艺路径
			PreparedStatement pastupdatePath = connection
					.prepareStatement(updatePath);
			String updatePath1 = CoreXmlSqlParsersFactory
					.getSql("HeatTreatmentService.UpdatePath1");// 修改队列表工艺路径
			PreparedStatement pastupdatePath1 = connection
					.prepareStatement(updatePath1);
			String updatePath2 = CoreXmlSqlParsersFactory
					.getSql("HeatTreatmentService.UpdatePath2");// 修改队列表工艺路径
			PreparedStatement pastupdatePath2 = connection
					.prepareStatement(updatePath2);

			String addHttControlLog = CoreXmlSqlParsersFactory
					.getSql("HeatTreatmentService.addHttControlLog"); // 增加调度日志
			PreparedStatement pastaddHttControlLog = connection
					.prepareStatement(addHttControlLog);

			// 获取热处理计划实体了
			PlnZyRclMEntity pln = PlanService.getSendHttPlanCInfo(connection,
					PlanNo);

			if (pln == null)
				return core;
			if (pln.getPlanstatus().equals("3")) {
				core.setV_errMsg("该计划已关闭！");
				return core;
			}
			String ifMonitNo = "";
			if (pln.getIfMonitor().equals("是")) {
				ifMonitNo = "1";
			} else {
				ifMonitNo = "0";
			}

			HttHheatResultEntity result = EntityTool.getEntityByJSONStr(
					resultStr, HttHheatResultEntity.class);

			int ProNum = 0;
			int FailNum = 0;

			if (StringTool.isInteger(result.getProNum())) {
				ProNum = Integer.parseInt(result.getProNum());

			}

			if (StringTool.isInteger(result.getFailNum())) {
				FailNum = Integer.parseInt(result.getFailNum());
			}

			HttQuenchingResultEntity result1 = EntityTool.getEntityByJSONStr(
					resultStr1, HttQuenchingResultEntity.class);

			int ProNum1 = 0;
			int FailNum1 = 0;

			if (StringTool.isInteger(result1.getProNum())) {
				ProNum1 = Integer.parseInt(result1.getProNum());

			}

			if (StringTool.isInteger(result1.getFailNum())) {
				FailNum1 = Integer.parseInt(result1.getFailNum());
			}

			HttLheatResultEntity result2 = EntityTool.getEntityByJSONStr(
					resultStr2, HttLheatResultEntity.class);

			int ProNum2 = 0;
			int FailNum2 = 0;

			if (StringTool.isInteger(result2.getProNum())) {
				ProNum2 = Integer.parseInt(result2.getProNum());

			}

			if (StringTool.isInteger(result2.getFailNum())) {
				FailNum2 = Integer.parseInt(result2.getFailNum());
			}

			if (ProNum == 0 && ProNum1 == 0 && ProNum2 == 0) {
				core.setV_errMsg("请输入正确的作业支数");
				return core;
			}

			String cutFalg1 = "";
			String sql = CoreXmlSqlParsersFactory
					.getSql("HeatTreatmentService.qureyGxComInfoNew");// 查询工序是否是结炉状态
			psta = connection.prepareStatement(sql);
			psta.setString(1, PlanNo);
			psta.setObject(2, Highgx);
			psta.setObject(3, Lowgx);
			psta.setObject(4, QuenchtGx);
			psta.setObject(5, pln.getRealProcessSeq());
			rs1 = psta.executeQuery();
			if (rs1.next()) {
				cutFalg1 = rs1.getString("STATION_STATUS");
			}

			if (cutFalg1 != null && cutFalg1.equals("2")) {
				core.setV_errMsg("该工序已经结炉,无法新增");
				return core;
			}
			rs1.close();
			psta.close();

			// region 高温炉

			String resultNo = "";
			if (ProNum > 0
					&& result.getProcessSeq().equals(pln.getRealProcessSeq())) {

				if (ProNum < FailNum) {
					core.setV_errMsg("作业支数不能小于废品支数！");
					return core;
				}

				if (!result.getHheatExitTemp().equals("")
						&& result.getTotalTime().equals("")) {
					core.setV_errMsg("请录入高温炉时间！");
					return core;
				}

				if (pln.getProducname().contains("套管线")
						|| pln.getProducname().contains("低温管道线")
						|| pln.getProducname().contains("锅炉")
						|| pln.getProducname().contains("机械")
						|| pln.getProducname().contains("化肥")
						|| pln.getProducname().contains("核电")
						|| pln.getProducname().contains("裂化")
						|| (pln.getStationRoad().contains("高温炉（淬火）") && pln
								.getStationRoad().contains("低温炉（回火）"))) {

					if (result.getHttTechnology().equals("")) {
						core.setV_errMsg("热处理制度不能为空！");
						return core;
					}
				}
				// 高温炉时间不重叠
				/*String HEAT_PLAN_NO = "";
				String sqlCount = CoreXmlSqlParsersFactory
						.getSql("HeatTreatmentService.getHHeatEnterTimeOK");
				psta = connection.prepareStatement(sqlCount);
				psta.setObject(1, result.getHheatEnterTime());
				psta.setObject(2, result.getHheatEnterTime());
				psta.setObject(3, result.getHheatOutTime());
				psta.setObject(4, result.getHheatOutTime());
				rs1 = psta.executeQuery();
				if (rs1.next()) {
					HEAT_PLAN_NO = rs1.getString("HEAT_PLAN_NO");
				}
				rs1.close();
				psta.close();

				if (!HEAT_PLAN_NO.equals("")) {
					core.setV_errMsg("与炉批计划号：" + HEAT_PLAN_NO + " 的时间重叠,无法新增！");
					return core;
				}*/

				/*
				 * Integer OkCount = 0;
				 * 
				 * String sqlCount =CoreXmlSqlParsersFactory.getSql(
				 * "HeatTreatmentService.getHHeatOKCountByProcessSeq"); psta =
				 * connection.prepareStatement(sqlCount); psta.setObject(1,
				 * result.getHeatPlanNo()); psta.setObject(2,
				 * result.getProcessSeq()); psta.setObject(3, Highgx);
				 * psta.setObject(4, result.getProcessSeq()); psta.setObject(5,
				 * result.getHeatPlanNo()); psta.setObject(6,
				 * result.getProcessSeq()); rs1 = psta.executeQuery(); if
				 * (rs1.next()) { OkCount = rs1.getInt("COUNT"); } rs1.close();
				 * psta.close();
				 * 
				 * if (OkCount < ProNum) {
				 * core.setV_errMsg("作业支数大于剩余合格支数,无法新增！"); return core; }
				 */

				String sqlloading = CoreXmlSqlParsersFactory
						.getSql("HeatTreatmentService.queryHightMaxResultNo");// 查询最大高温炉实绩编号
				psta = connection.prepareStatement(sqlloading);
				psta.setObject(1, pln.getPlineCode() + Highgx
						+ matter1.format(dt));
				psta.setObject(2, pln.getPlineCode() + Highgx
						+ matter1.format(dt));
				rs1 = psta.executeQuery();
				if (rs1.next()) {
					resultNo = rs1.getString("RESULT_NO");
				}
				rs1.close();
				psta.close();

				// 新增高温炉实绩
				patAdd.setObject(1, resultNo);
				patAdd.setObject(2, result.getZyBatchId());
				// patAdd.setObject(3, pln.getProdIndex());
				patAdd.setObject(3, pln.getProPlanId());
				patAdd.setObject(4, pln.getGxPlanNo());
				patAdd.setObject(5, result.getHheatEnterTime());
				patAdd.setObject(6, result.getHheatOutTime());
				patAdd.setObject(7, result.getHheatExitTemp());
				patAdd.setObject(8, result.getHheatTaktTime());
				patAdd.setObject(9, result.getHheatAvgTemp1());
				patAdd.setObject(10, result.getHheatAvgTemp2());
				patAdd.setObject(11, result.getHheatAvgTemp3());
				patAdd.setObject(12, result.getHheatAvgTemp4());
				patAdd.setObject(13, result.getHheatAvgTemp5());
				patAdd.setObject(14, result.getHheatAvgTemp6());
				patAdd.setObject(15, result.getProNum());
				patAdd.setObject(16, result.getProWt());
				patAdd.setObject(17, result.getFailNum());
				patAdd.setObject(18, resultNo);
				patAdd.setObject(19, result.getOfflineNum());
				patAdd.setObject(20, result.getOfflineWt());
				patAdd.setObject(21, result.getReNum());
				patAdd.setObject(22, result.getReWt());
				patAdd.setObject(23, "1");
				patAdd.setObject(24, result.getColTime());
				patAdd.setObject(25, result.getColUser());
				patAdd.setObject(26, result.getColShift());
				patAdd.setObject(27, result.getColGroup());
				patAdd.setObject(28, result.getProducer());
				if (result.getProducer().equals("")) {
					patAdd.setObject(29, "");
				} else {
					patAdd.setObject(29, result.getProducerTime());
				}
				patAdd.setObject(30, pln.getPlineCode());
				patAdd.setObject(31, result.getHeatPlanNo());
				patAdd.setObject(32, pln.getPlineName());
				patAdd.setObject(33, systime);
				patAdd.setObject(34, result.getProcessSeq());
				patAdd.setObject(35, result.getTotalTime());
				patAdd.setObject(36, result.getCoolingType());
				patAdd.setObject(37, result.getHttTechnology());
				patAdd.setObject(38, result.getHttType());
				patAdd.addBatch();

				// 新增高温炉公共信息
				patsPlan.setObject(1, resultNo);
				patsPlan.setObject(2, pln.getZyBatchId());
				// patsPlan.setObject(3, pln.getProdIndex());
				patsPlan.setObject(3, pln.getProPlanId());
				patsPlan.setObject(4, pln.getGxPlanNo());
				patsPlan.setObject(5, pln.getOrderSource());
				patsPlan.setObject(6, pln.getOrderNo());
				patsPlan.setObject(7, pln.getOrderSeq());
				patsPlan.setObject(8, pln.getReqBlId());
				patsPlan.setObject(9, pln.getPlineCode());
				patsPlan.setObject(10, pln.getPlineName());
				patsPlan.setObject(11, Highgx);
				patsPlan.setObject(12, "高温炉");
				patsPlan.setObject(13, pln.getGradecode());
				patsPlan.setObject(14, pln.getGradename());
				patsPlan.setObject(15, pln.getSteelcode());
				patsPlan.setObject(16, pln.getSteelname());
				patsPlan.setObject(17, pln.getOutdiameterIn());
				patsPlan.setObject(18, pln.getWallthickIn());
				patsPlan.setObject(19, "");
				patsPlan.setObject(20, "");
				patsPlan.setObject(21, "");
				patsPlan.setObject(22, "");
				patsPlan.setObject(23, "");
				patsPlan.setObject(24, "");
				patsPlan.setObject(25, "");
				patsPlan.setObject(26, "");
				patsPlan.setObject(27, pln.getOutwlId());
				patsPlan.setObject(28, pln.getOutwlDesc());
				patsPlan.setObject(29, pln.getInwlId());
				patsPlan.setObject(30, pln.getInwlDesc());
				patsPlan.setObject(31, pln.getMonitorPoint());
				patsPlan.setObject(32, ifMonitNo);
				patsPlan.setObject(33, pln.getPrdcrNo());
				patsPlan.setObject(34, result.getProducer());
				if (result.getProducer().equals("")) {
					patsPlan.setObject(35, "");
				} else {
					patsPlan.setObject(35, result.getProducerTime());
				}
				patsPlan.setObject(36, pln.getStationRoad());
				patsPlan.setObject(37, pln.getCraftFileNo());
				patsPlan.setObject(38, pln.getCraftFileMan());
				patsPlan.setObject(39, pln.getCraftSeq());
				patsPlan.setObject(40, result.getProNum());
				patsPlan.setObject(41, result.getProWt());
				patsPlan.setObject(42, result.getFailNum());
				patsPlan.setObject(43, resultNo);
				patsPlan.setObject(44, result.getOfflineNum());
				patsPlan.setObject(45, result.getOfflineWt());
				patsPlan.setObject(46, result.getReNum());
				patsPlan.setObject(47, result.getReWt());
				patsPlan.setObject(48, "1");
				patsPlan.setObject(49, result.getColTime());
				patsPlan.setObject(50, "");
				patsPlan.setObject(51, result.getColUser());
				patsPlan.setObject(52, result.getColShift());
				patsPlan.setObject(53, result.getColGroup());
				patsPlan.setObject(54, "1");
				patsPlan.setObject(55, systime);
				patsPlan.setObject(56, "");
				patsPlan.setObject(57, result.getHeatPlanNo());
				patsPlan.setObject(58, pln.getJudgeStoveNo());
				patsPlan.setObject(59, "");
				patsPlan.setObject(60, "");
				patsPlan.setObject(61, pln.getProduccode());
				patsPlan.setObject(62, pln.getProducname());
				patsPlan.setObject(63, pln.getSpecCode());
				patsPlan.setObject(64, pln.getSpecName());
				patsPlan.setObject(65, result.getProcessSeq());
				patsPlan.addBatch();

				// 修改工艺路径
				pastupdatePath.setObject(1, "1");
				pastupdatePath.setObject(2, result.getHeatPlanNo());
				pastupdatePath.addBatch();
				pastupdatePath.executeBatch();
				// 修改计划表
				patsupdatepln.setObject(1, "10");
				patsupdatepln.setObject(2, result.getHeatPlanNo());
				patsupdatepln.addBatch();
				patsupdatepln.executeBatch();

				FrmHttBugD.AddHttWaste(connection, result.getHeatPlanNo(),
						resultNo, pln.getPlineCode(), result.getColUser(),
						result.getProcessSeq(), Highgx, list1Str, list2Str);

			}

			// endregion

			// region 淬火

			String resultNo1 = "";
			if (ProNum1 > 0
					&& result1.getProcessSeq().equals(pln.getRealProcessSeq())) {

				if (ProNum1 < FailNum1) {
					core.setV_errMsg("作业支数不能小于废品支数！");
					return core;
				}

				/*
				 * Integer OkCount = 0;
				 * 
				 * String sqlCount =CoreXmlSqlParsersFactory.getSql(
				 * "HeatTreatmentService.getQuenchingOKCountByProcessSeq"); psta
				 * = connection.prepareStatement(sqlCount); psta.setObject(1,
				 * result1.getHeatPlanNo()); psta.setObject(2,
				 * result1.getProcessSeq()); psta.setObject(3, QuenchtGx);
				 * psta.setObject(4, result1.getProcessSeq()); psta.setObject(5,
				 * result1.getHeatPlanNo()); psta.setObject(6,
				 * result1.getProcessSeq()); rs1 = psta.executeQuery(); if
				 * (rs1.next()) { OkCount = rs1.getInt("COUNT"); } rs1.close();
				 * psta.close();
				 * 
				 * if (OkCount < ProNum1) {
				 * core.setV_errMsg("作业支数大于剩余合格支数,无法新增！"); return core; }
				 */

				String sqlloading = CoreXmlSqlParsersFactory
						.getSql("HeatTreatmentService.queryQuechtsMaxResultNo");// 查询最大淬火炉实绩编号
				psta = connection.prepareStatement(sqlloading);
				psta.setObject(1, pln.getPlineCode() + QuenchtGx
						+ matter1.format(dt));
				psta.setObject(2, pln.getPlineCode() + QuenchtGx
						+ matter1.format(dt));
				rs1 = psta.executeQuery();
				if (rs1.next()) {
					resultNo1 = rs1.getString("RESULT_NO");
				}
				rs1.close();
				psta.close();

				// 新增淬火实绩
				patAddD.setObject(1, resultNo1);
				patAddD.setObject(2, result1.getHeatPlanNo());
				patAddD.setObject(3, result1.getZyBatchId());
				// patAddD.setObject(4, pln.getProdIndex());
				patAddD.setObject(4, pln.getProPlanId());
				patAddD.setObject(5, pln.getGxPlanNo());
				patAddD.setObject(6, result1.getQuenchWay());
				patAddD.setObject(7, result1.getTraffic());
				patAddD.setObject(8, result1.getLengthTime());
				patAddD.setObject(9, result1.getPassNum());
				patAddD.setObject(10, result1.getColTime());
				patAddD.setObject(11, result1.getColUser());
				patAddD.setObject(12, result1.getColShift());
				patAddD.setObject(13, result1.getColGroup());
				patAddD.setObject(14, systime);
				patAddD.setObject(15, pln.getPlineCode());
				patAddD.setObject(16, pln.getPlineName());
				patAddD.setObject(17, result1.getProcessSeq());
				patAddD.setObject(18, result1.getProNum());
				patAddD.setObject(19, result1.getProWt());
				patAddD.setObject(20, result1.getFailNum());
				patAddD.setObject(21, resultNo1);
				patAddD.addBatch();

				// 新增淬火公共信息
				patsPlan.setObject(1, resultNo1);
				patsPlan.setObject(2, pln.getZyBatchId());
				// patsPlan.setObject(3, pln.getProdIndex());
				patsPlan.setObject(3, pln.getProPlanId());
				patsPlan.setObject(4, pln.getGxPlanNo());
				patsPlan.setObject(5, pln.getOrderSource());
				patsPlan.setObject(6, pln.getOrderNo());
				patsPlan.setObject(7, pln.getOrderSeq());
				patsPlan.setObject(8, pln.getReqBlId());
				patsPlan.setObject(9, pln.getPlineCode());
				patsPlan.setObject(10, pln.getPlineName());
				patsPlan.setObject(11, QuenchtGx);
				patsPlan.setObject(12, "淬火");
				patsPlan.setObject(13, pln.getGradecode());
				patsPlan.setObject(14, pln.getGradename());
				patsPlan.setObject(15, pln.getSteelcode());
				patsPlan.setObject(16, pln.getSteelname());
				patsPlan.setObject(17, pln.getOutdiameterIn());
				patsPlan.setObject(18, pln.getWallthickIn());
				patsPlan.setObject(19, "");
				patsPlan.setObject(20, "");
				patsPlan.setObject(21, "");
				patsPlan.setObject(22, "");
				patsPlan.setObject(23, "");
				patsPlan.setObject(24, "");
				patsPlan.setObject(25, "");
				patsPlan.setObject(26, "");
				patsPlan.setObject(27, pln.getOutwlId());
				patsPlan.setObject(28, pln.getOutwlDesc());
				patsPlan.setObject(29, pln.getInwlId());
				patsPlan.setObject(30, pln.getInwlDesc());
				patsPlan.setObject(31, pln.getMonitorPoint());
				patsPlan.setObject(32, ifMonitNo);
				patsPlan.setObject(33, pln.getPrdcrNo());
				patsPlan.setObject(34, "");
				patsPlan.setObject(35, "");
				patsPlan.setObject(36, pln.getStationRoad());
				patsPlan.setObject(37, pln.getCraftFileNo());
				patsPlan.setObject(38, pln.getCraftFileMan());
				patsPlan.setObject(39, pln.getCraftSeq());
				patsPlan.setObject(40, result1.getProNum());
				patsPlan.setObject(41, result1.getProWt());
				patsPlan.setObject(42, result1.getFailNum());
				patsPlan.setObject(43, resultNo1);
				patsPlan.setObject(44, "");
				patsPlan.setObject(45, "");
				patsPlan.setObject(46, "");
				patsPlan.setObject(47, "");
				patsPlan.setObject(48, "1");
				patsPlan.setObject(49, result1.getColTime());
				patsPlan.setObject(50, "");
				patsPlan.setObject(51, result1.getColUser());
				patsPlan.setObject(52, result1.getColShift());
				patsPlan.setObject(53, result1.getColGroup());
				patsPlan.setObject(54, "1");
				patsPlan.setObject(55, systime);
				patsPlan.setObject(56, "");
				patsPlan.setObject(57, result1.getHeatPlanNo());
				patsPlan.setObject(58, pln.getJudgeStoveNo());
				patsPlan.setObject(59, "");
				patsPlan.setObject(60, "");
				patsPlan.setObject(61, pln.getProduccode());
				patsPlan.setObject(62, pln.getProducname());
				patsPlan.setObject(63, pln.getSpecCode());
				patsPlan.setObject(64, pln.getSpecName());
				patsPlan.setObject(65, result1.getProcessSeq());
				patsPlan.addBatch();

				// 修改工艺路径
				pastupdatePath1.setObject(1, "1");
				pastupdatePath1.setObject(2, result1.getHeatPlanNo());
				pastupdatePath1.addBatch();
				pastupdatePath1.executeBatch();
				// 修改计划表
				patsupdatepln.setObject(1, "20");
				patsupdatepln.setObject(2, result1.getHeatPlanNo());
				patsupdatepln.addBatch();
				patsupdatepln.executeBatch();

				FrmHttBugD.AddHttWaste(connection, result1.getHeatPlanNo(),
						resultNo1, pln.getPlineCode(), result1.getColUser(),
						result1.getProcessSeq(), QuenchtGx, list3Str, list4Str);

			}
			// endregion

			// region 低温炉

			String resultNo2 = "";
			if (ProNum2 > 0
					&& result2.getProcessSeq().equals(pln.getRealProcessSeq())) {

				if (ProNum2 < FailNum2) {
					core.setV_errMsg("作业支数不能小于废品支数！");
					return core;
				}

				if (!result2.getLheatExitTemp().equals("")
						&& result2.getTotalTime().equals("")) {
					core.setV_errMsg("请录入低温炉时间！");
					return core;
				}

				String Status = "";
				sql = CoreXmlSqlParsersFactory
						.getSql("HeatTreatmentService.GetStatus");//
				psta = connection.prepareStatement(sql);
				psta.setString(1, pln.getIndexSeq());
				psta.setObject(2, pln.getOrdLnDlyPk());
				psta.setObject(3, pln.getCraftSeq());
				rs1 = psta.executeQuery();
				if (rs1.next()) {
					Status = rs1.getString("STATUS");
				}

				rs1.close();
				psta.close();

				if (pln.getProducname().contains("接箍")
						|| pln.getProducname().contains("油管")
						|| pln.getProducname().contains("套管")
						|| pln.getProducname().contains("短节")
						|| pln.getProducname().contains("附件")) {

					if (result2.getLowTemp().equals("")
							&& !result2.getHttType().equals("")) {
						core.setV_errMsg("接箍/油管/套管/短节/附件 ,必须录入最低回火温度！");
						return core;
					}
				}

				if (pln.getProducname().contains("套管线")
						|| pln.getProducname().contains("低温管道线")
						|| pln.getProducname().contains("锅炉")
						|| pln.getProducname().contains("机械")
						|| pln.getProducname().contains("化肥")
						|| pln.getProducname().contains("核电")
						|| pln.getProducname().contains("裂化")) {

					if (result2.getHttTechnology().equals("")) {
						core.setV_errMsg("热处理制度不能为空！");
						return core;
					}
				}


				if(!pln.getPlineCode().equals("C091")) {
					if (!result2.getLowTemp().equals("")
							&& !result2.getLheatExitTemp().equals("")
							&& !result2.getLowTemp().equals(
							result2.getLheatExitTemp())) {
						core.setV_errMsg("最低回火温度必须与低温炉温度一致！");
						return core;
					}
				}

				/*
				 * Integer OkCount = 0;
				 * 
				 * String sqlCount =CoreXmlSqlParsersFactory.getSql(
				 * "HeatTreatmentService.getLHeatOKCountByProcessSeq");//
				 * 查询最大高温炉实绩编号 psta = connection.prepareStatement(sqlCount);
				 * psta.setObject(1, result2.getHeatPlanNo()); psta.setObject(2,
				 * result2.getProcessSeq()); psta.setObject(3, Lowgx);
				 * psta.setObject(4, result2.getProcessSeq()); psta.setObject(5,
				 * result2.getHeatPlanNo()); psta.setObject(6,
				 * result2.getProcessSeq()); rs1 = psta.executeQuery(); if
				 * (rs1.next()) { OkCount = rs1.getInt("COUNT"); } rs1.close();
				 * psta.close();
				 * 
				 * if (OkCount < ProNum2) {
				 * core.setV_errMsg("作业支数大于剩余合格支数,无法新增！"); return core; }
				 */

				String sqlloading = CoreXmlSqlParsersFactory
						.getSql("HeatTreatmentService.queryLowMaxResultNo");// 查询最大低温炉实绩编号
				psta = connection.prepareStatement(sqlloading);
				psta.setObject(1, pln.getPlineCode() + Lowgx
						+ matter1.format(dt));
				psta.setObject(2, pln.getPlineCode() + Lowgx
						+ matter1.format(dt));
				rs1 = psta.executeQuery();
				if (rs1.next()) {
					resultNo2 = rs1.getString("RESULT_NO");
				}
				rs1.close();
				psta.close();

				// 新增低温炉实绩
				patAddS.setObject(1, resultNo2);
				patAddS.setObject(2, result2.getZyBatchId());
				// patAddS.setObject(3, pln.getProdIndex());
				patAddS.setObject(3, pln.getProPlanId());
				patAddS.setObject(4, pln.getGxPlanNo());
				patAddS.setObject(5, result2.getLheatEnterTime());
				patAddS.setObject(6, result2.getLheatOutTime());
				patAddS.setObject(7, result2.getLheatExitTemp());
				patAddS.setObject(8, result2.getLheatTaktTime());
				patAddS.setObject(9, result2.getLheatAvgTemp1());
				patAddS.setObject(10, result2.getLheatAvgTemp2());
				patAddS.setObject(11, result2.getLheatAvgTemp3());
				patAddS.setObject(12, result2.getLheatAvgTemp4());
				patAddS.setObject(13, result2.getLheatAvgTemp5());
				patAddS.setObject(14, result2.getLheatAvgTemp6());
				patAddS.setObject(15, result2.getLheatAvgTemp7());
				patAddS.setObject(16, result2.getLheatAvgTemp8());
				patAddS.setObject(17, result2.getLheatAvgTemp9());
				patAddS.setObject(18, result2.getProNum());
				patAddS.setObject(19, result2.getProWt());
				patAddS.setObject(20, result2.getFailNum());
				patAddS.setObject(21, resultNo2);
				patAddS.setObject(22, result2.getOfflineNum());
				patAddS.setObject(23, result2.getOfflineWt());
				patAddS.setObject(24, result2.getReNum());
				patAddS.setObject(25, result2.getReWt());
				patAddS.setObject(26, "1");
				patAddS.setObject(27, result2.getColTime());
				patAddS.setObject(28, result2.getColUser());
				patAddS.setObject(29, result2.getColShift());
				patAddS.setObject(30, result2.getColGroup());
				patAddS.setObject(31, result2.getProducer());
				if (result2.getProducer().equals("")) {
					patAddS.setObject(32, "");
				} else {
					patAddS.setObject(32, result2.getProducerTime());
				}
				patAddS.setObject(33, pln.getPlineCode());
				patAddS.setObject(34, result2.getHeatPlanNo());
				patAddS.setObject(35, pln.getPlineName());
				patAddS.setObject(36, systime);
				patAddS.setObject(37, result2.getProcessSeq());
				patAddS.setObject(38, result2.getTotalTime());
				patAddS.setObject(39, result2.getLowTemp());
				patAddS.setObject(40, result2.getCoolingType());
				patAddS.setObject(41, result.getHttTechnology());
				patAddS.setObject(42, result2.getHttType());
				patAddS.addBatch();

				// 新增低温炉公共信息
				patsPlan.setObject(1, resultNo2);
				patsPlan.setObject(2, pln.getZyBatchId());
				// patsPlan.setObject(3, pln.getProdIndex());
				patsPlan.setObject(3, pln.getProPlanId());
				patsPlan.setObject(4, pln.getGxPlanNo());
				patsPlan.setObject(5, pln.getOrderSource());
				patsPlan.setObject(6, pln.getOrderNo());
				patsPlan.setObject(7, pln.getOrderSeq());
				patsPlan.setObject(8, pln.getReqBlId());
				patsPlan.setObject(9, pln.getPlineCode());
				patsPlan.setObject(10, pln.getPlineName());
				patsPlan.setObject(11, Lowgx);
				patsPlan.setObject(12, "低温炉");
				patsPlan.setObject(13, pln.getGradecode());
				patsPlan.setObject(14, pln.getGradename());
				patsPlan.setObject(15, pln.getSteelcode());
				patsPlan.setObject(16, pln.getSteelname());
				patsPlan.setObject(17, pln.getOutdiameterIn());
				patsPlan.setObject(18, pln.getWallthickIn());
				patsPlan.setObject(19, "");
				patsPlan.setObject(20, "");
				patsPlan.setObject(21, "");
				patsPlan.setObject(22, "");
				patsPlan.setObject(23, "");
				patsPlan.setObject(24, "");
				patsPlan.setObject(25, "");
				patsPlan.setObject(26, "");
				patsPlan.setObject(27, pln.getOutwlId());
				patsPlan.setObject(28, pln.getOutwlDesc());
				patsPlan.setObject(29, pln.getInwlId());
				patsPlan.setObject(30, pln.getInwlDesc());
				patsPlan.setObject(31, pln.getMonitorPoint());
				patsPlan.setObject(32, ifMonitNo);
				patsPlan.setObject(33, pln.getPrdcrNo());
				patsPlan.setObject(34, result2.getProducer());
				if (result2.getProducer().equals("")) {
					patsPlan.setObject(35, "");
				} else {
					patsPlan.setObject(35, result2.getProducerTime());
				}
				patsPlan.setObject(36, pln.getStationRoad());
				patsPlan.setObject(37, pln.getCraftFileNo());
				patsPlan.setObject(38, pln.getCraftFileMan());
				patsPlan.setObject(39, pln.getCraftSeq());
				patsPlan.setObject(40, result2.getProNum());
				patsPlan.setObject(41, result2.getProWt());
				patsPlan.setObject(42, result2.getFailNum());
				patsPlan.setObject(43, resultNo2);
				patsPlan.setObject(44, result2.getOfflineNum());
				patsPlan.setObject(45, result2.getOfflineWt());
				patsPlan.setObject(46, result2.getReNum());
				patsPlan.setObject(47, result2.getReWt());
				patsPlan.setObject(48, "1");
				patsPlan.setObject(49, result2.getColTime());
				patsPlan.setObject(50, "");
				patsPlan.setObject(51, result2.getColUser());
				patsPlan.setObject(52, result2.getColShift());
				patsPlan.setObject(53, result2.getColGroup());
				patsPlan.setObject(54, "1");
				patsPlan.setObject(55, systime);
				patsPlan.setObject(56, "");
				patsPlan.setObject(57, result2.getHeatPlanNo());
				patsPlan.setObject(58, pln.getJudgeStoveNo());
				patsPlan.setObject(59, "");
				patsPlan.setObject(60, "");
				patsPlan.setObject(61, pln.getProduccode());
				patsPlan.setObject(62, pln.getProducname());
				patsPlan.setObject(63, pln.getSpecCode());
				patsPlan.setObject(64, pln.getSpecName());
				patsPlan.setObject(65, result2.getProcessSeq());
				patsPlan.addBatch();

				// 修改工艺路径
				pastupdatePath2.setObject(1, "1");
				pastupdatePath2.setObject(2, result2.getHeatPlanNo());
				pastupdatePath2.addBatch();
				pastupdatePath2.executeBatch();
				// 修改计划表
				patsupdatepln.setObject(1, "30");
				patsupdatepln.setObject(2, result2.getHeatPlanNo());
				patsupdatepln.addBatch();
				patsupdatepln.executeBatch();

				FrmHttBugD.AddHttWaste(connection, result2.getHeatPlanNo(),
						resultNo2, pln.getPlineCode(), result2.getColUser(),
						result2.getProcessSeq(), Lowgx, list5Str, list6Str);
			}

			// endregion

			patAdd.executeBatch();
			patAddD.executeBatch();
			patAddS.executeBatch();
			patsPlan1.executeBatch();
			patsPlan.executeBatch();

			int RealProNum = ProNum != 0 ? ProNum : ProNum1 != 0 ? ProNum1
					: ProNum2;
			String Weight = ProNum != 0 ? result.getProWt()
					: ProNum1 != 0 ? result1.getProWt() : result2.getProWt();
			String RealResultNo = ProNum != 0 ? resultNo
					: ProNum1 != 0 ? resultNo1 : resultNo2;
			SimpleDateFormat matter2 = new SimpleDateFormat("yyyyMMddHHmm");
			SimpleDateFormat matter3 = new SimpleDateFormat("yyyyMM");
			SimpleDateFormat matter4 = new SimpleDateFormat("yyyyMMdd");

			Date colDate = result.getHheatEnterTime().length() == 17 ? dateFormat1
					.parse(result.getHheatEnterTime())
					: dateFormat.parse(result.getHheatEnterTime());
			Date endDate = result.getHheatEnterTime().length() == 17 ? dateFormat1
					.parse(result.getHheatOutTime())
					: dateFormat.parse(result.getHheatOutTime());
			Date procDate = colDate;
			if (result1.getColShift().equals("3")) {
				Calendar date = Calendar.getInstance();
				date.setTime(colDate);
				date.set(Calendar.HOUR_OF_DAY,
						date.get(Calendar.HOUR_OF_DAY) + 12);
				procDate = dateFormat.parse(dateFormat.format(date.getTime()));
			}

			if (colDate.after(endDate)) {
				core.setV_errMsg("结束时间不能早于开始时间");
				return core;
			}
			
			int acount = 0;
			String sql1 = CoreXmlSqlParsersFactory
					.getSql("FrmHttControlLog.qureyConfirmFlag");// 查询录入时间是否调度已确认.
			psta = connection.prepareStatement(sql1);
			psta.setString(1, matter2.format(colDate));
			psta.setObject(2, matter2.format(colDate));
			psta.setObject(3, matter2.format(endDate));
			psta.setObject(4, matter2.format(endDate));
			psta.setObject(5, result1.getPlineCode());
			psta.setObject(6, "0");
			rs1 = psta.executeQuery();
			if (rs1.next()) {
				acount = Integer.parseInt(rs1.getString("ACOUT")) ;
			}
			if (acount > 0) {
				core.setV_errMsg("该时间段,调度已确认或已审核,请联系调度取消确认或取消审核!");
				return core;
			}
			rs1.close();
			psta.close();

			pastaddHttControlLog.setObject(1, matter2.format(colDate));
			pastaddHttControlLog.setObject(2, matter2.format(endDate));
			pastaddHttControlLog.setObject(3, RealResultNo);
			// patAdd.setObject(3, pln.getProdIndex());
			pastaddHttControlLog.setObject(4, result1.getColShift());
			pastaddHttControlLog.setObject(5, result1.getColGroup());
			pastaddHttControlLog.setObject(6, RealProNum);
			pastaddHttControlLog.setObject(7, Weight);
			pastaddHttControlLog.setObject(8, systime);
			pastaddHttControlLog.setObject(9, result1.getColUser());
			pastaddHttControlLog.setObject(10, com.steering.common.StringTool.GetBalYear(procDate,com.steering.common.StringTool.GetSupplyUnit(result1.getPlineCode()))); //改25号结转
			pastaddHttControlLog.setObject(11, matter4.format(procDate));
			pastaddHttControlLog.setObject(12, "0");
			pastaddHttControlLog.setObject(13, PlanNo);
			pastaddHttControlLog.addBatch();
			pastaddHttControlLog.executeBatch();

			core.setV_errMsg("新增成功！");

			//throw new Exception("ceshi");

			core.setResult(1);
			connection.commit();
		} catch (Exception e) {
			core.setV_errMsg(e.getMessage());
			if (connection != null) {
				try {
					connection.rollback(); // 回滚事务
				} catch (Exception e2) {
				}
			}
		} finally {
			try {
				if (connection != null && !connection.isClosed()) {
					connection.close();
				}
			} catch (Exception e2) {
			}
		}
		return core;
	}

	/**
	 * 修改热处理
	 * 
	 *            修改热处理
	 * @return
	 */
	public CoreReturnObject updateHeatTreatmentResult(String resultStr,
			String PlanNo, String hertSqe, String Highgx, String QuenchtGx,
			String Lowgx, ArrayList<String> list3Str,
			ArrayList<String> list4Str, String updateCount) {
		CoreReturnObject core = new CoreReturnObject();
		Connection connection = this.getDao(CoreConstantData.sysbeanstr)
				.getConnection();
		Date now = new Date();
		SimpleDateFormat dateFormat = new SimpleDateFormat(
				"yyyy-MM-dd HH:mm:ss", Locale.CHINA);
		SimpleDateFormat dateFormat1 = new SimpleDateFormat("yyyy-MM-dd HH:mm",
				Locale.CHINA);
		String systime = dateFormat.format(now);
		PreparedStatement psta = null;
		ResultSet rs1 = null;
		try {
			connection.setAutoCommit(false); // 取消自动提交事务
			String sqlUpdate = CoreXmlSqlParsersFactory
					.getSql("HeatTreatmentService.updateHightResult");// 修改高温炉实绩
			PreparedStatement patUpdate = connection
					.prepareStatement(sqlUpdate);
			String sqlUpdateD = CoreXmlSqlParsersFactory
					.getSql("HeatTreatmentService.updateQuechtResult");// 修改淬火记录
			PreparedStatement patUpdateD = connection
					.prepareStatement(sqlUpdateD);
			String sqlUpdateS = CoreXmlSqlParsersFactory
					.getSql("HeatTreatmentService.updateLowResult");// 修改低温炉记录
			PreparedStatement patUpdateS = connection
					.prepareStatement(sqlUpdateS);
			String addPlnInfo = CoreXmlSqlParsersFactory
					.getSql("HttLoadingService.updateComInfoResult");// 修改公共信息
			PreparedStatement patsupdatePlan = connection
					.prepareStatement(addPlnInfo);
			String addPlnInfo1 = CoreXmlSqlParsersFactory
					.getSql("HeatTreatmentService.AddComInfoResult1");// 查询材料状态和工序点编码
			PreparedStatement patsPlan1 = connection
					.prepareStatement(addPlnInfo1);

			// 获取热处理计划实体了
			PlnZyRclMEntity pln = PlanService.getSendHttPlanCInfo(connection,
					PlanNo);

			if (pln == null)
				return core;
			if (pln.getPlanstatus().equals("3")) {
				core.setV_errMsg("该计划已关闭！");
				return core;
			}
			String ifMonitNo = "";
			if (pln.getIfMonitor().equals("是")) {
				ifMonitNo = "1";
			} else {
				ifMonitNo = "0";
			}

			if (pln == null)
				return core;
			if (pln.getPlanstatus().equals("3")) {
				core.setV_errMsg("该计划已关闭！");
				return core;
			}

			String cutFalg1 = "";
			String sql = CoreXmlSqlParsersFactory
					.getSql("HeatTreatmentService.qureyGxComInfoNew");// 查询工序是否是结炉状态
			psta = connection.prepareStatement(sql);
			psta.setString(1, PlanNo);
			psta.setObject(2, Highgx);
			psta.setObject(3, Lowgx);
			psta.setObject(4, QuenchtGx);
			psta.setObject(5, pln.getRealProcessSeq());
			rs1 = psta.executeQuery();
			if (rs1.next()) {
				cutFalg1 = rs1.getString("STATION_STATUS");
			}

			if (cutFalg1 != null && cutFalg1.equals("2")) {
				core.setV_errMsg("该工序已经结炉,无法修改");
				return core;
			}
			rs1.close();
			psta.close();

			// 高温炉
			if (updateCount.equals("1")) {

				// region 高温炉
				HttHheatResultEntity result = EntityTool.getEntityByJSONStr(
						resultStr, HttHheatResultEntity.class);

				String Sql = CoreXmlSqlParsersFactory
						.getSql("HeatTreatmentService.GetHeatTreatmentResult");
				Sql += " WHERE RESULT_NO = '" + result.getResultNo() + "'";
				HttHheatResultEntity resultOld = EntityTool
						.getEntityBySqlNoClsCon(Sql, connection,
								HttHheatResultEntity.class);
				result.setProcessSeq(resultOld.getProcessSeq());

				if (resultOld == null || resultOld.getResultNo().equals("")) {
					core.setV_errMsg("数据发生改变,请先刷新！");
					return core;
				}

				if (!result.getProcessSeq().equals(resultOld.getProcessSeq())) {
					core.setV_errMsg("不允许修改循环次数！");
					return core;
				}
				

				int ProNum = 0;
				int FailNum = 0;
				int OldProNum = 0;
				int OldFailNum = 0;

				if (StringTool.isInteger(result.getProNum())) {
					ProNum = Integer.parseInt(result.getProNum());

				} else {
					core.setV_errMsg("请输入正确的支数！");
					return core;
				}

				if (StringTool.isInteger(result.getFailNum())) {
					FailNum = Integer.parseInt(result.getFailNum());
				}

				if (StringTool.isInteger(resultOld.getProNum())) {
					OldProNum = Integer.parseInt(resultOld.getProNum());

				}

				if (StringTool.isInteger(resultOld.getFailNum())) {
					OldFailNum = Integer.parseInt(resultOld.getFailNum());
				}

				if (ProNum <= 0) {
					core.setV_errMsg("作业支数不能等于0或者小于0！");
					return core;
				}

				if (ProNum < FailNum) {
					core.setV_errMsg("作业支数不能小于废品支数！");
					return core;
				}

				FrmHttBugD.DeleteHttWaste(connection, PlanNo, result
						.getResultNo(), result.getPlineCode(), result
						.getProcessSeq(), Highgx, OldFailNum);
				FrmHttBugD.AddHttWaste(connection, PlanNo,
						result.getResultNo(), result.getPlineCode(), result
								.getColUser(), result.getProcessSeq(), Highgx,
						list3Str, list4Str);

				// 修改高温炉实绩
				patUpdate.setObject(1, result.getHheatEnterTime());
				patUpdate.setObject(2, result.getHheatOutTime());
				patUpdate.setObject(3, result.getHheatExitTemp());
				patUpdate.setObject(4, result.getHheatTaktTime());
				patUpdate.setObject(5, result.getHheatAvgTemp1());
				patUpdate.setObject(6, result.getHheatAvgTemp2());
				patUpdate.setObject(7, result.getHheatAvgTemp3());
				patUpdate.setObject(8, result.getHheatAvgTemp4());
				patUpdate.setObject(9, result.getHheatAvgTemp5());
				patUpdate.setObject(10, result.getHheatAvgTemp6());
				patUpdate.setObject(11, result.getProNum());
				patUpdate.setObject(12, result.getProWt());
				patUpdate.setObject(13, result.getFailNum());
				patUpdate.setObject(14, result.getFailWt());
				patUpdate.setObject(15, result.getOfflineNum());
				patUpdate.setObject(16, result.getOfflineWt());
				patUpdate.setObject(17, result.getReNum());
				patUpdate.setObject(18, result.getReWt());
				patUpdate.setObject(19, result.getColTime());
				patUpdate.setObject(20, result.getColShift());
				patUpdate.setObject(21, result.getColGroup());
				patUpdate.setObject(22, result.getProducer());
				patUpdate.setObject(23, result.getProducerTime());
				patUpdate.setObject(24, systime);
				patUpdate.setObject(25, result.getColUser());
				patUpdate.setObject(26, result.getResultNo());
				patUpdate.addBatch();

				// 修改公共信息
				patsupdatePlan.setObject(1, result.getProNum());
				patsupdatePlan.setObject(2, result.getProWt());
				patsupdatePlan.setObject(3, result.getColTime());
				patsupdatePlan.setObject(4, result.getColGroup());
				patsupdatePlan.setObject(5, result.getColGroup());
				patsupdatePlan.setObject(6, result.getResultNo());
				patsupdatePlan.addBatch();

				patUpdate.executeBatch();
				patsupdatePlan.executeBatch();
				// endregion
			}

			// 淬火
			else if (updateCount.equals("2")) {

				// region 淬火
				HttQuenchingResultEntity result1 = EntityTool
						.getEntityByJSONStr(resultStr,
								HttQuenchingResultEntity.class);

				String Sql = CoreXmlSqlParsersFactory
						.getSql("HeatTreatmentService.GetQuechtHeatTreatmentResult");
				Sql += " WHERE RESULT_NO = '" + result1.getResultNo() + "'";
				HttQuenchingResultEntity result1Old = EntityTool
						.getEntityBySqlNoClsCon(Sql, connection,
								HttQuenchingResultEntity.class);

				if (result1Old == null || result1Old.getResultNo().equals("")) {
					core.setV_errMsg("数据发生改变,请先刷新！");
					return core;
				}

				if (!result1.getProcessSeq().equals(result1Old.getProcessSeq())) {
					core.setV_errMsg("不允许修改循环次数！");
					return core;
				}

				int ProNum = 0;
				int FailNum = 0;

				if (StringTool.isInteger(result1.getProNum())) {
					ProNum = Integer.parseInt(result1.getProNum());

				} else {
					core.setV_errMsg("请输入正确的支数！");
					return core;
				}

				if (StringTool.isInteger(result1.getFailNum())) {
					FailNum = Integer.parseInt(result1.getFailNum());

				}

				if (ProNum <= 0) {
					core.setV_errMsg("作业支数不能等于0或者小于0！");
					return core;
				}

				FrmHttBugD.DeleteHttWaste(connection, PlanNo, result1
						.getResultNo(), result1.getPlineCode(), result1
						.getProcessSeq(), Highgx, FailNum);
				FrmHttBugD.AddHttWaste(connection, PlanNo, result1
						.getResultNo(), result1.getPlineCode(), result1
						.getColUser(), result1.getProcessSeq(), Highgx,
						list3Str, list4Str);

				// 修改淬火实绩
				patUpdateD.setObject(1, result1.getQuenchWay());
				patUpdateD.setObject(2, result1.getTraffic());

				patUpdateD.setObject(3, result1.getLengthTime());
				patUpdateD.setObject(4, result1.getProNum());
				patUpdateD.setObject(5, result1.getProWt());
				patUpdateD.setObject(6, result1.getFailNum());
				patUpdateD.setObject(7, result1.getFailWt());

				patUpdateD.setObject(8, result1.getColTime());
				patUpdateD.setObject(9, result1.getColShift());
				patUpdateD.setObject(10, result1.getColGroup());
				patUpdateD.setObject(11, systime);
				patUpdateD.setObject(12, result1.getColUser());
				patUpdateD.setObject(13, result1.getResultNo());
				patUpdateD.addBatch();

				// 修改公共信息
				patsupdatePlan.setObject(1, result1.getProNum());
				patsupdatePlan.setObject(2, result1.getProWt());
				patsupdatePlan.setObject(3, result1.getColTime());
				patsupdatePlan.setObject(4, result1.getColGroup());
				patsupdatePlan.setObject(5, result1.getColGroup());
				patsupdatePlan.setObject(6, result1.getResultNo());
				patsupdatePlan.addBatch();

				patUpdateD.executeBatch();
				patsupdatePlan.executeBatch();
				// endregion
			}

			// 低温炉
			else {
				// region 低温炉
				HttLheatResultEntity result2 = EntityTool.getEntityByJSONStr(
						resultStr, HttLheatResultEntity.class);

				String Sql = CoreXmlSqlParsersFactory
						.getSql("HeatTreatmentService.GetLowHeatTreatmentResult");
				Sql += " WHERE RESULT_NO = '" + result2.getResultNo() + "'";
				HttLheatResultEntity result2Old = EntityTool
						.getEntityBySqlNoClsCon(Sql, connection,
								HttLheatResultEntity.class);

				if (result2Old == null || result2Old.getResultNo().equals("")) {
					core.setV_errMsg("数据发生改变,请先刷新！");
					return core;
				}

				if (!result2.getProcessSeq().equals(result2Old.getProcessSeq())) {
					core.setV_errMsg("不允许修改循环次数！");
					return core;
				}

				int ProNum = 0;
				int FailNum = 0;
				int ProNumOld = 0;
				int FailNumOld = 0;

				if (StringTool.isInteger(result2.getProNum())) {
					ProNum = Integer.parseInt(result2.getProNum());

				} else {
					core.setV_errMsg("请输入正确的支数！");
					return core;
				}

				if (StringTool.isInteger(result2.getFailNum())) {
					FailNum = Integer.parseInt(result2.getFailNum());
				}

				if (StringTool.isInteger(result2Old.getProNum())) {
					ProNumOld = Integer.parseInt(result2Old.getProNum());

				}

				if (StringTool.isInteger(result2Old.getFailNum())) {
					FailNumOld = Integer.parseInt(result2Old.getFailNum());
				}

				if (ProNum <= 0) {
					core.setV_errMsg("作业支数不能等于0或者小于0！");
					return core;
				}

				if (ProNum < FailNum) {
					core.setV_errMsg("作业支数不能小于废品支数！");
					return core;
				}

				FrmHttBugD.DeleteHttWaste(connection, PlanNo, result2
						.getResultNo(), result2.getPlineCode(), result2
						.getProcessSeq(), Lowgx, FailNumOld);
				FrmHttBugD.AddHttWaste(connection, PlanNo, result2
						.getResultNo(), result2.getPlineCode(), result2
						.getColUser(), result2.getProcessSeq(), Lowgx,
						list3Str, list4Str);

				// 修改低温炉实绩
				patUpdateS.setObject(1, result2.getLheatEnterTime());
				patUpdateS.setObject(2, result2.getLheatOutTime());
				patUpdateS.setObject(3, result2.getLheatExitTemp());
				patUpdateS.setObject(4, result2.getLheatTaktTime());
				patUpdateS.setObject(5, result2.getLheatAvgTemp1());
				patUpdateS.setObject(6, result2.getLheatAvgTemp2());
				patUpdateS.setObject(7, result2.getLheatAvgTemp3());
				patUpdateS.setObject(8, result2.getLheatAvgTemp4());
				patUpdateS.setObject(9, result2.getLheatAvgTemp5());
				patUpdateS.setObject(10, result2.getLheatAvgTemp6());
				patUpdateS.setObject(11, result2.getLheatAvgTemp7());
				patUpdateS.setObject(12, result2.getLheatAvgTemp8());
				patUpdateS.setObject(13, result2.getLheatAvgTemp9());
				patUpdateS.setObject(14, result2.getProNum());
				patUpdateS.setObject(15, result2.getProWt());
				patUpdateS.setObject(16, result2.getFailNum());
				patUpdateS.setObject(17, result2.getFailWt());
				patUpdateS.setObject(18, result2.getOfflineNum());
				patUpdateS.setObject(19, result2.getOfflineWt());
				patUpdateS.setObject(20, result2.getReNum());
				patUpdateS.setObject(21, result2.getReWt());
				patUpdateS.setObject(22, result2.getColTime());
				patUpdateS.setObject(23, result2.getColShift());
				patUpdateS.setObject(24, result2.getColGroup());
				patUpdateS.setObject(25, result2.getProducer());
				patUpdateS.setObject(26, result2.getProducerTime());
				patUpdateS.setObject(27, systime);
				patUpdateS.setObject(28, result2.getColUser());
				patUpdateS.setObject(29, result2.getResultNo());
				patUpdateS.addBatch();

				// 修改公共信息
				patsupdatePlan.setObject(1, result2.getProNum());
				patsupdatePlan.setObject(2, result2.getProWt());
				patsupdatePlan.setObject(3, result2.getColTime());
				patsupdatePlan.setObject(4, result2.getColGroup());
				patsupdatePlan.setObject(5, result2.getColGroup());
				patsupdatePlan.setObject(6, result2.getResultNo());
				patsupdatePlan.addBatch();

				patUpdateS.executeBatch();
				patsupdatePlan.executeBatch();
				// endregion
			}
			

			core.setV_errMsg("修改成功！");
			core.setResult(1);
			connection.commit();
		} catch (Exception e) {
			core.setV_errMsg(e.getMessage());
			if (connection != null) {
				try {
					connection.rollback(); // 回滚事务
				} catch (Exception e2) {
				}
			}
		} finally {
			try {
				if (connection != null && !connection.isClosed()) {
					connection.close();
				}
			} catch (Exception e2) {
			}
		}
		return core;
	}

	/**
	 * 删除热处理实绩
	 * 
	 *            热处理实绩
	 * @return
	 */
	public CoreReturnObject deleteHeatTreatmentResult(String updateCount,
			String heratNo, String rentNo, String rentNo1, String rentNo2,
			String HightGx, String QuenchtGx, String LowGx) {
		CoreReturnObject core = new CoreReturnObject();
		Connection connection = this.getDao(CoreConstantData.sysbeanstr)
				.getConnection();
		PreparedStatement psta = null;
		ResultSet rs = null;
		int acount = 0;
		try {
			connection.setAutoCommit(false); // 取消自动提交事务
			String sqlUpdate = CoreXmlSqlParsersFactory
					.getSql("HeatTreatmentService.deleteHightResult");// 删除高温炉实绩
			PreparedStatement patUpdate = connection
					.prepareStatement(sqlUpdate);
			String sqlUpdateD = CoreXmlSqlParsersFactory
					.getSql("HeatTreatmentService.deleteQuechtResult");// 删除淬火记录
			PreparedStatement patUpdateD = connection
					.prepareStatement(sqlUpdateD);
			String sqlUpdateS = CoreXmlSqlParsersFactory
					.getSql("HeatTreatmentService.deleteLowResult");// 删除低温炉记录
			PreparedStatement patUpdateS = connection
					.prepareStatement(sqlUpdateS);
			String addPlnInfo = CoreXmlSqlParsersFactory
					.getSql("HttLoadingService.deleteComInfoResult");// 删除公共信息
			PreparedStatement patsupdatePlan = connection
					.prepareStatement(addPlnInfo);
			String addPlnInfo1 = CoreXmlSqlParsersFactory
					.getSql("HeatTreatmentService.AddComInfoResult1");// 查询材料状态和工序点编码
			PreparedStatement patsPlan1 = connection
					.prepareStatement(addPlnInfo1);
			String updatePath = CoreXmlSqlParsersFactory
					.getSql("HeatTreatmentService.UpdatePath");// 修改队列表工艺路径
			PreparedStatement pastupdatePath = connection
					.prepareStatement(updatePath);
			String updatePath1 = CoreXmlSqlParsersFactory
					.getSql("HeatTreatmentService.UpdatePath1");// 修改队列表工艺路径
			PreparedStatement pastupdatePath1 = connection
					.prepareStatement(updatePath1);
			String updatePath2 = CoreXmlSqlParsersFactory
					.getSql("HeatTreatmentService.UpdatePath2");// 修改队列表工艺路径
			PreparedStatement pastupdatePath2 = connection
					.prepareStatement(updatePath2);

			String DeleteHttControl = CoreXmlSqlParsersFactory
					.getSql("HeatTreatmentService.deleteHttControlLog");
			PreparedStatement pastDeleteHttControl = connection
					.prepareStatement(DeleteHttControl);

			// 获取热处理计划实体了
			PlnZyRclMEntity pln = PlanService.getSendHttPlanCInfo(connection,
					heratNo);

			if (pln == null)
				return core;
			if (pln.getPlanstatus().equals("3")) {
				core.setV_errMsg("该计划已关闭！");
				return core;
			}

			String cutFalg1 = "";
			String sql = CoreXmlSqlParsersFactory
					.getSql("HeatTreatmentService.qureyGxComInfoNew");// 查询工序是否是结炉状态
			psta = connection.prepareStatement(sql);
			psta.setString(1, heratNo);
			psta.setObject(2, HightGx);
			psta.setObject(3, LowGx);
			psta.setObject(4, QuenchtGx);
			psta.setObject(5, pln.getRealProcessSeq());
			rs = psta.executeQuery();
			if (rs.next()) {
				cutFalg1 = rs.getString("STATION_STATUS");
			} else {
				core.setV_errMsg("无实绩！");
				return core;
			}

			if (cutFalg1 != null && cutFalg1.equals("2")) {
				core.setV_errMsg("该工序已经结炉,无法修改");
				return core;
			}
			rs.close();
			psta.close();

			sql = CoreXmlSqlParsersFactory
					.getSql("HeatTreatmentService.qureyIsConfirm");// 查询调度是否确认
			psta = connection.prepareStatement(sql);
			psta.setString(1, rentNo);
			rs = psta.executeQuery();
			if (rs.next()) {
				acount = Integer.parseInt(rs.getString("acout"));
			}
			if (acount > 0) {
				core.setV_errMsg("调度已确认，不能删除！");
				return core;
			}
			rs.close();
			psta.close();

			// 高温炉
			if (!rentNo.equals("")) {
				// region 高温炉
				String Sql = CoreXmlSqlParsersFactory
						.getSql("HeatTreatmentService.GetHeatTreatmentResult");
				Sql += " WHERE RESULT_NO = '" + rentNo + "'";
				HttHheatResultEntity result = EntityTool
						.getEntityBySqlNoClsCon(Sql, connection,
								HttHheatResultEntity.class);

				if (result == null || result.getResultNo().equals("")) {
					core.setV_errMsg("数据发生改变,请先刷新！");
					return core;
				}

				if (!pln.getPlineCode().equals(result.getPlineCode())) {
					core.setV_errMsg("不允许删除其他产线实绩,若需删除,请离线委内回原产线进行删除！");
					return core;
				}

				int detCount = 0;

				if (StringTool.isInteger(result.getFailNum())) {
					detCount = Integer.parseInt(result.getFailNum());
				}

				if (result.getProcessSeq().equals(pln.getRealProcessSeq())) {

					FrmHttBugD.DeleteHttWaste(connection, heratNo, rentNo,
							result.getPlineCode(), result.getProcessSeq(),
							HightGx, detCount);
					// 删除高温炉实绩
					patUpdate.setObject(1, rentNo);
					patUpdate.addBatch();

					pastDeleteHttControl.setObject(1, rentNo);
					pastDeleteHttControl.addBatch();

					// 删除公共信息
					patsupdatePlan.setObject(1, rentNo);
					patsupdatePlan.addBatch();
					patUpdate.executeBatch();
					patsupdatePlan.executeBatch();

					pastupdatePath.setObject(1, "0");
					pastupdatePath.setObject(2, heratNo);
					pastupdatePath.addBatch();
					pastupdatePath.executeBatch();
					String updatepln = CoreXmlSqlParsersFactory
							.getSql("AppearanceService.updatePlnZyRclM");// 删除时修改计划表
					PreparedStatement patsupdatepln = connection
							.prepareStatement(updatepln);
					// 修改计划表
					patsupdatepln.setObject(1, "00");
					patsupdatepln.setObject(2, heratNo);
					patsupdatepln.addBatch();
					patsupdatepln.executeBatch();
				} else {
					core.setV_errMsg("该记录是上次热处理的实绩,无法删除！");
					return core;
				}

				// endregion
			}

			if (!rentNo1.equals("")) {
				// region 淬火
				String Sql = CoreXmlSqlParsersFactory
						.getSql("HeatTreatmentService.GetQuechtHeatTreatmentResult");
				Sql += " WHERE RESULT_NO = '" + rentNo1 + "'";
				HttQuenchingResultEntity result1 = EntityTool
						.getEntityBySqlNoClsCon(Sql, connection,
								HttQuenchingResultEntity.class);

				if (result1 == null || result1.getResultNo().equals("")) {
					core.setV_errMsg("数据发生改变,请先刷新！");
					return core;
				}

				if (!pln.getPlineCode().equals(result1.getPlineCode())) {
					core.setV_errMsg("不允许删除其他产线实绩,若需删除,请离线委内回原产线进行删除！");
					return core;
				}

				int detCount = 0;

				if (StringTool.isInteger(result1.getFailNum())) {
					detCount = Integer.parseInt(result1.getFailNum());
				}

				if (result1.getProcessSeq().equals(pln.getRealProcessSeq())) {

					FrmHttBugD.DeleteHttWaste(connection, heratNo, rentNo1,
							result1.getPlineCode(), result1.getProcessSeq(),
							QuenchtGx, detCount);

					// 删除淬火实绩
					patUpdateD.setObject(1, rentNo1);
					patUpdateD.addBatch();

					pastDeleteHttControl.setObject(1, rentNo1);
					pastDeleteHttControl.addBatch();

					// 删除公共信息
					patsupdatePlan.setObject(1, rentNo1);
					patsupdatePlan.addBatch();

					patUpdateD.executeBatch();
					patsupdatePlan.executeBatch();

					// 修改工艺路径
					pastupdatePath1.setObject(1, "0");
					pastupdatePath1.setObject(2, heratNo);
					pastupdatePath1.addBatch();
					pastupdatePath1.executeBatch();
					String updatepln = CoreXmlSqlParsersFactory
							.getSql("AppearanceService.updatePlnZyRclM");// 删除时修改计划表
					PreparedStatement patsupdatepln = connection
							.prepareStatement(updatepln);
					// 修改计划表
					patsupdatepln.setObject(1, "00");
					patsupdatepln.setObject(2, heratNo);
					patsupdatepln.addBatch();
					patsupdatepln.executeBatch();

				} else {
					core.setV_errMsg("该记录是上次热处理的实绩,无法删除！");
					return core;
				}
				// endregion
			}

			// 低温炉
			if (!rentNo2.equals("")) {
				String Sql = CoreXmlSqlParsersFactory
						.getSql("HeatTreatmentService.GetLowHeatTreatmentResult");
				Sql += " WHERE RESULT_NO = '" + rentNo2 + "'";
				HttLheatResultEntity result3 = EntityTool
						.getEntityBySqlNoClsCon(Sql, connection,
								HttLheatResultEntity.class);

				if (result3 == null || result3.getResultNo().equals("")) {
					core.setV_errMsg("数据发生改变,请先刷新！");
					return core;
				}

				if (!pln.getPlineCode().equals(result3.getPlineCode())) {
					core.setV_errMsg("不允许删除其他产线实绩,若需删除,请离线委内回原产线进行删除！");
					return core;
				}

				int detCount = 0;

				if (StringTool.isInteger(result3.getFailNum())) {
					detCount = Integer.parseInt(result3.getFailNum());
				}

				if (result3.getProcessSeq().equals(pln.getRealProcessSeq())) {

					// 删除低温炉实绩
					patUpdateS.setObject(1, rentNo2);
					patUpdateS.addBatch();

					pastDeleteHttControl.setObject(1, rentNo2);
					pastDeleteHttControl.addBatch();

					// 删除公共信息
					patsupdatePlan.setObject(1, rentNo2);
					patsupdatePlan.addBatch();

					patUpdateS.executeBatch();
					patsupdatePlan.executeBatch();

					FrmHttBugD.DeleteHttWaste(connection, heratNo, rentNo2,
							result3.getPlineCode(), result3.getProcessSeq(),
							LowGx, detCount);

					// 修改工艺路径
					pastupdatePath2.setObject(1, "0");
					pastupdatePath2.setObject(2, heratNo);
					pastupdatePath2.addBatch();
					pastupdatePath2.executeBatch();
					String updatepln = CoreXmlSqlParsersFactory
							.getSql("AppearanceService.updatePlnZyRclM");// 删除时修改计划表
					PreparedStatement patsupdatepln = connection
							.prepareStatement(updatepln);
					// 修改计划表
					patsupdatepln.setObject(1, "00");
					patsupdatepln.setObject(2, heratNo);
					patsupdatepln.addBatch();
					patsupdatepln.executeBatch();

				} else {
					core.setV_errMsg("该记录是上次热处理的实绩,无法删除！");
					return core;
				}
			}

			pastDeleteHttControl.executeBatch();

			core.setV_errMsg("删除成功！");
			core.setResult(1);
			connection.commit();
		} catch (Exception e) {
			core.setV_errMsg(e.getMessage());
			if (connection != null) {
				try {
					connection.rollback(); // 回滚事务
				} catch (Exception e2) {
				}
			}
		} finally {
			try {
				if (connection != null && !connection.isClosed()) {
					connection.close();
				}
			} catch (Exception e2) {
			}
		}
		return core;
	}

	/***
	 * 结炉
	 * 
	 * @return
	 */
	public CoreReturnObject updateDoBeside(ArrayList<String> parm) {
		CoreReturnObject cro = new CoreReturnObject();
		Connection connection = this.getDao(CoreConstantData.sysbeanstr)
				.getConnection();
		String sql = "";
		PreparedStatement psta = null;
		ResultSet rs = null;
		try {
			connection.setAutoCommit(false); // 取消自动提交事务
			String updateSql = CoreXmlSqlParsersFactory
					.getSql("HttLoadingService.doBeside");// 修改工序状态为结炉
			PreparedStatement updateSqlPsta = connection
					.prepareStatement(updateSql);
			String updatePln = CoreXmlSqlParsersFactory
					.getSql("HttLoadingService.doPlnBeside");// 修改计划表结炉状态
			PreparedStatement updatePlnPsta = connection
					.prepareStatement(updatePln);

			String AllFailUpdatePlanStatus = CoreXmlSqlParsersFactory
					.getSql("HttLoadingService.updateAllFailStatus");//
			PreparedStatement psAllFailUpdatePlanStatus = connection
					.prepareStatement(AllFailUpdatePlanStatus);

			String UpdateControlEnd = CoreXmlSqlParsersFactory
					.getSql("HeatTreatmentService.UpdateHttControlLog2");//
			PreparedStatement psUpdateControlEnd = connection
					.prepareStatement(UpdateControlEnd);

			PlnZyRclMEntity pln = PlanService.getSendHttPlanCInfo(connection,
					parm.get(0));

			String cutFalg1 = "";
			sql = CoreXmlSqlParsersFactory
					.getSql("HttLoadingService.qureyGxComInfo");// 上一工序没结炉，无法结炉
			psta = connection.prepareStatement(sql);
			psta.setString(1, parm.get(0));
			// psta.setString(2, parm.get(1));
			psta.setObject(2, Integer.parseInt(parm.get(2)) - 1);
			psta.setObject(3, pln.getRealProcessSeq());
			rs = psta.executeQuery();
			if (rs.next()) {
				cutFalg1 = rs.getString("STATION_STATUS");

			} else if ((pln.getIfMatchOdd().equals("2") || pln.getIfMatchOdd()
					.equals("4"))
					&& pln.getBesideStatus().equals("00")) {
				cutFalg1 = "2";
			} else {
				cro.setV_errMsg("上一工序没结炉,不允许结炉!");
				return cro;
			}

			if (cutFalg1.equals("1")) {
				cro.setV_errMsg("上一工序没结炉,不允许结炉!");
				return cro;
			}
			rs.close();
			psta.close();

			String cutFalg2 = "";
			String MaxStation = "";
			sql = CoreXmlSqlParsersFactory
					.getSql("HeatTreatmentService.qureyGxComInfoNew");// 查询工序是否是结炉状态
			psta = connection.prepareStatement(sql);
			psta.setString(1, parm.get(0));
			psta.setObject(2, Integer.parseInt(parm.get(2)));
			psta.setObject(3, Integer.parseInt(parm.get(3)));
			psta.setObject(4, Integer.parseInt(parm.get(4)));
			psta.setObject(5, pln.getRealProcessSeq());
			rs = psta.executeQuery();
			if (rs.next()) {
				cutFalg1 = rs.getString("STATION_STATUS");
				MaxStation = rs.getString("STATION_CODE");
			} else {
				cro.setV_errMsg("无实绩,,无法结炉");
				return cro;
			}

			if (cutFalg1 == null) {
				cro.setV_errMsg("无实绩,,无法结炉");
				return cro;
			}

			if (cutFalg1 != null && cutFalg1.equals("2")) {
				cro.setV_errMsg("该工序已经结炉,无法新增");
				return cro;
			}
			rs.close();
			psta.close();

			int lxCount = 0;
			sql = CoreXmlSqlParsersFactory
					.getSql("AppearanceService.qureyGxLxCount1");// 查询是否离线
			psta = connection.prepareStatement(sql);
			psta.setString(1, parm.get(0));
			// psta.setString(2, parm.get(1));
			psta.setString(2, parm.get(2));
			psta.setString(3, parm.get(3));
			psta.setString(4, parm.get(4));
			rs = psta.executeQuery();
			if (rs.next()) {
				lxCount = Integer.parseInt(rs.getString("COUNT"));
			}
			rs.close();
			psta.close();
			if (lxCount != 0) {
				cro.setV_errMsg("该工序点有离线记录,不允许此操作！");
				return cro;
			}

			// 修改计划结炉状态
			updatePlnPsta.setObject(1, MaxStation.equals(parm.get(2)) ? "10"
					: MaxStation.equals(parm.get(3)) ? "20" : "30");
			updatePlnPsta.setObject(2, parm.get(0));
			updatePlnPsta.addBatch();

			updateSqlPsta.setString(1, parm.get(0));
			// updateSqlPsta.setString(2, parm.get(1));
			updateSqlPsta.setString(2, parm.get(4));
			updateSqlPsta.setString(3, pln.getRealProcessSeq());
			updateSqlPsta.addBatch();

			updateSqlPsta.setString(1, parm.get(0));
			// /\ updateSqlPsta.setString(2, parm.get(1));
			updateSqlPsta.setString(2, parm.get(3));
			updateSqlPsta.setString(3, pln.getRealProcessSeq());
			updateSqlPsta.addBatch();

			updateSqlPsta.setString(1, parm.get(0));
			// updateSqlPsta.setString(2, parm.get(1));
			updateSqlPsta.setString(2, parm.get(2));
			updateSqlPsta.setString(3, pln.getRealProcessSeq());
			updateSqlPsta.addBatch();

			updateSqlPsta.executeBatch();
			updatePlnPsta.executeBatch();

			psAllFailUpdatePlanStatus.setString(1, parm.get(0));
			psAllFailUpdatePlanStatus.addBatch();
			psAllFailUpdatePlanStatus.executeBatch();

			psUpdateControlEnd.setObject(1, "1");
			psUpdateControlEnd.setObject(2, pln.getHeatPlanNo());
			psUpdateControlEnd.addBatch();
			psUpdateControlEnd.executeBatch();

			cro.setV_errMsg("结炉成功！");
			connection.commit();
		} catch (Exception e) {
			System.out.println(e.getMessage());
			if (connection != null) {
				try {
					cro.setV_errMsg(e.getMessage());
					connection.rollback(); // 回滚事务
				} catch (Exception e2) {
				}
			}
		} finally {
			try {
				if (connection != null && !connection.isClosed()) {
					connection.close();
				}
			} catch (Exception e2) {
			}
		}
		return cro;
	}

	/***
	 * 撤销结炉
	 * 
	 * @param zYgNo
	 * @return
	 */
	public CoreReturnObject undoBeside(ArrayList<String> parm) {
		CoreReturnObject cro = new CoreReturnObject();
		Connection connection = this.getDao(CoreConstantData.sysbeanstr)
				.getConnection();
		String sql = "";
		PreparedStatement psta = null;
		ResultSet rs = null;
		try {
			connection.setAutoCommit(false); // 取消自动提交事务
			String updateSql = CoreXmlSqlParsersFactory
					.getSql("HttLoadingService.deleteBeside");// 修改工序状态撤销结炉
			PreparedStatement updateSqlPsta = connection
					.prepareStatement(updateSql);
			String updatePln = CoreXmlSqlParsersFactory
					.getSql("HttLoadingService.doPlnBeside");// 修改计划表结炉状态
			PreparedStatement updatePlnPsta = connection
					.prepareStatement(updatePln);

			String AllFailUpdatePlanStatus = CoreXmlSqlParsersFactory
					.getSql("HttLoadingService.CancelAllFailStatus");
			PreparedStatement psAllFailUpdatePlanStatus = connection
					.prepareStatement(AllFailUpdatePlanStatus);

			String UpdateHttControl = CoreXmlSqlParsersFactory
					.getSql("HeatTreatmentService.UpdateHttControlLog2");
			PreparedStatement psUpdateHttControl = connection
					.prepareStatement(UpdateHttControl);

			// 获取热处理计划实体了
			PlnZyRclMEntity pln = PlanService.getSendHttPlanCInfo(connection,
					parm.get(0));

			if (pln == null) {
				cro.setV_errMsg("无炉计划数据,,不允许此操作！");
				return cro;
			}

			String cutFalg1 = "";
			sql = CoreXmlSqlParsersFactory
					.getSql("HttLoadingService.qureyGxComInfo");// 查询工序是否是结炉状态
			psta = connection.prepareStatement(sql);
			psta.setString(1, parm.get(0));
			// psta.setString(2, parm.get(1));
			psta.setObject(2, Integer.parseInt(parm.get(2)) + 3);
			psta.setObject(3, pln.getRealProcessSeq());
			rs = psta.executeQuery();
			if (rs.next()) {
				cutFalg1 = rs.getString("STATION_STATUS");
			}
			if (cutFalg1.equals("2")) {
				cro.setV_errMsg("下一道工序没有撤销结炉,不允许此工序撤销结炉!");
				return cro;
			}
			rs.close();
			psta.close();

			Boolean HBeside = false;
			Boolean QBeside = false;
			Boolean LBeside = false;

			String cutFalg = "";
			sql = CoreXmlSqlParsersFactory
					.getSql("HttLoadingService.qureyGxComInfo");// 查询工序是否是结炉状态
			psta = connection.prepareStatement(sql);
			psta.setString(1, parm.get(0));
			// psta.setString(2, parm.get(1));
			psta.setString(2, parm.get(2));
			psta.setObject(3, pln.getRealProcessSeq());
			rs = psta.executeQuery();
			if (rs.next()) {
				cutFalg = rs.getString("STATION_STATUS");
				HBeside = true;
			}

			if (cutFalg.equals("1")) {
				cro.setV_errMsg("未结炉,不允许此操作！");
				return cro;
			}
			rs.close();
			psta.close();

			sql = CoreXmlSqlParsersFactory
					.getSql("HttLoadingService.qureyGxComInfo");// 查询工序是否是结炉状态
			psta = connection.prepareStatement(sql);
			psta.setString(1, parm.get(0));
			// psta.setString(2, parm.get(1));
			psta.setString(2, parm.get(3));
			psta.setObject(3, pln.getRealProcessSeq());
			rs = psta.executeQuery();
			if (rs.next()) {
				cutFalg = rs.getString("STATION_STATUS");
				QBeside = true;
			}

			if (cutFalg.equals("1")) {
				cro.setV_errMsg("未结炉,不允许此操作！");
				return cro;
			}
			rs.close();
			psta.close();

			sql = CoreXmlSqlParsersFactory
					.getSql("HttLoadingService.qureyGxComInfo");// 查询工序是否是结炉状态
			psta = connection.prepareStatement(sql);
			psta.setString(1, parm.get(0));
			// psta.setString(2, parm.get(1));
			psta.setString(2, parm.get(4));
			psta.setObject(3, pln.getRealProcessSeq());
			rs = psta.executeQuery();
			if (rs.next()) {
				cutFalg = rs.getString("STATION_STATUS");
				LBeside = true;
			}

			if (cutFalg.equals("1")) {
				cro.setV_errMsg("未结炉,不允许此操作！");
				return cro;
			}
			rs.close();
			psta.close();

			if (!HBeside && !QBeside && !LBeside) {
				cro.setV_errMsg("无实绩,无法进行结炉!");
				return cro;
			}

			updatePlnPsta.setObject(1, "00");
			updatePlnPsta.setObject(2, parm.get(0));
			updatePlnPsta.addBatch();

			updateSqlPsta.setString(1, parm.get(0));
			// updateSqlPsta.setString(2, parm.get(1));
			updateSqlPsta.setString(2, parm.get(2));
			updateSqlPsta.setString(3, pln.getRealProcessSeq());
			updateSqlPsta.addBatch();

			updateSqlPsta.setString(1, parm.get(0));
			// updateSqlPsta.setString(2, parm.get(1));
			updateSqlPsta.setString(2, parm.get(4));
			updateSqlPsta.setString(3, pln.getRealProcessSeq());
			updateSqlPsta.addBatch();

			updateSqlPsta.setString(1, parm.get(0));
			// updateSqlPsta.setString(2, parm.get(1));
			updateSqlPsta.setString(2, parm.get(3));
			updateSqlPsta.setString(3, pln.getRealProcessSeq());
			updateSqlPsta.addBatch();

			updatePlnPsta.executeBatch();
			updateSqlPsta.executeBatch();

			psAllFailUpdatePlanStatus.setString(1, parm.get(0));
			psAllFailUpdatePlanStatus.addBatch();
			psAllFailUpdatePlanStatus.executeBatch();

			psUpdateHttControl.setObject(1, "0");
			psUpdateHttControl.setObject(2, parm.get(0));
			psUpdateHttControl.addBatch();
			psUpdateHttControl.executeBatch();

			cro.setV_errMsg("撤销结炉成功!");
			connection.commit();
		} catch (Exception e) {
			System.out.println(e.getMessage());
			if (connection != null) {
				try {
					cro.setV_errMsg(e.getMessage());
					connection.rollback(); // 回滚事务
				} catch (Exception e2) {
				}
			}
		} finally {
			try {
				if (connection != null && !connection.isClosed()) {
					connection.close();
				}
			} catch (Exception e2) {
			}
		}
		return cro;
	}

	/**
	 * 每支材料对应的入库单号
	 * 
	 * @param conn
	 *            c
	 * @param strlist
	 *            传递参数
	 * @return obj
	 * @throws Exception
	 *             异常处理
	 */
	public String querySendSqlDoc(Connection conn, String strlist, String memo)
			throws Exception {
		String seq = "";
		PreparedStatement psta = null;
		Date dt = new Date();
		SimpleDateFormat matter1 = new SimpleDateFormat("yyyy-MM-dd");
		SimpleDateFormat matter2 = new SimpleDateFormat("yyMMdd");
		String sqlLovsqe = CoreXmlSqlParsersFactory
				.getSql("AppearanceService.getInListDoc");
		psta = conn.prepareStatement(sqlLovsqe);
		psta.setString(1, memo);
		psta.setString(2, matter2.format(dt));
		psta.setString(3, matter1.format(dt));
		psta.setString(4, strlist);
		ResultSet rs = psta.executeQuery();
		if (rs.next()) {
			seq = rs.getString("INSTOCK_DOC");
		}
		rs.close();
		psta.close();
		return seq;
	}

	public CoreReturnObject GetStatus(String IndexSeq, String OrdLnDlyPk,
			String CraftSeq) throws Exception {
		return getDataBySqlID("HeatTreatmentService.GetStatus", new Object[] {
				IndexSeq, OrdLnDlyPk, CraftSeq });
	}

	/**
	 * 每支材料对应的入库流水号
	 * 
	 * @param conn
	 *            c
	 * @param strlist
	 *            传递参数
	 * @return obj
	 * @throws Exception
	 *             异常处理
	 */
	public String querySendSql(Connection conn, String strlist)
			throws Exception {
		String seq = "";
		PreparedStatement psta = null;
		String sqlLovsqe = CoreXmlSqlParsersFactory
				.getSql("AppearanceService.getInListDoc1");
		psta = conn.prepareStatement(sqlLovsqe);
		psta.setString(1, strlist);
		ResultSet rs = psta.executeQuery();
		if (rs.next()) {
			seq = rs.getString("INSTOCK_SQE");
		}
		rs.close();
		psta.close();
		return seq;
	}

	public CoreReturnObject CheckTime(String EntityStr) {
		CoreReturnObject cro = new CoreReturnObject();
		Connection connection = this.getDao(CoreConstantData.sysbeanstr)
				.getConnection();
		String sql = "";
		PreparedStatement psta = null;
		ResultSet rs = null;
		try {
			connection.setAutoCommit(false); // 取消自动提交事务
			SimpleDateFormat dateFormat = new SimpleDateFormat(
					"yyyy-MM-dd HH:mm:ss", Locale.CHINA);
			SimpleDateFormat dateFormat1 = new SimpleDateFormat(
					"yyyy-MM-dd HH:mm", Locale.CHINA);
			SimpleDateFormat matter2 = new SimpleDateFormat("yyyyMMddHHmm");
			SimpleDateFormat matter3 = new SimpleDateFormat("yyyyMMdd");

			HttHheatResultEntity result = EntityTool.getEntityByJSONStr(
					EntityStr, HttHheatResultEntity.class);

			HttControlShiftEntity ShiftEntity = FrmHttControlLog
					.getHttControlByID(connection, result.getPlineCode(),
							result.getColShift());

			if (ShiftEntity == null) {
				return cro;
			}

			Date colDate = result.getHheatEnterTime().length() == 17 ? dateFormat1
					.parse(result.getHheatEnterTime())
					: dateFormat.parse(result.getHheatEnterTime());
			Date endDate = result.getHheatEnterTime().length() == 17 ? dateFormat1
					.parse(result.getHheatOutTime())
					: dateFormat.parse(result.getHheatOutTime());
			Date procDate = colDate;
			if (result.getColShift().equals("3")) {
				Calendar date = Calendar.getInstance();
				date.setTime(colDate);
				date.set(Calendar.HOUR_OF_DAY,
						date.get(Calendar.HOUR_OF_DAY) + 12);
				procDate = dateFormat.parse(dateFormat.format(date.getTime()));
			}

			Date BegDate = matter2.parse(matter3.format(procDate)
					+ ShiftEntity.getShiftBeg());
			Date EndDate = matter2.parse(matter3.format(procDate)
					+ ShiftEntity.getShiftEnd());

			if (BegDate.after(EndDate)) {
				BegDate = new Date(BegDate.getTime() - 24 * 60 * 60 * 1000);
			}

			if (colDate.before(BegDate) || endDate.after(EndDate)) {
				cro.setV_errMsg((result.getColShift().equals("0") ? "白班"
						: result.getColShift().equals("1") ? "早" : result
								.getColShift().equals("2") ? "中" : "晚")
						+ "班上班时间为"
						+ dateFormat1.format(BegDate)
						+ "到"
						+ dateFormat1.format(EndDate)
						+ "\n"
						+ "请确认时间或班次是否维护正确！！ 是否仍要新增实绩?");
				return cro;
			}

			if (colDate.before(BegDate) || endDate.after(EndDate)) {
				cro.setV_errMsg((result.getColShift().equals("0") ? "白班"
						: result.getColShift().equals("1") ? "早" : result
								.getColShift().equals("2") ? "中" : "晚")
						+ "班上班时间为"
						+ dateFormat1.format(BegDate)
						+ "到"
						+ dateFormat1.format(EndDate)
						+ "\n"
						+ "请确认时间或班次是否维护正确！！是否仍要新增实绩?");
				return cro;
			}

			List<HttControlLogEntity> ConficEntity = FrmHttControlLog
					.getConflictHttContorlLog(connection,
							result.getPlineCode(), result.getColShift(),
							matter3.format(procDate), matter2.format(colDate),
							matter2.format(endDate));

			if (ConficEntity.size() > 0) {
				cro.setV_errMsg("炉号"
						+ ConficEntity.get(0).getJudgeStoveNo()
						+ "已维护了炉的时间"
						+ dateFormat1.format(matter2.parse(ConficEntity.get(0)
								.getLogsBeg()))
						+ "到"
						+ dateFormat1.format(matter2.parse(ConficEntity.get(0)
								.getLogsEnd())) + "\n"
						+ "与当前炉号维护的时间冲突！！是否仍要新增实绩?");
				return cro;
			}

			/*
			 * sql =
			 * CoreXmlSqlParsersFactory.getSql("HttLoadingService.qureyGxComInfo"
			 * );//上一工序没结炉，无法结炉 psta = connection.prepareStatement(sql);
			 * psta.setString(1, parm.get(0)); // psta.setString(2,
			 * parm.get(1)); psta.setObject(2, Integer.parseInt(parm.get(2)) -
			 * 1); psta.setObject(3, pln.getRealProcessSeq()); rs =
			 * psta.executeQuery(); if (rs.next()) { cutFalg1 =
			 * rs.getString("STATION_STATUS");
			 * 
			 * } else if ((pln.getIfMatchOdd().equals("2") ||
			 * pln.getIfMatchOdd().equals("4")) &&
			 * pln.getBesideStatus().equals("00")) { cutFalg1 = "2"; } else {
			 * cro.setV_errMsg("上一工序没结炉,不允许结炉!"); return cro; }
			 * 
			 * 
			 * if (cutFalg1.equals("1")) { cro.setV_errMsg("上一工序没结炉,不允许结炉!");
			 * return cro; } rs.close(); psta.close();
			 */

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

	/**
	 * 修改实绩
	 * 
	 * @param resultStr
	 * @return
	 */
	public CoreReturnObject updateHeatTreatmentResult(String resultStr,
			String updateCount) {
		CoreReturnObject core = new CoreReturnObject();
		Connection connection = this.getDao(CoreConstantData.sysbeanstr)
				.getConnection();
		PreparedStatement psta = null;
		ResultSet rs1 = null;
		try {
			connection.setAutoCommit(false); // 取消自动提交事务
			String sqlAdd = CoreXmlSqlParsersFactory
					.getSql("HeatTreatmentService.UpdateHHeatResult");// 修改高温炉实绩
			String sqlAddS = CoreXmlSqlParsersFactory
					.getSql("HeatTreatmentService.UpdateLHeatResult");// 修改低温炉记录

			// 高温炉
			if (updateCount.equals("1")) {
				HttHheatResultEntity result = EntityTool.getEntityByJSONStr(
						resultStr, HttHheatResultEntity.class);
				// 修改高温炉实绩
				sqlAdd = EntityTool.fillSqlByEntity(sqlAdd, result);
				PreparedStatement patAdd = connection.prepareStatement(sqlAdd);
				patAdd.addBatch();
				patAdd.executeBatch();
			} else {
				HttLheatResultEntity result2 = EntityTool.getEntityByJSONStr(
						resultStr, HttLheatResultEntity.class);
				// 修改低温炉实绩
				sqlAddS = EntityTool.fillSqlByEntity(sqlAddS, result2);
				PreparedStatement patAddS = connection
						.prepareStatement(sqlAddS);
				patAddS.addBatch();
				patAddS.executeBatch();
			}
			core.setV_errMsg("修改成功！");
			connection.commit();
		} catch (Exception e) {
			System.out.println(e.getMessage());
			if (connection != null) {
				try {
					core.setV_errMsg("");
					connection.rollback(); // 回滚事务
				} catch (Exception e2) {
				}
			}
		} finally {
			try {
				if (connection != null && !connection.isClosed()) {
					connection.close();
				}
			} catch (Exception e2) {
			}
		}
		return core;
	}

}
