123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251 |
- package main
- import (
- util "jygit.jydev.jianyu360.cn/data_processing/common_utils"
- "log"
- "regexp"
- "strings"
- )
- // getCodeType 根据企业名称,获取经营主体代码标签
- func getCodeType(name string) (tab1, tab2 string) {
- where := map[string]interface{}{
- "use_flag": 0,
- "company_status": map[string]interface{}{
- "$nin": []string{"注销", "吊销", "吊销,已注销"},
- },
- "company_name": name,
- }
- // 🔍 正则,用于提取4位数字
- re4 := regexp.MustCompile(`\d{4}`)
- top_bases, _ := Mgo181.FindOne("company_base", where)
- company_type := util.ObjToString((*top_bases)["company_type"])
- // 去除引号
- cleanText := strings.ReplaceAll(company_type, `"`, "")
- cleanText = strings.TrimSpace(cleanText)
- // 替换中文括号为英文括号
- cleanText = strings.ReplaceAll(cleanText, "(", "(")
- cleanText = strings.ReplaceAll(cleanText, ")", ")")
- cleanText = strings.ReplaceAll(cleanText, "外资比例低于25%", "")
- // 判断是不是日期(如 2008/10/31)
- if matched, _ := regexp.MatchString(`^\d{4}/\d{1,2}/\d{1,2}$`, cleanText); matched {
- log.Printf("跳过日期行: %s", cleanText)
- return
- }
- // 如果包含“年”/“月”/“日”等,也跳过(不提取数字)
- if strings.Contains(cleanText, "年") || strings.Contains(cleanText, "月") || strings.Contains(cleanText, "日") {
- log.Printf("跳过含日期描述的行: %s", cleanText)
- return
- }
- 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)
- if code != "" {
- tab1 = codeZhu[code]
- tab2 = codeZhu2[code]
- }
- } else {
- tab1 = codeZhu[code]
- tab2 = codeZhu2[code]
- }
- return
- }
- // getCompanyType 获取公司类型;央企、国企、央企下属、事业单位、民企
- func getCompanyType(name string) (company_type string) {
- if name == "" {
- return
- }
- if yangMap[name] {
- company_type = "央企"
- return
- }
- if yangChildMap[name] {
- company_type = "央企下属"
- return
- }
- where := map[string]interface{}{
- "company_name": name,
- }
- // special_enterprise 事业单位
- enterprise, _ := Mgo181.FindOne("special_enterprise", where)
- if enterprise != nil && (len(*enterprise)) > 0 {
- company_type = "事业单位"
- return
- }
- //special_gov_unit 机关单位
- gov, _ := Mgo181.FindOne("special_gov_unit", where)
- if gov != nil && (len(*gov)) > 0 {
- company_type = "党政机关"
- return
- }
- //special_social_organ 社会团体
- soc, _ := Mgo181.FindOne("special_social_organ", where)
- if soc != nil && (len(*soc)) > 0 {
- company_type = "社会团体"
- return
- }
- //company_base
- where["use_flag"] = 0
- bases, _ := Mgo181.Find("company_base", where, nil, nil, false, -1, -1)
- if bases != nil && (len(*bases)) > 0 {
- for _, v := range *bases {
- 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 == "集体经营单位(非法人)" {
- 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
- }
- }
- }
- }
- //company_type = "民企"
- return
- }
- // getMarketType 获取上市公司类型;A股、新三板、非上市
- func getMarketType(name string) (stype string) {
- stype = "非上市"
- where := map[string]interface{}{
- "company_name": name,
- "use_flag": 0,
- }
- bases, _ := Mgo181.Find("company_base", where, nil, nil, false, -1, -1)
- if bases != nil && (len(*bases)) > 0 {
- for _, v := range *bases {
- if strings.Contains(util.ObjToString(v["company_status"]), "吊销") || strings.Contains(util.ObjToString(v["company_status"]), "注销") {
- continue
- } else {
- list_code := util.ObjToString((v)["list_code"])
- if list_code == "" {
- continue
- }
- //新三板股票代码 开头
- if strings.HasPrefix(list_code, "43") || strings.HasPrefix(list_code, "83") || strings.HasPrefix(list_code, "87") || strings.HasPrefix(list_code, "88") {
- stype = "新三板"
- return
- } else {
- stype = "A股"
- return
- }
- }
- }
- }
- return
- }
- // getTop 获取最上级公司
- // getTop 获取最上级公司
- func getTop(name string) (top 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 currName
- }
- // 避免循环:如果 topName 与 currName 相同,或 topName 已访问过,说明进入环路
- if topName == currName || visited[topName] {
- return currName
- }
- // 如果 topName 不符合要求,比如不含“公司”,也返回当前
- if !strings.Contains(topName, "公司") {
- return currName
- }
- // 更新当前公司名,继续向上找
- currName = topName
- visited[currName] = true
- }
- }
- // getParentsByPartner 获取母公司,投资比例 50% 以上
- 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)
- 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
- }
|