Browse Source

Merge branch 'master' into feature/v4.9.96

yuelujie 5 months ago
parent
commit
723833eb41

+ 1 - 1
src/jfw/front/index.go

@@ -514,7 +514,7 @@ func GetIndexProjectList(typ, pageSize int, resArr []map[string]interface{}) (da
 	if len(resArr) > 5 {
 		return resArr[:5], types
 	}
-	res, err := g.DB().Query(gctx.New(), fmt.Sprintf(`SELECT bid_id,publish_time,bitmapToArray(sign) FROM new_bid_sign WHERE bitmapContains(sign, %d) ORDER BY publish_time DESC LIMIT %d, %d`, typ, pageSize-10, 10))
+	res, err := g.DB().Query(gctx.New(), fmt.Sprintf(`SELECT bid_id,publish_time,bitmapToArray(sign) FROM new_bid_sign WHERE bitmapContains(sign, %d) and publish_time > '%s' ORDER BY publish_time DESC LIMIT %d, %d`, typ, time.Now().AddDate(0, -6, 0).Format(time.DateTime), pageSize-10, 10))
 	if err != nil || res.IsEmpty() {
 		return nil, types
 	}

+ 1 - 1
src/jfw/modules/app/src/web/staticres/jyapp/big-member/js/report_analysis.js

@@ -1819,7 +1819,7 @@ var vm = new Vue({
     toSubManage: function () {
       location.href = '/jyapp/vipsubscribe/toSetKeyWordPage?vSwitch=m'
     },
-    toArticleContent (item) {
+    clickTOP10ProjectName (item) {
       this.saveState()
       location.href = `/jyapp/article/content/${item._id}.html`
     },

+ 15 - 3
src/jfw/modules/app/src/web/templates/big-member/page_report_analysis.html

@@ -223,7 +223,7 @@
                                                 'soft-orange': index === 2
                                             }">
                                                 ${ index + 1 }</div>
-                                            <div class="p-t-i-hd-r" @click="toArticleContent(item)">
+                                            <div class="p-t-i-hd-r" @click="clickTOP10ProjectName(item)">
                                                 <div class="project-name">${ item.projectname }</div>
                                                 <div class="project-info">
                                                     <div class="project-tags">
@@ -332,7 +332,7 @@
                                     </div>
                                 </div>
                             </div>
-                            <van-popup v-model="sections.areaScatter.showAreaPopup" closeable round position="bottom"
+                            <!-- <van-popup v-model="sections.areaScatter.showAreaPopup" closeable round position="bottom"
                                 close-icon="clear" class="j-popup collection" :lazy-render="false"
                                 overlay-class="j-overlay" :style="{ height: '60%' }" get-container="body">
                                 <div class="j-container report-popup">
@@ -343,7 +343,7 @@
                                             @confirm="confirmSelectArea"></area-component>
                                     </div>
                                 </div>
-                            </van-popup>
+                            </van-popup> -->
                             <div class="section bg-white pd-16"
                                 v-if="sections.areaScatter.projectCountTop3 && getStatus">
                                 <div class="section-title">各地区重点中标单位-项目数量</div>
@@ -593,6 +593,18 @@
             <!-- 下载弹窗 -->
             <downloadpopup ref="downloadpopup"  @lookmore="anchorTo({top:0})" :data="{buyercount,winnercount,projectTotalMoney,projectCount,balance,getStatus}"></downloadpopup>
 
+            <van-popup v-model="sections.areaScatter.showAreaPopup" closeable round position="bottom"
+                close-icon="clear" class="j-popup collection" :lazy-render="false"
+                overlay-class="j-overlay" :style="{ height: '60%' }" get-container="body">
+                <div class="j-container report-popup">
+                    <div class="popup-header header-title">请选择省份</div>
+                    <div class="j-main area-content">
+                        <area-component :multiple="false" :newprovincelist="reportFilters.area"
+                            :showcountry="false" ref="areaSelector" @cancel="cancelSelectArea"
+                            @confirm="confirmSelectArea"></area-component>
+                    </div>
+                </div>
+            </van-popup>
             <van-popup v-model="filterDialogShow.keys" closeable round position="bottom" close-icon="clear"
                 class="j-popup collection" overlay-class="j-overlay" :lazy-render="false" :style="{ height: '60%' }"
                 get-container="body">

+ 15 - 2
src/jfw/modules/bigmember/src/config.yaml

@@ -1,6 +1,19 @@
 etcd:
   hosts:
-  - 192.168.3.206:2379
+    - 192.168.3.207:2379
+    - 192.168.3.165:2379
+    - 192.168.3.204:2379
 powerCheckCenterKey: "powercheck.rpc" #权益校验中台
 userCenterKey: "usercenter.rpc" #用户中台rpc
-resourceCenterKey: "resource.rpc" #资源中台
+resourceCenterKey: "resource.rpc" #资源中台
+
+ma:
+  minKCount: 100
+  maxPCount: 5000000
+  bwCount: 0
+  bwdCount: 0
+  index: projectset
+  type: projectset
+  fields:
+    - projectname.pname
+    - purchasing

+ 10 - 0
src/jfw/modules/bigmember/src/config/config.go

@@ -5,6 +5,7 @@ import (
 	"app.yhyue.com/moapp/jybase/mail"
 	"app.yhyue.com/moapp/jypkg/common/src/qfw/util/middleGround"
 	"app.yhyue.com/moapp/jypkg/compatible"
+	ma "app.yhyue.com/moapp/jypkg/marketanalysis"
 	"app.yhyue.com/moapp/jypkg/middleground"
 	"github.com/gogf/gf/v2/frame/g"
 	"github.com/gogf/gf/v2/os/gcfg"
@@ -139,4 +140,13 @@ func init() {
 	if Config.RestrictionSwitch {
 		restriction.ReqLimitInit(Config.RestrictionDoPool, Config.RestrictionWaitPool)
 	}
+	//定制化报告
+	ptIndex := g.Cfg().MustGet(gctx.New(), "ma.index").String()
+	ptType := g.Cfg().MustGet(gctx.New(), "ma.type").String()
+	fields := g.Cfg().MustGet(gctx.New(), "ma.fields").Strings()
+	minKCount := g.Cfg().MustGet(gctx.New(), "ma.minKCount").Int()
+	maxPCount := g.Cfg().MustGet(gctx.New(), "ma.maxPCount").Int()
+	bwCount := g.Cfg().MustGet(gctx.New(), "ma.bwCount").Int()
+	bwdCount := g.Cfg().MustGet(gctx.New(), "ma.bwdCount").Int()
+	ma.MAInit(Config.MarketAnalysisPool.Limit, Config.MarketAnalysisPool.TimeOut, Config.MarketAnalysisPool.ProjectNumLimit, Config.MarketAnalysisPool.KeyWordsCount, Config.ProjectCount, minKCount, maxPCount, bwCount, bwdCount, ptIndex, ptType, fields)
 }

+ 1 - 1
src/jfw/modules/bigmember/src/db.json

@@ -1,7 +1,7 @@
 {
   "mongodb": {
     "main": {
-      "address": "192.168.3.206:27080",
+      "address": "192.168.3.149:27180",
       "size": 5,
       "dbName": "qfw",
       "replSet": ""

+ 5 - 26
src/jfw/modules/bigmember/src/entity/marketAnalysis/analysisPdf.go

@@ -8,6 +8,7 @@ import (
 	"app.yhyue.com/moapp/jybase/go-xweb/xweb"
 	"app.yhyue.com/moapp/jybase/mongodb"
 	"app.yhyue.com/moapp/jypkg/common/src/qfw/util/jy"
+	ma "app.yhyue.com/moapp/jypkg/marketanalysis"
 	"fmt"
 	"github.com/gogf/gf/v2/util/gconv"
 	. "jy/src/jfw/modules/bigmember/src/config"
@@ -154,7 +155,7 @@ func (this *AnalysisReportPdf) GetPdfDetail() {
 			userId := qutil.ObjToString(sessVal["userId"])
 			go func() { //分析数据
 				wait.Done()
-				mae := &MarketAnalysisEntity{MgoRecordId: qutil.InterfaceToStr(getQueryMap["rid"]), UId: userId, Pid: pid, MgoUserId: qutil.ObjToString(sessVal["mgoUserId"]), PositionId: qutil.IntAll(sessVal["positionId"])}
+				mae := &ma.AnalysisEntity{MgoRecordId: qutil.InterfaceToStr(getQueryMap["rid"]), UId: userId, Pid: pid, MgoUserId: qutil.ObjToString(sessVal["mgoUserId"]), PositionId: qutil.Int64All(sessVal["positionId"]), Mgo: &db.Mgo, MySql: db.Mysql}
 				rDataMap, err := mae.GetPdfPageApi()
 				if err != nil {
 					log.Println("GetPdfPageApi", err.Error())
@@ -167,7 +168,7 @@ func (this *AnalysisReportPdf) GetPdfDetail() {
 			}()
 			go func() { //项目明细
 				defer wait.Done()
-				mae := &MarketAnalysisEntity{MgoRecordId: qutil.InterfaceToStr(getQueryMap["rid"]), UId: userId, Pid: pid, MgoUserId: qutil.ObjToString(sessVal["mgoUserId"]), PositionId: qutil.IntAll(sessVal["positionId"])}
+				mae := &ma.AnalysisEntity{MgoRecordId: qutil.InterfaceToStr(getQueryMap["rid"]), UId: userId, Pid: pid, MgoUserId: qutil.ObjToString(sessVal["mgoUserId"]), PositionId: qutil.Int64All(sessVal["positionId"]), Mgo: &db.Mgo, MySql: db.Mysql}
 				err = mae.GetAnalysisFromMgoDb()
 				if err != nil {
 					log.Println("GetAnalysisFromMgoDb err", err.Error())
@@ -321,28 +322,6 @@ func (this *AnalysisReportPdf) GetPdfDetail() {
 	this.ServeJson(NewResult(rData, errMsg))
 }
 
-func (me *MarketAnalysisEntity) GetPdfPageApi() (finalDate map[string]interface{}, err error) {
-	var (
-		wg   = sync.WaitGroup{}
-		lock = &sync.Mutex{}
-	)
-	finalDate = make(map[string]interface{})
-	for i := 1; i <= 5; i++ {
-		wg.Add(1)
-		go func(flag int) {
-			defer wg.Done()
-			mgoData, _ := me.GetMongoData(flag)
-			lock.Lock()
-			for s, i2 := range mgoData {
-				finalDate[s] = i2
-			}
-			lock.Unlock()
-		}(i)
-	}
-	wg.Wait()
-	return
-}
-
 func (this *AnalysisReportPdf) PdfSave() {
 	sessVal := this.Session().GetMultiple()
 	userId := qutil.ObjToString(sessVal["userId"])
@@ -372,7 +351,7 @@ func (this *AnalysisReportPdf) PdfSave() {
 			return
 		}
 		pid, _, _ := CheckPowerEquity(this.Session())
-		mae := &MarketAnalysisEntity{MgoRecordId: rid, UId: userId, Pid: pid, MgoUserId: qutil.ObjToString(sessVal["mgoUserId"]), PositionId: qutil.IntAll(sessVal["positionId"])}
+		mae := &ma.AnalysisEntity{MgoRecordId: rid, UId: userId, Pid: pid, MgoUserId: qutil.ObjToString(sessVal["mgoUserId"]), PositionId: qutil.Int64All(sessVal["positionId"]), Mgo: &db.Mgo, MySql: db.Mysql}
 		queryMap := map[string]interface{}{
 			"_id":   mongodb.StringTOBsonId(mae.MgoRecordId),
 			"i_del": map[string]interface{}{"$ne": 1},
@@ -382,7 +361,7 @@ func (this *AnalysisReportPdf) PdfSave() {
 		} else {
 			queryMap["s_userId"] = mae.UId
 		}
-		resData, _ := db.Mgo.FindOne(ReportHistoryTable, queryMap)
+		resData, _ := db.Mgo.FindOne(ma.ReportHistoryTable, queryMap)
 		if resData == nil || len(*resData) == 0 {
 			this.ServeJson(NewResult(nil, fmt.Errorf("定制化分析异常")))
 			return

+ 0 - 153
src/jfw/modules/bigmember/src/entity/marketAnalysis/commonSearch.go

@@ -1,153 +0,0 @@
-package marketAnalysis
-
-import (
-	qutil "app.yhyue.com/moapp/jybase/common"
-	elastic "app.yhyue.com/moapp/jybase/es"
-	mgo "app.yhyue.com/moapp/jybase/mongodb"
-	"fmt"
-	"strings"
-)
-
-const (
-	query_bool_must_and = `{"bool": {"must": [%s]%s}}`
-	PSearch_DecMust     = `"bidstatus": ["中标","成交","合同","单一"]`
-	query_bool_must     = `{"terms": {%s}}`
-)
-
-// GetCommonQuerySql 公共筛选
-func (mae *MarketAnalysisEntity) GetCommonQuerySql() string {
-	var musts, bools []string
-	//时间
-	musts = append(musts, fmt.Sprintf(`{"range":{"jgtime":{"gte":%d,"lte":%d}}}`, mae.FormatParam.STime, mae.FormatParam.ETime))
-	//地区
-	if len(mae.FormatParam.Area) > 0 || len(mae.FormatParam.City) > 0 {
-		var areaCity []string
-		if len(mae.FormatParam.Area) > 0 {
-			areaCity = append(areaCity, fmt.Sprintf(`{"terms":{"area":["%s"]}}`, strings.Join(mae.FormatParam.Area, `","`)))
-		}
-		if len(mae.FormatParam.City) > 0 {
-			areaCity = append(areaCity, fmt.Sprintf(`{"terms":{"city":["%s"]}}`, strings.Join(mae.FormatParam.City, `","`)))
-		}
-		musts = append(musts, fmt.Sprintf(`{"bool":{"should":[%s],"minimum_should_match": 1}}`, strings.Join(areaCity, ",")))
-	}
-	//行业
-	if len(mae.FormatParam.Industry) > 0 {
-		musts = append(musts, fmt.Sprintf(`{"terms":{"subscopeclass":["%s"]}}`, strings.Join(mae.FormatParam.Industry, `","`)))
-	}
-	//类型
-	if len(mae.FormatParam.BuyerClass) > 0 {
-		musts = append(musts, fmt.Sprintf(`{"terms":{"buyerclass":["%s"]}}`, strings.Join(mae.FormatParam.BuyerClass, `","`)))
-	}
-	//分析报告中标状态限制
-	musts = append(musts, fmt.Sprintf(query_bool_must, PSearch_DecMust))
-	//订阅词
-	for _, v := range getAllKeywordArr(mae.FormatParam.KeysItems) {
-		if sql := getKeyWordSql(v, mae.BaseParam.MatchingMode); sql != "" {
-			bools = append(bools, sql)
-		}
-	}
-	//中标企业
-	if mae.FormatParam.Winner != "" {
-		var winnerId string
-		if mgo.IsObjectIdHex(mae.FormatParam.Winner) {
-			winnerId = mae.FormatParam.Winner
-		} else {
-			rData := elastic.Get("qyxy", "qyxy", fmt.Sprintf(`{"query": {"bool": {"must": [{"term": {"company_name": "%s"}}]}},"_source":["_id"],"size": 1}`, mae.FormatParam.Winner))
-			if rData != nil && len(*rData) > 0 {
-				winnerId = qutil.InterfaceToStr((*rData)[0]["_id"])
-			}
-		}
-		if winnerId != "" {
-			musts = append(musts, fmt.Sprintf(`{"term":{"entidlist":"%s"}}`, winnerId))
-		} else {
-			musts = append(musts, fmt.Sprintf(`{"term":{"s_winner":"%s"}}`, mae.FormatParam.Winner))
-		}
-	}
-	//采购单位
-	if mae.FormatParam.Buyer != "" {
-		musts = append(musts, fmt.Sprintf(`{"term":{"buyer":"%s"}}`, mae.FormatParam.Buyer))
-	}
-	return fmt.Sprintf(`{"query":{"bool":{"must":[%s],"should":[%s],"minimum_should_match": %d}}%s}`, strings.Join(musts, ","), strings.Join(bools, ","), qutil.If(len(bools) > 0, 1, 0).(int), "%s")
-}
-
-// GetCommonQuerySqlWithAggs 此方法用于聚合查询
-func (mae *MarketAnalysisEntity) GetCommonQuerySqlWithAggs() string {
-	return fmt.Sprintf(mae.GetCommonQuerySql(), `,"aggs":{%s},"size":0`)
-}
-
-// getGroupKeywordArr 模糊拆分为多个精准匹配
-func getGroupKeywordArr(res []viewKeyWord) (rData []viewKeyWord) {
-	for _, kw := range res {
-		if kw.MatchWay == 1 {
-			for _, kk := range kw.Keyword {
-				rData = append(rData, viewKeyWord{
-					Keyword: []string{kk},
-					Exclude: kw.Exclude,
-				})
-			}
-			for _, kk := range kw.Appended {
-				rData = append(rData, viewKeyWord{
-					Keyword: []string{kk},
-					Exclude: kw.Exclude,
-				})
-			}
-		} else {
-			rData = append(rData, kw)
-		}
-	}
-	return
-}
-
-// getAllKeywordArr 获取所有匹配词
-func getAllKeywordArr(res []keyWordGroup) (rData []viewKeyWord) {
-	for _, kwg := range res {
-		rData = append(rData, getGroupKeywordArr(kwg.A_Key)...)
-	}
-	return
-}
-
-func getKeyWordSql(v viewKeyWord, matchingMode string) string {
-	var (
-		shoulds, must_not []string
-		//默认查询项目名称与标的物
-		localMultiMatch = `{"multi_match": {"query": %s,"type": "phrase", "fields": ["purchasing","projectname.pname"]}}`
-	)
-	if matchingMode == "title" { //只匹配项目名称
-		localMultiMatch = `{"multi_match": {"query": %s,"type": "phrase", "fields": ["projectname.pname"]}}`
-	}
-	//附加词
-	for _, vv := range v.Keyword {
-		vv = strings.TrimSpace(vv)
-		if vv == "" {
-			continue
-		}
-		shoulds = append(shoulds, fmt.Sprintf(localMultiMatch, "\""+vv+"\""))
-	}
-
-	for _, vv := range v.Appended {
-		vv = strings.TrimSpace(vv)
-		if vv == "" {
-			continue
-		}
-		shoulds = append(shoulds, fmt.Sprintf(localMultiMatch, "\""+vv+"\""))
-	}
-
-	//排除词
-	for _, vv := range v.Exclude {
-		vv = strings.TrimSpace(vv)
-		if vv == "" {
-			continue
-		}
-		must_not = append(must_not, fmt.Sprintf(localMultiMatch, "\""+vv+"\""))
-	}
-
-	//添加
-	if len(shoulds) > 0 {
-		notStr := ""
-		if len(must_not) > 0 {
-			notStr = fmt.Sprintf(`,"must_not":[%s]`, strings.Join(must_not, ","))
-		}
-		return fmt.Sprintf(query_bool_must_and, strings.Join(shoulds, ","), notStr)
-	}
-	return ""
-}

+ 0 - 975
src/jfw/modules/bigmember/src/entity/marketAnalysis/customizad_distribution.go

@@ -1,975 +0,0 @@
-package marketAnalysis
-
-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"
-	"math"
-	"strings"
-	"sync"
-	"time"
-
-	elastic "app.yhyue.com/moapp/jybase/es"
-)
-
-const (
-	//市场分析聚合查询
-	aggs_market_analysis = `"%s": {"range": {"field": "jgtime","ranges": [%s]},"aggs":{"project_count": {"filter": {"match_all":{}}},"project_amount":{"sum":{"field":"sortprice"}},"project_avgMoney": { "avg": {"field": "sortprice","missing": 0}} ,"buyer_count":{"cardinality":{"field":"buyer"}},"winner_count":{"cardinality":{"field":"s_winner"}}}}`
-	//aggs_market_analysis = `"%s": {"range": {"field": "jgtime","ranges": [%s]},"aggs":{"project_count": {"filter": {"match_all":{}}},"project_amount":{"sum":{"field":"sortprice"}},"project_avgMoney": {"filter": {"range": {"sortprice": {"gt": 0}}},"aggs": {"avg_amount": {"avg": {"field": "sortprice"}}}} ,"buyer_count":{"cardinality":{"field":"buyer"}},"winner_count":{"cardinality":{"field":"s_winner"}}}}`
-	//aggs_market_analysis = `"%s": {"range": {"field": "firsttime","ranges": [%s]},"aggs":{"project_count": {"filter": {"range": {"sortprice": {"gt": 0}}}},"project_amount":{"sum":{"field":"sortprice"}},"project_avgMoney": {"filter": {"range": {"sortprice": {"gt": 0}}},"aggs": {"avg_amount": {"avg": {"field": "sortprice"}}}},"buyer_count":{"filter": {"range": {"sortprice": {"gt": 0}}},"aggs": {"cardinality_buyer_count": {"cardinality": {"field": "buyer"}}}},"winner_count":{"filter": {"range": {"sortprice": {"gt": 0}}},"aggs": {"cardinality_winner_count": {"cardinality": {"field": "s_winner"}}}}}}`
-
-	//时间分布统计
-	project_time_distribution = `"%s": {"range": { "field": "jgtime","ranges": [%s]},"aggs":{ "scale_amount": {"sum": {"field": "sortprice"}}, "scale_total": {"filter": {"match_all":{}}}}}`
-
-	//采购单位聚合查询
-	//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 = `"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"}}}}}}`
-	//采购单位top3(数量)
-	//buyer_count = `"buyer_count_top3": {"terms": {"field": "buyer","order": [{"buyer_count": "desc"}],"size": 3},"aggs": {"buyer_count": {"cardinality": {"field": "buyer"}},"s_winner_top": {"terms": {"field": "s_winner","order": [{"buyer_winner_count": "desc"}],"size": 3},"aggs": {"buyer_winner_count": {"cardinality": {"field": "s_winner"}}}}}}`
-	buyer_count = `"buyer_count_top3": {"terms": {"field": "buyer","order": [{"buyer_count": "desc"}],"size": 30},"aggs": {"buyer_count": {"filter":{"match_all":{}}},"s_winner_top": {"terms": {"field": "entidlist","exclude":["-"],"order": [{"buyer_winner_count": "desc"}],"size": 3},"aggs": { "buyer_winner_count": {"filter":{"match_all":{}}}}}}}`
-
-	//中标单位
-	//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": {"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"}}}}}}`
-	//中标单位(数量)
-	//winner_count = `"winner_count_top3": {"terms": {"field": "s_winner","order": [{"s_winner_count": "desc"}],"size": 3},"aggs": {"s_winner_count": {"cardinality": {"field": "s_winner"}},"buyer_top": {"terms": {"field": "buyer","order": [{"buyer_winner_count": "desc"}],"size": 3},"aggs": {"buyer_winner_count": {"cardinality": {"field": "buyer"}}}}}}`
-	winner_count = `"winner_count_top3": {"terms": {"field": "entidlist","exclude":["-"],"order": [{"s_winner_count": "desc"}],"size": 30},"aggs": {"s_winner_count": {"filter":{"match_all":{}}},"buyer_top": {"terms": {"field": "buyer","order": [{"buyer_winner_count": "desc"}],"size": 3},"aggs": {"buyer_winner_count": {"filter":{"match_all":{}}}}}}}`
-)
-
-var y_m_day = map[int]int{1: 31, 2: 28, 3: 31, 4: 30, 5: 31, 6: 30, 7: 31, 8: 31, 9: 30, 10: 31, 11: 30, 12: 31}
-
-type SWinner struct {
-	Buckets []struct {
-		Key               string `json:"key"`
-		DocCount          int    `json:"doc_count"`
-		BuyerWinnerAmount struct {
-			Value float64 `json:"value"`
-		} `json:"buyer_winner_amount"`
-	} `json:"buckets"`
-}
-
-func getPreviousMarket(sTime, eTime time.Time) int64 {
-	var os_time int64
-	s_time := sTime
-	if SEMonth(sTime, eTime) {
-		var min int
-		//统计月份
-		for sTime.Before(eTime) {
-			sTime = sTime.AddDate(0, 1, 0)
-			min++
-		}
-		os_time = s_time.AddDate(0, -min, 0).Unix()
-	} else {
-		os_time = s_time.AddDate(0, 0, -int(math.Ceil(eTime.Sub(sTime).Hours()/24))).Unix()
-	}
-
-	return os_time
-}
-
-// 判断是否月初到月末
-func SEMonth(sTime, eTime time.Time) bool {
-	var day int
-	month := int(eTime.Month())
-	if month == 2 {
-		if eTime.Year()%4 == 0 {
-			day = 29
-		} else {
-			day = 28
-		}
-	} else {
-		day = y_m_day[month]
-	}
-
-	if sTime.Day() == 1 && eTime.Day() == day {
-		return true
-	}
-	return false
-}
-
-func Rest(res esV7.Aggregations, thisRow *marketTime) {
-	for name, object := range res {
-		bArr, err := object.MarshalJSON()
-		if len(bArr) == 0 || err != nil {
-			continue
-		}
-		if name == "thismarket" {
-			if json.Unmarshal(bArr, &thisRow.Thismarket) != nil {
-				continue
-			}
-		} else if name == "oldmarket" {
-			if json.Unmarshal(bArr, &thisRow.Oldmarket) != nil {
-				continue
-			}
-		} else if name == "monthtime" {
-			if json.Unmarshal(bArr, &thisRow.Monthtime) != nil {
-				continue
-			}
-		} else if name == "yeartime" {
-			if json.Unmarshal(bArr, &thisRow.Yeartime) != nil {
-				continue
-			}
-		}
-	}
-}
-
-func GetMonthData(sTime, eTime time.Time) (bool, string) {
-	var _b bool
-	//整月多取一个月进行环比
-	if SEMonth(sTime, eTime) {
-		_b = true
-		sTime = sTime.AddDate(0, -1, 0)
-	}
-
-	return _b, getBidamountStatistics(sTime, eTime)
-}
-
-func getBidamountStatistics(sTime, eTime time.Time) string {
-	timeRange := ``
-	tmpTime, rTime, tEndTime := sTime, sTime, getMonthRange(eTime, false)
-	for rTime.Before(tEndTime) {
-		ts, te := getMonthRange(tmpTime, true), getMonthRange(tmpTime, false)
-		if sTime == tmpTime {
-			ts = sTime
-		}
-		if te == tEndTime {
-			te = eTime
-		}
-		if ts.Before(te) {
-			timeRange += fmt.Sprintf(`{"key":"%s","from":%d,"to":%d},`, fmt.Sprintf("%d-%d", ts.Year(), ts.Month()), ts.Unix(), te.Unix())
-		}
-		rTime = rTime.AddDate(0, 1, 0)
-		if int(rTime.Month())-int(tmpTime.Month()) > 1 {
-			rTime = rTime.AddDate(0, -1, 0)
-		}
-		tmpTime = rTime
-	}
-	if timeRange == `` {
-		return ""
-	}
-	return timeRange[:len(timeRange)-1]
-}
-
-// getMonthRange获取月份范围
-// isStart true本月月初  false 本月月末(下月月初)
-func getMonthRange(t time.Time, isStart bool) time.Time {
-	if isStart {
-		return time.Date(t.Year(), t.Month(), 1, 0, 0, 0, 0, t.Location())
-	}
-	return time.Date(t.Year(), t.Month()+1, 1, 0, 0, 0, 0, t.Location())
-}
-
-func GetYearData(sTime, eTime time.Time) (bool, string) {
-	var _b bool
-	//整月多取一个月进行环比
-	if sTime.Month() == 1 && sTime.Day() == 1 && eTime.Month() == 12 && eTime.Day() == 31 {
-		_b = true
-		sTime = sTime.AddDate(-1, 0, 0)
-	}
-	return _b, getCommonYearStatistics(sTime, eTime)
-}
-
-// getYearRange获取月份范围
-// isStart true本月月初  false 本月月末(下月月初)
-func getYearRange(t time.Time, isStart bool) time.Time {
-	if isStart {
-		return time.Date(t.Year(), 1, 1, 0, 0, 0, 0, t.Location())
-	}
-	return time.Date(t.Year()+1, 1, 1, 0, 0, 0, 0, t.Location())
-}
-
-// 年份统计
-func getCommonYearStatistics(sTime, eTime time.Time) string {
-	timeRange := ``
-	tmpTime, rTime, tEndTime := sTime, sTime, getYearRange(eTime, false)
-	for rTime.Before(tEndTime) {
-		ts, te := getYearRange(tmpTime, true), getYearRange(tmpTime, false)
-		if sTime == tmpTime {
-			ts = sTime
-		}
-		if te == tEndTime {
-			te = eTime
-		}
-		if ts.Before(te) {
-			timeRange += fmt.Sprintf(`{"key":"%d","from":%d,"to":%d},`, ts.Year(), ts.Unix(), te.Unix())
-		}
-		rTime = rTime.AddDate(1, 0, 0)
-		tmpTime = rTime
-	}
-	if timeRange == `` {
-		return ""
-	}
-	return timeRange[:len(timeRange)-1]
-}
-
-type marketTime struct {
-	Thismarket struct {
-		Buckets []marketBuckets `json:"buckets"`
-	} `json:"thismarket"`
-	Oldmarket struct {
-		Buckets []marketBuckets `json:"buckets"`
-	} `json:"oldmarket"`
-	Monthtime struct {
-		Buckets []Buckets `json:"buckets"`
-	} `json:"monthtime"`
-	Yeartime struct {
-		Buckets []Buckets `json:"buckets"`
-	} `json:"yeartime"`
-}
-type marketBuckets struct {
-	ProjectCount struct {
-		DocCount int `json:"doc_count"`
-	} `json:"project_count"`
-	ProjectAmount struct {
-		Value float64 `json:"value"`
-	} `json:"project_amount"`
-	BuyerCount struct {
-		Value int `json:"value"`
-	} `json:"buyer_count"`
-	WinnerCount struct {
-		Value int `json:"value"`
-	} `json:"winner_count"`
-	ProjectAvgMoney struct {
-		//DocCount  int `json:"doc_count"`
-		//AvgAmount struct {
-		//	Value float64 `json:"value"`
-		//} `json:"avg_amount"`
-		Value float64 `json:"value"`
-	} `json:"project_avgMoney"`
-}
-type Buckets struct {
-	Key          string `json:"key"`
-	From         int    `json:"from"`
-	FromAsString string `json:"from_as_string"`
-	To           int    `json:"to"`
-	ToAsString   string `json:"to_as_string"`
-	DocCount     int    `json:"doc_count"`
-	ScaleTotal   struct {
-		DocCount int `json:"doc_count"`
-	} `json:"scale_total"`
-	ScaleAmount struct {
-		Value float64 `json:"value"`
-	} `json:"scale_amount"`
-}
-
-func sequential(now, old float64) interface{} {
-	if old == 0 {
-		return nil
-	}
-	return (now - old) / old
-}
-
-// 市场概况+时间分布
-func (mae *MarketAnalysisEntity) MarketTime() (map[string]interface{}, error) {
-	var (
-		sql                   []string
-		monthB, yearB         bool
-		MonthRange, YearRange string
-	)
-	sql = append(sql, fmt.Sprintf(aggs_market_analysis, "thismarket", fmt.Sprintf(`{"key":"%s","from":%d,"to":%d}`, "market", mae.FormatParam.STime, mae.FormatParam.ETime)))
-	n_stime := mae.FormatParam.STime
-	var n_mae MarketAnalysisEntity
-	n_mae.FormatParam = mae.FormatParam
-	n_mae.BaseParam = mae.BaseParam
-	n_mae.MgoRecordId = mae.MgoRecordId
-	n_mae.FormatParam.ETime = mae.FormatParam.ETime
-	if time.Unix(mae.FormatParam.STime, 0).AddDate(1, 0, 0).Unix() >= time.Unix(mae.FormatParam.ETime, 0).Unix() {
-		n_stime = getPreviousMarket(time.Unix(mae.FormatParam.STime, 0), time.Unix(mae.FormatParam.ETime, 0))
-		sql = append(sql, fmt.Sprintf(aggs_market_analysis, "oldmarket", fmt.Sprintf(`{"key":"%s","from":%d,"to":%d}`, "market", n_stime, mae.FormatParam.STime)))
-	}
-
-	if time.Unix(mae.FormatParam.STime, 0).AddDate(0, 1, 0).Unix() < time.Unix(mae.FormatParam.ETime, 0).Unix() {
-		var mon_time, year_time int64
-		stime, etime := time.Unix(mae.FormatParam.STime, 0), time.Unix(mae.FormatParam.ETime, 0)
-		monthB, MonthRange = GetMonthData(stime, etime)
-		sql = append(sql, fmt.Sprintf(project_time_distribution, "monthtime", MonthRange))
-		if monthB {
-			mon_time = stime.AddDate(0, -1, 0).Unix()
-		} else {
-			mon_time = mae.FormatParam.STime
-		}
-		//年度数据
-		yearB, YearRange = GetYearData(stime, etime)
-		sql = append(sql, fmt.Sprintf(project_time_distribution, "yeartime", YearRange))
-		if yearB {
-			year_time = stime.AddDate(-1, 0, 0).Unix()
-		} else {
-			year_time = mae.FormatParam.STime
-		}
-
-		if n_stime > mon_time {
-			n_stime = mon_time
-		}
-		if n_stime > year_time {
-			n_stime = year_time
-		}
-	}
-
-	n_mae.FormatParam.STime = n_stime
-	finalSql := fmt.Sprintf(n_mae.GetCommonQuerySqlWithAggs(), strings.Join(sql, ","))
-	log.Printf("final marketScaleRefineQuery sql: %s", finalSql)
-	rMap := make(map[string]interface{})
-	rMapData := make(map[string]interface{})
-	thisRow := marketTime{}
-	res := util.GetAggs("projectset", "projectset", finalSql)
-	if res == nil || len(res) == 0 {
-		return nil, fmt.Errorf("未查询到项目")
-	}
-	Rest(res, &thisRow)
-	if thisRow.Thismarket.Buckets != nil && len(thisRow.Thismarket.Buckets) != 0 {
-		Projectmarket := thisRow.Thismarket.Buckets[0]
-		if Projectmarket.ProjectCount.DocCount == 0 {
-			return nil, fmt.Errorf("未查询到项目数据")
-		}
-		if Projectmarket.ProjectCount.DocCount > config.Config.MarketAnalysisPool.ProjectNumLimit {
-			return nil, fmt.Errorf("项目数量超出上限")
-		}
-		rMapData["project_count"] = Projectmarket.ProjectCount.DocCount
-		rMapData["projctamout"] = Projectmarket.ProjectAmount.Value
-		rMapData["projectavgmoney"] = Projectmarket.ProjectAvgMoney.Value
-		rMapData["buyercount"] = Projectmarket.BuyerCount.Value
-		rMapData["winnercount"] = Projectmarket.WinnerCount.Value
-		if thisRow.Oldmarket.Buckets != nil && len(thisRow.Oldmarket.Buckets) != 0 {
-			oldProjectmarket := thisRow.Oldmarket.Buckets[0]
-			//环比数据
-			rMapData["projctamount_ratio"] = sequential(Projectmarket.ProjectAmount.Value, oldProjectmarket.ProjectAmount.Value)
-			rMapData["project_count_ratio"] = sequential(float64(Projectmarket.ProjectCount.DocCount), float64(oldProjectmarket.ProjectCount.DocCount))
-			rMapData["projectavgmoney_ratio"] = sequential(Projectmarket.ProjectAvgMoney.Value, oldProjectmarket.ProjectAvgMoney.Value)
-			rMapData["buyercount_ratio"] = sequential(float64(Projectmarket.BuyerCount.Value), float64(oldProjectmarket.BuyerCount.Value))
-			rMapData["winnercount_ratio"] = sequential(float64(Projectmarket.WinnerCount.Value), float64(oldProjectmarket.WinnerCount.Value))
-		}
-	}
-	rMap["market_profile"] = rMapData
-
-	if thisRow.Monthtime.Buckets != nil && len(thisRow.Monthtime.Buckets) != 0 {
-		rMap["month_distribution"] = n_mae.TimeData(monthB, thisRow.Monthtime.Buckets)
-	}
-	if thisRow.Yeartime.Buckets != nil && len(thisRow.Yeartime.Buckets) != 0 {
-		rMap["year_distribution"] = n_mae.TimeData(yearB, thisRow.Yeartime.Buckets)
-	}
-	return rMap, nil
-}
-
-// 时间分布月,年通用数据处理
-func (mae *MarketAnalysisEntity) TimeData(_b bool, thisRow []Buckets) map[string]interface{} {
-	var count_ss, amout_ss []map[string]interface{}
-
-	for k, v := range thisRow {
-		//环比多取一期数据
-		if _b && k == 0 {
-			continue
-		}
-		count := make(map[string]interface{})
-		amount := make(map[string]interface{})
-		count["minth"] = v.Key
-		count["value"] = v.ScaleTotal.DocCount
-		amount["minth"] = v.Key
-		amount["value"] = v.ScaleAmount.Value
-		//整月,年统计环比
-		if _b {
-			doccount := thisRow[k-1].ScaleTotal.DocCount
-			amountvalue := thisRow[k-1].ScaleAmount.Value
-
-			count["ratio"] = sequential(float64(v.ScaleTotal.DocCount), float64(doccount))
-			amount["ratio"] = sequential(v.ScaleAmount.Value, amountvalue)
-		}
-		count_ss = append(count_ss, count)
-		amout_ss = append(amout_ss, amount)
-	}
-	rMapData := make(map[string]interface{})
-	rMapData["project_count"] = count_ss
-	rMapData["project_amount"] = amout_ss
-	return rMapData
-}
-
-func amountDistribution(v float64, data map[string]*distributionTrend) {
-	if v <= 0 {
-		return
-	}
-	if v < 100000 {
-		if data["<10万"] == nil {
-			data["<10万"] = new(distributionTrend)
-		}
-		data["<10万"].Amount += v
-		data["<10万"].Count++
-	} else if v < 500000 {
-		if data["10万~50万"] == nil {
-			data["10万~50万"] = new(distributionTrend)
-		}
-		data["10万~50万"].Amount += v
-		data["10万~50万"].Count++
-	} else if v < 1000000 {
-		if data["50万~100万"] == nil {
-			data["50万~100万"] = new(distributionTrend)
-		}
-		data["50万~100万"].Amount += v
-		data["50万~100万"].Count++
-	} else if v < 1000000*5 {
-		if data["100万~500万"] == nil {
-			data["100万~500万"] = new(distributionTrend)
-		}
-		data["100万~500万"].Amount += v
-		data["100万~500万"].Count++
-	} else if v < 1000000*10 {
-		if data["500万~1000万"] == nil {
-			data["500万~1000万"] = new(distributionTrend)
-		}
-		data["500万~1000万"].Amount += v
-		data["500万~1000万"].Count++
-	} else if v < 100000000 {
-		if data["1000万~1亿"] == nil {
-			data["1000万~1亿"] = new(distributionTrend)
-		}
-		data["1000万~1亿"].Amount += v
-		data["1000万~1亿"].Count++
-	} else if v >= 100000000 {
-		if data["≥1亿"] == nil {
-			data["≥1亿"] = new(distributionTrend)
-		}
-		data["≥1亿"].Amount += v
-		data["≥1亿"].Count++
-	}
-
-}
-
-type BuyerWinnerRow struct {
-	BuyerAmountDistribution struct {
-		Buckets []struct {
-			Key      string `json:"key"`
-			DocCount int    `json:"doc_count"`
-			Amount   struct {
-				Value float64 `json:"value"`
-			} `json:"amount"`
-		} `json:"buckets"`
-	} `json:"buyer_amount_distribution"`
-
-	ProjectAmount struct {
-		Value float64 `json:"value"`
-	} `json:"project_amount"`
-	BuyerCountTop3 struct {
-		Buckets []struct {
-			Key        string `json:"key"`
-			BuyerCount struct {
-				//Value int64 `json:"value"`
-				Value int64 `json:"doc_count"`
-			} `json:"buyer_count"`
-			SWinnerTop struct {
-				Buckets []struct {
-					Key           string `json:"key"`
-					DocCount      int64  `json:"doc_count"`
-					ProjectDetail struct {
-						Hits struct {
-							Total    int `json:"total"`
-							MaxScore int `json:"max_score"`
-							Hits     []struct {
-								Source struct {
-									Entidlist []string `json:"entidlist"`
-									SWinner   string   `json:"s_winner"`
-								} `json:"_source"`
-							} `json:"hits"`
-						} `json:"hits"`
-					} `json:"project_detail"`
-					BuyerWinnerAmount struct {
-						//Value int64 `json:"value"`
-						Value int64 `json:"doc_count"`
-					} `json:"buyer_winner_count"`
-				} `json:"buckets"`
-				Value float64 `json:"value"`
-			} `json:"s_winner_top"`
-		} `json:"buckets"`
-	} `json:"buyer_count_top3"`
-	BuyerAmountTop3 struct {
-		Buckets []struct {
-			Key         string `json:"key"`
-			BuyerAmount struct {
-				Value float64 `json:"value"`
-			} `json:"buyer_amount"`
-			SWinnerTop struct {
-				Buckets []struct {
-					Key           string `json:"key"`
-					DocCount      int64  `json:"doc_count"`
-					ProjectDetail struct {
-						Hits struct {
-							Total    int `json:"total"`
-							MaxScore int `json:"max_score"`
-							Hits     []struct {
-								Source struct {
-									Entidlist []string `json:"entidlist"`
-									SWinner   string   `json:"s_winner"`
-								} `json:"_source"`
-							} `json:"hits"`
-						} `json:"hits"`
-					} `json:"project_detail"`
-					BuyerWinnerAmount struct {
-						Value float64 `json:"value"`
-					} `json:"buyer_winner_amount"`
-				} `json:"buckets"`
-				Value float64 `json:"value"`
-			} `json:"s_winner_top"`
-		} `json:"buckets"`
-	} `json:"buyer_amount_top3"`
-
-	WinnerAmountDistribution struct {
-		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"`
-			ProjectDetail struct {
-				Hits struct {
-					Total    int `json:"total"`
-					MaxScore int `json:"max_score"`
-					Hits     []struct {
-						Id     string `json:"_id"`
-						Source struct {
-							Entidlist []string `json:"entidlist"`
-							SWinner   string   `json:"s_winner"`
-						} `json:"_source"`
-					} `json:"hits"`
-				} `json:"hits"`
-			} `json:"project_detail"`
-			BuyerCount struct {
-				//Value int64 `json:"value"`
-				Value int64 `json:"doc_count"`
-			} `json:"s_winner_count"`
-			BuyerTop struct {
-				Buckets []struct {
-					Key               string `json:"key"`
-					DocCount          int64  `json:"doc_count"`
-					BuyerWinnerAmount struct {
-						//Value int64 `json:"value"`
-						Value int64 `json:"doc_count"`
-					} `json:"buyer_winner_count"`
-				} `json:"buckets"`
-				Value float64 `json:"value"`
-			} `json:"buyer_top"`
-		} `json:"buckets"`
-	} `json:"winner_count_top3"`
-	WinnerAmountTop3 struct {
-		SWinnerAmount []struct {
-			Key           string `json:"key"`
-			ProjectDetail struct {
-				Hits struct {
-					Total    int `json:"total"`
-					MaxScore int `json:"max_score"`
-					Hits     []struct {
-						Source struct {
-							Entidlist []string `json:"entidlist"`
-							SWinner   string   `json:"s_winner"`
-						} `json:"_source"`
-					} `json:"hits"`
-				} `json:"hits"`
-			} `json:"project_detail"`
-			SWinnerAmount struct {
-				Value float64 `json:"value"`
-			} `json:"s_winner_amount"`
-			BuyerTop struct {
-				Buckets []struct {
-					Key               string `json:"key"`
-					DocCount          int64  `json:"doc_count"`
-					BuyerWinnerAmount struct {
-						Value float64 `json:"value"`
-					} `json:"buyer_winner_amount"`
-				} `json:"buckets"`
-				Value float64 `json:"value"`
-			} `json:"buyer_top"`
-		} `json:"buckets"`
-	} `json:"winner_amount_top3"`
-}
-
-// 采购单位分析
-func (mae *MarketAnalysisEntity) BuyerWinnerAnalysis() map[string]interface{} {
-	var datas []string
-	//采购单位-采购规模分布
-	//buyer_scalefmt := fmt.Sprintf(buyer_procurement_scale, sortprice_str)
-
-	//采购单位-项目数量 采购单位-项目金额
-	datas = append(datas, buyer_procurement_scale, buyer_count, buyer_sortprice)
-	//中标单位-规模分布
-	//winner_scalefmt := fmt.Sprintf(winner_procurement_scale, sortprice_str)
-
-	//中标单位-项目数量 中标单位-项目金额
-	datas = append(datas, winner_procurement_scale, winner_count, winner_sortprice)
-	finalSql := fmt.Sprintf(mae.GetCommonQuerySqlWithAggs(), strings.Join(datas, ","))
-	log.Printf("final PurchasingAnalysiseQuery sql: %s", finalSql)
-	t := time.Now()
-	res := util.GetAggs("projectset", "projectset", finalSql)
-	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 {
-		bArr, err := object.MarshalJSON()
-		if len(bArr) == 0 || err != nil {
-			continue
-		}
-		if name == "buyer_amount_distribution" {
-			if json.Unmarshal(bArr, &thisBuyerWinnerRow.BuyerAmountDistribution) != nil {
-				continue
-			}
-		} else if name == "buyer_count_top3" {
-			if json.Unmarshal(bArr, &thisBuyerWinnerRow.BuyerCountTop3) != nil {
-				continue
-			}
-		} else if name == "buyer_amount_top3" {
-			if json.Unmarshal(bArr, &thisBuyerWinnerRow.BuyerAmountTop3) != nil {
-				continue
-			}
-		} else if name == "winner_amount_distribution" {
-			if json.Unmarshal(bArr, &thisBuyerWinnerRow.WinnerAmountDistribution) != nil {
-				continue
-			}
-		} else if name == "winner_count_top3" {
-			if json.Unmarshal(bArr, &thisBuyerWinnerRow.WinnerCountTop3) != nil {
-				continue
-			}
-		} else if name == "winner_amount_top3" {
-			if json.Unmarshal(bArr, &thisBuyerWinnerRow.WinnerAmountTop3) != nil {
-				continue
-			}
-		}
-	}
-	var winnerKeys []string
-	for _, v := range thisBuyerWinnerRow.BuyerCountTop3.Buckets {
-		for _, v1 := range v.SWinnerTop.Buckets {
-			winnerKeyMap[v1.Key]++
-		}
-	}
-	for _, v := range thisBuyerWinnerRow.BuyerAmountTop3.Buckets {
-		for _, v1 := range v.SWinnerTop.Buckets {
-			winnerKeyMap[v1.Key]++
-		}
-	}
-	for _, v := range thisBuyerWinnerRow.WinnerCountTop3.SWinnerCount {
-		winnerKeyMap[v.Key]++
-	}
-	for _, v := range thisBuyerWinnerRow.WinnerAmountTop3.SWinnerAmount {
-		winnerKeyMap[v.Key]++
-	}
-	for k := range winnerKeyMap {
-		winnerKeys = append(winnerKeys, k)
-	}
-	winnerName := GetEntNameByIds(winnerKeys)
-	//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, entArrMap, winnerName, &sy)
-	sy.Wait()
-	log.Println("采购单位-中标单位分析报告程序计算耗时===", time.Since(t))
-	rMaps := make(map[string]interface{})
-	rMap.Range(func(key, value interface{}) bool {
-		rMaps[common.InterfaceToStr(key)] = value
-		return true
-	})
-	return rMaps
-}
-
-type distributionTrend struct {
-	Key    string
-	Count  int
-	Amount float64
-}
-
-var Analysis = []string{"<10万", "10万~50万", "50万~100万", "100万~500万", "500万~1000万", "1000万~1亿", "≥1亿"}
-
-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"`
-		TotalNumber interface{} `json:"total_number"`
-	}
-	//采购单位-采购规模分布
-	buyerMap := []interface{}{}
-
-	//计算采购单位各区间金额
-	buyerA := make(map[string]*distributionTrend)
-	for _, v := range thisBuyerRow.BuyerAmountDistribution.Buckets {
-		amountDistribution(v.Amount.Value, buyerA)
-	}
-	var (
-		countAll  int
-		amountAll float64
-	)
-	for _, v := range buyerA {
-		countAll += v.Count
-		amountAll += v.Amount
-	}
-
-	for _, v := range Analysis {
-		var data buyer
-		data.Name = v
-		if vlu, ok := buyerA[v]; ok && countAll != 0 {
-			data.TotalNumber = float64(vlu.Count) / float64(countAll)
-		}
-		if vlu, ok := buyerA[v]; ok && amountAll != 0 {
-			data.TotalAmount = vlu.Amount / amountAll
-		}
-		buyerMap = append(buyerMap, data)
-	}
-
-	type number_projects struct {
-		Name   string `json:"name"`
-		Number int64  `json:"number"`
-		//Accounted interface{} `json:"accounted"`
-		Data interface{} `json:"winnertop3"`
-	}
-	type number_project struct {
-		Id     interface{} `json:"id"`
-		Name   string      `json:"name"`
-		Number int64       `json:"number"`
-		//Accounted interface{} `json:"accounted"`
-	}
-
-	//采购单位-项目数量TOP3
-	countMap := []interface{}{}
-	for _, v := range thisBuyerRow.BuyerCountTop3.Buckets {
-		var _d number_projects
-		_d.Name = v.Key
-		_d.Number = v.BuyerCount.Value
-		/*if thisBuyerRow.ProjectCount.Value != 0 {
-			_d.Accounted = float64(v.BuyerCount.Value) / float64(thisBuyerRow.ProjectCount.Value)
-		}*/
-		var ss []interface{}
-		for _, v1 := range v.SWinnerTop.Buckets {
-			var _dd number_project
-			_dd.Number = v1.BuyerWinnerAmount.Value
-			if winnerName[v1.Key] == "" {
-				continue
-			}
-			_dd.Name = winnerName[v1.Key]
-			_dd.Id = util.EncodeId(v1.Key)
-
-			/*if _d.Number != 0 {
-				_dd.Accounted = float64(v1.BuyerWinnerAmount.Value) / float64(_d.Number)
-			}*/
-			ss = append(ss, _dd)
-		}
-		_d.Data = ss
-		countMap = append(countMap, _d)
-	}
-
-	//采购单位-项目金额TOP3
-	type amount_projects struct {
-		Name   string  `json:"name"`
-		Amount float64 `json:"amount"`
-		//Accounted interface{} `json:"accounted"`
-		Data interface{} `json:"winnertop3"`
-	}
-	type amount_project struct {
-		Id     interface{} `json:"id"`
-		Name   string      `json:"name"`
-		Amount float64     `json:"amount"`
-		//Accounted interface{} `json:"accounted"`
-	}
-	amountMap := []interface{}{}
-	for _, v := range thisBuyerRow.BuyerAmountTop3.Buckets {
-		if v.BuyerAmount.Value == 0 {
-			continue
-		}
-		var _d amount_projects
-		_d.Name = v.Key
-		_d.Amount = v.BuyerAmount.Value
-		/*if thisBuyerRow.ProjectAmount.Value != 0 {
-			_d.Accounted = v.BuyerAmount.Value / thisBuyerRow.ProjectAmount.Value
-		}*/
-
-		var ss []interface{}
-		for _, v1 := range v.SWinnerTop.Buckets {
-			if v1.BuyerWinnerAmount.Value == 0 || winnerName[v1.Key] == "" {
-				continue
-			}
-			var _dd amount_project
-			_dd.Amount = v1.BuyerWinnerAmount.Value
-
-			_dd.Name = winnerName[v1.Key]
-			_dd.Id = util.EncodeId(v1.Key)
-			/*	if _d.Amount != 0 {
-				_dd.Accounted = v1.BuyerWinnerAmount.Value / _d.Amount
-			}*/
-
-			ss = append(ss, _dd)
-		}
-		_d.Data = ss
-		amountMap = append(amountMap, _d)
-	}
-	rMap.Store("buyer_time_distribution", buyerMap)
-	rMap.Store("buyer_count_top3", countMap)
-	rMap.Store("buyer_amount_top3", amountMap)
-}
-
-// 中标单位分析
-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"`
-		TotalAmount interface{} `json:"total_amount"`
-		TotalNumber interface{} `json:"total_number"`
-	}
-	//中标单位-中标规模分布
-	winnerA := make(map[string]*distributionTrend)
-	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)
-	}
-	for _, f := range entArrMap {
-		amountDistribution(f, winnerA)
-	}
-	var (
-		countAll  int
-		amountAll float64
-	)
-	for _, v := range winnerA {
-		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 && countAll != 0 {
-			data.TotalNumber = float64(vlu.Count) / float64(countAll)
-		}
-		if vlu, ok := winnerA[v]; ok && amountAll != 0 {
-			data.TotalAmount = vlu.Amount / amountAll
-		}
-		buyerMap = append(buyerMap, data)
-	}
-
-	type number_projects struct {
-		Id     interface{} `json:"id"`
-		Name   string      `json:"name"`
-		Number int64       `json:"number"`
-		//Accounted interface{} `json:"accounted"`
-		Data interface{} `json:"buyertop3"`
-	}
-	type number_project struct {
-		Name   string `json:"name"`
-		Number int64  `json:"number"`
-		//Accounted interface{} `json:"accounted"`
-	}
-
-	//中标单位-项目数量TOP3
-	countMap := []interface{}{}
-	for _, v := range thisWinnerRow.WinnerCountTop3.SWinnerCount {
-		var _d number_projects
-		_d.Number = v.BuyerCount.Value
-		if winnerName[v.Key] == "" {
-			continue
-		}
-		_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)
-		}*/
-
-		var ss []interface{}
-		for _, v1 := range v.BuyerTop.Buckets {
-			var _dd number_project
-			_dd.Name = v1.Key
-			_dd.Number = v1.BuyerWinnerAmount.Value
-			/*if _d.Number != 0 {
-				_dd.Accounted = float64(v1.BuyerWinnerAmount.Value) / float64(_d.Number)
-			}*/
-			ss = append(ss, _dd)
-		}
-		_d.Data = ss
-		countMap = append(countMap, _d)
-	}
-
-	//中标单位-项目金额TOP3
-	type amount_projects struct {
-		Id     interface{} `json:"id"`
-		Name   string      `json:"name"`
-		Amount float64     `json:"amount"`
-		//Accounted interface{} `json:"accounted"`
-		Data interface{} `json:"buyertop3"`
-	}
-	type buyertop3 struct {
-		Name   string  `json:"name"`
-		Amount float64 `json:"amount"`
-		//Accounted interface{} `json:"accounted"`
-	}
-	amountMap := []interface{}{}
-	for _, v := range thisWinnerRow.WinnerAmountTop3.SWinnerAmount {
-		if v.SWinnerAmount.Value == 0 || winnerName[v.Key] == "" {
-			continue
-		}
-		var _d amount_projects
-		_d.Amount = v.SWinnerAmount.Value
-		_d.Name = winnerName[v.Key]
-		_d.Id = util.EncodeId(v.Key)
-		/*if thisWinnerRow.ProjectAmount.Value != 0 {
-			_d.Accounted = v.SWinnerAmount.Value / thisWinnerRow.ProjectAmount.Value
-		}*/
-
-		var ss []interface{}
-		for _, v1 := range v.BuyerTop.Buckets {
-			if v1.BuyerWinnerAmount.Value == 0 {
-				continue
-			}
-			var _dd buyertop3
-			_dd.Name = v1.Key
-			_dd.Amount = v1.BuyerWinnerAmount.Value
-			/*if _d.Amount != 0 {
-				_dd.Accounted = v1.BuyerWinnerAmount.Value / _d.Amount
-			}*/
-			ss = append(ss, _dd)
-		}
-		_d.Data = ss
-		amountMap = append(amountMap, _d)
-	}
-	rMap.Store("winner_time_distribution", buyerMap)
-	rMap.Store("winner_count_top3", countMap)
-	rMap.Store("winner_amount_top3", amountMap)
-}

+ 0 - 659
src/jfw/modules/bigmember/src/entity/marketAnalysis/customized_analysis.go

@@ -1,659 +0,0 @@
-package marketAnalysis
-
-import (
-	util "app.yhyue.com/moapp/jybase/common"
-	elastic "app.yhyue.com/moapp/jybase/es"
-	"encoding/json"
-	"fmt"
-	util2 "jy/src/jfw/modules/bigmember/src/util"
-	"log"
-	"strings"
-)
-
-const (
-	query_aggs_sortprice = `"sortprice_ranges": {"range":{"field":"sortprice","ranges":[%s]},"aggs":{"sum_sortprice":{"sum":{"field":"sortprice"}}}}`
-	aggs_area            = `"area_distribution": {"terms": {"field": "area","size": 40},"aggs": {"area_amount": {"sum": {"field": "sortprice"}},"area_total": {"filter": {"match_all":{}}},"city_group": {"terms": {"field": "city","size": 40},"aggs": {"city_amount": {"sum": {"field": "sortprice"}}}}}}`
-	query_top10          = `,"sort": [{"sortprice": "desc"}],"from": 0,"size": 10`
-	aggs_area_amounttop3 = `"area_amount_top3":{"terms":{"field":"area","exclude":["全国"],"order":[{"area_amount":"desc"}],"size":34},"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":40},"aggs":{"area_count":{"filter":{"match_all":{}}},"winner_top":{"terms":{"field":"entidlist","exclude": ["-"],"order":[{"area_winner_count":"desc"}],"size":3},"aggs":{"area_winner_count":{"filter":{"match_all":{}}}}}}}`
-	aggs_buyerclass      = `"buyerclass_scale":{"terms":{"field":"buyerclass","size":2000,"exclude":["其它",""]},"aggs":{"buyerclass_amount":{"sum":{"field":"sortprice"}},"buyerclass_total":{"filter":{"match_all":{}}}}}`
-	//aggs_buyerclass_other      = `"buyerclass_scale_other":{"terms":{"field":"buyerclass","include":["其它",""]},"aggs":{"buyerclass_amount":{"sum":{"field":"sortprice"}},"buyerclass_total":{"filter":{"match_all":{}}}}}`
-	aggs_buyerclass_counttop3  = `"buyerclass_count_top3":{"terms":{"field":"buyerclass","exclude":["其它",""],"order":[{"buyerclass_count":"desc"}],"size":70},"aggs":{"buyerclass_count":{"filter":{"match_all":{}}},"bidcount_top":{"terms":{"field":"entidlist","exclude": ["-"],"order":[{"buyer_winner_count":"desc"}],"size":3},"aggs":{"buyer_winner_count":{"filter":{"match_all":{}}}}}}}`
-	aggs_buyerclass_amounttop3 = `"buyerclass_amount_top3":{"terms":{"field":"buyerclass","exclude":["其它",""],"order":[{"buyerclass_amount":"desc"}],"size":70},"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}`
-	aggs_all_c_m               = `"project_count": {"filter": {"match_all":{}}},"project_count_not0": {"filter": {"range": {"sortprice": {"gt": 0}}}},"project_amount": {"sum": {"field": "sortprice"}}`
-	query_id                   = `{"query": {"bool": {"must": [{"term": {"entidlist": "%s"}}]}},"size": 1}`
-	query_idto                 = `{"query": {"bool": {"must": [{"terms": {"id": ["%s"]}}]}},"_source":["_id","company_name"],"size": %d}`
-)
-
-type AreaCTop struct {
-	ProjectCount struct {
-		DocCount int `json:"doc_count"`
-	} `json:"project_count"`
-	Total     int64 `json:"doc_count"`
-	CountNot0 struct {
-		Count int64 `json:"doc_count"`
-	} `json:"project_count_not0"`
-	Amount struct {
-		Value float64 `json:"value"`
-	} `json:"project_amount"`
-	SortpriceRanges struct {
-		Buckets []struct {
-			Name         string `json:"key"`
-			Total        int64  `json:"doc_count"`
-			SumSortprice struct {
-				Value float64 `json:"value"`
-			} `json:"sum_sortprice"`
-		}
-	} `json:"sortprice_ranges"`
-	AreaDistribution 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"`
-			CityGroup struct {
-				Buckets []struct {
-					City       string `json:"key"`
-					CityTotal  int64  `json:"doc_count"`
-					CityAmount struct {
-						Value float64 `json:"value"`
-					} `json:"city_amount"`
-				}
-			} `json:"city_group"`
-		}
-	} `json:"area_distribution"`
-	BuyerclassScale 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"`
-	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 {
-		Buckets []struct {
-			Key        string `json:"key"`
-			Total      int64  `json:"doc_count"`
-			AreaAmount struct {
-				Amount float64 `json:"value"`
-			} `json:"area_amount"`
-			WinnerTop struct {
-				Buckets []struct {
-					Winner       string `json:"key"`
-					WinnerTotal  int64  `json:"doc_count"`
-					WinnerAmount struct {
-						Amount float64 `json:"value"`
-					} `json:"area_winner_amount"`
-					ProjectDetail struct {
-						Hits struct {
-							Hits []struct {
-								Source struct {
-									Entidlist []string `json:"entidlist"`
-									SWinner   string   `json:"s_winner"`
-								} `json:"_source"`
-							}
-						}
-					} `json:"project_detail"`
-				}
-			} `json:"winner_top"`
-		}
-	} `json:"area_amount_top3"`
-	AreaCountTop3 struct {
-		Buckets []struct {
-			Area      string `json:"key"`
-			Total     int64  `json:"doc_count"`
-			WinnerTop struct {
-				Buckets []struct {
-					Winner        string `json:"key"`
-					WinnerTotal   int64  `json:"doc_count"`
-					ProjectDetail struct {
-						Hits struct {
-							Hits []struct {
-								Source struct {
-									Entidlist []string `json:"entidlist"`
-									SWinner   string   `json:"s_winner"`
-								} `json:"_source"`
-							}
-						}
-					} `json:"project_detail"`
-				}
-			} `json:"winner_top"`
-		}
-	} `json:"area_count_top3"`
-	BuyclassAmountTop3 struct {
-		Buckets []struct {
-			Key        string `json:"key"`
-			Total      int64  `json:"doc_count"`
-			AreaAmount struct {
-				Amount float64 `json:"value"`
-			} `json:"buyerclass_amount"`
-			WinnerTop struct {
-				Buckets []struct {
-					Winner       string `json:"key"`
-					WinnerTotal  int64  `json:"doc_count"`
-					WinnerAmount struct {
-						Amount float64 `json:"value"`
-					} `json:"buyer_winner_amount"`
-					ProjectDetail struct {
-						Hits struct {
-							Hits []struct {
-								Source struct {
-									Entidlist []string `json:"entidlist"`
-									SWinner   string   `json:"s_winner"`
-								} `json:"_source"`
-							}
-						}
-					} `json:"project_detail"`
-				}
-			} `json:"winner_top"`
-		}
-	} `json:"buyerclass_amount_top3"`
-	BuyclassCountTop3 struct {
-		Buckets []struct {
-			Buyclass    string `json:"key"`
-			Total       int64  `json:"doc_count"`
-			BidcountTop struct {
-				Buckets []struct {
-					Winner        string `json:"key"`
-					WinnerTotal   int64  `json:"doc_count"`
-					ProjectDetail struct {
-						Hits struct {
-							Hits []struct {
-								Source struct {
-									Entidlist []string `json:"entidlist"`
-									SWinner   string   `json:"s_winner"`
-								} `json:"_source"`
-							}
-						}
-					} `json:"project_detail"`
-				}
-			} `json:"bidcount_top"`
-		}
-	} `json:"buyerclass_count_top3"`
-}
-
-// 企业id查企业名 传入数组
-func IDToName(ids []string) (iMap map[string]string) {
-	iMap = map[string]string{}
-	d := strings.Join(ids, `","`)
-	finalSql := fmt.Sprintf(query_idto, d, len(ids))
-	log.Println("IDToName sql:", finalSql)
-	hits := elastic.Get("qyxy", "qyxy", finalSql)
-	if hits == nil || len(*hits) == 0 {
-		return
-	}
-	for _, item := range *hits {
-		id, _ := item["_id"].(string)
-		name, _ := item["company_name"].(string)
-		if id != "" && name != "" {
-			iMap[id] = name
-		}
-	}
-	return
-}
-
-func (mae *MarketAnalysisEntity) AllData() (rMap map[string]interface{}, err error) {
-	rMap = map[string]interface{}{}
-	var aggs []string
-	area := mae.FormatParam.Area
-	city := mae.FormatParam.City
-	buyclass := mae.FormatParam.BuyerClass
-	aggs = append(aggs, aggs_all_c_m, fmt.Sprintf(query_aggs_sortprice, sortprice_str), aggs_area)
-	if (len(area) + len(city)) != 1 {
-		aggs = append(aggs, aggs_area_amounttop3, aggs_area_counttop3)
-	}
-	if len(buyclass) != 1 {
-		//aggs = append(aggs, aggs_buyerclass, aggs_buyerclass_other, aggs_buyerclass_amounttop3, aggs_buyerclass_counttop3)
-		aggs = append(aggs, aggs_buyerclass, aggs_buyerclass_amounttop3, aggs_buyerclass_counttop3)
-	}
-	finalSql := fmt.Sprintf(mae.GetCommonQuerySqlWithAggs(), strings.Join(aggs, ","))
-	log.Println("allData sql:", finalSql)
-	res := util2.GetAggs("projectset", "projectset", finalSql)
-	if res == nil || len(res) == 0 {
-		return
-	}
-	thisRow := AreaCTop{}
-	for name, object := range res {
-		bArr, err := object.MarshalJSON()
-		if len(bArr) == 0 || err != nil {
-			continue
-		}
-		if name == "project_amount" {
-			if json.Unmarshal(bArr, &thisRow.Amount) != nil {
-				continue
-			}
-		} else if name == "project_count" {
-			if json.Unmarshal(bArr, &thisRow.ProjectCount) != nil {
-				continue
-			}
-			//} else if name == "buyerclass_scale_other" {
-			//	if json.Unmarshal(bArr, &thisRow.BuyerclassScaleOther) != nil {
-			//		continue
-			//	}
-		} else if name == "project_count_not0" {
-			if json.Unmarshal(bArr, &thisRow.CountNot0) != nil {
-				continue
-			}
-		} else if name == "sortprice_ranges" {
-			if json.Unmarshal(bArr, &thisRow.SortpriceRanges) != nil {
-				continue
-			}
-		} else if name == "area_distribution" {
-			if json.Unmarshal(bArr, &thisRow.AreaDistribution) != nil {
-				continue
-			}
-		} else if name == "buyerclass_scale" {
-			if json.Unmarshal(bArr, &thisRow.BuyerclassScale) != nil {
-				continue
-			}
-		} else if name == "area_amount_top3" {
-			if json.Unmarshal(bArr, &thisRow.AreaAmountTop3) != nil {
-				continue
-			}
-		} else if name == "area_count_top3" {
-			if json.Unmarshal(bArr, &thisRow.AreaCountTop3) != nil {
-				continue
-			}
-		} else if name == "buyerclass_amount_top3" {
-			if json.Unmarshal(bArr, &thisRow.BuyclassAmountTop3) != nil {
-				continue
-			}
-		} else if name == "buyerclass_count_top3" {
-			if json.Unmarshal(bArr, &thisRow.BuyclassCountTop3) != nil {
-				continue
-			}
-		}
-	}
-	data := ProjectScale(thisRow)
-	area_data := AreaDistribute(thisRow)
-	customerData, customerOther := CustomerDistribute(thisRow)
-	//customerOther, customerData := CustomerDistributeDetails(thisRow, customerDetails)
-	var ids []string
-	for _, v := range thisRow.AreaAmountTop3.Buckets {
-		for _, va := range v.WinnerTop.Buckets {
-			ids = append(ids, va.Winner)
-		}
-	}
-	for _, v := range thisRow.BuyclassAmountTop3.Buckets {
-		for _, va := range v.WinnerTop.Buckets {
-			ids = append(ids, va.Winner)
-		}
-	}
-	for _, v := range thisRow.AreaCountTop3.Buckets {
-		for _, va := range v.WinnerTop.Buckets {
-			ids = append(ids, va.Winner)
-		}
-	}
-	for _, v := range thisRow.BuyclassCountTop3.Buckets {
-		for _, va := range v.BidcountTop.Buckets {
-			ids = append(ids, va.Winner)
-		}
-	}
-	eid := IDToName(ids)
-	rMap["projectScale"] = data
-	rMap["area_infos"] = area_data
-	rMap["customer_scale"] = customerData
-	rMap["customer_scale_other"] = customerOther //客户分布(其它)
-	rMap["scaleAreaAmountTop"] = AmountCompute(thisRow, "area", eid)
-	rMap["scaleBuyclassAmountTop"] = AmountCompute(thisRow, "buyclass", eid)
-	rMap["scaleAreaCountTop"] = CountCompute(thisRow, "area", eid)
-	rMap["scaleBuyclassCountTop"] = CountCompute(thisRow, "buyclass", eid)
-	return
-}
-
-// 项目规模分布
-func ProjectScale(thisRow AreaCTop) (data []interface{}) {
-	ammount := thisRow.Amount.Value
-	total := thisRow.CountNot0.Count
-	buckets := thisRow.SortpriceRanges.Buckets
-	type Scale struct {
-		Name      string  `bson:"Name"`
-		Persent_c float64 `bson:"Persent_c"`
-		Persent_a float64 `bson:"Persent_a"`
-		Ammount   float64 `json:"ammount"`
-		Total     int64   `json:"total"`
-	}
-	for _, v := range buckets {
-		data = append(data, Scale{
-			Name:      v.Name,
-			Ammount:   v.SumSortprice.Value,
-			Total:     v.Total,
-			Persent_a: Formula(float64(v.Total), float64(total)),
-			Persent_c: Formula(v.SumSortprice.Value, ammount),
-		})
-	}
-	return
-}
-
-func InterToSliceString(obj interface{}) []string {
-	var sli = make([]string, 0)
-	if obj == nil {
-		return sli
-	}
-
-	if _, ok := obj.([]interface{}); ok {
-		for _, i := range obj.([]interface{}) {
-			sli = append(sli, i.(string))
-		}
-	}
-
-	if _, ok := obj.([]string); ok {
-		return obj.([]string)
-	}
-
-	return sli
-}
-
-// top10
-func (mae *MarketAnalysisEntity) ProjectTop10() (rMap map[string]interface{}, err error) {
-	finalSql := fmt.Sprintf(mae.GetCommonQuerySql(), query_top10)
-	log.Println("ProjectTop10:", finalSql)
-	hits := elastic.Get("projectset", "projectset", finalSql)
-	rMap = map[string]interface{}{}
-	bArr := []map[string]interface{}{}
-	source := *hits
-	for _, v := range source {
-		bA := map[string]interface{}{}
-		if v["ids"] != nil && len(InterToSliceString(v["ids"])) > 0 {
-			idss := InterToSliceString(v["ids"])
-			bA["_id"] = util2.EncodeId(idss[len(idss)-1])
-		} else {
-			bA["_id"] = nil
-		}
-		if v["area"] == "" {
-			bA["city"] = nil
-		} else {
-			bA["area"] = v["area"]
-		}
-		if v["city"] == "" {
-			bA["city"] = nil
-		} else {
-			bA["city"] = v["city"]
-		}
-		bA["jgtime"] = v["jgtime"]
-		bA["projectname"] = v["s_projectname"]
-		bA["sortprice"] = v["sortprice"]
-		ids := v["entidlist"]
-		var id_s []string
-		var winner_s []string
-		for _, i := range InterToSliceString(ids) {
-			iid := util2.EncodeId(i)
-			id_s = append(id_s, iid)
-		}
-		bA["eidlist"] = id_s
-		bA["winner_s"] = nil
-		if util.ObjToString(v["s_winner"]) != "" {
-			w_s := strings.Split(util.ObjToString(v["s_winner"]), ",")
-			for _, vv := range w_s {
-				winner_s = append(winner_s, vv)
-			}
-			bA["winner_s"] = winner_s
-		}
-		bArr = append(bArr, bA)
-	}
-	rMap["ProjectTop10"] = bArr
-	return
-}
-
-// 地区分布
-func AreaDistribute(thisRow AreaCTop) (data []map[string]interface{}) {
-	for _, v := range thisRow.AreaDistribution.Buckets {
-		rM := map[string]interface{}{}
-		rM["area"] = v.Area
-		rM["total"] = v.AreaTotal
-		rM["amount"] = v.AreaAmount.Value
-		var rmc []map[string]interface{}
-		if len(v.CityGroup.Buckets) > 0 {
-			for _, c := range v.CityGroup.Buckets {
-				rmc = append(rmc, map[string]interface{}{
-					"city":   c.City,
-					"total":  c.CityTotal,
-					"amount": c.CityAmount.Value,
-				})
-			}
-			rM["areaDetails"] = rmc
-		}
-		data = append(data, rM)
-	}
-	return
-}
-
-// 客户分布
-func CustomerDistribute(thisRow AreaCTop) (data []map[string]interface{}, otherData map[string]interface{}) {
-	var (
-		total  int64
-		amount float64
-	)
-	for _, v := range thisRow.BuyerclassScale.Buckets {
-		if v.AreaTotal == 0 && v.BuyclassAmount.Value == 0 {
-			continue
-		}
-		rM := map[string]interface{}{}
-		rM["buyclass"] = v.Area
-		rM["total"] = v.AreaTotal
-		rM["amount"] = v.BuyclassAmount.Value
-		total += v.AreaTotal
-		amount += v.BuyclassAmount.Value
-		data = append(data, rM)
-	}
-	//for _, v := range thisRow.BuyerclassScaleOther.Buckets {
-	//	total += v.AreaTotal
-	//	amount += v.BuyclassAmount.Value
-	//}
-	otherData = make(map[string]interface{})
-	otherData["buyclass"] = "其它"
-	if pCount := util.Int64All(thisRow.ProjectCount.DocCount) - total; pCount > 0 {
-		otherData["total"] = pCount
-	}
-	if pAmount := thisRow.Amount.Value - amount; pAmount > 0 {
-		otherData["amount"] = pAmount
-	}
-	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
-}
-
-// top3金额计算
-func AmountCompute(thisRow AreaCTop, types string, eid map[string]string) (rData []map[string]interface{}) {
-	if types == "area" {
-		area_infos := thisRow.AreaAmountTop3
-		for _, v := range area_infos.Buckets {
-			if v.AreaAmount.Amount == 0 {
-				break
-			}
-			rM := map[string]interface{}{}
-			rWinner := []map[string]interface{}{}
-			rM["name"] = v.Key
-			rM["area_amount"] = v.AreaAmount.Amount
-			for _, va := range v.WinnerTop.Buckets {
-				if va.WinnerAmount.Amount == 0 {
-					break
-				}
-				rW := map[string]interface{}{}
-				id := util2.EncodeId(va.Winner)
-				rW["id"] = id
-				rW["winner"] = eid[va.Winner]
-				if eid[va.Winner] == "" {
-					continue
-				}
-				rW["winner_amount"] = va.WinnerAmount.Amount
-				//rW["amount_scale"] = va.WinnerAmount.Amount / v.AreaAmount.Amount
-				rWinner = append(rWinner, rW)
-			}
-			rM["winner"] = rWinner
-			if thisRow.Amount.Value != 0 {
-				vv := v.AreaAmount.Amount / thisRow.Amount.Value
-				rM["area_scale"] = vv
-			} else {
-				rM["area_scale"] = 0
-			}
-			rData = append(rData, rM)
-		}
-	} else {
-		area_infos := thisRow.BuyclassAmountTop3
-		for _, v := range area_infos.Buckets {
-			if v.AreaAmount.Amount == 0 {
-				break
-			}
-			rM := map[string]interface{}{}
-			rWinner := []map[string]interface{}{}
-			rM["name"] = v.Key
-			rM["buyclass_amount"] = v.AreaAmount.Amount
-			for _, va := range v.WinnerTop.Buckets {
-				if va.WinnerAmount.Amount == 0 {
-					break
-				}
-				rW := map[string]interface{}{}
-				id := util2.EncodeId(va.Winner)
-				rW["id"] = id
-				rW["winner"] = eid[va.Winner]
-				if eid[va.Winner] == "" {
-					continue
-				}
-				rW["winner_amount"] = va.WinnerAmount.Amount
-				//rW["amount_scale"] = va.WinnerAmount.Amount / v.AreaAmount.Amount
-				rWinner = append(rWinner, rW)
-			}
-			rM["winner"] = rWinner
-			if thisRow.Amount.Value != 0 {
-				vv := v.AreaAmount.Amount / thisRow.Amount.Value
-				rM["buyclass_scale"] = vv
-			} else {
-				rM["buyclass_scale"] = 0
-			}
-
-			rData = append(rData, rM)
-		}
-	}
-	return
-}
-
-// top3数量计算
-func CountCompute(thisRow AreaCTop, types string, eid map[string]string) (rData []map[string]interface{}) {
-	if types == "area" {
-		area_infos := thisRow.AreaCountTop3
-		for _, v := range area_infos.Buckets {
-			if v.Total == 0 {
-				break
-			}
-			rM := map[string]interface{}{}
-			rWinner := []map[string]interface{}{}
-			rM["name"] = v.Area
-			rM["area_count"] = v.Total
-			for _, va := range v.WinnerTop.Buckets {
-				if va.WinnerTotal == 0 {
-					break
-				}
-				rW := map[string]interface{}{}
-				id := util2.EncodeId(va.Winner)
-				rW["id"] = id
-				rW["winner"] = eid[va.Winner]
-				if eid[va.Winner] == "" {
-					continue
-				}
-				rW["winner_total"] = va.WinnerTotal
-				rWinner = append(rWinner, rW)
-			}
-			if len(rWinner) == 0 {
-				continue
-			}
-			rM["winner"] = rWinner
-			if thisRow.Total != 0 {
-				vv := float64(v.Total) / float64(thisRow.Total)
-				rM["area_scale"] = vv
-			} else {
-				rM["area_scale"] = 0
-			}
-
-			rData = append(rData, rM)
-		}
-	} else {
-		area_infos := thisRow.BuyclassCountTop3
-		for _, v := range area_infos.Buckets {
-			if v.Total == 0 {
-				break
-			}
-			rM := map[string]interface{}{}
-			rWinner := []map[string]interface{}{}
-			rM["name"] = v.Buyclass
-			rM["buyclass_count"] = v.Total
-			for _, va := range v.BidcountTop.Buckets {
-				if va.WinnerTotal == 0 {
-					break
-				}
-				rW := map[string]interface{}{}
-				id := util2.EncodeId(va.Winner)
-				rW["id"] = id
-				rW["winner"] = eid[va.Winner]
-				if eid[va.Winner] == "" {
-					continue
-				}
-				rW["winner_total"] = va.WinnerTotal
-				rWinner = append(rWinner, rW)
-			}
-			if len(rWinner) == 0 {
-				continue
-			}
-			rM["winner"] = rWinner
-			if thisRow.Total != 0 {
-				vv := float64(v.Total) / float64(thisRow.Total)
-				rM["buyclass_scale"] = vv
-			} else {
-				rM["buyclass_scale"] = 0
-			}
-
-			rData = append(rData, rM)
-		}
-	}
-	return
-}
-
-// 计算公式
-func Formula(current, total float64) (result float64) {
-	if total == 0 {
-		return 0
-	}
-	result = current / total
-	return
-}

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

@@ -1,986 +0,0 @@
-package marketAnalysis
-
-import (
-	qutil "app.yhyue.com/moapp/jybase/common"
-	"app.yhyue.com/moapp/jybase/encrypt"
-	elastic "app.yhyue.com/moapp/jybase/es"
-	"app.yhyue.com/moapp/jybase/mongodb"
-	"app.yhyue.com/moapp/jybase/redis"
-	"app.yhyue.com/moapp/jypkg/common/src/qfw/util/jy"
-	"encoding/json"
-	"errors"
-	"fmt"
-	"jy/src/jfw/modules/bigmember/src/config"
-	"jy/src/jfw/modules/bigmember/src/db"
-	"jy/src/jfw/modules/bigmember/src/util"
-	"log"
-	"strings"
-	"time"
-)
-
-const (
-	marketQueryItem      = iota //回显查询条件
-	marketScaleMain             //市场规模
-	marketTopProject            //项目规模TOP10
-	marketProjectAllData        //项目规模 地区分布 客户分布 地区客户top3
-	marketScaleRefine           //细化市场
-	marketBuyerAndWinner        //市场-采购单位&&中标企业
-
-	ReportHistoryTable = "marketAnalysisReport"
-	ReportCacheDB      = "other"
-	ReportCacheKey     = "marketAnalysis_%s_%d"
-	ReportCacheTime    = 60 * 5
-	ReportCanceledKey  = "marketAnalysisCanceled_%s" // 取消的报告id
-	ReportCanceledTime = 60 * 60 * 24
-
-	ReportStateGenerating        = 0                             // 报告生成状态 生成中
-	ReportStateGenerated         = 1                             // 生成 成功
-	ReportStateCanceled          = 2                             // 已取消
-	ReportStateFailed            = -1                            // 生成失败
-	CollMarketScaleMain          = "marketanalysisreport_scal"   //市场规模 报告模块对应的mongo 集合名称
-	CollMarketTopProject         = "marketanalysisreport_top"    //项目规模TOP10
-	CollMarketProjectAllData     = "marketanalysisreport_all"    //项目规模 地区分布 客户分布 地区客户top3
-	CollMarketScaleRefine        = "marketanalysisreport_refine" //细化市场
-	CollMarketBuyerAndWinner     = "marketanalysisreport_bw"     //市场-采购单位&&中标企业
-	ValueOffline                 = 1                             // 离线
-	ValueRealTime                = 2                             // 实时
-	Tablejianyu_mar_user_account = "jianyu.mar_user_account"     // 离线市场报告分析关键词标准信息表
-)
-
-var (
-	MarketAnalysisPool chan bool
-)
-
-func init() {
-	MarketAnalysisPool = make(chan bool, config.Config.MarketAnalysisPool.Limit)
-	for i := 0; i < config.Config.MarketAnalysisPool.Limit; i++ {
-		MarketAnalysisPool <- true
-	}
-}
-
-// AnalysisRequestParam 接口原请求参数
-type AnalysisRequestParam struct {
-	KeysItemsStr   string //分析内容【字符串】结构和o_member_jy.a_items保持一致
-	RangeTime      string //时间【字符串】 时间戳开始-结束时间戳
-	RangeTimeExtra string //时间【字符串】前段回显使用
-	Area           string //省份【对象字符串】
-	Industry       string //行业【对象字符串】
-	BuyerClass     string //采购单位类型【字符串】多个采购单位类型用逗号拼接
-	Buyer          string //采购单位
-	Winner         string //中标单位
-	Sort           int    //排序:默认0:成交时间倒序;1:项目金额倒序
-	PageSize       int    //默认每页10条
-	PageNum        int    //默认当前第一页
-	IsDetail       bool   //是否是项目明细请求
-	MatchingMode   string //匹配方式 title:标题 content:项目名称/标的物
-}
-
-type viewKeyWord struct {
-	Keyword  []string `json:"key"`       //关键词
-	Appended []string `json:"appendkey"` //附加词
-	Exclude  []string `json:"notkey"`    //排除词
-	MatchWay int      `json:"matchway"`  //匹配模式
-}
-
-// keyWordGroup 订阅词结构体
-type keyWordGroup struct {
-	A_Key      []viewKeyWord `json:"a_key"`
-	ItemName   string        `json:"s_item"`
-	UpdateTime int64         `json:"updatetime"`
-}
-
-// AnalysisRequestFormat 格式化后参数
-type AnalysisRequestFormat struct {
-	KeysItems    []keyWordGroup
-	Area, City   []string //省份城市
-	STime, ETime int64    //开始结束时间
-	Industry     []string //行业
-	BuyerClass   []string //采购单位类型
-	Buyer        string   //采购单位
-	Winner       string   //中标单位
-	Sort         int      //排序:默认0:成交时间倒序;1:项目金额倒序
-	PageSize     int      //默认每页10条
-	PageNum      int      //默认当前第一页
-}
-
-type MarketAnalysisEntity struct {
-	MgoRecordId   string
-	BaseParam     AnalysisRequestParam
-	FormatParam   AnalysisRequestFormat
-	UId, Pid      string
-	ProjectInfo   projectInfo
-	Offline       int // 1-离线 2-实时
-	State         int // 状态:默认0:生成中;1:已生成;2:已取消;-1:生成失败
-	MgoUserId     string
-	Phone         string // 手机号
-	PositionId    int
-	OriginalTotal int64 // 数据总数
-	PositionType  int
-	EntId         int
-	EntUserId     int
-	Source        string
-}
-
-type projectInfo struct {
-	Count int64
-	List  []ProjectList
-}
-
-type ProjectList struct {
-	Name       string   `json:"name"`       //项目名称
-	Id         string   `json:"id"`         //项目id
-	Area       string   `json:"area"`       //地区
-	DealTime   int64    `json:"dealTime"`   //成交时间
-	BidStatus  string   `json:"bidStatus"`  //项目类型
-	BuyerClass string   `json:"buyerClass"` //采购单位类型
-	Winner     []string `json:"winner"`     //中标单位
-	WinnerId   []string `json:"winnerId"`   //中标单位id
-	Buyer      string   `json:"buyer"`      //采购单位
-	BidAmount  float64  `json:"bidAmount"`  //中标金额
-	Budget     float64  `json:"budget"`     //预算
-}
-
-// ForMatData 获取格式化请求参数
-func (mae *MarketAnalysisEntity) ForMatData() error {
-	//格式化订阅词
-	if err := json.Unmarshal([]byte(mae.BaseParam.KeysItemsStr), &mae.FormatParam.KeysItems); err != nil {
-		return fmt.Errorf("关键词组格式异常")
-	}
-	if mae.FormatParam.KeysItems == nil || len(mae.FormatParam.KeysItems) == 0 {
-		return fmt.Errorf("请选择关键词组")
-	}
-	var flag bool
-	// 判断关键词是不是为空
-	for i := 0; i < len(mae.FormatParam.KeysItems); i++ {
-		items := mae.FormatParam.KeysItems[i]
-		for j := 0; j < len(items.A_Key); j++ {
-			AKey := items.A_Key[j]
-			if len(AKey.Keyword) > 0 {
-				flag = true
-				break
-			}
-		}
-		if flag {
-			break
-		}
-	}
-	if !flag {
-		return fmt.Errorf("请选择关键词组")
-	}
-	//格式化时间段
-	if timeArr := strings.Split(mae.BaseParam.RangeTime, "-"); len(timeArr) == 2 {
-		mae.FormatParam.STime = qutil.Int64All(timeArr[0])
-		mae.FormatParam.ETime = qutil.Int64All(timeArr[1])
-		if mae.FormatParam.STime == 0 || mae.FormatParam.ETime == 0 {
-			return fmt.Errorf("开始时间和结束时间不能为空")
-		}
-	} else {
-		return fmt.Errorf("时间戳格式异常")
-	}
-	//格式化省份、城市
-	if areaStr := strings.TrimSpace(mae.BaseParam.Area); areaStr != "" {
-		imap := map[string][]string{}
-		if err := json.Unmarshal([]byte(mae.BaseParam.Area), &imap); err != nil {
-			return fmt.Errorf("非法地区信息")
-		}
-		var city, area []string
-		for name, v := range imap {
-			if len(v) == 0 {
-				area = append(area, name)
-			} else {
-				for _, vv := range v {
-					city = append(city, vv)
-				}
-			}
-		}
-		mae.FormatParam.Area = area
-		mae.FormatParam.City = city
-	}
-	//格式化行业
-	if industryStr := strings.TrimSpace(mae.BaseParam.Industry); industryStr != "" {
-		imap := map[string][]string{}
-		if err := json.Unmarshal([]byte(industryStr), &imap); err != nil {
-			return fmt.Errorf("非法行业信息")
-		}
-		var farr []string
-		for name, v := range imap {
-			for _, vv := range v {
-				farr = append(farr, fmt.Sprintf("%s_%s", name, vv))
-			}
-		}
-		if len(farr) > 0 {
-			//P510 行业:其它
-			if qt := jy.IndustryHandle(strings.Join(farr, ",")); len(qt) > 0 {
-				farr = append(farr, qt...)
-			}
-		}
-		mae.FormatParam.Industry = farr
-	}
-	//格式化类型
-	if buyerClassStr := strings.TrimSpace(mae.BaseParam.BuyerClass); buyerClassStr != "" {
-		mae.FormatParam.BuyerClass = strings.Split(buyerClassStr, ",")
-	}
-	//中标企业
-	mae.FormatParam.Winner = mae.BaseParam.Winner
-	//采购单位
-	mae.FormatParam.Buyer = mae.BaseParam.Buyer
-	//排序
-	mae.FormatParam.Sort = qutil.If(mae.BaseParam.Sort != 0 && mae.BaseParam.Sort != 1, 0, mae.BaseParam.Sort).(int)
-	if mae.BaseParam.PageNum*mae.BaseParam.PageSize > config.Config.ProjectCount {
-		mae.BaseParam.PageNum = config.Config.ProjectCount / mae.BaseParam.PageSize
-	}
-	//当前页码
-	mae.FormatParam.PageNum = qutil.If(mae.BaseParam.PageNum < 1 || mae.BaseParam.PageNum > 1000, 1, mae.BaseParam.PageNum).(int)
-	//默认每页10条
-	mae.FormatParam.PageSize = qutil.If(mae.BaseParam.PageSize < 1 || mae.BaseParam.PageSize > 100, 50, mae.BaseParam.PageSize).(int)
-	return nil
-}
-
-// ForMatData 获取格式化请求参数
-func (mae *MarketAnalysisEntity) ForMatDataPdf() (string, error) {
-	//格式化订阅词
-	if err := json.Unmarshal([]byte(mae.BaseParam.KeysItemsStr), &mae.FormatParam.KeysItems); err != nil {
-		return "", fmt.Errorf("关键词组格式异常")
-	}
-
-	//格式化时间段
-	if timeArr := strings.Split(mae.BaseParam.RangeTime, "-"); len(timeArr) == 2 {
-		mae.FormatParam.STime = qutil.Int64All(timeArr[0])
-		mae.FormatParam.ETime = qutil.Int64All(timeArr[1])
-		if mae.FormatParam.STime == 0 || mae.FormatParam.ETime == 0 {
-			return "", fmt.Errorf("开始时间和结束时间不能为空")
-		}
-	} else {
-		return "", fmt.Errorf("时间戳格式异常")
-	}
-	//格式化省份、城市
-	if areaStr := strings.TrimSpace(mae.BaseParam.Area); areaStr != "" {
-		imap := map[string][]string{}
-		if err := json.Unmarshal([]byte(mae.BaseParam.Area), &imap); err != nil {
-			return "", fmt.Errorf("非法地区信息")
-		}
-		var city, area []string
-		for name, v := range imap {
-			if len(v) == 0 {
-				area = append(area, name)
-			} else {
-				for _, vv := range v {
-					city = append(city, vv)
-				}
-			}
-		}
-		mae.FormatParam.Area = area
-		mae.FormatParam.City = city
-	}
-	//格式化行业
-	if industryStr := strings.TrimSpace(mae.BaseParam.Industry); industryStr != "" {
-		imap := map[string][]string{}
-		if err := json.Unmarshal([]byte(industryStr), &imap); err != nil {
-			return "", fmt.Errorf("非法行业信息")
-		}
-		var farr []string
-		for name, v := range imap {
-			for _, vv := range v {
-				farr = append(farr, fmt.Sprintf("%s_%s", name, vv))
-			}
-		}
-		mae.FormatParam.Industry = farr
-	}
-	//格式化类型
-	if buyerClassStr := strings.TrimSpace(mae.BaseParam.BuyerClass); buyerClassStr != "" {
-		mae.FormatParam.BuyerClass = strings.Split(buyerClassStr, ",")
-	}
-	//中标企业
-	mae.FormatParam.Winner = mae.BaseParam.Winner
-	//采购单位
-	mae.FormatParam.Buyer = mae.BaseParam.Buyer
-	//排序
-	mae.FormatParam.Sort = qutil.If(mae.BaseParam.Sort != 0 && mae.BaseParam.Sort != 1, 0, mae.BaseParam.Sort).(int)
-	if mae.BaseParam.PageNum*mae.BaseParam.PageSize > config.Config.ProjectCount {
-		mae.BaseParam.PageNum = config.Config.ProjectCount / mae.BaseParam.PageSize
-	}
-	//当前页码
-	mae.FormatParam.PageNum = qutil.If(mae.BaseParam.PageNum < 1 || mae.BaseParam.PageNum > 1000, 1, mae.BaseParam.PageNum).(int)
-	//默认每页10条
-	mae.FormatParam.PageSize = qutil.If(mae.BaseParam.PageSize < 1 || mae.BaseParam.PageSize > 100, 50, mae.BaseParam.PageSize).(int)
-	data := map[string]interface{}{
-		"s_keysItems":      mae.BaseParam.KeysItemsStr,
-		"s_rangeTime":      mae.BaseParam.RangeTime,
-		"s_rangeTimeExtra": mae.BaseParam.RangeTimeExtra,
-		"s_area":           mae.BaseParam.Area,
-		"s_industry":       mae.BaseParam.Industry,
-		"s_buyerClass":     mae.BaseParam.BuyerClass,
-		"s_matchingMode":   mae.BaseParam.MatchingMode,
-		"s_userId":         mae.UId,
-		"s_parentId":       mae.Pid,
-		"s_mgoUserId":      mae.MgoUserId,
-		"i_positionId":     mae.PositionId,
-		"s_phone":          mae.Phone,
-		"audit":            1,
-	}
-	if mae.OriginalTotal > 0 {
-		data["l_originalTotal"] = mae.OriginalTotal
-	}
-	if mae.Source != "" {
-		data["source"] = mae.Source
-	}
-	rs, b := db.Mgo.FindOne(ReportHistoryTable, data)
-	if b && rs != nil && len(*rs) > 0 {
-		return qutil.InterfaceToStr((*rs)["_id"]), errors.New("当期分析已存在")
-	}
-	return "", nil
-}
-
-// GetProjectInfoList 项目明细
-func (mae *MarketAnalysisEntity) GetProjectInfoList() error {
-	var (
-		queryDefault = `,"sort": [{%s}],"from": %d,"size": %d`
-		start        = (mae.FormatParam.PageNum - 1) * mae.FormatParam.PageSize
-		sort         = `"jgtime": "desc"`
-	)
-	if mae.FormatParam.Sort > 0 {
-		sort = `"bidamount": "desc","budget": "desc"`
-	}
-	countSql := fmt.Sprintf(mae.GetCommonQuerySql(), "")
-	queryDefault = fmt.Sprintf(queryDefault, sort, start, mae.FormatParam.PageSize)
-	finalSql := fmt.Sprintf(mae.GetCommonQuerySql(), queryDefault)
-	log.Println("finalSql:", finalSql)
-	count, hits := elastic.GetWithCount("projectset", "projectset", countSql, finalSql)
-	//hits, count := elastic.GetOA("projectset", "projectset", finalSql)
-	if count > 0 {
-		mae.ProjectInfo.Count = count
-		source := *hits
-		for _, v := range source {
-			var winnerIdArr []string
-			if qutil.ObjToString(v["s_winner"]) != "" && v["entidlist"] != nil {
-				idObjs, _ := v["entidlist"].([]interface{})
-				for _, v := range qutil.ObjArrToStringArr(idObjs) {
-					if v != "" && v != "-" {
-						v = encrypt.EncodeArticleId2ByCheck(v)
-					}
-					winnerIdArr = append(winnerIdArr, v)
-				}
-			}
-			mae.ProjectInfo.List = append(mae.ProjectInfo.List, ProjectList{
-				Name:       qutil.ObjToString(v["projectname"]),
-				Id:         encrypt.EncodeArticleId2ByCheck(qutil.ObjToString(v["id"])),
-				Area:       qutil.ObjToString(v["area"]),
-				DealTime:   qutil.Int64All(v["jgtime"]), //截止时间
-				BidStatus:  qutil.ObjToString(v["bidstatus"]),
-				BuyerClass: qutil.ObjToString(v["buyerclass"]),
-				Winner:     strings.Split(qutil.ObjToString(v["s_winner"]), ","),
-				WinnerId:   winnerIdArr,
-				Buyer:      qutil.ObjToString(v["buyer"]),
-				BidAmount:  qutil.Float64All(v["bidamount"]), //中标金额
-				Budget:     qutil.Float64All(v["budget"]),    //预算
-			})
-		}
-	}
-	return nil
-}
-
-// SaveAnalysisRecord 保存分析记录
-func (mae *MarketAnalysisEntity) SaveAnalysisRecord() error {
-	if mae.Offline == ValueRealTime {
-		mae.State = ReportStateGenerated
-	} else {
-		mae.State = ReportStateGenerating
-	}
-	data := map[string]interface{}{
-		"s_keysItems":      mae.BaseParam.KeysItemsStr,
-		"s_rangeTime":      mae.BaseParam.RangeTime,
-		"s_rangeTimeExtra": mae.BaseParam.RangeTimeExtra,
-		"s_area":           mae.BaseParam.Area,
-		"s_industry":       mae.BaseParam.Industry,
-		"s_buyerClass":     mae.BaseParam.BuyerClass,
-		"s_matchingMode":   mae.BaseParam.MatchingMode,
-		"s_userId":         mae.UId,
-		"s_parentId":       mae.Pid,
-		"i_state":          qutil.If(mae.Source == "analysisPDF", 1, mae.State), //状态:默认0:生成中;1:已生成;2:已取消;-1:生成失败
-		"l_updateTime":     time.Now().Unix(),                                   //生成时间 or 取消时间
-		"l_createTime":     time.Now().Unix(),
-		"i_offline":        qutil.If(mae.Source == "analysisPDF", 2, mae.Offline),
-		"s_mgoUserId":      mae.MgoUserId,
-		"i_positionId":     mae.PositionId,
-		"s_phone":          mae.Phone,
-	}
-	if mae.OriginalTotal > 0 {
-		data["l_originalTotal"] = mae.OriginalTotal
-	}
-	if mae.Source != "" {
-		data["source"] = mae.Source
-	}
-	mae.MgoRecordId = db.Mgo.Save(ReportHistoryTable, data)
-	if mae.MgoRecordId == "" {
-		return fmt.Errorf("分析创建异常")
-	}
-	return nil
-}
-
-// GetAnalysisFromMgoDb 从数据库中获取分析记录
-func (mae *MarketAnalysisEntity) GetAnalysisFromMgoDb() error {
-	if mae.MgoRecordId == "" {
-		return fmt.Errorf("缺少参数")
-	}
-	queryMap := map[string]interface{}{
-		"_id":   mongodb.StringTOBsonId(mae.MgoRecordId),
-		"i_del": map[string]interface{}{"$ne": 1},
-	}
-	if mae.UId == mae.Pid { //主账号
-		queryMap["s_parentId"] = mae.Pid
-	} else {
-		queryMap["s_userId"] = mae.UId
-	}
-	res, _ := db.Mgo.FindOne(ReportHistoryTable, queryMap)
-	if res == nil || len(*res) == 0 {
-		return fmt.Errorf("未查询到相关数据")
-	}
-	mae.Offline = qutil.IntAll((*res)["i_offline"])
-	mae.State = qutil.IntAll((*res)["i_state"])
-	mae.BaseParam.KeysItemsStr, _ = (*res)["s_keysItems"].(string)
-	mae.BaseParam.RangeTime, _ = (*res)["s_rangeTime"].(string)
-	mae.BaseParam.RangeTimeExtra, _ = (*res)["s_rangeTimeExtra"].(string)
-	mae.BaseParam.Area, _ = (*res)["s_area"].(string)
-	mae.BaseParam.Industry, _ = (*res)["s_industry"].(string)
-	mae.BaseParam.BuyerClass, _ = (*res)["s_buyerClass"].(string)
-	mae.BaseParam.MatchingMode, _ = (*res)["s_matchingMode"].(string)
-	return nil
-}
-
-// removeEmptyRecord 删除空报告记录
-func (mae *MarketAnalysisEntity) removeEmptyRecord() {
-	queryMap := map[string]interface{}{
-		"_id": mongodb.StringTOBsonId(mae.MgoRecordId),
-	}
-	if mae.UId == mae.Pid { //主账号
-		queryMap["s_parentId"] = mae.Pid
-	} else {
-		queryMap["s_userId"] = mae.UId
-	}
-	db.Mgo.Update(ReportHistoryTable, queryMap, map[string]interface{}{
-		"$set": map[string]interface{}{"i_del": 1},
-	}, false, false)
-	//log.Println("删除空报告", queryMap)
-}
-
-// GetRecordList 获取分析记录
-func (mae *MarketAnalysisEntity) GetRecordList(pageNum, PageSize int, positionType int, entId, entUserId int) (total int, list []map[string]interface{}) {
-	queryMap := map[string]interface{}{
-		"i_del": map[string]interface{}{"$ne": 1},
-	}
-	if mae.UId == mae.Pid { //主账号
-		queryMap["s_parentId"] = mae.Pid
-	} else {
-		queryMap["s_userId"] = mae.UId
-	}
-	if pageNum == 1 {
-		total = db.Mgo.Count(ReportHistoryTable, queryMap)
-		if total == 0 {
-			return
-		}
-	} else {
-		total = -1
-	}
-	res, _ := db.Mgo.Find(ReportHistoryTable, queryMap, `{"l_createTime":-1}`, nil, false, (pageNum-1)*PageSize, PageSize)
-	if res == nil || len(*res) == 0 {
-		return
-	}
-	var ids []string
-	for _, m := range *res {
-		ids = append(ids, qutil.InterfaceToStr(m["_id"]))
-	}
-	idMap := make(map[string]map[string]interface{})
-	tName, _ := GetMongoColl(marketScaleMain)
-	mids, _ := db.Mgo.Find(tName, map[string]interface{}{
-		"s_m_id": map[string]interface{}{
-			"$in": ids,
-		},
-	}, "", `{"market_profile":1,"s_m_id":1}`, false, -1, -1)
-	if mids != nil && len(*mids) > 0 {
-		for _, m := range *mids {
-			marketProfile, _ := m["market_profile"].(map[string]interface{})
-			if qutil.IntAll(marketProfile["project_count"]) > 0 {
-				idMap[qutil.InterfaceToStr(m["s_m_id"])] = marketProfile
-			}
-		}
-	}
-
-	//用户消息开关
-	open := GetMsgOpen(mae.MgoUserId, positionType, entId, entUserId)
-	for _, row := range *res {
-		var status int
-		if row["i_state"] != nil {
-			status = qutil.IntAll(row["i_state"])
-			if status == ReportStateFailed {
-				status = ReportStateGenerating // 生成失败对外还是展示为生成中
-			}
-		}
-		var (
-			isDownload bool
-		)
-		marketProfile := make(map[string]interface{})
-		if marketProfile = idMap[mongodb.BsonIdToSId(row["_id"])]; marketProfile != nil && qutil.IntAll(marketProfile["project_count"]) > 0 && status == 1 {
-			isDownload = true
-		}
-		//P510  回显 移除 其它
-		industry := qutil.ObjToString(row["s_industry"])
-		if industry != "" {
-			industry = strings.ReplaceAll(industry, "\"其它\"", "")
-		}
-		data := map[string]interface{}{
-			"id":               util.EncodeId(mongodb.BsonIdToSId(row["_id"])),
-			"keysItems":        qutil.ObjToString(row["s_keysItems"]),
-			"area":             qutil.ObjToString(row["s_area"]),
-			"industry":         industry,
-			"buyerclass":       qutil.ObjToString(row["s_buyerClass"]),
-			"rangeTime":        qutil.ObjToString(row["s_rangeTime"]),
-			"s_rangeTimeExtra": qutil.ObjToString(row["s_rangeTimeExtra"]),
-			"createTime":       qutil.Int64All(row["l_createTime"]),
-			"matchingMode":     qutil.ObjToString(row["s_matchingMode"]), //项目匹配方式
-			"state":            qutil.If(row["i_state"] == nil, nil, status),
-			"updateTime":       qutil.Int64All(row["l_updateTime"]),
-			"msgOpen":          open,
-			"isDownload":       isDownload,
-			"marketProfile":    marketProfile,
-		}
-		list = append(list, data)
-	}
-	return
-}
-
-func (mae *MarketAnalysisEntity) GetRecordPdfList(pageNum, PageSize int) (total int, list []map[string]interface{}) {
-	queryMap := map[string]interface{}{
-		"i_del":  map[string]interface{}{"$ne": 1},
-		"source": "analysisPDF",
-	}
-	if mae.UId == mae.Pid { //主账号
-		queryMap["s_parentId"] = mae.Pid
-	} else {
-		queryMap["s_userId"] = mae.UId
-	}
-	if pageNum == 1 {
-		total = db.Mgo.Count(ReportHistoryTable, queryMap)
-		if total == 0 {
-			return
-		}
-	} else {
-		total = -1
-	}
-	res, _ := db.Mgo.Find(ReportHistoryTable, queryMap, `{"l_createTime":-1}`, nil, false, (pageNum-1)*PageSize, PageSize)
-	if res == nil || len(*res) == 0 {
-		return
-	}
-	for _, row := range *res {
-		data := map[string]interface{}{
-			"id":               util.EncodeId(mongodb.BsonIdToSId(row["_id"])),
-			"keysItems":        qutil.ObjToString(row["s_keysItems"]),
-			"area":             qutil.ObjToString(row["s_area"]),
-			"industry":         qutil.ObjToString(row["s_industry"]),
-			"buyerclass":       qutil.ObjToString(row["s_buyerClass"]),
-			"rangeTime":        qutil.ObjToString(row["s_rangeTime"]),
-			"s_rangeTimeExtra": qutil.ObjToString(row["s_rangeTimeExtra"]),
-			"createTime":       qutil.Int64All(row["l_createTime"]),
-			"matchingMode":     qutil.ObjToString(row["s_matchingMode"]), //项目匹配方式
-			"updateTime":       qutil.Int64All(row["l_updateTime"]),
-			"audit":            qutil.Int64All(row["audit"]),
-		}
-		list = append(list, data)
-	}
-	return
-}
-
-// GetQueryItem 获取查询条件,前端回显使用
-func (mae *MarketAnalysisEntity) getQueryItem() (map[string]interface{}, error) {
-	return map[string]interface{}{
-		"keysItems":        mae.BaseParam.KeysItemsStr,
-		"area":             mae.BaseParam.Area,
-		"industry":         mae.BaseParam.Industry,
-		"buyerclass":       mae.BaseParam.BuyerClass,
-		"rangeTime":        mae.BaseParam.RangeTime,
-		"s_rangeTimeExtra": mae.BaseParam.RangeTimeExtra,
-		"matchingMode":     mae.BaseParam.MatchingMode,
-	}, nil
-}
-
-// GetPartResult 分块儿获取报告内容
-func (mae *MarketAnalysisEntity) GetPartResult(flag int) (map[string]interface{}, error) {
-	defer qutil.Catch()
-	if flag == marketQueryItem { //返回查询内容
-		return mae.getQueryItem()
-	}
-	thisCacheKey := fmt.Sprintf(ReportCacheKey, mae.MgoRecordId, flag)
-	if cacheData := redis.Get(ReportCacheDB, thisCacheKey); cacheData != nil {
-		if cacheMap, ok := cacheData.(map[string]interface{}); ok && len(cacheMap) > 0 {
-			return cacheMap, nil
-		}
-	}
-	rData, err := func() (map[string]interface{}, error) {
-		//控制并发&&超时返回超时异常
-		select {
-		case <-time.After(time.Duration(config.Config.MarketAnalysisPool.TimeOut) * time.Second * 20):
-			return nil, fmt.Errorf("查询超时,请稍后重试")
-		case <-MarketAnalysisPool:
-		}
-		start := time.Now()
-		defer func() {
-			MarketAnalysisPool <- true
-			log.Printf("report %s[%d] speed %d ms\n", mae.MgoRecordId, flag, time.Now().Sub(start).Milliseconds())
-		}()
-		//校验报告是否合法
-		//if flag != marketScaleMain {
-		//	if exists, _ := redis.Exists(ReportCacheDB, fmt.Sprintf(ReportCacheKey, mae.MgoRecordId, 1)); !exists {
-		//		return nil, fmt.Errorf("报告异常请求,请刷新重试")
-		//	}
-		//}
-		// 1. 查mongo
-		var rData map[string]interface{}
-		var err error
-		rData, err = mae.GetMongoData(flag)
-		// 查到数据则直接返回
-		if err == nil && rData != nil {
-			return rData, nil
-		}
-		// 2.没有查询到数据 判断是不是离线的
-		//  正常情况下正在离线生的不会走到这里
-		// 离线的应该生成完报告之后才会调用获取结果接口 这里处理是防止直接调接口传正在离线生的报告
-		if mae.Offline == ValueOffline || mae.Offline == 0 {
-			return nil, err
-		}
-		// 3. 实时则查es
-		rData, err = mae.realTimeQuery(flag)
-		if err == nil && len(rData) > 0 {
-			// 4.存库
-			mae.SaveMongoReport(rData, flag)
-			return rData, err
-		}
-		return nil, err
-	}()
-	if err == nil && rData != nil && len(rData) > 0 {
-		delete(rData, "s_m_id")
-		delete(rData, "_id")
-		redis.Put(ReportCacheDB, thisCacheKey, rData, ReportCacheTime)
-	}
-	return rData, err
-}
-
-// 实时查询
-func (mae *MarketAnalysisEntity) realTimeQuery(flag int) (map[string]interface{}, error) {
-	switch flag {
-	case marketScaleMain:
-		rData, err := mae.MarketTime()
-		if err != nil { //若无报告内容,删除报告记录
-			go mae.removeEmptyRecord()
-		}
-		return rData, err
-	case marketTopProject:
-		return mae.ProjectTop10()
-	case marketProjectAllData:
-		return mae.AllData()
-	case marketScaleRefine:
-		return mae.marketScaleRefineQuery()
-	case marketBuyerAndWinner:
-		return mae.BuyerWinnerAnalysis(), nil
-	}
-	return nil, fmt.Errorf("未知请求")
-}
-
-// GetMongoData 从mongo库查询数据
-func (mae *MarketAnalysisEntity) GetMongoData(flag int) (map[string]interface{}, error) {
-	collName, err := GetMongoColl(flag)
-	if err != nil || collName == "" {
-		return nil, fmt.Errorf("未知请求")
-	}
-	// 查询
-	query := map[string]interface{}{
-		"s_m_id": mae.MgoRecordId,
-	}
-	data, b := db.Mgo.FindOne(collName, query)
-	if !b || data == nil || len(*data) == 0 {
-		log.Println("没有查询到数据", b, query, collName)
-		return nil, nil
-	}
-	delete(*data, "s_m_id")
-	delete(*data, "_id")
-	return *data, nil
-}
-
-// GetMongoColl 获取mgo库对应的Coll
-func GetMongoColl(flag int) (string, error) {
-	switch flag {
-	case marketScaleMain:
-		return CollMarketScaleMain, nil
-	case marketTopProject:
-		return CollMarketTopProject, nil
-	case marketProjectAllData:
-		return CollMarketProjectAllData, nil
-	case marketScaleRefine:
-		return CollMarketScaleRefine, nil
-	case marketBuyerAndWinner:
-		return CollMarketBuyerAndWinner, nil
-	}
-	return "", fmt.Errorf("未知类型")
-}
-
-// SaveMongoReport 数据存mongo库
-func (mae *MarketAnalysisEntity) SaveMongoReport(rData map[string]interface{}, flag int) {
-	collName, _ := GetMongoColl(flag)
-	rData["s_m_id"] = mae.MgoRecordId
-	b, err := json.Marshal(rData)
-	if err != nil {
-		log.Println("JSON marshal error:", err)
-	} else {
-		var saveMap map[string]interface{}
-		err = json.Unmarshal(b, &saveMap)
-		if err != nil {
-			log.Println("JSON Unmarshal error:", err)
-			db.Mgo.Save(collName, rData)
-		} else {
-			db.Mgo.Save(collName, saveMap)
-		}
-	}
-}
-
-// GetAnalyzingReport 是否有正在分析的离线报告
-func (mae *MarketAnalysisEntity) GetAnalyzingReport() string {
-	query := map[string]interface{}{
-		"s_userId": mae.UId,
-		"i_state":  map[string]interface{}{"$in": []int{ReportStateGenerating, ReportStateFailed}}, //状态:默认0:生成中;1:已生成;2:已取消;-1:生成失败
-		"i_del":    map[string]interface{}{"$ne": 1},
-	}
-	//log.Println("query:", query)
-	rs, b := db.Mgo.FindOne(ReportHistoryTable, query)
-	//log.Println("rs,b:", rs, b)
-	if b && rs != nil {
-		return mongodb.BsonIdToSId((*rs)["_id"])
-	}
-	return ""
-}
-
-// IsOffline 判断是否符合在线分析的条件
-func (mae *MarketAnalysisEntity) IsOffline() (offline bool) {
-	//离线生成:订阅词(关键词+排除词)超过300个(数量支持配置),或单次分析数据超过60万条,则离线生成;
-	keyCount := 0
-	for i := 0; i < len(mae.FormatParam.KeysItems); i++ {
-		items := mae.FormatParam.KeysItems[i]
-		for j := 0; j < len(items.A_Key); j++ {
-			AKey := items.A_Key[j]
-			for k := 0; k < len(AKey.Keyword); k++ {
-				keyCount++
-			}
-			for k := 0; k < len(AKey.Appended); k++ {
-				keyCount++
-			}
-			for k := 0; k < len(AKey.Exclude); k++ {
-				keyCount++
-			}
-		}
-	}
-	if keyCount > config.Config.MarketAnalysisPool.KeyWordsCount {
-		// 查询配置
-		if mac := mae.getMarUserAccount(); mac != nil {
-			if keyCount >= mac.Threshold {
-				mae.Offline = ValueOffline
-				return true
-			}
-		} else {
-			mae.Offline = ValueOffline
-			return true
-		}
-	}
-
-	//  查询数据量
-	countSql := fmt.Sprintf(mae.GetCommonQuerySql(), "")
-	log.Println("IsOffline count SQL:", countSql)
-	a := time.Now()
-	dataCount := elastic.Count("projectset", "projectset", countSql)
-	b := time.Since(a)
-	log.Println("IsOffline 统计数据量耗时:", b)
-	log.Println("IsOffline 数据量:", dataCount)
-	mae.OriginalTotal = dataCount
-	if int(dataCount) > config.Config.MarketAnalysisPool.ProjectNumLimit {
-		mae.Offline = ValueOffline
-		return true
-	}
-	mae.Offline = ValueRealTime
-	return false
-}
-
-type MarUserAccount struct {
-	Threshold int // 关键词离线标准量
-}
-
-// 获取离线市场报告分析关键词标准信息
-func (mae *MarketAnalysisEntity) getMarUserAccount() *MarUserAccount {
-	rs := db.Mysql.SelectBySql(fmt.Sprintf("SELECT threshold FROM %s where  position_id=? and state = 0;", Tablejianyu_mar_user_account), mae.PositionId)
-	if rs != nil && len(*rs) > 0 {
-		return &MarUserAccount{Threshold: qutil.IntAll((*rs)[0]["threshold"])}
-	}
-	return nil
-}
-func (mae *MarketAnalysisEntity) GetReportState() (generated bool, needUpdate bool, err error) {
-	// 查库
-	err = mae.GetAnalysisFromMgoDb()
-	if err != nil {
-		return
-	}
-	// 已经生成的可以直接返回
-	if mae.State == ReportStateGenerated {
-		generated = true
-		return
-	}
-	// 该字段没有值 说明是还没有被更新的历史数据 需要更新
-	// 且判断之后后续需要更新i_state和i_offline字段
-	if mae.Offline == 0 {
-		needUpdate = true
-	}
-	// 如果没有值的话 说明这是历史数据  需要接着走下面的流程进行判断
-	// 格式化数据 用于后面校验个数
-	if err = mae.ForMatData(); err != nil {
-		return
-	}
-	return
-
-}
-
-// Cancel 取消正在分析中的报告
-func (mae *MarketAnalysisEntity) Cancel() (bool, error) {
-	// 取消报告
-	queryMap := map[string]interface{}{
-		"_id":     mae.MgoRecordId,
-		"i_state": map[string]interface{}{"$in": []int{ReportStateGenerating, ReportStateFailed}}, //状态:默认0:生成中;1:已生成;2:已取消;-1:生成失败
-		"i_del":   map[string]interface{}{"$ne": 1},
-	}
-	if mae.UId == mae.Pid { //主账号
-		queryMap["s_parentId"] = mae.Pid
-	} else {
-		queryMap["s_userId"] = mae.UId
-	}
-	//验证
-	rs, b := db.Mgo.FindOne(ReportHistoryTable, queryMap)
-	//
-	if !b || rs == nil {
-		return false, fmt.Errorf("未查询到该记录")
-	}
-	update := db.Mgo.UpdateById(ReportHistoryTable, mae.MgoRecordId, map[string]interface{}{"$set": map[string]interface{}{
-		"l_updateTime": time.Now().Unix(),
-		"i_state":      ReportStateCanceled,
-	}})
-	if !update {
-		log.Println("分析报告取消失败:", mae.MgoRecordId)
-		return false, fmt.Errorf("取消失败")
-	}
-	// redis里面放取消标识
-	redis.Put(ReportCacheDB, fmt.Sprintf(ReportCanceledKey, mae.MgoRecordId), 1, ReportCanceledTime)
-	return update, nil
-}
-
-// UpdateOffline 更新报告是否是离线报告
-func (mae *MarketAnalysisEntity) UpdateOffline(offline bool) bool {
-	set := map[string]interface{}{
-		"i_state":      qutil.If(offline, ReportStateGenerating, ReportStateGenerated),
-		"i_offline":    qutil.If(offline, ValueOffline, ValueRealTime),
-		"l_updateTime": time.Now().Unix(),
-		"s_mgoUserId":  mae.MgoUserId, // 这里更新这些字段是因为这几个字段是p437 版本新加上的 历史数据没有这些字段
-		"s_positionId": mae.PositionId,
-		"s_phone":      mae.Phone,
-	}
-	if mae.OriginalTotal > 0 {
-		set["l_originalTotal"] = mae.OriginalTotal
-	}
-	data := map[string]interface{}{
-		"$set": set,
-	}
-	update := db.Mgo.UpdateById(ReportHistoryTable, mae.MgoRecordId, data)
-	if !update {
-		log.Println("UpdateOffline 更新报告状态失败:", data, mae.MgoRecordId)
-	}
-	return update
-}
-
-// UpdateState 更新报告生成状态
-func (mae *MarketAnalysisEntity) UpdateState(state int) bool {
-	data := map[string]interface{}{
-		"$set": map[string]interface{}{
-			"i_state":      state,
-			"l_updateTime": time.Now().Unix(),
-		},
-	}
-	update := db.Mgo.UpdateById(ReportHistoryTable, mae.MgoRecordId, data)
-	if !update {
-		log.Println("UpdateState 更新报告生成状态失败:", data, mae.MgoRecordId)
-	}
-	return update
-}
-
-// Delete 删除正在分析中的报告
-func (mae *MarketAnalysisEntity) Delete() (bool, error) {
-	// 删除报告
-	queryMap := map[string]interface{}{
-		"_id":   mae.MgoRecordId,
-		"i_del": map[string]interface{}{"$ne": 1},
-	}
-	if mae.UId == mae.Pid { //主账号
-		queryMap["s_parentId"] = mae.Pid
-	} else {
-		queryMap["s_userId"] = mae.UId
-	}
-	//验证
-	rs, b := db.Mgo.FindOne(ReportHistoryTable, queryMap)
-	//
-	if !b || rs == nil {
-		return false, fmt.Errorf("未查询到该记录")
-	}
-	update := db.Mgo.UpdateById(ReportHistoryTable, mae.MgoRecordId, map[string]interface{}{"$set": map[string]interface{}{
-		"l_updateTime": time.Now().Unix(),
-		"i_del":        1,
-	}})
-	if !update {
-		log.Println("分析报告删除失败:", mae.MgoRecordId)
-		return false, fmt.Errorf("删除失败")
-	}
-	// redis里面放取消标识
-	redis.Put(ReportCacheDB, fmt.Sprintf(ReportCanceledKey, mae.MgoRecordId), 1, ReportCanceledTime)
-	return update, nil
-}
-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
-}
-
-// GetMsgOpen 获取用户服务通知开关是否开启
-func GetMsgOpen(mgoUserId string, positionType int, entId, entUserId int) bool {
-	pushSetMap := &map[string]interface{}{}
-	if positionType == 1 {
-		pushSetMap, _ = db.Mgo.FindOne("ent_user", map[string]interface{}{"i_entid": entId, "i_userid": entUserId})
-	} else {
-		pushSetMap, _ = db.Mgo.FindById("user", mgoUserId, `{"o_pushset":1,"s_m_openid":1}`)
-	}
-	//log.Println(mgoUserId, pushSetMap)
-	if pushSetMap != nil && len(*pushSetMap) > 0 {
-		pushset := qutil.ObjToMap((*pushSetMap)["o_pushset"])
-		if pushset == nil || len(*pushset) == 0 {
-			return false
-		}
-		msgServicePushSet := qutil.ObjToMap((*pushset)["o_msg_service"])
-		if msgServicePushSet != nil {
-			if qutil.IntAll((*msgServicePushSet)["i_apppush"]) == 1 || qutil.IntAll((*msgServicePushSet)["i_wxpush"]) == 1 {
-				return true
-			}
-		}
-	}
-	return false
-}

+ 0 - 274
src/jfw/modules/bigmember/src/entity/marketAnalysis/scaleRefineQuery.go

@@ -1,274 +0,0 @@
-package marketAnalysis
-
-import (
-	"encoding/json"
-	"fmt"
-	"jy/src/jfw/modules/bigmember/src/util"
-	"sort"
-	"strings"
-)
-
-const (
-	_ = iota
-	onlyTotal
-	onlyAmount
-	totalAndAmount
-
-	topWinnerLimit = 3   //细分市场展示前x个企业
-	topItemLimit   = 300 //返回前x组关键词
-)
-
-type scaleRefineData struct {
-	Data       []*scaleRefineRow
-	Total      simpleTotal
-	Amount     simpleSum
-	IdSwitch   map[string]string
-	ReturnData struct {
-		Overall             []map[string]interface{}
-		TotalTop, AmountTop []*returnItem
-	}
-}
-
-type simpleTotal struct {
-	Total int64 `json:"doc_count"`
-}
-
-type simpleSum struct {
-	Value float64 `json:"value"`
-}
-
-type scaleRefineRow struct {
-	Total          int64     `json:"doc_count"`
-	TotalProp      float64   `json:"total_prop"`
-	Amount         simpleSum `json:"project_amount"`
-	AmountProp     float64   `json:"amount_prop"`
-	WinnerTotalTop struct {
-		Buckets []*struct {
-			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"`
-			Amount  struct {
-				Value float64 `json:"value"`
-			} `json:"refine_winner_amount"`
-			Prop float64 `json:"prop"`
-		} `json:"buckets"`
-	} `json:"winner_amount_top"`
-	ItemName   string `json:"itemName"`
-	UpdateTime int64  `json:"updateTime"`
-}
-
-type returnItem struct {
-	Name    string      `json:"name"`
-	Value   interface{} `json:"value"`
-	Prop    interface{} `json:"prop"`
-	TopList []*entValue `json:"topList"`
-}
-
-type entValue struct {
-	Id    string      `json:"id"`
-	Name  string      `json:"name"`
-	Value interface{} `json:"value"`
-	Prop  interface{} `json:"prop"`
-}
-
-// marketScaleRefineQuery 细化聚合
-func (mae *MarketAnalysisEntity) marketScaleRefineQuery() (rMap map[string]interface{}, err error) {
-	//关键词分组聚合
-	var aggsGroup []string
-	//获取总金额及总数
-	aggsGroup = append(aggsGroup, `"projectAmount":{"sum":{"field":"sortprice"}}`)
-	aggsGroup = append(aggsGroup, `"projectTotal":{"filter":{"match_all":{}}}`)
-	itemDataMap := map[string]int64{}
-	for _, group := range mae.FormatParam.KeysItems {
-		var bools []string
-		for _, v := range getGroupKeywordArr(group.A_Key) {
-			if sql := getKeyWordSql(v, mae.BaseParam.MatchingMode); sql != "" {
-				bools = append(bools, sql)
-			}
-		}
-		if len(bools) > 0 {
-			aggsGroup = append(aggsGroup, fmt.Sprintf(`"%s":{"filter":{"bool":{"should":[%s],"minimum_should_match": 1}},"aggs":{"project_count":{"filter":{"match_all":{}}},"project_amount":{"sum":{"field":"sortprice"}},"winner_total_top":{"terms":{"field":"entidlist","exclude":["-"],"order":[{"refine_winner_total":"desc"}],"size":%d},"aggs":{"refine_winner_total":{"filter":{"match_all":{}}}}},"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, ","))
-	fmt.Println("finalSql-----4", finalSql)
-	rMap = map[string]interface{}{}
-	res := util.GetAggs("projectset", "projectset", finalSql)
-	if res == nil || len(res) == 0 {
-		return
-	}
-	scale := scaleRefineData{IdSwitch: map[string]string{}}
-	for name, object := range res {
-		bArr, err := object.MarshalJSON()
-		if len(bArr) == 0 || err != nil {
-			continue
-		}
-		if name == "projectTotal" {
-			st := simpleTotal{}
-			if err := json.Unmarshal(bArr, &st); err == nil {
-				scale.Total = st
-			}
-			continue
-		} else if name == "projectAmount" {
-			ss := simpleSum{}
-			if err := json.Unmarshal(bArr, &ss); err == nil {
-				scale.Amount = ss
-			}
-			continue
-		}
-		thisRow := scaleRefineRow{}
-		if err := json.Unmarshal(bArr, &thisRow); err != nil {
-			continue
-		}
-		thisRow.ItemName = name
-		thisRow.UpdateTime = itemDataMap[name]
-		scale.Data = append(scale.Data, &thisRow)
-	}
-	scale.formatData() //获取所需数据
-	scale.doIdSwitch() //补充企业名称
-	return map[string]interface{}{
-		"scaleRefineAll":       scale.ReturnData.Overall,
-		"scaleRefineTotalTop":  scale.ReturnData.TotalTop,
-		"scaleRefineAmountTop": scale.ReturnData.AmountTop,
-	}, nil
-}
-
-// 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 计算百分比&获取企业对应名称
-func (srd *scaleRefineData) formatData() {
-	for _, v := range srd.Data {
-		if srd.Total.Total == 0 {
-			v.TotalProp = 0
-		} else {
-			v.TotalProp = float64(v.Total) / float64(srd.Total.Total)
-		}
-		if srd.Amount.Value == 0 {
-			v.AmountProp = 0
-		} else {
-			v.AmountProp = v.Amount.Value / srd.Amount.Value
-		}
-
-		for _, vv := range v.WinnerTotalTop.Buckets {
-			if v.Total == 0 {
-				vv.Prop = 0
-			} else {
-				vv.Prop = float64(vv.Total) / float64(v.Total)
-			}
-		}
-		for _, vv := range v.WinnerAmountTop.Buckets {
-			if v.Amount.Value == 0 {
-				vv.Prop = 0
-			} else {
-				vv.Prop = vv.Amount.Value / v.Amount.Value
-			}
-		}
-	}
-	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仅返回金额统计
-func (srd *scaleRefineData) getFormatTop(limit, flag int) (rData []*returnItem) {
-	for index, Value := range srd.Data {
-		if index >= limit && limit > -1 {
-			return
-		}
-		thisRow := &returnItem{
-			Name: Value.ItemName,
-		}
-		if flag == 1 || flag == 3 { //返回数量相关数据
-			thisRow.Value = Value.Total
-			if flag != 3 {
-				for _, v := range Value.WinnerTotalTop.Buckets {
-					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
-			}
-		}
-		if flag == 2 || flag == 3 { //返回金额相关数据
-			thisRow.Value = Value.Amount.Value
-			if flag != 3 {
-				for _, v := range Value.WinnerAmountTop.Buckets {
-					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.TotalProp
-			}
-		}
-		rData = append(rData, thisRow)
-	}
-	return
-}
-
-// getScaleRefineAll 根据订阅词组创建时间排序
-func (srd *scaleRefineData) sortBy(flag int) *scaleRefineData {
-	sort.Slice(srd.Data, func(i, j int) bool {
-		switch flag {
-		case onlyTotal:
-			return srd.Data[i].Total > srd.Data[j].Total
-		case onlyAmount:
-			return srd.Data[i].Amount.Value > srd.Data[j].Amount.Value
-		case totalAndAmount:
-			return srd.Data[i].UpdateTime > srd.Data[j].UpdateTime
-		}
-		return false
-	})
-	return srd
-}

+ 2 - 2
src/jfw/modules/bigmember/src/go.mod

@@ -5,8 +5,8 @@ go 1.20
 require (
 	app.yhyue.com/moapp/jybase v0.0.0-20240226084952-7e7b38ef8a66
 	app.yhyue.com/moapp/jylog v0.0.0-20230522075550-05d7230ca545
-	app.yhyue.com/moapp/jypkg v1.22.2
-	bp.jydev.jianyu360.cn/BaseService/powerCheckCenter v0.0.0-20240607062231-ae1d02891843
+	app.yhyue.com/moapp/jypkg v1.30.8
+	bp.jydev.jianyu360.cn/BaseService/powerCheckCenter v0.0.0-20241213060113-ac41966a58ec
 	bp.jydev.jianyu360.cn/BaseService/userCenter v1.2.18
 	github.com/donnie4w/go-logger v0.0.0-20230316073421-36a48f87a69a
 	github.com/gogf/gf/v2 v2.7.0

+ 4 - 4
src/jfw/modules/bigmember/src/go.sum

@@ -20,8 +20,8 @@ app.yhyue.com/moapp/jybase v0.0.0-20240226084952-7e7b38ef8a66/go.mod h1:XHNATN6t
 app.yhyue.com/moapp/jyfs v0.0.0-20231024061508-480c270480d4/go.mod h1:61hzZ3dZHXL28BNl8BOgZsvM2S5UVY5YFzOkEUPrSu4=
 app.yhyue.com/moapp/jylog v0.0.0-20230522075550-05d7230ca545 h1:+Lak4m1zgsigQloOsvp8AJ+0XeX/+PGp9QP550xlbBQ=
 app.yhyue.com/moapp/jylog v0.0.0-20230522075550-05d7230ca545/go.mod h1:uFrsdUBFbETiJlEmr4PtJWPsZlUpPj2bHQRhryu6ggk=
-app.yhyue.com/moapp/jypkg v1.22.2 h1:JGACT09PXN/DEjDgBSwC7veHiNrSRZH73mAc9MUV5w8=
-app.yhyue.com/moapp/jypkg v1.22.2/go.mod h1:FylaC4MJ4G36WndktgeZfc8jTq3uvBGWIwbk02xfdQI=
+app.yhyue.com/moapp/jypkg v1.30.8 h1:Yeho4JVVQGdbTDX/QhMLL5qjmuuGlfaK3csYD0nChAQ=
+app.yhyue.com/moapp/jypkg v1.30.8/go.mod h1:7f9hBxeF9RTp6vhTMZ24k4VLsn7HJHyAXOx6qzA3xOw=
 app.yhyue.com/moapp/message v0.0.0-20231204024949-8c7145bfc161 h1:WGi4OEIoqw6NpNFGioUEBZnjK9aBa+xJqf/5WY+QyhM=
 app.yhyue.com/moapp/message v0.0.0-20231204024949-8c7145bfc161/go.mod h1:0Oj8SB4pVjdCLD28sy2zyM3hS0WHGpNuVcakLW43GmI=
 bp.jydev.jianyu360.cn/BP/jynsq v0.0.0-20220222052708-ebc43af90698/go.mod h1:ojo/AUH9Yr1wzarEjOaNMkj1Cet/9r8IgLyba64Z52E=
@@ -31,8 +31,8 @@ bp.jydev.jianyu360.cn/BaseService/gateway v0.0.0-20220419090715-88ddb32961be/go.
 bp.jydev.jianyu360.cn/BaseService/gateway v1.3.4/go.mod h1:BMLd/5wb3BIEGhnEgF9y1sJN9P5/Dw9kYsoiE9V8I9g=
 bp.jydev.jianyu360.cn/BaseService/jyMicroservices v0.0.2 h1:Qi8C7gZeR7+kjOtSl9ilR5HwbjCe8GO1RuotFb4+kFA=
 bp.jydev.jianyu360.cn/BaseService/jyMicroservices v0.0.2/go.mod h1:v8y7FCbkKEIRP4Ie9ZM8NtoRP+Fk4O3C1hnexNusYIQ=
-bp.jydev.jianyu360.cn/BaseService/powerCheckCenter v0.0.0-20240607062231-ae1d02891843 h1:u+8k/T0D6EUjj9BhI5RJdRa+8v4FZbyZhaNcm66L6Vs=
-bp.jydev.jianyu360.cn/BaseService/powerCheckCenter v0.0.0-20240607062231-ae1d02891843/go.mod h1:rCCaOSWBYfQabf/yIvSVheSPtN2THnHeTl2J5/RrcuU=
+bp.jydev.jianyu360.cn/BaseService/powerCheckCenter v0.0.0-20241213060113-ac41966a58ec h1:oCO36pHkEHQa5+Z/DU83T5xT5NKptVbw5UVQSN6lJjw=
+bp.jydev.jianyu360.cn/BaseService/powerCheckCenter v0.0.0-20241213060113-ac41966a58ec/go.mod h1:rCCaOSWBYfQabf/yIvSVheSPtN2THnHeTl2J5/RrcuU=
 bp.jydev.jianyu360.cn/BaseService/pushpkg v0.0.0-20230911091604-2faa31032743/go.mod h1:1SQIPPL5Ya5BzQdByFKtTkXrXTWBv+PDqWIhNknLnZw=
 bp.jydev.jianyu360.cn/BaseService/resourceCenter v0.0.0-20220418005748-8ba5d936dd53/go.mod h1:E5lcDI3k4FESLxiAetCfWQTq8qfpy9cv0yN1oKoEO34=
 bp.jydev.jianyu360.cn/BaseService/resourceCenter v0.0.0-20220419023723-0b32d4a41751/go.mod h1:6KL5LMEku83uRbre0W/bj5kXG2I6pJGBFtktmtp51yM=

+ 37 - 26
src/jfw/modules/bigmember/src/service/report/marketAnalysis.go

@@ -5,7 +5,10 @@ import (
 	"errors"
 	"fmt"
 	"jy/src/jfw/modules/bigmember/src/config"
-	"jy/src/jfw/modules/bigmember/src/entity/marketAnalysis"
+	"jy/src/jfw/modules/bigmember/src/db"
+
+	//"jy/src/jfw/modules/bigmember/src/entity/marketAnalysis"
+	ma "app.yhyue.com/moapp/jypkg/marketanalysis"
 	"jy/src/jfw/modules/bigmember/src/util"
 	"log"
 	"strings"
@@ -52,7 +55,7 @@ func (this *MarketAnalysis) ProjectInfo() {
 		}
 		log.Println("keysItems==", this.GetString("keysItems"))
 		//接受参数
-		bParam := marketAnalysis.AnalysisRequestParam{
+		bParam := ma.AnalysisRequestParam{
 			KeysItemsStr:   this.GetString("keysItems"),      //分析内容【字符串】结构和o_member_jy.a_items保持一致
 			RangeTime:      this.GetString("rangeTime"),      //时间【字符串】 时间戳开始-结束时间戳
 			RangeTimeExtra: this.GetString("rangeTimeExtra"), //时间【字符串】 时间戳开始-结束时间戳
@@ -67,11 +70,11 @@ func (this *MarketAnalysis) ProjectInfo() {
 			PageNum:        pageNum,                          //当前页码
 			IsDetail:       true,                             //是否是项目明细请求
 		}
-		mae := &marketAnalysis.MarketAnalysisEntity{MgoRecordId: rid, BaseParam: bParam, UId: userId, Pid: pid}
+		mae := &ma.AnalysisEntity{MgoRecordId: rid, BaseParam: bParam, UId: userId, Pid: pid, Mgo: &db.Mgo, MySql: db.Mysql}
 		//参数验证 --:回显字段keysItems、area、industry、buyerclass
 
 		//原查询条件
-		maePrimary := &marketAnalysis.MarketAnalysisEntity{MgoRecordId: rid, UId: userId, Pid: pid}
+		maePrimary := &ma.AnalysisEntity{MgoRecordId: rid, UId: userId, Pid: pid, Mgo: &db.Mgo, MySql: db.Mysql}
 		if err := maePrimary.GetAnalysisFromMgoDb(); err == nil {
 			if bParam.KeysItemsStr == "" || bParam.KeysItemsStr == "{}" ||
 				bParam.KeysItemsStr == "[]" || len([]rune(bParam.KeysItemsStr)) < 2 { //分析内容【字符串】结构和o_member_jy.a_items保持一致
@@ -145,7 +148,7 @@ func (this *MarketAnalysis) DoAnalysisPdf() {
 	sessVal := this.Session().GetMultiple()
 	mgoUserId := qutil.ObjToString(sessVal["mgoUserId"])
 	userId := qutil.ObjToString(sessVal["userId"])
-	positionId := qutil.IntAll(sessVal["positionId"])
+	positionId := qutil.Int64All(sessVal["positionId"])
 	phone := qutil.ObjToString(sessVal["phone"])
 	rData, errMsg := func() (interface{}, error) {
 		if phone == "" || !strings.Contains(config.Config.AnalysisPDFPhone, phone) {
@@ -157,7 +160,7 @@ func (this *MarketAnalysis) DoAnalysisPdf() {
 			return nil, powerErr
 		}
 		//接受参数
-		bParam := marketAnalysis.AnalysisRequestParam{
+		bParam := ma.AnalysisRequestParam{
 			KeysItemsStr:   this.GetString("keysItems"),      //分析内容【字符串】结构和o_member_jy.a_items保持一致
 			RangeTime:      this.GetString("rangeTime"),      //时间【字符串】 时间戳开始-结束时间戳
 			RangeTimeExtra: this.GetString("rangeTimeExtra"), //时间【字符串】 时间戳开始-结束时间戳
@@ -166,7 +169,7 @@ func (this *MarketAnalysis) DoAnalysisPdf() {
 			BuyerClass:     this.GetString("buyerclass"),     //采购单位类型【字符串】多个采购单位类型用逗号拼接
 			MatchingMode:   this.GetString("matchingMode"),   //匹配方式
 		}
-		mae := &marketAnalysis.MarketAnalysisEntity{BaseParam: bParam, UId: userId, Pid: pid, MgoUserId: mgoUserId, PositionId: positionId, Phone: phone, Source: "analysisPDF"}
+		mae := &ma.AnalysisEntity{BaseParam: bParam, UId: userId, Pid: pid, MgoUserId: mgoUserId, PositionId: positionId, Phone: phone, Source: "analysisPDF", Mgo: &db.Mgo, MySql: db.Mysql}
 		if id, err := mae.ForMatDataPdf(); err != nil {
 			return map[string]interface{}{
 				"id": util.EncodeId(id),
@@ -193,7 +196,7 @@ func (this *MarketAnalysis) AnalysisPdfList() {
 	sessVal := this.Session().GetMultiple()
 	mgoUserId := qutil.ObjToString(sessVal["mgoUserId"])
 	userId := qutil.ObjToString(sessVal["userId"])
-	positionId := qutil.IntAll(sessVal["positionId"])
+	positionId := qutil.Int64All(sessVal["positionId"])
 	phone := qutil.ObjToString(sessVal["phone"])
 	rData, errMsg := func() (interface{}, error) {
 		if phone == "" || !strings.Contains(config.Config.AnalysisPDFPhone, phone) {
@@ -213,7 +216,7 @@ func (this *MarketAnalysis) AnalysisPdfList() {
 		if pageSizeErr != nil {
 			pageSize = 10
 		}
-		mae := &marketAnalysis.MarketAnalysisEntity{UId: userId, Pid: pid, MgoUserId: mgoUserId, PositionId: positionId}
+		mae := &ma.AnalysisEntity{UId: userId, Pid: pid, MgoUserId: mgoUserId, PositionId: positionId, Mgo: &db.Mgo, MySql: db.Mysql}
 		total, list := mae.GetRecordPdfList(pageNum, pageSize)
 		return map[string]interface{}{
 			"total": total,
@@ -231,7 +234,7 @@ func (this *MarketAnalysis) DoAnalysis() {
 	sessVal := this.Session().GetMultiple()
 	mgoUserId := qutil.ObjToString(sessVal["mgoUserId"])
 	userId := qutil.ObjToString(sessVal["userId"])
-	positionId := qutil.IntAll(sessVal["positionId"])
+	positionId := qutil.Int64All(sessVal["positionId"])
 	phone := qutil.ObjToString(sessVal["phone"])
 	positionType := qutil.IntAll(sessVal["positionType"])
 	entId := qutil.IntAll(sessVal["entId"])
@@ -242,7 +245,7 @@ func (this *MarketAnalysis) DoAnalysis() {
 			return nil, powerErr
 		}
 		//接受参数
-		bParam := marketAnalysis.AnalysisRequestParam{
+		bParam := ma.AnalysisRequestParam{
 			KeysItemsStr:   this.GetString("keysItems"),      //分析内容【字符串】结构和o_member_jy.a_items保持一致
 			RangeTime:      this.GetString("rangeTime"),      //时间【字符串】 时间戳开始-结束时间戳
 			RangeTimeExtra: this.GetString("rangeTimeExtra"), //时间【字符串】 时间戳开始-结束时间戳
@@ -251,7 +254,7 @@ func (this *MarketAnalysis) DoAnalysis() {
 			BuyerClass:     this.GetString("buyerclass"),     //采购单位类型【字符串】多个采购单位类型用逗号拼接
 			MatchingMode:   this.GetString("matchingMode"),   //匹配方式
 		}
-		mae := &marketAnalysis.MarketAnalysisEntity{BaseParam: bParam, UId: userId, Pid: pid, MgoUserId: mgoUserId, PositionId: positionId, Phone: phone}
+		mae := &ma.AnalysisEntity{BaseParam: bParam, UId: userId, Pid: pid, MgoUserId: mgoUserId, PositionId: positionId, Phone: phone, Mgo: &db.Mgo, MySql: db.Mysql}
 		if err := mae.ForMatData(); err != nil {
 			return nil, err
 		}
@@ -265,11 +268,18 @@ func (this *MarketAnalysis) DoAnalysis() {
 		var status int
 		var msgOpen bool
 		// 判断是否为离线生成报告
-		offline := mae.IsOffline()
+		mae.IsOffline()
+		if mae.Offline < 0 {
+			return map[string]interface{}{
+				"msg":    "当前请求分析数量过大,请修改条件后再试",
+				"status": -1,
+			}, nil
+		}
+		offline := mae.Offline == 1
 		if offline {
 			// 查询消息开关
 			status = AnalysisStatusOffline
-			msgOpen = marketAnalysis.GetMsgOpen(mgoUserId, positionType, entId, entUserId)
+			msgOpen = ma.GetMsgOpen(&db.Mgo, mgoUserId, positionType, entId, entUserId)
 		} else {
 			status = AnalysisStatusRealTime
 		}
@@ -297,13 +307,13 @@ func (this *MarketAnalysis) GetAnalysisResult() {
 	sessVal := this.Session().GetMultiple()
 	mgoUserId := qutil.ObjToString(sessVal["mgoUserId"])
 	userId := qutil.ObjToString(sessVal["userId"])
-	positionId := qutil.IntAll(sessVal["positionId"])
+	positionId := qutil.Int64All(sessVal["positionId"])
 	rData, errMsg := func() (interface{}, error) {
 		pid, isEquity, powerErr := CheckPowerEquity(this.Session())
 		if powerErr != nil {
 			return nil, powerErr
 		}
-		mae := &marketAnalysis.MarketAnalysisEntity{MgoRecordId: util.DecodeId(this.GetString("rid")), UId: userId, Pid: pid, MgoUserId: mgoUserId, PositionId: positionId}
+		mae := &ma.AnalysisEntity{MgoRecordId: util.DecodeId(this.GetString("rid")), UId: userId, Pid: pid, MgoUserId: mgoUserId, PositionId: positionId, Mgo: &db.Mgo, MySql: db.Mysql}
 		if err := mae.GetAnalysisFromMgoDb(); err != nil {
 			return nil, err
 		}
@@ -340,13 +350,13 @@ func (this *MarketAnalysis) Cancel() {
 	sessVal := this.Session().GetMultiple()
 	mgoUserId := qutil.ObjToString(sessVal["mgoUserId"])
 	userId := qutil.ObjToString(sessVal["userId"])
-	positionId := qutil.IntAll(sessVal["positionId"])
+	positionId := qutil.Int64All(sessVal["positionId"])
 	rData, errMsg := func() (interface{}, error) {
 		pid, powerErr := checkPower(this.Session())
 		if powerErr != nil {
 			return nil, powerErr
 		}
-		mae := &marketAnalysis.MarketAnalysisEntity{MgoRecordId: util.DecodeId(this.GetString("rid")), UId: userId, Pid: pid, MgoUserId: mgoUserId, PositionId: positionId}
+		mae := &ma.AnalysisEntity{MgoRecordId: util.DecodeId(this.GetString("rid")), UId: userId, Pid: pid, MgoUserId: mgoUserId, PositionId: positionId, Mgo: &db.Mgo, MySql: db.Mysql}
 		rData, err := mae.Cancel()
 		return rData, err
 	}()
@@ -361,7 +371,7 @@ func (this *MarketAnalysis) IsOffline() {
 	sessVal := this.Session().GetMultiple()
 	mgoUserId := qutil.ObjToString(sessVal["mgoUserId"])
 	userId := qutil.ObjToString(sessVal["userId"])
-	positionId := qutil.IntAll(sessVal["positionId"])
+	positionId := qutil.Int64All(sessVal["positionId"])
 	phone := qutil.ObjToString(sessVal["phone"])
 	positionType := qutil.IntAll(sessVal["positionType"])
 	entId := qutil.IntAll(sessVal["entId"])
@@ -371,7 +381,7 @@ func (this *MarketAnalysis) IsOffline() {
 		if powerErr != nil {
 			return nil, powerErr
 		}
-		mae := &marketAnalysis.MarketAnalysisEntity{MgoRecordId: util.DecodeId(this.GetString("rid")), UId: userId, Pid: pid, MgoUserId: mgoUserId, PositionId: positionId, Phone: phone}
+		mae := &ma.AnalysisEntity{MgoRecordId: util.DecodeId(this.GetString("rid")), UId: userId, Pid: pid, MgoUserId: mgoUserId, PositionId: positionId, Phone: phone, Mgo: &db.Mgo, MySql: db.Mysql}
 		// 判断是否已经生成成功
 		generated, needUpdate, err := mae.GetReportState()
 		if err != nil {
@@ -396,7 +406,8 @@ func (this *MarketAnalysis) IsOffline() {
 		var status int
 		var msgOpen bool
 		// 判断是实时的还是离线的
-		offline := mae.IsOffline()
+		mae.IsOffline()
+		offline := mae.Offline == 1
 		if err != nil {
 			return nil, err
 		}
@@ -408,7 +419,7 @@ func (this *MarketAnalysis) IsOffline() {
 		if offline {
 			// 查询消息开关
 			status = AnalysisStatusOffline
-			msgOpen = marketAnalysis.GetMsgOpen(mgoUserId, positionType, entId, entUserId)
+			msgOpen = ma.GetMsgOpen(&db.Mgo, mgoUserId, positionType, entId, entUserId)
 		} else {
 			status = AnalysisStatusRealTime
 		}
@@ -430,13 +441,13 @@ func (this *MarketAnalysis) Delete() {
 	sessVal := this.Session().GetMultiple()
 	mgoUserId := qutil.ObjToString(sessVal["mgoUserId"])
 	userId := qutil.ObjToString(sessVal["userId"])
-	positionId := qutil.IntAll(sessVal["positionId"])
+	positionId := qutil.Int64All(sessVal["positionId"])
 	rData, errMsg := func() (interface{}, error) {
 		pid, powerErr := checkPower(this.Session())
 		if powerErr != nil {
 			return nil, powerErr
 		}
-		mae := &marketAnalysis.MarketAnalysisEntity{MgoRecordId: util.DecodeId(this.GetString("rid")), UId: userId, Pid: pid, MgoUserId: mgoUserId, PositionId: positionId}
+		mae := &ma.AnalysisEntity{MgoRecordId: util.DecodeId(this.GetString("rid")), UId: userId, Pid: pid, MgoUserId: mgoUserId, PositionId: positionId, Mgo: &db.Mgo, MySql: db.Mysql}
 		data, err := mae.Delete()
 		return data, err
 	}()
@@ -451,7 +462,7 @@ func (this *MarketAnalysis) AnalysisHistory() {
 	sessVal := this.Session().GetMultiple()
 	mgoUserId := qutil.ObjToString(sessVal["mgoUserId"])
 	userId := qutil.ObjToString(sessVal["userId"])
-	positionId := qutil.IntAll(sessVal["positionId"])
+	positionId := qutil.Int64All(sessVal["positionId"])
 	positionType := qutil.IntAll(sessVal["positionType"])
 	entId := qutil.IntAll(sessVal["entId"])
 	entUserId := qutil.IntAll(sessVal["entUserId"])
@@ -469,7 +480,7 @@ func (this *MarketAnalysis) AnalysisHistory() {
 		if pageSizeErr != nil {
 			pageSize = 10
 		}
-		mae := &marketAnalysis.MarketAnalysisEntity{UId: userId, Pid: pid, MgoUserId: mgoUserId, PositionId: positionId}
+		mae := &ma.AnalysisEntity{UId: userId, Pid: pid, MgoUserId: mgoUserId, PositionId: positionId, Mgo: &db.Mgo, MySql: db.Mysql}
 		total, list := mae.GetRecordList(pageNum, pageSize, positionType, entId, entUserId)
 		return map[string]interface{}{
 			"total": total,

+ 12 - 4
src/web/staticres/common-module/report-analysis/js/report_analysis.js

@@ -987,8 +987,9 @@ var vm = new Vue({
                   }
                 }
               })
+            } else if (res.data.status === -1) {
+              return this.$toast(res.data.msg)
             }
-            
           } else {
             loading.clear()
             this.$toast(res.error_msg)
@@ -2219,12 +2220,19 @@ var vm = new Vue({
         location.href = '/jyapp/vipsubscribe/toSetKeyWordPage?vSwitch=' + rootlink
       }
     },
-    toArticleContent (item) {
+    clickTOP10ProjectName (item) {
       this.saveState()
+      const payload = {
+        fid: '',
+        sid: item._id,
+      }
+      sessionStorage.setItem('bigvip-fid', JSON.stringify(payload))
       if (utils.$envs.inWX) {
-        location.href = `/article/content/${item._id}.html`
+        // location.href = `/article/content/${item._id}.html`
+        location.href = '/big/wx/page/pro_follow_detail'
       } else {
-        location.href = `/jyapp/article/content/${item._id}.html`
+        // location.href = `/jyapp/article/content/${item._id}.html`
+        location.href = '/jyapp/big/page/pro_follow_detail'
       }
     },
     toPortrait (id, type) {

+ 27 - 3
src/web/templates/big-member/wx/page_report_analysis.html

@@ -231,7 +231,7 @@
                                               'soft-orange': index === 2
                                           }">
                                           ${ index + 1 }</div>
-                                      <div class="p-t-i-hd-r" @click="toArticleContent(item)">
+                                      <div class="p-t-i-hd-r" @click="clickTOP10ProjectName(item)">
                                           <div class="project-name">${ item.projectname }</div>
                                           <div class="project-info">
                                               <div class="project-tags">
@@ -330,7 +330,7 @@
                           </div>
                         </div>
                       </div>
-                      <van-popup
+                      <!-- <van-popup
                         v-model="sections.areaScatter.showAreaPopup"
                         closeable
                         round
@@ -353,7 +353,7 @@
                                     @confirm="confirmSelectArea"></area-component>
                             </div>
                         </div>
-                      </van-popup>
+                      </van-popup> -->
                       <div class="section bg-white pd-16" v-if="sections.areaScatter.projectCountTop3 && getStatus">
                           <div class="section-title">各地区重点中标单位-项目数量</div>
                           <div class="section-content">
@@ -562,6 +562,30 @@
       </div>
         <!-- 下载弹窗 -->
       <downloadpopup ref="downloadpopup" @lookmore="anchorTo({top:0})" :data="{buyercount,winnercount,projectTotalMoney,projectCount,balance,getStatus}"></downloadpopup>
+      <van-popup
+        v-model="sections.areaScatter.showAreaPopup"
+        closeable
+        round
+        position="bottom"
+        close-icon="clear"
+        class="j-popup collection"
+        :lazy-render="false"
+        overlay-class="j-overlay"
+        :style="{ height: '60%' }"
+        get-container="body">
+        <div class="j-container report-popup">
+            <div class="popup-header header-title">请选择省份</div>
+            <div class="j-main area-content">
+                <area-component
+                    :newprovincelist="reportFilters.area"
+                    :showcountry="false"
+                    :multiple="false"
+                    ref="areaSelector"
+                    @cancel="cancelSelectArea"
+                    @confirm="confirmSelectArea"></area-component>
+            </div>
+        </div>
+      </van-popup>
       <van-popup
           v-model="filterDialogShow.keys"
           closeable