券 失效定时任务 领取列表 头像 名称
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,7 +1,10 @@
|
||||
package com.czg.config;
|
||||
|
||||
import com.czg.account.service.ShopTableService;
|
||||
import com.czg.market.entity.MkShopCouponRecord;
|
||||
import com.czg.market.service.MkShopCouponRecordService;
|
||||
import com.czg.order.service.OrderInfoService;
|
||||
import com.mybatisflex.core.query.QueryWrapper;
|
||||
import jakarta.annotation.Resource;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.dubbo.config.annotation.DubboReference;
|
||||
@@ -29,6 +32,8 @@ public class RedisKeyExpirationListener implements MessageListener {
|
||||
private OrderInfoService orderInfoService;
|
||||
@DubboReference
|
||||
private ShopTableService tableService;
|
||||
@Resource
|
||||
private MkShopCouponRecordService mkShopCouponRecordService;
|
||||
|
||||
|
||||
//redis key失效监听
|
||||
@@ -50,10 +55,17 @@ public class RedisKeyExpirationListener implements MessageListener {
|
||||
log.info("监听到订单过期,订单Id: {}", expiredKey);
|
||||
String orderId = expiredKey.substring(RedisCst.classKeyExpired.EXPIRED_ORDER.length());
|
||||
orderInfoService.expired(Long.parseLong(orderId));
|
||||
}else if (expiredKey.startsWith(RedisCst.classKeyExpired.EXPIRED_TABLE)) {
|
||||
} else if (expiredKey.startsWith(RedisCst.classKeyExpired.EXPIRED_TABLE)) {
|
||||
log.info("监听到台桌清台过期,台桌Id: {}", expiredKey);
|
||||
String tableId = expiredKey.substring(RedisCst.classKeyExpired.EXPIRED_TABLE.length());
|
||||
tableService.expiredTable(Long.parseLong(tableId));
|
||||
} else if (expiredKey.startsWith(RedisCst.classKeyExpired.EXPIRED_COUPON)) {
|
||||
log.info("监听到优惠券过期,优惠券Id: {}", expiredKey);
|
||||
String couponId = expiredKey.substring(RedisCst.classKeyExpired.EXPIRED_COUPON.length());
|
||||
mkShopCouponRecordService.update(MkShopCouponRecord.builder().status(2).build(), new QueryWrapper()
|
||||
.eq(MkShopCouponRecord::getStatus, 0)
|
||||
.eq(MkShopCouponRecord::getId, Long.parseLong(couponId))
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user