Explorar o código

Merge remote-tracking branch 'origin/master'

WH01243 hai 9 meses
pai
achega
4fd286d21c
Modificáronse 2 ficheiros con 36 adicións e 32 borrados
  1. 17 12
      api/internal/service/CoopHistoryService.go
  2. 19 20
      api/internal/service/plistService.go

+ 17 - 12
api/internal/service/CoopHistoryService.go

@@ -19,12 +19,14 @@ import (
 var (
 	INDEX_1   = "transaction_info"
 	sql_2_0   = `SELECT buyer, buyer_id, agency, agency_id, property_form FROM information.transaction_info WHERE project_id = ?`
+	sql_2_2   = `SELECT buyer, buyer_id, agency, agency_id, property_form FROM information.transaction_info WHERE has(info_ids, ?)`
 	sql_2_1   = `SELECT project_id, project_name, zbtime FROM information.transaction_info WHERE buyer_id = ? AND has(winner, ?) ORDER BY zbtime DESC`
 	sql_2_1_1 = `SELECT project_id, project_name, zbtime FROM information.transaction_info WHERE buyer_id = ? AND agency = ? ORDER BY zbtime DESC`
-	sql_2_2   = `select DISTINCT  b.company_id,b.company_name,a.relate_id,a.relate_name,b.contact_person   from  connection_introduce a  INNER JOIN connection b on  a.position_id= ? and a.connection_id=b.id  and   a.relate_Id = ? and  a.itype =1  and  b.itype=4 and  b.status=1 `
-	sql_2_3   = `select a.a_id as a_id, a.b_id as b_id, a.a_name as a_name, a.b_name as b_name, a.code as code, c.legal_person as c_person, d.legal_person d_person from crm.ent_map_code a left join ent_info c on (a.a_id = ? or a.b_id = ? ) and a.code in('0101', '0201') and a.a_id = c.id left join ent_info d on (a.a_id = ? or a.b_id = ? ) and a.code in('0101', '0201') and a.b_id = d.id where (a.a_id = ? or a.b_id = ? ) and a.code in('0101', '0201')`
-	es_query  = `{"query": {"bool": {"must": [{"terms": {"buyer_id": ["%s"]}},{"exists": {"field": "winner_id"}}],"must_not": {"terms": {"property_form": ["%s"]}}}},"aggs": {"winner_count": {"terms": {"field": "winner","size": 1000,"order": {"_count": "desc"}},"aggs": {"amount_all": {"sum": {"field": "project_money"}},"ent_id": {"terms": {"field": "winner_id"}},"buyer_id": {"terms": {"field": "buyer_id"}}}}},"size": 1}`
-	es_query1 = `{"query": {"bool": {"must": [{"terms": {"buyer_id": ["%s"]}}],"must_not": [{"term": {"agency_id": {"value": ""}}}]}},"aggs": {"agency_count": {"terms": {"field": "agency","size": 1000,"order": {"_count": "desc"}},"aggs": {"amount_all": {"sum": {"field": "project_money"}},"ent_id": {"terms": {"field": "agency_id"}},"buyer_id": {"terms": {"field": "buyer_id"}}}}},"size": 1}`
+	//sql_2_2    = `select DISTINCT  b.company_id,b.company_name,a.relate_id,a.relate_name,b.contact_person   from  connection_introduce a  INNER JOIN connection b on  a.position_id= ? and a.connection_id=b.id  and   a.relate_Id = ? and  a.itype =1  and  b.itype=4 and  b.status=1 `
+	//sql_2_3    = `select a.a_id as a_id, a.b_id as b_id, a.a_name as a_name, a.b_name as b_name, a.code as code, c.legal_person as c_person, d.legal_person d_person from crm.ent_map_code a left join ent_info c on (a.a_id = ? or a.b_id = ? ) and a.code in('0101', '0201') and a.a_id = c.id left join ent_info d on (a.a_id = ? or a.b_id = ? ) and a.code in('0101', '0201') and a.b_id = d.id where (a.a_id = ? or a.b_id = ? ) and a.code in('0101', '0201')`
+	es_query   = `{"query": {"bool": {"must": [{"terms": {"buyer_id": ["%s"]}},{"exists": {"field": "winner_id"}}],"should": [%s],"minimum_should_match": 1}},"aggs": {"winner_count": {"terms": {"field": "winner","size": 1000,"order": {"_count": "desc"}},"aggs": {"amount_all": {"sum": {"field": "project_money"}},"ent_id": {"terms": {"field": "winner_id"}},"buyer_id": {"terms": {"field": "buyer_id"}}}}},"size": 1}`
+	es_query1  = `{"query": {"bool": {"must": [{"terms": {"buyer_id": ["%s"]}}],"must_not": [{"term": {"agency_id": {"value": ""}}}]}},"aggs": {"agency_count": {"terms": {"field": "agency","size": 1000,"order": {"_count": "desc"}},"aggs": {"amount_all": {"sum": {"field": "project_money"}},"ent_id": {"terms": {"field": "agency_id"}},"buyer_id": {"terms": {"field": "buyer_id"}}}}},"size": 1}`
+	shouldMul1 = `{"term": {"topscopeclass": "%s"}}`
 )
 
 type ResultData struct {
@@ -76,16 +78,15 @@ type Cooperate struct {
 
 func GetPrList(req *types.CoopHistoryReq) (result []*ResultData, size_1, size_2, size_3, size_4 int64) {
 	pTmp := ProjectTmp{}
-	id := ""
+	var err error
 	if req.Pid != "" {
-		id = req.Pid
+		err = T.ClickhouseConn.QueryRow(context.TODO(), sql_2_0, req.Pid).ScanStruct(&pTmp)
 	} else if req.Bid != "" {
-		id = encrypt.CommonDecodeArticle("content", req.Bid)[0]
-	}
-	if id == "" {
+		id := encrypt.CommonDecodeArticle("content", req.Bid)[0]
+		err = T.ClickhouseConn.QueryRow(context.TODO(), sql_2_2, id).ScanStruct(&pTmp)
+	} else {
 		return
 	}
-	err := T.ClickhouseConn.QueryRow(context.TODO(), sql_2_0, id).ScanStruct(&pTmp)
 	if err != nil {
 		return nil, 0, 0, 0, 0
 	}
@@ -203,8 +204,12 @@ func GetData(scopeClass []string, bid string) (result1, result2 map[string][]map
 	noIds := []string{}
 	if len(scopeClass) > 0 {
 		//同甲异态 中标企业
-		aggs, _, _ := elastic.GetAggs(INDEX_1, INDEX_1, fmt.Sprintf(es_query, strings.ReplaceAll(bid, ",", `","`), strings.Join(scopeClass, "\",\"")))
-		logx.Info("es聚合查询结果:", fmt.Sprintf(es_query, strings.ReplaceAll(bid, ",", `","`), strings.Join(scopeClass, "\",\"")))
+		var should []string
+		for _, v := range scopeClass {
+			should = append(should, fmt.Sprintf(shouldMul1, v))
+		}
+		aggs, _, _ := elastic.GetAggs(INDEX_1, INDEX_1, fmt.Sprintf(es_query, strings.ReplaceAll(bid, ",", `","`), strings.Join(should, ",")))
+		logx.Info("es聚合查询结果:", fmt.Sprintf(es_query, strings.ReplaceAll(bid, ",", `","`), strings.Join(should, ",")))
 		var m1Buckets = AggStruct{}
 		if aggs != nil && aggs["winner_count"] != nil {
 			bs, err := aggs["winner_count"].MarshalJSON()

+ 19 - 20
api/internal/service/plistService.go

@@ -81,13 +81,12 @@ func GetProjectList(req *types.ProjectListReq) (resultList []*ProjectEntry, hasN
 	//if req.SaleStatus == "0" {
 	//	isSqlPage = true // 是否sql分页
 	//}
-
+	countSql, findSql := getQuerySql(req, true, buyerArr, plist)
 	// 缓存
 	rkey := "projectList-" + common.GetMd5String(fmt.Sprintf("%+v", req))
 	if ret, err := redis.GetBytes("newother", rkey); err == nil {
 		err = json.Unmarshal(*ret, &resultList)
 	} else {
-		countSql, findSql := getQuerySql(req, true, buyerArr, plist)
 		logx.Info("findSql: ", findSql)
 		logx.Info("countSql: ", countSql)
 		rows, err := T.ClickhouseConn.Query(context.TODO(), findSql)
@@ -105,26 +104,26 @@ func GetProjectList(req *types.ProjectListReq) (resultList []*ProjectEntry, hasN
 
 	resultList = filterData(req, resultList, nil, mmp, true)
 	//if !isSqlPage {
-	total = len(resultList)
+	//total = len(resultList)
+	//if total > req.PageSize {
+	//	hasNextPage = true
+	//	start := (req.PageNum - 1) * req.PageSize
+	//	end := req.PageNum * req.PageSize
+	//	if end > total {
+	//		end = total
+	//		hasNextPage = false
+	//	}
+	//	resultList = resultList[start:end]
+	//} else {
+	//	hasNextPage = false
+	//}
+	//} else {
+	total = int(T.NetworkCom.Count(countSql))
 	if total > req.PageSize {
 		hasNextPage = true
-		start := (req.PageNum - 1) * req.PageSize
-		end := req.PageNum * req.PageSize
-		if end > total {
-			end = total
-			hasNextPage = false
-		}
-		resultList = resultList[start:end]
 	} else {
 		hasNextPage = false
 	}
-	//} else {
-	//	total = int(T.NetworkCom.Count(countSql))
-	//	if total > req.PageSize {
-	//		hasNextPage = true
-	//	} else {
-	//		hasNextPage = false
-	//	}
 	//}
 	moreInfo(req, plist, resultList) //  补充信息
 
@@ -378,9 +377,9 @@ func moreInfo(req *types.ProjectListReq, plist []string, list []*ProjectEntry) (
 			}
 		}
 		// 补充跳转链接
-		if m.BusinessType == "采购意向" || m.BusinessType == "招标项目" {
-			m.Href = fmt.Sprintf("/article/content/%s.html", encrypt.CommonEncodeArticle("content", m.ProjectId))
-		}
+		//if m.BusinessType == "采购意向" || m.BusinessType == "招标项目" {
+		m.Href = fmt.Sprintf("/article/content/%s.html", encrypt.CommonEncodeArticle("content", m.InfoId))
+		//}
 		m.ProjectId = util.EncodeId(m.ProjectId)
 		// 人脉、人脉所在单位项目 conn_type: 1 人脉可转介绍项目; conn_type: 2 人脉所在单位项目
 		if !m.MyConn {