chart_info.go 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. package data_manage
  2. import (
  3. "fmt"
  4. "github.com/beego/beego/v2/client/orm"
  5. "hongze/hongze_chart_lib/utils"
  6. )
  7. // GetChartInfoRefreshData 获取图表关联的指标信息
  8. func GetChartInfoRefreshData(chartInfoId int) (baseEdbInfoArr, calculateInfoArr []*EdbInfo, err error) {
  9. o := orm.NewOrmUsingDB("data")
  10. sql := ` SELECT b.* FROM chart_edb_mapping AS a
  11. INNER JOIN edb_info AS b ON a.edb_info_id=b.edb_info_id
  12. WHERE a.chart_info_id=? `
  13. edbInfoList := make([]*EdbInfo, 0)
  14. _, err = o.Raw(sql, chartInfoId).QueryRows(&edbInfoList)
  15. if err != nil {
  16. return
  17. }
  18. for _, v := range edbInfoList {
  19. fmt.Println(v.EdbInfoId, v.EdbType)
  20. if v.EdbType == 1 {
  21. baseEdbInfoArr = append(baseEdbInfoArr, v)
  22. } else {
  23. calculateInfoArr = append(calculateInfoArr, v)
  24. newBaseEdbInfoArr, newCalculateInfoArr, err := GetChartRefreshEdbInfo(v.EdbInfoId, v.Source, 0)
  25. if err != nil {
  26. return baseEdbInfoArr, calculateInfoArr, err
  27. }
  28. baseEdbInfoArr = append(baseEdbInfoArr, newBaseEdbInfoArr...)
  29. calculateInfoArr = append(calculateInfoArr, newCalculateInfoArr...)
  30. }
  31. }
  32. return
  33. }
  34. func GetChartRefreshEdbInfo(edbInfoId, source, n int) (baseEdbInfoArr, calculateInfoArr []*EdbInfo, err error) {
  35. calculateList, err := GetEdbInfoCalculateMap(edbInfoId, source)
  36. if err != nil && err.Error() != utils.ErrNoRow() {
  37. return
  38. }
  39. n++
  40. for _, item := range calculateList {
  41. fmt.Println(item.EdbInfoId)
  42. if item.EdbType == 1 {
  43. baseEdbInfoArr = append(baseEdbInfoArr, item)
  44. } else {
  45. calculateInfoArr = append(calculateInfoArr, item)
  46. if n > 10 {
  47. return
  48. }
  49. newBaseEdbInfoArr, newCalculateInfoArr, _ := GetChartRefreshEdbInfo(item.EdbInfoId, item.Source, n)
  50. baseEdbInfoArr = append(baseEdbInfoArr, newBaseEdbInfoArr...)
  51. calculateInfoArr = append(calculateInfoArr, newCalculateInfoArr...)
  52. }
  53. }
  54. return
  55. }