package com.steering.pss.ydm.pipeleavefactory;

import CoreFS.SA06.CoreReturnObject;
import CoreFS.SA08.CoreXmlSqlParsersFactory;
import CoreFS.SC01.CoreConstantData;
import com.steering.comm.converter.CoreConverter;
import com.steering.comm.db.DBCommon;
import com.steering.comm.tools.StringTool;
import com.steering.pss.ydm.entity.YdmZcSendplanCEntity;
import com.steering.pss.ydm.entity.YdmZcSendplanMEntity;
import net.sf.json.JSONObject;

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

/**
 * 铁运出厂月计划
 * @author Administrator 2015-06-15
 */
public class FrmPipeTrainMonth extends DBCommon {

    /**
     * 库存量可编制量
     * @param list 参数
     * @return obj
     */
    public CoreReturnObject queryMatPlan(ArrayList<String> list) {
        return this.getDataBySqlID("FrmPipeTrainMonth.QueryMatPlan", list
                .toArray());
    }

    /**
     * 查询主表发货计划状态
     * @param list 参数
     * @return obj
     */
    public CoreReturnObject queryPlanState(ArrayList<String> list) {
        return this.getDataBySqlID("FrmPipeTrainMonth.QueryPlanState", list
                .toArray());
    }
    /**
     * 查询计划向下的提单状态
     * @param list 参数
     * @return obj
     */
    public CoreReturnObject querySendPlanBillM(String sendNo) {
        return this.getDataBySqlID("FrmPipeTrainMonth.querySendPlanBillM", new Object[]{sendNo});
    }
    /**
     * 查询可发货资源主信息
     * @param list 查询参数
     * @return obj
     */
    public CoreReturnObject queryOrderInfo(ArrayList<Object> params,
            String spclNO, String staintNo, String reviaNo,
            String[] salgs,String supplyUnit,String orderStart,String orderEnd) {
        String sql = CoreXmlSqlParsersFactory
                .getSql("FrmPipeTrainMonth.queryOrderInfo");
        if (!spclNO.equals("")) {
            sql += "  AND T.SPCL_LN_NO='" + spclNO + "'";
        }
        if (!staintNo.equals("")) {
            sql += "  AND T.STATION_NO='" + staintNo + "'";
        }
        if (!reviaNo.equals("")) {
            sql += "  AND T.CUSTOMER_NO='" + reviaNo + "'";
        }
        if (!orderStart.equals("")) {
            sql += "  AND T.DELVRY_EDATE BETWEEN '" +orderStart+ "' and '"+ orderEnd +"' ";
        }
        if(supplyUnit.equals("120501"))
        {
            //sql += " AND (T.SUPPLY_UNIT = '"+supplyUnit+"' OR T.SUPPLY_UNIT IS NULL)";
        }else if(supplyUnit.equals("120504")){
            sql += " AND T.SUPPLY_UNIT = '"+supplyUnit+"'";
        }
//        if (tryptrNo.equals("0")) {
//            sql += "  AND T.PRD_CLS !='405005'";
//        }
//        else {
//            sql += "  AND T.PRD_CLS ='" + tryptrNo + "'";
//        }
        sql += " AND (" + CoreConverter.toSqlConditionString1("T.CREATE_DEPT", salgs);
        sql += " OR " + CoreConverter.toSqlConditionString1("T.DOCUMENTARY_DEPT", salgs) + ")" ;
        sql += " GROUP BY T.CUSTOMER_NO,T.CUSTOMER_NM,T.TRANSIT_TYP,T.RECEIV_NO,"
                + "T.RECEIV_NM,T.STATION_NO,T.STATION_NM,T.SPCL_LN_NO,T.SPCL_LN_NM,"
                + "T.SALE_ORG,T.SALE_ORG_DESC,T.CREATE_DEPT,T.DEPARTNAME,T.SUPPLY_UNIT ORDER BY T.CUSTOMER_NM ";
        return this.getData(sql, params.toArray());
    }

    /**
     * 查询发货资源子信息
     * @param list 查询参数
     * @return obj
     */
    public CoreReturnObject queryOrderInfoC(ArrayList<Object> param) {
        return this.getDataBySqlID("FrmPipeTrainMonth.queryOrderInfoC", param
                .toArray());
    }

