base_from_trade_index.go 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703
  1. package data_manage
  2. import (
  3. "fmt"
  4. "github.com/beego/beego/v2/client/orm"
  5. "github.com/rdlucklib/rdluck_tools/paging"
  6. "time"
  7. )
  8. type BaseFromTradeShanghaiIndex struct {
  9. BaseFromTradeShangHaiIndexId int `orm:"column(base_from_trade_shanghai_index_id);pk"`
  10. Rank int
  11. DealShortName string
  12. DealName string
  13. DealCode string
  14. DealValue string
  15. DealChange string
  16. BuyShortName string
  17. BuyName string
  18. BuyCode string
  19. BuyValue string
  20. BuyChange string
  21. SoldShortName string
  22. SoldName string
  23. SoldCode string
  24. SoldValue string
  25. SoldChange string
  26. Frequency string
  27. ClassifyName string
  28. ClassifyType string
  29. CreateTime time.Time
  30. ModifyTime time.Time
  31. DataTime string
  32. }
  33. type BaseFromTradeCffexIndex struct {
  34. BaseFromTradeCffexIndexId int `orm:"column(base_from_trade_cffex_index_id);pk"`
  35. Rank int
  36. DealShortName string
  37. DealName string
  38. DealCode string
  39. DealValue string
  40. DealChange string
  41. BuyShortName string
  42. BuyName string
  43. BuyCode string
  44. BuyValue string
  45. BuyChange string
  46. SoldShortName string
  47. SoldName string
  48. SoldCode string
  49. SoldValue string
  50. SoldChange string
  51. Frequency string
  52. ClassifyName string
  53. ClassifyType string
  54. CreateTime time.Time
  55. ModifyTime time.Time
  56. DataTime string
  57. }
  58. type BaseFromTradeIneIndex struct {
  59. BaseFromTradeIneIndexId int `orm:"column(base_from_trade_ine_index_id);pk"`
  60. Rank int
  61. DealShortName string
  62. DealName string
  63. DealCode string
  64. DealValue string
  65. DealChange string
  66. BuyShortName string
  67. BuyName string
  68. BuyCode string
  69. BuyValue string
  70. BuyChange string
  71. SoldShortName string
  72. SoldName string
  73. SoldCode string
  74. SoldValue string
  75. SoldChange string
  76. Frequency string
  77. ClassifyName string
  78. ClassifyType string
  79. CreateTime time.Time
  80. ModifyTime time.Time
  81. DataTime string
  82. }
  83. type BaseFromTradeEicIndex struct {
  84. BaseFromEicIndexId int `orm:"column(base_from_eic_index_id);pk"`
  85. Country string
  86. Type string
  87. EicCode string
  88. ShortName string
  89. Name string
  90. Status string
  91. GasDayStartedOn string
  92. GasInStorage string
  93. GasInStorageCode string
  94. Full string
  95. FullCode string
  96. Trend string
  97. TrendCode string
  98. Injection string
  99. InjectionCode string
  100. Withdrawal string
  101. WithdrawalCode string
  102. WorkingGasVolume string
  103. WorkingGasVolumeCode string
  104. InjectionCapacity string
  105. InjectionCapacityCode string
  106. WithdrawalCapacity string
  107. WithdrawalCapacityCode string
  108. Info string
  109. CreateTime time.Time
  110. ModifyTime time.Time
  111. }
  112. func GetBaseFromTradeIndexByParam(exchange, date, classifyName, classifyType string) (list []*BaseFromTradeShanghaiIndex, err error) {
  113. o := orm.NewOrmUsingDB("data")
  114. if classifyName == "" {
  115. sql := "SELECT * FROM base_from_trade_" + exchange + "_index where data_time=?"
  116. _, err = o.Raw(sql, date).QueryRows(&list)
  117. return
  118. } else if classifyType == "" {
  119. sql := "SELECT * FROM base_from_trade_" + exchange + "_index where data_time=? and classify_name=? ORDER BY classify_type,rank"
  120. _, err = o.Raw(sql, date, classifyName).QueryRows(&list)
  121. return
  122. } else {
  123. sql := "SELECT * FROM base_from_trade_" + exchange + "_index where data_time=? and classify_name=? and classify_type=?"
  124. _, err = o.Raw(sql, date, classifyName, classifyType).QueryRows(&list)
  125. return
  126. }
  127. }
  128. func GetExchangeClassify(exchange, dataTime string) (classifyName []string, err error) {
  129. o := orm.NewOrmUsingDB("data")
  130. sql := "SELECT DISTINCT classify_name FROM base_from_trade_" + exchange + "_index where data_time=? ORDER BY CONVERT(classify_name using gbk) DESC"
  131. _, err = o.Raw(sql, dataTime).QueryRows(&classifyName)
  132. return
  133. }
  134. func GetLatestDate(exchange string) (dataTime string, err error) {
  135. o := orm.NewOrmUsingDB("data")
  136. sql := "SELECT data_time FROM base_from_trade_" + exchange + "_index ORDER BY data_time desc limit 1"
  137. err = o.Raw(sql).QueryRow(&dataTime)
  138. return
  139. }
  140. func GetExchangeClassifyContract(exchange, Classify, dataTime string) (classifyName []*string, err error) {
  141. o := orm.NewOrmUsingDB("data")
  142. sql := "SELECT DISTINCT classify_type FROM base_from_trade_" + exchange + "_index where classify_name=? and data_time=?"
  143. _, err = o.Raw(sql, Classify, dataTime).QueryRows(&classifyName)
  144. return
  145. }
  146. func GetContinentEicDate(date string) (data []*BaseFromTradeEicIndex, err error) {
  147. o := orm.NewOrmUsingDB("data")
  148. sql := "SELECT * FROM base_from_trade_eic_index where gas_day_started_on=? and type='continent' "
  149. _, err = o.Raw(sql, date).QueryRows(&data)
  150. return
  151. }
  152. func GetCountryEicDate(date string) (data []*BaseFromTradeEicIndex, err error) {
  153. o := orm.NewOrmUsingDB("data")
  154. sql := "SELECT * FROM base_from_trade_eic_index where gas_day_started_on=? and type='country' "
  155. _, err = o.Raw(sql, date).QueryRows(&data)
  156. return
  157. }
  158. func GetSSOEicDate(date, country string) (data []*BaseFromTradeEicIndex, err error) {
  159. o := orm.NewOrmUsingDB("data")
  160. sql := "SELECT * FROM base_from_trade_eic_index where gas_day_started_on=? and country=? and type='SSO' "
  161. _, err = o.Raw(sql, date, country).QueryRows(&data)
  162. return
  163. }
  164. func GetStorageEicDate(date, country string) (data []*BaseFromTradeEicIndex, err error) {
  165. o := orm.NewOrmUsingDB("data")
  166. sql := "SELECT * FROM base_from_trade_eic_index where gas_day_started_on=? and country=? " +
  167. " and (type='Storage Facility' or type='Storage Group') "
  168. _, err = o.Raw(sql, date, country).QueryRows(&data)
  169. return
  170. }
  171. func GetEicDate() (date []*BaseFromTradeEicIndex, err error) {
  172. o := orm.NewOrmUsingDB("data")
  173. sql := "SELECT * FROM base_from_trade_eic_index ORDER BY gas_day_started_on desc limit 1"
  174. _, err = o.Raw(sql).QueryRows(&date)
  175. return
  176. }
  177. func GetEicHistoryDate(code string) (date []*BaseFromTradeEicIndex, err error) {
  178. o := orm.NewOrmUsingDB("data")
  179. sql := "SELECT * FROM base_from_trade_eic_index WHERE eic_code=? ORDER BY gas_day_started_on desc limit 30"
  180. _, err = o.Raw(sql, code).QueryRows(&date)
  181. return
  182. }
  183. func GetEicHistoryDateByDate(code, startDate, endDate string) (date []*BaseFromTradeEicIndex, err error) {
  184. o := orm.NewOrmUsingDB("data")
  185. sql := "SELECT * FROM base_from_trade_eic_index WHERE eic_code=? and gas_day_started_on between ? and ? ORDER BY gas_day_started_on desc"
  186. _, err = o.Raw(sql, code, startDate, endDate).QueryRows(&date)
  187. return
  188. }
  189. type BaseFromCoalmineJsmIndex struct {
  190. BaseFromCoalmineJsmIndexId int `orm:"column(base_from_coalmine_jsm_index_id);pk"`
  191. IndexName string `description:"持买单量指标名称"`
  192. IndexCode string `description:"持买单量指标编码"`
  193. Exchange string `description:"样本统计类别"`
  194. DealValue string `description:"成交量"`
  195. DataTime string `description:"数据日期"`
  196. Source string `description:"来源"`
  197. Province string `description:"省份"`
  198. Description string `description:"描述"`
  199. Unit string `description:"单位"`
  200. Frequency string `description:"频率"`
  201. CreateTime string `description:"插入时间"`
  202. ModifyTime string `description:"修改时间"`
  203. }
  204. // GetBaseFromCoalmineIndex 查询数据
  205. func GetBaseFromCoalmineIndex(startDate, endDate string) (items []*BaseFromCoalmineJsmIndex, err error) {
  206. o := orm.NewOrmUsingDB("data")
  207. sql := `SELECT * FROM base_from_coalmine_jsm_index WHERE data_time between ? and ? `
  208. _, err = o.Raw(sql, startDate, endDate).QueryRows(&items)
  209. return
  210. }
  211. type BaseFromCoalmineCompanyIndex struct {
  212. BaseFromCoalmineCompanyIndexId int `orm:"column(base_from_coalmine_company_index_id);pk"`
  213. IndexName string `description:"持买单量指标名称"`
  214. IndexCode string `description:"持买单量指标编码"`
  215. DealValue string `description:"成交量"`
  216. DataTime string `description:"数据日期"`
  217. Source string `description:"来源"`
  218. Province string `description:"省份"`
  219. City string `description:"城市"`
  220. GroupName string `description:"集团名称"`
  221. Unit string `description:"单位"`
  222. Frequency string `description:"频率"`
  223. CreateTime string `description:"插入时间"`
  224. ModifyTime string `description:"修改时间"`
  225. }
  226. // GetBaseFromCoalmineCompanyIndex 查询公司指标
  227. func GetBaseFromCoalmineCompanyIndex(startDate, endDate string) (items []*BaseFromCoalmineCompanyIndex, err error) {
  228. o := orm.NewOrmUsingDB("data")
  229. sql := `SELECT * FROM base_from_coalmine_company_index WHERE data_time between ? and ? `
  230. _, err = o.Raw(sql, startDate, endDate).QueryRows(&items)
  231. return
  232. }
  233. // BaseFromCoalmineFirmIndex 煤矿产量周度公司数据表
  234. type BaseFromCoalmineFirmIndex struct {
  235. BaseFromCoalmineFirmIndexID int `orm:"column(base_from_coalmine_firm_index_id);pk"`
  236. IndexName string // 省份/企业名称
  237. IndexCode string // 持买单量指标编码
  238. DataTime string // 指标时间
  239. DealValue string // 数据量
  240. GroupName string // 集团名
  241. Source string // 来源
  242. Unit string // 来源
  243. Frequency string `description:"频率"`
  244. CreateTime string `description:"插入时间"`
  245. ModifyTime string `description:"修改时间"`
  246. }
  247. // 查询指标
  248. func GetBaseFromCoalmineFirmIndex(dataTime string) (items []*BaseFromCoalmineFirmIndex, err error) {
  249. o := orm.NewOrmUsingDB("data")
  250. sql := `SELECT * FROM base_from_coalmine_firm_index WHERE data_time LIKE `
  251. sql = sql + "'" + dataTime + "%" + "'"
  252. _, err = o.Raw(sql).QueryRows(&items)
  253. fmt.Println(sql)
  254. return
  255. }
  256. // BaseFromCoalmineCoastalIndex 沿海八省动力煤用户供耗存数据指标表
  257. type BaseFromCoalmineCoastalIndex struct {
  258. BaseFromCoalmineCoastalIndexID int `orm:"column(base_from_coalmine_coastal_index_id);pk"`
  259. IndexName string // 省份/企业名称
  260. IndexCode string // 持买单量指标编码
  261. DataTime string // 指标时间
  262. DealValue string // 数据量
  263. GroupName string // 地区
  264. Source string // 来源
  265. Unit string //单位
  266. Frequency string `description:"频率"`
  267. CreateTime string `description:"插入时间"`
  268. ModifyTime string `description:"修改时间"`
  269. }
  270. // 查询指标
  271. func GetBaseFromCoalmineCoastalIndex(startDate, endDate string) (items []*BaseFromCoalmineCoastalIndex, err error) {
  272. o := orm.NewOrmUsingDB("data")
  273. sql := `SELECT * FROM base_from_coalmine_coastal_index WHERE data_time between ? and ? `
  274. _, err = o.Raw(sql, startDate, endDate).QueryRows(&items)
  275. return
  276. }
  277. // BaseFromCoalmineInlandIndex 内陆动力煤用户供耗存数据指标表
  278. type BaseFromCoalmineInlandIndex struct {
  279. BaseFromCoalmineInlandIndexID int `orm:"column(base_from_coalmine_inland_index_id);pk"`
  280. IndexName string // 省份/企业名称
  281. IndexCode string // 持买单量指标编码
  282. DataTime string // 指标时间
  283. DealValue string // 数据量
  284. GroupName string // 地区
  285. Source string // 来源
  286. Unit string // 来源
  287. Frequency string `description:"频率"`
  288. CreateTime string `description:"插入时间"`
  289. ModifyTime string `description:"修改时间"`
  290. }
  291. // 查询指标
  292. func GetBaseFromCoalmineInlandIndex(startDate, endDate string) (items []*BaseFromCoalmineInlandIndex, err error) {
  293. o := orm.NewOrmUsingDB("data")
  294. sql := `SELECT * FROM base_from_coalmine_inland_index WHERE data_time between ? and ? `
  295. _, err = o.Raw(sql, startDate, endDate).QueryRows(&items)
  296. return
  297. }
  298. type BaseFromCoalmineClassifyItem struct {
  299. ClassifyId int
  300. ClassifyName string
  301. Child []CoalChild
  302. }
  303. type CoalChild struct {
  304. ClassifyId int
  305. ClassifyName string
  306. }
  307. type CoalmineDataResp struct {
  308. IndexName string
  309. IndexCode string // 持买单量指标编码
  310. Unit string // 来源
  311. Frequency string
  312. ModifyTime string
  313. DataList []DataList
  314. }
  315. type CoalmineDataPageResp struct {
  316. IndexName string
  317. IndexCode string // 持买单量指标编码
  318. Unit string // 来源
  319. Frequency string
  320. ModifyTime string
  321. Paging *paging.PagingItem `description:"分页数据"`
  322. DataList []DataList
  323. }
  324. type CoalmineSingalDataResp struct {
  325. IndexName string
  326. IndexCode string // 持买单量指标编码
  327. Unit string // 来源
  328. GroupId int // 二级id
  329. GroupName string // 二级名称
  330. Frequency string
  331. ModifyTime string
  332. ClassifyId int
  333. DataList []DataList
  334. }
  335. type DataList struct {
  336. Value string
  337. DataTime string
  338. }
  339. type FrequencyResp struct {
  340. Frequency int
  341. }
  342. // GetFrequencyFromCoal 获取指标信息
  343. func GetFrequencyFromCoal(suffix string) (list *string, err error) {
  344. o := orm.NewOrmUsingDB("data")
  345. sql := `SELECT DISTINCT frequency FROM base_from_coalmine_%s `
  346. sql = fmt.Sprintf(sql, suffix)
  347. err = o.Raw(sql).QueryRow(&list)
  348. return
  349. }
  350. // 查询数据
  351. func GetBaseFromCoalmineIndexByFrequency(frequency, groupName string) (items []*BaseFromCoalmineJsmIndex, err error) {
  352. o := orm.NewOrmUsingDB("data")
  353. sql := `SELECT * FROM base_from_coalmine_jsm_index WHERE frequency=? AND province=?`
  354. _, err = o.Raw(sql, frequency, groupName).QueryRows(&items)
  355. return
  356. }
  357. // 查询数据
  358. func GetGroupNameFromCoalmineIndex(suffix string) (items []*string, err error) {
  359. o := orm.NewOrmUsingDB("data")
  360. sql := `SELECT DISTINCT group_name FROM base_from_coalmine_%s `
  361. sql = fmt.Sprintf(sql, suffix)
  362. _, err = o.Raw(sql).QueryRows(&items)
  363. return
  364. }
  365. // 查询数据
  366. func GetProvinceFromCoalmineIndex(suffix string) (items []*string, err error) {
  367. o := orm.NewOrmUsingDB("data")
  368. sql := `SELECT DISTINCT province FROM base_from_coalmine_%s `
  369. sql = fmt.Sprintf(sql, suffix)
  370. _, err = o.Raw(sql).QueryRows(&items)
  371. return
  372. }
  373. // 查询数据
  374. func GetClassifyCoalmineIndexByGroupName(groupName string) (items []*string, err error) {
  375. o := orm.NewOrmUsingDB("data")
  376. sql := `SELECT DISTINCT index_code FROM base_from_coalmine_jsm_index WHERE province=? `
  377. _, err = o.Raw(sql, groupName).QueryRows(&items)
  378. return
  379. }
  380. // 查询数据
  381. func GetPageFromCoalmineIndexByFrequency(frequency, classify string, startSize, pageSize int) (items []*BaseFromCoalmineJsmIndex, err error) {
  382. o := orm.NewOrmUsingDB("data")
  383. sql := `SELECT * FROM base_from_coalmine_jsm_index WHERE frequency=? AND index_code=? ORDER BY data_time DESC LIMIT ?,? `
  384. _, err = o.Raw(sql, frequency, classify, startSize, pageSize).QueryRows(&items)
  385. return
  386. }
  387. // 查询数据
  388. func GetCountFromJsm(indexCode string) (item int, err error) {
  389. o := orm.NewOrmUsingDB("data")
  390. sql := `SELECT COUNT(1) FROM base_from_coalmine_jsm_index WHERE index_code=? `
  391. err = o.Raw(sql, indexCode).QueryRow(&item)
  392. return
  393. }
  394. func GetClassifyCompanyByGroupName(groupName string) (items []*string, err error) {
  395. o := orm.NewOrmUsingDB("data")
  396. sql := `SELECT DISTINCT index_code FROM base_from_coalmine_company_index WHERE group_name=? `
  397. _, err = o.Raw(sql, groupName).QueryRows(&items)
  398. return
  399. }
  400. func GetClassifyJsmByGroupName(groupName string) (items []*string, err error) {
  401. o := orm.NewOrmUsingDB("data")
  402. sql := `SELECT DISTINCT index_code FROM base_from_coalmine_jsm_index WHERE province=? `
  403. _, err = o.Raw(sql, groupName).QueryRows(&items)
  404. return
  405. }
  406. // 查询公司指标
  407. func GetPageFromCoalmineCompanyIndexByFrequency(frequency, classify string, startSize, pageSize int) (items []*BaseFromCoalmineCompanyIndex, err error) {
  408. o := orm.NewOrmUsingDB("data")
  409. sql := `SELECT * FROM base_from_coalmine_company_index WHERE frequency=? AND index_code=? ORDER BY data_time DESC LIMIT ?,? `
  410. _, err = o.Raw(sql, frequency, classify, startSize, pageSize).QueryRows(&items)
  411. return
  412. }
  413. func GetCountFromCompany(indexCode string) (item int, err error) {
  414. o := orm.NewOrmUsingDB("data")
  415. sql := `SELECT COUNT(1) FROM base_from_coalmine_company_index WHERE index_code=? `
  416. err = o.Raw(sql, indexCode).QueryRow(&item)
  417. return
  418. }
  419. func GetCountFromFirm(indexCode string) (item int, err error) {
  420. o := orm.NewOrmUsingDB("data")
  421. sql := `SELECT COUNT(1) FROM base_from_coalmine_firm_index WHERE index_code=? `
  422. err = o.Raw(sql, indexCode).QueryRow(&item)
  423. return
  424. }
  425. func GetClassifyFirmByGroupName(groupName string) (items []*string, err error) {
  426. o := orm.NewOrmUsingDB("data")
  427. sql := `SELECT DISTINCT index_code FROM base_from_coalmine_firm_index WHERE group_name=? `
  428. _, err = o.Raw(sql, groupName).QueryRows(&items)
  429. return
  430. }
  431. // 查询指标
  432. func GetPageFromCoalmineFirmIndexByFrequency(frequency, classify string, startSize, pageSize int) (items []*BaseFromCoalmineFirmIndex, err error) {
  433. o := orm.NewOrmUsingDB("data")
  434. sql := `SELECT * FROM base_from_coalmine_firm_index WHERE frequency=? AND index_code=? ORDER BY data_time DESC LIMIT ?,? `
  435. _, err = o.Raw(sql, frequency, classify, startSize, pageSize).QueryRows(&items)
  436. return
  437. }
  438. func GetCountFromCoastal(indexCode string) (item int, err error) {
  439. o := orm.NewOrmUsingDB("data")
  440. sql := `SELECT COUNT(1) FROM base_from_coalmine_coastal_index WHERE index_code=? `
  441. err = o.Raw(sql, indexCode).QueryRow(&item)
  442. return
  443. }
  444. func GetClassifyCoastalByGroupName(groupName string) (items []*string, err error) {
  445. o := orm.NewOrmUsingDB("data")
  446. sql := `SELECT DISTINCT index_code FROM base_from_coalmine_coastal_index WHERE group_name=? `
  447. _, err = o.Raw(sql, groupName).QueryRows(&items)
  448. return
  449. }
  450. // 查询指标
  451. func GetPageFromCoalmineCoastalIndexByFrequency(frequency, classify string, startSize, pageSize int) (items []*BaseFromCoalmineCoastalIndex, err error) {
  452. o := orm.NewOrmUsingDB("data")
  453. sql := `SELECT * FROM base_from_coalmine_coastal_index WHERE frequency=? AND index_code=? ORDER BY data_time DESC LIMIT ?,? `
  454. _, err = o.Raw(sql, frequency, classify, startSize, pageSize).QueryRows(&items)
  455. return
  456. }
  457. func GetCountFromInland(indexCode string) (item int, err error) {
  458. o := orm.NewOrmUsingDB("data")
  459. sql := `SELECT COUNT(1) FROM base_from_coalmine_inland_index WHERE index_code=? `
  460. err = o.Raw(sql, indexCode).QueryRow(&item)
  461. return
  462. }
  463. func GetClassifyInlandByGroupName(groupName string) (items []*string, err error) {
  464. o := orm.NewOrmUsingDB("data")
  465. sql := `SELECT DISTINCT index_code FROM base_from_coalmine_inland_index WHERE group_name=? `
  466. _, err = o.Raw(sql, groupName).QueryRows(&items)
  467. return
  468. }
  469. // 查询指标
  470. func GetPageFromCoalmineInlandIndexByFrequency(frequency, classify string, startSize, pageSize int) (items []*BaseFromCoalmineInlandIndex, err error) {
  471. o := orm.NewOrmUsingDB("data")
  472. sql := `SELECT * FROM base_from_coalmine_inland_index WHERE frequency=? AND index_code=? ORDER BY data_time DESC LIMIT ?,? `
  473. _, err = o.Raw(sql, frequency, classify, startSize, pageSize).QueryRows(&items)
  474. return
  475. }
  476. // 查询公司指标
  477. func GetBaseFromCoalmineCompanyIndexByFrequency(frequency, groupName string) (items []*BaseFromCoalmineCompanyIndex, err error) {
  478. o := orm.NewOrmUsingDB("data")
  479. sql := `SELECT * FROM base_from_coalmine_company_index WHERE frequency=? AND group_name=? `
  480. _, err = o.Raw(sql, frequency, groupName).QueryRows(&items)
  481. return
  482. }
  483. // 查询指标
  484. func GetBaseFromCoalmineFirmIndexByFrequency(frequency, groupName string) (items []*BaseFromCoalmineFirmIndex, err error) {
  485. o := orm.NewOrmUsingDB("data")
  486. sql := `SELECT * FROM base_from_coalmine_firm_index WHERE frequency=? AND group_name=? `
  487. _, err = o.Raw(sql, frequency, groupName).QueryRows(&items)
  488. return
  489. }
  490. // 查询指标
  491. func GetBaseFromCoalmineCoastalIndexByFrequency(frequency, groupName string) (items []*BaseFromCoalmineCoastalIndex, err error) {
  492. o := orm.NewOrmUsingDB("data")
  493. sql := `SELECT * FROM base_from_coalmine_coastal_index WHERE frequency=? AND group_name=? `
  494. _, err = o.Raw(sql, frequency, groupName).QueryRows(&items)
  495. return
  496. }
  497. // 查询指标
  498. func GetBaseFromCoalmineInlandIndexByFrequency(frequency, groupName string) (items []*BaseFromCoalmineInlandIndex, err error) {
  499. o := orm.NewOrmUsingDB("data")
  500. sql := `SELECT * FROM base_from_coalmine_inland_index WHERE frequency=? AND group_name=? `
  501. _, err = o.Raw(sql, frequency, groupName).QueryRows(&items)
  502. return
  503. }
  504. // 查询数据
  505. func GetBaseFromCoalmineIndexByCode(indexCode string) (items []*BaseFromCoalmineJsmIndex, err error) {
  506. o := orm.NewOrmUsingDB("data")
  507. sql := `SELECT * FROM base_from_coalmine_jsm_index WHERE index_code=?`
  508. _, err = o.Raw(sql, indexCode).QueryRows(&items)
  509. return
  510. }
  511. // 查询公司指标
  512. func GetBaseFromCoalmineCompanyIndexByCode(indexCode string) (items []*BaseFromCoalmineCompanyIndex, err error) {
  513. o := orm.NewOrmUsingDB("data")
  514. sql := `SELECT * FROM base_from_coalmine_company_index WHERE index_code=? `
  515. _, err = o.Raw(sql, indexCode).QueryRows(&items)
  516. return
  517. }
  518. // 查询指标
  519. func GetBaseFromCoalmineFirmIndexByCode(indexCode string) (items []*BaseFromCoalmineFirmIndex, err error) {
  520. o := orm.NewOrmUsingDB("data")
  521. sql := `SELECT * FROM base_from_coalmine_firm_index WHERE index_code=? `
  522. _, err = o.Raw(sql, indexCode).QueryRows(&items)
  523. return
  524. }
  525. // 查询指标
  526. func GetBaseFromCoalmineCoastalIndexByCode(indexCode string) (items []*BaseFromCoalmineCoastalIndex, err error) {
  527. o := orm.NewOrmUsingDB("data")
  528. sql := `SELECT * FROM base_from_coalmine_coastal_index WHERE index_code=? `
  529. _, err = o.Raw(sql, indexCode).QueryRows(&items)
  530. return
  531. }
  532. // 查询指标
  533. func GetBaseFromCoalmineInlandIndexByCode(indexCode string) (items []*BaseFromCoalmineInlandIndex, err error) {
  534. o := orm.NewOrmUsingDB("data")
  535. sql := `SELECT * FROM base_from_coalmine_inland_index WHERE index_code=? `
  536. _, err = o.Raw(sql, indexCode).QueryRows(&items)
  537. return
  538. }
  539. type BaseFromTradeEicIndexV2 struct {
  540. BaseFromEicIndexId int `orm:"column(base_from_eic_index_id);pk"`
  541. Type string
  542. EicCode string
  543. Name string
  544. Status string
  545. GasDayStart string
  546. GasInStorage float64
  547. GasInStorageCode string
  548. Consumption string
  549. ConsumptionCode string
  550. ConsumptionFull string
  551. ConsumptionFullCode string
  552. Full float64
  553. FullCode string
  554. Trend float64
  555. TrendCode string
  556. Injection float64
  557. InjectionCode string
  558. Withdrawal float64
  559. WithdrawalCode string
  560. WorkingGasVolume float64
  561. WorkingGasVolumeCode string
  562. InjectionCapacity float64
  563. InjectionCapacityCode string
  564. WithdrawalCapacity float64
  565. WithdrawalCapacityCode string
  566. Info string
  567. Parent string
  568. CreateTime time.Time
  569. ModifyTime time.Time
  570. Children []BaseFromTradeEicIndexV2
  571. }
  572. func GetEicDateV2() (date []*BaseFromTradeEicIndexV2, err error) {
  573. o := orm.NewOrmUsingDB("data")
  574. sql := "SELECT * FROM base_from_trade_eic_index_v2 ORDER BY gas_day_start desc limit 1"
  575. _, err = o.Raw(sql).QueryRows(&date)
  576. return
  577. }
  578. func GetEicDataV2(date string) (data []*BaseFromTradeEicIndexV2, err error) {
  579. o := orm.NewOrmUsingDB("data")
  580. sql := "SELECT * FROM base_from_trade_eic_index_v2 where gas_day_start=? "
  581. _, err = o.Raw(sql, date).QueryRows(&data)
  582. return
  583. }
  584. func GetEicHistoryDateByDateV2(code, startDate, endDate string) (date []*BaseFromTradeEicIndexV2, err error) {
  585. o := orm.NewOrmUsingDB("data")
  586. sql := "SELECT * FROM base_from_trade_eic_index_v2 WHERE eic_code=? and gas_day_start between ? and ? ORDER BY gas_day_start desc"
  587. _, err = o.Raw(sql, code, startDate, endDate).QueryRows(&date)
  588. return
  589. }
  590. func GetEicHistoryDateV2(code string) (date []*BaseFromTradeEicIndexV2, err error) {
  591. o := orm.NewOrmUsingDB("data")
  592. sql := "SELECT * FROM base_from_trade_eic_index_v2 WHERE eic_code=? ORDER BY gas_day_start desc limit 30"
  593. _, err = o.Raw(sql, code).QueryRows(&date)
  594. return
  595. }
  596. func GetContinentAndCountryEicDateV2(date string) (data []*BaseFromTradeEicIndexV2, err error) {
  597. o := orm.NewOrmUsingDB("data")
  598. sql := "SELECT * FROM base_from_trade_eic_index_v2 where gas_day_start=? and (type='continent' OR type='country') "
  599. _, err = o.Raw(sql, date).QueryRows(&data)
  600. return
  601. }
  602. func GetSSOAndFacEicDateV2(date, name string) (data []*BaseFromTradeEicIndexV2, err error) {
  603. o := orm.NewOrmUsingDB("data")
  604. sql := "SELECT * FROM base_from_trade_eic_index_v2 where gas_day_start=? and (type='sso' OR type='fac') "
  605. _, err = o.Raw(sql, date).QueryRows(&data)
  606. return
  607. }
  608. func GetBaseFromTradeIndexByDate(exchange, startDate, endDate string) (list []*BaseFromTradeShanghaiIndex, err error) {
  609. o := orm.NewOrmUsingDB("data")
  610. sql := "SELECT * FROM base_from_trade_" + exchange + "_index where rank < 50 and data_time between ? and ? order by data_time asc"
  611. _, err = o.Raw(sql, startDate, endDate).QueryRows(&list)
  612. return
  613. }
  614. func GetFirstBaseFromTradeIndexByDate(exchange string) (item *BaseFromTradeShanghaiIndex, err error) {
  615. o := orm.NewOrmUsingDB("data")
  616. sql := "SELECT * FROM base_from_trade_" + exchange + "_index where rank < 50 order by data_time asc"
  617. err = o.Raw(sql).QueryRow(&item)
  618. return
  619. }
  620. type BaseFromCoalmineClassify struct {
  621. BaseFromCoalmineClassifyId int `orm:"column(base_from_coalmine_classify_id);pk"`
  622. ClassifyName string // 分类名称
  623. Suffix string // 表名后缀
  624. CreateTime time.Time
  625. }
  626. func GetCoalmineClassifyList() (list []*BaseFromCoalmineClassify, err error) {
  627. o := orm.NewOrmUsingDB("data")
  628. sql := "SELECT * FROM base_from_coalmine_classify"
  629. _, err = o.Raw(sql).QueryRows(&list)
  630. return
  631. }