|
@@ -9,11 +9,11 @@ import (
|
|
|
|
|
|
"app.yhyue.com/moapp/jybase/common"
|
|
"app.yhyue.com/moapp/jybase/common"
|
|
"app.yhyue.com/moapp/jybase/encrypt"
|
|
"app.yhyue.com/moapp/jybase/encrypt"
|
|
- elastic "app.yhyue.com/moapp/jybase/es"
|
|
|
|
"app.yhyue.com/moapp/jybase/redis"
|
|
"app.yhyue.com/moapp/jybase/redis"
|
|
T "bp.jydev.jianyu360.cn/CRM/networkManage/api/common"
|
|
T "bp.jydev.jianyu360.cn/CRM/networkManage/api/common"
|
|
"bp.jydev.jianyu360.cn/CRM/networkManage/api/internal/types"
|
|
"bp.jydev.jianyu360.cn/CRM/networkManage/api/internal/types"
|
|
"github.com/ClickHouse/clickhouse-go/v2/lib/driver"
|
|
"github.com/ClickHouse/clickhouse-go/v2/lib/driver"
|
|
|
|
+ "github.com/shopspring/decimal"
|
|
"github.com/zeromicro/go-zero/core/logx"
|
|
"github.com/zeromicro/go-zero/core/logx"
|
|
)
|
|
)
|
|
|
|
|
|
@@ -23,10 +23,6 @@ var (
|
|
sql_2_2 = `select id as buyer_id from ent_info where company_name=? order by id desc limit 1`
|
|
sql_2_2 = `select id as buyer_id from ent_info where company_name=? order by id desc limit 1`
|
|
sql_2_1 = `SELECT project_id, project_name, zbtime FROM information.transaction_info_all WHERE buyer_id = ? AND has(winner, ?) ORDER BY zbtime DESC`
|
|
sql_2_1 = `SELECT project_id, project_name, zbtime FROM information.transaction_info_all WHERE buyer_id = ? AND has(winner, ?) ORDER BY zbtime DESC`
|
|
sql_2_1_1 = `SELECT project_id, project_name, zbtime FROM information.transaction_info_all WHERE buyer_id = ? AND agency = ? ORDER BY zbtime DESC`
|
|
sql_2_1_1 = `SELECT project_id, project_name, zbtime FROM information.transaction_info_all 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_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": [{"terms": {"buyer_id": ["%s"]}},{"exists": {"field": "winner_id"}}],"must_not": {"terms": {"topscopeclass": ["%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 {
|
|
@@ -73,25 +69,11 @@ type Cooperate struct {
|
|
}
|
|
}
|
|
|
|
|
|
type AggStruct struct {
|
|
type AggStruct struct {
|
|
- Buckets []struct {
|
|
|
|
- Key string `json:"key,omitempty"`
|
|
|
|
- Doc_count int64 `json:"doc_count,omitempty"`
|
|
|
|
- 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"`
|
|
|
|
- BuyerId struct {
|
|
|
|
- Buckets []struct {
|
|
|
|
- Key string `json:"key,omitempty"`
|
|
|
|
- Doc_count int64 `json:"doc_count,omitempty"`
|
|
|
|
- } `json:"buckets"`
|
|
|
|
- } `json:"buyer_id"`
|
|
|
|
- } `json:"buckets"`
|
|
|
|
|
|
+ Id string `ch:"id"`
|
|
|
|
+ Name string `ch:"name"`
|
|
|
|
+ Sum uint64 `ch:"sum"`
|
|
|
|
+ ProjectMoney decimal.Decimal `ch:"project_money"`
|
|
|
|
+ Zbtime int64 `ch:"zbtime"`
|
|
}
|
|
}
|
|
|
|
|
|
func GetPrList(req *types.CoopHistoryReq) (result []*ResultData, size_1, size_2, size_3, size_4 int64) {
|
|
func GetPrList(req *types.CoopHistoryReq) (result []*ResultData, size_1, size_2, size_3, size_4 int64) {
|
|
@@ -104,217 +86,148 @@ func GetPrList(req *types.CoopHistoryReq) (result []*ResultData, size_1, size_2,
|
|
} else {
|
|
} else {
|
|
return
|
|
return
|
|
}
|
|
}
|
|
- if err != nil {
|
|
|
|
- return nil, 0, 0, 0, 0
|
|
|
|
|
|
+ if err != nil || pTmp.BuyerId == "" {
|
|
|
|
+ return
|
|
}
|
|
}
|
|
- //propertyForm := T.NetworkCom.GetMyProbusfor(req.EntAccountId)
|
|
|
|
- scopeClass := FindBusiness(req.EntId, req.EntUserId)
|
|
|
|
// firstparty:甲方 supplier:供应商 adiffb:同甲异业 middleman:中间人 agency:招标代理机构 sup_sub: 上下级
|
|
// firstparty:甲方 supplier:供应商 adiffb:同甲异业 middleman:中间人 agency:招标代理机构 sup_sub: 上下级
|
|
// 1、同甲异业数据/ 3、招标代理机构渠道
|
|
// 1、同甲异业数据/ 3、招标代理机构渠道
|
|
- if pTmp.BuyerId != "" {
|
|
|
|
- // 中间人可介绍业主
|
|
|
|
|
|
+ // 中间人可介绍业主
|
|
|
|
+ if req.ChannelType == "0" || req.ChannelType == "4" {
|
|
var r3 []map[string]interface{}
|
|
var r3 []map[string]interface{}
|
|
r3 = FindMiddleman([]string{fmt.Sprintf("'%s'", pTmp.BuyerId)}, req.PositionId, r3)
|
|
r3 = FindMiddleman([]string{fmt.Sprintf("'%s'", pTmp.BuyerId)}, req.PositionId, r3)
|
|
- if r3 != nil && len(r3) > 0 {
|
|
|
|
- size_4 = int64(len(r3))
|
|
|
|
- if req.ChannelType == "0" || req.ChannelType == "4" {
|
|
|
|
- for _, m := range r3 {
|
|
|
|
- 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,
|
|
|
|
- }
|
|
|
|
- result = append(result, &tmp)
|
|
|
|
- }
|
|
|
|
|
|
+ size_4 = int64(len(r3))
|
|
|
|
+ for _, m := range r3 {
|
|
|
|
+ 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,
|
|
}
|
|
}
|
|
|
|
+ result = append(result, &tmp)
|
|
}
|
|
}
|
|
- // 关联单位
|
|
|
|
|
|
+ }
|
|
|
|
+ // 关联单位
|
|
|
|
+ if req.ChannelType == "0" || req.ChannelType == "2" {
|
|
var r4 []map[string]interface{}
|
|
var r4 []map[string]interface{}
|
|
r4 = Findfirstparty([]string{fmt.Sprintf("'%s'", pTmp.BuyerId)}, r4)
|
|
r4 = Findfirstparty([]string{fmt.Sprintf("'%s'", pTmp.BuyerId)}, r4)
|
|
- if r4 != nil && len(r4) > 0 {
|
|
|
|
- size_2 = int64(len(r4))
|
|
|
|
- if req.ChannelType == "0" || req.ChannelType == "2" {
|
|
|
|
- for _, m := range r4 {
|
|
|
|
- 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,
|
|
|
|
- }
|
|
|
|
- result = append(result, &tmp)
|
|
|
|
- }
|
|
|
|
|
|
+ size_2 = int64(len(r4))
|
|
|
|
+ for _, m := range r4 {
|
|
|
|
+ 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,
|
|
}
|
|
}
|
|
|
|
+ result = append(result, &tmp)
|
|
}
|
|
}
|
|
- r1 := GetWinnerData(strings.Split(scopeClass, ","), pTmp.BuyerId)
|
|
|
|
- r2 := GetAgencyData(pTmp.BuyerId)
|
|
|
|
- winners, agency := []string{}, []string{}
|
|
|
|
|
|
+ }
|
|
|
|
+ if req.ChannelType == "0" || req.ChannelType == "1" {
|
|
|
|
+ scopeClass := FindBusiness(req.EntId, req.EntUserId)
|
|
|
|
+ r1 := GetWinnerData(scopeClass, pTmp.BuyerId)
|
|
|
|
+ size_1 = int64(len(r1))
|
|
for _, m := range r1 {
|
|
for _, m := range r1 {
|
|
- winners = append(winners, common.ObjToString(m["name"]))
|
|
|
|
|
|
+ tmp := ResultData{
|
|
|
|
+ SourceType: "adiffb",
|
|
|
|
+ EntName: m.Name,
|
|
|
|
+ ProjectNum: int(m.Sum),
|
|
|
|
+ BuyerId: pTmp.BuyerId,
|
|
|
|
+ RecentTime: m.Zbtime,
|
|
|
|
+ }
|
|
|
|
+ tmp.TotalAmount, _ = m.ProjectMoney.Float64()
|
|
|
|
+ if time.Now().AddDate(-3, 0, 0).Unix() <= tmp.RecentTime {
|
|
|
|
+ tmp.NearlyYears = true
|
|
|
|
+ }
|
|
|
|
+ result = append(result, &tmp)
|
|
}
|
|
}
|
|
|
|
+ }
|
|
|
|
+ if req.ChannelType == "0" || req.ChannelType == "3" {
|
|
|
|
+ r2 := GetAgencyData(pTmp.BuyerId)
|
|
|
|
+ size_3 = int64(len(r2))
|
|
for _, m := range r2 {
|
|
for _, m := range r2 {
|
|
- agency = append(agency, common.ObjToString(m["name"]))
|
|
|
|
- }
|
|
|
|
- logx.Info("CandidateChannel LastTimeCoopBath start ", req.PositionId, " ", pTmp.BuyerId, " ", len(winners), " ", len(agency))
|
|
|
|
- ltcs1, ltcs2 := LastTimeCoopBath(req.PositionId, pTmp.BuyerId, winners, agency)
|
|
|
|
- logx.Info("CandidateChannel LastTimeCoopBath over ", req.PositionId)
|
|
|
|
- if r1 != nil && len(r1) > 0 {
|
|
|
|
- size_1 = int64(len(r1))
|
|
|
|
- if req.ChannelType == "0" || req.ChannelType == "1" {
|
|
|
|
- for _, m := range r1 {
|
|
|
|
- tmp := ResultData{
|
|
|
|
- SourceType: "adiffb",
|
|
|
|
- EntName: common.ObjToString(m["name"]),
|
|
|
|
- ProjectNum: common.IntAll(m["coop_size"]),
|
|
|
|
- TotalAmount: common.Float64All(m["coop_amount"]),
|
|
|
|
- BuyerId: pTmp.BuyerId,
|
|
|
|
- }
|
|
|
|
- if ltc := ltcs1[common.ObjToString(m["name"])]; ltc != nil {
|
|
|
|
- tmp.NearlyYears = ltc.Near
|
|
|
|
- tmp.RecentTime = ltc.ZbTime
|
|
|
|
- }
|
|
|
|
- result = append(result, &tmp)
|
|
|
|
- }
|
|
|
|
|
|
+ tmp := ResultData{
|
|
|
|
+ SourceType: "agency",
|
|
|
|
+ EntName: m.Name,
|
|
|
|
+ ProjectNum: int(m.Sum),
|
|
|
|
+ BuyerId: pTmp.BuyerId,
|
|
|
|
+ RecentTime: m.Zbtime,
|
|
}
|
|
}
|
|
- }
|
|
|
|
- if r2 != nil && len(r2) > 0 {
|
|
|
|
- size_3 = int64(len(r2))
|
|
|
|
- if req.ChannelType == "0" || req.ChannelType == "3" {
|
|
|
|
- for _, m := range r2 {
|
|
|
|
- tmp := ResultData{
|
|
|
|
- SourceType: "agency",
|
|
|
|
- EntName: common.ObjToString(m["name"]),
|
|
|
|
- ProjectNum: common.IntAll(m["coop_size"]),
|
|
|
|
- TotalAmount: common.Float64All(m["coop_amount"]),
|
|
|
|
- BuyerId: pTmp.BuyerId,
|
|
|
|
- }
|
|
|
|
- if ltc := ltcs2[common.ObjToString(m["name"])]; ltc != nil {
|
|
|
|
- tmp.NearlyYears = ltc.Near
|
|
|
|
- tmp.RecentTime = ltc.ZbTime
|
|
|
|
- }
|
|
|
|
- result = append(result, &tmp)
|
|
|
|
- }
|
|
|
|
|
|
+ tmp.TotalAmount, _ = m.ProjectMoney.Float64()
|
|
|
|
+ if time.Now().AddDate(-3, 0, 0).Unix() <= tmp.RecentTime {
|
|
|
|
+ tmp.NearlyYears = true
|
|
}
|
|
}
|
|
|
|
+ result = append(result, &tmp)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return
|
|
return
|
|
}
|
|
}
|
|
-func GetWinnerData(scopeClass []string, bid string) (result1 []map[string]interface{}) {
|
|
|
|
- result1 = []map[string]interface{}{}
|
|
|
|
- winnerKey := fmt.Sprintf("networkManage_coopHistory_winner_%s", common.GetMd5String(strings.Join(scopeClass, ",")+"_"+bid))
|
|
|
|
|
|
+func GetWinnerData(scopeClass string, bid string) []AggStruct {
|
|
|
|
+ ass := []AggStruct{}
|
|
|
|
+ if scopeClass == "" {
|
|
|
|
+ return ass
|
|
|
|
+ }
|
|
|
|
+ winnerKey := fmt.Sprintf("networkManage_coopHistory_winner_%s", common.GetMd5String(scopeClass+"_"+bid))
|
|
wb, err := redis.GetBytes("newother", winnerKey)
|
|
wb, err := redis.GetBytes("newother", winnerKey)
|
|
- if err == nil {
|
|
|
|
- json.Unmarshal(*wb, &result1)
|
|
|
|
- return
|
|
|
|
|
|
+ if err == nil && wb != nil {
|
|
|
|
+ json.Unmarshal(*wb, &ass)
|
|
|
|
+ return ass
|
|
}
|
|
}
|
|
- m1 := make(map[string]interface{}) //采购单位-中标单位
|
|
|
|
- noIds := []string{}
|
|
|
|
- if len(scopeClass) > 0 {
|
|
|
|
- //同甲异态 中标企业
|
|
|
|
- aggs, _, _ := elastic.GetAggs(INDEX_1, INDEX_1, fmt.Sprintf(es_query, strings.ReplaceAll(bid, ",", `","`), strings.Join(scopeClass, "\",\"")))
|
|
|
|
- logx.Info("es聚合查询结果:", fmt.Sprintf(es_query, strings.ReplaceAll(bid, ",", `","`), strings.Join(scopeClass, "\",\"")))
|
|
|
|
- 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 {
|
|
|
|
- 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
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
|
|
+ args := []interface{}{bid, bid}
|
|
|
|
+ wh, newArgs := common.WhArgs(strings.Split(scopeClass, ","))
|
|
|
|
+ args = append(args, newArgs...)
|
|
|
|
+ rows, err1 := T.ClickhouseConn.Query(context.TODO(), `select winner as name,winner_id as id,sum(1) as sum,sum(project_money) as project_money,max(zbtime) as zbtime from information.transaction_info_all ARRAY JOIN winner_id,winner
|
|
|
|
+ WHERE buyer_id IN (SELECT buyer_id from information.transaction_info_all WHERE has(winner_id,?) and buyer_id<>'') and winner_id<>? AND hasAny(topscopeclass,[`+wh+`])=0 group by winner,winner_id`, args...)
|
|
|
|
+ if err1 != nil {
|
|
|
|
+ logx.Error(err1)
|
|
|
|
+ return ass
|
|
}
|
|
}
|
|
- 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]
|
|
|
|
|
|
+ for rows.Next() {
|
|
|
|
+ as := AggStruct{}
|
|
|
|
+ if err := rows.ScanStruct(&as); err != nil {
|
|
|
|
+ logx.Error(err)
|
|
|
|
+ continue
|
|
}
|
|
}
|
|
- tmp["nameId"] = nameId
|
|
|
|
- tmp["coop_size"] = v1["count"]
|
|
|
|
- tmp["coop_amount"] = v1["amount"]
|
|
|
|
- result1 = append(result1, tmp)
|
|
|
|
|
|
+ ass = append(ass, as)
|
|
}
|
|
}
|
|
- redis.Put("newother", winnerKey, result1, T.C.CacheTimeOut)
|
|
|
|
- return
|
|
|
|
|
|
+ rows.Close()
|
|
|
|
+ if err := rows.Err(); err != nil {
|
|
|
|
+ logx.Error(err)
|
|
|
|
+ }
|
|
|
|
+ redis.Put("newother", winnerKey, ass, T.C.CacheTimeOut)
|
|
|
|
+ return ass
|
|
}
|
|
}
|
|
|
|
|
|
-func GetAgencyData(bid string) (result2 []map[string]interface{}) {
|
|
|
|
- result2 = []map[string]interface{}{}
|
|
|
|
|
|
+//代理机构
|
|
|
|
+func GetAgencyData(bid string) []AggStruct {
|
|
|
|
+ ass := []AggStruct{}
|
|
agencyKey := fmt.Sprintf("networkManage_coopHistory_agency_%s", bid)
|
|
agencyKey := fmt.Sprintf("networkManage_coopHistory_agency_%s", bid)
|
|
- wb, err := redis.GetBytes("newother", agencyKey)
|
|
|
|
- if err == nil {
|
|
|
|
- json.Unmarshal(*wb, &result2)
|
|
|
|
- return
|
|
|
|
|
|
+ wb, err := redis.GetNewBytes("newother", agencyKey)
|
|
|
|
+ if err == nil && wb != nil {
|
|
|
|
+ json.Unmarshal(*wb, &ass)
|
|
|
|
+ return ass
|
|
}
|
|
}
|
|
- m2 := make(map[string]interface{}) //采购单位-代理机构
|
|
|
|
- noIds := []string{}
|
|
|
|
- //代理机构
|
|
|
|
- aggs1, _, _ := elastic.GetAggs(INDEX_1, INDEX_1, fmt.Sprintf(es_query1, strings.ReplaceAll(bid, ",", `","`)))
|
|
|
|
- var m2Buckets = AggStruct{}
|
|
|
|
- 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)
|
|
|
|
- logx.Info(err)
|
|
|
|
- if len(m2Buckets.Buckets) > 0 {
|
|
|
|
- for _, v := range m2Buckets.Buckets {
|
|
|
|
- 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}
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
|
|
+ rows, err1 := T.ClickhouseConn.Query(context.TODO(), `select agency as name,agency_id as id,sum(1) as sum,sum(project_money) as project_money,max(zbtime) as zbtime from information.transaction_info_all where buyer_id=? and agency<>'' and agency_id<>'' GROUP by agency,agency_id`, bid)
|
|
|
|
+ if err1 != nil {
|
|
|
|
+ logx.Error(err1)
|
|
|
|
+ return ass
|
|
}
|
|
}
|
|
- idName := T.NetworkCom.GetEntIdByName(noIds)
|
|
|
|
- for k, v := range m2 {
|
|
|
|
- v1 := v.(map[string]interface{})
|
|
|
|
- tmp := make(map[string]interface{})
|
|
|
|
- tmp["name"] = k
|
|
|
|
- nameId, _ := v1["nameId"].(string)
|
|
|
|
- if nameId == "" {
|
|
|
|
- nameId = idName[k]
|
|
|
|
|
|
+ for rows.Next() {
|
|
|
|
+ as := AggStruct{}
|
|
|
|
+ if err := rows.ScanStruct(&as); err != nil {
|
|
|
|
+ logx.Error(err)
|
|
|
|
+ continue
|
|
}
|
|
}
|
|
- tmp["nameId"] = nameId
|
|
|
|
- tmp["coop_size"] = v1["count"]
|
|
|
|
- tmp["coop_amount"] = v1["amount"]
|
|
|
|
- result2 = append(result2, tmp)
|
|
|
|
|
|
+ ass = append(ass, as)
|
|
}
|
|
}
|
|
- redis.Put("newother", agencyKey, result2, T.C.CacheTimeOut)
|
|
|
|
- return
|
|
|
|
|
|
+ rows.Close()
|
|
|
|
+ if err := rows.Err(); err != nil {
|
|
|
|
+ logx.Error(err)
|
|
|
|
+ }
|
|
|
|
+ redis.Put("newother", agencyKey, ass, T.C.CacheTimeOut)
|
|
|
|
+ return ass
|
|
}
|
|
}
|
|
|
|
|
|
type P_History struct {
|
|
type P_History struct {
|