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


4 5 6 7 8
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;
import com.kwan.springbootkwan.enums.LikeStatus;
9
import com.kwan.springbootkwan.service.CsdnService;
10
import com.kwan.springbootkwan.service.CsdnUserInfoService;
11 12 13 14 15
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

16 17
import java.util.List;

18 19

@Slf4j
20
@Component
21 22 23 24
public class CsdnSchedule {

    @Autowired
    private CsdnService csdnService;
25 26
    @Autowired
    private CsdnUserInfoService csdnUserInfoService;
27

28
    @Scheduled(cron = "0 0 8,10,12,14,16,18,20 * * ?")
29
    public void execute() {
30
        log.info("execute task is running ... ...");
31
        csdnService.multiTriplet();
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
        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());
//                csdnUserInfo.setCommentStatus(CommentStatus.UN_PROCESSED.getCode());
                csdnUserInfoService.updateById(csdnUserInfo);
            }
        }
        log.info("executeInit task is finish ... ...");
51 52 53
    }
}