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);
|
|
}
|
|
}
|