wcc 2 недель назад
Родитель
Сommit
ef9a734a3e

+ 35 - 8
environment/company_type.go

@@ -200,6 +200,12 @@ func getCompanyType(name string) (company_type string) {
 						}
 
 						top_bases, _ := Mgo181.FindOne("company_base", topwhere)
+						if top_bases == nil && len(*top_bases) == 0 {
+							if strings.Contains(par_name, "(") && strings.Contains(par_name, ")") {
+								par_name = strings.ReplaceAll(par_name, ")", ")")
+								par_name = strings.ReplaceAll(par_name, "(", "(")
+							}
+						}
 						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, "国有控股") ||
@@ -271,8 +277,7 @@ func getMarketType(name string) (stype string) {
 }
 
 // getTop 获取最上级公司
-// getTop 获取最上级公司;isCompany true 必须是企业类型,含有公司;
-func getTop(name string, isCompany bool) (top string) {
+func getTop(name string) (top string) {
 	if name == "" {
 		return
 	}
@@ -283,7 +288,7 @@ func getTop(name string, isCompany bool) (top string) {
 	visited[currName] = true
 
 	for {
-		topTmp := getParentsByPartner(currName)
+		topTmp := getParentsByPartner1(currName)
 		topName := util.ObjToString(topTmp["stock_name"])
 
 		// 第一次查找就失败,直接返回空
@@ -302,11 +307,9 @@ func getTop(name string, isCompany bool) (top string) {
 			return currName
 		}
 
-		if isCompany {
-			// 如果 topName 不符合要求,比如不含“公司”,也返回当前
-			if !strings.Contains(topName, "公司") {
-				return currName
-			}
+		// 如果 topName 不符合要求,比如不含“公司”,也返回当前
+		if !strings.Contains(topName, "公司") && !strings.Contains(topName, "集团") {
+			return currName
 		}
 
 		// 更新当前公司名,继续向上找
@@ -315,6 +318,30 @@ func getTop(name string, isCompany bool) (top string) {
 	}
 }
 
+// getParentsByPartner1	返回投资比例50%以上的上级企业
+func getParentsByPartner1(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)
+
+	if info == nil || len(*info) == 0 {
+		return
+	}
+
+	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
+		}
+	}
+	return
+}
+
 // 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}

+ 4 - 4
environment/env_test.go

@@ -8,11 +8,11 @@ import (
 func TestGetTop(t *testing.T) {
 	InitConfig()
 	InitMgo()
-	readXlsx()
-	name := "陕西中基项目管理有限公司"
+	//readXlsx()
+	name := "日照华盛康源环境科技有限公司"
 	//name := "南京厚建软件有限责任公司"
-	//res := getTop(name, true)
-	//log.Println(res)
+	res := getTop(name)
+	log.Println(res)
 	//
 	//res2 := getMarketType(name)
 	//log.Println(res2)

+ 7 - 3
environment/main.go

@@ -62,6 +62,7 @@ func updateXlsx() {
 		name = strings.TrimSpace(name)
 		res1 := getCompanyType(name)
 		if res1 == "" {
+			// 替换 成 中文括号再去匹配
 			if strings.Contains(name, "(") && strings.Contains(name, ")") {
 				name = strings.ReplaceAll(name, ")", ")")
 				name = strings.ReplaceAll(name, "(", "(")
@@ -72,15 +73,18 @@ func updateXlsx() {
 			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, true)
+		// 获取投资比例大于50%的最上级 企业
+		res3 := getTop(name)
 		if res3 != "" {
 			f.SetCellValue(GF.Env.Sheet, fmt.Sprintf("F%v", i+1), res3)
 		}
 
+		//获取
 		tab1, tab2 := getCodeType(name)
 		if res1 == "" {
 			if tab1 == "私企" || tab1 == "个体" {
@@ -122,7 +126,7 @@ func updateBidding() {
 		update := make(map[string]interface{}, 0)
 		res1 := getCompanyType(name)
 		res2 := getMarketType(name)
-		res3 := getTop(name, true)
+		res3 := getTop(name)
 		if res1 != "" {
 			update["company_type"] = res1
 		}
@@ -168,7 +172,7 @@ func getCompanyTypes() {
 		for _, v := range req.Names {
 			res1 := getCompanyType(v)
 			res2 := getMarketType(v)
-			res3 := getTop(v, false)
+			res3 := getTop(v)
 			dd := map[string]interface{}{
 				"company_type": res1,
 				"market_type":  res2,

BIN
environment/大气-企业类型程序抽取.xlsx