edb_info_calculate.go 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. package data_manage
  2. import (
  3. "eta/eta_chart_lib/utils"
  4. "github.com/beego/beego/v2/client/orm"
  5. "time"
  6. )
  7. func GetEdbInfoCalculateMap(edbInfoId, source int) (list []*EdbInfo, err error) {
  8. o := orm.NewOrmUsingDB("data")
  9. //calculateTableName := GetEdbInfoCalculateTableName(source)
  10. //sql := ` SELECT b.* FROM %s AS a
  11. // INNER JOIN edb_info AS b ON a.from_edb_info_id=b.edb_info_id
  12. // WHERE a.edb_info_id=? ORDER BY sort ASC `
  13. //sql = fmt.Sprintf(sql, calculateTableName)
  14. sql := ` SELECT b.* FROM edb_info_calculate_mapping AS a
  15. INNER JOIN edb_info AS b ON a.from_edb_info_id=b.edb_info_id
  16. WHERE a.edb_info_id=? ORDER BY sort ASC `
  17. _, err = o.Raw(sql, edbInfoId).QueryRows(&list)
  18. return
  19. }
  20. // GetEdbInfoAllCalculateByEdbInfoIdList 根据指标id集合 获取基础指标对应的所有计算指标
  21. func GetEdbInfoAllCalculateByEdbInfoIdList(edbInfoIdList []int) (list []*EdbInfo, err error) {
  22. num := len(edbInfoIdList)
  23. if num <= 0 {
  24. return
  25. }
  26. o := orm.NewOrmUsingDB("data")
  27. sql := ` SELECT b.* FROM edb_info_calculate_mapping AS a
  28. INNER JOIN edb_info AS b ON a.edb_info_id=b.edb_info_id
  29. WHERE a.from_edb_info_id in (` + utils.GetOrmInReplace(num) + `)
  30. GROUP BY a.edb_info_id
  31. ORDER BY a.edb_info_id ASC `
  32. _, err = o.Raw(sql, edbInfoIdList).QueryRows(&list)
  33. return
  34. }
  35. // EdbInfoCalculateMappingInfo
  36. type EdbInfoCalculateMappingInfo struct {
  37. EdbInfoCalculateMappingId int `orm:"column(edb_info_calculate_mapping_id);pk"`
  38. EdbInfoId int `description:"计算指标id"`
  39. Source int `description:"计算指标来源"`
  40. SourceName string `description:"计算指标来源名称"`
  41. EdbCode string `description:"计算指标编码"`
  42. FromEdbInfoId int `description:"基础指标id"`
  43. FromEdbCode string `description:"基础指标编码"`
  44. FromEdbName string `description:"基础指标名称"`
  45. FromSource int `description:"基础指标来源"`
  46. FromSourceName string `description:"基础指标来源名称"`
  47. MoveValue int `description:"领先值"`
  48. FromTag string `description:"来源指标标签"`
  49. Sort int `description:"计算指标名称排序"`
  50. CreateTime time.Time `description:"创建时间"`
  51. ModifyTime time.Time `description:"修改时间"`
  52. FromEdbType int `description:"来源指标类型:1:基础指标,2:计算指标"`
  53. FromEdbInfoType int `description:"来源指标类型: 0-基础指标; 1-预测指标"`
  54. FromClassifyId int `description:"来源指标分类ID"`
  55. FromUniqueCode string `description:"来源指标唯一编码"`
  56. }
  57. // GetEdbInfoCalculateMappingListByEdbInfoId 根据生成的指标id获取来源的指标id列表
  58. func GetEdbInfoCalculateMappingListByEdbInfoId(edbInfoId int) (items []*EdbInfoCalculateMappingInfo, err error) {
  59. o := orm.NewOrmUsingDB("data")
  60. sql := ` SELECT a.*,b.edb_type as from_edb_type,b.edb_info_type as from_edb_info_type, b.unique_code AS from_unique_code, b.classify_id AS from_classify_id FROM edb_info_calculate_mapping AS a
  61. INNER JOIN edb_info AS b ON a.from_edb_info_id=b.edb_info_id
  62. WHERE a.edb_info_id=? `
  63. _, err = o.Raw(sql, edbInfoId).QueryRows(&items)
  64. return
  65. }