CsdnSchedule.java 2.3 KB
Newer Older
1 2 3
package com.kwan.springbootkwan.schedule;


4 5 6 7
import cn.hutool.core.collection.CollectionUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.kwan.springbootkwan.entity.CsdnUserInfo;
import com.kwan.springbootkwan.enums.CollectStatus;
8
import com.kwan.springbootkwan.enums.CommentStatus;
9
import com.kwan.springbootkwan.enums.LikeStatus;
10
import com.kwan.springbootkwan.service.CsdnCommentService;
11
import com.kwan.springbootkwan.service.CsdnService;
12
import com.kwan.springbootkwan.service.CsdnUserInfoService;
13 14 15 16 17
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

18 19
import java.util.List;

20 21

@Slf4j
22
@Component
23 24 25 26
public class CsdnSchedule {

    @Autowired
    private CsdnService csdnService;
27
    @Autowired
28 29
    private CsdnCommentService csdnCommentService;
    @Autowired
30
    private CsdnUserInfoService csdnUserInfoService;
31

32
    @Scheduled(cron = "0 0 8,10,12,14,16,18,20 * * ?")
33
    public void execute() {
34
        log.info("execute task is running ... ...");
35
        csdnService.multiTriplet();
36 37 38 39 40 41 42 43 44 45 46 47 48 49
        log.info("execute task is finish ... ...");
    }

    @Scheduled(cron = "0 0 3 * * ?")
    public void executeInit() {
        log.info("executeInit task is running ... ...");
        QueryWrapper<CsdnUserInfo> wrapper = new QueryWrapper<>();
        wrapper.eq("is_delete", 0);
        wrapper.orderByAsc("rand()");
        final List<CsdnUserInfo> list = csdnUserInfoService.list(wrapper);
        if (CollectionUtil.isNotEmpty(list)) {
            for (CsdnUserInfo csdnUserInfo : list) {
                csdnUserInfo.setLikeStatus(LikeStatus.UN_PROCESSED.getCode());
                csdnUserInfo.setCollectStatus(CollectStatus.UN_PROCESSED.getCode());
50
                csdnUserInfo.setCommentStatus(CommentStatus.RESTRICTED_COMMENTS.getCode());
51 52 53 54
                csdnUserInfoService.updateById(csdnUserInfo);
            }
        }
        log.info("executeInit task is finish ... ...");
55
    }
56 57 58 59 60 61 62

    @Scheduled(cron = "0 0 8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23 * * ?")
    public void executeReply() {
        log.info("executeReply task is running ... ...");
        csdnCommentService.commentSelf();
        log.info("executeReply task is finish ... ...");
    }
63 64
}