lzy 1 week ago
parent
commit
d98c658d14

+ 2 - 0
src/main/java/com/futu/course/GooseApplication.java

@@ -3,9 +3,11 @@ package com.futu.course;
 import org.mybatis.spring.annotation.MapperScan;
 import org.springframework.boot.SpringApplication;
 import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.scheduling.annotation.EnableScheduling;
 
 @SpringBootApplication
 @MapperScan("com.futu.course.*.mapper")
+@EnableScheduling
 public class GooseApplication {
 
     public static void main(String[] args) {

+ 15 - 6
src/main/java/com/futu/course/cupons/ScheduledTask.java

@@ -4,13 +4,17 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.futu.course.course.domain.Course;
 import com.futu.course.course.mapper.CourseMapper;
+import com.futu.course.cupons.domain.Coupon;
+import com.futu.course.cupons.mapper.CouponMapper;
 import com.futu.course.user.domain.UserCoupon;
 import com.futu.course.user.mapper.UserCouponMapper;
 import org.springframework.scheduling.annotation.EnableScheduling;
 import org.springframework.scheduling.annotation.Scheduled;
 import org.springframework.stereotype.Component;
+import sun.awt.geom.AreaOp;
 
 import javax.annotation.Resource;
+import java.util.ArrayList;
 import java.util.Date;
 import java.util.List;
 
@@ -19,24 +23,29 @@ import java.util.List;
 public class ScheduledTask {
 
     @Resource
-    private CourseMapper courseMapper;
+    private CouponMapper couponMapper;
     @Resource
     private UserCouponMapper userCouponMapper;
 //  定时任务检查优惠券是否过期
-    @Scheduled(cron = "* * * * * * *")
+    @Scheduled(cron = "* * * * * *")  // 6个星号(秒级触发)
     public void setCourse(){
-        List<Course> courses = courseMapper.selectList(new QueryWrapper<>(null));
-        for (Course c:courses){
+        List<Coupon> list = couponMapper.selectList(new QueryWrapper<>(null));
+        forCoursers(list);
+    }
+
+    public void forCoursers(List<Coupon> list){
+        System.err.println(list);
+        for (Coupon c:list){
             if (c.getEndTime().before(new Date())){
+                System.err.println(1);
                 setUserCoupon(c.getId());
             }
         }
-
     }
 
     public void setUserCoupon(Long id){
         userCouponMapper.delete(new QueryWrapper<UserCoupon>().eq("coupon_id",id));
-        courseMapper.deleteById(id);
+        couponMapper.deleteById(id);
     }