edb_data_base.go 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389
  1. package data_manage
  2. import (
  3. "eta/eta_task/utils"
  4. "strings"
  5. "time"
  6. )
  7. // GetEdbDataTableName 指标数据->存储表
  8. func GetEdbDataTableName(source, subSource int) (tableName string) {
  9. switch source {
  10. case utils.DATA_SOURCE_THS:
  11. tableName = "edb_data_ths"
  12. if subSource == utils.DATA_SUB_SOURCE_DATE {
  13. tableName = "edb_data_ths_ds"
  14. } else {
  15. tableName = "edb_data_ths"
  16. }
  17. case utils.DATA_SOURCE_WIND:
  18. if subSource == utils.DATA_SUB_SOURCE_DATE {
  19. tableName = "edb_data_wind_wsd"
  20. } else {
  21. tableName = "edb_data_wind"
  22. }
  23. case utils.DATA_SOURCE_PB, utils.DATA_SOURCE_PB_FINANCE:
  24. tableName = "edb_data_pb"
  25. case utils.DATA_SOURCE_CALCULATE:
  26. tableName = "edb_data_calculate"
  27. case utils.DATA_SOURCE_CALCULATE_LJZZY:
  28. tableName = "edb_data_calculate_ljzzy"
  29. case utils.DATA_SOURCE_CALCULATE_TBZ:
  30. tableName = "edb_data_calculate_tbz"
  31. case utils.DATA_SOURCE_CALCULATE_TCZ:
  32. tableName = "edb_data_calculate_tcz"
  33. case utils.DATA_SOURCE_CALCULATE_NSZYDPJJS:
  34. tableName = "edb_data_calculate_nszydpjjs"
  35. case utils.DATA_SOURCE_MANUAL:
  36. tableName = "edb_data_manual"
  37. case utils.DATA_SOURCE_LZ:
  38. tableName = "edb_data_lz"
  39. case utils.DATA_SOURCE_YS:
  40. tableName = "edb_data_ys"
  41. case utils.DATA_SOURCE_CALCULATE_HBZ:
  42. tableName = "edb_data_calculate_hbz"
  43. case utils.DATA_SOURCE_CALCULATE_HCZ:
  44. tableName = "edb_data_calculate_hcz"
  45. case utils.DATA_SOURCE_CALCULATE_BP:
  46. tableName = "edb_data_calculate_bp"
  47. case utils.DATA_SOURCE_GL:
  48. tableName = "edb_data_gl"
  49. case utils.DATA_SOURCE_ZZ:
  50. tableName = "edb_data_zz"
  51. case utils.DATA_SOURCE_DL:
  52. tableName = "edb_data_dl"
  53. case utils.DATA_SOURCE_SH:
  54. tableName = "edb_data_sh"
  55. case utils.DATA_SOURCE_CFFEX:
  56. tableName = "edb_data_cffex"
  57. case utils.DATA_SOURCE_SHFE:
  58. tableName = "edb_data_ine"
  59. case utils.DATA_SOURCE_GIE:
  60. tableName = "edb_data_gie"
  61. case utils.DATA_SOURCE_CALCULATE_ZJPJ:
  62. tableName = "edb_data_calculate_zjpj"
  63. case utils.DATA_SOURCE_CALCULATE_TIME_SHIFT:
  64. tableName = "edb_data_calculate_time_shift"
  65. case utils.DATA_SOURCE_CALCULATE_LJZTBPJ:
  66. tableName = "edb_data_calculate_ljztbpj"
  67. case utils.DATA_SOURCE_LT:
  68. tableName = "edb_data_lt"
  69. case utils.DATA_SOURCE_COAL:
  70. tableName = "edb_data_coal"
  71. case utils.DATA_SOURCE_PYTHON:
  72. tableName = "edb_data_python"
  73. case utils.DATA_SOURCE_GOOGLE_TRAVEL:
  74. tableName = "edb_data_google_travel"
  75. case utils.DATA_SOURCE_PREDICT_CALCULATE:
  76. tableName = "edb_data_predict_calculate"
  77. case utils.DATA_SOURCE_PREDICT_CALCULATE_TBZ:
  78. tableName = "edb_data_predict_calculate_tbz"
  79. case utils.DATA_SOURCE_PREDICT_CALCULATE_TCZ:
  80. tableName = "edb_data_predict_calculate_tcz"
  81. case utils.DATA_SOURCE_MYSTEEL_CHEMICAL:
  82. tableName = "edb_data_mysteel_chemical"
  83. case utils.DATA_SOURCE_CALCULATE_CJJX:
  84. tableName = "edb_data_calculate_cjjx"
  85. case utils.DATA_SOURCE_EIA_STEO:
  86. tableName = "edb_data_eia_steo"
  87. case utils.DATA_SOURCE_CALCULATE_NHCC:
  88. tableName = "edb_data_calculate_nhcc"
  89. case utils.DATA_SOURCE_COM_TRADE:
  90. tableName = "edb_data_com_trade"
  91. case utils.DATA_SOURCE_PREDICT_CALCULATE_NSZYDPJJS:
  92. tableName = "edb_data_predict_calculate_nszydpjjs"
  93. case utils.DATA_SOURCE_CALCULATE_ADJUST:
  94. tableName = "edb_data_calculate_adjust"
  95. case utils.DATA_SOURCE_SCI:
  96. tableName = "edb_data_sci"
  97. case utils.DATA_SOURCE_PREDICT_CALCULATE_LJZZY:
  98. tableName = "edb_data_predict_calculate_ljzzy"
  99. case utils.DATA_SOURCE_PREDICT_CALCULATE_TIME_SHIFT:
  100. tableName = "edb_data_predict_calculate_time_shift"
  101. case utils.DATA_SOURCE_PREDICT_CALCULATE_ZJPJ:
  102. tableName = "edb_data_predict_calculate_zjpj"
  103. case utils.DATA_SOURCE_PREDICT_CALCULATE_LJZTBPJ:
  104. tableName = "edb_data_predict_calculate_ljztbpj"
  105. case utils.DATA_SOURCE_PREDICT_CALCULATE_NHCC:
  106. tableName = "edb_data_predict_calculate_nhcc"
  107. case utils.DATA_SOURCE_PREDICT_CALCULATE_CJJX:
  108. tableName = "edb_data_predict_calculate_cjjx"
  109. case utils.DATA_SOURCE_PREDICT_CALCULATE_HBZ:
  110. tableName = "edb_data_predict_calculate_hbz"
  111. case utils.DATA_SOURCE_PREDICT_CALCULATE_HCZ:
  112. tableName = "edb_data_predict_calculate_hcz"
  113. case utils.DATA_SOURCE_PREDICT_CALCULATE_BP:
  114. tableName = "edb_data_predict_calculate_bp"
  115. case utils.DATA_SOURCE_CALCULATE_JP:
  116. tableName = "edb_data_calculate_jp"
  117. case utils.DATA_SOURCE_CALCULATE_NH:
  118. tableName = "edb_data_calculate_nh"
  119. case utils.DATA_SOURCE_CALCULATE_KSZS:
  120. tableName = "edb_data_calculate_kszs"
  121. case utils.DATA_SOURCE_PREDICT_CALCULATE_JP:
  122. tableName = "edb_data_predict_calculate_jp"
  123. case utils.DATA_SOURCE_PREDICT_CALCULATE_NH:
  124. tableName = "edb_data_predict_calculate_nh"
  125. case utils.DATA_SOURCE_PREDICT_CALCULATE_KSZS:
  126. tableName = "edb_data_predict_calculate_kszs"
  127. case utils.DATA_SOURCE_BAIINFO:
  128. tableName = "edb_data_baiinfo"
  129. case utils.DATA_SOURCE_STOCK_PLANT:
  130. tableName = "edb_data_stock_plant"
  131. case utils.DATA_SOURCE_CALCULATE_CORRELATION:
  132. tableName = "edb_data_calculate_correlation"
  133. case utils.DATA_SOURCE_NATIONAL_STATISTICS:
  134. tableName = "edb_data_national_statistics"
  135. case utils.DATA_SOURCE_CALCULATE_LJZZJ: //累计值转季 -> 61
  136. tableName = "edb_data_calculate_ljzzj"
  137. case utils.DATA_SOURCE_CALCULATE_LJZ: //累计值 -> 62
  138. tableName = "edb_data_calculate_ljz"
  139. case utils.DATA_SOURCE_CALCULATE_LJZNCZJ: //累计值(年初至今) -> 63
  140. tableName = "edb_data_calculate_ljznczj"
  141. case utils.DATA_SOURCE_PREDICT_CALCULATE_LJZZJ: // 预测指标 - 累计值 -> 65
  142. tableName = "edb_data_predict_calculate_ljzzj"
  143. case utils.DATA_SOURCE_PREDICT_CALCULATE_LJZ: //预测指标 - 累计值转季->64
  144. tableName = "edb_data_predict_calculate_ljz"
  145. case utils.DATA_SOURCE_PREDICT_CALCULATE_LJZNCZJ: //预测指标 - 累计值(年初至今) -> 66
  146. tableName = "edb_data_predict_calculate_ljznczj"
  147. case utils.DATA_SOURCE_CALCULATE_STANDARD_DEVIATION: //标准差->67
  148. tableName = "edb_data_calculate_standard_deviation"
  149. case utils.DATA_SOURCE_CALCULATE_PERCENTILE: //百分位->68
  150. tableName = "edb_data_calculate_percentile"
  151. case utils.DATA_SOURCE_PREDICT_CALCULATE_STANDARD_DEVIATION: //预测标准差->69
  152. tableName = "edb_data_predict_ccalculate_standard_deviation"
  153. case utils.DATA_SOURCE_PREDICT_CALCULATE_PERCENTILE: //预测百分位->70
  154. tableName = "edb_data_predict_ccalculate_percentile"
  155. case utils.DATA_SOURCE_FUBAO:
  156. tableName = "edb_data_fubao"
  157. case utils.DATA_SOURCE_CALCULATE_ZSXY:
  158. tableName = "edb_data_calculate_zsxy" // 指数修匀->72
  159. case utils.DATA_SOURCE_PREDICT_CALCULATE_ZSXY:
  160. tableName = "edb_data_predict_calculate_zsxy" // 预测指数修匀->73
  161. case utils.DATA_SOURCE_CALCULATE_ZDYFX:
  162. tableName = "edb_data_calculate_zdyfx" // 自定义分析->74
  163. case utils.DATA_SOURCE_CALCULATE_RJZ: //日均值75
  164. tableName = "edb_data_calculate_rjz"
  165. default:
  166. edbSource := EdbSourceIdMap[source]
  167. if edbSource != nil {
  168. tableName = edbSource.TableName
  169. }
  170. }
  171. return
  172. }
  173. // GetSourceAndSubSourceTableName 存储表->指标数据
  174. func GetSourceAndSubSourceTableName(tableName, edbCode string) (source, subSource int) {
  175. switch tableName {
  176. case "edb_data_ths":
  177. source = utils.DATA_SOURCE_THS
  178. case "edb_data_ths_ds":
  179. source = utils.DATA_SOURCE_THS
  180. subSource = utils.DATA_SUB_SOURCE_DATE
  181. case "edb_data_wind":
  182. source = utils.DATA_SOURCE_WIND
  183. case "edb_data_wind_wsd":
  184. source = utils.DATA_SOURCE_WIND
  185. subSource = utils.DATA_SUB_SOURCE_DATE
  186. case "edb_data_pb":
  187. source = utils.DATA_SOURCE_PB
  188. // 彭博财务
  189. if strings.Contains(edbCode, "&&") {
  190. source = utils.DATA_SOURCE_PB_FINANCE
  191. }
  192. case "edb_data_calculate":
  193. source = utils.DATA_SOURCE_CALCULATE
  194. case "edb_data_calculate_ljzzy":
  195. source = utils.DATA_SOURCE_CALCULATE_LJZZY
  196. case "edb_data_calculate_tbz":
  197. source = utils.DATA_SOURCE_CALCULATE_TBZ
  198. case "edb_data_calculate_tcz":
  199. source = utils.DATA_SOURCE_CALCULATE_TCZ
  200. case "edb_data_calculate_nszydpjjs":
  201. source = utils.DATA_SOURCE_CALCULATE_NSZYDPJJS
  202. case "edb_data_manual":
  203. source = utils.DATA_SOURCE_MANUAL
  204. case "edb_data_lz":
  205. source = utils.DATA_SOURCE_LZ
  206. case "edb_data_ys":
  207. source = utils.DATA_SOURCE_YS
  208. case "edb_data_calculate_hbz":
  209. source = utils.DATA_SOURCE_CALCULATE_HBZ
  210. case "edb_data_calculate_hcz":
  211. source = utils.DATA_SOURCE_CALCULATE_HCZ
  212. case "edb_data_calculate_bp":
  213. source = utils.DATA_SOURCE_CALCULATE_BP
  214. case "edb_data_gl":
  215. source = utils.DATA_SOURCE_GL
  216. case "edb_data_zz":
  217. source = utils.DATA_SOURCE_ZZ
  218. case "edb_data_dl":
  219. source = utils.DATA_SOURCE_DL
  220. case "edb_data_sh":
  221. source = utils.DATA_SOURCE_SH
  222. case "edb_data_cffex":
  223. source = utils.DATA_SOURCE_CFFEX
  224. case "edb_data_ine":
  225. source = utils.DATA_SOURCE_SHFE
  226. case "edb_data_gie":
  227. source = utils.DATA_SOURCE_GIE
  228. case "edb_data_calculate_zjpj":
  229. source = utils.DATA_SOURCE_CALCULATE_ZJPJ
  230. case "edb_data_calculate_time_shift":
  231. source = utils.DATA_SOURCE_CALCULATE_TIME_SHIFT
  232. case "edb_data_calculate_ljztbpj":
  233. source = utils.DATA_SOURCE_CALCULATE_LJZTBPJ
  234. case "edb_data_lt":
  235. source = utils.DATA_SOURCE_LT
  236. case "edb_data_coal":
  237. source = utils.DATA_SOURCE_COAL
  238. case "edb_data_python":
  239. source = utils.DATA_SOURCE_PYTHON
  240. case "edb_data_google_travel":
  241. source = utils.DATA_SOURCE_GOOGLE_TRAVEL
  242. case "edb_data_predict_calculate":
  243. source = utils.DATA_SOURCE_PREDICT_CALCULATE
  244. case "edb_data_predict_calculate_tbz":
  245. source = utils.DATA_SOURCE_PREDICT_CALCULATE_TBZ
  246. case "edb_data_predict_calculate_tcz":
  247. source = utils.DATA_SOURCE_PREDICT_CALCULATE_TCZ
  248. case "edb_data_mysteel_chemical":
  249. source = utils.DATA_SOURCE_MYSTEEL_CHEMICAL
  250. case "edb_data_calculate_cjjx":
  251. source = utils.DATA_SOURCE_CALCULATE_CJJX
  252. case "edb_data_eia_steo":
  253. source = utils.DATA_SOURCE_EIA_STEO
  254. case "edb_data_calculate_nhcc":
  255. source = utils.DATA_SOURCE_CALCULATE_NHCC
  256. case "edb_data_com_trade":
  257. source = utils.DATA_SOURCE_COM_TRADE
  258. case "edb_data_predict_calculate_nszydpjjs":
  259. source = utils.DATA_SOURCE_PREDICT_CALCULATE_NSZYDPJJS
  260. case "edb_data_calculate_adjust":
  261. source = utils.DATA_SOURCE_CALCULATE_ADJUST
  262. case "edb_data_sci":
  263. source = utils.DATA_SOURCE_SCI
  264. case "edb_data_predict_calculate_ljzzy":
  265. source = utils.DATA_SOURCE_PREDICT_CALCULATE_LJZZY
  266. case "edb_data_predict_calculate_time_shift":
  267. source = utils.DATA_SOURCE_PREDICT_CALCULATE_TIME_SHIFT
  268. case "edb_data_predict_calculate_zjpj":
  269. source = utils.DATA_SOURCE_PREDICT_CALCULATE_ZJPJ
  270. case "edb_data_predict_calculate_ljztbpj":
  271. source = utils.DATA_SOURCE_PREDICT_CALCULATE_LJZTBPJ
  272. case "edb_data_predict_calculate_nhcc":
  273. source = utils.DATA_SOURCE_PREDICT_CALCULATE_NHCC
  274. case "edb_data_predict_calculate_cjjx":
  275. source = utils.DATA_SOURCE_PREDICT_CALCULATE_CJJX
  276. case "edb_data_predict_calculate_hbz":
  277. source = utils.DATA_SOURCE_PREDICT_CALCULATE_HBZ
  278. case "edb_data_predict_calculate_hcz":
  279. source = utils.DATA_SOURCE_PREDICT_CALCULATE_HCZ
  280. case "edb_data_predict_calculate_bp":
  281. source = utils.DATA_SOURCE_PREDICT_CALCULATE_BP
  282. case "edb_data_calculate_jp":
  283. source = utils.DATA_SOURCE_CALCULATE_JP
  284. case "edb_data_calculate_nh":
  285. source = utils.DATA_SOURCE_CALCULATE_NH
  286. case "edb_data_calculate_kszs":
  287. source = utils.DATA_SOURCE_CALCULATE_KSZS
  288. case "edb_data_predict_calculate_jp":
  289. source = utils.DATA_SOURCE_PREDICT_CALCULATE_JP
  290. case "edb_data_predict_calculate_nh":
  291. source = utils.DATA_SOURCE_PREDICT_CALCULATE_NH
  292. case "edb_data_predict_calculate_kszs":
  293. source = utils.DATA_SOURCE_PREDICT_CALCULATE_KSZS
  294. case "edb_data_baiinfo":
  295. source = utils.DATA_SOURCE_BAIINFO
  296. case "edb_data_stock_plant":
  297. source = utils.DATA_SOURCE_STOCK_PLANT
  298. case "edb_data_calculate_correlation":
  299. source = utils.DATA_SOURCE_CALCULATE_CORRELATION
  300. case "edb_data_national_statistics":
  301. source = utils.DATA_SOURCE_NATIONAL_STATISTICS
  302. case "edb_data_calculate_ljzzj": //累计值转季 -> 61
  303. source = utils.DATA_SOURCE_CALCULATE_LJZZJ
  304. case "edb_data_calculate_ljz": //累计值 -> 62
  305. source = utils.DATA_SOURCE_CALCULATE_LJZ
  306. case "edb_data_calculate_ljznczj": //累计值(年初至今) -> 63
  307. source = utils.DATA_SOURCE_CALCULATE_LJZNCZJ
  308. case "edb_data_predict_calculate_ljzzj": // 预测指标 - 累计值 -> 65
  309. source = utils.DATA_SOURCE_PREDICT_CALCULATE_LJZZJ
  310. case "edb_data_predict_calculate_ljz": //预测指标 - 累计值转季->64
  311. source = utils.DATA_SOURCE_PREDICT_CALCULATE_LJZ
  312. case "edb_data_predict_calculate_ljznczj": //预测指标 - 累计值(年初至今) -> 66
  313. source = utils.DATA_SOURCE_PREDICT_CALCULATE_LJZNCZJ
  314. case "edb_data_calculate_standard_deviation": //标准差->67
  315. source = utils.DATA_SOURCE_CALCULATE_STANDARD_DEVIATION
  316. case "edb_data_calculate_percentile": //百分位->68
  317. source = utils.DATA_SOURCE_CALCULATE_PERCENTILE
  318. case "edb_data_predict_ccalculate_standard_deviation": //预测标准差->69
  319. source = utils.DATA_SOURCE_PREDICT_CALCULATE_STANDARD_DEVIATION
  320. case "edb_data_predict_ccalculate_percentile": //预测百分位->70
  321. source = utils.DATA_SOURCE_PREDICT_CALCULATE_PERCENTILE
  322. case "edb_data_fubao":
  323. source = utils.DATA_SOURCE_FUBAO
  324. case "edb_data_calculate_zsxy":
  325. source = utils.DATA_SOURCE_CALCULATE_ZSXY // 指数修匀->72
  326. case "edb_data_predict_calculate_zsxy":
  327. source = utils.DATA_SOURCE_PREDICT_CALCULATE_ZSXY // 预测指数修匀->73
  328. case "edb_data_calculate_zdyfx":
  329. source = utils.DATA_SOURCE_CALCULATE_ZDYFX // 自定义分析->74
  330. case "edb_data_calculate_rjz": //日均值75
  331. source = utils.DATA_SOURCE_CALCULATE_RJZ
  332. default:
  333. edbSource := EdbTableNameSourceMap[tableName]
  334. if edbSource != nil {
  335. source = edbSource.EdbSourceId
  336. }
  337. }
  338. return
  339. }
  340. func GetEdbInfoCalculateTableName(source int) (tableName string) {
  341. switch source {
  342. case utils.DATA_SOURCE_CALCULATE:
  343. tableName = "edb_info_calculate"
  344. case utils.DATA_SOURCE_CALCULATE_LJZZY:
  345. tableName = "edb_info_calculate_ljzzy"
  346. case utils.DATA_SOURCE_CALCULATE_TBZ:
  347. tableName = "edb_info_calculate_tbz"
  348. case utils.DATA_SOURCE_CALCULATE_TCZ:
  349. tableName = "edb_info_calculate_tcz"
  350. case utils.DATA_SOURCE_CALCULATE_NSZYDPJJS:
  351. tableName = "edb_info_calculate_nszydpjjs"
  352. case utils.DATA_SOURCE_CALCULATE_HBZ:
  353. tableName = "edb_info_calculate_hbz"
  354. case utils.DATA_SOURCE_CALCULATE_HCZ:
  355. tableName = "edb_info_calculate_hcz"
  356. case utils.DATA_SOURCE_CALCULATE_BP:
  357. tableName = "edb_info_calculate_bp"
  358. default:
  359. tableName = EdbDataTableNameMap[source] // 没有对应的从edb_source中取
  360. return
  361. }
  362. return
  363. }
  364. func GetAddSql(edbInfoId, edbCode, dataTime, timestampStr, value string) (addSql string) {
  365. nowStr := time.Now().Format(utils.FormatDateTime)
  366. addSql += "("
  367. addSql += edbInfoId + "," + "'" + edbCode + "'" + "," + "'" + dataTime + "'" + "," + value + "," + "'" + nowStr + "'" +
  368. "," + "'" + nowStr + "'" + "," + "1"
  369. addSql += "," + "'" + timestampStr + "'"
  370. addSql += "),"
  371. return
  372. }
  373. type EdbDataBase struct {
  374. EdbDataId int `orm:"column(edb_data_id);pk"`
  375. EdbInfoId int
  376. EdbCode string
  377. DataTime string
  378. Value string
  379. Status int
  380. CreateTime time.Time
  381. ModifyTime time.Time
  382. DataTimestamp int64
  383. }