package com.steering.mes.mcp.common;

import CoreFS.SA06.CoreReturnObject;
import CoreFS.SA08.CoreXmlSqlParsersFactory;
import CoreFS.SC01.CoreConstantData;
import com.steering.comm.converter.CoreConverter;
import com.steering.comm.converter.EntityTool;
import com.steering.comm.converter.QualityDesignTool;
import com.steering.comm.db.DBCommon;
import com.steering.comm.tools.StringTool;
import com.steering.mes.mcp.entity.*;
import com.steering.mes.mcp.entity.MchEntity.*;
import org.hsqldb.lib.StringUtil;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;

public class PlanService extends DBCommon {
	/**
	 * 修改长度
	 */
	@SuppressWarnings("unchecked")
	public CoreReturnObject updateAcLen(ArrayList<String> arr) {
		CoreReturnObject cro = new CoreReturnObject();
		Connection connection = this.getDao(CoreConstantData.sysbeanstr)
				.getConnection();
		try {
			String updatesql = " UPDATE PORT_HTT_BATCH_SAMPLE_RESULT SET ACT_LEN = ?, ACT_LEN_U = ? WHERE MAT_NO = ?";
			connection.setAutoCommit(false); // 取消自动提交事务
			PreparedStatement sql = connection.prepareStatement(updatesql);
			for (String json : arr) {
				PortHttBatchSampleResultEntity entity = EntityTool.getEntityByJSONStr(json, PortHttBatchSampleResultEntity.class);
				sql.setString(1, entity.getActLen());
				sql.setString(2, entity.getActLenU());
				sql.setString(3, entity.getMatNo());
				sql.addBatch();
				sql.executeBatch();
			}
			cro.setV_errMsg("操作成功");
			connection.commit();
		}
		catch (Exception e) {
			cro.setV_errMsg(e.getMessage());
			cro.setV_errCode(-1);
			if (connection != null) {
				try {
					connection.rollback(); // 回滚事务
				} catch (Exception e2) {
				}
			}
		} finally {
			try {
				if (connection != null && !connection.isClosed()) {
					connection.close();
				}
			} catch (Exception e2) {
			}
		}
		return cro;
    }
    /**
     * 查询产线
     *
     * @param Process
     * @return
     */
    public CoreReturnObject getPlineCode(String Process) {
        String sql = CoreXmlSqlParsersFactory
                .getSql("PlanService.getPlineCodeByProcess");
        if (!"".equals(Process)) {
            sql += " AND PROCESS_CODE = '" + Process + "'";
        }


        return this.getData(sql);
    }


    /**
	 *
	 *
     * @return
     */
    public CoreReturnObject getStorage() {
        String sql = CoreXmlSqlParsersFactory
                .getSql("PlanService.getStorage");
        return this.getData(sql);
    }


    /**
     * 查询热处理简单作业计划
     *
     * @param coupProcessPlan
     * @return
     */
    public CoreReturnObject getSingleRclPlan(HttPlan plan, String plinCode,
                                             String[] stats) {
        String sql = CoreXmlSqlParsersFactory
                .getSql("PlanService.HeatTreatme.GetSingleRclPlan");
        if (!plan.getHeatPlanNo().equals("")) {
            sql += " AND T.HEAT_PLAN_NO || '&' LIKE '%' || '"
                    + plan.getHeatPlanNo() + "' || '%'";
        }
        if (!plan.getJudgeStoveNo().equals("")) {
            sql += " AND T.JUDGE_STOVE_NO || '&' LIKE '%' || '"
                    + plan.getJudgeStoveNo() + "' || '%'";
        }
        // if (!plan.getPlanstatus().equals("")) {
        // sql += " AND T.PLANSTATUS ='" + plan.getPlanstatus() + "'";
        // }
        sql += CoreConverter.toSqlConditionString("T.PLANSTATUS", stats);

        sql += " AND T.PLINE_CODE ='" + plinCode + "'";
        sql += " ORDER BY T.PLANSTATUS DESC ) T3 ORDER BY T3.PRO_PLAN_ID,T3.GX_PLAN_NO,T3.HEAT_PLAN_NO  ASC";
        return this.getData(sql);
    }

    /**
     * 查询热处理简单作业计划
     *
     * @param
     * @return
     */
    public CoreReturnObject getSingleRclPlan(HttPlan plan, String[] plinCodes,
                                             String[] stats) {
        String sql = CoreXmlSqlParsersFactory
                .getSql("PlanService.HeatTreatme.GetSingleRclPlan");
        if (!plan.getHeatPlanNo().equals("")) {
            sql += " AND T.HEAT_PLAN_NO || '&' LIKE '%' || '"
                    + plan.getHeatPlanNo() + "' || '%'";
        }
        if (!plan.getJudgeStoveNo().equals("")) {
            sql += " AND T.JUDGE_STOVE_NO || '&' LIKE '%' || '"
                    + plan.getJudgeStoveNo() + "' || '%'";
        }
        sql += CoreConverter.toSqlConditionString("T.PLANSTATUS", stats);

        sql += CoreConverter.toSqlConditionString("T.PLINE_CODE", plinCodes);

        sql += " ORDER BY T.PLANSTATUS DESC ) T3 ORDER BY T3.PRO_PLAN_ID,T3.GX_PLAN_NO,T3.HEAT_PLAN_NO  ASC";
        return this.getData(sql);
    }

    public CoreReturnObject getSingleRclPlan(Boolean OnlyShowMain, String PlanID, String JudgeStove, String[] plinCodes,
                                             String[] stats, String Gx, String BesideStatus) {
        return getSingleRclPlan(OnlyShowMain, PlanID, JudgeStove, "", plinCodes,
                stats, Gx, BesideStatus);
    }

    /**
     * 查询热处理简单作业计划
     *
     * @param
     * @return
     */
    public CoreReturnObject getSingleRclPlan(Boolean OnlyShowMain, String PlanID, String JudgeStove, String FeedStove, String[] plinCodes,
                                             String[] stats, String Gx, String BesideStatus) {
        String sql = CoreXmlSqlParsersFactory
                .getSql(OnlyShowMain ? "PlanService.HeatTreatme.GetNewRclPla1" : "PlanService.HeatTreatme.GetNewRclPlan");

        String Beside = "00";
        if (OnlyShowMain) {
            String Columns = "";

            Columns += ",(SELECT SUM(PRO_NUM)  FROM HTT_LOADING_RESULT WHERE  HEAT_PLAN_NO = T.HEAT_PLAN_NO)  REAL_INDOUBLE_NUM";
            Columns += ",(SELECT SUM(PRO_WT)  FROM HTT_LOADING_RESULT WHERE  HEAT_PLAN_NO = T.HEAT_PLAN_NO)  REAL_INDOUBLE_WT";


            if (Gx.equals("600201")) {
                Beside = "00";
            } else if (Gx.equals("600202")) {
                Columns += ",(SELECT SUM(PRO_NUM)  FROM HTT_HHEAT_RESULT WHERE  HEAT_PLAN_NO = T.HEAT_PLAN_NO)  PRO_COUNT";
                Columns += ",(SELECT SUM(PRO_WT)  FROM HTT_HHEAT_RESULT WHERE  HEAT_PLAN_NO = T.HEAT_PLAN_NO)  PRO_WEIGHT";


                Beside = "10";
			}
			else if (Gx.equals("600203")){
                Columns += ",(SELECT SUM(PRO_NUM)  FROM HTT_QUENCHING_RESULT WHERE  HEAT_PLAN_NO = T.HEAT_PLAN_NO)  PRO_COUNT";
                Columns += ",(SELECT SUM(PRO_WT)  FROM HTT_QUENCHING_RESULT WHERE  HEAT_PLAN_NO = T.HEAT_PLAN_NO)  PRO_WEIGHT";

                Beside = "10";
			}
			else if (Gx.equals("600204")){
                Columns += ",(SELECT SUM(PRO_NUM)  FROM HTT_LHEAT_RESULT WHERE  HEAT_PLAN_NO = T.HEAT_PLAN_NO)  PRO_COUNT";
                Columns += ",(SELECT SUM(PRO_WT)  FROM HTT_LHEAT_RESULT WHERE  HEAT_PLAN_NO = T.HEAT_PLAN_NO)  PRO_WEIGHT";

                Beside = "10";
			}
			else if (Gx.equals("600205")){
                Columns += ",(SELECT SUM(PRO_NUM)  FROM HTT_SIZING_RESULT WHERE  HEAT_PLAN_NO = T.HEAT_PLAN_NO)  PRO_COUNT";
                Columns += ",(SELECT SUM(PRO_WT)  FROM HTT_SIZING_RESULT WHERE  HEAT_PLAN_NO = T.HEAT_PLAN_NO)  PRO_WEIGHT";

                Beside = "40";
			}
			else if (Gx.equals("600206")){
                Columns += ",(SELECT SUM(PRO_NUM)  FROM HTT_HLSTRAIGHTEN_RESULT WHERE  HEAT_PLAN_NO = T.HEAT_PLAN_NO)  PRO_COUNT";
                Columns += ",(SELECT SUM(PRO_WT)  FROM HTT_HLSTRAIGHTEN_RESULT WHERE  HEAT_PLAN_NO = T.HEAT_PLAN_NO)  PRO_WEIGHT";

                Beside = "40";
			}
			else if (Gx.equals("600207")){
                Columns += ",(SELECT SUM(PRO_NUM)  FROM HTT_CLSTRAIGHTEN_RESULT WHERE  HEAT_PLAN_NO = T.HEAT_PLAN_NO)  PRO_COUNT";
                Columns += ",(SELECT SUM(PRO_WT)  FROM HTT_CLSTRAIGHTEN_RESULT WHERE  HEAT_PLAN_NO = T.HEAT_PLAN_NO)  PRO_WEIGHT";

                Beside = "40";
			}
			else if (Gx.equals("600208")){
                Columns += ",(SELECT SUM(CHECKPIECES)  FROM HTT_APPEARANCECHECK_RESULT WHERE  HEAT_PLAN_NO = T.HEAT_PLAN_NO)  PRO_COUNT";

                Beside = "70";
			}
			else if (Gx.equals("600209")){
                Columns += ",(SELECT SUM(TESTING_NUM)  FROM HTT_CRACK_DETECTION_ET WHERE  HEAT_PLAN_NO = T.HEAT_PLAN_NO)  PRO_COUNT";

                Beside = "80";
            }


            sql = sql.replace("@Columns", Columns);
            sql = sql + " WHERE 1 =1";

            if (!Gx.equals("600209")) sql += " AND T.PROCESS_CODE_C!='B024' ";
        }


        if (!PlanID.equals("")) {
            sql += " AND T.HEAT_PLAN_NO || '&' LIKE '%' || '"
                    + PlanID + "' || '%'";
        }
        if (!JudgeStove.equals("")) {
            sql += " AND T.JUDGE_STOVE_NO || '&' LIKE '%' || '"
                    + JudgeStove + "' || '%'";
        }

        if (!FeedStove.equals("")) {
            sql += " AND T.FEED_HEAT_NO || '&' LIKE '%' || '"
                    + FeedStove + "' || '%'";
        }

        sql += CoreConverter.toSqlConditionString("T.PLANSTATUS", stats);


        sql += CoreConverter.toSqlConditionString("(NVL(T.PLINE_CODE_W,T.PLINE_CODE))", plinCodes);


/*		if(BesideStatus.equals("0")){
			sql += " AND (T.BESIDE_STATUS < '" + Beside +"' OR  T.BESIDE_STATUS IS NULL) ";
		}else 	if(BesideStatus.equals("1")) {
			sql += " AND (T.BESIDE_STATUS >= '" + Beside +"' AND  T.BESIDE_STATUS IS NOT NULL) ";
		}*/

        if (BesideStatus.equals("0")) {
            sql += " AND (SELECT COUNT(1) FROM HTT_COM_INFO  WHERE HEAT_PLAN_NO=T.HEAT_PLAN_NO AND PROCESS_SEQ = T.PROCESS_SEQ   AND  STATION_CODE='" + Gx + "' AND STATION_STATUS='2')<=0 ";

            sql += " AND ('" + Gx + "'  !='600201' OR  T.IF_MATCH_ODD != '2' ) ";

        } else if (BesideStatus.equals("1")) {
            sql += "AND (SELECT COUNT(1) FROM HTT_COM_INFO  WHERE HEAT_PLAN_NO=T.HEAT_PLAN_NO AND PROCESS_SEQ = T.PROCESS_SEQ AND  STATION_CODE='" + Gx + "' AND STATION_STATUS='2')>0 ";
        }

        sql += OnlyShowMain ? " ORDER BY  T.PLINE_CODE,TO_NUMBER(S.GX_PRO_SEQ),T.JUDGE_STOVE_NO, T.JUDGE_STOVE_NO, T.BATCH_NO ASC" :

                " ORDER BY  T.PLINE_CODE,TO_NUMBER(S.GX_PRO_SEQ),T.JUDGE_STOVE_NO, T.JUDGE_STOVE_NO,T2.BATCH_NO ASC";
        return this.getData(sql);
    }


    public CoreReturnObject getSingleJGPlan(Boolean OnlyShowMain, String PlanID, String JudgeStove, String[] plinCodes,
                                            String[] stats, String Gx, String BesideStatus) {
        return getSingleJGPlan(OnlyShowMain, PlanID, JudgeStove, plinCodes,
                stats, Gx, BesideStatus, "");

    }


    public CoreReturnObject getSingleJGPlan(Boolean OnlyShowMain, String PlanID, String JudgeStove, String[] plinCodes,
                                            String[] stats, String Gx, String BesideStatus, String CheckStation, String OtherStatus) {
        return getSingleJGPlan(OnlyShowMain, PlanID, JudgeStove, "", plinCodes, stats, Gx, BesideStatus, CheckStation, OtherStatus);
    }

