fix: 修复 v1.1.10 版本下单成功不发送通知的问题
- 移除 OrderStatusUpdateService 中错误的双重检查逻辑 - 修复买入订单和卖出订单通知逻辑 - 确保在标记为已发送后立即发送通知 - 问题:保存 notificationSent=true 后立即查询检查,导致通知永远被跳过 - 修复:改为标记后直接发送通知,利用数据库状态防止并发重复
This commit is contained in:
+55
-87
@@ -450,27 +450,19 @@ class OrderStatusUpdateService(
|
|||||||
|
|
||||||
logger.info("更新卖出订单价格成功: orderId=${record.sellOrderId}, 原价格=${record.sellPrice}, 新价格=$actualSellPrice")
|
logger.info("更新卖出订单价格成功: orderId=${record.sellOrderId}, 原价格=${record.sellPrice}, 新价格=$actualSellPrice")
|
||||||
|
|
||||||
// 重新从数据库查询最新的记录状态,检查是否已被其他任务标记为已处理
|
// 发送通知(使用实际价格)
|
||||||
val latestRecord = sellMatchRecordRepository.findById(record.id!!).orElse(null)
|
sendSellOrderNotification(
|
||||||
if (latestRecord == null) {
|
record = updatedRecord,
|
||||||
logger.warn("卖出记录已被删除,跳过发送通知: orderId=${record.sellOrderId}, recordId=${record.id}")
|
actualPrice = actualSellPrice.toString(),
|
||||||
} else if (latestRecord.priceUpdated) {
|
actualSize = record.totalMatchedQuantity.toString(),
|
||||||
logger.debug("卖出记录已被标记为已处理,跳过重复发送通知: orderId=${record.sellOrderId}, recordId=${record.id}")
|
account = account,
|
||||||
} else {
|
copyTrading = copyTrading,
|
||||||
// 发送通知(使用实际价格)
|
clobApi = clobApi,
|
||||||
sendSellOrderNotification(
|
apiSecret = apiSecret,
|
||||||
record = updatedRecord,
|
apiPassphrase = apiPassphrase,
|
||||||
actualPrice = actualSellPrice.toString(),
|
orderCreatedAt = record.createdAt
|
||||||
actualSize = record.totalMatchedQuantity.toString(),
|
)
|
||||||
account = account,
|
logger.info("卖出订单通知已发送: orderId=${record.sellOrderId}")
|
||||||
copyTrading = copyTrading,
|
|
||||||
clobApi = clobApi,
|
|
||||||
apiSecret = apiSecret,
|
|
||||||
apiPassphrase = apiPassphrase,
|
|
||||||
orderCreatedAt = record.createdAt
|
|
||||||
)
|
|
||||||
logger.info("卖出订单通知已发送: orderId=${record.sellOrderId}")
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
// 价格相同,但已经查询过,先标记为已处理再发送通知
|
// 价格相同,但已经查询过,先标记为已处理再发送通知
|
||||||
val updatedRecord = SellMatchRecord(
|
val updatedRecord = SellMatchRecord(
|
||||||
@@ -491,27 +483,19 @@ class OrderStatusUpdateService(
|
|||||||
|
|
||||||
logger.debug("卖出订单价格无需更新: orderId=${record.sellOrderId}, price=$actualSellPrice")
|
logger.debug("卖出订单价格无需更新: orderId=${record.sellOrderId}, price=$actualSellPrice")
|
||||||
|
|
||||||
// 重新从数据库查询最新的记录状态,检查是否已被其他任务标记为已处理
|
// 发送通知
|
||||||
val latestRecord = sellMatchRecordRepository.findById(record.id!!).orElse(null)
|
sendSellOrderNotification(
|
||||||
if (latestRecord == null) {
|
record = updatedRecord,
|
||||||
logger.warn("卖出记录已被删除,跳过发送通知: orderId=${record.sellOrderId}, recordId=${record.id}")
|
actualPrice = actualSellPrice.toString(),
|
||||||
} else if (latestRecord.priceUpdated) {
|
actualSize = record.totalMatchedQuantity.toString(),
|
||||||
logger.debug("卖出记录已被标记为已处理,跳过重复发送通知: orderId=${record.sellOrderId}, recordId=${record.id}")
|
account = account,
|
||||||
} else {
|
copyTrading = copyTrading,
|
||||||
// 发送通知
|
clobApi = clobApi,
|
||||||
sendSellOrderNotification(
|
apiSecret = apiSecret,
|
||||||
record = updatedRecord,
|
apiPassphrase = apiPassphrase,
|
||||||
actualPrice = actualSellPrice.toString(),
|
orderCreatedAt = record.createdAt
|
||||||
actualSize = record.totalMatchedQuantity.toString(),
|
)
|
||||||
account = account,
|
logger.info("卖出订单通知已发送: orderId=${record.sellOrderId}")
|
||||||
copyTrading = copyTrading,
|
|
||||||
clobApi = clobApi,
|
|
||||||
apiSecret = apiSecret,
|
|
||||||
apiPassphrase = apiPassphrase,
|
|
||||||
orderCreatedAt = record.createdAt
|
|
||||||
)
|
|
||||||
logger.info("卖出订单通知已发送: orderId=${record.sellOrderId}")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
logger.warn("更新卖出订单价格失败: orderId=${record.sellOrderId}, error=${e.message}", e)
|
logger.warn("更新卖出订单价格失败: orderId=${record.sellOrderId}, error=${e.message}", e)
|
||||||
@@ -566,15 +550,7 @@ class OrderStatusUpdateService(
|
|||||||
)
|
)
|
||||||
copyOrderTrackingRepository.save(updatedOrder)
|
copyOrderTrackingRepository.save(updatedOrder)
|
||||||
|
|
||||||
// 重新从数据库查询最新的订单状态,检查是否已被其他任务标记为已发送通知
|
sendBuyOrderNotification(updatedOrder, useTemporaryData = true, orderCreatedAt = order.createdAt)
|
||||||
val latestOrder = copyOrderTrackingRepository.findById(order.id!!).orElse(null)
|
|
||||||
if (latestOrder == null) {
|
|
||||||
logger.warn("订单已被删除,跳过发送通知: orderId=${order.buyOrderId}, copyOrderTrackingId=${order.id}")
|
|
||||||
} else if (latestOrder.notificationSent) {
|
|
||||||
logger.debug("订单已被标记为已发送通知,跳过重复发送: orderId=${order.buyOrderId}, copyOrderTrackingId=${order.id}")
|
|
||||||
} else {
|
|
||||||
sendBuyOrderNotification(updatedOrder, useTemporaryData = true, orderCreatedAt = order.createdAt)
|
|
||||||
}
|
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -662,44 +638,37 @@ class OrderStatusUpdateService(
|
|||||||
// 更新订单数据(如果实际数据与临时数据不同)
|
// 更新订单数据(如果实际数据与临时数据不同)
|
||||||
val needUpdate = actualPrice != order.price || actualSize != order.quantity
|
val needUpdate = actualPrice != order.price || actualSize != order.quantity
|
||||||
|
|
||||||
// 先保存更新后的订单,标记 notificationSent = true
|
// 先保存更新后的订单,标记 notificationSent = true
|
||||||
// 这样可以防止其他并发任务重复发送通知
|
// 这样可以防止其他并发任务重复发送通知
|
||||||
val updatedOrder = CopyOrderTracking(
|
val updatedOrder = CopyOrderTracking(
|
||||||
id = order.id,
|
id = order.id,
|
||||||
copyTradingId = order.copyTradingId,
|
copyTradingId = order.copyTradingId,
|
||||||
accountId = order.accountId,
|
accountId = order.accountId,
|
||||||
leaderId = order.leaderId,
|
leaderId = order.leaderId,
|
||||||
marketId = order.marketId,
|
marketId = order.marketId,
|
||||||
side = order.side,
|
side = order.side,
|
||||||
outcomeIndex = order.outcomeIndex,
|
outcomeIndex = order.outcomeIndex,
|
||||||
buyOrderId = order.buyOrderId,
|
buyOrderId = order.buyOrderId,
|
||||||
leaderBuyTradeId = order.leaderBuyTradeId,
|
leaderBuyTradeId = order.leaderBuyTradeId,
|
||||||
quantity = actualSize, // 使用实际数量
|
quantity = actualSize, // 使用实际数量
|
||||||
price = actualPrice, // 使用实际价格
|
price = actualPrice, // 使用实际价格
|
||||||
matchedQuantity = order.matchedQuantity,
|
matchedQuantity = order.matchedQuantity,
|
||||||
remainingQuantity = order.remainingQuantity,
|
remainingQuantity = order.remainingQuantity,
|
||||||
status = order.status,
|
status = order.status,
|
||||||
notificationSent = true, // 标记为已发送通知
|
notificationSent = true, // 标记为已发送通知
|
||||||
createdAt = order.createdAt,
|
createdAt = order.createdAt,
|
||||||
updatedAt = System.currentTimeMillis()
|
updatedAt = System.currentTimeMillis()
|
||||||
)
|
)
|
||||||
|
|
||||||
// 保存更新后的订单(在发送通知之前保存)
|
// 保存更新后的订单(在发送通知之前保存)
|
||||||
copyOrderTrackingRepository.save(updatedOrder)
|
copyOrderTrackingRepository.save(updatedOrder)
|
||||||
|
|
||||||
if (needUpdate) {
|
if (needUpdate) {
|
||||||
logger.info("更新买入订单数据成功: orderId=${order.buyOrderId}, 原价格=${order.price}, 新价格=$actualPrice, 原数量=${order.quantity}, 新数量=$actualSize")
|
logger.info("更新买入订单数据成功: orderId=${order.buyOrderId}, 原价格=${order.price}, 新价格=$actualPrice, 原数量=${order.quantity}, 新数量=$actualSize")
|
||||||
} else {
|
} else {
|
||||||
logger.debug("买入订单数据无需更新: orderId=${order.buyOrderId}")
|
logger.debug("买入订单数据无需更新: orderId=${order.buyOrderId}")
|
||||||
}
|
}
|
||||||
|
|
||||||
// 重新从数据库查询最新的订单状态,检查是否已被其他任务标记为已发送通知
|
|
||||||
val latestOrder = copyOrderTrackingRepository.findById(order.id!!).orElse(null)
|
|
||||||
if (latestOrder == null) {
|
|
||||||
logger.warn("订单已被删除,跳过发送通知: orderId=${order.buyOrderId}, copyOrderTrackingId=${order.id}")
|
|
||||||
} else if (latestOrder.notificationSent) {
|
|
||||||
logger.debug("订单已被标记为已发送通知,跳过重复发送: orderId=${order.buyOrderId}, copyOrderTrackingId=${order.id}")
|
|
||||||
} else {
|
|
||||||
// 发送通知(使用实际数据)
|
// 发送通知(使用实际数据)
|
||||||
sendBuyOrderNotification(
|
sendBuyOrderNotification(
|
||||||
order = updatedOrder,
|
order = updatedOrder,
|
||||||
@@ -713,7 +682,6 @@ class OrderStatusUpdateService(
|
|||||||
apiPassphrase = apiPassphrase,
|
apiPassphrase = apiPassphrase,
|
||||||
orderCreatedAt = order.createdAt
|
orderCreatedAt = order.createdAt
|
||||||
)
|
)
|
||||||
}
|
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
logger.warn("更新买入订单失败: orderId=${order.buyOrderId}, error=${e.message}", e)
|
logger.warn("更新买入订单失败: orderId=${order.buyOrderId}, error=${e.message}", e)
|
||||||
// 继续处理下一条记录
|
// 继续处理下一条记录
|
||||||
|
|||||||
Reference in New Issue
Block a user