edb_info_calculate.go 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. package data_manage
  2. import (
  3. "eta_gn/eta_chart_lib/global"
  4. "eta_gn/eta_chart_lib/utils"
  5. "time"
  6. )
  7. func GetEdbInfoCalculateMap(edbInfoId, source int) (list []*EdbInfo, err error) {
  8. o := global.DmSQL["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).Find(&list).Error
  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 := global.DmSQL["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.GetGormInReplace(num) + `)
  30. GROUP BY a.edb_info_id
  31. ORDER BY a.edb_info_id ASC `
  32. err = o.Raw(sql, edbInfoIdList).Scan(&list).Error
  33. return
  34. }
  35. // func GetEdbInfoCalculateMap(edbInfoId, source int) (list []*EdbInfo, err error) {
  36. // o := orm.NewOrmUsingDB("data")
  37. // //calculateTableName := GetEdbInfoCalculateTableName(source)
  38. // //sql := ` SELECT b.* FROM %s AS a
  39. // // INNER JOIN edb_info AS b ON a.from_edb_info_id=b.edb_info_id
  40. // // WHERE a.edb_info_id=? ORDER BY sort ASC `
  41. // //sql = fmt.Sprintf(sql, calculateTableName)
  42. // sql := ` SELECT b.* FROM edb_info_calculate_mapping AS a
  43. // INNER JOIN edb_info AS b ON a.from_edb_info_id=b.edb_info_id
  44. // WHERE a.edb_info_id=? ORDER BY sort ASC `
  45. // _, err = o.Raw(sql, edbInfoId).QueryRows(&list)
  46. // return
  47. // }
  48. // // GetEdbInfoAllCalculateByEdbInfoIdList 根据指标id集合 获取基础指标对应的所有计算指标
  49. // func GetEdbInfoAllCalculateByEdbInfoIdList(edbInfoIdList []int) (list []*EdbInfo, err error) {
  50. // num := len(edbInfoIdList)
  51. // if num <= 0 {
  52. // return
  53. // }
  54. // o := orm.NewOrmUsingDB("data")
  55. // sql := ` SELECT b.* FROM edb_info_calculate_mapping AS a
  56. // INNER JOIN edb_info AS b ON a.edb_info_id=b.edb_info_id
  57. // WHERE a.from_edb_info_id in (` + utils.GetOrmInReplace(num) + `)
  58. // GROUP BY a.edb_info_id
  59. // ORDER BY a.edb_info_id ASC `
  60. // _, err = o.Raw(sql, edbInfoIdList).QueryRows(&list)
  61. // return
  62. // }
  63. // EdbInfoCalculateMappingInfo
  64. //
  65. // type EdbInfoCalculateMappingInfo struct {
  66. // EdbInfoCalculateMappingId int `orm:"column(edb_info_calculate_mapping_id);pk"`
  67. // EdbInfoId int `description:"计算指标id"`
  68. // Source int `description:"计算指标来源"`
  69. // SourceName string `description:"计算指标来源名称"`
  70. // EdbCode string `description:"计算指标编码"`
  71. // FromEdbInfoId int `description:"基础指标id"`
  72. // FromEdbCode string `description:"基础指标编码"`
  73. // FromEdbName string `description:"基础指标名称"`
  74. // FromSource int `description:"基础指标来源"`
  75. // FromSourceName string `description:"基础指标来源名称"`
  76. // MoveValue int `description:"领先值"`
  77. // FromTag string `description:"来源指标标签"`
  78. // Sort int `description:"计算指标名称排序"`
  79. // CreateTime time.Time `description:"创建时间"`
  80. // ModifyTime time.Time `description:"修改时间"`
  81. // FromEdbType int `description:"来源指标类型:1:基础指标,2:计算指标"`
  82. // FromEdbInfoType int `description:"来源指标类型: 0-基础指标; 1-预测指标"`
  83. // FromClassifyId int `description:"来源指标分类ID"`
  84. // FromUniqueCode string `description:"来源指标唯一编码"`
  85. // }
  86. type EdbInfoCalculateMappingInfo struct {
  87. EdbInfoCalculateMappingId int `gorm:"column:edb_info_calculate_mapping_id;primaryKey" description:"计算指标映射ID" orm:"column(edb_info_calculate_mapping_id);pk"`
  88. EdbInfoId int `gorm:"column:edb_info_id" description:"计算指标id"`
  89. Source int `gorm:"column:source" description:"计算指标来源"`
  90. SourceName string `gorm:"column:source_name" description:"计算指标来源名称"`
  91. EdbCode string `gorm:"column:edb_code" description:"计算指标编码"`
  92. FromEdbInfoId int `gorm:"column:from_edb_info_id" description:"基础指标id"`
  93. FromEdbCode string `gorm:"column:from_edb_code" description:"基础指标编码"`
  94. FromEdbName string `gorm:"column:from_edb_name" description:"基础指标名称"`
  95. FromSource int `gorm:"column:from_source" description:"基础指标来源"`
  96. FromSourceName string `gorm:"column:from_source_name" description:"基础指标来源名称"`
  97. MoveValue int `gorm:"column:move_value" description:"领先值"`
  98. FromTag string `gorm:"column:from_tag" description:"来源指标标签"`
  99. Sort int `gorm:"column:sort" description:"计算指标名称排序"`
  100. CreateTime time.Time `gorm:"column:create_time" description:"创建时间"`
  101. ModifyTime time.Time `gorm:"column:modify_time" description:"修改时间"`
  102. FromEdbType int `gorm:"column:from_edb_type" description:"来源指标类型:1:基础指标,2:计算指标"`
  103. FromEdbInfoType int `gorm:"column:from_edb_info_type" description:"来源指标类型: 0-基础指标; 1-预测指标"`
  104. FromClassifyId int `gorm:"column:from_classify_id" description:"来源指标分类ID"`
  105. FromUniqueCode string `gorm:"column:from_unique_code" description:"来源指标唯一编码"`
  106. }
  107. // GetEdbInfoCalculateMappingListByEdbInfoId 根据生成的指标id获取来源的指标id列表
  108. func GetEdbInfoCalculateMappingListByEdbInfoId(edbInfoId int) (items []*EdbInfoCalculateMappingInfo, err error) {
  109. o := global.DmSQL["data"]
  110. 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
  111. INNER JOIN edb_info AS b ON a.from_edb_info_id=b.edb_info_id
  112. WHERE a.edb_info_id=? `
  113. err = o.Raw(sql, edbInfoId).Scan(&items).Error
  114. return
  115. }
  116. // GetEdbInfoCalculateMappingListByEdbInfoId 根据生成的指标id获取来源的指标id列表
  117. // func GetEdbInfoCalculateMappingListByEdbInfoId(edbInfoId int) (items []*EdbInfoCalculateMappingInfo, err error) {
  118. // o := orm.NewOrmUsingDB("data")
  119. // 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
  120. // INNER JOIN edb_info AS b ON a.from_edb_info_id=b.edb_info_id
  121. // WHERE a.edb_info_id=? `
  122. // _, err = o.Raw(sql, edbInfoId).QueryRows(&items)
  123. // return
  124. // }