瀏覽代碼

数据导出整理

wangkaiyue 4 年之前
父節點
當前提交
b47fb3bccd

+ 16 - 23
src/jfw/front/dataExport.go

@@ -9,6 +9,7 @@ import (
 	"log"
 	"os"
 	"qfw/util"
+	"qfw/util/dataexport"
 	"qfw/util/redis"
 	"regexp"
 	"strconv"
@@ -109,7 +110,7 @@ func (d *DataExport) SieveData() error {
 	var buyerArr []string
 	var buyerclassArr []string
 	var winnerArr []string
-	var keywordList []public.KeyWord
+	var keywordList []dataexport.KeyWord
 
 	log.Println("price", minPrice, maxPrice)
 	if publishtime != "" {
@@ -180,7 +181,7 @@ func (d *DataExport) SieveData() error {
 	if d.GetSession("userId") != nil {
 		sieveCondition["s_userid"] = d.GetSession("userId").(string)
 	}
-	_id := mongodb.Save(public.ExportTable, sieveCondition)
+	_id := mongodb.Save(dataexport.ExportTable, sieveCondition)
 	if _id != "" {
 		d.T["success"] = true
 		d.T["redirectUrl"] = "/front/dataExport/toCreateOrderPage/" + util.SE.Encode2Hex(_id)
@@ -221,7 +222,7 @@ func (d *DataExport) ToOrderDetail(orderCode string) error {
 		return nil
 	}
 	orderDetail := map[string]interface{}{}
-	filter := public.SieveCondition{}
+	filter := dataexport.SieveCondition{}
 	queryMap := map[string]interface{}{
 		"order_code": orderCode,
 		"user_id":    myUserId,
@@ -367,7 +368,7 @@ func (d *DataExport) SuperSearchExport() error {
 	saveData["s_userid"] = userId
 
 	//存入数据库
-	_id := mongodb.Save(public.ExportTable, saveData)
+	_id := mongodb.Save(dataexport.ExportTable, saveData)
 	return d.Redirect("/front/dataExport/toCreateOrderPage/" + util.SE.Encode2Hex(_id))
 }
 func (d *DataExport) ToCreateOrderPage(_id string) error {
@@ -419,8 +420,8 @@ func (d *DataExport) ToCreateOrderPage(_id string) error {
 	} else {
 		d.DelSession("Structed")
 	}
-	msgCount := public.GetDataExportSearchCountUseId(id)
-	if msgCount > public.ExConf.MsgMaxCount {
+	msgCount := dataexport.GetDataExportSearchCountByScdId(public.MQFW, public.DbConf.Elasticsearch.Main.Address, id)
+	if msgCount > public.ExConf.MsgMaxCount || msgCount == -1 {
 		msgCount = public.ExConf.MsgMaxCount
 	}
 	d.T["logid"] = config.Seoconfig["dataexport"].(string)
@@ -507,24 +508,16 @@ func (d *DataExport) PreviewData(source, _id string) error {
 	_id = util.SE.Decode4Hex(_id)
 	dataType := d.GetString("dataType")
 	//从500条数据中筛选字段最全五条
-	res, kws := public.GetDataExportSearchResultUseId(_id, dataType, -1)
-	if res == nil {
-		d.Render("/pc/dataExport_noDataErr.html", &d.T)
-		log.Println("PreviewData查询出错")
-		return nil
+	scd := dataexport.GetSqlObjFromId(public.MQFW, _id)
+	kws := scd.Keyword
+	res, err := dataexport.GetDataExportSearchResult(public.Mgo_Ent, public.DbConf.Elasticsearch.Main.Address, scd, dataType, -1, util.ObjToString(config.Seoconfig["webdomain"]))
+	if res == nil || err != nil {
+		log.Println("PreviewData查询出错", res)
+		return d.Render("/pc/dataExport_noDataErr.html", &d.T)
 	}
 	//格式化字段
-	res_screen := public.ScreenData(res, dataType, 20, kws)
-	var EntArr = []string{}
-	if dataType == "2" {
-		for _, v := range res_screen {
-			//高级字段查询且winner不为空
-			if v["s_winner"] != nil && v["s_winner"] != "" {
-				EntArr = append(EntArr, v["s_winner"].(string))
-			}
-		}
-	}
-	list := public.FormatExportData(&res_screen, config.Sysconfig["webdomain"].(string), dataType, EntArr)
+	res_screen := dataexport.ScreenData(res, dataType, 20, kws)
+	list := dataexport.FormatExportData(public.Mgo_Ent, &res_screen, config.Sysconfig["webdomain"].(string), dataType, true)
 	d.T["data"] = subUrl(list, dataType)
 	d.T["dataType"] = dataType
 	d.T["ttf"] = public.GetFontVersion() + "_" + public.PC
@@ -811,7 +804,7 @@ func (d *DataExport) EntDataExport(_id string) error {
 	data := &[]map[string]interface{}{}
 	current := GetCurrentCount(entId)
 	log.Println("企业总条数", current)
-	count, newCount, data = public.GetEntDataExportCount(id, entId, entUserId, remain_nums, current, isFirst)
+	count, newCount, data = public.GetEntDataExportCount(id, entId, entUserId, remain_nums, current, isFirst, util.ObjToString(config.Sysconfig["webdomain"]))
 	isExport := true
 	isEntExport := true
 	if newCount > current {

+ 12 - 33
src/jfw/front/ws_dataExport.go

@@ -6,6 +6,7 @@ import (
 	"fmt"
 	"jfw/config"
 	"jfw/jyutil"
+	"qfw/util/dataexport"
 	"strconv"
 
 	"github.com/go-xweb/xweb"
@@ -82,7 +83,7 @@ func (w *WsDataExport) WxToOrderDetail() error {
 	w.T["avatar"] = myavatar
 	//-----------------------
 	orderDetail := map[string]interface{}{}
-	filter := public.SieveCondition{}
+	filter := dataexport.SieveCondition{}
 	queryMap := map[string]interface{}{
 		"order_code": orderCode,
 		"user_id":    myUserId,
@@ -199,24 +200,16 @@ func (w *WsDataExport) GetPreview() error {
 	_id := util.SE.Decode4Hex(w.GetString("_id"))
 	dataType := w.GetString("dataType")
 	//从500条数据中筛选字段最全五条
-	res, kws := public.GetDataExportSearchResultUseId(_id, dataType, -1)
-	if res == nil {
-		w.Render("/pc/dataExport_noDataErr.html", &w.T)
+	scd := dataexport.GetSqlObjFromId(public.MQFW, _id)
+	kws := scd.Keyword
+	res, err := dataexport.GetDataExportSearchResult(public.Mgo_Ent, public.DbConf.Elasticsearch.Main.Address, scd, dataType, -1, util.ObjToString(config.Seoconfig["webdomain"]))
+	if res == nil || err != nil {
 		log.Println("PreviewData查询出错")
-		return nil
+		return w.Render("/pc/dataExport_noDataErr.html", &w.T)
 	}
 	//格式化字段
-	res_screen := public.ScreenData(res, dataType, 20, kws)
-	var EntArr = []string{}
-	if dataType == "2" {
-		for _, v := range res_screen {
-			//高级字段查询且winner不为空
-			if v["s_winner"] != nil && v["s_winner"] != "" {
-				EntArr = append(EntArr, v["s_winner"].(string))
-			}
-		}
-	}
-	list := public.FormatExportData(&res_screen, config.Sysconfig["webdomain"].(string), dataType, EntArr)
+	res_screen := dataexport.ScreenData(res, dataType, 20, kws)
+	list := dataexport.FormatExportData(public.Mgo_Ent, &res_screen, config.Sysconfig["webdomain"].(string), dataType, true)
 	_res["data"] = subUrl(list, dataType)
 	_res["dataType"] = dataType
 	w.ServeJson(map[string]interface{}{
@@ -225,20 +218,6 @@ func (w *WsDataExport) GetPreview() error {
 	return nil
 }
 
-//
-//func (w *WsDataExport) PaySuccessPage() error {
-//	defer util.Catch()
-//	orderCode := w.GetString("orderCode")
-//	userId := util.ObjToString(w.GetSession("userId"))
-//	res := public.Mysql.FindOne("dataexport_order", map[string]interface{}{"user_id": userId, "order_code": orderCode}, "user_mail,pay_time", "")
-//	if res != nil || len(*res) == 0 {
-//		w.T["email"] = (*res)["user_mail"]
-//		w.T["payTime"] = (*res)["pay_time"]
-//	}
-//	w.T["orderCode"] = orderCode
-//	return w.Render("/weixin/dataExport/dataExport_paySuccess.html", &w.T)
-//}
-
 //预览
 func (w *WsDataExport) ToPreview(_id string) error {
 	defer util.Catch()
@@ -311,8 +290,8 @@ func (w *WsDataExport) SubmitOrder() error {
 			return errors.New("未登录")
 		}
 	}
-	msgCount := public.GetDataExportSearchCountUseId(id)
-	if msgCount > public.ExConf.MsgMaxCount {
+	msgCount := dataexport.GetDataExportSearchCountByScdId(public.MQFW, public.DbConf.Elasticsearch.Main.Address, id)
+	if msgCount > public.ExConf.MsgMaxCount || msgCount == -1 {
 		msgCount = public.ExConf.MsgMaxCount
 	}
 	if msgCount < 1 {
@@ -413,7 +392,7 @@ func (wd *WsDataExport) SearchExport() error {
 	saveData["s_userid"] = userId
 
 	//存入数据库
-	_id := mongodb.Save(public.ExportTable, saveData)
+	_id := mongodb.Save(dataexport.ExportTable, saveData)
 
 	wd.ServeJson(bson.M{"_id": util.SE.Encode2Hex(_id)})
 	return nil

+ 4 - 3
src/jfw/front/wx_dataExport.go

@@ -7,6 +7,7 @@ import (
 	"jfw/wx"
 	"log"
 	"qfw/util"
+	"qfw/util/dataexport"
 	"strings"
 	"time"
 
@@ -47,7 +48,7 @@ func (w *WxDataExport) ToSieve() error {
 	if orderCode != "" && myUserId != "" {
 		//-----------------------
 		orderDetail := map[string]interface{}{}
-		filter := public.SieveCondition{}
+		filter := dataexport.SieveCondition{}
 		queryMap := map[string]interface{}{
 			"order_code": orderCode,
 			"user_id":    myUserId,
@@ -121,7 +122,7 @@ func (w *WxDataExport) SaveData() error {
 	var buyerArr []string
 	var buyerclassArr []string
 	var winnerArr []string
-	var keyWordArr []public.KeyWord
+	var keyWordArr []dataexport.KeyWord
 
 	if area != "" {
 		areaArr = strings.Split(area, ",")
@@ -215,7 +216,7 @@ func (w *WxDataExport) SaveData() error {
 	if w.GetSession("userId") != nil {
 		saveData["s_userid"] = w.GetSession("userId").(string)
 	}
-	_id := mongodb.Save(public.ExportTable, saveData)
+	_id := mongodb.Save(dataexport.ExportTable, saveData)
 	log.Println("_id", _id)
 	w.ServeJson(bson.M{"_id": util.SE.Encode2Hex(_id)})
 	return nil

+ 4 - 3
src/jfw/modules/app/src/app/front/dataExport.go

@@ -6,6 +6,7 @@ import (
 	"jfw/public"
 	"log"
 	"qfw/util"
+	"qfw/util/dataexport"
 	"strings"
 	"time"
 
@@ -46,7 +47,7 @@ func (w *WxDataExport) ToSieve() error {
 	if orderCode != "" && myUserId != "" {
 		//-----------------------
 		orderDetail := map[string]interface{}{}
-		filter := public.SieveCondition{}
+		filter := dataexport.SieveCondition{}
 		queryMap := map[string]interface{}{
 			"order_code": orderCode,
 			"user_id":    myUserId,
@@ -125,7 +126,7 @@ func (w *WxDataExport) SaveData() error {
 	var buyerArr []string
 	var buyerclassArr []string
 	var winnerArr []string
-	var keyWordArr []public.KeyWord
+	var keyWordArr []dataexport.KeyWord
 
 	if area != "" {
 		areaArr = strings.Split(area, ",")
@@ -219,7 +220,7 @@ func (w *WxDataExport) SaveData() error {
 	if w.GetSession("userId") != nil {
 		saveData["s_userid"] = w.GetSession("userId").(string)
 	}
-	_id := mongodb.Save(public.ExportTable, saveData)
+	_id := mongodb.Save(dataexport.ExportTable, saveData)
 	log.Println("_id", _id)
 	w.ServeJson(bson.M{"_id": util.SE.Encode2Hex(_id)})
 	return nil

+ 12 - 10
src/jfw/modules/app/src/app/front/ws_dataExport.go

@@ -8,6 +8,7 @@ import (
 	"jfw/public"
 	"log"
 	"qfw/util"
+	"qfw/util/dataexport"
 	"qfw/util/redis"
 	"regexp"
 	"strconv"
@@ -62,14 +63,15 @@ func (w *WsDataExport) GetPreview() error {
 	_id := util.SE.Decode4Hex(w.GetString("_id"))
 	dataType := w.GetString("dataType")
 	//从500条数据中筛选字段最全五条
-	res, kws := public.GetDataExportSearchResultUseId(_id, dataType, -1)
-	if res == nil {
-		w.Render("/pc/dataExport_noDataErr.html", &w.T)
+	scd := dataexport.GetSqlObjFromId(public.MQFW, _id)
+	kws := scd.Keyword
+	res, err := dataexport.GetDataExportSearchResult(public.Mgo_Ent, public.DbConf.Elasticsearch.Main.Address, scd, dataType, -1, util.ObjToString(config.Seoconfig["webdomain"]))
+	if res == nil || err != nil {
 		log.Println("PreviewData查询出错")
-		return nil
+		return w.Render("/pc/dataExport_noDataErr.html", &w.T)
 	}
 	//格式化字段
-	res_screen := public.ScreenData(res, dataType, 20, kws)
+	res_screen := dataexport.ScreenData(res, dataType, 20, kws)
 	var EntArr = []string{}
 	if dataType == "2" {
 		for _, v := range res_screen {
@@ -79,7 +81,7 @@ func (w *WsDataExport) GetPreview() error {
 			}
 		}
 	}
-	list := public.FormatExportData(&res_screen, config.Sysconfig["webdomain"].(string), dataType, EntArr)
+	list := dataexport.FormatExportData(public.Mgo_Ent, &res_screen, config.Sysconfig["webdomain"].(string), dataType)
 	_res["data"] = subUrl(list, dataType)
 	_res["dataType"] = dataType
 	w.ServeJson(map[string]interface{}{
@@ -255,8 +257,8 @@ func (w *WsDataExport) ToCreateOrderPage() error {
 		return errors.New("未登录")
 	}
 	log.Println(id)
-	msgCount := public.GetDataExportSearchCountUseId(id)
-	if msgCount > public.ExConf.MsgMaxCount {
+	msgCount := dataexport.GetDataExportSearchCountByScdId(public.MQFW, public.DbConf.Elasticsearch.Main.Address, id)
+	if msgCount > public.ExConf.MsgMaxCount || msgCount == -1 {
 		msgCount = public.ExConf.MsgMaxCount
 	}
 	if msgCount < 1 {
@@ -357,7 +359,7 @@ func (wd *WsDataExport) SearchExport() error {
 	saveData["s_userid"] = userId
 
 	//存入数据库
-	_id := mongodb.Save(public.ExportTable, saveData)
+	_id := mongodb.Save(dataexport.ExportTable, saveData)
 
 	wd.ServeJson(bson.M{"_id": util.SE.Encode2Hex(_id)})
 	return nil
@@ -370,7 +372,7 @@ func (m *WsDataExport) ToOrderDetail() error {
 	}
 	orderCode := m.GetString("orderCode")
 	orderDetail := map[string]interface{}{}
-	filter := public.SieveCondition{}
+	filter := dataexport.SieveCondition{}
 	queryMap := map[string]interface{}{
 		"order_code": orderCode,
 		"user_id":    userId,

+ 297 - 56
src/jfw/modules/common/src/qfw/util/dataexport/dataexport.go

@@ -5,18 +5,19 @@ import (
 	"encoding/json"
 	"errors"
 	"fmt"
+	"go.mongodb.org/mongo-driver/bson"
 	"log"
 	"math"
+	mg "mongodb"
 	qutil "qfw/util"
 	"qfw/util/elastic"
 	"qfw/util/jy"
+	"regexp"
+	"sort"
 	"strconv"
 	"strings"
 	"sync"
 	"time"
-	"util"
-
-	"go.mongodb.org/mongo-driver/bson"
 )
 
 /*筛选条件--关键词*/
@@ -48,27 +49,14 @@ type SieveCondition struct {
 	DisWord     string    `json:"disWord"`     //分销系统 口令
 }
 
-//VIP订单
-type VipFilter struct {
-	Area               map[string]interface{} `json:"area"`     //地区
-	Industry           []string               `json:"industry"` //
-	Cyclecount         int                    `json:"cyclecount"`
-	Cycleunit          int                    `json:"cycleunit"`
-	Ordertype          int                    `json:"ordertype"`
-	Addarea            map[string]interface{} `json:"addarea"`            //新增地区
-	Addindustry        []string               `json:"addindustry"`        //新增行业
-	Addareacount       map[string]interface{} `json:"addareacount"`       //新增地区数量
-	Addbuyerclasscount int                    `json:"addbuyerclasscount"` //新增地区数量
-	Buyset             map[string]interface{} `json:buyset`
-	NewBuyset          map[string]interface{} `json:newBuyset` //逻辑重写后的判断条件
-}
-
 const (
 	INDEX          = "bidding"
 	TYPE           = "bidding"
 	bidSearch_sort = `{"publishtime":-1}`
 )
 
+var ClearOther = regexp.MustCompile("[\n\r\\s\u3000\u2003\u00a0]")
+var ClearHtml = regexp.MustCompile("<[^>]*>")
 var onceSearchCount = 500
 var ExportTable string = "export_search"
 var searchPool = make(chan bool, 8)
@@ -263,12 +251,13 @@ func getDataExportSql(scd *SieveCondition) string {
 	return qstr
 }
 
-func GetSqlObjFromId(_id string) *SieveCondition {
+//获取数据导出筛选条件
+func GetSqlObjFromId(mongo mg.MongodbSim, _id string) *SieveCondition {
 	var (
 		query *map[string]interface{}
 		ok    bool
 	)
-	if query, ok = util.MQFW.FindById(ExportTable, _id, nil); !ok {
+	if query, ok = mongo.FindById(ExportTable, _id, nil); !ok {
 		return nil
 	}
 	return &SieveCondition{
@@ -291,8 +280,12 @@ func GetSqlObjFromId(_id string) *SieveCondition {
 }
 
 //数据导出-查询结果数量
-func GetDataExportSearchCountUseId(id, elasticAddress string) (count int) {
-	scd := GetSqlObjFromId(id) //用户筛选条件
+func GetDataExportSearchCountByScdId(sim mg.MongodbSim, elasticAddress, id string) (count int) {
+	scd := GetSqlObjFromId(sim, id) //用户筛选条件
+	return GetDataExportSearchCountBySieveCondition(scd, elasticAddress)
+}
+
+func GetDataExportSearchCountBySieveCondition(scd *SieveCondition, elasticAddress string) (count int) {
 	qstr := getDataExportSql(scd)
 	if isNullSearch(scd) {
 		return -1 //程序端返回最大值
@@ -365,11 +358,18 @@ func isNullSearch(scd *SieveCondition) (isNull bool) {
  */
 var EntTable = "winner_enterprise"
 
-func GetDataExportSearchResult(id, dataType string, checkCount int, elasticAddress, webdomain string) (*[]map[string]interface{}, error) {
+func GetDataExportSearchResultByScdId(sim, entmg mg.MongodbSim, elasticAddress, id string, dataType string, checkCount int, webdomain string) (*[]map[string]interface{}, error) {
+	scd := GetSqlObjFromId(sim, id)
+	return GetDataExportSearchResult(entmg, elasticAddress, scd, dataType, checkCount, webdomain)
+}
+
+//GetDataExportSearchResult 获取数据导出内容
+//entmg 高级字段包查询企业电话邮箱等字段
+//checkCount -1 预览500条
+func GetDataExportSearchResult(entmg mg.MongodbSim, elasticAddress string, scd *SieveCondition, dataType string, checkCount int, webdomain string) (*[]map[string]interface{}, error) {
 	defer qutil.Catch()
 	var res []map[string]interface{}
 	//获取查询语句
-	scd := GetSqlObjFromId(id)
 	if scd == nil {
 		return nil, errors.New("GetDataExportSearchResult-获取查询条件")
 	}
@@ -420,7 +420,8 @@ func GetDataExportSearchResult(id, dataType string, checkCount int, elasticAddre
 		searchWaitGroup.Wait()
 		log.Printf("GetDataExportSearchResult-%s-分批次加载数据总量为%d\n", scd.Id, len(res))
 	} else {
-		tmp := doSearch(qstr, 0, checkCount, dataType)
+		queryCount := qutil.If(checkCount == -1, 500, checkCount).(int)
+		tmp := doSearch(qstr, 0, queryCount, dataType)
 		if tmp == nil || len(*tmp) == 0 {
 			log.Printf("GetDataExportSearchResult-%s-一次性加载数据异常\n", scd.Id)
 		} else {
@@ -451,48 +452,121 @@ func GetDataExportSearchResult(id, dataType string, checkCount int, elasticAddre
 		}
 	}
 	//校验数量
-	if checkCount != len(res) {
+	if checkCount != len(res) && checkCount != -1 {
 		return nil, fmt.Errorf("GetDataExportSearchResult-%s-数据总量校验异常,期望:%d,实际:%d", scd.Id, checkCount, len(res))
 		//发邮件
 	}
-
-	var EntArr = []string{}
-	for _, v := range res {
-		//高级字段查询且winner不为空
-		if v["s_winner"] != nil && v["s_winner"] != "" && dataType == "2" {
-			EntArr = append(EntArr, v["s_winner"].(string))
-		}
-	}
-	res = *FormatExportData(&res, webdomain, dataType, EntArr)
+	res = *FormatExportData(entmg, &res, webdomain, dataType)
 	return &res, nil
 }
 
-func FormatExportData(data *[]map[string]interface{}, webdomain string, dataType string, EntArr []string) *[]map[string]interface{} {
+//数据导出预览
+//func GetDataExportSearchResultPreview(sim mg.MongodbSim, elasticAddress string, _id, dataType string) (*[]map[string]interface{}, []KeyWord) {
+//	defer qutil.Catch()
+//	var res []map[string]interface{}
+//	var kws []KeyWord
+//	scd := GetSqlObjFromId(sim, _id)
+//	//获取查询语句
+//	qstr := getDataExportSql(scd)
+//	log.Printf("GetDataExportSearchResultUseId-%s-sql:%s\n", scd.Id, qstr)
+//	kws = scd.Keyword
+//	//数据预览数据查询
+//	if scd.Comeinfrom == "supersearchPage" && len(scd.Keyword) == 0 && len(scd.Industry) == 0 {
+//		//空查询
+//		obj := redis.Get("other", "export_news")
+//		if obj != nil {
+//			res = qutil.ObjArrToMapArr(obj.([]interface{}))
+//		} else {
+//			res = *doSearch(qstr, 0, 500, "2")
+//			if len(res) > 0 {
+//				redis.Put("other", "export_news", res, 7200)
+//			}
+//		}
+//		return &res, kws
+//	} else if scd.Comeinfrom == "supersearchPage" {
+//		//超级搜索非空查询
+//		count := int(elastic.Count(INDEX, TYPE, qstr))
+//		searchTextSize := 0
+//		if len(scd.Keyword) > 0 {
+//			searchTextSize = len([]rune(scd.Keyword[0].Keyword))
+//		}
+//		if searchTextSize > 3 && count < 50 {
+//			var res *[]map[string]interface{}
+//			if count > 0 {
+//				res = doSearch(qstr, 0, count, "")
+//			}
+//			secondKWS := jy.HttpEs(scd.Keyword[0].Keyword, "ik_smart", elasticAddress)
+//			scd.Keyword[0].Keyword = secondKWS
+//			scd.SelectType = "title"
+//			qstr = getDataExportSql(scd)
+//			log.Printf("GetDataExportSearchResultUseId-%s-分词-sql:%s\n", scd.Id, qstr)
+//			res2 := doSearch(qstr, 0, 100, "")
+//			if len(*res2) > 100 {
+//				res2_temp := (*res2)[:100]
+//				res2 = &res2_temp
+//			}
+//			return delRepeatMapArr(res, res2), kws
+//		}
+//	}
+//	//非空查询
+//	res = *doSearch(qstr, 0, 500, dataType)
+//	return &res, kws
+//}
+
+func FormatExportData(entmg mg.MongodbSim, data *[]map[string]interface{}, webdomain string, dataType string, encry ...bool) *[]map[string]interface{} {
 	//格式化输出
+	isEncry := false
+	if len(encry) > 0 {
+		isEncry = true
+	}
 	for _, v := range *data {
 		//有中标企业 且 高级字段查询
-		if len(EntArr) > 0 && dataType == "2" {
+		if dataType == "2" {
 			//查询企业公示 法人 公司电话 公司邮箱地址
-			query := bson.M{"company_name": bson.M{"$in": EntArr}} //
-			if entData, ok := util.MQFWENT.Find(EntTable, query, nil, `{"company_name":1,"company_email":1,"legal_person":1,"company_phone":1}`, false, -1, -1); ok {
-				if entData != nil && *entData != nil && len(*entData) > 0 {
-					for _, ev := range *entData {
-						if v["s_winner"] == ev["company_name"] {
-							legal_person := ""
-							if ev["legal_person"] != nil {
-								legal_person = ev["legal_person"].(string)
-							}
-							company_phone := ""
-							if ev["company_phone"] != nil {
-								company_phone = ev["company_phone"].(string)
-							}
-							company_email := ""
-							if ev["company_email"] != nil && ev["company_email"] != "无" {
-								company_email = ev["company_email"].(string)
+			s_winner, ok := v["s_winner"].(string) //改为entidlist?
+			if ok && s_winner != "" {
+				if entData, ok := entmg.Find(EntTable, bson.M{"company_name": s_winner}, nil, `{"company_name":1,"company_email":1,"legal_person":1,"company_phone":1}`, false, -1, -1); ok {
+					if entData != nil && *entData != nil && len(*entData) > 0 {
+						for _, ev := range *entData {
+							if v["s_winner"] == ev["company_name"] {
+								legal_person := ""
+								if ev["legal_person"] != nil {
+									legal_person = ev["legal_person"].(string)
+									if isEncry {
+										var xx = "*"
+										switch len([]rune(legal_person)) {
+										case 3:
+											xx = "**"
+										case 4:
+											xx = "***"
+										}
+										legal_person = string([]rune(legal_person)[:1]) + xx
+									}
+								}
+								company_phone := ""
+								if ev["company_phone"] != nil {
+									company_phone = ev["company_phone"].(string)
+									if isEncry {
+										if len([]rune(company_phone)) > 7 {
+											company_phone = company_phone[:7] + "****"
+										} else {
+											company_phone = "****"
+										}
+									}
+								}
+								company_email := ""
+								if ev["company_email"] != nil && ev["company_email"] != "无" {
+									company_email = ev["company_email"].(string)
+									if isEncry {
+										if len(strings.Split(company_email, "@")) > 1 {
+											company_email = "******" + "@" + strings.Split(company_email, "@")[1]
+										}
+									}
+								}
+								v["legal_person"] = legal_person
+								v["company_phone"] = company_phone
+								v["company_email"] = company_email
 							}
-							v["legal_person"] = legal_person
-							v["company_phone"] = company_phone
-							v["company_email"] = company_email
 						}
 					}
 				}
@@ -548,6 +622,38 @@ func FormatExportData(data *[]map[string]interface{}, webdomain string, dataType
 		if v["currency"] == "" || v["currency"] == nil {
 			v["currency"] = "人民币"
 		}
+
+		if isEncry {
+			if v["projectscope"] != "" && v["projectscope"] != nil {
+				str := ClearHtml.ReplaceAllString(v["projectscope"].(string), "")
+				str = ClearOther.ReplaceAllString(str, "")
+				str = strings.Replace(str, " ", "", -1)
+				if len([]rune(str)) > 100 {
+					str = qutil.SubString(str, 0, 100) + "..."
+				}
+				v["projectscope"] = str
+			}
+			if v["detail"] != "" && v["detail"] != nil {
+				str := ClearHtml.ReplaceAllString(v["detail"].(string), "")
+				str = ClearOther.ReplaceAllString(str, "")
+				str = strings.Replace(str, " ", "", -1)
+				if len([]rune(str)) > 100 {
+					str = qutil.SubString(str, 0, 100) + "..."
+				}
+				v["detail"] = str
+			}
+			if v["title"] != "" && v["title"] != nil {
+				str := ClearHtml.ReplaceAllString(v["title"].(string), "")
+				str = ClearOther.ReplaceAllString(str, "")
+				str = strings.Replace(str, " ", "", -1)
+				if len([]rune(str)) > 100 {
+					str = qutil.SubString(str, 0, 100) + "..."
+				}
+				v["title"] = str
+			}
+
+		}
+
 		if v["subtype"] == nil && v["toptype"] != nil {
 			v["subtype"] = v["toptype"]
 		}
@@ -604,3 +710,138 @@ func getStringArrFromDbResult(c interface{}) (arr []string) {
 	}
 	return
 }
+
+//获取结果,空字段最少的数据
+func ScreenData(arr *[]map[string]interface{}, dataType string, resultNum int, kws []KeyWord) (res []map[string]interface{}) {
+	AllMap := map[int][]map[string]interface{}{}
+
+	NoKwsMap := map[int][]map[string]interface{}{}
+	lastNum := resultNum
+	for _, v := range *arr {
+		emptyNum := countOfTheEmpty(v, dataType)
+		if emptyNum == -1 {
+			continue
+		}
+		if len(kws) > 0 && kws[0].Keyword != "" {
+			var kwsFlag = true
+			for _, vk := range kws {
+				if strings.Contains(qutil.ObjToString(v["title"]), strings.Replace(vk.Keyword, "+", "", -1)) {
+					kwsFlag = false
+					continue
+				}
+			}
+			if kwsFlag {
+				if NoKwsMap[emptyNum] == nil {
+					NoKwsMap[emptyNum] = []map[string]interface{}{v}
+				} else {
+					NoKwsMap[emptyNum] = append(NoKwsMap[emptyNum], v)
+				}
+				continue
+			}
+		}
+		if AllMap[emptyNum] == nil {
+			AllMap[emptyNum] = []map[string]interface{}{v}
+			continue
+		}
+		AllMap[emptyNum] = append(AllMap[emptyNum], v)
+	}
+	//获取key
+	keys := []int{}
+	for k, _ := range AllMap {
+		keys = append(keys, k)
+	}
+	sort.Ints(keys)
+	log.Println("空字段数量", keys)
+	//选取结果
+	for _, v := range keys {
+		if len(AllMap[v]) >= resultNum {
+			return append(res, AllMap[v][:resultNum]...)
+		} else {
+			resultNum = resultNum - len(AllMap[v])
+			tmp := append(res, AllMap[v][:len(AllMap[v])]...)
+			res = tmp
+		}
+	}
+	if len(res) < lastNum {
+		resultNum = lastNum - len(res)
+		//获取key
+		Nokeys := []int{}
+		for k, _ := range NoKwsMap {
+			Nokeys = append(Nokeys, k)
+		}
+		sort.Ints(Nokeys)
+		log.Println("没关键词的空字段数量", Nokeys)
+		//选取结果
+		for _, v := range Nokeys {
+			if len(NoKwsMap[v]) >= resultNum {
+				return append(res, NoKwsMap[v][:resultNum]...)
+			} else {
+				resultNum = resultNum - len(NoKwsMap[v])
+				tmp := append(res, NoKwsMap[v][:len(NoKwsMap[v])]...)
+				res = tmp
+			}
+		}
+	}
+	return res
+}
+func countOfTheEmpty(m map[string]interface{}, dataType string) int {
+	MsgType := m["subtype"]
+	//	if MsgType == "拟建" {
+	//		return -1
+	//	}
+	//计算空字段数量
+	var count int = 0
+	//高级字段包
+	if dataType == "2" {
+		if m["href"] == "" || m["href"] == nil {
+			count++
+		}
+		if m["projectcode"] == "" || m["projectcode"] == nil {
+			count++
+		}
+		if m["buyerperson"] == "" || m["buyerperson"] == nil {
+			count++
+		}
+		if m["buyertel"] == "" || m["buyertel"] == nil {
+			count++
+		}
+		if m["budget"] == "" || m["budget"] == nil {
+			count++
+		}
+		if m["bidopentime"] == "" || m["bidopentime"] == nil {
+			count++
+		}
+		if m["agency"] == "" || m["agency"] == nil {
+			count++
+		}
+		if m["projectscope"] == "" || m["projectscope"] == nil {
+			count++
+		}
+	}
+	if m["city"] == "" || m["city"] == nil {
+		count++
+	}
+	if m["publishtime"] == "" || m["publishtime"] == nil {
+		count++
+	}
+	if m["projectname"] == "" || m["projectname"] == nil {
+		count++
+	}
+	if m["buyer"] == "" || m["buyer"] == nil {
+		count++
+	}
+	if m["s_winner"] == "" || m["s_winner"] == nil {
+		if MsgType != "招标" {
+			count++
+		}
+	}
+	if m["bidamount"] == "" || m["bidamount"] == nil {
+		if MsgType != "招标" {
+			count++
+		}
+	}
+	if m["subtype"] == "" || m["subtype"] == nil {
+		count++
+	}
+	return count
+}

+ 16 - 1
src/jfw/modules/subscribepay/src/entity/dataexport.go

@@ -41,6 +41,21 @@ func init() {
 
 type dataExportStruct struct{}
 
+//VIP订单
+type VipFilter struct {
+	Area               map[string]interface{} `json:"area"`     //地区
+	Industry           []string               `json:"industry"` //
+	Cyclecount         int                    `json:"cyclecount"`
+	Cycleunit          int                    `json:"cycleunit"`
+	Ordertype          int                    `json:"ordertype"`
+	Addarea            map[string]interface{} `json:"addarea"`            //新增地区
+	Addindustry        []string               `json:"addindustry"`        //新增行业
+	Addareacount       map[string]interface{} `json:"addareacount"`       //新增地区数量
+	Addbuyerclasscount int                    `json:"addbuyerclasscount"` //新增地区数量
+	Buyset             map[string]interface{} `json:buyset`
+	NewBuyset          map[string]interface{} `json:newBuyset` //逻辑重写后的判断条件
+}
+
 var JyDataExportStruct dataExportStruct
 
 //数据导出支付完成回调方法
@@ -318,7 +333,7 @@ func SendMailToBJFinance(order *map[string]interface{}, pay_time, transaction_id
 			vip_endtime := qutil.ObjToString((*order)["vip_endtime"])
 			payment_number = getPayTransactionId(qutil.ObjToString((*order)["pay_way"]), qutil.ObjToString((*order)["out_trade_no"]))
 			vip_type := qutil.Int64All((*order)["vip_type"]) //判断 续费 升级订单
-			vf := new(dataexport.VipFilter)
+			vf := new(VipFilter)
 			err := json.Unmarshal([]byte(filter), &vf)
 			if err == nil && vf != nil {
 				newbuyset := vf.NewBuyset //如果newBuyset存在  则为<续费升级逻辑更新>之后的订单 (否则为老订单)

+ 4 - 7
src/jfw/modules/subscribepay/src/service/dataExportPay.go

@@ -61,11 +61,11 @@ func (p *DataExportPay) CreateOrder() {
 	} else {
 		user_phone, _ = p.GetSession("DataExportVerifyPhone_val").(string)
 	}
-
-	data_count := dataexport.GetDataExportSearchCountUseId(id, config.Config.Elasticsearch)
-	if data_count == -1 {
+	data_count := dataexport.GetDataExportSearchCountByScdId(util.MQFW, config.Config.Elasticsearch, id)
+	if data_count > config.ExConf.MsgMaxCount || data_count == -1 {
 		data_count = config.ExConf.MsgMaxCount
 	}
+
 	if data_count == 0 {
 		log.Println("未查询到检索信息", userId, id)
 		p.ServeJson(map[string]interface{}{
@@ -74,9 +74,6 @@ func (p *DataExportPay) CreateOrder() {
 		return
 	}
 
-	if data_count > config.ExConf.MsgMaxCount {
-		data_count = config.ExConf.MsgMaxCount
-	}
 	order_money_, original_price_ := float64(0), float64(0)
 	if data_spec == "标准字段包" {
 		original_price_ = float64(data_count) * config.ExConf.UnitPrice_normal
@@ -154,7 +151,7 @@ func (p *DataExportPay) CreateOrder() {
 		ordercode := pay.GetOrderCode(openId)
 		download_url := util.GetExcelFilePath(ordercode)
 		go func() {
-			list, err := dataexport.GetDataExportSearchResult(id, qutil.If(data_spec == "高级字段包", "2", "1").(string), data_count, config.Config.Elasticsearch, config.Config.WebDomain)
+			list, err := dataexport.GetDataExportSearchResultByScdId(util.MQFW, util.MQFWENT, config.Config.Elasticsearch, id, qutil.If(data_spec == "高级字段包", "2", "1").(string), data_count, config.Config.WebDomain)
 			if err == nil {
 				err = util.CreateDataExportExcelFile(list, data_spec == "高级字段包", download_url)
 			}

+ 3 - 2
src/jfw/public/dataexport.go

@@ -5,6 +5,7 @@ import (
 	"jfw/modules/common/src/qfw/util/jy"
 	"log"
 	"qfw/util"
+	"qfw/util/dataexport"
 	"qfw/util/mail"
 	"strings"
 	"sync"
@@ -128,7 +129,7 @@ func (this *BidSearchExport) PassBidSearchExport() map[string]interface{} {
 		winnerSave = strings.Split(this.Winner, ",")
 	}
 
-	KeyWordSave := []KeyWord{}
+	KeyWordSave := []dataexport.KeyWord{}
 	if len(this.Keywords) > 0 {
 		isIntercept := false
 		if this.SelectType == "all" {
@@ -136,7 +137,7 @@ func (this *BidSearchExport) PassBidSearchExport() map[string]interface{} {
 		}
 		_, _, keywords := jy.InterceptSearchKW(this.Keywords, isIntercept, len(this.Industry) == 0)
 		keywords = strings.Replace(keywords, "+", " ", -1)
-		KeyWordSave = append(KeyWordSave, KeyWord{Keyword: keywords})
+		KeyWordSave = append(KeyWordSave, dataexport.KeyWord{Keyword: keywords})
 	}
 
 	//时间

+ 280 - 0
src/jfw/public/entdataexport.go

@@ -0,0 +1,280 @@
+package public
+
+import (
+	"fmt"
+	"go.mongodb.org/mongo-driver/bson"
+	"log"
+	"qfw/util"
+	"qfw/util/dataexport"
+	"qfw/util/elastic"
+	"qfw/util/redis"
+	"strings"
+	"sync"
+	"time"
+)
+
+func GetEntDataExportCount(_id string, entId, entUserId, limitNum, current int, isFirst bool, webdomain string) (count, newCount int, data *[]map[string]interface{}) {
+	defer util.Catch()
+	var (
+		searchsWaitGroup = &sync.WaitGroup{}
+		searchsPool      = make(chan bool, 20)
+		// res              = &[]map[string]interface{}{}
+		newCountPool = make(chan bool, 20000)
+	)
+	//count = GetDataExportSearchCountUseId(_id)
+	count = dataexport.GetDataExportSearchCountByScdId(MQFW, DbConf.Elasticsearch.Main.Address, _id)
+	log.Println("count", count)
+	if count > ExConf.MsgMaxCount || count == -1 {
+		count = ExConf.MsgMaxCount
+	}
+	dataType := "2"
+	//数据导出数据查询
+
+	res, err := dataexport.GetDataExportSearchResultByScdId(Mgo_Ent, MQFW, DbConf.Elasticsearch.Main.Address, _id, dataType, count, webdomain)
+	if err != nil {
+		log.Println("企业数据导出错误 ", err)
+		return 0, 0, nil
+	}
+	// secondCount := 0
+
+	// isOK := true
+	// if secondCount > current {
+	// 	isOK = false
+	// }
+	for _, v := range *res {
+		searchsWaitGroup.Add(1)
+		searchsPool <- true
+		id := util.ObjToString(v["_id"])
+		go func(id string) {
+			defer func() {
+				searchsWaitGroup.Done()
+				<-searchsPool
+			}()
+			isExist, err := redis.Exists("other", "entexportdata_"+id+"_"+fmt.Sprintln(entId))
+			if err != nil {
+				log.Println("企业搜索数据导出redis判重失败")
+			} else if isExist {
+				log.Println("数据重复,id ", id, "entid ", entId, "userid ", entUserId)
+				return
+			}
+			newCountPool <- true
+			if !isFirst {
+				redis.Put("other", "entexportdata_"+id+"_"+fmt.Sprintln(entId), 1, -1)
+			}
+		}(id)
+		if !isFirst {
+			delete(v, "_id")
+			v["entid"] = entId
+			v["userid"] = entUserId
+			v["infoid"] = id
+			v["createtime"] = time.Now().Unix()
+		}
+	}
+	searchsWaitGroup.Wait()
+	log.Println("企业数据导出--数据遍历完成")
+	newCount = len(newCountPool)
+	log.Println("new", newCount)
+	data = res
+	return
+}
+
+func FormatExportDatas(data *[]map[string]interface{}, webdomain string, dataType string, entId int) *[]map[string]interface{} {
+	//格式化输出
+	var (
+		entexportPool      = make(chan bool, 20)
+		entexportWaitGroup = &sync.WaitGroup{}
+	)
+	log.Println("补充信息开始")
+	for _, v := range *data {
+		entexportWaitGroup.Add(1)
+		entexportPool <- true
+		go func(v map[string]interface{}) {
+			defer func() {
+				entexportWaitGroup.Done()
+				<-entexportPool
+			}()
+			//有中标企业 且 高级字段查询
+			if dataType == "2" {
+				//查询企业公示 法人 公司电话 公司邮箱地址
+				s_winner := strings.Split(util.ObjToString(v["s_winner"]), ",")[0]
+				if entData, ok := Mgo_Ent.Find("winner_enterprise", bson.M{"company_name": s_winner}, nil,
+					`{"company_name":1,"company_email":1,"legal_person":1,"company_phone":1}`, false, -1, -1); ok {
+					if entData != nil && *entData != nil && len(*entData) > 0 {
+						for _, ev := range *entData {
+							if v["s_winner"] == ev["company_name"] {
+								legal_person := ""
+								if ev["legal_person"] != nil {
+									legal_person = ev["legal_person"].(string)
+								}
+								company_phone := ""
+								if ev["company_phone"] != nil {
+									company_phone = ev["company_phone"].(string)
+								}
+								company_email := ""
+								if ev["company_email"] != nil && ev["company_email"] != "无" {
+									company_email = ev["company_email"].(string)
+								}
+								v["legal_person"] = legal_person
+								v["company_phone"] = company_phone
+								v["company_email"] = company_email
+							}
+						}
+					}
+				}
+			}
+			//====================字段补漏=========================
+			if v["toptype"] == "结果" && dataType == "2" && !(v["agency"] != nil && v["budget"] != nil && v["buyerperson"] != nil && v["buyertel"] != nil) {
+				r := elastic.Get("projectset", "projectset", fmt.Sprintf(`{"query":{"term":{"list.infoid":"%s"}},"_source": ["list"]}`, v["_id"]))
+				if len(*r) > 0 {
+					MsgList := (*r)[0]["list"]
+					if MsgList != nil {
+						list := util.ObjArrToMapArr(MsgList.([]interface{}))
+						for _, vv := range list {
+							if vv["subtype"] == "招标" {
+								if v["agency"] == nil && vv["agency"] != nil {
+									v["agency"] = vv["agency"]
+								}
+								if v["budget"] == nil && vv["budget"] != nil {
+									v["budget"] = vv["budget"]
+								}
+								if v["buyerperson"] == nil && vv["buyerperson"] != nil {
+									v["buyerperson"] = vv["buyerperson"]
+								}
+								if v["buyertel"] == nil && vv["buyertel"] != nil {
+									v["buyertel"] = vv["buyertel"]
+								}
+								break
+							}
+						}
+					}
+				}
+			}
+			if v["area"] == "A" {
+				v["area"] = "全国"
+			}
+			if v["publishtime"] != nil {
+				date := v["publishtime"]
+				v["publishtime"] = util.FormatDateWithObj(&date, util.Date_Short_Layout)
+			}
+			if v["bidopentime"] != nil {
+				date := v["bidopentime"]
+				v["bidopentime"] = util.FormatDateWithObj(&date, util.Date_Short_Layout)
+			}
+			if v["currency"] == "" || v["currency"] == nil {
+				v["currency"] = "人民币"
+			}
+			if v["subtype"] == nil && v["toptype"] != nil {
+				v["subtype"] = v["toptype"]
+			}
+			if v["detail"] != "" && v["detail"] != nil {
+				str := ClearHtml.ReplaceAllString(v["detail"].(string), "")
+				str = ClearOther.ReplaceAllString(str, "")
+				str = strings.Replace(str, " ", "", -1)
+				v["detail"] = str
+			}
+			if v["_id"] != nil {
+				v["url"] = webdomain + "/article/content/" + util.CommonEncodeArticle("content", v["_id"].(string)) + ".html"
+			}
+		}(v)
+	}
+	entexportWaitGroup.Wait()
+	log.Println("补充信息结束")
+	return data
+}
+
+//func GetDataExportSearchResult(id string, dataType string, checkCount int) (*[]map[string]interface{}, error) {
+//	defer util.Catch()
+//	var (
+//		onceSearchCount = 500
+//		searchPool      = make(chan bool, 20)
+//		res             []map[string]interface{}
+//	)
+//	//获取查询语句
+//	scd := dataexport.GetSqlObjFromId(MQFW, id)
+//	if scd == nil {
+//		return nil, errors.New("GetDataExportSearchResult-获取查询条件")
+//	}
+//	qstr := getDataExportSql(scd)
+//	log.Printf("GetDataExportSearchResult-%s-sql:%s\n", scd.Id, qstr)
+//	//数据导出数据查询
+//	if checkCount > onceSearchCount { //分批次查询
+//		batchNum := util.IntAll(math.Ceil(float64(checkCount) / float64(onceSearchCount)))
+//		var searchWaitGroup = &sync.WaitGroup{}
+//		var lock sync.Mutex
+//		for n := 0; n < batchNum; n++ {
+//			searchWaitGroup.Add(1)
+//			searchPool <- true
+//			go func(start int) {
+//				defer func() {
+//					searchWaitGroup.Done()
+//					<-searchPool
+//				}()
+//				checkNum, checkOk := onceSearchCount, false
+//				if start == (batchNum - 1) {
+//					if checkCount%onceSearchCount != 0 {
+//						checkNum = checkCount % onceSearchCount
+//					}
+//				}
+//
+//				var tmp *[]map[string]interface{}
+//				for i := 0; i < 3; i++ {
+//					tmp = doSearch(qstr, start*onceSearchCount, onceSearchCount, dataType)
+//					if tmp != nil && (len(*tmp) == checkNum) { //校验数据量是否够
+//						checkOk = true
+//						break
+//					}
+//				}
+//				if tmp == nil {
+//					log.Printf("GetDataExportSearchResult-%s-第%d页数据查询结果为空\n", scd.Id, start+1)
+//					return
+//				}
+//				if checkOk {
+//					log.Printf("GetDataExportSearchResult-%s-第%d页数据加载完成,共%d条\n", scd.Id, start+1, len(*tmp))
+//				} else {
+//					log.Printf("GetDataExportSearchResult-%s-第%d页数据加载异常,共%d条,预期%d条\n", scd.Id, start+1, len(*tmp), checkNum)
+//				}
+//				lock.Lock()
+//				res = append(res, *tmp...)
+//				lock.Unlock()
+//			}(n)
+//		}
+//		searchWaitGroup.Wait()
+//		log.Printf("GetDataExportSearchResult-%s-分批次加载数据总量为%d\n", scd.Id, len(res))
+//	} else {
+//		tmp := doSearch(qstr, 0, checkCount, dataType)
+//		if tmp == nil || len(*tmp) == 0 {
+//			log.Printf("GetDataExportSearchResult-%s-一次性加载数据异常\n", scd.Id)
+//		} else {
+//			res = *tmp
+//			log.Printf("GetDataExportSearchResult-%s-一次性加载数据总量为%d\n", scd.Id, len(res))
+//		}
+//	}
+//	//超级搜索一致的检索(防止数据导出和超级搜索数据量不一致)
+//	if scd.Comeinfrom == "supersearchPage" && (len(scd.Keyword) != 0 || len(scd.Industry) != 0) {
+//		if len(scd.Keyword) != 0 {
+//			num := len(res)
+//			searchTextSize := 0
+//			if len(scd.Keyword) > 0 {
+//				searchTextSize = len([]rune(scd.Keyword[0].Keyword))
+//			}
+//			if searchTextSize > 3 && num < 50 {
+//				secondKWS := jy.HttpEs(scd.Keyword[0].Keyword, "ik_smart", DbConf.Elasticsearch.Main.Address)
+//				scd.Keyword[0].Keyword = secondKWS
+//				scd.SelectType = "title"
+//				qstr = getDataExportSql(scd)
+//				log.Printf("GetDataExportSearchResult-%s-分词查询-sql:%s\n", scd.Id, qstr)
+//				res2 := doSearch(qstr, 0, 100, "")
+//				res = *delRepeatMapArr(&res, res2)
+//				if len(res) > 100 {
+//					res = res[:100]
+//				}
+//			}
+//		}
+//	}
+//	//校验数量
+//	if checkCount != len(res) {
+//		return nil, fmt.Errorf("GetDataExportSearchResult-%s-数据总量校验异常,期望:%d,实际:%d", scd.Id, checkCount, len(res))
+//		//发邮件
+//	}
+//	return &res, nil
+//}

+ 5 - 0
src/jfw/public/public.go

@@ -22,6 +22,11 @@ var filterReg_2 = regexp.MustCompile("^[)\\)>》】\\]}}〕,,;;::'\"
 var filterReg_1 = regexp.MustCompile("^([0-9]{1,3}|[零一二三四五六七八九十]{1,2}|联系人?|电话|地址|编号|采购|政府采购|成交|更正|招标|中标|变更|结果)$")
 var filterReg = regexp.MustCompile("^[的人号时元万公告项目地址电话邮编日期联系招标中结果成交项目项目采购采购项目政府采购公告更正公告]+$")
 
+const (
+	INDEX = "bidding"
+	TYPE  = "bidding"
+)
+
 func FilteKey(k string) string {
 	k = strings.TrimSpace(k)
 	k = filterReg_3.ReplaceAllString(k, "")

+ 1000 - 999
src/jfw/public/search.go

@@ -1,1001 +1,1002 @@
 package public
 
-import (
-	"encoding/json"
-	"errors"
-	"fmt"
-	"log"
-	"math"
-	"qfw/util"
-	"qfw/util/elastic"
-	"qfw/util/jy"
-	"qfw/util/redis"
-	"sort"
-	"strconv"
-	"strings"
-	"sync"
-	"time"
-
-	"go.mongodb.org/mongo-driver/bson"
-)
-
-/*筛选条件--关键词*/
-type KeyWord struct {
-	Keyword  string   `json:"keyword"`  //关键词
-	Appended []string `json:"appended"` //附加词
-	Exclude  []string `json:"exclude"`  //排除词
-}
-
-/*筛选条件*/
-type SieveCondition struct {
-	Id          string    `json:"id"`
-	PublishTime string    `json:"publishtime"` //发布时间
-	Area        []string  `json:"area"`        //地区-省份
-	City        []string  `json:"city"`        //地区-城市
-	Region      []string  `json:"region"`      //地区-省份+城市
-	Industry    []string  `json:"industry"`    //行业
-	Keyword     []KeyWord `json:"keywords"`    //关键词
-	Buyer       []string  `json:"buyer"`       //招标单位(采购单位)
-	Buyerclass  []string  `json:"buyerclass"`  //采购单位类型
-	Winner      []string  `json:"winner"`      //中标单位
-	ComeInTime  int64     `json:"comeintime"`  //入库时间(秒)
-	OpenId      string    `json:"openid"`      //用户openid
-	MinPrice    string    `json:"minprice"`    //金额——最少
-	MaxPrice    string    `json:"maxprice"`    //金额——最多
-	SelectType  string    `json:"selectType"`  //筛选(正文 or 标题)
-	Subtype     string    `json:"subtype"`     //信息类型
-	Comeinfrom  string    `json:"comeinfrom"`  //查询来源
-}
-
-const (
-	INDEX          = "bidding"
-	TYPE           = "bidding"
-	bidSearch_sort = `{"publishtime":-1}`
-)
-
-var ExportTable string = "export_search"
-
-//获取数据导出查询语句
-func getDataExportSql(scd *SieveCondition) string {
-	multi_match := `{"multi_match": {"query": %s,"type": "phrase", "fields": [%s]}}`
-	query := `{"query":{"bool":{"must":[%s],"should":[%s],"minimum_should_match": %d}}}`
-	query_bool_should := `{"bool":{"should":[%s],"minimum_should_match": 1}}`
-	query_price := `{"bool":{"must":[{"range":{"bidamount":{%s}}}]}},{"bool":{"must":[{"range":{"budget":{%s}}}],"must_not":[{"range":{"bidamount":{"gte":-1}}}]}}`
-	query_bool_must := `{"terms":{"%s":[%s]}}`
-	query_bool_must_and := `{"bool":{"must":[%s]%s}}`
-	gte := `"gte": %s`
-	lte := `"lte": %s`
-
-	bools := []string{}
-	musts := []string{fmt.Sprintf(`{"range":{"comeintime":{"lt":%d}}}`, scd.ComeInTime)}
-	//省份
-	areaCity := []string{}
-	if len(scd.Area) > 0 {
-		areaquery := `{"terms":{"area":[`
-		for k, v := range scd.Area {
-			if k > 0 {
-				areaquery += `,`
-			}
-			areaquery += `"` + v + `"`
-		}
-		areaquery += `]}}`
-		areaCity = append(areaCity, areaquery)
-	}
-	//城市
-	if len(scd.City) > 0 {
-		areaquery := `{"terms":{"city":[`
-		for k, v := range scd.City {
-			if k > 0 {
-				areaquery += `,`
-			}
-			areaquery += `"` + v + `"`
-		}
-		areaquery += `]}}`
-		areaCity = append(areaCity, areaquery)
-	}
-	if len(areaCity) > 0 {
-		musts = append(musts, fmt.Sprintf(query_bool_should, strings.Join(areaCity, ",")))
-	}
-	//检索日期
-
-	starttime := ""
-	now := time.Unix(scd.ComeInTime, 0)
-	endtime := fmt.Sprintf("%d", now.Unix())
-	if scd.PublishTime == "lately-7" { //最近7天
-		starttime = fmt.Sprint(time.Date(now.Year(), now.Month(), now.Day()-7, 0, 0, 0, 0, time.Local).Unix())
-	} else if scd.PublishTime == "lately-30" { //最近30天
-		starttime = fmt.Sprint(time.Date(now.Year(), now.Month(), now.Day()-30, 0, 0, 0, 0, time.Local).Unix())
-	} else if scd.PublishTime == "thisyear" { //去年
-		starttime = fmt.Sprint(time.Date(now.Year()-1, 1, 1, 0, 0, 0, 0, time.Local).Unix())
-		endtime = fmt.Sprint(time.Date(now.Year()-1, 12, 31, 23, 59, 59, 0, time.Local).Unix())
-	} else if strings.Contains(scd.PublishTime, "_") { //设置检索日期
-		starttime = strings.Split(scd.PublishTime, "_")[0]
-		endTime_tmp := now
-		if etime := strings.Split(scd.PublishTime, "_")[1]; etime != "" {
-			etTime := time.Unix(util.Int64All(etime), 0)
-			endTime_tmp = time.Date(etTime.Year(), etTime.Month(), etTime.Day()+1, 0, 0, 0, 0, time.Local)
-		}
-		//结束时间必须小于筛选时间
-		if endTime_tmp.After(now) {
-			endTime_tmp = now
-		}
-		endtime = fmt.Sprintf("%d", endTime_tmp.Unix())
-	}
-	timequery := `{"range":{"publishtime":{`
-	if starttime != "" {
-		timequery += `"gte":` + starttime
-	}
-	if starttime != "" && endtime != "" {
-		timequery += `,`
-	}
-	if endtime != "" {
-		timequery += `"lt":` + endtime
-	}
-	timequery += `}}}`
-	musts = append(musts, timequery)
-
-	if scd.Subtype != "" {
-		subquery := `{"terms":{"subtype":[`
-		for k, v := range strings.Split(scd.Subtype, ",") {
-			if k > 0 {
-				subquery += `,`
-			}
-			subquery += `"` + v + `"`
-		}
-		subquery += `]}}`
-		musts = append(musts, subquery)
-	}
-	if len(scd.Industry) > 0 {
-		musts = append(musts, fmt.Sprintf(query_bool_must, "s_subscopeclass", `"`+strings.Join(scd.Industry, `","`)+`"`))
-	}
-	if len(scd.Buyer) > 0 {
-		musts = append(musts, fmt.Sprintf(query_bool_must, "buyer", `"`+strings.Join(scd.Buyer, `","`)+`"`))
-	}
-	if len(scd.Buyerclass) > 0 {
-		musts = append(musts, fmt.Sprintf(query_bool_must, "buyerclass", `"`+strings.Join(scd.Buyerclass, `","`)+`"`))
-	}
-	if len(scd.Winner) > 0 {
-		musts = append(musts, fmt.Sprintf(query_bool_must, "s_winner", `"`+strings.Join(scd.Winner, `","`)+`"`))
-	}
-	_minPrice := ""
-	_maxPrice := ""
-	if scd.MinPrice != "" || scd.MaxPrice != "" {
-		sq := ``
-		if scd.MinPrice != "" {
-			min, _ := strconv.ParseFloat(scd.MinPrice, 64)
-			_minPrice = fmt.Sprintf("%.0f", min*10000)
-			if _minPrice == "0" {
-				_minPrice = ""
-			}
-		}
-		if scd.MaxPrice != "" {
-			max, _ := strconv.ParseFloat(scd.MaxPrice, 64)
-			_maxPrice = fmt.Sprintf("%.0f", max*10000)
-			if _maxPrice == "0" {
-				_maxPrice = ""
-			}
-		}
-		if _minPrice != "" {
-			sq += fmt.Sprintf(gte, _minPrice)
-		}
-		if _minPrice != "" && _maxPrice != "" {
-			sq += `,`
-		}
-		if _maxPrice != "" {
-			sq += fmt.Sprintf(lte, _maxPrice)
-		}
-		if _minPrice != "" || _maxPrice != "" {
-			query_price := fmt.Sprintf(query_bool_should, fmt.Sprintf(query_price, sq, sq))
-			musts = append(musts, query_price)
-		}
-	}
-	boolsNum := 0
-	//should
-	if len(scd.Keyword) > 0 {
-		boolsNum = 1
-		if scd.SelectType == "" || scd.SelectType == "all" {
-			scd.SelectType = "detail\", \"title"
-		}
-		multi_match = fmt.Sprintf(multi_match, "%s", "\""+scd.SelectType+"\"")
-
-		if scd.Comeinfrom == "supersearchPage" {
-			var keywordArr []string
-			if strings.Contains(scd.Keyword[0].Keyword, "+") {
-				keywordArr = strings.Split(scd.Keyword[0].Keyword, "+")
-			} else if strings.Contains(scd.Keyword[0].Keyword, " ") {
-				keywordArr = strings.Split(scd.Keyword[0].Keyword, " ")
-			}
-			if len(keywordArr) > 1 {
-				KeyWordSearch := KeyWord{}
-				for _, v := range keywordArr {
-					KeyWordSearch.Appended = append(KeyWordSearch.Appended, v)
-				}
-				scd.Keyword = []KeyWord{KeyWordSearch}
-			}
-		}
-
-		for _, v := range scd.Keyword {
-			shoulds := []string{}
-			must_not := []string{}
-			//附加词
-			if v.Keyword != "" {
-				shoulds = append(shoulds, fmt.Sprintf(multi_match, "\""+v.Keyword+"\""))
-			}
-
-			for _, vv := range v.Appended {
-				shoulds = append(shoulds, fmt.Sprintf(multi_match, "\""+vv+"\""))
-			}
-
-			//排除词
-			for _, vv := range v.Exclude {
-				must_not = append(must_not, fmt.Sprintf(multi_match, "\""+vv+"\""))
-			}
-
-			//添加
-			if len(shoulds) > 0 {
-				notStr := ""
-				if len(must_not) > 0 {
-					notStr = fmt.Sprintf(`,"must_not":[%s]`, strings.Join(must_not, ","))
-				}
-				bools = append(bools, fmt.Sprintf(query_bool_must_and, strings.Join(shoulds, ","), notStr))
-			}
-		}
-	}
-	qstr := fmt.Sprintf(query, strings.Join(musts, ","), strings.Join(bools, ","), boolsNum)
-	return qstr
-}
-
-func getSqlObjFromId(_id string) *SieveCondition {
-	var (
-		query *map[string]interface{}
-		ok    bool
-	)
-	if query, ok = MQFW.FindById(ExportTable, _id, nil); !ok {
-		return nil
-	}
-	return &SieveCondition{
-		Id:          _id,
-		Keyword:     getKeyWordArrFromDbResult((*query)["keywords"]),
-		Industry:    getStringArrFromDbResult((*query)["industry"]),
-		MinPrice:    util.ObjToString((*query)["minprice"]),
-		MaxPrice:    util.ObjToString((*query)["maxprice"]),
-		Subtype:     util.ObjToString((*query)["subtype"]),
-		Area:        getStringArrFromDbResult((*query)["area"]),
-		City:        getStringArrFromDbResult((*query)["city"]),
-		SelectType:  util.ObjToString((*query)["selectType"]),
-		PublishTime: util.ObjToString((*query)["publishtime"]),
-		Buyer:       getStringArrFromDbResult((*query)["buyer"]),
-		Buyerclass:  getStringArrFromDbResult((*query)["buyerclass"]),
-		Winner:      getStringArrFromDbResult((*query)["winner"]),
-		ComeInTime:  util.Int64All((*query)["comeintime"]),
-		Comeinfrom:  util.ObjToString((*query)["comeinfrom"]),
-	}
-}
-
-//数据导出-查询结果数量
-func GetDataExportSearchCountUseId(_id string) (count int) {
-	scd := getSqlObjFromId(_id)
-	qstr := getDataExportSql(scd)
-	log.Printf("GetDataExportSearchCountUseId-%s-count:%d-sql:%s\n", _id, count, qstr)
-	if isNullSearch(scd) {
-		return ExConf.MsgMaxCount
-	}
-	count = int(elastic.Count(INDEX, TYPE, qstr))
-	//超级搜索一致的检索(防止数据导出和超级搜索数据量不一致)
-	if scd.Comeinfrom == "supersearchPage" && (len(scd.Keyword) != 0 || len(scd.Industry) != 0) {
-		if len(scd.Keyword) != 0 {
-			searchTextSize := 0
-			if len(scd.Keyword) > 0 {
-				searchTextSize = len([]rune(scd.Keyword[0].Keyword))
-			}
-			if searchTextSize > 3 && count < 50 {
-				var res *[]map[string]interface{}
-				if count > 0 {
-					res = doSearch(qstr, 0, count, "")
-				}
-				secondKWS := jy.HttpEs(scd.Keyword[0].Keyword, "ik_smart", DbConf.Elasticsearch.Main.Address)
-				scd.Keyword[0].Keyword = secondKWS
-				scd.SelectType = "title"
-				qstr = getDataExportSql(scd)
-				res2 := doSearch(qstr, 0, 100, "")
-				result := len(*delRepeatMapArr(res, res2))
-				if result > 100 {
-					result = 100
-				}
-				log.Printf("GetDataExportSearchCountUseId-%s-count:%d-分词-sql:%s\n", _id, result, qstr)
-				return result
-			}
-			return
-		}
-	}
-	log.Printf("GetDataExportSearchCountUseId-%s-count:%d\n", _id, count)
-	return
-}
-
-//合并map数据,去重
-func delRepeatMapArr(res *[]map[string]interface{}, res2 *[]map[string]interface{}) *[]map[string]interface{} {
-	if res != nil {
-		for _, v := range *res {
-			for n, m := range *res2 {
-				if util.ObjToString(v["_id"]) == util.ObjToString(m["_id"]) {
-					*res2 = append((*res2)[0:n], (*res2)[n+1:]...)
-					break
-				}
-			}
-		}
-		*res = append(*res, *res2...)
-	} else {
-		res = res2
-	}
-	return res
-}
-
-//查询条件是否为空
-func isNullSearch(scd *SieveCondition) (isNull bool) {
-	if scd.PublishTime == "" && len(scd.Area) == 0 && len(scd.Industry) == 0 && len(scd.Keyword) == 0 && len(scd.Buyer) == 0 && len(scd.Winner) == 0 && scd.MinPrice == "" && scd.MaxPrice == "" && scd.Subtype == "" && len(scd.City) == 0 {
-		isNull = true
-	}
-	return isNull
-}
-
-/*
- * 数据导出 查询结果
- * _id 数据库查询条件记录id
- * dataType 1-普通字段 2-高级字段
- * webdomain 三级页域名
- * count 返回数量 (-1:预览数据查询)
- */
-var EntTable = "winner_enterprise"
-
-func GetDataExportSearchResultUseId(_id, dataType string, count int) (*[]map[string]interface{}, []KeyWord) {
-	defer util.Catch()
-	var res []map[string]interface{}
-	var kws []KeyWord
-	scd := getSqlObjFromId(_id)
-	//获取查询语句
-	qstr := getDataExportSql(scd)
-	log.Printf("GetDataExportSearchResultUseId-%s-sql:%s\n", scd.Id, qstr)
-	kws = scd.Keyword
-	//数据预览数据查询
-	if scd.Comeinfrom == "supersearchPage" && len(scd.Keyword) == 0 && len(scd.Industry) == 0 {
-		//空查询
-		obj := redis.Get("other", "export_news")
-		if obj != nil {
-			res = util.ObjArrToMapArr(obj.([]interface{}))
-		} else {
-			res = *doSearch(qstr, 0, 500, "2")
-			if len(res) > 0 {
-				redis.Put("other", "export_news", res, 7200)
-			}
-		}
-		return &res, kws
-	} else if scd.Comeinfrom == "supersearchPage" {
-		//超级搜索非空查询
-		count = int(elastic.Count(INDEX, TYPE, qstr))
-		searchTextSize := 0
-		if len(scd.Keyword) > 0 {
-			searchTextSize = len([]rune(scd.Keyword[0].Keyword))
-		}
-		if searchTextSize > 3 && count < 50 {
-			var res *[]map[string]interface{}
-			if count > 0 {
-				res = doSearch(qstr, 0, count, "")
-			}
-			secondKWS := jy.HttpEs(scd.Keyword[0].Keyword, "ik_smart", DbConf.Elasticsearch.Main.Address)
-			scd.Keyword[0].Keyword = secondKWS
-			scd.SelectType = "title"
-			qstr = getDataExportSql(scd)
-			log.Printf("GetDataExportSearchResultUseId-%s-分词-sql:%s\n", scd.Id, qstr)
-			res2 := doSearch(qstr, 0, 100, "")
-			if len(*res2) > 100 {
-				res2_temp := (*res2)[:100]
-				res2 = &res2_temp
-			}
-			return delRepeatMapArr(res, res2), kws
-		}
-	}
-	//非空查询
-	res = *doSearch(qstr, 0, 500, dataType)
-	return &res, kws
-}
-
-func FormatExportData(data *[]map[string]interface{}, webdomain string, dataType string, EntArr []string) *[]map[string]interface{} {
-	//格式化输出
-	for _, v := range *data {
-		//有中标企业 且 高级字段查询
-		if len(EntArr) > 0 && dataType == "2" {
-			//查询企业公示 法人 公司电话 公司邮箱地址
-			query := bson.M{"company_name": bson.M{"$in": EntArr}} //
-			if entData, ok := Mgo_Ent.Find(EntTable, query, nil, `{"company_name":1,"company_email":1,"legal_person":1,"company_phone":1}`, false, -1, -1); ok {
-				if entData != nil && *entData != nil && len(*entData) > 0 {
-					for _, ev := range *entData {
-						if v["s_winner"] == ev["company_name"] {
-							legal_person := ""
-							if ev["legal_person"] != nil && ev["legal_person"].(string) != "" {
-								legal_person = ev["legal_person"].(string)
-								var xx = "*"
-								switch len([]rune(legal_person)) {
-								case 3:
-									xx = "**"
-								case 4:
-									xx = "***"
-								}
-								legal_person = string([]rune(legal_person)[:1]) + xx
-							}
-							company_phone := ""
-							if ev["company_phone"] != nil && ev["company_phone"].(string) != "" {
-								company_phone = ev["company_phone"].(string)
-								if len([]rune(company_phone)) > 7 {
-									company_phone = company_phone[:7] + "****"
-								} else {
-									company_phone = "****"
-								}
-							}
-							company_email := ""
-							if ev["company_email"] != nil && ev["company_email"].(string) != "无" {
-								company_email = ev["company_email"].(string)
-								if len(strings.Split(company_email, "@")) > 1 {
-									company_email = "******" + "@" + strings.Split(company_email, "@")[1]
-								}
-							}
-							v["legal_person"] = legal_person
-							v["company_phone"] = company_phone
-							v["company_email"] = company_email
-						}
-					}
-				}
-			}
-		}
-		//====================字段补漏=========================
-		if v["toptype"] == "结果" && dataType == "2" && !(v["agency"] != nil && v["budget"] != nil && v["buyerperson"] != nil && v["buyertel"] != nil) {
-			r := elastic.Get("projectset", "projectset", fmt.Sprintf(`{"query":{"term":{"list.infoid":"%s"}},"_source": ["list"]}`, v["_id"]))
-			if len(*r) > 0 {
-				MsgList := (*r)[0]["list"]
-				if MsgList != nil {
-					list := util.ObjArrToMapArr(MsgList.([]interface{}))
-					for _, vv := range list {
-						if vv["subtype"] == "招标" {
-							if v["agency"] == nil && vv["agency"] != nil {
-								v["agency"] = vv["agency"]
-							}
-							if v["budget"] == nil && vv["budget"] != nil {
-								v["budget"] = vv["budget"]
-							}
-							if v["buyerperson"] == nil && vv["buyerperson"] != nil {
-								v["buyerperson"] = vv["buyerperson"]
-							}
-							if v["buyertel"] == nil && vv["buyertel"] != nil {
-								v["buyertel"] = vv["buyertel"]
-							}
-							break
-						}
-					}
-				}
-			}
-		}
-		if v["area"] == "A" {
-			v["area"] = "全国"
-		}
-		if v["bidamount"] != nil {
-			v["bidamount"] = formatFloat(util.Float64All(v["bidamount"]))
-		}
-		if v["budget"] != nil {
-			v["budget"] = formatFloat(util.Float64All(v["budget"]))
-		}
-		if v["publishtime"] != nil {
-			date := v["publishtime"]
-			v["publishtime"] = util.FormatDateWithObj(&date, util.Date_Short_Layout)
-		}
-		if v["bidopentime"] != nil {
-			date := v["bidopentime"]
-			v["bidopentime"] = util.FormatDateWithObj(&date, util.Date_Short_Layout)
-		}
-		if v["_id"] != nil {
-			v["url"] = webdomain + "/article/content/" + util.CommonEncodeArticle("content", v["_id"].(string)) + ".html"
-		}
-		if v["currency"] == "" || v["currency"] == nil {
-			v["currency"] = "人民币"
-		}
-		if v["projectscope"] != "" && v["projectscope"] != nil {
-			str := ClearHtml.ReplaceAllString(v["projectscope"].(string), "")
-			str = ClearOther.ReplaceAllString(str, "")
-			str = strings.Replace(str, " ", "", -1)
-			if len([]rune(str)) > 100 {
-				str = util.SubString(str, 0, 100) + "..."
-			}
-			v["projectscope"] = str
-		}
-		if v["detail"] != "" && v["detail"] != nil {
-			str := ClearHtml.ReplaceAllString(v["detail"].(string), "")
-			str = ClearOther.ReplaceAllString(str, "")
-			str = strings.Replace(str, " ", "", -1)
-			if len([]rune(str)) > 100 {
-				str = util.SubString(str, 0, 100) + "..."
-			}
-			v["detail"] = str
-		}
-		if v["title"] != "" && v["title"] != nil {
-			str := ClearHtml.ReplaceAllString(v["title"].(string), "")
-			str = ClearOther.ReplaceAllString(str, "")
-			str = strings.Replace(str, " ", "", -1)
-			if len([]rune(str)) > 100 {
-				str = util.SubString(str, 0, 100) + "..."
-			}
-			v["title"] = str
-		}
-		if v["subtype"] == nil && v["toptype"] != nil {
-			v["subtype"] = v["toptype"]
-		}
-	}
-	return data
-}
-
-//保留到0.01分
-func formatFloat(value float64) string {
-	str := strings.TrimRight(fmt.Sprintf("%.7f", value*10000/100000000), "0")
-	if str[len(str)-1:] == "." {
-		return str[:len(str)-1]
-	}
-	return str
-}
-
-func FormatExportDatas(data *[]map[string]interface{}, webdomain string, dataType string, entId int) *[]map[string]interface{} {
-	//格式化输出
-	var (
-		entexportPool      = make(chan bool, 20)
-		entexportWaitGroup = &sync.WaitGroup{}
-		// newsDatalen        = make(chan bool, 20000)
-		// datalock           = sync.RWMutex{}
-	)
-	log.Println("补充信息开始")
-	for _, v := range *data {
-		entexportWaitGroup.Add(1)
-		entexportPool <- true
-		go func(v map[string]interface{}) {
-			defer func() {
-				entexportWaitGroup.Done()
-				<-entexportPool
-				// datalock.Unlock()
-			}()
-			// datalock.Lock()
-			//二次验证
-			// id := util.ObjToString(v["_id"])
-			// isExist, err := redis.Exists("other", "entexportdata_"+id+"_"+fmt.Sprintln(entId))
-			// if err != nil {
-			// 	log.Println("企业搜索数据导出redis判重失败")
-			// } else if !isExist {
-			// 	newsDatalen <- true
-			// }
-			//
-			//有中标企业 且 高级字段查询
-			if dataType == "2" {
-				//查询企业公示 法人 公司电话 公司邮箱地址
-				// query := bson.M{"company_name": bson.M{"$in": EntArr}} //
-				s_winner := strings.Split(util.ObjToString(v["s_winner"]), ",")[0]
-				query := bson.M{"company_name": s_winner} //
-				if entData, ok := Mgo_Ent.Find(EntTable, query, nil, `{"company_name":1,"company_email":1,"legal_person":1,"company_phone":1}`, false, -1, -1); ok {
-					if entData != nil && *entData != nil && len(*entData) > 0 {
-						for _, ev := range *entData {
-							if v["s_winner"] == ev["company_name"] {
-								legal_person := ""
-								if ev["legal_person"] != nil {
-									legal_person = ev["legal_person"].(string)
-								}
-								company_phone := ""
-								if ev["company_phone"] != nil {
-									company_phone = ev["company_phone"].(string)
-								}
-								company_email := ""
-								if ev["company_email"] != nil && ev["company_email"] != "无" {
-									company_email = ev["company_email"].(string)
-								}
-								v["legal_person"] = legal_person
-								v["company_phone"] = company_phone
-								v["company_email"] = company_email
-							}
-						}
-					}
-				}
-			}
-			//====================字段补漏=========================
-			if v["toptype"] == "结果" && dataType == "2" && !(v["agency"] != nil && v["budget"] != nil && v["buyerperson"] != nil && v["buyertel"] != nil) {
-				r := elastic.Get("projectset", "projectset", fmt.Sprintf(`{"query":{"term":{"list.infoid":"%s"}},"_source": ["list"]}`, v["_id"]))
-				if len(*r) > 0 {
-					MsgList := (*r)[0]["list"]
-					if MsgList != nil {
-						list := util.ObjArrToMapArr(MsgList.([]interface{}))
-						for _, vv := range list {
-							if vv["subtype"] == "招标" {
-								if v["agency"] == nil && vv["agency"] != nil {
-									v["agency"] = vv["agency"]
-								}
-								if v["budget"] == nil && vv["budget"] != nil {
-									v["budget"] = vv["budget"]
-								}
-								if v["buyerperson"] == nil && vv["buyerperson"] != nil {
-									v["buyerperson"] = vv["buyerperson"]
-								}
-								if v["buyertel"] == nil && vv["buyertel"] != nil {
-									v["buyertel"] = vv["buyertel"]
-								}
-								break
-							}
-						}
-					}
-				}
-			}
-			if v["area"] == "A" {
-				v["area"] = "全国"
-			}
-			// if v["bidamount"] != nil {
-			// 	v["bidamount"] = fmt.Sprintf("%g", util.Float64All(v["bidamount"]))
-			// }
-			// if v["budget"] != nil {
-			// 	v["budget"] = fmt.Sprintf("%g", util.Float64All(v["budget"]))
-			// }
-			if v["publishtime"] != nil {
-				date := v["publishtime"]
-				v["publishtime"] = util.FormatDateWithObj(&date, util.Date_Short_Layout)
-			}
-			if v["bidopentime"] != nil {
-				date := v["bidopentime"]
-				v["bidopentime"] = util.FormatDateWithObj(&date, util.Date_Short_Layout)
-			}
-			if v["currency"] == "" || v["currency"] == nil {
-				v["currency"] = "人民币"
-			}
-			if v["subtype"] == nil && v["toptype"] != nil {
-				v["subtype"] = v["toptype"]
-			}
-			if v["detail"] != "" && v["detail"] != nil {
-				str := ClearHtml.ReplaceAllString(v["detail"].(string), "")
-				str = ClearOther.ReplaceAllString(str, "")
-				str = strings.Replace(str, " ", "", -1)
-				v["detail"] = str
-			}
-			if v["_id"] != nil {
-				v["url"] = webdomain + "/article/content/" + util.CommonEncodeArticle("content", v["_id"].(string)) + ".html"
-			}
-		}(v)
-	}
-	entexportWaitGroup.Wait()
-	log.Println("补充信息结束")
-	return data
-}
-
-func doSearch(sql string, start, count int, dataType string) *[]map[string]interface{} {
-	if sql != "" {
-		//筛选字段
-		if dataType != "" {
-			dataexport_field := `"_id","title","detail","area","city","publishtime","projectname","buyer","s_winner","bidamount","subtype","toptype"`
-			if dataType == "2" {
-				dataexport_field += `,"href","projectcode","buyerperson","buyertel","budget","bidopentime","agency","projectscope","winnerperson","winnertel"`
-			}
-			sql = sql[:len(sql)-1] + `,"_source":[` + dataexport_field + "]}"
-		}
-		//分页排序
-		sql = sql[:len(sql)-1] + `,"sort": {"publishtime":"desc"},"from":` + strconv.Itoa(start) + `,"size":` + strconv.Itoa(count) + "}"
-	}
-	return elastic.Get(INDEX, TYPE, sql)
-}
-
-func getKeyWordArrFromDbResult(k interface{}) (arr []KeyWord) {
-	if k == nil {
-		return
-	}
-	kArr := k.([]interface{})
-	for _, v := range kArr {
-		kw := KeyWord{}
-		b, e := json.Marshal(v)
-		if e != nil {
-			log.Println(e.Error())
-		}
-		json.Unmarshal(b, &kw)
-		arr = append(arr, kw)
-	}
-	return
-}
-
-func getStringArrFromDbResult(c interface{}) (arr []string) {
-	if c != nil {
-		cArr := c.([]interface{})
-		arr = util.ObjArrToStringArr(cArr)
-	}
-	return
-}
-
-//获取结果,空字段最少的数据
-func ScreenData(arr *[]map[string]interface{}, dataType string, resultNum int, kws []KeyWord) (res []map[string]interface{}) {
-	AllMap := map[int][]map[string]interface{}{}
-
-	NoKwsMap := map[int][]map[string]interface{}{}
-	lastNum := resultNum
-	for _, v := range *arr {
-		emptyNum := countOfTheEmpty(v, dataType)
-		if emptyNum == -1 {
-			continue
-		}
-		if len(kws) > 0 && kws[0].Keyword != "" {
-			var kwsFlag = true
-			for _, vk := range kws {
-				if strings.Contains(util.ObjToString(v["title"]), strings.Replace(vk.Keyword, "+", "", -1)) {
-					kwsFlag = false
-					continue
-				}
-			}
-			if kwsFlag {
-				if NoKwsMap[emptyNum] == nil {
-					NoKwsMap[emptyNum] = []map[string]interface{}{v}
-				} else {
-					NoKwsMap[emptyNum] = append(NoKwsMap[emptyNum], v)
-				}
-				continue
-			}
-		}
-		if AllMap[emptyNum] == nil {
-			AllMap[emptyNum] = []map[string]interface{}{v}
-			continue
-		}
-		AllMap[emptyNum] = append(AllMap[emptyNum], v)
-	}
-	//获取key
-	keys := []int{}
-	for k, _ := range AllMap {
-		keys = append(keys, k)
-	}
-	sort.Ints(keys)
-	log.Println("空字段数量", keys)
-	//选取结果
-	for _, v := range keys {
-		if len(AllMap[v]) >= resultNum {
-			return append(res, AllMap[v][:resultNum]...)
-		} else {
-			resultNum = resultNum - len(AllMap[v])
-			tmp := append(res, AllMap[v][:len(AllMap[v])]...)
-			res = tmp
-		}
-	}
-	if len(res) < lastNum {
-		resultNum = lastNum - len(res)
-		//获取key
-		Nokeys := []int{}
-		for k, _ := range NoKwsMap {
-			Nokeys = append(Nokeys, k)
-		}
-		sort.Ints(Nokeys)
-		log.Println("没关键词的空字段数量", Nokeys)
-		//选取结果
-		for _, v := range Nokeys {
-			if len(NoKwsMap[v]) >= resultNum {
-				return append(res, NoKwsMap[v][:resultNum]...)
-			} else {
-				resultNum = resultNum - len(NoKwsMap[v])
-				tmp := append(res, NoKwsMap[v][:len(NoKwsMap[v])]...)
-				res = tmp
-			}
-		}
-	}
-	return res
-}
-func countOfTheEmpty(m map[string]interface{}, dataType string) int {
-	MsgType := m["subtype"]
-	//	if MsgType == "拟建" {
-	//		return -1
-	//	}
-	//计算空字段数量
-	var count int = 0
-	//高级字段包
-	if dataType == "2" {
-		if m["href"] == "" || m["href"] == nil {
-			count++
-		}
-		if m["projectcode"] == "" || m["projectcode"] == nil {
-			count++
-		}
-		if m["buyerperson"] == "" || m["buyerperson"] == nil {
-			count++
-		}
-		if m["buyertel"] == "" || m["buyertel"] == nil {
-			count++
-		}
-		if m["budget"] == "" || m["budget"] == nil {
-			count++
-		}
-		if m["bidopentime"] == "" || m["bidopentime"] == nil {
-			count++
-		}
-		if m["agency"] == "" || m["agency"] == nil {
-			count++
-		}
-		if m["projectscope"] == "" || m["projectscope"] == nil {
-			count++
-		}
-	}
-	if m["city"] == "" || m["city"] == nil {
-		count++
-	}
-	if m["publishtime"] == "" || m["publishtime"] == nil {
-		count++
-	}
-	if m["projectname"] == "" || m["projectname"] == nil {
-		count++
-	}
-	if m["buyer"] == "" || m["buyer"] == nil {
-		count++
-	}
-	if m["s_winner"] == "" || m["s_winner"] == nil {
-		if MsgType != "招标" {
-			count++
-		}
-	}
-	if m["bidamount"] == "" || m["bidamount"] == nil {
-		if MsgType != "招标" {
-			count++
-		}
-	}
-	if m["subtype"] == "" || m["subtype"] == nil {
-		count++
-	}
-	return count
-}
-
-func GetEntDataExportCount(_id string, entId, entUserId, limitNum, current int, isFirst bool) (count, newCount int, data *[]map[string]interface{}) {
-	defer util.Catch()
-	var (
-		searchsWaitGroup = &sync.WaitGroup{}
-		searchsPool      = make(chan bool, 20)
-		// res              = &[]map[string]interface{}{}
-		newCountPool = make(chan bool, 20000)
-	)
-	count = GetDataExportSearchCountUseId(_id)
-	log.Println("count", count)
-	if count > ExConf.MsgMaxCount {
-		count = ExConf.MsgMaxCount
-	}
-	dataType := "2"
-	//数据导出数据查询
-
-	res, err := GetDataExportSearchResult(_id, dataType, count)
-	if err != nil {
-		log.Println("企业数据导出错误 ", err)
-		return 0, 0, nil
-	}
-	// secondCount := 0
-
-	// isOK := true
-	// if secondCount > current {
-	// 	isOK = false
-	// }
-	for _, v := range *res {
-		searchsWaitGroup.Add(1)
-		searchsPool <- true
-		id := util.ObjToString(v["_id"])
-		go func(id string) {
-			defer func() {
-				searchsWaitGroup.Done()
-				<-searchsPool
-			}()
-			isExist, err := redis.Exists("other", "entexportdata_"+id+"_"+fmt.Sprintln(entId))
-			if err != nil {
-				log.Println("企业搜索数据导出redis判重失败")
-			} else if isExist {
-				log.Println("数据重复,id ", id, "entid ", entId, "userid ", entUserId)
-				return
-			}
-			newCountPool <- true
-			if !isFirst {
-				redis.Put("other", "entexportdata_"+id+"_"+fmt.Sprintln(entId), 1, -1)
-			}
-		}(id)
-		if !isFirst {
-			delete(v, "_id")
-			v["entid"] = entId
-			v["userid"] = entUserId
-			v["infoid"] = id
-			v["createtime"] = time.Now().Unix()
-		}
-	}
-	searchsWaitGroup.Wait()
-	log.Println("企业数据导出--数据遍历完成")
-	newCount = len(newCountPool)
-	log.Println("new", newCount)
-	data = res
-	return
-}
-
-func GetDataExportSearchResult(id string, dataType string, checkCount int) (*[]map[string]interface{}, error) {
-	defer util.Catch()
-	var (
-		onceSearchCount = 500
-		searchPool      = make(chan bool, 20)
-		res             []map[string]interface{}
-	)
-	//获取查询语句
-	scd := getSqlObjFromId(id)
-	if scd == nil {
-		return nil, errors.New("GetDataExportSearchResult-获取查询条件")
-	}
-	qstr := getDataExportSql(scd)
-	log.Printf("GetDataExportSearchResult-%s-sql:%s\n", scd.Id, qstr)
-	//数据导出数据查询
-	if checkCount > onceSearchCount { //分批次查询
-		batchNum := util.IntAll(math.Ceil(float64(checkCount) / float64(onceSearchCount)))
-		var searchWaitGroup = &sync.WaitGroup{}
-		var lock sync.Mutex
-		for n := 0; n < batchNum; n++ {
-			searchWaitGroup.Add(1)
-			searchPool <- true
-			go func(start int) {
-				defer func() {
-					searchWaitGroup.Done()
-					<-searchPool
-				}()
-				checkNum, checkOk := onceSearchCount, false
-				if start == (batchNum - 1) {
-					if checkCount%onceSearchCount != 0 {
-						checkNum = checkCount % onceSearchCount
-					}
-				}
-
-				var tmp *[]map[string]interface{}
-				for i := 0; i < 3; i++ {
-					tmp = doSearch(qstr, start*onceSearchCount, onceSearchCount, dataType)
-					if tmp != nil && (len(*tmp) == checkNum) { //校验数据量是否够
-						checkOk = true
-						break
-					}
-				}
-				if tmp == nil {
-					log.Printf("GetDataExportSearchResult-%s-第%d页数据查询结果为空\n", scd.Id, start+1)
-					return
-				}
-				if checkOk {
-					log.Printf("GetDataExportSearchResult-%s-第%d页数据加载完成,共%d条\n", scd.Id, start+1, len(*tmp))
-				} else {
-					log.Printf("GetDataExportSearchResult-%s-第%d页数据加载异常,共%d条,预期%d条\n", scd.Id, start+1, len(*tmp), checkNum)
-				}
-				lock.Lock()
-				res = append(res, *tmp...)
-				lock.Unlock()
-			}(n)
-		}
-		searchWaitGroup.Wait()
-		log.Printf("GetDataExportSearchResult-%s-分批次加载数据总量为%d\n", scd.Id, len(res))
-	} else {
-		tmp := doSearch(qstr, 0, checkCount, dataType)
-		if tmp == nil || len(*tmp) == 0 {
-			log.Printf("GetDataExportSearchResult-%s-一次性加载数据异常\n", scd.Id)
-		} else {
-			res = *tmp
-			log.Printf("GetDataExportSearchResult-%s-一次性加载数据总量为%d\n", scd.Id, len(res))
-		}
-	}
-	//超级搜索一致的检索(防止数据导出和超级搜索数据量不一致)
-	if scd.Comeinfrom == "supersearchPage" && (len(scd.Keyword) != 0 || len(scd.Industry) != 0) {
-		if len(scd.Keyword) != 0 {
-			num := len(res)
-			searchTextSize := 0
-			if len(scd.Keyword) > 0 {
-				searchTextSize = len([]rune(scd.Keyword[0].Keyword))
-			}
-			if searchTextSize > 3 && num < 50 {
-				secondKWS := jy.HttpEs(scd.Keyword[0].Keyword, "ik_smart", DbConf.Elasticsearch.Main.Address)
-				scd.Keyword[0].Keyword = secondKWS
-				scd.SelectType = "title"
-				qstr = getDataExportSql(scd)
-				log.Printf("GetDataExportSearchResult-%s-分词查询-sql:%s\n", scd.Id, qstr)
-				res2 := doSearch(qstr, 0, 100, "")
-				res = *delRepeatMapArr(&res, res2)
-				if len(res) > 100 {
-					res = res[:100]
-				}
-			}
-		}
-	}
-	//校验数量
-	if checkCount != len(res) {
-		return nil, fmt.Errorf("GetDataExportSearchResult-%s-数据总量校验异常,期望:%d,实际:%d", scd.Id, checkCount, len(res))
-		//发邮件
-	}
-	return &res, nil
-}
+//
+//import (
+//	"encoding/json"
+//	"errors"
+//	"fmt"
+//	"log"
+//	"math"
+//	"qfw/util"
+//	"qfw/util/elastic"
+//	"qfw/util/jy"
+//	"qfw/util/redis"
+//	"sort"
+//	"strconv"
+//	"strings"
+//	"sync"
+//	"time"
+//
+//	"go.mongodb.org/mongo-driver/bson"
+//)
+//
+///*筛选条件--关键词*/
+//type KeyWord struct {
+//	Keyword  string   `json:"keyword"`  //关键词
+//	Appended []string `json:"appended"` //附加词
+//	Exclude  []string `json:"exclude"`  //排除词
+//}
+//
+///*筛选条件*/
+//type SieveCondition struct {
+//	Id          string    `json:"id"`
+//	PublishTime string    `json:"publishtime"` //发布时间
+//	Area        []string  `json:"area"`        //地区-省份
+//	City        []string  `json:"city"`        //地区-城市
+//	Region      []string  `json:"region"`      //地区-省份+城市
+//	Industry    []string  `json:"industry"`    //行业
+//	Keyword     []KeyWord `json:"keywords"`    //关键词
+//	Buyer       []string  `json:"buyer"`       //招标单位(采购单位)
+//	Buyerclass  []string  `json:"buyerclass"`  //采购单位类型
+//	Winner      []string  `json:"winner"`      //中标单位
+//	ComeInTime  int64     `json:"comeintime"`  //入库时间(秒)
+//	OpenId      string    `json:"openid"`      //用户openid
+//	MinPrice    string    `json:"minprice"`    //金额——最少
+//	MaxPrice    string    `json:"maxprice"`    //金额——最多
+//	SelectType  string    `json:"selectType"`  //筛选(正文 or 标题)
+//	Subtype     string    `json:"subtype"`     //信息类型
+//	Comeinfrom  string    `json:"comeinfrom"`  //查询来源
+//}
+//
+//const (
+//	INDEX          = "bidding"
+//	TYPE           = "bidding"
+//	bidSearch_sort = `{"publishtime":-1}`
+//)
+//
+//var ExportTable string = "export_search"
+//
+////获取数据导出查询语句
+//func getDataExportSql(scd *SieveCondition) string {
+//	multi_match := `{"multi_match": {"query": %s,"type": "phrase", "fields": [%s]}}`
+//	query := `{"query":{"bool":{"must":[%s],"should":[%s],"minimum_should_match": %d}}}`
+//	query_bool_should := `{"bool":{"should":[%s],"minimum_should_match": 1}}`
+//	query_price := `{"bool":{"must":[{"range":{"bidamount":{%s}}}]}},{"bool":{"must":[{"range":{"budget":{%s}}}],"must_not":[{"range":{"bidamount":{"gte":-1}}}]}}`
+//	query_bool_must := `{"terms":{"%s":[%s]}}`
+//	query_bool_must_and := `{"bool":{"must":[%s]%s}}`
+//	gte := `"gte": %s`
+//	lte := `"lte": %s`
+//
+//	bools := []string{}
+//	musts := []string{fmt.Sprintf(`{"range":{"comeintime":{"lt":%d}}}`, scd.ComeInTime)}
+//	//省份
+//	areaCity := []string{}
+//	if len(scd.Area) > 0 {
+//		areaquery := `{"terms":{"area":[`
+//		for k, v := range scd.Area {
+//			if k > 0 {
+//				areaquery += `,`
+//			}
+//			areaquery += `"` + v + `"`
+//		}
+//		areaquery += `]}}`
+//		areaCity = append(areaCity, areaquery)
+//	}
+//	//城市
+//	if len(scd.City) > 0 {
+//		areaquery := `{"terms":{"city":[`
+//		for k, v := range scd.City {
+//			if k > 0 {
+//				areaquery += `,`
+//			}
+//			areaquery += `"` + v + `"`
+//		}
+//		areaquery += `]}}`
+//		areaCity = append(areaCity, areaquery)
+//	}
+//	if len(areaCity) > 0 {
+//		musts = append(musts, fmt.Sprintf(query_bool_should, strings.Join(areaCity, ",")))
+//	}
+//	//检索日期
+//
+//	starttime := ""
+//	now := time.Unix(scd.ComeInTime, 0)
+//	endtime := fmt.Sprintf("%d", now.Unix())
+//	if scd.PublishTime == "lately-7" { //最近7天
+//		starttime = fmt.Sprint(time.Date(now.Year(), now.Month(), now.Day()-7, 0, 0, 0, 0, time.Local).Unix())
+//	} else if scd.PublishTime == "lately-30" { //最近30天
+//		starttime = fmt.Sprint(time.Date(now.Year(), now.Month(), now.Day()-30, 0, 0, 0, 0, time.Local).Unix())
+//	} else if scd.PublishTime == "thisyear" { //去年
+//		starttime = fmt.Sprint(time.Date(now.Year()-1, 1, 1, 0, 0, 0, 0, time.Local).Unix())
+//		endtime = fmt.Sprint(time.Date(now.Year()-1, 12, 31, 23, 59, 59, 0, time.Local).Unix())
+//	} else if strings.Contains(scd.PublishTime, "_") { //设置检索日期
+//		starttime = strings.Split(scd.PublishTime, "_")[0]
+//		endTime_tmp := now
+//		if etime := strings.Split(scd.PublishTime, "_")[1]; etime != "" {
+//			etTime := time.Unix(util.Int64All(etime), 0)
+//			endTime_tmp = time.Date(etTime.Year(), etTime.Month(), etTime.Day()+1, 0, 0, 0, 0, time.Local)
+//		}
+//		//结束时间必须小于筛选时间
+//		if endTime_tmp.After(now) {
+//			endTime_tmp = now
+//		}
+//		endtime = fmt.Sprintf("%d", endTime_tmp.Unix())
+//	}
+//	timequery := `{"range":{"publishtime":{`
+//	if starttime != "" {
+//		timequery += `"gte":` + starttime
+//	}
+//	if starttime != "" && endtime != "" {
+//		timequery += `,`
+//	}
+//	if endtime != "" {
+//		timequery += `"lt":` + endtime
+//	}
+//	timequery += `}}}`
+//	musts = append(musts, timequery)
+//
+//	if scd.Subtype != "" {
+//		subquery := `{"terms":{"subtype":[`
+//		for k, v := range strings.Split(scd.Subtype, ",") {
+//			if k > 0 {
+//				subquery += `,`
+//			}
+//			subquery += `"` + v + `"`
+//		}
+//		subquery += `]}}`
+//		musts = append(musts, subquery)
+//	}
+//	if len(scd.Industry) > 0 {
+//		musts = append(musts, fmt.Sprintf(query_bool_must, "s_subscopeclass", `"`+strings.Join(scd.Industry, `","`)+`"`))
+//	}
+//	if len(scd.Buyer) > 0 {
+//		musts = append(musts, fmt.Sprintf(query_bool_must, "buyer", `"`+strings.Join(scd.Buyer, `","`)+`"`))
+//	}
+//	if len(scd.Buyerclass) > 0 {
+//		musts = append(musts, fmt.Sprintf(query_bool_must, "buyerclass", `"`+strings.Join(scd.Buyerclass, `","`)+`"`))
+//	}
+//	if len(scd.Winner) > 0 {
+//		musts = append(musts, fmt.Sprintf(query_bool_must, "s_winner", `"`+strings.Join(scd.Winner, `","`)+`"`))
+//	}
+//	_minPrice := ""
+//	_maxPrice := ""
+//	if scd.MinPrice != "" || scd.MaxPrice != "" {
+//		sq := ``
+//		if scd.MinPrice != "" {
+//			min, _ := strconv.ParseFloat(scd.MinPrice, 64)
+//			_minPrice = fmt.Sprintf("%.0f", min*10000)
+//			if _minPrice == "0" {
+//				_minPrice = ""
+//			}
+//		}
+//		if scd.MaxPrice != "" {
+//			max, _ := strconv.ParseFloat(scd.MaxPrice, 64)
+//			_maxPrice = fmt.Sprintf("%.0f", max*10000)
+//			if _maxPrice == "0" {
+//				_maxPrice = ""
+//			}
+//		}
+//		if _minPrice != "" {
+//			sq += fmt.Sprintf(gte, _minPrice)
+//		}
+//		if _minPrice != "" && _maxPrice != "" {
+//			sq += `,`
+//		}
+//		if _maxPrice != "" {
+//			sq += fmt.Sprintf(lte, _maxPrice)
+//		}
+//		if _minPrice != "" || _maxPrice != "" {
+//			query_price := fmt.Sprintf(query_bool_should, fmt.Sprintf(query_price, sq, sq))
+//			musts = append(musts, query_price)
+//		}
+//	}
+//	boolsNum := 0
+//	//should
+//	if len(scd.Keyword) > 0 {
+//		boolsNum = 1
+//		if scd.SelectType == "" || scd.SelectType == "all" {
+//			scd.SelectType = "detail\", \"title"
+//		}
+//		multi_match = fmt.Sprintf(multi_match, "%s", "\""+scd.SelectType+"\"")
+//
+//		if scd.Comeinfrom == "supersearchPage" {
+//			var keywordArr []string
+//			if strings.Contains(scd.Keyword[0].Keyword, "+") {
+//				keywordArr = strings.Split(scd.Keyword[0].Keyword, "+")
+//			} else if strings.Contains(scd.Keyword[0].Keyword, " ") {
+//				keywordArr = strings.Split(scd.Keyword[0].Keyword, " ")
+//			}
+//			if len(keywordArr) > 1 {
+//				KeyWordSearch := KeyWord{}
+//				for _, v := range keywordArr {
+//					KeyWordSearch.Appended = append(KeyWordSearch.Appended, v)
+//				}
+//				scd.Keyword = []KeyWord{KeyWordSearch}
+//			}
+//		}
+//
+//		for _, v := range scd.Keyword {
+//			shoulds := []string{}
+//			must_not := []string{}
+//			//附加词
+//			if v.Keyword != "" {
+//				shoulds = append(shoulds, fmt.Sprintf(multi_match, "\""+v.Keyword+"\""))
+//			}
+//
+//			for _, vv := range v.Appended {
+//				shoulds = append(shoulds, fmt.Sprintf(multi_match, "\""+vv+"\""))
+//			}
+//
+//			//排除词
+//			for _, vv := range v.Exclude {
+//				must_not = append(must_not, fmt.Sprintf(multi_match, "\""+vv+"\""))
+//			}
+//
+//			//添加
+//			if len(shoulds) > 0 {
+//				notStr := ""
+//				if len(must_not) > 0 {
+//					notStr = fmt.Sprintf(`,"must_not":[%s]`, strings.Join(must_not, ","))
+//				}
+//				bools = append(bools, fmt.Sprintf(query_bool_must_and, strings.Join(shoulds, ","), notStr))
+//			}
+//		}
+//	}
+//	qstr := fmt.Sprintf(query, strings.Join(musts, ","), strings.Join(bools, ","), boolsNum)
+//	return qstr
+//}
+//
+//func getSqlObjFromId(_id string) *SieveCondition {
+//	var (
+//		query *map[string]interface{}
+//		ok    bool
+//	)
+//	if query, ok = MQFW.FindById(ExportTable, _id, nil); !ok {
+//		return nil
+//	}
+//	return &SieveCondition{
+//		Id:          _id,
+//		Keyword:     getKeyWordArrFromDbResult((*query)["keywords"]),
+//		Industry:    getStringArrFromDbResult((*query)["industry"]),
+//		MinPrice:    util.ObjToString((*query)["minprice"]),
+//		MaxPrice:    util.ObjToString((*query)["maxprice"]),
+//		Subtype:     util.ObjToString((*query)["subtype"]),
+//		Area:        getStringArrFromDbResult((*query)["area"]),
+//		City:        getStringArrFromDbResult((*query)["city"]),
+//		SelectType:  util.ObjToString((*query)["selectType"]),
+//		PublishTime: util.ObjToString((*query)["publishtime"]),
+//		Buyer:       getStringArrFromDbResult((*query)["buyer"]),
+//		Buyerclass:  getStringArrFromDbResult((*query)["buyerclass"]),
+//		Winner:      getStringArrFromDbResult((*query)["winner"]),
+//		ComeInTime:  util.Int64All((*query)["comeintime"]),
+//		Comeinfrom:  util.ObjToString((*query)["comeinfrom"]),
+//	}
+//}
+//
+////数据导出-查询结果数量
+//func GetDataExportSearchCountUseId(_id string) (count int) {
+//	scd := getSqlObjFromId(_id)
+//	qstr := getDataExportSql(scd)
+//	log.Printf("GetDataExportSearchCountUseId-%s-count:%d-sql:%s\n", _id, count, qstr)
+//	if isNullSearch(scd) {
+//		return ExConf.MsgMaxCount
+//	}
+//	count = int(elastic.Count(INDEX, TYPE, qstr))
+//	//超级搜索一致的检索(防止数据导出和超级搜索数据量不一致)
+//	if scd.Comeinfrom == "supersearchPage" && (len(scd.Keyword) != 0 || len(scd.Industry) != 0) {
+//		if len(scd.Keyword) != 0 {
+//			searchTextSize := 0
+//			if len(scd.Keyword) > 0 {
+//				searchTextSize = len([]rune(scd.Keyword[0].Keyword))
+//			}
+//			if searchTextSize > 3 && count < 50 {
+//				var res *[]map[string]interface{}
+//				if count > 0 {
+//					res = doSearch(qstr, 0, count, "")
+//				}
+//				secondKWS := jy.HttpEs(scd.Keyword[0].Keyword, "ik_smart", DbConf.Elasticsearch.Main.Address)
+//				scd.Keyword[0].Keyword = secondKWS
+//				scd.SelectType = "title"
+//				qstr = getDataExportSql(scd)
+//				res2 := doSearch(qstr, 0, 100, "")
+//				result := len(*delRepeatMapArr(res, res2))
+//				if result > 100 {
+//					result = 100
+//				}
+//				log.Printf("GetDataExportSearchCountUseId-%s-count:%d-分词-sql:%s\n", _id, result, qstr)
+//				return result
+//			}
+//			return
+//		}
+//	}
+//	log.Printf("GetDataExportSearchCountUseId-%s-count:%d\n", _id, count)
+//	return
+//}
+//
+////合并map数据,去重
+//func delRepeatMapArr(res *[]map[string]interface{}, res2 *[]map[string]interface{}) *[]map[string]interface{} {
+//	if res != nil {
+//		for _, v := range *res {
+//			for n, m := range *res2 {
+//				if util.ObjToString(v["_id"]) == util.ObjToString(m["_id"]) {
+//					*res2 = append((*res2)[0:n], (*res2)[n+1:]...)
+//					break
+//				}
+//			}
+//		}
+//		*res = append(*res, *res2...)
+//	} else {
+//		res = res2
+//	}
+//	return res
+//}
+//
+////查询条件是否为空
+//func isNullSearch(scd *SieveCondition) (isNull bool) {
+//	if scd.PublishTime == "" && len(scd.Area) == 0 && len(scd.Industry) == 0 && len(scd.Keyword) == 0 && len(scd.Buyer) == 0 && len(scd.Winner) == 0 && scd.MinPrice == "" && scd.MaxPrice == "" && scd.Subtype == "" && len(scd.City) == 0 {
+//		isNull = true
+//	}
+//	return isNull
+//}
+//
+///*
+// * 数据导出 查询结果
+// * _id 数据库查询条件记录id
+// * dataType 1-普通字段 2-高级字段
+// * webdomain 三级页域名
+// * count 返回数量 (-1:预览数据查询)
+// */
+//var EntTable = "winner_enterprise"
+//
+//func GetDataExportSearchResultUseId(_id, dataType string, count int) (*[]map[string]interface{}, []KeyWord) {
+//	defer util.Catch()
+//	var res []map[string]interface{}
+//	var kws []KeyWord
+//	scd := getSqlObjFromId(_id)
+//	//获取查询语句
+//	qstr := getDataExportSql(scd)
+//	log.Printf("GetDataExportSearchResultUseId-%s-sql:%s\n", scd.Id, qstr)
+//	kws = scd.Keyword
+//	//数据预览数据查询
+//	if scd.Comeinfrom == "supersearchPage" && len(scd.Keyword) == 0 && len(scd.Industry) == 0 {
+//		//空查询
+//		obj := redis.Get("other", "export_news")
+//		if obj != nil {
+//			res = util.ObjArrToMapArr(obj.([]interface{}))
+//		} else {
+//			res = *doSearch(qstr, 0, 500, "2")
+//			if len(res) > 0 {
+//				redis.Put("other", "export_news", res, 7200)
+//			}
+//		}
+//		return &res, kws
+//	} else if scd.Comeinfrom == "supersearchPage" {
+//		//超级搜索非空查询
+//		count = int(elastic.Count(INDEX, TYPE, qstr))
+//		searchTextSize := 0
+//		if len(scd.Keyword) > 0 {
+//			searchTextSize = len([]rune(scd.Keyword[0].Keyword))
+//		}
+//		if searchTextSize > 3 && count < 50 {
+//			var res *[]map[string]interface{}
+//			if count > 0 {
+//				res = doSearch(qstr, 0, count, "")
+//			}
+//			secondKWS := jy.HttpEs(scd.Keyword[0].Keyword, "ik_smart", DbConf.Elasticsearch.Main.Address)
+//			scd.Keyword[0].Keyword = secondKWS
+//			scd.SelectType = "title"
+//			qstr = getDataExportSql(scd)
+//			log.Printf("GetDataExportSearchResultUseId-%s-分词-sql:%s\n", scd.Id, qstr)
+//			res2 := doSearch(qstr, 0, 100, "")
+//			if len(*res2) > 100 {
+//				res2_temp := (*res2)[:100]
+//				res2 = &res2_temp
+//			}
+//			return delRepeatMapArr(res, res2), kws
+//		}
+//	}
+//	//非空查询
+//	res = *doSearch(qstr, 0, 500, dataType)
+//	return &res, kws
+//}
+//
+//func FormatExportData(data *[]map[string]interface{}, webdomain string, dataType string, EntArr []string) *[]map[string]interface{} {
+//	//格式化输出
+//	for _, v := range *data {
+//		//有中标企业 且 高级字段查询
+//		if len(EntArr) > 0 && dataType == "2" {
+//			//查询企业公示 法人 公司电话 公司邮箱地址
+//			query := bson.M{"company_name": bson.M{"$in": EntArr}} //
+//			if entData, ok := Mgo_Ent.Find(EntTable, query, nil, `{"company_name":1,"company_email":1,"legal_person":1,"company_phone":1}`, false, -1, -1); ok {
+//				if entData != nil && *entData != nil && len(*entData) > 0 {
+//					for _, ev := range *entData {
+//						if v["s_winner"] == ev["company_name"] {
+//							legal_person := ""
+//							if ev["legal_person"] != nil && ev["legal_person"].(string) != "" {
+//								legal_person = ev["legal_person"].(string)
+//								var xx = "*"
+//								switch len([]rune(legal_person)) {
+//								case 3:
+//									xx = "**"
+//								case 4:
+//									xx = "***"
+//								}
+//								legal_person = string([]rune(legal_person)[:1]) + xx
+//							}
+//							company_phone := ""
+//							if ev["company_phone"] != nil && ev["company_phone"].(string) != "" {
+//								company_phone = ev["company_phone"].(string)
+//								if len([]rune(company_phone)) > 7 {
+//									company_phone = company_phone[:7] + "****"
+//								} else {
+//									company_phone = "****"
+//								}
+//							}
+//							company_email := ""
+//							if ev["company_email"] != nil && ev["company_email"].(string) != "无" {
+//								company_email = ev["company_email"].(string)
+//								if len(strings.Split(company_email, "@")) > 1 {
+//									company_email = "******" + "@" + strings.Split(company_email, "@")[1]
+//								}
+//							}
+//							v["legal_person"] = legal_person
+//							v["company_phone"] = company_phone
+//							v["company_email"] = company_email
+//						}
+//					}
+//				}
+//			}
+//		}
+//		//====================字段补漏=========================
+//		if v["toptype"] == "结果" && dataType == "2" && !(v["agency"] != nil && v["budget"] != nil && v["buyerperson"] != nil && v["buyertel"] != nil) {
+//			r := elastic.Get("projectset", "projectset", fmt.Sprintf(`{"query":{"term":{"list.infoid":"%s"}},"_source": ["list"]}`, v["_id"]))
+//			if len(*r) > 0 {
+//				MsgList := (*r)[0]["list"]
+//				if MsgList != nil {
+//					list := util.ObjArrToMapArr(MsgList.([]interface{}))
+//					for _, vv := range list {
+//						if vv["subtype"] == "招标" {
+//							if v["agency"] == nil && vv["agency"] != nil {
+//								v["agency"] = vv["agency"]
+//							}
+//							if v["budget"] == nil && vv["budget"] != nil {
+//								v["budget"] = vv["budget"]
+//							}
+//							if v["buyerperson"] == nil && vv["buyerperson"] != nil {
+//								v["buyerperson"] = vv["buyerperson"]
+//							}
+//							if v["buyertel"] == nil && vv["buyertel"] != nil {
+//								v["buyertel"] = vv["buyertel"]
+//							}
+//							break
+//						}
+//					}
+//				}
+//			}
+//		}
+//		if v["area"] == "A" {
+//			v["area"] = "全国"
+//		}
+//		if v["bidamount"] != nil {
+//			v["bidamount"] = formatFloat(util.Float64All(v["bidamount"]))
+//		}
+//		if v["budget"] != nil {
+//			v["budget"] = formatFloat(util.Float64All(v["budget"]))
+//		}
+//		if v["publishtime"] != nil {
+//			date := v["publishtime"]
+//			v["publishtime"] = util.FormatDateWithObj(&date, util.Date_Short_Layout)
+//		}
+//		if v["bidopentime"] != nil {
+//			date := v["bidopentime"]
+//			v["bidopentime"] = util.FormatDateWithObj(&date, util.Date_Short_Layout)
+//		}
+//		if v["_id"] != nil {
+//			v["url"] = webdomain + "/article/content/" + util.CommonEncodeArticle("content", v["_id"].(string)) + ".html"
+//		}
+//		if v["currency"] == "" || v["currency"] == nil {
+//			v["currency"] = "人民币"
+//		}
+//		if v["projectscope"] != "" && v["projectscope"] != nil {
+//			str := ClearHtml.ReplaceAllString(v["projectscope"].(string), "")
+//			str = ClearOther.ReplaceAllString(str, "")
+//			str = strings.Replace(str, " ", "", -1)
+//			if len([]rune(str)) > 100 {
+//				str = util.SubString(str, 0, 100) + "..."
+//			}
+//			v["projectscope"] = str
+//		}
+//		if v["detail"] != "" && v["detail"] != nil {
+//			str := ClearHtml.ReplaceAllString(v["detail"].(string), "")
+//			str = ClearOther.ReplaceAllString(str, "")
+//			str = strings.Replace(str, " ", "", -1)
+//			if len([]rune(str)) > 100 {
+//				str = util.SubString(str, 0, 100) + "..."
+//			}
+//			v["detail"] = str
+//		}
+//		if v["title"] != "" && v["title"] != nil {
+//			str := ClearHtml.ReplaceAllString(v["title"].(string), "")
+//			str = ClearOther.ReplaceAllString(str, "")
+//			str = strings.Replace(str, " ", "", -1)
+//			if len([]rune(str)) > 100 {
+//				str = util.SubString(str, 0, 100) + "..."
+//			}
+//			v["title"] = str
+//		}
+//		if v["subtype"] == nil && v["toptype"] != nil {
+//			v["subtype"] = v["toptype"]
+//		}
+//	}
+//	return data
+//}
+//
+////保留到0.01分
+//func formatFloat(value float64) string {
+//	str := strings.TrimRight(fmt.Sprintf("%.7f", value*10000/100000000), "0")
+//	if str[len(str)-1:] == "." {
+//		return str[:len(str)-1]
+//	}
+//	return str
+//}
+//
+//func FormatExportDatas(data *[]map[string]interface{}, webdomain string, dataType string, entId int) *[]map[string]interface{} {
+//	//格式化输出
+//	var (
+//		entexportPool      = make(chan bool, 20)
+//		entexportWaitGroup = &sync.WaitGroup{}
+//		// newsDatalen        = make(chan bool, 20000)
+//		// datalock           = sync.RWMutex{}
+//	)
+//	log.Println("补充信息开始")
+//	for _, v := range *data {
+//		entexportWaitGroup.Add(1)
+//		entexportPool <- true
+//		go func(v map[string]interface{}) {
+//			defer func() {
+//				entexportWaitGroup.Done()
+//				<-entexportPool
+//				// datalock.Unlock()
+//			}()
+//			// datalock.Lock()
+//			//二次验证
+//			// id := util.ObjToString(v["_id"])
+//			// isExist, err := redis.Exists("other", "entexportdata_"+id+"_"+fmt.Sprintln(entId))
+//			// if err != nil {
+//			// 	log.Println("企业搜索数据导出redis判重失败")
+//			// } else if !isExist {
+//			// 	newsDatalen <- true
+//			// }
+//			//
+//			//有中标企业 且 高级字段查询
+//			if dataType == "2" {
+//				//查询企业公示 法人 公司电话 公司邮箱地址
+//				// query := bson.M{"company_name": bson.M{"$in": EntArr}} //
+//				s_winner := strings.Split(util.ObjToString(v["s_winner"]), ",")[0]
+//				query := bson.M{"company_name": s_winner} //
+//				if entData, ok := Mgo_Ent.Find(EntTable, query, nil, `{"company_name":1,"company_email":1,"legal_person":1,"company_phone":1}`, false, -1, -1); ok {
+//					if entData != nil && *entData != nil && len(*entData) > 0 {
+//						for _, ev := range *entData {
+//							if v["s_winner"] == ev["company_name"] {
+//								legal_person := ""
+//								if ev["legal_person"] != nil {
+//									legal_person = ev["legal_person"].(string)
+//								}
+//								company_phone := ""
+//								if ev["company_phone"] != nil {
+//									company_phone = ev["company_phone"].(string)
+//								}
+//								company_email := ""
+//								if ev["company_email"] != nil && ev["company_email"] != "无" {
+//									company_email = ev["company_email"].(string)
+//								}
+//								v["legal_person"] = legal_person
+//								v["company_phone"] = company_phone
+//								v["company_email"] = company_email
+//							}
+//						}
+//					}
+//				}
+//			}
+//			//====================字段补漏=========================
+//			if v["toptype"] == "结果" && dataType == "2" && !(v["agency"] != nil && v["budget"] != nil && v["buyerperson"] != nil && v["buyertel"] != nil) {
+//				r := elastic.Get("projectset", "projectset", fmt.Sprintf(`{"query":{"term":{"list.infoid":"%s"}},"_source": ["list"]}`, v["_id"]))
+//				if len(*r) > 0 {
+//					MsgList := (*r)[0]["list"]
+//					if MsgList != nil {
+//						list := util.ObjArrToMapArr(MsgList.([]interface{}))
+//						for _, vv := range list {
+//							if vv["subtype"] == "招标" {
+//								if v["agency"] == nil && vv["agency"] != nil {
+//									v["agency"] = vv["agency"]
+//								}
+//								if v["budget"] == nil && vv["budget"] != nil {
+//									v["budget"] = vv["budget"]
+//								}
+//								if v["buyerperson"] == nil && vv["buyerperson"] != nil {
+//									v["buyerperson"] = vv["buyerperson"]
+//								}
+//								if v["buyertel"] == nil && vv["buyertel"] != nil {
+//									v["buyertel"] = vv["buyertel"]
+//								}
+//								break
+//							}
+//						}
+//					}
+//				}
+//			}
+//			if v["area"] == "A" {
+//				v["area"] = "全国"
+//			}
+//			// if v["bidamount"] != nil {
+//			// 	v["bidamount"] = fmt.Sprintf("%g", util.Float64All(v["bidamount"]))
+//			// }
+//			// if v["budget"] != nil {
+//			// 	v["budget"] = fmt.Sprintf("%g", util.Float64All(v["budget"]))
+//			// }
+//			if v["publishtime"] != nil {
+//				date := v["publishtime"]
+//				v["publishtime"] = util.FormatDateWithObj(&date, util.Date_Short_Layout)
+//			}
+//			if v["bidopentime"] != nil {
+//				date := v["bidopentime"]
+//				v["bidopentime"] = util.FormatDateWithObj(&date, util.Date_Short_Layout)
+//			}
+//			if v["currency"] == "" || v["currency"] == nil {
+//				v["currency"] = "人民币"
+//			}
+//			if v["subtype"] == nil && v["toptype"] != nil {
+//				v["subtype"] = v["toptype"]
+//			}
+//			if v["detail"] != "" && v["detail"] != nil {
+//				str := ClearHtml.ReplaceAllString(v["detail"].(string), "")
+//				str = ClearOther.ReplaceAllString(str, "")
+//				str = strings.Replace(str, " ", "", -1)
+//				v["detail"] = str
+//			}
+//			if v["_id"] != nil {
+//				v["url"] = webdomain + "/article/content/" + util.CommonEncodeArticle("content", v["_id"].(string)) + ".html"
+//			}
+//		}(v)
+//	}
+//	entexportWaitGroup.Wait()
+//	log.Println("补充信息结束")
+//	return data
+//}
+//
+//func doSearch(sql string, start, count int, dataType string) *[]map[string]interface{} {
+//	if sql != "" {
+//		//筛选字段
+//		if dataType != "" {
+//			dataexport_field := `"_id","title","detail","area","city","publishtime","projectname","buyer","s_winner","bidamount","subtype","toptype"`
+//			if dataType == "2" {
+//				dataexport_field += `,"href","projectcode","buyerperson","buyertel","budget","bidopentime","agency","projectscope","winnerperson","winnertel"`
+//			}
+//			sql = sql[:len(sql)-1] + `,"_source":[` + dataexport_field + "]}"
+//		}
+//		//分页排序
+//		sql = sql[:len(sql)-1] + `,"sort": {"publishtime":"desc"},"from":` + strconv.Itoa(start) + `,"size":` + strconv.Itoa(count) + "}"
+//	}
+//	return elastic.Get(INDEX, TYPE, sql)
+//}
+//
+//func getKeyWordArrFromDbResult(k interface{}) (arr []KeyWord) {
+//	if k == nil {
+//		return
+//	}
+//	kArr := k.([]interface{})
+//	for _, v := range kArr {
+//		kw := KeyWord{}
+//		b, e := json.Marshal(v)
+//		if e != nil {
+//			log.Println(e.Error())
+//		}
+//		json.Unmarshal(b, &kw)
+//		arr = append(arr, kw)
+//	}
+//	return
+//}
+//
+//func getStringArrFromDbResult(c interface{}) (arr []string) {
+//	if c != nil {
+//		cArr := c.([]interface{})
+//		arr = util.ObjArrToStringArr(cArr)
+//	}
+//	return
+//}
+//
+////获取结果,空字段最少的数据
+//func ScreenData(arr *[]map[string]interface{}, dataType string, resultNum int, kws []KeyWord) (res []map[string]interface{}) {
+//	AllMap := map[int][]map[string]interface{}{}
+//
+//	NoKwsMap := map[int][]map[string]interface{}{}
+//	lastNum := resultNum
+//	for _, v := range *arr {
+//		emptyNum := countOfTheEmpty(v, dataType)
+//		if emptyNum == -1 {
+//			continue
+//		}
+//		if len(kws) > 0 && kws[0].Keyword != "" {
+//			var kwsFlag = true
+//			for _, vk := range kws {
+//				if strings.Contains(util.ObjToString(v["title"]), strings.Replace(vk.Keyword, "+", "", -1)) {
+//					kwsFlag = false
+//					continue
+//				}
+//			}
+//			if kwsFlag {
+//				if NoKwsMap[emptyNum] == nil {
+//					NoKwsMap[emptyNum] = []map[string]interface{}{v}
+//				} else {
+//					NoKwsMap[emptyNum] = append(NoKwsMap[emptyNum], v)
+//				}
+//				continue
+//			}
+//		}
+//		if AllMap[emptyNum] == nil {
+//			AllMap[emptyNum] = []map[string]interface{}{v}
+//			continue
+//		}
+//		AllMap[emptyNum] = append(AllMap[emptyNum], v)
+//	}
+//	//获取key
+//	keys := []int{}
+//	for k, _ := range AllMap {
+//		keys = append(keys, k)
+//	}
+//	sort.Ints(keys)
+//	log.Println("空字段数量", keys)
+//	//选取结果
+//	for _, v := range keys {
+//		if len(AllMap[v]) >= resultNum {
+//			return append(res, AllMap[v][:resultNum]...)
+//		} else {
+//			resultNum = resultNum - len(AllMap[v])
+//			tmp := append(res, AllMap[v][:len(AllMap[v])]...)
+//			res = tmp
+//		}
+//	}
+//	if len(res) < lastNum {
+//		resultNum = lastNum - len(res)
+//		//获取key
+//		Nokeys := []int{}
+//		for k, _ := range NoKwsMap {
+//			Nokeys = append(Nokeys, k)
+//		}
+//		sort.Ints(Nokeys)
+//		log.Println("没关键词的空字段数量", Nokeys)
+//		//选取结果
+//		for _, v := range Nokeys {
+//			if len(NoKwsMap[v]) >= resultNum {
+//				return append(res, NoKwsMap[v][:resultNum]...)
+//			} else {
+//				resultNum = resultNum - len(NoKwsMap[v])
+//				tmp := append(res, NoKwsMap[v][:len(NoKwsMap[v])]...)
+//				res = tmp
+//			}
+//		}
+//	}
+//	return res
+//}
+//func countOfTheEmpty(m map[string]interface{}, dataType string) int {
+//	MsgType := m["subtype"]
+//	//	if MsgType == "拟建" {
+//	//		return -1
+//	//	}
+//	//计算空字段数量
+//	var count int = 0
+//	//高级字段包
+//	if dataType == "2" {
+//		if m["href"] == "" || m["href"] == nil {
+//			count++
+//		}
+//		if m["projectcode"] == "" || m["projectcode"] == nil {
+//			count++
+//		}
+//		if m["buyerperson"] == "" || m["buyerperson"] == nil {
+//			count++
+//		}
+//		if m["buyertel"] == "" || m["buyertel"] == nil {
+//			count++
+//		}
+//		if m["budget"] == "" || m["budget"] == nil {
+//			count++
+//		}
+//		if m["bidopentime"] == "" || m["bidopentime"] == nil {
+//			count++
+//		}
+//		if m["agency"] == "" || m["agency"] == nil {
+//			count++
+//		}
+//		if m["projectscope"] == "" || m["projectscope"] == nil {
+//			count++
+//		}
+//	}
+//	if m["city"] == "" || m["city"] == nil {
+//		count++
+//	}
+//	if m["publishtime"] == "" || m["publishtime"] == nil {
+//		count++
+//	}
+//	if m["projectname"] == "" || m["projectname"] == nil {
+//		count++
+//	}
+//	if m["buyer"] == "" || m["buyer"] == nil {
+//		count++
+//	}
+//	if m["s_winner"] == "" || m["s_winner"] == nil {
+//		if MsgType != "招标" {
+//			count++
+//		}
+//	}
+//	if m["bidamount"] == "" || m["bidamount"] == nil {
+//		if MsgType != "招标" {
+//			count++
+//		}
+//	}
+//	if m["subtype"] == "" || m["subtype"] == nil {
+//		count++
+//	}
+//	return count
+//}
+//
+//func GetEntDataExportCount(_id string, entId, entUserId, limitNum, current int, isFirst bool) (count, newCount int, data *[]map[string]interface{}) {
+//	defer util.Catch()
+//	var (
+//		searchsWaitGroup = &sync.WaitGroup{}
+//		searchsPool      = make(chan bool, 20)
+//		// res              = &[]map[string]interface{}{}
+//		newCountPool = make(chan bool, 20000)
+//	)
+//	count = GetDataExportSearchCountUseId(_id)
+//	log.Println("count", count)
+//	if count > ExConf.MsgMaxCount {
+//		count = ExConf.MsgMaxCount
+//	}
+//	dataType := "2"
+//	//数据导出数据查询
+//
+//	res, err := GetDataExportSearchResult(_id, dataType, count)
+//	if err != nil {
+//		log.Println("企业数据导出错误 ", err)
+//		return 0, 0, nil
+//	}
+//	// secondCount := 0
+//
+//	// isOK := true
+//	// if secondCount > current {
+//	// 	isOK = false
+//	// }
+//	for _, v := range *res {
+//		searchsWaitGroup.Add(1)
+//		searchsPool <- true
+//		id := util.ObjToString(v["_id"])
+//		go func(id string) {
+//			defer func() {
+//				searchsWaitGroup.Done()
+//				<-searchsPool
+//			}()
+//			isExist, err := redis.Exists("other", "entexportdata_"+id+"_"+fmt.Sprintln(entId))
+//			if err != nil {
+//				log.Println("企业搜索数据导出redis判重失败")
+//			} else if isExist {
+//				log.Println("数据重复,id ", id, "entid ", entId, "userid ", entUserId)
+//				return
+//			}
+//			newCountPool <- true
+//			if !isFirst {
+//				redis.Put("other", "entexportdata_"+id+"_"+fmt.Sprintln(entId), 1, -1)
+//			}
+//		}(id)
+//		if !isFirst {
+//			delete(v, "_id")
+//			v["entid"] = entId
+//			v["userid"] = entUserId
+//			v["infoid"] = id
+//			v["createtime"] = time.Now().Unix()
+//		}
+//	}
+//	searchsWaitGroup.Wait()
+//	log.Println("企业数据导出--数据遍历完成")
+//	newCount = len(newCountPool)
+//	log.Println("new", newCount)
+//	data = res
+//	return
+//}
+//
+//func GetDataExportSearchResult(id string, dataType string, checkCount int) (*[]map[string]interface{}, error) {
+//	defer util.Catch()
+//	var (
+//		onceSearchCount = 500
+//		searchPool      = make(chan bool, 20)
+//		res             []map[string]interface{}
+//	)
+//	//获取查询语句
+//	scd := getSqlObjFromId(id)
+//	if scd == nil {
+//		return nil, errors.New("GetDataExportSearchResult-获取查询条件")
+//	}
+//	qstr := getDataExportSql(scd)
+//	log.Printf("GetDataExportSearchResult-%s-sql:%s\n", scd.Id, qstr)
+//	//数据导出数据查询
+//	if checkCount > onceSearchCount { //分批次查询
+//		batchNum := util.IntAll(math.Ceil(float64(checkCount) / float64(onceSearchCount)))
+//		var searchWaitGroup = &sync.WaitGroup{}
+//		var lock sync.Mutex
+//		for n := 0; n < batchNum; n++ {
+//			searchWaitGroup.Add(1)
+//			searchPool <- true
+//			go func(start int) {
+//				defer func() {
+//					searchWaitGroup.Done()
+//					<-searchPool
+//				}()
+//				checkNum, checkOk := onceSearchCount, false
+//				if start == (batchNum - 1) {
+//					if checkCount%onceSearchCount != 0 {
+//						checkNum = checkCount % onceSearchCount
+//					}
+//				}
+//
+//				var tmp *[]map[string]interface{}
+//				for i := 0; i < 3; i++ {
+//					tmp = doSearch(qstr, start*onceSearchCount, onceSearchCount, dataType)
+//					if tmp != nil && (len(*tmp) == checkNum) { //校验数据量是否够
+//						checkOk = true
+//						break
+//					}
+//				}
+//				if tmp == nil {
+//					log.Printf("GetDataExportSearchResult-%s-第%d页数据查询结果为空\n", scd.Id, start+1)
+//					return
+//				}
+//				if checkOk {
+//					log.Printf("GetDataExportSearchResult-%s-第%d页数据加载完成,共%d条\n", scd.Id, start+1, len(*tmp))
+//				} else {
+//					log.Printf("GetDataExportSearchResult-%s-第%d页数据加载异常,共%d条,预期%d条\n", scd.Id, start+1, len(*tmp), checkNum)
+//				}
+//				lock.Lock()
+//				res = append(res, *tmp...)
+//				lock.Unlock()
+//			}(n)
+//		}
+//		searchWaitGroup.Wait()
+//		log.Printf("GetDataExportSearchResult-%s-分批次加载数据总量为%d\n", scd.Id, len(res))
+//	} else {
+//		tmp := doSearch(qstr, 0, checkCount, dataType)
+//		if tmp == nil || len(*tmp) == 0 {
+//			log.Printf("GetDataExportSearchResult-%s-一次性加载数据异常\n", scd.Id)
+//		} else {
+//			res = *tmp
+//			log.Printf("GetDataExportSearchResult-%s-一次性加载数据总量为%d\n", scd.Id, len(res))
+//		}
+//	}
+//	//超级搜索一致的检索(防止数据导出和超级搜索数据量不一致)
+//	if scd.Comeinfrom == "supersearchPage" && (len(scd.Keyword) != 0 || len(scd.Industry) != 0) {
+//		if len(scd.Keyword) != 0 {
+//			num := len(res)
+//			searchTextSize := 0
+//			if len(scd.Keyword) > 0 {
+//				searchTextSize = len([]rune(scd.Keyword[0].Keyword))
+//			}
+//			if searchTextSize > 3 && num < 50 {
+//				secondKWS := jy.HttpEs(scd.Keyword[0].Keyword, "ik_smart", DbConf.Elasticsearch.Main.Address)
+//				scd.Keyword[0].Keyword = secondKWS
+//				scd.SelectType = "title"
+//				qstr = getDataExportSql(scd)
+//				log.Printf("GetDataExportSearchResult-%s-分词查询-sql:%s\n", scd.Id, qstr)
+//				res2 := doSearch(qstr, 0, 100, "")
+//				res = *delRepeatMapArr(&res, res2)
+//				if len(res) > 100 {
+//					res = res[:100]
+//				}
+//			}
+//		}
+//	}
+//	//校验数量
+//	if checkCount != len(res) {
+//		return nil, fmt.Errorf("GetDataExportSearchResult-%s-数据总量校验异常,期望:%d,实际:%d", scd.Id, checkCount, len(res))
+//		//发邮件
+//	}
+//	return &res, nil
+//}