query.go 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. package edb_info
  2. import (
  3. "hongze/hongze_yb/global"
  4. "hongze/hongze_yb/utils"
  5. )
  6. // GetEdbInfoById 主键获取指标信息
  7. func GetEdbInfoById(edbInfoId int) (item *EdbInfo, err error) {
  8. err = global.MYSQL["data"].Where("edb_info_id = ? ", edbInfoId).First(&item).Error
  9. return
  10. }
  11. // GetEdbInfoAllCalculateByEdbInfoIdList 根据指标id集合 获取基础指标对应的所有计算指标
  12. func GetEdbInfoAllCalculateByEdbInfoIdList(edbInfoIdList []int) (list []*EdbInfo, err error) {
  13. num := len(edbInfoIdList)
  14. if num <= 0 {
  15. return
  16. }
  17. sql := ` SELECT b.* FROM edb_info_calculate_mapping AS a
  18. INNER JOIN edb_info AS b ON a.edb_info_id=b.edb_info_id
  19. WHERE a.from_edb_info_id IN (?)
  20. GROUP BY a.edb_info_id
  21. ORDER BY a.edb_info_id ASC `
  22. err = global.MYSQL["data"].Raw(sql, edbInfoIdList).Scan(&list).Error
  23. return
  24. }
  25. // GetEdbInfoByIdList 根据指标id集合 获取 指标列表
  26. func GetEdbInfoByIdList(edbInfoIdList []int) (items []*EdbInfo, err error) {
  27. num := len(edbInfoIdList)
  28. if num <= 0 {
  29. return
  30. }
  31. sql := ` SELECT * FROM edb_info WHERE edb_info_id IN (?) `
  32. err = global.MYSQL["data"].Raw(sql, edbInfoIdList).Scan(&items).Error
  33. return
  34. }
  35. // GetRefreshEdbInfoFromBase 查询基础指标
  36. func GetRefreshEdbInfoFromBase(edbInfoId, source int) (baseEdbInfoArr, calculateInfoArr []*EdbInfo, err error) {
  37. calculateList, err := GetEdbInfoCalculateMap(edbInfoId)
  38. if err != nil && err != utils.ErrNoRow {
  39. return
  40. }
  41. for _, item := range calculateList {
  42. if item.EdbInfoId == edbInfoId { // 如果查出来关联的指标就是自己的话,那么就过滤
  43. continue
  44. }
  45. if item.EdbType == 1 {
  46. baseEdbInfoArr = append(baseEdbInfoArr, item)
  47. } else {
  48. calculateInfoArr = append(calculateInfoArr, item)
  49. newBaseEdbInfoArr, newCalculateInfoArr, _ := GetRefreshEdbInfoFromBase(item.EdbInfoId, item.Source)
  50. baseEdbInfoArr = append(baseEdbInfoArr, newBaseEdbInfoArr...)
  51. calculateInfoArr = append(calculateInfoArr, newCalculateInfoArr...)
  52. }
  53. }
  54. return
  55. }
  56. // GetEdbInfoCalculateMap 获取计算指标关联信息
  57. func GetEdbInfoCalculateMap(edbInfoId int) (list []*EdbInfo, err error) {
  58. sql := ` SELECT b.* FROM edb_info_calculate_mapping AS a
  59. INNER JOIN edb_info AS b ON a.from_edb_info_id=b.edb_info_id
  60. WHERE a.edb_info_id=? ORDER BY sort ASC `
  61. err = global.MYSQL["data"].Raw(sql, edbInfoId).Scan(&list).Error
  62. return
  63. }
  64. // GetPredictEdbInfoAllCalculate 根据基础预测指标id集合 获取 所有的普通指标列表数据
  65. func GetPredictEdbInfoAllCalculate(edbInfoIdList []int) (list []*EdbInfo, err error) {
  66. num := len(edbInfoIdList)
  67. if num <= 0 {
  68. return
  69. }
  70. sql := ` SELECT b.* FROM predict_edb_conf AS a
  71. INNER JOIN edb_info AS b ON a.source_edb_info_id=b.edb_info_id
  72. WHERE a.predict_edb_info_id IN (?)
  73. GROUP BY a.source_edb_info_id
  74. ORDER BY a.source_edb_info_id ASC `
  75. err = global.MYSQL["data"].Raw(sql, edbInfoIdList).Scan(&list).Error
  76. return
  77. }
  78. type EdbInfoSearchData struct {
  79. DataTime string `description:"数据日期"`
  80. Value float64 `description:"数据"`
  81. }