|
| 1 | +package org.linlinjava.litemall.admin.job; |
| 2 | + |
| 3 | +import org.apache.commons.logging.Log; |
| 4 | +import org.apache.commons.logging.LogFactory; |
| 5 | +import org.linlinjava.litemall.db.domain.LitemallCoupon; |
| 6 | +import org.linlinjava.litemall.db.domain.LitemallCouponUser; |
| 7 | +import org.linlinjava.litemall.db.service.LitemallCouponService; |
| 8 | +import org.linlinjava.litemall.db.service.LitemallCouponUserService; |
| 9 | +import org.linlinjava.litemall.db.util.CouponConstant; |
| 10 | +import org.linlinjava.litemall.db.util.CouponUserConstant; |
| 11 | +import org.springframework.beans.factory.annotation.Autowired; |
| 12 | +import org.springframework.scheduling.annotation.Scheduled; |
| 13 | +import org.springframework.stereotype.Component; |
| 14 | +import java.util.List; |
| 15 | + |
| 16 | +/** |
| 17 | + * 检测优惠券过期情况 |
| 18 | + */ |
| 19 | +@Component |
| 20 | +public class CouponJob { |
| 21 | + private final Log logger = LogFactory.getLog(CouponJob.class); |
| 22 | + |
| 23 | + @Autowired |
| 24 | + private LitemallCouponService couponService; |
| 25 | + @Autowired |
| 26 | + private LitemallCouponUserService couponUserService; |
| 27 | + |
| 28 | + /** |
| 29 | + * 每隔一个小时检查 |
| 30 | + */ |
| 31 | + @Scheduled(fixedDelay = 60 * 60 * 1000) |
| 32 | + public void checkCouponExpired() { |
| 33 | + logger.info("系统开启任务检查优惠券是否已经过期"); |
| 34 | + |
| 35 | + List<LitemallCoupon> couponList = couponService.queryExpired(); |
| 36 | + for(LitemallCoupon coupon : couponList){ |
| 37 | + coupon.setStatus(CouponConstant.STATUS_EXPIRED); |
| 38 | + couponService.updateById(coupon); |
| 39 | + } |
| 40 | + |
| 41 | + List<LitemallCouponUser> couponUserList = couponUserService.queryExpired(); |
| 42 | + for(LitemallCouponUser couponUser : couponUserList){ |
| 43 | + couponUser.setStatus(CouponUserConstant.STATUS_EXPIRED); |
| 44 | + couponUserService.update(couponUser); |
| 45 | + } |
| 46 | + } |
| 47 | + |
| 48 | +} |
0 commit comments