package com.steering.mes.mcp.Mch;

import CoreFS.SA06.CoreReturnObject;
import CoreFS.SA08.CoreXmlSqlParsersFactory;
import CoreFS.SC01.CoreConstantData;
import com.steering.comm.converter.CoreConverter;
import com.steering.comm.converter.EntityTool;
import com.steering.comm.db.DBCommon;
import com.steering.comm.tools.StringTool;
import com.steering.mes.mcp.common.PlanService;
import com.steering.mes.mcp.entity.MchEntity.PlnZyJgxMEntity;
import com.steering.mes.mcp.entity.MchFinalCheckResultDEntity;
import com.steering.mes.mcp.entity.MchFinalCheckResultEntity;
import com.steering.mes.mcp.entity.MchFinalCheckTreatmentEntity;
import com.steering.mes.mcp.entity.PortMchBatchSampleResultEntity;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Locale;

/**
 * Created by 朱少波 on 2019/2/21.
 */
public class FrmFinalCheck  extends DBCommon {

    /**
     *  抽检实绩
     */
    public CoreReturnObject getQueryExpandResult(String heatNo , String BatchNo) {
        return this.getDataBySqlID("FrmFinalCheck.getQueryExpandResult",
                new Object[] { heatNo,BatchNo});
    }

    
    public CoreReturnObject QuerTreatment(String No,String JudgeStove,String[] PlineCodes,String Status, String ResponsibleCode)
    {
    	
      return  QuerTreatment("","",No,JudgeStove,PlineCodes,Status,ResponsibleCode);
    }


    public CoreReturnObject QuerTreatment(
    		String start, String end,
    		String No,String JudgeStove,String[] PlineCodes,String Status, String ResponsibleCode   ){

        String sql = CoreXmlSqlParsersFactory.getSql("frmEntrust.QuerTreatment");

        if (!start.equals("")) {
			sql += " AND T.PRO_TIME >=TO_DATE('" + start
					+ "', 'YYYY-MM-DD HH24:MI:SS')AND T.PRO_TIME <=TO_DATE('"
					+ end + "', 'YYYY-MM-DD HH24:MI:SS') ";
		}
        
        
        if (!No.equals("")) {

            sql +=  " AND T.TREATMENT_NO LIKE '" +No + "%'";
        }



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


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


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

            sql +=  " AND T.APPROVAL_STATUS = '" +Status + "'";
        }

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

