Browse Source

企业检索

张金坤 9 năm trước cách đây
mục cha
commit
2784a1c4a2
1 tập tin đã thay đổi với 134 bổ sung4 xóa
  1. 134 4
      core/src/qfw/search/wxsearchservice.go

+ 134 - 4
core/src/qfw/search/wxsearchservice.go

@@ -114,7 +114,7 @@ func (n *Wxsearch) WxgetEnterpriseList(reqType, param /*参数*/ string) error {
 	//必须是登录之后的已认证用户才可以进入企业社区
 	//if ui, _ := (n.GetSession("userInfo")).(*map[string]interface{}); reqType == "m_" || (n.GetSession("userType") != nil && IntAll(n.GetSession("userType")) > 0) && ((n.GetSession("identWay") != nil && IntAll(n.GetSession("identWay")) == 1) || ((*ui)["s_pid"] != nil && (*ui)["s_pid"].(string) != "")) {
 	//n.T["uri"] = n.Uri()
-
+	i_mingpian := n.GetString("i_mingpian") //是否走名片查询
 	if len(param) == 0 {
 		//请求是表单提交,走的查询
 		//拼装查询对象
@@ -127,11 +127,20 @@ func (n *Wxsearch) WxgetEnterpriseList(reqType, param /*参数*/ string) error {
 			"c_zb":        n.GetString("c_zb"),
 			"all":         n.GetString("all"),
 			"c_author":    n.GetString("c_author"),
-			"cityNo":      n.GetString("cityNo"), // 是否是第一次查询并且没有选择地市,自动根据IP来设
+			"cityNo":      n.GetString("cityNo"), //是否是第一次查询并且没有选择地市,自动根据IP来设
 		}
 		//查询生成列表数据
-		data, pagination := wxsearhWebContentent(querymap, n, reqType)
-		n.Render("/search/wxentlist.html", &xweb.T{"querymap": querymap, "data": data, "pagination": pagination})
+		if i_mingpian != "" {
+			data, pagination, has := wxsearhWebContententMp(querymap, n, reqType, false)
+			n.Render("/search/wxentlist.html", &xweb.T{"querymap": querymap, "data": data, "pagination": pagination})
+			if !has {
+				data, pagination := wxsearhWebContentent(querymap, n, reqType)
+				n.Render("/search/wxentlist.html", &xweb.T{"querymap": querymap, "data": data, "pagination": pagination})
+			}
+		} else {
+			data, pagination := wxsearhWebContentent(querymap, n, reqType)
+			n.Render("/search/wxentlist.html", &xweb.T{"querymap": querymap, "data": data, "pagination": pagination})
+		}
 	} else {
 		//反转生成map
 		paramstr := param[1:]
@@ -375,6 +384,7 @@ func wxsearhWebContentent(querymap map[string]string, n *Wxsearch, reqType strin
 	if err != nil {
 		return nil, nil
 	}
+	log.Println("query", query)
 	var res []map[string]interface{}
 	if searchResult.Hits != nil {
 		resNum := len(searchResult.Hits.Hits)
@@ -464,3 +474,123 @@ func wxsearhWebContentent(querymap map[string]string, n *Wxsearch, reqType strin
 	return &res, &pagination
 
 }
+
+//通过企业名片查询
+func wxsearhWebContententMp(querymap map[string]string, n *Wxsearch, reqType string, has bool) (*[]map[string]interface{}, *[]interface{}, bool) {
+	queryStr := querymap["query"]
+	fmt.Println("检索条件:", queryStr)
+	keyword := queryStr
+	var query = `{
+	    "query": {
+	        "bool": {
+	            "must": ["match": {"enterprise.EntName": {"query": "` + keyword + `","operator": "and"}}}],
+	            "must_not": {"terms": {"SourceType": ["03", "04"]}},
+	            "should": [],
+	            "minimum_should_match": 1
+	        }
+	    },
+	    "highlight": {
+	        "pre_tags": ["<span class='highlight'>"],
+	        "post_tags": ["</span>"],
+	        "fields": {
+	            "EntName": {"force_source": true},
+	            "LeRep": {"force_source": true},
+	            "s_servicenames": {"force_source": true},
+	            "RegNo": {"force_source": true},
+	            "OpScope": {"force_source": true},
+	            "s_synopsis": {"force_source": true},
+	            "stock": {"force_source": true}
+	        }
+	    },
+	    "_source": [
+	        "_id","EntName","RegOrgName","RegNo","EntType",
+	        "LeRep","EstDate","OpLocDistrictName","OpStateName",
+	        "s_servicenames","s_action","OpLocDistrict","s_submitid"
+	    ],
+	    "from": 0,"size": 10,
+	    "sort": [{"OpSint": "desc","RegCap": "desc"}]
+	}`
+	//查询列表数据
+	client := elastic.GetEsConn()
+	defer elastic.DestoryEsConn(client)
+	if client == nil {
+		return nil, nil, false
+	}
+	searchResult, err := client.Search().Index("enterprise").Type("enterprise").Source(query).Do()
+	if err != nil {
+		return nil, nil, false
+	}
+	var res []map[string]interface{}
+	if searchResult.Hits != nil {
+		resNum := len(searchResult.Hits.Hits)
+		res = make([]map[string]interface{}, resNum)
+		for i, hit := range searchResult.Hits.Hits {
+			json.Unmarshal(*hit.Source, &res[i])
+			//查询结果数据加工处理
+			for k, v := range hit.Highlight {
+				res[i][k] = v[0]
+			}
+			EntName, _ := res[i]["EntName"].(string)
+			if EntName != keyword {
+				continue
+			} else {
+				has = true
+			}
+			tmpNo := res[i]["EntType"]
+			if tmpNo != nil {
+				switch tmpNo.(string) {
+				case "4500", "6800", "6810", "6820", "7100", "7110", "7120", "7130", "7190", "9200", "6840", "2100", "2110", "2120", "2121", "2122", "2123", "2130", "2140", "2150", "2151", "2152", "2190", "2200", "2210", "2211", "2212", "2213", "2219", "2220", "2221", "2222", "2223", "2229", "4000", "4300", "4310", "4320", "4330", "4340", "4550", "4551", "4552", "4553", "4560", "5800", "5810", "5820":
+					res[i]["EntType"] = "5810"
+				}
+			}
+
+			entlerp, _ := res[i]["LeRep"].(string)
+			tmpentno, _ := res[i]["RegNo"].(string)
+			if len(keyword) < 1 {
+				tmpentno = strings.Replace(tmpentno, "highlight", "", -1)
+				EntName = strings.Replace(EntName, "highlight", "", -1)
+			}
+			res[i]["RegNo"] = template.HTML(tmpentno)
+			if tmpNo == "9600" && strings.Contains(EntName, tmpentno) {
+				res[i]["EntName"] = template.HTML(strings.Replace(EntName, tmpentno, entlerp, -1))
+			} else {
+				res[i]["EntName"] = template.HTML(EntName)
+			}
+
+			id := res[i]["s_submitid"]
+			if id != nil {
+				ud := FindById("user", id.(string), `{"i_comauthenttype":1}`)
+				res[i]["i_comauthenttype"] = (*ud)["i_comauthenttype"]
+			}
+			//
+
+			res[i]["tmpentno"] = template.HTML(tmpentno)
+			LeRep, _ := res[i]["LeRep"].(string)
+			res[i]["LeRep"] = template.HTML(LeRep)
+			s_servicenames, _ := res[i]["s_servicenames"].(string)
+			res[i]["s_servicenames"] = template.HTML(s_servicenames)
+
+			OpScope, _ := res[i]["OpScope"].(string)
+			if len(OpScope) > 0 {
+				res[i]["OpScope"] = template.HTML(OpScope)
+			}
+			s_synopsis, _ := res[i]["s_synopsis"].(string)
+			if len(s_synopsis) > 0 {
+				res[i]["s_synopsis"] = template.HTML(s_synopsis)
+			}
+			stock, _ := res[i]["stock"].(string)
+			if len(stock) > 0 {
+				res[i]["stock"] = template.HTML(stock)
+			}
+			tmpdate, _ := res[i]["EstDate"]
+			if tmpdate != nil {
+				res[i]["EstDate"] = FormatDateWithObj(&tmpdate, Date_Short_Layout)
+			} else {
+				res[i]["EstDate"] = ""
+			}
+		}
+	}
+	//生成分页
+	pagination := front.MakePagination(1, 1, 1, querymap, "/wx/search/enterprise/"+reqType+"ent_%s.html")
+	return &res, &pagination, has
+}