延迟发送订阅消息

This commit is contained in:
谭凯凯 2024-10-21 10:42:08 +08:00 committed by Tankaikai
parent 8aa6b1e56b
commit 7425f0a4d5
2 changed files with 19 additions and 16 deletions

View File

@ -9,10 +9,12 @@ import cn.hutool.core.util.StrUtil;
import cn.ysk.cashier.config.security.security.TokenProvider;
import cn.ysk.cashier.cons.RedisConstant;
import cn.ysk.cashier.cons.rabbit.RabbitConstants;
import cn.ysk.cashier.dto.shop.TbShopTableDto;
import cn.ysk.cashier.dto.shop.TbShopTableQueryCriteria;
import cn.ysk.cashier.dto.shoptable.*;
import cn.ysk.cashier.enums.*;
import cn.ysk.cashier.exception.BadRequestException;
import cn.ysk.cashier.mybatis.entity.TbShopUserFlow;
import cn.ysk.cashier.mapper.shop.TbShopTableMapper;
import cn.ysk.cashier.mybatis.mapper.*;
import cn.ysk.cashier.mybatis.service.MpCashierCartService;
import cn.ysk.cashier.mybatis.service.MpOrderDetailService;
@ -29,9 +31,11 @@ import cn.ysk.cashier.repository.TbShopPayTypeRepository;
import cn.ysk.cashier.repository.order.TbCashierCartRepository;
import cn.ysk.cashier.repository.product.TbProductSkuRepository;
import cn.ysk.cashier.repository.shop.TbShopInfoRepository;
import cn.ysk.cashier.repository.shop.TbShopTableRepository;
import cn.ysk.cashier.service.PayService;
import cn.ysk.cashier.service.impl.TbPayServiceImpl;
import cn.ysk.cashier.service.order.TbOrderInfoService;
import cn.ysk.cashier.service.shop.TbShopTableService;
import cn.ysk.cashier.utils.*;
import cn.ysk.cashier.vo.PendingCountVO;
import com.alibaba.fastjson.JSONObject;
@ -39,32 +43,27 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.dianguang.cloud.ossservice.model.DateUtils;
import lombok.RequiredArgsConstructor;
import cn.ysk.cashier.repository.shop.TbShopTableRepository;
import cn.ysk.cashier.service.shop.TbShopTableService;
import cn.ysk.cashier.dto.shop.TbShopTableDto;
import cn.ysk.cashier.dto.shop.TbShopTableQueryCriteria;
import cn.ysk.cashier.mapper.shop.TbShopTableMapper;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.amqp.rabbit.connection.CorrelationData;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.time.Instant;
import java.util.*;
import java.io.IOException;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicReference;
import java.util.stream.Collectors;
import javax.servlet.http.HttpServletResponse;
/**
* @author lyf
@ -1606,7 +1605,7 @@ public class TbShopTableServiceImpl implements TbShopTableService {
jsonObject.put("token", null);
jsonObject.put("type", "create");
jsonObject.put("orderId", orderInfo.getId());
rabbitMsgUtils.sendOrderCollectMsg(jsonObject);
rabbitMsgUtils.sendOrderCollectMsg(jsonObject,3);
// 打印消息
if (!shopEatTypeInfoDTO.isDineInAfter()) {

View File

@ -32,7 +32,7 @@ public class RabbitMsgUtils implements RabbitTemplate.ConfirmCallback {
}
}
private <T> void sendMsg(String exchange, String routingKey, T data, String note, boolean isJson, Integer waitTime) {
private <T> void sendMsg(String exchange, String routingKey, T data, String note, boolean isJson, Integer waitTime) {
ThreadUtil.execAsync(() -> {
if (waitTime != null) {
ThreadUtil.sleep(waitTime, TimeUnit.SECONDS);
@ -47,7 +47,11 @@ public class RabbitMsgUtils implements RabbitTemplate.ConfirmCallback {
sendMsg(RabbitConstants.CART_ORDER_COLLECT_PUT, RabbitConstants.CART_ORDER_COLLECT_ROUTINGKEY_PUT, data, "订单信息收集", true, null);
}
public void printTicket(String orderId){
public <T> void sendOrderCollectMsg(T data, int waitTime) {
sendMsg(RabbitConstants.CART_ORDER_COLLECT_PUT, RabbitConstants.CART_ORDER_COLLECT_ROUTINGKEY_PUT, data, "订单信息收集", true, waitTime);
}
public void printTicket(String orderId) {
sendMsg(RabbitConstants.PRINT_MECHINE_COLLECT_PUT, RabbitConstants.PRINT_MECHINE_COLLECT_ROUTINGKEY_PUT, orderId, "打印票", false, null);
}
@ -91,7 +95,7 @@ public class RabbitMsgUtils implements RabbitTemplate.ConfirmCallback {
printDTO.setCurrentUserId(SecurityUtils.getCurrentUserId());
printDTO.setCurrentUserName(SecurityUtils.getCurrentUsername());
printDTO.setCurrentUserNickName(SecurityUtils.getCurrentUserNickName());
}catch (Exception e){
} catch (Exception e) {
log.error("获取当前用户信息失败", e);
}
sendMsg(RabbitConstants.EXCHANGE_PRINT, RabbitConstants.ROUTING_KEY_CALL_TABLE, printDTO, "排号小票打印", true, null);
@ -106,12 +110,12 @@ public class RabbitMsgUtils implements RabbitTemplate.ConfirmCallback {
}
public void buildCurrentUserInfo(JSONObject jsonObject){
public void buildCurrentUserInfo(JSONObject jsonObject) {
try {
jsonObject.put("currentUserId", SecurityUtils.getCurrentUserId());
jsonObject.put("currentUserName", SecurityUtils.getCurrentUsername());
jsonObject.put("currentUserNickName", SecurityUtils.getCurrentUserNickName());
}catch (Exception e){
} catch (Exception e) {
log.error("获取当前用户信息失败", e);
}
}