base_from_trade_index.go 31 KB

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