Jianghan 1 gadu atpakaļ
vecāks
revīzija
2d85cd37a6

+ 8 - 2
api/application.api

@@ -195,7 +195,7 @@ type (
 		pageNum      int64  `json:"pageNum"`
 		pageSize     int64  `json:"pageSize"`
 		businessType string `json:"businessType"`
-		saleStatus   string `json:"saleStatus"`
+		saleStatus   int    `json:"saleStatus"`
 		projectName  string `json:"projectName"`
 		startTime    int64  `json:"startTime"`
 		entTime      int64  `json:"entTime"`
@@ -210,7 +210,13 @@ type (
 		ProjectName string `json:"projectName"`
 	}
 	CoopHistoryReq {
-		Pid string `json:"porjectId"`
+		EntAccountId int64  `header:"entAccountId,optional"` //企业账户id
+		PositionId   int64  `header:"positionId,optional"`
+		EntId        string `header:"entId,optional"`
+		EntUserId    string `header:"entUserId,optional"`
+		DeptId       string `header:"deptId,optional"` //部门id
+		Pid          string `json:"porjectId"`
+		ChannelType  int    `json:"channelType"`
 	}
 )
 

+ 11 - 0
api/internal/logic/coophistorylistlogic.go

@@ -1,6 +1,7 @@
 package logic
 
 import (
+	"bp.jydev.jianyu360.cn/CRM/application/api/internal/service"
 	"context"
 
 	"bp.jydev.jianyu360.cn/CRM/application/api/internal/svc"
@@ -24,6 +25,16 @@ func NewCoopHistoryListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *C
 }
 
 func (l *CoopHistoryListLogic) CoopHistoryList(req *types.CoopHistoryReq) (resp *types.Reply, err error) {
+	resp = &types.Reply{}
+	result := service.GetPrList(req)
+	if result == nil {
+		resp.Error_code = -1
+		resp.Error_msg = "未查询到项目信息"
+	} else {
+		resp.Data = map[string]interface{}{
+			"list": result,
+		}
+	}
 
 	return
 }

+ 219 - 0
api/internal/service/CoopHistoryService.go

