package com.steering.mes.zgmil.coup;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import com.steering.comm.db.DBCommon;

import CoreFS.SA06.CoreReturnObject;
import CoreFS.SA08.CoreXmlSqlParsersFactory;
import CoreFS.SC01.CoreConstantData;
import com.steering.common.EntityTool;
import com.steering.common.StringTool;
import com.steering.mes.signature.MeanValueCalculation;
import com.steering.mes.zgmil.entity.MIL_QA_DEFECT_Entity;
import com.steering.mes.zgmil.entity.MilSizeCheckDeatilEntity;
import com.steering.mes.zgmil.entity.MilSurfaceResultEntity;
import com.steering.mes.zgmil.entity.MilCheckDeatilEntity;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;

import com.steering.mes.zgmil.entity.MilPlanEntity3;

/**
 * 人工质检业务查询
 * 
 * @author Administrator 查询数据
 */
public class SurfaceInspectionResult extends DBCommon {
	/**
	 * 查询质检信息
	 * 
	 * @param MilSurface_Entity
	 * @return
	 */
	public CoreReturnObject getSurface_Ins(
			com.steering.mes.zgmil.entity.MilSurfaceResultEntity MilSurface_Entity) {

		String sql = CoreXmlSqlParsersFactory
				.getSql("SurFace_Insp.SurFaceQuery");
		// sql = EntityTool.fillSqlByEntity(sql, MilSurface_Entity);
		return this.getData(sql,
				new Object[] { MilSurface_Entity.getRollLotNo(),
						MilSurface_Entity.getHeatNo() });
	}

	/***
	 * 查询复检流通卡
	 * 
	 * @param jugeNo
	 * @return
	 */
	public CoreReturnObject doQueryRollCard(String jugeNo, String proPlanId,
			String gxPlanNo) {
		return this.getDataBySqlID("SurFace_Insp.doQueryRollCard",
				new Object[] { jugeNo, proPlanId, gxPlanNo });
	}

	/***
	 * 查询探伤返线流通卡
	 * 
	 * @param jugeNo
	 * @return
	 */
	public CoreReturnObject doQueryRollCardTest(String jugeNo,
			String proPlanId, String gxPlanNo) {
		return this.getDataBySqlID("SurFace_Insp.doQueryRollCardTest",
				new Object[] { jugeNo, proPlanId, gxPlanNo });
	}

	/***
	 * 查询探伤返线流通卡(168)
	 * 
	 * @param jugeNo
	 * @return
	 */
	public CoreReturnObject getRollCard168Test(String jugeNo, String proPlanId,
			String gxPlanNo) {
		return this.getDataBySqlID("SurFace_Insp.getRollCard168Test",
				new Object[] { jugeNo, proPlanId, gxPlanNo });
	}

	/***
	 * 查询探伤返线流通卡(超声)
	 * 
	 * @param jugeNo
	 * @return
	 */
	public CoreReturnObject getRollingCardTest(String jugeNo, String proPlanId,
			String gxPlanNo) {
		return this.getDataBySqlID("SurFace_Insp.getRollingCardTest",
				new Object[] { jugeNo, proPlanId, gxPlanNo });
	}

	/**
	 * 查询质检信息
	 * 
	 * @param MilSurface_Entity
	 * @return
	 */
	public CoreReturnObject GetQAResult(String JudgeStoveNo, String ResultNo,
			String proPlanId, String gxPlanNo) {
		String sql = CoreXmlSqlParsersFactory
				.getSql("SurFace_Insp.GetQAResult");
		return this.getData(sql, new Object[] { JudgeStoveNo, ResultNo,
				proPlanId, gxPlanNo });
	}

	public CoreReturnObject getMilPlan(String JudgeStoveNo, String ResultNo,
			String proPlanId, String gxPlanNo) {
		return this.getDataBySqlID("SurFace_Insp.getMilPlan", new Object[] {
				JudgeStoveNo, ResultNo, proPlanId, gxPlanNo });
	}

	/**
	 * 是否跟队（天淮）
	 * @param jugeNo
	 * @param plineCode
	 * @return
	 */
	public CoreReturnObject getIsAgain(String jugeNo, String plineCode) {
		return this.getDataBySqlID("SurFace_Insp.getIsAgain",
				new Object[] { jugeNo, plineCode });
	}
	/**
	 * 开始质检 - 添加开始质检时间
	 * 
	 * @param 加热炉实绩实体类
	 * @return CoreReturnObject
	 */
	public CoreReturnObject startInSurFace(
			com.steering.mes.zgmil.entity.MilSurfaceResultEntity MilSurface_Entity,
			com.steering.mes.zgmil.entity.MilPlan milplan_E, String sizeFlag) {
		ArrayList<String> sqllist = new ArrayList<String>();
		String sql = CoreXmlSqlParsersFactory
				.getSql("SurFace_Insp.ADD_SurFaceQuery");
		String sql_1 = CoreXmlSqlParsersFactory
				.getSql("SurFace_Insp.Upd_SurFaceQuery_1");
		sql = EntityTool.fillSqlByEntity(sql, MilSurface_Entity);
		sql = sql.replace("#SIZE_CHECK#", sizeFlag);
		sql_1 = EntityTool.fillSqlByEntity(sql_1, milplan_E);
		sqllist.add(sql);
		sqllist.add(sql_1);
		return this.getDao(CoreConstantData.sysbeanstr).ExcuteTransction(
				sqllist);
	}

	/**
	 * 质检信息保存
	 * 
	 * @param MilSurface_Entity
	 * @return
	 */
	public CoreReturnObject Save_SurFace(
			com.steering.mes.zgmil.entity.MilSurfaceResultEntity MilSurface_Entity) {
		String sql = CoreXmlSqlParsersFactory
				.getSql("SurFace_Insp.Upd_SurFaceQuery");
		sql = EntityTool.fillSqlByEntity(sql, MilSurface_Entity);
		return this.setData(sql);
	}

	/**
	 * 结炉操作
	 * 
	 * @param MilSurface_Entity
	 *            结炉实绩实体类
	 * @return CoreReturnObject
	 * @throws SQLException
	 */
	public CoreReturnObject FeedSawResultNode(
			com.steering.mes.zgmil.entity.MilPlan enMilPlan,
			com.steering.mes.zgmil.entity.MilSurfaceResultEntity MilSurface_Entity)
			throws SQLException {
		ArrayList<String> sqllist = new ArrayList<String>();
		Connection con = null;
		ArrayList<String> matNoList = null;
		PreparedStatement psta = null;
		ResultSet rs = null;

		String sql1 = CoreXmlSqlParsersFactory
				.getSql("SurFace_Insp.Upd_Node_SurFaceQuery");
		String sql = CoreXmlSqlParsersFactory
				.getSql("SurFace_Insp.Node_SurFaceQuery");
		String sql2 = CoreXmlSqlParsersFactory
				.getSql("SurFace_Insp.updateGroup");
		// String sql3 =
		// CoreXmlSqlParsersFactory.getSql("SurFace_Insp.updatePortSample");//表检结炉时写黄尼玛那边的表
		// 更新进程表mil_processes数据
		String updateProcess = CoreXmlSqlParsersFactory
				.getSql("FrmInOnlineStore.insertMilProcess2");
		sql1 = EntityTool.fillSqlByEntity(sql1, enMilPlan);
		sql = EntityTool.fillSqlByEntity(sql, MilSurface_Entity);
		sql2 = EntityTool.fillSqlByEntity(sql2, MilSurface_Entity);
		// sql3 = EntityTool.fillSqlByEntity(sql3, MilSurface_Entity);
		updateProcess = EntityTool.fillSqlByEntity(updateProcess, enMilPlan);
		sqllist.add(sql1);
		sqllist.add(sql);
		sqllist.add(sql2);
		// sqllist.add(sql3);
		sqllist.add(updateProcess);
		return this.getDao(CoreConstantData.sysbeanstr).ExcuteTransction(
				sqllist);
	}

	/**
	 * 结炉实绩查询
	 * 
	 * @return
	 */
	public CoreReturnObject SurfaceResult_query(String str_PliceCode,
			String str_Shift, String str_Group, String str_StartTime,
			String str_EndTime) {
		return this.getDataBySqlID("SurFace_Insp.SurfaceResult_query",
				new Object[] { str_PliceCode, str_Shift, str_Group,
						str_StartTime, str_EndTime });
	}

	/**
	 * 查询质检上料管号队列表
	 * 
	 * @return
	 */
	public CoreReturnObject getSurfaceRackSeq(String str_JudgeStove_No,
			String OffLineFlag) {
		// if(OffLineFlag.equals("1"))
		// {
		// return this.getDataBySqlID("SurFace_Insp.getSurfaceRackSeq",
		// new Object[] { str_JudgeStove_No });
		// }
		// else
		// {
		return this.getDataBySqlID("SurFace_Insp.getSurfaceRackSeq",
				new Object[] { str_JudgeStove_No });
		// }
	}

	/**
	 * 质检执行操作
	 * 
	 * @param MilSurface_Entity
	 *            结炉实绩实体类
	 * @return CoreReturnObject
	 */
	public CoreReturnObject AddMIL_QA_DEFECT(
			ArrayList<MilCheckDeatilEntity> L_strchk,
			ArrayList<MilSizeCheckDeatilEntity> L_MilSizeCheckDeatilEntity,
			MilSurfaceResultEntity enMilSurfaceResultEntity) {
		ArrayList<String> sqllist = new ArrayList<String>();
		String sql1 = CoreXmlSqlParsersFactory
				.getSql("SurFace_Insp.DelMIL_CHECK_DEATIL");// 删除原来的缺陷项记录
		String sql2 = CoreXmlSqlParsersFactory
				.getSql("SurFace_Insp.Upd_MIL_SURFACE_RESULT_ChkRate");// 更新原来的抽检率
		String sql3 = CoreXmlSqlParsersFactory
				.getSql("SurFace_Insp.DelMilSizeCheckDeatilEntity");// 删除原来的管号记录
		sql1 = EntityTool.fillSqlByEntity(sql1, L_strchk.get(0));
		sql2 = EntityTool.fillSqlByEntity(sql2, enMilSurfaceResultEntity);
		sql3 = EntityTool.fillSqlByEntity(sql3, L_MilSizeCheckDeatilEntity
				.get(0));
		sqllist.add(sql1);
		sqllist.add(sql2);
		sqllist.add(sql3);
		for (int i = 0; i < L_strchk.size(); i++) {

			String sql4 = CoreXmlSqlParsersFactory
					.getSql("SurFace_Insp.InsMIL_QA_DEFECT");
			MilCheckDeatilEntity DEFECT = (MilCheckDeatilEntity) L_strchk
					.get(i);
			sql4 = EntityTool.fillSqlByEntity(sql4, DEFECT);
			sqllist.add(sql4);
		}
		for (int i = 0; i < L_MilSizeCheckDeatilEntity.size(); i++) {
			sql3 = CoreXmlSqlParsersFactory
					.getSql("SurFace_Insp.AddMilSizeCheckDeatilEntity");
			MilSizeCheckDeatilEntity en_MilSizeCheckDeatil = (MilSizeCheckDeatilEntity) L_MilSizeCheckDeatilEntity
					.get(i);
			sql3 = EntityTool.fillSqlByEntity(sql3, en_MilSizeCheckDeatil);
			sqllist.add(sql3);
		}
		return this.getDao(CoreConstantData.sysbeanstr).ExcuteTransction(
				sqllist);
	}

	/**
	 * 查询质检上料管号队列表
	 * 
	 * @return
	 */
	public CoreReturnObject getDefect(String strJudgeStoveNo) {
		return this.getDataBySqlID("SurFace_Insp.getDefect",
				new Object[] { strJudgeStoveNo });
	}

	/**
	 * 修改质检结果
	 * 
	 * @param MilSurface_Entity
	 * @return
	 */
	public CoreReturnObject UpdMIL_QA_DEFECT(
			MIL_QA_DEFECT_Entity MilQaDefect_Entity) {
		String sql = CoreXmlSqlParsersFactory
				.getSql("SurFace_Insp.UpdMIL_QA_DEFECT");
		sql = EntityTool.fillSqlByEntity(sql, MilQaDefect_Entity);
		return this.setData(sql);
	}

	/**
	 * 查询质检上料管号队列表
	 * 
	 * @return
	 */
	public CoreReturnObject getDefect_by_MIL_QA_DEFECT(
			MIL_QA_DEFECT_Entity MilQaDefect_Entity) {
		String sql = CoreXmlSqlParsersFactory
				.getSql("SurFace_Insp.getDefect_by_MIL_QA_DEFECT");
		sql = EntityTool.fillSqlByEntity(sql, MilQaDefect_Entity);
		return this.getData(sql);
	}

