edb_data_base.go 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. package data_manage
  2. import (
  3. "errors"
  4. "fmt"
  5. "github.com/beego/beego/v2/client/orm"
  6. "hongze/hongze_task/utils"
  7. "strconv"
  8. "time"
  9. )
  10. func GetEdbDataTableName(source int) (tableName string) {
  11. switch source {
  12. case utils.DATA_SOURCE_THS:
  13. tableName = "edb_data_ths"
  14. case utils.DATA_SOURCE_WIND:
  15. tableName = "edb_data_wind"
  16. case utils.DATA_SOURCE_PB, utils.DATA_SOURCE_PB_FINANCE:
  17. tableName = "edb_data_pb"
  18. case utils.DATA_SOURCE_CALCULATE:
  19. tableName = "edb_data_calculate"
  20. case utils.DATA_SOURCE_CALCULATE_LJZZY:
  21. tableName = "edb_data_calculate_ljzzy"
  22. case utils.DATA_SOURCE_CALCULATE_TBZ:
  23. tableName = "edb_data_calculate_tbz"
  24. case utils.DATA_SOURCE_CALCULATE_TCZ:
  25. tableName = "edb_data_calculate_tcz"
  26. case utils.DATA_SOURCE_CALCULATE_NSZYDPJJS:
  27. tableName = "edb_data_calculate_nszydpjjs"
  28. case utils.DATA_SOURCE_MANUAL:
  29. tableName = "edb_data_manual"
  30. case utils.DATA_SOURCE_LZ:
  31. tableName = "edb_data_lz"
  32. case utils.DATA_SOURCE_YS:
  33. tableName = "edb_data_ys"
  34. case utils.DATA_SOURCE_CALCULATE_HBZ:
  35. tableName = "edb_data_calculate_hbz"
  36. case utils.DATA_SOURCE_CALCULATE_HCZ:
  37. tableName = "edb_data_calculate_hcz"
  38. case utils.DATA_SOURCE_CALCULATE_BP:
  39. tableName = "edb_data_calculate_bp"
  40. case utils.DATA_SOURCE_GL:
  41. tableName = "edb_data_gl"
  42. case utils.DATA_SOURCE_ZZ:
  43. tableName = "edb_data_zz"
  44. case utils.DATA_SOURCE_DL:
  45. tableName = "edb_data_dl"
  46. case utils.DATA_SOURCE_SH:
  47. tableName = "edb_data_sh"
  48. case utils.DATA_SOURCE_CFFEX:
  49. tableName = "edb_data_cffex"
  50. case utils.DATA_SOURCE_SHFE:
  51. tableName = "edb_data_ine"
  52. case utils.DATA_SOURCE_GIE:
  53. tableName = "edb_data_gie"
  54. case utils.DATA_SOURCE_CALCULATE_ZJPJ:
  55. tableName = "edb_data_calculate_zjpj"
  56. case utils.DATA_SOURCE_CALCULATE_TIME_SHIFT:
  57. tableName = "edb_data_calculate_time_shift"
  58. case utils.DATA_SOURCE_CALCULATE_LJZTBPJ:
  59. tableName = "edb_data_calculate_ljztbpj"
  60. case utils.DATA_SOURCE_LT:
  61. tableName = "edb_data_lt"
  62. case utils.DATA_SOURCE_COAL:
  63. tableName = "edb_data_coal"
  64. case utils.DATA_SOURCE_GOOGLE_TRAVEL:
  65. tableName = "edb_data_google_travel"
  66. case utils.DATA_SOURCE_PREDICT_CALCULATE:
  67. tableName = "edb_data_predict_calculate"
  68. case utils.DATA_SOURCE_PREDICT_CALCULATE_TBZ:
  69. tableName = "edb_data_predict_calculate_tbz"
  70. case utils.DATA_SOURCE_PREDICT_CALCULATE_TCZ:
  71. tableName = "edb_data_predict_calculate_tcz"
  72. case utils.DATA_SOURCE_MYSTEEL_CHEMICAL:
  73. tableName = "edb_data_mysteel_chemical"
  74. case utils.DATA_SOURCE_CALCULATE_CJJX:
  75. tableName = "edb_data_calculate_cjjx"
  76. case utils.DATA_SOURCE_EIA_STEO:
  77. tableName = "edb_data_eia_steo"
  78. case utils.DATA_SOURCE_PREDICT_CALCULATE_LJZZY:
  79. tableName = "edb_data_predict_calculate_ljzzy"
  80. case utils.DATA_SOURCE_PREDICT_CALCULATE_TIME_SHIFT:
  81. tableName = "edb_data_predict_calculate_time_shift"
  82. case utils.DATA_SOURCE_PREDICT_CALCULATE_ZJPJ:
  83. tableName = "edb_data_predict_calculate_zjpj"
  84. case utils.DATA_SOURCE_PREDICT_CALCULATE_LJZTBPJ:
  85. tableName = "edb_data_predict_calculate_ljztbpj"
  86. case utils.DATA_SOURCE_PREDICT_CALCULATE_NHCC:
  87. tableName = "edb_data_predict_calculate_nhcc"
  88. case utils.DATA_SOURCE_PREDICT_CALCULATE_CJJX:
  89. tableName = "edb_data_predict_calculate_cjjx"
  90. case utils.DATA_SOURCE_PREDICT_CALCULATE_HBZ:
  91. tableName = "edb_data_predict_calculate_hbz"
  92. case utils.DATA_SOURCE_PREDICT_CALCULATE_HCZ:
  93. tableName = "edb_data_predict_calculate_hcz"
  94. case utils.DATA_SOURCE_PREDICT_CALCULATE_BP:
  95. tableName = "edb_data_predict_calculate_bp"
  96. default:
  97. tableName = ""
  98. errors.New("无效的渠道:" + strconv.Itoa(source))
  99. return
  100. }
  101. return
  102. }
  103. func GetEdbInfoCalculateTableName(source int) (tableName string) {
  104. switch source {
  105. case utils.DATA_SOURCE_CALCULATE:
  106. tableName = "edb_info_calculate"
  107. case utils.DATA_SOURCE_CALCULATE_LJZZY:
  108. tableName = "edb_info_calculate_ljzzy"
  109. case utils.DATA_SOURCE_CALCULATE_TBZ:
  110. tableName = "edb_info_calculate_tbz"
  111. case utils.DATA_SOURCE_CALCULATE_TCZ:
  112. tableName = "edb_info_calculate_tcz"
  113. case utils.DATA_SOURCE_CALCULATE_NSZYDPJJS:
  114. tableName = "edb_info_calculate_nszydpjjs"
  115. case utils.DATA_SOURCE_CALCULATE_HBZ:
  116. tableName = "edb_info_calculate_hbz"
  117. case utils.DATA_SOURCE_CALCULATE_HCZ:
  118. tableName = "edb_info_calculate_hcz"
  119. case utils.DATA_SOURCE_CALCULATE_BP:
  120. tableName = "edb_info_calculate_bp"
  121. default:
  122. tableName = ""
  123. errors.New("无效的渠道:" + strconv.Itoa(source))
  124. return
  125. }
  126. return
  127. }
  128. func GetAddSql(edbInfoId, edbCode, dataTime, timestampStr, value string) (addSql string) {
  129. nowStr := time.Now().Format(utils.FormatDateTime)
  130. addSql += "("
  131. addSql += edbInfoId + "," + "'" + edbCode + "'" + "," + "'" + dataTime + "'" + "," + value + "," + "'" + nowStr + "'" +
  132. "," + "'" + nowStr + "'" + "," + "1"
  133. addSql += "," + "'" + timestampStr + "'"
  134. addSql += "),"
  135. return
  136. }
  137. func GetEdbDataBaseByCodeAndDate(source int, edbCode string, startDate string) (count int, err error) {
  138. o := orm.NewOrmUsingDB("data")
  139. tableName := GetEdbDataTableName(source)
  140. sql := ` SELECT COUNT(1) AS count FROM %s WHERE edb_code=? AND data_time=? `
  141. sql = fmt.Sprintf(sql, tableName)
  142. err = o.Raw(sql, edbCode, startDate).QueryRow(&count)
  143. return
  144. }
  145. type EdbDataBase struct {
  146. EdbDataId int `orm:"column(edb_data_id);pk"`
  147. EdbInfoId int
  148. EdbCode string
  149. DataTime string
  150. Value string
  151. Status int
  152. CreateTime time.Time
  153. ModifyTime time.Time
  154. DataTimestamp int64
  155. }