Jianghan 1 year ago
parent
commit
21176fe952
1 changed files with 63 additions and 39 deletions
  1. 63 39
      api/internal/service/plistService.go

+ 63 - 39
api/internal/service/plistService.go

@@ -3,6 +3,7 @@ package service
 import (
 	"context"
 	"fmt"
+	"github.com/shopspring/decimal"
 	"strings"
 
 	"app.yhyue.com/moapp/jybase/common"
@@ -12,8 +13,9 @@ import (
 )
 
 const (
-	sql_1 = `SELECT count(1) FROM information.transaction_info WHERE buyer_id = ?`
+	sql_1 = `SELECT buyer_id, count(1) as count FROM information.transaction_info WHERE buyer_id in (?) GROUP BY buyer_id`
 	sql_2 = `SELECT relate_id, is_handle, is_ignore, is_create FROM crm.connection_status WHERE position_id = ? AND itype = 2`
+	sql_3 = `SELECT * FROM crm.connection WHERE company_id in (?) AND status = 1`
 )
 
 type ProjectData struct {
@@ -23,25 +25,29 @@ type ProjectData struct {
 }
 
 type ProjectEntry struct {
-	ProjectId    string                 `ch:"project_id"`
-	ProjectName  string                 `ch:"project_name"`
-	BusinessType string                 `ch:"business_type"`
-	Buyer        string                 `ch:"buyer"`
-	BuyerId      string                 `ch:"buyer_id"`
-	Winner       []string               `ch:"winner"`
-	WinnerId     []string               `ch:"winner_id"`
-	Area         string                 `ch:"area"`
-	City         string                 `ch:"city"`
-	District     string                 `ch:"district"`
-	ZbTime       int64                  `ch:"zbtime"`
-	EndTime      int64                  `ch:"endtime"`
-	IsHandle     int                    `json:"IsHandle"`
-	IsIgnore     int                    `json:"IsIgnore"`
-	IsCreate     int                    `json:"IsCreate"`
-	MyConn       bool                   `json:"MyConn"`
-	ConnType     int                    `json:"ConnType"`
-	HighSuccess  bool                   `json:"HighSuccess"`
-	NwRoute      map[string]interface{} `json:"NwRoute"`
+	ProjectId    string          `ch:"project_id"`
+	ProjectName  string          `ch:"project_name"`
+	BusinessType string          `ch:"business_type"`
+	Buyer        string          `ch:"buyer"`
+	BuyerId      string          `ch:"buyer_id"`
+	Area         string          `ch:"area"`
+	City         string          `ch:"city"`
+	District     string          `ch:"district"`
+	ZbTime       int64           `ch:"zbtime"`
+	EndTime      int64           `ch:"endtime"`
+	ProjectMoney decimal.Decimal `ch:"project_money"`
+	IsHandle     int             `json:"IsHandle"`
+	IsIgnore     int             `json:"IsIgnore"`
+	IsCreate     int             `json:"IsCreate"`
+	MyConn       bool            `json:"MyConn"`
+	ConnType     int             `json:"ConnType"`
+	HighSuccess  bool            `json:"HighSuccess"`
+	BId          string          `json:"BId"`
+	BName        string          `json:"BName"`
+	RelationShip string          `json:"RelationShip"`
+	SourceType   string          `json:"SourceType"` // firstparty:甲方 supplier:供应商 adiffb:同甲异业 middleman:中间人 agency:招标代理机构
+	Person       string          `json:"Person"`
+	Num          string          `json:"Num"`
 }
 
 func GetProjectList(req *types.ProjectListReq) (resultList []*ProjectEntry, hasNextPage bool, total int) {
@@ -201,7 +207,7 @@ func getQuerySql(req *types.ProjectListReq, isPage bool, buyerArr []string) (cou
 		}
 		querys = append(querys, fmt.Sprintf(" a.property_form in (%s) ", strings.Join(arr, ",")))
 	}
-	findSql = "select a.project_id, a.project_name, a.business_type, a.buyer, a.buyer_id, a.winner, a.winner_id, a.area, a.city, a.district, a.zbtime, a.endtime "
+	findSql = "select a.project_id, a.project_name, a.business_type, a.buyer, a.buyer_id, a.area, a.city, a.district, a.zbtime, a.endtime, a.project_money "
 	if len(querys) > 0 {
 		countSql = fmt.Sprintf("select count(1) from %s a where %s ", "information.transaction_info", strings.Join(querys, " and "))
 		findSql = fmt.Sprintf("%s from %s  a  where  %s ", findSql, "information.transaction_info", strings.Join(querys, " and "))
@@ -263,36 +269,50 @@ func filterData(req *types.ProjectListReq, resultList []*ProjectEntry, preSales
 // @Description 补充人脉 等信息
 // @Date 2024/4/17
 func moreInfo(req *types.ProjectListReq, list []*ProjectEntry) (result []*ProjectEntry) {
+	var buyerIds []string
 	for _, m := range list {
-		// 人脉、人脉所在单位项目 conn_type: 1 人脉可转介绍项目; conn_type: 2 人脉所在单位项目
-		field1 := ""
-		query1 := map[string]interface{}{
-			"position_id": req.PositionId,
-			"company_id":  m.BuyerId,
-			"status":      1,
+		if m.BuyerId != "" {
+			buyerIds = append(buyerIds, m.BuyerId)
+		}
+	}
+	countMap := make(map[string]int)
+	info1, err := T.ClickhouseConn.Query(context.TODO(), sql_1, strings.Join(buyerIds, ","))
+	if err == nil {
+		for info1.Next() {
+			var buyerId string
+			var count int
+			_ = info1.Scan(&buyerId, &count)
+			countMap[buyerId] = count
+		}
+	}
+	info2 := T.CrmMysql.SelectBySql(sql_3, strings.Join(buyerIds, ","))
+	connMap := make(map[string]int)
+	if info2 != nil && len(*info2) > 0 {
+		for _, m := range *info2 {
+			if req.PositionId == common.Int64All(m["position_id"]) {
+				connMap[common.ObjToString(m["company_id"])] = 1 // 我的人脉
+			} else {
+				connMap[common.ObjToString(m["company_id"])] = 2
+			}
 		}
-		info1 := T.CrmMysql.FindOne("connection", query1, field1, "")
-		if info1 != nil && len(*info1) > 0 {
+	}
+	for _, m := range list {
+		// 人脉、人脉所在单位项目 conn_type: 1 人脉可转介绍项目; conn_type: 2 人脉所在单位项目
+		if connMap[m.BuyerId] == 1 {
 			m.MyConn = true // 我的人脉
 			m.ConnType = 1
 		} else {
 			m.MyConn = false
 		}
 		if m.ConnType == 0 {
-			query2 := map[string]interface{}{
-				"company_id": m.BuyerId,
-			}
-			info2 := T.CrmMysql.FindOne("connection", query2, field1, "")
-			if info2 != nil && len(*info2) > 0 {
+			if connMap[m.BuyerId] != 0 {
 				m.ConnType = 1
 			} else {
 				m.ConnType = 2
 			}
 		}
 		// 转介绍成功率高标签
-		count := 0
-		err := T.ClickhouseConn.QueryRow(context.TODO(), sql_1, m.BuyerId).Scan(&count)
-		if err != nil && count > 2 {
+		if countMap[m.BuyerId] > 2 {
 			m.HighSuccess = true
 		} else {
 			m.HighSuccess = false
@@ -303,10 +323,14 @@ func moreInfo(req *types.ProjectListReq, list []*ProjectEntry) (result []*Projec
 		if m.MyConn == false && m.BuyerId != "" {
 			companyList := ConnectionsHandle([]string{m.BuyerId}, req.PositionId, false)
 			if len(companyList) > 0 {
-				m.NwRoute = companyList[0]
+				m.BId = common.ObjToString(companyList[0]["b_id"])
+				m.BName = common.ObjToString(companyList[0]["b_name"])
+				m.RelationShip = common.ObjToString(companyList[0]["relationship"])
+				m.SourceType = common.ObjToString(companyList[0]["sourceType"])
+				m.Person = common.ObjToString(companyList[0]["person"])
+				m.Num = common.ObjToString(companyList[0]["count"])
 			}
 		}
 	}
-
 	return list
 }