whychdw
2020-04-20 bb577c3e96fc3cb91f27ed5e5d096702598534c5
Merge branch 'dev_lxw' of http://whychdw@118.89.139.230:10101/r/~whyclxw/gx_tieta.git into dev_lxw
2个文件已修改
1529 ■■■■ 已修改文件
gx_tieta/src/com/fgkj/dao/DAOHelper.java 675 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
gx_tieta/src/com/fgkj/dao/impl/Bts_station_eventImpl.java 854 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
gx_tieta/src/com/fgkj/dao/DAOHelper.java
@@ -1,337 +1,338 @@
package com.fgkj.dao;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
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;
import java.util.List;
import com.fgkj.db.DBUtil;
import com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException;
/**
 *
 * 数据库操作相关的封装类,封装了所有的增删改以及查询的操作
 * @author Administrator
 *
 */
public class DAOHelper {
    public static SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    public static SimpleDateFormat sdfwithOut=new SimpleDateFormat("yyyy-MM-dd");
    /**
     * 封装所有更新的操作(添加,删除,修改)
     * @param conn
     * @param sql
     * @param values
     * @return
     */
    public static boolean executeUpdate(Connection conn,String sql,Object[] values){
        //System.out.println("释放之前************");
        //DBUtil.getConnections();
        PreparedStatement ps = null;
        try {
            ps = conn.prepareStatement(sql);
            if(values != null){
                for (int i = 0; i < values.length; i++) {
                    ps.setObject(i+1, values[i]);
                }
            }
            int flag =  ps.executeUpdate();
            if(flag>0){
                return true;
            }
        }catch (MySQLSyntaxErrorException e) {
            e.printStackTrace();
            //System.out.println("权限不足");
        } catch (SQLException e) {
            e.printStackTrace();
        }finally{
            DBUtil.close(null, ps, conn);
            //System.out.println("释放之后++++++++++++");
            //DBUtil.getConnections();
        }
        return false;
    }
    /**
     * 根据指定sql语句执行相关查询
     * @param sql        需要执行的sql查询语句
     * @param values    执行sql查询时需要的参数值
     * @param call        回调函数对象:将获取结果的任务以回调的方式交给调用者处理
     * @return
     */
    public static List executeQuery(String sql,Connection conn,Object[] values,CallBack call){
        //System.out.println("释放之前************");
        //DBUtil.getConnections();
        PreparedStatement ps = null;
        ResultSet rs = null;
        try {
            ps = conn.prepareStatement(sql);
            ps.setQueryTimeout(600);
            //当查询条件不为空时,设置查询条件对应的值
            if(values != null){
                for (int i = 0; i < values.length; i++) {
                    ps.setObject(i+1, values[i]);
                }
            }
            rs=ps.executeQuery();
            return call.getResults(rs);
        } catch (SQLException e) {
            e.printStackTrace();
        }finally{
            DBUtil.close(rs, ps, conn);
            //System.out.println("释放之后++++++++++++");
            //DBUtil.getConnections();
        }
        return null;
    }
    //对图片的更新操作(添加,删除,修改)
    public static boolean executeUpdatePicture(Connection conn,String sql,List list){
        PreparedStatement ps = null;
        InputStream in = null;
        try {
            conn.setAutoCommit(false);
            ps = conn.prepareStatement(sql);
            for (int i = 0; i < list.size(); i++) {
                Object obj=list.get(i);
                if(obj.getClass().getName().equals("java.io.File")){
                    File file=(File) obj;
                    try {
                        in = new FileInputStream(file);
                        //System.out.println(in);
                        //生成被插入文件的节点流
                        //设置Blob
                         ps.setBlob(i+1, in);
                    } catch (FileNotFoundException e) {
                        conn.rollback();
                        e.printStackTrace();
                    } catch (IOException e) {
                        conn.rollback();
                        e.printStackTrace();
                    }
                }else{
                    ps.setObject(i+1, obj);
                }
            }
            int rs =  ps.executeUpdate();
            if(rs>0){
                conn.commit();
                return true;
            }
        }catch (MySQLSyntaxErrorException e) {
            e.printStackTrace();
        } catch (SQLException e) {
            e.printStackTrace();
        }finally{
            DBUtil.close(null, ps, conn);
            if(in != null){
                try {
                    in.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
        return false;
    }
    //对图片的查询操作
    public static List executeQueryPicture(String sql,Connection conn,Object[] values,CallBack call){
        PreparedStatement ps = null;
        ResultSet rs = null;
        try {
            ps = conn.prepareStatement(sql);
            ps.setQueryTimeout(600);
            //当查询条件不为空时,设置查询条件对应的值
            if(values != null){
                for (int i = 0; i < values.length; i++) {
                    ps.setObject(i+1, values[i]);
                }
            }
            rs=ps.executeQuery();
            return call.getResults(rs);
        } catch (SQLException e) {
            e.printStackTrace();
        }finally{
            DBUtil.close(rs, ps, conn);
        }
        return null;
    }
    //用于分页的查询
    public static List executeQueryLimit(String sql,Connection conn,Object[] values,CallBack call){
        PreparedStatement ps = null;
        ResultSet rs = null;
        try {
            ps = conn.prepareStatement(sql);
            //当查询条件不为空时,设置查询条件对应的值
            if(values != null){
                for (int i = 0; i < values.length; i++) {
                    ps.setObject(i+1, values[i]);
                }
            }
            rs=ps.executeQuery();
            return call.getResults(rs);
        } catch (SQLException e) {
            e.printStackTrace();
        }finally{
            DBUtil.close(rs, ps, null);
        }
        return null;
    }
    //用于修改回滚
    public static boolean executeUpdateLimit(Connection conn,String sql,Object[] values){
        PreparedStatement ps = null;
        try {
            ps = conn.prepareStatement(sql);
            if(values != null){
                for (int i = 0; i < values.length; i++) {
                    ps.setObject(i+1, values[i]);
                }
            }
            int flag =  ps.executeUpdate();
            conn.commit();
            if(flag>0){
                return true;
            }
        }catch (MySQLSyntaxErrorException e) {
            e.printStackTrace();
        } catch (SQLException e) {
            e.printStackTrace();
        }finally{
            DBUtil.close(null, ps, null);
        }
        return false;
    }
    /**
     *
     * @param regex        SimpleDateFormat 的形式
     * @return    根据传入的regex获取的SimpleDateFormat对象
     */
    public static SimpleDateFormat getSdf(String regex){
        if(regex!=null){
            return new SimpleDateFormat(regex);
        }else{
            return  new SimpleDateFormat();
        }
    }
    public static double toFixid(Double a,long index){
        StringBuffer ms=new StringBuffer();
        if(a!=null && index>=0){
            if(index==0){
                ms=ms.append("#");
            }else{
                ms=ms.append("#.");
                for(int i=0;i<index;i++){
                    ms.append("0");
                }
            }
            //System.out.println(new DecimalFormat(ms.toString()).format(a));
            return Double.parseDouble(new DecimalFormat(ms.toString()).format(a));
        }else{
            return a;
        }
    }
    //执行sql语句
    public static boolean executeCreateTable(Connection mysql_con,String sql_str)
    {
        PreparedStatement ps=null;
        boolean rest = true;
        try
        {
            //System.out.println(sql_str);
            ps = mysql_con.prepareStatement(sql_str);
            ps.setQueryTimeout(600);
            ps.executeUpdate();
        }
        catch(SQLException ex)
        {
            //System.out.println("##########################");
            ex.printStackTrace();
            rest = false;
            DBUtil.close(null, ps, mysql_con);
        }
        return rest;
    }
    //执行sql语句with no colse
    public static boolean executeCreateTableNoclose(Connection mysql_con,String sql_str)
    {
        PreparedStatement ps=null;
        boolean rest = true;
        try
        {
            ps = mysql_con.prepareStatement(sql_str);
            ps.setQueryTimeout(600);
            ps.execute();
        }
        catch(SQLException ex)
        {
            ex.printStackTrace();
            rest = false;
        }
        return rest;
    }
    public static boolean makeManualCommit(Connection mysql_con,ArrayList<String> al_sql_strs)
    {
        //System.out.println("释放之前************");
        //DBUtil.getConnections();
        boolean exe_res = true;
        try {
            mysql_con.setAutoCommit(false);
            for(int n=0; n<al_sql_strs.size(); n++) {
                if(true == exe_res) {
                    exe_res = executeCreateTableNoclose(mysql_con,al_sql_strs.get(n));
                } else {
                    break;
                }
            }
            if(true == exe_res) {
                mysql_con.commit();
            }
        } catch (SQLException e) {
            e.printStackTrace();
            exe_res = false;
        } finally {
            try {
                if(false == exe_res) {
                    mysql_con.rollback();
                }
                mysql_con.setAutoCommit(true);
            } catch (SQLException e1) {
                e1.printStackTrace();
            } finally{
                DBUtil.close(null, null, mysql_con);
                //System.out.println("释放之后++++++++++++");
                //DBUtil.getConnections();
            }
        }
        return exe_res;
    }
    public static void main(String[] args) {
        //System.out.println(getSdf(null));
        float f=1.2546f;
        System.out.println(toFixid(new Double(f), 9));;
    }
}
package com.fgkj.dao;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
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;
import java.util.List;
import com.fgkj.db.DBUtil;
import com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException;
/**
 *
 * 数据库操作相关的封装类,封装了所有的增删改以及查询的操作
 * @author Administrator
 *
 */
public class DAOHelper {
    public static SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    public static SimpleDateFormat sdfwithOut=new SimpleDateFormat("yyyy-MM-dd");
    /**
     * 封装所有更新的操作(添加,删除,修改)
     * @param conn
     * @param sql
     * @param values
     * @return
     */
    public static boolean executeUpdate(Connection conn,String sql,Object[] values){
        //System.out.println("释放之前************");
        //DBUtil.getConnections();
        PreparedStatement ps = null;
        try {
            ps = conn.prepareStatement(sql);
            if(values != null){
                for (int i = 0; i < values.length; i++) {
                    ps.setObject(i+1, values[i]);
                }
            }
            int flag =  ps.executeUpdate();
            if(flag>0){
                return true;
            }
        }catch (MySQLSyntaxErrorException e) {
            e.printStackTrace();
            //System.out.println("权限不足");
        } catch (SQLException e) {
            e.printStackTrace();
        }finally{
            DBUtil.close(null, ps, conn);
            //System.out.println("释放之后++++++++++++");
            //DBUtil.getConnections();
        }
        return false;
    }
    /**
     * 根据指定sql语句执行相关查询
     * @param sql        需要执行的sql查询语句
     * @param values    执行sql查询时需要的参数值
     * @param call        回调函数对象:将获取结果的任务以回调的方式交给调用者处理
     * @return
     */
    public static List executeQuery(String sql,Connection conn,Object[] values,CallBack call){
        //System.out.println("释放之前************");
        //DBUtil.getConnections();
        PreparedStatement ps = null;
        ResultSet rs = null;
        try {
            ps = conn.prepareStatement(sql);
            ps.setQueryTimeout(600);
            //当查询条件不为空时,设置查询条件对应的值
            if(values != null){
                for (int i = 0; i < values.length; i++) {
                    //System.out.println(values[i]);
                    ps.setObject(i+1, values[i]);
                }
            }
            rs=ps.executeQuery();
            return call.getResults(rs);
        } catch (SQLException e) {
            e.printStackTrace();
        }finally{
            DBUtil.close(rs, ps, conn);
            //System.out.println("释放之后++++++++++++");
            //DBUtil.getConnections();
        }
        return null;
    }
    //对图片的更新操作(添加,删除,修改)
    public static boolean executeUpdatePicture(Connection conn,String sql,List list){
        PreparedStatement ps = null;
        InputStream in = null;
        try {
            conn.setAutoCommit(false);
            ps = conn.prepareStatement(sql);
            for (int i = 0; i < list.size(); i++) {
                Object obj=list.get(i);
                if(obj.getClass().getName().equals("java.io.File")){
                    File file=(File) obj;
                    try {
                        in = new FileInputStream(file);
                        //System.out.println(in);
                        //生成被插入文件的节点流
                        //设置Blob
                         ps.setBlob(i+1, in);
                    } catch (FileNotFoundException e) {
                        conn.rollback();
                        e.printStackTrace();
                    } catch (IOException e) {
                        conn.rollback();
                        e.printStackTrace();
                    }
                }else{
                    ps.setObject(i+1, obj);
                }
            }
            int rs =  ps.executeUpdate();
            if(rs>0){
                conn.commit();
                return true;
            }
        }catch (MySQLSyntaxErrorException e) {
            e.printStackTrace();
        } catch (SQLException e) {
            e.printStackTrace();
        }finally{
            DBUtil.close(null, ps, conn);
            if(in != null){
                try {
                    in.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
        return false;
    }
    //对图片的查询操作
    public static List executeQueryPicture(String sql,Connection conn,Object[] values,CallBack call){
        PreparedStatement ps = null;
        ResultSet rs = null;
        try {
            ps = conn.prepareStatement(sql);
            ps.setQueryTimeout(600);
            //当查询条件不为空时,设置查询条件对应的值
            if(values != null){
                for (int i = 0; i < values.length; i++) {
                    ps.setObject(i+1, values[i]);
                }
            }
            rs=ps.executeQuery();
            return call.getResults(rs);
        } catch (SQLException e) {
            e.printStackTrace();
        }finally{
            DBUtil.close(rs, ps, conn);
        }
        return null;
    }
    //用于分页的查询
    public static List executeQueryLimit(String sql,Connection conn,Object[] values,CallBack call){
        PreparedStatement ps = null;
        ResultSet rs = null;
        try {
            ps = conn.prepareStatement(sql);
            //当查询条件不为空时,设置查询条件对应的值
            if(values != null){
                for (int i = 0; i < values.length; i++) {
                    ps.setObject(i+1, values[i]);
                }
            }
            rs=ps.executeQuery();
            return call.getResults(rs);
        } catch (SQLException e) {
            e.printStackTrace();
        }finally{
            DBUtil.close(rs, ps, null);
        }
        return null;
    }
    //用于修改回滚
    public static boolean executeUpdateLimit(Connection conn,String sql,Object[] values){
        PreparedStatement ps = null;
        try {
            ps = conn.prepareStatement(sql);
            if(values != null){
                for (int i = 0; i < values.length; i++) {
                    ps.setObject(i+1, values[i]);
                }
            }
            int flag =  ps.executeUpdate();
            conn.commit();
            if(flag>0){
                return true;
            }
        }catch (MySQLSyntaxErrorException e) {
            e.printStackTrace();
        } catch (SQLException e) {
            e.printStackTrace();
        }finally{
            DBUtil.close(null, ps, null);
        }
        return false;
    }
    /**
     *
     * @param regex        SimpleDateFormat 的形式
     * @return    根据传入的regex获取的SimpleDateFormat对象
     */
    public static SimpleDateFormat getSdf(String regex){
        if(regex!=null){
            return new SimpleDateFormat(regex);
        }else{
            return  new SimpleDateFormat();
        }
    }
    public static double toFixid(Double a,long index){
        StringBuffer ms=new StringBuffer();
        if(a!=null && index>=0){
            if(index==0){
                ms=ms.append("#");
            }else{
                ms=ms.append("#.");
                for(int i=0;i<index;i++){
                    ms.append("0");
                }
            }
            //System.out.println(new DecimalFormat(ms.toString()).format(a));
            return Double.parseDouble(new DecimalFormat(ms.toString()).format(a));
        }else{
            return a;
        }
    }
    //执行sql语句
    public static boolean executeCreateTable(Connection mysql_con,String sql_str)
    {
        PreparedStatement ps=null;
        boolean rest = true;
        try
        {
            //System.out.println(sql_str);
            ps = mysql_con.prepareStatement(sql_str);
            ps.setQueryTimeout(600);
            ps.executeUpdate();
        }
        catch(SQLException ex)
        {
            //System.out.println("##########################");
            ex.printStackTrace();
            rest = false;
            DBUtil.close(null, ps, mysql_con);
        }
        return rest;
    }
    //执行sql语句with no colse
    public static boolean executeCreateTableNoclose(Connection mysql_con,String sql_str)
    {
        PreparedStatement ps=null;
        boolean rest = true;
        try
        {
            ps = mysql_con.prepareStatement(sql_str);
            ps.setQueryTimeout(600);
            ps.execute();
        }
        catch(SQLException ex)
        {
            ex.printStackTrace();
            rest = false;
        }
        return rest;
    }
    public static boolean makeManualCommit(Connection mysql_con,ArrayList<String> al_sql_strs)
    {
        //System.out.println("释放之前************");
        //DBUtil.getConnections();
        boolean exe_res = true;
        try {
            mysql_con.setAutoCommit(false);
            for(int n=0; n<al_sql_strs.size(); n++) {
                if(true == exe_res) {
                    exe_res = executeCreateTableNoclose(mysql_con,al_sql_strs.get(n));
                } else {
                    break;
                }
            }
            if(true == exe_res) {
                mysql_con.commit();
            }
        } catch (SQLException e) {
            e.printStackTrace();
            exe_res = false;
        } finally {
            try {
                if(false == exe_res) {
                    mysql_con.rollback();
                }
                mysql_con.setAutoCommit(true);
            } catch (SQLException e1) {
                e1.printStackTrace();
            } finally{
                DBUtil.close(null, null, mysql_con);
                //System.out.println("释放之后++++++++++++");
                //DBUtil.getConnections();
            }
        }
        return exe_res;
    }
    public static void main(String[] args) {
        //System.out.println(getSdf(null));
        float f=1.2546f;
        System.out.println(toFixid(new Double(f), 9));;
    }
}
gx_tieta/src/com/fgkj/dao/impl/Bts_station_eventImpl.java
@@ -1,426 +1,428 @@
package com.fgkj.dao.impl;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import sun.security.krb5.internal.PAEncTSEnc;
import com.fgkj.actions.ActionUtil;
import com.fgkj.dao.AlarmDaoFactory;
import com.fgkj.dao.BaseDAO;
import com.fgkj.dao.CallBack;
import com.fgkj.dao.DAOHelper;
import com.fgkj.dao.LimitNumberFactory;
import com.fgkj.db.DBUtil;
import com.fgkj.dto.BattInf;
import com.fgkj.dto.Batt_Maint_Dealarm;
import com.fgkj.dto.Batt_devalarm_data_history;
import com.fgkj.dto.Bts_station_event;
import com.fgkj.dto.Page;
import com.fgkj.dto.User_inf;
public class Bts_station_eventImpl implements BaseDAO,CallBack{
    public List getResults(ResultSet rs) {
        // TODO Auto-generated method stub
        return null;
    }
    public boolean add(Object obj) {
        // TODO Auto-generated method stub
        return false;
    }
    public boolean update(Object obj) {
        // TODO Auto-generated method stub
        return false;
    }
    public boolean del(Object obj) {
        // TODO Auto-generated method stub
        return false;
    }
    public List searchAll() {
        // TODO Auto-generated method stub
        return null;
    }
    //机房事件统计
    public List serchByCondition(Object obj) {
        final BattInf binf=(BattInf) obj;
        //System.out.println(binf);
        String sql="select distinct station_id,dev_id,station_event_type,record_datetime,station_event_trig ,tb_battinf.StationName,tb_battinf.StationName1,tb_battinf.StationName2,tb_battinf.StationName3,tb_battinf.StationName5 " +
                " from db_alarm.tb_bts_station_event,db_battinf.tb_battinf " +
                " where  tb_bts_station_event.dev_id=tb_battinf.FBSDeviceId " +
                " and db_battinf.tb_battinf.StationId in (" +
                " select distinct db_user.tb_user_battgroup_baojigroup_battgroup.StationId from db_user.tb_user_battgroup_baojigroup_battgroup,db_user.tb_user_battgroup_baojigroup_usr where db_user.tb_user_battgroup_baojigroup_battgroup.baoji_group_id=db_user.tb_user_battgroup_baojigroup_usr.baoji_group_id  and db_user.tb_user_battgroup_baojigroup_usr.uId=?" +
                " ) " +
                " and  record_datetime>=?  and  record_datetime<=?  " +
                " and stationname1 like ? and stationname2 like  ? and stationname3 like ? and stationname5 like ? " ;//stationid like ?
        //设备id
        String dev_idT="  and  tb_battinf.FBSDeviceId!=? ";
        String dev_idF="  and  tb_battinf.FBSDeviceId=? ";
        if(binf.getFBSDeviceId()==0){
            sql+=dev_idT;
        }else{
            sql+=dev_idF;
        }
        /*//事件筛选
        String eventSqlT=" and station_event_type!=? ";
        String eventSqlF=" and station_event_type=? ";
        if(binf.getNum()==0){
            sql+=eventSqlT;
        }else{
            sql+=eventSqlF;
        }*/
        //事件唯一
        String onlySql=" and station_event_trig=1 ";
        sql+=onlySql;
        //排序
        String orderSql="  order by dev_id,record_datetime,station_event_type asc  ";
        sql+=orderSql;
        //System.err.println(sql);
        List list=DAOHelper.executeQuery(sql, DBUtil.getConn(), new Object[]{binf.getNum(),binf.getBattInUseDate(),binf.getBattInUseDate1(),"%"+binf.getStationName1()+"%","%"+binf.getStationName2()+"%","%"+binf.getStationName3()+"%","%"+binf.getStationName5()+"%","%"+binf.getFBSDeviceId()+"%"}, new CallBack() {
            public List getResults(ResultSet rs) {
                List list=new ArrayList();
                int STATION_EVENT_TYPE_POFF=0;               //基站停电
                int STATION_EVENT_TYPE_XUHANG=0;             //基站续航
                int STATION_EVENT_TYPE_FADIAN=0;             //基站发电
                int STATION_EVENT_TYPE_DOOROPEN=0;           //基站开门
                int STATION_EVENT_TYPE_DIAOZHAN=0;           //基站掉站
                int STATION_EVENT_TYPE_TEMPUP=0;             //基站温度上限
                int STATION_EVENT_TYPE_TEMPLOW=0;            //基站温度下限
                int STATION_EVENT_TYPE_DAMPUP=0;             //基站湿度上限
                int STATION_EVENT_TYPE_DAMPLOW=0;            //基站湿度下限
                int dev_id=0;
                int alm_type=0;
                // 时间段
                String perid_Time = "";
                //机房名称
                String stationName="";
                try {
                    while(rs.next()){
                        int dev_ids=rs.getInt("dev_id");
                        int alm_types=rs.getInt("station_event_type");
                        String stationNames=rs.getString("stationName");
                        // 年份,季度,月份
                        Date dev_recordtime = rs.getTimestamp("record_datetime");
                        // 获取具体年份,月份和该月的总天数
                        int year = dev_recordtime.getYear() + 1900;
                        int month = dev_recordtime.getMonth() + 1;
                        String perid_Times="";
                        if(binf.getBattGroupNum()==1){//月统计
                            perid_Times = ActionUtil.getFirstDayOfMonth(year, month - 1);
                            perid_Times += "~";
                            perid_Times += ActionUtil.getLastDayOfMonth(year, month - 1);
                        }else if (binf.getBattGroupNum()==3) {// 按年份
                            perid_Times = ActionUtil.getFirstDayOfMonth(year, 0);
                            perid_Times += "~";
                            perid_Times += ActionUtil.getLastDayOfMonth(year, 11);
                        }
                        if(perid_Times.equals(perid_Time)){
                            if(dev_ids==dev_id){
                                    if(alm_types==AlarmDaoFactory.STATION_EVENT_TYPE_POFF){
                                        STATION_EVENT_TYPE_POFF+=1;
                                    }else if(alm_types==AlarmDaoFactory.STATION_EVENT_TYPE_XUHANG){
                                        STATION_EVENT_TYPE_XUHANG+=1;
                                    }else if(alm_types==AlarmDaoFactory.STATION_EVENT_TYPE_FADIAN){
                                        STATION_EVENT_TYPE_FADIAN+=1;
                                    }else if(alm_types==AlarmDaoFactory.STATION_EVENT_TYPE_DIAOZHAN){
                                        STATION_EVENT_TYPE_DIAOZHAN+=1;
                                    }else if(alm_types==AlarmDaoFactory.STATION_EVENT_TYPE_DOOROPEN){
                                        STATION_EVENT_TYPE_DOOROPEN+=1;
                                    }else if(alm_types==AlarmDaoFactory.STATION_EVENT_TYPE_TEMPUP){
                                        STATION_EVENT_TYPE_TEMPUP+=1;
                                    }else if(alm_types==AlarmDaoFactory.STATION_EVENT_TYPE_TEMPLOW){
                                        STATION_EVENT_TYPE_TEMPLOW+=1;
                                    }else if(alm_types==AlarmDaoFactory.STATION_EVENT_TYPE_DAMPUP){
                                        STATION_EVENT_TYPE_DAMPUP+=1;
                                    }else if(alm_types==AlarmDaoFactory.STATION_EVENT_TYPE_DAMPLOW){
                                        STATION_EVENT_TYPE_DAMPLOW+=1;
                                    }
                            }else{
                                Bts_station_event bevent=new Bts_station_event();
                                bevent.setStationName(stationName);
                                bevent.setDev_id(dev_id);
                                bevent.setStation_event_type_xuhang(STATION_EVENT_TYPE_XUHANG);
                                bevent.setStation_event_type_poff(STATION_EVENT_TYPE_POFF);
                                bevent.setStation_event_type_fadian(STATION_EVENT_TYPE_FADIAN);
                                bevent.setStation_event_type_diaozhan(STATION_EVENT_TYPE_DIAOZHAN);
                                bevent.setStation_event_type_dooropen(STATION_EVENT_TYPE_DOOROPEN);
                                bevent.setStation_event_type_tempup(STATION_EVENT_TYPE_TEMPUP);
                                bevent.setStation_event_type_templow(STATION_EVENT_TYPE_TEMPLOW);
                                bevent.setStation_event_type_dampup(STATION_EVENT_TYPE_DAMPUP);
                                bevent.setNote(String.valueOf(STATION_EVENT_TYPE_DAMPLOW));
                                bevent.setNote(perid_Time);
                                list.add(bevent);
                                stationName=stationNames;
                                dev_id=dev_ids;
                                STATION_EVENT_TYPE_POFF=0;
                                STATION_EVENT_TYPE_XUHANG=0;
                                STATION_EVENT_TYPE_FADIAN=0;
                                STATION_EVENT_TYPE_DIAOZHAN=0;
                                STATION_EVENT_TYPE_DOOROPEN=0;
                                STATION_EVENT_TYPE_TEMPUP    =0;        //基站温度上限告警
                                STATION_EVENT_TYPE_TEMPLOW   = 0;        //基站温度下限告警
                                STATION_EVENT_TYPE_DAMPUP    = 0;        //基站湿度上限告警
                                STATION_EVENT_TYPE_DAMPLOW   = 0;        //基站湿度下限告警
                                if(alm_types==AlarmDaoFactory.STATION_EVENT_TYPE_POFF){
                                    STATION_EVENT_TYPE_POFF+=1;
                                }else if(alm_types==AlarmDaoFactory.STATION_EVENT_TYPE_XUHANG){
                                    STATION_EVENT_TYPE_XUHANG+=1;
                                }else if(alm_types==AlarmDaoFactory.STATION_EVENT_TYPE_FADIAN){
                                    STATION_EVENT_TYPE_FADIAN+=1;
                                }else if(alm_types==AlarmDaoFactory.STATION_EVENT_TYPE_DIAOZHAN){
                                    STATION_EVENT_TYPE_DIAOZHAN+=1;
                                }else if(alm_types==AlarmDaoFactory.STATION_EVENT_TYPE_DOOROPEN){
                                    STATION_EVENT_TYPE_DOOROPEN+=1;
                                }else if(alm_types==AlarmDaoFactory.STATION_EVENT_TYPE_TEMPUP){
                                    STATION_EVENT_TYPE_TEMPUP+=1;
                                }else if(alm_types==AlarmDaoFactory.STATION_EVENT_TYPE_TEMPLOW){
                                    STATION_EVENT_TYPE_TEMPLOW+=1;
                                }else if(alm_types==AlarmDaoFactory.STATION_EVENT_TYPE_DAMPUP){
                                    STATION_EVENT_TYPE_DAMPUP+=1;
                                }else if(alm_types==AlarmDaoFactory.STATION_EVENT_TYPE_DAMPLOW){
                                    STATION_EVENT_TYPE_DAMPLOW+=1;
                                }
                            }
                        }else{
                               if(perid_Time.equals("")){
                                   if(alm_types==AlarmDaoFactory.STATION_EVENT_TYPE_POFF){
                                          STATION_EVENT_TYPE_POFF+=1;
                                       }else if(alm_types==AlarmDaoFactory.STATION_EVENT_TYPE_XUHANG){
                                        STATION_EVENT_TYPE_XUHANG+=1;
                                    }else if(alm_types==AlarmDaoFactory.STATION_EVENT_TYPE_FADIAN){
                                          STATION_EVENT_TYPE_FADIAN+=1;
                                       }else if(alm_types==AlarmDaoFactory.STATION_EVENT_TYPE_DIAOZHAN){
                                          STATION_EVENT_TYPE_DIAOZHAN+=1;
                                       }else if(alm_types==AlarmDaoFactory.STATION_EVENT_TYPE_DOOROPEN){
                                          STATION_EVENT_TYPE_DOOROPEN+=1;
                                       }else if(alm_types==AlarmDaoFactory.STATION_EVENT_TYPE_TEMPUP){
                                        STATION_EVENT_TYPE_TEMPUP+=1;
                                    }else if(alm_types==AlarmDaoFactory.STATION_EVENT_TYPE_TEMPLOW){
                                        STATION_EVENT_TYPE_TEMPLOW+=1;
                                    }else if(alm_types==AlarmDaoFactory.STATION_EVENT_TYPE_DAMPUP){
                                        STATION_EVENT_TYPE_DAMPUP+=1;
                                    }else if(alm_types==AlarmDaoFactory.STATION_EVENT_TYPE_DAMPLOW){
                                        STATION_EVENT_TYPE_DAMPLOW+=1;
                                    }
                                   perid_Time=perid_Times;
                                   dev_id=dev_ids;
                                   stationName=stationNames;
                                   continue;
                                }
                               Bts_station_event bevent=new Bts_station_event();
                                bevent.setStationName(stationName);
                                bevent.setDev_id(dev_id);
                                bevent.setStation_event_type_xuhang(STATION_EVENT_TYPE_XUHANG);
                                bevent.setStation_event_type_poff(STATION_EVENT_TYPE_POFF);
                                bevent.setStation_event_type_fadian(STATION_EVENT_TYPE_FADIAN);
                                bevent.setStation_event_type_diaozhan(STATION_EVENT_TYPE_DIAOZHAN);
                                bevent.setStation_event_type_dooropen(STATION_EVENT_TYPE_DOOROPEN);
                                bevent.setStation_event_type_tempup(STATION_EVENT_TYPE_TEMPUP);
                                bevent.setStation_event_type_templow(STATION_EVENT_TYPE_TEMPLOW);
                                bevent.setStation_event_type_dampup(STATION_EVENT_TYPE_DAMPUP);
                                bevent.setNote(String.valueOf(STATION_EVENT_TYPE_DAMPLOW));
                                bevent.setNote(perid_Time);
                                //System.out.println(2+" "+dalarm.getDev_ip()+" "+dalarm.getDev_id()+" "+dalarm.getNum()+" "+dalarm.getRecord_id()+" "+dalarm.getAlm_type()+" "+dalarm.getAlm_level()+" "+dalarm.getStationName());
                                list.add(bevent);
                                STATION_EVENT_TYPE_POFF=0;
                                STATION_EVENT_TYPE_XUHANG=0;
                                STATION_EVENT_TYPE_FADIAN=0;
                                STATION_EVENT_TYPE_DIAOZHAN=0;
                                STATION_EVENT_TYPE_DOOROPEN=0;
                                STATION_EVENT_TYPE_TEMPUP    =0;        //基站温度上限告警
                                STATION_EVENT_TYPE_TEMPLOW   = 0;        //基站温度下限告警
                                STATION_EVENT_TYPE_DAMPUP    = 0;        //基站湿度上限告警
                                STATION_EVENT_TYPE_DAMPLOW   = 0;        //基站湿度下限告警
                                if(alm_types==AlarmDaoFactory.STATION_EVENT_TYPE_POFF){
                                    STATION_EVENT_TYPE_POFF+=1;
                                }else if(alm_types==AlarmDaoFactory.STATION_EVENT_TYPE_XUHANG){
                                    STATION_EVENT_TYPE_XUHANG+=1;
                                }else if(alm_types==AlarmDaoFactory.STATION_EVENT_TYPE_FADIAN){
                                    STATION_EVENT_TYPE_FADIAN+=1;
                                }else if(alm_types==AlarmDaoFactory.STATION_EVENT_TYPE_DIAOZHAN){
                                    STATION_EVENT_TYPE_DIAOZHAN+=1;
                                }else if(alm_types==AlarmDaoFactory.STATION_EVENT_TYPE_DOOROPEN){
                                    STATION_EVENT_TYPE_DOOROPEN+=1;
                                }else if(alm_types==AlarmDaoFactory.STATION_EVENT_TYPE_TEMPUP){
                                    STATION_EVENT_TYPE_TEMPUP+=1;
                                }else if(alm_types==AlarmDaoFactory.STATION_EVENT_TYPE_TEMPLOW){
                                    STATION_EVENT_TYPE_TEMPLOW+=1;
                                }else if(alm_types==AlarmDaoFactory.STATION_EVENT_TYPE_DAMPUP){
                                    STATION_EVENT_TYPE_DAMPUP+=1;
                                }else if(alm_types==AlarmDaoFactory.STATION_EVENT_TYPE_DAMPLOW){
                                    STATION_EVENT_TYPE_DAMPLOW+=1;
                                }
                                dev_id=dev_ids;
                                stationName=stationNames;
                                perid_Time=perid_Times;
                        }
                       if(rs.isLast()){
                           Bts_station_event bevent=new Bts_station_event();
                            bevent.setStationName(stationName);
                            bevent.setDev_id(dev_id);
                            bevent.setStation_event_type_xuhang(STATION_EVENT_TYPE_XUHANG);
                            bevent.setStation_event_type_poff(STATION_EVENT_TYPE_POFF);
                            bevent.setStation_event_type_fadian(STATION_EVENT_TYPE_FADIAN);
                            bevent.setStation_event_type_diaozhan(STATION_EVENT_TYPE_DIAOZHAN);
                            bevent.setStation_event_type_dooropen(STATION_EVENT_TYPE_DOOROPEN);
                            bevent.setStation_event_type_tempup(STATION_EVENT_TYPE_TEMPUP);
                            bevent.setStation_event_type_templow(STATION_EVENT_TYPE_TEMPLOW);
                            bevent.setStation_event_type_dampup(STATION_EVENT_TYPE_DAMPUP);
                            bevent.setNote(String.valueOf(STATION_EVENT_TYPE_DAMPLOW));
                            bevent.setNote(perid_Time);
                            list.add(bevent);
                        }
                    }
                } catch (SQLException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
                return list;
            }
        });
        return list;
    }
    //机房事件统计(详情)
    public List serchByInfo(Object obj) {
        Bts_station_event bevent=(Bts_station_event) obj;
        Page p=bevent.getPage();
        //Connection conn=DBUtil.getConn();
        //String numberSql=" SELECT FOUND_ROWS() number";
        //SQL_CALC_FOUND_ROWS
        String sql="select  distinct station_id,dev_id,station_event_type,record_datetime,station_event_trig ,tb_battinf.StationName,tb_battinf.StationName1,tb_battinf.StationName2,tb_battinf.StationName3 " +
                " from db_alarm.tb_bts_station_event,db_battinf.tb_battinf " +
                " where  tb_bts_station_event.dev_id=tb_battinf.FBSDeviceId " +
                "  and db_battinf.tb_battinf.StationId in (" +
                " select distinct db_user.tb_user_battgroup_baojigroup_battgroup.StationId from db_user.tb_user_battgroup_baojigroup_battgroup,db_user.tb_user_battgroup_baojigroup_usr where db_user.tb_user_battgroup_baojigroup_battgroup.baoji_group_id=db_user.tb_user_battgroup_baojigroup_usr.baoji_group_id  and db_user.tb_user_battgroup_baojigroup_usr.uId=?" +
                " ) " +
                " and dev_id=?  " +
                " and  record_datetime>=?  and  record_datetime<=? ";
        //基站状态
        String eventSqlT=" and station_event_type!=? ";
        String eventSqlF=" and station_event_type=? ";
        if(bevent.getStation_event_type()==0){
            sql+=eventSqlT;
        }else{
            sql+=eventSqlF;
        }
        //排序
        String orderSql=" order by dev_id,station_event_type,record_datetime,station_event_trig asc " ;
        sql+=orderSql;
        //分页
        //String limitSql=" limit ?,? ";
        //sql+=limitSql;
        //,(p.getPageCurr()-1)*p.getPageSize(),p.getPageSize()
        //executeQueryLimit
        List<Bts_station_event> list=DAOHelper.executeQuery(sql, DBUtil.getConn(), new Object[]{bevent.getNum(),bevent.getDev_id(),bevent.getRecord_datetime(),bevent.getRecord_datetime_end(),bevent.getStation_event_type()}, new CallBack() {
            public List getResults(ResultSet rs) {
                List list=new ArrayList();
                try {
                    while(rs.next()){
                        Bts_station_event b=new Bts_station_event();
                        b.setStation_id(rs.getInt("station_id"));
                        b.setDev_id(rs.getInt("dev_id"));
                        b.setRecord_datetime(rs.getTimestamp("record_datetime"));
                        b.setStation_event_type(rs.getInt("station_event_type"));
                        b.setStation_event_trig(rs.getInt("station_event_trig"));
                        b.setStationName(rs.getString("stationName"));
                        Page p=new Page();
                        b.setPage(p);
                        list.add(b);
                    }
                } catch (SQLException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
                return list;
            }
        });
        /*//去掉limit条件后的总数
        int number=LimitNumberFactory.GetLimtitNumber(conn, numberSql);
        //System.out.println("number: "+number);
        if(list!=null&&list.size()>0){
            list.get(list.size()-1).getPage().setPageAll(number);
        }*/
        return list;
    }
    public static void main(String[] args) throws ParseException {
        Bts_station_eventImpl bimpl=new Bts_station_eventImpl();
        Page p = new Page();
        p.setPageCurr(1);
        p.setPageSize(10);
        /*条件所存放的位置前台:tb_batt_maint_inf
         * 在线电压:usr_id
         * 组端电压:fault_type_id
         * 充电电流:fault_level
         * 放电电流:record_uid
         * 单体电压:maint_type_id
         * 单体温度:maint_done
         * 单体内阻:maint_close
         * 连接条阻抗:master_id
         * */
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date date1 = sdf.parse("2000-01-01 00:00:00");
        Date date2 = sdf.parse("2020-01-01 00:00:00");
        BattInf binf = new BattInf();
        binf.setNum(1002);
        binf.setStationName("");
        binf.setStationName1("");
        binf.setStationName2("");
        binf.setStationName3("");
        binf.setStationName5("右江区");
        binf.setStationId("42000524");
        binf.setFBSDeviceId(0);
        binf.setBattGroupNum(1);
        binf.setBattInUseDate(ActionUtil.getSimpDate(date1));
        binf.setBattInUseDate1(ActionUtil.getSimpDate(date2));
        User_inf uinf=new User_inf();
        uinf.setUId(1002);
        Batt_Maint_Dealarm bmd = new Batt_Maint_Dealarm();
        bmd.setPage(p);
        bmd.setBinf(binf);
        bmd.setUinf(uinf);
        List<Bts_station_event> list=bimpl.serchByCondition(binf);
        System.out.println(list.size());
        for (Bts_station_event b : list) {
            System.out.println(b.getNote()+" "+b.getDev_id()+" "+b.getStation_event_type_poff()+" "+b.getStation_event_type_xuhang()+" "+b.getStation_event_type_fadian()+" "+b.getStation_event_type_diaozhan()+" "+b.getStation_event_type_dooropen()+" "+b.getStation_event_type_tempup()+" "+b.getStation_event_type_templow()+" "+b.getStation_event_type_dampup()+" "+b.getStation_event_type_damplow()+" "+b.getStationName());
        }
        Bts_station_event b=new Bts_station_event();
        b.setNum(1002);
        b.setDev_id(910000534);
        b.setRecord_datetime(ActionUtil.getSimpDate(date1));
        b.setRecord_datetime_end(ActionUtil.getSimpDate(date2));
        b.setStation_event_type(0);
        Page page=new Page();
        page.setPageCurr(1);
        page.setPageSize(10);
        b.setPage(page);
        //List list=bimpl.serchByInfo(b);
        //System.out.println(list.size());
    }
}
package com.fgkj.dao.impl;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import sun.security.krb5.internal.PAEncTSEnc;
import com.fgkj.actions.ActionUtil;
import com.fgkj.dao.AlarmDaoFactory;
import com.fgkj.dao.BaseDAO;
import com.fgkj.dao.CallBack;
import com.fgkj.dao.DAOHelper;
import com.fgkj.dao.LimitNumberFactory;
import com.fgkj.db.DBUtil;
import com.fgkj.dto.BattInf;
import com.fgkj.dto.Batt_Maint_Dealarm;
import com.fgkj.dto.Batt_devalarm_data_history;
import com.fgkj.dto.Bts_station_event;
import com.fgkj.dto.Page;
import com.fgkj.dto.User_inf;
public class Bts_station_eventImpl implements BaseDAO,CallBack{
    public List getResults(ResultSet rs) {
        // TODO Auto-generated method stub
        return null;
    }
    public boolean add(Object obj) {
        // TODO Auto-generated method stub
        return false;
    }
    public boolean update(Object obj) {
        // TODO Auto-generated method stub
        return false;
    }
    public boolean del(Object obj) {
        // TODO Auto-generated method stub
        return false;
    }
    public List searchAll() {
        // TODO Auto-generated method stub
        return null;
    }
    //机房事件统计
    public List serchByCondition(Object obj) {
        BattInf binf=(BattInf) obj;
        final int type=binf.getBattGroupNum();
        //System.out.println(binf);
        String sql="select distinct station_id,dev_id,station_event_type,record_datetime,station_event_trig ,tb_battinf.StationName,tb_battinf.StationName1,tb_battinf.StationName2,tb_battinf.StationName3,tb_battinf.StationName5 " +
                " from db_alarm.tb_bts_station_event,db_battinf.tb_battinf " +
                " where  tb_bts_station_event.dev_id=tb_battinf.FBSDeviceId " +
                " and db_battinf.tb_battinf.StationId in (" +
                " select distinct db_user.tb_user_battgroup_baojigroup_battgroup.StationId from db_user.tb_user_battgroup_baojigroup_battgroup,db_user.tb_user_battgroup_baojigroup_usr where db_user.tb_user_battgroup_baojigroup_battgroup.baoji_group_id=db_user.tb_user_battgroup_baojigroup_usr.baoji_group_id  and db_user.tb_user_battgroup_baojigroup_usr.uId=?" +
                " ) " +
                " and  record_datetime>=?  and  record_datetime<=?  " +
                " and StationName1 like ? and StationName2 like  ? and StationName3 like ? and StationName5 like ? " ;//stationid like ?
        //设备id
        String dev_idT="  and  tb_battinf.FBSDeviceId!=? ";
        String dev_idF="  and  tb_battinf.FBSDeviceId=? ";
        if(binf.getFBSDeviceId()==0){
            sql+=dev_idT;
        }else{
            sql+=dev_idF;
        }
        /*//事件筛选
        String eventSqlT=" and station_event_type!=? ";
        String eventSqlF=" and station_event_type=? ";
        if(binf.getNum()==0){
            sql+=eventSqlT;
        }else{
            sql+=eventSqlF;
        }*/
        //事件唯一
        String onlySql=" and station_event_trig=1 ";
        sql+=onlySql;
        //排序
        String orderSql="  order by dev_id,record_datetime,station_event_type asc  ";
        sql+=orderSql;
        //System.out.println(sql);
        List list=DAOHelper.executeQuery(sql, DBUtil.getConn(), new Object[]{binf.getNum(),binf.getBattInUseDate(),binf.getBattInUseDate1(),"%"+binf.getStationName1()+"%","%"+binf.getStationName2()+"%","%"+binf.getStationName3()+"%","%"+binf.getStationName5()+"%",binf.getFBSDeviceId()}, new CallBack() {
            public List getResults(ResultSet rs) {
                List list=new ArrayList();
                int STATION_EVENT_TYPE_POFF=0;               //基站停电
                int STATION_EVENT_TYPE_XUHANG=0;             //基站续航
                int STATION_EVENT_TYPE_FADIAN=0;             //基站发电
                int STATION_EVENT_TYPE_DOOROPEN=0;           //基站开门
                int STATION_EVENT_TYPE_DIAOZHAN=0;           //基站掉站
                int STATION_EVENT_TYPE_TEMPUP=0;             //基站温度上限
                int STATION_EVENT_TYPE_TEMPLOW=0;            //基站温度下限
                int STATION_EVENT_TYPE_DAMPUP=0;             //基站湿度上限
                int STATION_EVENT_TYPE_DAMPLOW=0;            //基站湿度下限
                int dev_id=0;
                int alm_type=0;
                // 时间段
                String perid_Time = "";
                //机房名称
                String stationName="";
                try {
                    while(rs.next()){
                        int dev_ids=rs.getInt("dev_id");
                        int alm_types=rs.getInt("station_event_type");
                        String stationNames=rs.getString("stationName");
                        // 年份,季度,月份
                        Date dev_recordtime = rs.getTimestamp("record_datetime");
                        // 获取具体年份,月份和该月的总天数
                        int year = dev_recordtime.getYear() + 1900;
                        int month = dev_recordtime.getMonth() + 1;
                        String perid_Times="";
                        if(type==1){//月统计
                            perid_Times = ActionUtil.getFirstDayOfMonth(year, month - 1);
                            perid_Times += "~";
                            perid_Times += ActionUtil.getLastDayOfMonth(year, month - 1);
                        }else if (type==3) {// 按年份
                            perid_Times = ActionUtil.getFirstDayOfMonth(year, 0);
                            perid_Times += "~";
                            perid_Times += ActionUtil.getLastDayOfMonth(year, 11);
                        }
                        if(perid_Times.equals(perid_Time)){
                            if(dev_ids==dev_id){
                                    if(alm_types==AlarmDaoFactory.STATION_EVENT_TYPE_POFF){
                                        STATION_EVENT_TYPE_POFF+=1;
                                    }else if(alm_types==AlarmDaoFactory.STATION_EVENT_TYPE_XUHANG){
                                        STATION_EVENT_TYPE_XUHANG+=1;
                                    }else if(alm_types==AlarmDaoFactory.STATION_EVENT_TYPE_FADIAN){
                                        STATION_EVENT_TYPE_FADIAN+=1;
                                    }else if(alm_types==AlarmDaoFactory.STATION_EVENT_TYPE_DIAOZHAN){
                                        STATION_EVENT_TYPE_DIAOZHAN+=1;
                                    }else if(alm_types==AlarmDaoFactory.STATION_EVENT_TYPE_DOOROPEN){
                                        STATION_EVENT_TYPE_DOOROPEN+=1;
                                    }else if(alm_types==AlarmDaoFactory.STATION_EVENT_TYPE_TEMPUP){
                                        STATION_EVENT_TYPE_TEMPUP+=1;
                                    }else if(alm_types==AlarmDaoFactory.STATION_EVENT_TYPE_TEMPLOW){
                                        STATION_EVENT_TYPE_TEMPLOW+=1;
                                    }else if(alm_types==AlarmDaoFactory.STATION_EVENT_TYPE_DAMPUP){
                                        STATION_EVENT_TYPE_DAMPUP+=1;
                                    }else if(alm_types==AlarmDaoFactory.STATION_EVENT_TYPE_DAMPLOW){
                                        STATION_EVENT_TYPE_DAMPLOW+=1;
                                    }
                            }else{
                                Bts_station_event bevent=new Bts_station_event();
                                bevent.setStationName(stationName);
                                bevent.setDev_id(dev_id);
                                bevent.setStation_event_type_xuhang(STATION_EVENT_TYPE_XUHANG);
                                bevent.setStation_event_type_poff(STATION_EVENT_TYPE_POFF);
                                bevent.setStation_event_type_fadian(STATION_EVENT_TYPE_FADIAN);
                                bevent.setStation_event_type_diaozhan(STATION_EVENT_TYPE_DIAOZHAN);
                                bevent.setStation_event_type_dooropen(STATION_EVENT_TYPE_DOOROPEN);
                                bevent.setStation_event_type_tempup(STATION_EVENT_TYPE_TEMPUP);
                                bevent.setStation_event_type_templow(STATION_EVENT_TYPE_TEMPLOW);
                                bevent.setStation_event_type_dampup(STATION_EVENT_TYPE_DAMPUP);
                                bevent.setNote(String.valueOf(STATION_EVENT_TYPE_DAMPLOW));
                                bevent.setNote(perid_Time);
                                list.add(bevent);
                                stationName=stationNames;
                                dev_id=dev_ids;
                                STATION_EVENT_TYPE_POFF=0;
                                STATION_EVENT_TYPE_XUHANG=0;
                                STATION_EVENT_TYPE_FADIAN=0;
                                STATION_EVENT_TYPE_DIAOZHAN=0;
                                STATION_EVENT_TYPE_DOOROPEN=0;
                                STATION_EVENT_TYPE_TEMPUP    =0;        //基站温度上限告警
                                STATION_EVENT_TYPE_TEMPLOW   = 0;        //基站温度下限告警
                                STATION_EVENT_TYPE_DAMPUP    = 0;        //基站湿度上限告警
                                STATION_EVENT_TYPE_DAMPLOW   = 0;        //基站湿度下限告警
                                if(alm_types==AlarmDaoFactory.STATION_EVENT_TYPE_POFF){
                                    STATION_EVENT_TYPE_POFF+=1;
                                }else if(alm_types==AlarmDaoFactory.STATION_EVENT_TYPE_XUHANG){
                                    STATION_EVENT_TYPE_XUHANG+=1;
                                }else if(alm_types==AlarmDaoFactory.STATION_EVENT_TYPE_FADIAN){
                                    STATION_EVENT_TYPE_FADIAN+=1;
                                }else if(alm_types==AlarmDaoFactory.STATION_EVENT_TYPE_DIAOZHAN){
                                    STATION_EVENT_TYPE_DIAOZHAN+=1;
                                }else if(alm_types==AlarmDaoFactory.STATION_EVENT_TYPE_DOOROPEN){
                                    STATION_EVENT_TYPE_DOOROPEN+=1;
                                }else if(alm_types==AlarmDaoFactory.STATION_EVENT_TYPE_TEMPUP){
                                    STATION_EVENT_TYPE_TEMPUP+=1;
                                }else if(alm_types==AlarmDaoFactory.STATION_EVENT_TYPE_TEMPLOW){
                                    STATION_EVENT_TYPE_TEMPLOW+=1;
                                }else if(alm_types==AlarmDaoFactory.STATION_EVENT_TYPE_DAMPUP){
                                    STATION_EVENT_TYPE_DAMPUP+=1;
                                }else if(alm_types==AlarmDaoFactory.STATION_EVENT_TYPE_DAMPLOW){
                                    STATION_EVENT_TYPE_DAMPLOW+=1;
                                }
                            }
                        }else{
                               if(perid_Time.equals("")){
                                   if(alm_types==AlarmDaoFactory.STATION_EVENT_TYPE_POFF){
                                          STATION_EVENT_TYPE_POFF+=1;
                                       }else if(alm_types==AlarmDaoFactory.STATION_EVENT_TYPE_XUHANG){
                                        STATION_EVENT_TYPE_XUHANG+=1;
                                    }else if(alm_types==AlarmDaoFactory.STATION_EVENT_TYPE_FADIAN){
                                          STATION_EVENT_TYPE_FADIAN+=1;
                                       }else if(alm_types==AlarmDaoFactory.STATION_EVENT_TYPE_DIAOZHAN){
                                          STATION_EVENT_TYPE_DIAOZHAN+=1;
                                       }else if(alm_types==AlarmDaoFactory.STATION_EVENT_TYPE_DOOROPEN){
                                          STATION_EVENT_TYPE_DOOROPEN+=1;
                                       }else if(alm_types==AlarmDaoFactory.STATION_EVENT_TYPE_TEMPUP){
                                        STATION_EVENT_TYPE_TEMPUP+=1;
                                    }else if(alm_types==AlarmDaoFactory.STATION_EVENT_TYPE_TEMPLOW){
                                        STATION_EVENT_TYPE_TEMPLOW+=1;
                                    }else if(alm_types==AlarmDaoFactory.STATION_EVENT_TYPE_DAMPUP){
                                        STATION_EVENT_TYPE_DAMPUP+=1;
                                    }else if(alm_types==AlarmDaoFactory.STATION_EVENT_TYPE_DAMPLOW){
                                        STATION_EVENT_TYPE_DAMPLOW+=1;
                                    }
                                   perid_Time=perid_Times;
                                   dev_id=dev_ids;
                                   stationName=stationNames;
                                   continue;
                                }
                               Bts_station_event bevent=new Bts_station_event();
                                bevent.setStationName(stationName);
                                bevent.setDev_id(dev_id);
                                bevent.setStation_event_type_xuhang(STATION_EVENT_TYPE_XUHANG);
                                bevent.setStation_event_type_poff(STATION_EVENT_TYPE_POFF);
                                bevent.setStation_event_type_fadian(STATION_EVENT_TYPE_FADIAN);
                                bevent.setStation_event_type_diaozhan(STATION_EVENT_TYPE_DIAOZHAN);
                                bevent.setStation_event_type_dooropen(STATION_EVENT_TYPE_DOOROPEN);
                                bevent.setStation_event_type_tempup(STATION_EVENT_TYPE_TEMPUP);
                                bevent.setStation_event_type_templow(STATION_EVENT_TYPE_TEMPLOW);
                                bevent.setStation_event_type_dampup(STATION_EVENT_TYPE_DAMPUP);
                                bevent.setNote(String.valueOf(STATION_EVENT_TYPE_DAMPLOW));
                                bevent.setNote(perid_Time);
                                //System.out.println(2+" "+dalarm.getDev_ip()+" "+dalarm.getDev_id()+" "+dalarm.getNum()+" "+dalarm.getRecord_id()+" "+dalarm.getAlm_type()+" "+dalarm.getAlm_level()+" "+dalarm.getStationName());
                                list.add(bevent);
                                STATION_EVENT_TYPE_POFF=0;
                                STATION_EVENT_TYPE_XUHANG=0;
                                STATION_EVENT_TYPE_FADIAN=0;
                                STATION_EVENT_TYPE_DIAOZHAN=0;
                                STATION_EVENT_TYPE_DOOROPEN=0;
                                STATION_EVENT_TYPE_TEMPUP    =0;        //基站温度上限告警
                                STATION_EVENT_TYPE_TEMPLOW   = 0;        //基站温度下限告警
                                STATION_EVENT_TYPE_DAMPUP    = 0;        //基站湿度上限告警
                                STATION_EVENT_TYPE_DAMPLOW   = 0;        //基站湿度下限告警
                                if(alm_types==AlarmDaoFactory.STATION_EVENT_TYPE_POFF){
                                    STATION_EVENT_TYPE_POFF+=1;
                                }else if(alm_types==AlarmDaoFactory.STATION_EVENT_TYPE_XUHANG){
                                    STATION_EVENT_TYPE_XUHANG+=1;
                                }else if(alm_types==AlarmDaoFactory.STATION_EVENT_TYPE_FADIAN){
                                    STATION_EVENT_TYPE_FADIAN+=1;
                                }else if(alm_types==AlarmDaoFactory.STATION_EVENT_TYPE_DIAOZHAN){
                                    STATION_EVENT_TYPE_DIAOZHAN+=1;
                                }else if(alm_types==AlarmDaoFactory.STATION_EVENT_TYPE_DOOROPEN){
                                    STATION_EVENT_TYPE_DOOROPEN+=1;
                                }else if(alm_types==AlarmDaoFactory.STATION_EVENT_TYPE_TEMPUP){
                                    STATION_EVENT_TYPE_TEMPUP+=1;
                                }else if(alm_types==AlarmDaoFactory.STATION_EVENT_TYPE_TEMPLOW){
                                    STATION_EVENT_TYPE_TEMPLOW+=1;
                                }else if(alm_types==AlarmDaoFactory.STATION_EVENT_TYPE_DAMPUP){
                                    STATION_EVENT_TYPE_DAMPUP+=1;
                                }else if(alm_types==AlarmDaoFactory.STATION_EVENT_TYPE_DAMPLOW){
                                    STATION_EVENT_TYPE_DAMPLOW+=1;
                                }
                                dev_id=dev_ids;
                                stationName=stationNames;
                                perid_Time=perid_Times;
                        }
                       if(rs.isLast()){
                           Bts_station_event bevent=new Bts_station_event();
                            bevent.setStationName(stationName);
                            bevent.setDev_id(dev_id);
                            bevent.setStation_event_type_xuhang(STATION_EVENT_TYPE_XUHANG);
                            bevent.setStation_event_type_poff(STATION_EVENT_TYPE_POFF);
                            bevent.setStation_event_type_fadian(STATION_EVENT_TYPE_FADIAN);
                            bevent.setStation_event_type_diaozhan(STATION_EVENT_TYPE_DIAOZHAN);
                            bevent.setStation_event_type_dooropen(STATION_EVENT_TYPE_DOOROPEN);
                            bevent.setStation_event_type_tempup(STATION_EVENT_TYPE_TEMPUP);
                            bevent.setStation_event_type_templow(STATION_EVENT_TYPE_TEMPLOW);
                            bevent.setStation_event_type_dampup(STATION_EVENT_TYPE_DAMPUP);
                            bevent.setNote(String.valueOf(STATION_EVENT_TYPE_DAMPLOW));
                            bevent.setNote(perid_Time);
                            list.add(bevent);
                        }
                    }
                } catch (SQLException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
                return list;
            }
        });
        return list;
    }
    //机房事件统计(详情)
    public List serchByInfo(Object obj) {
        Bts_station_event bevent=(Bts_station_event) obj;
        Page p=bevent.getPage();
        //Connection conn=DBUtil.getConn();
        //String numberSql=" SELECT FOUND_ROWS() number";
        //SQL_CALC_FOUND_ROWS
        String sql="select  distinct station_id,dev_id,station_event_type,record_datetime,station_event_trig ,tb_battinf.StationName,tb_battinf.StationName1,tb_battinf.StationName2,tb_battinf.StationName3 " +
                " from db_alarm.tb_bts_station_event,db_battinf.tb_battinf " +
                " where  tb_bts_station_event.dev_id=tb_battinf.FBSDeviceId " +
                "  and db_battinf.tb_battinf.StationId in (" +
                " select distinct db_user.tb_user_battgroup_baojigroup_battgroup.StationId from db_user.tb_user_battgroup_baojigroup_battgroup,db_user.tb_user_battgroup_baojigroup_usr where db_user.tb_user_battgroup_baojigroup_battgroup.baoji_group_id=db_user.tb_user_battgroup_baojigroup_usr.baoji_group_id  and db_user.tb_user_battgroup_baojigroup_usr.uId=?" +
                " ) " +
                " and dev_id=?  " +
                " and  record_datetime>=?  and  record_datetime<=? ";
        //基站状态
        String eventSqlT=" and station_event_type!=? ";
        String eventSqlF=" and station_event_type=? ";
        if(bevent.getStation_event_type()==0){
            sql+=eventSqlT;
        }else{
            sql+=eventSqlF;
        }
        //排序
        String orderSql=" order by dev_id,station_event_type,record_datetime,station_event_trig asc " ;
        sql+=orderSql;
        //分页
        //String limitSql=" limit ?,? ";
        //sql+=limitSql;
        //,(p.getPageCurr()-1)*p.getPageSize(),p.getPageSize()
        //executeQueryLimit
        List<Bts_station_event> list=DAOHelper.executeQuery(sql, DBUtil.getConn(), new Object[]{bevent.getNum(),bevent.getDev_id(),bevent.getRecord_datetime(),bevent.getRecord_datetime_end(),bevent.getStation_event_type()}, new CallBack() {
            public List getResults(ResultSet rs) {
                List list=new ArrayList();
                try {
                    while(rs.next()){
                        Bts_station_event b=new Bts_station_event();
                        b.setStation_id(rs.getInt("station_id"));
                        b.setDev_id(rs.getInt("dev_id"));
                        b.setRecord_datetime(rs.getTimestamp("record_datetime"));
                        b.setStation_event_type(rs.getInt("station_event_type"));
                        b.setStation_event_trig(rs.getInt("station_event_trig"));
                        b.setStationName(rs.getString("stationName"));
                        Page p=new Page();
                        b.setPage(p);
                        list.add(b);
                    }
                } catch (SQLException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
                return list;
            }
        });
        /*//去掉limit条件后的总数
        int number=LimitNumberFactory.GetLimtitNumber(conn, numberSql);
        //System.out.println("number: "+number);
        if(list!=null&&list.size()>0){
            list.get(list.size()-1).getPage().setPageAll(number);
        }*/
        return list;
    }
    public static void main(String[] args) throws ParseException {
        Bts_station_eventImpl bimpl=new Bts_station_eventImpl();
        Page p = new Page();
        p.setPageCurr(1);
        p.setPageSize(10);
        /*条件所存放的位置前台:tb_batt_maint_inf
         * 在线电压:usr_id
         * 组端电压:fault_type_id
         * 充电电流:fault_level
         * 放电电流:record_uid
         * 单体电压:maint_type_id
         * 单体温度:maint_done
         * 单体内阻:maint_close
         * 连接条阻抗:master_id
         * */
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date date1 = sdf.parse("2000-01-01 00:00:00");
        Date date2 = sdf.parse("2020-01-01 00:00:00");
        BattInf binf = new BattInf();
        binf.setNum(1018);
        binf.setStationName("");
        binf.setStationName1("广西省");
        binf.setStationName2("崇左");
        binf.setStationName3("GX崇左濑湍全凤");
        binf.setStationName5("江州区");
        binf.setStationId("42000164");
        binf.setFBSDeviceId(910000174);
        binf.setBattGroupNum(3);
        //System.out.println(ActionUtil.getSimpDate(date1));
        binf.setBattInUseDate(ActionUtil.getSimpDate(date1));
        binf.setBattInUseDate1(ActionUtil.getSimpDate(date2));
        User_inf uinf=new User_inf();
        uinf.setUId(1002);
        Batt_Maint_Dealarm bmd = new Batt_Maint_Dealarm();
        bmd.setPage(p);
        bmd.setBinf(binf);
        bmd.setUinf(uinf);
        List<Bts_station_event> list=bimpl.serchByCondition(binf);
        System.out.println(list.size());
        for (Bts_station_event b : list) {
            System.out.println(b.getNote()+" "+b.getDev_id()+" "+b.getStation_event_type_poff()+" "+b.getStation_event_type_xuhang()+" "+b.getStation_event_type_fadian()+" "+b.getStation_event_type_diaozhan()+" "+b.getStation_event_type_dooropen()+" "+b.getStation_event_type_tempup()+" "+b.getStation_event_type_templow()+" "+b.getStation_event_type_dampup()+" "+b.getStation_event_type_damplow()+" "+b.getStationName());
        }
        /*Bts_station_event b=new Bts_station_event();
        b.setNum(1002);
        b.setDev_id(910000534);
        b.setRecord_datetime(ActionUtil.getSimpDate(date1));
        b.setRecord_datetime_end(ActionUtil.getSimpDate(date2));
        b.setStation_event_type(0);
        Page page=new Page();
        page.setPageCurr(1);
        page.setPageSize(10);
        b.setPage(page);
        List list=bimpl.serchByInfo(b);
        System.out.println(list.size());*/
    }
}