CsdnSchedule.java 1.9 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.CsdnService;
11
import com.kwan.springbootkwan.service.CsdnUserInfoService;
12 13 14 15 16
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

17 18
import java.util.List;

19 20

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

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

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