            sql +=  " AND T.RESPONSIBLE_CODE = '" +ResponsibleCode + "'";
        }else{
            sql +=  " AND T.RESPONSIBLE_CODE IS NULL ";
        }


        sql += " ORDER BY T.JUDGE_STOVE_NO,T.BATCH_NO, T.RESPONSIBLE_CODE, T.PRO_TIME";

        return this.getData(sql);
    }

    /**
     *  抽检实绩
     */
    public CoreReturnObject getQueryDetail(String ResultNo) {
        return this.getDataBySqlID("FrmFinalCheck.getQueryDetail",
                new Object[] { ResultNo});
    }


    /**
     *  抽检检查管号
     */
    public CoreReturnObject SelectCheckMatNo(String ResultNo,String TreatmentNo) {
        return this.getDataBySqlID("FrmFinalCheck.SelectCheckMatNo",
                new Object[] { ResultNo,TreatmentNo});
    }


    /**
     *  抽检实绩
     */
    public CoreReturnObject getQueryDetail(String ResultNo,String TreatmentCode, String ResponsibleCode) {
        String sql=CoreXmlSqlParsersFactory
                .getSql("FrmFinalCheck.getQueryDetail1");
        if(!ResultNo.equals("")) {
            sql += "AND RESULT_NO = '" + ResultNo + "'";
        }
        if(!TreatmentCode.equals("")) {
            sql += "AND TREATMENT_CODE = '" + TreatmentCode + "'";
        }

        if(!ResponsibleCode.equals("")) {
            sql += "AND RESPONSIBLE_CODE = '" + ResponsibleCode + "'";
        }
        sql+=" ORDER BY MEASURING_SEQ,MAT_NO,POSITION_CODE";
        return this.getData(sql);
    }


    /**
     *  抽检实绩
     */
    public CoreReturnObject getQueryUnPassDetail(String ResultNo) {
        String sql=CoreXmlSqlParsersFactory
                .getSql("FrmFinalCheck.getQueryUnPassDetail");
        if(!ResultNo.equals("")) {
            sql += "AND RESULT_NO = '" + ResultNo + "'";
        }
        sql+=" ORDER BY MEASURING_SEQ,MAT_NO,POSITION_CODE";
        return this.getData(sql);
    }


    /**
     *  抽检实绩
     */
    public CoreReturnObject getQueryUnPassDetail(String ResultNo,String TreatmentNo) {
        String sql=CoreXmlSqlParsersFactory
                .getSql("FrmFinalCheck.getQueryUnPassDetail");
        if(!ResultNo.equals("")) {
            sql += "AND RESULT_NO = '" + ResultNo + "'";
        }
        if(!TreatmentNo.equals("")) {
            sql += "AND TREATMENT_NO = '" + TreatmentNo + "'";
        }
        sql+=" ORDER BY MEASURING_SEQ,MAT_NO,POSITION_CODE";
        return this.getData(sql);
    }

    public CoreReturnObject getQueryDetail(String[] ResultNos) {
        String sql=CoreXmlSqlParsersFactory
                .getSql("FrmFinalCheck.getQueryDetail2");
        if(ResultNos.length<=0){
            sql+= " AND 1<>1";
        }else {
            sql += CoreConverter.toSqlConditionString("T.RESULT_NO", ResultNos);
        }
        sql+=" ORDER BY MEASURING_SEQ,MAT_NO,POSITION_CODE";
        return this.getData(sql);
    }


    public CoreReturnObject getQueryDetailByTreatmentNo(String[] TreatmentNo) {
        String sql=CoreXmlSqlParsersFactory
                .getSql("FrmFinalCheck.getQueryDetail2");
        if(TreatmentNo.length<=0){
            sql+= " AND 1<>1";
        }else {
            sql += CoreConverter.toSqlConditionString("T.TREATMENT_NO", TreatmentNo);
        }
        sql+=" ORDER BY MEASURING_SEQ,MAT_NO,POSITION_CODE";
        return this.getData(sql);
    }

    public CoreReturnObject getQueryTreatment(String[] ResultNos) {
        String sql=CoreXmlSqlParsersFactory
                .getSql("FrmFinalCheck.getQueryTreatment");
        if(ResultNos.length<=0){
            sql+= " AND 1<>1";
        }else {
            sql += PlanService.toSqlConditionString("T.RESULT_NO", ResultNos);
        }
        sql+=" ORDER BY RESULT_NO,RESPONSIBLE_CODE,RESPONSIBLE_CODE";
        return this.getData(sql);
    }


    public CoreReturnObject getFailDetail(String[] TreatNo) {
        String sql=CoreXmlSqlParsersFactory
                .getSql("FrmFinalCheck.getFailDetail");
        if(TreatNo.length<=0){
            sql+= " AND 1<>1";
        }else {
            sql += CoreConverter.toSqlConditionString("D.RESULT_NO", TreatNo);
        }
        sql+=" ORDER BY D.RESULT_NO,T.MEASURING_SEQ";
        return this.getData(sql);
    }

    public CoreReturnObject DoAdd(String loadStr, ArrayList<String> ProMatNos, ArrayList<String> CheckDetails,ArrayList<String> ListTreatment ,String gx,ArrayList<String> ScrappedList){
                CoreReturnObject core = new CoreReturnObject();
                Connection connection = this.getDao(CoreConstantData.sysbeanstr)
                        .getConnection();
                PreparedStatement psta = null;
                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 sqlupdatepln = CoreXmlSqlParsersFactory
                    .getSql("FrmMcpLoading.updatePlnZyRclM2");// 修改加工计划表
            PreparedStatement patupdatepln = connection
                    .prepareStatement(sqlupdatepln);*/

                /*    String addPlnInfo = CoreXmlSqlParsersFactory
                            .getSql("FrmMcpLoading.AddComInfoResultNew");// 新增公共信息
                    PreparedStatement patsPlan = connection
                            .prepareStatement(addPlnInfo);*/




                    MchFinalCheckResultEntity Load = EntityTool.getEntityByJSONStr(loadStr,MchFinalCheckResultEntity.class);


            // 获取加工计划实体了
            PlnZyJgxMEntity pln = PlanService.getSendHttPlanCInfo3(connection,
                    Load.getHeatPlanNo());


            //region 检查
            if (pln == null){
                core.setV_errMsg("找不到炉计划数据！");
                return core;
            }
/*
            if (pln.getPlanstatus().equals("40")) {
                core.setV_errMsg("炉计划已关闭！");
                return core;
            }*/


        /*            String cutFalg = "";
                    String sql = CoreXmlSqlParsersFactory
                            .getSql("MchComm.queryComInfo");// 查询 工序是否是结炉状态
                    psta = connection.prepareStatement(sql);
                    psta.setString(1, Load.getHeatPlanNo());
                    psta.setString(2, Load.getBatchNo());
                    psta.setString(3, gx);
                    ResultSet rs = psta.executeQuery();
                    if (rs.next()) {
                        cutFalg = rs.getString("STATION_STATUS");
                    }


                    if (cutFalg.equals("2")) {
                        core.setV_errMsg("已结炉,不允许此操作！");
                        return core;
                    }
                    rs.close();
                    psta.close();*/




           String resultNo= "";
            //获取最大实绩编号
            String  sql =   CoreXmlSqlParsersFactory
                    .getSql("FrmFinalCheck.queryResultNo");
            psta = connection.prepareStatement(sql);
            psta.setObject(1, pln.getPlineCode() + gx );
            psta.setObject(2, pln.getPlineCode() + gx );
            ResultSet rs1 = psta.executeQuery();
            if (rs1.next()) {
                resultNo = rs1.getString("RESULT_NO");
            }
            rs1.close();
            psta.close();


            Load.setResultNo(resultNo);

            String sqlAdd = CoreXmlSqlParsersFactory
                    .getSql("FrmFinalCheck.AddResult");

            sqlAdd = com.steering.common.EntityTool.fillSqlByEntity(sqlAdd, Load);
            PreparedStatement patAdd = connection.prepareStatement(sqlAdd);
            patAdd.addBatch();

            if(ProMatNos.size()<=0){
                core.setV_errMsg("送检支不能为0");
                return core;
            }
                    String SqlAddProMat =CoreXmlSqlParsersFactory
                            .getSql("FrmFinalCheck.AddMatNo");
                    PreparedStatement   patAddProMat =connection.prepareStatement(SqlAddProMat);

                    String SqlUpdateMatNoStatus =CoreXmlSqlParsersFactory
                            .getSql("FrmFinalCheck.UpdateMatNoStatus");
                    PreparedStatement   patUpdateMatNoStatus =connection.prepareStatement(SqlUpdateMatNoStatus);

                    for (int i = 0; i < ProMatNos.size(); i++) {
                        PortMchBatchSampleResultEntity Port = EntityTool.getEntityByJSONStr(ProMatNos.get(i),PortMchBatchSampleResultEntity.class);

                        patAddProMat.setObject(1,resultNo);
                        patAddProMat.setObject(2,Port.getMatNo());
                        patAddProMat.setObject(3,Port.getMeasuringSeq());
                        patAddProMat.setObject(4,Port.getBarCode());
                        patAddProMat.setObject(5,Port.getActLen());
                        patAddProMat.setObject(6,Port.getActWeight());

                        patAddProMat.addBatch();


                        patUpdateMatNoStatus.setObject(1, Load.getHeatPlanNo());
                        patUpdateMatNoStatus.setObject(2, Port.getMatNo());
                        patUpdateMatNoStatus.addBatch();
                    }





            String sqlAddD = CoreXmlSqlParsersFactory
                    .getSql("FrmFinalCheck.AddResultD");
            PreparedStatement patAddD = connection.prepareStatement(sqlAddD);


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

                MchFinalCheckResultDEntity DEntity = EntityTool.getEntityByJSONStr(CheckDetails.get(i),MchFinalCheckResultDEntity.class);
                if(DEntity.getStation().equals("0")){
                    DEntity.setUnpassCode("");
                    DEntity.setUnpassName("");
                    DEntity.setUnpassMemo("");
                    DEntity.setTreatmentCode("");
                    DEntity.setTreatmentName("");
                }else if(DEntity.getStation().equals("1")) {
                    if(DEntity.getUnpassCode().equals("")){
                        throw  new  Exception("请录入不合管号的不合项目");
                    }

                    if(DEntity.getTreatmentCode().equals("")){
                        throw  new  Exception("请录入不合管号的处置方式");
                    }
                }

                if(DEntity.getStation().equals("0")){
                    DEntity.setReplayStation("0");
                    DEntity.setReplayMeasuringSeq(DEntity.getMeasuringSeq());
                }
                if(DEntity.getStation().equals("2")){
                    DEntity.setReplayStation("2");
                    DEntity.setReplayMeasuringSeq(DEntity.getMeasuringSeq());
                }


                patAddD.setObject(1,resultNo);
                patAddD.setObject(2,DEntity.getMatNo());
                patAddD.setObject(3,DEntity.getMeasuringSeq());
                patAddD.setObject(4,DEntity.getBarCode());
                patAddD.setObject(5,DEntity.getPositionCode());
                patAddD.setObject(6,DEntity.getUnpassCode());
                patAddD.setObject(7,DEntity.getUnpassName());
                patAddD.setObject(8,DEntity.getUnpassMemo());
                patAddD.setObject(9,DEntity.getStation());
                patAddD.setObject(10,DEntity.getTreatmentCode());
                patAddD.setObject(11,DEntity.getTreatmentName());
                patAddD.setObject(12,DEntity.getPositionName());
                patAddD.setObject(13,DEntity.getResponsibleCode());
                patAddD.setObject(14,DEntity.getResponsibleName());
                patAddD.setObject(15,DEntity.getTreatmentCode1());
                patAddD.setObject(16,DEntity.getTreatmentName1());
                patAddD.setObject(17,DEntity.getIsSizeCheck());
                patAddD.setObject(18,DEntity.getIsAppCheck());
                patAddD.setObject(19,DEntity.getReplayStation());
                patAddD.setObject(20,DEntity.getReplayMeasuringSeq());
                patAddD.addBatch();
            }



                    String addPlnInfo = CoreXmlSqlParsersFactory
                            .getSql("FrmMcpLoading.AddComInfoResultNew");// 新增公共信息
                    PreparedStatement patsPlan = connection
                            .prepareStatement(addPlnInfo);



           // 新增加工公共信息
            patsPlan.setObject(1, resultNo);
            patsPlan.setObject(2, Load.getPlineCode());
            patsPlan.setObject(3, Load.getPlineName());
            patsPlan.setObject(4, gx);
            patsPlan.setObject(5, gx);
            patsPlan.setObject(6, Load.getBatchNo());
            patsPlan.setObject(7, Load.getProNum());
            patsPlan.setObject(8, Load.getProWt());
            patsPlan.setObject(9, Load.getFailNum());
            patsPlan.setObject(10, Load.getFailWt());
            patsPlan.setObject(11, Load.getProTime());
            patsPlan.setObject(12, Load.getProShift());
            patsPlan.setObject(13, Load.getProGroup());
            patsPlan.setObject(14, Load.getProUser());
            patsPlan.setObject(15, Load.getProUser());
            patsPlan.setObject(16, Load.getHeatPlanNo());
            patsPlan.addBatch();

            //00-上料开始,10-探伤开始，20-切管开始，30-车丝开始，40-螺纹检验开始，50拧接开始，60-通径开始,70-水压开始，80-倒凌开始，90-测量点开始，11-交库开始
        /*    patupdatepln.setObject(1,"60");
            patupdatepln.setObject(2,Load.getHeatPlanNo());
            patupdatepln.setObject(3,Load.getBatchNo());
            patupdatepln.addBatch();*/

            patAdd.executeBatch();
                    patAddProMat.executeBatch();
                    patUpdateMatNoStatus.executeBatch();
            patAddD.executeBatch();

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

                        String sqlAddT = CoreXmlSqlParsersFactory
                                .getSql("FrmFinalCheck.AddResultT");
                        PreparedStatement patAddT = connection.prepareStatement(sqlAddT);

                        MchFinalCheckTreatmentEntity TEntity = EntityTool.getEntityByJSONStr(ListTreatment.get(i),MchFinalCheckTreatmentEntity.class);

                        patAddT.setObject(1,Load.getJudgeStoveNo());
                        patAddT.setObject(2,Load.getJudgeStoveNo());
                        patAddT.setObject(3,resultNo);
                        patAddT.setObject(4,TEntity.getResponsibleCode());
                        patAddT.setObject(5,TEntity.getResponsibleName());
                        patAddT.setObject(6,TEntity.getUnqualifiedNum());
                        patAddT.setObject(7,TEntity.getTreatmentCode());
                        patAddT.setObject(8,TEntity.getTreatmentName());
                        patAddT.setObject(9,resultNo);
                        patAddT.addBatch();
                        patAddT.executeBatch();


                        String sqlUpdateTreatmentNo = CoreXmlSqlParsersFactory
                                .getSql("FrmFinalCheck.UpdateTreatmentNo");
                        PreparedStatement patUpdateTreatmentNo = connection.prepareStatement(sqlUpdateTreatmentNo);

                        patUpdateTreatmentNo.setObject(1,resultNo);
                        patUpdateTreatmentNo.setObject(2,TEntity.getTreatmentCode());
                        patUpdateTreatmentNo.setObject(3,TEntity.getResponsibleCode());
                        patUpdateTreatmentNo.addBatch();
                        patUpdateTreatmentNo.executeBatch();
                    }

            patsPlan.executeBatch();
        //   patupdatepln.executeBatch();


            FrmMchBugD.AddMchWaste(connection,Load.getHeatPlanNo(),resultNo,Load.getPlineCode(),Load.getProUser(),gx,new ArrayList<String>(), ScrappedList);

            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;
    }


    public CoreReturnObject DoAdd(String loadStr, ArrayList<String> ProMatNos, ArrayList<String> CheckDetails,ArrayList<String> ListTreatment,String gx,ArrayList<String> UnpassList, ArrayList<String> ScrappedList ){
        CoreReturnObject core = new CoreReturnObject();
        Connection connection = this.getDao(CoreConstantData.sysbeanstr)
                .getConnection();
        PreparedStatement psta = null;
        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); //


            MchFinalCheckResultEntity Load = EntityTool.getEntityByJSONStr(loadStr,MchFinalCheckResultEntity.class);


            // 获取加工计划实体了
            PlnZyJgxMEntity pln = PlanService.getSendHttPlanCInfo3(connection,
                    Load.getHeatPlanNo());


            //region 检查
            if (pln == null){
                core.setV_errMsg("找不到炉计划数据！");
                return core;
            }