    /**
     * 查询热处理简单作业计划
     *
     * @param
     * @return
     */
    public CoreReturnObject getSingleJGPlan(Boolean OnlyShowMain, String PlanID, String JudgeStove, String FeedStove, String[] plinCodes,
                                            String[] stats, String Gx, String BesideStatus, String CheckStation, String OtherStatus) {

        String sql = "";


			sql = CoreXmlSqlParsersFactory
                    .getSql(OnlyShowMain ? "PlanService.GetNewRclPlanOther" : "PlanService.GetNewJGXPlanLoad");

        String Columns = "";
        String Where = "";

        Columns += ",(SELECT SUM(PRO_NUM)  FROM MCH_LOADING_RESULT WHERE  HEAT_PLAN_NO = T.HEAT_PLAN_NO AND BATCH_NO = T.BATCH_NO )  REAL_INDOUBLE_NUM";
        Columns += ",(SELECT SUM(PRO_WT)  FROM MCH_LOADING_RESULT WHERE  HEAT_PLAN_NO = T.HEAT_PLAN_NO AND BATCH_NO = T.BATCH_NO)  REAL_INDOUBLE_WT";

        Columns += ",(SELECT MAX(BESIDE_TIME) FROM MCH_COM_INFO WHERE  HEAT_PLAN_NO = T.HEAT_PLAN_NO AND BATCH_NO = T.BATCH_NO AND STATION_CODE = '" + Gx + "' )  BESIDE_DATE";
        Columns += ",DECODE((SELECT MAX(STATION_STATUS) FROM MCH_COM_INFO WHERE  HEAT_PLAN_NO = T.HEAT_PLAN_NO AND BATCH_NO = T.BATCH_NO AND STATION_CODE = '" + Gx + "' ),'2','已结炉','未结炉')  CURRENT_STATUS";

        Columns += ", (SELECT (SELECT BASENAME FROM COM_BASE_INFO " +
                "WHERE BASECODE =  GET_SHIPPED_STATE(C.DESGIN_KEY, T.INDEX_SEQ, 'B')) STATUS " +
                " FROM CRAFT_ORD_DESIGN C, PLN_SALEORD E " +
                "WHERE E.ORD_LN_PK = C.ORD_LN_PK AND E.ORD_LN_DLY_PK = T.ORD_LN_DLY_PK   " +
                "AND C.CRAFT_SEQ = T.CRAFT_SEQ AND ROWNUM = 1) STATUS";

        Columns += ",(SELECT PRODUC_TYPE FROM COM_BASE_PRODUCT WHERE PRODUCCODE = T.PRODUCCODE)  PRODUC_TYPE";

        if (Gx.equals("701301")) {

            Where += " AND T.IF_MATCH_ODD != '2' ";

        } else if (Gx.equals("701302")) {
            Columns += ",(SELECT SUM(TESTING_NUM)  FROM HTT_CRACK_DETECTION_ET WHERE  HEAT_PLAN_NO = T.HEAT_PLAN_NO AND BATCH_NO = T.BATCH_NO)  OPERATE_COUNT";
            Columns += ",(SELECT SUM(TESTING_WT)  FROM HTT_CRACK_DETECTION_ET WHERE  HEAT_PLAN_NO = T.HEAT_PLAN_NO AND BATCH_NO = T.BATCH_NO)  OPERATE_WEIGHT";
            Where += " AND T2.PER_STATUS IS NOT NULL";
        } else if (Gx.equals("701303")) {
            Columns += ",(SELECT SUM(PRO_NUM)  FROM MCH_CUT_RESULT WHERE  HEAT_PLAN_NO = T.HEAT_PLAN_NO AND BATCH_NO = T.BATCH_NO)  OPERATE_COUNT";
            Columns += ",(SELECT SUM(PRO_WT)  FROM MCH_CUT_RESULT WHERE  HEAT_PLAN_NO = T.HEAT_PLAN_NO AND BATCH_NO = T.BATCH_NO)  OPERATE_WEIGHT";
            Where += " AND T2.PER_STATUS IS NOT NULL";
            Where += " AND T.OUTNUM_CUT>1 ";
        } else if (Gx.equals("701304")) {
            Columns += ",(SELECT SUM(PRO_NUM)  FROM MCH_THREADER_RESULT WHERE  HEAT_PLAN_NO = T.HEAT_PLAN_NO AND BATCH_NO = T.BATCH_NO)  OPERATE_COUNT";
            Columns += ",(SELECT SUM(PRO_WT)  FROM MCH_THREADER_RESULT WHERE  HEAT_PLAN_NO = T.HEAT_PLAN_NO AND BATCH_NO = T.BATCH_NO)  OPERATE_WEIGHT";
            Where += " AND T2.PER_STATUS IS NOT NULL";
        } else if (Gx.equals("701305")) {
            Where += " AND T2.PER_STATUS IS NOT NULL";
            Columns += ",(SELECT SUM(PRO_NUM)  FROM MCH_HREAD_RESULT WHERE  HEAT_PLAN_NO = T.HEAT_PLAN_NO AND BATCH_NO = T.BATCH_NO)  OPERATE_COUNT";
            Columns += ",(SELECT SUM(PRO_WT)  FROM MCH_HREAD_RESULT WHERE  HEAT_PLAN_NO = T.HEAT_PLAN_NO AND BATCH_NO = T.BATCH_NO)  OPERATE_WEIGHT";


            if (OtherStatus.equals("0")) {
                Where += " AND (NVL((SELECT SUM(PRO_NUM) FROM MCH_HREAD_RESULT WHERE HEAT_PLAN_NO = T.HEAT_PLAN_NO AND BATCH_NO = T2.BATCH_NO AND MACHINE_NO = '1'),0) \n" +
                        "< (SELECT COUNT(1) FROM   PORT_MCH_BATCH_SAMPLE_RESULT  WHERE HEAT_PLAN_NO = T.HEAT_PLAN_NO AND BATCH_NO = T2.BATCH_NO AND VALIDFLAG = '1') " +
                        "OR NVL((SELECT SUM(PRO_NUM) FROM MCH_HREAD_RESULT WHERE HEAT_PLAN_NO = T.HEAT_PLAN_NO AND BATCH_NO = T2.BATCH_NO AND MACHINE_NO = '2'),0) \n" +
                        "< (SELECT COUNT(1) FROM   PORT_MCH_BATCH_SAMPLE_RESULT  WHERE HEAT_PLAN_NO = T.HEAT_PLAN_NO AND BATCH_NO = T2.BATCH_NO AND VALIDFLAG = '1'))";

            }
            if (OtherStatus.equals("1")) {
                Where += " AND NVL((SELECT SUM(PRO_NUM) FROM MCH_HREAD_RESULT WHERE HEAT_PLAN_NO = T.HEAT_PLAN_NO AND BATCH_NO = T2.BATCH_NO AND MACHINE_NO = '1'),0) \n" +
                        ">= (SELECT COUNT(1) FROM   PORT_MCH_BATCH_SAMPLE_RESULT  WHERE HEAT_PLAN_NO = T.HEAT_PLAN_NO AND BATCH_NO = T2.BATCH_NO AND VALIDFLAG = '1') " +
                        "AND NVL((SELECT SUM(PRO_NUM) FROM MCH_HREAD_RESULT WHERE HEAT_PLAN_NO = T.HEAT_PLAN_NO AND BATCH_NO = T2.BATCH_NO AND MACHINE_NO = '2'),0) \n" +
                        ">= (SELECT COUNT(1) FROM   PORT_MCH_BATCH_SAMPLE_RESULT  WHERE HEAT_PLAN_NO = T.HEAT_PLAN_NO AND BATCH_NO = T2.BATCH_NO AND VALIDFLAG = '1')";

            }
            if (OtherStatus.equals("3")) {
                Where += " AND (SELECT COUNT(1) FROM MCH_COM_INFO  WHERE HEAT_PLAN_NO=T.HEAT_PLAN_NO AND BATCH_NO=T2.BATCH_NO AND  STATION_CODE='" + Gx + "' AND STATION_STATUS='2')<=0 ";

            }

            if (OtherStatus.equals("4")) {
                Where += " AND (SELECT COUNT(1) FROM MCH_COM_INFO  WHERE HEAT_PLAN_NO=T.HEAT_PLAN_NO AND BATCH_NO=T2.BATCH_NO AND  STATION_CODE='" + Gx + "' AND STATION_STATUS='2')>0 ";

            }


        } else if (Gx.equals("701306")) {
            Where += " AND T2.PER_STATUS IS NOT NULL";
            Columns += ",(SELECT SUM(PRO_NUM)  FROM MCH_TWISTINGLY_RESULT WHERE  HEAT_PLAN_NO = T.HEAT_PLAN_NO AND BATCH_NO = T.BATCH_NO)  OPERATE_COUNT";
            Columns += ",(SELECT SUM(PRO_WT)  FROM MCH_TWISTINGLY_RESULT WHERE  HEAT_PLAN_NO = T.HEAT_PLAN_NO AND BATCH_NO = T.BATCH_NO)  OPERATE_WEIGHT";

        } else if (Gx.equals("701307")) {
            Where += " AND T2.PER_STATUS IS NOT NULL";
            Columns += ",(SELECT SUM(PRO_NUM)  FROM MCH_PATH_RESULT WHERE  HEAT_PLAN_NO = T.HEAT_PLAN_NO AND BATCH_NO = T.BATCH_NO)  OPERATE_COUNT";
            Columns += ",(SELECT SUM(PRO_WT)  FROM MCH_PATH_RESULT WHERE  HEAT_PLAN_NO = T.HEAT_PLAN_NO AND BATCH_NO = T.BATCH_NO)  OPERATE_WEIGHT";
        } else if (Gx.equals("701308")) {
            Where += " AND T2.PER_STATUS IS NOT NULL";
            Columns += ",(SELECT SUM(PRO_NUM)  FROM MCH_WATERGAGE_RESULT WHERE  HEAT_PLAN_NO = T.HEAT_PLAN_NO AND BATCH_NO = T.BATCH_NO)  OPERATE_COUNT";
            Columns += ",(SELECT SUM(PRO_WT)  FROM MCH_WATERGAGE_RESULT WHERE  HEAT_PLAN_NO = T.HEAT_PLAN_NO AND BATCH_NO = T.BATCH_NO)  OPERATE_WEIGHT";
        } else if (Gx.equals("701309")) {
            Where += " AND T2.PER_STATUS IS NOT NULL";
            Columns += ",(SELECT SUM(PRO_NUM)  FROM MCH_CHAMFERING_RESULT WHERE  HEAT_PLAN_NO = T.HEAT_PLAN_NO AND BATCH_NO = T.BATCH_NO)  OPERATE_COUNT";
            Columns += ",(SELECT SUM(PRO_WT)  FROM MCH_CHAMFERING_RESULT WHERE  HEAT_PLAN_NO = T.HEAT_PLAN_NO AND BATCH_NO = T.BATCH_NO)  OPERATE_WEIGHT";
        } else if (Gx.equals("701310")) {
            Where += " AND T2.PER_STATUS IS NOT NULL";
            Columns += ",(SELECT SUM(PRO_NUM)  FROM MCH_MEASURE_RESULT WHERE  HEAT_PLAN_NO = T.HEAT_PLAN_NO AND BATCH_NO = T.BATCH_NO)  OPERATE_COUNT";
            Columns += ",(SELECT SUM(PRO_WT)  FROM MCH_MEASURE_RESULT WHERE  HEAT_PLAN_NO = T.HEAT_PLAN_NO AND BATCH_NO = T.BATCH_NO)  OPERATE_WEIGHT";
            Columns += ",(SELECT COUNT(1) FROM (SELECT JUDGE_STOVE_NO, BATCH_NO,PLINE_CODE FROM RTD_MEASURE_POSDATA WHERE FLAG ='00' GROUP BY JUDGE_STOVE_NO, BATCH_NO,MAT_NO,PLINE_CODE) WHERE  JUDGE_STOVE_NO =  T.JUDGE_STOVE_NO AND (BATCH_NO = T.BATCH_NO OR T.PLINE_CODE='C092') AND PLINE_CODE= T.PLINE_CODE)  MEASURE_COUNT ";
        }
        else if (Gx.equals("701312")) {
            Where += " AND T2.PER_STATUS IS NOT NULL";
            Columns += ",(SELECT SUM(PRO_NUM)  FROM MCH_BUNDLING_RESULT WHERE  HEAT_PLAN_NO = T.HEAT_PLAN_NO AND BATCH_NO = T.BATCH_NO)  OPERATE_COUNT";
            Columns += ",(SELECT SUM(PRO_WT)  FROM MCH_BUNDLING_RESULT WHERE  HEAT_PLAN_NO = T.HEAT_PLAN_NO AND BATCH_NO = T.BATCH_NO)  OPERATE_WEIGHT";

		}
		else if (Gx.equals("701313")){
            Where += " AND T2.PER_STATUS IS NOT NULL";
            Columns += ",(SELECT SUM(PRO_NUM)  FROM MCH_FINAL_CHECK_RESULT WHERE  HEAT_PLAN_NO = T.HEAT_PLAN_NO AND BATCH_NO = T.BATCH_NO)  OPERATE_COUNT";
            Columns += ",(SELECT SUM(PRO_WT)  FROM MCH_FINAL_CHECK_RESULT WHERE  HEAT_PLAN_NO = T.HEAT_PLAN_NO AND BATCH_NO = T.BATCH_NO)  OPERATE_WEIGHT";

            //	Where += "  AND EXISTS (SELECT 1 FROM PORT_MCH_BATCH_SAMPLE_RESULT WHERE  HEAT_PLAN_NO = T.HEAT_PLAN_NO AND PHY_BATCH_NO = T2.BATCH_NO AND MEASURING_SEQ IS NOT NULL ) ";

            Columns += ", \n" +
                    "DECODE((SELECT MAX(APPROVAL_STATUS) FROM MCH_FINAL_CHECK_TREATMENT R ,MCH_FINAL_CHECK_RESULT D WHERE D.HEAT_PLAN_NO = T.HEAT_PLAN_NO AND D.BATCH_NO = T.BATCH_NO \n" +
                    "AND D.RESULT_NO = R.RESULT_NO),'0','未反馈','1','已反馈','2','已验证','') PER_STATUS ";

            Columns += ", ( DECODE((SELECT COUNT(1)\n" +
                    "                FROM MCH_FINAL_CHECK_TREATMENT \n" +
                    "               WHERE RESULT_NO IN\n" +
                    "                     (SELECT RESULT_NO\n" +
                    "                        FROM MCH_FINAL_CHECK_RESULT\n" +
                    "                       WHERE HEAT_PLAN_NO = T.HEAT_PLAN_NO\n" +
                    "                         AND BATCH_NO = T.BATCH_NO)\n" +
                    "                 AND APPROVAL_STATUS != '2'),\n" +
                    "              0,\n" +
                    "              DECODE((SELECT COUNT(1)\n" +
                    "                       FROM PORT_MCH_BATCH_SAMPLE_RESULT P\n" +
                    "                      WHERE HEAT_PLAN_NO = T.HEAT_PLAN_NO\n" +
                    "                        AND BATCH_NO = T.BATCH_NO\n" +
                    "                             AND  (SELECT COUNT(1)\n" +
                    "           FROM MCH_FINAL_CHECK_RESULT R, MCH_FINAL_CHECK_RESULT_MAT_NO R1\n" +
                    "          WHERE R.RESULT_NO = R1.RESULT_NO\n" +
                    "            AND R.HEAT_PLAN_NO = P.HEAT_PLAN_NO\n" +
                    "            AND R.BATCH_NO = P.PHY_BATCH_NO\n" +
                    "            AND P.MAT_NO = R1.MAT_NO) = '0'   AND VALIDFLAG ='1' AND (MAT_STATUS ='00' OR MAT_STATUS ='20') ),\n" +
                    "                     0,\n" +
                    "                     DECODE((SELECT COUNT(1)\n" +
                    "                              FROM MCH_FINAL_CHECK_TREATMENT \n" +
                    "                             WHERE RESULT_NO IN\n" +
                    "                                   (SELECT RESULT_NO\n" +
                    "                                      FROM MCH_FINAL_CHECK_RESULT\n" +
                    "                                     WHERE HEAT_PLAN_NO = T.HEAT_PLAN_NO\n" +
                    "                                       AND BATCH_NO = T.BATCH_NO)\n" +
                    "                               AND APPROVAL_STATUS = '2'),\n" +
                    "                            0,\n" +
                    "                            '合格',\n" +
                    "                            '处置合格')\n" +
                    "                    ,\n" +
                    "                     ''),\n" +
                    "              '不合格')) BESIDE_STATUS ";

            Columns += ",(SELECT SUM(PRO_NUM)  FROM MCH_MEASURE_RESULT WHERE  HEAT_PLAN_NO = T.HEAT_PLAN_NO AND BATCH_NO = T.BATCH_NO)  Pro_Count";
            Columns += ",(SELECT SUM(PRO_WT)  FROM MCH_MEASURE_RESULT WHERE  HEAT_PLAN_NO = T.HEAT_PLAN_NO AND BATCH_NO = T.BATCH_NO)  Pro_Weight";
            Columns += ",(SELECT MIN(PRO_TIME)  FROM MCH_MEASURE_RESULT WHERE  HEAT_PLAN_NO = T.HEAT_PLAN_NO AND BATCH_NO = T.BATCH_NO)  PRO_DATE";


            if (OtherStatus.equals("0")) {
                Where += " AND (SELECT COUNT(1)\n" +
                        "                       FROM PORT_MCH_BATCH_SAMPLE_RESULT P\n" +
                        "                      WHERE HEAT_PLAN_NO = T.HEAT_PLAN_NO\n" +
                        "                        AND BATCH_NO = T2.BATCH_NO\n" +
                        "                              AND  (SELECT COUNT(1)\n" +
                        "           FROM MCH_FINAL_CHECK_RESULT R, MCH_FINAL_CHECK_RESULT_MAT_NO R1\n" +
                        "          WHERE R.RESULT_NO = R1.RESULT_NO\n" +
                        "            AND R.HEAT_PLAN_NO = P.HEAT_PLAN_NO\n" +
                        "            AND R.BATCH_NO = P.PHY_BATCH_NO\n" +
                        "            AND P.MAT_NO = R1.MAT_NO) = '0'   AND VALIDFLAG ='1' AND (MAT_STATUS ='00' OR MAT_STATUS ='20')) >0";


            }
            if (OtherStatus.equals("1")) {
                Where += " AND T.MODEL_CODE NOT IN ('C070','C001','C028','C330')";


            }
            if (OtherStatus.equals("2")) {
                Where += " AND T.MODEL_CODE IN ('C070','C001','C028','C330')";

            }

        } else if (Gx.equals("701314")) {
            Where += " AND T2.PER_STATUS IS NOT NULL";
            Columns += ",(SELECT SUM(PRO_NUM)  FROM MCH_REMANENCE_RESULT WHERE  HEAT_PLAN_NO = T.HEAT_PLAN_NO AND BATCH_NO = T.BATCH_NO)  OPERATE_COUNT";
            Columns += ",(SELECT SUM(PRO_WT)  FROM MCH_REMANENCE_RESULT WHERE  HEAT_PLAN_NO = T.HEAT_PLAN_NO AND BATCH_NO = T.BATCH_NO)  OPERATE_WEIGHT";

        }



        sql = sql.replace("@Columns", Columns);



        if (!PlanID.equals("")) {
            Where += " AND T.HEAT_PLAN_NO  LIKE '"
                    + PlanID + "' || '%'";
        }
        if (!JudgeStove.equals("")) {
            Where += " AND T.JUDGE_STOVE_NO LIKE '"
                    + JudgeStove + "' || '%'";
        }

        if (!FeedStove.equals("")) {
            Where += " AND T.FEED_HEAT_NO LIKE '"
                    + FeedStove + "' || '%'";
        }

        if (JudgeStove.equals("") && FeedStove.equals("") && Gx.equals("701313")) {

            stats = null;

            Where += " AND   (SELECT SUM(PRO_NUM) " +
                    " FROM MCH_MEASURE_RESULT WHERE  HEAT_PLAN_NO = T.HEAT_PLAN_NO AND BATCH_NO = T2.BATCH_NO) >0";

            Where += " AND EXISTS (SELECT 1 FROM MCH_MEASURE_RESULT WHERE PRO_TIME > TO_DATE('2019-07-01 00:00:00', 'YYYY-MM-DD HH24:MI:SS') " +
                    "AND   HEAT_PLAN_NO = T.HEAT_PLAN_NO AND BATCH_NO = T2.BATCH_NO)";
        }

        if (!CheckStation.equals("")) {

            Where += " AND NVL(T2.PLINE_CODE_W,T2.PLINE_CODE) IN (SELECT PLINE_CODE FROM COM_BASE_PLINE WHERE CHECK_STATION = '" + CheckStation + "')";
        }

        Where += CoreConverter.toSqlConditionString("T.PLANSTATUS", stats);

        Where += CoreConverter.toSqlConditionString("NVL(T2.PLINE_CODE_W,T2.PLINE_CODE) ", plinCodes);


        if (BesideStatus.equals("0")) {
            Where += " AND (SELECT COUNT(1) FROM MCH_COM_INFO  WHERE HEAT_PLAN_NO=T.HEAT_PLAN_NO AND BATCH_NO=T2.BATCH_NO AND  STATION_CODE='" + Gx + "' AND STATION_STATUS='2')<=0 ";

        } else if (BesideStatus.equals("1")) {
            Where += "AND (SELECT COUNT(1) FROM MCH_COM_INFO  WHERE HEAT_PLAN_NO=T.HEAT_PLAN_NO AND BATCH_NO=T2.BATCH_NO AND  STATION_CODE='" + Gx + "' AND STATION_STATUS='2')>0 ";
        }
        sql = sql.replace("@Where", Where);
        return this.getData(sql);
        
    }


    /**
     * 查询热处理简单作业计划
     *
     * @param
     * @return
     */
    public CoreReturnObject getSingleJGPlan(Boolean OnlyShowMain, String PlanID, String JudgeStove, String[] plinCodes,
                                            String[] stats, String Gx, String BesideStatus, String CheckStation) {
        return this.getSingleJGPlan(OnlyShowMain, PlanID, JudgeStove, plinCodes,
                stats, Gx, BesideStatus, CheckStation, "");
    }



    /**
     * 查询加工简单作业计划
     *
     * @param coupProcessPlan
     * @return
     */
    public CoreReturnObject getSingleJGPlan(String txtZyBatchId, String txtRollBatchId,
                                            String[] plinCodes, String dobeside, String index, String slgx) {
        String sql = CoreXmlSqlParsersFactory
                .getSql("PlanService.HeatTreatme.GetSingleJGPlan");
        if (!txtRollBatchId.equals("")) {
            sql += " AND T.HEAT_PLAN_NO || '&' LIKE '%' || '"
                    + txtRollBatchId + "' || '%'";
        }
        if (!txtZyBatchId.equals("")) {
            sql += " AND T.JUDGE_STOVE_NO || '&' LIKE '%' || '"
                    + txtZyBatchId + "' || '%'";
        }
        // if (!plan.getPlanstatus().equals("")) {
        // sql += " AND T.PLANSTATUS ='" + plan.getPlanstatus() + "'";
        // }
//		sql += CoreConverter.toSqlConditionString("T.PLANSTATUS", stats);

		if(index.equals("0"))
		{
			if(slgx.equals("701301"))
			{
                sql += " AND NVL(T.BESIDE_STATUS,'/') < NVL('" + dobeside + "','/')";
			}else
			{
                sql += " AND NVL(T.BESIDE_STATUS,'/') < '" + dobeside + "' AND NVL(T.BESIDE_STATUS,'/') !=NVL('11','/') ";
            }
        } else {
            sql += " AND NVL(T.BESIDE_STATUS,'/') >= NVL('" + dobeside + "','/') AND NVL(T.BESIDE_STATUS,'/') !=NVL('11','/')";
        }
        //sql += " AND T.PLINE_CODE ='" + plinCode + "'";
        sql += CoreConverter.toSqlConditionString("T.PLINE_CODE", plinCodes);
        sql += " ORDER BY T.PLANSTATUS DESC ) T3 ORDER BY T3.BATCH_NO,T3.OUTNUM_CUT,t3.HEAT_PLAN_SQE,T3.BATCH_GROUD_NO,T3.PRO_PLAN_ID,t3.JUDGE_STOVE_NO,T3.GX_PLAN_NO,T3.HEAT_PLAN_NO  ASC";
        return this.getData(sql);
    }

