edb_info_es.go 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. package data
  2. import (
  3. "eta_gn/eta_api/models/data_manage"
  4. "eta_gn/eta_api/services/data/data_manage_permission"
  5. "eta_gn/eta_api/services/elastic"
  6. "eta_gn/eta_api/utils"
  7. "fmt"
  8. "strconv"
  9. "strings"
  10. )
  11. // AddOrEditEdbInfoToEs 添加/修改ES中的指标
  12. func AddOrEditEdbInfoToEs(edbInfoId int) {
  13. var err error
  14. defer func() {
  15. if err != nil {
  16. utils.FileLog.Error("添加/修改ES中的指标失败; err:%s", err.Error())
  17. }
  18. }()
  19. //添加es
  20. itemInfo, err := data_manage.GetEdbInfoEsByCondition("AND edb_info_id=?", []interface{}{edbInfoId})
  21. if err != nil {
  22. return
  23. }
  24. obj := data_manage.EdbInfoShare{}
  25. list, _ := obj.GetListByEdbInfoId(edbInfoId)
  26. sharedList := make([]int, 0)
  27. for _, v := range list {
  28. sharedList = append(sharedList, v.SysUserId)
  29. }
  30. itemInfo.SharedUserIdList = sharedList
  31. err = elastic.EsAddOrEditEdbInfoData(utils.DATA_INDEX_NAME, strconv.Itoa(itemInfo.EdbInfoId), itemInfo)
  32. }
  33. // AddOrEditAllEdbInfoToEs 修复ES中的所有指标
  34. func AddOrEditAllEdbInfoToEs() {
  35. //添加es
  36. total, itemInfoList, _ := data_manage.GetEsEdbInfo("", []interface{}{}, 0, 100000)
  37. obj := data_manage.EdbInfoShare{}
  38. for k, itemInfo := range itemInfoList {
  39. list, _ := obj.GetListByEdbInfoId(itemInfo.EdbInfoId)
  40. sharedList := make([]int, 0)
  41. for _, v := range list {
  42. sharedList = append(sharedList, v.SysUserId)
  43. }
  44. itemInfo.SharedUserIdList = sharedList
  45. elastic.EsAddOrEditEdbInfoData(utils.DATA_INDEX_NAME, strconv.Itoa(itemInfo.EdbInfoId), itemInfo)
  46. fmt.Println("剩余", int(total)-k-1, "条指标数据")
  47. }
  48. }
  49. // DeleteEdbInfoToEs 删除ES中的指标
  50. func DeleteEdbInfoToEs(edbInfoId int) {
  51. //添加es
  52. go elastic.EsDeleteEdbInfoData(utils.DATA_INDEX_NAME, strconv.Itoa(edbInfoId))
  53. }
  54. 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) {
  55. // 指标类型数组:1-基础指标;2-计算指标;3-预测指标
  56. edbTypeList = make([]int, 0)
  57. edbInfoType = -1 // 指标范围
  58. // 搜索用户id
  59. searchUserId = sysUserId
  60. {
  61. if edbTypeStr == `` || edbTypeStr == `0` {
  62. edbTypeList = []int{1, 2}
  63. edbInfoType = 0
  64. } else if edbTypeStr == `1` { // 数据查看(基础指标),不应该固定创建人的
  65. edbTypeList = []int{1}
  66. edbInfoType = 0
  67. searchUserId = 0
  68. } else {
  69. var hasEdb, hasPredictEdb bool
  70. tmpEdbTypeList := strings.Split(edbTypeStr, `,`)
  71. for _, v := range tmpEdbTypeList {
  72. edbType, tmpErr := strconv.Atoi(v)
  73. if tmpErr != nil {
  74. err = tmpErr
  75. errMsg = "EdbType异常"
  76. return
  77. }
  78. // 指标类型
  79. switch edbType {
  80. case 1, 2:
  81. hasEdb = true
  82. edbTypeList = append(edbTypeList, edbType)
  83. case 3:
  84. hasPredictEdb = true
  85. edbTypeList = []int{1, 2}
  86. }
  87. }
  88. // 只有数据查看和指标加工
  89. if hasEdb && !hasPredictEdb {
  90. edbInfoType = 0
  91. } else if !hasEdb && hasPredictEdb {
  92. // 只有预测指标
  93. edbInfoType = 1
  94. }
  95. }
  96. }
  97. edbAuth = reqEdbAuth
  98. // 筛选分类id列表
  99. searchClassifyIdList = make([]int, 0)
  100. searchPublicClassifyIdList = make([]int, 0)
  101. // 父级分类id
  102. if classifyId > 0 {
  103. switch edbAuth {
  104. case 1: // 1-我的;2-公共
  105. allChildClassifyItemList, tmpErr, _ := GetAllChildClassifyByParentId(classifyId)
  106. if tmpErr != nil {
  107. err = tmpErr
  108. return
  109. }
  110. searchClassifyIdList = append(searchClassifyIdList, classifyId)
  111. for _, v := range allChildClassifyItemList {
  112. searchClassifyIdList = append(searchClassifyIdList, v.ClassifyId)
  113. }
  114. case 2: // 1-我的;2-公共
  115. obj := data_manage.EdbPublicClassify{}
  116. allChildClassifyItemList, tmpErr, _ := obj.GetAllChildClassifyByParentId(classifyId)
  117. if tmpErr != nil {
  118. err = tmpErr
  119. return
  120. }
  121. searchPublicClassifyIdList = append(searchPublicClassifyIdList, classifyId)
  122. for _, v := range allChildClassifyItemList {
  123. searchPublicClassifyIdList = append(searchPublicClassifyIdList, v.EdbPublicClassifyId)
  124. }
  125. default:
  126. if edbTypeStr == `1` { // 如果仅仅是基础指标,那么也需要查询分类
  127. allChildClassifyItemList, tmpErr, _ := GetAllChildClassifyByParentId(classifyId)
  128. if tmpErr != nil {
  129. err = tmpErr
  130. return
  131. }
  132. searchClassifyIdList = append(searchClassifyIdList, classifyId)
  133. for _, v := range allChildClassifyItemList {
  134. searchClassifyIdList = append(searchClassifyIdList, v.ClassifyId)
  135. }
  136. }
  137. }
  138. }
  139. // 无权限指标 和 无权限指标分类id(只考虑)
  140. noPermissionEdbInfoIdList, noPermissionEdbClassifyIdList, err = data_manage_permission.GetUserAllEdbAndClassifyNoPermissionListV2(sysUserId)
  141. if err != nil {
  142. return
  143. }
  144. // 收藏的指标id
  145. collectEdbInfoIdList = make([]int, 0)
  146. if edbCollect == 1 {
  147. collectEdbInfoIdList, err = data_manage.GetUserAllCollectEdbInfoIdList(sysUserId)
  148. if err != nil {
  149. return
  150. }
  151. }
  152. return
  153. }