Skip to content

Commit 337b099

Browse files
committed
feat[litemall-admin-api]: 优惠券定时任务,检查是否过期
1 parent a831c94 commit 337b099

File tree

1 file changed

+48
-0
lines changed
  • litemall-admin-api/src/main/java/org/linlinjava/litemall/admin/job

1 file changed

+48
-0
lines changed
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
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

Comments
 (0)