admin
2021-06-16 42fa17d6209d10cbe4774388d0ff3fcf3329eb5a
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
package com.yeshi.buwan.controller.admin.api;
 
import java.io.PrintWriter;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
 
import javax.annotation.Resource;
 
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;
 
    @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 = "/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);
 
    }
 
}