Jelajahi Sumber

Merge branch 'feature/v4.7.49' of http://192.168.3.207:8080/qmx/jy into feature/v4.7.49

tangshizhe 2 tahun lalu
induk
melakukan
2bead79a3d

+ 25 - 12
src/jfw/modules/bigmember/src/entity/marketAnalysis/customizad_distribution.go

@@ -6,7 +6,9 @@ import (
 	"fmt"
 	elastic1 "gopkg.in/olivere/elastic.v1"
 	"math"
+	qutil "qfw/util"
 	"strings"
+	"sync"
 	"time"
 	"util"
 )
@@ -661,10 +663,19 @@ func (mae *MarketAnalysisEntity) BuyerWinnerAnalysis() map[string]interface{} {
 		winnerKeys = append(winnerKeys, k)
 	}
 	winnerName := GetEntNameByIds(winnerKeys)
-	rMap := make(map[string]interface{})
-	BuyerAnalysis(thisBuyerWinnerRow, rMap, winnerName)
-	WinningAnalysis(thisBuyerWinnerRow, rMap, winnerName)
-	return rMap
+	//rMap := make(map[string]interface{})
+	var rMap = sync.Map{}
+	sy := sync.WaitGroup{}
+	sy.Add(2)
+	go BuyerAnalysis(thisBuyerWinnerRow, &rMap, winnerName, &sy)
+	go WinningAnalysis(thisBuyerWinnerRow, &rMap, winnerName, &sy)
+	sy.Wait()
+	rMaps := make(map[string]interface{})
+	rMap.Range(func(key, value interface{}) bool {
+		rMaps[qutil.InterfaceToStr(key)] = value
+		return true
+	})
+	return rMaps
 }
 
 type distributionTrend struct {
@@ -675,7 +686,8 @@ type distributionTrend struct {
 
 var Analysis = []string{"<10万", "10万~50万", "50万~100万", "100万~500万", "500万~1000万", "1000万~1亿", "≥1亿"}
 
-func BuyerAnalysis(thisBuyerRow BuyerWinnerRow, rMap map[string]interface{}, winnerName map[string]string) {
+func BuyerAnalysis(thisBuyerRow BuyerWinnerRow, rMap *sync.Map, winnerName map[string]string, sy *sync.WaitGroup) {
+	defer sy.Done()
 	type buyer struct {
 		Name        string      `json:"key"`
 		TotalAmount interface{} `json:"total_amount"`
@@ -791,13 +803,14 @@ func BuyerAnalysis(thisBuyerRow BuyerWinnerRow, rMap map[string]interface{}, win
 		_d.Data = ss
 		amountMap = append(amountMap, _d)
 	}
-	rMap["buyer_time_distribution"] = buyerMap
-	rMap["buyer_count_top3"] = countMap
-	rMap["buyer_amount_top3"] = amountMap
+	rMap.Store("buyer_time_distribution", buyerMap)
+	rMap.Store("buyer_count_top3", countMap)
+	rMap.Store("buyer_amount_top3", amountMap)
 }
 
 // 中标单位分析
-func WinningAnalysis(thisWinnerRow BuyerWinnerRow, rMap map[string]interface{}, winnerName map[string]string) {
+func WinningAnalysis(thisWinnerRow BuyerWinnerRow, rMap *sync.Map, winnerName map[string]string, sy *sync.WaitGroup) {
+	defer sy.Done()
 	type s_Winner struct {
 		Name        string      `json:"key"`
 		TotalAmount interface{} `json:"total_amount"`
@@ -908,7 +921,7 @@ func WinningAnalysis(thisWinnerRow BuyerWinnerRow, rMap map[string]interface{},
 		_d.Data = ss
 		amountMap = append(amountMap, _d)
 	}
-	rMap["winner_time_distribution"] = buyerMap
-	rMap["winner_count_top3"] = countMap
-	rMap["winner_amount_top3"] = amountMap
+	rMap.Store("winner_time_distribution", buyerMap)
+	rMap.Store("winner_count_top3", buyerMap)
+	rMap.Store("winner_amount_top3", amountMap)
 }