package com.steering.mes.mcp.heatTreatment;

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

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

/**
 * 精整作业实绩服务类
 * @author lzh 2015-7-23
 */
public class FinishingService extends DBCommon {

    /**
     * 查询热矫实绩
     * @param planNo
     * @return
     */
    public CoreReturnObject queryHlstraightenResult(String heratNo) {
        return this.getDataBySqlID("FinishingService.QueryHlstraightenResult",
                new Object[] { heratNo });
    }

    /**
     * 查询冷矫实绩
     * @param planNo
     * @return
     */
    public CoreReturnObject queryClstraightenResult(String heratNo) {
        return this.getDataBySqlID("FinishingService.QueryClstraightenResult",
                new Object[] { heratNo });
    }

    /**
     * 查询定径实绩
     * @param planNo
     * @return
     */
    public CoreReturnObject querySizingResult(String heratNo) {
        return this.getDataBySqlID("FinishingService.QuerySizingResult",
                new Object[] { heratNo });
    }
    /**
     * 查询热矫合格支数的和
     */
    public CoreReturnObject getQueryExpandResult1(String heatNo) {
		return this.getDataBySqlID("FinishingService.getQueryExpandResult1",
				new Object[] { heatNo });
	}
    
    /**
     * 查询冷矫合格支数的和
     */
    public CoreReturnObject getQueryExpandResult2(String heatNo) {
		return this.getDataBySqlID("FinishingService.getQueryExpandResult2",
				new Object[] { heatNo });
	}
    /**
     * 查询定径合格支数的和
     */
    public CoreReturnObject getQueryExpandResult3(String heatNo) {
		return this.getDataBySqlID("FinishingService.getQueryExpandResult3",
				new Object[] { heatNo });
	}
    /**
	 * 查询相同炉计划ID下定径
	 */
	public CoreReturnObject getQueryExpandResultStuts(String heatNo,
			String plinCode) {
		return this.getDataBySqlID(
				"FinishingService.getQueryExpandResultStuts", new Object[] {
						heatNo, plinCode });
	}
    /**
	 * 查询相同炉计划ID下热矫
	 */
	public CoreReturnObject getQueryExpandResultStuts1(String heatNo,
			String plinCode) {
		return this.getDataBySqlID(
				"FinishingService.getQueryExpandResultStuts1", new Object[] {
						heatNo, plinCode });
	}
    /**
	 * 查询相同炉计划ID下冷矫
	 */
	public CoreReturnObject getQueryExpandResultStuts2(String heatNo,
			String plinCode) {
		return this.getDataBySqlID(
				"FinishingService.getQueryExpandResultStuts2", new Object[] {
						heatNo, plinCode });
	}
    /**
     * 查询工序点
     * @param list
     * @param startTim
     * @param endTim
     * @return
     */
    public CoreReturnObject doQuery(String sortCode) {

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

    /**
     * 保存精整作业实绩
     * @param result 精整作业实绩
     * @return
     */
    public CoreReturnObject saveFinishingResult(
            String resultStr,String resultStr1,String resultStr2,
            String PlanNo, String  hertSqe,
            String Highgx,String QuenchtGx,String Lowgx,
            ArrayList<String> list1Str,  ArrayList<String> list2Str,
            ArrayList<String> list3Str, ArrayList<String> list4Str,
            ArrayList<String> list5Str,  ArrayList<String> list6Str) {
        CoreReturnObject core = new CoreReturnObject();
        Connection connection = this.getDao(CoreConstantData.sysbeanstr)
                .getConnection();
        Date dt = new Date();
        SimpleDateFormat matter1 = new SimpleDateFormat("yyMMdd");
        SimpleDateFormat matter = new SimpleDateFormat("yyyy-MM-dd");

        PreparedStatement psta = null;
        ResultSet rs1 =null;

        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("FinishingService.AddHlstraightenResult");// 新增热矫实绩
            PreparedStatement patAdd = connection.prepareStatement(sqlAdd);
            String sqlAddD = CoreXmlSqlParsersFactory
                    .getSql("FinishingService.AddClstraightenResult");// 新增冷矫记录
            PreparedStatement patAddD = connection.prepareStatement(sqlAddD);
            String sqlAddS = CoreXmlSqlParsersFactory
                    .getSql("FinishingService.AddSizingResult");// 新增定径记录
            PreparedStatement patAddS = connection.prepareStatement(sqlAddS);
            String addPlnInfo = CoreXmlSqlParsersFactory
                    .getSql("HttLoadingService.AddComInfoResult");// 新增公共信息
            PreparedStatement patsPlan = connection
                    .prepareStatement(addPlnInfo);
            String updatepln = CoreXmlSqlParsersFactory
                    .getSql("AppearanceService.updatePlnZyRclM");// 新增时修改计划表
            PreparedStatement patsupdatepln = connection
                    .prepareStatement(updatepln);

            String updatePath = CoreXmlSqlParsersFactory
                    .getSql("FinishingService.UpdatePath");// 修改队列表工艺路径
            PreparedStatement pastupdatePath = connection
                    .prepareStatement(updatePath);
            String updatePath1 = CoreXmlSqlParsersFactory
                    .getSql("FinishingService.UpdatePath1");// 修改队列表工艺路径
            PreparedStatement pastupdatePath1 = connection
                    .prepareStatement(updatePath1);
            String updatePath2 = CoreXmlSqlParsersFactory
                    .getSql("FinishingService.UpdatePath2");// 修改队列表工艺路径
            PreparedStatement pastupdatePath2 = connection
                    .prepareStatement(updatePath2);
            // 获取热处理计划实体了
            PlnZyRclMEntity pln = PlanService.getSendHttPlanCInfo(connection,
                    PlanNo);


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


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

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

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

            int ProNum = 0;
            int FailNum = 0;

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

            }

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


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


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

            }

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


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


