package com.steering.pss.ydm.Report;

import CoreFS.SA06.CoreReturnObject;
import CoreFS.SA08.CoreXmlSqlParsersFactory;
import CoreFS.SC01.CoreConstantData;
import CoreFS.Util.StringUtils;
import com.steering.comm.converter.CoreConverter;
import com.steering.comm.db.DBCommon;
import com.steering.comm.tools.EntityTool;
import com.steering.pss.ydm.entity.SlmOrderLogoutReviewEntity;

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

public class FrmOrderNoReport extends DBCommon {

    // /**
    // * 查询合同行信息
    // *
    // * @param strWhere
    // * @return
    // */
    // public CoreReturnObject getQueryOrderNoMount(String stratTime,
    // String endTime, String orderNo, String orderStrats,
    // String[] salgPermissions) {
    // String str = CoreConverter.toSqlConditionString("B.SALE_ORG",
    // salgPermissions);
    // String sql = CoreXmlSqlParsersFactory.getSql(
    // "FrmOrderNoReport.GetQueryOrderNoMount").replace("#SALEORG#",
    // str);
    // return this.getData(sql,
    // new Object[] { stratTime, endTime, orderNo, orderStrats,
    // stratTime, endTime, orderNo, orderStrats, stratTime,
    // endTime, orderNo, orderStrats, stratTime, endTime,
    // orderNo, orderStrats, stratTime, endTime, orderNo,
    // orderStrats, stratTime, endTime, orderNo, orderStrats,
    // stratTime, endTime, orderNo, orderStrats, stratTime,
    // endTime, orderNo, orderStrats });
    // }
    /**
     * 查询合同行信息
     * @param strWhere
     * @return
     */
    public CoreReturnObject getQueryOrderNoMount(String stratTime,
            String endTime, String orderNo, String orderStrats,
            String[] salgPermissions) {

        String sql = CoreXmlSqlParsersFactory
                .getSql("FrmOrderNoReport.GetQueryOrderNoReport");
        String str = CoreConverter.toSqlConditionString("B.SALE_ORG",
                salgPermissions);
        sql += str;
        if (!stratTime.equals("")) {
            sql += "  AND A.CREATE_TIME BETWEEN TO_DATE('" + stratTime
                    + "', 'YYYY-MM-DD HH24:MI:SS') AND" + " TO_DATE('"
                    + endTime + "', 'YYYY-MM-DD HH24:MI:SS')";
        }
        if (!orderStrats.equals("")) {
            sql += " AND A.ORDER_LN_STATUS ='" + orderStrats + "'";
        }
        if (!orderNo.equals("")) {
            sql += " AND B.ORDER_NO LIKE '%'||'" + orderNo + "'||'%'";
        }
        return this.getData(sql);
    }

    /**
     * 查询合同信息
     * @param strWhere
     * @return
     */
    public CoreReturnObject getQueryOrderSeqNo(String stratTime,
            String endTime, String orderNo, String orderStrats,
            String[] salgPermissions, String count, String validflag) {
        String sql = CoreXmlSqlParsersFactory
                .getSql("FrmOrderNoReport.GetQueryOrderSeqNo");
        sql += CoreConverter.toSqlConditionString("T1.SALE_ORG",
                salgPermissions);
        if (!stratTime.equals("")) {
            sql += " AND T.CREATE_TIME BETWEEN TO_DATE('" + stratTime
                    + "', 'YYYY-MM-DD HH24:MI:SS')  AND TO_DATE('" + endTime
                    + "', 'YYYY-MM-DD HH24:MI:SS')";
        }
        if (!orderNo.equals("")) {
            sql += "  AND T1.ORDER_NO LIKE '%'||'" + orderNo + "'||'%'";
        }
        if (count.equals("2")) {
            if (orderStrats.equals("")) {
                sql += " AND T.ORDER_LN_STATUS >='12020802'";
            }
            else {
                sql += " AND T.ORDER_LN_STATUS ='" + orderStrats + "'";
            }
            sql += "  AND T.VALIDFLAG='1'";
//            sql += "  AND T1.VALIDFLAG='1'";
        }
        else {
            if (orderStrats.equals("")) {
                sql += "  AND T.ORDER_LN_STATUS IN ('12020301','12020302')";
                sql += "  AND T.VALIDFLAG='1'";
//                sql += "  AND T1.VALIDFLAG='1'";
            }
            else {
                if (orderStrats.equals("1")) {
                    sql += " AND T.ORDER_LN_STATUS IN ('12020301','12020302')";
                    sql += "  AND T.VALIDFLAG='0'";
//                    sql += "  AND T1.VALIDFLAG='0'";
                }
                else {
                    sql += " AND T.ORDER_LN_STATUS ='" + orderStrats + "'";
                    sql += "  AND T.VALIDFLAG='1'";
//                    sql += "  AND T1.VALIDFLAG='1'";
                }

            }
        }
//        if (validflag.equals("0")) {
//            sql += "  AND T1.VALIDFLAG IN ('0','1')";
//        }else{
//            sql += "  AND T1.VALIDFLAG ='1'";
//        }
        sql += " ORDER BY T1.ORDER_NO , T.ORDER_SEQ ASC";
        return this.getData(sql);
    }

    /**
     * 查询注销单
     * @param strWhere
     * @return
     */
    public CoreReturnObject getDoQueryRev(String[] salgPermissions) {
        String sql = CoreXmlSqlParsersFactory
                .getSql("FrmOrderNoReport.getDoQueryRev");
        sql += CoreConverter.toSqlConditionString("T.REVIEW_STATUS",
                salgPermissions);
        sql += " GROUP BY T.REVIEW_NO,T.REVIEW_SRC,T.REVIEW_STATUS,T.REVEIW_BDATE,T.REVEIW_EDATE,"
                + "T.REVEIW_MAN,T.REVEIW_CONTENT,T.REVEIW_ASKER,T.REVEIW_ASK_TIME,T.MEMO,T.CREATE_NAME,"
                + " T.CREATE_TIME,T.UPDATE_NAME,T.UPDATE_TIME";
        sql += " ORDER BY T.CREATE_TIME DESC";
        return this.getData(sql);
    }

    // /**
    // * 查询合同行信息
    // *
    // * @param strWhere
    // * @return
    // */
    // public CoreReturnObject getQueryOrderSeqNo(String ordPk) {
    // String sql = CoreXmlSqlParsersFactory
    // .getSql("FrmOrderNoReport.GetQueryOrderSeqNo");
    // return this.getData(sql, new Object[] { ordPk });
    // }