    /**
     * 查询加工简单作业计划(分切后的)
     *
     * @param coupProcessPlan
     * @return
     */
    public CoreReturnObject getSingleJGPlancut(String txtZyBatchId, String txtRollBatchId,
                                               String[] plinCode, String dobeside, String index) {
        String sql = CoreXmlSqlParsersFactory
                .getSql("PlanService.HeatTreatme.GetSingleJGPlancut");
        if (!txtRollBatchId.equals("")) {
            sql += " AND T.HEAT_PLAN_NO || '&' LIKE '%' || '"
                    + txtRollBatchId + "' || '%'";
        }
        if (!txtZyBatchId.equals("")) {
            sql += " AND T.JUDGE_STOVE_NO || '&' LIKE '%' || '"
                    + txtZyBatchId + "' || '%'";
        }
        // if (!plan.getPlanstatus().equals("")) {
        // sql += " AND T.PLANSTATUS ='" + plan.getPlanstatus() + "'";
        // }
        //sql += CoreConverter.toSqlConditionString("T.PLANSTATUS", stats);
		if(index.equals("0"))
		{
            sql += " AND NVL(T.BESIDE_STATUS,'/') < NVL('" + dobeside + "','/') AND NVL(T.BESIDE_STATUS,'/') !=NVL('11','/')";
        } else {
            sql += " AND NVL(T.BESIDE_STATUS,'/') >= NVL('" + dobeside + "','/')";
        }
        //sql += " AND T.PLINE_CODE ='" + plinCode + "'";
        sql += CoreConverter.toSqlConditionString("T.PLINE_CODE", plinCode);
        sql += " ORDER BY T.PLANSTATUS DESC ) T3 ORDER BY T3.PRO_PLAN_ID,t3.JUDGE_STOVE_NO,T3.GX_PLAN_NO,T3.HEAT_PLAN_NO  ASC";
        return this.getData(sql);
    }
    /**
     * 根据计划号查询热处理详细计划
     *
     * @param planNo
     * @return
     */
    public CoreReturnObject getRclPlan(String heatNo) {
        return this.getDataBySqlID("PlanService.HeatTreatme.GetRclPlan",
                new Object[]{heatNo});
    }

    /**
     * 根据计划号查询墩拔扩详细计划
     *
     * @param planNo
     * @return
     */
    public CoreReturnObject getDbkPlan(PlnZyDbkMEntity plan, String plinCode,
                                       String[] stats) {
        String sql = CoreXmlSqlParsersFactory.getSql("PlanService.GetDbkPlan");
        if (!plan.getHeatPlanNo().equals("")) {
            sql += " AND T.HEAT_PLAN_NO || '&' LIKE '%' || '"
                    + plan.getHeatPlanNo() + "' || '%'";
        }
        if (!plan.getJudgeStoveNo().equals("")) {
            sql += " AND T.JUDGE_STOVE_NO || '&' LIKE '%' || '"
                    + plan.getJudgeStoveNo() + "' || '%'";
        }
        // if (!plan.getPlanstatus().equals("")) {
        // sql += " AND T.PLANSTATUS ='" + plan.getPlanstatus() + "'";
        // }
        sql += CoreConverter.toSqlConditionString("T.PLANSTATUS", stats);
        // if(isOnl.equals("1")){
        // sql += " AND T2.IS_ONLOAD_LINE ='" + isOnl + "'";
        // }

        sql += " AND T.PLINE_CODE ='" + plinCode + "'";
        sql += " ORDER BY T.GX_PRO_SEQ,T.PRO_PLAN_ID,T.GX_PLAN_NO,T.HEAT_PLAN_NO ASC";
        return this.getData(sql);

    }

    /**
     * 根据计划号查询墩拔扩详细计划
     *
     * @param planNo
     * @return
     */
    public CoreReturnObject getDbkPlan(PlnZyDbkMEntity plan, String[] plinCodes,
                                       String dobeside, String index, String[] stats) {
        String sql = CoreXmlSqlParsersFactory.getSql("PlanService.GetDbkPlan");
        if (!plan.getHeatPlanNo().equals("")) {
            sql += " AND T.HEAT_PLAN_NO || '&' LIKE '%' || '"
                    + plan.getHeatPlanNo() + "' || '%'";
        }
        if (!plan.getJudgeStoveNo().equals("")) {
            sql += " AND T.JUDGE_STOVE_NO || '&' LIKE '%' || '"
                    + plan.getJudgeStoveNo() + "' || '%'";
        }
        // if (!plan.getPlanstatus().equals("")) {
        // sql += " AND T.PLANSTATUS ='" + plan.getPlanstatus() + "'";
        // }
        sql += CoreConverter.toSqlConditionString("T.PLANSTATUS", stats);
        // if(isOnl.equals("1")){
        // sql += " AND T2.IS_ONLOAD_LINE ='" + isOnl + "'";
        // }
		 if(index.equals("0"))
	        {
			 if(dobeside.equals("40"))
			 {
                int dobe = 0;
                dobe = Integer.parseInt(dobeside) + 11;
                sql += " AND NVL(T.BESIDE_STATUS,'/') < NVL('" + dobe + "','/')";
            } else {
                sql += " AND NVL(T.BESIDE_STATUS,'/') < NVL('" + dobeside + "','/')";
            }
	        }else if(index.equals("1"))
	        {
	        	if(dobeside.equals("40"))
	        	{
                sql += " AND NVL(T.BESIDE_STATUS,'/') >= NVL('" + dobeside + "','/')";
                sql += " AND T.BESIDE_STATUS !='50'";
            } else {
                sql += " AND NVL(T.BESIDE_STATUS,'/') >= NVL('" + dobeside + "','/')";
            }
        }
        sql += CoreConverter.toSqlConditionString("T.PLINE_CODE", plinCodes);
        sql += " ORDER BY T.GX_PRO_SEQ,T.PRO_PLAN_ID,T.GX_PLAN_NO,T.HEAT_PLAN_NO ASC";
        return this.getData(sql);

    }

    /**
     * 墩拔库管号队列查询
     *
     * @param planNo
     * @return
     */
    public CoreReturnObject getQueryDbkPortVrp(String heatNo) {
        return this.getDataBySqlID("PlanService.getQueryDbkPortVrp",
                new Object[]{heatNo});
    }

    /**
     * 热处理管号队列查询
     *
     * @param planNo
     * @return
     */
    public CoreReturnObject getQueryDbkPortVrphot(String heatNo, Integer ProcessSeq) {
        return this.getDataBySqlID("PlanService.getQueryDbkPortVrp3",
                new Object[]{heatNo, ProcessSeq});
    }

    /**
     * 加工管号队列查询
     *
     * @param planNo
     * @return
     */
    public CoreReturnObject getQueryJGPortVrphot(String heatNo) {
        return this.getDataBySqlID("PlanService.getQueryJGPortVrp3",
                new Object[]{heatNo});
    }



    /**
     * 加工管号队列查询
     *
     * @param planNo
     * @return
     */
    public CoreReturnObject getQueryJGPortVrphot(String heatNo, String BatchNo) {
        return getQueryJGPortVrphot(heatNo, BatchNo, false);
    }

    /**
     * 加工管号队列查询
     *
     * @param planNo
     * @return
     */
    public CoreReturnObject getQueryJGPortVrphot(String heatNo, String BatchNo, Boolean OrderBy) {
        String sql = CoreXmlSqlParsersFactory
                .getSql("PlanService.getQueryJGPortMchNew");


        if (OrderBy) {
            sql += "ORDER BY T.MEASURING_SEQ, DECODE(MAT_STATUS,'10','1','30','1','0'), T.MAT_NO ASC";
        } else {
            sql += "ORDER BY  T.MAT_NO ASC";
        }

        return this.getData(sql, new Object[]{heatNo, BatchNo});
    }
    public CoreReturnObject getQueryDBPortVrphot(String heatNo, String BatchNo, Boolean OrderBy) {
        String sql = CoreXmlSqlParsersFactory
                .getSql("PlanService.getQueryDBPortMchNew");


        if (OrderBy) {
            sql += "ORDER BY T.MAT_NO, DECODE(MAT_STATUS,'10','1','30','1','0'), T.MAT_NO ASC";
        } else {
            sql += "ORDER BY  T.MAT_NO ASC";
        }

        return this.getData(sql, new Object[]{heatNo});
    }

    /**
     * 加工管号队列查询
     *
     * @param planNo
     * @return
     */
    public CoreReturnObject getQueryJGPortVrphotAll(String heatNo, String BatchNo, Boolean OrderBy) {
        String sql = CoreXmlSqlParsersFactory
                .getSql("PlanService.getQueryJGPortMchNewAll");


        if (OrderBy) {
            sql += "ORDER BY T.MEASURING_SEQ, DECODE(MAT_STATUS,'10','1','30','1','0'), T.MAT_NO ASC";
        } else {
            sql += "ORDER BY  T.MAT_NO ASC";
        }

        return this.getData(sql, new Object[]{heatNo, BatchNo});
    }

    /**
     * 加工管号队列查询
     *
     * @param planNo
     * @return
     */
    public CoreReturnObject getQueryJGPortVrphot(String heatNo, String BatchNo, String GroupNo) {
        return this.getDataBySqlID("PlanService.QueryLoadMchPort",
                new Object[]{BatchNo, GroupNo, heatNo});
    }

    /**
     * 查询墩拔库管号队列合格的支、吨
     *
     * @param planNo
     * @return
     */
    public CoreReturnObject getQueryDbkPortVrp1(String heatNo) {
        return this.getDataBySqlID("PlanService.getQueryDbkPortVrp1",
                new Object[]{heatNo});
    }

    public static PortVrpBatchSampleResultEntity getPortVrpBatchSampleResultEntity(String HeatID, String MatNo, Connection connection) throws SQLException {
        String sqlMatNo = CoreXmlSqlParsersFactory
                .getSql("PlanService.getQueryDbkPortVrp2");// 查询新增物料信息
        PreparedStatement psta = connection.prepareStatement(sqlMatNo);
        psta.setObject(1, HeatID);
        psta.setObject(2, MatNo);
        ResultSet rs = psta.executeQuery();
        PortVrpBatchSampleResultEntity PortVrpBatchSampleResultEntity = EntityTool.getEntityByRs(rs, PortVrpBatchSampleResultEntity.class);
        rs.close();
        psta.close();
        return PortVrpBatchSampleResultEntity;
    }

    public static PortHttBatchSampleResultEntity getPortHttBatchSampleResultEntity(String HeatID, String MatNo, Integer ProcessSeq, Connection connection) throws SQLException {
        String sqlMatNo = CoreXmlSqlParsersFactory
                .getSql("PlanService.getQueryRclPortHtt2");// 查询新增物料信息
        PreparedStatement psta = connection.prepareStatement(sqlMatNo);
        psta.setObject(1, HeatID);
        psta.setObject(2, ProcessSeq);
        psta.setObject(3, MatNo);
        ResultSet rs = psta.executeQuery();
        PortHttBatchSampleResultEntity PortHttBatchSampleResultEntity = EntityTool.getEntityByRs(rs, PortHttBatchSampleResultEntity.class);
        rs.close();
        psta.close();
        return PortHttBatchSampleResultEntity;
    }
    public static PortMchBatchSampleResultEntity getPortMchBatchSampleResultEntitydbk(String HeatID, String MatNo, Connection connection) throws SQLException {
        String sqlMatNo = CoreXmlSqlParsersFactory
                .getSql("PlanService.getQueryJgxPortMch2dbk");// 查询新增物料信息
        PreparedStatement psta = connection.prepareStatement(sqlMatNo);
        psta.setObject(1, HeatID);
        psta.setObject(2, MatNo);
        ResultSet rs = psta.executeQuery();
        PortMchBatchSampleResultEntity PortMchBatchSampleResultEntity = EntityTool.getEntityByRs(rs, PortMchBatchSampleResultEntity.class);
        rs.close();
        psta.close();
        return PortMchBatchSampleResultEntity;
    }

    public static PortMchBatchSampleResultEntity getPortMchBatchSampleResultEntity(String HeatID, String MatNo, Connection connection) throws SQLException {
        String sqlMatNo = CoreXmlSqlParsersFactory
                .getSql("PlanService.getQueryJgxPortMch2");// 查询新增物料信息
        PreparedStatement psta = connection.prepareStatement(sqlMatNo);
        psta.setObject(1, HeatID);
        psta.setObject(2, MatNo);
        ResultSet rs = psta.executeQuery();
        PortMchBatchSampleResultEntity PortMchBatchSampleResultEntity = EntityTool.getEntityByRs(rs, PortMchBatchSampleResultEntity.class);
        rs.close();
        psta.close();
        return PortMchBatchSampleResultEntity;
    }

    /**
     * 查询热处理管号队列合格的支、吨
     *
     * @param planNo
     * @return
     */
    public CoreReturnObject getQueryRCLPortVrp1(String heatNo) {
        return this.getDataBySqlID("PlanService.getQueryRCLPortVrp1",
                new Object[]{heatNo});
    }

    /**
     * 查询加工管号队列合格的支、吨
     *
     * @param planNo
     * @return
     */
    public CoreReturnObject getQueryRCLPortVrp2(String heatNo) {
        return this.getDataBySqlID("PlanService.getQueryJGPortVrp1",
                new Object[]{heatNo});
    }


    /**
     * 初始查询管号队列合格的支吨显示
     *
     * @param planNo
     * @return
     */
    public CoreReturnObject getQueryRCLPortVrp3(String heatNo, String outnumcut) {
        return this.getDataBySqlID("PlanService.getQueryJGPortVrp2",
                new Object[]{heatNo, outnumcut});
    }


	
    /**
     * 接箍计划简单查询
     *
	 * @param cutPlan
	 *            接箍计划实体
     * @return
     */
    public CoreReturnObject getSingleJGCutPlan(CoupCutPlan cutPlan,
                                               String plineCode) {
        Object[] params = new Object[]{plineCode, cutPlan.getJudgeStoveNo(),
                cutPlan.getBatchNo(), cutPlan.getLotNo()};
        String sql = CoreXmlSqlParsersFactory
                .getSql("PlanService.CutPlan.GetSingleJGCutPlan");
        // sql += CoreConverter.toSqlConditionString("T.PLINE_CODE", plineCode);
        sql += "  ORDER BY T.ZY_PLAN_ID";
        return this.getData(sql, params);
    }

    /**
     * 接箍计划详细查询
     *
	 * @param planNo
	 *            计划号
     * @return
     */
    public CoreReturnObject getJGCutPlan(String planNo) {
        Object[] params = new Object[]{planNo};
        return this.getDataBySqlID("PlanService.CutPlan.GetJGCutPlan", params);
    }

    /**
     * 接箍加工计划简单查询
     *
     * @param plan
     * @return
     */
    public CoreReturnObject getSingleJGProcessPlan(CoupProcessPlan plan,
                                                   String plineCode) {
        Object[] params = new Object[]{plineCode, plan.getLotNo(),
                plan.getHeatNo(), plan.getBatchNo()};
        String sql = CoreXmlSqlParsersFactory
                .getSql("PlanService.ProcessPlan.SingleJGProcessPlan");
        // sql += CoreConverter.toSqlConditionString("T.PLINE_CODE", plineCode);
        sql += "  ORDER BY T.ZY_PLAN_ID";
        return this.getData(sql, params);
    }

    /**
     * 查询工艺文件路径
     *
     * @param planNo
     * @return
     */
    public CoreReturnObject getCraftPathById(String CraftNo) {
        return this.getDataBySqlID("PlanService.ProcessPlan.getCraftPathById",
                new Object[]{CraftNo});
    }

    /**
     * 查询接箍计划信息
     *
     * @param con
     * @param sendPlanNo
     * @return
     * @throws SQLException
     */
    public static PlnZyJgEntity getSendPlanCInfo(Connection con, String planNo)
            throws SQLException {
        String sql = CoreXmlSqlParsersFactory
                .getSql("PlanService.CutPlan.GetJGCutPlan");
        PreparedStatement ps = con.prepareStatement(sql);
        ps.setObject(1, planNo);
        ResultSet rs = ps.executeQuery();
        List<PlnZyJgEntity> sendPlanCEntitys = EntityTool.getEntitysByRs(rs,
                PlnZyJgEntity.class);
        rs.close();
        ps.close();
        if (sendPlanCEntitys == null || sendPlanCEntitys.size() == 0) {
            return null;
        } else {
            for (PlnZyJgEntity sendPlanCEntity : sendPlanCEntitys) {
                QualityDesignTool.nullConverNullString(sendPlanCEntity);
            }
            return sendPlanCEntitys.get(0);
        }
    }


    /**
     * 查询热处理订单
     *
     * @param con
     * @param sendPlanNo
     * @return
     * @throws SQLException
     */
    public static PlnOrderRclSEntity getHttOrder(Connection con,
                                                 String PRO_PLAN_ID, String GX_PLAN_NO) throws SQLException {
        String sql = CoreXmlSqlParsersFactory
                .getSql("PlanService.HeatTreatme.GetHttOrder");
        PreparedStatement ps = con.prepareStatement(sql);
        ps.setObject(1, PRO_PLAN_ID);
        ps.setObject(2, GX_PLAN_NO);
        ResultSet rs = ps.executeQuery();
        List<PlnOrderRclSEntity> PlnOrderRclSEntity = EntityTool.getEntitysByRs(rs,
                PlnOrderRclSEntity.class);
        rs.close();
        ps.close();
        if (PlnOrderRclSEntity == null || PlnOrderRclSEntity.size() == 0) {
            return null;
        } else {
            for (PlnOrderRclSEntity sendPlanCEntity : PlnOrderRclSEntity) {
                QualityDesignTool.nullConverNullString(sendPlanCEntity);
            }
            return PlnOrderRclSEntity.get(0);
        }
    }



    /**
     * 查询加工线订单
     *
     * @param con
     * @param sendPlanNo
     * @return
     * @throws SQLException
     */
    public static PlnOrderJgxSEntity getMchOrder(Connection con,
                                                 String PRO_PLAN_ID, String GX_PLAN_NO) throws SQLException {
        String sql = CoreXmlSqlParsersFactory
                .getSql("PlanService.HeatTreatme.GetMchOrder");
        PreparedStatement ps = con.prepareStatement(sql);
        ps.setObject(1, PRO_PLAN_ID);
        ps.setObject(2, GX_PLAN_NO);
        ResultSet rs = ps.executeQuery();
        List<PlnOrderJgxSEntity> PlnOrderJgxSEntity = EntityTool.getEntitysByRs(rs,
                PlnOrderJgxSEntity.class);
        rs.close();
        ps.close();
        if (PlnOrderJgxSEntity == null || PlnOrderJgxSEntity.size() == 0) {
            return null;
        } else {
            for (PlnOrderJgxSEntity sendPlanCEntity : PlnOrderJgxSEntity) {
                QualityDesignTool.nullConverNullString(sendPlanCEntity);
            }
            return PlnOrderJgxSEntity.get(0);
        }
    }



    /**
     * 查询热处理计划信息
     *
     * @param con
     * @param sendPlanNo
     * @return
     * @throws SQLException
     */
    public static PlnZyRclMEntity getSendHttPlanCInfo(Connection con,
                                                      String heatNo) throws SQLException {
        String sql = CoreXmlSqlParsersFactory
                .getSql("PlanService.HeatTreatme.GetRclPlan");
        PreparedStatement ps = con.prepareStatement(sql);
        ps.setObject(1, heatNo);
        ResultSet rs = ps.executeQuery();
        List<PlnZyRclMEntity> sendPlanCEntitys = EntityTool.getEntitysByRs(rs,
                PlnZyRclMEntity.class);
        rs.close();
        ps.close();
        if (sendPlanCEntitys == null || sendPlanCEntitys.size() == 0) {
            return null;
        } else {
            for (PlnZyRclMEntity sendPlanCEntity : sendPlanCEntitys) {
                QualityDesignTool.nullConverNullString(sendPlanCEntity);
            }
            return sendPlanCEntitys.get(0);
        }
    }

    /**
     * 查询热处理计划从表信息
     *
     * @param con
     * @param sendPlanNo
     * @return
     * @throws SQLException
     */
    public static PlnZyRclCEntity getSendHttPlanCInfoC(Connection con,
                                                       String heatNo) throws SQLException {
        String sql = CoreXmlSqlParsersFactory
                .getSql("PlanService.HeatTreatme.GetRclPlanC");
        PreparedStatement ps = con.prepareStatement(sql);
        ps.setObject(1, heatNo);
        ResultSet rs = ps.executeQuery();
        List<PlnZyRclCEntity> sendPlanCEntitys = EntityTool.getEntitysByRs(rs,
                PlnZyRclCEntity.class);
        rs.close();
        ps.close();
        if (sendPlanCEntitys == null || sendPlanCEntitys.size() == 0) {
            return null;
        } else {
            for (PlnZyRclCEntity sendPlanCEntity : sendPlanCEntitys) {
                QualityDesignTool.nullConverNullString(sendPlanCEntity);
            }
            return sendPlanCEntitys.get(0);
        }
    }

