拼团超时
This commit is contained in:
@@ -5,6 +5,7 @@ import com.czg.market.entity.MkShopCouponRecord;
|
||||
import com.czg.market.service.AcPushEventService;
|
||||
import com.czg.market.service.MkShopCouponRecordService;
|
||||
import com.czg.market.service.SmsPushEventService;
|
||||
import com.czg.order.service.GbOrderService;
|
||||
import com.czg.order.service.OrderInfoCustomService;
|
||||
import com.mybatisflex.core.query.QueryWrapper;
|
||||
import jakarta.annotation.Resource;
|
||||
@@ -40,6 +41,8 @@ public class RedisKeyExpirationListener implements MessageListener {
|
||||
private SmsPushEventService smsPushEventService;
|
||||
@Resource
|
||||
private AcPushEventService acPushEventService;
|
||||
@Resource
|
||||
private GbOrderService gbOrderService;
|
||||
|
||||
|
||||
//redis key失效监听
|
||||
@@ -72,6 +75,10 @@ public class RedisKeyExpirationListener implements MessageListener {
|
||||
.eq(MkShopCouponRecord::getStatus, 0)
|
||||
.eq(MkShopCouponRecord::getId, Long.parseLong(couponId))
|
||||
);
|
||||
} else if (expiredKey.startsWith(RedisCst.classKeyExpired.EXPIRED_GB_ORDER)) {
|
||||
log.info("监听到拼团任务过期,gb_order任务Id: {}", expiredKey);
|
||||
String eventId = expiredKey.substring(RedisCst.classKeyExpired.EXPIRED_GB_ORDER.length());
|
||||
gbOrderService.expireRefund(Long.parseLong(eventId), null);
|
||||
} else if (expiredKey.startsWith(RedisCst.classKeyExpired.EXPIRED_SMS)) {
|
||||
log.info("监听到短信定时发放优惠券,sms_push_event任务Id: {}", expiredKey);
|
||||
String eventId = expiredKey.substring(RedisCst.classKeyExpired.EXPIRED_SMS.length());
|
||||
|
||||
@@ -1,14 +1,19 @@
|
||||
package com.czg.task;
|
||||
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.date.LocalDateTimeUtil;
|
||||
import com.czg.config.RedisCst;
|
||||
import com.czg.enums.OrderNoPrefixEnum;
|
||||
import com.czg.market.service.OrderInfoService;
|
||||
import com.czg.order.entity.CashierCart;
|
||||
import com.czg.order.entity.GbOrder;
|
||||
import com.czg.order.entity.OrderInfo;
|
||||
import com.czg.order.entity.OrderPayment;
|
||||
import com.czg.order.enums.PaymentPayTypeEnum;
|
||||
import com.czg.order.service.CashierCartService;
|
||||
import com.czg.order.service.GbOrderService;
|
||||
import com.czg.order.service.OrderPaymentService;
|
||||
import com.czg.service.RedisService;
|
||||
import com.czg.service.order.enums.OrderStatusEnums;
|
||||
import com.czg.service.order.service.PayService;
|
||||
import com.czg.utils.CzgRandomUtils;
|
||||
@@ -18,13 +23,14 @@ 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.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 订单定时任务
|
||||
* 订单过期处理
|
||||
*
|
||||
* @author ww
|
||||
* @description
|
||||
@@ -39,7 +45,11 @@ public class OTimeTask {
|
||||
@Resource
|
||||
private OrderPaymentService orderPaymentService;
|
||||
@Resource
|
||||
private GbOrderService gbOrderService;
|
||||
@Resource
|
||||
private PayService payService;
|
||||
@Resource
|
||||
private RedisService redisService;
|
||||
|
||||
/**
|
||||
* order 过期
|
||||
@@ -62,9 +72,38 @@ public class OTimeTask {
|
||||
|
||||
/**
|
||||
* 订单 过期 退钱
|
||||
* 每两小时 触发一次
|
||||
*/
|
||||
@Scheduled(cron = "0 0 0/2 * * ?")
|
||||
public void gbOrderExpire() {
|
||||
// 当前系统时间
|
||||
LocalDateTime now = LocalDateTime.now();
|
||||
// 过期时间下限:当前时间往前推4小时(只查最近4小时内过期的)
|
||||
LocalDateTime expire4HoursAgo = now.minusHours(4);
|
||||
List<GbOrder> expiredOrderList = gbOrderService.list(QueryWrapper.create()
|
||||
.eq(GbOrder::getStatus, "ing")
|
||||
.le(GbOrder::getGroupEndTime, now)
|
||||
.ge(GbOrder::getGroupEndTime, expire4HoursAgo));
|
||||
|
||||
// 处理已过期订单
|
||||
for (GbOrder expiredOrder : expiredOrderList) {
|
||||
//退款
|
||||
gbOrderService.expireRefund(null, expiredOrder);
|
||||
}
|
||||
|
||||
//查询【当前时间往后2小时内】将要过期的订单
|
||||
LocalDateTime willExpire2HoursLater = now.plusHours(2);
|
||||
List<GbOrder> willExpireOrderList = gbOrderService.list(QueryWrapper.create()
|
||||
.eq(GbOrder::getStatus, "ing")
|
||||
.ge(GbOrder::getGroupEndTime, now)
|
||||
.le(GbOrder::getGroupEndTime, willExpire2HoursLater));
|
||||
// 处理将要过期订单(如推送提醒、催参团等)
|
||||
for (GbOrder willExpireOrder : willExpireOrderList) {
|
||||
LocalDateTime endTime = willExpireOrder.getGroupEndTime();
|
||||
Duration duration = Duration.between(now, endTime);
|
||||
long seconds = duration.getSeconds();
|
||||
redisService.set(RedisCst.classKeyExpired.EXPIRED_GB_ORDER + willExpireOrder.getId(), willExpireOrder.getId(), seconds);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -23,6 +23,8 @@ public interface RedisCst {
|
||||
public static final String EXPIRED_TABLE = "expired:table:";
|
||||
//优惠券过期
|
||||
public static final String EXPIRED_COUPON = "expired:coupon:";
|
||||
//拼团 任务过期
|
||||
public static final String EXPIRED_GB_ORDER = "expired:gb:order:";
|
||||
//短信定时发放 倒计时KEY
|
||||
public static final String EXPIRED_SMS = "expired:sms:";
|
||||
//公众号推送 倒计时KEY
|
||||
|
||||
@@ -57,7 +57,7 @@ public interface GbOrderService extends IService<GbOrder> {
|
||||
boolean editGbWareOnlineStatus(Long id, Integer onlineStatus);
|
||||
|
||||
//任务过期 自动退款 成团期限超时
|
||||
boolean expireRefund(Long gbOrderId);
|
||||
boolean expireRefund(Long gbOrderId,GbOrder order);
|
||||
|
||||
//商品下架 退款 所属活动变更为下架状态
|
||||
boolean wareDownRefund(Long wareId);
|
||||
|
||||
@@ -293,7 +293,7 @@ public class GbOrderServiceImpl extends ServiceImpl<GbOrderMapper, GbOrder> impl
|
||||
if ("success".equals(order.getStatus())) {
|
||||
record.setStatus("待核销");
|
||||
//推送 拼团成功
|
||||
sendMessage(order.getShopId(),order.getGroupOrderNo());
|
||||
sendMessage(order.getShopId(), order.getGroupOrderNo());
|
||||
}
|
||||
} else {
|
||||
GbOrder order = getOne(query().eq(GbOrder::getGroupOrderNo, record.getGroupOrderNo())
|
||||
@@ -313,7 +313,7 @@ public class GbOrderServiceImpl extends ServiceImpl<GbOrderMapper, GbOrder> impl
|
||||
.eq(GbOrderDetail::getStatus, "待成团")
|
||||
);
|
||||
//推送 拼团成功
|
||||
sendMessage(order.getShopId(),order.getGroupOrderNo());
|
||||
sendMessage(order.getShopId(), order.getGroupOrderNo());
|
||||
}
|
||||
updateById(order);
|
||||
}
|
||||
@@ -409,8 +409,16 @@ public class GbOrderServiceImpl extends ServiceImpl<GbOrderMapper, GbOrder> impl
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean expireRefund(Long gbOrderId) {
|
||||
GbOrder order = getOne(query().eq(GbOrder::getId, gbOrderId).eq(GbOrder::getStatus, "ing"));
|
||||
public boolean expireRefund(Long gbOrderId, GbOrder order) {
|
||||
if (gbOrderId == null && order == null) {
|
||||
return false;
|
||||
}
|
||||
if (order == null) {
|
||||
order = getOne(query().eq(GbOrder::getId, gbOrderId).eq(GbOrder::getStatus, "ing"));
|
||||
}
|
||||
if (order == null) {
|
||||
return false;
|
||||
}
|
||||
return refundByGbOrder(order, "成团期限超时");
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user