    /**
     * 修改注销单打印时间
     * @param strWhere
     * @return
     */
    public CoreReturnObject queryLogOutNo(String time, String logOutNo) {
        String sql = CoreXmlSqlParsersFactory
                .getSql("FrmOrderNoReport.QueryLogOutNo");
        return this.setData(sql, new Object[] { time, logOutNo });
    }

    /**
     * 修改注销单打印时间
     * @param strWhere
     * @return
     */
    public CoreReturnObject updateLogoutState(String time, String orderNo) {
        String sql = CoreXmlSqlParsersFactory
                .getSql("FrmOrderNoReport.updateLogoutState");
        return this.setData(sql, new Object[] { time, orderNo });
    }

    /**
     * 获取合同行状态
     * @param strWhere
     * @return
     */
    public CoreReturnObject getQueryOrderStrats(String orderStrats,
            String baseCode, String falg) {
        String sql = CoreXmlSqlParsersFactory
                .getSql("FrmOrderNoReport.GetQueryOrderStrats");
        if (baseCode.equals("12020101")) {
            sql += "  AND T.BASECODE<'12020401'";
        }
        if (falg.equals("1")) {
            sql += "   AND T.BASECODE NOT IN ('12020701', '12020801','12020901')";
        }
        sql += "   ORDER BY T.BASECODE";
        return this.getData(sql, new Object[] { orderStrats, baseCode });
    }

    /**
     * 查询余量
     * @param strWhere
     * @return
     */
    public CoreReturnObject getQueryLogoutNo(String ordLnPk) {
        String sql = CoreXmlSqlParsersFactory
                .getSql("FrmOrderNoReport.GetQueryLogoutNo");
        return this.getData(sql, new Object[] { ordLnPk });
    }

    /**
     * 提单是否结算
     * @param strWhere
     * @return
     */
    public CoreReturnObject getQueryBillJs(String ordLiPk) {
        String sql = CoreXmlSqlParsersFactory
                .getSql("FrmOrderNoReport.GetQueryBillJs");
        return this.getData(sql, new Object[] { ordLiPk });
    }

    /**
     * 合同状态确认
     * @param list 传递参数
     * @return obj
     */
    @SuppressWarnings("unchecked")
    public CoreReturnObject updateOrderStrats(ArrayList<Object> pram) {
        CoreReturnObject cro = new CoreReturnObject();
        Connection connection = this.getDao(CoreConstantData.sysbeanstr)
                .getConnection();
        try {
            connection.setAutoCommit(false); // 取消自动提交事务
            String sqlOrdLnPk = CoreXmlSqlParsersFactory
                    .getSql("FrmOrderNoReport.UpdateOrdLnPk");// 修改合同行状态
            PreparedStatement psupdate = connection
                    .prepareStatement(sqlOrdLnPk);
            String sqlOrdPk = CoreXmlSqlParsersFactory
                    .getSql("FrmOrderNoReport.UpdateOrdPk");// 修改合同头信息
            PreparedStatement psOrdPk = connection.prepareStatement(sqlOrdPk);

            for (int i = 0; i < pram.size(); i++) {
                ArrayList<String> list = (ArrayList<String>) pram.get(i);
                String ordPk = list.get(0);
                String ordLnPk = list.get(1);
                // String fq = list.get(2);// 发齐
                String jq = list.get(3);// 结齐
                String name = list.get(4);
                String time = list.get(5);
                String orderTyp = list.get(7);//合同类型
                String strats = "";
                String stratsName = "";

                // 判断合同行是否缴库完毕
                int countStatus = 0;
                String sqlquery = CoreXmlSqlParsersFactory
                        .getSql("FrmOrderNoReport.QueryOrdLnPk");
                PreparedStatement psta = connection.prepareStatement(sqlquery);
                psta.setObject(1, ordLnPk);
                ResultSet rs = psta.executeQuery();
                if (rs.next()) {
                    countStatus = Integer.parseInt(rs
                            .getString("ORDER_LN_STATUS"));
                }
                rs.close();
                psta.close();
                if (countStatus < 12020602 && !"120102".equals(orderTyp)) {
                    cro.setV_errMsg("合同行状态未到缴库完毕，不能修改！");
                    return cro;
                }
                if("120102".equals(orderTyp) && countStatus < 12020301){
                    cro.setV_errMsg("现货合同合同行状态未到生效，不能修改！");
                    return cro;
                }
                if (countStatus == 12020901) {
                    cro.setV_errMsg("合同行已结案，不能修改！");
                    return cro;
                }
                if (countStatus >= 12021001) {
                    cro.setV_errMsg("合同行封锁，不能修改！");
                    return cro;
                }

                if (jq.equals("OK")) {
                    strats = "12020802";
                    stratsName = "结齐";
                }
                else {
                    strats = "12020702";
                    stratsName = "发齐";
                }
                psupdate.setObject(1, strats);
                psupdate.setObject(2, name);
                psupdate.setObject(3, time);
                psupdate.setObject(4, ordLnPk);
                psupdate.setObject(5, list.get(6));
                psupdate.addBatch();
                psupdate.executeBatch();

                // 判断合同行是否全部发齐或结齐
                int count = 0;
                String orderLnStatus = "";
                sqlquery = CoreXmlSqlParsersFactory
                        .getSql("FrmOrderNoReport.QueryOrdPk");
                psta = connection.prepareStatement(sqlquery);
                psta.setObject(1, ordPk);
                rs = psta.executeQuery();
                if (rs.next()) {
                    count = Integer.parseInt(rs.getString("COUNT"));
                    if (count == 0) {
                        cro.setV_errMsg("合同信息发生变化！");
                        return cro;
                    }
                    orderLnStatus = rs.getString("ORDER_LN_STATUS");
                }
                rs.close();
                psta.close();
                if (count == 1 && orderLnStatus == strats) {
                    psOrdPk.setObject(1, strats);
                    psOrdPk.setObject(2, stratsName);
                    psOrdPk.setObject(3, name);
                    psOrdPk.setObject(4, time);
                    psOrdPk.setObject(5, ordPk);
                    psOrdPk.addBatch();
                    psOrdPk.executeBatch();
                }
            }

            cro.setV_errMsg("修改成功!");
            cro.setResult(1);
            connection.commit();
        }
        catch (Exception e) {
            cro.setV_errMsg(e.getMessage());
            cro.setV_errCode(-1);
            if (connection != null) {
                try {
                    connection.rollback(); // 回滚事务
                }
                catch (Exception e2) {
                }
            }
        }
        finally {
            try {
                if (connection != null && !connection.isClosed()) {
                    connection.close();
                }
            }
            catch (Exception e2) {
            }
        }
        return cro;
    }
    
