edb_data_base.go 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. package data_manage
  2. import (
  3. "fmt"
  4. "github.com/beego/beego/v2/client/orm"
  5. "hongze/hongze_ETA_mobile_api/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, utils.DATA_SOURCE_PB_FINANCE: //彭博经济数据、彭博财务数据
  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. case utils.DATA_SOURCE_PYTHON:
  64. tableName = "edb_data_python"
  65. case utils.DATA_SOURCE_GOOGLE_TRAVEL:
  66. tableName = "edb_data_google_travel"
  67. case utils.DATA_SOURCE_PREDICT_CALCULATE:
  68. tableName = "edb_data_predict_calculate"
  69. case utils.DATA_SOURCE_PREDICT_CALCULATE_TBZ:
  70. tableName = "edb_data_predict_calculate_tbz"
  71. case utils.DATA_SOURCE_PREDICT_CALCULATE_TCZ:
  72. tableName = "edb_data_predict_calculate_tcz"
  73. case utils.DATA_SOURCE_MYSTEEL_CHEMICAL:
  74. tableName = "edb_data_mysteel_chemical"
  75. case utils.DATA_SOURCE_CALCULATE_CJJX:
  76. tableName = "edb_data_calculate_cjjx"
  77. case utils.DATA_SOURCE_EIA_STEO:
  78. tableName = "edb_data_eia_steo"
  79. case utils.DATA_SOURCE_CALCULATE_NHCC:
  80. tableName = "edb_data_calculate_nhcc"
  81. case utils.DATA_SOURCE_COM_TRADE:
  82. tableName = "edb_data_com_trade"
  83. case utils.DATA_SOURCE_PREDICT_CALCULATE_NSZYDPJJS:
  84. tableName = "edb_data_predict_calculate_nszydpjjs"
  85. case utils.DATA_SOURCE_CALCULATE_ADJUST:
  86. tableName = "edb_data_calculate_adjust"
  87. case utils.DATA_SOURCE_SCI:
  88. tableName = "edb_data_sci"
  89. case utils.DATA_SOURCE_PREDICT_CALCULATE_LJZZY:
  90. tableName = "edb_data_predict_calculate_ljzzy"
  91. case utils.DATA_SOURCE_PREDICT_CALCULATE_TIME_SHIFT:
  92. tableName = "edb_data_predict_calculate_time_shift"
  93. case utils.DATA_SOURCE_PREDICT_CALCULATE_ZJPJ:
  94. tableName = "edb_data_predict_calculate_zjpj"
  95. case utils.DATA_SOURCE_PREDICT_CALCULATE_LJZTBPJ:
  96. tableName = "edb_data_predict_calculate_ljztbpj"
  97. case utils.DATA_SOURCE_PREDICT_CALCULATE_NHCC:
  98. tableName = "edb_data_predict_calculate_nhcc"
  99. case utils.DATA_SOURCE_PREDICT_CALCULATE_CJJX:
  100. tableName = "edb_data_predict_calculate_cjjx"
  101. case utils.DATA_SOURCE_PREDICT_CALCULATE_HBZ:
  102. tableName = "edb_data_predict_calculate_hbz"
  103. case utils.DATA_SOURCE_PREDICT_CALCULATE_HCZ:
  104. tableName = "edb_data_predict_calculate_hcz"
  105. case utils.DATA_SOURCE_PREDICT_CALCULATE_BP:
  106. tableName = "edb_data_predict_calculate_bp"
  107. case utils.DATA_SOURCE_CALCULATE_JP:
  108. tableName = "edb_data_calculate_jp"
  109. case utils.DATA_SOURCE_CALCULATE_NH:
  110. tableName = "edb_data_calculate_nh"
  111. case utils.DATA_SOURCE_CALCULATE_KSZS:
  112. tableName = "edb_data_calculate_kszs"
  113. case utils.DATA_SOURCE_PREDICT_CALCULATE_JP:
  114. tableName = "edb_data_predict_calculate_jp"
  115. case utils.DATA_SOURCE_PREDICT_CALCULATE_NH:
  116. tableName = "edb_data_predict_calculate_nh"
  117. case utils.DATA_SOURCE_PREDICT_CALCULATE_KSZS:
  118. tableName = "edb_data_predict_calculate_kszs"
  119. case utils.DATA_SOURCE_BAIINFO:
  120. tableName = "edb_data_baiinfo"
  121. case utils.DATA_SOURCE_STOCK_PLANT:
  122. tableName = "edb_data_stock_plant"
  123. case utils.DATA_SOURCE_CALCULATE_CORRELATION:
  124. tableName = "edb_data_calculate_correlation"
  125. case utils.DATA_SOURCE_NATIONAL_STATISTICS:
  126. tableName = "edb_data_national_statistics"
  127. case utils.DATA_SOURCE_CALCULATE_LJZZJ: //累计值转季 -> 61
  128. tableName = "edb_data_calculate_ljzzj"
  129. case utils.DATA_SOURCE_CALCULATE_LJZ: //累计值 -> 62
  130. tableName = "edb_data_calculate_ljz"
  131. case utils.DATA_SOURCE_CALCULATE_LJZNCZJ: //累计值(年初至今) -> 63
  132. tableName = "edb_data_calculate_ljznczj"
  133. case utils.DATA_SOURCE_PREDICT_CALCULATE_LJZZJ: // 预测指标 - 累计值 -> 65
  134. tableName = "edb_data_predict_calculate_ljzzj"
  135. case utils.DATA_SOURCE_PREDICT_CALCULATE_LJZ: //预测指标 - 累计值转季->64
  136. tableName = "edb_data_predict_calculate_ljz"
  137. case utils.DATA_SOURCE_PREDICT_CALCULATE_LJZNCZJ: //预测指标 - 累计值(年初至今) -> 66
  138. tableName = "edb_data_predict_calculate_ljznczj"
  139. case utils.DATA_SOURCE_FUBAO: //富宝数据 -> 71
  140. tableName = "edb_data_fubao"
  141. default:
  142. tableName = ""
  143. }
  144. return
  145. }
  146. //计算指标->关联的基础指标表
  147. //func GetEdbInfoCalculateTableName(source int) (tableName string) {
  148. // switch source {
  149. // case utils.DATA_SOURCE_CALCULATE:
  150. // tableName = "edb_info_calculate"
  151. // case utils.DATA_SOURCE_CALCULATE_LJZZY:
  152. // tableName = "edb_info_calculate_ljzzy"
  153. // case utils.DATA_SOURCE_CALCULATE_TBZ:
  154. // tableName = "edb_info_calculate_tbz"
  155. // case utils.DATA_SOURCE_CALCULATE_TCZ:
  156. // tableName = "edb_info_calculate_tcz"
  157. // case utils.DATA_SOURCE_CALCULATE_NSZYDPJJS:
  158. // tableName = "edb_info_calculate_nszydpjjs"
  159. // case utils.DATA_SOURCE_CALCULATE_HBZ:
  160. // tableName = "edb_info_calculate_hbz"
  161. // case utils.DATA_SOURCE_CALCULATE_HCZ:
  162. // tableName = "edb_info_calculate_hcz"
  163. // case utils.DATA_SOURCE_CALCULATE_BP:
  164. // tableName = "edb_info_calculate_bp"
  165. // default:
  166. // tableName = ""
  167. // }
  168. // return
  169. //}
  170. type EdbDataBase struct {
  171. EdbDataId int `orm:"column(edb_data_id);pk"`
  172. EdbInfoId int
  173. EdbCode string
  174. DataTime string
  175. Value string
  176. Status int
  177. CreateTime time.Time
  178. ModifyTime time.Time
  179. DataTimestamp int64
  180. }
  181. func GetEdbDataAllByEdbCode(edbCode string, source, limit int) (items []*EdbInfoSearchData, err error) {
  182. var pars []interface{}
  183. pars = append(pars, edbCode)
  184. o := orm.NewOrmUsingDB("data")
  185. tableName := GetEdbDataTableName(source)
  186. sql := ` SELECT * FROM %s WHERE edb_code=? ORDER BY data_time DESC`
  187. if limit > 0 {
  188. sql += ` LIMIT ? `
  189. pars = append(pars, limit)
  190. }
  191. sql = fmt.Sprintf(sql, tableName)
  192. _, err = o.Raw(sql, pars).QueryRows(&items)
  193. return
  194. }
  195. func GetEdbDataBaseByCodeAndDate(source int, edbCode string, startDate string) (count int, err error) {
  196. o := orm.NewOrmUsingDB("data")
  197. tableName := GetEdbDataTableName(source)
  198. sql := ` SELECT COUNT(1) AS count FROM %s WHERE edb_code=? AND data_time=? `
  199. sql = fmt.Sprintf(sql, tableName)
  200. err = o.Raw(sql, edbCode, startDate).QueryRow(&count)
  201. return
  202. }