forked from linlinjava/litemall
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat[litemall-admin-api]: 优惠券定时任务,检查是否过期
- Loading branch information
1 parent
a831c94
commit 337b099
Showing
1 changed file
with
48 additions
and
0 deletions.
There are no files selected for viewing
48 changes: 48 additions & 0 deletions
48
litemall-admin-api/src/main/java/org/linlinjava/litemall/admin/job/CouponJob.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package org.linlinjava.litemall.admin.job; | ||
|
||
import org.apache.commons.logging.Log; | ||
import org.apache.commons.logging.LogFactory; | ||
import org.linlinjava.litemall.db.domain.LitemallCoupon; | ||
import org.linlinjava.litemall.db.domain.LitemallCouponUser; | ||
import org.linlinjava.litemall.db.service.LitemallCouponService; | ||
import org.linlinjava.litemall.db.service.LitemallCouponUserService; | ||
import org.linlinjava.litemall.db.util.CouponConstant; | ||
import org.linlinjava.litemall.db.util.CouponUserConstant; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.scheduling.annotation.Scheduled; | ||
import org.springframework.stereotype.Component; | ||
import java.util.List; | ||
|
||
/** | ||
* 检测优惠券过期情况 | ||
*/ | ||
@Component | ||
public class CouponJob { | ||
private final Log logger = LogFactory.getLog(CouponJob.class); | ||
|
||
@Autowired | ||
private LitemallCouponService couponService; | ||
@Autowired | ||
private LitemallCouponUserService couponUserService; | ||
|
||
/** | ||
* 每隔一个小时检查 | ||
*/ | ||
@Scheduled(fixedDelay = 60 * 60 * 1000) | ||
public void checkCouponExpired() { | ||
logger.info("系统开启任务检查优惠券是否已经过期"); | ||
|
||
List<LitemallCoupon> couponList = couponService.queryExpired(); | ||
for(LitemallCoupon coupon : couponList){ | ||
coupon.setStatus(CouponConstant.STATUS_EXPIRED); | ||
couponService.updateById(coupon); | ||
} | ||
|
||
List<LitemallCouponUser> couponUserList = couponUserService.queryExpired(); | ||
for(LitemallCouponUser couponUser : couponUserList){ | ||
couponUser.setStatus(CouponUserConstant.STATUS_EXPIRED); | ||
couponUserService.update(couponUser); | ||
} | ||
} | ||
|
||
} |