admin
2023-04-12 f06a592dd1a7e995bf313ccb5efe7dff73ccfc4e
src/main/java/com/yeshi/buwan/controller/admin/api/StatisticsController.java
@@ -1,12 +1,20 @@
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;
@@ -28,6 +36,9 @@
   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) {
@@ -89,6 +100,56 @@
      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) {