|
@@ -1,12 +1,65 @@
|
|
|
package main
|
|
|
|
|
|
import (
|
|
|
+ "fmt"
|
|
|
+ "github.com/xuri/excelize/v2"
|
|
|
util "jygit.jydev.jianyu360.cn/data_processing/common_utils"
|
|
|
"log"
|
|
|
"regexp"
|
|
|
"strings"
|
|
|
)
|
|
|
|
|
|
+// matchCompanyCode 根据企业库有的类型,匹配对应标准法人库类型
|
|
|
+func matchCompanyCode() {
|
|
|
+ filePath := "company_types_finish.xlsx"
|
|
|
+ // 1. 读取 Excel(获取 A 列数据)
|
|
|
+ f, err := excelize.OpenFile(filePath)
|
|
|
+ if err != nil {
|
|
|
+ log.Fatal("❌ 无法打开 Excel 文件:", err)
|
|
|
+ }
|
|
|
+ defer f.Close()
|
|
|
+
|
|
|
+ //读取央企
|
|
|
+ rows, err := f.GetRows("企业库所有类型")
|
|
|
+ if err != nil {
|
|
|
+ log.Fatal("❌ 无法读取 企业所有类型:", err)
|
|
|
+ }
|
|
|
+ // 🔍 正则,用于提取4位数字
|
|
|
+ re4 := regexp.MustCompile(`\d{4}`)
|
|
|
+
|
|
|
+ for i := 1; i < len(rows); i++ {
|
|
|
+ name := rows[i][0]
|
|
|
+ log.Println("name", name)
|
|
|
+ // 去除引号
|
|
|
+ cleanText := strings.ReplaceAll(name, `"`, "")
|
|
|
+ cleanText = strings.TrimSpace(cleanText)
|
|
|
+ // 替换中文括号为英文括号
|
|
|
+ cleanText = strings.ReplaceAll(cleanText, "(", "(")
|
|
|
+ cleanText = strings.ReplaceAll(cleanText, ")", ")")
|
|
|
+ var code string
|
|
|
+ // 优先提取4位数字
|
|
|
+ if m := re4.FindString(cleanText); m != "" {
|
|
|
+ code = m
|
|
|
+ } else {
|
|
|
+ // 去除引号后完全匹配
|
|
|
+ if c, ok := codeMap[cleanText]; ok {
|
|
|
+ code = c
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if code == "" {
|
|
|
+ code = getCodeByCompanyType(cleanText, codeMap)
|
|
|
+ }
|
|
|
+
|
|
|
+ tt := nameMap[code]
|
|
|
+ f.SetCellValue("企业库所有类型", fmt.Sprintf("D%v", i+1), code)
|
|
|
+ f.SetCellValue("企业库所有类型", fmt.Sprintf("E%v", i+1), tt)
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ f.Save()
|
|
|
+}
|
|
|
+
|
|
|
// getCodeType 根据企业名称,获取经营主体代码标签
|
|
|
func getCodeType(name string) (tab1, tab2 string) {
|
|
|
where := map[string]interface{}{
|
|
@@ -106,6 +159,17 @@ func getCompanyType(name string) (company_type string) {
|
|
|
return
|
|
|
}
|
|
|
|
|
|
+ //铁塔智联技术有限公司重庆市分公司
|
|
|
+ if strings.Contains(name, "铁塔") {
|
|
|
+ if strings.Contains(name, "分公司") {
|
|
|
+ company_type = "地方国企"
|
|
|
+ return
|
|
|
+ } else {
|
|
|
+ company_type = "国企"
|
|
|
+ return
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
//company_base
|
|
|
where["use_flag"] = 0
|
|
|
bases, _ := Mgo181.Find("company_base", where, nil, nil, false, -1, -1)
|
|
@@ -114,34 +178,56 @@ func getCompanyType(name string) (company_type string) {
|
|
|
if strings.Contains(util.ObjToString(v["company_status"]), "吊销") || strings.Contains(util.ObjToString(v["company_status"]), "注销") || util.ObjToString((v)["company_type"]) == "" {
|
|
|
continue
|
|
|
} else {
|
|
|
-
|
|
|
bty := util.ObjToString((v)["company_type"])
|
|
|
if strings.Contains(bty, "国有独资") || strings.Contains(bty, "国有控股") ||
|
|
|
- bty == "全民所有制" || bty == "集体所有制" || bty == "全民所有制分支机构(非法人)" ||
|
|
|
- bty == "集体分支机构(非法人)" || bty == "内资集团" || bty == "国有事业单位营业" || bty == "集体事业单位营业" ||
|
|
|
+ bty == "全民所有制" || bty == "集体所有制" ||
|
|
|
+ bty == "国有事业单位营业" || bty == "集体事业单位营业" ||
|
|
|
bty == "国有社团法人营业" || bty == "国有经营单位(非法人)" || bty == "集体经营单位(非法人)" {
|
|
|
company_type = "国企"
|
|
|
return
|
|
|
}
|
|
|
// 地方国企
|
|
|
- par_name := getTop(name)
|
|
|
- topwhere := map[string]interface{}{
|
|
|
- "use_flag": 0,
|
|
|
- "company_status": map[string]interface{}{
|
|
|
- "$nin": []string{"注销", "吊销", "吊销,已注销"},
|
|
|
- },
|
|
|
- "company_name": par_name,
|
|
|
- }
|
|
|
-
|
|
|
- top_bases, _ := Mgo181.FindOne("company_base", topwhere)
|
|
|
- top_company_type := util.ObjToString((*top_bases)["company_type"])
|
|
|
-
|
|
|
- if strings.Contains(top_company_type, "国有独资") || strings.Contains(top_company_type, "国有控股") ||
|
|
|
- top_company_type == "全民所有制" || top_company_type == "集体所有制" || top_company_type == "全民所有制分支机构(非法人)" ||
|
|
|
- top_company_type == "集体分支机构(非法人)" || top_company_type == "内资集团" || top_company_type == "国有事业单位营业" || top_company_type == "集体事业单位营业" ||
|
|
|
- top_company_type == "国有社团法人营业" || top_company_type == "国有经营单位(非法人)" || top_company_type == "集体经营单位(非法人)" || top_company_type == "事业单位" {
|
|
|
- company_type = "地方国企"
|
|
|
- return
|
|
|
+ //par_name := getTop(name, false)
|
|
|
+ par_names := getTopNames(name)
|
|
|
+ if len(par_names) > 0 {
|
|
|
+ for _, par_name := range par_names {
|
|
|
+ topwhere := map[string]interface{}{
|
|
|
+ "use_flag": 0,
|
|
|
+ "company_status": map[string]interface{}{
|
|
|
+ "$nin": []string{"注销", "吊销", "吊销,已注销"},
|
|
|
+ },
|
|
|
+ "company_name": par_name,
|
|
|
+ }
|
|
|
+
|
|
|
+ top_bases, _ := Mgo181.FindOne("company_base", topwhere)
|
|
|
+ if top_bases != nil && len(*top_bases) > 0 {
|
|
|
+ top_company_type := util.ObjToString((*top_bases)["company_type"])
|
|
|
+ if strings.Contains(top_company_type, "国有独资") || strings.Contains(top_company_type, "国有控股") ||
|
|
|
+ top_company_type == "全民所有制" || top_company_type == "集体所有制" ||
|
|
|
+ top_company_type == "国有事业单位营业" || top_company_type == "集体事业单位营业" ||
|
|
|
+ top_company_type == "国有社团法人营业" || top_company_type == "国有经营单位(非法人)" || top_company_type == "集体经营单位(非法人)" || top_company_type == "事业单位" {
|
|
|
+ company_type = "地方国企"
|
|
|
+ return
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ // 去政府机关和事业单位查询
|
|
|
+ where2 := map[string]interface{}{
|
|
|
+ "company_name": par_name,
|
|
|
+ }
|
|
|
+ // special_enterprise 事业单位
|
|
|
+ enterprise, _ := Mgo181.FindOne("special_enterprise", where2)
|
|
|
+ if enterprise != nil && (len(*enterprise)) > 0 {
|
|
|
+ company_type = "地方国企"
|
|
|
+ return
|
|
|
+ }
|
|
|
+ //special_gov_unit 机关单位
|
|
|
+ gov, _ := Mgo181.FindOne("special_gov_unit", where2)
|
|
|
+ if gov != nil && (len(*gov)) > 0 {
|
|
|
+ company_type = "地方国企"
|
|
|
+ return
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -185,8 +271,8 @@ func getMarketType(name string) (stype string) {
|
|
|
}
|
|
|
|
|
|
// getTop 获取最上级公司
|
|
|
-// getTop 获取最上级公司
|
|
|
-func getTop(name string) (top string) {
|
|
|
+// getTop 获取最上级公司;isCompany true 必须是企业类型,含有公司;
|
|
|
+func getTop(name string, isCompany bool) (top string) {
|
|
|
if name == "" {
|
|
|
return
|
|
|
}
|
|
@@ -216,9 +302,11 @@ func getTop(name string) (top string) {
|
|
|
return currName
|
|
|
}
|
|
|
|
|
|
- // 如果 topName 不符合要求,比如不含“公司”,也返回当前
|
|
|
- if !strings.Contains(topName, "公司") {
|
|
|
- return currName
|
|
|
+ if isCompany {
|
|
|
+ // 如果 topName 不符合要求,比如不含“公司”,也返回当前
|
|
|
+ if !strings.Contains(topName, "公司") {
|
|
|
+ return currName
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
// 更新当前公司名,继续向上找
|
|
@@ -227,7 +315,7 @@ func getTop(name string) (top string) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-// getParentsByPartner 获取母公司,投资比例 50% 以上
|
|
|
+// getParentsByPartner 获取母公司,返回投资比例最大的企业
|
|
|
func getParentsByPartner(companyName string) (res map[string]interface{}) {
|
|
|
q := map[string]interface{}{"company_name": companyName, "use_flag": 0, "is_history": 0, "is_personal": 0}
|
|
|
info, _ := Mgo181.Find("company_partner", q, nil, nil, false, -1, -1)
|
|
@@ -236,16 +324,57 @@ func getParentsByPartner(companyName string) (res map[string]interface{}) {
|
|
|
return
|
|
|
}
|
|
|
|
|
|
+ var maxProportion float64
|
|
|
for _, v := range *info {
|
|
|
// 不是法人企业,直接跳过
|
|
|
if !strings.Contains(util.ObjToString(v["stock_type"]), "法人") {
|
|
|
continue
|
|
|
}
|
|
|
- // 投资比例 必须 0.5以上
|
|
|
- stock_proportion := util.Float64All(v["stock_proportion"])
|
|
|
- if stock_proportion >= 0.5 {
|
|
|
- return v
|
|
|
+ // 获取比例
|
|
|
+ stockProportion := util.Float64All(v["stock_proportion"])
|
|
|
+
|
|
|
+ // 比较当前比例是否更大
|
|
|
+ if stockProportion > maxProportion {
|
|
|
+ maxProportion = stockProportion
|
|
|
+ res = v
|
|
|
}
|
|
|
}
|
|
|
return
|
|
|
}
|
|
|
+
|
|
|
+// getTopCompanyType 寻找上级企业
|
|
|
+func getTopNames(name string) (res []string) {
|
|
|
+ if name == "" {
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ currName := name
|
|
|
+ firstSearch := true
|
|
|
+ visited := make(map[string]bool)
|
|
|
+ visited[currName] = true
|
|
|
+
|
|
|
+ for {
|
|
|
+ topTmp := getParentsByPartner(currName)
|
|
|
+ topName := util.ObjToString(topTmp["stock_name"])
|
|
|
+
|
|
|
+ // 第一次查找就失败,直接返回空
|
|
|
+ if firstSearch && topName == "" {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ firstSearch = false
|
|
|
+
|
|
|
+ // 非第一次查找,上级为空,返回当前获取到的上级
|
|
|
+ if topName == "" {
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ // 避免循环:如果 topName 与 currName 相同,或 topName 已访问过,说明进入环路
|
|
|
+ if topName == currName || visited[topName] {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ // 更新当前公司名,继续向上找
|
|
|
+ currName = topName
|
|
|
+ visited[currName] = true
|
|
|
+ res = append(res, topName)
|
|
|
+ }
|
|
|
+}
|