    /**
     * 自动生成发运计划号
     * @param conn c
     * @param strlist 传递参数
     * @return obj
     * @throws Exception 异常处理
     */
    public String querySendSl(Connection conn, String strlist, String strSale)
            throws Exception {
        int seq = 0;
        PreparedStatement psta = null;
        String sqlLovsqe = CoreXmlSqlParsersFactory
                .getSql("FrmPipeTrainMonth.QuerySendSl");
        psta = conn.prepareStatement(sqlLovsqe);
        psta.setString(1, strSale);
        ResultSet rs = psta.executeQuery();
        if (rs.next()) {
            String res = rs.getString(1);
            if (res == null) {
                res = strlist + "0001";
            }
            else {
                seq = Integer.parseInt(res.substring(9, 13));
            }
        }
        rs.close();
        psta.close();
        return strlist + StringTool.formatDecimal(++seq, "0000");
    }

    /**
     * 铁运计划保存
     * @param baseList 主表数据
     * @param childList 从表数据
     * @return 执行条数
     */
    public CoreReturnObject saveYdmSendPlan(ArrayList<Object> baseList,
            ArrayList<Object> childList) {
        CoreReturnObject cro = new CoreReturnObject();
        Connection connection = this.getDao(CoreConstantData.sysbeanstr)
                .getConnection();
        PreparedStatement psta = null;
        String sqlInster = "";
        String sqlquery = "";
        try {
            connection.setAutoCommit(false); // 取消自动提交事务
            String sendPlanNo = "";
            sqlInster = CoreXmlSqlParsersFactory
                    .getSql("FrmPipeTrainMonth.ADDSENDPLANM"); // 新增到计划主表
            for (int i = 0; i < baseList.size(); i++) {
                // 将JSON字符串转化成对象
                String baseStr = baseList.get(i).toString();
                JSONObject json = JSONObject.fromObject(baseStr);
                YdmZcSendplanMEntity com = (YdmZcSendplanMEntity) JSONObject
                        .toBean(json, YdmZcSendplanMEntity.class);
                sendPlanNo = querySendSl(connection, com.getSendPlanNo(), com
                        .getSaleOrg());
                psta = connection.prepareStatement(sqlInster);
                psta.setString(1, sendPlanNo);
                psta.setString(2, com.getSaleOrg());
                psta.setString(3, com.getSaleOrgDesc());
                psta.setString(4, com.getCustomerNo());
                psta.setString(5, com.getCustomerNm());
                psta.setString(6, com.getReceivNo());
                psta.setString(7, com.getReceivNm());
                psta.setString(8, com.getTransType());
                psta.setString(9, com.getPlanYearMonth());
                psta.setString(10, com.getPlanStartTime());
                psta.setString(11, com.getPlanEndTime());
                psta.setString(12, com.getPlanWt());
                psta.setString(13, com.getPlanNum());
                psta.setString(14, com.getPlanTotlLen());
                psta.setString(15, com.getStationNo());
                psta.setString(16, com.getStationNm());
                psta.setString(17, com.getSpclLnNo());
                psta.setString(18, com.getSpclLnNm());
                psta.setString(19, com.getCreateName());
                psta.setString(20, com.getDepartmentCode());
                psta.setString(21, com.getDepartmentDesc());
                psta.setString(22, com.getManagementNo());
                psta.setString(23, com.getManagementName());
                psta.setString(24, com.getSupplyUnit());
                psta.setString(25, com.getSupplyUnitDesc());
                psta.executeUpdate();
                psta.close();
            }
            // 从表成分索引号与与之对应的序号
            for (int i = 0; i < childList.size(); i++) {
                // 将JSON字符串转化成对象
                String childStr = childList.get(i).toString();
                JSONObject json = JSONObject.fromObject(childStr);
                YdmZcSendplanCEntity comc = (YdmZcSendplanCEntity) JSONObject
                        .toBean(json, YdmZcSendplanCEntity.class);

                DecimalFormat df = new DecimalFormat("0.000");
                double pcweghit = 0;// 排产量
                double jkweghit = 0;// 缴库量
                double kcweghit = 0;// 库存量
                double weightMonth = 0;// 可编制量
                // double delvrMonth = 0;// 交货量
                // double maxDelvr = 0;// 上限值
                // double maxdelvrMonth = 0;// 交货量上限值
                double beenwt = 0;// 已编制量
                double tdwt = 0;// 提单量
//                if (comc.getPrdCls().equals("405005")) {
//                    sqlquery = CoreXmlSqlParsersFactory
//                            .getSql("FrmPipeTrainMonth.QueryMatPlan1");// 查询可编辑量
//                }
//                else {
                    sqlquery = CoreXmlSqlParsersFactory
                            .getSql("FrmPipeTrainMonth.QueryMatPlan");// 查询可编辑量
//                }
                psta = connection.prepareStatement(sqlquery);
                psta.setString(1, comc.getOrdLnDlyPk());
                ResultSet rs1 = psta.executeQuery();
                if (rs1.next()) {
                    pcweghit = Double.parseDouble(rs1.getString("PLANWEIGHT"));
                    jkweghit = Double.parseDouble(rs1
                            .getString("PAYDOWNWEIGHT"));
                    kcweghit = Double.parseDouble(rs1
                            .getString("STORAGE_COUNT"));
                    // delvrMonth = Double
                    // .parseDouble(rs1.getString("DELVRY_QTY"));
                    // maxDelvr = Double.parseDouble(rs1
                    // .getString("DELVRY_RANGE_MAX"));
                    beenwt = Double.parseDouble(rs1.getString("BEEN_WT"));
                    tdwt = Double.parseDouble(rs1.getString("ActWeightBeen"));
                }
                rs1.close();
                psta.close();

                if (pcweghit - jkweghit > 0) {
                    if (pcweghit - kcweghit - beenwt > 0) {

                        weightMonth = pcweghit - beenwt;

                    }
                    else {
                        weightMonth = kcweghit + tdwt - beenwt;
                    }
                }
                else if (pcweghit - jkweghit < 0) {
                    if (jkweghit - kcweghit - beenwt > 0) {

                        weightMonth = jkweghit - beenwt;

                    }
                    else {
                        weightMonth = kcweghit + tdwt - beenwt;
                    }
                }
                else {
                    weightMonth = kcweghit + tdwt - beenwt;
                }
                String str = df.format(weightMonth);
                // maxdelvrMonth = delvrMonth + delvrMonth * (maxDelvr / 100);
                // 计划量不能大于可编制量
                if (Double.parseDouble(str) < Double.parseDouble(comc
                        .getPlanWt())) {
                    cro.setV_errMsg("合同号为:" + comc.getOrderNo() + "、合同行号为:"
                            + comc.getOrderSeq() + "、交货行为:"
                            + comc.getDeliveryNo() + "该记录,可编制计划量为:"
                            + weightMonth + "吨,计划量大于可编制计划量,请重新输入！");
                    cro.setV_errCode(-1);
                    return cro;
                }
                sqlInster = CoreXmlSqlParsersFactory
                        .getSql("FrmPipeTrainMonth.ADDSENDPLANC"); // 新增到计划子表
                psta = connection.prepareStatement(sqlInster);
                psta.setString(1, sendPlanNo);
                psta.setString(2, comc.getOrderNo());
                psta.setString(3, comc.getOrderSeq());
                psta.setString(4, comc.getDeliveryNo());
                psta.setString(5, comc.getProduccode());
                psta.setString(6, comc.getProducname());
                psta.setString(7, comc.getPrdCls());
                psta.setString(8, comc.getPsc());
                psta.setString(9, comc.getPscDesc());
                psta.setString(10, comc.getSpecCode());
                psta.setString(11, comc.getSpecName());
                psta.setString(12, comc.getLenNo());
                psta.setString(13, comc.getLenDesc());
                psta.setString(14, comc.getPlanWt());
                psta.setString(15, comc.getPlanNum());
                psta.setString(16, comc.getPlanTotlLen());
                psta.setString(17, comc.getCreateName());
                psta.setString(18, comc.getOrdPk());
                psta.setString(19, comc.getOrdLnPk());
                psta.setString(20, comc.getOrdLnDlyPk());
                psta.setString(21, comc.getDelvryBdate());
                psta.setString(22, comc.getDelvryEdate());
                psta.executeUpdate();
                psta.close();
            }
            cro.setResult(baseList.size());
            cro.setResult(childList.size());
            connection.commit();
        }
        catch (Exception e) {
            System.out.println(e.getMessage());
            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 pram 主表数据
     * @param list 从表数据
     * @return 返回条数
     */
    public CoreReturnObject deltePlanSend(ArrayList<String> param,
            String userName) {
        CoreReturnObject core = new CoreReturnObject();
        Connection con = null;
        PreparedStatement ps = null;
        ResultSet rs = null;
        try {
            con = this.getDao(CoreConstantData.sysbeanstr).getConnection();
            con.setAutoCommit(false);
            String sql = CoreXmlSqlParsersFactory
                    .getSql("FrmPipeTrainMonth.getSendPlanStatus");
            String sqlUm = CoreXmlSqlParsersFactory
                    .getSql("FrmPipeTrainMonth.UdatePlan");
            String sqlDc = CoreXmlSqlParsersFactory
                    .getSql("FrmPipeTrainMonth.UdateSendPlan");
            for (String sendPlanNo : param) {
                ps = con.prepareStatement(sql);
                ps.setObject(1, sendPlanNo);
                rs = ps.executeQuery();
                String status = "";
                if (rs.next()) {
                    status = rs.getString("SEND_PLAN_STATUS");
                }
                rs.close();
                ps.close();
                if (!status.equals("0")) {
                    core.setV_errMsg("不是编辑的计划号,不能撤销!");
                    return core;
                }
                ps = con.prepareStatement(sqlDc);
                ps.setObject(1, sendPlanNo);
                ps.execute();
                ps.close();
                ps = con.prepareStatement(sqlUm);
                ps.setObject(1, sendPlanNo);
                ps.execute();
                ps.close();
            }
            core.setV_errMsg("撤销计划成功!");
            con.commit();
        }
        catch (SQLException e) {

            e.printStackTrace();
        }
        finally {
            if (con != null)
                try {
                    con.close();
                }
                catch (SQLException e) {
                    e.printStackTrace();
                }
        }
        return core;
    }

    /**
     * 废除出厂计划子表数据更新主表计划支、重量、长度
     * @param pram 子表数据
     * @param list 主表数据
     * @return 返回条数
     */
    public CoreReturnObject deltePlanChild(ArrayList<String> pram,
            ArrayList<String> list) {
        // sql语句
        ArrayList<String> sqllist = new ArrayList<String>();
        // 字段集合
        ArrayList<Object[]> parmlist = new ArrayList<Object[]>();
        // 删除子表信息
        sqllist.add(CoreXmlSqlParsersFactory
                .getSql("FrmPipeTrainMonth.DeltePlanSend"));
        parmlist.add(pram.toArray());
        // 更新主表信息（支、吨、米）
        sqllist.add(CoreXmlSqlParsersFactory
                .getSql("FrmPipeTrainMonth.UdateSendPlanChild"));
        parmlist.add(list.toArray());
        return this.getDao(CoreConstantData.sysbeanstr).ExcuteTransction(
                sqllist, parmlist);
    }

    /**
     * 查询出厂计划主表信息
     * @param list 查询参数
     * @return obj
     */
    public CoreReturnObject querySendPlanM(ArrayList<Object> param,
            String[] salgs,String supplyUnit) {
        String sql = CoreXmlSqlParsersFactory
                .getSql("FrmPipeTrainMonth.QuerySENDPLANM");
        if(supplyUnit.equals("120501"))
        {
            //sql += " AND (T.SUPPLY_UNIT = '"+supplyUnit+"' OR T.SUPPLY_UNIT IS NULL)";
        }else if(supplyUnit.equals("120504")){
            sql += " AND T.SUPPLY_UNIT = '"+supplyUnit+"'";
        }
        sql += CoreConverter.toSqlConditionString("T.MANAGEMENT_NO", salgs);
        sql += " ORDER BY T.SEND_PLAN_NO DESC";
        return this.getData(sql, param.toArray());
    }

    /**
     * 根据主表查询出厂计划子表信息
     * @return obj
     */
    public CoreReturnObject querySendPlanC(String sendPlanNo) {
        Object[] params = new Object[] { sendPlanNo };
        return this.getDataBySqlID("FrmPipeTrainMonth.QuerySENDPLANC", params);
    }

    /**
     * 下发计划
     * @param pram 主表数据
     * @param list 从表数据
     * @return 返回条数
     */
    public CoreReturnObject doDown(ArrayList<String> param, String userName) {
        CoreReturnObject core = new CoreReturnObject();
        Connection con = null;
        PreparedStatement ps = null;
        ResultSet rs = null;
        try {
            con = this.getDao(CoreConstantData.sysbeanstr).getConnection();
            con.setAutoCommit(false);
            String sql = CoreXmlSqlParsersFactory
                    .getSql("FrmPipeTrainMonth.getSendPlanStatus");
            String sqlUm = CoreXmlSqlParsersFactory
                    .getSql("FrmPipeTrainMonth.doDown");
            PreparedStatement psUm = con.prepareStatement(sqlUm);
            for (String sendPlanNo : param) {
                ps = con.prepareStatement(sql);
                ps.setObject(1, sendPlanNo);
                rs = ps.executeQuery();
                String status = "";
                if (rs.next()) {
                    status = rs.getString("SEND_PLAN_STATUS");
                }
                rs.close();
                ps.close();
                if (!status.equals("0")) {
                    core.setV_errMsg(sendPlanNo+"不是编辑的计划号,不能下发!");
                    return core;
                }
//                ps = con.prepareStatement(sqlUm);
//                ps.setObject(1, sendPlanNo);
//                ps.execute();
//                ps.close();
                psUm.setObject(1, sendPlanNo);
                psUm.addBatch();
                
            }
            psUm.executeBatch();
            core.setV_errMsg("下发计划成功!");
            con.commit();
        }
        catch (Exception e) {
            System.out.println(e.getMessage());
            core.setV_errMsg(e.getMessage());
            core.setV_errCode(-1);
            if (con != null) {
                try {
                    con.rollback(); // 回滚事务
                }
                catch (Exception e2) {
                }
            }
        }
        finally {
            try {
                if (con != null && !con.isClosed()) {
                    con.close();
                }
            }
            catch (Exception e2) {
            }
        }
        return core;
    }

    /**
     * 取消下发计划
     * @param pram 主表数据
     * @param list 从表数据
     * @return 返回条数
     */
    public CoreReturnObject canceldoDown(ArrayList<String> param,
            String userName) {
        CoreReturnObject core = new CoreReturnObject();
        Connection con = null;
        PreparedStatement ps = null;
        ResultSet rs = null;
        try {
            con = this.getDao(CoreConstantData.sysbeanstr).getConnection();
            con.setAutoCommit(false);
            String sql = CoreXmlSqlParsersFactory
                    .getSql("FrmPipeTrainMonth.getSendPlanStatus");
            String sqlUm = CoreXmlSqlParsersFactory
                    .getSql("FrmPipeTrainMonth.canceldoDown");
            String sqlQuery = CoreXmlSqlParsersFactory
                    .getSql("FrmPipeTrainMonth.queryBillBySendPlanNo");
            for (String sendPlanNo : param) {
                ps = con.prepareStatement(sql);
                ps.setObject(1, sendPlanNo);
                rs = ps.executeQuery();
                String status = "";
                if (rs.next()) {
                    status = rs.getString("SEND_PLAN_STATUS");
                }
                rs.close();
                ps.close();
                if (!status.equals("1")) {
                    core.setV_errMsg("不是下发的计划号,不能撤销下发!");
                    return core;
                }
                int count = 0;
                ps = con.prepareStatement(sqlQuery);
                ps.setObject(1, sendPlanNo);
                rs = ps.executeQuery();
                if (rs.next()) {
                    count = rs.getInt("COUNT");
                }
                rs.close();
                ps.close();
                if (count > 0) {
                    core.setV_errMsg("计划号" + sendPlanNo + "下存在提单号,不能撤销下发!");
                    return core;
                }
                ps = con.prepareStatement(sqlUm);
                ps.setObject(1, sendPlanNo);
                ps.execute();
                ps.close();
            }
            core.setV_errMsg("撤销下发计划成功!");
            con.commit();
        }
        catch (SQLException e) {

            e.printStackTrace();
        }
        finally {
            if (con != null)
                try {
                    con.close();
                }
                catch (SQLException e) {
                    e.printStackTrace();
                }
        }
        return core;
    }

    /**
     * 关闭计划
     * @param pram 主表数据
     * @param list 从表数据
     * @return 返回条数
     */
    public CoreReturnObject planClose(ArrayList<String> param, String userName) {
        CoreReturnObject core = new CoreReturnObject();
        Connection con = null;
        PreparedStatement ps = null;
        ResultSet rs = null;
        Date nowTime = new Date();
        SimpleDateFormat dfT = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String strNowTime = dfT.format(nowTime);
        try {
            con = this.getDao(CoreConstantData.sysbeanstr).getConnection();
            con.setAutoCommit(false);
            String sql = CoreXmlSqlParsersFactory
                    .getSql("FrmPipeTrainMonth.getSendPlanStatus");
            // String sqlBill = CoreXmlSqlParsersFactory
            // .getSql("FrmPipeTrainMonth.getBillSendStatus");
            String sqlUm = CoreXmlSqlParsersFactory
                    .getSql("FrmPipeTrainMonth.getSendPlanC");
            String updateSendM = CoreXmlSqlParsersFactory
                    .getSql("FrmPipeTrainMonth.updateSendPlanM");
            PreparedStatement psSendM = con.prepareStatement(updateSendM);
            String updateSendC = CoreXmlSqlParsersFactory
                    .getSql("FrmPipeTrainMonth.updateSendPlanC");
            PreparedStatement psSendC = con.prepareStatement(updateSendC);
            for (String sendPlanNo : param) {
                ps = con.prepareStatement(sql);
                ps.setObject(1, sendPlanNo);
                rs = ps.executeQuery();
                String status = "";
                double sendActWtM = 0;
                if (rs.next()) {
                    status = rs.getString("SEND_PLAN_STATUS");
                    sendActWtM = rs.getDouble("ACT_WT");
                }
                rs.close();
                ps.close();
                if (!status.equals("2")) {
                    core.setV_errMsg("不是执行的计划号,不能关闭!");
                    return core;
                }
                // ps = con.prepareStatement(sqlBill);
                // ps.setObject(1, sendPlanNo);
                // rs = ps.executeQuery();
                // while (rs.next()) {
                // if (Integer.parseInt(rs.getString("BILL_STATUS")) <= 3) {
                // core.setV_errMsg("" + sendPlanNo
                // + "该计划号下有提单未关闭，不能计划关闭!");
                // return core;
                // }
                // }
                // rs.close();
                // ps.close();

                double SendActWtc = 0;
                ps = con.prepareStatement(sqlUm);
                ps.setObject(1, sendPlanNo);
                rs = ps.executeQuery();
                while (rs.next()) {
                    SendActWtc = rs.getDouble("ACT_WT");
                    psSendC.setObject(1, SendActWtc);
                    psSendC.setObject(2, userName);
                    psSendC.setObject(3, strNowTime);
                    psSendC.setObject(4, sendPlanNo);
                    psSendC.setObject(5, rs.getString("ORD_LN_DLY_PK"));
                    psSendC.addBatch();
                }
                rs.close();
                ps.close();

                psSendM.setObject(1, sendActWtM);
                psSendM.setObject(2, userName);
                psSendM.setObject(3, strNowTime);
                psSendM.setObject(4, sendPlanNo);
                psSendM.addBatch();
            }
            psSendC.executeBatch();
            psSendM.executeBatch();
            core.setV_errMsg("计划关闭成功!");
            con.commit();
        }
        catch (Exception e) {
            System.out.println(e.getMessage());
            core.setV_errMsg(e.getMessage());
            core.setV_errCode(-1);
            if (con != null) {
                try {
                    con.rollback(); // 回滚事务
                }
                catch (Exception e2) {
                }
            }
        }
        finally {
            try {
                if (con != null && !con.isClosed()) {
                    con.close();
                }
            }
            catch (Exception e2) {
            }
        }
        return core;
    }
}
