admin
2023-04-12 f06a592dd1a7e995bf313ccb5efe7dff73ccfc4e
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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
package com.yeshi.buwan.controller.admin.api;
 
import java.io.IOException;
import java.io.PrintWriter;
import java.lang.reflect.Type;
import java.sql.Time;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
 
import javax.annotation.Resource;
 
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.yeshi.buwan.util.JsonUtil;
import com.yeshi.buwan.util.RedisManager;
import com.yeshi.buwan.util.log.SearchKeyLogUtil;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
 
import com.yeshi.buwan.domain.web.StatisticXY;
import com.yeshi.buwan.service.imp.StatisticsService;
import com.yeshi.buwan.service.imp.SystemService;
import com.yeshi.buwan.util.StringUtil;
import com.yeshi.buwan.util.TimeUtil;
 
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
 
@Controller
@RequestMapping("admin/new/api/statistics")
public class StatisticsController {
 
    @Resource
    private SystemService systemService;
    @Resource
    private StatisticsService statisticsService;
 
    @Resource
    private RedisManager redisManager;
 
    @RequestMapping(value = "/gettesterdaydata", method = RequestMethod.POST)
    public void getYesterdayData(String startdate, String enddate, String fastdate, int detailsystem, PrintWriter out) {
 
        startdate = StringUtil.isNullOrEmpty(startdate) ? "" : startdate;
        enddate = StringUtil.isNullOrEmpty(enddate) ? "" : enddate;
        fastdate = StringUtil.isNullOrEmpty(fastdate) ? "0" : fastdate;
        if (!"0".equalsIgnoreCase(fastdate)) {
            enddate = TimeUtil.getGernalTime(System.currentTimeMillis());
            startdate = TimeUtil.getGernalTime(
                    System.currentTimeMillis() - 24 * 60 * 60 * 1000L * (Integer.parseInt(fastdate) - 1));
        }
 
        long registerCount = statisticsService.getRegisterCount(startdate, enddate, detailsystem + "");
        long totalRegisterCount = statisticsService.getTotalRegisterCount(detailsystem + "");
        List<StatisticXY> xyList = statisticsService.getDetailSystemWatchCount(startdate, enddate, detailsystem + "");
        long watchCount = 0;
        if (xyList != null && xyList.size() > 0)
            watchCount = xyList.get(0).getY();
 
        JSONObject object = new JSONObject();
        object.put("code", 0);
        JSONObject data = new JSONObject();
        data.put("rcount", registerCount);
        data.put("trcount", totalRegisterCount);
        data.put("wcount", watchCount);
        object.put("data", data);
        out.print(object);
    }
 
    @RequestMapping(value = "/gettopplay", method = RequestMethod.POST)
    public void getTopPlay(String startdate, String enddate, String fastdate, int detailsystem, PrintWriter out) {
 
        startdate = StringUtil.isNullOrEmpty(startdate) ? "" : startdate;
        enddate = StringUtil.isNullOrEmpty(enddate) ? "" : enddate;
        fastdate = StringUtil.isNullOrEmpty(fastdate) ? "0" : fastdate;
        if (!"0".equalsIgnoreCase(fastdate)) {
            enddate = TimeUtil.getGernalTime(System.currentTimeMillis());
            startdate = TimeUtil.getGernalTime(
                    System.currentTimeMillis() - 24 * 60 * 60 * 1000L * (Integer.parseInt(fastdate) - 1));
        }
 
        List<StatisticXY> xyList = statisticsService.getWatchDetail(startdate, enddate, detailsystem + "");
 
        JSONArray nameArray = new JSONArray();
        JSONArray countArray = new JSONArray();
        for (StatisticXY xy : xyList) {
            if ((xy.getTime() + "").length() > 15)
                xy.setTime(xy.getTime().substring(0, 15) + "..");
            nameArray.add(xy.getTime());
            countArray.add(xy.getY());
        }
        JSONObject object = new JSONObject();
        object.put("code", 0);
        JSONObject data = new JSONObject();
        data.put("name", nameArray);
        data.put("count", countArray);
        object.put("data", data);
        out.print(object);
    }
 
    @RequestMapping(value = "/gettopsearch", method = RequestMethod.POST)
    public void getTopSearch(int detailsystem, PrintWriter out) {
        //是否最近1小时更新过
        String updateTime = redisManager.getCommonString("search_key_updatetime");
        if (StringUtil.isNullOrEmpty(updateTime)) {
            //更新数据
            refreshTopSearch(detailsystem, out);
        }
 
 
        String day = TimeUtil.getGernalTime(System.currentTimeMillis(), "yyyyMMdd");
        String key = "search_key-" + day;
        String value = redisManager.getCommonString(key);
        JSONArray countList = new JSONArray();
        JSONArray nameList = new JSONArray();
        if (!StringUtil.isNullOrEmpty(value)) {
            Type type = new TypeToken<List<SearchKeyLogUtil.RankInfo>>() {
            }.getType();
            List<SearchKeyLogUtil.RankInfo> resultList = new Gson().fromJson(value, type);
            for (SearchKeyLogUtil.RankInfo rank : resultList) {
                countList.add(rank.getCount());
                nameList.add(rank.getKey());
            }
        }
        JSONObject data = new JSONObject();
        data.put("name", nameList);
        data.put("count", countList);
        out.print(JsonUtil.loadTrueAdmin(data));
    }
 