	/**
	 * 抽检统计
	 * 
	 * @return
	 */
	public CoreReturnObject getDefect_statistics(String strJUDGE_STOVE_NO) {
		String sql = CoreXmlSqlParsersFactory
				.getSql("SurFace_Insp.getDefect_statistics");
		return this.getData(sql, new Object[] { strJUDGE_STOVE_NO });
	}

	/**
	 * 几何尺寸抽查记录
	 * 
	 * @return
	 */
	public CoreReturnObject getMIL_SIZE_CHECK_DEATIL(
			MilSizeCheckDeatilEntity en_MilSizeCheckDeatilEntity) {
		String sql = CoreXmlSqlParsersFactory
				.getSql("SurFace_Insp.getMIL_SIZE_CHECK_DEATIL");
		sql = EntityTool.fillSqlByEntity(sql, en_MilSizeCheckDeatilEntity);
		return this.getData(sql);
	}

	/**
	 * 质检执行操作
	 * 
	 * @param MilSurface_Entity
	 *            结炉实绩实体类
	 * @return CoreReturnObject
	 */
	public CoreReturnObject Upd_MIL_SIZE_CHECK_DEATIL(
			ArrayList<MilSizeCheckDeatilEntity> L_strchk) {
		ArrayList<String> sqllist = new ArrayList<String>();
		for (int i = 0; i < L_strchk.size(); i++) {
			String sql = CoreXmlSqlParsersFactory
					.getSql("SurFace_Insp.Upd_MIL_SIZE_CHECK_DEATIL");
			MilSizeCheckDeatilEntity DEFECT = (MilSizeCheckDeatilEntity) L_strchk
					.get(i);
			sql = EntityTool.fillSqlByEntity(sql, DEFECT);
			sqllist.add(sql);
		}
		return this.getDao(CoreConstantData.sysbeanstr).ExcuteTransction(
				sqllist);
	}

	/**
	 * 几何尺寸抽查记录
	 * 
	 * @return
	 */
	public CoreReturnObject get_Chk_Active(String strJUDGE_STOVE_NO) {
		String sql = CoreXmlSqlParsersFactory
				.getSql("SurFace_Insp.get_Chk_Active");
		return this.getData(sql, new Object[] { strJUDGE_STOVE_NO });
	}

	/**
	 * 删除质检缺陷项表相应炉号记录
	 * 
	 * @return
	 */
	public CoreReturnObject DelMIL_QA_DEFECT(String strJUDGE_STOVE_NO) {
		String sql = CoreXmlSqlParsersFactory
				.getSql("SurFace_Insp.DelMIL_QA_DEFECT");
		return this.setData(sql, new Object[] { strJUDGE_STOVE_NO });
	}

	/**
	 * 保存抽检率到质检表MIL_SURFACE_RESULT
	 * 
	 * @return
	 */
	public CoreReturnObject Upd_MIL_SURFACE_RESULT_ChkRate(
			String strSIMPLE_RATE, String strJUDGE_STOVE_NO) {
		String sql = CoreXmlSqlParsersFactory
				.getSql("SurFace_Insp.Upd_MIL_SURFACE_RESULT_ChkRate");
		return this.setData(sql, new Object[] { strSIMPLE_RATE,
				strJUDGE_STOVE_NO });
	}

	/**
	 * 更新质检合格支MIL_SURFACE_RESULT
	 * 
	 * @return
	 */
	public CoreReturnObject update_SurFace_QUALIFIED_BRANCH(
			String strQUALIFIED_BRANCH, String strJUDGE_STOVE_NO) {
		String sql = CoreXmlSqlParsersFactory
				.getSql("SurFace_Insp.update_SurFace_QUALIFIED_BRANCH");
		return this.setData(sql, new Object[] { strQUALIFIED_BRANCH,
				strJUDGE_STOVE_NO });
	}

	/**
	 * 查询抽检项
	 * 
	 * @return
	 */
	public CoreReturnObject getMIL_CHECK_DEATIL(String strJUDGE_STOVE_NO) {
		String sql = CoreXmlSqlParsersFactory
				.getSql("SurFace_Insp.getMIL_CHECK_DEATIL");
		return this.getData(sql, new Object[] { strJUDGE_STOVE_NO });
	}

	/*
	 * 缺陷项保存
	 */
	public CoreReturnObject SaveMIL_CHECK_DEATIL(
			ArrayList<MilCheckDeatilEntity> L_strchk) {
		ArrayList<String> sqllist = new ArrayList<String>();
		for (int i = 0; i < L_strchk.size(); i++) {
			String sql = CoreXmlSqlParsersFactory
					.getSql("SurFace_Insp.SaveMIL_CHECK_DEATIL");
			MilCheckDeatilEntity DEFECT = (MilCheckDeatilEntity) L_strchk
					.get(i);
			sql = EntityTool.fillSqlByEntity(sql, DEFECT);
			sqllist.add(sql);
		}
		return this.getDao(CoreConstantData.sysbeanstr).ExcuteTransction(
				sqllist);
	}

	/**
	 *查询MT总检量
	 * 
	 * @return
	 */
	public CoreReturnObject getMIL_MT_RESULT(String strJUDGE_STOVE_NO) {
		String sql = CoreXmlSqlParsersFactory
				.getSql("SurFace_Insp.getMIL_MT_RESULT");
		return this.getData(sql, new Object[] { strJUDGE_STOVE_NO });
	}

	/**
	 *查询ET总检量
	 * 
	 * @return
	 */
	public CoreReturnObject getMIL_ET_RESULT(String strJUDGE_STOVE_NO) {
		String sql = CoreXmlSqlParsersFactory
				.getSql("SurFace_Insp.getMIL_ET_RESULT");
		return this.getData(sql, new Object[] { strJUDGE_STOVE_NO });
	}

	/**
	 * 统计废品量
	 * 
	 * @return
	 */
	public CoreReturnObject getMIL_CHECK_DEATIL_Statictis(
			String strJUDGE_STOVE_NO) {
		String sql = CoreXmlSqlParsersFactory
				.getSql("SurFace_Insp.getMIL_CHECK_DEATIL_Statictis");
		return this.getData(sql, new Object[] { strJUDGE_STOVE_NO });
	}

	/**
	 * 查询缺陷项信息
	 * 
	 * @return
	 */
	public CoreReturnObject getMIL_BASE_DEFECT_ITEM() {
		String sql = CoreXmlSqlParsersFactory
				.getSql("SurFace_Insp.getMIL_BASE_DEFECT_ITEM");
		return this.getData(sql);
	}

	/**
	 * 添加缺陷项
	 * 
	 * @return
	 */
	public CoreReturnObject AddMIL_BASE_DEFECT_ITEM(String strCode,
			String strName, String strLever, String strPLINE_CODE) {
		String sql = CoreXmlSqlParsersFactory
				.getSql("SurFace_Insp.AddMIL_BASE_DEFECT_ITEM");
		return this.setData(sql, new Object[] { strCode, strName, strLever,
				strPLINE_CODE });
	}

	/**
	 * 更新缺陷项
	 * 
	 * @return
	 */
	public CoreReturnObject UpdMIL_BASE_DEFECT_ITEM(String newCode,
			String strName, String strLever, String strPLINE_CODE,
			String oldstrCode) {
		String sql = CoreXmlSqlParsersFactory
				.getSql("SurFace_Insp.UpdMIL_BASE_DEFECT_ITEM");
		return this.setData(sql, new Object[] { newCode, strName, strLever,
				strPLINE_CODE, oldstrCode });
	}

	/**
	 * 删除缺陷项
	 * 
	 * @return
	 */
	public CoreReturnObject DelMIL_BASE_DEFECT_ITEM(String strCode) {
		String sql = CoreXmlSqlParsersFactory
				.getSql("SurFace_Insp.DelMIL_BASE_DEFECT_ITEM");
		return this.setData(sql, new Object[] { strCode });
	}

	/**
	 * 查询质检员信息
	 * 
	 * @return
	 */
	public CoreReturnObject getMIL_BASE_INSPECTOR() {
		String sql = CoreXmlSqlParsersFactory
				.getSql("SurFace_Insp.getMIL_BASE_INSPECTOR");
		return this.getData(sql);
	}

	/**
	 * 添加质检员信息
	 * 
	 * @return
	 */
	public CoreReturnObject AddMIL_BASE_INSPECTOR(String strCode,
			String strName, String strShift, String strGroup, String strPlanCode) {
		String sql = CoreXmlSqlParsersFactory
				.getSql("SurFace_Insp.AddMIL_BASE_INSPECTOR");
		return this.setData(sql, new Object[] { strCode, strName, strShift,
				strGroup, strPlanCode });
	}

	/**
	 * 更新质检员信息
	 * 
	 * @return
	 */
	public CoreReturnObject UpdMIL_BASE_INSPECTOR(String strNewCode,
			String strName, String strShift, String strGroup,
			String strPlanCode, String strCode) {
		String sql = CoreXmlSqlParsersFactory
				.getSql("SurFace_Insp.UpdMIL_BASE_INSPECTOR");
		return this.setData(sql, new Object[] { strNewCode, strName, strShift,
				strGroup, strPlanCode, strCode });
	}

	/**
	 * 删除质检员信息
	 * 
	 * @return
	 */
	public CoreReturnObject DelMIL_BASE_INSPECTOR(String strCode) {
		String sql = CoreXmlSqlParsersFactory
				.getSql("SurFace_Insp.DelMIL_BASE_INSPECTOR");
		return this.setData(sql, new Object[] { strCode });
	}

	/**
	 * 查询常用缺陷项
	 * 
	 * @return
	 */
	public CoreReturnObject getdtDefectComb() {
		return this
				.getData("select * from mil_base_defect_item t where DEFECT_LEVEL='0'");
	}

	/**
	 * 查询不常用缺陷项
	 * 
	 * @return
	 */
	public CoreReturnObject getdtCombGenerel() {
		return this
				.getData("select * from mil_base_defect_item t where DEFECT_LEVEL='1'");
	}

	/**
	 * 缺陷项查询
	 * 
	 * @return
	 */
	public CoreReturnObject defectItemQuery(String ItemLevel, String ItemName) {
		return this.getDataBySqlID("SurFace_Insp.checkedDefectItemQuery",
				new Object[] { ItemLevel, ItemName });
	}

	/**
	 * 已抽检的缺陷项查询
	 * 
	 * @return
	 */
	public CoreReturnObject checkedDefectItemQuery(String JudgeStoveNo,
			String ResultNo, Integer Flag) {
		return this.getDataBySqlID("SurFace_Insp.ItemQuery", new Object[] {
				JudgeStoveNo, ResultNo });
	}

	/**
	 * 几何尺寸抽检管查询
	 * 
	 * @return
	 */
	public CoreReturnObject sizeCheckQuery(String JudgeStoveNo,
			String ResultNo, String proPlanId, String gxPlanNo) {
		return this.getDataBySqlID("SurFace_Insp.SizeCheckQuery", new Object[] {
				JudgeStoveNo, proPlanId, gxPlanNo });
	}

	/**
	 * 是否抽检
	 * 
	 * @return
	 */
	public CoreReturnObject GetZLXS(String JudgeStoveNo, String ResultNo) {
		return this.getDataBySqlID("SurFace_Insp.ZLXSQuery", new Object[] {
				JudgeStoveNo, ResultNo });
	}

	/**
	 * 查询管号队列
	 * 
	 * @return
	 */
	public CoreReturnObject checkMatNoQuery(String JudgeStoveNo,
			String ResultNo, String proPlanId, String gxPlanNo) {
		return this.getDataBySqlID("SurFace_Insp.checkMatNoQuery",
				new Object[] { JudgeStoveNo, ResultNo, proPlanId, gxPlanNo });
	}

	/**
	 * 成品管缺陷项查询
	 * 
	 * @return
	 */
	public CoreReturnObject pipeDefectQuery(String JudgeStoveNo,
			String ResultNo, String Seq, String Flag) {
		return this.getDataBySqlID("SurFace_Insp.PipeDefectQuery",
				new Object[] { JudgeStoveNo, ResultNo, Seq, Flag });
	}

