edb_data_base.go 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. package data_manage
  2. import (
  3. "fmt"
  4. "github.com/rdlucklib/rdluck_tools/orm"
  5. "hongze/hongze_chart_lib/utils"
  6. "time"
  7. )
  8. //指标数据->存储表
  9. func GetEdbDataTableName(source int) (tableName string) {
  10. switch source {
  11. case utils.DATA_SOURCE_THS:
  12. tableName = "edb_data_ths"
  13. case utils.DATA_SOURCE_WIND:
  14. tableName = "edb_data_wind"
  15. case utils.DATA_SOURCE_PB:
  16. tableName = "edb_data_pb"
  17. case utils.DATA_SOURCE_CALCULATE:
  18. tableName = "edb_data_calculate"
  19. case utils.DATA_SOURCE_CALCULATE_LJZZY:
  20. tableName = "edb_data_calculate_ljzzy"
  21. case utils.DATA_SOURCE_CALCULATE_TBZ:
  22. tableName = "edb_data_calculate_tbz"
  23. case utils.DATA_SOURCE_CALCULATE_TCZ:
  24. tableName = "edb_data_calculate_tcz"
  25. case utils.DATA_SOURCE_CALCULATE_NSZYDPJJS:
  26. tableName = "edb_data_calculate_nszydpjjs"
  27. case utils.DATA_SOURCE_MANUAL:
  28. tableName = "edb_data_manual"
  29. case utils.DATA_SOURCE_LZ:
  30. tableName = "edb_data_lz"
  31. case utils.DATA_SOURCE_YS:
  32. tableName = "edb_data_ys"
  33. case utils.DATA_SOURCE_CALCULATE_HBZ:
  34. tableName = "edb_data_calculate_hbz"
  35. case utils.DATA_SOURCE_CALCULATE_HCZ:
  36. tableName = "edb_data_calculate_hcz"
  37. case utils.DATA_SOURCE_CALCULATE_BP:
  38. tableName = "edb_data_calculate_bp"
  39. case utils.DATA_SOURCE_GL:
  40. tableName = "edb_data_gl"
  41. case utils.DATA_SOURCE_ZZ:
  42. tableName = "edb_data_zz"
  43. case utils.DATA_SOURCE_DL:
  44. tableName = "edb_data_dl"
  45. case utils.DATA_SOURCE_SH:
  46. tableName = "edb_data_sh"
  47. case utils.DATA_SOURCE_CFFEX:
  48. tableName = "edb_data_cffex"
  49. case utils.DATA_SOURCE_SHFE:
  50. tableName = "edb_data_ine"
  51. case utils.DATA_SOURCE_GIE:
  52. tableName = "edb_data_gie"
  53. case utils.DATA_SOURCE_CALCULATE_ZJPJ:
  54. tableName = "edb_data_calculate_zjpj"
  55. case utils.DATA_SOURCE_CALCULATE_TIME_SHIFT:
  56. tableName = "edb_data_calculate_time_shift"
  57. case utils.DATA_SOURCE_CALCULATE_LJZTBPJ:
  58. tableName = "edb_data_calculate_ljztbpj"
  59. case utils.DATA_SOURCE_LT:
  60. tableName = "edb_data_lt"
  61. case utils.DATA_SOURCE_COAL:
  62. tableName = "edb_data_coal"
  63. default:
  64. tableName = ""
  65. }
  66. return
  67. }
  68. //计算指标->关联的基础指标表
  69. //func GetEdbInfoCalculateTableName(source int) (tableName string) {
  70. // switch source {
  71. // case utils.DATA_SOURCE_CALCULATE:
  72. // tableName = "edb_info_calculate"
  73. // case utils.DATA_SOURCE_CALCULATE_LJZZY:
  74. // tableName = "edb_info_calculate_ljzzy"
  75. // case utils.DATA_SOURCE_CALCULATE_TBZ:
  76. // tableName = "edb_info_calculate_tbz"
  77. // case utils.DATA_SOURCE_CALCULATE_TCZ:
  78. // tableName = "edb_info_calculate_tcz"
  79. // case utils.DATA_SOURCE_CALCULATE_NSZYDPJJS:
  80. // tableName = "edb_info_calculate_nszydpjjs"
  81. // case utils.DATA_SOURCE_CALCULATE_HBZ:
  82. // tableName = "edb_info_calculate_hbz"
  83. // case utils.DATA_SOURCE_CALCULATE_HCZ:
  84. // tableName = "edb_info_calculate_hcz"
  85. // case utils.DATA_SOURCE_CALCULATE_BP:
  86. // tableName = "edb_info_calculate_bp"
  87. // default:
  88. // tableName = ""
  89. // }
  90. // return
  91. //}
  92. type EdbDataBase struct {
  93. EdbDataId int `orm:"column(edb_data_id);pk"`
  94. EdbInfoId int
  95. EdbCode string
  96. DataTime string
  97. Value string
  98. Status int
  99. CreateTime time.Time
  100. ModifyTime time.Time
  101. DataTimestamp int64
  102. }
  103. func GetEdbDataAllByEdbCode(edbCode string, source, limit int) (items []*EdbInfoSearchData, err error) {
  104. var pars []interface{}
  105. pars = append(pars, edbCode)
  106. o := orm.NewOrm()
  107. o.Using("data")
  108. tableName := GetEdbDataTableName(source)
  109. sql := ` SELECT * FROM %s WHERE edb_code=? ORDER BY data_time DESC`
  110. if limit > 0 {
  111. sql += ` LIMIT ? `
  112. pars = append(pars, limit)
  113. }
  114. sql = fmt.Sprintf(sql, tableName)
  115. _, err = o.Raw(sql, pars).QueryRows(&items)
  116. return
  117. }
  118. func GetEdbDataBaseByCodeAndDate(source int, edbCode string, startDate string) (count int, err error) {
  119. o := orm.NewOrm()
  120. o.Using("data")
  121. tableName := GetEdbDataTableName(source)
  122. sql := ` SELECT COUNT(1) AS count FROM %s WHERE edb_code=? AND data_time=? `
  123. sql = fmt.Sprintf(sql, tableName)
  124. err = o.Raw(sql, edbCode, startDate).QueryRow(&count)
  125. return
  126. }