Jianghan 1 жил өмнө
parent
commit
163b58df89

+ 2 - 2
api/application.api

@@ -234,8 +234,8 @@ type (
 		EntId        string `header:"entId,optional"`
 		EntUserId    string `header:"entUserId,optional"`
 		DeptId       string `header:"deptId,optional"` //部门id
-		Pid          string `json:"porjectId"`
-		ChannelType  int    `json:"channelType"`
+		Pid          string `json:"projectId"`
+		ChannelType  string `json:"channelType"`
 	}
 	AddOrUpdateReq {
 		PositionId             int64  `header:"positionId"`

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

@@ -3,6 +3,7 @@ package logic
 import (
 	"bp.jydev.jianyu360.cn/CRM/application/api/internal/service"
 	"context"
+	"log"
 
 	"bp.jydev.jianyu360.cn/CRM/application/api/internal/svc"
 	"bp.jydev.jianyu360.cn/CRM/application/api/internal/types"
@@ -27,6 +28,7 @@ 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)
+	log.Println(result)
 	if result == nil {
 		resp.Error_code = -1
 		resp.Error_msg = "查询异常"

+ 6 - 1
api/internal/logic/infodetaillogic.go

@@ -2,8 +2,10 @@ package logic
 
 import (
 	"app.yhyue.com/moapp/jybase/common"
+	"app.yhyue.com/moapp/jybase/encrypt"
 	T "bp.jydev.jianyu360.cn/CRM/application/api/common"
 	"context"
+	"fmt"
 
 	"bp.jydev.jianyu360.cn/CRM/application/api/internal/svc"
 	"bp.jydev.jianyu360.cn/CRM/application/api/internal/types"
@@ -33,7 +35,8 @@ type Infomation struct {
 	Area        string `ch:"area"`
 	City        string `ch:"city"`
 	DataJsonId  string `ch:"datajson_id"`
-	ProjectName string `ch:"project_name"`
+	ProjectName string `json:"project_name"`
+	Href        string `json:"href"`
 }
 
 func (l *InfoDetailLogic) InfoDetail(req *types.InfoDetailReq) (resp *types.Reply, err error) {
@@ -42,9 +45,11 @@ func (l *InfoDetailLogic) InfoDetail(req *types.InfoDetailReq) (resp *types.Repl
 	info := Infomation{}
 	err = T.ClickhouseConn.QueryRow(context.TODO(), sql, req.InfoId).ScanStruct(&info)
 	if err == nil {
+		info.DataJsonId = encrypt.CommonEncodeArticle("content", info.DataJsonId)
 		binfo, b := T.MgoBidding.FindById("bidding", info.DataJsonId, map[string]interface{}{"title": 1, "projectname": 1})
 		if b && binfo != nil && len(*binfo) > 0 {
 			info.ProjectName = common.ObjToString((*binfo)["projectname"])
+			info.Href = fmt.Sprintf("/article/content/%s.html", encrypt.CommonEncodeArticle("content", info.DataJsonId))
 		}
 		resp.Data = info
 	} else {

+ 127 - 145
api/internal/service/CoopHistoryService.go

@@ -13,78 +13,27 @@ 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_1  = `SELECT project_id, project_name, zbtime FROM information.transaction_info WHERE buyer_id = ? AND has(winner_id, ?) ORDER BY zbtime DESC`
-	sql_2_2  = `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 AND a.connection_id = b.id AND b.state = 1 AND a.itype = 1 AND b.itype = 4 AND a.relate_Id = %s`
-	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 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": [
-			{
-			  "range": {
-				"zbtime": {
-				  "gte": %d
-				}
-			  }
-			},
-			{
-			  "term": {
-				"buyer_id": %s
-			  }
-			}
-		  ],
-		  "must_not": {
-			"term": {
-			  "property_form": %s
-			}
-		  }
-		}
-	  },
-	  "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
-	}`
+	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 has(winner_id, ?) 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}`
 )
 
 type ResultData struct {
-	channelType int                      `json:"channel_type"`
-	channel     string                   `json:"channel"`
-	size        int                      `json:"size"`
-	data        []map[string]interface{} `json:"data"`
+	SourceType   string  `json:"SourceType"`
+	EntName      string  `json:"EntName"`
+	EntPerson    string  `json:"EntPerson"`
+	Middleman    string  `json:"Middleman"`
+	ProjectNum   int     `json:"ProjectNum"`
+	TotalAmount  float64 `json:"TotalAmount"`
+	RecentTime   int64   `json:"RecentTime"`
+	NearlyYears  bool    `json:"NearlyYears"`
+	SupEnt       string  `json:"SupEnt"`       // 上级
+	NextEnt      string  `json:"NextEnt"`      // 下级
+	Relationship string  `json:"Relationship"` // 关系
 }
 
 type ProjectTmp struct {
@@ -107,126 +56,139 @@ func GetPrList(req *types.CoopHistoryReq) (result []*ResultData) {
 		propertyForm = common.ObjToString((*m1)["probusfor"])
 	}
 
+	// firstparty:甲方 supplier:供应商 adiffb:同甲异业 middleman:中间人 agency:招标代理机构 sup_sub: 上下级
 	// 1、同甲异业数据/招标代理机构渠道
-	if propertyForm != "" {
-		r1, r2 := GetData(propertyForm, pTmp.BuyerId)
-		if r1 != nil && len(r1) > 0 {
-			tmp := &ResultData{
-				channelType: 1,
-				channel:     "同甲异业渠道",
-				size:        len(r1),
-				data:        r1,
+	r1, r2 := GetData(propertyForm, pTmp.BuyerId)
+	if r1 != nil && len(r1) > 0 {
+		for _, m := range r1 {
+			near, zbtime := LastTimeCoop(pTmp.BuyerId, common.ObjToString(m["name"]), "adiffb")
+			tmp := ResultData{
+				SourceType:  "adiffb",
+				EntName:     common.ObjToString(m["name"]),
+				ProjectNum:  common.IntAll(m["coop_size"]),
+				TotalAmount: common.Float64All(m["coop_amount"]),
+				RecentTime:  zbtime,
+				NearlyYears: near,
 			}
-			result = append(result, tmp)
-		}
-		if r2 != nil && len(r2) > 0 {
-			tmp := &ResultData{
-				channelType: 1,
-				channel:     "招标代理机构",
-				size:        len(r2),
-				data:        r2,
-			}
-			result = append(result, tmp)
+			result = append(result, &tmp)
 		}
 	}
-	// 中间人可介绍业主
-	if pTmp.BuyerId != "" {
-		r3 := GetData1(req.PositionId, pTmp.BuyerId)
-		if r3 != nil && len(r3) > 0 {
-			tmp := &ResultData{
-				channelType: 1,
-				channel:     "中间人",
-				size:        len(r3),
-				data:        r3,
-			}
-			result = append(result, tmp)
-		}
-		// 关联单位
-		r4 := GetData2(pTmp.BuyerId)
-		if r4 != nil && len(r4) > 0 {
-			tmp := &ResultData{
-				channelType: 1,
-				channel:     "业主关联单位",
-				size:        len(r4),
-				data:        r4,
+	if r2 != nil && len(r2) > 0 {
+		for _, m := range r2 {
+			near, zbtime := LastTimeCoop(pTmp.BuyerId, common.ObjToString(m["name"]), "agency")
+			tmp := ResultData{
+				SourceType:  "agency",
+				EntName:     common.ObjToString(m["name"]),
+				ProjectNum:  common.IntAll(m["coop_size"]),
+				TotalAmount: common.Float64All(m["coop_amount"]),
+				RecentTime:  zbtime,
+				NearlyYears: near,
 			}
-			result = append(result, tmp)
+			result = append(result, &tmp)
 		}
 	}
+	// 中间人可介绍业主
+	//if pTmp.BuyerId != "" {
+	//	r3 := GetData1(req.PositionId, pTmp.BuyerId)
+	//	if r3 != nil && len(r3) > 0 {
+	//		tmp := ResultData{
+	//			SourceType:  "middleman",
+	//			EntName:     common.ObjToString(m["name"]),
+	//			ProjectNum:  common.IntAll(m["coop_size"]),
+	//			TotalAmount: common.Float64All(m["coop_amount"]),
+	//			RecentTime:  zbtime,
+	//			NearlyYears: near,
+	//		}
+	//		result = append(result, &tmp)
+	//	}
+	//// 关联单位
+	//r4 := GetData2(pTmp.BuyerId)
+	//if r4 != nil && len(r4) > 0 {
+	//	tmp := &ResultData{
+	//		channelType: 1,
+	//		channel:     "业主关联单位",
+	//		size:        len(r4),
+	//		data:        r4,
+	//	}
+	//	result = append(result, tmp)
+	//}
+	//}
 	return
 }
 
 func GetData(propertyForm, bid string) (result1, result2 []map[string]interface{}) {
-	timestamp := time.Now().AddDate(-3, 0, 0).Unix()
-	aggs, count, res := elastic.GetAggs(INDEX_1, INDEX_1, fmt.Sprintf(es_query, timestamp, 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"`
+				Value float64 `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 {
+	if propertyForm != "" {
+		//同甲异态 中标企业
+		aggs, count, res := elastic.GetAggs("bidding", "bidding", fmt.Sprintf(es_query, propertyForm, "中国计量大学"))
+		logx.Info("es聚合查询结果:", aggs, count, res)
+		var m1Buckets = AggStruct{}
+		if aggs != nil && aggs["winner_count"] != nil {
+			bs, err := aggs["winner_count"].MarshalJSON()
+			if err != nil {
 				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}
+				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}
+						}
 					}
 				}
 			}
 		}
+		for k, v := range m1 {
+			v1 := v.(map[string]interface{})
+			tmp := make(map[string]interface{})
+			tmp["name"] = k
+			tmp["coop_size"] = v1["count"]
+			tmp["coop_amount"] = v1["amount"]
+			result1 = append(result1, tmp)
+		}
 	}
+	//代理机构
+	aggs1, count1, res1 := elastic.GetAggs("bidding", "bidding", fmt.Sprintf(es_query1, "中国计量大学"))
+	logx.Info("es聚合查询结果:", aggs1, count1, res1)
 	var m2Buckets = AggStruct{}
-	if aggs != nil && aggs["amount_all"] != nil {
-		bs, err := aggs["amount_all"].MarshalJSON()
+	if aggs1 != nil && aggs1["agency_count"] != nil {
+		bs, err := aggs1["agency_count"].MarshalJSON()
 		if err != nil {
 			logx.Info(err)
 		} else {
 			if len(bs) == 0 {
 				logx.Info(err)
 			} else {
-				err := json.Unmarshal(bs, &m2Buckets)
+				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}
+						m2[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)
-		}
+		v1 := v.(map[string]interface{})
+		tmp := make(map[string]interface{})
+		tmp["name"] = k
+		tmp["coop_size"] = v1["count"]
+		tmp["coop_amount"] = v1["amount"]
+		result2 = append(result2, tmp)
 	}
 	return
 }
@@ -275,3 +237,23 @@ func GetData3(buyerId, winnerId string) (result []*P_History) {
 	}
 	return
 }
+
+// @Author jianghan
+// @Description 上次合作时间
+// @Date 2024/4/24
+func LastTimeCoop(buyerId, ent, stype string) (bool, int64) {
+	zbtime := int64(0)
+	near := false
+	if stype == "adiffb" {
+		sql := `SELECT zbtime FROM information.transaction_info WHERE buyer_id = ? AND has(winner, ?) ORDER BY zbtime DESC LIMIT 1`
+		_ = T.ClickhouseConn.QueryRow(context.TODO(), sql, buyerId, ent).Scan(&zbtime)
+	} else if stype == "agency" {
+		sql := `SELECT zbtime FROM information.transaction_info WHERE buyer_id = ? AND agency = ? ORDER BY zbtime DESC LIMIT 1`
+		_ = T.ClickhouseConn.QueryRow(context.TODO(), sql, buyerId, ent).Scan(&zbtime)
+	}
+	timestamp := time.Now().AddDate(-3, 0, 0).Unix()
+	if timestamp <= zbtime {
+		near = true
+	}
+	return near, zbtime
+}

+ 38 - 24
api/internal/service/owner.go

@@ -814,42 +814,56 @@ func (t *OwnerService) CandidateChannel() []*ResultData {
 			logx.Info(buyerId)
 			r1, r2 := GetData(propertyForm, buyerId)
 			if r1 != nil && len(r1) > 0 {
-				tmp := &ResultData{
-					channelType: 1,
-					channel:     "同甲异业渠道",
-					size:        len(r1),
-					data:        r1,
+				for _, m := range r1 {
+					near, zbtime := LastTimeCoop(buyerId, common.ObjToString(m["name"]), "adiffb")
+					tmp := ResultData{
+						SourceType:  "adiffb",
+						EntName:     common.ObjToString(m["name"]),
+						ProjectNum:  common.IntAll(m["coop_size"]),
+						TotalAmount: common.Float64All(m["coop_amount"]),
+						RecentTime:  zbtime,
+						NearlyYears: near,
+					}
+					returnData = append(returnData, &tmp)
 				}
-				returnData = append(returnData, tmp)
 			}
 			if r2 != nil && len(r2) > 0 {
-				tmp := &ResultData{
-					channelType: 1,
-					channel:     "招标代理机构",
-					size:        len(r2),
-					data:        r2,
+				for _, m := range r2 {
+					near, zbtime := LastTimeCoop(buyerId, common.ObjToString(m["name"]), "agency")
+					tmp := ResultData{
+						SourceType:  "agency",
+						EntName:     common.ObjToString(m["name"]),
+						ProjectNum:  common.IntAll(m["coop_size"]),
+						TotalAmount: common.Float64All(m["coop_amount"]),
+						RecentTime:  zbtime,
+						NearlyYears: near,
+					}
+					returnData = append(returnData, &tmp)
 				}
-				returnData = append(returnData, tmp)
 			}
 			r3 := GetData1(t.PositionId, buyerId)
 			if r3 != nil && len(r3) > 0 {
-				tmp := &ResultData{
-					channelType: 1,
-					channel:     "中间人",
-					size:        len(r3),
-					data:        r3,
+				for _, m := range r3 {
+					tmp := ResultData{
+						SourceType:  "middleman",
+						EntName:     common.ObjToString(m["name"]),
+						ProjectNum:  common.IntAll(m["coop_size"]),
+						TotalAmount: common.Float64All(m["coop_amount"]),
+					}
+					returnData = append(returnData, &tmp)
 				}
-				returnData = append(returnData, tmp)
 			}
 			r4 := GetData2(buyerId)
 			if r4 != nil && len(r4) > 0 {
-				tmp := &ResultData{
-					channelType: 1,
-					channel:     "业主关联单位",
-					size:        len(r4),
-					data:        r4,
+				for _, m := range r4 {
+					tmp := ResultData{
+						SourceType:  "sup_sub",
+						EntName:     common.ObjToString(m["name"]),
+						ProjectNum:  common.IntAll(m["coop_size"]),
+						TotalAmount: common.Float64All(m["coop_amount"]),
+					}
+					returnData = append(returnData, &tmp)
 				}
-				returnData = append(returnData, tmp)
 			}
 		}
 

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

@@ -80,8 +80,8 @@ type CoopHistoryReq struct {
 	EntId        string `header:"entId,optional"`
 	EntUserId    string `header:"entUserId,optional"`
 	DeptId       string `header:"deptId,optional"` //部门id
-	Pid          string `json:"porjectId"`
-	ChannelType  int    `json:"channelType"`
+	Pid          string `json:"projectId"`
+	ChannelType  string `json:"channelType"`
 }
 
 type CooperateOwnerListReq struct {