|
@@ -13,78 +13,27 @@ import (
|
|
)
|
|
)
|
|
|
|
|
|
var (
|
|
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 {
|
|
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 {
|
|
type ProjectTmp struct {
|
|
@@ -107,126 +56,139 @@ func GetPrList(req *types.CoopHistoryReq) (result []*ResultData) {
|
|
propertyForm = common.ObjToString((*m1)["probusfor"])
|
|
propertyForm = common.ObjToString((*m1)["probusfor"])
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ // firstparty:甲方 supplier:供应商 adiffb:同甲异业 middleman:中间人 agency:招标代理机构 sup_sub: 上下级
|
|
// 1、同甲异业数据/招标代理机构渠道
|
|
// 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
|
|
return
|
|
}
|
|
}
|
|
|
|
|
|
func GetData(propertyForm, bid string) (result1, result2 []map[string]interface{}) {
|
|
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 {
|
|
type AggStruct struct {
|
|
Buckets []struct {
|
|
Buckets []struct {
|
|
Key string `json:"key,omitempty"`
|
|
Key string `json:"key,omitempty"`
|
|
Doc_count int64 `json:"doc_count,omitempty"`
|
|
Doc_count int64 `json:"doc_count,omitempty"`
|
|
Amount_all struct {
|
|
Amount_all struct {
|
|
- Value string `json:"value,omitempty"`
|
|
|
|
|
|
+ Value float64 `json:"value,omitempty"`
|
|
} `json:"amount_all"`
|
|
} `json:"amount_all"`
|
|
} `json:"buckets"`
|
|
} `json:"buckets"`
|
|
}
|
|
}
|
|
m1 := make(map[string]interface{}) //采购单位-中标单位
|
|
m1 := make(map[string]interface{}) //采购单位-中标单位
|
|
m2 := 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)
|
|
logx.Info(err)
|
|
} else {
|
|
} 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{}
|
|
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 {
|
|
if err != nil {
|
|
logx.Info(err)
|
|
logx.Info(err)
|
|
} else {
|
|
} else {
|
|
if len(bs) == 0 {
|
|
if len(bs) == 0 {
|
|
logx.Info(err)
|
|
logx.Info(err)
|
|
} else {
|
|
} else {
|
|
- err := json.Unmarshal(bs, &m2Buckets)
|
|
|
|
|
|
+ err = json.Unmarshal(bs, &m2Buckets)
|
|
logx.Info(err)
|
|
logx.Info(err)
|
|
if len(m2Buckets.Buckets) > 0 {
|
|
if len(m2Buckets.Buckets) > 0 {
|
|
for _, v := range m2Buckets.Buckets {
|
|
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 {
|
|
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
|
|
return
|
|
}
|
|
}
|
|
@@ -275,3 +237,23 @@ func GetData3(buyerId, winnerId string) (result []*P_History) {
|
|
}
|
|
}
|
|
return
|
|
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
|
|
|
|
+}
|