1
81041
2019-06-20 ab3c4acf83f54f8449ca8664c4a2bb79bd30f297
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
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 dayflow=0;
                try {
                    while(rs.next()){
                        
                        int dayflows=rs.getInt("dayflow");
                        // 年份,季度,月份
                        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)){
                            dayflow+=dayflows;
                        }else{
                            if(perid_Time.equals("")){
                                 perid_Time=perid_Times;
                                 dayflow+=dayflows;
                                 continue;
                            }
                            Stationtraffic st=new Stationtraffic();
                            st.setDev_id(rs.getInt("dev_id"));
                            st.setDayflow(dayflow);
                            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);
                            dayflow=0;
                            dayflow+=dayflows;
                            perid_Time=perid_Times;
                            
                        }
                    if(rs.isLast()){
                        Stationtraffic st=new Stationtraffic();
                        st.setDev_id(rs.getInt("dev_id"));
                        st.setDayflow(dayflow);
                        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);
        }
}
}