订单展示支付流程

This commit is contained in:
2025-07-03 11:10:16 +08:00
parent bd9330675e
commit 6294765388
3 changed files with 828 additions and 14 deletions

View File

@@ -181,6 +181,51 @@ public class MessageListenerService {
log.debug("推荐替代商品: 用户ID={}, 秒杀ID={}", userId, flashSaleId);
}
/**
* 提取Long值
*/
private Long extractLongValue(Object value) {
if (value == null) return null;
if (value instanceof Long) return (Long) value;
if (value instanceof Integer) return ((Integer) value).longValue();
if (value instanceof String) return Long.valueOf((String) value);
return Long.valueOf(value.toString());
}
/**
* 提取Integer值
*/
private Integer extractIntegerValue(Object value) {
if (value == null) return null;
if (value instanceof Integer) return (Integer) value;
if (value instanceof Long) return ((Long) value).intValue();
if (value instanceof String) return Integer.valueOf((String) value);
return Integer.valueOf(value.toString());
}
/**
* 解析Redisson消息格式
*/
private Map<String, Object> parseRedissonMessage(String messageBody) throws Exception {
// 处理Redisson序列化的数据格式
if (messageBody.startsWith("[") && messageBody.contains("java.util.HashMap")) {
// 解析Redisson序列化格式: ["java.util.HashMap",{...}]
int startIndex = messageBody.indexOf('{');
int endIndex = messageBody.lastIndexOf('}') + 1;
if (startIndex > 0 && endIndex > startIndex) {
String jsonPart = messageBody.substring(startIndex, endIndex);
// 处理Redisson的类型信息格式: ["java.lang.Long",11] -> 11
jsonPart = jsonPart.replaceAll("\\[\"java\\.lang\\.(Long|Integer|String)\",([^\\]]+)\\]", "$2");
return objectMapper.readValue(jsonPart, Map.class);
} else {
throw new RuntimeException("无法解析Redisson消息格式");
}
} else {
// 标准JSON格式
return objectMapper.readValue(messageBody, Map.class);
}
}
/**
* 订单状态变更监听器
*/
@@ -189,11 +234,13 @@ public class MessageListenerService {
public void onMessage(Message message, byte[] pattern) {
try {
String messageBody = new String(message.getBody());
Map<String, Object> data = objectMapper.readValue(messageBody, Map.class);
log.debug("接收到订单状态变更消息: {}", messageBody);
Long orderId = Long.valueOf(data.get("orderId").toString());
Long userId = Long.valueOf(data.get("userId").toString());
Integer status = Integer.valueOf(data.get("status").toString());
Map<String, Object> data = parseRedissonMessage(messageBody);
Long orderId = extractLongValue(data.get("orderId"));
Long userId = extractLongValue(data.get("userId"));
Integer status = extractIntegerValue(data.get("status"));
String action = data.get("action").toString();
log.info("订单状态变更: 订单ID={}, 用户ID={}, 状态={}, 操作={}",
@@ -216,10 +263,12 @@ public class MessageListenerService {
public void onMessage(Message message, byte[] pattern) {
try {
String messageBody = new String(message.getBody());
Map<String, Object> data = objectMapper.readValue(messageBody, Map.class);
log.debug("接收到库存变更消息: {}", messageBody);
Long productId = Long.valueOf(data.get("productId").toString());
Integer quantity = Integer.valueOf(data.get("quantity").toString());
Map<String, Object> data = parseRedissonMessage(messageBody);
Long productId = extractLongValue(data.get("productId"));
Integer quantity = extractIntegerValue(data.get("quantity"));
String operation = data.get("operation").toString();
log.info("库存变更: 商品ID={}, 数量={}, 操作={}", productId, quantity, operation);
@@ -241,10 +290,12 @@ public class MessageListenerService {
public void onMessage(Message message, byte[] pattern) {
try {
String messageBody = new String(message.getBody());
Map<String, Object> data = objectMapper.readValue(messageBody, Map.class);
log.debug("接收到秒杀结果消息: {}", messageBody);
Long userId = Long.valueOf(data.get("userId").toString());
Long flashSaleId = Long.valueOf(data.get("flashSaleId").toString());
Map<String, Object> data = parseRedissonMessage(messageBody);
Long userId = extractLongValue(data.get("userId"));
Long flashSaleId = extractLongValue(data.get("flashSaleId"));
Boolean success = Boolean.valueOf(data.get("success").toString());
log.info("秒杀结果: 用户ID={}, 秒杀ID={}, 成功={}", userId, flashSaleId, success);
@@ -266,9 +317,11 @@ public class MessageListenerService {
public void onMessage(Message message, byte[] pattern) {
try {
String messageBody = new String(message.getBody());
Map<String, Object> data = objectMapper.readValue(messageBody, Map.class);
log.debug("接收到用户行为消息: {}", messageBody);
Long userId = Long.valueOf(data.get("userId").toString());
Map<String, Object> data = parseRedissonMessage(messageBody);
Long userId = extractLongValue(data.get("userId"));
String action = data.get("action").toString();
log.info("用户行为: 用户ID={}, 行为={}", userId, action);