New file |
| | |
| | | package com.fgkj.dao.impl;
|
| | |
|
| | | import java.sql.ResultSet;
|
| | | import java.sql.SQLException;
|
| | | import java.text.ParseException;
|
| | | import java.text.SimpleDateFormat;
|
| | | import java.util.ArrayList;
|
| | | import java.util.Calendar;
|
| | | import java.util.Date;
|
| | | import java.util.List;
|
| | |
|
| | | import com.fgkj.actions.ActionUtil;
|
| | | import com.fgkj.dao.BaseDAO;
|
| | | import com.fgkj.dao.CallBack;
|
| | | import com.fgkj.dao.DAOHelper;
|
| | | import com.fgkj.db.DBUtil;
|
| | | import com.fgkj.dto.Stationtraffic;
|
| | | import com.sun.org.apache.bcel.internal.generic.IINC;
|
| | |
|
| | | public class StationtrafficImpl 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 Stationtraffic straffic=(Stationtraffic) obj;
|
| | | String sql=" select distinct tb_stationtraffic.num,dev_id,record_time,dayflow,nowflow" +
|
| | | " ,tb_battinf.StationId,tb_battinf.stationName,tb_battinf.stationName1,tb_battinf.stationName2,tb_battinf.stationName3,tb_battinf.stationName5 " +
|
| | | " from web_site.tb_stationtraffic,db_battinf.tb_battinf " +
|
| | | " where web_site.tb_stationtraffic.dev_id=db_battinf.tb_battinf.fBSDeviceId " +
|
| | | " and record_time>? and record_time<? " +
|
| | | " and dev_id=? " ;
|
| | | //用户管理
|
| | | String userSql=" 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=? "+
|
| | | " ) "; |
| | | sql+=userSql;
|
| | | String orderSql=" order by dev_id,record_time asc ";
|
| | | sql+=orderSql;
|
| | | List list=DAOHelper.executeQuery(sql, DBUtil.getConn(), new Object[]{straffic.getRecord_time(),straffic.getRecord_time1(),straffic.getDev_id(),Integer.parseInt(straffic.getNote())}, new CallBack() {
|
| | | |
| | | public List getResults(ResultSet rs) {
|
| | | List list=new ArrayList();
|
| | | // 时间段
|
| | | String perid_Time = ""; |
| | | Calendar now = Calendar.getInstance();
|
| | | int nowflow=0;
|
| | | try {
|
| | | while(rs.next()){
|
| | | |
| | | int nowflows=rs.getInt("nowflow");
|
| | | // 年份,季度,月份
|
| | | Date dev_recordtime = rs.getTimestamp("record_time");
|
| | | // 获取具体年份,月份和该月的总天数
|
| | | /*int year = dev_recordtime.getYear() + 1900;
|
| | | int month = dev_recordtime.getMonth() + 1;*/
|
| | | now.setTime(dev_recordtime);
|
| | | int year = now.get(Calendar.YEAR);
|
| | | int month = now.get(Calendar.MONTH) + 1; // 0-based!
|
| | | int day = now.get(Calendar.DAY_OF_MONTH);
|
| | | //System.out.println(dev_recordtime+" "+day);
|
| | | String perid_Times="";
|
| | | if(straffic.getNum()==1){//月统计
|
| | | perid_Times = ActionUtil.getFirstDayOfMonth(year, month - 1);
|
| | | perid_Times += "~";
|
| | | perid_Times += ActionUtil.getLastDayOfMonth(year, month - 1);
|
| | | }else if (straffic.getNum()==3) {// 按年份
|
| | | perid_Times = ActionUtil.getFirstDayOfMonth(year, 0);
|
| | | perid_Times += "~";
|
| | | perid_Times += ActionUtil.getLastDayOfMonth(year, 11);
|
| | | }else if(straffic.getNum()==2){ //日统计
|
| | | perid_Times = ActionUtil.getDayTime(year, month-1, day, 1);
|
| | | perid_Times += "~";
|
| | | perid_Times += ActionUtil.getDayTime(year, month-1, day, 4);
|
| | | }
|
| | | //System.out.println(perid_Times+" "+perid_Time+" "+nowflows);
|
| | | if(perid_Times.equals(perid_Time)){
|
| | | nowflow+=nowflows;
|
| | | }else{
|
| | | if(perid_Time.equals("")){
|
| | | perid_Time=perid_Times;
|
| | | nowflow+=nowflows;
|
| | | continue;
|
| | | }
|
| | | Stationtraffic st=new Stationtraffic();
|
| | | st.setDev_id(rs.getInt("dev_id"));
|
| | | st.setNowflow(nowflow);
|
| | | st.setStationName(rs.getString("stationName"));
|
| | | st.setStationName1(rs.getString("stationName1"));
|
| | | st.setStationName2(rs.getString("stationName2"));
|
| | | st.setStationName3(rs.getString("stationName3"));
|
| | | st.setStationName5(rs.getString("stationName5"));
|
| | | st.setNote(perid_Time);
|
| | | list.add(st);
|
| | | nowflow=0;
|
| | | nowflow+=nowflows;
|
| | | perid_Time=perid_Times;
|
| | | |
| | | }
|
| | | if(rs.isLast()){
|
| | | Stationtraffic st=new Stationtraffic();
|
| | | st.setDev_id(rs.getInt("dev_id"));
|
| | | st.setNowflow(nowflow);
|
| | | st.setStationName(rs.getString("stationName"));
|
| | | st.setStationName1(rs.getString("stationName1"));
|
| | | st.setStationName2(rs.getString("stationName2"));
|
| | | st.setStationName3(rs.getString("stationName3"));
|
| | | st.setStationName5(rs.getString("stationName5"));
|
| | | st.setNote(perid_Time);
|
| | | list.add(st);
|
| | | }
|
| | | }
|
| | | |
| | | } catch (SQLException e) {
|
| | | // TODO Auto-generated catch block
|
| | | e.printStackTrace();
|
| | | }
|
| | | return list;
|
| | | }
|
| | | });
|
| | | return list;
|
| | | }
|
| | |
|
| | | public List serchByInfo(Object obj) {
|
| | | // TODO Auto-generated method stub
|
| | | return null;
|
| | | }
|
| | | public static void main(String[] args) throws ParseException {
|
| | | StationtrafficImpl simpl=new StationtrafficImpl();
|
| | | 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");
|
| | | |
| | | Stationtraffic st=new Stationtraffic();
|
| | | st.setNum(3);
|
| | | st.setDev_id(910000001);
|
| | | st.setNote("1002");
|
| | | st.setRecord_time(ActionUtil.getSimpDate(date1));
|
| | | st.setRecord_time1(ActionUtil.getSimpDate(date2));
|
| | | List<Stationtraffic> list=simpl.serchByCondition(st);
|
| | | for (Stationtraffic s : list) {
|
| | | System.out.println(s);
|
| | | }
|
| | | }
|
| | | }
|