zqbao 5 сар өмнө
parent
commit
709fe6a3b9

+ 200 - 0
controllers/data_manage/stl/stl.go

@@ -4,9 +4,17 @@ import (
 	"encoding/json"
 	"eta/eta_api/controllers"
 	"eta/eta_api/models"
+	"eta/eta_api/services/data/data_manage_permission"
 	"eta/eta_api/services/data/stl"
+	"eta/eta_api/services/elastic"
+	"eta/eta_api/utils"
+	"strings"
+	"time"
 
+	"eta/eta_api/models/data_manage"
 	"eta/eta_api/models/data_manage/stl/request"
+
+	"github.com/rdlucklib/rdluck_tools/paging"
 )
 
 type STLController struct {
@@ -54,3 +62,195 @@ func (c *STLController) Preview() {
 	br.Success = true
 	return
 }
+
+// EdbInfoFilterByEs
+// @Title 指标筛选接口
+// @Description 指标筛选接口
+// @Param   KeyWord   query   string  false       "搜索关键词:指标ID/指标名称"
+// @Param   FilterSource   query   int  false       "搜索来源:1:其他搜索,2:累计值转月值搜索,3:变频,4:基础指标,5:同比"
+// @Param   Frequency   query   string  false       "频度"
+// @Param   IsAddPredictEdb   query   bool  false       "是否查询添加预测指标"
+// @Param   PageSize   query   int  true       "每页数据条数"
+// @Param   CurrentIndex   query   int  true       "当前页页码,从1开始"
+// @Success 200 {object} data_manage.EdbInfoList
+// @router /edb_info/search [get]
+func (this *STLController) EdbInfoFilterByEs() {
+	br := new(models.BaseResponse).Init()
+	defer func() {
+		this.Data["json"] = br
+		this.ServeJSON()
+	}()
+
+	pageSize, _ := this.GetInt("PageSize")
+	currentIndex, _ := this.GetInt("CurrentIndex")
+
+	var total int64
+
+	var startSize int
+	if pageSize <= 0 {
+		pageSize = utils.PageSize20
+	}
+	if currentIndex <= 0 {
+		currentIndex = 1
+	}
+	startSize = paging.StartIndex(currentIndex, pageSize)
+
+	keyWord := this.GetString("KeyWord")
+	keyWord = strings.TrimSpace(keyWord) //移除字符串首尾空格
+
+	frequency := this.GetString("Frequency") //频度
+
+	var edbInfoList []*data_manage.EdbInfoList
+	var err error
+
+	noPermissionEdbInfoIdList := make([]int, 0) //无权限指标
+	// 获取当前账号的不可见指标
+	{
+		obj := data_manage.EdbInfoNoPermissionAdmin{}
+		confList, err := obj.GetAllListByAdminId(this.SysUser.AdminId)
+		if err != nil && err.Error() != utils.ErrNoRow() {
+			br.Msg = "获取失败"
+			br.ErrMsg = "获取不可见指标配置数据失败,Err:" + err.Error()
+			return
+		}
+		for _, v := range confList {
+			noPermissionEdbInfoIdList = append(noPermissionEdbInfoIdList, v.EdbInfoId)
+		}
+	}
+
+	// 是否走ES
+	isEs := false
+	if keyWord != "" {
+		var keyWordArr []string
+		keyWordArr = append(keyWordArr, keyWord)
+
+		newKeyWord := strings.Split(keyWord, " ")
+		keyWordArr = append(keyWordArr, newKeyWord...)
+
+		// 普通的搜索
+		total, edbInfoList, err = elastic.SearchEdbInfoData(utils.DATA_INDEX_NAME, keyWord, startSize, pageSize, filterSource, source, 0, frequency, noPermissionEdbInfoIdList)
+		isEs = true
+	} else {
+		var condition string
+		var pars []interface{}
+		// 普通指标
+		condition += ` AND edb_info_type = ? `
+		pars = append(pars, 0)
+
+		// 无权限指标id
+		lenNoPermissionEdbInfoIdList := len(noPermissionEdbInfoIdList)
+		if lenNoPermissionEdbInfoIdList > 0 {
+			condition += ` AND edb_info_id  not in (` + utils.GetOrmInReplace(lenNoPermissionEdbInfoIdList) + `) `
+			pars = append(pars, noPermissionEdbInfoIdList)
+		}
+
+		//频度
+		if frequency != "" {
+			condition += ` AND frequency = ? `
+			pars = append(pars, frequency)
+		}
+
+		total, edbInfoList, err = data_manage.GetEdbInfoFilterList(condition, pars, startSize, pageSize)
+	}
+	if err != nil {
+		edbInfoList = make([]*data_manage.EdbInfoList, 0)
+	}
+
+	page := paging.GetPaging(currentIndex, pageSize, int(total))
+
+	edbInfoListLen := len(edbInfoList)
+
+	classifyIdList := make([]int, 0)
+	for i := 0; i < edbInfoListLen; i++ {
+		edbInfoList[i].EdbNameAlias = edbInfoList[i].EdbName
+		classifyIdList = append(classifyIdList, edbInfoList[i].ClassifyId)
+	}
+
+	// 当前列表中的分类map
+	classifyMap := make(map[int]*data_manage.EdbClassify)
+	if edbInfoListLen > 0 {
+		classifyList, err := data_manage.GetEdbClassifyByIdList(classifyIdList)
+		if err != nil {
+			br.Msg = "获取失败"
+			br.ErrMsg = "获取分类列表失败,Err:" + err.Error()
+			return
+		}
+
+		for _, v := range classifyList {
+			classifyMap[v.ClassifyId] = v
+		}
+
+		// 获取所有有权限的指标和分类
+		permissionEdbIdList, permissionClassifyIdList, err := data_manage_permission.GetUserEdbAndClassifyPermissionList(this.SysUser.AdminId, 0, 0)
+		if err != nil {
+			br.Msg = "获取失败"
+			br.ErrMsg = "获取所有有权限的指标和分类失败,Err:" + err.Error()
+			return
+		}
+
+		// 如果是ES的话,需要重新查一下指标的信息,主要是为了把是否授权字段找出来
+		if isEs {
+			edbInfoIdList := make([]int, 0)
+			for i := 0; i < edbInfoListLen; i++ {
+				edbInfoIdList = append(edbInfoIdList, edbInfoList[i].EdbInfoId)
+				tmpEdbInfo := edbInfoList[i]
+				if currClassify, ok := classifyMap[tmpEdbInfo.ClassifyId]; ok {
+					edbInfoList[i].HaveOperaAuth = data_manage_permission.CheckEdbPermissionByPermissionIdList(tmpEdbInfo.IsJoinPermission, currClassify.IsJoinPermission, tmpEdbInfo.EdbInfoId, tmpEdbInfo.ClassifyId, permissionEdbIdList, permissionClassifyIdList)
+				}
+			}
+
+			tmpEdbList, err := data_manage.GetEdbInfoByIdList(edbInfoIdList)
+			if err != nil {
+				br.Msg = "获取失败"
+				br.ErrMsg = "获取所有有权限的指标失败,Err:" + err.Error()
+				return
+			}
+			edbInfoMap := make(map[int]*data_manage.EdbInfo)
+			for _, v := range tmpEdbList {
+				edbInfoMap[v.EdbInfoId] = v
+			}
+
+			for i := 0; i < edbInfoListLen; i++ {
+				tmpEdbInfo, ok := edbInfoMap[edbInfoList[i].EdbInfoId]
+				if !ok {
+					continue
+				}
+				edbInfoList[i].IsJoinPermission = tmpEdbInfo.IsJoinPermission
+			}
+		}
+
+		// 权限校验
+		for i := 0; i < edbInfoListLen; i++ {
+			tmpEdbInfoItem := edbInfoList[i]
+			if currClassify, ok := classifyMap[tmpEdbInfoItem.ClassifyId]; ok {
+				edbInfoList[i].HaveOperaAuth = data_manage_permission.CheckEdbPermissionByPermissionIdList(tmpEdbInfoItem.IsJoinPermission, currClassify.IsJoinPermission, tmpEdbInfoItem.EdbInfoId, tmpEdbInfoItem.ClassifyId, permissionEdbIdList, permissionClassifyIdList)
+			}
+		}
+	}
+
+	for i := 0; i < edbInfoListLen; i++ {
+		for j := 0; j < edbInfoListLen; j++ {
+			if (edbInfoList[i].EdbNameAlias == edbInfoList[j].EdbNameAlias) &&
+				(edbInfoList[i].EdbInfoId != edbInfoList[j].EdbInfoId) &&
+				!(strings.Contains(edbInfoList[i].EdbName, edbInfoList[i].SourceName)) {
+				edbInfoList[i].EdbName = edbInfoList[i].EdbName + "(" + edbInfoList[i].SourceName + ")"
+			}
+		}
+	}
+	//新增搜索词记录
+	{
+		searchKeyword := new(data_manage.SearchKeyword)
+		searchKeyword.KeyWord = keyWord
+		searchKeyword.CreateTime = time.Now()
+		go data_manage.AddSearchKeyword(searchKeyword)
+	}
+
+	resp := data_manage.EdbInfoFilterDataResp{
+		Paging: page,
+		List:   edbInfoList,
+	}
+	br.Ret = 200
+	br.Success = true
+	br.Msg = "获取成功"
+	br.Data = resp
+}

+ 3 - 0
models/data_manage/stl/request/stl.go

@@ -15,3 +15,6 @@ type STLReq struct {
 	SeasonalDeg   int     `description:"分解中季节性多项次数,默认为1,不超过5的正整数"`
 	LowPassDeg    int     `description:"分解中低通滤波器次数,默认为1,不超过5的正整数"`
 }
+
+type EdbInfoSearch struct {
+}

+ 394 - 0
services/data/stl/stl.go

@@ -5,6 +5,7 @@ import (
 	"eta/eta_api/models/data_manage"
 	"eta/eta_api/models/data_manage/stl/request"
 	"eta/eta_api/models/data_manage/stl/response"
+	"eta/eta_api/services/data/data_manage_permission"
 	"eta/eta_api/utils"
 	"fmt"
 	"os"
@@ -14,6 +15,8 @@ import (
 	"strings"
 	"time"
 
+	"github.com/olivere/elastic"
+	"github.com/rdlucklib/rdluck_tools/paging"
 	"github.com/tealeg/xlsx"
 )
 
@@ -158,6 +161,17 @@ func GenerateStlEdbData(req *request.STLReq, adminId int) (resp *response.StlPre
 	return
 }
 
+func EdbInfoSearch(req *request.EdbInfoSearchReq) (resp *response.EdbInfoSearchResp, msg string, err error) {
+	edbInfoList, err := data_manage.GetEdbInfoListByCondition(req.Keyword, req.Source, req.SubSource)
+	if err != nil {
+		msg = "获取指标列表失败"
+		return
+	}
+	resp = new(response.EdbInfoSearchResp)
+	resp.EdbInfoList = edbInfoList
+	return
+}
+
 func formatEdbData(items []*data_manage.EdbData) []*response.EdbData {
 	res := make([]*response.EdbData, 0, len(items))
 	for _, item := range items {
@@ -350,3 +364,383 @@ print(output)
 	}
 	return
 }
+
+func SearchEdbInfoWithStl(adminId int, keyWord string) (msg string, err error) {
+
+	var edbInfoList []*data_manage.EdbInfoList
+
+	noPermissionEdbInfoIdList := make([]int, 0) //无权限指标
+	// 获取当前账号的不可见指标
+	{
+		obj := data_manage.EdbInfoNoPermissionAdmin{}
+		confList, er := obj.GetAllListByAdminId(adminId)
+		if er != nil && err.Error() != utils.ErrNoRow() {
+			msg = "获取失败"
+			err = fmt.Errorf("获取不可见指标配置数据失败,Err:" + er.Error())
+			return
+		}
+		for _, v := range confList {
+			noPermissionEdbInfoIdList = append(noPermissionEdbInfoIdList, v.EdbInfoId)
+		}
+	}
+
+	// 是否走ES
+	isEs := false
+	if keyWord != "" {
+		var keyWordArr []string
+		keyWordArr = append(keyWordArr, keyWord)
+
+		newKeyWord := strings.Split(keyWord, " ")
+		keyWordArr = append(keyWordArr, newKeyWord...)
+
+		// 普通的搜索
+		total, edbInfoList, err = elastic.SearchEdbInfoData(utils.DATA_INDEX_NAME, keyWord, startSize, pageSize, filterSource, source, 0, frequency, noPermissionEdbInfoIdList)
+		isEs = true
+	} else {
+		var condition string
+		var pars []interface{}
+		// 普通指标
+		condition += ` AND edb_info_type = ? `
+		pars = append(pars, 0)
+
+		// 无权限指标id
+		lenNoPermissionEdbInfoIdList := len(noPermissionEdbInfoIdList)
+		if lenNoPermissionEdbInfoIdList > 0 {
+			condition += ` AND edb_info_id  not in (` + utils.GetOrmInReplace(lenNoPermissionEdbInfoIdList) + `) `
+			pars = append(pars, noPermissionEdbInfoIdList)
+		}
+
+		//频度
+		if frequency != "" {
+			condition += ` AND frequency = ? `
+			pars = append(pars, frequency)
+		}
+
+		total, edbInfoList, err = data_manage.GetEdbInfoFilterList(condition, pars, startSize, pageSize)
+	}
+	if err != nil {
+		edbInfoList = make([]*data_manage.EdbInfoList, 0)
+	}
+
+	page := paging.GetPaging(currentIndex, pageSize, int(total))
+
+	edbInfoListLen := len(edbInfoList)
+
+	classifyIdList := make([]int, 0)
+	for i := 0; i < edbInfoListLen; i++ {
+		edbInfoList[i].EdbNameAlias = edbInfoList[i].EdbName
+		classifyIdList = append(classifyIdList, edbInfoList[i].ClassifyId)
+	}
+
+	// 当前列表中的分类map
+	classifyMap := make(map[int]*data_manage.EdbClassify)
+	if edbInfoListLen > 0 {
+		classifyList, err := data_manage.GetEdbClassifyByIdList(classifyIdList)
+		if err != nil {
+			br.Msg = "获取失败"
+			br.ErrMsg = "获取分类列表失败,Err:" + err.Error()
+			return
+		}
+
+		for _, v := range classifyList {
+			classifyMap[v.ClassifyId] = v
+		}
+
+		// 获取所有有权限的指标和分类
+		permissionEdbIdList, permissionClassifyIdList, err := data_manage_permission.GetUserEdbAndClassifyPermissionList(this.SysUser.AdminId, 0, 0)
+		if err != nil {
+			br.Msg = "获取失败"
+			br.ErrMsg = "获取所有有权限的指标和分类失败,Err:" + err.Error()
+			return
+		}
+
+		// 如果是ES的话,需要重新查一下指标的信息,主要是为了把是否授权字段找出来
+		if isEs {
+			edbInfoIdList := make([]int, 0)
+			for i := 0; i < edbInfoListLen; i++ {
+				edbInfoIdList = append(edbInfoIdList, edbInfoList[i].EdbInfoId)
+				tmpEdbInfo := edbInfoList[i]
+				if currClassify, ok := classifyMap[tmpEdbInfo.ClassifyId]; ok {
+					edbInfoList[i].HaveOperaAuth = data_manage_permission.CheckEdbPermissionByPermissionIdList(tmpEdbInfo.IsJoinPermission, currClassify.IsJoinPermission, tmpEdbInfo.EdbInfoId, tmpEdbInfo.ClassifyId, permissionEdbIdList, permissionClassifyIdList)
+				}
+			}
+
+			tmpEdbList, err := data_manage.GetEdbInfoByIdList(edbInfoIdList)
+			if err != nil {
+				br.Msg = "获取失败"
+				br.ErrMsg = "获取所有有权限的指标失败,Err:" + err.Error()
+				return
+			}
+			edbInfoMap := make(map[int]*data_manage.EdbInfo)
+			for _, v := range tmpEdbList {
+				edbInfoMap[v.EdbInfoId] = v
+			}
+
+			for i := 0; i < edbInfoListLen; i++ {
+				tmpEdbInfo, ok := edbInfoMap[edbInfoList[i].EdbInfoId]
+				if !ok {
+					continue
+				}
+				edbInfoList[i].IsJoinPermission = tmpEdbInfo.IsJoinPermission
+			}
+		}
+
+		// 权限校验
+		for i := 0; i < edbInfoListLen; i++ {
+			tmpEdbInfoItem := edbInfoList[i]
+			if currClassify, ok := classifyMap[tmpEdbInfoItem.ClassifyId]; ok {
+				edbInfoList[i].HaveOperaAuth = data_manage_permission.CheckEdbPermissionByPermissionIdList(tmpEdbInfoItem.IsJoinPermission, currClassify.IsJoinPermission, tmpEdbInfoItem.EdbInfoId, tmpEdbInfoItem.ClassifyId, permissionEdbIdList, permissionClassifyIdList)
+			}
+		}
+	}
+
+	for i := 0; i < edbInfoListLen; i++ {
+		for j := 0; j < edbInfoListLen; j++ {
+			if (edbInfoList[i].EdbNameAlias == edbInfoList[j].EdbNameAlias) &&
+				(edbInfoList[i].EdbInfoId != edbInfoList[j].EdbInfoId) &&
+				!(strings.Contains(edbInfoList[i].EdbName, edbInfoList[i].SourceName)) {
+				edbInfoList[i].EdbName = edbInfoList[i].EdbName + "(" + edbInfoList[i].SourceName + ")"
+			}
+		}
+	}
+	//新增搜索词记录
+	{
+		searchKeyword := new(data_manage.SearchKeyword)
+		searchKeyword.KeyWord = keyWord
+		searchKeyword.CreateTime = time.Now()
+		go data_manage.AddSearchKeyword(searchKeyword)
+	}
+}
+
+// SearchEdbInfoData 查询es中的指标数据
+func SearchEdbInfoData(indexName, keywordStr string, from, size, filterSource, source int, edbInfoType int8, frequency string, noPermissionEdbInfoIdList []int) (total int64, list []*data_manage.EdbInfoList, err error) {
+	list = make([]*data_manage.EdbInfoList, 0)
+	defer func() {
+		if err != nil {
+			fmt.Println("EsAddOrEditData Err:", err.Error())
+		}
+	}()
+
+	highlight := elastic.NewHighlight()
+	highlight = highlight.Fields(elastic.NewHighlighterField("EdbCode"), elastic.NewHighlighterField("EdbName"))
+	highlight = highlight.PreTags("<font color='red'>").PostTags("</font>")
+
+	//var source map[string]interface{}
+	//source := map[string]interface{}{
+	//	"query": map[string]interface{}{
+	//		"match_all": map[string]interface{}{},
+	//	},
+	//}
+	mustMap := make([]interface{}, 0)
+	mustNotMap := make([]interface{}, 0)
+
+	//source := map[string]interface{}{
+	//	"query": map[string]interface{}{
+	//		"bool": map[string]interface{}{
+	//			"must": map[string]interface{}{
+	//				"query_string": map[string]interface{}{
+	//					"query":  keywordStr,
+	//					"fields": []string{"EdbCode", "EdbName"},
+	//				},
+	//			},
+	//		},
+	//	},
+	//}
+
+	switch filterSource {
+	case 2:
+		//source = map[string]interface{}{
+		//	"query": map[string]interface{}{
+		//		"bool": map[string]interface{}{
+		//			"must": map[string]interface{}{
+		//				"query_string": map[string]interface{}{
+		//					"query": keywordStr,
+		//				},
+		//			},
+		//			"filter": []interface{}{
+		//				map[string]interface{}{
+		//					"term": map[string]interface{}{
+		//						"Frequency.keyword": "月度",
+		//					},
+		//				}},
+		//		},
+		//	},
+		//}
+		mustMap = []interface{}{
+			map[string]interface{}{
+				"term": map[string]interface{}{
+					"Frequency.keyword": "月度",
+					//"Frequency.keyword": "月度",
+				},
+			},
+		}
+	case 3:
+		//source = map[string]interface{}{
+		//	"query": map[string]interface{}{
+		//		"bool": map[string]interface{}{
+		//			"must": map[string]interface{}{
+		//				"query_string": map[string]interface{}{
+		//					"query": keywordStr,
+		//				},
+		//			},
+		//			"must_not": []interface{}{
+		//				map[string]interface{}{
+		//					"match": map[string]interface{}{
+		//						"Frequency.keyword": "日度",
+		//					},
+		//				}},
+		//		},
+		//	},
+		//}
+
+		////注释掉,所有频度都可以变频 2022-08-31 14:31:28
+		//mustNotMap = []interface{}{
+		//	map[string]interface{}{
+		//		"match": map[string]interface{}{
+		//			"Frequency.keyword": "日度",
+		//			//"Frequency.keyword": "月度",
+		//		},
+		//	},
+		//}
+	case 4:
+		//source = map[string]interface{}{
+		//	"query": map[string]interface{}{
+		//		"bool": map[string]interface{}{
+		//			"must": map[string]interface{}{
+		//				"query_string": map[string]interface{}{
+		//					"query": keywordStr,
+		//				},
+		//			},
+		//			"filter": []interface{}{
+		//				map[string]interface{}{
+		//					"term": map[string]interface{}{
+		//						"EdbType": 1,
+		//					},
+		//				}},
+		//		},
+		//	},
+		//}
+		mustMap = []interface{}{
+			map[string]interface{}{
+				"term": map[string]interface{}{
+					"EdbType": 1,
+				},
+			},
+		}
+	case 5:
+		mustMap = []interface{}{
+			map[string]interface{}{
+				"term": map[string]interface{}{
+					"Source": 6,
+				},
+			},
+		}
+	case 6:
+		mustNotMap = []interface{}{
+			map[string]interface{}{
+				"match": map[string]interface{}{
+					"Frequency.keyword": "年度",
+				},
+			},
+		}
+	}
+
+	//指标来源
+	if source > 0 {
+		mustMap = append(mustMap, map[string]interface{}{
+			"term": map[string]interface{}{
+				"Source": source,
+				//"Frequency.keyword": "月度",
+			},
+		})
+	}
+
+	if frequency != "" {
+		mustMap = append(mustMap, map[string]interface{}{
+			"term": map[string]interface{}{
+				"Frequency.keyword": frequency,
+				//"Frequency.keyword": "月度",
+			},
+		})
+	}
+
+	// noPermissionEdbInfoIdList 无权限指标id
+	if len(noPermissionEdbInfoIdList) > 0 {
+		mustNotMap = append(mustNotMap, map[string]interface{}{
+			"terms": map[string]interface{}{
+				"EdbInfoId": noPermissionEdbInfoIdList,
+				//"Frequency.keyword": "月度",
+			},
+		})
+	}
+
+	// 指标类型:普通指标、预测指标(小于0 代表不区分指标是普通还是预测)
+	if edbInfoType >= 0 {
+		mustMap = append(mustMap, map[string]interface{}{
+			"term": map[string]interface{}{
+				"EdbInfoType": edbInfoType,
+			},
+		})
+	}
+
+	//普通指标
+	//mustMap = append(mustMap, map[string]interface{}{
+	//	"term": map[string]interface{}{
+	//		"EdbInfoType": 0,
+	//		//"Frequency.keyword": "月度",
+	//	},
+	//})
+
+	//关键字匹配
+	//shouldMap := map[string]interface{}{
+	//	"should": []interface{}{
+	//		map[string]interface{}{
+	//			"match": map[string]interface{}{
+	//				"EdbCode": keywordStr,
+	//				//"Frequency.keyword": "月度",
+	//			},
+	//		},
+	//		map[string]interface{}{
+	//			"match": map[string]interface{}{
+	//				"EdbName": keywordStr,
+	//				//"Frequency.keyword": "月度",
+	//			},
+	//		},
+	//		map[string]interface{}{
+	//			"match": map[string]interface{}{
+	//				"EdbNameEn": keywordStr,
+	//				//"Frequency.keyword": "月度",
+	//			},
+	//		},
+	//	},
+	//}
+
+	// 默认使用中文名字字段去匹配
+	keywordNameKey := `EdbName`
+	// 如果没有中文,则使用英文名称字段去匹配
+	if !utils.ContainsChinese(keywordStr) {
+		keywordNameKey = `EdbNameEn`
+	}
+	shouldMap := map[string]interface{}{
+		"should": []interface{}{
+			map[string]interface{}{
+				"match": map[string]interface{}{
+					"EdbCode": keywordStr,
+					//"Frequency.keyword": "月度",
+				},
+			},
+			map[string]interface{}{
+				"match": map[string]interface{}{
+					keywordNameKey: keywordStr,
+					//"Frequency.keyword": "月度",
+				},
+			},
+		},
+	}
+
+	//mustMap = append(mustMap, map[string]interface{}{
+	//	"bool": shouldMap,
+	//})
+
+	return searchEdbInfoData(indexName, mustMap, mustNotMap, shouldMap, from, size)
+}

+ 68 - 1
services/elastic/elastic.go

@@ -8,9 +8,10 @@ import (
 	"eta/eta_api/models/data_manage"
 	"eta/eta_api/utils"
 	"fmt"
-	"github.com/olivere/elastic/v7"
 	"strconv"
 	"strings"
+
+	"github.com/olivere/elastic/v7"
 )
 
 // indexName:索引名称
@@ -319,6 +320,72 @@ func SearchEdbInfoData(indexName, keywordStr string, from, size, filterSource, s
 	return searchEdbInfoData(indexName, mustMap, mustNotMap, shouldMap, from, size)
 }
 
+// SearchEdbInfoData 查询es中的指标数据
+func SearchEdbInfoDataByfrequency(indexName, keywordStr string, from, size int, edbInfoType int8, frequency string, noPermissionEdbInfoIdList []int) (total int64, list []*data_manage.EdbInfoList, err error) {
+	list = make([]*data_manage.EdbInfoList, 0)
+	defer func() {
+		if err != nil {
+			fmt.Println("EsAddOrEditData Err:", err.Error())
+		}
+	}()
+
+	mustMap := make([]interface{}, 0)
+	mustNotMap := make([]interface{}, 0)
+
+	if frequency != "" {
+		mustMap = append(mustMap, map[string]interface{}{
+			"term": map[string]interface{}{
+				"Frequency.keyword": frequency,
+				//"Frequency.keyword": "月度",
+			},
+		})
+	}
+
+	// noPermissionEdbInfoIdList 无权限指标id
+	if len(noPermissionEdbInfoIdList) > 0 {
+		mustNotMap = append(mustNotMap, map[string]interface{}{
+			"terms": map[string]interface{}{
+				"EdbInfoId": noPermissionEdbInfoIdList,
+				//"Frequency.keyword": "月度",
+			},
+		})
+	}
+
+	// 指标类型:普通指标、预测指标(小于0 代表不区分指标是普通还是预测)
+	if edbInfoType >= 0 {
+		mustMap = append(mustMap, map[string]interface{}{
+			"term": map[string]interface{}{
+				"EdbInfoType": edbInfoType,
+			},
+		})
+	}
+
+	// 默认使用中文名字字段去匹配
+	keywordNameKey := `EdbName`
+	// 如果没有中文,则使用英文名称字段去匹配
+	if !utils.ContainsChinese(keywordStr) {
+		keywordNameKey = `EdbNameEn`
+	}
+	shouldMap := map[string]interface{}{
+		"should": []interface{}{
+			map[string]interface{}{
+				"match": map[string]interface{}{
+					"EdbCode": keywordStr,
+					//"Frequency.keyword": "月度",
+				},
+			},
+			map[string]interface{}{
+				"match": map[string]interface{}{
+					keywordNameKey: keywordStr,
+					//"Frequency.keyword": "月度",
+				},
+			},
+		},
+	}
+
+	return searchEdbInfoData(indexName, mustMap, mustNotMap, shouldMap, from, size)
+}
+
 func SearchEdbInfoDataBak(indexName, keywordStr string, from, size, filterSource, source int, frequency string) (total int64, list []*data_manage.EdbInfoList, err error) {
 	list = make([]*data_manage.EdbInfoList, 0)
 	defer func() {