From e88bcd2b69fc0c799eaf183f19d4cc3425ea08e9 Mon Sep 17 00:00:00 2001
From: Administrator <15274802129@163.com>
Date: Fri, 20 Nov 2026 13:39:30 +0800
Subject: [PATCH] fix(gateApi): 忽略Gate配置反序列化未知属性

---
 src/main/java/com/xcong/excoin/modules/gateApi/GateConfigPersistenceService.java |   45 +++++++++++++++++++++++++++++++++++++++++++--
 1 files changed, 43 insertions(+), 2 deletions(-)

diff --git a/src/main/java/com/xcong/excoin/modules/gateApi/GateConfigPersistenceService.java b/src/main/java/com/xcong/excoin/modules/gateApi/GateConfigPersistenceService.java
index 480b87c..8db0131 100644
--- a/src/main/java/com/xcong/excoin/modules/gateApi/GateConfigPersistenceService.java
+++ b/src/main/java/com/xcong/excoin/modules/gateApi/GateConfigPersistenceService.java
@@ -1,6 +1,7 @@
 package com.xcong.excoin.modules.gateApi;
 
 import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.DeserializationFeature;
 import com.fasterxml.jackson.databind.SerializationFeature;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.stereotype.Service;
@@ -25,7 +26,9 @@
     private static final String CONFIG_PREFIX = "gate-config-";
     private static final String JSON_SUFFIX = ".json";
 
-    private final ObjectMapper mapper = new ObjectMapper().enable(SerializationFeature.INDENT_OUTPUT);
+    private final ObjectMapper mapper = new ObjectMapper()
+            .enable(SerializationFeature.INDENT_OUTPUT)
+            .disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
 
     @PostConstruct
     public void ensureConfigDir() {
@@ -93,7 +96,7 @@
                 .priceScale(GateWebSocketClientManager.DEFAULT_PRICE_SCALE)
                 .contractMultiplier(new BigDecimal(GateWebSocketClientManager.DEFAULT_CONTRACT_MULTIPLIER))
                 .unrealizedPnlPriceMode(GateConfig.PnLPriceMode.valueOf(GateWebSocketClientManager.DEFAULT_PNL_MODE))
-                .isProduction(true)
+                .isProduction(false)
                 .reopenMaxRetries(GateWebSocketClientManager.DEFAULT_REOPEN_MAX_RETRIES)
                 // 可调参数 — 从 DTO 读取
                 .gridRate(nvl(dto.getGridRate(), new BigDecimal("0.005")))
@@ -103,6 +106,24 @@
                 .quantity(nvl(dto.getQuantity(), "2"))
                 .maxPositionSize(dto.getMaxPositionSize())
                 .stopLossCount(dto.getStopLossCount())
+                .takeProfitGridSpan(dto.getTakeProfitGridSpan())
+                .priceDriveEnabled(nvl(dto.getPriceDriveEnabled(), true))
+                .rounds(dto.getRounds())
+                .stopLossCountMode(nvl(dto.getStopLossCountMode(), "dual"))
+                .addPositionInterval(dto.getAddPositionInterval() >= 0 ? dto.getAddPositionInterval() : 3)
+                .addPositionQuantity(dto.getAddPositionQuantity() > 0 ? dto.getAddPositionQuantity() : 1)
+                .maxPositionPerSide(dto.getMaxPositionPerSide())
+                .addPositionStartThreshold(dto.getAddPositionStartThreshold() >= 0 ? dto.getAddPositionStartThreshold() : 1)
+                .addPositionStopThreshold(dto.getAddPositionStopThreshold() >= 0 ? dto.getAddPositionStopThreshold() : 0)
+                .placeExcessTakeProfit(normalizeTakeProfitMode(dto.getPlaceExcessTakeProfit()))
+                .dualStopLossEnabled(nvl(dto.getDualStopLossEnabled(), false))
+                .longStopLossPrice(dto.getLongStopLossPrice())
+                .shortStopLossPrice(dto.getShortStopLossPrice())
+                .tpTriggerOppositeAddEnabled(nvl(dto.getTpTriggerOppositeAddEnabled(), false))
+                .tpTriggerOppositeAddQuantity(dto.getTpTriggerOppositeAddQuantity() != null && dto.getTpTriggerOppositeAddQuantity() > 0 ? dto.getTpTriggerOppositeAddQuantity() : 0)
+                .tpPositionReplenishEnabled(nvl(dto.getTpPositionReplenishEnabled(), false))
+                .baseTakeProfitTotalQty(dto.getBaseTakeProfitTotalQty() != null && dto.getBaseTakeProfitTotalQty() > 0 ? dto.getBaseTakeProfitTotalQty() : 0)
+                .originalPositionReduce(dto.getOriginalPositionReduce() != null && dto.getOriginalPositionReduce() > 0 ? dto.getOriginalPositionReduce() : 0)
                 .build();
     }
 
@@ -132,4 +153,24 @@
     private static <T> T nvl(T value, T fallback) {
         return value != null ? value : fallback;
     }
+
+    /**
+     * 归一化止盈挂单模式,兼容旧版 boolean 配置(旧 JSON 的 true/false 会被 Jackson 反序列化为字符串)。
+     */
+    private static String normalizeTakeProfitMode(String raw) {
+        if (raw == null || raw.trim().isEmpty()) {
+            return GateConfig.EXCESS_TP_OFF;
+        }
+        switch (raw.trim()) {
+            case "off":
+                return GateConfig.EXCESS_TP_OFF;
+            case "true":
+            case "concentrated":
+                return GateConfig.EXCESS_TP_CONCENTRATED;
+            case "dispersed":
+                return GateConfig.EXCESS_TP_DISPERSED;
+            default:
+                return GateConfig.EXCESS_TP_OFF;
+        }
+    }
 }

--
Gitblit v1.9.1