|
|
@@ -189,6 +189,48 @@ public class WashOrderServiceImpl extends MyBaseServiceImpl<WashOrderMapper, Was
|
|
|
throw new BusinessException("关闭订单失败,请稍后重试或联系管理员");
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public void forceSettleOrder(String orderId) {
|
|
|
+ var order = lambdaQuery()
|
|
|
+ .eq(WashOrder::getOrderId, orderId)
|
|
|
+ .eq(WashOrder::getOrderStatus, WashOrder.ORDER_STATUS_开机)
|
|
|
+ .eq(WashOrder::getPayStatus, WashOrder.PAY_STATUS_未支付)
|
|
|
+ .one();
|
|
|
+ if (order == null) {
|
|
|
+ throw new BusinessException("未找到该订单或订单已完结");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 尝试通过 RRpc 发送关闭命令
|
|
|
+ boolean sent = sendCloseOrderWithRetry(order.getProductKey(), order.getDeviceName(), order.getOrderId(), 1);
|
|
|
+ if (sent) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ // RRpc 失败,主动查询设备订单状态
|
|
|
+ log.warn("订单 {} 关闭命令发送失败,尝试主动查询设备状态", order.getOrderId());
|
|
|
+ try {
|
|
|
+ OrderInfo orderInfo = awoaraService.queryOrder(order.getProductKey(), order.getDeviceName(), order.getOrderId());
|
|
|
+ if (orderInfo != null && orderInfo.getClose_type() != null && !orderInfo.getClose_type().isEmpty()) {
|
|
|
+ log.info("订单 {} 设备已关闭,执行结算", order.getOrderId());
|
|
|
+ orderSettlementService.settleOrder(order, orderInfo);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (orderInfo != null && (orderInfo.getClose_type() == null || orderInfo.getClose_type().isEmpty())) {
|
|
|
+ // 设备还在运行,尝试强制关闭
|
|
|
+ log.info("订单 {} 设备仍在运行,尝试强制关闭", order.getOrderId());
|
|
|
+ try {
|
|
|
+ awoaraService.forceCloseOrder(order.getProductKey(), order.getDeviceName());
|
|
|
+ } catch (Exception fe) {
|
|
|
+ log.error("订单 {} 强制关闭也失败", order.getOrderId(), fe);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("订单 {} 主动查询设备状态也失败", order.getOrderId(), e);
|
|
|
+ }
|
|
|
+
|
|
|
+ throw new BusinessException("强制结算失败,请稍后重试或联系管理员");
|
|
|
+ }
|
|
|
+
|
|
|
private boolean sendCloseOrderWithRetry(String productKey, String deviceName, String orderId, int maxRetries) {
|
|
|
for (int i = 0; i <= maxRetries; i++) {
|
|
|
try {
|