            int ProNum2 = 0;
            int FailNum2 = 0;

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

            }

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


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

            //region 定径


            if(ProNum>0 && result.getProcessSeq().equals(pln.getRealProcessSeq())) {

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

               /* Integer OkCount = 0;

                String sqlCount = CoreXmlSqlParsersFactory.getSql("HeatTreatmentService.getHHeatOKCountByProcessSeq");
                psta = connection.prepareStatement(sqlCount);
                psta.setObject(1, result.getHeatPlanNo());
                psta.setObject(2, result.getProcessSeq());
                psta.setObject(3, Highgx);
                psta.setObject(4, result.getProcessSeq());
                psta.setObject(5, result.getHeatPlanNo());
                psta.setObject(6, result.getProcessSeq());
                rs1 = psta.executeQuery();
                if (rs1.next()) {
                    OkCount = rs1.getInt("COUNT");
                }
                rs1.close();
                psta.close();

                if (OkCount < ProNum) {
                    core.setV_errMsg("作业支数大于剩余合格支数,无法新增！");
                    return core;
                }*/


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

                // 新增定径实绩
                patAddS.setObject(1, resultNo);
                patAddS.setObject(2, result.getZyBatchId());
                //patAddS.setObject(3, pln.getProdIndex());
                patAddS.setObject(3, pln.getProPlanId());
                patAddS.setObject(4, pln.getGxPlanNo());
                patAddS.setObject(5, result.getProNum());
                patAddS.setObject(6, result.getProWt());
                patAddS.setObject(7, "1");
                patAddS.setObject(8, result.getColTime());
                patAddS.setObject(9, result.getColUser());
                patAddS.setObject(10, result.getColShift());
                patAddS.setObject(11, result.getColGroup());
                patAddS.setObject(12, pln.getPlineCode());
                patAddS.setObject(13, pln.getPlineName());
                patAddS.setObject(14, result.getHeatPlanNo());
                patAddS.setObject(15, systime);
                patAddS.setObject(16, result.getFailNum());
                patAddS.setObject(17, resultNo);
                patAddS.setObject(18, result.getProcessSeq());
                patAddS.setObject(19, result.getTemperatureBeforeSizing());
                patAddS.setObject(20, result.getTemperatureAfterSizing());
                patAddS.setObject(21, result.getSizeAfterSizing());
                patAddS.setObject(22, result.getMemo());
                patAddS.addBatch();


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

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


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

            }

            //endregion

            //region 热矫


            if(ProNum1 >0&& result1.getProcessSeq().equals(pln.getRealProcessSeq())) {

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

                /*Integer OkCount = 0;

                String sqlCount = CoreXmlSqlParsersFactory.getSql("FinishingService.querySizMaxResultNo");
                psta = connection.prepareStatement(sqlCount);
                psta.setObject(1, result1.getHeatPlanNo());
                psta.setObject(2, result1.getProcessSeq());
                psta.setObject(3, QuenchtGx);
                psta.setObject(4, result1.getProcessSeq());
                psta.setObject(5, result1.getHeatPlanNo());
                psta.setObject(6, result1.getProcessSeq());
                rs1 = psta.executeQuery();
                if (rs1.next()) {
                    OkCount = rs1.getInt("COUNT");
                }
                rs1.close();
                psta.close();

                if (OkCount < ProNum1) {
                    core.setV_errMsg("作业支数大于剩余合格支数,无法新增！");
                    return core;
                }*/

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

                // 新增热矫实绩
                patAdd.setObject(1, resultNo1);
                patAdd.setObject(2, result1.getZyBatchId());
                //patAdd.setObject(3, pln.getProdIndex());
                patAdd.setObject(3, pln.getProPlanId());
                patAdd.setObject(4, pln.getGxPlanNo());
                patAdd.setObject(5, result1.getRollNum1());
                patAdd.setObject(6, result1.getRollNum2());
                patAdd.setObject(7, result1.getRollNum3());
                patAdd.setObject(8, result1.getBendRate());
                patAdd.setObject(9, result1.getLstraightenTemp());
                patAdd.setObject(10, result1.getProNum());
                patAdd.setObject(11, result1.getProWt());
                patAdd.setObject(12, "1");
                patAdd.setObject(13, result1.getColTime());
                patAdd.setObject(14, result1.getColUser());
                patAdd.setObject(15, result1.getColShift());
                patAdd.setObject(16, result1.getColGroup());
                patAdd.setObject(17, pln.getPlineCode());
                patAdd.setObject(18, pln.getPlineName());
                patAdd.setObject(19, result1.getHeatPlanNo());
                patAdd.setObject(20, systime);
                patAdd.setObject(21, result1.getFailNum());
                patAdd.setObject(22, resultNo1);
                patAdd.setObject(23, result1.getProcessSeq());
                patAdd.setObject(24, result1.getDeflection());
                patAdd.setObject(25, result1.getAngle());
                patAdd.setObject(26, result1.getEndTime());
                patAdd.setObject(27, result1.getPreLstraightenTemp());
                patAdd.setObject(28, result1.getAfterLstraightenTemp());
                patAdd.addBatch();

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

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

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

            }
            //endregion

            //region 低温炉


            if(ProNum2 >0&& result2.getProcessSeq().equals(pln.getRealProcessSeq())) {


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

/*                Integer OkCount = 0;

                String sqlCount = CoreXmlSqlParsersFactory.getSql("FinishingService.getClsOKCountByProcessSeq");// 查询最大高温炉实绩编号
                psta = connection.prepareStatement(sqlCount);
                psta.setObject(1, result2.getHeatPlanNo());
                psta.setObject(2, result2.getProcessSeq());
                psta.setObject(3, Lowgx);
                psta.setObject(4, result2.getProcessSeq());
                psta.setObject(5, result2.getHeatPlanNo());
                psta.setObject(6, result2.getProcessSeq());
                rs1 = psta.executeQuery();
                if (rs1.next()) {
                    OkCount = rs1.getInt("COUNT");
                }
                rs1.close();
                psta.close();

                if (OkCount < ProNum2) {
                    core.setV_errMsg("作业支数大于剩余合格支数,无法新增！");
                    return core;
                }*/


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

                // 新增冷矫实绩
                patAddD.setObject(1, resultNo2);
                patAddD.setObject(2, result2.getZyBatchId());
                //patAddD.setObject(3, pln.getProdIndex());
                patAddD.setObject(3, pln.getProPlanId());
                patAddD.setObject(4, pln.getGxPlanNo());
                patAddD.setObject(5, result2.getRollNum1());
                patAddD.setObject(6, result2.getRollNum2());
                patAddD.setObject(7, result2.getRollNum3());
                patAddD.setObject(8, result2.getBendRate());
                patAddD.setObject(9, result2.getLstraightenTemp());
                patAddD.setObject(10, result2.getProNum());
                patAddD.setObject(11, result2.getProWt());
                patAddD.setObject(12, "1");
                patAddD.setObject(13, result2.getColTime());
                patAddD.setObject(14, result2.getColUser());
                patAddD.setObject(15, result2.getColShift());
                patAddD.setObject(16, result2.getColGroup());
                patAddD.setObject(17, pln.getPlineCode());
                patAddD.setObject(18, pln.getPlineName());
                patAddD.setObject(19, result2.getHeatPlanNo());
                patAddD.setObject(20, systime);
                patAddD.setObject(21, result2.getFailNum());
                patAddD.setObject(22, resultNo2);
                patAddD.setObject(23, result2.getProcessSeq());
                patAddD.addBatch();


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


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

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

            //endregion

            patAdd.executeBatch();
            patAddS.executeBatch();
            patAddD.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 result 精整作业实绩
     * @return
     */
    public CoreReturnObject updateFinishingResult(
            String resultStr,String PlanNo, String  hertSqe,
            String SizGx,String HlsGx,String ClsGx, ArrayList<String> list3Str,ArrayList<String> list4Str,
            String updateCount ) {
        CoreReturnObject core = new CoreReturnObject();
        Connection connection = this.getDao(CoreConstantData.sysbeanstr)
                .getConnection();
        Date now = new Date();
        PreparedStatement psta = null;
        ResultSet rs1 =null;
        SimpleDateFormat dateFormat = new SimpleDateFormat(
                "yyyy-MM-dd HH:mm:ss", Locale.CHINA);
        String systime = dateFormat.format(now);
        try {
            connection.setAutoCommit(false); // 取消自动提交事务
            String sqlUpdate = CoreXmlSqlParsersFactory
                    .getSql("FinishingService.updateHlstraightenResult");// 修改热矫实绩
            PreparedStatement patUpdate = connection
                    .prepareStatement(sqlUpdate);
            String sqlUpdateD = CoreXmlSqlParsersFactory
                    .getSql("FinishingService.updateClstraightenResult");// 修改冷矫记录
            PreparedStatement patUpdateD = connection
                    .prepareStatement(sqlUpdateD);
            String sqlUpdateS = CoreXmlSqlParsersFactory
                    .getSql("FinishingService.updateSizingResult");// 修改定径记录
            PreparedStatement patUpdateS = connection
                    .prepareStatement(sqlUpdateS);
            String addPlnInfo = CoreXmlSqlParsersFactory
                    .getSql("HttLoadingService.updateComInfoResult");// 修改公共信息
            PreparedStatement patsupdatePlan = connection
                    .prepareStatement(addPlnInfo);


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


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

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

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

            if (updateCount.equals("1")) {

                //region 定径
                HttSizingResultEntity result =  EntityTool.getEntityByJSONStr(resultStr,HttSizingResultEntity.class);

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


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

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

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

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

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

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

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

                }

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


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

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

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

                // 修改定径实绩
                patUpdateS.setObject(1, result.getProNum());
                patUpdateS.setObject(2, result.getProWt());
                patUpdateS.setObject(3, result.getColTime());
                patUpdateS.setObject(4, result.getColShift());
                patUpdateS.setObject(5, result.getColGroup());
                patUpdateS.setObject(6, systime);
                patUpdateS.setObject(7, result.getColUser());
                patUpdateS.setObject(8, result.getResultNo());
                patUpdateS.addBatch();

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

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


                //endregion

            }
            else if (updateCount.equals("2")) {

                //region 热矫
                HttHlstraightenResultEntity result1 =  EntityTool.getEntityByJSONStr(resultStr,HttHlstraightenResultEntity.class);

                String Sql=CoreXmlSqlParsersFactory
                        .getSql("FinishingService.GetHighResult");
                Sql += " WHERE RESULT_NO = '" + result1.getResultNo() + "'";
                HttHlstraightenResultEntity result1Old =  EntityTool.getEntityBySqlNoClsCon(Sql,connection,HttHlstraightenResultEntity.class);

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

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


                int ProNum = 0;
                int FailNum =0;

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

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

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

                }

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

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


                // 修改热矫实绩
                patUpdate.setObject(1, result1.getRollNum1());
                patUpdate.setObject(2, result1.getRollNum2());
                patUpdate.setObject(3, result1.getRollNum3());
                patUpdate.setObject(4, result1.getBendRate());
                patUpdate.setObject(5, result1.getLstraightenTemp());
                patUpdate.setObject(6, result1.getProNum());
                patUpdate.setObject(7, result1.getProWt());
                patUpdate.setObject(8, result1.getColTime());
                patUpdate.setObject(9, result1.getColShift());
                patUpdate.setObject(10, result1.getColGroup());
                patUpdate.setObject(11, systime);
                patUpdate.setObject(12, result1.getColUser());
                patUpdate.setObject(13, result1.getResultNo());
                patUpdate.addBatch();

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

                patUpdate.executeBatch();
                patsupdatePlan.executeBatch();

                //endregion



            }

            // 冷矫
            else if (updateCount.equals("3")) {

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

                String Sql = CoreXmlSqlParsersFactory.getSql("FinishingService.GetClsResult");
                Sql += " WHERE RESULT_NO = '" + result2.getResultNo() + "'";
                HttClstraightenResultEntity result2Old = EntityTool.getEntityBySqlNoClsCon(Sql, connection, HttClstraightenResultEntity.class);

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

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

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

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

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

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

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

                }

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


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

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

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


                // 修改冷矫实绩
                patUpdateD.setObject(1, result2.getRollNum1());
                patUpdateD.setObject(2, result2.getRollNum2());
                patUpdateD.setObject(3, result2.getRollNum3());
                patUpdateD.setObject(4, result2.getBendRate());
                patUpdateD.setObject(5, result2.getLstraightenTemp());
                patUpdateD.setObject(6, result2.getProNum());
                patUpdateD.setObject(7, result2.getProWt());
                patUpdateD.setObject(8, result2.getColTime());
                patUpdateD.setObject(9, result2.getColShift());
                patUpdateD.setObject(10, result2.getColGroup());
                patUpdateD.setObject(11, systime);
                patUpdateD.setObject(12, result2.getColUser());
                patUpdateD.setObject(13, result2.getResultNo());
                patUpdateD.addBatch();

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




                patUpdateD.executeBatch();
                patsupdatePlan.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 result 精整作业实绩
     * @return
     */
    public CoreReturnObject deleteFinishingResult(
            String updateCount,
            String heratNo,String rentNo,String rentNo1,String rentNo2,
            String SizGx,String HlsGx,String ClsGx) {
        CoreReturnObject core = new CoreReturnObject();
        Connection connection = this.getDao(CoreConstantData.sysbeanstr)
                .getConnection();
        Date now = new Date();
        PreparedStatement psta = null;
        ResultSet rs1 =null;
        SimpleDateFormat dateFormat = new SimpleDateFormat(
                "yyyy-MM-dd HH:mm:ss", Locale.CHINA);
        String systime = dateFormat.format(now);
        try {
            connection.setAutoCommit(false); // 取消自动提交事务
            String sqlUpdate = CoreXmlSqlParsersFactory
                    .getSql("FinishingService.deleteHlstraightenResult");// 删除热矫实绩
            PreparedStatement patUpdate = connection
                    .prepareStatement(sqlUpdate);
            String sqlUpdateD = CoreXmlSqlParsersFactory
                    .getSql("FinishingService.deleteClstraightenResult");// 删除冷矫记录
            PreparedStatement patUpdateD = connection
                    .prepareStatement(sqlUpdateD);
            String sqlUpdateS = CoreXmlSqlParsersFactory
                    .getSql("FinishingService.deleteSizingResult");// 删除定径记录
            PreparedStatement patUpdateS = connection
                    .prepareStatement(sqlUpdateS);
            String addPlnInfo = CoreXmlSqlParsersFactory
                    .getSql("HttLoadingService.deleteComInfoResult");// 删除公共信息
            PreparedStatement patsupdatePlan = connection
                    .prepareStatement(addPlnInfo);

            String updatePath = CoreXmlSqlParsersFactory
                    .getSql("FinishingService.UpdatePath");// 修改队列表工艺路径
            PreparedStatement pastupdatePath = connection
                    .prepareStatement(updatePath);
            String updatePath1 = CoreXmlSqlParsersFactory
                    .getSql("FinishingService.UpdatePath1");// 修改队列表工艺路径
            PreparedStatement pastupdatePath1 = connection
                    .prepareStatement(updatePath1);
            String updatePath2 = CoreXmlSqlParsersFactory
                    .getSql("FinishingService.UpdatePath2");// 修改队列表工艺路径
            PreparedStatement pastupdatePath2 = connection
                    .prepareStatement(updatePath2);

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

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

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

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


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


                String Sql=CoreXmlSqlParsersFactory
                        .getSql("FinishingService.GetSizeResult");
                Sql += " WHERE RESULT_NO = '" + rentNo + "'";
                HttHheatResultEntity result =  EntityTool.getEntityBySqlNoClsCon(Sql,connection,HttHheatResultEntity.class);

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

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


                int detCount =0;

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

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

                    FrmHttBugD.DeleteHttWaste(connection, heratNo, rentNo, pln.getPlineCode(), result.getProcessSeq(), SizGx, detCount);

                    // 删除定径实绩
                    patUpdateS.setObject(1, rentNo);
                    patUpdateS.addBatch();

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

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

                    // 修改工艺路径
                    pastupdatePath.setObject(1, "0");
                    pastupdatePath.setObject(2, heratNo);
                    pastupdatePath.addBatch();
                    pastupdatePath.executeBatch();
                    String updatepln = CoreXmlSqlParsersFactory.getSql("AppearanceService.updatePlnZyRclM");// 删除时修改计划表
                    PreparedStatement patsupdatepln = connection.prepareStatement(updatepln);
                    // 修改计划表
                    patsupdatepln.setObject(1, "30");
                    patsupdatepln.setObject(2, heratNo);
                    patsupdatepln.addBatch();
                    patsupdatepln.executeBatch();
                }else{
                    core.setV_errMsg("该记录是上次热处理的实绩,无法删除！");
                    return core;
                }
            }
            // 热矫
            if (!rentNo1.equals("")) {
                String Sql=CoreXmlSqlParsersFactory
                        .getSql("FinishingService.GetHighResult");
                Sql += " WHERE RESULT_NO = '" + rentNo1 + "'";
                HttHheatResultEntity result =  EntityTool.getEntityBySqlNoClsCon(Sql,connection,HttHheatResultEntity.class);

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

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

                int detCount =0;

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

                if(result.getProcessSeq().equals(pln.getRealProcessSeq())) {
                    FrmHttBugD.DeleteHttWaste(connection, heratNo, rentNo1, pln.getPlineCode(), result.getProcessSeq(), HlsGx, detCount);

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

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


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

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


                     String Sql = CoreXmlSqlParsersFactory.getSql("FinishingService.GetClsResult");
                     Sql += " WHERE RESULT_NO = '" + rentNo2 + "'";
                     HttHheatResultEntity result = EntityTool.getEntityBySqlNoClsCon(Sql, connection, HttHheatResultEntity.class);

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

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

                     int detCount = 0;

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

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

                     FrmHttBugD.DeleteHttWaste(connection, heratNo, rentNo2, pln.getPlineCode(), result.getProcessSeq(), ClsGx, detCount);

                     // 删除冷矫实绩
                     patUpdateD.setObject(1, rentNo2);
                     patUpdateD.addBatch();

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

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

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


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

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

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

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


            if(!pln.getBesideStatus().equals("10") &&!pln.getBesideStatus().equals("20") && !pln.getBesideStatus().equals("30")    ) {

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


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

            }


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

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

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

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


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

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

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

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


//            }
            updateSqlPsta.executeBatch();
            updatePlnPsta.executeBatch();

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

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

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


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

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

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


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


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


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

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


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


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

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


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

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



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

            }

            rs.close();
            psta.close();


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

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



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



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




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

            psAllFailUpdatePlanStatus.setString(1, parm.get(0));
            psAllFailUpdatePlanStatus.addBatch();
            psAllFailUpdatePlanStatus.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 load
     * @return
     */
    public CoreReturnObject offLineExpandResult1(ArrayList<HttOfflineResultDentity> list1,HttSizingResultEntity load,
            ArrayList<String> list, String plinCode, String storageNo,String groudno) {
        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("AppearanceService.AddOffLine");// 新增离线实绩
            PreparedStatement patAdd = connection.prepareStatement(addOff);
            String addOffD = CoreXmlSqlParsersFactory
                    .getSql("AppearanceService.AddOffLineD");// 新增离线实绩从表
            PreparedStatement patAddD = connection.prepareStatement(addOffD);

            String updateMat = CoreXmlSqlParsersFactory
                    .getSql("AppearanceService.UpdateMatNo");// 修改材料状态
            PreparedStatement patMatNo = connection.prepareStatement(updateMat);

            String updatePath = CoreXmlSqlParsersFactory
                    .getSql("AppearanceService.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);

            int num = 0;
            int num1 = 0;
            int num2 = 0;
                if (slgx.equals("600202")) {
                    num = 1;
                    num1 = 2;
                    num2 = 4;
                }
                else if (slgx.equals("600203")) {
                    num = 1;
                    num1 = 4;
                    num2 = 6;
                }
                else if (slgx.equals("600204")) {
                    num = 1;
                    num1 = 6;
                    num2 = 8;
                }
                else if (slgx.equals("600205")) {
                    num = 1;
                    num1 = 8;
                    num2 = 10;
                }
                else if (slgx.equals("600206")) {
                    num = 1;
                    num1 = 10;
                    num2 = 12;
                }
                else if (slgx.equals("600207")) {
                    num = 1;
                    num1 = 12;
                    num2 = 14;
                }
                else if (slgx.equals("600208")) {
                    num = 1;
                    num1 = 16;
                    num2 = 18;
                }
                else if (slgx.equals("600209")) {
                    num = 1;
                    num1 = 18;
                    num2 = 20;
                }
                else if (slgx.equals("600210")) {
                    num = 1;
                    num1 = 20;
                    num2 = 22;
                }
                else if (slgx.equals("600211")) {
                    num = 1;
                    num1 = 22;
                    num2 = 24;
                }
         
            // 获取墩拔扩计划实体类
                PlnZyRclMEntity pln = PlanService.getSendHttPlanCInfo(connection,
                    heatPlanNo);
             // 获取墩拔扩计划从表实体类
                PlnZyRclCEntity plnC = PlanService.getSendHttPlanCInfoC(connection,
                    heatPlanNo);
            if (pln == null)
                return core;
            String cutFalg = "";
            String sql = CoreXmlSqlParsersFactory
                    .getSql("AppearanceService.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<PortHttBatchSampleResultEntity> matNo = new ArrayList<PortHttBatchSampleResultEntity>();
            String sqlloading1 = CoreXmlSqlParsersFactory
                    .getSql("AppearanceService.queryPortVrpHg");// 查询管号队列里合格的材料号
            psta = connection.prepareStatement(sqlloading1);
            psta.setObject(1, heatPlanNo);
            psta.setObject(2, groudno);
            psta.setObject(3, Integer.parseInt(count) + 1);
            ResultSet rs2 = psta.executeQuery();
            matNo = EntityTool.getEntitysByRs(rs2,
            		PortHttBatchSampleResultEntity.class);
            rs2.close();
            psta.close();
            if (matNo == null) {
                core.setV_errMsg("管号队列全为样管，不能离线！");
                return core;
            }
            int batchCount = 0;
            sqlloading1 = CoreXmlSqlParsersFactory
                    .getSql("AppearanceService.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 judge = "";
            String batch = "";
            String procode = "";
            String proname = "";
            String stecode = "";
            String stename = "";
            String gracode = "";
            String graname = "";
            String modecode = "";
            String modedesc = "";
            String stdcode = "";
            String stdname = "";
            String stdstyle = "";
            String stdstyledesc = "";
            String actdimater = "";
            String actheight = "";
            String actlen = "";
            String actlenmin = "";
            String actlenmax = "";

            int countNum = 0;
            double weightNum = 0;
            for (PortHttBatchSampleResultEntity 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, heatPlanNo);
                pastupdatePath.setObject(9, prot.getMatNo());
                pastupdatePath.addBatch();


                // 修改材料表状态
                patMatNo.setObject(1, "80150104");
                //patMatNo.setObject(2, "11");
                patMatNo.setObject(2, prot.getMatNo());
                patMatNo.addBatch();
//                List<MatZcMEntity> listMat = new ArrayList<MatZcMEntity>();
//				listMat = EntityTool.getEntitysByRs(rs, MatZcMEntity.class);
//				for (MatZcMEntity lvMat : listMat) {
//                // 新增入库表数据
//                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);
////                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(60, lvMat.getOrdPk());// 合同pK
//				patIn.setObject(61, lvMat.getOrdLnPk());
//                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();

            String ifMonitNo = "";
            if (pln.getIfMonitor().equals("是")) {
                ifMonitNo = "1";
            }
            else {
                ifMonitNo = "0";
            }
            String resultNo = "";
            String sqlloading = CoreXmlSqlParsersFactory
                    .getSql("AppearanceService.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());
            ResultSet rs1 = psta.executeQuery();
            if (rs1.next()) {
                resultNo = rs1.getString("RESULT_NO");
            }
            rs1.close();
            psta.close();
            for (PortHttBatchSampleResultEntity lvMat : matNo) {
            // 新增离线实绩
            patAdd.setObject(1, resultNo);
            patAdd.setObject(2, pln.getPlineCode());
            patAdd.setObject(3, pln.getPlineName());
            patAdd.setObject(4, slgx);
            patAdd.setObject(5, slgx);
            patAdd.setObject(6, heatPlanNo);           
            patAdd.setObject(7, pln.getZyBatchId());
            patAdd.setObject(8, "");
            patAdd.setObject(9, pln.getProPlanId());
            patAdd.setObject(10, pln.getGxPlanNo());

            patAdd.setObject(11, judge);
            patAdd.setObject(12, batch);
            patAdd.setObject(13, groudno);
            patAdd.setObject(14, pln.getProduccode());
            patAdd.setObject(15, pln.getProducname());
            patAdd.setObject(16, pln.getSteelcode());
            patAdd.setObject(17, pln.getSteelname());
            patAdd.setObject(18, pln.getGradecode());
            patAdd.setObject(19, pln.getGradename());
            patAdd.setObject(20, pln.getModelCode());
            patAdd.setObject(21, pln.getModelDesc());
            patAdd.setObject(22, pln.getStdCode());
            patAdd.setObject(23, pln.getStdName());
            patAdd.setObject(24, pln.getStdStyle());
            patAdd.setObject(25, pln.getStdStyleDesc());
            patAdd.setObject(26, actdimater);
            patAdd.setObject(27, actheight);
            patAdd.setObject(28, actlen);
            patAdd.setObject(29, actlenmin);
            patAdd.setObject(30, actlenmax);
            patAdd.setObject(31, pln.getOrdLnDlyPk());
            patAdd.setObject(32, pln.getOrderNo());
            patAdd.setObject(33, pln.getOrderSeq());
            patAdd.setObject(34, pln.getDeliveryNo());
            patAdd.setObject(35, countNum);
            patAdd.setObject(36, weightNum);
            patAdd.setObject(37, name);
            patAdd.setObject(38, bc);
            patAdd.setObject(39, bz);
            patAdd.setObject(40, time);
                patAdd.setObject(41,"1");
                patAdd.setObject(42, pln.getFeedHeatNo());
            // 如果有离线新增到材料表
         			if (!count.equals("") && !count.equals("0")) {
                        PlanService.AddOffLineMat(connection,"F",load.getColUser(),"11",
                                lvMat.getMatNo(),slgx, heatPlanNo);
         				}
            }
            // 新增离线从表
            for (int i = 0; i < list1.size(); i++) {
                String resultsqe = "";
                sqlloading = CoreXmlSqlParsersFactory
                        .getSql("AppearanceService.querymaxsqe");// 查询从表最大序号 
                psta = connection.prepareStatement(sqlloading);
                psta.setObject(1, matter1.format(now));
                psta.setObject(2, heatPlanNo);
                psta.setObject(3, plinCode);
                ResultSet rs3 = psta.executeQuery();
                if (rs3.next()) {
                    resultsqe = rs3.getString("RESULT_SQE");
                }
            
                rs3.close();
                psta.close();
                HttOfflineResultDentity resultD = list1.get(i);
                patAddD.setObject(1, resultNo);
                patAddD.setObject(2, resultsqe);
                patAddD.setObject(3, heatPlanNo);
                patAddD.setObject(4, plinCode);
                patAddD.setObject(5, pln.getPlineName());
                patAddD.setObject(6, count);	          
                patAddD.setObject(7, resultD.getGowhereCode());
                patAddD.setObject(8, resultD.getGowhereName());
                patAddD.setObject(9, time);
                patAddD.setObject(10, slgx);
                patAddD.setObject(11, slgx);
                patAddD.addBatch();
                patAddD.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 load
     * @return
     */
    public CoreReturnObject offLineExpandResult2(ArrayList<HttOfflineResultDentity> list1,HttHlstraightenResultEntity load,
            ArrayList<String> list, String plinCode, String storageNo,String groudno) {
        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("AppearanceService.AddOffLine");// 新增离线实绩
            PreparedStatement patAdd = connection.prepareStatement(addOff);
            String addOffD = CoreXmlSqlParsersFactory
                    .getSql("AppearanceService.AddOffLineD");// 新增离线实绩从表
            PreparedStatement patAddD = connection.prepareStatement(addOffD);

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

            String updatePath = CoreXmlSqlParsersFactory
                    .getSql("AppearanceService.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);

            int num = 0;
            int num1 = 0;
            int num2 = 0;
                if (slgx.equals("600202")) {
                    num = 1;
                    num1 = 2;
                    num2 = 4;
                }
                else if (slgx.equals("600203")) {
                    num = 1;
                    num1 = 4;
                    num2 = 6;
                }
                else if (slgx.equals("600204")) {
                    num = 1;
                    num1 = 6;
                    num2 = 8;
                }
                else if (slgx.equals("600205")) {
                    num = 1;
                    num1 = 8;
                    num2 = 10;
                }
                else if (slgx.equals("600206")) {
                    num = 1;
                    num1 = 10;
                    num2 = 12;
                }
                else if (slgx.equals("600207")) {
                    num = 1;
                    num1 = 12;
                    num2 = 14;
                }
                else if (slgx.equals("600208")) {
                    num = 1;
                    num1 = 16;
                    num2 = 18;
                }
                else if (slgx.equals("600209")) {
                    num = 1;
                    num1 = 18;
                    num2 = 20;
                }
                else if (slgx.equals("600210")) {
                    num = 1;
                    num1 = 20;
                    num2 = 22;
                }
                else if (slgx.equals("600211")) {
                    num = 1;
                    num1 = 22;
                    num2 = 24;
                }
         
            // 获取墩拔扩计划实体类
                PlnZyRclMEntity pln = PlanService.getSendHttPlanCInfo(connection,
                    heatPlanNo);
             // 获取墩拔扩计划从表实体类
                PlnZyRclCEntity plnC = PlanService.getSendHttPlanCInfoC(connection,
                    heatPlanNo);
            if (pln == null)
                return core;
            // if (!pln.getPlanstatus().equals("2")) {
            // core.setV_errMsg("该计划不是生产中的，请确认是否生产完成或未上料！");
            // return core;
            // }
            String cutFalg = "";
            String sql = CoreXmlSqlParsersFactory
                    .getSql("AppearanceService.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<PortHttBatchSampleResultEntity> matNo = new ArrayList<PortHttBatchSampleResultEntity>();
            String sqlloading1 = CoreXmlSqlParsersFactory
                    .getSql("AppearanceService.queryPortVrpHg");// 查询管号队列里合格的材料号
            psta = connection.prepareStatement(sqlloading1);
            psta.setObject(1, heatPlanNo);
            psta.setObject(2, groudno);
            psta.setObject(3, Integer.parseInt(count) + 1);
            ResultSet rs2 = psta.executeQuery();
            matNo = EntityTool.getEntitysByRs(rs2,
            		PortHttBatchSampleResultEntity.class);
            rs2.close();
            psta.close();
            if (matNo == null) {
                core.setV_errMsg("管号队列全为样管，不能离线！");
                return core;
            }
            int batchCount = 0;
            sqlloading1 = CoreXmlSqlParsersFactory
                    .getSql("AppearanceService.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()));


            psta.close();
            String judge = "";
            String batch = "";
            String procode = "";
            String proname = "";
            String stecode = "";
            String stename = "";
            String gracode = "";
            String graname = "";
            String modecode = "";
            String modedesc = "";
            String stdcode = "";
            String stdname = "";
            String stdstyle = "";
            String stdstyledesc = "";
            String actdimater = "";
            String actheight = "";
            String actlen = "";
            String actlenmin = "";
            String actlenmax = "";

            int countNum = 0;
            double weightNum = 0;
            for (PortHttBatchSampleResultEntity 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, heatPlanNo);
                pastupdatePath.setObject(9, prot.getMatNo());
                pastupdatePath.addBatch();

                // 修改材料表状态
                patMatNo.setObject(1, "80150104");
                //patMatNo.setObject(2, "11");
                patMatNo.setObject(2, prot.getMatNo());
                patMatNo.addBatch();
//                List<MatZcMEntity> listMat = new ArrayList<MatZcMEntity>();
//				listMat = EntityTool.getEntitysByRs(rs, MatZcMEntity.class);
//				for (MatZcMEntity lvMat : listMat) {
//                // 新增入库表数据
//                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);
////                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(60, lvMat.getOrdPk());// 合同pK
//				patIn.setObject(61, lvMat.getOrdLnPk());
//                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();
            //patIn.executeBatch();
            patMatNo.executeBatch();

            String ifMonitNo = "";
            if (pln.getIfMonitor().equals("是")) {
                ifMonitNo = "1";
            }
            else {
                ifMonitNo = "0";
            }
            String resultNo = "";
            String sqlloading = CoreXmlSqlParsersFactory
                    .getSql("AppearanceService.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());
            ResultSet rs1 = psta.executeQuery();
            if (rs1.next()) {
                resultNo = rs1.getString("RESULT_NO");
            }
            rs1.close();
            psta.close();
            // 新增离线实绩
            for (PortHttBatchSampleResultEntity lvMat : matNo) {
            patAdd.setObject(1, resultNo);
            patAdd.setObject(2, pln.getPlineCode());
            patAdd.setObject(3, pln.getPlineName());
            patAdd.setObject(4, slgx);
            patAdd.setObject(5, slgx);
            patAdd.setObject(6, heatPlanNo);           
            patAdd.setObject(7, pln.getZyBatchId());
            patAdd.setObject(8, pln.getIndexSeq());
            patAdd.setObject(9, pln.getProPlanId());
            patAdd.setObject(10, pln.getGxPlanNo());

            patAdd.setObject(11, judge);
            patAdd.setObject(12, batch);
            patAdd.setObject(13, groudno);
            patAdd.setObject(14, pln.getProduccode());
            patAdd.setObject(15, pln.getProducname());
            patAdd.setObject(16, pln.getSteelcode());
            patAdd.setObject(17, pln.getSteelname());
            patAdd.setObject(18, pln.getGradecode());
            patAdd.setObject(19, pln.getGradename());
            patAdd.setObject(20, pln.getModelCode());
            patAdd.setObject(21, pln.getModelDesc());
            patAdd.setObject(22, pln.getStdCode());
            patAdd.setObject(23, pln.getStdName());
            patAdd.setObject(24, pln.getStdStyle());
            patAdd.setObject(25, pln.getStdStyleDesc());
            patAdd.setObject(26, actdimater);
            patAdd.setObject(27, actheight);
            patAdd.setObject(28, actlen);
            patAdd.setObject(29, actlenmin);
            patAdd.setObject(30, actlenmax);
            patAdd.setObject(31, pln.getOrdLnDlyPk());
            patAdd.setObject(32, pln.getOrderNo());
            patAdd.setObject(33, pln.getOrderSeq());
            patAdd.setObject(34, pln.getDeliveryNo());
            patAdd.setObject(35, countNum);
            patAdd.setObject(36, weightNum);
            patAdd.setObject(37, name);
            patAdd.setObject(38, bc);
            patAdd.setObject(39, bz);
            patAdd.setObject(40, time);
                patAdd.setObject(41,"1");
                patAdd.setObject(42, pln.getFeedHeatNo());
            // 如果有离线新增到材料表
 			if (!count.equals("") && !count.equals("0")) {
                PlanService.AddOffLineMat(connection,"F",load.getColUser(),"11",
                        lvMat.getMatNo(),slgx, heatPlanNo);
 				}
            }
            // 新增离线从表
            for (int i = 0; i < list1.size(); i++) {
                String resultsqe = "";
                sqlloading = CoreXmlSqlParsersFactory
                        .getSql("AppearanceService.querymaxsqe");// 查询从表最大序号 
                psta = connection.prepareStatement(sqlloading);
                psta.setObject(1, matter1.format(now));
                psta.setObject(2, heatPlanNo);
                psta.setObject(3, plinCode);
                ResultSet rs3 = psta.executeQuery();
                if (rs3.next()) {
                    resultsqe = rs3.getString("RESULT_SQE");
                }
            
                rs3.close();
                psta.close();
                HttOfflineResultDentity resultD = list1.get(i);
                patAddD.setObject(1, resultNo);
                patAddD.setObject(2, resultsqe);
                patAddD.setObject(3, heatPlanNo);
                patAddD.setObject(4, plinCode);
                patAddD.setObject(5, pln.getPlineName());
                patAddD.setObject(6, count);	          
                patAddD.setObject(7, resultD.getGowhereCode());
                patAddD.setObject(8, resultD.getGowhereName());
                patAddD.setObject(9, time);
                patAddD.setObject(10, slgx);
                patAddD.setObject(11, slgx);
                patAddD.addBatch();
                patAddD.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 load
     * @return
     */
    public CoreReturnObject offLineExpandResult3(ArrayList<HttOfflineResultDentity> list1,HttClstraightenResultEntity load,
            ArrayList<String> list, String plinCode, String storageNo,String groudno) {
        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("AppearanceService.AddOffLine");// 新增离线实绩
            PreparedStatement patAdd = connection.prepareStatement(addOff);
            String addOffD = CoreXmlSqlParsersFactory
                    .getSql("AppearanceService.AddOffLineD");// 新增离线实绩从表
            PreparedStatement patAddD = connection.prepareStatement(addOffD);

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

            String updatePath = CoreXmlSqlParsersFactory
                    .getSql("AppearanceService.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);

            int num = 0;
            int num1 = 0;
            int num2 = 0;
                if (slgx.equals("600202")) {
                    num = 1;
                    num1 = 2;
                    num2 = 4;
                }
                else if (slgx.equals("600203")) {
                    num = 1;
                    num1 = 4;
                    num2 = 6;
                }
                else if (slgx.equals("600204")) {
                    num = 1;
                    num1 = 6;
                    num2 = 8;
                }
                else if (slgx.equals("600205")) {
                    num = 1;
                    num1 = 8;
                    num2 = 10;
                }
                else if (slgx.equals("600206")) {
                    num = 1;
                    num1 = 10;
                    num2 = 12;
                }
                else if (slgx.equals("600207")) {
                    num = 1;
                    num1 = 12;
                    num2 = 14;
                }
                else if (slgx.equals("600208")) {
                    num = 1;
                    num1 = 16;
                    num2 = 18;
                }
                else if (slgx.equals("600209")) {
                    num = 1;
                    num1 = 18;
                    num2 = 20;
                }
                else if (slgx.equals("600210")) {
                    num = 1;
                    num1 = 20;
                    num2 = 22;
                }
                else if (slgx.equals("600211")) {
                    num = 1;
                    num1 = 22;
                    num2 = 24;
                }
         
            // 获取墩拔扩计划实体类
                PlnZyRclMEntity pln = PlanService.getSendHttPlanCInfo(connection,
                    heatPlanNo);
                // 获取墩拔扩计划从表实体类
                PlnZyRclCEntity plnC = PlanService.getSendHttPlanCInfoC(connection,
                    heatPlanNo);
            if (pln == null)
                return core;
            String cutFalg = "";
            String sql = CoreXmlSqlParsersFactory
                    .getSql("AppearanceService.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<PortHttBatchSampleResultEntity> matNo = new ArrayList<PortHttBatchSampleResultEntity>();
            String sqlloading1 = CoreXmlSqlParsersFactory
                    .getSql("AppearanceService.queryPortVrpHg");// 查询管号队列里合格的材料号
            psta = connection.prepareStatement(sqlloading1);
            psta.setObject(1, heatPlanNo);
            psta.setObject(2, Integer.parseInt(count) + 1);
            ResultSet rs2 = psta.executeQuery();
            matNo = EntityTool.getEntitysByRs(rs2,
            		PortHttBatchSampleResultEntity.class);
            rs2.close();
            psta.close();
            if (matNo == null) {
                core.setV_errMsg("管号队列全为样管，不能离线！");
                return core;
            }
            int batchCount = 0;
            sqlloading1 = CoreXmlSqlParsersFactory
                    .getSql("AppearanceService.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 storageAtte = "";
            String storageAtteName = "";
            String storageType = "";
            String storageTypeName = "";
            String managNo = "";
            String managName = "";
            String depNo = "";
            String depName = "";
            String sqlloading = CoreXmlSqlParsersFactory
                    .getSql("AppearanceService.queryStorageType");
            psta = connection.prepareStatement(sqlloading);
            psta.setObject(1, storageNo);
            rs = psta.executeQuery();
            if (rs.next()) {
                storageAtte = rs.getString("STORAGE_ATTR");
                storageAtteName = rs.getString("STORAGE_ATTR_NAME");
                storageType = rs.getString("STORAGE_TYPE_NO");
                storageTypeName = rs.getString("STORAGE_TYPE_NAME");
                managNo = rs.getString("MANAGEMENT_NO");
                managName = rs.getString("MANAGEMENT_NAME");
                depNo = rs.getString("DEPARTMENT_CODE");
                depName = rs.getString("DEPARTMENT_DESC");
            }
            rs.close();
            psta.close();
            String judge = "";
            String batch = "";
            String procode = "";
            String proname = "";
            String stecode = "";
            String stename = "";
            String gracode = "";
            String graname = "";
            String modecode = "";
            String modedesc = "";
            String stdcode = "";
            String stdname = "";
            String stdstyle = "";
            String stdstyledesc = "";
            String actdimater = "";
            String actheight = "";
            String actlen = "";
            String actlenmin = "";
            String actlenmax = "";

            int countNum = 0;
            double weightNum = 0;
            for (PortHttBatchSampleResultEntity 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, heatPlanNo);
                pastupdatePath.setObject(9, prot.getMatNo());
                pastupdatePath.addBatch();


                // 修改材料表状态
                patMatNo.setObject(1, "80150104");
                //patMatNo.setObject(2, "11");
                patMatNo.setObject(2, prot.getMatNo());
                patMatNo.addBatch();
//                List<MatZcMEntity> listMat = new ArrayList<MatZcMEntity>();
//				listMat = EntityTool.getEntitysByRs(rs, MatZcMEntity.class);
//				for (MatZcMEntity lvMat : listMat) {
//                // 新增入库表数据
//                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);
////                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(60, lvMat.getOrdPk());// 合同pK
//				patIn.setObject(61, lvMat.getOrdLnPk());
//                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();

            String ifMonitNo = "";
            if (pln.getIfMonitor().equals("是")) {
                ifMonitNo = "1";
            }
            else {
                ifMonitNo = "0";
            }
            String resultNo = "";
            sqlloading = CoreXmlSqlParsersFactory
                    .getSql("AppearanceService.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());
            ResultSet rs1 = psta.executeQuery();
            if (rs1.next()) {
                resultNo = rs1.getString("RESULT_NO");
            }
            rs1.close();
            psta.close();
            // 新增离线实绩
            for (PortHttBatchSampleResultEntity lvMat : matNo) {
            patAdd.setObject(1, resultNo);
            patAdd.setObject(2, pln.getPlineCode());
            patAdd.setObject(3, pln.getPlineName());
            patAdd.setObject(4, slgx);
            patAdd.setObject(5, slgx);
            patAdd.setObject(6, heatPlanNo);           
            patAdd.setObject(7, pln.getZyBatchId());
            patAdd.setObject(8, pln.getIndexSeq());
            patAdd.setObject(9, pln.getProPlanId());
            patAdd.setObject(10, pln.getGxPlanNo());

            patAdd.setObject(11, judge);
            patAdd.setObject(12, batch);
            patAdd.setObject(13, groudno);
            patAdd.setObject(14, pln.getProduccode());
            patAdd.setObject(15, pln.getProducname());
            patAdd.setObject(16, pln.getSteelcode());
            patAdd.setObject(17, pln.getSteelname());
            patAdd.setObject(18, pln.getGradecode());
            patAdd.setObject(19, pln.getGradename());
            patAdd.setObject(20, pln.getModelCode());
            patAdd.setObject(21, pln.getModelDesc());
            patAdd.setObject(22, pln.getStdCode());
            patAdd.setObject(23, pln.getStdName());
            patAdd.setObject(24, pln.getStdStyle());
            patAdd.setObject(25, pln.getStdStyleDesc());
            patAdd.setObject(26, actdimater);
            patAdd.setObject(27, actheight);
            patAdd.setObject(28, actlen);
            patAdd.setObject(29, actlenmin);
            patAdd.setObject(30, actlenmax);
            patAdd.setObject(31, pln.getOrdLnDlyPk());
            patAdd.setObject(32, pln.getOrderNo());
            patAdd.setObject(33, pln.getOrderSeq());
            patAdd.setObject(34, pln.getDeliveryNo());
            patAdd.setObject(35, countNum);
            patAdd.setObject(36, weightNum);
            patAdd.setObject(37, name);
            patAdd.setObject(38, bc);
            patAdd.setObject(39, bz);
            patAdd.setObject(40, time);
                patAdd.setObject(41,"1");
                patAdd.setObject(42, pln.getFeedHeatNo());
            // 如果有离线新增到材料表
 			if (!count.equals("") && !count.equals("0")) {


                PlanService.AddOffLineMat(connection,"F",load.getColUser(),"11",
                        lvMat.getMatNo(),slgx, heatPlanNo);
 				}
            }

            // 新增离线从表
            for (int i = 0; i < list1.size(); i++) {
                String resultsqe = "";
                sqlloading = CoreXmlSqlParsersFactory
                        .getSql("AppearanceService.querymaxsqe");// 查询从表最大序号 
                psta = connection.prepareStatement(sqlloading);
                psta.setObject(1, matter1.format(now));
                psta.setObject(2, heatPlanNo);
                psta.setObject(3, plinCode);
                ResultSet rs3 = psta.executeQuery();
                if (rs3.next()) {
                    resultsqe = rs3.getString("RESULT_SQE");
                }
            
                rs3.close();
                psta.close();
                HttOfflineResultDentity resultD = list1.get(i);
                patAddD.setObject(1, resultNo);
                patAddD.setObject(2, resultsqe);
                patAddD.setObject(3, heatPlanNo);
                patAddD.setObject(4, plinCode);
                patAddD.setObject(5, pln.getPlineName());
                patAddD.setObject(6, count);	          
                patAddD.setObject(7, resultD.getGowhereCode());
                patAddD.setObject(8, resultD.getGowhereName());
                patAddD.setObject(9, time);
                patAddD.setObject(10, slgx);
                patAddD.setObject(11, slgx);
                patAddD.addBatch();
                patAddD.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("AppearanceService.getInListDoc");
        psta = conn.prepareStatement(sqlLovsqe);
        psta.setString(1, memo);
        psta.setString(2, matter2.format(dt));
        psta.setString(3, matter1.format(dt));
        psta.setString(4, strlist);
        ResultSet rs = psta.executeQuery();
        if (rs.next()) {
            seq = rs.getString("INSTOCK_DOC");
        }
        rs.close();
        psta.close();
        return seq;
    }

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

    
}
