券 失效定时任务 领取列表 头像 名称
This commit is contained in:
@@ -0,0 +1,57 @@
|
||||
package com.czg.task;
|
||||
|
||||
import com.czg.config.RedisCst;
|
||||
import com.czg.market.entity.MkShopCouponRecord;
|
||||
import com.czg.market.service.MkShopCouponRecordService;
|
||||
import com.czg.service.RedisService;
|
||||
import com.mybatisflex.core.query.QueryWrapper;
|
||||
import jakarta.annotation.Resource;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.time.Duration;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 订单定时任务
|
||||
*
|
||||
* @author ww
|
||||
* @description
|
||||
*/
|
||||
@Slf4j
|
||||
@Component
|
||||
public class CouponTask {
|
||||
@Resource
|
||||
private MkShopCouponRecordService mkShopCouponRecordService;
|
||||
@Resource
|
||||
private RedisService redisService;
|
||||
|
||||
/**
|
||||
* 优惠券 过期
|
||||
*/
|
||||
@Scheduled(cron = "0 30 * * * ? ")
|
||||
public void deliver() {
|
||||
LocalDateTime now = LocalDateTime.now();
|
||||
mkShopCouponRecordService.update(MkShopCouponRecord.builder().status(2).build(), new QueryWrapper()
|
||||
.eq(MkShopCouponRecord::getStatus, 0)
|
||||
.le(MkShopCouponRecord::getUseEndTime, now)
|
||||
);
|
||||
// 计算当前时间加一小时
|
||||
LocalDateTime oneHourLater = now.plusHours(1);
|
||||
List<MkShopCouponRecord> list = mkShopCouponRecordService.list(new QueryWrapper()
|
||||
.eq(MkShopCouponRecord::getStatus, 0)
|
||||
.le(MkShopCouponRecord::getUseEndTime, oneHourLater)
|
||||
);
|
||||
for (MkShopCouponRecord mkShopCouponRecord : list) {
|
||||
LocalDateTime endTime = mkShopCouponRecord.getUseEndTime();
|
||||
if (endTime != null) {
|
||||
Duration duration = Duration.between(now, endTime);
|
||||
long seconds = duration.getSeconds() % 60;
|
||||
redisService.set(RedisCst.classKeyExpired.EXPIRED_COUPON + mkShopCouponRecord.getId(), mkShopCouponRecord.getId(), seconds);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user