打印延迟3s 防止事务未提交
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
package cn.ysk.cashier.utils;
|
package cn.ysk.cashier.utils;
|
||||||
|
|
||||||
|
import cn.hutool.core.thread.ThreadUtil;
|
||||||
import cn.ysk.cashier.cons.rabbit.RabbitConstants;
|
import cn.ysk.cashier.cons.rabbit.RabbitConstants;
|
||||||
import cn.ysk.cashier.dto.CallNumPrintDTO;
|
import cn.ysk.cashier.dto.CallNumPrintDTO;
|
||||||
import cn.ysk.cashier.pojo.order.TbOrderDetail;
|
import cn.ysk.cashier.pojo.order.TbOrderDetail;
|
||||||
@@ -10,6 +11,7 @@ import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
|||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
@Component
|
@Component
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@@ -30,23 +32,28 @@ public class RabbitMsgUtils implements RabbitTemplate.ConfirmCallback {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private <T> void sendMsg(String exchange, String routingKey, T data, String note, boolean isJson) {
|
private <T> void sendMsg(String exchange, String routingKey, T data, String note, boolean isJson, Integer waitTime) {
|
||||||
CorrelationData correlationId = new CorrelationData(UUID.randomUUID().toString());
|
ThreadUtil.execAsync(() -> {
|
||||||
log.info("开始发送{}mq消息, msgId: {}, exchange: {}, routingKey: {}, data: {}", note, correlationId.getId(), exchange, routingKey, data);
|
if (waitTime != null) {
|
||||||
rabbitTemplate.convertAndSend(exchange, routingKey, isJson ? JSONObject.toJSONString(data) : data, correlationId);
|
ThreadUtil.sleep(waitTime, TimeUnit.SECONDS);
|
||||||
|
}
|
||||||
|
CorrelationData correlationId = new CorrelationData(UUID.randomUUID().toString());
|
||||||
|
log.info("开始发送{}mq消息, msgId: {}, exchange: {}, routingKey: {}, data: {}", note, correlationId.getId(), exchange, routingKey, data);
|
||||||
|
rabbitTemplate.convertAndSend(exchange, routingKey, isJson ? JSONObject.toJSONString(data) : data, correlationId);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public <T> void sendOrderCollectMsg(T data) {
|
public <T> void sendOrderCollectMsg(T data) {
|
||||||
sendMsg(RabbitConstants.CART_ORDER_COLLECT_PUT, RabbitConstants.CART_ORDER_COLLECT_ROUTINGKEY_PUT, data, "订单信息收集", true);
|
sendMsg(RabbitConstants.CART_ORDER_COLLECT_PUT, RabbitConstants.CART_ORDER_COLLECT_ROUTINGKEY_PUT, data, "订单信息收集", true, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void printTicket(String orderId){
|
public void printTicket(String orderId){
|
||||||
sendMsg(RabbitConstants.PRINT_MECHINE_COLLECT_PUT, RabbitConstants.PRINT_MECHINE_COLLECT_ROUTINGKEY_PUT, orderId, "打印票", false);
|
sendMsg(RabbitConstants.PRINT_MECHINE_COLLECT_PUT, RabbitConstants.PRINT_MECHINE_COLLECT_ROUTINGKEY_PUT, orderId, "打印票", false, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public <T> void sendStockMsg(T mqData) {
|
public <T> void sendStockMsg(T mqData) {
|
||||||
// 发送库存记录mq消息
|
// 发送库存记录mq消息
|
||||||
sendMsg(RabbitConstants.EXCHANGE_STOCK_RECORD, RabbitConstants.ROUTING_STOCK_RECORD_SALE, mqData, "库存记录", true);
|
sendMsg(RabbitConstants.EXCHANGE_STOCK_RECORD, RabbitConstants.ROUTING_STOCK_RECORD_SALE, mqData, "库存记录", true, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void printDishesReturnTicket(Integer orderId, Integer... orderIds) {
|
public void printDishesReturnTicket(Integer orderId, Integer... orderIds) {
|
||||||
@@ -55,7 +62,7 @@ public class RabbitMsgUtils implements RabbitTemplate.ConfirmCallback {
|
|||||||
jsonObject.put("orderDetailIds", orderIds);
|
jsonObject.put("orderDetailIds", orderIds);
|
||||||
jsonObject.put("isReturn", true);
|
jsonObject.put("isReturn", true);
|
||||||
buildCurrentUserInfo(jsonObject);
|
buildCurrentUserInfo(jsonObject);
|
||||||
sendMsg(RabbitConstants.EXCHANGE_PRINT, RabbitConstants.ROUTING_KEY_PRINT_DISHES, jsonObject, "菜品退单", true);
|
sendMsg(RabbitConstants.EXCHANGE_PRINT, RabbitConstants.ROUTING_KEY_PRINT_DISHES, jsonObject, "菜品退单", true, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void printDishesTicket(Integer orderId, boolean isReturn, TbOrderDetail... detailOrderIds) {
|
public void printDishesTicket(Integer orderId, boolean isReturn, TbOrderDetail... detailOrderIds) {
|
||||||
@@ -64,7 +71,7 @@ public class RabbitMsgUtils implements RabbitTemplate.ConfirmCallback {
|
|||||||
jsonObject.put("orderDetailIds", detailOrderIds);
|
jsonObject.put("orderDetailIds", detailOrderIds);
|
||||||
jsonObject.put("isReturn", isReturn);
|
jsonObject.put("isReturn", isReturn);
|
||||||
buildCurrentUserInfo(jsonObject);
|
buildCurrentUserInfo(jsonObject);
|
||||||
sendMsg(RabbitConstants.EXCHANGE_PRINT, RabbitConstants.ROUTING_KEY_PRINT_DISHES, jsonObject, "菜品打印", true);
|
sendMsg(RabbitConstants.EXCHANGE_PRINT, RabbitConstants.ROUTING_KEY_PRINT_DISHES, jsonObject, "菜品打印", true, 3);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void printPlaceTicket(Integer id, boolean isReturn) {
|
public void printPlaceTicket(Integer id, boolean isReturn) {
|
||||||
@@ -72,7 +79,7 @@ public class RabbitMsgUtils implements RabbitTemplate.ConfirmCallback {
|
|||||||
jsonObject.put("orderId", id);
|
jsonObject.put("orderId", id);
|
||||||
jsonObject.put("isReturn", isReturn);
|
jsonObject.put("isReturn", isReturn);
|
||||||
buildCurrentUserInfo(jsonObject);
|
buildCurrentUserInfo(jsonObject);
|
||||||
sendMsg(RabbitConstants.EXCHANGE_PRINT, RabbitConstants.ROUTING_KEY_PRINT_PLACE, jsonObject, "订单打印", true);
|
sendMsg(RabbitConstants.EXCHANGE_PRINT, RabbitConstants.ROUTING_KEY_PRINT_PLACE, jsonObject, "订单打印", true, 3);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -87,15 +94,15 @@ public class RabbitMsgUtils implements RabbitTemplate.ConfirmCallback {
|
|||||||
}catch (Exception e){
|
}catch (Exception e){
|
||||||
log.error("获取当前用户信息失败", e);
|
log.error("获取当前用户信息失败", e);
|
||||||
}
|
}
|
||||||
sendMsg(RabbitConstants.EXCHANGE_PRINT, RabbitConstants.ROUTING_KEY_CALL_TABLE, printDTO, "排号小票打印", true);
|
sendMsg(RabbitConstants.EXCHANGE_PRINT, RabbitConstants.ROUTING_KEY_CALL_TABLE, printDTO, "排号小票打印", true, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addBalanceRecord(JSONObject baObj) {
|
public void addBalanceRecord(JSONObject baObj) {
|
||||||
sendMsg(RabbitConstants.EXCHANGE_BALANCE, RabbitConstants.ROUTING_KEY_BALANCE, baObj, "储值卡记录", true);
|
sendMsg(RabbitConstants.EXCHANGE_BALANCE, RabbitConstants.ROUTING_KEY_BALANCE, baObj, "储值卡记录", true, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateCons(JSONObject jsonObject1) {
|
public void updateCons(JSONObject jsonObject1) {
|
||||||
sendMsg(RabbitConstants.EXCHANGE_CONS, RabbitConstants.ROUTING_KEY_CONS, jsonObject1, "储值卡记录", true);
|
sendMsg(RabbitConstants.EXCHANGE_CONS, RabbitConstants.ROUTING_KEY_CONS, jsonObject1, "储值卡记录", true, null);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user