package data import ( "eta_gn/eta_api/models/data_manage" "eta_gn/eta_api/models/data_manage/request" "eta_gn/eta_api/services/data/data_manage_permission" "eta_gn/eta_api/services/elastic" "eta_gn/eta_api/utils" "fmt" "github.com/rdlucklib/rdluck_tools/paging" "strconv" "strings" ) // AddOrEditEdbInfoToEs 添加/修改ES中的指标 func AddOrEditEdbInfoToEs(edbInfoId int) { var err error defer func() { if err != nil { utils.FileLog.Error("添加/修改ES中的指标失败; err:%s", err.Error()) } }() //添加es itemInfo, err := data_manage.GetEdbInfoEsByCondition("AND edb_info_id=?", []interface{}{edbInfoId}) if err != nil { return } obj := data_manage.EdbInfoShare{} list, _ := obj.GetListByEdbInfoId(edbInfoId) sharedList := make([]int, 0) for _, v := range list { sharedList = append(sharedList, v.SysUserId) } itemInfo.SharedUserIdList = sharedList err = elastic.EsAddOrEditEdbInfoData(utils.DATA_INDEX_NAME, strconv.Itoa(itemInfo.EdbInfoId), itemInfo) } // AddOrEditAllEdbInfoToEs 修复ES中的所有指标 func AddOrEditAllEdbInfoToEs() { //添加es total, itemInfoList, _ := data_manage.GetEsEdbInfo("", []interface{}{}, 0, 100000) obj := data_manage.EdbInfoShare{} for k, itemInfo := range itemInfoList { list, _ := obj.GetListByEdbInfoId(itemInfo.EdbInfoId) sharedList := make([]int, 0) for _, v := range list { sharedList = append(sharedList, v.SysUserId) } itemInfo.SharedUserIdList = sharedList elastic.EsAddOrEditEdbInfoData(utils.DATA_INDEX_NAME, strconv.Itoa(itemInfo.EdbInfoId), itemInfo) fmt.Println("剩余", int(total)-k-1, "条指标数据") } } // DeleteEdbInfoToEs 删除ES中的指标 func DeleteEdbInfoToEs(edbInfoId int) { //添加es go elastic.EsDeleteEdbInfoData(utils.DATA_INDEX_NAME, strconv.Itoa(edbInfoId)) } // GetGeneralEdbEsSearchParams // @Description: 指标通用es搜索参数匹配 // @author: Roc // @datetime 2024-12-23 11:10:42 // @param edbTypeStr string 指标类型:0-基础和计算;1-基础指标;2-计算指标;3-预测指标 // @param sysUserId int // @param reqEdbAuth int 指标权限范围,0-全部;1-我的;2-公共 // @param edbCollect int 指标收藏状态:0-全部;1-已收藏 // @param classifyId int // @return noPermissionEdbInfoIdList []int // @return noPermissionEdbClassifyIdList []int // @return collectEdbInfoIdList []int // @return searchClassifyIdList []int // @return searchPublicClassifyIdList []int // @return edbTypeList []int // @return edbInfoType int // @return edbAuth int 指标权限范围,0-全部;1-我的;2-公共 // @return searchUserId int // @return err error // @return errMsg string func GetGeneralEdbEsSearchParams(edbTypeStr, frequency string, sysUserId, reqEdbAuth, edbCollect, classifyId int) (noPermissionEdbInfoIdList, noPermissionEdbClassifyIdList, collectEdbInfoIdList, searchClassifyIdList, searchPublicClassifyIdList, edbTypeList []int, edbInfoType, edbAuth, searchUserId int, frequencyList []string, err error, errMsg string) { // 指标类型数组:1-基础指标;2-计算指标;3-预测指标 edbTypeList = make([]int, 0) edbInfoType = -1 // 指标范围 frequencyList = []string{} if frequency != `` { frequencyList = strings.Split(frequency, `,`) } // 搜索用户id searchUserId = sysUserId { if edbTypeStr == `` || edbTypeStr == `0` { edbTypeList = []int{1, 2} edbInfoType = 0 } else if edbTypeStr == `1` { // 数据查看(基础指标),不应该固定创建人的 edbTypeList = []int{1} edbInfoType = 0 searchUserId = 0 } else { var hasEdb, hasPredictEdb bool tmpEdbTypeList := strings.Split(edbTypeStr, `,`) for _, v := range tmpEdbTypeList { edbType, tmpErr := strconv.Atoi(v) if tmpErr != nil { err = tmpErr errMsg = "EdbType异常" return } // 指标类型 switch edbType { case 1, 2: hasEdb = true edbTypeList = append(edbTypeList, edbType) case 3: hasPredictEdb = true edbTypeList = []int{1, 2} } } // 只有数据查看和指标加工 if hasEdb && !hasPredictEdb { edbInfoType = 0 } else if !hasEdb && hasPredictEdb { // 只有预测指标 edbInfoType = 1 } } } edbAuth = reqEdbAuth // 筛选分类id列表 searchClassifyIdList = make([]int, 0) searchPublicClassifyIdList = make([]int, 0) // 父级分类id if classifyId > 0 { switch edbAuth { case 1: // 1-我的;2-公共 allChildClassifyItemList, tmpErr, _ := GetAllChildClassifyByParentId(classifyId) if tmpErr != nil { err = tmpErr return } searchClassifyIdList = append(searchClassifyIdList, classifyId) for _, v := range allChildClassifyItemList { searchClassifyIdList = append(searchClassifyIdList, v.ClassifyId) } case 2: // 1-我的;2-公共 obj := data_manage.EdbPublicClassify{} allChildClassifyItemList, tmpErr, _ := obj.GetAllChildClassifyByParentId(classifyId) if tmpErr != nil { err = tmpErr return } searchPublicClassifyIdList = append(searchPublicClassifyIdList, classifyId) for _, v := range allChildClassifyItemList { searchPublicClassifyIdList = append(searchPublicClassifyIdList, v.EdbPublicClassifyId) } default: if edbTypeStr == `1` { // 如果仅仅是基础指标,那么也需要查询分类 allChildClassifyItemList, tmpErr, _ := GetAllChildClassifyByParentId(classifyId) if tmpErr != nil { err = tmpErr return } searchClassifyIdList = append(searchClassifyIdList, classifyId) for _, v := range allChildClassifyItemList { searchClassifyIdList = append(searchClassifyIdList, v.ClassifyId) } } } } // 无权限指标 和 无权限指标分类id(只考虑) noPermissionEdbInfoIdList, noPermissionEdbClassifyIdList, err = data_manage_permission.GetUserAllEdbAndClassifyNoPermissionListV2(sysUserId) if err != nil { return } // 收藏的指标id collectEdbInfoIdList = make([]int, 0) if edbCollect == 1 { collectEdbInfoIdList, err = data_manage.GetUserAllCollectEdbInfoIdList(sysUserId) if err != nil { return } } return } // GetAllGeneralEdbInfoListByGeneralEdbEsSearchReq // @Description: 获取所有指标列表(通用) // @author: Roc // @datetime 2024-12-23 11:31:51 // @param req request.GeneralEdbEsSearchReq // @param userId int // @return edbInfoList []*data_manage.EdbInfoList // @return err error // @return errMsg string func GetAllGeneralEdbInfoListByGeneralEdbEsSearchReq(req request.GeneralEdbEsSearchReq, userId int) (edbInfoList []*data_manage.EdbInfoList, err error, errMsg string) { keyword := req.Keyword if keyword == `` { keyword = req.KeyWord } // 获取es搜索参数 noPermissionEdbInfoIdList, noPermissionEdbClassifyIdList, collectEdbInfoIdList, searchClassifyIdList, searchPublicClassifyIdList, edbTypeList, edbInfoType, edbAuth, searchUserId, frequencyList, err, errMsg := GetGeneralEdbEsSearchParams(req.EdbType, req.Frequency, userId, req.EdbAuth, req.EdbCollect, req.ClassifyId) if err != nil { return } sortMap := make(map[string]string) // 如果没有搜索关键词,则默认根据指标编码倒序排序 if keyword == `` { sortMap["EdbInfoId"] = `desc` } notFrequencyList := make([]string, 0) if req.NotFrequency != "" { notFrequencyList = strings.Split(req.NotFrequency, ",") } _, edbInfoList, err = getAllEdbInfoDataByGeneralEdbEsSearch(keyword, 1, req.FilterSource, req.Source, frequencyList, notFrequencyList, noPermissionEdbInfoIdList, noPermissionEdbClassifyIdList, collectEdbInfoIdList, searchClassifyIdList, searchPublicClassifyIdList, edbTypeList, edbInfoType, edbAuth, searchUserId, sortMap) if err != nil { return } return } // getAllEdbInfoDataByGeneralEdbEsSearch // @Description: 获取所有的指标列表(通用es搜索接口) // @author: Roc // @datetime 2024-12-23 11:30:33 // @param keyword string // @param currPage int // @param filterSource int // @param source int // @param frequency string // @param noPermissionEdbInfoIdList []int // @param noPermissionEdbClassifyIdList []int // @param collectEdbInfoIdList []int // @param searchClassifyIdList []int // @param searchPublicClassifyIdList []int // @param edbTypeList []int // @param edbInfoType int // @param edbAuth int // @param sysUserId int // @param sortMap map[string]string // @return total int64 // @return list []*data_manage.EdbInfoList // @return err error func getAllEdbInfoDataByGeneralEdbEsSearch(keyword string, currPage, filterSource, source int, frequencyList, notFrequencyList []string, noPermissionEdbInfoIdList, noPermissionEdbClassifyIdList, collectEdbInfoIdList, searchClassifyIdList, searchPublicClassifyIdList, edbTypeList []int, edbInfoType, edbAuth, sysUserId int, sortMap map[string]string) (total int64, list []*data_manage.EdbInfoList, err error) { // 每页获取数据的数量 pageSize := 5000 var startSize int if currPage <= 0 { currPage = 1 } startSize = paging.StartIndex(currPage, pageSize) // 普通的搜索 total, list, err = elastic.SearchEdbInfoData(keyword, startSize, pageSize, filterSource, source, frequencyList, notFrequencyList, noPermissionEdbInfoIdList, noPermissionEdbClassifyIdList, collectEdbInfoIdList, searchClassifyIdList, searchPublicClassifyIdList, edbTypeList, edbInfoType, edbAuth, sysUserId, sortMap) if err != nil { return } page := paging.GetPaging(currPage, pageSize, int(total)) if !page.IsEnd { _, nextList, tmpErr := getAllEdbInfoDataByGeneralEdbEsSearch(keyword, page.NextIndex, filterSource, source, frequencyList, notFrequencyList, noPermissionEdbInfoIdList, noPermissionEdbClassifyIdList, collectEdbInfoIdList, searchClassifyIdList, searchPublicClassifyIdList, edbTypeList, edbInfoType, edbAuth, sysUserId, sortMap) if tmpErr != nil { err = tmpErr return } list = append(list, nextList...) } return }