    /**
     * 合同状态确认
     * @param list 传递参数
     * @return obj
     */
    @SuppressWarnings("unchecked")
    public CoreReturnObject forceUpdateStrats(ArrayList<Object> pram) {
        CoreReturnObject cro = new CoreReturnObject();
        Connection connection = this.getDao(CoreConstantData.sysbeanstr)
                .getConnection();
        try {
            connection.setAutoCommit(false); // 取消自动提交事务
            String sqlOrdLnPk = CoreXmlSqlParsersFactory
                    .getSql("FrmOrderNoReport.UpdateOrdLnPk");// 修改合同行状态
            PreparedStatement psupdate = connection
                    .prepareStatement(sqlOrdLnPk);
            String sqlOrdPk = CoreXmlSqlParsersFactory
                    .getSql("FrmOrderNoReport.UpdateOrdPk");// 修改合同头信息
            PreparedStatement psOrdPk = connection.prepareStatement(sqlOrdPk);

            for (int i = 0; i < pram.size(); i++) {
                ArrayList<String> list = (ArrayList<String>) pram.get(i);
                String ordPk = list.get(0);
                String ordLnPk = list.get(1);
                // String fq = list.get(2);// 发齐
                String jq = list.get(3);// 结齐
                String name = list.get(4);
                String time = list.get(5);
                String strats = "";
                String stratsName = "";

                // 判断合同行是否缴库完毕
                int countStatus = 0;
                String sqlquery = CoreXmlSqlParsersFactory
                        .getSql("FrmOrderNoReport.QueryOrdLnPk");
                PreparedStatement psta = connection.prepareStatement(sqlquery);
                psta.setObject(1, ordLnPk);
                ResultSet rs = psta.executeQuery();
                if (rs.next()) {
                    countStatus = Integer.parseInt(rs
                            .getString("ORDER_LN_STATUS"));
                }
                rs.close();
                psta.close();
                if (countStatus < 12020602) {
                    cro.setV_errMsg("合同行状态未到缴库完毕，不能修改！");
                    return cro;
                }
                if (countStatus == 12020901) {
                    cro.setV_errMsg("合同行已结案，不能修改！");
                    return cro;
                }
                if (countStatus >= 12021001) {
                    cro.setV_errMsg("合同行封锁，不能修改！");
                    return cro;
                }
                strats = "12020802";
                stratsName = "结齐";
                
                psupdate.setObject(1, strats);
                psupdate.setObject(2, name);
                psupdate.setObject(3, time);
                psupdate.setObject(4, ordLnPk);
                psupdate.setObject(5, list.get(6));
                psupdate.addBatch();
                psupdate.executeBatch();

                // 判断合同行是否全部发齐或结齐
                int count = 0;
                String orderLnStatus = "";
                sqlquery = CoreXmlSqlParsersFactory
                        .getSql("FrmOrderNoReport.QueryOrdPk");
                psta = connection.prepareStatement(sqlquery);
                psta.setObject(1, ordPk);
                rs = psta.executeQuery();
                if (rs.next()) {
                    count = Integer.parseInt(rs.getString("COUNT"));
                    if (count == 0) {
                        cro.setV_errMsg("合同信息发生变化！");
                        return cro;
                    }
                    orderLnStatus = rs.getString("ORDER_LN_STATUS");
                }
                rs.close();
                psta.close();
                if (count == 1 && orderLnStatus == strats) {
                    psOrdPk.setObject(1, strats);
                    psOrdPk.setObject(2, stratsName);
                    psOrdPk.setObject(3, name);
                    psOrdPk.setObject(4, time);
                    psOrdPk.setObject(5, ordPk);
                    psOrdPk.addBatch();
                    psOrdPk.executeBatch();
                }
            }

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

    /**
     * 合同关闭
     * @param list 传递参数
     * @return obj
     */
    @SuppressWarnings("unchecked")
    public CoreReturnObject updateOrderClose(ArrayList<Object> pram) {
        CoreReturnObject cro = new CoreReturnObject();
        Connection connection = this.getDao(CoreConstantData.sysbeanstr)
                .getConnection();
        try {
            connection.setAutoCommit(false); // 取消自动提交事务
            String sqlOrdLnPk = CoreXmlSqlParsersFactory
                    .getSql("FrmOrderNoReport.UpdateOrdLnPkNo");// 修改合同行状态
            PreparedStatement psupdate = connection
                    .prepareStatement(sqlOrdLnPk);
            String sqlOrdPk = CoreXmlSqlParsersFactory
                    .getSql("FrmOrderNoReport.UpdateOrdPkNo");// 修改合同头信息
            PreparedStatement psOrdPk = connection.prepareStatement(sqlOrdPk);

            for (int i = 0; i < pram.size(); i++) {
                ArrayList<String> list = (ArrayList<String>) pram.get(i);
                String ordPk = list.get(0);
                String name = list.get(1);
                String time = list.get(2);
                String ordLnPk = list.get(3);

                // 判断合同行是否缴库完毕
                int countStatus = 0;
                String sqlquery = CoreXmlSqlParsersFactory
                        .getSql("FrmOrderNoReport.QueryOrdLnPk");
                PreparedStatement psta = connection.prepareStatement(sqlquery);
                psta.setObject(1, ordLnPk);
                ResultSet rs = psta.executeQuery();
                if (rs.next()) {
                    countStatus = Integer.parseInt(rs
                            .getString("ORDER_LN_STATUS"));
                }
                rs.close();
                psta.close();
                if (countStatus < 12020802) {
                    cro.setV_errMsg("合同不是结算完毕状态，不能关闭！");
                    return cro;
                }
                if (countStatus == 12020901) {
                    cro.setV_errMsg("合同已结案，不能重复关闭！");
                    return cro;
                }
                if (countStatus >= 12021001) {
                    cro.setV_errMsg("合同已封锁，不能重复关闭！");
                    return cro;
                }

                // 关闭合同行
                psupdate.setObject(1, "12020901");
                psupdate.setObject(2, name);
                psupdate.setObject(3, time);
                psupdate.setObject(4, ordLnPk);
                psupdate.setObject(5, "12020901");
                psupdate.setObject(6, name);
                psupdate.setObject(7, time);
                psupdate.setObject(8, ordLnPk);
                psupdate.addBatch();
                psupdate.executeBatch();

                int count = 0;
                sqlquery = CoreXmlSqlParsersFactory
                        .getSql("FrmOrderNoReport.QueryOrdNo");
                psta = connection.prepareStatement(sqlquery);
                psta.setObject(1, ordPk);
                rs = psta.executeQuery();
                if (rs.next()) {
                    count = Integer.parseInt(rs.getString("COUNT"));
                }
                rs.close();
                psta.close();

                if (count == 1) {
                    // 关闭合同
                    psOrdPk.setObject(1, "12020901");
                    psOrdPk.setObject(2, "结案");
                    psOrdPk.setObject(3, name);
                    psOrdPk.setObject(4, time);
                    psOrdPk.setObject(5, ordPk);
                    psOrdPk.addBatch();
                    psOrdPk.executeBatch();
                }
            }

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

    /**
     * 撤销合同关闭
     * @return obj
     */
    @SuppressWarnings("unchecked")
    public CoreReturnObject unOrderClose(ArrayList<Object> pram) {
        CoreReturnObject cro = new CoreReturnObject();
        Connection connection = this.getDao(CoreConstantData.sysbeanstr)
                .getConnection();
        try {
            connection.setAutoCommit(false); // 取消自动提交事务
            String sqlOrdLnPk = CoreXmlSqlParsersFactory
                    .getSql("FrmOrderNoReport.UpdateOrdLnPkNo");// 修改合同行状态
            PreparedStatement psupdate = connection
                    .prepareStatement(sqlOrdLnPk);
            String sqlOrdPk = CoreXmlSqlParsersFactory
                    .getSql("FrmOrderNoReport.UpdateOrdPkNo");// 修改合同头信息
            PreparedStatement psOrdPk = connection.prepareStatement(sqlOrdPk);

            for (int i = 0; i < pram.size(); i++) {
                ArrayList<String> list = (ArrayList<String>) pram.get(i);
                String ordPk = list.get(0);
                String name = list.get(1);
                String time = list.get(2);
                String ordLnPk = list.get(3);

                // 判断合同行是否缴库完毕
                int countStatus = 0;
                String sqlquery = CoreXmlSqlParsersFactory
                        .getSql("FrmOrderNoReport.QueryOrdLnPk");
                PreparedStatement psta = connection.prepareStatement(sqlquery);
                psta.setObject(1, ordLnPk);
                ResultSet rs = psta.executeQuery();
                if (rs.next()) {
                    countStatus = Integer.parseInt(rs
                            .getString("ORDER_LN_STATUS"));
                }
                rs.close();
                psta.close();
                if (countStatus != 12020901) {
                    cro.setV_errMsg("合同不是结案状态，无法撤销！");
                    return cro;
                }

                // 关闭合同行
                psupdate.setObject(1, "12020802");
                psupdate.setObject(2, name);
                psupdate.setObject(3, time);
                psupdate.setObject(4, ordLnPk);
                psupdate.setObject(5, "12020802");
                psupdate.setObject(6, name);
                psupdate.setObject(7, time);
                psupdate.setObject(8, ordLnPk);
                psupdate.addBatch();
                psupdate.executeBatch();

                int count = 0;
                sqlquery = CoreXmlSqlParsersFactory
                        .getSql("FrmOrderNoReport.QueryOrdNo");
                psta = connection.prepareStatement(sqlquery);
                psta.setObject(1, ordPk);
                rs = psta.executeQuery();
                if (rs.next()) {
                    count = Integer.parseInt(rs.getString("COUNT"));
                }
                rs.close();
                psta.close();

                if (count > 1) {
                    // 关闭合同
                    psOrdPk.setObject(1, "12020802");
                    psOrdPk.setObject(2, "结齐");
                    psOrdPk.setObject(3, name);
                    psOrdPk.setObject(4, time);
                    psOrdPk.setObject(5, ordPk);
                    psOrdPk.addBatch();
                    psOrdPk.executeBatch();
                }
            }

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

    
    /**
     * 合同关闭
     * @param list 传递参数
     * @return obj
     */
    @SuppressWarnings("unchecked")
    public CoreReturnObject cancelOrderClose(ArrayList<Object> pram) {
        CoreReturnObject cro = new CoreReturnObject();
        Connection connection = this.getDao(CoreConstantData.sysbeanstr)
                .getConnection();
        try {
            connection.setAutoCommit(false); // 取消自动提交事务
            String sqlOrdLnPk = CoreXmlSqlParsersFactory
                    .getSql("FrmOrderNoReport.UpdateOrdLnPkNo");// 修改合同行状态
            PreparedStatement psupdate = connection
                    .prepareStatement(sqlOrdLnPk);
            String sqlOrdPk = CoreXmlSqlParsersFactory
                    .getSql("FrmOrderNoReport.UpdateOrdPkNo");// 修改合同头信息
            PreparedStatement psOrdPk = connection.prepareStatement(sqlOrdPk);

            for (int i = 0; i < pram.size(); i++) {
                ArrayList<String> list = (ArrayList<String>) pram.get(i);
                String ordPk = list.get(0);
                String name = list.get(1);
                String time = list.get(2);
                String ordLnPk = list.get(3);

                // 判断合同行是否缴库完毕
                int countStatus = 0;
                String sqlquery = CoreXmlSqlParsersFactory
                        .getSql("FrmOrderNoReport.QueryOrdLnPk");
                PreparedStatement psta = connection.prepareStatement(sqlquery);
                psta.setObject(1, ordLnPk);
                ResultSet rs = psta.executeQuery();
                if (rs.next()) {
                    countStatus = Integer.parseInt(rs
                            .getString("ORDER_LN_STATUS"));
                }
                rs.close();
                psta.close();
                if (countStatus != 12020901) {
                    cro.setV_errMsg("合同不是已关闭状态，不能撤销关闭！");
                    return cro;
                }
                
                // 撤销关闭合同行
                psupdate.setObject(1, "12020802");
                psupdate.setObject(2, name);
                psupdate.setObject(3, time);
                psupdate.setObject(4, ordLnPk);
                psupdate.setObject(5, "12020802");
                psupdate.setObject(6, name);
                psupdate.setObject(7, time);
                psupdate.setObject(8, ordLnPk);
                psupdate.addBatch();
                psupdate.executeBatch();

                int count = 0;
                sqlquery = CoreXmlSqlParsersFactory
                        .getSql("FrmOrderNoReport.QueryOrdNo");
                psta = connection.prepareStatement(sqlquery);
                psta.setObject(1, ordPk);
                rs = psta.executeQuery();
                if (rs.next()) {
                    count = Integer.parseInt(rs.getString("COUNT"));
                }
                rs.close();
                psta.close();

                if (count != 1) {
                    // 关闭合同
                    psOrdPk.setObject(1, "12020802");
                    psOrdPk.setObject(2, "结齐");
                    psOrdPk.setObject(3, name);
                    psOrdPk.setObject(4, time);
                    psOrdPk.setObject(5, ordPk);
                    psOrdPk.addBatch();
                    psOrdPk.executeBatch();
                }
            }

            cro.setV_errMsg("撤销关闭成功!");
            cro.setResult(1);
            connection.commit();
        }
        catch (Exception e) {
            cro.setV_errMsg(e.getMessage());
            cro.setV_errCode(-1);
            if (connection != null) {
                try {
                    connection.rollback(); // 回滚事务
                }
                catch (Exception e2) {
                }
            }
        }
        finally {
            try {
                if (connection != null && !connection.isClosed()) {
                    connection.close();
                }
            }
            catch (Exception e2) {
            }
        }
        return cro;
    }
    
    /**
     * 新增合同余量
     * @param list 传递参数
     * @return obj
     */
    @SuppressWarnings("unchecked")
    public CoreReturnObject addOrderLogout(ArrayList<Object> pram) {
        CoreReturnObject cro = new CoreReturnObject();
        Connection connection = this.getDao(CoreConstantData.sysbeanstr)
                .getConnection();
        try {
            connection.setAutoCommit(false); // 取消自动提交事务
            String sqladd = CoreXmlSqlParsersFactory
                    .getSql("FrmOrderNoReport.AddOrderLogout");// 新增合同余量
            PreparedStatement psadd = connection.prepareStatement(sqladd);

            for (int i = 0; i < pram.size(); i++) {
                ArrayList<String> list = (ArrayList<String>) pram.get(i);
                String ordPk = list.get(0);
                String ordLnPk = list.get(1);
                String logoutNum = list.get(2);// 余量
                String unit = list.get(3);
                String orderNo = list.get(4).substring(0,
                        list.get(4).indexOf("/", list.get(4).indexOf("/" + 1)));
                String seqNo = list.get(4).substring(
                        list.get(4).indexOf("/") + 1, list.get(4).length());
                String name = list.get(5);
                String time = list.get(6);
                String yearMatch = list.get(7);
                // 判断合同行是否缴库完毕
                int countStatus = 0;
                String sqlquery = CoreXmlSqlParsersFactory
                        .getSql("FrmOrderNoReport.QueryOrdLnPk");
                PreparedStatement psta = connection.prepareStatement(sqlquery);
                psta.setObject(1, ordLnPk);
                ResultSet rs = psta.executeQuery();
                if (rs.next()) {
                    countStatus = Integer.parseInt(rs
                            .getString("ORDER_LN_STATUS"));
                }
                rs.close();
                psta.close();
                // if (countStatus < 12020702) {
                // cro.setV_errMsg("合同行不是发齐状态，不能新增余量！");
                // return cro;
                // }
                if (countStatus == 12020901) {
                    cro.setV_errMsg("合同行已结案，不能新增余量！");
                    return cro;
                }
                if (countStatus >= 12021001) {
                    cro.setV_errMsg("合同行封锁，不能新增余量！");
                    return cro;
                }

                psadd.setObject(1, orderNo.split("-")[orderNo.split("-").length - 1]);
                psadd.setObject(2, seqNo);
                psadd.setObject(3, orderNo);
                psadd.setObject(4, seqNo);
                psadd.setObject(5, ordPk);
                psadd.setObject(6, ordLnPk);
                psadd.setObject(7, logoutNum);
                psadd.setObject(8, unit);
                psadd.setObject(9, "");
                psadd.setObject(10, name);
                psadd.setObject(11, time);
                psadd.setObject(12, orderNo);
                psadd.setObject(13, seqNo);
                psadd.addBatch();
                psadd.executeBatch();

            }

            cro.setV_errMsg("合同余量注销成功!");
            cro.setResult(1);
            connection.commit();
        }
        catch (Exception e) {
            cro.setV_errMsg(e.getMessage());
            cro.setV_errCode(-1);
            if (connection != null) {
                try {
                    connection.rollback(); // 回滚事务
                }
                catch (Exception e2) {
                }
            }
        }
        finally {
            try {
                if (connection != null && !connection.isClosed()) {
                    connection.close();
                }
            }
            catch (Exception e2) {
            }
        }
        return cro;
    }

    /**
     * 撤销注销余量
     * @param list 传递参数
     * @return obj
     */
    @SuppressWarnings("unchecked")
    public CoreReturnObject deleteOrderLogout(ArrayList<Object> pram) {
        CoreReturnObject cro = new CoreReturnObject();
        Connection connection = this.getDao(CoreConstantData.sysbeanstr)
                .getConnection();
        try {
            connection.setAutoCommit(false); // 取消自动提交事务
            String sqladd = CoreXmlSqlParsersFactory
                    .getSql("FrmOrderNoReport.DeleteOrderLogout");// 删除余量注销
            PreparedStatement psadd = connection.prepareStatement(sqladd);

            String sqlOrdPk = CoreXmlSqlParsersFactory
                    .getSql("FrmOrderNoReport.UpdateOrdPk");// 修改合同头信息
            PreparedStatement psOrdPk = connection.prepareStatement(sqlOrdPk);

            for (int i = 0; i < pram.size(); i++) {
                ArrayList<String> list = (ArrayList<String>) pram.get(i);
                // String ordPk = list.get(0);
                String ordLnPk = list.get(1);
                String logoutNo = list.get(2);
                String name = list.get(3);
                String time = list.get(4);
                // 判断合同行是否缴库完毕
                int countStatus = 0;
                String sqlquery = CoreXmlSqlParsersFactory
                        .getSql("FrmOrderNoReport.QueryOrdLnPk");
                PreparedStatement psta = connection.prepareStatement(sqlquery);
                psta.setObject(1, ordLnPk);
                ResultSet rs = psta.executeQuery();
                if (rs.next()) {
                    countStatus = Integer.parseInt(rs
                            .getString("ORDER_LN_STATUS"));
                }
                rs.close();
                psta.close();
                if (countStatus >= 12020901) {
                    cro.setV_errMsg("合同行已结案，不能撤销余量！");
                    return cro;
                }
                // if (countStatus >=12021001) {
                // cro.setV_errMsg("合同行封锁，不能新增余量！");
                // return cro;
                // }

                psadd.setObject(1, logoutNo);
                psadd.addBatch();


            }
            psadd.executeBatch();

            // 修改合同状态
            String sqlOrdLnPk = CoreXmlSqlParsersFactory
                    .getSql("FrmOrderNoReport.UpdateOrdLnPkNo");// 修改合同行状态
            PreparedStatement psupdate = connection
                    .prepareStatement(sqlOrdLnPk);
            for (int i = 0; i < pram.size(); i++) {
                ArrayList<String> list = (ArrayList<String>) pram.get(i);
                // String ordPk = list.get(0);
                String ordLnPk = list.get(1);
                String logoutNo = list.get(2);
                String name = list.get(3);
                String time = list.get(4);
                String orderTyp = list.get(5);
                // 查询余量注销表数据
                String no = "";
                String sqlqueryLogoutNo = CoreXmlSqlParsersFactory
                        .getSql("FrmOrderNoReport.GetQueryLogoutNo");
                PreparedStatement pst = connection.prepareStatement(sqlqueryLogoutNo);
                pst.setObject(1, ordLnPk);
                ResultSet prs = pst.executeQuery();
                if (prs.next()) {
                    no = prs.getString("LOGOUT_NO");
                }
                prs.close();
                // 为空修改合同状态
                if(StringUtils.isEmpty(no)) {
                    String orderState = "12020602";
                    String stratsName = "缴库完毕";
                    if("120102".equals(orderTyp)){
                        orderState = "12020301";
                        stratsName = "生效";
                    }
                    psupdate.setObject(1, orderState);
                    psupdate.setObject(2, name);
                    psupdate.setObject(3, time);
                    psupdate.setObject(4, ordLnPk);
                    psupdate.setObject(5, orderState);
                    psupdate.setObject(6, name);
                    psupdate.setObject(7, time);
                    psupdate.setObject(8, ordLnPk);
                    psupdate.addBatch();

                    psOrdPk.setObject(1, orderState);
                    psOrdPk.setObject(2, stratsName);
                    psOrdPk.setObject(3, name);
                    psOrdPk.setObject(4, time);
                    psOrdPk.setObject(5, ordLnPk.substring(0,32));
                    psOrdPk.addBatch();
                }
                psOrdPk.executeBatch();
            }
            psupdate.executeBatch();
            cro.setV_errMsg("撤销注销成功!");
            cro.setResult(1);
            connection.commit();
        }
        catch (Exception e) {
            cro.setV_errMsg(e.getMessage());
            cro.setV_errCode(-1);
            if (connection != null) {
                try {
                    connection.rollback(); // 回滚事务
                }
                catch (Exception e2) {
                }
            }
        }
        finally {
            try {
                if (connection != null && !connection.isClosed()) {
                    connection.close();
                }
            }
            catch (Exception e2) {
            }
        }
        return cro;
    }

    /**
     * 合同注销
     * @param list 传递参数
     * @return obj
     */
    @SuppressWarnings("unchecked")
    public CoreReturnObject updateOrderZx(ArrayList<Object> pram) {
        CoreReturnObject cro = new CoreReturnObject();
        Connection connection = this.getDao(CoreConstantData.sysbeanstr)
                .getConnection();
        try {
            connection.setAutoCommit(false); // 取消自动提交事务
            String sqlOrdLnPk = CoreXmlSqlParsersFactory
                    .getSql("FrmOrderNoReport.UpdateOrderSeqZx");// 修改合同行有效标志
            PreparedStatement psupdate = connection
                    .prepareStatement(sqlOrdLnPk);
            String sqlOrdPk = CoreXmlSqlParsersFactory
                    .getSql("FrmOrderNoReport.UpdateOrderZx");// 修改合同有效标志
            PreparedStatement psOrdPk = connection.prepareStatement(sqlOrdPk);
            for (int i = 0; i < pram.size(); i++) {
                ArrayList<String> list = (ArrayList<String>) pram.get(i);
                String ordPk = list.get(0);
                String name = list.get(1);
                String time = list.get(2);
                String ordLnPk = list.get(3);
                // 是否存在库存
                int count = 0;
                String sqlquery = CoreXmlSqlParsersFactory
                        .getSql("FrmOrderNoReport.QueryOrderMatNo");
                PreparedStatement psta = connection.prepareStatement(sqlquery);
                psta.setObject(1, ordLnPk);
                ResultSet rs = psta.executeQuery();
                if (rs.next()) {
                    count = Integer.parseInt(rs.getString("COUNT"));
                }
                rs.close();
                psta.close();
                if (count != 0) {
                    cro.setV_errMsg("您选择的合同行存在库存,请先脱单！");
                    return cro;
                }

                // 注销合同行
                psupdate.setObject(1, "0");
                psupdate.setObject(2, name);
                psupdate.setObject(3, time);
                psupdate.setObject(4, ordLnPk);
                psupdate.setObject(5, "0");
                psupdate.setObject(6, name);
                psupdate.setObject(7, time);
                psupdate.setObject(8, ordLnPk);
                psupdate.addBatch();
                psupdate.executeBatch();

                int countHt = 0;
                sqlquery = CoreXmlSqlParsersFactory
                        .getSql("FrmOrderNoReport.QueryOrdNo");
                psta = connection.prepareStatement(sqlquery);
                psta.setObject(1, ordPk);
                rs = psta.executeQuery();
                if (rs.next()) {
                    countHt = Integer.parseInt(rs.getString("COUNT"));
                }
                rs.close();
                psta.close();
                if (countHt == 0) {
                    psOrdPk.setObject(1, "0");
                    psOrdPk.setObject(2, name);
                    psOrdPk.setObject(3, time);
                    psOrdPk.setObject(4, ordPk);
                    psOrdPk.addBatch();
                    psOrdPk.executeBatch();
                }

            }

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

    /**
     * 撤销合同注销
     * @param list 传递参数
     * @return obj
     */
    @SuppressWarnings("unchecked")
    public CoreReturnObject deleteOrderZx(ArrayList<Object> pram) {
        CoreReturnObject cro = new CoreReturnObject();
        Connection connection = this.getDao(CoreConstantData.sysbeanstr)
                .getConnection();
        try {
            connection.setAutoCommit(false); // 取消自动提交事务
            String sqlOrdLnPk = CoreXmlSqlParsersFactory
                    .getSql("FrmOrderNoReport.UpdateOrderSeqZx");// 修改合同行有效标志
            PreparedStatement psupdate = connection
                    .prepareStatement(sqlOrdLnPk);
            String sqlOrdPk = CoreXmlSqlParsersFactory
                    .getSql("FrmOrderNoReport.UpdateOrderZx");// 修改合同有效标志
            PreparedStatement psOrdPk = connection.prepareStatement(sqlOrdPk);
            for (int i = 0; i < pram.size(); i++) {
                ArrayList<String> list = (ArrayList<String>) pram.get(i);
                String ordPk = list.get(0);
                String ordLnPk = list.get(3);
                // String name = list.get(1);
                // String time = list.get(2);
                // //是否存在库存
                // int count = 0;
                // String sqlquery = CoreXmlSqlParsersFactory
                // .getSql("FrmOrderNoReport.QueryOrderMatNo");
                // PreparedStatement psta =
                // connection.prepareStatement(sqlquery);
                // psta.setObject(1, ordPk);
                // ResultSet rs = psta.executeQuery();
                // if (rs.next()) {
                // count = Integer.parseInt(rs.getString("COUNT"));
                // }
                // rs.close();
                // psta.close();
                // if (count != 0) {
                // cro.setV_errMsg("您选择的合同存在库存,请先脱单！");
                // return cro;
                // }

                // 撤销注销合同
                psupdate.setObject(1, "1");
                psupdate.setObject(2, "");
                psupdate.setObject(3, "");
                psupdate.setObject(4, ordLnPk);
                psupdate.setObject(5, "1");
                psupdate.setObject(6, "");
                psupdate.setObject(7, "");
                psupdate.setObject(8, ordLnPk);
                psupdate.addBatch();

                psOrdPk.setObject(1, "1");
                psOrdPk.setObject(2, "");
                psOrdPk.setObject(3, "");
                psOrdPk.setObject(4, ordPk);
                psOrdPk.addBatch();

            }
            psupdate.executeBatch();
            psOrdPk.executeBatch();
            cro.setV_errMsg("撤销注销合同成功!");
            cro.setResult(1);
            connection.commit();
        }
        catch (Exception e) {
            cro.setV_errMsg(e.getMessage());
            cro.setV_errCode(-1);
            if (connection != null) {
                try {
                    connection.rollback(); // 回滚事务
                }
                catch (Exception e2) {
                }
            }
        }
        finally {
            try {
                if (connection != null && !connection.isClosed()) {
                    connection.close();
                }
            }
            catch (Exception e2) {
            }
        }
        return cro;
    }

    /**
     * 生成注销单号
     * @param conn c
     * @param strlist 传递参数
     * @return obj
     * @throws Exception 异常处理
     */
    public String querySendSql(Connection conn, String strlist)
            throws Exception {
        String seq = "";
        PreparedStatement psta = null;
        Date dt = new Date();
        SimpleDateFormat matter1 = new SimpleDateFormat("yyyy-MM-dd");
        SimpleDateFormat matter = new SimpleDateFormat("yyyyMMdd");
        String sqlLovsqe = CoreXmlSqlParsersFactory
                .getSql("FrmOrderNoReport.queryLoagoutRev");
        psta = conn.prepareStatement(sqlLovsqe);
        psta.setString(1, strlist + matter.format(dt));
        psta.setString(2, matter1.format(dt));
        psta.setString(3, strlist);
        ResultSet rs = psta.executeQuery();
        if (rs.next()) {
            seq = rs.getString(1);
        }
        rs.close();
        psta.close();
        return seq;
    }

    /**
     * 生成注销单
     * @param list 传递参数
     * @return obj
     */
    @SuppressWarnings("unchecked")
    public CoreReturnObject doApplyReview(ArrayList<Object> pram) {
        CoreReturnObject cro = new CoreReturnObject();
        Connection connection = this.getDao(CoreConstantData.sysbeanstr)
                .getConnection();
        try {
            connection.setAutoCommit(false); // 取消自动提交事务
            String sqlOrdPk = CoreXmlSqlParsersFactory
                    .getSql("FrmOrderNoReport.AddOrderLogoutRev");// 新增注销单
            PreparedStatement psOrdPk = connection.prepareStatement(sqlOrdPk);

            String revNo = querySendSql(connection, "X");
            for (int i = 0; i < pram.size(); i++) {
                ArrayList<String> list = (ArrayList<String>) pram.get(i);
                String ordPk = list.get(0);
                String name = list.get(1);
                String time = list.get(2);
                String ordLnPk = list.get(3);
                String content = list.get(4);
                String memo = list.get(5);
                // 是否存在库存
                int count = 0;
                String sqlquery = CoreXmlSqlParsersFactory
                        .getSql("FrmOrderNoReport.QueryOrderMatNo");
                PreparedStatement psta = connection.prepareStatement(sqlquery);
                psta.setObject(1, ordLnPk);
                ResultSet rs = psta.executeQuery();
                if (rs.next()) {
                    count = Integer.parseInt(rs.getString("COUNT"));
                }
                rs.close();
                psta.close();
                if (count != 0) {
                    cro.setV_errMsg("您选择的合同行存在库存,请先脱单！");
                    return cro;
                }
                // 查询合同行是否注销
                String logoutReviNo = "";
                sqlquery = CoreXmlSqlParsersFactory
                        .getSql("FrmOrderNoReport.QueryOrdLnPk");
                psta = connection.prepareStatement(sqlquery);
                psta.setObject(1, ordLnPk);
                rs = psta.executeQuery();
                if (rs.next()) {
                    logoutReviNo = rs.getString("LOGOUT_REVIEW_NO");
                }
                rs.close();
                psta.close();
                if (logoutReviNo != null) {
                    cro.setV_errMsg("你选择的合同行已生成评审单,请重新选择!");
                    return cro;
                }
                psOrdPk.setObject(1, revNo);
                psOrdPk.setObject(2, "X");
                psOrdPk.setObject(3, ordLnPk);
                psOrdPk.setObject(4, "L");
                psOrdPk.setObject(5, time);
                psOrdPk.setObject(6, "");
                psOrdPk.setObject(7, content);
                psOrdPk.setObject(8, memo);
                psOrdPk.setObject(9, name);
                psOrdPk.setObject(10, time);
                psOrdPk.setObject(11, revNo);
                psOrdPk.setObject(12, ordLnPk);
                psOrdPk.setObject(13, ordPk);
                psOrdPk.addBatch();
            }
            psOrdPk.executeBatch();

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

    /**
     * 撤销注销单
     * @param list 传递参数
     * @return obj
     */
    @SuppressWarnings("unchecked")
    public CoreReturnObject unApplyReview(ArrayList<Object> pram) {
        CoreReturnObject cro = new CoreReturnObject();
        Connection connection = this.getDao(CoreConstantData.sysbeanstr)
                .getConnection();
        try {
            connection.setAutoCommit(false); // 取消自动提交事务
            String sqlOrdPk = CoreXmlSqlParsersFactory
                    .getSql("FrmOrderNoReport.deleteRevNo");// 撤销注销单
            PreparedStatement psOrdPk = connection.prepareStatement(sqlOrdPk);
            String updateOrdLnPk = CoreXmlSqlParsersFactory
                    .getSql("FrmOrderNoReport.updateOrdLnPkRevNo");// 修改合同行注销单
            PreparedStatement pstaOrdLnPk = connection
                    .prepareStatement(updateOrdLnPk);
            for (int i = 0; i < pram.size(); i++) {
                ArrayList<String> list = (ArrayList<String>) pram.get(i);
                String revNo = list.get(0);
                String revSrc = list.get(1);
                // 查询是注销单状态
                ArrayList<SlmOrderLogoutReviewEntity> ordLnPk = new ArrayList<SlmOrderLogoutReviewEntity>();
                String sqlquery = CoreXmlSqlParsersFactory
                        .getSql("FrmOrderNoReport.queryLoagoutRevStart");
                PreparedStatement psta = connection.prepareStatement(sqlquery);
                psta.setObject(1, revNo);
                psta.setObject(2, revSrc);
                ResultSet rs = psta.executeQuery();
                ordLnPk = EntityTool.getEntitysByRs(rs,
                        SlmOrderLogoutReviewEntity.class);

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

                for (SlmOrderLogoutReviewEntity ordLnPkNo : ordLnPk) {
                    if (!ordLnPkNo.getReviewStatus().equals("L")) {
                        cro.setV_errMsg("您选择的评审单不是封锁状态,不能撤销！");
                        return cro;
                    }
                    pstaOrdLnPk.setObject(1, "");
                    pstaOrdLnPk.setObject(2, ordLnPkNo.getOrdLnPk());
                    pstaOrdLnPk.addBatch();
                }
                pstaOrdLnPk.executeBatch();

                psOrdPk.setObject(1, revNo);
                psOrdPk.addBatch();
            }

            psOrdPk.executeBatch();

            cro.setV_errMsg("撤销评审单成功!");
            cro.setResult(1);
            connection.commit();
        }
        catch (Exception e) {
            cro.setV_errMsg(e.getMessage());
            cro.setV_errCode(-1);
            if (connection != null) {
                try {
                    connection.rollback(); // 回滚事务
                }
                catch (Exception e2) {
                }
            }
        }
        finally {
            try {
                if (connection != null && !connection.isClosed()) {
                    connection.close();
                }
            }
            catch (Exception e2) {
            }
        }
        return cro;
    }

    /**
     * 提报
     * @param list 传递参数
     * @return obj
     */
    @SuppressWarnings("unchecked")
    public CoreReturnObject dosubmission(ArrayList<Object> pram) {
        CoreReturnObject cro = new CoreReturnObject();
        Connection connection = this.getDao(CoreConstantData.sysbeanstr)
                .getConnection();
        try {
            connection.setAutoCommit(false); // 取消自动提交事务
            String sqlOrdPk = CoreXmlSqlParsersFactory
                    .getSql("FrmOrderNoReport.UpdateRevNo");// 修改注销单
            PreparedStatement psOrdPk = connection.prepareStatement(sqlOrdPk);
            for (int i = 0; i < pram.size(); i++) {
                ArrayList<String> list = (ArrayList<String>) pram.get(i);
                String revNo = list.get(0);
                String revSrc = list.get(1);
                String user = list.get(2);
                String time = list.get(3);
                // 查询是注销单状态
                ArrayList<SlmOrderLogoutReviewEntity> ordLnPk = new ArrayList<SlmOrderLogoutReviewEntity>();
                String sqlquery = CoreXmlSqlParsersFactory
                        .getSql("FrmOrderNoReport.queryLoagoutRevStart");
                PreparedStatement psta = connection.prepareStatement(sqlquery);
                psta.setObject(1, revNo);
                psta.setObject(2, revSrc);
                ResultSet rs = psta.executeQuery();
                ordLnPk = EntityTool.getEntitysByRs(rs,
                        SlmOrderLogoutReviewEntity.class);

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

                for (SlmOrderLogoutReviewEntity ordLnPkNo : ordLnPk) {
                    if (!ordLnPkNo.getReviewStatus().equals("L")) {
                        cro.setV_errMsg("您选择的评审单不是封锁状态,不能提报！");
                        return cro;
                    }
                }
                psOrdPk.setObject(1, "W");
                psOrdPk.setObject(2, user);
                psOrdPk.setObject(3, time);
                psOrdPk.setObject(4, user);
                psOrdPk.setObject(5, time);
                psOrdPk.setObject(6, revNo);
                psOrdPk.addBatch();
            }

            psOrdPk.executeBatch();

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

    /**
     *撤销 提报
     * @param list 传递参数
     * @return obj
     */
    @SuppressWarnings("unchecked")
    public CoreReturnObject unsubmission(ArrayList<Object> pram) {
        CoreReturnObject cro = new CoreReturnObject();
        Connection connection = this.getDao(CoreConstantData.sysbeanstr)
                .getConnection();
        try {
            connection.setAutoCommit(false); // 取消自动提交事务
            String sqlOrdPk = CoreXmlSqlParsersFactory
                    .getSql("FrmOrderNoReport.UpdateRevNo");// 修改注销单
            PreparedStatement psOrdPk = connection.prepareStatement(sqlOrdPk);
            for (int i = 0; i < pram.size(); i++) {
                ArrayList<String> list = (ArrayList<String>) pram.get(i);
                String revNo = list.get(0);
                String revSrc = list.get(1);
                String user = list.get(2);
                String time = list.get(3);
                // 查询是注销单状态
                ArrayList<SlmOrderLogoutReviewEntity> ordLnPk = new ArrayList<SlmOrderLogoutReviewEntity>();
                String sqlquery = CoreXmlSqlParsersFactory
                        .getSql("FrmOrderNoReport.queryLoagoutRevStart");
                PreparedStatement psta = connection.prepareStatement(sqlquery);
                psta.setObject(1, revNo);
                psta.setObject(2, revSrc);
                ResultSet rs = psta.executeQuery();
                ordLnPk = EntityTool.getEntitysByRs(rs,
                        SlmOrderLogoutReviewEntity.class);

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

                for (SlmOrderLogoutReviewEntity ordLnPkNo : ordLnPk) {
                    if (!ordLnPkNo.getReviewStatus().equals("W")) {
                        cro.setV_errMsg("您选择的评审单不是待审状态,不能撤销提报！");
                        return cro;
                    }
                }
                psOrdPk.setObject(1, "L");
                psOrdPk.setObject(2, "");
                psOrdPk.setObject(3, "");
                psOrdPk.setObject(4, user);
                psOrdPk.setObject(5, time);
                psOrdPk.setObject(6, revNo);
                psOrdPk.addBatch();
            }

            psOrdPk.executeBatch();

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