Browse Source

企业查询提交

wangkaiyue 4 năm trước cách đây
mục cha
commit
a28813cef7

+ 143 - 0
src/jfw/modules/publicapply/src/enterpriseSearch/entity/entQuery.go

@@ -0,0 +1,143 @@
+package entity
+
+import (
+	"fmt"
+	"log"
+	qutil "qfw/util"
+	"qfw/util/elastic"
+	"strings"
+)
+
+type EnterpriseSearch struct {
+	Match       string //搜索内容
+	MatchType   string //搜索范围[A:企业名称,B:法定代表人,C:股东,D:高管,E:标的物]
+	EntArea     string //注册地省份[多个用逗号分割]
+	EntCity     string //注册地城市[多个用逗号分割]
+	EntCapital  string //注册资本[min-max,必有-]
+	EntType     string //企业类型[]
+	EntStatus   string //企业状态[吊销、存续、撤销、(停业??)]
+	BiddingArea string //中标地区[会员:多个用逗号分割]
+	EntClass    string //单位类型[会员:采购单位、投标企业、代理机构、厂商]
+	EntContact  string //联系方式[会员:固定电话、手机号、邮箱、不存在]
+
+	PageSize int  //每页数量
+	PageNum  int  //页码
+	Total    int  //一共多少条
+	IsVip    bool //是否是会员
+
+}
+
+const (
+	searchMaxLimit = 100 //最大查询数量限制
+	freeSearchNum  = 5   //免费查询数量限制
+
+	index, itype = "qyxy", "qyxy"
+)
+
+var (
+	AllMatchType = map[string]string{
+		"A": `{"match_phrase":{"ent_ikname":"%s"}}`, //企业名称
+		"B": `{"term":{"legal_person":"%s"}}`,       // 法定代表人
+		"C": `{"term":{"stock_name":"%s"}}`,         //股东
+		"D": `{"term":{"employee_name":"%s"}}`,      //高管
+		"E": `{"term":{"bid_purchasing":"%s"}}`,     //标的物
+	}
+)
+
+//Check 校验查询参数是否合法
+func (es *EnterpriseSearch) Check() (*EnterpriseSearch, error) {
+	if es.PageSize == 0 { //默认十条
+		es.PageSize = 10
+	}
+	if (es.PageNum+1)*es.PageSize > searchMaxLimit {
+		return nil, fmt.Errorf("超出查询数量限制")
+	}
+	if es.EntCapital != "" && strings.Index(es.EntCapital, "-") < 0 {
+		return es, fmt.Errorf("金额查询参数异常")
+	}
+	return es, nil
+}
+
+//GetQuerySql 获取检索语句
+//return  company_name、company_status、legal_person、capital、company_address、id
+//返回字段 企业名称、企业状态、法人、注册资本、地址、企业id
+func (es *EnterpriseSearch) GetQuerySql() string {
+	query := `{"query":{"bool":{"must":[%s]}},"_source":["id","company_name","GetQuerySql","legal_person","capital","company_address"]}`
+	musts := make([]string, 0, 0)
+	//输入查询
+	if es.Match != "" {
+		if es.MatchType != "" { //查询指定内容
+			for _, t := range strings.Split(es.MatchType, ",") {
+				if thisQuery, exists := AllMatchType[t]; exists {
+					musts = append(musts, fmt.Sprintf(thisQuery, es.Match))
+				}
+			}
+		} else { //查询全部
+			for _, q := range AllMatchType {
+				musts = append(musts, fmt.Sprintf(q, es.Match))
+			}
+		}
+	}
+	//注册地
+	if es.EntArea != "" {
+		musts = append(musts, fmt.Sprintf(`{"terms":{"company_area":["%s"]}}`, strings.ReplaceAll(es.EntArea, ",", "\",\"")))
+	}
+	if es.EntCity != "" {
+		musts = append(musts, fmt.Sprintf(`{"terms":{"company_city":["%s"]}}`, strings.ReplaceAll(es.EntCity, ",", "\",\"")))
+	}
+	//注册资本
+	if es.EntCapital != "" {
+		moneyRange := strings.Split(es.EntCapital, "-")
+		limit, max, moneyQuery := qutil.Int64All(moneyRange[0]), qutil.Int64All(moneyRange[1]), ""
+		if limit > 0 {
+			moneyQuery = fmt.Sprintf(`"from": "%d"`, qutil.Int64All(limit))
+		}
+		if max > 0 {
+			if moneyQuery != `` {
+				moneyQuery += ","
+			}
+			moneyQuery += fmt.Sprintf(`"to": "%d"`, qutil.Int64All(max))
+		}
+		if moneyQuery != "" {
+			musts = append(musts, fmt.Sprintf(`{"range": {"capital": {%s}}}`, moneyQuery))
+		}
+	}
+	//企业类型(页面显示的企业与数据已存在的类型不一致)
+	if es.EntType != "" {
+		musts = append(musts, fmt.Sprintf(`{"terms":{"xxx":["%s"]}}`, strings.ReplaceAll(es.EntType, ",", "\",\"")))
+	}
+	//企业状态
+	if es.EntStatus != "" {
+		musts = append(musts, fmt.Sprintf(`{"terms":{"company_status":["%s"]}}`, strings.ReplaceAll(es.EntStatus, ",", "\",\"")))
+	}
+	//中标区域 vip
+	if es.BiddingArea != "" && es.IsVip {
+		musts = append(musts, fmt.Sprintf(`{"term":{"bid_area":"%s"}}`, es.BiddingArea))
+	}
+	//单位类型 vip
+	if es.EntClass != "" && es.IsVip {
+		musts = append(musts, fmt.Sprintf(`{"term":{"bid_unittype":"%s"}}`, es.EntClass))
+	}
+	//联系方式 vip
+	if es.EntContact != "" && es.IsVip {
+		musts = append(musts, fmt.Sprintf(`{"term":{"bid_contracttype":"%s"}}`, es.EntContact))
+	}
+	return fmt.Sprintf(query, strings.Join(musts, ","))
+}
+
+//DoQuery 根据EnterpriseSearch参数进行企业相关查询
+func (es *EnterpriseSearch) DoQuery() (list *[]map[string]interface{}, total int64, err error) {
+	sql := es.GetQuerySql()
+	log.Println("EnterpriseSearch DoQuery sql", sql)
+	start, limit := es.PageNum*es.PageSize, es.PageSize
+	if !es.IsVip {
+		start, limit, total = 0, freeSearchNum, -1
+	} else if total == 0 {
+		if total = elastic.Count(index, itype, sql); total == 0 {
+			return
+		}
+	}
+	sql = sql[:len(sql)-1] + fmt.Sprintf(`,"from":%d,"size":%d}"`, start, limit)
+	list = elastic.Get(index, itype, sql)
+	return
+}

