|
@@ -4,6 +4,7 @@ import (
|
|
|
"app.yhyue.com/moapp/jybase/common"
|
|
|
"encoding/json"
|
|
|
"fmt"
|
|
|
+ esV7 "github.com/olivere/elastic/v7"
|
|
|
"jy/src/jfw/modules/bigmember/src/config"
|
|
|
"jy/src/jfw/modules/bigmember/src/util"
|
|
|
"log"
|
|
@@ -12,7 +13,7 @@ import (
|
|
|
"sync"
|
|
|
"time"
|
|
|
|
|
|
- esV7 "github.com/olivere/elastic/v7"
|
|
|
+ elastic "app.yhyue.com/moapp/jybase/es"
|
|
|
)
|
|
|
|
|
|
const (
|
|
@@ -26,7 +27,7 @@ const (
|
|
|
|
|
|
//采购单位聚合查询
|
|
|
//buyer_procurement_scale = `"project_count":{"filter":{"match_all":{}}},"project_amount":{"sum":{"field":"sortprice"}},"buyer_count":{"filter": {"range": {"sortprice": {"gt": 0}}},"aggs": {"cardinality_buyer_count": {"cardinality": {"field": "buyer"}}}},"buyer_time_distribution": {"range": { "field": "sortprice","ranges": [%s]},"aggs":{"buyer_count": {"cardinality": {"field": "buyer"}}}},"buyer_amount_distribution": {"terms": {"field": "buyer"},"aggs": {"amount": {"sum": {"field": "sortprice"}}}}`
|
|
|
- buyer_procurement_scale = `"project_amount":{"sum":{"field":"sortprice"}},"buyer_amount_distribution": {"terms": {"field": "buyer","order": [{"amount": "desc"}],"size":100000},"aggs": {"amount": {"sum": {"field": "sortprice"}}}}`
|
|
|
+ buyer_procurement_scale = `"buyer_amount_distribution": {"terms": {"field": "buyer","order": [{"amount": "desc"}],"size":100000},"aggs": {"amount": {"sum": {"field": "sortprice"}}}}`
|
|
|
|
|
|
//采购单位top3(价格)buyer_sortprice
|
|
|
buyer_sortprice = `"buyer_amount_top3": {"terms": {"field": "buyer","order": [{"buyer_amount": "desc"}],"size": 30},"aggs": {"buyer_amount": {"sum": {"field": "sortprice"}},"s_winner_top": {"terms": {"field": "entidlist","exclude":["-"],"order": [{"buyer_winner_amount": "desc"}],"size": 3},"aggs": {"buyer_winner_amount": {"sum": {"field": "sortprice"}}}}}}`
|
|
@@ -36,7 +37,8 @@ const (
|
|
|
|
|
|
//中标单位
|
|
|
//winner_procurement_scale = `"winner_count":{"filter": {"range": {"sortprice": {"gt": 0}}},"aggs": {"cardinality_winner_count": {"cardinality": {"field": "s_winner"}}}},"winner_time_distribution": {"range": { "field": "sortprice","ranges": [%s]},"aggs":{"s_winner_count": {"cardinality": {"field": "s_winner"}}}},"winner_amount_distribution": {"terms": {"field": "s_winner"},"aggs": {"amount": {"sum": {"field": "sortprice"}}}}`
|
|
|
- winner_procurement_scale = `"winner_amount_distribution": {"terms": {"field": "entidlist","order": [{"amount": "desc"}],"size":100000},"aggs": {"amount": {"sum": {"field": "sortprice"}}}}`
|
|
|
+ //winner_procurement_scale = `"winner_amount_distribution": {"terms": {"field": "entidlist","order": [{"amount": "desc"}],"size":100000},"aggs": {"amount": {"sum": {"field": "sortprice"}}}}`
|
|
|
+ winner_procurement_scale = `"winner_amount_distribution": {"filter": {"script": {"script": "doc['entidlist'].length == 1"}},"aggs": {"entidlist_terms": {"terms": {"field": "entidlist","order": {"amount": "desc"},"size": 100000},"aggs": {"amount": {"sum": {"field": "sortprice"}}}}}}`
|
|
|
|
|
|
//中标单位top3(价格)
|
|
|
winner_sortprice = `"winner_amount_top3": {"terms": {"field": "entidlist","exclude":["-"],"order": [{"s_winner_amount": "desc"}],"size": 30},"aggs": {"s_winner_amount": {"sum": {"field": "sortprice"}},"buyer_top": {"terms": {"field": "buyer","order": [{"buyer_winner_amount": "desc"}],"size": 3},"aggs": {"buyer_winner_amount": {"sum": {"field": "sortprice"}}}}}}`
|
|
@@ -516,15 +518,18 @@ type BuyerWinnerRow struct {
|
|
|
} `json:"s_winner_top"`
|
|
|
} `json:"buckets"`
|
|
|
} `json:"buyer_amount_top3"`
|
|
|
+
|
|
|
WinnerAmountDistribution struct {
|
|
|
- Buckets []struct {
|
|
|
- Key string `json:"key"`
|
|
|
- DocCount int `json:"doc_count"`
|
|
|
- Amount struct {
|
|
|
- Value float64 `json:"value"`
|
|
|
- } `json:"amount"`
|
|
|
- } `json:"buckets"`
|
|
|
+ EntidlistTerms struct {
|
|
|
+ Buckets []struct {
|
|
|
+ Key string `json:"key"`
|
|
|
+ Amount struct {
|
|
|
+ Value float64 `json:"value"`
|
|
|
+ } `json:"amount"`
|
|
|
+ } `json:"buckets"`
|
|
|
+ } `json:"entidlist_terms"`
|
|
|
} `json:"winner_amount_distribution"`
|
|
|
+
|
|
|
WinnerCountTop3 struct {
|
|
|
SWinnerCount []struct {
|
|
|
Key string `json:"key"`
|
|
@@ -610,6 +615,32 @@ func (mae *MarketAnalysisEntity) BuyerWinnerAnalysis() map[string]interface{} {
|
|
|
if res == nil || len(res) == 0 {
|
|
|
return nil
|
|
|
}
|
|
|
+ //计算entidlist大于1的中标单位金额
|
|
|
+ entArrMap := make(map[string]float64)
|
|
|
+ winnerKeyMap := make(map[string]int)
|
|
|
+ newSql := strings.ReplaceAll(fmt.Sprintf(mae.GetCommonQuerySql(), `,"sort": [{"sortprice": {"order": "desc"}}], "_source": ["entidlist","sortprice"],"size":10000`), `],"should":[`, fmt.Sprintf(`%s],"should":[`, `,{"script": {"script": {"source": "doc['entidlist'].length > 1"}}}`))
|
|
|
+ log.Println("winner new sql", newSql)
|
|
|
+ multiBid := elastic.Get("projectset", "projectset", newSql)
|
|
|
+ if multiBid != nil && len(*multiBid) > 0 {
|
|
|
+ for _, m := range *multiBid {
|
|
|
+ entidlist, _ := m["entidlist"].([]interface{})
|
|
|
+ entArr := common.ObjArrToStringArr(entidlist)
|
|
|
+ sortprice := common.Float64All(m["sortprice"])
|
|
|
+ entLen := len(entArr)
|
|
|
+ switch entLen {
|
|
|
+ case 1:
|
|
|
+ entArrMap[entArr[0]] = sortprice
|
|
|
+ winnerKeyMap[entArr[0]]++
|
|
|
+ case 0:
|
|
|
+ default:
|
|
|
+ assessedAmount := sortprice / common.Float64All(entLen)
|
|
|
+ for _, m2 := range entArr {
|
|
|
+ winnerKeyMap[m2]++
|
|
|
+ entArrMap[m2] = assessedAmount
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
log.Println("采购单位-中标单位分析报告es查询耗时===", time.Since(t))
|
|
|
var thisBuyerWinnerRow BuyerWinnerRow
|
|
|
for name, object := range res {
|
|
@@ -617,11 +648,7 @@ func (mae *MarketAnalysisEntity) BuyerWinnerAnalysis() map[string]interface{} {
|
|
|
if len(bArr) == 0 || err != nil {
|
|
|
continue
|
|
|
}
|
|
|
- if name == "project_amount" {
|
|
|
- if json.Unmarshal(bArr, &thisBuyerWinnerRow.ProjectAmount) != nil {
|
|
|
- continue
|
|
|
- }
|
|
|
- } else if name == "buyer_amount_distribution" {
|
|
|
+ if name == "buyer_amount_distribution" {
|
|
|
if json.Unmarshal(bArr, &thisBuyerWinnerRow.BuyerAmountDistribution) != nil {
|
|
|
continue
|
|
|
}
|
|
@@ -648,7 +675,6 @@ func (mae *MarketAnalysisEntity) BuyerWinnerAnalysis() map[string]interface{} {
|
|
|
}
|
|
|
}
|
|
|
var winnerKeys []string
|
|
|
- winnerKeyMap := make(map[string]int)
|
|
|
for _, v := range thisBuyerWinnerRow.BuyerCountTop3.Buckets {
|
|
|
for _, v1 := range v.SWinnerTop.Buckets {
|
|
|
winnerKeyMap[v1.Key]++
|
|
@@ -665,7 +691,7 @@ func (mae *MarketAnalysisEntity) BuyerWinnerAnalysis() map[string]interface{} {
|
|
|
for _, v := range thisBuyerWinnerRow.WinnerAmountTop3.SWinnerAmount {
|
|
|
winnerKeyMap[v.Key]++
|
|
|
}
|
|
|
- for k, _ := range winnerKeyMap {
|
|
|
+ for k := range winnerKeyMap {
|
|
|
winnerKeys = append(winnerKeys, k)
|
|
|
}
|
|
|
winnerName := GetEntNameByIds(winnerKeys)
|
|
@@ -674,7 +700,7 @@ func (mae *MarketAnalysisEntity) BuyerWinnerAnalysis() map[string]interface{} {
|
|
|
sy := sync.WaitGroup{}
|
|
|
sy.Add(2)
|
|
|
go BuyerAnalysis(thisBuyerWinnerRow, &rMap, winnerName, &sy)
|
|
|
- go WinningAnalysis(thisBuyerWinnerRow, &rMap, winnerName, &sy)
|
|
|
+ go WinningAnalysis(thisBuyerWinnerRow, &rMap, entArrMap, winnerName, &sy)
|
|
|
sy.Wait()
|
|
|
log.Println("采购单位-中标单位分析报告程序计算耗时===", time.Since(t))
|
|
|
rMaps := make(map[string]interface{})
|
|
@@ -708,19 +734,23 @@ func BuyerAnalysis(thisBuyerRow BuyerWinnerRow, rMap *sync.Map, winnerName map[s
|
|
|
for _, v := range thisBuyerRow.BuyerAmountDistribution.Buckets {
|
|
|
amountDistribution(v.Amount.Value, buyerA)
|
|
|
}
|
|
|
- var count_b int
|
|
|
+ var (
|
|
|
+ countAll int
|
|
|
+ amountAll float64
|
|
|
+ )
|
|
|
for _, v := range buyerA {
|
|
|
- count_b = count_b + v.Count
|
|
|
+ countAll += v.Count
|
|
|
+ amountAll += v.Amount
|
|
|
}
|
|
|
|
|
|
for _, v := range Analysis {
|
|
|
var data buyer
|
|
|
data.Name = v
|
|
|
- if vlu, ok := buyerA[v]; ok && count_b != 0 {
|
|
|
- data.TotalNumber = float64(vlu.Count) / float64(count_b)
|
|
|
+ if vlu, ok := buyerA[v]; ok && countAll != 0 {
|
|
|
+ data.TotalNumber = float64(vlu.Count) / float64(countAll)
|
|
|
}
|
|
|
- if vlu, ok := buyerA[v]; ok && thisBuyerRow.ProjectAmount.Value != 0 {
|
|
|
- data.TotalAmount = vlu.Amount / thisBuyerRow.ProjectAmount.Value
|
|
|
+ if vlu, ok := buyerA[v]; ok && amountAll != 0 {
|
|
|
+ data.TotalAmount = vlu.Amount / amountAll
|
|
|
}
|
|
|
buyerMap = append(buyerMap, data)
|
|
|
}
|
|
@@ -816,7 +846,7 @@ func BuyerAnalysis(thisBuyerRow BuyerWinnerRow, rMap *sync.Map, winnerName map[s
|
|
|
}
|
|
|
|
|
|
// 中标单位分析
|
|
|
-func WinningAnalysis(thisWinnerRow BuyerWinnerRow, rMap *sync.Map, winnerName map[string]string, sy *sync.WaitGroup) {
|
|
|
+func WinningAnalysis(thisWinnerRow BuyerWinnerRow, rMap *sync.Map, entArrMap map[string]float64, winnerName map[string]string, sy *sync.WaitGroup) {
|
|
|
defer sy.Done()
|
|
|
type s_Winner struct {
|
|
|
Name string `json:"key"`
|
|
@@ -825,22 +855,33 @@ func WinningAnalysis(thisWinnerRow BuyerWinnerRow, rMap *sync.Map, winnerName ma
|
|
|
}
|
|
|
//中标单位-中标规模分布
|
|
|
winnerA := make(map[string]*distributionTrend)
|
|
|
- for _, v := range thisWinnerRow.WinnerAmountDistribution.Buckets {
|
|
|
+ for _, v := range thisWinnerRow.WinnerAmountDistribution.EntidlistTerms.Buckets {
|
|
|
+ if vs, ok := entArrMap[v.Key]; ok {
|
|
|
+ v.Amount.Value += vs
|
|
|
+ delete(entArrMap, v.Key)
|
|
|
+ }
|
|
|
amountDistribution(v.Amount.Value, winnerA)
|
|
|
}
|
|
|
- var count_b int
|
|
|
+ for _, f := range entArrMap {
|
|
|
+ amountDistribution(f, winnerA)
|
|
|
+ }
|
|
|
+ var (
|
|
|
+ countAll int
|
|
|
+ amountAll float64
|
|
|
+ )
|
|
|
for _, v := range winnerA {
|
|
|
- count_b = count_b + v.Count
|
|
|
+ countAll += v.Count
|
|
|
+ amountAll += v.Amount
|
|
|
}
|
|
|
buyerMap := []interface{}{}
|
|
|
for _, v := range Analysis {
|
|
|
var data s_Winner
|
|
|
data.Name = v
|
|
|
- if vlu, ok := winnerA[v]; ok && count_b != 0 {
|
|
|
- data.TotalNumber = float64(vlu.Count) / float64(count_b)
|
|
|
+ if vlu, ok := winnerA[v]; ok && countAll != 0 {
|
|
|
+ data.TotalNumber = float64(vlu.Count) / float64(countAll)
|
|
|
}
|
|
|
- if vlu, ok := winnerA[v]; ok && thisWinnerRow.ProjectAmount.Value != 0 {
|
|
|
- data.TotalAmount = vlu.Amount / thisWinnerRow.ProjectAmount.Value
|
|
|
+ if vlu, ok := winnerA[v]; ok && amountAll != 0 {
|
|
|
+ data.TotalAmount = vlu.Amount / amountAll
|
|
|
}
|
|
|
buyerMap = append(buyerMap, data)
|
|
|
}
|