package com.steering.mes.mcp.coup;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.Locale;
import CoreFS.SA06.CoreReturnObject;
import CoreFS.SA08.CoreXmlSqlParsersFactory;
import CoreFS.SC01.CoreConstantData;
import com.steering.comm.db.DBCommon;
import com.steering.mes.mcp.common.PlanService;
import com.steering.mes.mcp.entity.PlnZyJgEntity;

/**
 * 接箍委外实绩
 * @author siy 2015/05/28
 * @version v1.0
 */
public class FrmOutSourPerfor extends DBCommon {
    /***
     * 查询委外工序实绩
     * @param zYgNo
     * @param plineCode
     * @return
     */
    public CoreReturnObject doQueryLoadResult(String zYgNo, String woId) {
        return this.getDataBySqlID("FrmOutSourPerfor.doQueryLoadResult",
                new Object[] { zYgNo, woId });
    }

    /**
     * 新增委外实绩
     * @param result 切割实绩
     * @return·
     */
    public CoreReturnObject addThreadingResult(ArrayList<String> list) {
        CoreReturnObject cor = new CoreReturnObject();
        Connection con = this.getDao(CoreConstantData.sysbeanstr)
                .getConnection();
        Calendar ca = Calendar.getInstance();
        ca.set(Calendar.DATE, ca.getActualMaximum(Calendar.DATE));
        Date now = new Date();
        SimpleDateFormat dateFormat = new SimpleDateFormat(
                "yyyy-MM-dd HH:mm:ss", Locale.CHINA);
        SimpleDateFormat date = new SimpleDateFormat("yyyy-MM-dd");
        String systime = dateFormat.format(now);
        String last = date.format(ca.getTime()) + " 21:00:00";

        try {
            con.setAutoCommit(false); // 取消自动提交事务
            String insertComInfoSql = CoreXmlSqlParsersFactory
                    .getSql("PhosphateResultService.AddPlnInfo");// 新增comInfo表
            PreparedStatement insertComInfoPsta = con
                    .prepareStatement(insertComInfoSql);

            String gxNo = list.get(0);
            String gxNmae = list.get(1);
            String count = list.get(2);
            String bc = list.get(3);
            String bz = list.get(4);
            String plnNo = list.get(5);
            String userNmae = list.get(6);
            String plineCode = list.get(7);
            String woId = list.get(8);
            String xh = list.get(9);
            String lutime = systime;
            if (PlanService.compareDate(systime, last) == true) {
                if (bc.equals("3")) {
                    ca.add(Calendar.DAY_OF_MONTH, 1);
                    lutime = date.format(ca.getTime()) + " 00:00:01";
                }
            }
            // 查询工单状态
            int falg = 0;
            int cutfalg = 0;
            int cjgfalg = 0;// 粗加工
            int impfalg = 0;// 压印
            int latfalg = 0;// 车丝
            int detfalg = 0;// 探伤
            int pltfalg = 0;// 镀铜
            int blafalg = 0;// 喷标
            int phofalg = 0;// 磷化
            int psfalg = 0;// 喷砂
            int lwfalg = 0;// 螺纹检验
            String sqlloading = CoreXmlSqlParsersFactory
                    .getSql("PhosphateResultService.queryPlanJg");
            PreparedStatement psta = con.prepareStatement(sqlloading);
            psta.setObject(1, woId);
            ResultSet rs1 = psta.executeQuery();
            if (rs1.next()) {
                falg = Integer.parseInt(rs1.getString("ZY_BILL_STATUS"));
                cutfalg = Integer.parseInt(rs1.getString("CUT_STATUS"));
                cjgfalg = Integer.parseInt(rs1.getString("CJG_STATUS"));
                impfalg = Integer.parseInt(rs1.getString("IMPRESS_STATUS"));
                latfalg = Integer.parseInt(rs1.getString("LATHE_STATUS"));
                detfalg = Integer.parseInt(rs1.getString("DETECT_STATUS"));
                pltfalg = Integer.parseInt(rs1.getString("PLT_CU_STATUS"));
                psfalg = Integer.parseInt(rs1.getString("BLAST_STATUS"));
                phofalg = Integer.parseInt(rs1.getString("PHOS_STATUS"));
                blafalg = Integer.parseInt(rs1.getString("COPPER_STATUS"));
                lwfalg = Integer.parseInt(rs1.getString("THREAD_CHK_STATUS"));
            }
            rs1.close();
            psta.close();

            if (falg > 2) {
                cor.setV_errMsg("该工单不是生产中的状态,不允许此操作！");
                return cor;
            }

            // 实绩编号
            String resultNo = doAddResultNo(xh, gxNo, plineCode, plnNo, woId,
                    con);

            // 获取工单实体了
            PlnZyJgEntity pln = PlanService.getSendPlanCInfo(con, plnNo);

            // // 查询是否存在离线记录
            // int countLx = 0;
            // sqlloading = CoreXmlSqlParsersFactory
            // .getSql("FrmOutSourPerfor.queryCutCou");
            // psta = con.prepareStatement(sqlloading);
            // psta.setObject(1, plnNo);
            // psta.setObject(2, gxNo);
            // psta.setObject(3, woId);
            // rs1 = psta.executeQuery();
            // if (rs1.next()) {
            // countLx = Integer.parseInt(rs1.getString("COUNT"));
            // }
            // rs1.close();
            // psta.close();
            //            
            // 新增接箍公共信息
            insertComInfoPsta.setObject(1, pln.getSteelcode());
            insertComInfoPsta.setObject(2, pln.getSteelname());
            insertComInfoPsta.setObject(3, pln.getModelCode());
            insertComInfoPsta.setObject(4, pln.getModelDesc());
            insertComInfoPsta.setObject(5, pln.getOutdiameter());
            insertComInfoPsta.setObject(6, pln.getWallthick());
            insertComInfoPsta.setObject(7, pln.getSpecJg());
            insertComInfoPsta.setObject(8, pln.getSpecJgDesc());
            insertComInfoPsta.setObject(9, pln.getStyleJg());
            insertComInfoPsta.setObject(10, pln.getDiameter());
            insertComInfoPsta.setObject(11, pln.getCheckJVal());
            insertComInfoPsta.setObject(12, pln.getAimlength());
            insertComInfoPsta.setObject(13, pln.getSingleweight());
            insertComInfoPsta.setObject(14, pln.getMonitordemand());
            insertComInfoPsta.setObject(15, pln.getIfMonitorJg());
            insertComInfoPsta.setObject(16, pln.getPrdcrNo());
            insertComInfoPsta.setObject(17, "");// 监制人
            insertComInfoPsta.setObject(18, "");// 监制到场时间
            insertComInfoPsta.setObject(19, pln.getCutMachGrpNo());
            insertComInfoPsta.setObject(20, pln.getCutMachGrpNm());
            insertComInfoPsta.setObject(21, count);
            insertComInfoPsta.setObject(22, "");
            insertComInfoPsta.setObject(23, "");// 废品重量
            insertComInfoPsta.setObject(24, "");// 废品支数
            insertComInfoPsta.setObject(25, "");
            insertComInfoPsta.setObject(26, "");
            insertComInfoPsta.setObject(27, "1");
            insertComInfoPsta.setObject(28, lutime);
            insertComInfoPsta.setObject(29, "");
            insertComInfoPsta.setObject(30, userNmae);
            insertComInfoPsta.setObject(31, bc);
            insertComInfoPsta.setObject(32, bz);
            insertComInfoPsta.setObject(33, resultNo);
            insertComInfoPsta.setObject(34, pln.getZyPlanId());
            insertComInfoPsta.setObject(35, pln.getProPlanId());
            insertComInfoPsta.setObject(36, pln.getCodeJgBl());
            insertComInfoPsta.setObject(37, pln.getJgGroupId());
            if (gxNo.equals("700302")) {
                if (cutfalg == 2) {
                    cor.setV_errMsg("该工单切管已生产完成,不允许此操作,如要修改请先撤销结炉！");
                    return cor;
                }
                insertComInfoPsta.setObject(38, "1");
            }
            else if (gxNo.equals("700303")) {
                if (cjgfalg == 2) {
                    cor.setV_errMsg("该工单粗加工已生产完成,不允许此操作,如要修改请先撤销结炉！");
                    return cor;
                }
                insertComInfoPsta.setObject(38, "1");
            }
            else if (gxNo.equals("700304")) {
                if (impfalg == 2) {
                    cor.setV_errMsg("该工单压印已生产完成,不允许此操作,如要修改请先撤销结炉！");
                    return cor;
                }
                insertComInfoPsta.setObject(38, "1");
            }
            else if (gxNo.equals("700305")) {
                if (latfalg == 2) {
                    cor.setV_errMsg("该工单车丝已生产完成,不允许此操作,如要修改请先撤销结炉！");
                    return cor;
                }
                insertComInfoPsta.setObject(38, "1");
            }
            else if (gxNo.equals("700307")) {
                if (detfalg == 2) {
                    cor.setV_errMsg("该工单探伤已生产完成,不允许此操作,如要修改请先撤销结炉！");
                    return cor;
                }
                insertComInfoPsta.setObject(38, "1");
            }
            else if (gxNo.equals("700308")) {
                if (psfalg == 2) {
                    cor.setV_errMsg("该工单喷砂已生产完成,不允许此操作,如要修改请先撤销结炉！");
                    return cor;
                }
                insertComInfoPsta.setObject(38, "1");
            }
            else if (gxNmae.equals("镀铜")) {
                if (pltfalg == 2) {
                    cor.setV_errMsg("该工单镀铜已生产完成,不允许此操作,如要修改请先撤销结炉！");
                    return cor;
                }
                insertComInfoPsta.setObject(38, "1");
            }
            else if (gxNmae.equals("磷化")) {
                if (phofalg == 2) {
                    cor.setV_errMsg("该工单磷化已生产完成,不允许此操作,如要修改请先撤销结炉！");
                    return cor;
                }
                insertComInfoPsta.setObject(38, "1");
            }
            else if (gxNo.equals("700311")) {
                if (blafalg == 2) {
                    cor.setV_errMsg("该工单喷标已生产完成,不允许此操作,如要修改请先撤销结炉！");
                    return cor;
                }
                insertComInfoPsta.setObject(38, "1");
            }
            else if (gxNo.equals("700306")) {
                if (lwfalg == 2) {
                    cor.setV_errMsg("该工单螺纹检验已生产完成,不允许此操作,如要修改请先撤销结炉！");
                    return cor;
                }
                insertComInfoPsta.setObject(38, "1");
            }

            insertComInfoPsta.setObject(39, pln.getPlineCode());
            insertComInfoPsta.setObject(40, pln.getPlineName());
            insertComInfoPsta.setObject(41, gxNo);
            insertComInfoPsta.setObject(42, gxNmae);
            insertComInfoPsta.setObject(43, pln.getJudgeStoveNo());
            insertComInfoPsta.setObject(44, pln.getBatchNo());
            insertComInfoPsta.setObject(45, pln.getBlWlId());
            insertComInfoPsta.setObject(46, pln.getBlWlDesc());
            insertComInfoPsta.setObject(47, pln.getMinD());
            insertComInfoPsta.setObject(48, pln.getMinH());
            insertComInfoPsta.setObject(49, pln.getAimlengthBl());
            insertComInfoPsta.setObject(50, pln.getAimCutLen());
            insertComInfoPsta.setObject(51, pln.getLengthMin());
            insertComInfoPsta.setObject(52, pln.getLengthMax());
            insertComInfoPsta.setObject(53, pln.getTaper());
            insertComInfoPsta.setObject(54, pln.getCodeJg());
            insertComInfoPsta.setObject(55, pln.getGradecode());
            insertComInfoPsta.setObject(56, pln.getGradename());
            insertComInfoPsta.setObject(57, pln.getIfAllOutWork());
            insertComInfoPsta.setObject(58, systime);
            insertComInfoPsta.setObject(59, "");
            insertComInfoPsta.setObject(60, woId);
            insertComInfoPsta.addBatch();
            insertComInfoPsta.executeBatch();

            // 查询总数
            int countQual = 0;
            sqlloading = CoreXmlSqlParsersFactory
                    .getSql("FrmOutSourPerfor.queryCutCou1");
            psta = con.prepareStatement(sqlloading);
            psta.setObject(1, plnNo);
            psta.setObject(2, gxNo);
            psta.setObject(3, woId);
            rs1 = psta.executeQuery();
            if (rs1.next()) {
                countQual = Integer.parseInt(rs1.getString("PRO_NUM"));
            }
            rs1.close();
            psta.close();

            Statement sta = null;
            String sqlupdateWoId = null;
            if (gxNo.equals("700302")) {// 锯切
                sqlupdateWoId = "UPDATE PLN_ZY_JG_WORKBILL SET "
                        + " CUT_OK_NUM = TO_NUMBER('" + countQual + "'),"
                        + " CUT_STATUS = '1' " + "WHERE WO_ID = '" + woId + "'";
                sta = con.createStatement();
                sta.executeUpdate(sqlupdateWoId);
                sta.close();
            }
            if (gxNo.equals("700303")) {// 粗加工
                sqlupdateWoId = "UPDATE PLN_ZY_JG_WORKBILL SET "
                        + " CJG_OK_NUM = TO_NUMBER('" + countQual + "'),"
                        + " CJG_STATUS = '1' " + "WHERE WO_ID = '" + woId + "'";
                sta = con.createStatement();
                sta.executeUpdate(sqlupdateWoId);
                sta.close();
            }
            if (gxNo.equals("700304")) {// 压印
                sqlupdateWoId = "UPDATE PLN_ZY_JG_WORKBILL SET "
                        + " IMPRESS_OK_NUM = TO_NUMBER('" + countQual + "'),"
                        + " IMPRESS_STATUS = '1' " + "WHERE WO_ID = '" + woId
                        + "'";
                sta = con.createStatement();
                sta.executeUpdate(sqlupdateWoId);
                sta.close();
            }
            if (gxNo.equals("700305")) {// 车丝
                sqlupdateWoId = "UPDATE PLN_ZY_JG_WORKBILL SET "
                        + " LATHE_OK_NUM = TO_NUMBER('" + countQual + "'),"
                        + " LATHE_STATUS = '1' " + "WHERE WO_ID = '" + woId
                        + "'";
                sta = con.createStatement();
                sta.executeUpdate(sqlupdateWoId);
                sta.close();
            }
            if (gxNo.equals("700306")) {// 螺纹检验
                sqlupdateWoId = "UPDATE PLN_ZY_JG_WORKBILL SET "
                        + " THREAD_CHK_OK_NUM = TO_NUMBER('" + countQual
                        + "')," + " THREAD_CHK_STATUS = '1' "
                        + "WHERE WO_ID = '" + woId + "'";
                sta = con.createStatement();
                sta.executeUpdate(sqlupdateWoId);
                sta.close();
            }
            if (gxNo.equals("700307")) {// 探伤
                sqlupdateWoId = "UPDATE PLN_ZY_JG_WORKBILL SET "
                        + " DETECT_OK_NUM = TO_NUMBER('" + countQual + "'),"
                        + " DETECT_STATUS = '1' " + "WHERE WO_ID = '" + woId
                        + "'";
                sta = con.createStatement();
                sta.executeUpdate(sqlupdateWoId);
                sta.close();
            }
            if (gxNo.equals("700311")) {// 喷标
                sqlupdateWoId = "UPDATE PLN_ZY_JG_WORKBILL SET "
                        + " COPPER_OK_NUM = TO_NUMBER('" + countQual + "'),"
                        + " COPPER_STATUS = '1' " + "WHERE WO_ID = '" + woId
                        + "'";
                sta = con.createStatement();
                sta.executeUpdate(sqlupdateWoId);
                sta.close();
            }
            if (gxNo.equals("700308")) {// 喷砂
                sqlupdateWoId = "UPDATE PLN_ZY_JG_WORKBILL SET "
                        + " BLAST_OK_NUM = TO_NUMBER('" + countQual + "'),"
                        + " BLAST_STATUS = '1' " + "WHERE WO_ID = '" + woId
                        + "'";
                sta = con.createStatement();
                sta.executeUpdate(sqlupdateWoId);
                sta.close();
            }
            if (gxNmae.equals("镀铜")) {
                sqlupdateWoId = "UPDATE PLN_ZY_JG_WORKBILL SET "
                        + " PLT_CU_OK_NUM = TO_NUMBER('" + countQual + "'),"
                        + " PLT_CU_STATUS = '1' " + "WHERE WO_ID = '" + woId
                        + "'";
                sta = con.createStatement();
                sta.executeUpdate(sqlupdateWoId);
                sta.close();
            }
            if (gxNmae.equals("磷化")) {
                sqlupdateWoId = "UPDATE PLN_ZY_JG_WORKBILL SET "
                        + " PHOS_OK_NUM = TO_NUMBER('" + countQual + "'),"
                        + " PHOS_STATUS = '1' " + "WHERE WO_ID = '" + woId
                        + "'";
                sta = con.createStatement();
                sta.executeUpdate(sqlupdateWoId);
                sta.close();
            }

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

    /**
     * 修改切割实绩
     * @param result 切割实绩
     * @return
     */
    public CoreReturnObject updateThreadingResult(
            ArrayList<ArrayList<String>> pram, String woId) {
        CoreReturnObject cor = new CoreReturnObject();
        Connection con = this.getDao(CoreConstantData.sysbeanstr)
                .getConnection();
        try {
            con.setAutoCommit(false); // 取消自动提交事务
            String comInfoSql = CoreXmlSqlParsersFactory
                    .getSql("FrmOutSourPerfor.UpdateComInfoResult");// 修改comInfo表
            PreparedStatement comInfoPsta = con.prepareStatement(comInfoSql);

            // 查询工单状态
            int falg = 0;
            int cutfalg = 0;
            int cjgfalg = 0;// 粗加工
            int impfalg = 0;// 压印
            int latfalg = 0;// 车丝
            int detfalg = 0;// 探伤
            int pltfalg = 0;// 镀铜
            int blafalg = 0;// 喷标
            int phofalg = 0;// 磷化
            int psfalg = 0;// 喷砂
            int lwfalg = 0;// 螺纹检验
            String sqlloading = CoreXmlSqlParsersFactory
                    .getSql("PhosphateResultService.queryPlanJg");
            PreparedStatement psta = con.prepareStatement(sqlloading);
            psta.setObject(1, woId);
            ResultSet rs1 = psta.executeQuery();
            if (rs1.next()) {
                falg = Integer.parseInt(rs1.getString("ZY_BILL_STATUS"));
                cutfalg = Integer.parseInt(rs1.getString("CUT_STATUS"));
                cjgfalg = Integer.parseInt(rs1.getString("CJG_STATUS"));
                impfalg = Integer.parseInt(rs1.getString("IMPRESS_STATUS"));
                latfalg = Integer.parseInt(rs1.getString("LATHE_STATUS"));
                detfalg = Integer.parseInt(rs1.getString("DETECT_STATUS"));
                pltfalg = Integer.parseInt(rs1.getString("PLT_CU_STATUS"));
                psfalg = Integer.parseInt(rs1.getString("BLAST_STATUS"));
                phofalg = Integer.parseInt(rs1.getString("PHOS_STATUS"));
                blafalg = Integer.parseInt(rs1.getString("COPPER_STATUS"));
                lwfalg = Integer.parseInt(rs1.getString("THREAD_CHK_STATUS"));
            }
            rs1.close();
            psta.close();

            if (falg != 2) {
                cor.setV_errMsg("该工单不是生产中的状态,不允许此操作！");
                return cor;
            }

            for (int i = 0; i < pram.size(); i++) {
                ArrayList<String> list = (ArrayList<String>) pram.get(i);
                String resNo = list.get(0);
                // String woId = list.get(1);
                String planNo = list.get(2);
                String quaCount = list.get(3);
                String bc = list.get(4);
                String bz = list.get(5);
                String stationNo = list.get(6);
                String stationName = list.get(7);

                comInfoPsta.setObject(1, quaCount);
                comInfoPsta.setObject(2, bc);
                comInfoPsta.setObject(3, bz);
                comInfoPsta.setObject(4, resNo);
                comInfoPsta.setObject(5, planNo);
                comInfoPsta.setObject(6, stationNo);
                comInfoPsta.setObject(7, woId);
                comInfoPsta.addBatch();
                comInfoPsta.executeBatch();

                // 查询总数
                int countQual = 0;
                sqlloading = CoreXmlSqlParsersFactory
                        .getSql("FrmOutSourPerfor.queryCutCou1");
                psta = con.prepareStatement(sqlloading);
                psta.setObject(1, planNo);
                psta.setObject(2, stationNo);
                psta.setObject(3, woId);
                rs1 = psta.executeQuery();
                if (rs1.next()) {
                    countQual = Integer.parseInt(rs1.getString("PRO_NUM"));
                }
                rs1.close();
                psta.close();

                Statement sta = null;
                String sqlupdateWoId = null;

                if (stationNo.equals("700302")) {// 锯切
                    if (cutfalg == 2) {
                        cor.setV_errMsg("该工单切管已生产完成,不允许此操作,如要修改请先撤销结炉！");
                        return cor;
                    }
                    sqlupdateWoId = "UPDATE PLN_ZY_JG_WORKBILL SET "
                            + " CUT_OK_NUM = TO_NUMBER('" + countQual + "'),"
                            + " CUT_STATUS = '1' " + "WHERE WO_ID = '" + woId
                            + "'";
                    sta = con.createStatement();
                    sta.executeUpdate(sqlupdateWoId);
                    sta.close();
                }
                if (stationNo.equals("700303")) {// 粗加工
                    if (cjgfalg == 2) {
                        cor.setV_errMsg("该工单粗加工已生产完成,不允许此操作,如要修改请先撤销结炉！");
                        return cor;
                    }
                    sqlupdateWoId = "UPDATE PLN_ZY_JG_WORKBILL SET "
                            + " CJG_OK_NUM = TO_NUMBER('" + countQual + "'),"
                            + " CJG_STATUS = '1' " + "WHERE WO_ID = '" + woId
                            + "'";
                    sta = con.createStatement();
                    sta.executeUpdate(sqlupdateWoId);
                    sta.close();
                }
                if (stationNo.equals("700304")) {// 压印
                    if (impfalg == 2) {
                        cor.setV_errMsg("该工单压印已生产完成,不允许此操作,如要修改请先撤销结炉！");
                        return cor;
                    }
                    sqlupdateWoId = "UPDATE PLN_ZY_JG_WORKBILL SET "
                            + " IMPRESS_OK_NUM = TO_NUMBER('" + countQual
                            + "')," + " IMPRESS_STATUS = '1' "
                            + "WHERE WO_ID = '" + woId + "'";
                    sta = con.createStatement();
                    sta.executeUpdate(sqlupdateWoId);
                    sta.close();
                }
                if (stationNo.equals("700305")) {// 车丝
                    if (latfalg == 2) {
                        cor.setV_errMsg("该工单车丝已生产完成,不允许此操作,如要修改请先撤销结炉！");
                        return cor;
                    }
                    sqlupdateWoId = "UPDATE PLN_ZY_JG_WORKBILL SET "
                            + " LATHE_OK_NUM = TO_NUMBER('" + countQual + "'),"
                            + " LATHE_STATUS = '1' " + "WHERE WO_ID = '" + woId
                            + "'";
                    sta = con.createStatement();
                    sta.executeUpdate(sqlupdateWoId);
                    sta.close();
                }
                if (stationNo.equals("700306")) {// 螺纹检验
                    if (lwfalg == 2) {
                        cor.setV_errMsg("该工单螺纹检验已生产完成,不允许此操作,如要修改请先撤销结炉！");
                        return cor;
                    }
                    sqlupdateWoId = "UPDATE PLN_ZY_JG_WORKBILL SET "
                            + " THREAD_CHK_OK_NUM = TO_NUMBER('" + countQual
                            + "')," + " THREAD_CHK_STATUS = '1' "
                            + "WHERE WO_ID = '" + woId + "'";
                    sta = con.createStatement();
                    sta.executeUpdate(sqlupdateWoId);
                    sta.close();
                }
                if (stationNo.equals("700307")) {// 探伤
                    if (detfalg == 2) {
                        cor.setV_errMsg("该工单探伤已生产完成,不允许此操作,如要修改请先撤销结炉！");
                        return cor;
                    }
                    sqlupdateWoId = "UPDATE PLN_ZY_JG_WORKBILL SET "
                            + " DETECT_OK_NUM = TO_NUMBER('" + countQual
                            + "')," + " DETECT_STATUS = '1' "
                            + "WHERE WO_ID = '" + woId + "'";
                    sta = con.createStatement();
                    sta.executeUpdate(sqlupdateWoId);
                    sta.close();
                }
                if (stationNo.equals("700311")) {// 喷标
                    if (blafalg == 2) {
                        cor.setV_errMsg("该工单喷标已生产完成,不允许此操作,如要修改请先撤销结炉！");
                        return cor;
                    }
                    sqlupdateWoId = "UPDATE PLN_ZY_JG_WORKBILL SET "
                            + " COPPER_OK_NUM = TO_NUMBER('" + countQual
                            + "')," + " COPPER_STATUS = '1' "
                            + "WHERE WO_ID = '" + woId + "'";
                    sta = con.createStatement();
                    sta.executeUpdate(sqlupdateWoId);
                    sta.close();
                }
                if (stationNo.equals("700308")) {// 喷砂
                    if (psfalg == 2) {
                        cor.setV_errMsg("该工单喷砂已生产完成,不允许此操作,如要修改请先撤销结炉！");
                        return cor;
                    }
                    sqlupdateWoId = "UPDATE PLN_ZY_JG_WORKBILL SET "
                            + " BLAST_OK_NUM = TO_NUMBER('" + countQual + "'),"
                            + " BLAST_STATUS = '1' " + "WHERE WO_ID = '" + woId
                            + "'";
                    sta = con.createStatement();
                    sta.executeUpdate(sqlupdateWoId);
                    sta.close();
                }
                if (stationName.equals("镀铜")) {
                    if (pltfalg == 2) {
                        cor.setV_errMsg("该工单镀铜已生产完成,不允许此操作,如要修改请先撤销结炉！");
                        return cor;
                    }
                    sqlupdateWoId = "UPDATE PLN_ZY_JG_WORKBILL SET "
                            + " PLT_CU_OK_NUM = TO_NUMBER('" + countQual
                            + "')," + " PLT_CU_STATUS = '1' "
                            + "WHERE WO_ID = '" + woId + "'";
                    sta = con.createStatement();
                    sta.executeUpdate(sqlupdateWoId);
                    sta.close();
                }
                if (stationName.equals("磷化")) {
                    if (phofalg == 2) {
                        cor.setV_errMsg("该工单磷化已生产完成,不允许此操作,如要修改请先撤销结炉！");
                        return cor;
                    }
                    sqlupdateWoId = "UPDATE PLN_ZY_JG_WORKBILL SET "
                            + " PHOS_OK_NUM = TO_NUMBER('" + countQual + "'),"
                            + " PHOS_STATUS = '1' " + "WHERE WO_ID = '" + woId
                            + "'";
                    sta = con.createStatement();
                    sta.executeUpdate(sqlupdateWoId);
                    sta.close();
                }
            }
            cor.setV_errMsg("修改成功！");
            con.commit();
        }
        catch (Exception e) {
            System.out.println(e.getMessage());
            if (con != null) {
                try {
                    cor.setV_errMsg(e.getMessage());

                    con.rollback(); // 回滚事务
                }
                catch (Exception e2) {
                }
            }
        }
        finally {
            try {
                if (con != null && !con.isClosed()) {
                    con.close();
                }
            }
            catch (Exception e2) {
            }
        }
        return cor;
    }

    /**
     * 删除切割实绩
     * @param result 切割实绩
     * @return
     */
    public CoreReturnObject deleteThreadingResult(
            ArrayList<ArrayList<String>> pram, String woId) {
        CoreReturnObject cor = new CoreReturnObject();
        Connection con = this.getDao(CoreConstantData.sysbeanstr)
                .getConnection();
        try {
            con.setAutoCommit(false); // 取消自动提交事务
            String comInfoSql = CoreXmlSqlParsersFactory
                    .getSql("FrmOutSourPerfor.DeleteComInfoResult");// 删除comInfo表
            PreparedStatement comInfoPsta = con.prepareStatement(comInfoSql);

            // 查询工单状态
            int falg = 0;
            int cutfalg = 0;
            int cjgfalg = 0;// 粗加工
            int impfalg = 0;// 压印
            int latfalg = 0;// 车丝
            int detfalg = 0;// 探伤
            int pltfalg = 0;// 镀铜
            int blafalg = 0;// 喷标
            int phofalg = 0;// 磷化
            int psfalg = 0;// 喷砂
            int lwfalg = 0;// 螺纹检验
            String sqlloading = CoreXmlSqlParsersFactory
                    .getSql("PhosphateResultService.queryPlanJg");
            PreparedStatement psta = con.prepareStatement(sqlloading);
            psta.setObject(1, woId);
            ResultSet rs1 = psta.executeQuery();
            if (rs1.next()) {
                falg = Integer.parseInt(rs1.getString("ZY_BILL_STATUS"));
                cutfalg = Integer.parseInt(rs1.getString("CUT_STATUS"));
                cjgfalg = Integer.parseInt(rs1.getString("CJG_STATUS"));
                impfalg = Integer.parseInt(rs1.getString("IMPRESS_STATUS"));
                latfalg = Integer.parseInt(rs1.getString("LATHE_STATUS"));
                detfalg = Integer.parseInt(rs1.getString("DETECT_STATUS"));
                pltfalg = Integer.parseInt(rs1.getString("PLT_CU_STATUS"));
                blafalg = Integer.parseInt(rs1.getString("BLAST_STATUS"));
                phofalg = Integer.parseInt(rs1.getString("PHOS_STATUS"));
                psfalg = Integer.parseInt(rs1.getString("COPPER_STATUS"));
                lwfalg = Integer.parseInt(rs1.getString("THREAD_CHK_STATUS"));
            }
            rs1.close();
            psta.close();

            if (falg != 2) {
                cor.setV_errMsg("该工单不是生产中的状态,不允许此操作！");
                return cor;
            }

            for (int i = 0; i < pram.size(); i++) {
                ArrayList<String> list = (ArrayList<String>) pram.get(i);
                String resNo = list.get(0);
                String planNo = list.get(2);
                String stationNo = list.get(3);
                String stationName = list.get(4);

                comInfoPsta.setObject(1, resNo);
                comInfoPsta.setObject(2, planNo);
                comInfoPsta.setObject(3, stationNo);
                comInfoPsta.setObject(4, woId);
                comInfoPsta.addBatch();
                comInfoPsta.executeBatch();

                // 查询切管总数
                int countQual = 0;
                int count = 0;
                sqlloading = CoreXmlSqlParsersFactory
                        .getSql("FrmOutSourPerfor.queryCutCou1");
                psta = con.prepareStatement(sqlloading);
                psta.setObject(1, planNo);
                psta.setObject(2, stationNo);
                psta.setObject(3, woId);
                rs1 = psta.executeQuery();
                if (rs1.next()) {
                    count = Integer.parseInt(rs1.getString("count"));
                    if (count == 0) {
                        countQual = 0;
                    }
                    else {
                        countQual = Integer.parseInt(rs1.getString("PRO_NUM"));
                    }
                }
                rs1.close();
                psta.close();

                Statement sta = null;
                String sqlupdateWoId = null;
                if (count == 0) {
                    if (stationNo.equals("700302")) {// 锯切
                        if (cutfalg == 2) {
                            cor.setV_errMsg("该工单切管已生产完成,不允许此操作,如要修改请先撤销结炉！");
                            return cor;
                        }
                        sqlupdateWoId = "UPDATE PLN_ZY_JG_WORKBILL SET "
                                + " CUT_OK_NUM = TO_NUMBER('" + countQual
                                + "')," + " CUT_STATUS = '0' "
                                + "WHERE WO_ID = '" + woId + "'";
                        sta = con.createStatement();
                        sta.executeUpdate(sqlupdateWoId);
                        sta.close();
                    }
                    if (stationNo.equals("700303")) {// 粗加工
                        if (cjgfalg == 2) {
                            cor.setV_errMsg("该工单粗加工已生产完成,不允许此操作,如要修改请先撤销结炉！");
                            return cor;
                        }
                        sqlupdateWoId = "UPDATE PLN_ZY_JG_WORKBILL SET "
                                + " CJG_OK_NUM = TO_NUMBER('" + countQual
                                + "')," + " CJG_STATUS = '0' "
                                + "WHERE WO_ID = '" + woId + "'";
                        sta = con.createStatement();
                        sta.executeUpdate(sqlupdateWoId);
                        sta.close();
                    }
                    if (stationNo.equals("700304")) {// 压印
                        if (impfalg == 2) {
                            cor.setV_errMsg("该工单压印已生产完成,不允许此操作,如要修改请先撤销结炉！");
                            return cor;
                        }
                        sqlupdateWoId = "UPDATE PLN_ZY_JG_WORKBILL SET "
                                + " IMPRESS_OK_NUM = TO_NUMBER('" + countQual
                                + "')," + " IMPRESS_STATUS = '0' "
                                + "WHERE WO_ID = '" + woId + "'";
                        sta = con.createStatement();
                        sta.executeUpdate(sqlupdateWoId);
                        sta.close();
                    }
                    if (stationNo.equals("700305")) {// 车丝
                        if (latfalg == 2) {
                            cor.setV_errMsg("该工单车丝已生产完成,不允许此操作,如要修改请先撤销结炉！");
                            return cor;
                        }
                        sqlupdateWoId = "UPDATE PLN_ZY_JG_WORKBILL SET "
                                + " LATHE_OK_NUM = TO_NUMBER('" + countQual
                                + "')," + " LATHE_STATUS = '0' "
                                + "WHERE WO_ID = '" + woId + "'";
                        sta = con.createStatement();
                        sta.executeUpdate(sqlupdateWoId);
                        sta.close();
                    }
                    if (stationNo.equals("700306")) {// 螺纹检验
                        if (lwfalg == 2) {
                            cor.setV_errMsg("该工单螺纹检验已生产完成,不允许此操作,如要修改请先撤销结炉！");
                            return cor;
                        }
                        sqlupdateWoId = "UPDATE PLN_ZY_JG_WORKBILL SET "
                                + " THREAD_CHK_OK_NUM = TO_NUMBER('"
                                + countQual + "'),"
                                + " THREAD_CHK_STATUS = '0' "
                                + "WHERE WO_ID = '" + woId + "'";
                        sta = con.createStatement();
                        sta.executeUpdate(sqlupdateWoId);
                        sta.close();
                    }
                    if (stationNo.equals("700307")) {// 探伤
                        if (detfalg == 2) {
                            cor.setV_errMsg("该工单探伤已生产完成,不允许此操作,如要修改请先撤销结炉！");
                            return cor;
                        }
                        sqlupdateWoId = "UPDATE PLN_ZY_JG_WORKBILL SET "
                                + " DETECT_OK_NUM = TO_NUMBER('" + countQual
                                + "')," + " DETECT_STATUS = '0' "
                                + "WHERE WO_ID = '" + woId + "'";
                        sta = con.createStatement();
                        sta.executeUpdate(sqlupdateWoId);
                        sta.close();
                    }
                    if (stationNo.equals("700311")) {// 喷标
                        if (blafalg == 2) {
                            cor.setV_errMsg("该工单喷标已生产完成,不允许此操作,如要修改请先撤销结炉！");
                            return cor;
                        }
                        sqlupdateWoId = "UPDATE PLN_ZY_JG_WORKBILL SET "
                                + " COPPER_OK_NUM = TO_NUMBER('" + countQual
                                + "')," + " COPPER_STATUS = '0' "
                                + "WHERE WO_ID = '" + woId + "'";
                        sta = con.createStatement();
                        sta.executeUpdate(sqlupdateWoId);
                        sta.close();
                    }
                    if (stationNo.equals("700308")) {// 喷砂
                        if (psfalg == 2) {
                            cor.setV_errMsg("该工单喷砂已生产完成,不允许此操作,如要修改请先撤销结炉！");
                            return cor;
                        }
                        sqlupdateWoId = "UPDATE PLN_ZY_JG_WORKBILL SET "
                                + " BLAST_OK_NUM = TO_NUMBER('" + countQual
                                + "')," + " BLAST_STATUS = '0' "
                                + "WHERE WO_ID = '" + woId + "'";
                        sta = con.createStatement();
                        sta.executeUpdate(sqlupdateWoId);
                        sta.close();
                    }
                    if (stationName.equals("镀铜")) {
                        if (pltfalg == 2) {
                            cor.setV_errMsg("该工单镀铜已生产完成,不允许此操作,如要修改请先撤销结炉！");
                            return cor;
                        }
                        sqlupdateWoId = "UPDATE PLN_ZY_JG_WORKBILL SET "
                                + " PLT_CU_OK_NUM = TO_NUMBER('" + countQual
                                + "')," + " PLT_CU_STATUS = '0' "
                                + "WHERE WO_ID = '" + woId + "'";
                        sta = con.createStatement();
                        sta.executeUpdate(sqlupdateWoId);
                        sta.close();
                    }
                    if (stationName.equals("磷化")) {
                        if (phofalg == 2) {
                            cor.setV_errMsg("该工单磷化已生产完成,不允许此操作,如要修改请先撤销结炉！");
                            return cor;
                        }
                        sqlupdateWoId = "UPDATE PLN_ZY_JG_WORKBILL SET "
                                + " PHOS_OK_NUM = TO_NUMBER('" + countQual
                                + "')," + " PHOS_STATUS = '0' "
                                + "WHERE WO_ID = '" + woId + "'";
                        sta = con.createStatement();
                        sta.executeUpdate(sqlupdateWoId);
                        sta.close();
                    }
                }
                else {
                    if (stationNo.equals("700302")) {// 锯切
                        if (cutfalg == 2) {
                            cor.setV_errMsg("该工单切管已生产完成,不允许此操作,如要修改请先撤销结炉！");
                            return cor;
                        }
                        sqlupdateWoId = "UPDATE PLN_ZY_JG_WORKBILL SET "
                                + " CUT_OK_NUM = TO_NUMBER('" + countQual
                                + "')," + " CUT_STATUS = '1' "
                                + "WHERE WO_ID = '" + woId + "'";
                        sta = con.createStatement();
                        sta.executeUpdate(sqlupdateWoId);
                        sta.close();
                    }
                    if (stationNo.equals("700303")) {// 粗加工
                        if (cjgfalg == 2) {
                            cor.setV_errMsg("该工单粗加工已生产完成,不允许此操作,如要修改请先撤销结炉！");
                            return cor;
                        }
                        sqlupdateWoId = "UPDATE PLN_ZY_JG_WORKBILL SET "
                                + " CJG_OK_NUM = TO_NUMBER('" + countQual
                                + "')," + " CJG_STATUS = '1' "
                                + "WHERE WO_ID = '" + woId + "'";
                        sta = con.createStatement();
                        sta.executeUpdate(sqlupdateWoId);
                        sta.close();
                    }
                    if (stationNo.equals("700304")) {// 压印
                        if (impfalg == 2) {
                            cor.setV_errMsg("该工单压印已生产完成,不允许此操作,如要修改请先撤销结炉！");
                            return cor;
                        }
                        sqlupdateWoId = "UPDATE PLN_ZY_JG_WORKBILL SET "
                                + " IMPRESS_OK_NUM = TO_NUMBER('" + countQual
                                + "')," + " IMPRESS_STATUS = '1' "
                                + "WHERE WO_ID = '" + woId + "'";
                        sta = con.createStatement();
                        sta.executeUpdate(sqlupdateWoId);
                        sta.close();
                    }
                    if (stationNo.equals("700305")) {// 车丝
                        if (latfalg == 2) {
                            cor.setV_errMsg("该工单车丝已生产完成,不允许此操作,如要修改请先撤销结炉！");
                            return cor;
                        }
                        sqlupdateWoId = "UPDATE PLN_ZY_JG_WORKBILL SET "
                                + " LATHE_OK_NUM = TO_NUMBER('" + countQual
                                + "')," + " LATHE_STATUS = '1' "
                                + "WHERE WO_ID = '" + woId + "'";
                        sta = con.createStatement();
                        sta.executeUpdate(sqlupdateWoId);
                        sta.close();
                    }
                    if (stationNo.equals("700306")) {// 螺纹检验
                        if (lwfalg == 2) {
                            cor.setV_errMsg("该工单螺纹检验已生产完成,不允许此操作,如要修改请先撤销结炉！");
                            return cor;
                        }
                        sqlupdateWoId = "UPDATE PLN_ZY_JG_WORKBILL SET "
                                + " THREAD_CHK_OK_NUM = TO_NUMBER('"
                                + countQual + "'),"
                                + " THREAD_CHK_STATUS = '1' "
                                + "WHERE WO_ID = '" + woId + "'";
                        sta = con.createStatement();
                        sta.executeUpdate(sqlupdateWoId);
                        sta.close();
                    }
                    if (stationNo.equals("700307")) {// 探伤
                        if (detfalg == 2) {
                            cor.setV_errMsg("该工单探伤已生产完成,不允许此操作,如要修改请先撤销结炉！");
                            return cor;
                        }
                        sqlupdateWoId = "UPDATE PLN_ZY_JG_WORKBILL SET "
                                + " DETECT_OK_NUM = TO_NUMBER('" + countQual
                                + "')," + " DETECT_STATUS = '1' "
                                + "WHERE WO_ID = '" + woId + "'";
                        sta = con.createStatement();
                        sta.executeUpdate(sqlupdateWoId);
                        sta.close();
                    }
                    if (stationNo.equals("700311")) {// 喷标
                        if (blafalg == 2) {
                            cor.setV_errMsg("该工单喷标已生产完成,不允许此操作,如要修改请先撤销结炉！");
                            return cor;
                        }
                        sqlupdateWoId = "UPDATE PLN_ZY_JG_WORKBILL SET "
                                + " COPPER_OK_NUM = TO_NUMBER('" + countQual
                                + "')," + " COPPER_STATUS = '1' "
                                + "WHERE WO_ID = '" + woId + "'";
                        sta = con.createStatement();
                        sta.executeUpdate(sqlupdateWoId);
                        sta.close();
                    }
                    if (stationNo.equals("700308")) {// 喷砂
                        if (psfalg == 2) {
                            cor.setV_errMsg("该工单喷砂已生产完成,不允许此操作,如要修改请先撤销结炉！");
                            return cor;
                        }
                        sqlupdateWoId = "UPDATE PLN_ZY_JG_WORKBILL SET "
                                + " BLAST_OK_NUM = TO_NUMBER('" + countQual
                                + "')," + " BLAST_STATUS = '1' "
                                + "WHERE WO_ID = '" + woId + "'";
                        sta = con.createStatement();
                        sta.executeUpdate(sqlupdateWoId);
                        sta.close();
                    }
                    if (stationName.equals("镀铜")) {
                        if (pltfalg == 2) {
                            cor.setV_errMsg("该工单镀铜已生产完成,不允许此操作,如要修改请先撤销结炉！");
                            return cor;
                        }
                        sqlupdateWoId = "UPDATE PLN_ZY_JG_WORKBILL SET "
                                + " PLT_CU_OK_NUM = TO_NUMBER('" + countQual
                                + "')," + " PLT_CU_STATUS = '1' "
                                + "WHERE WO_ID = '" + woId + "'";
                        sta = con.createStatement();
                        sta.executeUpdate(sqlupdateWoId);
                        sta.close();
                    }
                    if (stationName.equals("磷化")) {
                        if (phofalg == 2) {
                            cor.setV_errMsg("该工单磷化已生产完成,不允许此操作,如要修改请先撤销结炉！");
                            return cor;
                        }
                        sqlupdateWoId = "UPDATE PLN_ZY_JG_WORKBILL SET "
                                + " PHOS_OK_NUM = TO_NUMBER('" + countQual
                                + "')," + " PHOS_STATUS = '1' "
                                + "WHERE WO_ID = '" + woId + "'";
                        sta = con.createStatement();
                        sta.executeUpdate(sqlupdateWoId);
                        sta.close();
                    }
                }
            }
            cor.setV_errMsg("删除成功！");
            con.commit();
        }
        catch (Exception e) {
            System.out.println(e.getMessage());
            if (con != null) {
                try {
                    cor.setV_errMsg(e.getMessage());

                    con.rollback(); // 回滚事务
                }
                catch (Exception e2) {
                }
            }
        }
        finally {
            try {
                if (con != null && !con.isClosed()) {
                    con.close();
                }
            }
            catch (Exception e2) {
            }
        }
        return cor;
    }

    /***
     * 生成实绩编号
     * @param plineCode
     * @param zygNo
     * @param connection
     * @return
     */
    public String doAddResultNo(String xh, String stationNo, String plineCode,
            String zygNo, String woId, Connection connection) {
        String resultNo = "";
        PreparedStatement psta = null;
        Date dt = new Date();
        SimpleDateFormat matter1 = new SimpleDateFormat("yyMMdd");
        SimpleDateFormat matter = new SimpleDateFormat("yyyy-MM-dd");
        String sqlloading = CoreXmlSqlParsersFactory
                .getSql("FrmOutSourPerfor.queryLoadRESULT");// 查询最大实绩编号

        try {
            psta = connection.prepareStatement(sqlloading);
            psta.setObject(1, plineCode);
            psta.setObject(2, xh);
            psta.setObject(3, matter1.format(dt));
            psta.setObject(4, matter.format(dt));
            psta.setObject(5, plineCode);
            psta.setObject(6, zygNo);
            psta.setObject(7, stationNo);
            psta.setObject(8, woId);
            ResultSet rs1 = psta.executeQuery();
            if (rs1.next()) {
                resultNo = rs1.getString("RESULT_NO");
            }
            rs1.close();
            psta.close();
        }
        catch (SQLException e) {
            e.printStackTrace();
        }

        return resultNo;
    }

    /***
     * 结炉
     * @param zYgNo
     * @return
     */
    public CoreReturnObject doBeside(ArrayList<ArrayList<String>> parm) {
        CoreReturnObject cro = new CoreReturnObject();
        Connection connection = this.getDao(CoreConstantData.sysbeanstr)
                .getConnection();
        // String sql = "";
        // PreparedStatement psta = null;
        // ResultSet rs = null;
        try {
            connection.setAutoCommit(false); // 取消自动提交事务
            String updateSql = CoreXmlSqlParsersFactory
                    .getSql("FrmOutSourPerfor.doBeside");// 锯切结炉
            PreparedStatement updateSqlPsta = connection
                    .prepareStatement(updateSql);
            String updateSqlCJG = CoreXmlSqlParsersFactory
                    .getSql("FrmOutSourPerfor.doBesideCJG");// 粗加工结炉
            PreparedStatement updateSqlPstaCJG = connection
                    .prepareStatement(updateSqlCJG);
            String updateSqlYY = CoreXmlSqlParsersFactory
                    .getSql("FrmOutSourPerfor.doBesideYY");// 压印结炉
            PreparedStatement updateSqlPstaYY = connection
                    .prepareStatement(updateSqlYY);
            String updateSqlTS = CoreXmlSqlParsersFactory
                    .getSql("FrmOutSourPerfor.doBesideTS");// 探伤结炉
            PreparedStatement updateSqlPstaTS = connection
                    .prepareStatement(updateSqlTS);
            String updateSqlPS = CoreXmlSqlParsersFactory
                    .getSql("FrmOutSourPerfor.doBesidePS");// 喷砂结炉
            PreparedStatement updateSqlPstaPS = connection
                    .prepareStatement(updateSqlPS);
            String updateSqlCS = CoreXmlSqlParsersFactory
                    .getSql("FrmOutSourPerfor.doBesideCS");// 车丝结炉
            PreparedStatement updateSqlPstaCS = connection
                    .prepareStatement(updateSqlCS);
            String updateSqlDT = CoreXmlSqlParsersFactory
                    .getSql("FrmOutSourPerfor.doBesideDT");// 镀铜结炉
            PreparedStatement updateSqlPstaDT = connection
                    .prepareStatement(updateSqlDT);
            String updateSqlLH = CoreXmlSqlParsersFactory
                    .getSql("FrmOutSourPerfor.doBesideLH");// 磷化结炉
            PreparedStatement updateSqlPstaLH = connection
                    .prepareStatement(updateSqlLH);
            String updateSqlPB = CoreXmlSqlParsersFactory
                    .getSql("FrmOutSourPerfor.doBesidePB");// 喷标结炉
            PreparedStatement updateSqlPstaPB = connection
                    .prepareStatement(updateSqlPB);
            String updateSqlLW = CoreXmlSqlParsersFactory
                    .getSql("FrmOutSourPerfor.doBesideLW");// 螺纹结炉
            PreparedStatement updateSqlPstaLW = connection
                    .prepareStatement(updateSqlLW);

            for (int i = 0; i < parm.size(); i++) {
                ArrayList<String> list = (ArrayList<String>) parm.get(i);
                String resNo = list.get(0);
                String woId = list.get(1);
                String planNo = list.get(2);
                String stationCode = list.get(3);
                String stationName = list.get(4);
                //                
                // sql = CoreXmlSqlParsersFactory
                // .getSql("FrmOutSourPerfor.selectComInfo");
                // psta = connection.prepareStatement(sql);
                // psta.setString(1, list.get(0));
                // psta.setString(2, list.get(1));
                // rs = psta.executeQuery();
                // if (rs.next()) {
                //
                // }
                // else {
                // cro.setV_errMsg("无当前工序实绩,无法进行结炉!");
                // return cro;
                // }
                // rs.close();
                // psta.close();
                if (stationCode.equals("700302")) {// 锯切
                    updateSqlPsta.setObject(1, "2");
                    updateSqlPsta.setObject(2, planNo);
                    updateSqlPsta.setObject(3, stationCode);
//                    updateSqlPsta.setObject(4, resNo);
                    updateSqlPsta.setObject(4, woId);
                    updateSqlPsta.setObject(5, "2");
                    updateSqlPsta.setObject(6, planNo);
                    updateSqlPsta.setObject(7, woId);
                    updateSqlPsta.addBatch();
                    updateSqlPsta.executeBatch();
                }
                else if (stationCode.equals("700303")) {// 粗加工
                    updateSqlPstaCJG.setObject(1, "2");
                    updateSqlPstaCJG.setObject(2, planNo);
                    updateSqlPstaCJG.setObject(3, stationCode);
//                    updateSqlPstaCJG.setObject(4, resNo);
                    updateSqlPstaCJG.setObject(4, woId);
                    updateSqlPstaCJG.setObject(5, "2");
                    updateSqlPstaCJG.setObject(6, planNo);
                    updateSqlPstaCJG.setObject(7, woId);
                    updateSqlPstaCJG.addBatch();
                    updateSqlPstaCJG.executeBatch();
                }
                else if (stationCode.equals("700304")) {// 压印
                    updateSqlPstaYY.setObject(1, "2");
                    updateSqlPstaYY.setObject(2, planNo);
                    updateSqlPstaYY.setObject(3, stationCode);
//                    updateSqlPstaYY.setObject(4, resNo);
                    updateSqlPstaYY.setObject(4, woId);   
                    updateSqlPstaYY.setObject(5, "2");
                    updateSqlPstaYY.setObject(6, planNo);
                    updateSqlPstaYY.setObject(7, woId);
                    updateSqlPstaYY.addBatch();
                    updateSqlPstaYY.executeBatch();
                }
                else if (stationCode.equals("700305")) {// 车丝
                    updateSqlPstaCS.setObject(1, "2");
                    updateSqlPstaCS.setObject(2, planNo);
                    updateSqlPstaCS.setObject(3, stationCode);
//                    updateSqlPstaCS.setObject(4, resNo);
                    updateSqlPstaCS.setObject(4, woId);                
                    updateSqlPstaCS.setObject(5, "2");
                    updateSqlPstaCS.setObject(6, planNo);
                    updateSqlPstaCS.setObject(7, woId);
                    updateSqlPstaCS.addBatch();
                    updateSqlPstaCS.executeBatch();
                }
                else if (stationCode.equals("700307")) {// 探伤
                    updateSqlPstaTS.setObject(1, "2");
                    updateSqlPstaTS.setObject(2, planNo);
                    updateSqlPstaTS.setObject(3, stationCode);
//                    updateSqlPstaTS.setObject(4, resNo);
                    updateSqlPstaTS.setObject(4, woId);
                    updateSqlPstaTS.setObject(5, "2");
                    updateSqlPstaTS.setObject(6, planNo);
                    updateSqlPstaTS.setObject(7, woId);
                    updateSqlPstaTS.addBatch();
                    updateSqlPstaTS.executeBatch();
                }
                else if (stationCode.equals("700306")) {// 螺纹
                    updateSqlPstaLW.setObject(1, "2");
                    updateSqlPstaLW.setObject(2, planNo);
                    updateSqlPstaLW.setObject(3, stationCode);
//                    updateSqlPstaLW.setObject(4, resNo);
                    updateSqlPstaLW.setObject(4, woId);          
                    updateSqlPstaLW.setObject(5, "2");
                    updateSqlPstaLW.setObject(6, planNo);
                    updateSqlPstaLW.setObject(7, woId);
                    updateSqlPstaLW.addBatch();
                    updateSqlPstaLW.executeBatch();
                }
                else if (stationCode.equals("700308")) {// 喷砂
                    updateSqlPstaPS.setObject(1, "2");
                    updateSqlPstaPS.setObject(2, planNo);
                    updateSqlPstaPS.setObject(3, stationCode);
//                    updateSqlPstaPS.setObject(4, resNo);
                    updateSqlPstaPS.setObject(4, woId);
                    updateSqlPstaPS.setObject(5, "2");
                    updateSqlPstaPS.setObject(6, planNo);
                    updateSqlPstaPS.setObject(7, woId);
                    updateSqlPstaPS.addBatch();
                    updateSqlPstaPS.executeBatch();
                }
                else if (stationCode.equals("700311")) {// 喷标
                    updateSqlPstaPB.setObject(1, "2");
                    updateSqlPstaPB.setObject(2, planNo);
                    updateSqlPstaPB.setObject(3, stationCode);
//                    updateSqlPstaPB.setObject(4, resNo);
                    updateSqlPstaPB.setObject(4, woId);
                    updateSqlPstaPB.setObject(5, "2");
                    updateSqlPstaPB.setObject(6, planNo);
                    updateSqlPstaPB.setObject(7, woId);
                    updateSqlPstaPB.addBatch();
                    updateSqlPstaPB.executeBatch();
                }
                else if (stationName.equals("镀铜")) {
                    updateSqlPstaDT.setObject(1, "2");
                    updateSqlPstaDT.setObject(2, planNo);
                    updateSqlPstaDT.setObject(3, stationCode);
//                    updateSqlPstaDT.setObject(4, resNo);
                    updateSqlPstaDT.setObject(4, woId);
                    updateSqlPstaDT.setObject(5, "2");
                    updateSqlPstaDT.setObject(6, planNo);
                    updateSqlPstaDT.setObject(7, woId);
                    updateSqlPstaDT.addBatch();
                    updateSqlPstaDT.executeBatch();
                }
                else if (stationName.equals("磷化")) {
                    updateSqlPstaLH.setObject(1, "2");
                    updateSqlPstaLH.setObject(2, planNo);
                    updateSqlPstaLH.setObject(3, stationCode);
//                    updateSqlPstaLH.setObject(4, resNo);
                    updateSqlPstaLH.setObject(4, woId);
                    updateSqlPstaLH.setObject(5, "2");
                    updateSqlPstaLH.setObject(6, planNo);
                    updateSqlPstaLH.setObject(7, woId);
                    updateSqlPstaLH.addBatch();
                    updateSqlPstaLH.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<ArrayList<String>> parm) {
        CoreReturnObject cro = new CoreReturnObject();
        Connection connection = this.getDao(CoreConstantData.sysbeanstr)
                .getConnection();
        PreparedStatement psta = null;
        try {
            connection.setAutoCommit(false); // 取消自动提交事务
            String updateSql = CoreXmlSqlParsersFactory
                    .getSql("FrmOutSourPerfor.doBeside");// 锯切结炉
            PreparedStatement updateSqlPsta = connection
                    .prepareStatement(updateSql);
            String updateSqlCJG = CoreXmlSqlParsersFactory
                    .getSql("FrmOutSourPerfor.doBesideCJG");// 粗加工结炉
            PreparedStatement updateSqlPstaCJG = connection
                    .prepareStatement(updateSqlCJG);
            String updateSqlYY = CoreXmlSqlParsersFactory
                    .getSql("FrmOutSourPerfor.doBesideYY");// 压印结炉
            PreparedStatement updateSqlPstaYY = connection
                    .prepareStatement(updateSqlYY);
            String updateSqlTS = CoreXmlSqlParsersFactory
                    .getSql("FrmOutSourPerfor.doBesideTS");// 探伤结炉
            PreparedStatement updateSqlPstaTS = connection
                    .prepareStatement(updateSqlTS);
            String updateSqlPS = CoreXmlSqlParsersFactory
                    .getSql("FrmOutSourPerfor.doBesidePS");// 喷砂结炉
            PreparedStatement updateSqlPstaPS = connection
                    .prepareStatement(updateSqlPS);
            String updateSqlCS = CoreXmlSqlParsersFactory
                    .getSql("FrmOutSourPerfor.doBesideCS");// 车丝结炉
            PreparedStatement updateSqlPstaCS = connection
                    .prepareStatement(updateSqlCS);
            String updateSqlDT = CoreXmlSqlParsersFactory
                    .getSql("FrmOutSourPerfor.doBesideDT");// 镀铜结炉
            PreparedStatement updateSqlPstaDT = connection
                    .prepareStatement(updateSqlDT);
            String updateSqlLH = CoreXmlSqlParsersFactory
                    .getSql("FrmOutSourPerfor.doBesideLH");// 磷化结炉
            PreparedStatement updateSqlPstaLH = connection
                    .prepareStatement(updateSqlLH);
            String updateSqlPB = CoreXmlSqlParsersFactory
                    .getSql("FrmOutSourPerfor.doBesidePB");// 喷标结炉
            PreparedStatement updateSqlPstaPB = connection
                    .prepareStatement(updateSqlPB);
            String updateSqlLW = CoreXmlSqlParsersFactory
                    .getSql("FrmOutSourPerfor.doBesideLW");// 螺纹结炉
            PreparedStatement updateSqlPstaLW = connection
                    .prepareStatement(updateSqlLW);
            for (int i = 0; i < parm.size(); i++) {
                ArrayList<String> list = (ArrayList<String>) parm.get(i);
                String resNo = list.get(0);
                String woId = list.get(1);
                String planNo = list.get(2);
                String stationCode = list.get(3);
                String stationName = list.get(4);

                // 查询工单状态
                int falg = 0;
                String cutfalg = "";
                String cjgfalg = "";// 粗加工
                String impfalg = "";// 压印
                String latfalg = "";// 车丝
                String detfalg = "";// 探伤
                String pltfalg = "";// 镀铜
                String blafalg = "";// 喷标
                String phofalg = "";// 磷化
                String psfalg = "";// 喷砂
                String lwfalg = "";// 螺纹检验

                String sqlloading = CoreXmlSqlParsersFactory
                        .getSql("PhosphateResultService.queryPlanJg");
                psta = connection.prepareStatement(sqlloading);
                psta.setObject(1,woId);
                ResultSet rs1 = psta.executeQuery();
                if (rs1.next()) {
                    falg = Integer.parseInt(rs1.getString("ZY_BILL_STATUS"));
                    cutfalg = rs1.getString("CUT_STATUS");
                    cjgfalg = rs1.getString("CJG_STATUS");
                    impfalg = rs1.getString("IMPRESS_STATUS");
                    latfalg = rs1.getString("LATHE_STATUS");
                    detfalg = rs1.getString("DETECT_STATUS");
                    pltfalg = rs1.getString("PLT_CU_STATUS");
                    psfalg = rs1.getString("BLAST_STATUS");
                    phofalg = rs1.getString("PHOS_STATUS");
                    blafalg = rs1.getString("COPPER_STATUS");
                    lwfalg = rs1.getString("THREAD_CHK_STATUS");
                }
                rs1.close();
                psta.close();
                if (falg >= 3) {
                    cro.setV_errMsg("该工单已生产完成!");
                    return cro;
                }
                if (stationCode.equals("700302")) {// 锯切
                    if (!cutfalg.equals("2")) {
                        cro.setV_errMsg("未结炉!");
                        return cro;
                    }
                    updateSqlPsta.setObject(1, "1");
                    updateSqlPsta.setObject(2, planNo);
                    updateSqlPsta.setObject(3, stationCode);
//                    updateSqlPsta.setObject(4, resNo);
                    updateSqlPsta.setObject(4, woId); 
                    updateSqlPsta.setObject(5, "1");
                    updateSqlPsta.setObject(6, planNo);
                    updateSqlPsta.setObject(7, woId);
                    updateSqlPsta.addBatch();
                    updateSqlPsta.executeBatch();
                }
                else if (stationCode.equals("700303")) {// 粗加工
                    if (!cjgfalg.equals("2")) {
                        cro.setV_errMsg("未结炉!");
                        return cro;
                    }
                    updateSqlPstaCJG.setObject(1, "1");
                    updateSqlPstaCJG.setObject(2, planNo);
                    updateSqlPstaCJG.setObject(3, stationCode);
//                    updateSqlPstaCJG.setObject(4, resNo);
                    updateSqlPstaCJG.setObject(4, woId);
                    updateSqlPstaCJG.setObject(5, "1");
                    updateSqlPstaCJG.setObject(6, planNo);
                    updateSqlPstaCJG.setObject(7, woId);
                    updateSqlPstaCJG.addBatch();
                    updateSqlPstaCJG.executeBatch();
                }
                else if (stationCode.equals("700304")) {// 压印
                    if (!impfalg.equals("2")) {
                        cro.setV_errMsg("未结炉!");
                        return cro;
                    }
                    updateSqlPstaYY.setObject(1, "1");
                    updateSqlPstaYY.setObject(2, planNo);
                    updateSqlPstaYY.setObject(3, stationCode);
//                    updateSqlPstaYY.setObject(4, resNo);
                    updateSqlPstaYY.setObject(4, woId);
                    updateSqlPstaYY.setObject(5, "1");
                    updateSqlPstaYY.setObject(6, planNo);
                    updateSqlPstaYY.setObject(7, woId);
                    updateSqlPstaYY.addBatch();
                    updateSqlPstaYY.executeBatch();
                }
                else if (stationCode.equals("700305")) {// 车丝
                    if (!latfalg.equals("2")) {
                        cro.setV_errMsg("未结炉!");
                        return cro;
                    }
                    updateSqlPstaCS.setObject(1, "1");
                    updateSqlPstaCS.setObject(2, planNo);
                    updateSqlPstaCS.setObject(3, stationCode);
//                    updateSqlPstaCS.setObject(4, resNo);
                    updateSqlPstaCS.setObject(4, woId);             
                    updateSqlPstaCS.setObject(5, "1");
                    updateSqlPstaCS.setObject(6, planNo);
                    updateSqlPstaCS.setObject(7, woId);
                    updateSqlPstaCS.addBatch();
                    updateSqlPstaCS.executeBatch();
                }
                else if (stationCode.equals("700307")) {// 探伤
                    if (!detfalg.equals("2")) {
                        cro.setV_errMsg("未结炉!");
                        return cro;
                    }
                    updateSqlPstaTS.setObject(1, "1");
                    updateSqlPstaTS.setObject(2, planNo);
                    updateSqlPstaTS.setObject(3, stationCode);
//                    updateSqlPstaTS.setObject(4, resNo);
                    updateSqlPstaTS.setObject(4, woId);           
                    updateSqlPstaTS.setObject(5, "1");
                    updateSqlPstaTS.setObject(6, planNo);
                    updateSqlPstaTS.setObject(7, woId);
                    updateSqlPstaTS.addBatch();
                    updateSqlPstaTS.executeBatch();
                }
                else if (stationCode.equals("700306")) {// 螺纹
                    if (!lwfalg.equals("2")) {
                        cro.setV_errMsg("未结炉!");
                        return cro;
                    }
                    updateSqlPstaLW.setObject(1, "1");
                    updateSqlPstaLW.setObject(2, planNo);
                    updateSqlPstaLW.setObject(3, stationCode);
//                    updateSqlPstaLW.setObject(4, resNo);
                    updateSqlPstaLW.setObject(4, woId);               
                    updateSqlPstaLW.setObject(5, "1");
                    updateSqlPstaLW.setObject(6, planNo);
                    updateSqlPstaLW.setObject(7, woId);
                    updateSqlPstaLW.addBatch();
                    updateSqlPstaLW.executeBatch();
                }
                else if (stationCode.equals("700308")) {// 喷砂
                    if (!psfalg.equals("2")) {
                        cro.setV_errMsg("未结炉!");
                        return cro;
                    }
                    updateSqlPstaPS.setObject(1, "1");
                    updateSqlPstaPS.setObject(2, planNo);
                    updateSqlPstaPS.setObject(3, stationCode);
//                    updateSqlPstaPS.setObject(4, resNo);
                    updateSqlPstaPS.setObject(4, woId);          
                    updateSqlPstaPS.setObject(5, "1");
                    updateSqlPstaPS.setObject(6, planNo);
                    updateSqlPstaPS.setObject(7, woId);
                    updateSqlPstaPS.addBatch();
                    updateSqlPstaPS.executeBatch();
                }
                else if (stationCode.equals("700311")) {// 喷标
                    if (!blafalg.equals("2")) {
                        cro.setV_errMsg("未结炉!");
                        return cro;
                    }
                    updateSqlPstaPB.setObject(1, "1");
                    updateSqlPstaPB.setObject(2, planNo);
                    updateSqlPstaPB.setObject(3, stationCode);
//                    updateSqlPstaPB.setObject(4, resNo);
                    updateSqlPstaPB.setObject(4, woId);                 
                    updateSqlPstaPB.setObject(5, "1");
                    updateSqlPstaPB.setObject(6, planNo);
                    updateSqlPstaPB.setObject(7, woId);
                    updateSqlPstaPB.addBatch();
                    updateSqlPstaPB.executeBatch();
                }
                else if (stationName.equals("镀铜")) {
                    if (!pltfalg.equals("2")) {
                        cro.setV_errMsg("未结炉!");
                        return cro;
                    }
                    updateSqlPstaDT.setObject(1, "1");
                    updateSqlPstaDT.setObject(2, planNo);
                    updateSqlPstaDT.setObject(3, stationCode);
//                    updateSqlPstaDT.setObject(4, resNo);
                    updateSqlPstaDT.setObject(4, woId);
                 
                    updateSqlPstaDT.setObject(5, "1");
                    updateSqlPstaDT.setObject(6, planNo);
                    updateSqlPstaDT.setObject(7, woId);
                    updateSqlPstaDT.addBatch();
                    updateSqlPstaDT.executeBatch();
                }
                else if (stationName.equals("磷化")) {
                    if (!phofalg.equals("2")) {
                        cro.setV_errMsg("未结炉!");
                        return cro;
                    }
                    updateSqlPstaLH.setObject(1, "1");
                    updateSqlPstaLH.setObject(2, planNo);
                    updateSqlPstaLH.setObject(3, stationCode);
//                    updateSqlPstaLH.setObject(4, resNo);
                    updateSqlPstaLH.setObject(4, woId);    
                    updateSqlPstaLH.setObject(5, "1");
                    updateSqlPstaLH.setObject(6, planNo);
                    updateSqlPstaLH.setObject(7, woId);
                    updateSqlPstaLH.addBatch();
                    updateSqlPstaLH.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;
    }
}