/*
            if (pln.getPlanstatus().equals("40")) {
                core.setV_errMsg("炉计划已关闭！");
                return core;
            }*/


                    String cutFalg = "";
                    String sql = CoreXmlSqlParsersFactory
                            .getSql("MchComm.queryComInfo");// 查询 工序是否是结炉状态
                    psta = connection.prepareStatement(sql);
                    psta.setString(1, Load.getHeatPlanNo());
                    psta.setString(2, Load.getBatchNo());
                    psta.setString(3, gx);
                    ResultSet rs = psta.executeQuery();
                    if (rs.next()) {
                        cutFalg = rs.getString("STATION_STATUS");
                    }


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




            String resultNo= "";
            //获取最大实绩编号
              sql =   CoreXmlSqlParsersFactory
                    .getSql("FrmFinalCheck.queryResultNo");
            psta = connection.prepareStatement(sql);
            psta.setObject(1, pln.getPlineCode() + gx );
            psta.setObject(2, pln.getPlineCode() + gx );
            ResultSet rs1 = psta.executeQuery();
            if (rs1.next()) {
                resultNo = rs1.getString("RESULT_NO");
            }
            rs1.close();
            psta.close();


            Load.setResultNo(resultNo);

            String sqlAdd = CoreXmlSqlParsersFactory
                    .getSql("FrmFinalCheck.AddResult");

            sqlAdd = com.steering.common.EntityTool.fillSqlByEntity(sqlAdd, Load);
            PreparedStatement patAdd = connection.prepareStatement(sqlAdd);
            patAdd.addBatch();

            if(ProMatNos.size()<=0){
                core.setV_errMsg("送检支不能为0");
                return core;
            }
            String SqlAddProMat =CoreXmlSqlParsersFactory
                    .getSql("FrmFinalCheck.AddMatNo");
            PreparedStatement   patAddProMat =connection.prepareStatement(SqlAddProMat);

            String SqlUpdateMatNoStatus =CoreXmlSqlParsersFactory
                    .getSql("FrmFinalCheck.UpdateMatNoStatus");
            PreparedStatement   patUpdateMatNoStatus =connection.prepareStatement(SqlUpdateMatNoStatus);

            for (int i = 0; i < ProMatNos.size(); i++) {
                PortMchBatchSampleResultEntity Port = EntityTool.getEntityByJSONStr(ProMatNos.get(i),PortMchBatchSampleResultEntity.class);

                patAddProMat.setObject(1,resultNo);
                patAddProMat.setObject(2,Port.getMatNo());
                patAddProMat.setObject(3,Port.getMeasuringSeq());
                patAddProMat.setObject(4,Port.getBarCode());
                patAddProMat.setObject(5,Port.getActLen());
                patAddProMat.setObject(6,Port.getActWeight());

                patAddProMat.addBatch();


                patUpdateMatNoStatus.setObject(1, Load.getHeatPlanNo());
                patUpdateMatNoStatus.setObject(2, Port.getMatNo());
                patUpdateMatNoStatus.addBatch();
            }





            String sqlAddD = CoreXmlSqlParsersFactory
                    .getSql("FrmFinalCheck.AddResultD");
            PreparedStatement patAddD = connection.prepareStatement(sqlAddD);


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

                MchFinalCheckResultDEntity DEntity = EntityTool.getEntityByJSONStr(CheckDetails.get(i),MchFinalCheckResultDEntity.class);
                if(DEntity.getStation().equals("0")){
                    DEntity.setUnpassCode("");
                    DEntity.setUnpassName("");
                    DEntity.setUnpassMemo("");
                    DEntity.setTreatmentCode("");
                    DEntity.setTreatmentName("");
                }

                if(DEntity.getStation().equals("0")){
                    DEntity.setReplayStation("0");
                    DEntity.setReplayMeasuringSeq(DEntity.getMeasuringSeq());
                }
                if(DEntity.getStation().equals("2")){
                    DEntity.setReplayStation("2");
                    DEntity.setReplayMeasuringSeq(DEntity.getMeasuringSeq());
                }

                patAddD.setObject(1,resultNo);
                patAddD.setObject(2,DEntity.getMatNo());
                patAddD.setObject(3,DEntity.getMeasuringSeq());
                patAddD.setObject(4,DEntity.getBarCode());
                patAddD.setObject(5,DEntity.getPositionCode());
                patAddD.setObject(6,DEntity.getUnpassCode());
                patAddD.setObject(7,DEntity.getUnpassName());
                patAddD.setObject(8,DEntity.getUnpassMemo());
                patAddD.setObject(9,DEntity.getStation());
                patAddD.setObject(10,DEntity.getTreatmentCode());
                patAddD.setObject(11,DEntity.getTreatmentName());
                patAddD.setObject(12,DEntity.getPositionName());
                patAddD.setObject(13,DEntity.getResponsibleCode());
                patAddD.setObject(14,DEntity.getResponsibleName());
                patAddD.setObject(15,DEntity.getTreatmentCode1());
                patAddD.setObject(16,DEntity.getTreatmentName1());
                patAddD.setObject(17,DEntity.getIsSizeCheck());
                patAddD.setObject(18,DEntity.getIsAppCheck());
                patAddD.setObject(19,DEntity.getReplayStation());
                patAddD.setObject(20,DEntity.getReplayMeasuringSeq());
                patAddD.addBatch();
            }



            String addPlnInfo = CoreXmlSqlParsersFactory
                    .getSql("FrmMcpLoading.AddComInfoResultNew");// 新增公共信息
            PreparedStatement patsPlan = connection
                    .prepareStatement(addPlnInfo);



            // 新增加工公共信息
            patsPlan.setObject(1, resultNo);
            patsPlan.setObject(2, Load.getPlineCode());
            patsPlan.setObject(3, Load.getPlineName());
            patsPlan.setObject(4, gx);
            patsPlan.setObject(5, gx);
            patsPlan.setObject(6, Load.getBatchNo());
            patsPlan.setObject(7, Load.getProNum());
            patsPlan.setObject(8, Load.getProWt());
            patsPlan.setObject(9, Load.getFailNum());
            patsPlan.setObject(10, Load.getFailWt());
            patsPlan.setObject(11, Load.getProTime());
            patsPlan.setObject(12, Load.getProShift());
            patsPlan.setObject(13, Load.getProGroup());
            patsPlan.setObject(14, Load.getProUser());
            patsPlan.setObject(15, Load.getProUser());
            patsPlan.setObject(16, Load.getHeatPlanNo());
            patsPlan.addBatch();

            //00-上料开始,10-探伤开始，20-切管开始，30-车丝开始，40-螺纹检验开始，50拧接开始，60-通径开始,70-水压开始，80-倒凌开始，90-测量点开始，11-交库开始
        /*    patupdatepln.setObject(1,"60");
            patupdatepln.setObject(2,Load.getHeatPlanNo());
            patupdatepln.setObject(3,Load.getBatchNo());
            patupdatepln.addBatch();*/

            patAdd.executeBatch();
            patAddProMat.executeBatch();
            patUpdateMatNoStatus.executeBatch();
            patAddD.executeBatch();



            patsPlan.executeBatch();
            //   patupdatepln.executeBatch();


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

                String sqlAddT = CoreXmlSqlParsersFactory
                        .getSql("FrmFinalCheck.AddResultT");
                PreparedStatement patAddT = connection.prepareStatement(sqlAddT);


                String sqlUpdateTreatmentNo = CoreXmlSqlParsersFactory
                        .getSql("FrmFinalCheck.UpdateTreatmentNo");
                PreparedStatement patUpdateTreatmentNo = connection.prepareStatement(sqlUpdateTreatmentNo);


                MchFinalCheckTreatmentEntity TEntity = EntityTool.getEntityByJSONStr(ListTreatment.get(i),MchFinalCheckTreatmentEntity.class);

                patAddT.setObject(1,Load.getJudgeStoveNo());
                patAddT.setObject(2,Load.getJudgeStoveNo());
                patAddT.setObject(3,resultNo);
                patAddT.setObject(4,TEntity.getResponsibleCode());
                patAddT.setObject(5,TEntity.getResponsibleName());
                patAddT.setObject(6,TEntity.getUnqualifiedNum());
                patAddT.setObject(7,TEntity.getTreatmentCode());
                patAddT.setObject(8,TEntity.getTreatmentName());
                patAddT.setObject(9,resultNo);
                patAddT.addBatch();
                patAddT.executeBatch();



                patUpdateTreatmentNo.setObject(1,resultNo);
                patUpdateTreatmentNo.setObject(2,TEntity.getResponsibleCode());
                patUpdateTreatmentNo.setObject(3,TEntity.getTreatmentCode());
                patUpdateTreatmentNo.addBatch();
                patUpdateTreatmentNo.executeBatch();

            }

            patsPlan.executeBatch();


            FrmMchBugD.AddMchWaste(connection,Load.getHeatPlanNo(),resultNo,Load.getPlineCode(),Load.getProUser(),gx,UnpassList, ScrappedList);

            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;
    }


    public CoreReturnObject DoDelete(String loadStr,String gx) {
        CoreReturnObject core = new CoreReturnObject();
        Connection connection = this.getDao(CoreConstantData.sysbeanstr)
                .getConnection();
        Date now = new Date();
        SimpleDateFormat dateFormat1 = new SimpleDateFormat(
                "yyyyMM", Locale.CHINA);
        String systime1 = dateFormat1.format(now);
        PreparedStatement psta = null;

        SimpleDateFormat dateFormat = new SimpleDateFormat(
                "yyyy-MM-dd HH:mm:ss", Locale.CHINA);
        String systime = dateFormat.format(new Date());

        try {
            connection.setAutoCommit(false); // 取消自动提交事务

            String DeleteComInfoSql = CoreXmlSqlParsersFactory
                    .getSql("FrmMcpLoading.deleteVrpResult");// 删除公共信息
            PreparedStatement patsDeleteComInfo = connection
                    .prepareStatement(DeleteComInfoSql);

            String DeleteResultSql = CoreXmlSqlParsersFactory
                    .getSql("FrmFinalCheck.DeleteResult");// 删除实绩
            PreparedStatement patsDeleteResult = connection
                    .prepareStatement(DeleteResultSql);

            String DeleteDetailMatNoSql = CoreXmlSqlParsersFactory
                    .getSql("FrmFinalCheck.DetailMatNo");// 删除实绩
            PreparedStatement patsDeleteDetailMatNo = connection
                    .prepareStatement(DeleteDetailMatNoSql);

            String DeleteDetailResultSql = CoreXmlSqlParsersFactory
                    .getSql("FrmFinalCheck.DeleteDetailResult");// 删除实绩
            PreparedStatement patsDeleteDetailResult = connection
                    .prepareStatement(DeleteDetailResultSql);



            String DeleteDeleteTreatMentSql = CoreXmlSqlParsersFactory
                    .getSql("FrmFinalCheck.DeleteTreatMent");// 删除实绩
            PreparedStatement patsDeleteDeleteTreatMent= connection
                    .prepareStatement(DeleteDeleteTreatMentSql);

            String UpdateStatusSql = CoreXmlSqlParsersFactory
                    .getSql("FrmFinalCheck.UpdateMatNoStatus1");// 删除实绩
            PreparedStatement patsUpdateStatus = connection
                    .prepareStatement(UpdateStatusSql);


            MchFinalCheckResultEntity Load = EntityTool.getEntityByJSONStr(loadStr,MchFinalCheckResultEntity.class);

            PlnZyJgxMEntity pln = PlanService.getSendHttPlanCInfo3(connection,
                    Load.getHeatPlanNo(),Load.getBatchNo());


            //region 检查
            if (pln == null){
                core.setV_errMsg("找不到炉计划数据！");
                return core;
            }
/*
            if (pln.getPlanstatus().equals("40")) {
                core.setV_errMsg("炉计划已经关闭！");
                return core;
            }*/


 /*           String cutFalg = "";
            String sql = CoreXmlSqlParsersFactory
                    .getSql("MchComm.queryComInfo");// 查询 工序是否是结炉状态
            psta = connection.prepareStatement(sql);
            psta.setString(1, Load.getHeatPlanNo());
            psta.setString(2, Load.getBatchNo());
            psta.setString(3, gx);
            ResultSet rs = psta.executeQuery();
            if (rs.next()) {
                cutFalg = rs.getString("STATION_STATUS");
            }


            if (cutFalg.equals("2")) {
                core.setV_errMsg("已结炉,不允许此操作！");
                return core;
            }
            rs.close();
            psta.close();*/


            String TreatStatus = "";
            String sql = CoreXmlSqlParsersFactory
                    .getSql("FrmFinalCheck.getTreatMentStatus");// 查询工序是否是结炉状态
            psta = connection.prepareStatement(sql);
            psta.setString(1, Load.getResultNo());
            ResultSet  rs = psta.executeQuery();
            if (rs.next()) {
                TreatStatus = rs.getString("APPROVAL_STATUS");
            }


            if (TreatStatus!=null && !TreatStatus.equals("0")) {
                core.setV_errMsg("处置单已经反馈,无法删除该实绩");
                return core;
            }
            rs.close();
            psta.close();

            //endregion

            patsUpdateStatus.setObject(1,Load.getHeatPlanNo());
            patsUpdateStatus.setObject(2,Load.getResultNo());
            patsUpdateStatus.addBatch();
            patsUpdateStatus.executeBatch();

            patsDeleteDetailMatNo.setObject(1,Load.getResultNo());
            patsDeleteDetailMatNo.addBatch();
            patsDeleteDetailMatNo.executeBatch();



            patsDeleteResult.setObject(1,Load.getResultNo());
            patsDeleteResult.addBatch();
            patsDeleteResult.executeBatch();

            patsDeleteDetailResult.setObject(1,Load.getResultNo());
            patsDeleteDetailResult.addBatch();
            patsDeleteDetailResult.executeBatch();


            patsDeleteDeleteTreatMent.setObject(1,Load.getResultNo());
            patsDeleteDeleteTreatMent.addBatch();
            patsDeleteDeleteTreatMent.executeBatch();

            patsDeleteComInfo.setObject(1,Load.getResultNo());
            patsDeleteComInfo.addBatch();
            patsDeleteComInfo.executeBatch();

           int detCount =0;
            if(StringTool.isInteger(Load.getFailNum())){
                detCount = Integer.parseInt(Load.getFailNum());
            }

            FrmMchBugD.DeleteMchWaste(connection, Load.getHeatPlanNo(),Load.getResultNo(), Load.getPlineCode(),gx,detCount);


            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;
    }


    public CoreReturnObject DoReply(String No, String name, String Info, String Departmentd, String DepartmentName,
                                    String FailNum, String FailWt, ArrayList<String> ScrappedList) {
        CoreReturnObject core = new CoreReturnObject();
        Connection connection = this.getDao(CoreConstantData.sysbeanstr)
                .getConnection();
        PreparedStatement psta = null;
        try {
            connection.setAutoCommit(false); // 取消自动提交事务


            String UpdateStatusSql = CoreXmlSqlParsersFactory
                    .getSql("FrmFinalCheck.UpdateTreatmentStatus");// 删除实绩
            PreparedStatement patsUpdateStatus = connection
                    .prepareStatement(UpdateStatusSql);

            String UpdateComInfoSql = CoreXmlSqlParsersFactory
                    .getSql("FrmFinalCheck.UpdateComInfo");//
            PreparedStatement patsUpdateComInfo = connection
                    .prepareStatement(UpdateComInfoSql);

            //region 检查


            if (Info.trim().equals("")) {
                core.setV_errMsg("请输入反馈信息！");
                return core;
            }



            String TreatStatus = "";
            String sql = CoreXmlSqlParsersFactory
                    .getSql("frmEntrust.QuerTreatment");//
            sql+="AND T.TREATMENT_NO = ?";
            psta = connection.prepareStatement(sql);
            psta.setString(1, No);
            ResultSet rs = psta.executeQuery();

            List<MchFinalCheckTreatmentEntity> TreatmentLsit = EntityTool.getEntitysByRs(rs,
                    MchFinalCheckTreatmentEntity.class);

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

            if(TreatmentLsit==null || TreatmentLsit.size()<=0){
                core.setV_errMsg("找不到处置单信息,请重新查询");
                return core;
            }

            if(!TreatmentLsit.get(0).getApprovalStatus().equals("0")){
                core.setV_errMsg("已反馈信息, 若需修改,请先撤销反馈");
                return core;
            }

            //endregion

            patsUpdateStatus.setObject(1,Info);
            patsUpdateStatus.setObject(2,name);
            patsUpdateStatus.setObject(3,Departmentd);
            patsUpdateStatus.setObject(4,DepartmentName);
            patsUpdateStatus.setObject(5,FailNum);
            patsUpdateStatus.setObject(6,FailWt);
            patsUpdateStatus.setObject(7,No);
            patsUpdateStatus.addBatch();
            patsUpdateStatus.executeBatch();

            patsUpdateComInfo.setObject(1,TreatmentLsit.get(0).getResultNo());
            patsUpdateComInfo.addBatch();
            patsUpdateComInfo.executeBatch();

            FrmMchBugD.AddMchWaste(connection,TreatmentLsit.get(0).getHeatPlanNo(),TreatmentLsit.get(0).getTreatmentNo()
                    ,TreatmentLsit.get(0).getPlineCode(),name,"701313",new ArrayList<String>(), ScrappedList);




            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;
    }

    public CoreReturnObject DoReply(String No, String name, String Info, String Departmentd, String DepartmentName,
                                    String FailNum, String FailWt,ArrayList<String> Detail , ArrayList<String> ScrappedList) {
       return DoReply( No,  name,  Info,  Departmentd,  DepartmentName,FailNum,  FailWt, Detail , ScrappedList,false);
    }

    public CoreReturnObject DoReply(String No, String name, String Info, String Departmentd, String DepartmentName,
                                    String FailNum, String FailWt,ArrayList<String> Detail , ArrayList<String> ScrappedList,Boolean NeedSplit) {
        return DoReply( No,  name,  Info,  Departmentd,  DepartmentName,FailNum,  FailWt, Detail , ScrappedList,NeedSplit,"","");
    }

    public CoreReturnObject DoReply(String No, String name, String Info, String Departmentd, String DepartmentName,
                                    String FailNum, String FailWt,ArrayList<String> Detail , ArrayList<String> ScrappedList,Boolean NeedSplit,String bc,String bz) {
        CoreReturnObject core = new CoreReturnObject();
        Connection connection = this.getDao(CoreConstantData.sysbeanstr)
                .getConnection();
        PreparedStatement psta = null;
        try {
            connection.setAutoCommit(false); // 取消自动提交事务


            String UpdateStatusSql = CoreXmlSqlParsersFactory
                    .getSql("FrmFinalCheck.UpdateTreatmentStatus");
            PreparedStatement patsUpdateStatus = connection
                    .prepareStatement(UpdateStatusSql);

            String UpdateComInfoSql = CoreXmlSqlParsersFactory
                    .getSql("FrmFinalCheck.UpdateComInfo");//
            PreparedStatement patsUpdateComInfo = connection
                    .prepareStatement(UpdateComInfoSql);

            //region 检查


            if (Info.trim().equals("")) {
                core.setV_errMsg("请输入反馈信息！");
                return core;
            }



            String sql = CoreXmlSqlParsersFactory
                    .getSql("frmEntrust.QuerTreatment");//
            sql+="AND T.TREATMENT_NO = ?";
            psta = connection.prepareStatement(sql);
            psta.setString(1, No);
            ResultSet rs = psta.executeQuery();

            List<MchFinalCheckTreatmentEntity> TreatmentLsit = EntityTool.getEntitysByRs(rs,
                    MchFinalCheckTreatmentEntity.class);

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

            if(TreatmentLsit==null || TreatmentLsit.size()<=0){
                core.setV_errMsg("找不到处置单信息,请重新查询");
                return core;
            }

            if(!TreatmentLsit.get(0).getApprovalStatus().equals("0")){
                core.setV_errMsg("已反馈信息, 若需修改,请先撤销反馈");
                return core;
            }

            //endregion


            String NewTreatMent= "";

            //拆分处置单
            if(NeedSplit){
                //获取最大实绩编号
                  sql =   CoreXmlSqlParsersFactory
                        .getSql("FrmFinalCheck.queryTreatmentNo");
                psta = connection.prepareStatement(sql);
                psta.setObject(1,No );
                psta.setObject(2, No );
                ResultSet rs1 = psta.executeQuery();
                if (rs1.next()) {
                    NewTreatMent = rs1.getString("TREATMENT_NO");
                }
                rs1.close();
                psta.close();


                String AddTreamtSql = CoreXmlSqlParsersFactory
                        .getSql("FrmFinalCheck.SplitTreatment");
                PreparedStatement patsAddTreamt = connection
                        .prepareStatement(AddTreamtSql);

                patsAddTreamt.setObject(1,NewTreatMent);
                patsAddTreamt.setObject(2,No);
                patsAddTreamt.addBatch();
                patsAddTreamt.executeBatch();



            }


            patsUpdateStatus.setObject(1,Info);
            patsUpdateStatus.setObject(2,name);
            patsUpdateStatus.setObject(3,Departmentd);
            patsUpdateStatus.setObject(4,DepartmentName);
            patsUpdateStatus.setObject(5,FailNum);
            patsUpdateStatus.setObject(6,FailWt);
            patsUpdateStatus.setObject(7,bc);
            patsUpdateStatus.setObject(8,bz);
            patsUpdateStatus.setObject(9,"".equals(NewTreatMent)?No:NewTreatMent);
            patsUpdateStatus.addBatch();
            patsUpdateStatus.executeBatch();

            patsUpdateComInfo.setObject(1,TreatmentLsit.get(0).getResultNo());
            patsUpdateComInfo.addBatch();
            patsUpdateComInfo.executeBatch();

            FrmMchBugD.AddMchWaste(connection,TreatmentLsit.get(0).getHeatPlanNo(),
                    "".equals(NewTreatMent)?No:NewTreatMent
                    ,TreatmentLsit.get(0).getPlineCode(),name,"701313",new ArrayList<String>(), ScrappedList);


            String sqlAddD = CoreXmlSqlParsersFactory
                    .getSql("FrmFinalCheck.UpdateResultD");
            PreparedStatement patAddD = connection.prepareStatement(sqlAddD);


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

                MchFinalCheckResultDEntity DEntity = EntityTool.getEntityByJSONStr(Detail.get(i),MchFinalCheckResultDEntity.class);



                if(!DEntity.getMeasuringSeq().equals("") && DEntity.getReplayMeasuringSeq().equals("")){
                    if(DEntity.getReplayStation().equals("0") && !"00".equals(TreatmentLsit.get(0).getResponsibleCode())) {

                        throw new Exception("当前反馈管号无喷印管号, 该管号已经返线,但未录入测量点数据!");
                    }else{
                        DEntity.setReplayMeasuringSeq(DEntity.getMeasuringSeq());
                    }
                }

                patAddD.setObject(1,DEntity.getReplayStation());
                patAddD.setObject(2,DEntity.getScrapCode());
                patAddD.setObject(3,DEntity.getScrapName());
                patAddD.setObject(4,"".equals(NewTreatMent)?No:NewTreatMent );
                patAddD.setObject(5,DEntity.getReplayMeasuringSeq());
                patAddD.setObject(6,DEntity.getResultNo());
                patAddD.setObject(7,DEntity.getMatNo());
                patAddD.setObject(8,DEntity.getMeasuringSeq());
                patAddD.setObject(9,DEntity.getPositionCode());
                patAddD.setObject(10,DEntity.getTreatmentCode());
                patAddD.setObject(11,DEntity.getResponsibleCode());
                patAddD.addBatch();
            }
            patAddD.executeBatch();


            if(NeedSplit) {

                String UpdateSql = CoreXmlSqlParsersFactory
                        .getSql("FrmFinalCheck.UpdateTreatmentNoNum");
                PreparedStatement patsUpdate = connection
                        .prepareStatement(UpdateSql);

                patsUpdate.setObject(1,NewTreatMent);
                patsUpdate.addBatch();

                patsUpdate.setObject(1,No);
                patsUpdate.addBatch();

                patsUpdate.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;
    }

    public CoreReturnObject DoCancelReply(String No,String name) {
        CoreReturnObject core = new CoreReturnObject();
        Connection connection = this.getDao(CoreConstantData.sysbeanstr)
                .getConnection();
        PreparedStatement psta = null;
        try {
            connection.setAutoCommit(false); // 取消自动提交事务


            String UpdateStatusSql = CoreXmlSqlParsersFactory
                    .getSql("FrmFinalCheck.UpdateTreatmentStatus1");// 删除实绩
            PreparedStatement patsUpdateStatus = connection
                    .prepareStatement(UpdateStatusSql);


            String UpdateComInfoSql = CoreXmlSqlParsersFactory
                    .getSql("FrmFinalCheck.UpdateComInfo");//
            PreparedStatement patsUpdateComInfo = connection
                    .prepareStatement(UpdateComInfoSql);


            String UpdateDetailSql = CoreXmlSqlParsersFactory
                    .getSql("FrmFinalCheck.UpdateDetail");//
            PreparedStatement patsUpdateDetail = connection
                    .prepareStatement(UpdateDetailSql);

            //region 检查

            String TreatStatus = "";
            String sql = CoreXmlSqlParsersFactory
                    .getSql("frmEntrust.QuerTreatment");//
            sql+="AND T.TREATMENT_NO = ?";
            psta = connection.prepareStatement(sql);
            psta.setString(1, No);
            ResultSet rs = psta.executeQuery();

            List<MchFinalCheckTreatmentEntity> TreatmentLsit = EntityTool.getEntitysByRs(rs,
                    MchFinalCheckTreatmentEntity.class);

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

            if(TreatmentLsit==null || TreatmentLsit.size()<=0){
                core.setV_errMsg("找不到处置单信息,请重新查询");
                return core;
            }

            if(TreatmentLsit.get(0).getApprovalStatus().equals("0")){
                core.setV_errMsg("该处置单未反馈信息!");
                return core;
            }

            if(!TreatmentLsit.get(0).getApprovalStatus().equals("1")){
                core.setV_errMsg("该处置单已经验证,无法撤销反馈!");
                return core;
            }

            //endregion

            patsUpdateStatus.setObject(1,"");
            patsUpdateStatus.setObject(2,"");
            patsUpdateStatus.setObject(3,No);
            patsUpdateStatus.addBatch();
            patsUpdateStatus.executeBatch();

            patsUpdateComInfo.setObject(1,TreatmentLsit.get(0).getResultNo());
            patsUpdateComInfo.addBatch();
            patsUpdateComInfo.executeBatch();

            patsUpdateDetail.setObject(1,TreatmentLsit.get(0).getResultNo());
            patsUpdateDetail.setObject(2,No);
            patsUpdateDetail.addBatch();
            patsUpdateDetail.executeBatch();

            int detCount =0;
            if(StringTool.isInteger(TreatmentLsit.get(0).getFailNum())){
                detCount = Integer.parseInt(TreatmentLsit.get(0).getFailNum());
            }

            FrmMchBugD.DeleteMchWaste(connection, TreatmentLsit.get(0).getHeatPlanNo(),TreatmentLsit.get(0).getTreatmentNo(), TreatmentLsit.get(0).getPlineCode(),"701313",detCount);

            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;
    }


    public CoreReturnObject DoApproval(String No,String name,String Info) {
        CoreReturnObject core = new CoreReturnObject();
        Connection connection = this.getDao(CoreConstantData.sysbeanstr)
                .getConnection();
        PreparedStatement psta = null;
        try {
            connection.setAutoCommit(false); // 取消自动提交事务


            String UpdateStatusSql = CoreXmlSqlParsersFactory
                    .getSql("FrmFinalCheck.UpdateTreatmentStatus2");// 删除实绩
            PreparedStatement patsUpdateStatus = connection
                    .prepareStatement(UpdateStatusSql);




            //region 检查





            if (Info.trim().equals("")) {
                core.setV_errMsg("请输入验证信息！");
                return core;
            }



            String TreatStatus = "";
            String sql = CoreXmlSqlParsersFactory
                    .getSql("frmEntrust.QuerTreatment");//
            sql+="AND T.TREATMENT_NO = ?";
            psta = connection.prepareStatement(sql);
            psta.setString(1, No);
            ResultSet rs = psta.executeQuery();

            List<MchFinalCheckTreatmentEntity> TreatmentLsit = EntityTool.getEntitysByRs(rs,
                    MchFinalCheckTreatmentEntity.class);

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

            if(TreatmentLsit==null || TreatmentLsit.size()<=0){
                core.setV_errMsg("找不到处置单信息,请重新查询");
                return core;
            }

            if(TreatmentLsit.get(0).getApprovalStatus().equals("2")){
                core.setV_errMsg("已验证通过, 请勿重复验证通过");
                return core;
            }

            if(!TreatmentLsit.get(0).getApprovalStatus().equals("1")){
                core.setV_errMsg("未反馈信息, 无法验证通过");
                return core;
            }

            String cutFalg = "";
             sql = CoreXmlSqlParsersFactory
                    .getSql("MchComm.queryComInfo");// 查询 工序是否是结炉状态
            psta = connection.prepareStatement(sql);
            psta.setString(1, TreatmentLsit.get(0).getHeatPlanNo());
            psta.setString(2, TreatmentLsit.get(0).getBatchNo());
            psta.setString(3, "701313");
             rs = psta.executeQuery();
            if (rs.next()) {
                cutFalg = rs.getString("STATION_STATUS");
            }


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

            //endregion

            patsUpdateStatus.setObject(1,Info);
            patsUpdateStatus.setObject(2,name);
            patsUpdateStatus.setObject(3,No);
            patsUpdateStatus.addBatch();
            patsUpdateStatus.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;
    }

    public CoreReturnObject DoCancleApproval( String No) {
        CoreReturnObject core = new CoreReturnObject();
        Connection connection = this.getDao(CoreConstantData.sysbeanstr)
                .getConnection();
        PreparedStatement psta = null;
        try {
            connection.setAutoCommit(false); // 取消自动提交事务


            String UpdateStatusSql = CoreXmlSqlParsersFactory
                    .getSql("FrmFinalCheck.UpdateTreatmentStatus3");// 删除实绩
            PreparedStatement patsUpdateStatus = connection
                    .prepareStatement(UpdateStatusSql);




            //region 检查


            String sql = CoreXmlSqlParsersFactory
                    .getSql("frmEntrust.QuerTreatment");//
            sql+="AND T.TREATMENT_NO = ?";
            psta = connection.prepareStatement(sql);
            psta.setString(1, No);
            ResultSet rs = psta.executeQuery();

            List<MchFinalCheckTreatmentEntity> TreatmentLsit = EntityTool.getEntitysByRs(rs,
                    MchFinalCheckTreatmentEntity.class);

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

            if(TreatmentLsit==null || TreatmentLsit.size()<=0){
                core.setV_errMsg("找不到处置单信息,请重新查询");
                return core;
            }



            if(!TreatmentLsit.get(0).getApprovalStatus().equals("2")){
                core.setV_errMsg("未验证通过,无法撤销!");
                return core;
            }

            PlnZyJgxMEntity pln = PlanService.getSendHttPlanCInfo3(connection,
                    TreatmentLsit.get(0).getHeatPlanNo(),TreatmentLsit.get(0).getBatchNo());


            //region 检查
            if (pln == null){
                core.setV_errMsg("找不到炉计划数据！");
                return core;
            }

            if (pln.getPlanstatus().equals("40")) {
                core.setV_errMsg("炉计划已经关闭,不允许撤销验证！");
                return core;
            }

            String cutFalg = "";
            sql = CoreXmlSqlParsersFactory
                    .getSql("MchComm.queryComInfo");// 查询 工序是否是结炉状态
            psta = connection.prepareStatement(sql);
            psta.setString(1, TreatmentLsit.get(0).getHeatPlanNo());
            psta.setString(2, TreatmentLsit.get(0).getBatchNo());
            psta.setString(3, "701313");
            rs = psta.executeQuery();
            if (rs.next()) {
                cutFalg = rs.getString("STATION_STATUS");
            }


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

            //endregion

            patsUpdateStatus.setObject(1,No);
            patsUpdateStatus.addBatch();
            patsUpdateStatus.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;
    }


    public CoreReturnObject CheckStatus(String heatNo , String BatchNo) {
        return this.getDataBySqlID("FrmFinalCheck.CheckStatus",
                new Object[] { heatNo,BatchNo, heatNo,BatchNo});
    }



    public CoreReturnObject DoAddCheckMatNo(String ResultNo, String TreatmetNo, ArrayList<String> AddData ){
        CoreReturnObject core = new CoreReturnObject();
        Connection connection = this.getDao(CoreConstantData.sysbeanstr)
                .getConnection();
        PreparedStatement psta = null;
        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 TreatStatus = "";
            String sql = CoreXmlSqlParsersFactory
                    .getSql("frmEntrust.QuerTreatment");//
            sql+="AND T.TREATMENT_NO = ?";
            psta = connection.prepareStatement(sql);
            psta.setString(1, TreatmetNo);
            ResultSet rs = psta.executeQuery();

            List<MchFinalCheckTreatmentEntity> TreatmentLsit = EntityTool.getEntitysByRs(rs,
                    MchFinalCheckTreatmentEntity.class);

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

            if(TreatmentLsit==null || TreatmentLsit.size()<=0){
                core.setV_errMsg("找不到处置单信息,请重新查询");
                return core;
            }

            if(!TreatmentLsit.get(0).getApprovalStatus().equals("0")){
                core.setV_errMsg("已反馈信息, 若需修改,请先撤销反馈");
                return core;
            }

            String DeleteSql = CoreXmlSqlParsersFactory
                    .getSql("FrmFinalCheck.DeleteCheckMatNo");// 删除实绩
            PreparedStatement patsDelete = connection
                    .prepareStatement(DeleteSql);

            String AddSql = CoreXmlSqlParsersFactory
                    .getSql("FrmFinalCheck.AddCheckMatNo");//
            PreparedStatement patsAdd = connection
                    .prepareStatement(AddSql);


            // 新增加工公共信息
            patsDelete.setObject(1, ResultNo);
            patsDelete.setObject(2, TreatmetNo);
            patsDelete.addBatch();
            patsDelete.executeBatch();

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



                MchFinalCheckResultDEntity TEntity = EntityTool.getEntityByJSONStr(AddData.get(i),MchFinalCheckResultDEntity.class);

                patsAdd.setObject(1,ResultNo);
                patsAdd.setObject(2,TEntity.getMatNo());
                patsAdd.setObject(3,TEntity.getMeasuringSeq());
                patsAdd.setObject(4,TEntity.getBarCode());
                patsAdd.setObject(5,TreatmetNo);
                patsAdd.addBatch();
                patsAdd.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;
    }

}
