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