异步非阻塞 秒数 增加。
This commit is contained in:
parent
1d328b38f7
commit
655998c805
@ -14,6 +14,7 @@ public class MqConstant {
|
|||||||
public static final Integer FAILURE = 2; // 消息消费失败更改状态
|
public static final Integer FAILURE = 2; // 消息消费失败更改状态
|
||||||
public static final Integer DELIVERED = 3; // 消息重试消费成功更改状态
|
public static final Integer DELIVERED = 3; // 消息重试消费成功更改状态
|
||||||
public static final Integer MAX_COUNT = 3; // 消息重新投递最大重试次数
|
public static final Integer MAX_COUNT = 3; // 消息重新投递最大重试次数
|
||||||
|
|
||||||
public static final String SHOP_EXCHANGE = "shop-event-exchange"; // SHOP服务交换机
|
public static final String SHOP_EXCHANGE = "shop-event-exchange"; // SHOP服务交换机
|
||||||
public static final String ACCOUNT_EXCHANGE = "account-event-exchange"; // ACCOUNT服务交换机
|
public static final String ACCOUNT_EXCHANGE = "account-event-exchange"; // ACCOUNT服务交换机
|
||||||
public static final String PAY_EXCHANGE = "pay-event-exchange"; // PAY服务交换机
|
public static final String PAY_EXCHANGE = "pay-event-exchange"; // PAY服务交换机
|
||||||
|
|||||||
@ -54,27 +54,9 @@ public class MqMessageServiceImpl extends BaseServiceImpl<MqMessageMapper, MqMes
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
String jsonString = null;
|
|
||||||
|
|
||||||
try {
|
|
||||||
ObjectMapper objectMapper = new ObjectMapper();
|
|
||||||
jsonString = objectMapper.writeValueAsString(data);
|
|
||||||
} catch (JsonProcessingException e) {
|
|
||||||
throw new RuntimeException(e);
|
|
||||||
}
|
|
||||||
|
|
||||||
MessageProperties properties = new MessageProperties();
|
|
||||||
properties.setMessageId(uuid);
|
|
||||||
Message message = new Message(jsonString.getBytes(StandardCharsets.UTF_8), properties);
|
|
||||||
|
|
||||||
rabbitTemplate.convertAndSend(exchange, routing_key, message, new CorrelationData(uuid));
|
|
||||||
*/
|
|
||||||
|
|
||||||
// 使用 MessageBuilder 确保设置 messageId
|
// 使用 MessageBuilder 确保设置 messageId
|
||||||
Message message = MessageBuilder.withBody(data.toString().getBytes(StandardCharsets.UTF_8))
|
Message message = MessageBuilder.withBody(data.toString().getBytes(StandardCharsets.UTF_8))
|
||||||
.setHeader("messageId", uuid) // 添加自定义头部存储消息ID
|
.setHeader("messageId", uuid) // 添加自定义头部存储消息ID
|
||||||
// .setContentType("text/plain") // 明确指定内容类型
|
|
||||||
.setMessageId(uuid) // 设置标准 messageId 属性
|
.setMessageId(uuid) // 设置标准 messageId 属性
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
|
|||||||
@ -30,7 +30,6 @@ public class MessageListener {
|
|||||||
listener(dataStr, channel, message);
|
listener(dataStr, channel, message);
|
||||||
}
|
}
|
||||||
|
|
||||||
// @RabbitHandler
|
|
||||||
public void listener(String data, Channel channel, Message message) {
|
public void listener(String data, Channel channel, Message message) {
|
||||||
MsgTO msgTO = JSONUtil.toBean(data, MsgTO.class);
|
MsgTO msgTO = JSONUtil.toBean(data, MsgTO.class);
|
||||||
String messageId = message.getMessageProperties().getMessageId();
|
String messageId = message.getMessageProperties().getMessageId();
|
||||||
|
|||||||
@ -70,7 +70,6 @@ public class OrderPayedListener {
|
|||||||
listener(dataStr, channel, message);
|
listener(dataStr, channel, message);
|
||||||
}
|
}
|
||||||
|
|
||||||
// @RabbitHandler
|
|
||||||
public void listener(String data, Channel channel, Message message) throws IOException, InterruptedException {
|
public void listener(String data, Channel channel, Message message) throws IOException, InterruptedException {
|
||||||
// String messageId = message.getMessageProperties().getMessageId();
|
// String messageId = message.getMessageProperties().getMessageId();
|
||||||
if (StrUtil.isBlank(data)) {
|
if (StrUtil.isBlank(data)) {
|
||||||
|
|||||||
@ -5182,11 +5182,11 @@ public class ShopOrderBaseServiceImpl extends BaseServiceImpl<ShopOrderBaseMappe
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 延迟 消息跳转路径设置接口
|
* 延迟 消息跳转路径设置接口(最好使用消息队列,延迟1秒消费)
|
||||||
*
|
*
|
||||||
* @param orderIds
|
* @param orderIds
|
||||||
*/
|
*/
|
||||||
private void processOrderJumpPathAsync(List<String> orderIds) {
|
public void processOrderJumpPathAsync(List<String> orderIds) {
|
||||||
if (CollectionUtils.isEmpty(orderIds)) {
|
if (CollectionUtils.isEmpty(orderIds)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -5195,15 +5195,15 @@ public class ShopOrderBaseServiceImpl extends BaseServiceImpl<ShopOrderBaseMappe
|
|||||||
for (String orderId : orderIds) {
|
for (String orderId : orderIds) {
|
||||||
try {
|
try {
|
||||||
// 控制API调用频率
|
// 控制API调用频率
|
||||||
Thread.sleep(300); // 根据实际API限制调整
|
Thread.sleep(1200); // 根据实际API限制调整
|
||||||
wxOrderShippingService.setMsgJumpPath(orderId);
|
wxOrderShippingService.setMsgJumpPath(orderId);
|
||||||
|
log.info("[异步处理] 订单跳转路径设置入口 processOrderJumpPathAsync,订单ID: {}", orderId);
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
Thread.currentThread().interrupt();
|
Thread.currentThread().interrupt();
|
||||||
log.warn("[异步处理] 线程中断,订单ID: {}", orderId);
|
log.error("[异步处理] 线程中断,订单ID: {}", orderId);
|
||||||
break;
|
break;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.warn("[异步处理] 消息跳转路径设置失败,订单ID: {}, 错误: {}", orderId, e.getMessage());
|
log.warn("[异步处理] 消息跳转路径设置失败,订单ID: {}, 错误: {}", orderId, e.getMessage());
|
||||||
// 继续处理下一个订单
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, executor);
|
}, executor);
|
||||||
|
|||||||
@ -444,7 +444,7 @@ public class ShopStorePrinterServiceImpl extends BaseServiceImpl<ShopStorePrinte
|
|||||||
orderId = binding.getOrder_id();
|
orderId = binding.getOrder_id();
|
||||||
Integer storeId = binding.getStore_id();
|
Integer storeId = binding.getStore_id();
|
||||||
if (CheckUtil.isEmpty(storeId) || CheckUtil.isEmpty(orderId)) {
|
if (CheckUtil.isEmpty(storeId) || CheckUtil.isEmpty(orderId)) {
|
||||||
logger.warn("订单Id:{},店铺ID:{}为空,无法打印小票。", orderId, storeId);
|
logger.error("订单Id:{},店铺ID:{}为空,无法打印小票。", orderId, storeId);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -458,7 +458,9 @@ public class ShopStorePrinterServiceImpl extends BaseServiceImpl<ShopStorePrinte
|
|||||||
|
|
||||||
// 获取适用于退货场景的打印模板
|
// 获取适用于退货场景的打印模板
|
||||||
ShopStorePrinterTemplate template = shopStorePrinterTemplateService.getShopStorePrinterTemplateInner(storeId, StateCode.PRINTER_TEMP_CATE_REFUND);
|
ShopStorePrinterTemplate template = shopStorePrinterTemplateService.getShopStorePrinterTemplateInner(storeId, StateCode.PRINTER_TEMP_CATE_REFUND);
|
||||||
if (template == null || StrUtil.isBlank(template.getTemplate_name()) || StrUtil.isBlank(template.getTemplate_value())) {
|
if (template == null
|
||||||
|
|| StrUtil.isBlank(template.getTemplate_name())
|
||||||
|
|| StrUtil.isBlank(template.getTemplate_value())) {
|
||||||
// 模板缺失或无效,终止打印流程
|
// 模板缺失或无效,终止打印流程
|
||||||
logger.error("店铺{}未添加打票机打印模版,无法打印小票。", storeId);
|
logger.error("店铺{}未添加打票机打印模版,无法打印小票。", storeId);
|
||||||
return false;
|
return false;
|
||||||
@ -527,7 +529,7 @@ public class ShopStorePrinterServiceImpl extends BaseServiceImpl<ShopStorePrinte
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.debug("#### 调用飞鹅打票机的打印操作结束 ####");
|
logger.debug("#### 调用飞鹅打票机的打印退款订单操作结束 ####");
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
|||||||
@ -2,6 +2,7 @@ package com.suisung.mall.shop.store.service.impl;
|
|||||||
|
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||||
import com.suisung.mall.common.api.CommonResult;
|
import com.suisung.mall.common.api.CommonResult;
|
||||||
|
import com.suisung.mall.common.constant.CommonConstant;
|
||||||
import com.suisung.mall.common.modules.store.ShopStorePrinterTemplate;
|
import com.suisung.mall.common.modules.store.ShopStorePrinterTemplate;
|
||||||
import com.suisung.mall.core.web.service.impl.BaseServiceImpl;
|
import com.suisung.mall.core.web.service.impl.BaseServiceImpl;
|
||||||
import com.suisung.mall.shop.store.mapper.ShopStorePrinterTemplateMapper;
|
import com.suisung.mall.shop.store.mapper.ShopStorePrinterTemplateMapper;
|
||||||
@ -37,6 +38,7 @@ public class ShopStorePrinterTemplateServiceImpl extends BaseServiceImpl<ShopSto
|
|||||||
QueryWrapper<ShopStorePrinterTemplate> queryWrapper = new QueryWrapper<>();
|
QueryWrapper<ShopStorePrinterTemplate> queryWrapper = new QueryWrapper<>();
|
||||||
queryWrapper.eq("store_id", storeId != null ? storeId : 0)
|
queryWrapper.eq("store_id", storeId != null ? storeId : 0)
|
||||||
.eq("category", category)
|
.eq("category", category)
|
||||||
|
.eq("status", CommonConstant.Enable)
|
||||||
.orderByAsc("template_id");
|
.orderByAsc("template_id");
|
||||||
|
|
||||||
ShopStorePrinterTemplate shopStorePrinterTemplate = findOne(queryWrapper);
|
ShopStorePrinterTemplate shopStorePrinterTemplate = findOne(queryWrapper);
|
||||||
@ -46,6 +48,7 @@ public class ShopStorePrinterTemplateServiceImpl extends BaseServiceImpl<ShopSto
|
|||||||
queryWrapper.clear();
|
queryWrapper.clear();
|
||||||
queryWrapper.eq("store_id", 0)
|
queryWrapper.eq("store_id", 0)
|
||||||
.eq("category", category)
|
.eq("category", category)
|
||||||
|
.eq("status", CommonConstant.Enable)
|
||||||
.orderByAsc("template_id");
|
.orderByAsc("template_id");
|
||||||
|
|
||||||
shopStorePrinterTemplate = findOne(queryWrapper);
|
shopStorePrinterTemplate = findOne(queryWrapper);
|
||||||
|
|||||||
@ -47,7 +47,7 @@
|
|||||||
--------------------------------<BR>
|
--------------------------------<BR>
|
||||||
<CB>#${order_pickup_num_str}</CB><BR>
|
<CB>#${order_pickup_num_str}</CB><BR>
|
||||||
<L>退款原因:${return_buyer_message!'-'}</L><BR>
|
<L>退款原因:${return_buyer_message!'-'}</L><BR>
|
||||||
<BOLD>配送时间:${payment_time?string('yyyy-MM-dd HH:mm:ss')}(之后20-30分钟)</BOLD><BR>
|
<BOLD>配送时间:${payment_time?string('yyyy-MM-dd HH:mm:ss')}(20-30分钟)</BOLD><BR>
|
||||||
--------------------------------<BR>
|
--------------------------------<BR>
|
||||||
订单编号:${order_id}<BR>
|
订单编号:${order_id}<BR>
|
||||||
退单编号:${return_id}<BR>
|
退单编号:${return_id}<BR>
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user