@@ -0,0 +1,219 @@
+package service
+
+import (
+	"app.yhyue.com/moapp/jybase/common"
+	elastic "app.yhyue.com/moapp/jybase/es"
+	T "bp.jydev.jianyu360.cn/CRM/application/api/common"
+	"bp.jydev.jianyu360.cn/CRM/application/api/internal/types"
+	"context"
+	"encoding/json"
+	"fmt"
+	"github.com/zeromicro/go-zero/core/logx"
+)
+
+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_1  = `SELECT project_id, project_name, zbtime FROM information.transaction_info WHERE buyer_id = ? AND winner winner IN ? ORDER BY zbtime DESC`
+	es_query = `{
+	  "query": {
+		"bool": {
+		  "must": [
+			{
+			  "range": {
+				"zbtime": {
+				  "gte": 123
+				}
+			  }
+			},
+			{
+			  "term": {
+				"buyer_id": "123"
+			  }
+			}
+		  ],
+		  "must_not": {
+			"term": {
+			  "property_form": "123123"
+			}
+		  }
+		}
+	  },
+	  "aggs": {
+		"winner_count": {
+		  "terms": {
+			"field": "winner",
+			"size": 100,
+			"order": {
+			  "_count": "desc"
+			}
+		  },
+		  "aggs": {
+			"amount_all": {
+			  "sum": {
+				"field": "bidamount"
+			  }
+			}
+		  }
+		},
+		"agency_count": {
+		  "terms": {
+			"field": "agency",
+			"size": 100,
+			"order": {
+			  "_count": "desc"
+			}
+		  },
+		  "aggs": {
+			"amount_all": {
+			  "sum": {
+				"field": "bidamount"
+			  }
+			}
+		  }
+		}
+	  },
+	  "size": 1
+	}`
+)
+
+type ResultData struct {
+	channelType int                      `json:"channel_type"`
+	channel     string                   `json:"channel"`
+	size        int                      `json:"size"`
+	data        []map[string]interface{} `json:"data"`
+}
+
+func GetPrList(req *types.CoopHistoryReq) (result []*ResultData) {
+	pMap := make(map[string]interface{})
+	err := T.ClickhouseConn.QueryRow(context.TODO(), sql_2_0, req.Pid).Scan(&pMap)
+	if err != nil {
+		return nil
+	}
+	propertyForm := ""
+	m1 := T.CrmMysql.FindOne("config_tenant", map[string]interface{}{"account_id": req.EntAccountId}, "probusfor", "")
+	if m1 != nil && len(*m1) > 0 {
+		propertyForm = common.ObjToString((*m1)["probusfor"])
+	}
+
+	// 1、同甲异业数据/招标代理机构渠道
+	if propertyForm != "" {
+		r1, r2 := getData(propertyForm, common.ObjToString(pMap["buyer_id"]))
+		if len(r1) > 0 {
+			tmp := &ResultData{
+				channelType: 1,
+				channel:     "同甲异业渠道",
+				size:        len(r1),
+				data:        r1,
+			}
+			result = append(result, tmp)
+		}
+		if len(r2) > 0 {
+			tmp := &ResultData{
+				channelType: 1,
+				channel:     "招标代理机构",
+				size:        len(r1),
+				data:        r2,
+			}
+			result = append(result, tmp)
+		}
+	}
+	return
+}
+
+func getData(propertyForm, bid string) (result1, result2 []map[string]interface{}) {
+	aggs, count, res := elastic.GetAggs(INDEX_1, INDEX_1, fmt.Sprintf(es_query, 1, propertyForm, bid))
+	logx.Info("es聚合查询结果:", aggs, count, res)
+	type AggStruct struct {
+		Buckets []struct {
+			Key        string `json:"key,omitempty"`
+			Doc_count  int64  `json:"doc_count,omitempty"`
+			Amount_all struct {
+				Value string `json:"value,omitempty"`
+			} `json:"amount_all"`
+		} `json:"buckets"`
+	}
+	m1 := make(map[string]interface{}) //采购单位-中标单位
+	m2 := make(map[string]interface{}) //采购单位-代理机构
+	var m1Buckets = AggStruct{}
+	if aggs != nil && aggs["winner_count"] != nil {
+		bs, err := aggs["winner_count"].MarshalJSON()
+		if err != nil {
+			logx.Info(err)
+		} else {
+			if len(bs) == 0 {
+				logx.Info(err)
+			} else {
+				err := json.Unmarshal(bs, &m1Buckets)
+				logx.Info(err)
+				if len(m1Buckets.Buckets) > 0 {
+					for _, v := range m1Buckets.Buckets {
+						m1[v.Key] = map[string]interface{}{"name": v.Key, "amount": v.Amount_all.Value, "count": v.Doc_count}
+					}
+				}
+			}
+		}
+	}
+	var m2Buckets = AggStruct{}
+	if aggs != nil && aggs["amount_all"] != nil {
+		bs, err := aggs["amount_all"].MarshalJSON()
+		if err != nil {
+			logx.Info(err)
+		} else {
+			if len(bs) == 0 {
+				logx.Info(err)
+			} else {
+				err := json.Unmarshal(bs, &m2Buckets)
+				logx.Info(err)
+				if len(m2Buckets.Buckets) > 0 {
+					for _, v := range m2Buckets.Buckets {
+						m1[v.Key] = map[string]interface{}{"name": v.Key, "amount": v.Amount_all.Value, "count": v.Doc_count}
+					}
+				}
+			}
+		}
+	}
+	for k, v := range m1 {
+		if m2[k] != nil {
+			tmp := make(map[string]interface{})
+			tmp["name"] = v
+			tmp["coop_size"] = v
+			tmp["coop_amount"] = m2[k]
+			result1 = append(result1, tmp)
+		}
+	}
+
+	for k, v := range m2 {
+		if m2[k] != nil {
+			tmp := make(map[string]interface{})
+			tmp["name"] = v
+			tmp["coop_size"] = v
+			tmp["coop_amount"] = m2[k]
+			result2 = append(result2, tmp)
+		}
+	}
+
+	// 合作项目, 业主与中标单位
+	for _, v := range result1 {
+		rows, err := T.ClickhouseConn.Query(context.TODO(), sql_2_1, bid, v["name"])
+		var mlist []map[string]interface{}
+		for err != nil && rows.Next() {
+			m := make(map[string]interface{})
+			rows.Scan(&m)
+			mlist = append(mlist, m)
+		}
+		v["data"] = mlist
+	}
+	// 业主与代理机构
+	for _, v := range result2 {
+		rows, err := T.ClickhouseConn.Query(context.TODO(), sql_2_1, bid, v["name"])
+		var mlist []map[string]interface{}
+		for err != nil && rows.Next() {
+			m := make(map[string]interface{})
+			rows.Scan(&m)
+			mlist = append(mlist, m)
+		}
+		v["data"] = mlist
+	}
+	return
+}

