|
@@ -0,0 +1,44 @@
|
|
|
+package com.futu.course.cupons;
|
|
|
+
|
|
|
+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.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 javax.annotation.Resource;
|
|
|
+import java.util.Date;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+@Component
|
|
|
+@EnableScheduling
|
|
|
+public class ScheduledTask {
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private CourseMapper courseMapper;
|
|
|
+ @Resource
|
|
|
+ private UserCouponMapper userCouponMapper;
|
|
|
+// 定时任务检查优惠券是否过期
|
|
|
+ @Scheduled(cron = "* * * * * * *")
|
|
|
+ public void setCourse(){
|
|
|
+
|
|
|
+ List<Course> courses = courseMapper.selectList(new QueryWrapper<>(null));
|
|
|
+ for (Course c:courses){
|
|
|
+ if (c.getEndTime().before(new Date())){
|
|
|
+ setUserCoupon(c.getId());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ public void setUserCoupon(Long id){
|
|
|
+ userCouponMapper.delete(new QueryWrapper<UserCoupon>().eq("coupon_id",id));
|
|
|
+ courseMapper.deleteById(id);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+}
|