f
This commit is contained in:
@@ -6,6 +6,7 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"math/rand"
|
"math/rand"
|
||||||
|
"regexp"
|
||||||
"sort"
|
"sort"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
@@ -947,40 +948,84 @@ func buildFinalResponse(enrichedCompanies []EnrichedCompanyInfo, allCompanies []
|
|||||||
}
|
}
|
||||||
return nil
|
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{}{}
|
basicInfo := map[string]interface{}{}
|
||||||
if v := getVal("regStatus"); v != nil {
|
// regStatus(从 orgStatus 获取)
|
||||||
|
if v := getVal("orgStatus", "regStatus"); v != nil {
|
||||||
basicInfo["regStatus"] = v
|
basicInfo["regStatus"] = v
|
||||||
}
|
}
|
||||||
if v := getVal("creditCode", "creditNo"); v != nil {
|
// creditCode(从 creditNo 获取)
|
||||||
|
if v := getVal("creditNo", "creditCode"); v != nil {
|
||||||
basicInfo["creditCode"] = v
|
basicInfo["creditCode"] = v
|
||||||
}
|
}
|
||||||
if v := getVal("regCapital"); v != nil {
|
// regCapital(从 regCap 中提取的数字部分)
|
||||||
basicInfo["regCapital"] = v
|
if regCapital != "" {
|
||||||
|
basicInfo["regCapital"] = regCapital
|
||||||
}
|
}
|
||||||
if v := getVal("regCapitalCurrency"); v != nil {
|
// regCapitalCurrency(从 regCap 中提取的单位部分,或从 regCapCur 获取)
|
||||||
basicInfo["regCapitalCurrency"] = v
|
if regCapitalCurrency != "" {
|
||||||
|
basicInfo["regCapitalCurrency"] = regCapitalCurrency
|
||||||
}
|
}
|
||||||
if v := getVal("estiblishTime"); v != nil {
|
// estiblishTime(从 esDate 获取)
|
||||||
|
if v := getVal("esDate", "estiblishTime", "establishDate"); v != nil {
|
||||||
basicInfo["estiblishTime"] = v
|
basicInfo["estiblishTime"] = v
|
||||||
}
|
}
|
||||||
if v := getVal("regNumber", "regNo"); v != nil {
|
// regNumber(从 regNo 获取)
|
||||||
|
if v := getVal("regNo", "regNumber"); v != nil {
|
||||||
basicInfo["regNumber"] = v
|
basicInfo["regNumber"] = v
|
||||||
}
|
}
|
||||||
if v := getVal("entType"); v != nil {
|
// entType(从 orgType 获取)
|
||||||
|
if v := getVal("orgType", "entType"); v != nil {
|
||||||
basicInfo["entType"] = v
|
basicInfo["entType"] = v
|
||||||
}
|
}
|
||||||
|
// industry
|
||||||
if v := getVal("industry"); v != nil {
|
if v := getVal("industry"); v != nil {
|
||||||
basicInfo["industry"] = v
|
basicInfo["industry"] = v
|
||||||
}
|
}
|
||||||
|
// legalPersonName(从 ryName 获取)
|
||||||
|
if v := getVal("ryName", "legalPersonName"); v != nil {
|
||||||
|
basicInfo["legalPersonName"] = v
|
||||||
|
}
|
||||||
|
// 保留其他可能的字段
|
||||||
if v := getVal("regInstitute"); v != nil {
|
if v := getVal("regInstitute"); v != nil {
|
||||||
basicInfo["regInstitute"] = v
|
basicInfo["regInstitute"] = v
|
||||||
}
|
}
|
||||||
if v := getVal("approvedTime"); v != nil {
|
if v := getVal("approvedTime"); v != nil {
|
||||||
basicInfo["approvedTime"] = v
|
basicInfo["approvedTime"] = v
|
||||||
}
|
}
|
||||||
if v := getVal("legalPersonName"); v != nil {
|
|
||||||
basicInfo["legalPersonName"] = v
|
|
||||||
}
|
|
||||||
if v := getVal("phone"); v != nil {
|
if v := getVal("phone"); v != nil {
|
||||||
basicInfo["phone"] = v
|
basicInfo["phone"] = v
|
||||||
}
|
}
|
||||||
@@ -1060,16 +1105,49 @@ func buildFinalResponse(enrichedCompanies []EnrichedCompanyInfo, allCompanies []
|
|||||||
companyMap["staffList"] = staffList
|
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个)
|
// 检查是否是已处理的企业(前3个)
|
||||||
if enriched, exists := processedMap[company.Index]; exists {
|
if enriched, exists := processedMap[company.Index]; exists {
|
||||||
// 已处理的企业,添加详细信息
|
// 已处理的企业,添加详细信息
|
||||||
companyMap["invest_history"] = enriched.InvestHistory
|
companyMap["invest_history"] = convertHistoryData(enriched.InvestHistory)
|
||||||
companyMap["financing_history"] = enriched.FinancingHistory
|
companyMap["financing_history"] = convertHistoryData(enriched.FinancingHistory)
|
||||||
companyMap["punishment_info"] = enriched.PunishmentInfo
|
companyMap["punishment_info"] = convertHistoryData(enriched.PunishmentInfo)
|
||||||
companyMap["abnormal_info"] = enriched.AbnormalInfo
|
companyMap["abnormal_info"] = convertHistoryData(enriched.AbnormalInfo)
|
||||||
companyMap["lawsuit_info"] = enriched.LawsuitInfo
|
// lawsuit_info 改为 lawsuitInfo(驼峰命名)
|
||||||
companyMap["own_tax"] = enriched.OwnTax
|
companyMap["lawsuitInfo"] = enriched.LawsuitInfo
|
||||||
companyMap["tax_contravention"] = enriched.TaxContravention
|
companyMap["own_tax"] = convertHistoryData(enriched.OwnTax)
|
||||||
|
companyMap["tax_contravention"] = convertHistoryData(enriched.TaxContravention)
|
||||||
} else {
|
} else {
|
||||||
// 未处理的企业,添加空的详细信息
|
// 未处理的企业,添加空的详细信息
|
||||||
companyMap["invest_history"] = map[string]interface{}{}
|
companyMap["invest_history"] = map[string]interface{}{}
|
||||||
|
|||||||
Reference in New Issue
Block a user