	/**
	 * 几何尺寸抽检管插入
	 * 
	 * @return CJNum 抽检支数
	 */
	public CoreReturnObject inserSizeCheck(String JudgeStoveNo, Integer CJNum,
			Double CJParama) {
		CoreReturnObject cro = new CoreReturnObject();
		Connection conn = null;
		PreparedStatement psta = null;
		PreparedStatement psta1 = null;
		try {
			conn = this.getDao("TgDao").getConnection();
			conn.setAutoCommit(false);
			ResultSet rs = null;
			String sql = "select seq,mat_no from MIL_QA_RACK where JUDGE_STOVE_NO = '"
					+ JudgeStoveNo
					+ "' and  rownum<="
					+ CJNum
					+ " order by seq ";
			psta = conn.prepareStatement(sql);
			rs = psta.executeQuery();

			while (rs.next()) {
				int Seq = rs.getInt(1);
				String Mat_no = rs.getString(2);
				sql = "insert into MIL_SIZE_CHECK_DEATIL (JUDGE_STOVE_NO,SAMPLE_PIPE_SEQ,SAMPLE_PIPE_NO) values ('"
						+ JudgeStoveNo + "'," + Seq + ",'" + Mat_no + "')";
				psta1 = conn.prepareStatement(sql);
				psta1.executeUpdate();
				psta1.close();
			}
			// 修改实绩表抽检率
			sql = "UPDATE MIL_SURFACE_RESULT SET  SIMPLE_RATE = " + CJParama
					+ "  ";
			psta1 = conn.prepareStatement(sql);
			psta1.executeUpdate();
			psta.close();
			psta1.close();
			rs.close();
			conn.commit();
			conn.close();
		} catch (SQLException sqle) {
			sqle.printStackTrace();
			try {
				conn.rollback();
			} catch (SQLException e) {
				e.printStackTrace();
			}
		} finally {
			try {
				if (conn != null && !conn.isClosed()) {
					conn.close();
				}
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		cro.setResult(0);
		return cro;
	}

	/**
	 * 几何尺寸插入
	 * 
	 * @return
	 * */
	public CoreReturnObject insertMatSize(ArrayList ListCehckSize,
			String JudgeStoveNo, String ResultNo, String proPlanId,
			String gxPlanNo) {
		ArrayList<String> sqllist = new ArrayList<String>();
		String sql = "";
		String sql1 = "delete from mil_size_check_deatil where Judge_Stove_No = '"
				+ JudgeStoveNo
				+ "' and RESULT_NO = '"
				+ ResultNo
				+ "' AND NVL(PRO_PLAN_ID,'/') = NVL('"
				+ proPlanId
				+ "','/') AND NVL(GX_PLAN_NO,'/') = NVL('"
				+ gxPlanNo
				+ "','/')";
		sqllist.add(sql1);
		for (int i = 0; i < ListCehckSize.size(); i++) {
			sql = CoreXmlSqlParsersFactory
					.getSql("SurFace_Insp.Upd_MIL_SIZE_CHECK_DEATIL");
			sql = EntityTool.fillSqlByEntity(sql, ListCehckSize.get(i));
			sqllist.add(sql);
		}
		String sql2 = "update MIL_SURFACE_RESULT set  SIZE_CHECK = '1' where Judge_Stove_No = '"
				+ JudgeStoveNo
				+ "' and  RESULT_NO = '"
				+ ResultNo
				+ "' AND NVL(PRO_PLAN_ID,'/') = NVL('"
				+ proPlanId
				+ "','/') AND NVL(GX_PLAN_NO,'/') = NVL('"
				+ gxPlanNo
				+ "','/')";
		sqllist.add(sql2);
		return this.getDao(CoreConstantData.sysbeanstr).ExcuteTransction(
				sqllist);

	}

	/**
	 * 几何尺寸抽检管数据填充
	 * 
	 * @return CJNum 抽检支数
	 */
	public CoreReturnObject fillSizeCheck(String JudgeStoveNo, Integer CJNum) {
		CoreReturnObject cro = new CoreReturnObject();
		Connection conn = null;
		PreparedStatement psta = null;
		PreparedStatement psta1 = null;
		try {
			int i = 1;
			conn = this.getDao("TgDao").getConnection();
			conn.setAutoCommit(false);
			ResultSet rs = null;
			String sql = " SELECT   D1, D2,  S1, S2, S3, S4,LOCATION, SAMPLE_PIPE_SEQ FROM MIL_SIZE_CHECK_DEATIL";
			sql += " WHERE JUDGE_STOVE_NO = (select distinct(JUDGE_STOVE_NO) from MIL_SIZE_CHECK_DEATIL where COL_TIME = (SELECT distinct( MAX(COL_TIME)) from MIL_SIZE_CHECK_DEATIL )) order by SAMPLE_PIPE_SEQ";
			psta = conn.prepareStatement(sql);
			rs = psta.executeQuery();
			while (rs.next()) {
				double D1 = rs.getDouble(1);
				double D2 = rs.getDouble(2);
				double D3 = rs.getDouble(3);
				double D4 = rs.getDouble(4);
				double D5 = rs.getDouble(5);
				double D6 = rs.getDouble(6);
				String Location = rs.getString(7);
				int Seq = rs.getInt(8);
				String sql1 = "update MIL_SIZE_CHECK_DEATIL set D1 = " + D1
						+ ",D2 = " + D2 + ",D2 = " + D2 + ",D3 = " + D3
						+ ",D4 = " + D4 + ",D5 = " + D5 + ",D6=" + D6
						+ ", LOCATION = '" + Location + "' ";
				sql1 += " where SAMPLE_PIPE_SEQ = " + Seq + "";
				psta1 = conn.prepareStatement(sql1);
				psta1.executeUpdate();
				psta1.close();
				i++;
				if (i == CJNum) {
					break;
				}
			}
		} catch (SQLException sqle) {
			sqle.printStackTrace();
			try {
				conn.rollback();
			} catch (SQLException e) {
				e.printStackTrace();
			}
		} finally {
			try {
				if (conn != null && !conn.isClosed()) {
					conn.close();
				}
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		cro.setResult(0);
		return cro;
	}

	/**
	 * 缺陷项数据插入
	 * 
	 * @return
	 */
	public CoreReturnObject insertDefectData(ArrayList ListEntity,
			String JudgeStoveNo, String ResultNo, Integer Flag) {
		ArrayList<String> sqllist = new ArrayList<String>();
		String sql1 = " DELETE MIL_CHECK_DEATIL WHERE JUDGE_STOVE_NO='"
				+ JudgeStoveNo + "' and RESULT_NO= '" + ResultNo
				+ "' and FLAG = '" + Flag + "'";
		sqllist.add(sql1);
		String sql = "";
		for (int i = 0; i < ListEntity.size(); i++) {
			sql = CoreXmlSqlParsersFactory
					.getSql("SurFace_Insp.InsertDefectData");
			sql = EntityTool.fillSqlByEntity(sql, ListEntity.get(i));
			sqllist.add(sql);
		}
		return this.getDao(CoreConstantData.sysbeanstr).ExcuteTransction(
				sqllist);
	}

	/**
	 * 缺陷管数据删除 1- 删除表MIL_QA_DEFECT 中 对应炉号的数据 2- 修改表 MIL_QA_RACK 中 状态为 最终下线
	 * 和剔除的管为正常轧制 3- 删除管号剔除表MIL_SLAB_SCRAP表中对应炉次数据
	 * 
	 * @return
	 */
	public CoreReturnObject deleteDefectMat(String JudgeStoveNo,
			String ResultNo, Integer Flag) {
		ArrayList<String> sqllist = new ArrayList<String>();
		String sql = "DELETE MIL_QA_DEFECT WHERE JUDGE_STOVE_NO = '"
				+ JudgeStoveNo + "' AND RESULT_NO = '" + ResultNo
				+ "' and FLAG = '" + Flag + "' ";
		String sql1 = "";
		String sql2 = "";
		if (Flag == 1) {
			sql1 = "update  MIL_QA_RACK set OFFLINE_FLAG_F = '0' ,STATUS = '0' WHERE JUDGE_STOVE_NO = '"
					+ JudgeStoveNo
					+ "'  AND RESULT_NO = '"
					+ ResultNo
					+ "' AND OFFLINE_FLAG_F in ('1','2')  ";
			sql2 = "DELETE MIL_SLAB_SCRAP WHERE JUDGE_STOVE_NO = '"
					+ JudgeStoveNo
					+ "' AND PROCESS_NO = '11'  AND RESULT_NO = '" + ResultNo
					+ "'  ";
		} else {
			sql1 = "update  MIL_QA_RACK set OFFLINE_FLAG_S = '0' ,STATUS = '0' WHERE JUDGE_STOVE_NO = '"
					+ JudgeStoveNo
					+ "'  AND RESULT_NO = '"
					+ ResultNo
					+ "' AND OFFLINE_FLAG_S in ('1','2')  ";
			sql2 = "DELETE MIL_SLAB_SCRAP WHERE JUDGE_STOVE_NO = '"
					+ JudgeStoveNo
					+ "' AND PROCESS_NO = '12'  AND RESULT_NO = '" + ResultNo
					+ "'  ";
		}

		sqllist.add(sql);
		sqllist.add(sql1);
		sqllist.add(sql2);
		return this.getDao(CoreConstantData.sysbeanstr).ExcuteTransction(
				sqllist);
	}

	/**
	 * 缺陷管数据插入 1-根据总下线支废品支插入表 2-修改QA_RACK 管号队列状态 下线 废品 3-插入MIL_SLAB_SCRAP 剔除管号数据
	 * 
	 * @return
	 */
	public CoreReturnObject insertDefectMat(String JudgeStoveNo,
			String ResultNo, Integer ScrapRanSeq, Integer ScrapNum,
			Integer OffLineNum, String ColUser, String ColShift,
			String ColGroup, Integer Flag) {
		CoreReturnObject cro = new CoreReturnObject();
		Connection conn = null;
		PreparedStatement psta = null;
		PreparedStatement psta1 = null;
		PreparedStatement psta2 = null;
		int result = 1;
		try {

			String Mat_No = "";
			int Seq = 0;
			int OffLineSeq = ScrapRanSeq + ScrapNum;
			conn = this.getDao("TgDao").getConnection();
			conn.setAutoCommit(false);
			ResultSet rs = null;
			ResultSet rs1 = null;
			// 查询缺陷剔除的管号
			String Sql = "";
			if (Flag.equals(2)) {

				String Sql1 = "update mil_qa_rack set status = '1' where OFFLINE_FLAG_F = '1' ";
				psta1 = conn.prepareStatement(Sql1);
				int count1 = psta1.executeUpdate();
				psta1.close();

			}
			// 一次抽检
			if (Flag.equals(1)) {
				Sql = "select SEQ,MAT_NO from MIL_QA_RACK where JUDGE_STOVE_NO = '"
						+ JudgeStoveNo
						+ "' and  RESULT_NO = '"
						+ ResultNo
						+ "' and SEQ in( ";
				Sql += "select seq from (select seq, rownum rn from mil_qa_rack where JUDGE_STOVE_NO = '"
						+ JudgeStoveNo
						+ "' and  RESULT_NO = '"
						+ ResultNo
						+ "' and offline_flag = 0  ) where rn  between "
						+ ScrapRanSeq
						+ "  and  "
						+ (ScrapRanSeq + ScrapNum - 1) + ")";
				psta = conn.prepareStatement(Sql);
				rs = psta.executeQuery();
				while (rs.next()) {
					Seq = rs.getInt(1);
					Mat_No = rs.getString(2);
					// 修改管号为剔除状态
					String Sql1 = "";
					Sql1 = "Update MIL_QA_RACK set OFFLINE_FLAG_F =  '2' ,status = '1' where JUDGE_STOVE_NO = '"
							+ JudgeStoveNo
							+ "' and  RESULT_NO = '"
							+ ResultNo
							+ "' and Seq = " + Seq + "";
					psta1 = conn.prepareStatement(Sql1);
					int count = psta1.executeUpdate();
					psta1.close();

					// 插入表MIL_SLAB_SCRAP
					Sql1 = " INSERT INTO MIL_SLAB_SCRAP(JUDGE_STOVE_NO, RESULT_NO,SEQ,PROCESS_NO, MAT_NO,SCRAP_USER,TIME,SCRAP_SHIFT, SCRAP_GROUP,FLAG,HANDLE_RESULT) ";
					Sql1 += " VALUES( '" + JudgeStoveNo + "', '" + ResultNo
							+ "', " + Seq + ", '11',  '" + Mat_No + "', '"
							+ ColUser + "', SYSDATE,  '" + ColShift + "', '"
							+ ColGroup + "',1,'500201')";
					psta1 = conn.prepareStatement(Sql1);
					count = psta1.executeUpdate();
					psta1.close();

					// 添加管号到表MIL_QA_DEFECT
					Sql1 = "Insert into MIL_QA_DEFECT (JUDGE_STOVE_NO,RESULT_NO,SAMPLE_PIPE_SEQ,SAMPLE_PIPE_NO,FLAG) values('"
							+ JudgeStoveNo
							+ "','"
							+ ResultNo
							+ "',"
							+ Seq
							+ ",'" + Mat_No + "'," + Flag + ")";
					psta1 = conn.prepareStatement(Sql1);
					int count1 = psta1.executeUpdate();
					psta1.close();
					ScrapRanSeq++;
				}
				rs.close();
				psta.close();
			}
			// 二次抽检
			else {
				int i = 1; // 用于计算操作的剔除支数
				Sql = "select SEQ,MAT_NO from MIL_QA_RACK where JUDGE_STOVE_NO = '"
						+ JudgeStoveNo
						+ "' and  RESULT_NO = '"
						+ ResultNo
						+ "' and SEQ ";
				Sql += "  in (select seq from MIL_QA_RACK where JUDGE_STOVE_NO = '"
						+ JudgeStoveNo
						+ "' and  RESULT_NO = '"
						+ ResultNo
						+ "' and OFFLINE_FLAG_F = '1') order by seq";
				psta = conn.prepareStatement(Sql);
				rs = psta.executeQuery();
				while (rs.next()) {

					Seq = rs.getInt(1);
					Mat_No = rs.getString(2);

					String Sql1 = "";
					// 修改管号为剔除状态
					Sql1 = "Update MIL_QA_RACK set OFFLINE_FLAG_S =  '2' ,status = '2' where JUDGE_STOVE_NO = '"
							+ JudgeStoveNo
							+ "' and  RESULT_NO = '"
							+ ResultNo
							+ "' and Seq ='" + Seq + "' ";
					psta1 = conn.prepareStatement(Sql1);
					int count = psta1.executeUpdate();
					psta1.close();

					// 插入表MIL_SLAB_SCRAP
					Sql1 = " INSERT INTO MIL_SLAB_SCRAP(JUDGE_STOVE_NO, RESULT_NO,SEQ,PROCESS_NO, MAT_NO,SCRAP_USER,TIME,SCRAP_SHIFT, SCRAP_GROUP,FLAG,HANDLE_RESULT) ";
					Sql1 += " VALUES( '" + JudgeStoveNo + "', '" + ResultNo
							+ "', " + Seq + ", '12',  '" + Mat_No + "', '"
							+ ColUser + "', SYSDATE,  '" + ColShift + "', '"
							+ ColGroup + "',1,'500201')";
					psta1 = conn.prepareStatement(Sql1);
					count = psta1.executeUpdate();
					psta1.close();

					// 添加管号到表MIL_QA_DEFECT
					Sql1 = "Insert into MIL_QA_DEFECT (JUDGE_STOVE_NO,RESULT_NO,SAMPLE_PIPE_SEQ,SAMPLE_PIPE_NO,FLAG) values('"
							+ JudgeStoveNo
							+ "','"
							+ ResultNo
							+ "',"
							+ Seq
							+ ",'" + Mat_No + "'," + Flag + ")";
					psta1 = conn.prepareStatement(Sql1);
					int count1 = psta1.executeUpdate();
					psta1.close();
					i++;
					if (i > ScrapNum) {
						break;
					}
				}
				rs.close();
				psta.close();
				conn.commit();
			}

			// 查询缺陷下线的管号
			// 一次抽检
			if (Flag.equals(1)) {
				String Sql2 = "select SEQ,MAT_NO from MIL_QA_RACK where JUDGE_STOVE_NO = '"
						+ JudgeStoveNo
						+ "'and  RESULT_NO = '"
						+ ResultNo
						+ "'  and   SEQ  in (";
				Sql2 += "select seq from (select seq ,rownum rn from MIL_QA_RACK where JUDGE_STOVE_NO = '"
						+ JudgeStoveNo
						+ "'and  RESULT_NO = '"
						+ ResultNo
						+ "' and offline_flag = 0  ) where rn between "
						+ OffLineSeq
						+ " and   "
						+ (OffLineSeq + OffLineNum - 1) + " )";
				psta2 = conn.prepareStatement(Sql2);
				rs1 = psta2.executeQuery();
				while (rs1.next()) {
					Seq = rs1.getInt(1);
					Mat_No = rs1.getString(2);
					// 修改管号为下线状态
					String Sql1 = "Update MIL_QA_RACK set STATUS =  '3' ,OFFLINE_FLAG_F = '1' where JUDGE_STOVE_NO = '"
							+ JudgeStoveNo
							+ "' and  RESULT_NO = '"
							+ ResultNo
							+ "'  and Seq = " + Seq + "";
					psta1 = conn.prepareStatement(Sql1);
					int count = psta1.executeUpdate();
					psta1.close();

					// 添加管号到表MIL_QA_DEFECT
					Sql1 = "Insert into MIL_QA_DEFECT (JUDGE_STOVE_NO,RESULT_NO,SAMPLE_PIPE_SEQ,SAMPLE_PIPE_NO,FLAG) values('"
							+ JudgeStoveNo
							+ "','"
							+ ResultNo
							+ "',"
							+ Seq
							+ ",'" + Mat_No + "','" + Flag + "')";
					psta1 = conn.prepareStatement(Sql1);
					int count1 = psta1.executeUpdate();
					psta1.close();
					OffLineSeq++;
				}
				rs1.close();
				psta2.close();

			}
			// 二次抽检
			else {
				String Sql1 = "";
				String Sql2 = "select seq,mat_no from (select seq , mat_no,rownum rno ,judge_stove_no from mil_qa_rack  where   judge_stove_no = '"
						+ JudgeStoveNo
						+ "' and result_no = '"
						+ ResultNo
						+ "' and OFFLINE_FLAG_F = 1 order by seq) where rno> "
						+ ScrapNum + "";
				psta2 = conn.prepareStatement(Sql2);
				rs1 = psta2.executeQuery();
				int i = 1; // 二检下线管自增
				while (rs1.next()) {

					Seq = rs1.getInt(1);
					Mat_No = rs1.getString(2);
					// 修改管号为下线状态
					Sql1 = "Update MIL_QA_RACK set STATUS =  '4' ,OFFLINE_FLAG_S = '1' where JUDGE_STOVE_NO = '"
							+ JudgeStoveNo
							+ "' and  RESULT_NO = '"
							+ ResultNo
							+ "'  and Seq = " + Seq + "";
					psta1 = conn.prepareStatement(Sql1);
					int count = psta1.executeUpdate();
					psta1.close();

					// 添加管号到表MIL_QA_DEFECT
					Sql1 = "Insert into MIL_QA_DEFECT (JUDGE_STOVE_NO,RESULT_NO,SAMPLE_PIPE_SEQ,SAMPLE_PIPE_NO,FLAG) values('"
							+ JudgeStoveNo
							+ "','"
							+ ResultNo
							+ "',"
							+ Seq
							+ ",'" + Mat_No + "','" + Flag + "')";
					psta1 = conn.prepareStatement(Sql1);
					int count1 = psta1.executeUpdate();
					psta1.close();
					i++;
					if (i > OffLineNum) {
						break;
					}
				}
				// 将一次抽检未下线，二次抽检不为下线的管状态修改为正常轧制
				Sql1 = "update mil_qa_rack set status = '0' where OFFLINE_FLAG_F = '1' and OFFLINE_FLAG_S NOT IN( '1','2')";
				psta1 = conn.prepareStatement(Sql1);
				int count1 = psta1.executeUpdate();
				psta1.close();
				rs1.close();
				psta2.close();
			}

			conn.commit();
			conn.close();
		}

		catch (SQLException sqle) {
			sqle.printStackTrace();
			try {
				result = 0;
				conn.rollback();
			} catch (SQLException e) {
				e.printStackTrace();
			}
		} finally {
			try {
				if (conn != null && !conn.isClosed()) {
					conn.close();
				}
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		cro.setResult(result);
		return cro;
	}

	/**
	 * 缺陷项对应管号队列 1-查询出该炉对应的缺陷项 下线支和废品支 2-将缺馅项中的废品支/下线支 循环插入到总废品支和总下线支的管号队列中
	 * 
	 * @return
	 */
	public CoreReturnObject inserDefectCheck(String JudgeStoveNo,
			String ResultNo, Integer ScrapRanSeq, Integer ScrapNum,
			Integer OffLineNum, Integer Flag) {
		CoreReturnObject cro = new CoreReturnObject();
		Connection conn = null;
		PreparedStatement psta = null;
		PreparedStatement psta1 = null;
		try {
			conn = this.getDao("TgDao").getConnection();
			conn.setAutoCommit(false);
			ResultSet rs = null;
			ResultSet rs1 = null;
			int i = 0; // 用于插入的剔除管缺陷项名称字段递增
			int j = 0; // 用于插入的下线管缺陷项名称字段递增
			int _ScrapSeq = 1; // 起始自增序号
			int _OffLineSeq = 1;
			String Sql = " SELECT DEFECT_CODE,DEFECT_ITEM,WASTE_BRANCH,OFFLINE_PRODUCT,WASTE_TONS  FROM  MIL_CHECK_DEATIL WHERE JUDGE_STOVE_NO = '"
					+ JudgeStoveNo + "' and FLAG = '" + Flag + "'";
			psta = conn.prepareStatement(Sql);
			rs = psta.executeQuery();
			String[] DeCode = new String[] { "DEFECT_CODE1", "DEFECT_CODE2",
					"DEFECT_CODE3", "DEFECT_CODE4", "DEFECT_CODE5",
					"DEFECT_CODE6", "DEFECT_CODE7", "DEFECT_CODE8",
					"DEFECT_CODE9" };
			String[] DeName = new String[] { "DEFECT_NAME1", "DEFECT_NAME2",
					"DEFECT_NAME3", "DEFECT_NAME4", "DEFECT_NAME5",
					"DEFECT_NAME6", "DEFECT_NAME7", "DEFECT_NAME8",
					"DEFECT_NAME9" };
			while (rs.next()) {

				String DefectCode = rs.getString(1);
				String DefectName = rs.getString(2);
				int WasteNum = rs.getInt(3);
				int OffNum = rs.getInt(4);
				if (Flag.equals(1)) {
					// 修改表MIL_QA_DEFECT 每支管剔除缺陷项
					for (int w = 0; w < WasteNum; w++) {
						String Sql1 = "update MIL_QA_DEFECT set " + DeCode[i]
								+ " = '" + DefectCode + "' , " + DeName[i]
								+ " = '" + DefectName
								+ "'  where JUDGE_STOVE_NO = '" + JudgeStoveNo
								+ "'  and  RESULT_NO = '" + ResultNo
								+ "'   and FLAG = '" + Flag
								+ "' and SAMPLE_PIPE_SEQ = ";
						Sql1 += "(select seq from (select  t.mat_no ,rownum rn,t.seq from mil_qa_rack t where T.JUDGE_STOVE_NO = '"
								+ JudgeStoveNo
								+ "'and t.offline_flag_f = '2'   ) where rn ='"
								+ _ScrapSeq + "')";
						psta1 = conn.prepareStatement(Sql1);
						int count1 = psta1.executeUpdate();
						psta1.close();
						_ScrapSeq++;
						// 当序号超过当前剔除最大管支数时 序号回到起始位置
						if (_ScrapSeq > ScrapNum) {
							_ScrapSeq = 0;
							i++;
						}

					}
					// 修改表MIL_QA_DEFECT 每支管下线缺陷项
					for (int o = 0; o < OffNum; o++) {
						String Sql1 = "update MIL_QA_DEFECT set " + DeCode[j]
								+ " = '" + DefectCode + "'  ," + DeName[j]
								+ " = '" + DefectName
								+ "'  where JUDGE_STOVE_NO = '" + JudgeStoveNo
								+ "' and  RESULT_NO = '" + ResultNo
								+ "' and FLAG = '" + Flag
								+ "' and SAMPLE_PIPE_SEQ =  ";
						Sql1 += "(select seq from (select  t.mat_no ,rownum rn,t.seq from mil_qa_rack t where T.JUDGE_STOVE_NO = '"
								+ JudgeStoveNo
								+ "'and t.offline_flag_f = '1'   ) where rn ='"
								+ _OffLineSeq + "')";
						psta1 = conn.prepareStatement(Sql1);
						int count1 = psta1.executeUpdate();
						psta1.close();
						_OffLineSeq++;
						if (_OffLineSeq > OffLineNum) {
							_OffLineSeq = 1;
							j++;
						}
					}
				} else {
					_ScrapSeq = 1;
					_OffLineSeq = 1;
					// 修改表MIL_QA_DEFECT 每支管剔除缺陷项
					for (int w = 1; w <= WasteNum; w++) {
						String Sql1 = "update MIL_QA_DEFECT set " + DeCode[i]
								+ " = '" + DefectCode + "' , " + DeName[i]
								+ " = '" + DefectName
								+ "'  where JUDGE_STOVE_NO = '" + JudgeStoveNo
								+ "'  and  RESULT_NO = '" + ResultNo
								+ "'  and FLAG = '" + Flag
								+ "' and SAMPLE_PIPE_SEQ =  ";
						Sql1 += " (select seq from (select  t.mat_no ,rownum rn,t.seq from mil_qa_rack t where T.JUDGE_STOVE_NO = '"
								+ JudgeStoveNo
								+ "' and t.offline_flag_s = '2'   ) where rn ='"
								+ _ScrapSeq + "')";
						psta1 = conn.prepareStatement(Sql1);
						int count1 = psta1.executeUpdate();
						_ScrapSeq++;
						if (_ScrapSeq > ScrapNum) {
							i++;
							_ScrapSeq = 1;
						}
					}
					// 修改表MIL_QA_DEFECT 每支管下线缺陷项
					for (int o = 0; o < OffNum; o++) {
						String Sql1 = "update MIL_QA_DEFECT set " + DeCode[j]
								+ " = '" + DefectCode + "'  ," + DeName[j]
								+ " = '" + DefectName
								+ "'  where JUDGE_STOVE_NO = '" + JudgeStoveNo
								+ "' and  RESULT_NO = '" + ResultNo
								+ "'  and FLAG = '" + Flag
								+ "' and SAMPLE_PIPE_SEQ = ";
						Sql1 += " (select seq from (select  t.mat_no ,rownum rn,t.seq from mil_qa_rack t where T.JUDGE_STOVE_NO = '"
								+ JudgeStoveNo
								+ "' and t.offline_flag_s = '1'   ) where rn ='"
								+ _OffLineSeq + "')";
						psta1 = conn.prepareStatement(Sql1);
						int count1 = psta1.executeUpdate();
						psta1.close();
						_OffLineSeq++;
						if (_OffLineSeq > OffLineNum) {
							_OffLineSeq = 1;
							j++;
						}
					}

				}

			}

			// 修改质检实绩表抽检类型
			String Sql1 = "update MIL_SURFACE_RESULT set QA_TYPE = '" + Flag
					+ "'  where JUDGE_STOVE_NO = '" + JudgeStoveNo
					+ "' and  RESULT_NO = '" + ResultNo + "' ";
			psta1 = conn.prepareStatement(Sql1);
			int count1 = psta1.executeUpdate();
			psta1.close();

			// FLAG -1 插入下线炉信息到表MIL_OFFLINE_RESLUT (上组批时处理)
			// String Sql1 = "";

			rs.close();
			psta.close();
			conn.commit();
			conn.close();

		} catch (SQLException sqle) {
			sqle.printStackTrace();
			try {
				conn.rollback();
			} catch (SQLException e) {
				e.printStackTrace();
			}
		} finally {
			try {
				if (conn != null && !conn.isClosed()) {
					conn.close();
				}
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		cro.setResult(1);
		return cro;
	}

	/**
	 * 缺陷项数据删除
	 * 
	 * @return
	 */
	public CoreReturnObject deleteDefectData(String JudgeStoveNo,
			String ResultNo) {
		return this.setDataBySqlID("SurFace_Insp.DeleteDefectData",
				new Object[] { JudgeStoveNo, ResultNo });
	}

	/**
	 * 抽检后更新质检实绩信息 总检量，合格支，合格吨,废品量，下线量，
	 * 
	 * @return
	 */
	public CoreReturnObject updateSurfaceResultNumF(
			MilSurfaceResultEntity MilSurfaceResultEntity, Integer Flag) {

		ArrayList<String> sqllist = new ArrayList<String>();
		String sql = "";
		if (Flag.equals(1)) {

			sql = CoreXmlSqlParsersFactory
					.getSql("SurFace_Insp.UpdateSurfaceResultNumF");
		} else {
			sql = CoreXmlSqlParsersFactory
					.getSql("SurFace_Insp.UpdateSurfaceResultNumS");
		}

		sql = EntityTool.fillSqlByEntity(sql, MilSurfaceResultEntity);

		sqllist.add(sql);

		return this.getDao(CoreConstantData.sysbeanstr).ExcuteTransction(
				sqllist);

	}

	/**
	 * 二检作废
	 * 
	 * @return
	 */
	public CoreReturnObject CheckSCancel(String JudgeStoveNo, String ResultNo) {

		ArrayList<String> sqllist = new ArrayList<String>();
		// 删除炉次对应缺陷项下线支、废品支
		String sql = "DELETE MIL_CHECK_DEATIL WHERE JUDGE_STOVE_NO = '"
				+ JudgeStoveNo + "' AND RESULT_NO = '" + ResultNo
				+ "' AND FLAG = 2";
		// 1-删除缺陷管号
		String sql1 = "DELETE MIL_QA_DEFECT WHERE JUDGE_STOVE_NO = '"
				+ JudgeStoveNo + "' AND RESULT_NO = '" + ResultNo
				+ "' AND FLAG = 2";
		// 2-修改管号OFFLINES STATUS 状态
		// a 将二次抽检剔除的管号STATUS为2的修改为0
		String sql2 = "UPDATE MIL_QA_RACK SET STATUS = 0 WHERE JUDGE_STOVE_NO = '"
				+ JudgeStoveNo
				+ "' AND RESULT_NO = '"
				+ ResultNo
				+ "' AND OFFLINE_FLAG_S = 2";
		// b 置0二次抽检管下线状态
		String sql3 = "UPDATE MIL_QA_RACK SET OFFLINE_FLAG_S = 0 WHERE JUDGE_STOVE_NO = '"
				+ JudgeStoveNo + "' AND RESULT_NO = '" + ResultNo + "' ";
		// c 修改STATUS为一次抽检下线的状态
		String sql4 = "UPDATE MIL_QA_RACK SET STATUS = 3  WHERE JUDGE_STOVE_NO = '"
				+ JudgeStoveNo
				+ "' AND RESULT_NO = '"
				+ ResultNo
				+ "' AND OFFLINE_FLAG_F = 1 ";
		// 3-删除管号剔除表记录
		String sql5 = "DELETE MIL_SLAB_SCRAP WHERE JUDGE_STOVE_NO = '"
				+ JudgeStoveNo + "' AND RESULT_NO = '" + ResultNo
				+ "' and PROCESS_NO = 12";
		// 4-还原质检实绩为一检实绩 清空二检实绩
		String sql6 = "UPDATE MIL_SURFACE_RESULT SET DIRECTOR_QUANTITY = DIRECTOR_QUANTITY_F ,OFFLINE_QUANTITY = OFFLINE_QUANTITY_F ,WASTE_QUANTITY=  WASTE_QUANTITY_F,	QUALIFIED_BRANCH = QUALIFIED_BRANCH_F, QUALIFIED_TONS= QUALIFIED_TONS_F ";
		sql6 += " , DIRECTOR_QUANTITY_S = '', OFFLINE_QUANTITY_S = '', WASTE_QUANTITY_S = '', QUALIFIED_BRANCH_S = '',QUALIFIED_TONS_S = '' ,QA_TYPE = 1  ";
		sql6 += " WHERE JUDGE_STOVE_NO = '" + JudgeStoveNo
				+ "' AND RESULT_NO = '" + ResultNo + "'";

		sqllist.add(sql);
		sqllist.add(sql1);
		sqllist.add(sql2);
		sqllist.add(sql3);
		sqllist.add(sql4);
		sqllist.add(sql5);
		sqllist.add(sql6);

		return this.getDao(CoreConstantData.sysbeanstr).ExcuteTransction(
				sqllist);

	}

	/**
	 * 开始状态回退 1-删除实绩表 2-修改管号队列开始状态
	 * 
	 * @param JudgeStoveNo
	 *            炉号
	 * @param ResultNo
	 *            实绩编号
	 * @param Status
	 *            下线状态
	 * @param ProcessNo
	 *            0-上料 1-加热炉 2-穿孔 3-连轧 4-再加热 5-定径 6-分切 7-矫直 8-探伤 9-质检
	 * @return CoreReturnObject
	 * @throws SQLException
	 */
	public CoreReturnObject startBack(String JudgeStoveNo, String ResultNo,
			Integer ProcessNo, String PlineCode, String proPlanId,
			String gxPlanNo) throws SQLException {
		ArrayList<String> sqllist = new ArrayList<String>();
		Connection conn = this.getDao(CoreConstantData.sysbeanstr)
				.getConnection();
		String _sql = "";
		PreparedStatement psta = null;
		ResultSet rs = null;
		String zpFlag = "";
		_sql = CoreXmlSqlParsersFactory.getSql("startBack.selectMilOfflineZp");
		psta = conn.prepareStatement(_sql);
		psta.setString(1, JudgeStoveNo);
		psta.setString(2, proPlanId);
		psta.setString(3, gxPlanNo);
		rs = psta.executeQuery();
		if (rs.next()) {
			zpFlag = rs.getString("ZP_FLAG");
		}
		rs.close();
		psta.close();
		// 删除实绩表
		String sql = "delete from  MIL_SURFACE_RESULT  where JUDGE_STOVE_NO = '"
				+ JudgeStoveNo
				+ "'  AND RESULT_NO = '"
				+ ResultNo
				+ "' AND NVL(PRO_PLAN_ID,'/') = NVL('"
				+ proPlanId
				+ "','/') AND NVL(GX_PLAN_NO,'/') = NVL('"
				+ gxPlanNo
				+ "','/')";
		// 修改跟踪表状态 一次下线状态，二次下线状态 交接班状态
		String sql1 = "";

		sql1 = "UPDATE  MIL_QA_RACK set status = '0' , START_TIME ='' ,END_TIME = '', COL_SHIFT = '',COL_GROUP='',COL_USER='',CHANGE_FLAG = 0,OFFLINE_FLAG = '0'  where JUDGE_STOVE_NO = '"
				+ JudgeStoveNo
				+ "'  AND RESULT_NO = '"
				+ ResultNo
				+ "' AND NVL(PRO_PLAN_ID,'/') = NVL('"
				+ proPlanId
				+ "','/') AND NVL(GX_PLAN_NO,'/') = NVL('"
				+ gxPlanNo
				+ "','/')";

		// 删除QA_Defect管号
		String sql2 = "";
		sql2 = "delete MIL_SIZE_CHECK_DEATIL where JUDGE_STOVE_NO = '"
				+ JudgeStoveNo + "' and RESULT_NO = '" + ResultNo
				+ "' AND NVL(PRO_PLAN_ID,'/') = NVL('" + proPlanId
				+ "','/') AND NVL(GX_PLAN_NO,'/') = NVL('" + gxPlanNo
				+ "','/')";
		// 删除MIL_CHECK_DEATIL缺陷项信息
		String sql3 = "delete MIL_CHECK_DEATIL_SIMPLE where JUDGE_STOVE_NO = '"
				+ JudgeStoveNo + "' and RESULT_NO = '" + ResultNo
				+ "' AND NVL(PRO_PLAN_ID,'/') = NVL('" + proPlanId
				+ "','/') AND NVL(GX_PLAN_NO,'/') = NVL('" + gxPlanNo
				+ "','/')";
		String sql4 = "update MIL_PLAN set STATUS = '95'  where JUDGE_STOVE_NO = '"
				+ JudgeStoveNo
				+ "'  AND ID = '"
				+ ResultNo
				+ "' AND NVL(PRO_PLAN_ID,'/') = NVL('"
				+ proPlanId
				+ "','/') AND NVL(GX_PLAN_NO,'/') = NVL('"
				+ gxPlanNo
				+ "','/')";
		String sql5 = "delete mil_offline_reslut where  JUDGE_STOVE_NO= ''";
		if (zpFlag.equals("0")) {
			sql5 = "delete mil_offline_reslut where JUDGE_STOVE_NO = '"
					+ JudgeStoveNo + "' AND NVL(PRO_PLAN_ID,'/') = NVL('"
					+ proPlanId + "','/') AND NVL(GX_PLAN_NO,'/') = NVL('"
					+ gxPlanNo + "','/')" + " and OFFLINE_PRO = 'ZJ'";
		}

		String sql6 = "delete mil_slab_scrap_seq where JUDGE_STOVE_NO = '"
				+ JudgeStoveNo + "' AND NVL(PRO_PLAN_ID,'/') = NVL('"
				+ proPlanId + "','/') AND NVL(GX_PLAN_NO,'/') = NVL('"
				+ gxPlanNo + "','/')" + " and PROCESS_NO = '11'";
		sqllist.add(sql);
		sqllist.add(sql1);
		sqllist.add(sql2);
		sqllist.add(sql3);
		sqllist.add(sql4);
		sqllist.add(sql5);
		sqllist.add(sql6);
		return this.getDao(CoreConstantData.sysbeanstr).ExcuteTransction(
				sqllist);
	}

	/**
	 * 查询性能批信息
	 * 
	 * @param MilSurface_Entity
	 * @return
	 */
	public CoreReturnObject GetSimpleInfo(String JudgeStoveNo, String ResultNo) {

		String sql = "select a.simple_lot_no,a.judge_stove_no,a.result_no,a.matNUM ,b.waste_branch,b.offline_product from ";
		sql += " (select min(t.simple_lot_no) as simple_lot_no, min(t.judge_stove_no) as judge_stove_no,min(t.result_no) as result_no, count(*) as  matNUM ";
		sql += " from mil_qa_rack t where t.judge_stove_no ='" + JudgeStoveNo
				+ "' and t.result_no = '" + ResultNo
				+ "' group by simple_lot_no,judge_stove_no) a, ";
		sql += " mil_check_deatil_simple b where a.judge_stove_no = b.judge_stove_no (+) and a.simple_lot_no = b.simple_lot_no(+) and a.result_no = b.result_no(+)";
		sql += " order by a.simple_lot_no";
		return this.getData(sql);
	}

	/**
	 * 查询性能批对应缺陷项
	 * 
	 * @param MilSurface_Entity
	 * @return
	 */
	public CoreReturnObject GetSimpleCheckInfo(String JudgeStoveNo,
			String ResultNo, String SimpleLotNo) {

		String sql = "select t.JUDGE_STOVE_NO,t.DEFECT_ITEM,t.WASTE_BRANCH,t.WASTE_TONS,t.OFFLINE_PRODUCT,t.DEFECT_CODE,'移除' DELETE_ITEM from MIL_CHECK_DEATIL_SIMPLE t where";
		sql += " JUDGE_STOVE_NO = '" + JudgeStoveNo + "' and RESULT_NO = '"
				+ ResultNo + "' and Simple_Lot_No = '" + SimpleLotNo + "'";
		return this.getData(sql);
	}

	public CoreReturnObject insertDefectDataSimple(
			MilCheckDeatilEntity MilCheckDeatilEntity) {
		ArrayList<String> sqllist = new ArrayList<String>();
		String sql1 = " DELETE MIL_CHECK_DEATIL_SIMPLE WHERE JUDGE_STOVE_NO='"
				+ MilCheckDeatilEntity.getJudgeStoveNo() + "' and RESULT_NO= '"
				+ MilCheckDeatilEntity.getResultNo()
				+ "'  and SIMPLE_LOT_NO = '"
				+ MilCheckDeatilEntity.getSimpleLotNo()
				+ "' and DEFECT_CODE = '"
				+ MilCheckDeatilEntity.getDefectCode() + "'";
		sqllist.add(sql1);
		String sql = CoreXmlSqlParsersFactory
				.getSql("SurFace_Insp.InsertDefectDataSimple");
		sql = EntityTool.fillSqlByEntity(sql, MilCheckDeatilEntity);
		sqllist.add(sql);

		return this.getDao(CoreConstantData.sysbeanstr).ExcuteTransction(
				sqllist);
	}

	public CoreReturnObject deleteDefectDataSimple(
			MilCheckDeatilEntity MilCheckDeatilEntity) {
		ArrayList<String> sqllist = new ArrayList<String>();
		String sql1 = " DELETE MIL_CHECK_DEATIL_SIMPLE WHERE JUDGE_STOVE_NO='"
				+ MilCheckDeatilEntity.getJudgeStoveNo() + "' and RESULT_NO= '"
				+ MilCheckDeatilEntity.getResultNo()
				+ "'  and SIMPLE_LOT_NO = '"
				+ MilCheckDeatilEntity.getSimpleLotNo()
				+ "' and DEFECT_CODE = '"
				+ MilCheckDeatilEntity.getDefectCode() + "'";
		sqllist.add(sql1);

		return this.getDao(CoreConstantData.sysbeanstr).ExcuteTransction(
				sqllist);
	}

	/**
	 * 查询炉号是否分批
	 * 
	 * @param MilSurface_Entity
	 * @return
	 */
	public CoreReturnObject GetIsSimple(String JudgeStoveNo, String ResultNo,
			String proPlanId, String gxPlanNo) {
		String sql = "select IS_BATCH from mil_plan where judge_stove_no = '"
				+ JudgeStoveNo + "' and ID = '" + ResultNo
				+ "' AND NVL(PRO_PLAN_ID,'/') = NVL('" + proPlanId
				+ "','/') AND NVL(GX_PLAN_NO,'/') = NVL('" + gxPlanNo
				+ "','/')";
		return this.getData(sql);
	}

	/***
	 * 查询指定炉号的缺陷项
	 * 
	 * @param jugeNo
	 * @return
	 */
	public CoreReturnObject getDefectData(String jugeNo) {
		return this.getDataBySqlID("SurfaceInspectionResult.getDefectData",
				new Object[] { jugeNo });
	}

	/***
	 * 登记缺陷项
	 * 
	 * @param parm
	 * @param scrapNum
	 * @param offlineNum
	 * @return
	 */
	public CoreReturnObject doInsetDefectData(ArrayList<String> parm,
			String scrapNum, String offlineNum, String userName,
			String userGroup, String userOrder, ArrayList<String> parmStoreNo,
			String strInBound, String strInMemo, String plineCode,
			String proPlanId, String gxPlanNo) {
		CoreReturnObject cro = new CoreReturnObject();
		Connection connection = this.getDao(CoreConstantData.sysbeanstr)
				.getConnection();
		PreparedStatement psta = null;
		String sql = "";
		String sql1 = "";
		ResultSet rs = null;
		Date now = new Date();
		SimpleDateFormat dateFormat = new SimpleDateFormat(
				"yyyy-MM-dd HH:mm:ss");
		SimpleDateFormat df = new SimpleDateFormat("yyyyMM");
		String systime = dateFormat.format(now);
		
		String yearMoth = StringTool.GetBalYear(now,StringTool.GetSupplyUnit(plineCode));// 改25号结转
		int acount = 0;
		String specName = "";
		String length = "";
		String str1[] = null;
		double strScrapWgt = 0.0;
		String jugeNo = "";// 炉号
		String bacthNo = "X";
		String resultNo = "";// 实绩编号

		String materiaNo = "";// 物料码
		String materiaName = "";// 物料描述
		String INWL_ID = "";// 投入物料编码
		String INWL_DESC = "";// 投入物料描述
		String CRAFT_SEQ = ""; // 工艺序号
		String judgeStdDes = ""; // 判定标准集合
		String cic = ""; // cic
		String offlineDoc = ""; // 离线单号
		String belongCode = ""; // 所属权
		String belongName = ""; // 所属权

		int offNum = 0;
		double offWgt = 0;
		String lengthCp[] = null;
		try {
			connection.setAutoCommit(false); // 取消自动提交事务
			String insertCheckDetiaSql = CoreXmlSqlParsersFactory
					.getSql("SurfaceInspectionResult.doInsetDefectData");
			PreparedStatement insertCheckDetiaPsta = connection
					.prepareStatement(insertCheckDetiaSql);
			String insertMatSql = CoreXmlSqlParsersFactory
					.getSql("SurfaceInspectionResult.doInsetMatData");// 入虚拟库存
			PreparedStatement insertMatPsta = connection
					.prepareStatement(insertMatSql);
			String insertInListSql = CoreXmlSqlParsersFactory
					.getSql("FrmOffLine.insertInListX");// 待处理数据入在线库
			PreparedStatement insertListPsta = connection
					.prepareStatement(insertInListSql);

			sql = CoreXmlSqlParsersFactory.getSql("FrmOffLine.offlineDoc");// 离线单号
			psta = connection.prepareStatement(sql);
			rs = psta.executeQuery();
			if (rs.next()) {
				offlineDoc = rs.getString("OFFLINE_DOC");
			}
			rs.close();
			psta.close();

			for (String str : parm) {
				MilCheckDeatilEntity checkDetaiTity = EntityTool
						.getEntityByJSONStr(str, MilCheckDeatilEntity.class);
				jugeNo = checkDetaiTity.getJudgeStoveNo();
				resultNo = checkDetaiTity.getResultNo();
				sql = CoreXmlSqlParsersFactory
						.getSql("doInsetDefectData.selectDefect");
				psta = connection.prepareStatement(sql);
				psta.setString(1, checkDetaiTity.getJudgeStoveNo());
				psta.setString(2, checkDetaiTity.getDefectCode());
				psta.setString(3, proPlanId);
				psta.setString(4, gxPlanNo);
				rs = psta.executeQuery();
				if (rs.next()) {
					acount = Integer.parseInt(rs.getString("ACOUNT"));
				}
				rs.close();
				psta.close();
				if (acount > 0) {
					cro.setV_errMsg("该炉已登记过缺陷,需重新录入请先移除已登记过的缺陷项!");
					return cro;
				}
				sql = CoreXmlSqlParsersFactory
						.getSql("doInsetDefectData.selectMilPlanSpece");// 查询计划规格、长度
				psta = connection.prepareStatement(sql);
				psta.setString(1, checkDetaiTity.getJudgeStoveNo());
				psta.setString(2, proPlanId);
				psta.setString(3, gxPlanNo);
				rs = psta.executeQuery();
				if (rs.next()) {
					specName = rs.getString("PIPE_SIZE");
					length = rs.getString("TARGET_LENGTH");
				}
				rs.close();
				psta.close();
				str1 = specName.split("[*]");
				strScrapWgt = 0.02466
						* Double.parseDouble(str1[1])
						* (Double.parseDouble(str1[0]) - Double
								.parseDouble(str1[1]))
						* Double.parseDouble(length)
						* Integer.parseInt(checkDetaiTity.getWasteBranch())
						/ 1000;
				insertCheckDetiaPsta.setString(1, checkDetaiTity
						.getJudgeStoveNo());
				insertCheckDetiaPsta.setString(2, proPlanId);
				insertCheckDetiaPsta.setString(3, gxPlanNo);
				insertCheckDetiaPsta.setString(4, checkDetaiTity
						.getDefectItem());
				insertCheckDetiaPsta.setString(5, checkDetaiTity
						.getWasteBranch());
				insertCheckDetiaPsta.setString(6, new DecimalFormat("0.000")
						.format(strScrapWgt));// 废品量
				insertCheckDetiaPsta.setString(7, checkDetaiTity
						.getOfflineProduct());
				insertCheckDetiaPsta.setString(8, checkDetaiTity
						.getDefectCode());
				insertCheckDetiaPsta.setString(9, checkDetaiTity.getResultNo());

				insertCheckDetiaPsta.setString(10, checkDetaiTity
						.getOfflineProduct());
				insertCheckDetiaPsta.setString(11, checkDetaiTity
						.getWasteBranch());

				// insertCheckDetiaPsta.setString(11,
				// checkDetaiTity.getJudgeStoveNo());

				// insertCheckDetiaPsta.setString(12,
				// checkDetaiTity.getJudgeStoveNo());
				insertCheckDetiaPsta.setInt(12, Integer.parseInt(checkDetaiTity
						.getOfflineProduct()));

				insertCheckDetiaPsta.setString(13, userName);
				insertCheckDetiaPsta.setString(14, userOrder);
				insertCheckDetiaPsta.setString(15, userGroup);

				// insertCheckDetiaPsta.setString(18,
				// checkDetaiTity.getJudgeStoveNo());
				insertCheckDetiaPsta.setInt(16, Integer.parseInt(checkDetaiTity
						.getWasteBranch()));

				insertCheckDetiaPsta.setString(17, userName);
				insertCheckDetiaPsta.setString(18, userOrder);
				insertCheckDetiaPsta.setString(19, userGroup);

				insertCheckDetiaPsta.setString(20, checkDetaiTity
						.getOfflineProduct());

				insertCheckDetiaPsta.setString(21, checkDetaiTity
						.getOfflineProduct());

				insertCheckDetiaPsta.setString(22, checkDetaiTity
						.getOfflineProduct());
				insertCheckDetiaPsta.setString(23, userName);
				insertCheckDetiaPsta.setString(24, userOrder);
				insertCheckDetiaPsta.setString(25, userGroup);
				insertCheckDetiaPsta.setString(26, checkDetaiTity
						.getOfflineProduct());// 重量
				insertCheckDetiaPsta.setString(27, offlineDoc); // 离线单号
				insertCheckDetiaPsta.addBatch();
				offNum = offNum
						+ Integer.parseInt(checkDetaiTity.getOfflineProduct());
			}

			String inListDoc = querySendSqlDoc(connection, strInBound,
					strInMemo, plineCode, systime);// 入库单号
			String inListSeq = querySendSql(connection, inListDoc, plineCode); // 入库流水号
			int n = Integer.parseInt(inListSeq.substring(
					inListSeq.length() - 4, inListSeq.length()));

			String matNo = queryMatNoM(connection, jugeNo.replaceFirst("-.*",
					""), bacthNo); // 材料号
			int g = Integer.parseInt(matNo.substring(matNo.length() - 4, matNo
					.length()));
			offWgt = 0.02466
					* Double.parseDouble(str1[1])
					* (Double.parseDouble(str1[0]) - Double
							.parseDouble(str1[1])) * Double.parseDouble(length)
					* offNum / 1000;
			List<double[]> list1 = null;
			if (offNum > 0) {
				list1 = MeanValueCalculation.MeanCalculation(
						Double.parseDouble(new DecimalFormat("0.000")
								.format(offWgt)), offNum);
			}

			sql = CoreXmlSqlParsersFactory
					.getSql("SurfaceInspectionResult.selectMilPlanData");// 查询炉计划信息
			psta = connection.prepareStatement(sql);
			psta.setString(1, resultNo);
			psta.setString(2, jugeNo);
			psta.setString(3, proPlanId);
			psta.setString(4, gxPlanNo);
			rs = psta.executeQuery();
			List<MilPlanEntity3> list = EntityTool.getEntitysByRs(rs,
					MilPlanEntity3.class);
			rs.close();
			psta.close();
			if (list == null) {
				cro.setV_errMsg("无该炉计划信息!");
				return cro;
			}

			sql = CoreXmlSqlParsersFactory
					.getSql("FrmOffLine.selectMaterialNo");// 查询物料码
			psta = connection.prepareStatement(sql);
			psta.setString(1, proPlanId);
			psta.setString(2, gxPlanNo);
			rs = psta.executeQuery();
			if (rs.next()) {
				judgeStdDes = rs.getString("judgeStdDes");
				cic = rs.getString("CIC");
				materiaNo = rs.getString("OUTWL_ID");
				materiaName = rs.getString("OUTWL_DESC");
				INWL_ID = rs.getString("INWL_ID");
				INWL_DESC = rs.getString("INWL_DESC");
				CRAFT_SEQ = rs.getString("CRAFT_SEQ");
			}
			rs.close();
			psta.close();

			MilPlanEntity3 milPlanTity = list.get(0);
			lengthCp = milPlanTity.getLengthRange().split("[-]");
			
			sql = CoreXmlSqlParsersFactory
					.getSql("FrmOffLine.selectBelongCode");// 查询产线、科室
			psta = connection.prepareStatement(sql);
			psta.setString(1, plineCode);
			rs = psta.executeQuery();
			if (rs.next()) {
				belongCode = rs.getString("DEPARTMENT_CODE");
				belongName = rs.getString("DEPARTMENT_DESC");
				milPlanTity.setPlineName(rs.getString("PLINE_NAME"));
			}
			rs.close();
			psta.close();

			if (list1 != null) {
				for (int j = 0; j < list1.size(); j++) {
					double[] conW = list1.get(j);
					if ((int) conW[0] >= 0) {
						for (int z = 0; z < (int) conW[0]; z++) {
							insertMatPsta.setString(1, jugeNo.replaceFirst(
									"-.*", ""));
							insertMatPsta.setString(2, bacthNo);
							insertMatPsta.setString(3, "001");
							insertMatPsta.setString(4, parmStoreNo.get(0));
							insertMatPsta.setString(5, parmStoreNo.get(1));
							insertMatPsta.setString(6, parmStoreNo.get(2));
							insertMatPsta.setString(7, parmStoreNo.get(3));
							insertMatPsta.setString(8, userName);
							insertMatPsta.setString(9, (jugeNo.replaceFirst(
									"-.*", "") + bacthNo)
									+ StringTool.formatDecimal(g, "0000"));
							insertMatPsta.setString(10, parmStoreNo.get(4));
							insertMatPsta.setString(11, parmStoreNo.get(5));
							insertMatPsta.setString(12, belongCode);
							insertMatPsta.setString(13, belongName);

							insertMatPsta.setString(14, jugeNo.replaceFirst(
									"-.*", ""));
							insertMatPsta.setString(15, bacthNo);
							insertMatPsta.setString(16, "001");
							insertMatPsta.setString(17, "1");
							insertMatPsta
									.setString(18, String.valueOf(conW[1]));
							insertMatPsta.setString(19, systime);
							insertMatPsta.setString(20, (jugeNo.replaceFirst(
									"-.*", "") + bacthNo)
									+ StringTool.formatDecimal(g, "0000"));
							insertMatPsta.setString(21, "801401");
							insertMatPsta.setString(22, "80150104");
							insertMatPsta.setString(23, milPlanTity
									.getPlineCode());
							insertMatPsta.setString(24, milPlanTity
									.getPlineName());
							insertMatPsta.setString(25, "11");
							insertMatPsta.setString(26, milPlanTity.getId());
							insertMatPsta.setString(27, jugeNo);
							insertMatPsta.setString(28, "");
							insertMatPsta.setString(29, milPlanTity
									.getVarieties());
							insertMatPsta.setString(30, "");
							insertMatPsta.setString(31, milPlanTity
									.getSteelname());
							insertMatPsta.setString(32, "");
							insertMatPsta.setString(33, milPlanTity
									.getPipeSize().replace("*", "x"));
							insertMatPsta.setString(34, "");
							insertMatPsta.setString(35, milPlanTity
									.getGradename());
							insertMatPsta.setString(36, "");
							insertMatPsta.setString(37, milPlanTity
									.getBuckleType());
							insertMatPsta.setString(38, "");
							insertMatPsta.setString(39, milPlanTity
									.getRollStandrad());
							insertMatPsta.setString(40, belongCode);
							insertMatPsta.setString(41, belongName);
							insertMatPsta.setString(42, milPlanTity
									.getStdStyle());
							insertMatPsta.setString(43, milPlanTity
									.getStdStyleDesc());
							insertMatPsta.setString(44, str1[0].toString());
							insertMatPsta.setString(45, str1[1].toString());
							insertMatPsta.setString(46, lengthCp[0].toString());
							insertMatPsta.setString(47, lengthCp[1].toString());
							insertMatPsta.setString(48, milPlanTity.getLotNo());
							insertMatPsta.setString(49, milPlanTity
									.getContractNo());
							insertMatPsta.setString(50, milPlanTity
									.getTargetLength());
							insertMatPsta
									.setString(51, milPlanTity.getTarget());
							insertMatPsta.setString(52, milPlanTity
									.getProcessStatus());
							insertMatPsta.setString(53, jugeNo.replaceFirst(
									"-.*", ""));
							insertMatPsta.setString(54, proPlanId);
							insertMatPsta.setString(55, gxPlanNo);

							insertMatPsta.setString(56, materiaNo);
							insertMatPsta.setString(57, materiaName);
							insertMatPsta.setString(58, INWL_ID);
							insertMatPsta.setString(59, INWL_DESC);
							insertMatPsta.setString(60, cic);
							insertMatPsta.setString(61, judgeStdDes);
							insertMatPsta.setString(62, CRAFT_SEQ);
							insertMatPsta.setString(63, offlineDoc); // 离线单号
							insertMatPsta.addBatch();

							insertListPsta.setString(1, parmStoreNo.get(5));
							insertListPsta.setString(2, belongCode);
							insertListPsta.setString(3, inListDoc
									+ StringTool.formatDecimal(n, "0000"));
							insertListPsta.setString(4, inListDoc);
							insertListPsta.setString(5, "800701");
							insertListPsta.setString(6, "产出入库");
							insertListPsta.setString(7, (jugeNo.replaceFirst(
									"-.*", "") + bacthNo)
									+ StringTool.formatDecimal(g, "0000"));
							insertListPsta.setString(8, milPlanTity.getLotNo());
							insertListPsta.setString(9, milPlanTity
									.getStoveNo());
							insertListPsta.setString(10, jugeNo.replaceFirst(
									"-.*", ""));
							insertListPsta.setString(11, bacthNo);
							insertListPsta.setString(12, "001");

							insertListPsta.setString(13, "");
							insertListPsta.setString(14, milPlanTity
									.getVarieties());
							insertListPsta.setString(15, "");// 标准
							insertListPsta.setString(16, milPlanTity
									.getRollStandrad());
							insertListPsta.setString(17, "");
							insertListPsta.setString(18, milPlanTity
									.getSteelname());
							insertListPsta.setString(19, "");
							insertListPsta.setString(20, milPlanTity
									.getStdStyleDesc());
							insertListPsta.setString(21, "");
							insertListPsta.setString(22, milPlanTity
									.getPipeSize().replace("*", "x"));
							insertListPsta.setString(23, "");
							insertListPsta.setString(24, milPlanTity
									.getBuckleType());

							insertListPsta.setString(25, milPlanTity
									.getDimater());
							insertListPsta.setString(26, milPlanTity
									.getHeight());
							insertListPsta.setString(27, milPlanTity
									.getLengthmin());
							insertListPsta.setString(28, milPlanTity
									.getLengthmax());
							insertListPsta.setString(29, "1");
							insertListPsta.setString(30, String
									.valueOf(conW[1]));
							insertListPsta.setString(31, String
									.valueOf(conW[1]));
							insertListPsta.setString(32, belongCode);
							insertListPsta.setString(33, belongName);
							insertListPsta.setString(34, parmStoreNo.get(0));
							insertListPsta.setString(35, "");
							insertListPsta.setString(36, "1");
							insertListPsta.setString(37, parmStoreNo.get(4));
							insertListPsta.setString(38, systime);
							insertListPsta.setString(39, "");// 合同号
							insertListPsta.setString(40, "");
							insertListPsta.setString(41, "");
							insertListPsta.setString(42, "");
							insertListPsta.setString(43, "");
							insertListPsta.setString(44, "");

							insertListPsta.setString(45, "801401");
							insertListPsta.setString(46, "80150101");
							insertListPsta.setString(47, systime);
							insertListPsta.setString(48, milPlanTity
									.getTargetLength());// 长度
							insertListPsta.setString(49, belongCode);
							insertListPsta.setString(50, belongName);
							insertListPsta.setString(51, milPlanTity
									.getRollStandrad());
							insertListPsta.setString(52, milPlanTity
									.getPlineCode());
							insertListPsta.setString(53, milPlanTity
									.getPlineName());
							insertListPsta.setString(54, milPlanTity
									.getGradecode());
							insertListPsta.setString(55, milPlanTity
									.getGradename());
							insertListPsta.setString(56, yearMoth);
							insertListPsta.setString(57, systime);
							insertListPsta.setString(58, "");
							insertListPsta.setString(59, "801302");
							insertListPsta.setString(60, "机组");
							insertListPsta.setString(61, milPlanTity
									.getPlineCode());
							insertListPsta.setString(62, milPlanTity
									.getPlineName());
							insertListPsta.setString(63, "");
							insertListPsta.setString(64, "");
							insertListPsta.setString(65, milPlanTity
									.getContractNo());
							insertListPsta.setString(66, "11");
							insertListPsta.setString(67, milPlanTity
									.getJudgeStoveNo());
							insertListPsta.setString(68, userOrder);
							insertListPsta.setString(69, userGroup);
							insertListPsta.addBatch();
							g++;
							n++;
						}
					}
				}
			}
			insertCheckDetiaPsta.executeBatch();
			insertMatPsta.executeBatch();
			insertListPsta.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,
			String plineCode, String systime) throws Exception {
		int seq = 0;
		String inListDoc = "";
		PreparedStatement psta = null;
		Date dt = new Date();
		SimpleDateFormat matter1 = new SimpleDateFormat("yyyy-MM-dd");
		SimpleDateFormat matter2 = new SimpleDateFormat("yyMMdd");
		String sqlLovsqe = CoreXmlSqlParsersFactory
				.getSql("FrmInOnlineStore.getInListDoc");
		psta = conn.prepareStatement(sqlLovsqe);
		psta.setString(1, memo);
		psta.setString(2, plineCode);
		psta.setString(3, systime);
		psta.setString(4, systime);
		// psta.setString(5, strlist);
		psta.setString(5, plineCode);
		ResultSet rs = psta.executeQuery();
		if (rs.next()) {
			// String res = rs.getString(1);
			// if (res == null) {
			// res = memo + plineCode + matter2.format(dt) + "00001";
			// } else {
			// //seq = Integer.parseInt(res.substring(8, 13));
			// seq = Integer.parseInt(res.substring(12, 17));
			// }
			inListDoc = rs.getString("INSTOCK_DOC");
		}
		rs.close();
		psta.close();
		// return memo + plineCode + matter2.format(dt)
		// + StringTool.formatDecimal(++seq, "00000");
		return inListDoc;
	}

	/**
	 * 每支材料对应的入库流水号
	 * 
	 * @param conn
	 *            c
	 * @param strlist
	 *            传递参数
	 * @return obj
	 * @throws Exception
	 *             异常处理
	 */
	public String querySendSql(Connection conn, String strlist, String plineCode)
			throws Exception {
		int seq = 0;
		String inListDocSeq = "";
		PreparedStatement psta = null;
		Date dt = new Date();
		SimpleDateFormat matter1 = new SimpleDateFormat("yyyy-MM-dd");
		String sqlLovsqe = CoreXmlSqlParsersFactory
				.getSql("FrmInOnlineStore.getInListDoc1");
		psta = conn.prepareStatement(sqlLovsqe);
		psta.setString(1, strlist);
		psta.setString(2, strlist);
		ResultSet rs = psta.executeQuery();
		if (rs.next()) {
			// String res = rs.getString(1);
			// if (res == null) {
			// res = strlist + "0001";
			// } else {
			// //seq = Integer.parseInt(res.substring(13, 17));
			// seq = Integer.parseInt(res.substring(17, 21));
			// }
			inListDocSeq = rs.getString("INSTOCK_SQE");
		}
		rs.close();
		psta.close();
		// return strlist + StringTool.formatDecimal(++seq, "0000");
		return inListDocSeq;
	}

	/**
	 * 根据炉号、批号自动生成材料号
	 * 
	 * @param conn
	 *            c
	 * @param strLcode
	 *            传递参数
	 * @return obj
	 * @throws Exception
	 *             异常处理
	 */
	public String queryMatNoM(Connection conn, String strLcode, String strBatch)
			throws Exception {
		int count = 0;
		String matNo = "";
		PreparedStatement psta = null;
		String sqlLovsqe = CoreXmlSqlParsersFactory
				.getSql("FrmInOnlineStore.queryMatNoM");
		psta = conn.prepareStatement(sqlLovsqe);
		psta.setString(1, strLcode);
		psta.setString(2, strBatch);
		psta.setString(3, strLcode);
		psta.setString(4, strBatch);
		psta.setString(5, strLcode);
		psta.setString(6, strBatch);
		psta.setString(7, strLcode);
		psta.setString(8, strBatch);
		ResultSet rs = psta.executeQuery();
		if (rs.next()) {
			// String res = rs.getString(1);
			// if (res == null) {
			// res = strLcode + strBatch + "0001";
			// } else {
			// count = Integer.parseInt(res.substring(res.length() - 4, res
			// .length()));
			// }
			matNo = rs.getString("MAT_NO");
		}
		rs.close();
		psta.close();
		// return (strLcode + strBatch)
		// + StringTool.formatDecimal(++count, "0000");
		return matNo;
	}

	/***
	 * 保存几何尺寸时变化重量
	 * 
	 * @param jugeNo
	 * @return
	 */
	public CoreReturnObject updateActWgt(String jugeNo) {
		CoreReturnObject cro = new CoreReturnObject();
		Connection connection = this.getDao(CoreConstantData.sysbeanstr)
				.getConnection();
		PreparedStatement psta = null;
		String sql = "";
		ResultSet rs = null;
		Date now = new Date();
		SimpleDateFormat dateFormat = new SimpleDateFormat(
				"yyyy-MM-dd HH:mm:ss");
		String systime = dateFormat.format(now);
		double dimater = 0.0;// 外径
		double height = 0.0;// 壁厚
		try {
			connection.setAutoCommit(false); // 取消自动提交事务
			String updateWgtSql = CoreXmlSqlParsersFactory
					.getSql("SurfaceInspectionResult.updateActWgt");
			PreparedStatement updateWgtPsta = connection
					.prepareStatement(updateWgtSql);

			sql = CoreXmlSqlParsersFactory
					.getSql("SurfaceInspectionResult.selectMinMaxD");
			psta = connection.prepareStatement(sql);
			psta.setString(1, jugeNo);
			psta.setString(2, jugeNo);
			rs = psta.executeQuery();
			if (rs.next()) {
				dimater = Double.parseDouble(rs.getString("DIMATER"));
			}
			rs.close();
			psta.close();

			sql = CoreXmlSqlParsersFactory
					.getSql("SurfaceInspectionResult.selectMinMaxS");
			psta = connection.prepareStatement(sql);
			psta.setString(1, jugeNo);
			psta.setString(2, jugeNo);
			psta.setString(3, jugeNo);
			psta.setString(4, jugeNo);
			rs = psta.executeQuery();
			if (rs.next()) {
				height = Double.parseDouble(rs.getString("HEIGHT"));
			}
			rs.close();
			psta.close();

			updateWgtPsta.setString(1, String.valueOf(height));
			updateWgtPsta.setString(2, String.valueOf(dimater));
			updateWgtPsta.setString(3, String.valueOf(height));
			updateWgtPsta.setString(4, jugeNo);
			updateWgtPsta.addBatch();

			updateWgtPsta.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 parm
	 * @return
	 */
	public CoreReturnObject doDeleteDefect(ArrayList<String> parm) {
		CoreReturnObject cro = new CoreReturnObject();
		Connection connection = this.getDao(CoreConstantData.sysbeanstr)
				.getConnection();
		PreparedStatement psta = null;
		String sql = "";
		ResultSet rs = null;
		// String isOk = ""; // 0-未变仓库位置；1-已导运
		int acount = 0;
		try {
			connection.setAutoCommit(false); // 取消自动提交事务
			String deleteSql = CoreXmlSqlParsersFactory
					.getSql("SurfaceInspectionResult.doDeleteDefect");
			PreparedStatement deletePsta = connection
					.prepareStatement(deleteSql);
			String deleteMatSql = CoreXmlSqlParsersFactory
					.getSql("SurfaceInspectionResult.doDeleteMatData");// 删除虚拟库存
			PreparedStatement deleteMatPsta = connection
					.prepareStatement(deleteMatSql);
			sql = CoreXmlSqlParsersFactory
					.getSql("SurfaceInspectionResult.doQueryBackCount");// 查询可撤销的支数
			psta = connection.prepareStatement(sql);
			psta.setString(1, parm.get(0));
			rs = psta.executeQuery();
			if (rs.next()) {
				acount = Integer.parseInt(rs.getString("ACOUNT").toString());
			}
			rs.close();
			psta.close();
			if (Integer.parseInt(parm.get(2)) > acount) {
				cro.setV_errMsg("输入的支数大于炉号:" + parm.get(0) + "的可撤销支数" + acount
						+ "!");
				return cro;
			}

			deletePsta.setString(1, parm.get(0));
			deletePsta.setString(2, parm.get(1));
			deletePsta.setString(3, parm.get(2));
			deletePsta.setString(4, parm.get(3));
			deletePsta.addBatch();

			deleteMatPsta.setString(1, parm.get(0));
			deleteMatPsta.setInt(2, Integer.parseInt(parm.get(2)));
			deleteMatPsta.addBatch();
			deleteMatPsta.executeBatch();
			deletePsta.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 lotNo
	 * @param jugeNo
	 * @return
	 */
	public CoreReturnObject getTestingResult(String lotNo, String jugeNo,
			String proPlanId, String gxPlanNo) {
		return this.getDataBySqlID("SurfaceInspectionResult.getTestingResult",
				new Object[] { jugeNo, lotNo, proPlanId, gxPlanNo, jugeNo,
						lotNo, proPlanId, gxPlanNo, jugeNo, lotNo, proPlanId,
						gxPlanNo });
	}

	/***
	 * 查询表检实绩支数
	 * 
	 * @param lotNo
	 * @param jugeNo
	 * @return
	 */
	public CoreReturnObject getSurfaceResult(String lotNo, String jugeNo,
			String proPlanId, String gxPlanNo) {
		return this.getDataBySqlID("SurfaceInspectionResult.getSurfaceResult",
				new Object[] { jugeNo, lotNo, proPlanId, gxPlanNo });
	}

	/***
	 * 查询下线支数是否已进行其他操作
	 * 
	 * @param jugeNo
	 * @return
	 */
	public CoreReturnObject doQueryOffline(String jugeNo, String proPlanId,
			String gxPlanNo) {
		return this.getDataBySqlID("SurfaceInspectionResult.doQueryOffline",
				new Object[] { jugeNo, proPlanId, gxPlanNo });
	}

	/***
	 * 移除时查询是否已保存该缺陷
	 * 
	 * @param jugeNo
	 * @param defctCode
	 * @return
	 */
	public CoreReturnObject getCheckDetail(String jugeNo, String defctCode) {
		return this.getDataBySqlID("SurfaceInspectionResult.getCheckDetail",
				new Object[] { jugeNo, defctCode });
	}

	/***
	 * 查询管号队列返线支数
	 * 
	 * @param resultNo
	 * @param jugeNo
	 * @return
	 */
	public CoreReturnObject selectBackLineNum(String resultNo, String jugeNo,
			String proPlanId, String gxPlanNo) {
		return this.getDataBySqlID("SurfaceInspectionResult.selectBackLineNum",
				new Object[] { resultNo, jugeNo });
	}

	/***
	 * 查询探伤合格支数
	 * 
	 * @param resultNo
	 * @param plineCode
	 * @return
	 */
	public CoreReturnObject doQueryTestResult(String resultNo, String plineCode) {
		String sql = CoreXmlSqlParsersFactory
				.getSql("SurfaceInspectionResult.doQueryTestResult");
		if (plineCode.equals("C009") || plineCode.equals("C008")
				|| plineCode.equals("C017")) {
			sql = sql.replace("#TABLENAME#", "MIL_MT_RESULT");
		} else if (plineCode.equals("C010")) {
			sql = sql.replace("#TABLENAME#", "MIL_ET_RESULT");
		}
		return this.getData(sql, new Object[] { resultNo });
	}

	/***
	 * 查询表面检验D1\D2最大最小
	 * 
	 * @return
	 */
	public CoreReturnObject doQuerySufaceD(String jugeNo) {
		return this.getDataBySqlID("SurfaceInspectionResult.doQuerySufaceD",
				new Object[] { jugeNo, jugeNo });
	}

	/***
	 * 查询壁厚最大最小
	 * 
	 * @param jugeNo
	 * @return
	 */
	public CoreReturnObject doQuerySufaceS(String jugeNo) {
		return this.getDataBySqlID("SurfaceInspectionResult.doQuerySufaceS",
				new Object[] { jugeNo, jugeNo, jugeNo, jugeNo });
	}

	/***
	 * 查询是否返线计划
	 * 
	 * @param resultNo
	 * @param jugeNo
	 * @return
	 */
	public CoreReturnObject doQueryBackFlag(String resultNo, String jugeNo,
			String proPlanId, String gxPlanNo) {
		return this.getDataBySqlID("SurfaceInspectionResult.doQueryBackFlag",
				new Object[] { resultNo, jugeNo, proPlanId, gxPlanNo });
	}

	/***
	 * 返线查询计划支数
	 * 
	 * @return
	 */
	public CoreReturnObject doQueryPlanBratch(String resultNo, String plineCode) {
		return this.getDataBySqlID("SurfaceInspectionResult.doQueryPlanBratch",
				new Object[] { resultNo, plineCode });
	}

	/***
	 * 查询进程合格支数
	 * 
	 * @param resultNo
	 * @param jugeNo
	 * @return
	 */
	public CoreReturnObject doQueryProcessNum(String resultNo, String jugeNo) {
		return this.getDataBySqlID("SurfaceInspectionResult.doQueryProcessNum",
				new Object[] { resultNo, jugeNo });
	}

	/***
	 * 查询进程合格状态支数
	 * 
	 * @param resultNo
	 * @param jugeNo
	 * @return
	 */
	public CoreReturnObject doQueryPort(String resultNo, String plineCode) {
		return this.getDataBySqlID("SurfaceInspectionResult.doQueryPort",
				new Object[] { resultNo, plineCode });
	}

	public CoreReturnObject doQueryNodeS(String resultNo, String plineCode) {
		String sql = CoreXmlSqlParsersFactory
				.getSql("SurfaceInspectionResult.doQueryNodeS");
		if (plineCode.equals("C010")) {
			sql = sql.replace("#RESULT#", "MIL_MT_RESULT");
		} else {
			sql = sql.replace("#RESULT#", "MIL_ET_RESULT");
		}
		return this.getData(sql, new Object[] { resultNo });
	}

	public CoreReturnObject doQueryPortWgt(String resultNo, String num,
			String proPlanId, String gxPlanNo) {
		return this.getDataBySqlID("SurfaceInspectionResult.doQueryPortWgt",
				new Object[] { resultNo, Integer.parseInt(num), proPlanId,
						gxPlanNo });
	}

	/***
	 * 查询几何尺寸
	 * 
	 * @param jugeNo
	 * @return
	 */
	public CoreReturnObject doQueryChcekSize(String jugeNo, String proPlanId,
			String gxPlanNo) {
		return this.getDataBySqlID("SurfaceInspectionResult.doQueryChcekSize",
				new Object[] { jugeNo, proPlanId, gxPlanNo });
	}

	/***
	 * 查询全程途径码
	 * 
	 * @param orderPk
	 * @return
	 */
	public CoreReturnObject doQueryProcessSeq(String orderPk) {
		return this.getDataBySqlID("SurfaceInspectionResult.doQueryProcessSeq",
				new Object[] { orderPk });
	}

	/***
	 * 获取目标外径
	 * 
	 * @param jugeNo
	 * @return
	 */
	public CoreReturnObject doQueryMinMaxD(String jugeNo) {
		return this.getDataBySqlID("SurfaceInspectionResult.selectMinMaxD",
				new Object[] { jugeNo, jugeNo });
	}

	/***
	 * 获取目标壁厚
	 * 
	 * @param jugeNo
	 * @return
	 */
	public CoreReturnObject doQueryMinMaxS(String jugeNo) {
		return this.getDataBySqlID("SurfaceInspectionResult.selectMinMaxS",
				new Object[] { jugeNo, jugeNo, jugeNo, jugeNo });
	}

}
