From 6104bfb84fdabc592d7334495dbcf461ee215e12 Mon Sep 17 00:00:00 2001 From: Mrx <18278715334@163.com> Date: Thu, 22 Jan 2026 18:10:21 +0800 Subject: [PATCH] f --- .../processors/qygl/qygl3f8e_processor.go | 50 ++++++++++++++----- 1 file changed, 38 insertions(+), 12 deletions(-) diff --git a/internal/domains/api/services/processors/qygl/qygl3f8e_processor.go b/internal/domains/api/services/processors/qygl/qygl3f8e_processor.go index 0ee6a96..3204d37 100644 --- a/internal/domains/api/services/processors/qygl/qygl3f8e_processor.go +++ b/internal/domains/api/services/processors/qygl/qygl3f8e_processor.go @@ -512,15 +512,19 @@ func processEntoutData(resultBytes []byte) map[string]interface{} { // 如果 entoutData 包含 "data" 字段,提取 data 字段的内容 // 因为有些响应格式是 { "data": { "civil": {...} } },需要提取内部的 data + var actualData map[string]interface{} if dataField, ok := entoutData["data"].(map[string]interface{}); ok { - entoutData = dataField + actualData = dataField + } else { + // 如果没有 data 字段,直接使用 entoutData(可能已经是 data 的内容) + actualData = entoutData } // 清理数据,将 "-" 转换为合适的默认值 - entoutData = cleanEntoutData(entoutData) + cleanedData := cleanEntoutData(actualData) // 检查是否有有效数据 - hasData := hasValidEntoutData(entoutData) + hasData := hasValidEntoutData(cleanedData) if !hasData { return map[string]interface{}{ "msg": "没有找到", @@ -530,7 +534,7 @@ func processEntoutData(resultBytes []byte) map[string]interface{} { // 构建返回格式 entoutWrapped := map[string]interface{}{ "msg": "成功", - "data": entoutData, + "data": cleanedData, } return entoutWrapped @@ -592,20 +596,28 @@ func cleanEntoutData(data map[string]interface{}) map[string]interface{} { "crc": cleanNumericValue, } - // 处理所有字段 + // 处理所有字段,确保所有字段都被正确映射 for key, value := range data { + if value == nil { + // 跳过 nil 值,但保留空对象和空数组 + continue + } + if handler, ok := specialFields[key]; ok { cleaned[key] = handler(value) } else { - cleaned[key] = cleanValue(value) + // 对于其他字段(如 cases_tree, civil, implement 等),使用 cleanValue 处理 + cleanedValue := cleanValue(value) + // 只有当清理后的值不为空时才添加 + if !isEmptyValue(cleanedValue) { + cleaned[key] = cleanedValue + } else if key == "cases_tree" { + // cases_tree 即使是空对象也保留,因为它是重要的结构字段 + cleaned[key] = cleanedValue + } } } - // 保留 count 在根级别(兼容旧逻辑,如果存在) - if countVal, ok := data["count"]; ok { - cleaned["count"] = cleanCountData(countVal) - } - return cleaned } @@ -764,6 +776,17 @@ func cleanMapData(data map[string]interface{}) map[string]interface{} { cleaned := make(map[string]interface{}) hasValidData := false + // 定义需要保留的结构字段(即使为空也保留) + structuralFields := map[string]bool{ + "cases_tree": true, + "civil": true, + "criminal": true, + "administrative": true, + "bankrupt": true, + "implement": true, + "preservation": true, + } + for key, value := range data { var cleanedValue interface{} // 根据字段命名规律判断是否为数值字段 @@ -777,10 +800,13 @@ func cleanMapData(data map[string]interface{}) map[string]interface{} { // 检查是否有有效数据 if !isEmptyValue(cleanedValue) { hasValidData = true + } else if structuralFields[key] { + // 结构字段即使为空也保留,并标记为有数据 + hasValidData = true } } - // 如果所有字段都是空值,返回空 map + // 如果所有字段都是空值且没有结构字段,返回空 map if !hasValidData { return make(map[string]interface{}) }