edb_data_base.go 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. package data_manage
  2. import (
  3. "fmt"
  4. "hongze/hongze_chart_lib/utils"
  5. "github.com/rdlucklib/rdluck_tools/orm"
  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. default:
  60. tableName = ""
  61. }
  62. return
  63. }
  64. //计算指标->关联的基础指标表
  65. //func GetEdbInfoCalculateTableName(source int) (tableName string) {
  66. // switch source {
  67. // case utils.DATA_SOURCE_CALCULATE:
  68. // tableName = "edb_info_calculate"
  69. // case utils.DATA_SOURCE_CALCULATE_LJZZY:
  70. // tableName = "edb_info_calculate_ljzzy"
  71. // case utils.DATA_SOURCE_CALCULATE_TBZ:
  72. // tableName = "edb_info_calculate_tbz"
  73. // case utils.DATA_SOURCE_CALCULATE_TCZ:
  74. // tableName = "edb_info_calculate_tcz"
  75. // case utils.DATA_SOURCE_CALCULATE_NSZYDPJJS:
  76. // tableName = "edb_info_calculate_nszydpjjs"
  77. // case utils.DATA_SOURCE_CALCULATE_HBZ:
  78. // tableName = "edb_info_calculate_hbz"
  79. // case utils.DATA_SOURCE_CALCULATE_HCZ:
  80. // tableName = "edb_info_calculate_hcz"
  81. // case utils.DATA_SOURCE_CALCULATE_BP:
  82. // tableName = "edb_info_calculate_bp"
  83. // default:
  84. // tableName = ""
  85. // }
  86. // return
  87. //}
  88. type EdbDataBase struct {
  89. EdbDataId int `orm:"column(edb_data_id);pk"`
  90. EdbInfoId int
  91. EdbCode string
  92. DataTime string
  93. Value string
  94. Status int
  95. CreateTime time.Time
  96. ModifyTime time.Time
  97. DataTimestamp int64
  98. }
  99. func GetEdbDataAllByEdbCode(edbCode string, source, limit int) (items []*EdbInfoSearchData, err error) {
  100. var pars []interface{}
  101. pars = append(pars, edbCode)
  102. o := orm.NewOrm()
  103. o.Using("data")
  104. tableName := GetEdbDataTableName(source)
  105. sql := ` SELECT * FROM %s WHERE edb_code=? ORDER BY data_time DESC`
  106. if limit > 0 {
  107. sql += ` LIMIT ? `
  108. pars = append(pars, limit)
  109. }
  110. sql = fmt.Sprintf(sql, tableName)
  111. _, err = o.Raw(sql, pars).QueryRows(&items)
  112. return
  113. }
  114. func GetEdbDataBaseByCodeAndDate(source int, edbCode string, startDate string) (count int, err error) {
  115. o := orm.NewOrm()
  116. o.Using("data")
  117. tableName := GetEdbDataTableName(source)
  118. sql := ` SELECT COUNT(1) AS count FROM %s WHERE edb_code=? AND data_time=? `
  119. sql = fmt.Sprintf(sql, tableName)
  120. err = o.Raw(sql, edbCode, startDate).QueryRow(&count)
  121. return
  122. }