Administrator
2026-09-22 8ab75ee6f68c3cde70319b9863db6947f668175f
fix(station): 修复指令执行失败时状态更新异常问题

- 在 GateCommandConsumer 中添加 newState 为空时的防御性处理,避免状态被污染
- 在 GateMessageConsumer 中添加对空状态值的校验,防止实例状态被设置为非法值
- 统一在异常情况下回退到当前真实状态,确保系统状态一致性
2 files modified
11 ■■■■■ changed files
src/main/java/com/xcong/excoin/modules/gateApi/GateCommandConsumer.java 6 ●●●●● patch | view | raw | blame | history
src/main/java/com/xcong/excoin/modules/station/consumer/GateMessageConsumer.java 5 ●●●●● patch | view | raw | blame | history
src/main/java/com/xcong/excoin/modules/gateApi/GateCommandConsumer.java
@@ -82,11 +82,15 @@
            }
        } catch (Exception e) {
            success = false;
            newState = "ERROR";
            message = e.getMessage();
            log.error("[Gate] 指令执行失败", e);
        }
        // 指令异常/未知类型时 newState 可能为空,统一回退为当前真实状态,避免污染 Station 侧实例状态
        if (newState == null || newState.isEmpty()) {
            newState = strategy.getState().name();
        }
        // 发送 ACK 到 Station
        CmdAckMsg ack = CmdAckMsg.builder()
                .commandId(cmd.getCommandId())
src/main/java/com/xcong/excoin/modules/station/consumer/GateMessageConsumer.java
@@ -44,7 +44,10 @@
            } else if ("CMD_ACK".equals(type)) {
                CmdAckMsg ack = JSON.parseObject(json.getString("payload"), CmdAckMsg.class);
                instanceRegistry.updateState(apiKeyMd5, ack.getNewState());
                // 防御:newState 为空时跳过更新,避免把实例状态污染为非法值(导致前端误置灰)
                if (ack.getNewState() != null && !ack.getNewState().isEmpty()) {
                    instanceRegistry.updateState(apiKeyMd5, ack.getNewState());
                }
                log.info("[Station] 指令确认: cmdId={}, success={}, newState={}",
                        ack.getCommandId(), ack.isSuccess(), ack.getNewState());
            }