    /**
     * 查询热处理计划从表信息
     *
     * @param con
     * @param sendPlanNo
     * @return
     * @throws SQLException
     */
    public static PlnZyRclCEntity getSendHttPlanCInfoC(Connection con,
                                                       String heatNo, String heatSeq) throws SQLException {
        String sql = CoreXmlSqlParsersFactory
                .getSql("PlanService.HeatTreatme.GetRclPlanC2");
        PreparedStatement ps = con.prepareStatement(sql);
        ps.setObject(1, heatNo);
        ps.setObject(2, heatSeq);
        ResultSet rs = ps.executeQuery();
        List<PlnZyRclCEntity> sendPlanCEntitys = EntityTool.getEntitysByRs(rs,
                PlnZyRclCEntity.class);
        rs.close();
        ps.close();
        if (sendPlanCEntitys == null || sendPlanCEntitys.size() == 0) {
            return null;
        } else {
            for (PlnZyRclCEntity sendPlanCEntity : sendPlanCEntitys) {
                QualityDesignTool.nullConverNullString(sendPlanCEntity);
            }
            return sendPlanCEntitys.get(0);
        }
    }
	
    /**
     * 查询加工计划信息--by zc
     *
     * @param con
     * @param sendPlanNo
     * @return
     * @throws SQLException
     */
    public static PlnZyJgxMEntity getSendHttPlanCInfo3Dbk(Connection con,
                                                       String heatNo) throws SQLException {
        String sql = CoreXmlSqlParsersFactory
                .getSql("PlanService.HeatTreatme.GetRclPlan3Dbk");
        PreparedStatement ps = con.prepareStatement(sql);
        ps.setObject(1, heatNo);
        ResultSet rs = ps.executeQuery();
        List<PlnZyJgxMEntity> sendPlanCEntitys = EntityTool.getEntitysByRs(rs,
                PlnZyJgxMEntity.class);
        rs.close();
        ps.close();
        if (sendPlanCEntitys == null || sendPlanCEntitys.size() == 0) {
            return null;
        } else {
            for (PlnZyJgxMEntity sendPlanCEntity : sendPlanCEntitys) {
                QualityDesignTool.nullConverNullString(sendPlanCEntity);
            }
            return sendPlanCEntitys.get(0);
        }
    }
    /**
     * 查询加工计划信息
     *
     * @param con
     * @param sendPlanNo
     * @return
     * @throws SQLException
     */
    public static PlnZyJgxMEntity getSendHttPlanCInfo3(Connection con,
                                                       String heatNo) throws SQLException {
        String sql = CoreXmlSqlParsersFactory
                .getSql("PlanService.HeatTreatme.GetRclPlan3");
        PreparedStatement ps = con.prepareStatement(sql);
        ps.setObject(1, heatNo);
        ResultSet rs = ps.executeQuery();
        List<PlnZyJgxMEntity> sendPlanCEntitys = EntityTool.getEntitysByRs(rs,
                PlnZyJgxMEntity.class);
        rs.close();
        ps.close();
        if (sendPlanCEntitys == null || sendPlanCEntitys.size() == 0) {
            return null;
        } else {
            for (PlnZyJgxMEntity sendPlanCEntity : sendPlanCEntitys) {
                QualityDesignTool.nullConverNullString(sendPlanCEntity);
            }
            return sendPlanCEntitys.get(0);
        }
    }


    /**
     * 查询dbk计划信息--by zc
     *
     * @param con
     * @param sendPlanNo
     * @return
     * @throws SQLException
     */
    public static PlnZyJgxMEntity getSendHttPlanCInfo3Dbk(Connection con,
                                                       String heatNo, String BatchNo) throws SQLException {
        String sql = CoreXmlSqlParsersFactory
                .getSql("PlanService.HeatTreatme.GetRclPlan3NewDbk");
        PreparedStatement ps = con.prepareStatement(sql);
        ps.setObject(1, BatchNo);
        ps.setObject(2, heatNo);
        ResultSet rs = ps.executeQuery();
        List<PlnZyJgxMEntity> sendPlanCEntitys = EntityTool.getEntitysByRs(rs,
                PlnZyJgxMEntity.class);
        rs.close();
        ps.close();
        if (sendPlanCEntitys == null || sendPlanCEntitys.size() == 0) {
            return null;
        } else {
            for (PlnZyJgxMEntity sendPlanCEntity : sendPlanCEntitys) {
                QualityDesignTool.nullConverNullString(sendPlanCEntity);
            }
            return sendPlanCEntitys.get(0);
        }
    }
    /**
     * 查询加工计划信息
     *
     * @param con
     * @param sendPlanNo
     * @return
     * @throws SQLException
     */
    public static PlnZyJgxMEntity getSendHttPlanCInfo3(Connection con,
                                                       String heatNo, String BatchNo) throws SQLException {
        String sql = CoreXmlSqlParsersFactory
                .getSql("PlanService.HeatTreatme.GetRclPlan3New");
        PreparedStatement ps = con.prepareStatement(sql);
        ps.setObject(1, BatchNo);
        ps.setObject(2, heatNo);
        ResultSet rs = ps.executeQuery();
        List<PlnZyJgxMEntity> sendPlanCEntitys = EntityTool.getEntitysByRs(rs,
                PlnZyJgxMEntity.class);
        rs.close();
        ps.close();
        if (sendPlanCEntitys == null || sendPlanCEntitys.size() == 0) {
            return null;
        } else {
            for (PlnZyJgxMEntity sendPlanCEntity : sendPlanCEntitys) {
                QualityDesignTool.nullConverNullString(sendPlanCEntity);
            }
            return sendPlanCEntitys.get(0);
        }
    }

    /**
     * 查询加工计划从表信息
     *
     * @param con
     * @param sendPlanNo
     * @return
     * @throws SQLException
     */
    public static PlnZyJgxCEntity getSendHttPlanCInfo3C(Connection con,
                                                        String heatNo) throws SQLException {
        String sql = CoreXmlSqlParsersFactory
                .getSql("PlanService.HeatTreatme.GetRclPlan3C");
        PreparedStatement ps = con.prepareStatement(sql);
        ps.setObject(1, heatNo);
        ResultSet rs = ps.executeQuery();
        List<PlnZyJgxCEntity> sendPlanCEntitys = EntityTool.getEntitysByRs(rs,
                PlnZyJgxCEntity.class);
        rs.close();
        ps.close();
        if (sendPlanCEntitys == null || sendPlanCEntitys.size() == 0) {
            return null;
        } else {
            for (PlnZyJgxCEntity sendPlanCEntity : sendPlanCEntitys) {
                QualityDesignTool.nullConverNullString(sendPlanCEntity);
            }
            return sendPlanCEntitys.get(0);
        }
    }


    /**
     * 查询加工计划从表信息
     *
     * @param con
     * @param sendPlanNo
     * @return
     * @throws SQLException
     */
    public static PlnZyJgxCEntity getSendHttPlanCInfo3C(Connection con,
                                                        String heatNo, String Sqe) throws SQLException {
        String sql = CoreXmlSqlParsersFactory
                .getSql("PlanService.HeatTreatme.GetRclPlan3CNew");
        PreparedStatement ps = con.prepareStatement(sql);
        ps.setObject(1, heatNo);
        ps.setObject(2, Sqe);
        ResultSet rs = ps.executeQuery();
        List<PlnZyJgxCEntity> sendPlanCEntitys = EntityTool.getEntitysByRs(rs,
                PlnZyJgxCEntity.class);
        rs.close();
        ps.close();
        if (sendPlanCEntitys == null || sendPlanCEntitys.size() == 0) {
            return null;
        } else {
            for (PlnZyJgxCEntity sendPlanCEntity : sendPlanCEntitys) {
                QualityDesignTool.nullConverNullString(sendPlanCEntity);
            }
            return sendPlanCEntitys.get(0);
        }
    }


    /**
     * 查询加工计划从表信息
     *
     * @param con
     * @param sendPlanNo
     * @return
     * @throws SQLException
     */
    public static List<PlnZyJgxCEntity> getSendHttPlanCInfo3C(Connection con,
                                                              String heatNo, String BatchNo, String GroupNo) throws SQLException {
        String sql = CoreXmlSqlParsersFactory
                .getSql("PlanService.HeatTreatme.GetRclPlan3CNew1");
        PreparedStatement ps = con.prepareStatement(sql);
        ps.setObject(1, heatNo);
        ps.setObject(2, BatchNo);
        ps.setObject(3, GroupNo);
        ResultSet rs = ps.executeQuery();
        List<PlnZyJgxCEntity> sendPlanCEntitys = EntityTool.getEntitysByRs(rs,
                PlnZyJgxCEntity.class);
        rs.close();
        ps.close();
        return sendPlanCEntitys;
    }

    /**
     * 查询d镦拔扩订单
     *
     * @param con
     * @param sendPlanNo
     * @return
     * @throws SQLException
     */
    public static PlnOrderDbkSEntity getDBKOrder(Connection con,
                                                 String PRO_PLAN_ID, String GX_PLAN_NO) throws SQLException {
        String sql = CoreXmlSqlParsersFactory
                .getSql("PlanService.HeatTreatme.GetDBKOrder");
        PreparedStatement ps = con.prepareStatement(sql);
        ps.setObject(1, PRO_PLAN_ID);
        ps.setObject(2, GX_PLAN_NO);
        ResultSet rs = ps.executeQuery();
        List<PlnOrderDbkSEntity> PlnOrderDbkSEntity = EntityTool.getEntitysByRs(rs,
                PlnOrderDbkSEntity.class);
        rs.close();
        ps.close();
        if (PlnOrderDbkSEntity == null || PlnOrderDbkSEntity.size() == 0) {
            return null;
        } else {
            for (PlnOrderDbkSEntity sendPlanCEntity : PlnOrderDbkSEntity) {
                QualityDesignTool.nullConverNullString(sendPlanCEntity);
            }
            return PlnOrderDbkSEntity.get(0);
        }
    }

    /**
     * 查询墩拔扩计划信息
     *
     * @param con
     * @param sendPlanNo
     * @return
     * @throws SQLException
     */
    public static PlnZyDbkMEntity getSendDBKPlanCInfo(Connection con,
                                                      String heatNo) throws SQLException {
        String sql = CoreXmlSqlParsersFactory
                .getSql("PlanService.HeatTreatme.GetDbkPlan");
        PreparedStatement ps = con.prepareStatement(sql);
        ps.setObject(1, heatNo);
        ResultSet rs = ps.executeQuery();
        List<PlnZyDbkMEntity> sendPlanCEntitys = EntityTool.getEntitysByRs(rs,
                PlnZyDbkMEntity.class);
        rs.close();
        ps.close();
        if (sendPlanCEntitys == null || sendPlanCEntitys.size() == 0) {
            return null;
        } else {
            for (PlnZyDbkMEntity sendPlanCEntity : sendPlanCEntitys) {
                QualityDesignTool.nullConverNullString(sendPlanCEntity);
            }
            return sendPlanCEntitys.get(0);
        }
    }
    /**
     * 查询墩拔扩计划信息从表
     *
     * @param con
     * @param sendPlanNo
     * @return
     * @throws SQLException
     */
    public static PlnZyDbkCEntity getSendDBKPlanCInfoC(Connection con,
                                                       String heatNo) throws SQLException {
        String sql = CoreXmlSqlParsersFactory
                .getSql("PlanService.HeatTreatme.GetDbkPlanC");
        PreparedStatement ps = con.prepareStatement(sql);
        ps.setObject(1, heatNo);
        ResultSet rs = ps.executeQuery();
        List<PlnZyDbkCEntity> sendPlanCEntitys = EntityTool.getEntitysByRs(rs,
                PlnZyDbkCEntity.class);
        rs.close();
        ps.close();
        if (sendPlanCEntitys == null || sendPlanCEntitys.size() == 0) {
            return null;
        } else {
            for (PlnZyDbkCEntity sendPlanCEntity : sendPlanCEntitys) {
                QualityDesignTool.nullConverNullString(sendPlanCEntity);
            }
            return sendPlanCEntitys.get(0);
        }
    }

    /**
     * 查询墩拔扩计划信息从表
     *
     * @param con
     * @param sendPlanNo
     * @return
     * @throws SQLException
     */
    public static PlnZyDbkCEntity getSendDBKPlanCInfoC(Connection con,
                                                       String heatNo, String heatSeq) throws SQLException {
        String sql = CoreXmlSqlParsersFactory
                .getSql("PlanService.HeatTreatme.GetDbkPlanC2");
        PreparedStatement ps = con.prepareStatement(sql);
        ps.setObject(1, heatNo);
        ps.setObject(2, heatSeq);
        ResultSet rs = ps.executeQuery();
        List<PlnZyDbkCEntity> sendPlanCEntitys = EntityTool.getEntitysByRs(rs,
                PlnZyDbkCEntity.class);
        rs.close();
        ps.close();
        if (sendPlanCEntitys == null || sendPlanCEntitys.size() == 0) {
            return null;
        } else {
            for (PlnZyDbkCEntity sendPlanCEntity : sendPlanCEntitys) {
                QualityDesignTool.nullConverNullString(sendPlanCEntity);
            }
            return sendPlanCEntitys.get(0);
        }
    }

    /**
     * 接箍生产产线
     *
     * @param plan
     * @return
     */
    public CoreReturnObject getQueryPlineCode(String[] plineCode, String gx) {
        String sql = CoreXmlSqlParsersFactory
                .getSql("PlanService.ProcessPlan.getQueryPlineCode");
        /*sql += CoreConverter.toSqlConditionString("T.DEPARTMENT_CODE",
                plineCode);*/
        sql += " AND T.PROCESS_CODE='" + gx + "'";
        sql += "  ORDER BY T.PLINE_NAME";
        return this.getData(sql);
    }

    /**
     * 根据部门获取产线
     *
     * @param plan
     * @return
     */
    public CoreReturnObject getQueryDepPlineCode(String department) {
        String sql = CoreXmlSqlParsersFactory
                .getSql("PlanService.ProcessPlan.getQueryDepPlineCode");
        // sql += "  ORDER BY T.PLINE_NAME";
        return this.getData(sql, new Object[]{department});
    }

    /**
     * 接箍工序点
     *
     * @param plan
     * @return
     */
    public CoreReturnObject getQueryGX(String gx) {
        String sql = CoreXmlSqlParsersFactory
                .getSql("PlanService.ProcessPlan.getQueryGX");
        return this.getData(sql, new Object[]{gx});
    }

    /**
     * 获取工艺文件
     *
     * @param plan
     * @return
     */
    public CoreReturnObject getQueryCraftNo(String CraftNo, String CraftSeq) {
        String sql = CoreXmlSqlParsersFactory
                .getSql("PlanService.ProcessPlan.getQueryCraftNo");
        return this.getData(sql, new Object[]{CraftNo, CraftSeq});
    }
    /**
     * 获取工艺文件接箍
     *
     * @param plan
     * @return
     */
    public CoreReturnObject getQueryCraftNoJG(String CraftNo, String CraftSeq) {
        String sql = CoreXmlSqlParsersFactory
                .getSql("PlanService.ProcessPlan.getQueryCraftNoJG");
        return this.getData(sql, new Object[]{CraftNo, CraftSeq});
    }

    /**
     * 获取工艺文件热处理
     *
     * @param plan
     * @return
     */
    public CoreReturnObject getQueryCraftNoRCL(String CraftNo, String CraftSeq) {
        String sql = CoreXmlSqlParsersFactory
                .getSql("PlanService.ProcessPlan.getQueryCraftNoRCL");
        return this.getData(sql, new Object[]{CraftNo, CraftSeq});
    }

    /**
     * 获取工艺文件镦拔扩
     *
     * @param plan
     * @return
     */
    public CoreReturnObject getQueryCraftNoDBK(String CraftNo, String CraftSeq) {
        String sql = CoreXmlSqlParsersFactory
                .getSql("PlanService.ProcessPlan.getQueryCraftNoDBK");
        return this.getData(sql, new Object[]{CraftNo, CraftSeq});
    }

    /**
     * 比较两个日期之间的大小
     *
     * @param d1
     * @param d2
     * @return 前者大于后者返回true 反之false
     */
    public static boolean compareDate(String d1, String d2) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Calendar c1 = Calendar.getInstance();
        Calendar c2 = Calendar.getInstance();
        try {
            c1.setTime(sdf.parse(d1));
            c2.setTime(sdf.parse(d2));
        } catch (ParseException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        int result = c1.compareTo(c2);
        if (result >= 0)
            return true;
        else
            return false;
    }

    /**
     * 根据登录人对应的部门+科室+仓库类型（投料库）+仓库类别代码（钢管）查询仓库
     *
     * @param plan
     * @return
     */
    public CoreReturnObject getStorage(String department, String depart) {
        String sql = CoreXmlSqlParsersFactory
                .getSql("PlanService.ProcessPlan.getStorage");
        return this.getData(sql, new Object[]{department, depart, "800302",
                "800202"});
    }

    /**
     * 根据登录人对应的部门+科室+仓库类型（投料库）+仓库类别代码（钢管）查询仓库
     *
     * @param plan
     * @return
     */
    public CoreReturnObject getStorage1(String department, String departif,
                                        String storageAttr, String storageTypeNo) {
        String sql = CoreXmlSqlParsersFactory
                .getSql("PlanService.ProcessPlan.getStorage1");
        if (!storageAttr.equals("")) {
            sql += " AND T.STORAGE_ATTR  = '" + storageAttr + "'";
        }
        if (!storageTypeNo.equals("")) {
            sql += " AND T.STORAGE_TYPE_NO = '" + storageTypeNo + "'";
        }
        return this.getData(sql, new Object[]{department, departif});
    }

    /**
     * 根据登录人对应的部门+科室+仓库类型（投料库）+仓库类别代码（钢管）查询仓库
     *
     * @param plan
     * @return
     */
    public CoreReturnObject getStorageDep(String manageNo, String depart,
                                          String StorageType, String StorageAttr) {
        String sql = CoreXmlSqlParsersFactory
                .getSql("PlanService.ProcessPlan.getStorage");
        return this.getData(sql, new Object[]{manageNo, depart, StorageAttr,
                StorageType});
    }

    /***
     * 根据条件查询工单
     *
     * @param department
     * @param depart
     * @return
     */
    public CoreReturnObject getQueryWoId(ArrayList<String> list, String plinCode) {
        String sql = CoreXmlSqlParsersFactory
                .getSql("PlanService.getQueryWoId");
        if (!plinCode.equals("")) {
            sql += " AND T.PLINE_CODE='" + plinCode + "'";
        }
        sql += " AND T.WO_ID like '%' || '" + list.get(0)
                + "' || '%'   AND T.ZY_PLAN_ID like '%' || '" + list.get(1)
                + "'  || '%'   AND T.JUDGE_STOVE_NO like '%' || '"
                + list.get(2)
                + "'  || '%'   AND T.ZY_BILL_STATUS like '%' || '"
                + list.get(3) + "'  || '%'";
        return this.getData(sql);
    }

    /**
     * 查询所有未封闭的工单信息
     */

