فهرست منبع

Merge branch 'dev4.6.2.15' of ssh://192.168.3.207:10022/qmx/jy into dev4.6.2.15

cuiyalong 3 سال پیش
والد
کامیت
0d1b1458b0

+ 7 - 1
config_formal/big_member_1_172.17.145.180/config.json

@@ -64,5 +64,11 @@
     "mainWebDomain": "https://www.jianyu360.cn",
     "createPdfServer": "http://10.170.187.34:8081/api/to-pdf/%s?delay=300&dir=%s&url=https://www.jianyu360.cn/swordfish/frontPage/report/free/report?pid=%s",
     "pdfDataApiWhiteList": ["123.56.103.12","1.192.61.183","1.192.61.146"],
-    "pdfServerPoor" : 5
+    "pdfServerPoor" : 5,
+    "marketAnalysisPool": {
+	  "limit": 5,
+	  "timeOut": 20,
+	  "projectNumLimit": 600000
+	}
+
 }

+ 1 - 1
config_formal/big_member_1_172.17.145.180/time.txt

@@ -1,2 +1,2 @@
 #上次修改时间,比当前修改时间小就行
-2021-12-30 16:15:12
+2022-1-14 9:00:00

+ 7 - 1
config_formal/bigmember_172.17.145.180/config.json

@@ -64,5 +64,11 @@
     "mainWebDomain": "https://www.jianyu360.cn",
     "createPdfServer": "http://172.17.145.176:8079/api/to-pdf/%s?delay=300&dir=%s&url=https://www.jianyu360.cn/swordfish/frontPage/report/free/report?pid=%s",
     "pdfDataApiWhiteList": ["123.56.103.12","1.192.61.183","1.192.61.146","39.107.83.53"],
-    "pdfServerPoor" : 5
+    "pdfServerPoor" : 5,
+    "marketAnalysisPool": {
+	  "limit": 3,
+	  "timeOut": 20,
+          "projectNumLimit": 600000
+	}
+
 }

+ 5 - 0
config_formal/publicapply_172.17.148.50/bigmembermenu.json

@@ -91,6 +91,11 @@
 				"name":"月报",
 				"url":"/swordfish/page_big_pc/bigvip_subreport_month",
 				"isusable":false
+			},
+			{
+				   "name":"定制化分析报告",
+				   "url":"/swordfish/page_big_pc/desktop/report_analysis",
+				   "isusable":false
 			}
 		]
 	},

+ 8 - 0
config_formal/publicapply_172.17.148.50/commonfunctions.json

@@ -135,6 +135,14 @@
 				"img":"/commonFunctions/pc_subreport_week.png"
 			}
 		},