    @RequestMapping(value = "/refreshtopsearch", method = RequestMethod.POST)
    public void refreshTopSearch(int detailsystem, PrintWriter out) {
        String day = TimeUtil.getGernalTime(System.currentTimeMillis(), "yyyyMMdd");
        List<SearchKeyLogUtil.RankInfo> rankList = null;
        try {
            rankList = SearchKeyLogUtil.getTodayRankList(50);
        } catch (IOException e) {
            e.printStackTrace();
        }
 
        if (rankList == null) {
            out.print(JsonUtil.loadFalseAdmin("更新失败"));
        } else {
            String key = "search_key-" + day;
            redisManager.cacheCommonString(key, new Gson().toJson(rankList));
            redisManager.cacheCommonString("search_key_updatetime", System.currentTimeMillis() + "",3600);
            out.print(JsonUtil.loadTrueAdmin("更新成功"));
        }
    }
 
    @RequestMapping(value = "/totalplay", method = RequestMethod.POST)
    public void totalPlay(String startdate, String enddate, String fastdate, int detailsystem, PrintWriter out) {
 
        startdate = StringUtil.isNullOrEmpty(startdate) ? "" : startdate;
        enddate = StringUtil.isNullOrEmpty(enddate) ? "" : enddate;
        fastdate = StringUtil.isNullOrEmpty(fastdate) ? "0" : fastdate;
        if (!"0".equalsIgnoreCase(fastdate)) {
            enddate = TimeUtil.getGernalTime(System.currentTimeMillis());
            startdate = TimeUtil.getGernalTime(
                    System.currentTimeMillis() - 24 * 60 * 60 * 1000L * (Integer.parseInt(fastdate) - 1));
        }
 
        List<StatisticXY> xyList = statisticsService.getDetailSystemWatchCount(startdate, enddate, detailsystem + "");
        JSONArray dateArray = new JSONArray();
        JSONArray countArray = new JSONArray();
        for (StatisticXY xy : xyList) {
            dateArray.add(xy.getTime());
            countArray.add(xy.getY());
        }
        JSONObject object = new JSONObject();
        object.put("code", 0);
        JSONObject data = new JSONObject();
        data.put("date", dateArray);
        data.put("count", countArray);
        object.put("data", data);
        out.print(object);
    }
 
    @RequestMapping(value = "/typeplay", method = RequestMethod.POST)
    public void typePlay(String startdate, String enddate, String fastdate, int detailsystem, PrintWriter out) {
        startdate = StringUtil.isNullOrEmpty(startdate) ? "" : startdate;
        enddate = StringUtil.isNullOrEmpty(enddate) ? "" : enddate;
        fastdate = StringUtil.isNullOrEmpty(fastdate) ? "0" : fastdate;
        if (!"0".equalsIgnoreCase(fastdate)) {
            enddate = TimeUtil.getGernalTime(System.currentTimeMillis());
            startdate = TimeUtil.getGernalTime(
                    System.currentTimeMillis() - 24 * 60 * 60 * 1000L * (Integer.parseInt(fastdate) - 1));
        }
 
        Map<String, List<StatisticXY>> map = statisticsService.getCategoryPlayStatistics(startdate, enddate,
                detailsystem + "");
        Iterator<String> its = map.keySet().iterator();
        JSONArray countArray = new JSONArray();
        while (its.hasNext()) {
            String key = its.next();
            List<StatisticXY> list = map.get(key);
            JSONObject item = new JSONObject();
            item.put("name", key);
            JSONArray itemtA = new JSONArray();
            for (StatisticXY xy : list) {
                itemtA.add(xy.getY());
            }
            item.put("data", itemtA);
            countArray.add(item);
        }
 
        JSONArray dateArray = new JSONArray();
        its = map.keySet().iterator();
        if (its.hasNext()) {
            List<StatisticXY> list = map.get(its.next());
            for (StatisticXY xy : list) {
                dateArray.add(xy.getTime());
            }
        }
        JSONObject object = new JSONObject();
        object.put("code", 0);
        JSONObject data = new JSONObject();
        data.put("date", dateArray);
        data.put("count", countArray);
        object.put("data", data);
        out.print(object);
 
    }
 
    @RequestMapping(value = "/singleplay", method = RequestMethod.POST)
    public void singlePlay(String videoid, String startdate, String enddate, String fastdate, int detailsystem,
                           PrintWriter out) {
        startdate = StringUtil.isNullOrEmpty(startdate) ? "" : startdate;
        enddate = StringUtil.isNullOrEmpty(enddate) ? "" : enddate;
        fastdate = StringUtil.isNullOrEmpty(fastdate) ? "0" : fastdate;
        if (!"0".equalsIgnoreCase(fastdate)) {
            enddate = TimeUtil.getGernalTime(System.currentTimeMillis());
            startdate = TimeUtil.getGernalTime(
                    System.currentTimeMillis() - 24 * 60 * 60 * 1000L * (Integer.parseInt(fastdate) - 1));
        }
 
        List<StatisticXY> list = statisticsService.getVideoWatchDetail(videoid, startdate, enddate, detailsystem + "");
        JSONArray countArray = new JSONArray();
        JSONArray dateArray = new JSONArray();
        for (StatisticXY xy : list) {
            countArray.add(xy.getY());
            dateArray.add(xy.getTime());
        }
 
        JSONObject object = new JSONObject();
        object.put("code", 0);
        JSONObject data = new JSONObject();
        data.put("date", dateArray);
        data.put("count", countArray);
        object.put("data", data);
        out.print(object);
 
    }
 
}