admin
2024-09-05 ab35ac8b769b2d9816dffb33a64f2c6f7bd5dd6e
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
package com.yeshi.buwan.job;
 
import com.google.gson.Gson;
import com.xxl.job.core.biz.model.ReturnT;
import com.xxl.job.core.handler.annotation.XxlJob;
import com.yeshi.buwan.service.inter.system.SystemConfigService;
import com.yeshi.buwan.util.rank.IqiyiRankUtil;
import com.yeshi.buwan.util.rank.TencentRankUtil;
import org.json.JSONArray;
import org.json.JSONObject;
import org.springframework.stereotype.Component;
 
import javax.annotation.Resource;
import java.io.IOException;
import java.util.*;
 
//10409568
@Component
public class RankJob {
 
 
    @Resource
    private SystemConfigService systemConfigService;
 
    private static List<String> concatRank(int count, List<String>... ranks) {
        List<String> flist = new ArrayList<>();
        Set<String> keys=new HashSet<>();
        for (int i = 0; i < count; i++) {
            for (List<String> rank : ranks) {
                if (rank == null) {
                    continue;
                }
                if (rank.size() > i) {
                    if (!keys.contains(rank.get(i).replace(" ",""))) {
                        flist.add(rank.get(i));
                        keys.add(rank.get(i).replace(" ",""));
                    }
                }
                if (flist.size() >= count) {
                    break;
                }
            }
            if (flist.size() >= count) {
                break;
            }
        }
        return flist;
    }
 
 
    //爱奇艺排行
    @XxlJob("rank-iqiyi-update")
    public ReturnT<String> updateRank(String params) throws Exception {
        Map<String, List<String>> map = IqiyiRankUtil.getRank(10);
        Map<String, List<String>> tencentMap = TencentRankUtil.getRank(10);
        Map<String,Integer> typeRank=new HashMap<>();
        typeRank.put("热搜",0);
        typeRank.put("电视剧",1);
        typeRank.put("动漫",2);
        typeRank.put("电影",3);
        typeRank.put("综艺",4);
 
        Map<String,List<String>> fmap=new TreeMap<>(new Comparator<String>() {
            @Override
            public int compare(String o1, String o2) {
                return typeRank.get(o1) - typeRank.get(o2);
            }
        });
        fmap.put("热搜", concatRank(10, map.get("总榜"), tencentMap.get("热搜")));
        fmap.put("电视剧", concatRank(10, map.get("电视剧"), tencentMap.get("电视剧")));
        fmap.put("动漫", tencentMap.get("动漫"));
        fmap.put("电影", concatRank(10, map.get("电影"), tencentMap.get("电影")));
        fmap.put("综艺", concatRank(10, map.get("综艺"), tencentMap.get("综艺")));
        if (map != null && map.size() > 0) {
            String json = new Gson().toJson(fmap);
            systemConfigService.setValue("searchRank", json);
        }
        return ReturnT.SUCCESS;
    }
 
 
    //爱奇艺排行
    @XxlJob("rank-tencent-update")
    public ReturnT<String> updateTencentRank(String params) throws Exception {
        Map<String, List<String>> map = TencentRankUtil.getRank(10);
        if (map != null && map.size() > 0) {
            String json = new Gson().toJson(map);
            systemConfigService.setValue("searchRank", json);
        }
        return ReturnT.SUCCESS;
    }
 
    public static void main(String[] args) throws Exception {
       new RankJob().updateRank("");
    }
 
 
}