48 lines
1.4 KiB
Java
48 lines
1.4 KiB
Java
package com.peanut.modules.book.task;
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
import com.peanut.modules.book.entity.MyUserEntity;
|
|
import com.peanut.modules.book.service.MyUserService;
|
|
import com.peanut.modules.sys.service.SysUserService;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.scheduling.annotation.EnableScheduling;
|
|
import org.springframework.scheduling.annotation.Scheduled;
|
|
import org.springframework.stereotype.Component;
|
|
|
|
import java.util.Date;
|
|
import java.util.List;
|
|
|
|
@Component
|
|
@EnableScheduling
|
|
//@Async
|
|
public class SysTask {
|
|
|
|
|
|
@Autowired
|
|
private MyUserService userService;
|
|
|
|
//
|
|
@Scheduled(cron = "0 0 2 ? * * ")
|
|
public void run() throws InterruptedException {
|
|
|
|
List<MyUserEntity> users = userService.getBaseMapper().selectList(new QueryWrapper<>());
|
|
for (MyUserEntity user : users) {
|
|
Date vipValidtime = user.getVipValidtime();
|
|
Date date = new Date();
|
|
long times = date.getTime() - vipValidtime.getTime();
|
|
|
|
if (times <= 0) {
|
|
String vip = user.getVip();
|
|
if (vip.equals("1")) {
|
|
user.setVip("0");
|
|
userService.save(user);
|
|
}
|
|
}
|
|
}
|
|
|
|
// System.out.println(Thread.currentThread().getName()+"=====>>>>>使用cron {}"+(System.currentTimeMillis()/1000));
|
|
}
|
|
|
|
|
|
}
|