+		{
+			   "name":"定制化分析报告",
+			   "charge":true,
+			   "pc":{
+			      "url":"/swordfish/page_big_pc/desktop/report_analysis",
+			      "img":"/commonFunctions/analysis_report.png"
+			   }
+		},
 		{
 			"name":"月报",
 			"charge":true,

+ 1 - 1
config_formal/publicapply_172.17.148.50/time.txt

@@ -1,2 +1,2 @@
 #上次修改时间,比当前修改时间小就行
-2021-12-30 16:15:12
+2022-1-14 9:00:00

+ 27 - 5
src/jfw/modules/bigmember/src/entity/marketAnalysis/customizad_distribution.go

@@ -32,7 +32,7 @@ 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","size": 0},"aggs": {"amount": {"sum": {"field": "sortprice"}}}}`
-	winner_procurement_scale = `"winner_amount_distribution": {"terms": {"field": "s_winner","size": 0},"aggs": {"amount": {"sum": {"field": "sortprice"}}}}`
+	winner_procurement_scale = `"winner_amount_distribution": {"terms": {"field": "entidlist","size": 0},"aggs": {"amount": {"sum": {"field": "sortprice"}}}}`
 
 	//中标单位top3(价格)
 	winner_sortprice = `"winner_amount_top3": {"terms": {"field": "entidlist","exclude":["-"],"order": [{"s_winner_amount": "desc"}],"size": 3},"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"}}}}}}`
@@ -672,6 +672,7 @@ func BuyerAnalysis(thisBuyerRow BuyerWinnerRow, rMap map[string]interface{}) {
 	for _, v := range buyerA {
 		count_b = count_b + v.Count
 	}
+
 	for _, v := range Analysis {
 		var data buyer
 		data.Name = v
@@ -696,6 +697,19 @@ func BuyerAnalysis(thisBuyerRow BuyerWinnerRow, rMap map[string]interface{}) {
 		Number int64       `json:"number"`
 		//Accounted interface{} `json:"accounted"`
 	}
+	var winnerKeys []string
+	for _, v := range thisBuyerRow.BuyerCountTop3.Buckets {
+		for _, v1 := range v.SWinnerTop.Buckets {
+			winnerKeys = append(winnerKeys, v1.Key)
+		}
+	}
+	for _, v := range thisBuyerRow.BuyerAmountTop3.Buckets {
+		for _, v1 := range v.SWinnerTop.Buckets {
+			winnerKeys = append(winnerKeys, v1.Key)
+		}
+	}
+
+	winnerName := GetEntNameByIds(winnerKeys)
 	//采购单位-项目数量TOP3
 	countMap := []interface{}{}
 	for _, v := range thisBuyerRow.BuyerCountTop3.Buckets {
@@ -709,7 +723,7 @@ func BuyerAnalysis(thisBuyerRow BuyerWinnerRow, rMap map[string]interface{}) {
 		for _, v1 := range v.SWinnerTop.Buckets {
 			var _dd number_project
 			_dd.Number = v1.BuyerWinnerAmount.Value
-			_dd.Name = IdToWinner(v1.Key)
+			_dd.Name = winnerName[v1.Key]
 			_dd.Id = util.EncodeId(v1.Key)
 
 			/*if _d.Number != 0 {
@@ -753,7 +767,7 @@ func BuyerAnalysis(thisBuyerRow BuyerWinnerRow, rMap map[string]interface{}) {
 			}
 			var _dd amount_project
 			_dd.Amount = v1.BuyerWinnerAmount.Value
-			_dd.Name = IdToWinner(v1.Key)
+			_dd.Name = winnerName[v1.Key]
 			_dd.Id = util.EncodeId(v1.Key)
 			/*	if _d.Amount != 0 {
 				_dd.Accounted = v1.BuyerWinnerAmount.Value / _d.Amount
@@ -810,13 +824,21 @@ func WinningAnalysis(thisWinnerRow BuyerWinnerRow, rMap map[string]interface{})
 		Number int64  `json:"number"`
 		//Accounted interface{} `json:"accounted"`
 	}
+	var winnerKeys []string
+	for _, v := range thisWinnerRow.WinnerCountTop3.SWinnerCount {
+		winnerKeys = append(winnerKeys, v.Key)
+	}
+	for _, v := range thisWinnerRow.WinnerAmountTop3.SWinnerAmount {
+		winnerKeys = append(winnerKeys, v.Key)
+	}
 
+	winnerName := GetEntNameByIds(winnerKeys)
 	//中标单位-项目数量TOP3
 	countMap := []interface{}{}
 	for _, v := range thisWinnerRow.WinnerCountTop3.SWinnerCount {
 		var _d number_projects
 		_d.Number = v.BuyerCount.Value
-		_d.Name = IdToWinner(v.Key)
+		_d.Name = winnerName[v.Key]
 		_d.Id = util.EncodeId(v.Key)
 		/*if thisWinnerRow.ProjectCount.Value != 0 {
 			_d.Accounted = float64(v.BuyerCount.Value) / float64(thisWinnerRow.ProjectCount.Value)
@@ -856,7 +878,7 @@ func WinningAnalysis(thisWinnerRow BuyerWinnerRow, rMap map[string]interface{})
 		}
 		var _d amount_projects
 		_d.Amount = v.SWinnerAmount.Value
-		_d.Name = IdToWinner(v.Key)
+		_d.Name = winnerName[v.Key]
 		_d.Id = util.EncodeId(v.Key)
 		/*if thisWinnerRow.ProjectAmount.Value != 0 {
 			_d.Accounted = v.SWinnerAmount.Value / thisWinnerRow.ProjectAmount.Value

+ 20 - 0
src/jfw/modules/bigmember/src/entity/marketAnalysis/marketAnalysisEntity.go

@@ -8,6 +8,7 @@ import (
 	"log"
 	"mongodb"
 	qutil "qfw/util"
+	"qfw/util/elastic"
 	"qfw/util/redis"
 	"strings"
 	"time"
@@ -300,3 +301,22 @@ func (mae *MarketAnalysisEntity) GetPartResult(flag int) (map[string]interface{}
 	}
 	return rData, err
 }
+
+func GetEntNameByIds(ids []string) (returnMap map[string]string) {
+	returnMap = map[string]string{}
+	if len(ids) == 0 {
+		return
+	}
+	list := elastic.Get("qyxy", "qyxy", fmt.Sprintf(`{"query":{"bool":{"must":[{"terms":{"_id":["%s"]}}]}},"_source":["_id","company_name"],"size":%d}`, strings.Join(ids, `","`), len(ids)))
+	if list == nil || len(*list) == 0 {
+		return
+	}
+	for _, item := range *list {
+		id, _ := item["_id"].(string)
+		name, _ := item["company_name"].(string)
+		if id != "" && name != "" {
+			returnMap[id] = name
+		}
+	}
+	return
+}

+ 92 - 85
src/jfw/modules/bigmember/src/entity/marketAnalysis/scaleRefineQuery.go

@@ -19,9 +19,14 @@ const (
 )
 
 type scaleRefineData struct {
-	Data   []*scaleRefineRow
-	Total  simpleTotal
-	Amount simpleSum
+	Data       []*scaleRefineRow
+	Total      simpleTotal
+	Amount     simpleSum
+	IdSwitch   map[string]string
+	ReturnData struct {
+		Overall             []map[string]interface{}
+		TotalTop, AmountTop []*returnItem
+	}
 }
 
 type simpleTotal struct {
@@ -39,18 +44,16 @@ type scaleRefineRow struct {
 	AmountProp     float64   `json:"amount_prop"`
 	WinnerTotalTop struct {
 		Buckets []*struct {
-			EntId   string       `json:"key"`
-			TopMsg  topMsgStruct `json:"topMsg"`
-			EntName string       `json:"entName"`
-			Total   int64        `json:"doc_count"`
-			Prop    float64      `json:"prop"`
+			EntId   string  `json:"key"`
+			EntName string  `json:"entName"`
+			Total   int64   `json:"doc_count"`
+			Prop    float64 `json:"prop"`
 		} `json:"buckets"`
 	} `json:"winner_total_top"`
 	WinnerAmountTop struct {
 		Buckets []*struct {
-			EntId   string       `json:"key"`
-			EntName string       `json:"entName"`
-			TopMsg  topMsgStruct `json:"topMsg"`
+			EntId   string `json:"key"`
+			EntName string `json:"entName"`
 			Amount  struct {
 				Value float64 `json:"value"`
 			} `json:"refine_winner_amount"`
@@ -61,43 +64,18 @@ type scaleRefineRow struct {
 	UpdateTime int64  `json:"updateTime"`
 }
 
-type topMsgStruct struct {
-	Hits struct {
-		Total    int     `json:"total"`
-		MaxScore float64 `json:"max_score"`
-		Hits     []struct {
-			Source struct {
-				EntIdList  []string `json:"entidlist"`
-				WinnerName string   `json:"s_winner"`
-			} `json:"_source"`
-		} `json:"hits"`
-	} `json:"hits"`
+type returnItem struct {
+	Name    string      `json:"name"`
+	Value   interface{} `json:"value"`
+	Prop    interface{} `json:"prop"`
+	TopList []*entValue `json:"topList"`
 }
 
-//getReallyName 根据企业id或企业名称
-func (tms topMsgStruct) getReallyName(entId string) string {
-	for _, rs := range tms.Hits.Hits {
-		//仅只有一个中标企业
-		if len(rs.Source.EntIdList) == 1 {
-			if rs.Source.EntIdList[0] == entId {
-				return rs.Source.WinnerName
-			}
-		} else { //多个中标企业,根据顺序返回对应名称
-			flag := -1
-			for index, tId := range rs.Source.EntIdList {
-				if tId == entId {
-					flag = index
-					break
-				}
-			}
-			if flag > -1 {
-				if names := strings.Split(rs.Source.WinnerName, ","); len(names)-1 >= flag {
-					return names[flag]
-				}
-			}
-		}
-	}
-	return ""
+type entValue struct {
+	Id    string      `json:"id"`
+	Name  string      `json:"name"`
+	Value interface{} `json:"value"`
+	Prop  interface{} `json:"prop"`
 }
 
 //marketScaleRefineQuery 细化聚合
@@ -116,18 +94,18 @@ func (mae *MarketAnalysisEntity) marketScaleRefineQuery() (rMap map[string]inter
 			}
 		}
 		if len(bools) > 0 {
-			aggsGroup = append(aggsGroup, fmt.Sprintf(`"%s":{"filter":{"query":{"bool":{"should":[%s],"minimum_should_match": 1}}},"aggs":{"project_count":{"filter":{}},"project_amount":{"sum":{"field":"sortprice"}},"winner_total_top":{"terms":{"field":"entidlist","order":[{"refine_winner_total":"desc"}],"size":%d},"aggs":{"refine_winner_total":{"filter":{}},"topMsg":{"top_hits":{"_source":{"includes":["entidlist","s_winner"]},"size":1}}}},"winner_amount_top":{"terms":{"field":"entidlist","order":[{"refine_winner_amount":"desc"}],"size":%d},"aggs":{"refine_winner_amount":{"sum":{"field":"sortprice"}},"topMsg":{"top_hits":{"_source":{"includes":["entidlist","s_winner"]},"size":1}}}}}}`, group.ItemName, strings.Join(bools, ","), topWinnerLimit, topWinnerLimit))
+			aggsGroup = append(aggsGroup, fmt.Sprintf(`"%s":{"filter":{"query":{"bool":{"should":[%s],"minimum_should_match": 1}}},"aggs":{"project_count":{"filter":{}},"project_amount":{"sum":{"field":"sortprice"}},"winner_total_top":{"terms":{"field":"entidlist","exclude":["-"],"order":[{"refine_winner_total":"desc"}],"size":%d},"aggs":{"refine_winner_total":{"filter":{}}}},"winner_amount_top":{"terms":{"field":"entidlist","exclude":["-"],"order":[{"refine_winner_amount":"desc"}],"size":%d},"aggs":{"refine_winner_amount":{"sum":{"field":"sortprice"}}}}}}`, group.ItemName, strings.Join(bools, ","), topWinnerLimit, topWinnerLimit))
 		}
 		itemDataMap[group.ItemName] = group.UpdateTime
 	}
 	finalSql := fmt.Sprintf(mae.GetCommonQuerySqlWithAggs(), strings.Join(aggsGroup, ","))
-	//log.Println("finalSql", finalSql)
+	//fmt.Println("finalSql-----4", finalSql)
 	rMap = map[string]interface{}{}
 	res, _ := util.GetAggs("projectset", "projectset", finalSql)
 	if res == nil || len(res) == 0 {
 		return
 	}
-	scale := scaleRefineData{}
+	scale := scaleRefineData{IdSwitch: map[string]string{}}
 	for name, object := range res {
 		bArr, err := object.MarshalJSON()
 		if len(bArr) == 0 || err != nil {
@@ -154,13 +132,37 @@ func (mae *MarketAnalysisEntity) marketScaleRefineQuery() (rMap map[string]inter
 		thisRow.UpdateTime = itemDataMap[name]
 		scale.Data = append(scale.Data, &thisRow)
 	}
-	//计算占比
-	scale.formatData()
+	scale.formatData() //获取所需数据
+	scale.doIdSwitch() //补充企业名称
+	return map[string]interface{}{
+		"scaleRefineAll":       scale.ReturnData.Overall,
+		"scaleRefineTotalTop":  scale.ReturnData.TotalTop,
+		"scaleRefineAmountTop": scale.ReturnData.AmountTop,
+	}, nil
+}
 
-	rMap["scaleRefineAll"] = scale.sortBy(totalAndAmount).getFormatTop(-1, totalAndAmount)
-	rMap["scaleRefineTotalTop"] = scale.sortBy(onlyTotal).getFormatTop(topItemLimit, onlyTotal)
-	rMap["scaleRefineAmountTop"] = scale.sortBy(onlyAmount).getFormatTop(topItemLimit, onlyAmount)
-	return
+//doIdSwitch 补充企业名称
+func (srd *scaleRefineData) doIdSwitch() {
+	if len(srd.IdSwitch) == 0 {
+		return
+	}
+	var ids []string
+	for id, _ := range srd.IdSwitch {
+		ids = append(ids, id)
+	}
+	srd.IdSwitch = GetEntNameByIds(ids)
+	for _, v := range srd.ReturnData.TotalTop {
+		for _, vv := range v.TopList {
+			vv.Name, _ = srd.IdSwitch[vv.Id]
+			vv.Id = util.EncodeId(vv.Id)
+		}
+	}
+	for _, v := range srd.ReturnData.AmountTop {
+		for _, vv := range v.TopList {
+			vv.Name, _ = srd.IdSwitch[vv.Id]
+			vv.Id = util.EncodeId(vv.Id)
+		}
+	}
 }
 
 //formatData 计算百分比&获取企业对应名称
@@ -171,62 +173,67 @@ func (srd *scaleRefineData) formatData() {
 
 		for _, vv := range v.WinnerTotalTop.Buckets {
 			vv.Prop = float64(vv.Total) / float64(v.Total)
-			vv.EntName = vv.TopMsg.getReallyName(vv.EntId)
 		}
 		for _, vv := range v.WinnerAmountTop.Buckets {
 			vv.Prop = vv.Amount.Value / v.Amount.Value
-			vv.EntName = vv.TopMsg.getReallyName(vv.EntId)
 		}
 	}
+	srd.ReturnData.Overall = srd.sortBy(totalAndAmount).getOverallData()
+	srd.ReturnData.AmountTop = srd.sortBy(onlyAmount).getFormatTop(topItemLimit, onlyAmount)
+	srd.ReturnData.TotalTop = srd.sortBy(onlyTotal).getFormatTop(topItemLimit, onlyTotal)
+}
+
+//getOverallData 获取分类总览数据
+func (srd *scaleRefineData) getOverallData() (rData []map[string]interface{}) {
+	for _, Value := range srd.Data {
+		rData = append(rData, map[string]interface{}{
+			"name":   Value.ItemName,
+			"total":  Value.Total,
+			"amount": Value.Amount.Value,
+		})
+	}
+	return
 }
 
 //getArrayFormatTop 获取前n个数据,并格式化
 //limit 获取前x条
-//flag 1仅返回数量统计 2仅返回金额统计 3返回数量和金额统计,但不返回各项Top数据
-func (srd *scaleRefineData) getFormatTop(limit, flag int) (rData []map[string]interface{}) {
+//flag 1仅返回数量统计 2仅返回金额统计
+func (srd *scaleRefineData) getFormatTop(limit, flag int) (rData []*returnItem) {
 	for index, Value := range srd.Data {
 		if index >= limit && limit > -1 {
 			return
 		}
-		thisRow := map[string]interface{}{
-			"name": Value.ItemName,
+		thisRow := &returnItem{
+			Name: Value.ItemName,
 		}
 		if flag == 1 || flag == 3 { //返回数量相关数据
-			thisRow["total"] = Value.Total
+			thisRow.Value = Value.Total
 			if flag != 3 {
-				topArr := []map[string]interface{}{}
 				for _, v := range Value.WinnerTotalTop.Buckets {
-					if len(v.EntId) <= 1 || len(v.EntName) <= 1 { //数据库过滤id为-,及未关联到企业名称的数据
-						continue
-					}
-					topArr = append(topArr, map[string]interface{}{
-						"id":    util.EncodeId(v.EntId),
-						"name":  v.EntName,
-						"value": v.Total,
-						"prop":  v.Prop,
+					thisRow.TopList = append(thisRow.TopList, &entValue{
+						Id:    v.EntId,
+						Name:  v.EntName,
+						Value: v.Total,
+						Prop:  v.Prop,
 					})
+					srd.IdSwitch[v.EntId] = ""
 				}
-				thisRow["prop"] = Value.TotalProp
-				thisRow["totalTop"] = topArr
+				thisRow.Prop = Value.TotalProp
 			}
 		}
 		if flag == 2 || flag == 3 { //返回金额相关数据
-			thisRow["amount"] = Value.Amount.Value
+			thisRow.Value = Value.Amount.Value
 			if flag != 3 {
-				topArr := []map[string]interface{}{}
 				for _, v := range Value.WinnerAmountTop.Buckets {
-					if len(v.EntId) <= 1 || len(v.EntName) <= 1 { //数据库过滤id为-,及未关联到企业名称的数据
-						continue
-					}
-					topArr = append(topArr, map[string]interface{}{
-						"id":    util.EncodeId(v.EntId),
-						"name":  v.EntName,
-						"value": v.Amount.Value,
-						"prop":  v.Prop,
+					thisRow.TopList = append(thisRow.TopList, &entValue{
+						Id:    v.EntId,
+						Name:  v.EntName,
+						Value: v.Amount.Value,
+						Prop:  v.Prop,
 					})
+					srd.IdSwitch[v.EntId] = ""
 				}
-				thisRow["prop"] = Value.AmountProp
-				thisRow["amountTop"] = topArr
+				thisRow.Prop = Value.TotalProp
 			}
 		}
 		rData = append(rData, thisRow)