|
@@ -6,6 +6,7 @@ import (
|
|
|
"fmt"
|
|
|
"github.com/gogf/gf/v2/frame/g"
|
|
|
"github.com/gogf/gf/v2/os/gctx"
|
|
|
+ "github.com/gogf/gf/v2/os/gtime"
|
|
|
"github.com/gogf/gf/v2/util/gconv"
|
|
|
"jyseo/utility"
|
|
|
"log"
|
|
@@ -33,6 +34,8 @@ type (
|
|
|
const (
|
|
|
NewMustSearch = `{"query":{"bool":{"must":[%s]}}%s}`
|
|
|
biddingIndex, biddingType = "bidding", "bidding"
|
|
|
+ projectSet = "projectset"
|
|
|
+ qyxy = "qyxy"
|
|
|
)
|
|
|
|
|
|
func init() {
|
|
@@ -41,68 +44,91 @@ func init() {
|
|
|
|
|
|
func (e *Enterprises) InitEnterprises(ctx context.Context) {
|
|
|
winnerConfig := g.Cfg("global").MustGet(ctx, "portraitRecommend.winner").Strings()
|
|
|
- if res, _ := g.DB("tidb").Query(ctx, fmt.Sprintf(`SELECT seo_id,name FROM global_common_data.dws_f_ent_baseinfo dfeb WHERE (dfeb.identity_type &(1 << 0)) > 0 AND name in ('%s') `, strings.Join(winnerConfig, "','"))); !res.IsEmpty() {
|
|
|
- for _, m := range res.List() {
|
|
|
- name := gconv.String(m["name"])
|
|
|
- sid := gconv.String(m["seo_id"])
|
|
|
- if name != "" && sid != "" {
|
|
|
- e.WinnerRecommend = append(e.WinnerRecommend, map[string]interface{}{
|
|
|
- "name": name,
|
|
|
- "url": fmt.Sprintf("/qy/%s.html", sid),
|
|
|
- })
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
+ e.WinnerRecommend = getWinnerSeoIdByName("company_name", false, winnerConfig...)
|
|
|
buyerConfig := g.Cfg("global").MustGet(ctx, "portraitRecommend.buyer").Strings()
|
|
|
- if res, _ := g.DB("tidb").Query(ctx, fmt.Sprintf(`SELECT seo_id,name FROM global_common_data.dws_f_ent_baseinfo dfeb WHERE (identity_type & (1 << 1)) > 0 AND name in ('%s') `, strings.Join(buyerConfig, "','"))); !res.IsEmpty() {
|
|
|
- for _, m := range res.List() {
|
|
|
- name := gconv.String(m["name"])
|
|
|
- sid := gconv.String(m["seo_id"])
|
|
|
- if name != "" && sid != "" {
|
|
|
- e.BuyerRecommend = append(e.BuyerRecommend, map[string]interface{}{
|
|
|
- "name": name,
|
|
|
- "url": fmt.Sprintf("/dw/%s.html", sid),
|
|
|
- })
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
+ e.BuyerRecommend = getBuyerSeoIdByName(false, buyerConfig...)
|
|
|
}
|
|
|
|
|
|
-func (e *Enterprises) InitEnterprises_Es(ctx context.Context) {
|
|
|
- winnerConfig := g.Cfg("global").MustGet(ctx, "portraitRecommend.winner").Strings()
|
|
|
- winnerRes := elastic.Get("qyxy", "qyxy", fmt.Sprintf(`{"query":{"terms":{"company_name":["%s"]}},"_source":["seo_id","company_name"]}`, strings.Join(winnerConfig, `","`)))
|
|
|
+// 根据企业名称获取seoid
|
|
|
+// query: company_name 根据名字匹配
|
|
|
+// query: _id 根据entid匹配
|
|
|
+func getWinnerSeoIdByName(query string, fullData bool, winners ...string) (res []map[string]interface{}) {
|
|
|
+ if len(winners) == 0 {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ var fields string = `"nseo_id","company_name"`
|
|
|
+ if fullData {
|
|
|
+ fields = `"nseo_id","company_name","legal_person","capital","establish_date","company_phone","company_address","company_status"`
|
|
|
+ }
|
|
|
+
|
|
|
+ winnerRes := elastic.Get(qyxy, qyxy, fmt.Sprintf(`{"query":{"terms":{"%s":["%s"]}},"_source":[%s],"size":%d}`, query, strings.Join(winners, `","`), fields, len(winners)))
|
|
|
if winnerRes != nil && len(*winnerRes) > 0 {
|
|
|
for _, m := range *winnerRes {
|
|
|
name := gconv.String(m["company_name"])
|
|
|
- sid := gconv.String(m["seo_id"])
|
|
|
+ sid := gconv.String(m["nseo_id"])
|
|
|
if name != "" && sid != "" {
|
|
|
- e.WinnerRecommend = append(e.WinnerRecommend, map[string]interface{}{
|
|
|
- "name": name,
|
|
|
- "url": fmt.Sprintf("/qy/%s.html", sid),
|
|
|
- })
|
|
|
+ row := map[string]interface{}{
|
|
|
+ "name": name,
|
|
|
+ "seoId": sid,
|
|
|
+ "url": fmt.Sprintf("/qy/%s.html", sid),
|
|
|
+ }
|
|
|
+ if fullData {
|
|
|
+ row["legal_person"] = m["legal_person"]
|
|
|
+ row["capital"] = m["capital"]
|
|
|
+ if dataStamp := gconv.Int64(m["establish_date"]); dataStamp > 0 {
|
|
|
+ row["establish_date"] = gtime.New(dataStamp).Format("Y-m-d")
|
|
|
+ }
|
|
|
+ row["company_phone"] = m["company_phone"]
|
|
|
+ row["address"] = m["company_address"]
|
|
|
+ if state := gconv.String(m["company_status"]); state != "" {
|
|
|
+ row["company_status"] = strings.Split(state, "(")[0]
|
|
|
+ }
|
|
|
+ }
|
|
|
+ res = append(res, row)
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- buyerRes := elastic.Get("qyxy", "qyxy", fmt.Sprintf(`{"query":{"terms":{"buyer_name":["%s"]}},"_source":["seo_id","name"]}`, strings.Join(winnerConfig, `","`)))
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+// 根据采购单位名字获取seoid
|
|
|
+func getBuyerSeoIdByName(fullData bool, buyer ...string) (res []map[string]interface{}) {
|
|
|
+ if len(buyer) == 0 {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ var fields string = `"seo_id","name"`
|
|
|
+ if fullData {
|
|
|
+ fields = `"seo_id","name","area","city","buyerclass"`
|
|
|
+ }
|
|
|
+
|
|
|
+ buyerRes := elastic.Get("buyer", "buyer", fmt.Sprintf(`{"query":{"terms":{"buyer_name":["%s"]}},"_source":[%s],"size":%d}`, strings.Join(buyer, `","`), fields, len(buyer)))
|
|
|
if buyerRes != nil && len(*buyerRes) > 0 {
|
|
|
for _, m := range *buyerRes {
|
|
|
name := gconv.String(m["name"])
|
|
|
sid := gconv.String(m["seo_id"])
|
|
|
if name != "" && sid != "" {
|
|
|
- e.BuyerRecommend = append(e.BuyerRecommend, map[string]interface{}{
|
|
|
- "name": name,
|
|
|
- "url": fmt.Sprintf("/dw/%s.html", sid),
|
|
|
- })
|
|
|
+ row := map[string]interface{}{
|
|
|
+ "name": name,
|
|
|
+ "seoId": sid,
|
|
|
+ "url": fmt.Sprintf("/dw/%s.html", sid),
|
|
|
+ }
|
|
|
+ if fullData {
|
|
|
+ row["buyerclass"] = m["buyerclass"]
|
|
|
+ row["province"] = m["area"]
|
|
|
+ row["city"] = m["city"]
|
|
|
+ }
|
|
|
+ res = append(res, row)
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+ return
|
|
|
}
|
|
|
|
|
|
// GetEnterprisesList 获取最新采购单位或中标企业列表
|
|
|
// identityType : 0 采购单位 1-中标单位
|
|
|
// limit: 数量
|
|
|
-func (*Enterprises) GetEnterprisesList(ctx context.Context, identityType, pageNum, pageSize, limit int) (res *MapsTotalResp, err error) {
|
|
|
- key := fmt.Sprintf("enterpriseList_%d_%d_%d_%d", identityType, pageNum, pageSize, limit)
|
|
|
+func (*Enterprises) GetEnterprisesList(ctx context.Context, isWinner bool, pageNum, pageSize, limit int) (res *MapsTotalResp, err error) {
|
|
|
+ key := fmt.Sprintf("enterpriseList_%v_%d_%d_%d", isWinner, pageNum, pageSize, limit)
|
|
|
gVal, err := g.Redis().Get(ctx, key)
|
|
|
if err == nil && !gVal.IsNil() {
|
|
|
res = &MapsTotalResp{}
|
|
@@ -111,48 +137,43 @@ func (*Enterprises) GetEnterprisesList(ctx context.Context, identityType, pageNu
|
|
|
}
|
|
|
}
|
|
|
var sql string
|
|
|
- if identityType == 0 {
|
|
|
- sql = fmt.Sprintf(`
|
|
|
- SELECT c.seo_id AS sid,c.name,c.company_id AS id,b.NAME AS buyerclass,p.area AS province,ca.city AS city
|
|
|
- FROM (
|
|
|
- SELECT dfeb.seo_id,dfeb.NAME, dfeb.company_id, dfeb.area_code, dfeb.city_code, dfeb.name_id,dfet.labelvalues
|
|
|
+ if !isWinner {
|
|
|
+ sql = fmt.Sprintf(`SELECT dfeb.name
|
|
|
FROM global_common_data.dws_f_ent_baseinfo dfeb
|
|
|
- INNER JOIN global_common_data.dws_f_ent_tags dfet
|
|
|
- ON (dfeb.identity_type &(1 << 0)) > 0 AND dfeb.name_id = dfet.name_id
|
|
|
- ORDER BY dfeb.latest_time DESC LIMIT %d
|
|
|
- ) c LEFT JOIN global_common_data.code_buyerclass b ON (b. CODE = c.labelvalues)
|
|
|
- LEFT JOIN global_common_data.code_area p ON (p. CODE = c.area_code)
|
|
|
- LEFT JOIN global_common_data.code_area ca ON (ca. CODE = c.city_code)`, limit)
|
|
|
- } else if identityType == 1 {
|
|
|
+ WHERE name NOT LIKE '%%\n%%' and (dfeb.identity_type &(1 << 0)) > 0
|
|
|
+ ORDER BY dfeb.latest_time DESC LIMIT %d`, limit)
|
|
|
+ } else {
|
|
|
sql = fmt.Sprintf(`
|
|
|
- SELECT c.seo_id AS sid,c.name, c.company_id AS id,c.address,cb.legal_person,cb.company_status,cb.capital,DATE_FORMAT(cb.establish_date, '%s') AS establish_date,cb.company_phone
|
|
|
- FROM (
|
|
|
- SELECT seo_id,name, company_id,address
|
|
|
+ SELECT company_id
|
|
|
FROM global_common_data.dws_f_ent_baseinfo
|
|
|
WHERE company_id!=''and (identity_type & (1 << 1)) > 0
|
|
|
- order by latest_time desc LIMIT %d
|
|
|
- ) c left join global_common_data.company_baseinfo cb on(cb.company_id=c.company_id)`, "%Y-%m-%d", limit)
|
|
|
+ order by latest_time desc LIMIT %d`, limit)
|
|
|
}
|
|
|
|
|
|
rData, err := g.DB("tidb").Query(ctx, sql)
|
|
|
- if err != nil {
|
|
|
- return nil, fmt.Errorf("查询数据异常")
|
|
|
- }
|
|
|
- if count := rData.Len(); count > 0 {
|
|
|
- urlFlag := "dw"
|
|
|
- if identityType == 1 {
|
|
|
- urlFlag = "qy"
|
|
|
- }
|
|
|
-
|
|
|
- finalList := rData.List()
|
|
|
-
|
|
|
- for i := 0; i < count; i++ {
|
|
|
- finalList[i]["url"] = fmt.Sprintf("/%s/%s.html", urlFlag, gconv.String(finalList[i]["sid"]))
|
|
|
- if state := gconv.String(finalList[i]["company_status"]); state != "" {
|
|
|
- finalList[i]["company_status"] = strings.Split(state, "(")[0]
|
|
|
+ //getData := elastic.Get(projectSet, projectSet, sql)
|
|
|
+ var finalList []map[string]interface{}
|
|
|
+ if rData.Size() > 0 {
|
|
|
+ var queryArr []string = make([]string, 0, limit)
|
|
|
+ if isWinner { //采购关联企业 校验正确性
|
|
|
+ for _, v := range rData.List() {
|
|
|
+ if company_id := gconv.String(v["company_id"]); company_id != "" {
|
|
|
+ queryArr = append(queryArr, company_id)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ finalList = getWinnerSeoIdByName("_id", true, queryArr...)
|
|
|
+ } else {
|
|
|
+ var queryArr []string
|
|
|
+ for _, v := range rData.List() {
|
|
|
+ if buyerName := gconv.String(v["name"]); buyerName != "" {
|
|
|
+ queryArr = append(queryArr, buyerName)
|
|
|
+ }
|
|
|
}
|
|
|
+ finalList = getBuyerSeoIdByName(true, queryArr...)
|
|
|
}
|
|
|
+ }
|
|
|
|
|
|
+ if count := len(finalList); count > 0 {
|
|
|
totalPage := count / pageSize
|
|
|
if count%pageSize != 0 {
|
|
|
totalPage++
|
|
@@ -169,7 +190,7 @@ func (*Enterprises) GetEnterprisesList(ctx context.Context, identityType, pageNu
|
|
|
if i == pageNum {
|
|
|
res = pageTmp
|
|
|
}
|
|
|
- if err := g.Redis().SetEX(ctx, fmt.Sprintf("enterpriseList_%d_%d_%d_%d", identityType, i, pageSize, limit), pageTmp, 60*60*24); err != nil {
|
|
|
+ if err := g.Redis().SetEX(ctx, fmt.Sprintf("enterpriseList_%v_%d_%d_%d", isWinner, i, pageSize, limit), pageTmp, 60*60*24); err != nil {
|
|
|
g.Log().Errorf(ctx, "第%d页数据 存储redis err:%v", i, err)
|
|
|
}
|
|
|
}
|
|
@@ -179,86 +200,71 @@ func (*Enterprises) GetEnterprisesList(ctx context.Context, identityType, pageNu
|
|
|
|
|
|
// GetEntDetailMsg 查询企业详细信息
|
|
|
func (*Enterprises) GetEntDetailMsg(ctx context.Context, seoId string, isWinner bool) map[string]interface{} {
|
|
|
- if isWinner {
|
|
|
- res, err := g.DB("tidb").Query(context.Background(), `
|
|
|
- SELECT c.seo_id AS sid,c.company_id as entId,c.name,cb.*,DATE_FORMAT(cb.establish_date, '%Y-%m-%d') AS establish_formatDate,ca.area
|
|
|
- FROM (
|
|
|
- SELECT seo_id,name, company_id,address
|
|
|
- FROM global_common_data.dws_f_ent_baseinfo
|
|
|
- WHERE company_id !='' and (identity_type & (1 << 1)) > 0
|
|
|
- and seo_id = ?
|
|
|
- ) c LEFT JOIN global_common_data.company_baseinfo cb on(cb.company_id=c.company_id)
|
|
|
- LEFT JOIN global_common_data.code_area ca on(cb.area_code=ca.code )`, seoId)
|
|
|
- if err != nil {
|
|
|
- g.Log().Errorf(ctx, "GetEntDetailMsg 异常", err)
|
|
|
- }
|
|
|
- if res.Len() == 1 {
|
|
|
- return res.List()[0]
|
|
|
- }
|
|
|
- } else {
|
|
|
- res, err := g.DB("tidb").Query(context.Background(), `
|
|
|
- SELECT c.*,cb.name AS buyerclass,ca.area as area ,ca.city as city FROM
|
|
|
- (SELECT name,area_code,city_code,name_id FROM global_common_data.dws_f_ent_baseinfo WHERE seo_id = ?) c
|
|
|
- LEFT JOIN global_common_data.dws_f_ent_tags dfet on(c.name_id=dfet.name_id )
|
|
|
- LEFT JOIN global_common_data.code_buyerclass cb on(dfet.labelvalues=cb.code)
|
|
|
- LEFT JOIN global_common_data.code_area ca on(IF(c.city_code,ca.code=c.city_code,ca.code=c.area_code))`, seoId)
|
|
|
- if err != nil {
|
|
|
- g.Log().Errorf(ctx, "GetEntDetailMsg 异常", err)
|
|
|
- }
|
|
|
- if res.Len() == 1 {
|
|
|
- return res.List()[0]
|
|
|
+ redisKey := fmt.Sprintf("jyseo_getEntDetailMsg_%v_%s", isWinner, seoId)
|
|
|
+ gVal, err := g.Redis().Get(ctx, redisKey)
|
|
|
+ if err == nil && !gVal.IsNil() {
|
|
|
+ res := map[string]interface{}{}
|
|
|
+ if err := gVal.Struct(&res); err == nil {
|
|
|
+ return res
|
|
|
}
|
|
|
}
|
|
|
- return nil
|
|
|
-}
|
|
|
-
|
|
|
-// GetEntDetailMsg 查询企业详细信息
|
|
|
-func (*Enterprises) GetEntDetailMsg_Es(ctx context.Context, seoId string, isWinner bool) map[string]interface{} {
|
|
|
- if isWinner {
|
|
|
- res := elastic.Get("qyxy", "qyxy", fmt.Sprintf(`{"query":{"term":{"seo_id":"%s"}},"_source":["seo_id","name","area","city","buyerclass"]}`, seoId))
|
|
|
- if res == nil || len(*res) == 0 {
|
|
|
- return nil
|
|
|
- }
|
|
|
- if dataMap := (*res)[0]; len(dataMap) > 0 {
|
|
|
- return map[string]interface{}{
|
|
|
- "entId": dataMap["id"],
|
|
|
- "seo_id": dataMap["seo_id"],
|
|
|
- "name": dataMap["company_name"],
|
|
|
- "area": dataMap["company_area"],
|
|
|
- "city": dataMap["company_city"],
|
|
|
- "legal_person": dataMap["legal_person"],
|
|
|
- "company_status": dataMap["company_status"],
|
|
|
- "credit_no": dataMap["credit_no"],
|
|
|
- "establish_date": dataMap["establish_date"],
|
|
|
- "org_code": dataMap["org_code"],
|
|
|
- "capital": dataMap["capital"],
|
|
|
- "tax_code": dataMap["tax_code"],
|
|
|
- "operation_startdate": dataMap["operation_startdate"],
|
|
|
- "operation_enddate": dataMap["operation_enddate"],
|
|
|
- "company_code": dataMap["company_code"],
|
|
|
- "company_type": dataMap["company_type"],
|
|
|
- "employee_num": dataMap["employee_num"],
|
|
|
- "company_phone": dataMap["company_phone"],
|
|
|
- "company_address": dataMap["company_address"],
|
|
|
- "business_scope": dataMap["business_scope"],
|
|
|
+ entDetail := func() map[string]interface{} {
|
|
|
+ if isWinner {
|
|
|
+ res := elastic.Get(qyxy, qyxy, fmt.Sprintf(`{"query":{"term":{"nseo_id":"%s"}},"_source":["_id","nseo_id","company_name","company_area","company_city","legal_person","company_status","credit_no","establish_date","org_code","capital","tax_code", "operation_startdate","operation_enddate","company_code","company_type","employee_num","company_phone","company_address","business_scope"]}`, seoId))
|
|
|
+ if res == nil || len(*res) == 0 {
|
|
|
+ return nil
|
|
|
}
|
|
|
- }
|
|
|
- } else {
|
|
|
- res := elastic.Get("buyer", "buyer", fmt.Sprintf(`{"query":{"term":{"seo_id":"%s"}},"_source":["seo_id","name","area","city","buyerclass"]}`, seoId))
|
|
|
- if res == nil || len(*res) == 0 {
|
|
|
- return nil
|
|
|
- }
|
|
|
- if dataMap := (*res)[0]; len(dataMap) > 0 {
|
|
|
- return map[string]interface{}{
|
|
|
- "seo_id": dataMap["seo_id"],
|
|
|
- "name": dataMap["name"],
|
|
|
- "area": dataMap["province"],
|
|
|
- "city": dataMap["city"],
|
|
|
- "buyerclass": dataMap["buyerclass"],
|
|
|
+ if dataMap := (*res)[0]; len(dataMap) > 0 {
|
|
|
+ if entId := gconv.String(dataMap["_id"]); entId == "" {
|
|
|
+ return nil
|
|
|
+ }
|
|
|
+ return map[string]interface{}{
|
|
|
+ "entId": dataMap["_id"],
|
|
|
+ "seo_id": dataMap["nseo_id"],
|
|
|
+ "name": dataMap["company_name"],
|
|
|
+ "area": dataMap["company_area"],
|
|
|
+ "city": dataMap["company_city"],
|
|
|
+ "legal_person": dataMap["legal_person"],
|
|
|
+ "company_status": dataMap["company_status"],
|
|
|
+ "credit_no": dataMap["credit_no"],
|
|
|
+ "establish_date": dataMap["establish_date"],
|
|
|
+ "org_code": dataMap["org_code"],
|
|
|
+ "capital": dataMap["capital"],
|
|
|
+ "tax_code": dataMap["tax_code"],
|
|
|
+ "operation_startdate": dataMap["operation_startdate"],
|
|
|
+ "operation_enddate": dataMap["operation_enddate"],
|
|
|
+ "company_code": dataMap["company_code"],
|
|
|
+ "company_type": dataMap["company_type"],
|
|
|
+ "employee_num": dataMap["employee_num"],
|
|
|
+ "company_phone": dataMap["company_phone"],
|
|
|
+ "company_address": dataMap["company_address"],
|
|
|
+ "business_scope": dataMap["business_scope"],
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ res := elastic.Get("buyer", "buyer", fmt.Sprintf(`{"query":{"term":{"seo_id":"%s"}},"_source":["seo_id","name","area","city","buyerclass"]}`, seoId))
|
|
|
+ if res == nil || len(*res) == 0 {
|
|
|
+ return nil
|
|
|
+ }
|
|
|
+ if dataMap := (*res)[0]; len(dataMap) > 0 {
|
|
|
+ if buyerName := gconv.String(dataMap["name"]); buyerName == "" {
|
|
|
+ return nil
|
|
|
+ }
|
|
|
+ return map[string]interface{}{
|
|
|
+ "seo_id": dataMap["seo_id"],
|
|
|
+ "name": dataMap["name"],
|
|
|
+ "area": dataMap["province"],
|
|
|
+ "city": dataMap["city"],
|
|
|
+ "buyerclass": dataMap["buyerclass"],
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
+ return nil
|
|
|
+ }()
|
|
|
+ if entDetail != nil {
|
|
|
+ _ = g.Redis().SetEX(ctx, redisKey, entDetail, 60*60*24)
|
|
|
}
|
|
|
- return nil
|
|
|
+ return entDetail
|
|
|
}
|
|
|
|
|
|
// GetDynamicNews 未登录用户动态信息
|
|
@@ -320,53 +326,28 @@ func (pwp *Enterprises) RelevanceData(ctx context.Context, name string, isWinner
|
|
|
if getData != nil && len(*getData) > 0 {
|
|
|
queryMap := make(map[string]bool)
|
|
|
if !isWinner { //采购关联企业 校验正确性
|
|
|
+ var queryArr []string
|
|
|
for _, v := range *getData {
|
|
|
for _, name := range gconv.Strings(v["entidlist"]) {
|
|
|
+ if queryMap[name] {
|
|
|
+ continue
|
|
|
+ }
|
|
|
+ queryArr = append(queryArr, name)
|
|
|
queryMap[name] = true
|
|
|
}
|
|
|
}
|
|
|
+ data = getWinnerSeoIdByName("_id", false, queryArr...)
|
|
|
} else {
|
|
|
+ var queryArr []string
|
|
|
for _, v := range *getData {
|
|
|
- for _, name := range gconv.Strings(v["buyer"]) {
|
|
|
- queryMap[name] = true
|
|
|
+ name = gconv.String(v["buyer"])
|
|
|
+ if queryMap[name] {
|
|
|
+ continue
|
|
|
}
|
|
|
+ queryArr = append(queryArr, name)
|
|
|
+ queryMap[name] = true
|
|
|
}
|
|
|
- }
|
|
|
- if len(queryMap) == 0 {
|
|
|
- return
|
|
|
- }
|
|
|
- var queryArr []string = make([]string, 0, len(queryMap))
|
|
|
- for name, _ := range queryMap {
|
|
|
- queryArr = append(queryArr, name)
|
|
|
- }
|
|
|
- var sql string
|
|
|
- if !isWinner {
|
|
|
- sql = fmt.Sprintf(`SELECT name,seo_id FROM global_common_data.dws_f_ent_baseinfo WHERE company_id in ("%s")`, strings.Join(queryArr, `","`))
|
|
|
- } else {
|
|
|
- sql = fmt.Sprintf(`SELECT name,seo_id FROM global_common_data.dws_f_ent_baseinfo WHERE name in ("%s")`, strings.Join(queryArr, `","`))
|
|
|
- }
|
|
|
-
|
|
|
- //根据采购单位名字或中标企业id查询seo_id
|
|
|
- dbRes, _ := g.DB("tidb").Query(ctx, sql)
|
|
|
- if dbRes.IsEmpty() {
|
|
|
- return
|
|
|
- }
|
|
|
-
|
|
|
- for _, m := range dbRes.List() {
|
|
|
- name, seo_id := gconv.String(m["name"]), gconv.String(m["seo_id"])
|
|
|
- if name == "" || seo_id == "" {
|
|
|
- continue
|
|
|
- }
|
|
|
- var url string
|
|
|
- if isWinner {
|
|
|
- url = fmt.Sprintf("/dw/%s.html", seo_id)
|
|
|
- } else {
|
|
|
- url = fmt.Sprintf("/qy/%s.html", seo_id)
|
|
|
- }
|
|
|
- data = append(data, map[string]interface{}{
|
|
|
- "name": name,
|
|
|
- "url": url,
|
|
|
- })
|
|
|
+ data = getBuyerSeoIdByName(false, queryArr...)
|
|
|
}
|
|
|
}
|
|
|
return
|
|
@@ -374,6 +355,7 @@ func (pwp *Enterprises) RelevanceData(ctx context.Context, name string, isWinner
|
|
|
if !fromCache {
|
|
|
_ = g.Redis().SetEX(ctx, redisKey, getFullArr, 60*60*24)
|
|
|
}
|
|
|
+ randomMaps = getFullArr
|
|
|
if len(getFullArr) > 10 { //大于10 随机取10个
|
|
|
rand.Seed(time.Now().UnixNano())
|
|
|
start := rand.Intn(len(getFullArr) - 10)
|
|
@@ -399,43 +381,40 @@ func (pwp *Enterprises) RecommendedData(ctx context.Context, name, province stri
|
|
|
return
|
|
|
}
|
|
|
}
|
|
|
- var sql string
|
|
|
+ var sql string = fmt.Sprintf(`{"query":{"bool":{"must":[{"term":{"area":"%s"}},%s]}},"sort":[{"lasttime":"desc"}],"_source":["entidlist","buyer"],"from":0,"size":200}`, province, "%s")
|
|
|
if isWinner {
|
|
|
- sql = fmt.Sprintf(`
|
|
|
- SELECT name,seo_id FROM global_common_data.dws_f_ent_baseinfo
|
|
|
- WHERE area_code = %s
|
|
|
- AND (identity_type & (1 << 1)) > 0
|
|
|
- ORDER BY latest_time desc limit 200
|
|
|
- `, province)
|
|
|
+ sql = fmt.Sprintf(sql, `{"exists": {"field": "s_winner"}},{"exists": {"field": "entidlist"}}`)
|
|
|
} else {
|
|
|
- sql = fmt.Sprintf(`
|
|
|
- SELECT name,seo_id FROM global_common_data.dws_f_ent_baseinfo
|
|
|
- WHERE area_code = %s
|
|
|
- AND (identity_type &(1 << 0)) > 0
|
|
|
- ORDER BY latest_time desc limit 200
|
|
|
- `, province)
|
|
|
+ sql = fmt.Sprintf(sql, `{"exists": {"field": "buyer"}`)
|
|
|
}
|
|
|
|
|
|
- dbRes, _ := g.DB("tidb").Query(ctx, sql)
|
|
|
- if dbRes.IsEmpty() {
|
|
|
- return
|
|
|
- }
|
|
|
-
|
|
|
- for _, m := range dbRes.List() {
|
|
|
- name, seo_id := gconv.String(m["name"]), gconv.String(m["seo_id"])
|
|
|
- if name == "" || seo_id == "" {
|
|
|
- continue
|
|
|
- }
|
|
|
- var url string
|
|
|
- if isWinner {
|
|
|
- url = fmt.Sprintf("/qy/%s.html", seo_id)
|
|
|
+ getData := elastic.Get(projectSet, projectSet, sql)
|
|
|
+ if getData != nil && len(*getData) > 0 {
|
|
|
+ queryMap := make(map[string]bool)
|
|
|
+ if isWinner { //采购关联企业 校验正确性
|
|
|
+ var queryArr []string
|
|
|
+ for _, v := range *getData {
|
|
|
+ for _, entId := range gconv.Strings(v["entidlist"]) {
|
|
|
+ if queryMap[entId] {
|
|
|
+ continue
|
|
|
+ }
|
|
|
+ queryArr = append(queryArr, entId)
|
|
|
+ queryMap[entId] = true
|
|
|
+ }
|
|
|
+ }
|
|
|
+ data = getWinnerSeoIdByName("_id", false, queryArr...)
|
|
|
} else {
|
|
|
- url = fmt.Sprintf("/dw/%s.html", seo_id)
|
|
|
+ var queryArr []string
|
|
|
+ for _, v := range *getData {
|
|
|
+ buyerName := gconv.String(v["buyer"])
|
|
|
+ if queryMap[buyerName] {
|
|
|
+ continue
|
|
|
+ }
|
|
|
+ queryArr = append(queryArr, buyerName)
|
|
|
+ queryMap[buyerName] = true
|
|
|
+ }
|
|
|
+ data = getBuyerSeoIdByName(false, queryArr...)
|
|
|
}
|
|
|
- data = append(data, map[string]interface{}{
|
|
|
- "name": name,
|
|
|
- "url": url,
|
|
|
- })
|
|
|
}
|
|
|
return
|
|
|
}()
|