package com.steering.mes.mcp.Vrp;

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

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

public class FrmVrpHoting extends DBCommon {

    /**
     * 热扩新增
     * @param load
     * @return
     */
    public CoreReturnObject saveHotingResult(VrpHotexpFaceMEntity load,
            ArrayList<VrpHotexpFaceDEntity> list, String slgx, String plinCode,String groupNo) {
        CoreReturnObject core = new CoreReturnObject();
        Connection connection = this.getDao(CoreConstantData.sysbeanstr)
                .getConnection();
        PreparedStatement psta = null;
        Date dt = new Date();
        SimpleDateFormat matter1 = new SimpleDateFormat("yyMMdd");
        SimpleDateFormat matter = new SimpleDateFormat("yyyy-MM-dd");
        Calendar ca = Calendar.getInstance();
        ca.set(Calendar.DATE, ca.getActualMaximum(Calendar.DATE));
        Date now = new Date();
        SimpleDateFormat dateFormat = new SimpleDateFormat(
                "yyyy-MM-dd HH:mm:ss", Locale.CHINA);
        String systime = dateFormat.format(now);
        try {
            connection.setAutoCommit(false); // 取消自动提交事务
            String sqlAdd = CoreXmlSqlParsersFactory
                    .getSql("FrmVrpHoting.AddVrpReKuo");// 新增热扩表检实绩主表
            PreparedStatement patAdd = connection.prepareStatement(sqlAdd);
            String sqlAddD = CoreXmlSqlParsersFactory
                    .getSql("FrmVrpHoting.AddAppearanceD");// 新增热扩表检实绩从表
            PreparedStatement patAddD = connection.prepareStatement(sqlAddD);
            String addPlnInfo = CoreXmlSqlParsersFactory
                    .getSql("FrmVrpExpandResult.AddComInfoResult");// 新增公共信息表
            PreparedStatement patsPlan = connection
                    .prepareStatement(addPlnInfo);
            String addPlnInfo1 = CoreXmlSqlParsersFactory
                    .getSql("FrmVrpHoting.AddComInfoResult1");// 查询材料状态和工序点编码
            PreparedStatement patsPlan1 = connection
                    .prepareStatement(addPlnInfo1);
            String updatePath = CoreXmlSqlParsersFactory
                    .getSql("FrmVrpHoting.UpdatePath");// 修改队列表工艺路径
            PreparedStatement pastupdatePath = connection
                    .prepareStatement(updatePath);
            String updatePln = CoreXmlSqlParsersFactory
                    .getSql("FrmVrpHoting.UpdatePln");// 新增修改计划表工序状态
            PreparedStatement pastupdatePln = connection
                    .prepareStatement(updatePln);
            // 获取镦拔扩计划实体类
            PlnZyDbkMEntity pln = PlanService.getSendDBKPlanCInfo(connection,
                    load.getHeatPlanNo());
            // 获取镦拔扩计划从表实体类
            PlnZyDbkCEntity plnC = PlanService.getSendDBKPlanCInfoC(connection,
                    load.getHeatPlanNo());
            if (pln == null)
                return core;
            if (!pln.getPlanstatus().equals("20")) {
                core.setV_errMsg("该计划不是生产中的状态！");
                return core;
            }
            String resultNo = "";
            String sqlloading = CoreXmlSqlParsersFactory
                    .getSql("FrmVrpHoting.queryHotKEY");// 查询最大实绩编号
            psta = connection.prepareStatement(sqlloading);
            psta.setObject(1, plinCode + slgx + matter1.format(dt));
            psta.setObject(2, matter.format(dt));
            psta.setObject(3, pln.getPlineCode());
            ResultSet rs1 = psta.executeQuery();
            if (rs1.next()) {
                resultNo = rs1.getString("RESULT_NO");
            }
            rs1.close();
            psta.close();
            // 新增热扩实绩
            patAdd.setObject(1, resultNo);
            patAdd.setObject(2, pln.getHeatPlanNo());
            patAdd.setObject(3, pln.getZyBatchId());
            patAdd.setObject(4, pln.getProPlanId());
            patAdd.setObject(5, pln.getGxPlanNo());
            patAdd.setObject(6, pln.getPlineCode());
            patAdd.setObject(7, pln.getPlineName());
            patAdd.setObject(8, load.getSizeD());
            patAdd.setObject(9, load.getSizeS());
            patAdd.setObject(10, load.getSizeW());
            patAdd.setObject(11, load.getSizeL());
            patAdd.setObject(12, load.getProNum());
            patAdd.setObject(13, load.getProWt());
            patAdd.setObject(14, load.getAccNum());
            patAdd.setObject(15, load.getAccWt());
            patAdd.setObject(16, load.getFailNum());
            patAdd.setObject(17, load.getFailWt());
            patAdd.setObject(18, load.getOfflineNum());
            patAdd.setObject(19, load.getOfflineWt());
            patAdd.setObject(20, load.getReNum());
            patAdd.setObject(21, load.getReWt());
            patAdd.setObject(22, "");// 监制要求
            patAdd.setObject(23, load.getIfMonitorDbk());
            patAdd.setObject(24, load.getProducer());
            patAdd.setObject(25, load.getPrdcrNo());
            if (load.getProducer().equals("")) {
                patAdd.setObject(26, "");
            }
            else {
                patAdd.setObject(26, load.getProducerTime());
            }
            patAdd.setObject(27, load.getLoadTime());
            patAdd.setObject(28, load.getLoadShift());
            patAdd.setObject(29, load.getLoadGroup());
            patAdd.setObject(30, load.getLoadUser());
            patAdd.setObject(31, "1");
            patAdd.setObject(32, systime);
            patAdd.addBatch();
            // 新增公共信息
            patsPlan.setObject(1, resultNo);
            patsPlan.setObject(2, pln.getHeatPlanNo());
            patsPlan.setObject(3, slgx);
            patsPlan.setObject(4, "热扩表检");
            patsPlan.setObject(5, pln.getPlineCode());
            patsPlan.setObject(6, pln.getPlineName());
            patsPlan.setObject(7, pln.getZyBatchId());
            patsPlan.setObject(8, pln.getProPlanId());
            patsPlan.setObject(9, pln.getGxPlanNo());
            patsPlan.setObject(10, pln.getIfMonitor());
            patsPlan.setObject(11, pln.getPrdcrNo());
            patsPlan.setObject(12, "");// 监制要求
            patsPlan.setObject(13, load.getProducer());
            if (load.getProducer().equals("")) {
                patsPlan.setObject(14, "");
            }
            else {
                patsPlan.setObject(14, load.getProducerTime());
            }
            patsPlan.setObject(15, pln.getCraftFileNo());
            patsPlan.setObject(16, pln.getCraftFileMan());
            patsPlan.setObject(17, pln.getCraftSeq());
            patsPlan.setObject(18, pln.getJudgeStoveNo());
            patsPlan.setObject(19, plnC.getBatchNo());
            patsPlan.setObject(20, groupNo);// 组号
            patsPlan.setObject(21, pln.getGradecode());
            patsPlan.setObject(22, pln.getGradename());
            patsPlan.setObject(23, pln.getLengthIn());
            patsPlan.setObject(24, pln.getOutdiameterIn());
            patsPlan.setObject(25, pln.getAimlength());
            patsPlan.setObject(26, pln.getWallthickIn());
            patsPlan.setObject(27, pln.getLengthminIn());
            patsPlan.setObject(28, pln.getLengthmaxIn());
            patsPlan.setObject(29, pln.getLenCuthead());
            patsPlan.setObject(30, pln.getLenCutend());
            patsPlan.setObject(31, pln.getAimoutdiameter());
            patsPlan.setObject(32, pln.getAimwallthick());
            patsPlan.setObject(33, pln.getOutwlId());// 物料码
            patsPlan.setObject(34, pln.getOutwlDesc());
            patsPlan.setObject(35, pln.getInwlId());
            patsPlan.setObject(36, pln.getInwlDesc());
            patsPlan.setObject(37, load.getProNum());
            patsPlan.setObject(38, load.getProWt());
            patsPlan.setObject(39, load.getFailNum());
            patsPlan.setObject(40, load.getFailWt());
            patsPlan.setObject(41, load.getOfflineNum());
            patsPlan.setObject(42, load.getOfflineWt());
            patsPlan.setObject(43, load.getReNum());
            patsPlan.setObject(44, load.getReWt());
            patsPlan.setObject(45, "1");
            patsPlan.setObject(46, load.getLoadTime());
            patsPlan.setObject(47, "");
            patsPlan.setObject(48, load.getLoadUser());
            patsPlan.setObject(49, load.getLoadShift());
            patsPlan.setObject(50, load.getLoadGroup());
            patsPlan.setObject(51, systime);
            patsPlan.setObject(52, "");
            patsPlan.setObject(53, pln.getSteelcode());
            patsPlan.setObject(54, pln.getSteelname());
            patsPlan.setObject(55, pln.getSpecCode());
            patsPlan.setObject(56, pln.getSpecName());
            patsPlan.addBatch();
            for (int i = 0; i < list.size(); i++) {
                String MResultNo = "";
                String sqlload = CoreXmlSqlParsersFactory
                        .getSql("FrmVrpHoting.queryHotingDKEY");// 查询检验表最大实绩编号
                psta = connection.prepareStatement(sqlload);
                psta.setObject(1, resultNo);
                ResultSet rs2 = psta.executeQuery();
                if (rs2.next()) {
                    MResultNo = rs2.getString("M_RESULT_NO");
                }
                rs2.close();
                psta.close();

                VrpHotexpFaceDEntity resultD = list.get(i);
                patAddD.setObject(1, resultNo);// 主表的主键
                patAddD.setObject(2, MResultNo);
                patAddD.setObject(3, resultD.getSqeNo());
                patAddD.setObject(4, resultD.getEndD1());
                patAddD.setObject(5, resultD.getEndD2());
                patAddD.setObject(6, resultD.getEndS1());
                patAddD.setObject(7, resultD.getEndS2());
                patAddD.setObject(8, resultD.getEndS3());
                patAddD.setObject(9, resultD.getEndS4());
                patAddD.setObject(10, resultD.getChkW());
                patAddD.setObject(11, resultD.getChkL());
                patAddD.setObject(12, resultD.getChkRes());
                patAddD.setObject(13, resultD.getChkPass());
                patAddD.setObject(14, systime);
                patAddD.setObject(15, resultD.getCreateName());
                patAddD.addBatch();
                patAddD.executeBatch();
            }

            ArrayList<String> matNo = new ArrayList<String>();
            String sqlloading1 = CoreXmlSqlParsersFactory
                    .getSql("FrmVrpHoting.queryExpandNUM");// 查询管号队列里合格的材料号
            psta = connection.prepareStatement(sqlloading1);
            psta.setObject(1, pln.getHeatPlanNo());
            psta.setObject(2, Integer.parseInt(load.getFailNum()) + 1);
            ResultSet rs2 = psta.executeQuery();
            while (rs2.next()) {
                matNo.add(rs2.getString("MAT_NO"));
            }
            rs2.close();
            psta.close();


            if(matNo.size()!=Integer.parseInt(load.getFailNum())  ){
                core.setV_errMsg("没有足够的未下线的合格管！请确认");
                return core;
            }

            for (int i = 0; i < matNo.size(); i++) {
                patsPlan1.setObject(1, "10");
                patsPlan1.setObject(2, slgx);
                patsPlan1.setObject(3, pln.getHeatPlanNo());
                patsPlan1.setObject(4, matNo.get(i));
                patsPlan1.addBatch();
            }
            // 修改工艺路径
            pastupdatePath.setObject(1, "1");
            pastupdatePath.setObject(2, pln.getHeatPlanNo());
            pastupdatePath.addBatch();
            pastupdatePath.executeBatch();

            // 新增修改计划状态
            pastupdatePln.setObject(1, pln.getHeatPlanNo());
            pastupdatePln.addBatch();
            pastupdatePln.executeBatch();
            


			// 如果有废品新增到材料表
			if (!load.getFailNum().equals("") && !load.getFailNum().equals("0")) {
				for (int i = 0; i < matNo.size(); i++) {
                    PlanService.AddOffLineMat(connection,"E",load.getLoadUser(),"22",
                            matNo.get(i),slgx,load.getHeatPlanNo());
					
				}
			}
            patsPlan1.executeBatch();
            patAdd.executeBatch();
            patsPlan.executeBatch();

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

    /**
     * 撤销热扩
     * @param planNo
     * @return
     */
    @SuppressWarnings("unchecked")
    public CoreReturnObject returnHotingResult(ArrayList<String> list1,
            ArrayList<Object> list2, String herPlanNo, String plinCode,
            String gx, String flag,Integer detCount) {
        CoreReturnObject core = new CoreReturnObject();
        Connection connection = this.getDao(CoreConstantData.sysbeanstr)
                .getConnection();
        try {
            connection.setAutoCommit(false); // 取消自动提交事务
            String sqlDelete = CoreXmlSqlParsersFactory
                    .getSql("FrmVrpHoting.ReturnVrpHotingResult");// 删除热扩主表实绩
            PreparedStatement patDelete = connection
                    .prepareStatement(sqlDelete);
            String sqlDeleteD = CoreXmlSqlParsersFactory
                    .getSql("FrmVrpHoting.ReturnVrpHotingDResult");// 删除热扩从表实绩
            PreparedStatement patDeleteD = connection
                    .prepareStatement(sqlDeleteD);
            String sqlDeleteD1 = CoreXmlSqlParsersFactory
                    .getSql("FrmVrpHoting.ReturnVrpColdingD1Result");// 删除热扩表检实绩1
            PreparedStatement patDeleteD1 = connection
                    .prepareStatement(sqlDeleteD1);
            String updatePlnInfo = CoreXmlSqlParsersFactory
                    .getSql("FrmVrpHoting.deleteVrpResult");// 删除公共实绩表
            PreparedStatement patsupdatePlan = connection
                    .prepareStatement(updatePlnInfo);
            String addPlnInfo1 = CoreXmlSqlParsersFactory
                    .getSql("FrmVrpHoting.AddComInfoResult1");// 查询材料状态和工序点编码
            PreparedStatement patsPlan1 = connection
                    .prepareStatement(addPlnInfo1);
            String updatePath = CoreXmlSqlParsersFactory
                    .getSql("FrmVrpHoting.UpdatePath");// 修改队列表工艺路径
            PreparedStatement pastupdatePath = connection
                    .prepareStatement(updatePath);
            String updatePln = CoreXmlSqlParsersFactory
                    .getSql("FrmVrpHoting.UpdatePln1");// 撤销修改计划表工序状态
            PreparedStatement pastupdatePln = connection
                    .prepareStatement(updatePln);
            // 获取镦拔扩计划实体类
            PlnZyDbkMEntity pln = PlanService.getSendDBKPlanCInfo(connection,
                    herPlanNo);
            if (pln == null)
                return core;
            if (!pln.getPlanstatus().equals("20")) {
                core.setV_errMsg("该计划不是生产中的状态！");
                return core;
            }
            String cutFalg = "";
            String sql = CoreXmlSqlParsersFactory
                    .getSql("FrmVrpExpandResult.qureyGxComInfo");// 查询工序是不是结炉状态
            PreparedStatement psta = connection.prepareStatement(sql);
            psta.setString(1, herPlanNo);
            psta.setString(2, plinCode);
            psta.setString(3, gx);
            ResultSet rs = psta.executeQuery();
            if (rs.next()) {
                cutFalg = rs.getString("STATION_STATUS");
            }
            rs.close();
            psta.close();
            if (cutFalg.equals("2")) {
                core.setV_errMsg("已结炉,不允许此操作！");
                return core;
            }
          
/*            int lxCount = 0;
            sql = CoreXmlSqlParsersFactory
                    .getSql("FrmVrpMeasuring.qureyGxLxCount");// 查询是否离线
            psta = connection.prepareStatement(sql);
            psta.setString(1, herPlanNo);
            psta.setString(2, plinCode);
            psta.setString(3, gx);
            rs = psta.executeQuery();
            if (rs.next()) {
                lxCount = Integer.parseInt(rs.getString("COUNT"));
            }
            rs.close();
            psta.close();
            if (lxCount!=0) {
                core.setV_errMsg("该工序点有离线记录,不允许此操作！");
                return core;
            }*/
            if (flag.equals("0")) {

                String resNo = list1.get(0);
                // 删除热扩实绩
                patDelete.setObject(1, resNo);
                patDelete.addBatch();
                // 删除热扩从表实绩
                patDeleteD.setObject(1, resNo);
                patDeleteD.addBatch();
                // 删除公共实绩表
                patsupdatePlan.setObject(1, resNo);
                patsupdatePlan.addBatch();

                patDelete.executeBatch();
                patDeleteD.executeBatch();
                patsupdatePlan.executeBatch();
            }
            else {
                for (int i = 0; i < list2.size(); i++) {
                    ArrayList<String> list = (ArrayList<String>) list2.get(i);
                    String resNo = list.get(0);
                    String mresNo = list.get(1);
                    // 删除热扩表检实绩
                    patDeleteD1.setObject(1, resNo);
                    patDeleteD1.setObject(2, mresNo);
                    patDeleteD1.addBatch();
                    patDeleteD1.executeBatch();
                    int count = 0;
                    String sqlloading1 = CoreXmlSqlParsersFactory
                            .getSql("FrmVrpHoting.queryHotingD");// 查询是否还有抽检记录
                    psta = connection.prepareStatement(sqlloading1);
                    psta.setObject(1, resNo);
                    ResultSet rs1 = psta.executeQuery();
                    if (rs1.next()) {
                        count = Integer.parseInt(rs1.getString("COUNT"));
                    }
                    rs1.close();
                    psta.close();

                    if (count == 0) {
                        // 删除热扩主表实绩
                        patDelete.setObject(1, resNo);
                        patDelete.addBatch();
                        // 删除公共实绩表
                        patsupdatePlan.setObject(1, resNo);
                        patsupdatePlan.addBatch();
                    }
                }
                patDelete.executeBatch();
                patsupdatePlan.executeBatch();
            }

            int count = 0;
            String sqlloading1 = CoreXmlSqlParsersFactory
                    .getSql("FrmVrpHoting.queryExpandFailNUM");// 查询管号队列表里废品数量
            psta = connection.prepareStatement(sqlloading1);
            psta.setObject(1, herPlanNo);
            psta.setObject(2, gx);
            ResultSet rs2 = psta.executeQuery();
            if (rs2.next()) {
                count = Integer.parseInt(rs2.getString("ACT_COUNT"));
            }
            rs2.close();
            psta.close();

            if (count < detCount) {
            	core.setV_errMsg("管号队列的废品支数小于实绩废品支数，请检查!");
                return core;
            }else{
                ArrayList<String> matNo = new ArrayList<String>();
                String sqlloading3 = CoreXmlSqlParsersFactory
                        .getSql("FrmVrpHoting.queryExpandNUM2");// 查询管号队列表里废品材料号
                psta = connection.prepareStatement(sqlloading3);
                psta.setObject(1, herPlanNo);
                psta.setObject(2, gx);
                psta.setObject(3, detCount + 1);
                ResultSet rs4 = psta.executeQuery();
                while (rs4.next()) {
                    matNo.add(rs4.getString("MAT_NO"));
                }
                rs4.close();
                psta.close();

                for (int i = 0; i < matNo.size(); i++) {
                    patsPlan1.setObject(1, "00");
                    patsPlan1.setObject(2, gx);
                    patsPlan1.setObject(3, herPlanNo);
                    patsPlan1.setObject(4, matNo.get(i));
                    patsPlan1.addBatch();

                    PlanService.DeleteOffLineMat(connection,matNo.get(i));
                }
                patsPlan1.executeBatch();
            }
            // 修改工艺路径
            pastupdatePath.setObject(1, "0");
            pastupdatePath.setObject(2, herPlanNo);
            pastupdatePath.addBatch();
            pastupdatePath.executeBatch();

            // 撤销修改计划状态
            pastupdatePln.setObject(1, herPlanNo);
            pastupdatePln.addBatch();
            pastupdatePln.executeBatch();
            core.setV_errMsg("删除成功！");
            core.setResult(1);
            connection.commit();
        }
        catch (Exception e) {
            core.setV_errMsg(e.getMessage());
            if (connection != null) {
                try {
                    connection.rollback(); // 回滚事务
                }
                catch (Exception e2) {
                }
            }
        }
        finally {
            try {
                if (connection != null && !connection.isClosed()) {
                    connection.close();
                }
            }
            catch (Exception e2) {
            }
        }
        return core;
    }

    /**
     * 热扩修改
     * @param planNo
     * @return
     */
    public CoreReturnObject updateLGHotingResult(VrpHotexpFaceMEntity load,
            ArrayList<VrpHotexpFaceDEntity> list, String rentNo,
            String heartNO, String gx) {
        CoreReturnObject core = new CoreReturnObject();
        Connection connection = this.getDao(CoreConstantData.sysbeanstr)
                .getConnection();
        Date now = new Date();
        SimpleDateFormat dateFormat = new SimpleDateFormat(
                "yyyy-MM-dd HH:mm:ss", Locale.CHINA);
        String systime = dateFormat.format(now);
        try {
            connection.setAutoCommit(false); // 取消自动提交事务
            String sqlDelete = CoreXmlSqlParsersFactory
                    .getSql("FrmVrpHoting.updateVrpLGHotingResult");// 修改热扩表检实绩主表
            PreparedStatement patDelete = connection
                    .prepareStatement(sqlDelete);
            String sqlDeleteD = CoreXmlSqlParsersFactory
                    .getSql("FrmVrpHoting.updateVrpHotDResult");// 修改热扩表检实绩从表
            PreparedStatement patDeleteD = connection
                    .prepareStatement(sqlDeleteD);
            String updatePlnInfo = CoreXmlSqlParsersFactory
                    .getSql("FrmVrpSizingResult.updateComInfoResult");// 修改公共信息实绩表
            PreparedStatement patsupdatePlan = connection
                    .prepareStatement(updatePlnInfo);
            String addPlnInfo1 = CoreXmlSqlParsersFactory
                    .getSql("FrmVrpRotexpFace.AddComInfoResult1");// 查询材料状态和工序点编码
            PreparedStatement patsPlan1 = connection
                    .prepareStatement(addPlnInfo1);



            // 获取镦拔扩计划实体类
            PlnZyDbkMEntity pln = PlanService.getSendDBKPlanCInfo(connection,
                    heartNO);
            if (pln == null)
                return core;
            if (!pln.getPlanstatus().equals("20")) {
                core.setV_errMsg("该计划不是生产中的状态！");
                return core;
            }
            String cutFalg = "";
            String sql = CoreXmlSqlParsersFactory
                    .getSql("FrmVrpExpandResult.qureyGxComInfo");// 查询工序是否是结炉状态
            PreparedStatement psta = connection.prepareStatement(sql);
            psta.setString(1, heartNO);
            psta.setString(2, load.getPlineCode());
            psta.setString(3, gx);
            ResultSet rs = psta.executeQuery();
            if (rs.next()) {
                cutFalg = rs.getString("STATION_STATUS");
            }
            if (cutFalg.equals("2")) {
                core.setV_errMsg("已结炉,不允许此操作！");
                return core;
            }
            rs.close();
            psta.close();
            // 修改热扩表检实绩主表
            patDelete.setObject(1, load.getSizeD());
            patDelete.setObject(2, load.getSizeS());
            patDelete.setObject(3, load.getSizeW());
            patDelete.setObject(4, load.getSizeL());
            patDelete.setObject(5, load.getProNum());
            patDelete.setObject(6, load.getProWt());
            patDelete.setObject(7, load.getAccNum());
            patDelete.setObject(8, load.getAccWt());
            patDelete.setObject(9, load.getFailNum());
            patDelete.setObject(10, load.getFailWt());
            patDelete.setObject(11, load.getProducer());
            patDelete.setObject(12, load.getProducerTime());
            patDelete.setObject(13, load.getLoadTime());
            patDelete.setObject(14, load.getLoadShift());
            patDelete.setObject(15, load.getLoadGroup());
            patDelete.setObject(16, load.getLoadUser());
            patDelete.setObject(17, rentNo);
            patDelete.addBatch();

            for (int i = 0; i < list.size(); i++) {
                VrpHotexpFaceDEntity resultD = list.get(i);
                patDeleteD.setObject(1, resultD.getSqeNo());
                patDeleteD.setObject(2, resultD.getEndD1());
                patDeleteD.setObject(3, resultD.getEndD2());
                patDeleteD.setObject(4, resultD.getEndS1());
                patDeleteD.setObject(5, resultD.getEndS2());
                patDeleteD.setObject(6, resultD.getEndS3());
                patDeleteD.setObject(7, resultD.getEndS4());
                patDeleteD.setObject(8, resultD.getChkW());
                patDeleteD.setObject(9, resultD.getChkL());
                patDeleteD.setObject(10, resultD.getChkRes());
                patDeleteD.setObject(11, resultD.getChkPass());
                patDeleteD.setObject(12, systime);
                patDeleteD.setObject(13, resultD.getUpdateName());
                patDeleteD.setObject(14, rentNo);
                patDeleteD.setObject(15, resultD.getMResultNo());
                patDeleteD.addBatch();
                patDeleteD.executeBatch();
            }
            // 修改公共实绩表
            patsupdatePlan.setObject(1, load.getProducer());
            patsupdatePlan.setObject(2, load.getProducerTime());
            patsupdatePlan.setObject(3, load.getProNum());
            patsupdatePlan.setObject(4, load.getProWt());
            patsupdatePlan.setObject(5, load.getFailNum());
            patsupdatePlan.setObject(6, load.getFailWt());
            patsupdatePlan.setObject(7, load.getLoadTime());
            patsupdatePlan.setObject(8, load.getLoadShift());
            patsupdatePlan.setObject(9, load.getLoadGroup());
            patsupdatePlan.setObject(10, load.getResultNo());
            patsupdatePlan.addBatch();
            patDelete.executeBatch();
            patsupdatePlan.executeBatch();

            int count = 0;
            int num = 0;
            int FAIL = 0;
            String sqlloading1 = CoreXmlSqlParsersFactory
                    .getSql("FrmVrpHoting.queryExpandFailNUM");// 查询管号队列表里废品数量
            psta = connection.prepareStatement(sqlloading1);
            psta.setObject(1, load.getHeatPlanNo());
            psta.setObject(2, gx);
            ResultSet rs2 = psta.executeQuery();
            if (rs2.next()) {
                count = Integer.parseInt(rs2.getString("ACT_COUNT"));
            }
            rs2.close();
            psta.close();
            String sqlloading2 = CoreXmlSqlParsersFactory
                    .getSql("FrmVrpHoting.queryExpandFailNUM1");// 查询工序废品数量
            psta = connection.prepareStatement(sqlloading2);
            psta.setObject(1, load.getHeatPlanNo());
            ResultSet rs3 = psta.executeQuery();
            if (rs3.next()) {
                FAIL = Integer.parseInt(rs3.getString("FAIL_NUM"));
            }
            rs3.close();
            psta.close();
            if (count > FAIL) {
                num = count - FAIL;
                ArrayList<String> matNo = new ArrayList<String>();
                String sqlloading3 = CoreXmlSqlParsersFactory
                        .getSql("FrmVrpHoting.queryExpandNUM2");// 查询管号队列表里废品材料号
                psta = connection.prepareStatement(sqlloading3);
                psta.setObject(1, load.getHeatPlanNo());
                psta.setObject(2, gx);
                psta.setObject(3, num + 1);
                ResultSet rs4 = psta.executeQuery();
                while (rs4.next()) {
                    matNo.add(rs4.getString("MAT_NO"));
                }
                rs4.close();
                psta.close();
                for (num = 0; num < matNo.size(); num++) {
                    patsPlan1.setObject(1, "00");
                    patsPlan1.setObject(2, gx);
                    patsPlan1.setObject(3, load.getHeatPlanNo());
                    patsPlan1.setObject(4, matNo.get(num));
                    patsPlan1.addBatch();

                    PlanService.DeleteOffLineMat(connection,matNo.get(num));
                }
                patsPlan1.executeBatch();
            }
            else if (count < FAIL) {
                num = FAIL - count;
                ArrayList<String> matNo1 = new ArrayList<String>();
                String sqlloading4 = CoreXmlSqlParsersFactory
                        .getSql("FrmVrpHoting.queryExpandNUM");// 查询管号队列表里合格材料号
                psta = connection.prepareStatement(sqlloading4);
                psta.setObject(1, load.getHeatPlanNo());
                psta.setObject(2, num + 1);
                ResultSet rs5 = psta.executeQuery();
                while (rs5.next()) {
                    matNo1.add(rs5.getString("MAT_NO"));
                }
                rs5.close();
                psta.close();
                for (num = 0; num < matNo1.size(); num++) {
                    patsPlan1.setObject(1, "10");
                    patsPlan1.setObject(2, gx);
                    patsPlan1.setObject(3, load.getHeatPlanNo());
                    patsPlan1.setObject(4, matNo1.get(num));
                    patsPlan1.addBatch();


                    PlanService.AddOffLineMat(connection,"E",load.getLoadUser(),"22",
                            matNo1.get(num),gx,load.getHeatPlanNo());
                }
                patsPlan1.executeBatch();
            }
            core.setV_errMsg("修改成功！");
            core.setResult(1);
            connection.commit();
        }
        catch (Exception e) {
            core.setV_errMsg(e.getMessage());
            if (connection != null) {
                try {
                    connection.rollback(); // 回滚事务
                }
                catch (Exception e2) {
                }
            }
        }
        finally {
            try {
                if (connection != null && !connection.isClosed()) {
                    connection.close();
                }
            }
            catch (Exception e2) {
            }
        }
        return core;
    }

    /**
     * 离线
     * @param load
     * @return
     */
    public CoreReturnObject offLineExpandResult(VrpHotexpFaceMEntity load,
            ArrayList<String> list, String plinCode, String storageNo,String groupNo) {
        CoreReturnObject core = new CoreReturnObject();
        Connection connection = this.getDao(CoreConstantData.sysbeanstr)
                .getConnection();
        PreparedStatement psta = null;
        Date dt = new Date();
        SimpleDateFormat matter1 = new SimpleDateFormat("yyMMdd");
        SimpleDateFormat matter = new SimpleDateFormat("yyyyMMdd");
        Calendar ca = Calendar.getInstance();
        ca.set(Calendar.DATE, ca.getActualMaximum(Calendar.DATE));
        Date now = new Date();
        SimpleDateFormat dateFormat = new SimpleDateFormat(
                "yyyy-MM-dd HH:mm:ss", Locale.CHINA);
        String systime = dateFormat.format(now);
        try {
            connection.setAutoCommit(false); // 取消自动提交事务
            String addOff = CoreXmlSqlParsersFactory
                    .getSql("FrmVrpExpandResult.AddOffLine");// 新增离线实绩

            PreparedStatement patAdd = connection.prepareStatement(addOff);
            String MarkOff = CoreXmlSqlParsersFactory
                    .getSql("FrmVrpExpandResult.MarkUnCancelFlag");// 标记之前同炉批组返线的离线实绩为无法撤销数据
            PreparedStatement patMarkOff = connection.prepareStatement(MarkOff);

//            String addIn = CoreXmlSqlParsersFactory
//                    .getSql("FrmVrpExpandResult.AddYdmInList");// 新增入库信息
//            PreparedStatement patIn = connection.prepareStatement(addIn);
            String updateMat = CoreXmlSqlParsersFactory
                    .getSql("FrmVrpExpandResult.UpdateMatNo");// 修改材料状态
            PreparedStatement patMatNo = connection.prepareStatement(updateMat);

            String updatePath = CoreXmlSqlParsersFactory
                    .getSql("FrmVrpExpandResult.UpdatePathPortVrp");// 修改队列表工艺路径,材料，工序状态
            PreparedStatement pastupdatePath = connection
                    .prepareStatement(updatePath);


            String heatPlanNo = list.get(0);
            String slgx = list.get(1);
            String slgxname = list.get(2);
            String name = list.get(3);
            String time = list.get(4);
            String bc = list.get(5);
            String bz = list.get(6);
            String count = list.get(7);
            String judge = list.get(8);
            String batch = list.get(9);
            String txtMemo = list.get(10);

            int num = 0;
            int num1 = 0;
            int num2 = 0;
            if (plinCode.equals("C018")) {
                if (slgx.equals("650102")) {
                    num = 1;
                    num1 = 2;
                    num2 = 4;
                }
                else if (slgx.equals("650103")) {
                    num = 1;
                    num1 = 4;
                    num2 = 6;
                }
                else if (slgx.equals("650104")) {
                    num = 1;
                    num1 = 6;
                    num2 = 8;
                }
                else if (slgx.equals("650105")) {
                    num = 1;
                    num1 = 8;
                    num2 = 10;
                }
                else if (slgx.equals("650106")) {
                    num = 1;
                    num1 = 10;
                    num2 = 12;
                }
                else if (slgx.equals("650107")) {
                    num = 1;
                    num1 = 12;
                    num2 = 14;
                }

            }
            else if (plinCode.equals("C021")) {
                if (slgx.equals("650402")) {
                    num = 1;
                    num1 = 2;
                    num2 = 4;
                }
                else if (slgx.equals("650403")) {
                    num = 1;
                    num1 = 4;
                    num2 = 6;
                }
                else if (slgx.equals("650404")) {
                    num = 1;
                    num1 = 6;
                    num2 = 8;
                }
                else if (slgx.equals("650405")) {
                    num = 1;
                    num1 = 8;
                    num2 = 10;
                }
            }
            else if (plinCode.equals("C014")) {
                if (slgx.equals("650502")) {
                    num = 1;
                    num1 = 2;
                    num2 = 4;
                }
                else if (slgx.equals("650503")) {
                    num = 1;
                    num1 = 4;
                    num2 = 6;
                }
                else if (slgx.equals("650504")) {
                    num = 1;
                    num1 = 6;
                    num2 = 8;
                }
                else if (slgx.equals("650505")) {
                    num = 1;
                    num1 = 8;
                    num2 = 10;
                }
            }
            else if (plinCode.equals("C013")) {
                if (slgx.equals("650602")) {
                    num = 1;
                    num1 = 2;
                    num2 = 4;
                }
                else if (slgx.equals("650603")) {
                    num = 1;
                    num1 = 4;
                    num2 = 6;
                }
                else if (slgx.equals("650604")) {
                    num = 1;
                    num1 = 6;
                    num2 = 8;
                }
                else if (slgx.equals("650605")) {
                    num = 1;
                    num1 = 8;
                    num2 = 10;
                }
            }
            else if (plinCode.equals("C070")) {
                if (slgx.equals("650702")) {
                    num = 1;
                    num1 = 2;
                    num2 = 4;
                }
                else if (slgx.equals("650703")) {
                    num = 1;
                    num1 = 4;
                    num2 = 6;
                }
                else if (slgx.equals("650704")) {
                    num = 1;
                    num1 = 6;
                    num2 = 8;
                }
                else if (slgx.equals("650705")) {
                    num = 1;
                    num1 = 8;
                    num2 = 10;
                }
            }

            // 获取墩拔扩计划实体类
            PlnZyDbkMEntity pln = PlanService.getSendDBKPlanCInfo(connection,
                    heatPlanNo);
            // 获取墩拔扩计划从表实体类
            PlnZyDbkCEntity plnC = PlanService.getSendDBKPlanCInfoC(connection,
                    heatPlanNo);
            if (pln == null)
                return core;
            // if (!pln.getPlanstatus().equals("2")) {
            // core.setV_errMsg("该计划不是生产中的，请确认是否生产完成或未上料！");
            // return core;
            // }
            String cutFalg = "";
            String sql = CoreXmlSqlParsersFactory
                    .getSql("FrmVrpExpandResult.qureyGxComInfo");// 查询工序结炉状态
            PreparedStatement psta1 = connection.prepareStatement(sql);
            psta1.setString(1, heatPlanNo);
            psta1.setString(2, plinCode);
            psta1.setString(3, slgx);
            ResultSet rs = psta1.executeQuery();
            if (rs.next()) {
                cutFalg = rs.getString("STATION_STATUS");
            }
            if (cutFalg.equals("2")) {
                core.setV_errMsg("已结炉,不允许此操作！");
                return core;
            }
            rs.close();
            psta1.close();
            List<PortVrpBatchSampleResultEntity> matNo = new ArrayList<PortVrpBatchSampleResultEntity>();
            String sqlloading1 = CoreXmlSqlParsersFactory
                    .getSql("FrmVrpExpandResult.queryPortVrpHg");// 查询管号队列里合格的材料号
            psta = connection.prepareStatement(sqlloading1);
            psta.setObject(1, heatPlanNo);
            psta.setObject(2, judge);
            psta.setObject(3, batch);
            psta.setObject(4, groupNo);
            psta.setObject(5, Integer.parseInt(count) + 1);
            ResultSet rs2 = psta.executeQuery();
            matNo = EntityTool.getEntitysByRs(rs2,
                    PortVrpBatchSampleResultEntity.class);
            rs2.close();
            psta.close();
            if (matNo == null) {
                core.setV_errMsg("管号队列全为样管，不能离线！");
                return core;
            }
            int batchCount = 0;
            sqlloading1 = CoreXmlSqlParsersFactory
                    .getSql("FrmVrpExpandResult.queryPortVrpBatchHg");// 查询管号队列里不是样管的合格支
            psta = connection.prepareStatement(sqlloading1);
            psta.setObject(1, heatPlanNo);
            rs2 = psta.executeQuery();
            if (rs2.next()) {
                batchCount = Integer.parseInt(rs2.getString("ACT_COUNT"));
            }
            rs2.close();
            psta.close();
            if (batchCount < Integer.parseInt(count)) {
                core.setV_errMsg("管号队列材料合格支数不足,请重新输入离线支数！");
                return core;
            }
            String inListDoc = querySendSqlDoc(connection, "800708", "LX");// 入库单号
            String A = querySendSql(connection, inListDoc);
            int g = Integer.parseInt(A.substring(A.length() - 4, A.length()));


            String actdimater = "";
            String actheight = "";
            String actlen = "";
            String actlenmin = "";
            String actlenmax = "";

            String resultNo = "";
            String sqlloading = CoreXmlSqlParsersFactory
                    .getSql("FrmVrpExpandResult.queryOffMaxRESULT");// 查询离线最大实绩编号
            psta = connection.prepareStatement(sqlloading);
            psta.setObject(1, plinCode + slgx + "L" + matter1.format(dt));
            psta.setObject(2, matter.format(dt));
            psta.setObject(3, pln.getPlineCode());
            psta.setObject(4, plinCode + slgx + "L" + matter1.format(dt));
            ResultSet rs1 = psta.executeQuery();
            if (rs1.next()) {
                resultNo = rs1.getString("RESULT_NO");
            }
            rs1.close();
            psta.close();

            int countNum = 0;
            double weightNum = 0;
            for (PortVrpBatchSampleResultEntity prot : matNo) {
                countNum += Integer.parseInt(prot.getActCount());
                weightNum += Double.parseDouble(prot.getActWeight());
                // 修改管号队列状态
                pastupdatePath.setObject(1, num);
                pastupdatePath.setObject(2, num1);
                pastupdatePath.setObject(3, "2");
                pastupdatePath.setObject(4, num2);
                pastupdatePath.setObject(5, "20");
                pastupdatePath.setObject(6, "10");
                pastupdatePath.setObject(7, slgx);
                pastupdatePath.setObject(8, resultNo);
				pastupdatePath.setObject(9, heatPlanNo);
				pastupdatePath.setObject(10, prot.getMatNo());
                pastupdatePath.addBatch();


                // 修改材料表状态
                patMatNo.setObject(1, "80150104");
                patMatNo.setObject(2, prot.getMatNo());
                patMatNo.addBatch();
//                // 新增入库表数据
//                patIn.setObject(1, inListDoc
//                        + StringTool.formatDecimal(g, "0000"));
//                patIn.setObject(2, inListDoc);
//                patIn.setObject(3, "800708");
//                patIn.setObject(4, "离线入库");
//                patIn.setObject(5, "");
//                patIn.setObject(6, prot.getMatNo());
//                patIn.setObject(7, "");
//                patIn.setObject(8, "");
//                patIn.setObject(9, prot.getJudgeStoveNo());
//                patIn.setObject(10, prot.getBatchNo());
//                patIn.setObject(11, prot.getGroupNo());
//                patIn.setObject(12, "");
//                patIn.setObject(13, "");
//                patIn.setObject(14, "");
//                patIn.setObject(15, "");
//                patIn.setObject(16, "");
//                patIn.setObject(17, "");
//                patIn.setObject(18, pln.getGradecode());
//                patIn.setObject(19, pln.getGradename());
//                patIn.setObject(20, "");
//                patIn.setObject(21, "");
//                patIn.setObject(22, "");
//                patIn.setObject(23, "");
//                patIn.setObject(24, "");
//                patIn.setObject(25, "");
//                patIn.setObject(26, "");
//                patIn.setObject(27, "");
//                patIn.setObject(28, "");
//                patIn.setObject(29, pln.getPlineCode());
//                patIn.setObject(30, pln.getPlineName());
//                patIn.setObject(31, prot.getActDimater());
//                patIn.setObject(32, prot.getActHeight());
//                patIn.setObject(33, prot.getActLen());
//                patIn.setObject(34, prot.getActLenMin());
//                patIn.setObject(35, prot.getActLenMax());
//                patIn.setObject(36, prot.getActCount());
//                patIn.setObject(37, prot.getActWeight());
//                patIn.setObject(38, prot.getActTheoryWeight());
//                patIn.setObject(39, "");// 组织
//                patIn.setObject(40, "");
//                patIn.setObject(41, storageNo);//
//                patIn.setObject(42, storageNo + "10101");
//                patIn.setObject(43, "");
//                patIn.setObject(44, "");
//                patIn.setObject(45, storageAtte);
//                patIn.setObject(46, storageAtteName);
//                patIn.setObject(47, storageType);
//                patIn.setObject(48, storageTypeName);
//                patIn.setObject(49, managNo);
//                patIn.setObject(50, managName);
//                patIn.setObject(51, time);
//                patIn.setObject(52, bc);
//                patIn.setObject(53, bz);
//                patIn.setObject(54, time);
//                patIn.setObject(55, bc);
//                patIn.setObject(56, bz);
//                patIn.setObject(57, "");
//                patIn.setObject(58, name);
//                patIn.setObject(59, time);
//                if(pln.getOrdLnDlyPk()==""||pln.getOrdLnDlyPk()==null)
//                {
//                	 patIn.setObject(60, "");// 合同pK
//                     patIn.setObject(61, "");	
//                }else
//                {
//                patIn.setObject(60, pln.getOrdLnDlyPk().substring(0,
//                        pln.getOrdLnDlyPk().length() - 6));// 合同pK
//                patIn.setObject(61, pln.getOrdLnDlyPk().substring(0,
//                        pln.getOrdLnDlyPk().length() - 3));
//                }
//                patIn.setObject(62, pln.getOrdLnDlyPk());
//                patIn.setObject(63, depNo);
//                patIn.setObject(64, depName);
//                patIn.setObject(65, pln.getOrderNo());// 合同号
//                patIn.setObject(66, pln.getOrderSeq());
//                patIn.setObject(67, pln.getDeliveryNo());
//                patIn.setObject(68, "801401");
//                patIn.setObject(69, "80150104");
//                patIn.setObject(70, "");
//                patIn.setObject(71, "");
//                patIn.setObject(72, time);
//                patIn.setObject(73, "");
//                patIn.setObject(74, "");
//                patIn.setObject(75, "");
//                patIn.setObject(76, "");
//                patIn.setObject(77, "");
//                patIn.setObject(78, "");
//                patIn.setObject(79, "");
//                patIn.setObject(80, "");
//                patIn.setObject(81, "1");
//                patIn.addBatch();
//                g++;
                judge = prot.getJudgeStoveNo();
                batch = prot.getBatchNo();
                actdimater = prot.getActDimater();
                actheight = prot.getActHeight();
                actlen = prot.getActLen();
                actlenmin = prot.getActLenMin();
                actlenmax = prot.getActLenMax();
            }
            pastupdatePath.executeBatch();

            patMatNo.executeBatch();


            for (PortVrpBatchSampleResultEntity lvMat : matNo) {
            // 新增离线实绩
            patAdd.setObject(1, resultNo);
            patAdd.setObject(2, heatPlanNo);
            patAdd.setObject(3, slgx);
            patAdd.setObject(4, slgx);
            patAdd.setObject(5, pln.getPlineCode());
            patAdd.setObject(6, pln.getPlineName());
            patAdd.setObject(7, pln.getZyBatchId());
            patAdd.setObject(8, pln.getProPlanId());
            patAdd.setObject(9, pln.getGxPlanNo());

            patAdd.setObject(10, judge);
            patAdd.setObject(11, batch);
            patAdd.setObject(12, pln.getProduccode());
            patAdd.setObject(13, pln.getProducname());
            patAdd.setObject(14, pln.getSteelcode());
            patAdd.setObject(15, pln.getSteelname());
            patAdd.setObject(16, pln.getGradecode());
            patAdd.setObject(17, pln.getGradename());
            patAdd.setObject(18, pln.getModelCode());
            patAdd.setObject(19, pln.getModelDesc());
            patAdd.setObject(20, pln.getStdCode());
            patAdd.setObject(21, pln.getStdName());
            patAdd.setObject(22, pln.getStdStyle());
            patAdd.setObject(23, pln.getStdStyleDesc());
                patAdd.setObject(24, pln.getAimoutdiameter());
                patAdd.setObject(25, pln.getAimwallthick());
            patAdd.setObject(26, actlen);
            patAdd.setObject(27, actlenmin);
            patAdd.setObject(28, actlenmax);

            patAdd.setObject(29, countNum);
            patAdd.setObject(30, weightNum);
            patAdd.setObject(31, time);
            patAdd.setObject(32, name);
            patAdd.setObject(33, bc);
            patAdd.setObject(34, bz);
            patAdd.setObject(35, pln.getOrdLnDlyPk());
            patAdd.setObject(36, pln.getOrderNo());
            patAdd.setObject(37, pln.getOrderSeq());
            patAdd.setObject(38, pln.getDeliveryNo());
            patAdd.setObject(39, groupNo);
            patAdd.setObject(40, pln.getFlagStoveNo());
            patAdd.setObject(41, txtMemo);
            patAdd.setObject(42, pln.getFeedHeatNo());
            // 如果有废品新增到材料表
         			if (!count.equals("") && !count.equals("0")) {
                        PlanService.AddOffLineMatWithResultNo(connection,"E",load.getLoadUser(),"11",
                               lvMat.getMatNo(),slgx,heatPlanNo,resultNo);
         				}
            }

            patMarkOff.setObject(1,pln.getHeatPlanNo());
            patMarkOff.setObject(2,pln.getJudgeStoveNo());
            patMarkOff.setObject(3,pln.getBatchNo());
            patMarkOff.setObject(4,groupNo);
            patMarkOff.setObject(5,slgx);
            patMarkOff.addBatch();
            patMarkOff.executeBatch();

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

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

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

    /**
     * 根据计划号查询热扩实绩
     * @param planNo 计划号
     * @return
     */
    public CoreReturnObject getLoadResult(String heatNo) {
        return this.getDataBySqlID("FrmVrpHoting.GetQuery",// 查询热扩表检实绩主表
                new Object[] { heatNo });
    }

    public CoreReturnObject getHotResult(String heatNo) {
        return this.getDataBySqlID("FrmVrpHoting.GetHotingQuery",// 查询热扩表检实绩从表
                new Object[] { heatNo });
    }

    /**
     * 根据计划号查询热扩实绩合格支数的和
     * @param planNo 计划号
     * @return
     */
    public CoreReturnObject getLoadResult1(String heatNo) {
        return this.getDataBySqlID("FrmVrpHoting.GetQuery1",
                new Object[] { heatNo });
    }

    /***
     * 结炉
     * @param zYgNo
     * @return
     */
    public CoreReturnObject updateDoBeside(ArrayList<String> parm,String num) {
        CoreReturnObject cro = new CoreReturnObject();
        Connection connection = this.getDao(CoreConstantData.sysbeanstr)
                .getConnection();
        String sql = "";
        PreparedStatement psta = null;
        ResultSet rs = null;
        try {
            connection.setAutoCommit(false); // 取消自动提交事务
            String updateSql = CoreXmlSqlParsersFactory
                    .getSql("FrmVrpExpandResult.doBeside");// 修改工序状态为结炉
            PreparedStatement updateSqlPsta = connection
                    .prepareStatement(updateSql);
            String cutFalg = "";
            sql = CoreXmlSqlParsersFactory
                    .getSql("FrmVrpExpandResult.qureyGxComInfo");// 查询工序是否是结炉状态
            psta = connection.prepareStatement(sql);
            psta.setString(1, parm.get(0));
            psta.setString(2, parm.get(1));
            psta.setObject(3, Integer.parseInt(parm.get(2)) - 2);
            rs = psta.executeQuery();
            if (rs.next()) {
                cutFalg = rs.getString("STATION_STATUS");
            }
            if (cutFalg.equals("1")) {
                cro.setV_errMsg("上一道工序没有结炉,不允许此工序结炉!");
                return cro;
            }
            rs.close();
            psta.close();
            int lxCount = 0;
            sql = CoreXmlSqlParsersFactory
                    .getSql("FrmVrpMeasuring.qureyGxLxCount");// 查询是否离线
            psta = connection.prepareStatement(sql);
            psta.setString(1, parm.get(0));
            psta.setString(2, parm.get(1));
            psta.setString(3, parm.get(2));
            rs = psta.executeQuery();
            if (rs.next()) {
                lxCount = Integer.parseInt(rs.getString("COUNT"));
            }
            rs.close();
            psta.close();
            if (lxCount!=0) {
                cro.setV_errMsg("该工序点有离线记录,不允许此操作！");
                return cro;
            }
            String cutFalg1 = "";
            sql = CoreXmlSqlParsersFactory
                    .getSql("FrmVrpColding.qureyGxComInfo");//查询工序点状态
            psta = connection.prepareStatement(sql);
            psta.setString(1, parm.get(0));
            psta.setString(2, parm.get(1));
            psta.setString(3, parm.get(2));
            rs = psta.executeQuery();
            if (rs.next()) {
                cutFalg1 = rs.getString("STATION_STATUS");
            }else{ cro.setV_errMsg("无当前工序实绩,无法进行结炉!");
            return cro;}
            if (cutFalg1.equals("2")) {
                cro.setV_errMsg("已结炉,不允许此操作！");
                return cro;
            }
            rs.close();
            psta.close();
            updateSqlPsta.setString(1, parm.get(0));
            updateSqlPsta.setString(2, parm.get(1));
            updateSqlPsta.setString(3, parm.get(2));
            updateSqlPsta.addBatch();
            updateSqlPsta.executeBatch();
            
            String actCount = "";
            //如果该工序都是废品结炉后变成生产完成
            sql = CoreXmlSqlParsersFactory.getSql("FrmVrpColding.queryPortStuts");//查询管号队列状态
            psta = connection.prepareStatement(sql);
            psta.setString(1, parm.get(0));
            psta.setString(2, parm.get(1));
            rs = psta.executeQuery();
            if(rs.next())
            {
            	actCount = rs.getString("ACT_COUNT");
            }
            rs.close();
            psta.close();
            if(Integer.parseInt(actCount)==0)
            {
            	 String updateSqlPlnStuts1 = CoreXmlSqlParsersFactory
                         .getSql("FrmVrpColding.plnupdateStuts");// 结炉修改计划工序状态为生产完成
                 PreparedStatement updateSqlPsta2 = connection
                         .prepareStatement(updateSqlPlnStuts1);
                 updateSqlPsta2.setObject(1, parm.get(0));
                 updateSqlPsta2.addBatch();
                 updateSqlPsta2.executeBatch();
            }else{
            	String updateSqlPln = CoreXmlSqlParsersFactory
                        .getSql("FrmVrpHoting.plnupdate");// 结炉修改计划工序状态
                PreparedStatement updateSqlPsta1 = connection
                        .prepareStatement(updateSqlPln);
                updateSqlPsta1.setObject(1, parm.get(0));
                updateSqlPsta1.addBatch();
                updateSqlPsta1.executeBatch();
            }

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

    /***
     * 撤销结炉
     * @param zYgNo
     * @return
     */
    public CoreReturnObject undoBeside(ArrayList<String> parm,String num) {
        CoreReturnObject cro = new CoreReturnObject();
        Connection connection = this.getDao(CoreConstantData.sysbeanstr)
                .getConnection();
        String sql = "";
        PreparedStatement psta = null;
        ResultSet rs = null;
        try {
            connection.setAutoCommit(false); // 取消自动提交事务connection.setAutoCommit(false)
            String updateSql = CoreXmlSqlParsersFactory
                    .getSql("FrmVrpExpandResult.deleteBeside");// 修改工序状态为撤销结炉
            PreparedStatement updateSqlPsta = connection
                    .prepareStatement(updateSql);
            String cutFalg1 = "";
            sql = CoreXmlSqlParsersFactory
                    .getSql("FrmVrpExpandResult.qureyGxComInfo");// 查询工序是否是结炉状态
            psta = connection.prepareStatement(sql);
            psta.setString(1, parm.get(0));
            psta.setString(2, parm.get(1));
            psta.setObject(3, Integer.parseInt(parm.get(2)) + 1);
            rs = psta.executeQuery();
            if (rs.next()) {
                cutFalg1 = rs.getString("STATION_STATUS");
            }
            if (cutFalg1.equals("2")) {
                cro.setV_errMsg("下一道工序没有撤销结炉,不允许此工序撤销结炉!");
                return cro;
            }
            rs.close();
            psta.close();
            String cutFalg = "";
            sql = CoreXmlSqlParsersFactory
                    .getSql("FrmVrpExpandResult.qureyGxComInfo");// 查询工序是否是结炉状态
            psta = connection.prepareStatement(sql);
            psta.setString(1, parm.get(0));
            psta.setString(2, parm.get(1));
            psta.setString(3, parm.get(2));
            rs = psta.executeQuery();
            if (rs.next()) {
                cutFalg = rs.getString("STATION_STATUS");
            }
            else {
                cro.setV_errMsg("无当前工序实绩,无法进行结炉!");
                return cro;
            }
            if (cutFalg.equals("1")) {
                cro.setV_errMsg("未结炉,不允许此操作！");
                return cro;
            }
            rs.close();
            psta.close();
            updateSqlPsta.setString(1, parm.get(0));
            updateSqlPsta.setString(2, parm.get(1));
            updateSqlPsta.setString(3, parm.get(2));
            updateSqlPsta.addBatch();
            updateSqlPsta.executeBatch();
            
            String actCount = "";
            //如果该工序都是废品结炉后变成生产完成
            sql = CoreXmlSqlParsersFactory.getSql("FrmVrpColding.queryPortStuts");//查询管号队列状态
            psta = connection.prepareStatement(sql);
            psta.setString(1, parm.get(0));
            psta.setString(2, parm.get(1));
            rs = psta.executeQuery();
            if(rs.next())
            {
            	actCount = rs.getString("ACT_COUNT");
            }
            rs.close();
            psta.close();
            if(Integer.parseInt(actCount)==0)
            {
            	 String updateSqlPlnStuts1 = CoreXmlSqlParsersFactory
                         .getSql("FrmVrpColding.updateplnupdateStuts");// 结炉修改计划工序状态为生产完成
                 PreparedStatement updateSqlPsta2 = connection
                         .prepareStatement(updateSqlPlnStuts1);
                 updateSqlPsta2.setObject(1, parm.get(0));
                 updateSqlPsta2.addBatch();
                 updateSqlPsta2.executeBatch();
            }else{
            	 String updateSqlPln = CoreXmlSqlParsersFactory
                         .getSql("FrmVrpHoting.plnupdate1");// 撤销结炉修改计划工序状态
                 PreparedStatement updateSqlPsta1 = connection
                         .prepareStatement(updateSqlPln);
                 updateSqlPsta1.setObject(1, parm.get(0));
                 updateSqlPsta1.addBatch();
                 updateSqlPsta1.executeBatch();
            }

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

}