|
@@ -23,8 +23,8 @@ var (
|
|
sql_2_1_1 = `SELECT project_id, project_name, zbtime FROM information.transaction_info WHERE buyer_id = ? AND agency = ? ORDER BY zbtime DESC`
|
|
sql_2_1_1 = `SELECT project_id, project_name, zbtime FROM information.transaction_info WHERE buyer_id = ? AND agency = ? 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_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')`
|
|
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_id": "%s"}},{"exists": {"field": "winner_id"}}],"must_not": {"terms": {"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"}}],"must_not": [{"term": {"agency_id": {"value": ""}}}]}},"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}`
|
|
|
|
|
|
+ es_query = `{"query": {"bool": {"must": [{"terms": {"buyer_id": ["%s"]}},{"exists": {"field": "winner_id"}}],"must_not": {"terms": {"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"}},"buyer_id": {"terms": {"field": "buyer_id"}}}}},"size": 1}`
|
|
|
|
+ es_query1 = `{"query": {"bool": {"must": [{"terms": {"buyer_id": ["%s"]}}],"must_not": [{"term": {"agency_id": {"value": ""}}}]}},"aggs": {"agency_count": {"terms": {"field": "agency","size": 1000,"order": {"_count": "desc"}},"aggs": {"amount_all": {"sum": {"field": "project_money"}},"ent_id": {"terms": {"field": "agency_id"}},"buyer_id": {"terms": {"field": "buyer_id"}}}}},"size": 1}`
|
|
)
|
|
)
|
|
|
|
|
|
type ResultData struct {
|
|
type ResultData struct {
|
|
@@ -102,7 +102,9 @@ func GetPrList(req *types.CoopHistoryReq) (result []*ResultData, size_1, size_2,
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- r1, r2 := GetData(propertyForm, pTmp.BuyerId)
|
|
|
|
|
|
+ rs1, rs2 := GetData(propertyForm, pTmp.BuyerId)
|
|
|
|
+ r1 := rs1[pTmp.BuyerId]
|
|
|
|
+ r2 := rs2[pTmp.BuyerId]
|
|
if r1 != nil && len(r1) > 0 {
|
|
if r1 != nil && len(r1) > 0 {
|
|
size_1 = int64(len(r1))
|
|
size_1 = int64(len(r1))
|
|
if req.ChannelType == "0" || req.ChannelType == "1" {
|
|
if req.ChannelType == "0" || req.ChannelType == "1" {
|
|
@@ -143,7 +145,8 @@ func GetPrList(req *types.CoopHistoryReq) (result []*ResultData, size_1, size_2,
|
|
return
|
|
return
|
|
}
|
|
}
|
|
|
|
|
|
-func GetData(propertyForm []string, bid string) (result1, result2 []map[string]interface{}) {
|
|
|
|
|
|
+func GetData(propertyForm []string, bid string) (result1, result2 map[string][]map[string]interface{}) {
|
|
|
|
+ result1, result2 = map[string][]map[string]interface{}{}, map[string][]map[string]interface{}{}
|
|
type AggStruct struct {
|
|
type AggStruct struct {
|
|
Buckets []struct {
|
|
Buckets []struct {
|
|
Key string `json:"key,omitempty"`
|
|
Key string `json:"key,omitempty"`
|
|
@@ -157,14 +160,21 @@ func GetData(propertyForm []string, bid string) (result1, result2 []map[string]i
|
|
Doc_count int64 `json:"doc_count,omitempty"`
|
|
Doc_count int64 `json:"doc_count,omitempty"`
|
|
} `json:"buckets"`
|
|
} `json:"buckets"`
|
|
} `json:"ent_id"`
|
|
} `json:"ent_id"`
|
|
|
|
+ BuyerId struct {
|
|
|
|
+ Buckets []struct {
|
|
|
|
+ Key string `json:"key,omitempty"`
|
|
|
|
+ Doc_count int64 `json:"doc_count,omitempty"`
|
|
|
|
+ } `json:"buckets"`
|
|
|
|
+ } `json:"buyer_id"`
|
|
} `json:"buckets"`
|
|
} `json:"buckets"`
|
|
}
|
|
}
|
|
m1 := make(map[string]interface{}) //采购单位-中标单位
|
|
m1 := make(map[string]interface{}) //采购单位-中标单位
|
|
m2 := make(map[string]interface{}) //采购单位-代理机构
|
|
m2 := make(map[string]interface{}) //采购单位-代理机构
|
|
|
|
+ noIds := []string{}
|
|
if len(propertyForm) > 0 {
|
|
if len(propertyForm) > 0 {
|
|
//同甲异态 中标企业
|
|
//同甲异态 中标企业
|
|
- aggs, _, _ := elastic.GetAggs(INDEX_1, INDEX_1, fmt.Sprintf(es_query, bid, strings.Join(propertyForm, "\",\"")))
|
|
|
|
- logx.Info("es聚合查询结果:", fmt.Sprintf(es_query, bid, strings.Join(propertyForm, "\",\"")))
|
|
|
|
|
|
+ aggs, _, _ := elastic.GetAggs(INDEX_1, INDEX_1, fmt.Sprintf(es_query, strings.ReplaceAll(bid, ",", `","`), strings.Join(propertyForm, "\",\"")))
|
|
|
|
+ logx.Info("es聚合查询结果:", fmt.Sprintf(es_query, strings.ReplaceAll(bid, ",", `","`), strings.Join(propertyForm, "\",\"")))
|
|
var m1Buckets = AggStruct{}
|
|
var m1Buckets = AggStruct{}
|
|
if aggs != nil && aggs["winner_count"] != nil {
|
|
if aggs != nil && aggs["winner_count"] != nil {
|
|
bs, err := aggs["winner_count"].MarshalJSON()
|
|
bs, err := aggs["winner_count"].MarshalJSON()
|
|
@@ -178,26 +188,23 @@ func GetData(propertyForm []string, bid string) (result1, result2 []map[string]i
|
|
logx.Info(err)
|
|
logx.Info(err)
|
|
if len(m1Buckets.Buckets) > 0 {
|
|
if len(m1Buckets.Buckets) > 0 {
|
|
for _, v := range m1Buckets.Buckets {
|
|
for _, v := range m1Buckets.Buckets {
|
|
- if v.Key != "" {
|
|
|
|
- m1[v.Key] = map[string]interface{}{"name": v.Key, "amount": v.Amount_all.Value, "count": v.Doc_count, "nameId": v.EntId.Buckets[0].Key}
|
|
|
|
|
|
+ if v.Key != "" && len(v.EntId.Buckets) > 0 && len(v.BuyerId.Buckets) > 0 {
|
|
|
|
+ mv := map[string]interface{}{"name": v.Key, "amount": v.Amount_all.Value, "count": v.Doc_count, "buyerId": v.BuyerId.Buckets[0].Key}
|
|
|
|
+ if len(v.EntId.Buckets) == 1 && v.EntId.Buckets[0].Key != "" {
|
|
|
|
+ mv["nameId"] = v.EntId.Buckets[0].Key
|
|
|
|
+ } else {
|
|
|
|
+ noIds = append(noIds, v.Key)
|
|
|
|
+ }
|
|
|
|
+ m1[v.Key] = mv
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- for k, v := range m1 {
|
|
|
|
- v1 := v.(map[string]interface{})
|
|
|
|
- tmp := make(map[string]interface{})
|
|
|
|
- tmp["name"] = k
|
|
|
|
- tmp["nameId"] = v1["nameId"]
|
|
|
|
- tmp["coop_size"] = v1["count"]
|
|
|
|
- tmp["coop_amount"] = v1["amount"]
|
|
|
|
- result1 = append(result1, tmp)
|
|
|
|
- }
|
|
|
|
}
|
|
}
|
|
//代理机构
|
|
//代理机构
|
|
- aggs1, _, _ := elastic.GetAggs(INDEX_1, INDEX_1, fmt.Sprintf(es_query1, bid))
|
|
|
|
|
|
+ aggs1, _, _ := elastic.GetAggs(INDEX_1, INDEX_1, fmt.Sprintf(es_query1, strings.ReplaceAll(bid, ",", `","`)))
|
|
var m2Buckets = AggStruct{}
|
|
var m2Buckets = AggStruct{}
|
|
if aggs1 != nil && aggs1["agency_count"] != nil {
|
|
if aggs1 != nil && aggs1["agency_count"] != nil {
|
|
bs, err := aggs1["agency_count"].MarshalJSON()
|
|
bs, err := aggs1["agency_count"].MarshalJSON()
|
|
@@ -211,22 +218,45 @@ func GetData(propertyForm []string, bid string) (result1, result2 []map[string]i
|
|
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 {
|
|
- if v.Key != "" {
|
|
|
|
- m2[v.Key] = map[string]interface{}{"name": v.Key, "amount": v.Amount_all.Value, "count": v.Doc_count, "nameId": v.EntId.Buckets[0].Key}
|
|
|
|
|
|
+ if v.Key != "" && len(v.EntId.Buckets) > 0 && len(v.BuyerId.Buckets) > 0 {
|
|
|
|
+ if v.EntId.Buckets[0].Key == "" {
|
|
|
|
+ noIds = append(noIds, v.Key)
|
|
|
|
+ }
|
|
|
|
+ m2[v.Key] = map[string]interface{}{"name": v.Key, "amount": v.Amount_all.Value, "count": v.Doc_count, "nameId": v.EntId.Buckets[0].Key, "buyerId": v.BuyerId.Buckets[0].Key}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+ idName := T.NetworkCom.GetEntIdByName(noIds)
|
|
|
|
+ for k, v := range m1 {
|
|
|
|
+ v1 := v.(map[string]interface{})
|
|
|
|
+ tmp := make(map[string]interface{})
|
|
|
|
+ tmp["name"] = k
|
|
|
|
+ nameId, _ := v1["nameId"].(string)
|
|
|
|
+ if nameId == "" {
|
|
|
|
+ nameId = idName[k]
|
|
|
|
+ }
|
|
|
|
+ tmp["nameId"] = nameId
|
|
|
|
+ tmp["coop_size"] = v1["count"]
|
|
|
|
+ tmp["coop_amount"] = v1["amount"]
|
|
|
|
+ buyerId, _ := v1["buyerId"].(string)
|
|
|
|
+ result1[buyerId] = append(result1[buyerId], tmp)
|
|
|
|
+ }
|
|
for k, v := range m2 {
|
|
for k, v := range m2 {
|
|
v1 := v.(map[string]interface{})
|
|
v1 := v.(map[string]interface{})
|
|
tmp := make(map[string]interface{})
|
|
tmp := make(map[string]interface{})
|
|
tmp["name"] = k
|
|
tmp["name"] = k
|
|
- tmp["nameId"] = v1["nameId"]
|
|
|
|
|
|
+ nameId, _ := v1["nameId"].(string)
|
|
|
|
+ if nameId == "" {
|
|
|
|
+ nameId = idName[k]
|
|
|
|
+ }
|
|
|
|
+ tmp["nameId"] = nameId
|
|
tmp["coop_size"] = v1["count"]
|
|
tmp["coop_size"] = v1["count"]
|
|
tmp["coop_amount"] = v1["amount"]
|
|
tmp["coop_amount"] = v1["amount"]
|
|
- result2 = append(result2, tmp)
|
|
|
|
|
|
+ buyerId, _ := v1["buyerId"].(string)
|
|
|
|
+ result2[buyerId] = append(result2[buyerId], tmp)
|
|
}
|
|
}
|
|
return
|
|
return
|
|
}
|
|
}
|