edb_refresh.go 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. package data
  2. import (
  3. "eta/eta_hub/models/data_manage"
  4. "eta/eta_hub/utils"
  5. "fmt"
  6. )
  7. /*// GetEdbRelationList 获取指标引用列表
  8. func GetEdbRelationList(source, edbType int, classifyId, sysUserId, frequency, keyword, status string, startSize, pageSize int, sortParam, sortType string) (total int, list []*data_manage.BaseRelationEdbInfo, err error) {
  9. var pars []interface{}
  10. var condition string
  11. list = make([]*data_manage.BaseRelationEdbInfo, 0)
  12. isStop := -1
  13. switch status {
  14. case `暂停`:
  15. isStop = 1
  16. case `启用`:
  17. isStop = 0
  18. case `供应商停用`:
  19. isStop = 3
  20. }
  21. // 关联表语句
  22. var addFieldStr, joinTableStr string
  23. switch source {
  24. case 0: // 计算指标,不校验source
  25. default:
  26. condition += ` AND e.source = ? `
  27. pars = append(pars, source)
  28. }
  29. if edbType == 2 { //计算指标
  30. condition += ` AND e.edb_type = ? AND e.edb_info_type = 0`
  31. pars = append(pars, edbType)
  32. }
  33. switch isStop {
  34. case -1:
  35. // 供应商停用
  36. if source == utils.DATA_SOURCE_MYSTEEL_CHEMICAL {
  37. joinTableStr = ` LEFT JOIN base_from_mysteel_chemical_index z ON e.edb_code = z.index_code `
  38. addFieldStr = ` ,z.is_supplier_stop `
  39. }
  40. case 0, 1:
  41. condition += " AND e.no_update = ? "
  42. pars = append(pars, isStop)
  43. // 供应商停用
  44. if source == utils.DATA_SOURCE_MYSTEEL_CHEMICAL {
  45. condition += " AND z.is_supplier_stop = ? "
  46. pars = append(pars, 0)
  47. joinTableStr = ` LEFT JOIN base_from_mysteel_chemical_index z ON e.edb_code = z.index_code `
  48. addFieldStr = ` ,z.is_supplier_stop `
  49. }
  50. case 3:
  51. // 供应商停用
  52. if source == utils.DATA_SOURCE_MYSTEEL_CHEMICAL {
  53. condition += " AND z.is_supplier_stop = ? "
  54. pars = append(pars, 1)
  55. joinTableStr = ` LEFT JOIN base_from_mysteel_chemical_index z ON e.edb_code = z.index_code `
  56. addFieldStr = ` ,z.is_supplier_stop `
  57. }
  58. }
  59. if classifyId != `` {
  60. classifyIdSlice := strings.Split(classifyId, ",")
  61. condition += ` AND e.classify_id IN (` + utils.GetOrmInReplace(len(classifyIdSlice)) + `)`
  62. pars = append(pars, classifyIdSlice)
  63. }
  64. if sysUserId != `` {
  65. sysUserIdSlice := strings.Split(sysUserId, ",")
  66. condition += ` AND e.sys_user_id IN (` + utils.GetOrmInReplace(len(sysUserIdSlice)) + `)`
  67. pars = append(pars, sysUserIdSlice)
  68. }
  69. if frequency != `` {
  70. frequencySlice := strings.Split(frequency, ",")
  71. condition += ` AND e.frequency IN (` + utils.GetOrmInReplace(len(frequencySlice)) + `)`
  72. pars = append(pars, frequencySlice)
  73. }
  74. if keyword != `` {
  75. keywordSlice := strings.Split(keyword, " ")
  76. if len(keywordSlice) > 0 {
  77. tmpConditionSlice := make([]string, 0)
  78. tmpConditionSlice = append(tmpConditionSlice, ` e.edb_name like ? or e.edb_code like ? `)
  79. pars = utils.GetLikeKeywordPars(pars, keyword, 2)
  80. for _, v := range keywordSlice {
  81. if v == ` ` || v == `` {
  82. continue
  83. }
  84. tmpConditionSlice = append(tmpConditionSlice, ` e.edb_name like ? or e.edb_code like ? `)
  85. pars = utils.GetLikeKeywordPars(pars, v, 2)
  86. }
  87. condition += ` AND (` + strings.Join(tmpConditionSlice, " or ") + `)`
  88. } else {
  89. condition += ` AND (e.edb_name like ? or e.edb_code like ? )`
  90. pars = utils.GetLikeKeywordPars(pars, keyword, 2)
  91. }
  92. }
  93. sortStr := ``
  94. if sortParam != `` {
  95. sortStr = fmt.Sprintf("%s %s,e.edb_info_id desc ", sortParam, sortType)
  96. }
  97. total, list, err = data_manage.GetEdbInfoRelationList(condition, pars, addFieldStr, joinTableStr, sortStr, startSize, pageSize)
  98. return
  99. }
  100. */
  101. // GetCalculateEdbByFromEdbInfo 找到依赖于该基础指标的所有计算指标
  102. func GetCalculateEdbByFromEdbInfo(edbInfoIds []int, calculateEdbIds []int, hasFind map[int]struct{}) (newCalculateEdbIds []int, err error) {
  103. if len(edbInfoIds) == 0 {
  104. return
  105. }
  106. newCalculateEdbIds = calculateEdbIds
  107. newEdbInfoIds := make([]int, 0)
  108. for _, v := range edbInfoIds {
  109. if _, ok := hasFind[v]; ok {
  110. continue
  111. }
  112. newEdbInfoIds = append(newEdbInfoIds, v)
  113. }
  114. if len(newEdbInfoIds) == 0 {
  115. return
  116. }
  117. var condition string
  118. var pars []interface{}
  119. // 关联指标
  120. condition += ` AND b.from_edb_info_id in (` + utils.GetOrmInReplace(len(newEdbInfoIds)) + `)`
  121. pars = append(pars, newEdbInfoIds)
  122. //获取关联图表列表
  123. list, err := data_manage.GetRelationEdbInfoListMappingByCondition(condition, pars)
  124. if err != nil && err.Error() != utils.ErrNoRow() {
  125. err = fmt.Errorf("获取关联指标信息失败,Err:%s", err.Error())
  126. return
  127. }
  128. calculateEdbIdsTmp := make([]int, 0)
  129. for _, mapping := range list {
  130. if mapping.EdbType == 2 && mapping.EdbInfoType == 0 { // 如果指标库里的计算指标,则加入,否则继续找
  131. newCalculateEdbIds = append(newCalculateEdbIds, mapping.EdbInfoId)
  132. calculateEdbIdsTmp = append(calculateEdbIdsTmp, mapping.EdbInfoId)
  133. }
  134. }
  135. for _, v := range newEdbInfoIds {
  136. hasFind[v] = struct{}{}
  137. }
  138. if len(calculateEdbIdsTmp) > 0 {
  139. newCalculateEdbIds, err = GetCalculateEdbByFromEdbInfo(calculateEdbIdsTmp, newCalculateEdbIds, hasFind)
  140. if err != nil {
  141. return
  142. }
  143. }
  144. return
  145. }