ConJobManager.java 1.58 KB
Newer Older
张辰's avatar
张辰 committed
1 2
package com.tanpu.community.manager;

张辰's avatar
张辰 committed
3
import com.tanpu.community.service.*;
张辰's avatar
张辰 committed
4 5 6 7 8 9 10 11 12 13 14 15
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;

@Slf4j
@Service
@Configuration
public class ConJobManager {

    @Autowired
刘基明's avatar
刘基明 committed
16
    private VisitLogService visitLogService;
张辰's avatar
张辰 committed
17 18 19 20

    @Autowired
    private RedisService redisService;

刘基明's avatar
刘基明 committed
21 22 23
    @Autowired
    private RankService rankService;

张辰's avatar
张辰 committed
24 25 26
    @Autowired
    private RankLogService rankLogService;

27 28 29
    @Autowired
    private RecommendService recommendService;

张辰's avatar
张辰 committed
30 31 32 33 34 35
    /**
     * 定时统计 话题 访问数据,并刷到redis
     */
    @Scheduled(cron = "*/10 * * * * ?")
    public void topicVisitorStats() {
        String topicId = "123";
刘基明's avatar
刘基明 committed
36
        Integer detailVisitTimes = visitLogService.queryTopicDetailVisit(topicId);
张辰's avatar
张辰 committed
37 38
        redisService.set("topicVisitorStats", detailVisitTimes);
    }
刘基明's avatar
刘基明 committed
39 40

    /**
41
     * 定时统计主题、话题排行
刘基明's avatar
刘基明 committed
42
     */
刘基明's avatar
刘基明 committed
43
    @Scheduled(cron = "*/30 * * * * ?")
刘基明's avatar
刘基明 committed
44 45
    public void themeRank() {
        rankService.rankThemes();
刘基明's avatar
刘基明 committed
46
        rankService.rankTopics();
刘基明's avatar
刘基明 committed
47 48 49 50 51 52 53
    }

    /**
     * 定时统计主题、话题排行
     */
    @Scheduled(cron = "*/5 * * * * ?")
    public void getThemeNewest() {
54
        recommendService.refreshNewestThemes();
刘基明's avatar
刘基明 committed
55
    }
张辰's avatar
张辰 committed
56 57 58 59 60 61 62 63

    /**
     * 定时把rank_log的日志拿出来,清理数据库
     */
    @Scheduled(cron = "0 0 0 ? * 1")
    public void clearRankLog() {
        rankLogService.clearRankLog();
    }
张辰's avatar
张辰 committed
64
}