Jianghan před 1 rokem
rodič
revize
c3d43bb721

+ 15 - 4
api/internal/service/CoopHistoryService.go

@@ -18,13 +18,14 @@ var (
 	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_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": [{"term": {"buyer": "%s"}}],"must_not": {"term": {"property_form": "%s"}}}},"aggs": {"winner_count": {"terms": {"field": "winner","size": 1000,"order": {"_count": "desc"}},"aggs": {"amount_all": {"sum": {"field": "bidamount"}}}}},"size": 1}`
-	es_query1 = `{"query": {"bool": {"must": [{"term": {"buyer": "%s"}}]}},"aggs": {"agency_count": {"terms": {"field": "agency","size": 1000,"order": {"_count": "desc"}},"aggs": {"amount_all": {"sum": {"field": "bidamount"}}}}},"size": 1}`
+	es_query  = `{"query": {"bool": {"must": [{"term": {"buyer_id": "%s"}}],"must_not": {"term": {"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"}}}}},"size": 1}`
+	es_query1 = `{"query": {"bool": {"must": [{"term": {"buyer_id": "%s"}}]}},"aggs": {"agency_count": {"terms": {"field": "agency","size": 1000,"order": {"_count": "desc"}},"aggs": {"amount_all": {"sum": {"field": "project_money"}},"ent_id": {"terms": {"field": "agency_id"}}}}},"size": 1}`
 )
 
 type ResultData struct {
 	SourceType   string  `json:"SourceType"`
 	EntName      string  `json:"EntName"`
+	EntId        string  `json:"EntId"`
 	EntPerson    string  `json:"EntPerson"`
 	Middleman    string  `json:"Middleman"`
 	ProjectNum   int     `json:"ProjectNum"`
@@ -104,6 +105,7 @@ func GetPrList(req *types.CoopHistoryReq) (result []*ResultData, size_1, size_2,
 					tmp := ResultData{
 						SourceType:   "middleman",
 						EntName:      common.ObjToString(m["b_name"]),
+						EntId:        common.ObjToString(m["b_id"]),
 						EntPerson:    common.ObjToString(m["personName"]),
 						Relationship: "业主的关系人",
 						BuyerId:      pTmp.BuyerId,
@@ -122,6 +124,7 @@ func GetPrList(req *types.CoopHistoryReq) (result []*ResultData, size_1, size_2,
 					tmp := ResultData{
 						SourceType:   "sup_sub",
 						EntName:      common.ObjToString(m["b_name"]),
+						EntId:        common.ObjToString(m["b_id"]),
 						EntPerson:    common.ObjToString(m["personName"]),
 						Relationship: common.ObjToString(m["relationship"]),
 						BuyerId:      pTmp.BuyerId,
@@ -143,13 +146,19 @@ func GetData(propertyForm, bid string) (result1, result2 []map[string]interface{
 			Amount_all struct {
 				Value float64 `json:"value,omitempty"`
 			} `json:"amount_all"`
+			EntId struct {
+				Buckets []struct {
+					Key       string `json:"key,omitempty"`
+					Doc_count int64  `json:"doc_count,omitempty"`
+				} `json:"buckets"`
+			} `json:"ent_id"`
 		} `json:"buckets"`
 	}
 	m1 := make(map[string]interface{}) //采购单位-中标单位
 	m2 := make(map[string]interface{}) //采购单位-代理机构
 	if propertyForm != "" {
 		//同甲异态 中标企业
-		aggs, count, res := elastic.GetAggs("bidding", "bidding", fmt.Sprintf(es_query, propertyForm, "中国计量大学"))
+		aggs, count, res := elastic.GetAggs(INDEX_1, INDEX_1, fmt.Sprintf(es_query, bid, propertyForm))
 		logx.Info("es聚合查询结果:", aggs, count, res)
 		var m1Buckets = AggStruct{}
 		if aggs != nil && aggs["winner_count"] != nil {
@@ -164,7 +173,9 @@ func GetData(propertyForm, bid string) (result1, result2 []map[string]interface{
 					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}
+							if v.Key != "" {
+								m1[v.Key] = map[string]interface{}{"name": v.Key, "amount": v.Amount_all.Value, "count": v.Doc_count}
+							}
 						}
 					}
 				}

+ 41 - 34
api/internal/service/plistService.go

@@ -2,6 +2,7 @@ package service
 
 import (
 	"app.yhyue.com/moapp/jybase/common"
+	"app.yhyue.com/moapp/jybase/encrypt"
 	"app.yhyue.com/moapp/jypkg/ent/util"
 	T "bp.jydev.jianyu360.cn/CRM/application/api/common"
 	"bp.jydev.jianyu360.cn/CRM/application/api/internal/types"
@@ -25,42 +26,43 @@ 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"`
-	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"`
-	InfoId       string          `ch:"info_id"`
-	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          int             `json:"Num"`
-	FocusId      string          `json:"FocusId"`
+	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"`
+	InfoId        string          `ch:"info_id"`
+	InformationId string          `ch:"information_id"`
+	InfoIds       string          `ch:"info_ids"`
+	Href          string          `json:"Href"`
+	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           int             `json:"Num"`
+	FocusId       string          `json:"FocusId"`
 }
 
 func GetProjectList(req *types.ProjectListReq) (resultList []*ProjectEntry, hasNextPage bool, total int) {
-
 	buyerM := BuyerList(req.PartyA, req.Supplier, req.Heterotophy, req.Intermediary, req.Agency, req.PositionId)
 	mmp := MonitorStatus(req.UserId) // 项目监控
 	buyerArr := make([]string, len(*buyerM))
 	for b := range *buyerM {
 		buyerArr = append(buyerArr, b)
 	}
-
 	preSales := preSalesStatus(req.PositionId)
 	isSqlPage := false
 	if req.SaleStatus == "0" {
@@ -76,7 +78,7 @@ func GetProjectList(req *types.ProjectListReq) (resultList []*ProjectEntry, hasN
 		project := ProjectEntry{}
 		_ = rows.ScanStruct(&project)
 		//project.ProjectId = encrypt.CommonEncodeArticle("content", project.ProjectId)
-		project.ProjectId = util.EncodeId(project.ProjectId)
+		//project.ProjectId = util.EncodeId(project.ProjectId)
 		resultList = append(resultList, &project)
 	}
 
@@ -172,9 +174,9 @@ func getQuerySql(req *types.ProjectListReq, isPage bool, buyerArr []string) (cou
 	if req.SubClass != "" {
 		arr := []string{}
 		for _, v := range strings.Split(req.SubClass, ",") {
-			arr = append(arr, fmt.Sprintf("'%s'", v))
+			arr = append(arr, fmt.Sprintf("has(a.subclass, '%s')", v))
 		}
-		querys = append(querys, fmt.Sprintf(" a.subclass in (%s) ", strings.Join(regionArr, ",")))
+		querys = append(querys, arr...)
 	}
 	// 项目金额
 	if req.Amount != "" && strings.Contains(req.Amount, "-") {
@@ -192,12 +194,12 @@ func getQuerySql(req *types.ProjectListReq, isPage bool, buyerArr []string) (cou
 	//物业业态
 	if req.PropertyForm != "" {
 		arr := []string{}
-		for _, v := range strings.Split(req.PropertyForm, ",") {
-			arr = append(arr, fmt.Sprintf("'%s'", v))
+		for _, v := range strings.Split(req.SubClass, ",") {
+			arr = append(arr, fmt.Sprintf("has(a.property_form, '%s')", v))
 		}
-		querys = append(querys, fmt.Sprintf(" a.property_form in (%s) ", strings.Join(arr, ",")))
+		querys = append(querys, arr...)
 	}
-	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, a.info_id "
+	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, a.info_id, a.information_id, a.info_ids "
 	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 order by zbtime", findSql, "information.transaction_info", strings.Join(querys, " and "))
@@ -294,6 +296,11 @@ func moreInfo(req *types.ProjectListReq, list []*ProjectEntry) (result []*Projec
 		}
 	}
 	for _, m := range list {
+		// 补充跳转链接
+		if m.BusinessType == "采购意向" || m.BusinessType == "招标项目" {
+			m.Href = fmt.Sprintf("/article/content/%s.html", encrypt.CommonEncodeArticle("content", m.ProjectId))
+		}
+		m.ProjectId = util.EncodeId(m.ProjectId)
 		// 人脉、人脉所在单位项目 conn_type: 1 人脉可转介绍项目; conn_type: 2 人脉所在单位项目
 		if connMap[m.BuyerId] == 1 {
 			m.MyConn = true // 我的人脉