fix: JSON_CONTAINS 参数类型修复 + API sync

- 修复 JSON_CONTAINS(node_group_ids, int64) 类型错误,改为传 JSON 字符串
- 添加 node_group_ids IS NOT NULL 兼容判断,防止 NULL 列报错
- 同步 apis/ 及 routes.go、compat_types.go 改动

Co-Authored-By: claude-flow <ruv@ruv.net>
This commit is contained in:
2026-03-23 06:58:28 -07:00
parent f703b5089a
commit f111b36389
8 changed files with 131 additions and 13 deletions
+8 -3
View File
@@ -2,6 +2,7 @@ package subscribe
import (
"context"
"fmt"
"strings"
"github.com/perfect-panel/server/pkg/tool"
@@ -113,7 +114,9 @@ func (m *customSubscribeModel) FilterList(ctx context.Context, params *FilterPar
}
if params.NodeGroupId != nil {
// Filter by node_group_ids using JSON_CONTAINS
query = query.Where("JSON_CONTAINS(node_group_ids, ?)", *params.NodeGroupId)
// JSON_CONTAINS requires a JSON string, not a bare integer
jsonVal := fmt.Sprintf("%d", *params.NodeGroupId)
query = query.Where("(node_group_ids IS NOT NULL AND JSON_CONTAINS(node_group_ids, ?))", jsonVal)
}
if lang != "" {
query = query.Where("language = ?", lang)
@@ -205,8 +208,10 @@ func (m *customSubscribeModel) FilterListByNodeGroups(ctx context.Context, param
// Condition 2: JSON_CONTAINS(node_group_ids, id) for each id
for _, id := range params.NodeGroupIds {
conditions = append(conditions, "JSON_CONTAINS(node_group_ids, ?)")
args = append(args, id)
// JSON_CONTAINS requires a JSON string value, not a bare integer
jsonVal := fmt.Sprintf("%d", id)
conditions = append(conditions, "node_group_ids IS NOT NULL AND JSON_CONTAINS(node_group_ids, ?)")
args = append(args, jsonVal)
}
// Combine with OR: (node_group_id IN (...) OR JSON_CONTAINS(node_group_ids, id1) OR ...)