+ 66 - 0
src/jfw/modules/publicapply/src/enterpriseSearch/service/search.go

@@ -0,0 +1,66 @@
+package service
+
+import (
+	. "api"
+	"db"
+	"enterpriseSearch/entity"
+	"github.com/go-xweb/xweb"
+	"log"
+	qutil "qfw/util"
+	"qfw/util/jy"
+)
+
+type EnterpriseSearchAction struct {
+	*xweb.Action
+	doEntSearch xweb.Mapper `xweb:"/enterpriseSearch/doQuery"` //企业搜索
+}
+
+//企业搜索
+func (esa *EnterpriseSearchAction) DoEntSearch() {
+	userId, _ := esa.GetSession("userId").(string)
+	rData, errMsg := func() (interface{}, error) {
+		entSearch, err := (&entity.EnterpriseSearch{
+			Match:       esa.GetString("match"),
+			MatchType:   esa.GetString("matchType"),
+			EntArea:     esa.GetString("entArea"),
+			EntCity:     esa.GetString("entCity"),
+			EntCapital:  esa.GetString("entCapital"),
+			EntType:     esa.GetString("entType"),
+			EntStatus:   esa.GetString("entStatus"),
+			BiddingArea: esa.GetString("biddingArea"),
+			EntClass:    esa.GetString("entClass"),
+			EntContact:  esa.GetString("entContact"),
+			PageSize:    qutil.IntAll(esa.GetString("pageSize")),
+			PageNum:     qutil.IntAll(esa.GetString("pageNum")),
+			Total:       qutil.IntAll(esa.GetString("total")),
+		}).Check()
+		if err != nil {
+			return nil, err
+		}
+		//查询是否是会员
+		if vipData := jy.GetBigVipUserBaseMsg(userId, db.Mysql, db.Mgo); vipData.Status > 0 || vipData.VipStatus > 0 {
+			entSearch.IsVip = true
+		}
+		//查询
+		searchList, total, err := entSearch.DoQuery()
+		if err != nil {
+			return nil, err
+		}
+		//格式化字段,加密id
+		if searchList != nil { //company_name、company_status、legal_person、capital、company_address、id
+			for index, _ := range *searchList {
+				if id := qutil.ObjToString((*searchList)[index]["id"]); id != "" {
+					(*searchList)[index]["id"] = qutil.DecodeArticleId2ByCheck(id)[0]
+				}
+			}
+		}
+		return map[string]interface{}{
+			"total": total,
+			"list":  searchList,
+		}, nil
+	}()
+	if errMsg != nil {
+		log.Printf("%s EnterpriseSearchAction DoEntSearch异常:%s\n", userId, errMsg.Error())
+	}
+	esa.ServeJson(NewResult(rData, errMsg))
+}

+ 1 - 0
src/jfw/modules/publicapply/src/main.go

@@ -5,6 +5,7 @@ import (
 	_ "bidcollection"
 	. "config"
 	_ "db"
+	_ "enterpriseSearch"
 	_ "filter"
 	_ "free"
 	"net/http"