|
@@ -15,7 +15,8 @@ const (
|
|
query_top10 = `,"sort": [{"sortprice": "desc"}],"from": 0,"size": 10`
|
|
query_top10 = `,"sort": [{"sortprice": "desc"}],"from": 0,"size": 10`
|
|
aggs_area_amounttop3 = `"area_amount_top3":{"terms":{"field":"area","exclude":["全国"],"order":[{"area_amount":"desc"}],"size":3},"aggs":{"area_amount":{"sum":{"field":"sortprice"}},"winner_top":{"terms":{"field":"entidlist","exclude": ["-"],"order":[{"area_winner_amount":"desc"}],"size":3},"aggs":{"area_winner_amount":{"sum":{"field":"sortprice"}}}}}}`
|
|
aggs_area_amounttop3 = `"area_amount_top3":{"terms":{"field":"area","exclude":["全国"],"order":[{"area_amount":"desc"}],"size":3},"aggs":{"area_amount":{"sum":{"field":"sortprice"}},"winner_top":{"terms":{"field":"entidlist","exclude": ["-"],"order":[{"area_winner_amount":"desc"}],"size":3},"aggs":{"area_winner_amount":{"sum":{"field":"sortprice"}}}}}}`
|
|
aggs_area_counttop3 = `"area_count_top3":{"terms":{"field":"area","exclude":["全国"],"order":[{"area_count":"desc"}],"size":3},"aggs":{"area_count":{"filter":{}},"winner_top":{"terms":{"field":"entidlist","exclude": ["-"],"order":[{"area_winner_count":"desc"}],"size":3},"aggs":{"area_winner_count":{"filter":{}}}}}}`
|
|
aggs_area_counttop3 = `"area_count_top3":{"terms":{"field":"area","exclude":["全国"],"order":[{"area_count":"desc"}],"size":3},"aggs":{"area_count":{"filter":{}},"winner_top":{"terms":{"field":"entidlist","exclude": ["-"],"order":[{"area_winner_count":"desc"}],"size":3},"aggs":{"area_winner_count":{"filter":{}}}}}}`
|
|
- aggs_buyerclass = `"buyerclass_scale":{"terms":{"field":"buyerclass","exclude":["其它",""]},"aggs":{"buyerclass_amount":{"sum":{"field":"sortprice"}},"buyerclass_total":{"filter":{}}}}`
|
|
|
|
|
|
+ aggs_buyerclass = `"buyerclass_scale":{"terms":{"field":"buyerclass","size":0,"exclude":["其它",""]},"aggs":{"buyerclass_amount":{"sum":{"field":"sortprice"}},"buyerclass_total":{"filter":{}}}}`
|
|
|
|
+ aggs_buyerclass_other = `"buyerclass_scale_other":{"terms":{"field":"buyerclass","include":["其它",""]},"aggs":{"buyerclass_amount":{"sum":{"field":"sortprice"}},"buyerclass_total":{"filter":{}}}}`
|
|
aggs_buyerclass_counttop3 = `"buyerclass_count_top3":{"terms":{"field":"buyerclass","exclude":["其它",""],"order":[{"buyerclass_count":"desc"}],"size":3},"aggs":{"buyerclass_count":{"filter":{}},"bidcount_top":{"terms":{"field":"entidlist","exclude": ["-"],"order":[{"buyer_winner_count":"desc"}],"size":3},"aggs":{"buyer_winner_count":{"filter":{}}}}}}`
|
|
aggs_buyerclass_counttop3 = `"buyerclass_count_top3":{"terms":{"field":"buyerclass","exclude":["其它",""],"order":[{"buyerclass_count":"desc"}],"size":3},"aggs":{"buyerclass_count":{"filter":{}},"bidcount_top":{"terms":{"field":"entidlist","exclude": ["-"],"order":[{"buyer_winner_count":"desc"}],"size":3},"aggs":{"buyer_winner_count":{"filter":{}}}}}}`
|
|
aggs_buyerclass_amounttop3 = `"buyerclass_amount_top3":{"terms":{"field":"buyerclass","exclude":["其它",""],"order":[{"buyerclass_amount":"desc"}],"size":3},"aggs":{"buyerclass_amount":{"sum":{"field":"sortprice"}},"winner_top":{"terms":{"field":"entidlist","exclude": ["-"],"order":[{"buyer_winner_amount":"desc"}],"size":3},"aggs":{"buyer_winner_amount":{"sum":{"field":"sortprice"}}}}}}`
|
|
aggs_buyerclass_amounttop3 = `"buyerclass_amount_top3":{"terms":{"field":"buyerclass","exclude":["其它",""],"order":[{"buyerclass_amount":"desc"}],"size":3},"aggs":{"buyerclass_amount":{"sum":{"field":"sortprice"}},"winner_top":{"terms":{"field":"entidlist","exclude": ["-"],"order":[{"buyer_winner_amount":"desc"}],"size":3},"aggs":{"buyer_winner_amount":{"sum":{"field":"sortprice"}}}}}}`
|
|
sortprice_str = `{"key":"<10万","from":0.0000000000001,"to":100000},{"key":"10万-50万","from":100000,"to":500000},{"key":"50万-100万","from":500000,"to":1000000},{"key":"100万-500万","from":1000000,"to":5000000},{"key":"500万-1000万","from":5000000,"to":10000000},{"key":"1000万-1亿","from":10000000,"to":100000000},{"key":"≥1亿","from":100000000}`
|
|
sortprice_str = `{"key":"<10万","from":0.0000000000001,"to":100000},{"key":"10万-50万","from":100000,"to":500000},{"key":"50万-100万","from":500000,"to":1000000},{"key":"100万-500万","from":1000000,"to":5000000},{"key":"500万-1000万","from":5000000,"to":10000000},{"key":"1000万-1亿","from":10000000,"to":100000000},{"key":"≥1亿","from":100000000}`
|
|
@@ -65,6 +66,18 @@ type AreaCTop struct {
|
|
} `json:"buyerclass_amount"`
|
|
} `json:"buyerclass_amount"`
|
|
}
|
|
}
|
|
} `json:"buyerclass_scale"`
|
|
} `json:"buyerclass_scale"`
|
|
|
|
+ BuyerclassScaleOther struct {
|
|
|
|
+ Buckets []struct {
|
|
|
|
+ Area string `json:"key"`
|
|
|
|
+ AreaTotal int64 `json:"doc_count"`
|
|
|
|
+ AreaAmount struct {
|
|
|
|
+ Value float64 `json:"value"`
|
|
|
|
+ } `json:"area_amount"`
|
|
|
|
+ BuyclassAmount struct {
|
|
|
|
+ Value float64 `json:"value"`
|
|
|
|
+ } `json:"buyerclass_amount"`
|
|
|
|
+ }
|
|
|
|
+ } `json:"buyerclass_scale_other"`
|
|
AreaAmountTop3 struct {
|
|
AreaAmountTop3 struct {
|
|
Buckets []struct {
|
|
Buckets []struct {
|
|
Key string `json:"key"`
|
|
Key string `json:"key"`
|
|
@@ -167,7 +180,7 @@ type AreaCTop struct {
|
|
} `json:"buyerclass_count_top3"`
|
|
} `json:"buyerclass_count_top3"`
|
|
}
|
|
}
|
|
|
|
|
|
-//企业id查企业名 传入数组
|
|
|
|
|
|
+// 企业id查企业名 传入数组
|
|
func IDToName(ids []string) (iMap map[string]string) {
|
|
func IDToName(ids []string) (iMap map[string]string) {
|
|
iMap = map[string]string{}
|
|
iMap = map[string]string{}
|
|
d := strings.Join(ids, `","`)
|
|
d := strings.Join(ids, `","`)
|
|
@@ -197,7 +210,7 @@ func (mae *MarketAnalysisEntity) AllData() (rMap map[string]interface{}, err err
|
|
aggs = append(aggs, aggs_area, aggs_area_amounttop3, aggs_area_counttop3)
|
|
aggs = append(aggs, aggs_area, aggs_area_amounttop3, aggs_area_counttop3)
|
|
}
|
|
}
|
|
if len(buyclass) != 1 {
|
|
if len(buyclass) != 1 {
|
|
- aggs = append(aggs, aggs_buyerclass, aggs_buyerclass_amounttop3, aggs_buyerclass_counttop3)
|
|
|
|
|
|
+ aggs = append(aggs, aggs_buyerclass, aggs_buyerclass_other, aggs_buyerclass_amounttop3, aggs_buyerclass_counttop3)
|
|
}
|
|
}
|
|
finalSql := fmt.Sprintf(mae.GetCommonQuerySqlWithAggs(), strings.Join(aggs, ","))
|
|
finalSql := fmt.Sprintf(mae.GetCommonQuerySqlWithAggs(), strings.Join(aggs, ","))
|
|
res, _ := util2.GetAggs("projectset", "projectset", finalSql)
|
|
res, _ := util2.GetAggs("projectset", "projectset", finalSql)
|
|
@@ -218,6 +231,10 @@ func (mae *MarketAnalysisEntity) AllData() (rMap map[string]interface{}, err err
|
|
if json.Unmarshal(bArr, &thisRow) != nil {
|
|
if json.Unmarshal(bArr, &thisRow) != nil {
|
|
continue
|
|
continue
|
|
}
|
|
}
|
|
|
|
+ } else if name == "buyerclass_scale_other" {
|
|
|
|
+ if json.Unmarshal(bArr, &thisRow.BuyerclassScaleOther) != nil {
|
|
|
|
+ continue
|
|
|
|
+ }
|
|
} else if name == "project_count_not0" {
|
|
} else if name == "project_count_not0" {
|
|
if json.Unmarshal(bArr, &thisRow.CountNot0) != nil {
|
|
if json.Unmarshal(bArr, &thisRow.CountNot0) != nil {
|
|
continue
|
|
continue
|
|
@@ -254,7 +271,8 @@ func (mae *MarketAnalysisEntity) AllData() (rMap map[string]interface{}, err err
|
|
}
|
|
}
|
|
data := ProjectScale(thisRow)
|
|
data := ProjectScale(thisRow)
|
|
area_data := AreaDistribute(thisRow)
|
|
area_data := AreaDistribute(thisRow)
|
|
- customer_data := CustomerDistribute(thisRow)
|
|
|
|
|
|
+ customerData, customerOther := CustomerDistribute(thisRow)
|
|
|
|
+ //customerOther, customerData := CustomerDistributeDetails(thisRow, customerDetails)
|
|
var ids []string
|
|
var ids []string
|
|
for _, v := range thisRow.AreaAmountTop3.Buckets {
|
|
for _, v := range thisRow.AreaAmountTop3.Buckets {
|
|
for _, va := range v.WinnerTop.Buckets {
|
|
for _, va := range v.WinnerTop.Buckets {
|
|
@@ -279,7 +297,8 @@ func (mae *MarketAnalysisEntity) AllData() (rMap map[string]interface{}, err err
|
|
eid := IDToName(ids)
|
|
eid := IDToName(ids)
|
|
rMap["projectScale"] = data
|
|
rMap["projectScale"] = data
|
|
rMap["area_infos"] = area_data
|
|
rMap["area_infos"] = area_data
|
|
- rMap["customer_scale"] = customer_data
|
|
|
|
|
|
+ rMap["customer_scale"] = customerData
|
|
|
|
+ rMap["customer_scale_other"] = customerOther //客户分布(其它)
|
|
rMap["scaleAreaAmountTop"] = AmountCompute(thisRow, "area", eid)
|
|
rMap["scaleAreaAmountTop"] = AmountCompute(thisRow, "area", eid)
|
|
rMap["scaleBuyclassAmountTop"] = AmountCompute(thisRow, "buyclass", eid)
|
|
rMap["scaleBuyclassAmountTop"] = AmountCompute(thisRow, "buyclass", eid)
|
|
rMap["scaleAreaCountTop"] = CountCompute(thisRow, "area", eid)
|
|
rMap["scaleAreaCountTop"] = CountCompute(thisRow, "area", eid)
|
|
@@ -287,7 +306,7 @@ func (mae *MarketAnalysisEntity) AllData() (rMap map[string]interface{}, err err
|
|
return
|
|
return
|
|
}
|
|
}
|
|
|
|
|
|
-//项目规模分布
|
|
|
|
|
|
+// 项目规模分布
|
|
func ProjectScale(thisRow AreaCTop) (data []interface{}) {
|
|
func ProjectScale(thisRow AreaCTop) (data []interface{}) {
|
|
ammount := thisRow.Amount.Value
|
|
ammount := thisRow.Amount.Value
|
|
total := thisRow.CountNot0.Count
|
|
total := thisRow.CountNot0.Count
|
|
@@ -330,7 +349,7 @@ func InterToSliceString(obj interface{}) []string {
|
|
return sli
|
|
return sli
|
|
}
|
|
}
|
|
|
|
|
|
-//top10
|
|
|
|
|
|
+// top10
|
|
func (mae *MarketAnalysisEntity) ProjectTop10() (rMap map[string]interface{}, err error) {
|
|
func (mae *MarketAnalysisEntity) ProjectTop10() (rMap map[string]interface{}, err error) {
|
|
finalSql := fmt.Sprintf(mae.GetCommonQuerySql(), query_top10)
|
|
finalSql := fmt.Sprintf(mae.GetCommonQuerySql(), query_top10)
|
|
hits := elastic.Get("projectset", "projectset", finalSql)
|
|
hits := elastic.Get("projectset", "projectset", finalSql)
|
|
@@ -380,7 +399,7 @@ func (mae *MarketAnalysisEntity) ProjectTop10() (rMap map[string]interface{}, er
|
|
return
|
|
return
|
|
}
|
|
}
|
|
|
|
|
|
-//地区分布
|
|
|
|
|
|
+// 地区分布
|
|
func AreaDistribute(thisRow AreaCTop) (data []map[string]interface{}) {
|
|
func AreaDistribute(thisRow AreaCTop) (data []map[string]interface{}) {
|
|
for _, v := range thisRow.AreaDistribution.Buckets {
|
|
for _, v := range thisRow.AreaDistribution.Buckets {
|
|
rM := map[string]interface{}{}
|
|
rM := map[string]interface{}{}
|
|
@@ -392,19 +411,58 @@ func AreaDistribute(thisRow AreaCTop) (data []map[string]interface{}) {
|
|
return
|
|
return
|
|
}
|
|
}
|
|
|
|
|
|
-//客户分布
|
|
|
|
-func CustomerDistribute(thisRow AreaCTop) (data []map[string]interface{}) {
|
|
|
|
|
|
+// 客户分布
|
|
|
|
+func CustomerDistribute(thisRow AreaCTop) (data []map[string]interface{}, otherData map[string]interface{}) {
|
|
|
|
+ var (
|
|
|
|
+ total int64
|
|
|
|
+ amount float64
|
|
|
|
+ )
|
|
for _, v := range thisRow.BuyerclassScale.Buckets {
|
|
for _, v := range thisRow.BuyerclassScale.Buckets {
|
|
|
|
+ if v.AreaTotal == 0 && v.BuyclassAmount.Value == 0 {
|
|
|
|
+ continue
|
|
|
|
+ }
|
|
rM := map[string]interface{}{}
|
|
rM := map[string]interface{}{}
|
|
rM["buyclass"] = v.Area
|
|
rM["buyclass"] = v.Area
|
|
rM["total"] = v.AreaTotal
|
|
rM["total"] = v.AreaTotal
|
|
rM["amount"] = v.BuyclassAmount.Value
|
|
rM["amount"] = v.BuyclassAmount.Value
|
|
data = append(data, rM)
|
|
data = append(data, rM)
|
|
}
|
|
}
|
|
|
|
+ for _, v := range thisRow.BuyerclassScaleOther.Buckets {
|
|
|
|
+ total += v.AreaTotal
|
|
|
|
+ amount += v.BuyclassAmount.Value
|
|
|
|
+ }
|
|
|
|
+ if total != 0 || amount != 0 {
|
|
|
|
+ otherData = make(map[string]interface{})
|
|
|
|
+ otherData["buyclass"] = "其它"
|
|
|
|
+ otherData["total"] = total
|
|
|
|
+ otherData["amount"] = amount
|
|
|
|
+ }
|
|
|
|
+ return
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+// 客户分布详情
|
|
|
|
+func CustomerDistributeDetails(thisRow AreaCTop, d []map[string]interface{}) (data map[string]interface{}, customer_data []map[string]interface{}) {
|
|
|
|
+ var (
|
|
|
|
+ total int64
|
|
|
|
+ amount float64
|
|
|
|
+ )
|
|
|
|
+ customer_data = d
|
|
|
|
+ if len(customer_data) > 10 {
|
|
|
|
+ customer_data = d[:10]
|
|
|
|
+ }
|
|
|
|
+ for _, v := range thisRow.BuyerclassScaleOther.Buckets {
|
|
|
|
+ total += v.AreaTotal
|
|
|
|
+ amount += v.BuyclassAmount.Value
|
|
|
|
+ }
|
|
|
|
+ if total != 0 || amount != 0 {
|
|
|
|
+ data["buyclass"] = "其他"
|
|
|
|
+ data["total"] = total
|
|
|
|
+ data["amount"] = amount
|
|
|
|
+ }
|
|
return
|
|
return
|
|
}
|
|
}
|
|
|
|
|
|
-//top3金额计算
|
|
|
|
|
|
+// top3金额计算
|
|
func AmountCompute(thisRow AreaCTop, types string, eid map[string]string) (rData []map[string]interface{}) {
|
|
func AmountCompute(thisRow AreaCTop, types string, eid map[string]string) (rData []map[string]interface{}) {
|
|
if types == "area" {
|
|
if types == "area" {
|
|
area_infos := thisRow.AreaAmountTop3
|
|
area_infos := thisRow.AreaAmountTop3
|
|
@@ -472,7 +530,7 @@ func AmountCompute(thisRow AreaCTop, types string, eid map[string]string) (rData
|
|
return
|
|
return
|
|
}
|
|
}
|
|
|
|
|
|
-//top3数量计算
|
|
|
|
|
|
+// top3数量计算
|
|
func CountCompute(thisRow AreaCTop, types string, eid map[string]string) (rData []map[string]interface{}) {
|
|
func CountCompute(thisRow AreaCTop, types string, eid map[string]string) (rData []map[string]interface{}) {
|
|
if types == "area" {
|
|
if types == "area" {
|
|
area_infos := thisRow.AreaCountTop3
|
|
area_infos := thisRow.AreaCountTop3
|
|
@@ -544,7 +602,7 @@ func CountCompute(thisRow AreaCTop, types string, eid map[string]string) (rData
|
|
return
|
|
return
|
|
}
|
|
}
|
|
|
|
|
|
-//计算公式
|
|
|
|
|
|
+// 计算公式
|
|
func Formula(current, total float64) (result float64) {
|
|
func Formula(current, total float64) (result float64) {
|
|
if total == 0 {
|
|
if total == 0 {
|
|
return 0
|
|
return 0
|