|
@@ -18,6 +18,7 @@ import (
|
|
|
elastic "qfw/util/elastic"
|
|
|
. "qfw/util/mongodb"
|
|
|
"qfw/util/redis"
|
|
|
+ "regexp"
|
|
|
"strconv"
|
|
|
"strings"
|
|
|
"time"
|
|
@@ -27,6 +28,8 @@ const ESINDEX string = "enterprise"
|
|
|
const ESTYPE string = "enterprise"
|
|
|
const ONEDAY int = 24 * 60 * 60
|
|
|
|
|
|
+var provinces []map[string]interface{}
|
|
|
+
|
|
|
//常量代码表
|
|
|
var city_map map[string]interface{} = map[string]interface{}{"11": "北京市", "12": "天津市", "13": "河北省", "14": "山西省", "15": "内蒙古",
|
|
|
"21": "辽宁省", "22": "吉林省", "23": "黑龙江省", "31": "上海市", "32": "江苏省", "33": "浙江省", "34": "安徽省",
|
|
@@ -130,9 +133,9 @@ func GetEntInfo(id string) map[string]interface{} {
|
|
|
func WxGetEntInfo(id string, flag bool) interface{} {
|
|
|
res := FindById("enterprise", id, `{"RegNo":1, "EntName":1, "EntType":1, "EntTypeName":1, "OpLocDistrict":1, "LeRep":1, "LegCerNO":1, "Tel":1, "Dom":1, "OpScope":1, "OpFrom":1, "OpTo":1, "RegCap":1, "EstDate":1, "CompForm":1, "CompFormName":1, "OpState":1, "OpStateName":1, "RegOrgName":1, "IssBLicDate":1, "Timestamp":1, "s_synopsis":1, "SourceType":1, "s_weixin":1, "s_enturl, "i_province":1, "i_city":1, "i_area":1,"s_action":1,"s_persion":1,"s_mobile":1,"s_address":1,"s_avatar":1,"s_microwebsite":1,"s_qq":1,"s_submitid":1}`)
|
|
|
if res != nil {
|
|
|
- id := (*res)["s_submitid"]
|
|
|
- if id != nil {
|
|
|
- ud := FindById("user", id.(string), `{"i_comauthenttype":1}`)
|
|
|
+ submitid := (*res)["s_submitid"]
|
|
|
+ if submitid != nil {
|
|
|
+ ud := FindById("user", submitid.(string), `{"i_comauthenttype":1}`)
|
|
|
(*res)["i_comauthenttype"] = (*ud)["i_comauthenttype"]
|
|
|
}
|
|
|
opl, _ := (*res)["OpLocDistrict"].(string)
|
|
@@ -263,11 +266,11 @@ func (yp *Yellowpage) EnterpriseInfo(id string) error {
|
|
|
yp.T["res"] = info
|
|
|
regNo, _ := info["RegNo"].(string)
|
|
|
entName, _ := info["EntName"].(string)
|
|
|
- //相关企业
|
|
|
- relation := getRelation(regNo, entName)
|
|
|
- if relation != nil {
|
|
|
- var nodes *[]map[string]interface{}
|
|
|
- if d, err := json.Marshal(relation.(map[string]interface{})["nodes"]); err == nil && json.Unmarshal(d, &nodes) == nil && len(*nodes) > 0 {
|
|
|
+ relation, ok := getRelation(regNo, entName).(map[string]interface{})
|
|
|
+ var nodes *[]map[string]interface{}
|
|
|
+ if ok {
|
|
|
+ if d, err := json.Marshal(relation["nodes"]); err == nil && json.Unmarshal(d, &nodes) == nil && len(*nodes) > 0 {
|
|
|
+ //相关企业
|
|
|
var regNos []string
|
|
|
for _, v := range *nodes {
|
|
|
if v["type"] == "e" {
|
|
@@ -302,9 +305,7 @@ func (yp *Yellowpage) EnterpriseInfo(id string) error {
|
|
|
}
|
|
|
}
|
|
|
if len(ids) > 0 {
|
|
|
- log.Println(ids)
|
|
|
news := Find("trs_news", M{"_id": M{"$in": ids}}, `{"l_comeintime":-1}`, `{"s_link":1,"s_title":1,"l_comeintime":1}`, false, 0, 8)
|
|
|
- log.Println(news)
|
|
|
if news != nil && len(*news) > 0 {
|
|
|
yp.T["relevantNews"] = news
|
|
|
}
|
|
@@ -316,10 +317,26 @@ func (yp *Yellowpage) EnterpriseInfo(id string) error {
|
|
|
yp.T["service"] = findServiceByEntId(id, 1, yp.Session())
|
|
|
//关系网数据
|
|
|
yp.T["relation"] = relation
|
|
|
+ //著作权
|
|
|
+ yp.T["copyright"] = FindOne("enterprise_copyright", `{"EntId":"`+id+`"}`)
|
|
|
contentuser, erruser := yp.Render4Cache("/yellowpage/enterpriseinfo.html", &yp.T)
|
|
|
if erruser == nil {
|
|
|
redis.PutBytes("enterprise", "enterpriseInfo_"+id, &contentuser, 7*ONEDAY)
|
|
|
}
|
|
|
+ //过滤企业名
|
|
|
+ if ok && nodes != nil && len(*nodes) > 0 {
|
|
|
+ go func() {
|
|
|
+ util.Try(func() {
|
|
|
+ if filterEntName(nodes) > 0 {
|
|
|
+ relation["nodes"] = nodes
|
|
|
+ redis.Put("enterprise", "relation-"+regNo, relation, 7*ONEDAY)
|
|
|
+ redis.Del("enterprise", "enterpriseInfo_"+id)
|
|
|
+ }
|
|
|
+ }, func(e interface{}) {
|
|
|
+ log.Println("过滤企业名出错:", e)
|
|
|
+ })
|
|
|
+ }()
|
|
|
+ }
|
|
|
return yp.SetBody(contentuser)
|
|
|
} else {
|
|
|
return yp.Render("/_error.html")
|
|
@@ -415,19 +432,11 @@ func storeNode(data *map[string]interface{}, ls *list.List, dir /*方向反转*/
|
|
|
regcap, _ := (*data)["regcap"].(float64)
|
|
|
invregcap, _ := (*data)["invregcap"].(float64)
|
|
|
legcerno, _ := (*data)["legcerno"].(string)
|
|
|
- opstate := ""
|
|
|
- if (*data)["opstate"] != nil {
|
|
|
- opstate = (*data)["opstate"].(string)
|
|
|
- }
|
|
|
- invopstate := ""
|
|
|
- if (*data)["invopstate"] != nil {
|
|
|
- invopstate = (*data)["invopstate"].(string)
|
|
|
- }
|
|
|
- regcapcurname := ""
|
|
|
- if (*data)["regcapcurname"] != nil {
|
|
|
- regcapcurname = (*data)["regcapcurname"].(string)
|
|
|
- }
|
|
|
- ls.PushBack([]string{invtype, invcerno, invname, entregno, entname, strconv.Itoa(level), fmt.Sprint(invweight), invacconam, fmt.Sprint(regcap), fmt.Sprint(invregcap), legcerno, opstate, invopstate, regcapcurname})
|
|
|
+ opstate, _ := (*data)["opstate"].(string)
|
|
|
+ invopstate, _ := (*data)["invopstate"].(string)
|
|
|
+ regcapcurname, _ := (*data)["regcapcurname"].(string)
|
|
|
+ shortname, _ := (*data)["shortname"].(string)
|
|
|
+ ls.PushBack([]string{invtype, invcerno, invname, entregno, entname, strconv.Itoa(level), fmt.Sprint(invweight), invacconam, fmt.Sprint(regcap), fmt.Sprint(invregcap), legcerno, opstate, invopstate, regcapcurname, util.BsonIdToSId((*data)["_id"]), shortname})
|
|
|
}
|
|
|
|
|
|
func findIndex(code string, arr []interface{}) (index int, mtType string) {
|
|
@@ -526,6 +535,8 @@ func makeRelation(mnregno, mnname string) interface{} {
|
|
|
"legcerno": v[10],
|
|
|
"opstate": v[12],
|
|
|
"regcapcurname": v[13],
|
|
|
+ "_id": v[14],
|
|
|
+ "shorttext": v[15],
|
|
|
}
|
|
|
}
|
|
|
//加企业
|
|
@@ -539,6 +550,8 @@ func makeRelation(mnregno, mnname string) interface{} {
|
|
|
"legcerno": v[10],
|
|
|
"opstate": v[11],
|
|
|
"regcapcurname": v[13],
|
|
|
+ "_id": v[14],
|
|
|
+ "shorttext": v[15],
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -656,6 +669,7 @@ func findServiceByEntId(id string, currentPage int, session *httpsession.Session
|
|
|
}
|
|
|
return res
|
|
|
}
|
|
|
+
|
|
|
func checkAuth(obj map[string]interface{}) (b bool, err string) {
|
|
|
if len(obj) > 0 {
|
|
|
//判断有没有预约的情况
|
|
@@ -679,3 +693,125 @@ func checkAuth(obj map[string]interface{}) (b bool, err string) {
|
|
|
}
|
|
|
return true, ""
|
|
|
}
|
|
|
+func filterEntName(nodes *[]map[string]interface{}) int {
|
|
|
+ if len(provinces) == 0 {
|
|
|
+ util.ReadConfig("./province.json", &provinces)
|
|
|
+ }
|
|
|
+ var count int
|
|
|
+ for _, v := range *nodes {
|
|
|
+ if v["text"] == nil {
|
|
|
+ continue
|
|
|
+ }
|
|
|
+ text, ok := v["text"].(string)
|
|
|
+ text = strings.Trim(text, " ")
|
|
|
+ if !ok || text == "" {
|
|
|
+ continue
|
|
|
+ }
|
|
|
+ shortText := text
|
|
|
+ if v["type"] == "e" || v["type"] == "ce" {
|
|
|
+ if v["shorttext"] == nil || v["shorttext"] == "" {
|
|
|
+ if len([]rune(shortText)) > 2 { //先替换结尾
|
|
|
+ r := regexp.MustCompile("(有限公司|有限责任公司|股份有限公司|总公司|分公司|公司|事务所|合伙企业)$|\\([^\\)]*\\)|([^)]*)")
|
|
|
+ shortTextTemp := r.ReplaceAllString(shortText, "")
|
|
|
+ if len([]rune(shortTextTemp)) > 2 {
|
|
|
+ shortText = shortTextTemp
|
|
|
+ }
|
|
|
+ if len([]rune(shortTextTemp)) > 4 { //再替换开头地区
|
|
|
+ shortTextTemp = filterRegion(shortText)
|
|
|
+ if len([]rune(shortTextTemp)) > 2 {
|
|
|
+ shortText = shortTextTemp
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ v["shorttext"] = shortText
|
|
|
+ count++
|
|
|
+ if v["type"] == "e" {
|
|
|
+ Update("entrelation", `{"_id":"`+v["_id"].(string)+`"}`, `{"$set":{"shortname":"`+shortText+`"}}`, false, false)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ log.Println("过滤", count, "个企业的名字!")
|
|
|
+ return count
|
|
|
+}
|
|
|
+func filterRegion(text string) string {
|
|
|
+ var commonReplace = func(t string) bool {
|
|
|
+ if len(t) > 1 && util.StartWith(text, t) {
|
|
|
+ r := regexp.MustCompile("^" + t)
|
|
|
+ var textCopy = r.ReplaceAllString(text, "")
|
|
|
+ if len(textCopy) > 2 {
|
|
|
+ text = textCopy
|
|
|
+ }
|
|
|
+ return true
|
|
|
+ }
|
|
|
+ return false
|
|
|
+ }
|
|
|
+ var replaceStart = func(t string, f bool) bool {
|
|
|
+ if t == "" {
|
|
|
+ return false
|
|
|
+ }
|
|
|
+ var flag bool
|
|
|
+ var minus int
|
|
|
+ if commonReplace(t) { //替换省、市、县、区
|
|
|
+ return true
|
|
|
+ }
|
|
|
+ if f { //不替换
|
|
|
+ flag = false
|
|
|
+ } else if util.EndWith(t, "维吾尔自治区") {
|
|
|
+ flag = true
|
|
|
+ minus = 6
|
|
|
+ } else if util.EndWith(t, "回族自治区") || util.EndWith(t, "壮族自治区") || util.EndWith(t, "特别行政区") {
|
|
|
+ flag = true
|
|
|
+ minus = 5
|
|
|
+ } else if util.EndWith(t, "自治州") || util.EndWith(t, "自治县") || util.EndWith(t, "自治区") {
|
|
|
+ flag = true
|
|
|
+ minus = 3
|
|
|
+ } else if util.EndWith(t, "地区") {
|
|
|
+ flag = true
|
|
|
+ minus = 2
|
|
|
+ } else if util.EndWith(t, "省") || util.EndWith(t, "市") || util.EndWith(t, "区") {
|
|
|
+ flag = true
|
|
|
+ minus = 1
|
|
|
+ }
|
|
|
+ if flag {
|
|
|
+ return commonReplace(util.SubString(t, 0, len([]rune(t))-minus))
|
|
|
+ }
|
|
|
+ return false
|
|
|
+ }
|
|
|
+ /*var replaceAreas = func(areas []interface{}) bool {
|
|
|
+ if len(areas) > 0 {
|
|
|
+ for _, _a := range areas { //县、区
|
|
|
+ a, a_ok := _a.(map[string]interface{})
|
|
|
+ if a_ok && replaceStart(util.ObjToString(a["n"]), true) {
|
|
|
+ return true
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return false
|
|
|
+ }*/
|
|
|
+ var replaceCity = func(citys []interface{}) bool {
|
|
|
+ if len(citys) > 0 {
|
|
|
+ for _, _c := range citys { //市
|
|
|
+ c, c_ok := _c.(map[string]interface{})
|
|
|
+ if c_ok && replaceStart(util.ObjToString(c["n"]), false) {
|
|
|
+ /*if c["s"] != nil {
|
|
|
+ replaceAreas(c["s"].([]interface{}))
|
|
|
+ }*/
|
|
|
+ return true
|
|
|
+ } /*else if c["s"] != nil && replaceAreas(c["s"].([]interface{})) {
|
|
|
+ return true
|
|
|
+ }*/
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return false
|
|
|
+ }
|
|
|
+ for _, p := range provinces { //省
|
|
|
+ if replaceStart(util.ObjToString(p["n"]), false) {
|
|
|
+ replaceCity(p["s"].([]interface{}))
|
|
|
+ break
|
|
|
+ } else if replaceCity(p["s"].([]interface{})) {
|
|
|
+ break
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return text
|
|
|
+}
|