123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171 |
- package data
- import (
- "eta_gn/eta_api/models/data_manage"
- "eta_gn/eta_api/services/data/data_manage_permission"
- "eta_gn/eta_api/services/elastic"
- "eta_gn/eta_api/utils"
- "fmt"
- "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))
- }
- func GetGeneralEdbEsSearchParams(edbTypeStr string, sysUserId, reqEdbAuth, edbCollect, classifyId int) (source int, frequency string, noPermissionEdbInfoIdList, noPermissionEdbClassifyIdList, collectEdbInfoIdList, searchClassifyIdList, searchPublicClassifyIdList, edbTypeList []int, edbInfoType, edbAuth, searchUserId int, err error, errMsg string) {
- // 指标类型数组:1-基础指标;2-计算指标;3-预测指标
- edbTypeList = make([]int, 0)
- edbInfoType = -1 // 指标范围
- // 搜索用户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
- }
|