+ 110 - 27
api/internal/service/plistService.go

@@ -14,6 +14,8 @@ const (
 	pageSize = 100
 
 	sql_1 = `SELECT count(1) FROM information.transaction_info WHERE 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 b.company_id, b.company_name, b.contact_name, a.relate_id, a.relate_name FROM connection_introduce a INNER JOIN connection b ON b.position_id =%d ND a.connection_id = b.idAND b.state = 1AND a.type = 1AND b.type = 4AND a.relate_Id = %s`
 )
 
 type ProjectData struct {
@@ -23,24 +25,77 @@ type ProjectData struct {
 }
 
 type ProjectEntry struct {
-	projectName string
+	projectName  string
+	buyer        string
+	buyerId      string
+	sWinner      string
+	area         string
+	city         string
+	district     string
+	startTime    int64
+	entTime      int64
+	subClass     string
+	propertyForm string
+	businessType string
 }
 
-func GetProjectList(req *types.ProjectListReq) (resultList *[]map[string]interface{}, hasNextPage bool, total int) {
+func GetProjectList(req *types.ProjectListReq) (resultList []map[string]interface{}, hasNextPage bool, total int) {
+	preSales := preSalesStatus(req.PositionId)
+	isSqlPage := false
+	if req.SaleStatus == 0 {
+		isSqlPage = true // 是否sql分页
+	}
+	findSql := getQuerySql(req, isSqlPage)
+	rows, err := T.ClickhouseConn.Query(context.TODO(), findSql)
+	defer rows.Close()
+	if err != nil {
+		return nil, false, 0
+	}
+	i := 0
+	info := make(map[string]interface{})
+	for rows.Next() {
+		rows.Scan(&info)
+		resultList = append(resultList, info)
+		i++
+	}
+
+	filterData(req, resultList, preSales, isSqlPage)
+	if !isSqlPage {
+		start := (req.PageNum - 1) * req.PageSize
+		end := start + req.PageSize
+		if req.PageNum > 1 {
+			resultList = resultList[start:end]
+		} else {
+			resultList = resultList[:pageSize]
+		}
+		total = len(resultList)
+		if total > pageSize {
+			hasNextPage = true
+		} else {
+			hasNextPage = false
+		}
+	}
 
-	getSql(req)
+	moreInfo(req, resultList)
 
-	//get(req, resultList)
-	//
-	//total = len(resultList)
-	//if total > pageSize {
-	//	resultList = resultList[:pageSize]
-	//	hasNextPage = true
-	//}
 	return
 }
 
-func getSql(req *types.ProjectListReq) (countSql, findSql string) {
+// @Author jianghan
+// @Description 销售机会线索状态
+// @Date 2024/4/18
+func preSalesStatus(posid int64) (m1 map[string]interface{}) {
+	m1 = make(map[string]interface{})
+	info := T.CrmMysql.SelectBySql(sql_2, posid)
+	if info != nil && len(*info) > 0 {
+		for _, m := range *info {
+			m1[common.ObjToString(m["relate_id"])] = m
+		}
+	}
+	return m1
+}
+
+func getQuerySql(req *types.ProjectListReq, isPage bool) (findSql string) {
 	querys := []string{}
 	//	商机类型
 	if req.BusinessType != "" {
@@ -131,28 +186,51 @@ func getSql(req *types.ProjectListReq) (countSql, findSql string) {
 		querys = append(querys, fmt.Sprintf(" a.property_form in (%s) ", strings.Join(arr, ",")))
 	}
 
-	findSql = "select a.project_id,a.project_name,a.project_budget,a.project_money,a.business_type,a.buyer"
+	findSql = "select a.project_id,a.project_name,a.project_budget,a.project_money,a.business_type,a.buyer from"
+	findSql = fmt.Sprintf("%s from %s  a  where  %s ", findSql, "information.transaction_info", strings.Join(querys, " and "))
+	if isPage {
+		findSql += fmt.Sprintf(" limit %d,%d", (req.PageNum-1)*pageSize, pageSize)
+	}
 	return
 }
 
 // @Author jianghan
-// @Description 处理状态/我的人脉
-// @Date 2024/4/17
-func get(req *types.ProjectListReq, list []map[string]interface{}) (result []map[string]interface{}) {
-	field := "is_handle,is_ignore,is_create"
-	for _, m := range list {
-		query := map[string]interface{}{
-			"position_id": req.PositionId,
-			"relate_id":   common.ObjToString(m["project_id"]),
-			"itype":       2,
-		}
-		info := T.CrmMysql.FindOne("connection_status", query, field, "")
-		if info != nil && len(*info) > 0 {
-			m["is_handle"] = (*info)["is_handle"]
-			m["is_ignore"] = (*info)["is_ignore"]
-			m["is_create"] = (*info)["is_create"]
+// @Description 过滤数据/补充销售机会状态信息,返回分页结果数据
+// @Date 2024/4/18
+func filterData(req *types.ProjectListReq, resultList []map[string]interface{}, preSales map[string]interface{}, isSqlPage bool) {
+	var newList []map[string]interface{}
+	f := ""
+	v := 0
+	if req.SaleStatus == 1 {
+		f = "is_handle"
+		v = 0
+	} else if req.SaleStatus == 2 {
+		f = "is_ignore"
+		v = 0
+	} else if req.SaleStatus == 3 {
+		f = "is_create"
+		v = 1
+	}
+	for _, m := range resultList {
+		if m1, ok := preSales[common.ObjToString(m["project_id"])].(map[string]interface{}); ok {
+			m["is_handle"] = m1["is_handle"]
+			m["is_ignore"] = m1["is_ignore"]
+			m["is_create"] = m1["is_create"]
+			if !isSqlPage && m1[f] == v {
+				newList = append(newList, m)
+			}
 		}
+	}
+	if len(newList) > 0 {
+		resultList = newList
+	}
+}
 
+// @Author jianghan
+// @Description 补充人脉 等信息
+// @Date 2024/4/17
+func moreInfo(req *types.ProjectListReq, list []map[string]interface{}) (result []map[string]interface{}) {
+	for _, m := range list {
 		// 人脉、人脉所在单位项目 conn_type: 1/人脉可转介绍项目 conn_type: 2
 		field1 := ""
 		query1 := map[string]interface{}{
@@ -187,6 +265,11 @@ func get(req *types.ProjectListReq, list []map[string]interface{}) (result []map
 			m["high_success"] = false
 		}
 
+		// 人脉路径
+		// 有我的人脉标签时不需要查询人脉路径信息
+		if m["my_conn"] == false {
+			//ConnectionsHandle([]string{common.ObjToString(m["buyer_id"])}, req.PositionId, false)
+		}
 	}
 
 	return list

+ 8 - 2
api/internal/types/types.go

@@ -34,7 +34,13 @@ type ClueAddReq struct {
 }
 
 type CoopHistoryReq struct {
-	Pid string `json:"porjectId"`
+	EntAccountId int64  `header:"entAccountId,optional"` //企业账户id
+	PositionId   int64  `header:"positionId,optional"`
+	EntId        string `header:"entId,optional"`
+	EntUserId    string `header:"entUserId,optional"`
+	DeptId       string `header:"deptId,optional"` //部门id
+	Pid          string `json:"porjectId"`
+	ChannelType  int    `json:"channelType"`
 }
 
 type CustomAddReq struct {
@@ -161,7 +167,7 @@ type ProjectListReq struct {
 	PageNum      int64  `json:"pageNum"`
 	PageSize     int64  `json:"pageSize"`
 	BusinessType string `json:"businessType"`
-	SaleStatus   string `json:"saleStatus"`
+	SaleStatus   int    `json:"saleStatus"`
 	ProjectName  string `json:"projectName"`
 	StartTime    int64  `json:"startTime"`
 	EntTime      int64  `json:"entTime"`