    public CoreReturnObject ulgetQueryWoId(ArrayList<String> list,
                                           String plinCode) {
        String sql = CoreXmlSqlParsersFactory
                .getSql("PlanService.ulgetQueryWoId");
        if (!plinCode.equals("")) {
            sql += " AND T.PLINE_CODE='" + plinCode + "'";
        }
        sql += " AND T.WO_ID like '%' || '" + list.get(0)
                + "' || '%'   AND T.ZY_PLAN_ID like '%' || '" + list.get(1)
                + "'  || '%'   AND T.JUDGE_STOVE_NO like '%' || '"
                + list.get(2)
                + "'  || '%'   AND T.ZY_BILL_STATUS like '%' || '"
                + list.get(3) + "'  || '%'";
        return this.getData(sql);
    }

    /***
     * 根据条件查询工单
     *
     * @param department
     * @param depart
     * @return
     */
    public CoreReturnObject getQueryWoIdDetails(String woId) {
        String sql = CoreXmlSqlParsersFactory
                .getSql("PlanService.getQueryWoId");
        sql += " AND T.WO_ID ='" + woId + "'  ";
        return this.getData(sql);
    }
    /***
     * 根据接箍公共信息表
     *
     * @param department
     * @param depart
     * @return
     */
    public CoreReturnObject getQueryCouplingcominfo(String woId, String gx) {
        String sql = CoreXmlSqlParsersFactory
                .getSql("PlanService.getQueryCouplingcominfo");
        sql += " AND T.WO_ID ='" + woId + "'  ";
        sql += " AND T.STATION_CODE ='" + gx + "'  ";
        return this.getData(sql);
    }
    /**
     * 查询生产产线
     */
    public CoreReturnObject getQueryplinename(String plineCode) {
        String sql = CoreXmlSqlParsersFactory
                .getSql("PlanService.getQueryplinename");
        sql += " AND T.PLINE_CODE ='" + plineCode + "'  ";
        return this.getData(sql);
    }


    /**
     * 查询同订单/排产序号最大炉计划Id
     *
     * @param con
     * @return
     * @throws SQLException
     */
    public static String getMaxHeatPlanNo(Connection con, String proPlanNoSeq,
                                          String proPlanId, String processCode) throws SQLException {
        String heatPlanNo = "";
        String sql = "SELECT ? ||  LPAD(SUBSTR(NVL(MAX(T.HEAT_PLAN_NO),'000'),-3,3) + 1, 3, '0') AS HEAT_PLAN_NO";
        if (processCode.equals("E")) {
            sql += "  FROM PLN_ZY_DBK_M T ";
        } else if (processCode.equals("F")) {
            sql += " FROM PLN_ZY_RCL_M T ";
        } else if (processCode.equals("G")) {
            sql += " FROM PLN_ZY_JGX_M T ";
        }
        sql += " WHERE T.PRO_PLAN_ID=?";
        PreparedStatement ps = con.prepareStatement(sql);
        ps.setObject(1, proPlanNoSeq);
        ps.setObject(2, proPlanId);
        ResultSet rs = ps.executeQuery();
        if (rs.next()) {
            heatPlanNo = rs.getString("HEAT_PLAN_NO");
        }
        rs.close();
        ps.close();
        return heatPlanNo;
    }

    /**
     * 获取实际炉计划上料行ID
     *
     * @param con
     * @param time
     * @return
     * @throws SQLException
     */
    public static String getHeatPlanSeq(Connection con, String heatPlanNo,
                                        String processCode) throws SQLException {
        String heatPlanSeq = "";
        String sql = CoreXmlSqlParsersFactory
                .getSql("PlanService.getHeatPlanSeq");

        if (processCode.equals("E")) {
            sql += " FROM PLN_ZY_DBK_C T ";
        } else if (processCode.equals("F")) {
            sql += " FROM PLN_ZY_RCL_C T ";
        } else if (processCode.equals("G")) {
            sql += " FROM PLN_ZY_JGX_C T ";
        }
        sql += " WHERE T.HEAT_PLAN_NO=?";
        PreparedStatement ps = con.prepareStatement(sql);
        ps.setObject(1, heatPlanNo);
        ps.setObject(2, heatPlanNo);
        ResultSet rs = ps.executeQuery();
        if (rs.next()) {
            heatPlanSeq = rs.getString("HEAT_PLAN_SQE");
        }
        rs.close();
        ps.close();
        return heatPlanSeq;
    }


