Browse Source

wip:数据导出白名单

wangshan 1 year ago
parent
commit
d7cab2cb19

+ 15 - 3
common/src/qfw/util/dataexport/common.go

@@ -3,10 +3,16 @@ package dataexport
 import (
 	qutil "app.yhyue.com/moapp/jybase/common"
 	"app.yhyue.com/moapp/jybase/mysql"
+	"app.yhyue.com/moapp/jybase/redis"
 	"fmt"
 	"strings"
 )
 
+const (
+	RedisPoly         = "poly"     // 查白名单用户用的redis
+	WhitelistRedisKey = "white_%s" // 白名单用户用的redis key
+)
+
 // GetLastExportPhoneAndMail 数据导出联想上次导出手机号和邮箱查询
 func GetLastExportPhoneAndMail(mysqlSess *mysql.Mysql, userId, entUserId string) (phone, email string) {
 	var searchSql []string
@@ -145,7 +151,13 @@ func KeyWordToDatas(item, key string, keyWord []string) []string {
 	return keyWord
 }
 
-// 获取关键词匹配字段
-func getKeywordFields() {
-
+// IsOnTheWhitelist 是否在白名单
+func IsOnTheWhitelist(userId, mgoUserId string) bool {
+	// 	mongoid 在白名单中没有查到 再去查职位id有没有在白名单里面
+	flag, err := redis.Exists(RedisPoly, fmt.Sprintf(WhitelistRedisKey, mgoUserId))
+	if err == nil && flag {
+		return flag
+	}
+	flag, err = redis.Exists(RedisPoly, fmt.Sprintf(WhitelistRedisKey, userId))
+	return flag
 }

+ 13 - 9
common/src/qfw/util/dataexport/dataexport.go

@@ -80,7 +80,9 @@ type SieveCondition struct {
 	SearchGroup      int       `json:"searchGroup"`      // 搜索分组:默认0:全部;1:招标采购公告;2:超前项目
 	SearchMode       int       `json:"searchMode"`       // 搜索模式:0:精准搜索;1:模糊搜索
 	WordsMode        int       `json:"wordsMode"`        // 搜索关键词模式;默认0:包含所有,1:包含任意
-	District         []string  `json:"district"`
+	District         []string  `json:"district"`         //
+	UserId           string    `json:"s_userid"`         //用户id 或 职位id
+	MgoUserId        string    `json:"mgoUserId"`        //mgoUserId
 }
 
 const (
@@ -557,11 +559,13 @@ func GetSqlObjFromId(mongo mg.MongodbSim, _id string) *SieveCondition {
 		PushKeyWords:     getStringArrFromDbResult((*query)["pushKeyWords"]),
 		FileExists:       qutil.ObjToString((*query)["fileExists"]),
 		SearchTypeSwitch: searchTypeSwitch,
-		BidField:         qutil.ObjToString((*query)["bid_field"]), // 领域化数据
-		SearchGroup:      qutil.IntAll((*query)["searchGroup"]),    //搜索分组:默认0:全部;1:招标采购公告;2:超前项目
-		SearchMode:       qutil.IntAll((*query)["searchMode"]),     // 搜索模式:0:精准搜索;1:模糊搜索
-		WordsMode:        qutil.IntAll((*query)["wordsMode"]),      // 搜索关键词模式;默认0:包含所有,1:包含任意
-		District:         gconv.Strings((*query)["district"]),
+		BidField:         qutil.ObjToString((*query)["bid_field"]),    // 领域化数据
+		SearchGroup:      qutil.IntAll((*query)["searchGroup"]),       //搜索分组:默认0:全部;1:招标采购公告;2:超前项目
+		SearchMode:       qutil.IntAll((*query)["searchMode"]),        // 搜索模式:0:精准搜索;1:模糊搜索
+		WordsMode:        qutil.IntAll((*query)["wordsMode"]),         // 搜索关键词模式;默认0:包含所有,1:包含任意
+		District:         gconv.Strings((*query)["district"]),         //
+		UserId:           qutil.InterfaceToStr((*query)["s_userid"]),  //
+		MgoUserId:        qutil.InterfaceToStr((*query)["mgoUserId"]), //
 	}
 }
 
@@ -587,7 +591,7 @@ func GetDataExportSearchCountBySieveCondition(scd *SieveCondition, elasticAddres
 	}
 	// 依据用户选择的搜索模式和搜索范围进行匹配,即不限制只能匹配标题,且不限制最多展示100条、针对输入的单个关键词分词后需要都包含
 	//超级搜索一致的检索(防止数据导出和超级搜索数据量不一致)
-	if scd.Comeinfrom == "supersearchPage" && (len(scd.Keyword) != 0 || len(scd.Industry) != 0) && scd.SearchMode == SearchModeFuzzy {
+	if scd.Comeinfrom == "supersearchPage" && (len(scd.Keyword) != 0 || len(scd.Industry) != 0 || IsOnTheWhitelist(scd.UserId, scd.MgoUserId)) && scd.SearchMode == SearchModeFuzzy {
 		if len(scd.Keyword) != 0 {
 			// 关键词分词
 			searchTextSize := 0
@@ -894,7 +898,7 @@ func GetDataExportIds(elasticAddress string, scd *SieveCondition, checkCount int
 	}
 	//超级搜索一致的检索(防止数据导出和超级搜索数据量不一致)
 	// 依据用户选择的搜索模式和搜索范围进行匹配,即不限制只能匹配标题,且不限制最多展示100条、针对输入的单个关键词分词后需要都包含
-	if scd.Comeinfrom == "supersearchPage" && (len(scd.Keyword) != 0 || len(scd.Industry) != 0) && len(scd.SelectIds) == 0 && scd.SearchMode == SearchModeFuzzy {
+	if scd.Comeinfrom == "supersearchPage" && (len(scd.Keyword) != 0 || len(scd.Industry) != 0 || IsOnTheWhitelist(scd.UserId, scd.MgoUserId)) && len(scd.SelectIds) == 0 && scd.SearchMode == SearchModeFuzzy {
 		if len(scd.Keyword) != 0 {
 			searchTextSize := 0
 			// 关键词分词
@@ -964,7 +968,7 @@ func GetDataExportSearchResult(bid mg.MongodbSim, bidMgoDBName, elasticAddress s
 		res = doSearchByBatch(qstr, dataType, checkCount, fmt.Sprintf("%s-%s", "GetDataExportSearchResult", scd.Id))
 	}
 	//超级搜索一致的检索(防止数据导出和超级搜索数据量不一致)
-	if scd.Comeinfrom == "supersearchPage" && (len(scd.Keyword) != 0 || len(scd.Industry) != 0) && len(scd.SelectIds) == 0 && scd.SearchMode == SearchModeFuzzy {
+	if scd.Comeinfrom == "supersearchPage" && (len(scd.Keyword) != 0 || len(scd.Industry) != 0 || IsOnTheWhitelist(scd.UserId, scd.MgoUserId)) && len(scd.SelectIds) == 0 && scd.SearchMode == SearchModeFuzzy {
 		if len(scd.Keyword) != 0 {
 			searchTextSize := 0
 			// 关键词分词