This commit is contained in:
Mrx
2026-01-22 14:26:15 +08:00
parent 7785d3b6ef
commit 473468e680

View File

@@ -6,6 +6,7 @@ import (
"errors"
"fmt"
"math/rand"
"regexp"
"sort"
"strconv"
"strings"
@@ -947,40 +948,84 @@ func buildFinalResponse(enrichedCompanies []EnrichedCompanyInfo, allCompanies []
}
return nil
}
// 处理 regCap分离数字和单位
// 例如:"100.000000万人民币" -> regCapital: "100.000000", regCapitalCurrency: "万人民币"
regCapital := ""
regCapitalCurrency := "万人民币"
if regCapVal := getVal("regCap", "regCapital"); regCapVal != nil {
if regCapStr, ok := regCapVal.(string); ok && regCapStr != "" {
// 使用正则表达式提取数字部分(包括小数点)
re := regexp.MustCompile(`[\d.]+`)
matches := re.FindString(regCapStr)
if matches != "" {
regCapital = matches
// 提取单位部分(数字之后的所有内容)
if numIndex := strings.Index(regCapStr, matches); numIndex >= 0 {
unitPart := regCapStr[numIndex+len(matches):]
unitPart = strings.TrimSpace(unitPart)
if unitPart != "" {
regCapitalCurrency = unitPart
}
}
} else {
// 如果没有找到数字,直接使用原值
regCapital = regCapStr
}
}
}
// 如果 regCapCur 有值,优先使用它
if regCapCurVal := getVal("regCapCur", "regCapitalCurrency"); regCapCurVal != nil {
if regCapCurStr, ok := regCapCurVal.(string); ok && regCapCurStr != "" {
regCapitalCurrency = regCapCurStr
}
}
// 构建完整的 basicInfo按前端期望的格式
basicInfo := map[string]interface{}{}
if v := getVal("regStatus"); v != nil {
// regStatus从 orgStatus 获取)
if v := getVal("orgStatus", "regStatus"); v != nil {
basicInfo["regStatus"] = v
}
if v := getVal("creditCode", "creditNo"); v != nil {
// creditCode从 creditNo 获取)
if v := getVal("creditNo", "creditCode"); v != nil {
basicInfo["creditCode"] = v
}
if v := getVal("regCapital"); v != nil {
basicInfo["regCapital"] = v
// regCapital从 regCap 中提取的数字部分)
if regCapital != "" {
basicInfo["regCapital"] = regCapital
}
if v := getVal("regCapitalCurrency"); v != nil {
basicInfo["regCapitalCurrency"] = v
// regCapitalCurrency从 regCap 中提取的单位部分,或从 regCapCur 获取)
if regCapitalCurrency != "" {
basicInfo["regCapitalCurrency"] = regCapitalCurrency
}
if v := getVal("estiblishTime"); v != nil {
// estiblishTime从 esDate 获取)
if v := getVal("esDate", "estiblishTime", "establishDate"); v != nil {
basicInfo["estiblishTime"] = v
}
if v := getVal("regNumber", "regNo"); v != nil {
// regNumber从 regNo 获取)
if v := getVal("regNo", "regNumber"); v != nil {
basicInfo["regNumber"] = v
}
if v := getVal("entType"); v != nil {
// entType从 orgType 获取)
if v := getVal("orgType", "entType"); v != nil {
basicInfo["entType"] = v
}
// industry
if v := getVal("industry"); v != nil {
basicInfo["industry"] = v
}
// legalPersonName从 ryName 获取)
if v := getVal("ryName", "legalPersonName"); v != nil {
basicInfo["legalPersonName"] = v
}
// 保留其他可能的字段
if v := getVal("regInstitute"); v != nil {
basicInfo["regInstitute"] = v
}
if v := getVal("approvedTime"); v != nil {
basicInfo["approvedTime"] = v
}
if v := getVal("legalPersonName"); v != nil {
basicInfo["legalPersonName"] = v
}
if v := getVal("phone"); v != nil {
basicInfo["phone"] = v
}
@@ -1060,16 +1105,49 @@ func buildFinalResponse(enrichedCompanies []EnrichedCompanyInfo, allCompanies []
companyMap["staffList"] = staffList
}
// 辅助函数:将历史记录数据转换为前端期望的格式
// 如果是数组,转换为 { items: [], total: 0 } 格式
// 如果是空对象,转换为空数组
convertHistoryData := func(data interface{}) interface{} {
if data == nil {
return []interface{}{}
}
// 如果是数组,转换为 { items: [], total: 0 } 格式
if arr, ok := data.([]interface{}); ok {
return map[string]interface{}{
"items": arr,
"total": len(arr),
}
}
// 如果是 map检查是否为空
if dataMap, ok := data.(map[string]interface{}); ok {
if len(dataMap) == 0 {
return []interface{}{}
}
// 如果已经有 items 和 total 字段,直接返回
if _, hasItems := dataMap["items"]; hasItems {
return dataMap
}
// 否则转换为 { items: [], total: 0 } 格式
return map[string]interface{}{
"items": []interface{}{},
"total": 0,
}
}
return []interface{}{}
}
// 检查是否是已处理的企业前3个
if enriched, exists := processedMap[company.Index]; exists {
// 已处理的企业,添加详细信息
companyMap["invest_history"] = enriched.InvestHistory
companyMap["financing_history"] = enriched.FinancingHistory
companyMap["punishment_info"] = enriched.PunishmentInfo
companyMap["abnormal_info"] = enriched.AbnormalInfo
companyMap["lawsuit_info"] = enriched.LawsuitInfo
companyMap["own_tax"] = enriched.OwnTax
companyMap["tax_contravention"] = enriched.TaxContravention
companyMap["invest_history"] = convertHistoryData(enriched.InvestHistory)
companyMap["financing_history"] = convertHistoryData(enriched.FinancingHistory)
companyMap["punishment_info"] = convertHistoryData(enriched.PunishmentInfo)
companyMap["abnormal_info"] = convertHistoryData(enriched.AbnormalInfo)
// lawsuit_info 改为 lawsuitInfo(驼峰命名)
companyMap["lawsuitInfo"] = enriched.LawsuitInfo
companyMap["own_tax"] = convertHistoryData(enriched.OwnTax)
companyMap["tax_contravention"] = convertHistoryData(enriched.TaxContravention)
} else {
// 未处理的企业,添加空的详细信息
companyMap["invest_history"] = map[string]interface{}{}