edb_data_base.go 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. package data_manage
  2. import (
  3. "fmt"
  4. "github.com/beego/beego/v2/client/orm"
  5. "hongze/hz_crm_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_CALCULATE_STANDARD_DEVIATION: //标准差->67
  140. tableName = "edb_data_calculate_standard_deviation"
  141. case utils.DATA_SOURCE_CALCULATE_PERCENTILE: //百分位->68
  142. tableName = "edb_data_calculate_percentile"
  143. case utils.DATA_SOURCE_PREDICT_CALCULATE_STANDARD_DEVIATION: //预测标准差->69
  144. tableName = "edb_data_predict_ccalculate_standard_deviation"
  145. case utils.DATA_SOURCE_PREDICT_CALCULATE_PERCENTILE: //预测百分位->70
  146. tableName = "edb_data_predict_ccalculate_percentile"
  147. case utils.DATA_SOURCE_FUBAO: //富宝-71
  148. tableName = "edb_data_fubao"
  149. default:
  150. tableName = ""
  151. }
  152. return
  153. }
  154. //计算指标->关联的基础指标表
  155. //func GetEdbInfoCalculateTableName(source int) (tableName string) {
  156. // switch source {
  157. // case utils.DATA_SOURCE_CALCULATE:
  158. // tableName = "edb_info_calculate"
  159. // case utils.DATA_SOURCE_CALCULATE_LJZZY:
  160. // tableName = "edb_info_calculate_ljzzy"
  161. // case utils.DATA_SOURCE_CALCULATE_TBZ:
  162. // tableName = "edb_info_calculate_tbz"
  163. // case utils.DATA_SOURCE_CALCULATE_TCZ:
  164. // tableName = "edb_info_calculate_tcz"
  165. // case utils.DATA_SOURCE_CALCULATE_NSZYDPJJS:
  166. // tableName = "edb_info_calculate_nszydpjjs"
  167. // case utils.DATA_SOURCE_CALCULATE_HBZ:
  168. // tableName = "edb_info_calculate_hbz"
  169. // case utils.DATA_SOURCE_CALCULATE_HCZ:
  170. // tableName = "edb_info_calculate_hcz"
  171. // case utils.DATA_SOURCE_CALCULATE_BP:
  172. // tableName = "edb_info_calculate_bp"
  173. // default:
  174. // tableName = ""
  175. // }
  176. // return
  177. //}
  178. type EdbDataBase struct {
  179. EdbDataId int `orm:"column(edb_data_id);pk"`
  180. EdbInfoId int
  181. EdbCode string
  182. DataTime string
  183. Value string
  184. Status int
  185. CreateTime time.Time
  186. ModifyTime time.Time
  187. DataTimestamp int64
  188. }
  189. func GetEdbDataAllByEdbCode(edbCode string, source, limit int) (items []*EdbInfoSearchData, err error) {
  190. var pars []interface{}
  191. pars = append(pars, edbCode)
  192. o := orm.NewOrmUsingDB("data")
  193. tableName := GetEdbDataTableName(source)
  194. sql := ` SELECT * FROM %s WHERE edb_code=? ORDER BY data_time DESC`
  195. if limit > 0 {
  196. sql += ` LIMIT ? `
  197. pars = append(pars, limit)
  198. }
  199. sql = fmt.Sprintf(sql, tableName)
  200. _, err = o.Raw(sql, pars).QueryRows(&items)
  201. return
  202. }
  203. func GetEdbDataBaseByCodeAndDate(source int, edbCode string, startDate string) (count int, err error) {
  204. o := orm.NewOrmUsingDB("data")
  205. tableName := GetEdbDataTableName(source)
  206. sql := ` SELECT COUNT(1) AS count FROM %s WHERE edb_code=? AND data_time=? `
  207. sql = fmt.Sprintf(sql, tableName)
  208. err = o.Raw(sql, edbCode, startDate).QueryRow(&count)
  209. return
  210. }