wcc 2 周之前
父节点
当前提交
f82a7782dd

+ 160 - 31
environment/company_type.go

@@ -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)
+	}
+}

+ 1 - 1
environment/config.toml

@@ -31,7 +31,7 @@
 
 [env]
 #    file = "./data.xlsx" ## 读取文件
-    file = "./首创企业类型.xlsx" ## 读取文件
+    file = "./大气-企业类型程序抽取.xlsx" ## 读取文件
     sheet= "Sheet1" ## 默认读取数据在Sheet1
 
 

+ 8 - 6
environment/env_test.go

@@ -6,14 +6,16 @@ import (
 )
 
 func TestGetTop(t *testing.T) {
+	InitConfig()
 	InitMgo()
-	name := "北京天融信网络安全技术有限公司"
+	readXlsx()
+	name := "陕西中基项目管理有限公司"
 	//name := "南京厚建软件有限责任公司"
-	res := getTop(name)
-	log.Println(res)
-
-	res2 := getMarketType(name)
-	log.Println(res2)
+	//res := getTop(name, true)
+	//log.Println(res)
+	//
+	//res2 := getMarketType(name)
+	//log.Println(res2)
 
 	res3 := getCompanyType(name)
 	log.Println(res3)

+ 14 - 11
environment/init.go

@@ -14,6 +14,7 @@ var (
 	codeZhu      = make(map[string]string) //内外个私农合 标签
 	codeZhu2     = make(map[string]string) //国企、外企、私企
 	codeMap      = make(map[string]string) //code-企业类型
+	nameMap      = make(map[string]string) //企业类型 -> code
 	Mgo181       *mongodb.MongodbSim       //
 	MgoB         *mongodb.MongodbSim       //
 	MgoP         *mongodb.MongodbSim       //
@@ -73,7 +74,7 @@ func InitMgo() {
 	//MgoB.InitPool()
 }
 
-// readXlsx 读取央企
+// readXlsx 读取央企 央企下属
 func readXlsx() {
 	filePath := "央企.xlsx"
 	// 1. 读取 Excel(获取 A 列数据)
@@ -96,7 +97,7 @@ func readXlsx() {
 	}
 	log.Println("央企数量", len(yangMap))
 	// 央企下属
-	rows2, err := f.GetRows("Sheet3")
+	rows2, err := f.GetRows("Sheet4")
 	if err != nil {
 		log.Fatal("❌ 无法读取 Sheet2:", err)
 	}
@@ -105,7 +106,7 @@ func readXlsx() {
 		if len(row) == 0 {
 			continue
 		}
-		name := rows2[i][0]
+		name := rows2[i][1]
 		if name != "" {
 			yangChildMap[name] = true
 		}
@@ -142,6 +143,7 @@ func readXlsx() {
 //	log.Println("readXlsx2", "企业经营主体代码表 处理完毕")
 //}
 
+// readXlsx2 读取整理的法人库 企业类型和对应代码
 func readXlsx2() {
 	filePath := "法人类型代码表.xlsx"
 	// 1. 读取 Excel(获取 A 列数据)
@@ -152,20 +154,21 @@ func readXlsx2() {
 	defer f.Close()
 
 	//读取央企
-	rows, err := f.GetRows("市场主体类型代码-叶子节点")
+	rows, err := f.GetRows("叶子节点")
 	if err != nil {
 		log.Fatal("❌ 无法读取 市场主体类型代码-叶子节点:", err)
 	}
-	for i := 2; i < len(rows); i++ {
-		if len(rows[i]) < 16 {
-			continue
-		}
-		code := strings.TrimSpace(rows[i][4])
-		name := strings.TrimSpace(rows[i][5])
+	for i := 1; i < len(rows); i++ {
+		//if len(rows[i]) < 16 {
+		//	continue
+		//}
+		code := strings.TrimSpace(rows[i][2])
+		name := strings.TrimSpace(rows[i][3])
 		name = strings.ReplaceAll(name, "(", "(")
 		name = strings.ReplaceAll(name, ")", ")")
 		codeMap[name] = code
-		tab1 := strings.TrimSpace(rows[i][15])
+		nameMap[code] = name
+		tab1 := strings.TrimSpace(rows[i][6])
 		codeZhu[code] = tab1
 
 	}

+ 30 - 21
environment/main.go

@@ -31,9 +31,9 @@ func main() {
 	readXlsx()  //98家 央企名单
 	readXlsx2() //企业经营主体代码表
 	InitMgo()
-	//getCompanyTypes()
-	updateXlsx()
-
+	//getCompanyTypes() //http 提供接口的服务形式
+	updateXlsx() // 根据提供的Excel文件更新对应标签
+	//matchCompanyCode() //测试;匹配现有企业库的类型
 	log.Println("数据处理完毕!")
 }
 
@@ -61,17 +61,25 @@ func updateXlsx() {
 		name := rows[i][0] //企业名称
 		name = strings.TrimSpace(name)
 		res1 := getCompanyType(name)
+		if res1 == "" {
+			if strings.Contains(name, "(") && strings.Contains(name, ")") {
+				name = strings.ReplaceAll(name, ")", ")")
+				name = strings.ReplaceAll(name, "(", "(")
+				res1 = getCompanyType(name)
+			}
+		}
 		if res1 != "" {
 			f.SetCellValue(GF.Env.Sheet, fmt.Sprintf("D%v", i+1), res1)
 		}
-		//res2 := getMarketType(name)
-		//if res2 != "" {
-		//	f.SetCellValue(GF.Env.Sheet, fmt.Sprintf("E%v", i+1), res2)
-		//}
-		//res3 := getTop(name)
-		//if res3 != "" {
-		//	f.SetCellValue(GF.Env.Sheet, fmt.Sprintf("F%v", i+1), res3)
-		//}
+
+		res2 := getMarketType(name)
+		if res2 != "" {
+			f.SetCellValue(GF.Env.Sheet, fmt.Sprintf("E%v", i+1), res2)
+		}
+		res3 := getTop(name, true)
+		if res3 != "" {
+			f.SetCellValue(GF.Env.Sheet, fmt.Sprintf("F%v", i+1), res3)
+		}
 
 		tab1, tab2 := getCodeType(name)
 		if res1 == "" {
@@ -79,15 +87,16 @@ func updateXlsx() {
 				f.SetCellValue(GF.Env.Sheet, fmt.Sprintf("D%v", i+1), "民企")
 			}
 		}
-		if tab1 != "" {
-			f.SetCellValue(GF.Env.Sheet, fmt.Sprintf("G%v", i+1), tab1)
-		}
-		if tab2 != "" {
-			f.SetCellValue(GF.Env.Sheet, fmt.Sprintf("H%v", i+1), tab2)
-		}
-
-		log.Println(name, res1, tab1, tab2)
+		//if tab1 != "" {
+		//	f.SetCellValue(GF.Env.Sheet, fmt.Sprintf("G%v", i+1), tab1)
+		//}
+		//if tab2 != "" {
+		//	f.SetCellValue(GF.Env.Sheet, fmt.Sprintf("H%v", i+1), tab2)
+		//}
 
+		if i%100 == 0 {
+			log.Println(name, res1, tab1, tab2)
+		}
 	}
 	f.Save()
 }
@@ -113,7 +122,7 @@ func updateBidding() {
 		update := make(map[string]interface{}, 0)
 		res1 := getCompanyType(name)
 		res2 := getMarketType(name)
-		res3 := getTop(name)
+		res3 := getTop(name, true)
 		if res1 != "" {
 			update["company_type"] = res1
 		}
@@ -159,7 +168,7 @@ func getCompanyTypes() {
 		for _, v := range req.Names {
 			res1 := getCompanyType(v)
 			res2 := getMarketType(v)
-			res3 := getTop(v)
+			res3 := getTop(v, false)
 			dd := map[string]interface{}{
 				"company_type": res1,
 				"market_type":  res2,

二进制
environment/大气-企业类型程序抽取.xlsx


二进制
environment/央企.xlsx


二进制
environment/法人类型代码表.xlsx


+ 68 - 0
getEs/buyer.go

@@ -0,0 +1,68 @@
+package main
+
+import (
+	"fmt"
+	util "jygit.jydev.jianyu360.cn/data_processing/common_utils"
+	"jygit.jydev.jianyu360.cn/data_processing/common_utils/elastic"
+	"jygit.jydev.jianyu360.cn/data_processing/common_utils/mongodb"
+	"log"
+)
+
+// deleteBuyerEs 删除buyer es 重复数据
+func deleteBuyerEs() {
+	//测试环境MongoDB
+	MgoT := &mongodb.MongodbSim{
+		MongodbAddr: "172.20.45.129:27002",
+		DbName:      "wjh",
+		Size:        10,
+		UserName:    "",
+		Password:    "",
+		//Direct:      true,
+	}
+	MgoT.InitPool()
+
+	Es := &elastic.Elastic{
+		S_esurl: "http://127.0.0.1:19908",
+		//S_esurl:  "http://172.17.4.184:19908",
+		I_size:   5,
+		Username: "jybid",
+		Password: "Top2023_JEB01i@31",
+	}
+	Es.InitElasticSize()
+
+	defer util.Catch()
+	sess := MgoT.GetMgoConn()
+	defer MgoT.DestoryMongoConn(sess)
+
+	where := map[string]interface{}{
+		"modify": map[string]interface{}{
+			"$exists": 1,
+		},
+	}
+
+	it := sess.DB("wjh").C("company_name").Find(where).Select(nil).Iter()
+
+	fmt.Println("taskRun 开始")
+	count := 0
+	//realNum := 0
+	for tmp := make(map[string]interface{}); it.Next(&tmp); count++ {
+		if count%100 == 0 {
+			log.Println("current", count, tmp["name"])
+		}
+
+		if modify, ok := tmp["modify"]; ok {
+			if ms, ok := modify.([]interface{}); ok {
+				for _, v := range ms {
+					if dd, ok := v.(map[string]interface{}); ok {
+						if util.ObjToString(dd["stype"]) == "delete" {
+							//log.Println(dd)
+							name_id := util.ObjToString(dd["name_id"])
+							Es.DeleteByID("buyer", name_id)
+						}
+					}
+				}
+			}
+		}
+
+	}
+}

二进制
xlsx/company_types_finish.xlsx