    public CoreReturnObject ChangeLen(ArrayList<String> parm, String HeatPlanId,
                                      String processCode) {

        CoreReturnObject cro = new CoreReturnObject();
        Connection connection = this.getDao(CoreConstantData.sysbeanstr)
                .getConnection();

        try {
            connection.setAutoCommit(false); // 取消自动提交事务
            String updateSql = CoreXmlSqlParsersFactory
                    .getSql("PlanService.SetPortLen");// 修改材料表判定单号
            PreparedStatement updatePsta = connection
                    .prepareStatement(updateSql);

            for (String str : parm) {
                ChangeLen ChangeLen = EntityTool
                        .getEntityByJSONStr(str.toString(),
                                ChangeLen.class);


                int count = 0;
                String sql = CoreXmlSqlParsersFactory
                        .getSql("PlanService.SelectPortActLenCount");// 查询工序是否是结炉状态
                PreparedStatement psta = connection.prepareStatement(sql);
                psta.setString(1, HeatPlanId);
                psta.setDouble(2, ChangeLen.getOrLen());
                ResultSet rs = psta.executeQuery();
                if (rs.next()) {
                    count = rs.getInt("COUNT");
                }
                if (count < ChangeLen.getEditCount()) {
                    cro.setV_errMsg("合格支数不够,请刷新数据,重新修改");
                    return cro;
                }
                rs.close();
                psta.close();


                updatePsta.setDouble(1, ChangeLen.getEditLen());
                updatePsta.setDouble(2, ChangeLen.getEditLen() / ChangeLen.getOrLen());
                updatePsta.setString(3, HeatPlanId);
                updatePsta.setDouble(4, ChangeLen.getOrLen());
                updatePsta.setInt(5, ChangeLen.getEditCount());
                updatePsta.addBatch();

            }


            updatePsta.executeBatch();

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


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

    /**
     * 获取产线对应去向
     *
     * @param con
     * @throws SQLException
     */
    public static String getPlineCodeGroup(Connection con, String plineCode,
                                           String proPlanId, String gxPlanNo, String processCode)
            throws SQLException {
        String param = "";
        String sql = "";
        if (processCode.equals("E")) {
            sql += CoreXmlSqlParsersFactory
                    .getSql("PlanService.QueryDbkGroup");
        } else if (processCode.equals("F")) {
            sql += CoreXmlSqlParsersFactory
                    .getSql("PlanService.QueryRclGroup");
        } else if (processCode.equals("G")) {
            sql += CoreXmlSqlParsersFactory
                    .getSql("PlanService.QueryJgxGroup");
        }
        PreparedStatement ps = con.prepareStatement(sql);
        ps.setObject(1, plineCode);
        ps.setObject(2, proPlanId);
        ps.setObject(3, gxPlanNo);
        ResultSet rs = ps.executeQuery();
        if (rs.next()) {
            param = rs.getString("AF_INFO");
        }
        rs.close();
        ps.close();
        return param;
    }


    /**
     * 查询产线内炉计划最大生产序号
     *
     * @param con
     * @param plineCode
     * @return
     * @throws SQLException
     */
    public static int getMaxGxPlnSeq(Connection con, String plineCode,
                                     String processCode) throws SQLException {
        int gxPlnSeq = 1;
        String sql = CoreXmlSqlParsersFactory
                .getSql("PlanService.getMaxGxPlnSeq");
        if (processCode.equals("E")) {
            sql += " FROM PLN_ZY_DBK_M T ";
        } else if (processCode.equals("F")) {
            sql += " FROM PLN_ZY_RCL_M T ";
        } else if (processCode.equals("G")) {
            sql += " FROM PLN_ZY_JGX_M T ";
        }
        sql += " WHERE T.PLINE_CODE=?";
        PreparedStatement ps = con.prepareStatement(sql);
        ps.setObject(1, plineCode);
        ResultSet rs = ps.executeQuery();
        if (rs.next()) {
            gxPlnSeq = rs.getInt("GX_PRO_SEQ");
        }
        rs.close();
        ps.close();
        return gxPlnSeq;
    }

    /**
     * 获取服务器时间
     */
    public static String getTime(Connection con) throws SQLException {
        String time = "";
        String sql = CoreXmlSqlParsersFactory
                .getSql("PlanService.getTime");
        PreparedStatement ps = con.prepareStatement(sql);
        ResultSet rs = ps.executeQuery();
        if (rs.next()) {
            time = rs.getString("DATETIME");
        }
        rs.close();
        ps.close();
        return time;
    }



    public static PlnZyDbkCEntity AddNewDBKPlan(Connection conn, VrpOfflineResultEntity VrpOfflineResultEntity, String UserName) throws Exception {
        PreparedStatement ps = null;
        ResultSet rs = null;





        String sqlCheck = CoreXmlSqlParsersFactory
                .getSql("PlanService.queryHttM");
        ps = conn.prepareStatement(sqlCheck);
        ps.setObject(1, VrpOfflineResultEntity.getJudgeStoveNo());
        rs = ps.executeQuery();
        if (rs.next()) {

            if (rs.getInt("COUNT") > 0) {
                throw new Exception("炉号重复,不允许返线!");
            }
        }
        rs.close();
        ps.close();

        PlnZyDbkMEntity OldPln = PlanService.getSendDBKPlanCInfo(conn,
                VrpOfflineResultEntity.getZyBatchId1());

        if (OldPln == null) {
            throw new Exception("找不到原炉计划信息!");
        }

        PlnZyDbkMEntity plnRclM = new PlnZyDbkMEntity();
        String heatPlanNo = getMaxHeatPlanNo(conn, OldPln.getProPlanId(),
                OldPln.getProPlanId(), "E");
        plnRclM.setHeatPlanNo(heatPlanNo);
        plnRclM.setOutnumCut("1");
        plnRclM.setHeatPlanNoOld(OldPln.getHeatPlanNo());
        plnRclM.setJudgeStoveNo(VrpOfflineResultEntity.getJudgeStoveNo());
        plnRclM.setBatchNo(VrpOfflineResultEntity.getBatchNo());
        plnRclM.setFlagStoveNo(VrpOfflineResultEntity.getJudgeStoveNo());
        plnRclM.setCreateName(UserName);
        plnRclM.setDownman(UserName);
        plnRclM.setPlanstatus("20");
        plnRclM.setPerStatus("00");
        plnRclM.setBesideStatus("00");
        plnRclM.setFeedHeatNo(OldPln.getFeedHeatNo());

        int Num = 0;
        Double Wt = 0d;


        if (StringTool.isInteger(VrpOfflineResultEntity.getOfflineNum())) {
            Num = Integer.parseInt(VrpOfflineResultEntity.getOfflineNum());
        }

        if (StringTool.isDouble(VrpOfflineResultEntity.getOfflineWt()) || StringTool.isInteger(VrpOfflineResultEntity.getOfflineWt())) {
            Wt = Double.parseDouble(VrpOfflineResultEntity.getOfflineWt());
        }

        // 单倍支吨
        plnRclM.setPlnInsingleNum(Num + "");
        plnRclM.setPlnInsingleWt(Wt + "");

        plnRclM.setPlnOutsingleNum(Num + "");
        plnRclM.setPlnOutsingleW(Wt + "");

        // 新增热处理虚拟炉计划
        String addPlnGxZg = EntityTool.fillSqlByEntity(
                CoreXmlSqlParsersFactory
                        .getSql("PlanService.addPlnZyDbk"),
                plnRclM);
        ps = conn.prepareStatement(addPlnGxZg);
        ps.executeUpdate();
        ps.close();

        PlnZyDbkCEntity plnC = new PlnZyDbkCEntity();
        // 获取炉计划顺序号
        String heatPlanSqe = getHeatPlanSeq(conn,
                heatPlanNo, "E");

        plnC.setHeatPlanNo(heatPlanNo);
        plnC.setHeatPlanSqe(heatPlanSqe);
        plnC.setOutnumCut(OldPln.getOutnumCut());
        plnC.setStoveNo(OldPln.getStoveNo());
        plnC.setProPlanId(OldPln.getProPlanId());
        plnC.setGxPlanNo(OldPln.getGxPlanNo());
        plnC.setFeedHeatNo(OldPln.getFeedHeatNo());

        plnC.setHeatPlanSqe(heatPlanSqe);
        // 新增
        addPlnGxZg = EntityTool.fillSqlByEntity(
                CoreXmlSqlParsersFactory
                        .getSql("PlanService.addPlnZyDbkC"),
                plnC);
        ps = conn.prepareStatement(addPlnGxZg);
        ps.executeUpdate();
        ps.close();



        return plnC;
    }


    public static PlnZyRclCEntity AddNewRCLPlan(Connection conn, HttOfflineResultEntity HttOfflineResultEntity, String UserName, String Status) throws Exception {
        PreparedStatement ps = null;
        ResultSet rs = null;



        String sqlCheck = CoreXmlSqlParsersFactory
                .getSql("PlanService.queryHttM");
        ps = conn.prepareStatement(sqlCheck);
        ps.setObject(1, HttOfflineResultEntity.getJudgeStoveNo());
        rs = ps.executeQuery();
        if (rs.next()) {

            if (rs.getInt("COUNT") > 0) {
                throw new Exception("炉号重复,不允许返线!");
            }
        }
        rs.close();
        ps.close();

        PlnZyRclMEntity OldPln = getSendHttPlanCInfo(conn,
                HttOfflineResultEntity.getZyBatchId1());

        if (OldPln == null) {
            throw new Exception("找不到原炉计划信息!");
        }

        PlnZyRclMEntity plnRclM = new PlnZyRclMEntity();
        String heatPlanNo = getMaxHeatPlanNo(conn, OldPln.getProPlanId(),
                OldPln.getProPlanId(), "F");
        plnRclM.setHeatPlanNo(heatPlanNo);
        plnRclM.setOutnumCut("1");
        plnRclM.setHeatPlanNoOld(OldPln.getHeatPlanNo());
        plnRclM.setJudgeStoveNo(HttOfflineResultEntity.getJudgeStoveNo());
        plnRclM.setBatchNo(HttOfflineResultEntity.getBatchNo());
        plnRclM.setFlagStoveNo(HttOfflineResultEntity.getJudgeStoveNo());
        plnRclM.setCreateName(UserName);
        plnRclM.setDownman(UserName);
        plnRclM.setPlanstatus("20");
        plnRclM.setPerStatus(Status);
        plnRclM.setBesideStatus(Status);
        plnRclM.setFeedHeatNo(OldPln.getFeedHeatNo());

        int CutNum = 1;
        int Num = 0;
        Double Wt = 0d;


        if (StringTool.isInteger(HttOfflineResultEntity.getOfflineNum())) {
            Num = Integer.parseInt(HttOfflineResultEntity.getOfflineNum());
        }

        if (StringTool.isDouble(HttOfflineResultEntity.getOfflineWt()) || StringTool.isInteger(HttOfflineResultEntity.getOfflineWt())) {
            Wt = Double.parseDouble(HttOfflineResultEntity.getOfflineWt());
        }



        // 单倍支吨
        plnRclM.setPlnInsingleNum(Num + "");
        plnRclM.setPlnInsingleWt(Wt + "");

        plnRclM.setPlnOutsingleNum(Num * CutNum + "");
        plnRclM.setPlnOutsingleW(Wt * CutNum + "");

        // 新增热处理虚拟炉计划
        String addPlnGxZg = EntityTool.fillSqlByEntity(
                CoreXmlSqlParsersFactory
                        .getSql("PlanService.addPlnZyRcl"),
                plnRclM);
        ps = conn.prepareStatement(addPlnGxZg);
        ps.executeUpdate();
        ps.close();

        PlnZyRclCEntity plnC = new PlnZyRclCEntity();
        // 获取炉计划顺序号
        String heatPlanSqe = getHeatPlanSeq(conn,
                heatPlanNo, "F");

        plnC.setHeatPlanNo(heatPlanNo);
        plnC.setHeatPlanSqe(heatPlanSqe);
        plnC.setOutnumCut(OldPln.getOutnumCut());
        plnC.setStoveNo(OldPln.getStoveNo());
        plnC.setProPlanId(OldPln.getProPlanId());
        plnC.setGxPlanNo(OldPln.getGxPlanNo());
        plnC.setFeedHeatNo(OldPln.getFeedHeatNo());

        plnC.setHeatPlanSqe(heatPlanSqe);
        // 新增
        addPlnGxZg = EntityTool.fillSqlByEntity(
                CoreXmlSqlParsersFactory
                        .getSql("PlanService.addPlnZyRclC"),
                plnC);
        ps = conn.prepareStatement(addPlnGxZg);
        ps.executeUpdate();
        ps.close();


        //updatePlnRclGroup(conn,OldPln.getProPlanId(),OldPln.getGxPlanNo(),plnRclM.getPic());

        return plnC;
    }

    public static PlnZyJgxCEntity AddNewJGXPlan(Connection conn, MchOfflineResultEntity MchOfflineResultEntity, String UserName) throws Exception {
        PreparedStatement ps = null;
        ResultSet rs = null;


        String sqlCheck = CoreXmlSqlParsersFactory
                .getSql("PlanService.queryMchM");
        ps = conn.prepareStatement(sqlCheck);
        ps.setObject(1, MchOfflineResultEntity.getJudgeStoveNo());
        rs = ps.executeQuery();
        if (rs.next()) {

            if (rs.getInt("COUNT") > 0) {
                throw new Exception("炉号重复,不允许返线!");
            }
        }
        rs.close();
        ps.close();


        PlnZyJgxMEntity OldPln = PlanService.getSendHttPlanCInfo3(conn,
                MchOfflineResultEntity.getZyBatchId1());

        if (OldPln == null) {
            throw new Exception("找不到原炉计划信息!");
        }


        PlnZyJgxMEntity plnJgxM = new PlnZyJgxMEntity();
        String heatPlanNo = getMaxHeatPlanNo(conn, OldPln.getProPlanId(),
                OldPln.getProPlanId(), "G");

        plnJgxM.setHeatPlanNo(heatPlanNo);
        plnJgxM.setOutnumCut(MchOfflineResultEntity.getOutnumCut());
        plnJgxM.setHeatPlanNoOld(OldPln.getHeatPlanNo());
        plnJgxM.setJudgeStoveNo(MchOfflineResultEntity.getJudgeStoveNo());
        plnJgxM.setBatchNo(MchOfflineResultEntity.getBatchNo());
        plnJgxM.setFlagStoveNo(MchOfflineResultEntity.getJudgeStoveNo());
        plnJgxM.setCreateName(UserName);
        plnJgxM.setDownman(UserName);
        plnJgxM.setFeedHeatNo(OldPln.getFeedHeatNo());

        int CutNum = 1;
        int Num = 0;
        Double Wt = 0d;

        if (StringTool.isInteger(MchOfflineResultEntity.getOutnumCut())) {
            CutNum = Integer.parseInt(MchOfflineResultEntity.getOutnumCut());
        }

        if (StringTool.isInteger(MchOfflineResultEntity.getOfflineNum())) {
            Num = Integer.parseInt(MchOfflineResultEntity.getOfflineNum());
        }


        if (StringTool.isDouble(MchOfflineResultEntity.getOfflineWt()) || StringTool.isInteger(MchOfflineResultEntity.getOfflineWt())) {
            Wt = Double.parseDouble(MchOfflineResultEntity.getOfflineWt());
        }

        // 单倍支吨
        plnJgxM.setPlnInsingleNum(Num + "");
        plnJgxM.setPlnInsingleWt(Wt + "");

        plnJgxM.setPlnOutsingleNum(Num * CutNum + "");
        plnJgxM.setPlnOutsingleW(Wt * CutNum + "");


        // 新增加工线虚拟炉计划
        String addPlnGxZg = EntityTool.fillSqlByEntity(
                CoreXmlSqlParsersFactory
                        .getSql("PlanService.addPlnZyJgx"),
                plnJgxM);
        ps = conn.prepareStatement(addPlnGxZg);
        ps.executeUpdate();
        ps.close();

        PlnZyJgxCEntity plnC = new PlnZyJgxCEntity();
        // 获取炉计划顺序号
        String heatPlanSqe = getHeatPlanSeq(conn,
                heatPlanNo, "G");
        plnC.setHeatPlanNo(heatPlanNo);
        plnC.setHeatPlanSqe(heatPlanSqe);
        plnC.setOutnumCut(MchOfflineResultEntity.getOutnumCut());
        plnC.setStoveNo(OldPln.getStoveNo());
        plnC.setProPlanId(OldPln.getProPlanId());
        plnC.setGxPlanNo(OldPln.getGxPlanNo());
        plnC.setFeedHeatNo(OldPln.getFeedHeatNo());
        // 新增
        addPlnGxZg = EntityTool.fillSqlByEntity(
                CoreXmlSqlParsersFactory
                        .getSql("PlanService.addPlnZyJgxC"),
                plnC);
        ps = conn.prepareStatement(addPlnGxZg);
        ps.executeUpdate();
        ps.close();

        updatePlnJgxGroup(conn, OldPln.getProPlanId(), OldPln.getGxPlanNo(), OldPln.getPic());

        return plnC;
    }

    public static void AddOffLineMat(Connection connection, String ProcessCode,
                                     String UserName, String QcmStatus,
                                     String MatNo, String GxCode, String HeatPlanId) throws Exception {
        AddOffLineMat(connection, ProcessCode,
                UserName, QcmStatus,
                MatNo, GxCode, HeatPlanId, "", "", "", "", "");
    }

    public static void AddOffLineMatWithResultNo(Connection connection, String ProcessCode,
                                                 String UserName, String QcmStatus,
                                                 String MatNo, String GxCode, String HeatPlanId, String ResultNo) throws Exception {
        AddOffLineMat(connection, ProcessCode,
                UserName, QcmStatus,
                MatNo, GxCode, HeatPlanId, "", "", "", "", ResultNo);
    }

    //接箍离线添加材料表
    public static void AddJgMatBcM(Connection connection, String ProcessCode,
                                   String UserName, String QcmStatus,
                                   String MatNo, String GxCode, String HeatPlanId, String ScrapReson, String judgeNo) throws Exception {
        AddMatBcM(connection, ProcessCode,
                UserName, QcmStatus,
                MatNo, GxCode, HeatPlanId, "", "", "", ScrapReson, judgeNo);
    }

    public static void AddMatBcM(Connection connection, String ProcessCode,
                                 String UserName, String QcmStatus,
                                 String MatNo, String GxCode, String HeatPlanId, String GoWhereCode, String GoWhereName,
			String Memo,String ScrapReson,String judgeNo) throws Exception
	{
        PreparedStatement pastaddMatBc = null;
        PreparedStatement pstaAddButt = null;

        String addMatBc = CoreXmlSqlParsersFactory
                .getSql("PlanService.AddJgOfflineMat");// 新增材料表
        pastaddMatBc = connection
                .prepareStatement(addMatBc);

        String addButt = CoreXmlSqlParsersFactory
                .getSql("PlanService.AddJgBut");// 新增位置表
        pstaAddButt = connection.prepareStatement(addButt);

        pastaddMatBc.setObject(1, MatNo);
        pastaddMatBc.setObject(2, GoWhereCode);
        pastaddMatBc.setObject(3, GoWhereName);
        pastaddMatBc.setObject(4, Memo);
        pastaddMatBc.setObject(5, UserName);
        pastaddMatBc.setObject(6, QcmStatus);
        pastaddMatBc.setObject(7, QcmStatus.equals("22") ? "000000" : "");
        pastaddMatBc.setObject(8, ScrapReson);
        pastaddMatBc.setObject(9, GxCode);
        pastaddMatBc.setObject(10, QcmStatus.equals("22") ? "40740705" : "");
        pastaddMatBc.setObject(11, MatNo);
        pastaddMatBc.setObject(12, HeatPlanId);

        pastaddMatBc.addBatch();
        pastaddMatBc.executeBatch();

        pstaAddButt.setObject(1, judgeNo);
        pstaAddButt.setObject(2, MatNo);
        pstaAddButt.setObject(3, UserName);
        //pstaAddButt.setObject(4, HeatPlanId);
        pstaAddButt.addBatch();
        pstaAddButt.executeBatch();

        pstaAddButt.close();
        pastaddMatBc.close();

    }

    //接箍离线添加材料表
    public static void AddJgCoupMatNo(Connection connection, String ProcessCode,
                                      String UserName, String QcmStatus,
                                      String MatNo, String GxCode, String HeatPlanId, String ScrapReson, String count,
                                      String resultNo, PlnZyJgWorkbillEntity work, String time) throws Exception {
        AddCoupMatBcM(connection, ProcessCode,
                UserName, QcmStatus,
                MatNo, GxCode, HeatPlanId, "", "", "", ScrapReson, count, resultNo, work, time);
    }

    public static void AddCoupMatBcM(Connection connection, String ProcessCode,
                                     String UserName, String QcmStatus,
                                     String MatNo, String GxCode, String HeatPlanId, String GoWhereCode, String GoWhereName,
				String Memo,String ScrapReson,String count,String resultNo,PlnZyJgWorkbillEntity work,String time) throws Exception
		{
        PreparedStatement pastaddMatBc = null;
        PreparedStatement pstaAddButt = null;
        ResultSet rs = null;
        PreparedStatement psta = null;

        String storageNo = "";
        String storageAtte = "";
        String storageAtteName = "";
        String storageType = "";
        String storageTypeName = "";
        String managNo = "";
        String managName = "";
        String sqlloading = CoreXmlSqlParsersFactory
                .getSql("FrmInLibrary.queryStorageType");
        psta = connection.prepareStatement(sqlloading);
        psta.setObject(1, work.getPlineCode());
        rs = psta.executeQuery();
        if (rs.next()) {
            storageNo = rs.getString("STORAGE_NO");
            storageAtte = rs.getString("STORAGE_ATTR");
            storageAtteName = rs.getString("STORAGE_ATTR_NAME");
            storageType = rs.getString("STORAGE_TYPE_NO");
            storageTypeName = rs.getString("STORAGE_TYPE_NAME");
            managNo = rs.getString("MANAGEMENT_NO");
            managName = rs.getString("MANAGEMENT_NAME");
        }
        rs.close();
        psta.close();
        String belongCode = "";
        String belongName = "";
        sqlloading = CoreXmlSqlParsersFactory
                .getSql("FrmInLibrary.selectBelong");
        psta = connection.prepareStatement(sqlloading);
        psta.setObject(1, work.getPlineCode());
        rs = psta.executeQuery();
			if(rs.next())
			{
            belongCode = rs.getString("DEPARTMENT_CODE");
            belongName = rs.getString("DEPARTMENT_DESC");
        }
        rs.close();
        psta.close();

        String addMatBc = CoreXmlSqlParsersFactory
                .getSql("FrmInLibrary.AddMatM");// 新增材料表
        pastaddMatBc = connection
                .prepareStatement(addMatBc);

        String addButt = CoreXmlSqlParsersFactory
                .getSql("FrmInLibrary.AddMatButters");// 新增位置表
        pstaAddButt = connection.prepareStatement(addButt);

        // 新增材料表
        pastaddMatBc.setObject(1, MatNo);
        pastaddMatBc.setObject(2, resultNo);
        pastaddMatBc.setObject(3, "");
        pastaddMatBc.setObject(4, HeatPlanId);
        pastaddMatBc.setObject(5, work.getPlineCode());
        pastaddMatBc.setObject(6, work.getPlineName());
        pastaddMatBc.setObject(7, work.getJudgeStoveNo());
        pastaddMatBc.setObject(8, work.getBatchNo());
        pastaddMatBc.setObject(9, work.getBlWlId());
        pastaddMatBc.setObject(10, work.getBlWlDesc());
        pastaddMatBc.setObject(11, work.getMinD());
        pastaddMatBc.setObject(12, work.getMinH());
        pastaddMatBc.setObject(13, work.getCodeJg());
        pastaddMatBc.setObject(14, work.getGradecode());
        pastaddMatBc.setObject(15, work.getGradename());
        pastaddMatBc.setObject(16, work.getSteelcode());
        pastaddMatBc.setObject(17, work.getSteelname());
        pastaddMatBc.setObject(18, work.getModelCode());
        pastaddMatBc.setObject(19, work.getModelDesc());
        pastaddMatBc.setObject(20, work.getDiameterJg());
        pastaddMatBc.setObject(21, work.getHeightJg());
        pastaddMatBc.setObject(22, work.getSpecJg());
        pastaddMatBc.setObject(23, work.getSpecJgDesc());
        pastaddMatBc.setObject(24, work.getStyleJg());
        pastaddMatBc.setObject(25, work.getDiameter());
        pastaddMatBc.setObject(26, work.getCheckJVal());
        pastaddMatBc.setObject(27, work.getLengthJg());
        pastaddMatBc.setObject(28, work.getSingleweight());
        pastaddMatBc.setObject(29, "");
        pastaddMatBc.setObject(30, work.getIfMonitorJg());
        pastaddMatBc.setObject(31, work.getPrdcrNo());
        pastaddMatBc.setObject(32, "");

        pastaddMatBc.setObject(33, String.valueOf(count));
        pastaddMatBc.setObject(34, Double.parseDouble(count)
                * (Double.parseDouble(work.getSingleweight()) / 1000));// 重量


        pastaddMatBc.setObject(35, time);
        pastaddMatBc.setObject(36, "");
        pastaddMatBc.setObject(37, "");
        pastaddMatBc.setObject(38, "");// 操作人
        pastaddMatBc.setObject(39, UserName);
        pastaddMatBc.setObject(40, time);
        pastaddMatBc.setObject(41, time);
        pastaddMatBc.setObject(42, work.getOrderNo() + "/" + work.getOrderSeq());
        pastaddMatBc.setObject(43, belongCode);
        pastaddMatBc.setObject(44, belongName);
        pastaddMatBc.setObject(45, "11");
        pastaddMatBc.setObject(46, work.getCraftSeq());
        pastaddMatBc.setObject(47, work.getCodeJgBl());
        pastaddMatBc.setObject(48, work.getStoveNo());
        pastaddMatBc.setObject(49, work.getFlagStoveNo());
        pastaddMatBc.addBatch();
        pastaddMatBc.executeBatch();


        // 新增材料从表
        pstaAddButt.setObject(1, MatNo);
        pstaAddButt.setObject(2, "0001");
        pstaAddButt.setObject(3, "801402");
        pstaAddButt.setObject(4, "80150201");
        pstaAddButt.setObject(5, "");
        pstaAddButt.setObject(6, count);
        if (work.getSingleweight().equals("")) {
            pstaAddButt.setObject(7, 0);
        } else {
            pstaAddButt.setObject(7, Double.parseDouble(count)
                    * Double.parseDouble(work.getSingleweight())
                    / 1000);
        }
        pstaAddButt.setObject(8, "");
        pstaAddButt.setObject(9, "");
        pstaAddButt.setObject(10, "");
        pstaAddButt.setObject(11, storageNo);
        pstaAddButt.setObject(12, storageNo + "10101");
        pstaAddButt.setObject(13, storageAtte);
        pstaAddButt.setObject(14, storageAtteName);
        pstaAddButt.setObject(15, storageType);
        pstaAddButt.setObject(16, storageTypeName);
        pstaAddButt.setObject(17, managNo);
        pstaAddButt.setObject(18, managName);
        pstaAddButt.setObject(19, "");
        pstaAddButt.setObject(20, UserName);
        pstaAddButt.setObject(21, time);
        pstaAddButt.setObject(22, "0");
        pstaAddButt.setObject(23, "");
        pstaAddButt.setObject(24, "");
        pstaAddButt.setObject(25, work.getLatheGrpNo());
        pstaAddButt.setObject(26, work.getLatheGrpNm());
        pstaAddButt.setObject(27, "");
        pstaAddButt.addBatch();
        pstaAddButt.executeBatch();

        pstaAddButt.close();
        pastaddMatBc.close();

    }


    public static void AddOffLineMat(Connection connection, String ProcessCode,
                                     String UserName, String QcmStatus,
                                     String MatNo, String GxCode, String HeatPlanId, String ScrapReson) throws Exception {
        AddOffLineMat(connection, ProcessCode,
                UserName, QcmStatus,
                MatNo, GxCode, HeatPlanId, "", "", "", ScrapReson, "");
    }

    public static void AddOffLineMat(Connection connection, String ProcessCode,
                                     String UserName, String QcmStatus,
                                     String MatNo, String GxCode, String HeatPlanId, String GoWhereCode, String GoWhereName, String Memo) throws Exception {
        AddOffLineMat(connection, ProcessCode,
                UserName, QcmStatus,
                MatNo, GxCode, HeatPlanId, GoWhereCode, GoWhereName, Memo, "", "");
    }

    public static void AddOffLineMat(Connection connection, String ProcessCode,
                                     String UserName, String QcmStatus,
                                     String MatNo, String GxCode, String HeatPlanId, String GoWhereCode, String GoWhereName, String Memo, String ResultNo) throws Exception {
        AddOffLineMat(connection, ProcessCode,
                UserName, QcmStatus,
                MatNo, GxCode, HeatPlanId, GoWhereCode, GoWhereName, Memo, "", ResultNo);
    }

    public static void AddOffLineMat(Connection connection, String ProcessCode,
                                     String UserName, String QcmStatus,
                                     String MatNo, String GxCode, String HeatPlanId, String GoWhereCode, String GoWhereName,
	              String Memo,String ScrapReson,String ResultNo) throws Exception
		{
        PreparedStatement pastaddMatBc = null;
        PreparedStatement pstaAddButt = null;

        String addButt = CoreXmlSqlParsersFactory
                .getSql("PlanService.AddBut");// 新增位置表
        pstaAddButt = connection.prepareStatement(addButt);

        if ("E".equals(ProcessCode)) {
            String addMatBc = CoreXmlSqlParsersFactory
                    .getSql("PlanService.AddVrpOfflineMat");// 新增材料表
            pastaddMatBc = connection
                    .prepareStatement(addMatBc);

			}
			else	if("F".equals(ProcessCode)){
            String addMatBc = CoreXmlSqlParsersFactory
                    .getSql("PlanService.AddHttOfflineMat");// 新增材料表
            pastaddMatBc = connection
                    .prepareStatement(addMatBc);

        } else if ("G".equals(ProcessCode)) {
            String addMatBc = CoreXmlSqlParsersFactory
                    .getSql("PlanService.AddMchOfflineMat");// 新增材料表
            pastaddMatBc = connection
                    .prepareStatement(addMatBc);
			}
			else {
            return;
        }

        //if(QcmStatus.equals("22")) QcmStatus = "33";  //状态又22转成33  33为未审核  审核之后才调整至22

        pastaddMatBc.setObject(1, GoWhereCode);
        pastaddMatBc.setObject(2, GoWhereName);
        pastaddMatBc.setObject(3, Memo);
        pastaddMatBc.setObject(4, UserName);
        pastaddMatBc.setObject(5, QcmStatus);
        pastaddMatBc.setObject(6, QcmStatus.equals("22") ? "000000" : "");
        pastaddMatBc.setObject(7, ScrapReson);
        pastaddMatBc.setObject(8, ResultNo);
        pastaddMatBc.setObject(9, MatNo);
        pastaddMatBc.setObject(10, GxCode);
        pastaddMatBc.setObject(11, QcmStatus.equals("22") ? "" : "");
        pastaddMatBc.setObject(12, ResultNo);
        pastaddMatBc.setObject(13, HeatPlanId);

        pastaddMatBc.addBatch();
        pastaddMatBc.executeBatch();

        pstaAddButt.setObject(1, HeatPlanId);
        pstaAddButt.setObject(2, MatNo);
        pstaAddButt.setObject(3, UserName);
        pstaAddButt.addBatch();
        pstaAddButt.executeBatch();

        pstaAddButt.close();
        pastaddMatBc.close();

    }


    public static void DeleteOffLineMat(Connection connection,
                                        String MatNo) throws Exception {
        DeleteOffLineMat(connection, MatNo, false, "");
    }

    public static void DeleteOffLineMat(Connection connection,
									 String MatNo, boolean NeedCheck, String PLineCode) throws Exception
	{

        String addMatBc = CoreXmlSqlParsersFactory
                .getSql("PlanService.deleteMatBc");
        PreparedStatement pastDeletMatBc = connection
                .prepareStatement(addMatBc);

        String addButt = CoreXmlSqlParsersFactory
                .getSql("PlanService.deleteMatButNew");
        PreparedStatement pstaDeletButt = connection.prepareStatement(addButt);


        MatBcMEntity MatBcMEntity = OfflineHelper.getMatBcM(connection, MatNo);
        if (MatBcMEntity == null || MatBcMEntity.getMatNo().equals("")) {
            throw new Exception("找不到废品/待处理库存!");
        }

        if (!MatBcMEntity.getScrapFrimFlag().equals("0") && !MatBcMEntity.getScrapFrimFlag().equals("")) {
            throw new Exception("废品已申请审核或已经审核!无法撤销实绩！");
        }

        if (MatBcMEntity.getStorageNo().equals("")) {
            throw new Exception("废品或者离线管正在倒运途中,不允许此操作!");
        }

        if (NeedCheck && !MatBcMEntity.getFlag().equals("1")) {
            if (PLineCode.equals("")) PLineCode = MatBcMEntity.getPlineCode();

            String StorageNo = PlanService.GetStorageOut(PLineCode, connection);
            if (!MatBcMEntity.getStorageNo().equals(StorageNo)) {
                throw new Exception("待处理品不在产出库,不允许此操作!");
            }
        }

        pstaDeletButt.setObject(1, MatNo);
        pstaDeletButt.setObject(2, MatBcMEntity.getPlineCode());
        pstaDeletButt.setObject(3, MatBcMEntity.getPlineCode());
        pstaDeletButt.setObject(4, MatNo);
        pstaDeletButt.setObject(5, MatNo);
        pstaDeletButt.setObject(6, MatBcMEntity.getPlineCode());
        pstaDeletButt.setObject(7, MatNo);
        pstaDeletButt.addBatch();
        pstaDeletButt.executeBatch();
        pstaDeletButt.close();


        pastDeletMatBc.setObject(1, MatNo);
        pastDeletMatBc.addBatch();
        pastDeletMatBc.executeBatch();
        pastDeletMatBc.close();


    }



    public static void DeleteZcMat(Connection connection, String MatNo) throws Exception {


        String addMatBc = CoreXmlSqlParsersFactory
                .getSql("PlanService.deleteMatZc");
        PreparedStatement pastDeletMatBc = connection
                .prepareStatement(addMatBc);
        
        String addMatBcXs = CoreXmlSqlParsersFactory
                .getSql("PlanServiceXs.deleteMatZc");
        PreparedStatement pastDeletMatBcXs = connection
                .prepareStatement(addMatBcXs);

        String addButt = CoreXmlSqlParsersFactory
                .getSql("PlanService.deleteMatZcBut");
        PreparedStatement pstaDeletButt = connection.prepareStatement(addButt);

        MatZcMEntity MatZcMEntity = OfflineHelper.getMatZcM(connection, MatNo);
        if (MatZcMEntity == null || MatZcMEntity.getMatNo().equals("")) {
            throw new Exception("找不到库存!");
        }

        pstaDeletButt.setObject(1, MatNo);
        pstaDeletButt.addBatch();
        pstaDeletButt.executeBatch();
        pstaDeletButt.close();


        pastDeletMatBc.setObject(1, MatNo);
        pastDeletMatBc.addBatch();
        pastDeletMatBc.executeBatch();
        pastDeletMatBc.close();
        
        pastDeletMatBcXs.setObject(1, MatNo);
        pastDeletMatBcXs.addBatch();
        pastDeletMatBcXs.executeBatch();
        pastDeletMatBcXs.close();


    }


    public static String GetPlineCodeFlag(Connection connection, String PlineCode) throws SQLException {
        String flag = "";
        String sql = CoreXmlSqlParsersFactory
                .getSql("PlanService.getPlineInfo");
        PreparedStatement ps = connection.prepareStatement(sql);
        ps.setObject(1, PlineCode);
        ResultSet rs = ps.executeQuery();
        if (rs.next()) {
            flag = rs.getString("CHECK_NO_SHORT");
        }
        rs.close();
        ps.close();
        return flag;
    }




    /***
     * 修改生产批
     *
     * @param con
     * @param proPlanId
     * @param gxPlanNo
     * @throws SQLException
     */
    public static void updatePlnRclGroup(Connection con, String proPlanId,
                                         String gxPlanNo, String picPlan) throws SQLException {
        PreparedStatement ps = null;
        ResultSet rs = null;
        String desginKey = "";
        String mscPline = "";
        // 查询DesginKey与制程索引号
        String sqlOrderRcl = CoreXmlSqlParsersFactory
                .getSql("PlanService.queryDesginKey");
        ps = con.prepareStatement(sqlOrderRcl);
        ps.setObject(1, proPlanId);
        ps.setObject(2, gxPlanNo);
        rs = ps.executeQuery();
        if (rs.next()) {
            desginKey = rs.getString("DESGIN_KEY");
            mscPline = rs.getString("INDEX_SEQ");
        }
        rs.close();
        ps.close();

        int topStove = 0;// 前几炉
        int loopValue = 0;// 循环值
        // 查询是否生产批,前几炉及循环值
        String sqlPic = CoreXmlSqlParsersFactory
                .getSql("PlanService.querySqlPic");
        ps = con.prepareStatement(sqlPic);
        ps.setObject(1, desginKey);
        ps.setObject(2, mscPline);
        ps.setObject(3, picPlan);
        rs = ps.executeQuery();
        if (rs.next()) {
            topStove = rs.getInt("TOP_STOVE");
            loopValue = rs.getInt("LOOP_VALUE");
        }
        rs.close();
        ps.close();

        if (topStove != 0 || loopValue != 0) {
            int count = 0;
            // 查询有多少炉计划
            String sqlPlnM = "SELECT COUNT(*) COUNT FROM PLN_ZY_RCL_M T WHERE T.PRO_PLAN_ID=? AND T.GX_PLAN_NO=?";
            ps = con.prepareStatement(sqlPlnM);
            ps.setObject(1, proPlanId);
            ps.setObject(2, gxPlanNo);
            rs = ps.executeQuery();
            if (rs.next()) {
                count = rs.getInt("COUNT");
            }
            rs.close();
            ps.close();
            if (topStove != 0) {
                // 修改生产批前topStove 生产坯==A
                String sql = "UPDATE PLN_ZY_RCL_M T SET T.LOT_NO_GROUP='A'"
                        + " WHERE T.PRO_PLAN_ID=? AND T.GX_PLAN_NO=? AND TO_NUMBER(T.LOT_NO_SQE) <=?";
                ps = con.prepareStatement(sql);
                ps.setObject(1, proPlanId);
                ps.setObject(2, gxPlanNo);
                ps.setObject(3, topStove);
                ps.executeUpdate();
                ps.close();
            }
            if (loopValue == 0) {
                // 修改生产批 排除前几炉修改==1
                String sql = "UPDATE PLN_ZY_RCL_M T SET T.LOT_NO_GROUP='1'"
                        + " WHERE T.PRO_PLAN_ID=? AND T.GX_PLAN_NO=? AND TO_NUMBER(T.LOT_NO_SQE) >?";
                ps = con.prepareStatement(sql);
                ps.setObject(1, proPlanId);
                ps.setObject(2, gxPlanNo);
                ps.setObject(3, topStove);
                ps.executeUpdate();
                ps.close();
            } else {
                int intCount = 0;
                int intCount1 = 0;
                int group = 1;
                int topStove1 = topStove;
                if (count - topStove < loopValue) {
                    String sql = "UPDATE PLN_ZY_RCL_M T SET T.LOT_NO_GROUP='1'"
                            + " WHERE T.PRO_PLAN_ID=? AND T.GX_PLAN_NO=? AND TO_NUMBER(T.LOT_NO_SQE) >?";
                    ps = con.prepareStatement(sql);
                    ps.setObject(1, proPlanId);
                    ps.setObject(2, gxPlanNo);
                    ps.setObject(3, topStove);
                    ps.executeUpdate();
                    ps.close();
                } else {
                    for (int i = 0; i < count - topStove; i++) {
                        // 修改生产批 排除前几炉修改==1
                        String sql = "UPDATE PLN_ZY_RCL_M T SET T.LOT_NO_GROUP='"
                                + group
                                + "'"
                                + " WHERE T.PRO_PLAN_ID=? AND T.GX_PLAN_NO=? AND TO_NUMBER(T.LOT_NO_SQE) >? AND TO_NUMBER(T.LOT_NO_SQE) <=?";
                        ps = con.prepareStatement(sql);
                        ps.setObject(1, proPlanId);
                        ps.setObject(2, gxPlanNo);
                        ps.setObject(3, topStove + intCount1);
                        ps.setObject(4, topStove1 + loopValue);
                        ps.executeUpdate();
                        ps.close();
                        intCount++;
                        intCount1++;
                        if (loopValue == intCount) {
                            topStove1 += loopValue;
                            group++;
                            intCount = 0;
                        }

                    }
                }

            }
        } else {
            String sql = "UPDATE PLN_ZY_RCL_M T SET T.LOT_NO_GROUP='1'"
                    + " WHERE T.PRO_PLAN_ID=? AND T.GX_PLAN_NO=? AND TO_NUMBER(T.LOT_NO_SQE) >?";
            ps = con.prepareStatement(sql);
            ps.setObject(1, proPlanId);
            ps.setObject(2, gxPlanNo);
            ps.setObject(3, topStove);
            ps.executeUpdate();
            ps.close();
        }
    }



    /***
     * 修改生产批
     *
     * @param con
     * @param proPlanId
     * @param gxPlanNo
     * @throws SQLException
     */
    public static void updatePlnJgxGroup(Connection con, String proPlanId,
                                         String gxPlanNo, String picPlan) throws SQLException {
        PreparedStatement ps = null;
        ResultSet rs = null;
        String desginKey = "";
        String mscPline = "";
        // 查询DesginKey与制程索引号
        String sqlOrderRcl = CoreXmlSqlParsersFactory
                .getSql("PlanService.queryDesginKeyG");
        ps = con.prepareStatement(sqlOrderRcl);
        ps.setObject(1, proPlanId);
        ps.setObject(2, gxPlanNo);
        rs = ps.executeQuery();
        if (rs.next()) {
            desginKey = rs.getString("DESGIN_KEY");
            mscPline = rs.getString("INDEX_SEQ");
        }
        rs.close();
        ps.close();

        int topStove = 0;// 前几炉
        int loopValue = 0;// 循环值
        // 查询是否生产批,前几炉及循环值
        String sqlPic = CoreXmlSqlParsersFactory
                .getSql("PlanService.querySqlPicG");
        ps = con.prepareStatement(sqlPic);
        ps.setObject(1, desginKey);
        ps.setObject(2, mscPline);
        ps.setObject(3, picPlan);
        rs = ps.executeQuery();
        if (rs.next()) {
            topStove = rs.getInt("TOP_STOVE");
            loopValue = rs.getInt("LOOP_VALUE");
        }
        rs.close();
        ps.close();

        if (topStove != 0 || loopValue != 0) {
            int count = 0;
            // 查询有多少炉计划
            String sqlPlnM = "SELECT COUNT(*) COUNT FROM PLN_ZY_JGX_M T WHERE T.PRO_PLAN_ID=? AND T.GX_PLAN_NO=?";
            ps = con.prepareStatement(sqlPlnM);
            ps.setObject(1, proPlanId);
            ps.setObject(2, gxPlanNo);
            rs = ps.executeQuery();
            if (rs.next()) {
                count = rs.getInt("COUNT");
            }
            rs.close();
            ps.close();
            if (topStove != 0) {
                // 修改生产批前topStove 生产坯==A
                String sql = "UPDATE PLN_ZY_JGX_M T SET T.LOT_NO_GROUP='A'"
                        + " WHERE T.PRO_PLAN_ID=? AND T.GX_PLAN_NO=? AND TO_NUMBER(T.LOT_NO_SQE) <=?";
                ps = con.prepareStatement(sql);
                ps.setObject(1, proPlanId);
                ps.setObject(2, gxPlanNo);
                ps.setObject(3, topStove);
                ps.executeUpdate();
                ps.close();
            }
            if (loopValue == 0) {
                // 修改生产批 排除前几炉修改==1
                String sql = "UPDATE PLN_ZY_JGX_M T SET T.LOT_NO_GROUP='1'"
                        + " WHERE T.PRO_PLAN_ID=? AND T.GX_PLAN_NO=? AND TO_NUMBER(T.LOT_NO_SQE) >?";
                ps = con.prepareStatement(sql);
                ps.setObject(1, proPlanId);
                ps.setObject(2, gxPlanNo);
                ps.setObject(3, topStove);
                ps.executeUpdate();
                ps.close();
            } else {
                int intCount = 0;
                int intCount1 = 0;
                int group = 1;
                int topStove1 = topStove;
                if (count - topStove < loopValue) {
                    String sql = "UPDATE PLN_ZY_JGX_M T SET T.LOT_NO_GROUP='1'"
                            + " WHERE T.PRO_PLAN_ID=? AND T.GX_PLAN_NO=? AND TO_NUMBER(T.LOT_NO_SQE) >?";
                    ps = con.prepareStatement(sql);
                    ps.setObject(1, proPlanId);
                    ps.setObject(2, gxPlanNo);
                    ps.setObject(3, topStove);
                    ps.executeUpdate();
                    ps.close();
                } else {
                    for (int i = 0; i < count - topStove; i++) {
                        // 修改生产批 排除前几炉修改==1
                        String sql = "UPDATE PLN_ZY_JGX_M T SET T.LOT_NO_GROUP='"
                                + group
                                + "'"
                                + " WHERE T.PRO_PLAN_ID=? AND T.GX_PLAN_NO=? AND TO_NUMBER(T.LOT_NO_SQE) >? AND TO_NUMBER(T.LOT_NO_SQE) <=?";
                        ps = con.prepareStatement(sql);
                        ps.setObject(1, proPlanId);
                        ps.setObject(2, gxPlanNo);
                        ps.setObject(3, topStove + intCount1);
                        ps.setObject(4, topStove1 + loopValue);
                        ps.executeUpdate();
                        ps.close();
                        intCount++;
                        intCount1++;
                        if (loopValue == intCount) {
                            topStove1 += loopValue;
                            group++;
                            intCount = 0;
                        }

                    }
                }

            }
        } else {
            String sql = "UPDATE PLN_ZY_JGX_M T SET T.LOT_NO_GROUP='1'"
                    + " WHERE T.PRO_PLAN_ID=? AND T.GX_PLAN_NO=? AND TO_NUMBER(T.LOT_NO_SQE) >?";
            ps = con.prepareStatement(sql);
            ps.setObject(1, proPlanId);
            ps.setObject(2, gxPlanNo);
            ps.setObject(3, topStove);
            ps.executeUpdate();
            ps.close();
        }
    }


    /**
     * COM_BASE_INFO通用基础信息查询
     * @param sortCode 快速检索码
     * @return CoreReturnObject 通用基础信息集合
     */
    public CoreReturnObject getBaseInfo(String sortCode) {
        return this.getDataBySqlID("PlanService.COMMQUERY",
                new Object[]{sortCode});
    }


    /**
     * COM_BASE_INFO通用基础信息查询
     * @param sortCode 快速检索码
     * @return CoreReturnObject 通用基础信息集合
     */
    public CoreReturnObject getBaseInfoOrder(String sortCode) {
        return this.getDataBySqlID("PlanService.COMMQUERY3",
                new Object[]{sortCode});
    }


    /**
     * COM_BASE_INFO通用基础信息查询
     * @param sortCode 快速检索码
     * @return CoreReturnObject 通用基础信息集合
     */
    public CoreReturnObject getBaseInfoSingle(String sortCode) {
        return this.getDataBySqlID("PlanService.COMMQUERY1",
                new Object[]{sortCode});
    }



    /**
     *
     */
    public CoreReturnObject getTreeData(ArrayList<String> sortCodes) {
        String sql = CoreXmlSqlParsersFactory.getSql("PlanService.TreeData");

        if (sortCodes.size() > 0) {
            sql += "  AND ( 1<> 1 ";
            for (int i = 0; i < sortCodes.size(); i++) {

                sql += " OR BASECODE LIKE '" + sortCodes.get(i) + "%'";

            }

            sql += "  ) ";
        } else {



        }

        sql += "        ORDER BY BASECODE";

        return this.getData(sql);
    }


    /**
     * COM_BASE_INFO通用基础信息查询
     * @param sortCode 快速检索码
     * @return CoreReturnObject 通用基础信息集合
     */
    public CoreReturnObject getBaseInfoAll(String sortCode) {
        return this.getDataBySqlID("PlanService.COMMQUERY2",
                new Object[]{sortCode});
    }


    /**
     * COM_BASE_INFO通用基础信息查询
     * @param sortCode 快速检索码
     * @return CoreReturnObject 通用基础信息集合
     */
    public CoreReturnObject getBaseInfoAll(String sortCode, String[] items) {

        String sql = CoreXmlSqlParsersFactory.getSql("PlanService.COMMQUERY3");
        sql += CoreConverter.toSqlNotLikeConditionString("T.BASECODE", items);
        sql += "  ORDER BY T.BASECODE";

        return this.getData(sql,
                new Object[]{sortCode});
    }


    /**
     * 热处理炉计划取消下发根据工序删除虚拟炉计划(自炼)
     */
    public static void deletePlnFurnJgx(String heatPlanNo, Connection con) throws Exception {

        PreparedStatement ps = null;
        ResultSet rs = null;
        String sql = "";
        // 获取当前下发炉次订单信息
        PlnZyRclMEntity stord = PlanService.getSendHttPlanCInfo(con,
                heatPlanNo);
        if (stord == null) {
            return;
        }


        if (!stord.getHeatPlanNoOld().equals("")) {
            return;
        }
        if (!stord.getNextProcessCode().equals("")) {
            // 删除虚拟炉计划
            if (stord.getNextProcessCode().equals("F")) {// 热处理工序
                sql = "SELECT T.HEAT_PLAN_NO,T.PLANSTATUS,T.PLN_INSINGLE_NUM,T.PLN_INSINGLE_WT,"
                        + "T.PRO_PLAN_ID,T.GX_PLAN_NO,T.PLINE_CODE,T.GX_PRO_SEQ FROM PLN_ZY_RCL_M  T WHERE T.UPPER_HEATPLAN_ID=?";
                ps = con.prepareStatement(sql);
                ps.setObject(1, stord.getHeatPlanNo());
                rs = ps.executeQuery();
                while (rs.next()) {
                    int countNum = 0;
                    if (!rs.getString("PLANSTATUS").equals("00")) {
                        throw new Exception("判定炉号:" + stord.getFeedHeatNo()
                                + "的热处理虚拟炉计划已下发,不能撤销");
                    }
                    // 查询是否存在实际炉计划
                    String sqlZgC = "SELECT COUNT(*) COUNT FROM PLN_ZY_RCL_C T WHERE T.HEAT_PLAN_NO=?";
                    PreparedStatement psC = con.prepareStatement(sqlZgC);
                    psC.setObject(1, rs.getString("HEAT_PLAN_NO"));
                    ResultSet rsC = psC.executeQuery();
                    if (rsC.next()) {
                        countNum = rsC.getInt("COUNT");
                    }
                    rsC.close();
                    psC.close();
                    if (countNum > 0) {
                        throw new Exception("判定炉号:" + stord.getJudgeStoveNo()
                                + "的热处理虚拟炉计划存在实际炉计划,不能撤销");
                    }
                    // 删除虚拟炉计划
                    String sqlDeleteZg = "DELETE PLN_ZY_RCL_M  WHERE HEAT_PLAN_NO = ? ";
                    psC = con.prepareStatement(sqlDeleteZg);
                    psC.setObject(1, rs.getString("HEAT_PLAN_NO"));
                    psC.executeUpdate();
                    psC.close();

                    // 更新订单虚拟挂料量
                    // String update =
                    // "UPDATE PLN_ORDER_RCL_S T SET T.BATCHED_NUM=TO_NUMBER(NVL(T.BATCHED_NUM,0))-TO_NUMBER(?),"
                    // +
                    // "T.BATCHED_WT=TO_NUMBER(NVL(T.BATCHED_WT,0))-TO_NUMBER(?) WHERE T.PRO_PLAN_ID=? AND T.GX_PLAN_NO=?";
                    // ps = con.prepareStatement(update);
                    // ps.setObject(1, rs.getString("PLN_INSINGLE_NUM"));
                    // ps.setObject(2, rs.getString("PLN_INSINGLE_WT"));
                    // ps.setObject(3, rs.getString("PRO_PLAN_ID"));
                    // ps.setObject(4, rs.getString("GX_PLAN_NO"));
                    // ps.executeUpdate();
                    // ps.close();
                }
                rs.close();
                ps.close();
            } else if (stord.getNextProcessCode().equals("G")) {// 加工工序
                sql = "SELECT T.HEAT_PLAN_NO,T.PLANSTATUS,T.PLN_INSINGLE_NUM,T.PLN_INSINGLE_WT,"
                        + "T.PRO_PLAN_ID,T.GX_PLAN_NO,T.PLINE_CODE,T.GX_PRO_SEQ FROM PLN_ZY_JGX_M  T WHERE T.UPPER_HEATPLAN_ID=?";
                ps = con.prepareStatement(sql);
                ps.setObject(1, stord.getHeatPlanNo());
                rs = ps.executeQuery();
                while (rs.next()) {
                    int countNum = 0;
                    if (!rs.getString("PLANSTATUS").equals("00")) {

                        throw new Exception("判定炉号:" + stord.getFeedHeatNo()
                                + "的加工线虚拟炉计划已下发,不能撤销");
                    }
                    // 查询是否存在实际炉计划
                    String sqlZgC = "SELECT COUNT(*) COUNT FROM PLN_ZY_JGX_C T WHERE T.HEAT_PLAN_NO=?";
                    PreparedStatement psC = con.prepareStatement(sqlZgC);
                    psC.setObject(1, rs.getString("HEAT_PLAN_NO"));
                    ResultSet rsC = psC.executeQuery();
                    if (rsC.next()) {
                        countNum = rsC.getInt("COUNT");
                    }
                    rsC.close();
                    psC.close();
                    if (countNum > 0) {
                        throw new Exception("判定炉号:" + stord.getFeedHeatNo()
                                + "的加工线虚拟炉计划存在实际炉计划,不能撤销");
                    }
                    // 删除虚拟炉计划
                    String sqlDeleteZg = "DELETE PLN_ZY_JGX_M  WHERE HEAT_PLAN_NO = ? ";
                    psC = con.prepareStatement(sqlDeleteZg);
                    psC.setObject(1, rs.getString("HEAT_PLAN_NO"));
                    psC.executeUpdate();
                    psC.close();
                    // 更新订单虚拟挂料量
                    // String update =
                    // "UPDATE PLN_ORDER_JGX_S T SET T.BATCHED_NUM=TO_NUMBER(NVL(T.BATCHED_NUM,0))-TO_NUMBER(?),"
                    // +
                    // "T.BATCHED_WT=TO_NUMBER(NVL(T.BATCHED_WT,0))-TO_NUMBER(?) WHERE T.PRO_PLAN_ID=? AND T.GX_PLAN_NO=?";
                    // ps = con.prepareStatement(update);
                    // ps.setObject(1, rs.getString("PLN_INSINGLE_NUM"));
                    // ps.setObject(2, rs.getString("PLN_INSINGLE_WT"));
                    // ps.setObject(3, rs.getString("PRO_PLAN_ID"));
                    // ps.setObject(4, rs.getString("GX_PLAN_NO"));
                    // ps.executeUpdate();
                    // ps.close();

                }
                rs.close();
                ps.close();
            } else if (stord.getNextProcessCode().equals("H")) {
                sql = "SELECT T.HEAT_PLAN_NO,T.PLANSTATUS,T.PRO_PLAN_ID,T.GX_PLAN_NO,T.PLINE_CODE,T.GX_PRO_SEQ FROM PLN_ZY_JG_M  T WHERE T.UPPER_HEATPLAN_ID=? AND T.ORD_LN_DLY_PK = ?";
                ps = con.prepareStatement(sql);
                ps.setObject(1, stord.getHeatPlanNo());
                ps.setObject(2, stord.getOrdLnDlyPk());
                rs = ps.executeQuery();
                while (rs.next()) {
                    int countNum = 0;
                    if (!rs.getString("PLANSTATUS").equals("00")) {
                        throw new Exception("判定炉号:" + stord.getFeedHeatNo()
                                + "的接箍虚拟炉计划已下发,不能撤销");
                    }
                    // 查询是否存在实际炉计划
                    String sqlZgC = "SELECT COUNT(*) COUNT FROM PLN_ZY_JG_C T WHERE T.HEAT_PLAN_NO=?";
                    PreparedStatement psC = con.prepareStatement(sqlZgC);
                    psC.setObject(1, rs.getString("HEAT_PLAN_NO"));
                    ResultSet rsC = psC.executeQuery();
                    if (rsC.next()) {
                        countNum = rsC.getInt("COUNT");
                    }
                    rsC.close();
                    psC.close();
                    if (countNum > 0) {
                        throw new Exception("判定炉号:" + stord.getFeedHeatNo()
                                + "的接箍虚拟炉计划存在实际炉计划,不能撤销");
                    }
                    // 删除虚拟炉计划
                    String sqlDeleteZg = "DELETE PLN_ZY_JG_M  WHERE HEAT_PLAN_NO = ? ";
                    psC = con.prepareStatement(sqlDeleteZg);
                    psC.setObject(1, rs.getString("HEAT_PLAN_NO"));
                    psC.executeUpdate();
                    psC.close();
                }
                rs.close();
                ps.close();
            }
        }

    }


    /**
     * 镦拔扩炉计划取消下发根据工序删除虚拟炉计划(自炼)
     */
    public static void deletePlnFurnRcl(String heatPlanNo, Connection con) throws Exception {
        String mess = "";
        PreparedStatement ps = null;
        ResultSet rs = null;
        String sql = "";
        // 获取当前下发炉次订单信息
        PlnZyDbkMEntity stord = PlanService.getSendDBKPlanCInfo(con,
                heatPlanNo);

        if (stord == null) {
            mess = "未查到镦拔扩炉计划信息,请确认!";
            throw new Exception(mess);
        }
        if (!stord.getHeatPlanNoOld().equals("")) {
            return;
        }
        if (!stord.getNextProcessCode().equals("")) {
            // 删除虚拟炉计划
            if (stord.getNextProcessCode().equals("F")) {// 热处理工序
                sql = "SELECT T.HEAT_PLAN_NO,T.PLANSTATUS,T.PLN_INSINGLE_NUM,T.PLN_INSINGLE_WT,"
                        + "T.PRO_PLAN_ID,T.GX_PLAN_NO,T.PLINE_CODE,T.GX_PRO_SEQ FROM PLN_ZY_RCL_M  T WHERE T.UPPER_HEATPLAN_ID=?";
                ps = con.prepareStatement(sql);
                ps.setObject(1, stord.getHeatPlanNo());
                rs = ps.executeQuery();
                while (rs.next()) {
                    int countNum = 0;
                    if (!rs.getString("PLANSTATUS").equals("00")) {
                        mess = "判定炉号:" + stord.getFeedHeatNo()
                                + "的热处理虚拟炉计划已下发,不能撤销";
                        throw new Exception(mess);
                    }
                    // 查询是否存在实际炉计划
                    String sqlZgC = "SELECT COUNT(*) COUNT FROM PLN_ZY_RCL_C T WHERE T.HEAT_PLAN_NO=?";
                    PreparedStatement psC = con.prepareStatement(sqlZgC);
                    psC.setObject(1, rs.getString("HEAT_PLAN_NO"));
                    ResultSet rsC = psC.executeQuery();
                    if (rsC.next()) {
                        countNum = rsC.getInt("COUNT");
                    }
                    rsC.close();
                    psC.close();
                    if (countNum > 0) {
                        mess = "判定炉号:" + stord.getJudgeStoveNo()
                                + "的热处理虚拟炉计划存在实际炉计划,不能撤销";
                        throw new Exception(mess);
                    }
                    // 删除虚拟炉计划
                    String sqlDeleteZg = "DELETE PLN_ZY_RCL_M  WHERE HEAT_PLAN_NO = ? ";
                    psC = con.prepareStatement(sqlDeleteZg);
                    psC.setObject(1, rs.getString("HEAT_PLAN_NO"));
                    psC.executeUpdate();
                    psC.close();

                    // 更新订单虚拟挂料量
                    // String update =
                    // "UPDATE PLN_ORDER_RCL_S T SET T.BATCHED_NUM=TO_NUMBER(NVL(T.BATCHED_NUM,0))-TO_NUMBER(?),"
                    // +
                    // "T.BATCHED_WT=TO_NUMBER(NVL(T.BATCHED_WT,0))-TO_NUMBER(?) WHERE T.PRO_PLAN_ID=? AND T.GX_PLAN_NO=?";
                    // ps = con.prepareStatement(update);
                    // ps.setObject(1, rs.getString("PLN_INSINGLE_NUM"));
                    // ps.setObject(2, rs.getString("PLN_INSINGLE_WT"));
                    // ps.setObject(3, rs.getString("PRO_PLAN_ID"));
                    // ps.setObject(4, rs.getString("GX_PLAN_NO"));
                    // ps.executeUpdate();
                    // ps.close();
                }
                rs.close();
                ps.close();
            } else if (stord.getNextProcessCode().equals("G")) {// 加工工序
                sql = "SELECT T.HEAT_PLAN_NO,T.PLANSTATUS,T.PLN_INSINGLE_NUM,T.PLN_INSINGLE_WT,"
                        + "T.PRO_PLAN_ID,T.GX_PLAN_NO,T.PLINE_CODE,T.GX_PRO_SEQ FROM PLN_ZY_JGX_M  T WHERE T.UPPER_HEATPLAN_ID=? ";
                ps = con.prepareStatement(sql);
                ps.setObject(1, stord.getHeatPlanNo());
                rs = ps.executeQuery();
                while (rs.next()) {
                    int countNum = 0;
                    if (!rs.getString("PLANSTATUS").equals("00")) {
                        mess = "判定炉号:" + stord.getFeedHeatNo()
                                + "的加工线虚拟炉计划已下发,不能撤销";
                        throw new Exception(mess);
                    }
                    // 查询是否存在实际炉计划
                    String sqlZgC = "SELECT COUNT(*) COUNT FROM PLN_ZY_JGX_C T WHERE T.HEAT_PLAN_NO=?";
                    PreparedStatement psC = con.prepareStatement(sqlZgC);
                    psC.setObject(1, rs.getString("HEAT_PLAN_NO"));
                    ResultSet rsC = psC.executeQuery();
                    if (rsC.next()) {
                        countNum = rsC.getInt("COUNT");
                    }
                    rsC.close();
                    psC.close();
                    if (countNum > 0) {
                        mess = "判定炉号:" + stord.getJudgeStoveNo()
                                + "的加工线虚拟炉计划存在实际炉计划,不能撤销";
                        throw new Exception(mess);
                    }
                    // 删除虚拟炉计划
                    String sqlDeleteZg = "DELETE PLN_ZY_JGX_M  WHERE HEAT_PLAN_NO = ? ";
                    psC = con.prepareStatement(sqlDeleteZg);
                    psC.setObject(1, rs.getString("HEAT_PLAN_NO"));
                    psC.executeUpdate();
                    psC.close();
                    // 更新订单虚拟挂料量
                    // String update =
                    // "UPDATE PLN_ORDER_JGX_S T SET T.BATCHED_NUM=TO_NUMBER(NVL(T.BATCHED_NUM,0))-TO_NUMBER(?),"
                    // +
                    // "T.BATCHED_WT=TO_NUMBER(NVL(T.BATCHED_WT,0))-TO_NUMBER(?) WHERE T.PRO_PLAN_ID=? AND T.GX_PLAN_NO=?";
                    // ps = con.prepareStatement(update);
                    // ps.setObject(1, rs.getString("PLN_INSINGLE_NUM"));
                    // ps.setObject(2, rs.getString("PLN_INSINGLE_WT"));
                    // ps.setObject(3, rs.getString("PRO_PLAN_ID"));
                    // ps.setObject(4, rs.getString("GX_PLAN_NO"));
                    // ps.executeUpdate();
                    // ps.close();

                }
                rs.close();
                ps.close();
            } else if (stord.getNextProcessCode().equals("H")) {
                sql = "SELECT T.HEAT_PLAN_NO,T.PLANSTATUS,T.PRO_PLAN_ID,T.GX_PLAN_NO,T.PLINE_CODE,T.GX_PRO_SEQ FROM PLN_ZY_JG_M  T WHERE T.UPPER_HEATPLAN_ID=? AND T.ORD_LN_DLY_PK = ? ";
                ps = con.prepareStatement(sql);
                ps.setObject(1, stord.getHeatPlanNo());
                ps.setObject(2, stord.getOrdLnDlyPk());
                rs = ps.executeQuery();
                while (rs.next()) {
                    int countNum = 0;
                    if (!rs.getString("PLANSTATUS").equals("00")) {
                        mess = "判定炉号:" + stord.getFeedHeatNo()
                                + "的接箍虚拟炉计划已下发,不能撤销";
                        throw new Exception(mess);
                    }
                    // 查询是否存在实际炉计划
                    String sqlZgC = "SELECT COUNT(*) COUNT FROM PLN_ZY_JG_C T WHERE T.HEAT_PLAN_NO=?";
                    PreparedStatement psC = con.prepareStatement(sqlZgC);
                    psC.setObject(1, rs.getString("HEAT_PLAN_NO"));
                    ResultSet rsC = psC.executeQuery();
                    if (rsC.next()) {
                        countNum = rsC.getInt("COUNT");
                    }
                    rsC.close();
                    psC.close();
                    if (countNum > 0) {
                        mess = "判定炉号:" + stord.getFeedHeatNo()
                                + "的接箍虚拟炉计划存在实际炉计划,不能撤销";
                        throw new Exception(mess);
                    }
                    // 删除虚拟炉计划
                    String sqlDeleteZg = "DELETE PLN_ZY_JG_M  WHERE HEAT_PLAN_NO = ? ";
                    psC = con.prepareStatement(sqlDeleteZg);
                    psC.setObject(1, rs.getString("HEAT_PLAN_NO"));
                    psC.executeUpdate();
                    psC.close();
                }
                rs.close();
                ps.close();
            }
        }
    }


    /**
     * 加工线计划取消下发删除接箍虚拟炉计划
     */
    public static void deletePlnFurnJg(String heatPlanNo, Connection con) throws Exception {
        String mess = "";
        PreparedStatement ps = null;
        ResultSet rs = null;
        String sql = "";
        // 获取当前下发炉次订单信息
        PlnZyJgxMEntity stord = PlanService.getSendHttPlanCInfo3(con,
                heatPlanNo);
        if (stord == null) {
            // mess = "未查到热处理炉计划信息,请确认!";
            return;
        }

        if (!stord.getHeatPlanNoOld().equals("")) {
            return;
        }
        sql = "SELECT T.HEAT_PLAN_NO,T.PLANSTATUS,T.PRO_PLAN_ID,T.GX_PLAN_NO,T.PLINE_CODE,T.GX_PRO_SEQ FROM PLN_ZY_JG_M  T WHERE T.UPPER_HEATPLAN_ID=? AND T.ORD_LN_DLY_PK = ?";
        ps = con.prepareStatement(sql);
        ps.setObject(1, stord.getHeatPlanNo());
        ps.setObject(2, stord.getOrdLnDlyPk());
        rs = ps.executeQuery();
        while (rs.next()) {
            int countNum = 0;
            if (!rs.getString("PLANSTATUS").equals("00")) {
                mess = "判定炉号:" + stord.getFeedHeatNo() + "的接箍虚拟炉计划已下发,不能撤销";
                throw new Exception(mess);
            }
            // 查询是否存在实际炉计划
            String sqlZgC = "SELECT COUNT(*) COUNT FROM PLN_ZY_JG_C T WHERE T.HEAT_PLAN_NO=?";
            PreparedStatement psC = con.prepareStatement(sqlZgC);
            psC.setObject(1, rs.getString("HEAT_PLAN_NO"));
            ResultSet rsC = psC.executeQuery();
            if (rsC.next()) {
                countNum = rsC.getInt("COUNT");
            }
            rsC.close();
            psC.close();
            if (countNum > 0) {
                mess = "判定炉号:" + stord.getFeedHeatNo()
                        + "的接箍虚拟炉计划存在实际炉计划,不能撤销";
                throw new Exception(mess);
            }
            // 删除虚拟炉计划
            String sqlDeleteZg = "DELETE PLN_ZY_JG_M  WHERE HEAT_PLAN_NO = ? ";
            psC = con.prepareStatement(sqlDeleteZg);
            psC.setObject(1, rs.getString("HEAT_PLAN_NO"));
            psC.executeUpdate();
            psC.close();
        }
        rs.close();
        ps.close();

    }

    /**
     * 生成SQL where条件字符串 "and condition in('args[1],args[2],...')"  AND  IN
     * @param column 条件列
     * @param args   条件参数
     * @return String sql条件字符串
     */
    public static String toSqlConditionString(String column, String[] args) {

        StringBuffer sb = new StringBuffer();

        if (args != null && args.length > 0) {
            sb.append(" AND (");
            sb.append(column.toUpperCase());
            sb.append(" IN(");

            int inNum = 1; //已拼装IN条件数量
            for (int i = 0; i < args.length; i++) {

                if (StringUtil.isEmpty(args[i])) continue;

                //这里不要犯低级错误而写成：if(i == custNOs.length)
                if (i == (args.length - 1))
                    sb.append("'" + args[i] + "'");    //SQL拼装，最后一条不加“,”。
                else if (inNum == 1000 && i > 0) {
                    sb.append("'" + args[i] + "' ) OR " + column.toUpperCase() + " IN ( ");    //解决ORA-01795问题
                    inNum = 1;
				}
				else {
                    sb.append("'" + args[i] + "', ");
                    inNum++;
                }

            }

            sb.append("))");
		}
		else{
            return " AND 1!=1";
        }
        return sb.toString();
    }

    /**
     * 投料库
     * @param PlineCode
     * @param conn
     * @return
     */
    public static String GetStorageIn(String PlineCode, Connection conn) throws SQLException {
        String STORAGE_NO = "";
        PreparedStatement psta = null;
        String sqlLovsqe = CoreXmlSqlParsersFactory
                .getSql("PlanService.GetStorageIn");
        psta = conn.prepareStatement(sqlLovsqe);
        psta.setString(1, PlineCode);
        ResultSet rs = psta.executeQuery();
        if (rs.next()) {
            STORAGE_NO = rs.getString("STORAGE_NO");
        }
        rs.close();
        psta.close();
        return STORAGE_NO;
    }


    /**
     * 投料库
     * @param PlineCode
     * @param conn
     * @return
     */
    public static String GetStorageOut(String PlineCode, Connection conn) throws SQLException {
        String STORAGE_NO = "";
        PreparedStatement psta = null;
        String sqlLovsqe = CoreXmlSqlParsersFactory
                .getSql("PlanService.GetStorageOut");
        psta = conn.prepareStatement(sqlLovsqe);
        psta.setString(1, PlineCode);
        ResultSet rs = psta.executeQuery();
        if (rs.next()) {
            STORAGE_NO = rs.getString("STORAGE_NO");
        }
        rs.close();
        psta.close();
        return STORAGE_NO;
    }


    public CoreReturnObject SaveBarcode(ArrayList<String> PortMch) {
        CoreReturnObject core = new CoreReturnObject();
        Connection connection = this.getDao(CoreConstantData.sysbeanstr)
                .getConnection();
        PreparedStatement psta = null;
        SimpleDateFormat matter1 = new SimpleDateFormat("yyMMdd");
        try {
            connection.setAutoCommit(false); // 取消自动提交事务


            String sql = CoreXmlSqlParsersFactory.getSql("PlanService.SaveBarcode");
            PreparedStatement past = connection.prepareStatement(sql);

            for (int i = 0; i < PortMch.size(); i++) {

                PortMchBatchSampleResultEntity entity = EntityTool.getEntityByJSONStr(PortMch.get(i), PortMchBatchSampleResultEntity.class);
                past.setObject(1, entity.getBarCode());
                past.setObject(2, entity.getHeatPlanNo());
                past.setObject(3, entity.getMatNo());
                past.addBatch();

            }




            past.executeBatch();

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


    public CoreReturnObject SaveRemark(ArrayList<String> PortMch,String remark) {
        CoreReturnObject core = new CoreReturnObject();
        Connection connection = this.getDao(CoreConstantData.sysbeanstr)
                .getConnection();
        try {
            connection.setAutoCommit(false); // 取消自动提交事务

            String sql = CoreXmlSqlParsersFactory.getSql("PlanService.SaveRemark");
            PreparedStatement past = connection.prepareStatement(sql);

            for (int i = 0; i < PortMch.size(); i++) {

                PortMchBatchSampleResultEntity entity = EntityTool.getEntityByJSONStr(PortMch.get(i), PortMchBatchSampleResultEntity.class);
                past.setObject(1, remark);
                past.setObject(2, entity.getHeatPlanNo());
                past.setObject(3, entity.getMatNo());
                past.addBatch();

            }

            past.executeBatch();

            core.setV_errMsg("修改成功！");
            core.setResult("修改成功！");
            connection.commit();
        }
        catch (Exception e) {
            core.setV_errMsg(e.getMessage());
            core.setV_errCode(-1);
            core.setResult(1);
            if (connection != null) {
                try {
                    connection.rollback(); // 回滚事务
                }
                catch (Exception e2) {
                }
            }
        }
        finally {
            try {
                if (connection != null && !connection.isClosed()) {
                    connection.close();
                }
            }
            catch (Exception e2) {
            }
        }
        return core;
    }
    
    /**
     * TZH 24.4.24 新增获取外委合同号
     * @param sortCode 查询编码
     * @return CoreReturnObject 外委合同号
     */
    public CoreReturnObject getWwdd(String sortCode) {
        return this.getDataBySqlID("PlanService.QueryWwdd",
                new Object[]{sortCode});
    }
}
