first commit
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
package com.peanut.modules.book.task;
|
||||
|
||||
import com.peanut.modules.book.service.CouponHistoryService;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.scheduling.annotation.EnableScheduling;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
|
||||
@Configuration
|
||||
@EnableScheduling
|
||||
public class CouponsUserScheduleTask {
|
||||
|
||||
@Autowired
|
||||
private CouponHistoryService couponsUserService;
|
||||
|
||||
private static Logger log = LoggerFactory.getLogger(CouponsUserScheduleTask.class);
|
||||
|
||||
@Scheduled(cron = "0 0/1 * * * ?")//每3分 //crontab -e 动态代替应用命令
|
||||
public void handlerCouponsUserStatusTimeOutToExpired(){
|
||||
log.info("handlerCouponsUserStatusTimeOutToExpired start.......time={}",System.currentTimeMillis());
|
||||
Long startTime01 = System.currentTimeMillis();
|
||||
couponsUserService.runCouponsUserStatusTimeOutToExpired();
|
||||
Long endTime02 = System.currentTimeMillis();
|
||||
log.info("handlerCouponsUserStatusTimeOutToExpired end second={},mills={}",(endTime02-startTime01)/1000,(endTime02-startTime01)%1000);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
package com.peanut.modules.book.task;
|
||||
|
||||
import com.peanut.modules.book.service.ShopSeckillService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.concurrent.locks.Lock;
|
||||
import java.util.concurrent.locks.ReentrantLock;
|
||||
|
||||
@Slf4j
|
||||
@Service
|
||||
public class SeckillProdScheduled {
|
||||
@Autowired
|
||||
ShopSeckillService shopSeckillService;
|
||||
|
||||
@Scheduled(cron = "0 0/1 * * * ?")
|
||||
public void uploadSeckilProd3Days() {
|
||||
Lock l = new ReentrantLock();
|
||||
l.lock();
|
||||
try {
|
||||
shopSeckillService.uploadSeckilProd3Days();
|
||||
}catch (Exception e){
|
||||
e.printStackTrace();
|
||||
}finally {
|
||||
l.unlock();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
47
src/main/java/com/peanut/modules/book/task/SysTask.java
Normal file
47
src/main/java/com/peanut/modules/book/task/SysTask.java
Normal file
@@ -0,0 +1,47 @@
|
||||
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));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user