|
@@ -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)
|
|
|
+}
|