commodity_trade_base_index.go 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933
  1. package controllers
  2. import (
  3. "eta/eta_hub/models"
  4. "eta/eta_hub/models/data_manage"
  5. "fmt"
  6. "strings"
  7. )
  8. type TradeCommonController struct {
  9. BaseAuthController
  10. }
  11. type Data []struct {
  12. Title string
  13. ItemList []ShanghaiList
  14. }
  15. type ShanghaiList struct {
  16. Code string
  17. Item []*data_manage.BaseFromTradeShanghaiIndex
  18. }
  19. type EicData struct {
  20. Country string
  21. Type string
  22. EicCode string
  23. ShortName string
  24. Name string
  25. Status string
  26. GasDayStartedOn string
  27. GasInStorage float64
  28. GasInStorageCode string
  29. Full float64
  30. FullCode string
  31. Trend float64
  32. TrendCode string
  33. Injection float64
  34. InjectionCode string
  35. Withdrawal float64
  36. WithdrawalCode string
  37. WorkingGasVolume float64
  38. WorkingGasVolumeCode string
  39. InjectionCapacity float64
  40. InjectionCapacityCode string
  41. WithdrawalCapacity float64
  42. WithdrawalCapacityCode string
  43. Info string
  44. Children []*data_manage.BaseFromTradeEicIndex
  45. }
  46. // ExchangeClassify
  47. // @title 获取交易所种类列表
  48. // @Description 获取交易所种类列表接口
  49. // @Param Exchange query string true "交易所名称"
  50. // @Success 200 {object} models.
  51. // @router /data/exchange/classify [get]
  52. func (this *TradeCommonController) ExchangeClassify() {
  53. br := new(models.BaseResponse).Init()
  54. defer func() {
  55. this.Data["json"] = br
  56. this.ServeJSON()
  57. }()
  58. exchange := this.GetString("Exchange")
  59. date := this.GetString("DataTime")
  60. var respItem [][]string
  61. latestData, err := data_manage.GetLatestDate(exchange)
  62. if err != nil {
  63. br.Msg = "获取失败"
  64. return
  65. }
  66. if latestData == "" {
  67. br.Ret = 200
  68. br.Msg = "获取成功"
  69. br.Data = respItem
  70. return
  71. }
  72. if date == "" {
  73. date = latestData
  74. }
  75. classifyName, err := data_manage.GetExchangeClassify(exchange, date)
  76. if err != nil {
  77. br.Msg = "获取种类失败"
  78. br.ErrMsg = "获取种类失败,Err:" + err.Error()
  79. return
  80. }
  81. respItem = append(respItem, classifyName)
  82. respItem = append(respItem, []string{latestData})
  83. br.Ret = 200
  84. br.Msg = "获取成功"
  85. br.Data = respItem
  86. }
  87. // ExchangeClassifyContract
  88. // @title 获取交易所种类合约列表
  89. // @Description 获取交易所种类合约列表接口
  90. // @Param Exchange query string true "交易所名称"
  91. // @Param Classify query string true "种类名称"
  92. // @Param DataTime query string true "时间"
  93. // @Success 200 {object} models.
  94. // @router /data/exchange/classifyContract [get]
  95. func (this *TradeCommonController) ExchangeClassifyContract() {
  96. br := new(models.BaseResponse).Init()
  97. defer func() {
  98. this.Data["json"] = br
  99. this.ServeJSON()
  100. }()
  101. exchange := this.GetString("Exchange")
  102. classify := this.GetString("Classify")
  103. dataTime := this.GetString("DataTime")
  104. classifyName, err := data_manage.GetExchangeClassifyContract(exchange, classify, dataTime)
  105. if err != nil {
  106. br.Msg = "获取种类失败"
  107. br.ErrMsg = "获取种类失败,Err:" + err.Error()
  108. return
  109. }
  110. br.Ret = 200
  111. br.Msg = "获取成功"
  112. br.Data = classifyName
  113. }
  114. // ShfeDataList
  115. // @title 获取上期所列表
  116. // @Description 获取上期所列表接口
  117. // @Param Date query string true "查询日期"
  118. // @Param ClassifyName query string false "分类名称"
  119. // @Param ClassifyType query string false "分类合约"
  120. // @Success 200 {object} models.
  121. // @router /data/shfe [get]
  122. func (this *TradeCommonController) ShfeDataList() {
  123. br := new(models.BaseResponse).Init()
  124. defer func() {
  125. this.Data["json"] = br
  126. this.ServeJSON()
  127. }()
  128. date := this.GetString("Date")
  129. classifyName := this.GetString("ClassifyName")
  130. classifyType := this.GetString("ClassifyType")
  131. frequencyList, err := data_manage.GetBaseFromTradeIndexByParam("shanghai", date, classifyName, classifyType)
  132. if err != nil {
  133. br.Msg = "获取持仓排名失败"
  134. br.ErrMsg = "获取持仓排名失败,Err:" + err.Error()
  135. return
  136. }
  137. var data Data
  138. var j, k int
  139. if len(frequencyList) == 0 {
  140. br.Ret = 200
  141. br.Msg = "获取成功"
  142. br.Data = data
  143. } else {
  144. if classifyName == "" {
  145. data = make(Data, 50)
  146. for i, item := range frequencyList {
  147. if item.DealCode == "" {
  148. item.DealValue = ""
  149. item.DealChange = ""
  150. }
  151. if item.BuyCode == "" {
  152. item.BuyValue = ""
  153. item.BuyChange = ""
  154. }
  155. if item.SoldCode == "" {
  156. item.SoldValue = ""
  157. item.SoldChange = ""
  158. }
  159. if data[j].Title == item.ClassifyName {
  160. if data[j].ItemList[k].Code == item.ClassifyType {
  161. data[j].ItemList[k].Item = append(data[j].ItemList[k].Item, item)
  162. continue
  163. }
  164. if i > 0 {
  165. k++
  166. }
  167. data[j].ItemList[k].Code = item.ClassifyType
  168. data[j].ItemList[k].Item = append(data[j].ItemList[k].Item, item)
  169. continue
  170. }
  171. if i != 0 {
  172. if k == 0 {
  173. data[j].ItemList = data[j].ItemList[:k+1]
  174. } else {
  175. data[j].ItemList = data[j].ItemList[:k]
  176. }
  177. j++
  178. k = 0
  179. }
  180. if data[j].ItemList == nil {
  181. list := make([]ShanghaiList, 930)
  182. data[j].ItemList = list
  183. }
  184. data[j].Title = item.ClassifyName
  185. data[j].ItemList[k].Code = item.ClassifyType
  186. data[j].ItemList[k].Item = append(data[j].ItemList[k].Item, item)
  187. }
  188. data = data[:j]
  189. br.Ret = 200
  190. br.Msg = "获取成功"
  191. br.Data = data
  192. } else {
  193. data = make(Data, 1)
  194. for i, item := range frequencyList {
  195. if item.DealCode == "" {
  196. item.DealValue = ""
  197. item.DealChange = ""
  198. }
  199. if item.BuyCode == "" {
  200. item.BuyValue = ""
  201. item.BuyChange = ""
  202. }
  203. if item.SoldCode == "" {
  204. item.SoldValue = ""
  205. item.SoldChange = ""
  206. }
  207. data[0].Title = classifyName
  208. if data[0].ItemList == nil {
  209. list := make([]ShanghaiList, 200)
  210. data[0].ItemList = list
  211. }
  212. if data[0].ItemList[k].Code == item.ClassifyType {
  213. data[0].ItemList[k].Item = append(data[0].ItemList[k].Item, item)
  214. continue
  215. }
  216. if i > 0 {
  217. k++
  218. }
  219. data[0].ItemList[k].Code = item.ClassifyType
  220. data[0].ItemList[k].Item = append(data[0].ItemList[k].Item, item)
  221. }
  222. data[0].ItemList = data[0].ItemList[:k+1]
  223. br.Ret = 200
  224. br.Msg = "获取成功"
  225. br.Data = data
  226. }
  227. }
  228. }
  229. // IneDataList
  230. // @title 获取上海国际能源交易所列表
  231. // @Description 获取上海国际能源交易所列表接口
  232. // @Param Date query string true "查询日期"
  233. // @Param ClassifyName query string false "分类名称"
  234. // @Param ClassifyType query string false "分类合约"
  235. // @Success 200 {object} models.
  236. // @router /data/ine [get]
  237. func (this *TradeCommonController) IneDataList() {
  238. br := new(models.BaseResponse).Init()
  239. defer func() {
  240. this.Data["json"] = br
  241. this.ServeJSON()
  242. }()
  243. date := this.GetString("Date")
  244. classifyName := this.GetString("ClassifyName")
  245. classifyType := this.GetString("ClassifyType")
  246. frequencyList, err := data_manage.GetBaseFromTradeIndexByParam("ine", date, classifyName, classifyType)
  247. if err != nil {
  248. br.Msg = "获取持仓排名失败"
  249. br.ErrMsg = "获取持仓排名失败,Err:" + err.Error()
  250. return
  251. }
  252. var data Data
  253. var k int
  254. if len(frequencyList) == 0 {
  255. br.Ret = 200
  256. br.Msg = "获取成功"
  257. br.Data = data
  258. } else {
  259. data = make(Data, 1)
  260. if len(frequencyList) > 20 {
  261. for i, item := range frequencyList {
  262. if item.DealCode == "" {
  263. item.DealValue = ""
  264. item.DealChange = ""
  265. }
  266. if item.BuyCode == "" {
  267. item.BuyValue = ""
  268. item.BuyChange = ""
  269. }
  270. if item.SoldCode == "" {
  271. item.SoldValue = ""
  272. item.SoldChange = ""
  273. }
  274. data[0].Title = classifyName
  275. if data[0].ItemList == nil {
  276. list := make([]ShanghaiList, 200)
  277. data[0].ItemList = list
  278. }
  279. if data[0].ItemList[k].Code == item.ClassifyType {
  280. data[0].ItemList[k].Item = append(data[0].ItemList[k].Item, item)
  281. continue
  282. }
  283. if i > 0 {
  284. k++
  285. }
  286. data[0].ItemList[k].Code = item.ClassifyType
  287. data[0].ItemList[k].Item = append(data[0].ItemList[k].Item, item)
  288. }
  289. data[0].ItemList = data[0].ItemList[:k+1]
  290. br.Ret = 200
  291. br.Msg = "获取成功"
  292. br.Data = data
  293. } else {
  294. for _, item := range frequencyList {
  295. if item.DealCode == "" {
  296. item.DealValue = ""
  297. item.DealChange = ""
  298. }
  299. if item.BuyCode == "" {
  300. item.BuyValue = ""
  301. item.BuyChange = ""
  302. }
  303. if item.SoldCode == "" {
  304. item.SoldValue = ""
  305. item.SoldChange = ""
  306. }
  307. data[0].Title = item.ClassifyName
  308. if data[0].ItemList == nil {
  309. list := make([]ShanghaiList, 1)
  310. data[0].ItemList = list
  311. }
  312. if data[0].ItemList[0].Code == item.ClassifyType {
  313. data[0].ItemList[0].Item = append(data[0].ItemList[0].Item, item)
  314. continue
  315. }
  316. //if i != 0 {
  317. // k++
  318. // fmt.Println(k)
  319. //}
  320. data[0].ItemList[0].Code = item.ClassifyType
  321. data[0].ItemList[0].Item = append(data[0].ItemList[0].Item, item)
  322. }
  323. //data[0].ItemList = data[0].ItemList[:k]
  324. br.Ret = 200
  325. br.Msg = "获取成功"
  326. br.Data = data
  327. }
  328. }
  329. }
  330. // CffexDataList
  331. // @title 获取中金所所列表
  332. // @Description 获取中金所列表接口
  333. // @Param Date query string true "查询日期"
  334. // @Param ClassifyName query string false "分类名称"
  335. // @Param ClassifyType query string false "分类合约"
  336. // @Success 200 {object} models.
  337. // @router /data/cffex [get]
  338. func (this *TradeCommonController) CffexDataList() {
  339. br := new(models.BaseResponse).Init()
  340. defer func() {
  341. this.Data["json"] = br
  342. this.ServeJSON()
  343. }()
  344. date := this.GetString("Date")
  345. date = strings.Replace(date, "-", "", -1)
  346. classifyName := this.GetString("ClassifyName")
  347. classifyType := this.GetString("ClassifyType")
  348. frequencyList, err := data_manage.GetBaseFromTradeIndexByParam("cffex", date, classifyName, classifyType)
  349. if err != nil {
  350. br.Msg = "获取持仓排名失败"
  351. br.ErrMsg = "获取持仓排名失败,Err:" + err.Error()
  352. return
  353. }
  354. var data Data
  355. var k int
  356. if len(frequencyList) == 0 {
  357. br.Ret = 200
  358. br.Msg = "获取成功"
  359. br.Data = data
  360. } else {
  361. data = make(Data, 1)
  362. if len(frequencyList) > 20 {
  363. for i, item := range frequencyList {
  364. if item.DealCode == "" {
  365. item.DealValue = ""
  366. item.DealChange = ""
  367. }
  368. if item.BuyCode == "" {
  369. item.BuyValue = ""
  370. item.BuyChange = ""
  371. }
  372. if item.SoldCode == "" {
  373. item.SoldValue = ""
  374. item.SoldChange = ""
  375. }
  376. data[0].Title = classifyName
  377. if data[0].ItemList == nil {
  378. list := make([]ShanghaiList, 200)
  379. data[0].ItemList = list
  380. }
  381. if data[0].ItemList[k].Code == item.ClassifyType {
  382. data[0].ItemList[k].Item = append(data[0].ItemList[k].Item, item)
  383. continue
  384. }
  385. if i > 0 {
  386. k++
  387. }
  388. data[0].ItemList[k].Code = item.ClassifyType
  389. data[0].ItemList[k].Item = append(data[0].ItemList[k].Item, item)
  390. }
  391. data[0].ItemList = data[0].ItemList[:k+1]
  392. br.Ret = 200
  393. br.Msg = "获取成功"
  394. br.Data = data
  395. } else {
  396. for _, item := range frequencyList {
  397. if item.DealCode == "" {
  398. item.DealValue = ""
  399. item.DealChange = ""
  400. }
  401. if item.BuyCode == "" {
  402. item.BuyValue = ""
  403. item.BuyChange = ""
  404. }
  405. if item.SoldCode == "" {
  406. item.SoldValue = ""
  407. item.SoldChange = ""
  408. }
  409. data[0].Title = item.ClassifyName
  410. if data[0].ItemList == nil {
  411. list := make([]ShanghaiList, 1)
  412. data[0].ItemList = list
  413. }
  414. if data[0].ItemList[0].Code == item.ClassifyType {
  415. data[0].ItemList[0].Item = append(data[0].ItemList[0].Item, item)
  416. continue
  417. }
  418. //if i != 0 {
  419. // k++
  420. // fmt.Println(k)
  421. //}
  422. data[0].ItemList[0].Code = item.ClassifyType
  423. data[0].ItemList[0].Item = append(data[0].ItemList[0].Item, item)
  424. }
  425. //data[0].ItemList = data[0].ItemList[:20]
  426. br.Ret = 200
  427. br.Msg = "获取成功"
  428. br.Data = data
  429. }
  430. }
  431. }
  432. // ZhengzhouDataList
  433. // @title 获取郑州交易所列表
  434. // @Description 获取郑州交易所列表接口
  435. // @Param Date query string true "查询日期"
  436. // @Param ClassifyName query string false "分类名称"
  437. // @Param ClassifyType query string false "分类合约"
  438. // @Success 200 {object} models.
  439. // @router /data/zhengzhou [get]
  440. func (this *TradeCommonController) ZhengzhouDataList() {
  441. br := new(models.BaseResponse).Init()
  442. defer func() {
  443. this.Data["json"] = br
  444. this.ServeJSON()
  445. }()
  446. date := this.GetString("Date")
  447. fmt.Println(date)
  448. date = strings.Replace(date, "-", "", -1)
  449. fmt.Println(date)
  450. classifyName := this.GetString("ClassifyName")
  451. classifyType := this.GetString("ClassifyType")
  452. frequencyList, err := data_manage.GetBaseFromTradeIndexByParam("zhengzhou", date, classifyName, classifyType)
  453. if err != nil {
  454. br.Msg = "获取持仓排名失败"
  455. br.ErrMsg = "获取持仓排名失败,Err:" + err.Error()
  456. return
  457. }
  458. var data Data
  459. var k int
  460. if len(frequencyList) == 0 {
  461. br.Ret = 200
  462. br.Msg = "获取成功"
  463. br.Data = data
  464. } else {
  465. data = make(Data, 1)
  466. fmt.Println(len(frequencyList))
  467. if len(frequencyList) > 21 {
  468. for i, item := range frequencyList {
  469. if item.DealCode == "" {
  470. item.DealValue = ""
  471. item.DealChange = ""
  472. }
  473. if item.BuyCode == "" {
  474. item.BuyValue = ""
  475. item.BuyChange = ""
  476. }
  477. if item.SoldCode == "" {
  478. item.SoldValue = ""
  479. item.SoldChange = ""
  480. }
  481. data[0].Title = classifyName
  482. if data[0].ItemList == nil {
  483. list := make([]ShanghaiList, 200)
  484. data[0].ItemList = list
  485. }
  486. if data[0].ItemList[k].Code == item.ClassifyType {
  487. data[0].ItemList[k].Item = append(data[0].ItemList[k].Item, item)
  488. continue
  489. }
  490. if i > 0 {
  491. k++
  492. }
  493. data[0].ItemList[k].Code = item.ClassifyType
  494. data[0].ItemList[k].Item = append(data[0].ItemList[k].Item, item)
  495. }
  496. data[0].ItemList = data[0].ItemList[:k]
  497. br.Ret = 200
  498. br.Msg = "获取成功"
  499. br.Data = data
  500. } else {
  501. for _, item := range frequencyList {
  502. if item.DealCode == "" {
  503. item.DealValue = ""
  504. item.DealChange = ""
  505. }
  506. if item.BuyCode == "" {
  507. item.BuyValue = ""
  508. item.BuyChange = ""
  509. }
  510. if item.SoldCode == "" {
  511. item.SoldValue = ""
  512. item.SoldChange = ""
  513. }
  514. data[0].Title = item.ClassifyName
  515. if data[0].ItemList == nil {
  516. list := make([]ShanghaiList, 1)
  517. data[0].ItemList = list
  518. }
  519. if data[0].ItemList[0].Code == item.ClassifyType {
  520. data[0].ItemList[0].Item = append(data[0].ItemList[0].Item, item)
  521. continue
  522. }
  523. //if i != 0 {
  524. // k++
  525. // fmt.Println(k)
  526. //}
  527. data[0].ItemList[0].Code = item.ClassifyType
  528. data[0].ItemList[0].Item = append(data[0].ItemList[0].Item, item)
  529. }
  530. //data[0].ItemList = data[0].ItemList[:k]
  531. br.Ret = 200
  532. br.Msg = "获取成功"
  533. br.Data = data
  534. }
  535. }
  536. }
  537. // DalianDataList
  538. // @title 获取大连交易所列表
  539. // @Description 获取大连交易所列表接口
  540. // @Param Date query string true "查询日期"
  541. // @Param ClassifyName query string false "分类名称"
  542. // @Param ClassifyType query string false "分类合约"
  543. // @Success 200 {object} models.
  544. // @router /data/dalian [get]
  545. func (this *TradeCommonController) DalianDataList() {
  546. br := new(models.BaseResponse).Init()
  547. defer func() {
  548. this.Data["json"] = br
  549. this.ServeJSON()
  550. }()
  551. date := this.GetString("Date")
  552. classifyName := this.GetString("ClassifyName")
  553. classifyType := this.GetString("ClassifyType")
  554. frequencyList, err := data_manage.GetBaseFromTradeIndexByParam("dalian", date, classifyName, classifyType)
  555. if err != nil {
  556. br.Msg = "获取持仓排名失败"
  557. br.ErrMsg = "获取持仓排名失败,Err:" + err.Error()
  558. return
  559. }
  560. var data Data
  561. var k int
  562. if len(frequencyList) == 0 {
  563. br.Ret = 200
  564. br.Msg = "获取成功"
  565. br.Data = data
  566. } else {
  567. data = make(Data, 1)
  568. fmt.Println("len:", len(frequencyList))
  569. if len(frequencyList) > 21 {
  570. for i, item := range frequencyList {
  571. if item.DealCode == "" {
  572. item.DealValue = ""
  573. item.DealChange = ""
  574. }
  575. if item.BuyCode == "" {
  576. item.BuyValue = ""
  577. item.BuyChange = ""
  578. }
  579. if item.SoldCode == "" {
  580. item.SoldValue = ""
  581. item.SoldChange = ""
  582. }
  583. data[0].Title = classifyName
  584. if data[0].ItemList == nil {
  585. list := make([]ShanghaiList, 200)
  586. data[0].ItemList = list
  587. }
  588. if data[0].ItemList[k].Code == item.ClassifyType {
  589. data[0].ItemList[k].Item = append(data[0].ItemList[k].Item, item)
  590. continue
  591. }
  592. if i > 0 {
  593. k++
  594. }
  595. data[0].ItemList[k].Code = item.ClassifyType
  596. data[0].ItemList[k].Item = append(data[0].ItemList[k].Item, item)
  597. }
  598. data[0].ItemList = data[0].ItemList[:k]
  599. br.Ret = 200
  600. br.Msg = "获取成功"
  601. br.Data = data
  602. } else {
  603. for _, item := range frequencyList {
  604. if item.DealCode == "" {
  605. item.DealValue = ""
  606. item.DealChange = ""
  607. }
  608. if item.BuyCode == "" {
  609. item.BuyValue = ""
  610. item.BuyChange = ""
  611. }
  612. if item.SoldCode == "" {
  613. item.SoldValue = ""
  614. item.SoldChange = ""
  615. }
  616. data[0].Title = item.ClassifyName
  617. if data[0].ItemList == nil {
  618. list := make([]ShanghaiList, 1)
  619. data[0].ItemList = list
  620. }
  621. if data[0].ItemList[0].Code == item.ClassifyType {
  622. data[0].ItemList[0].Item = append(data[0].ItemList[0].Item, item)
  623. continue
  624. }
  625. //if i != 0 {
  626. // k++
  627. // fmt.Println(k)
  628. //}
  629. data[0].ItemList[0].Code = item.ClassifyType
  630. data[0].ItemList[0].Item = append(data[0].ItemList[0].Item, item)
  631. }
  632. //data[0].ItemList = data[0].ItemList[:k]
  633. br.Ret = 200
  634. br.Msg = "获取成功"
  635. br.Data = data
  636. }
  637. }
  638. }
  639. // EicLatestDateV2
  640. // @title 获取欧洲天然气最新日期V2
  641. // @Description 获取欧洲天然气最新日期接口
  642. // @Success 200 {object} models.
  643. // @router /data/eicLatestDateV2 [get]
  644. func (this *TradeCommonController) EicLatestDateV2() {
  645. br := new(models.BaseResponse).Init()
  646. defer func() {
  647. this.Data["json"] = br
  648. this.ServeJSON()
  649. }()
  650. latestData, err := data_manage.GetEicDateV2()
  651. if err != nil {
  652. br.Msg = "获取日期失败"
  653. br.ErrMsg = "获取日期失败,Err:" + err.Error()
  654. return
  655. }
  656. br.Ret = 200
  657. br.Msg = "获取成功"
  658. br.Data = latestData[0].GasDayStart
  659. }
  660. type EicDataV2 struct {
  661. Name string `json:"name" description:"指标名称"`
  662. Code string `json:"code" description:"指标编码"`
  663. GasDayStart string `json:"gasDayStart" description:"指标日期"`
  664. GasInStorage float64 `json:"gasInStorage" description:"储存容量"`
  665. Consumption string `json:"consumption" description:"消耗"`
  666. ConsumptionFull string `json:"consumptionFull" description:"消耗百分比"`
  667. Injection float64 `json:"injection" description:"注入量"`
  668. Withdrawal float64 `json:"withdrawal" description:"减少量"`
  669. WorkingGasVolume float64 `json:"workingGasVolume" description:"工作气体量"`
  670. InjectionCapacity float64 `json:"injectionCapacity" description:"注入速度"`
  671. WithdrawalCapacity float64 `json:"withdrawalCapacity" description:"减少速度"`
  672. Status string `json:"status" description:"状态"`
  673. Trend float64 `json:"trend" description:"较前日对比"`
  674. Full float64 `json:"full" description:"储存容量百分比"`
  675. Info string `json:"info" description:"信息"`
  676. Children []EicDataV2 `json:"children"`
  677. }
  678. // eicDataV2
  679. // @title 获取欧洲天然气列表
  680. // @Description 获取欧洲天然气列表接口
  681. // @Param Date query string true "查询日期"
  682. // @Success 200 {object} models.
  683. // @router /data/eicDataV2 [get]
  684. func (this *TradeCommonController) EicDataV2() {
  685. br := new(models.BaseResponse).Init()
  686. defer func() {
  687. this.Data["json"] = br
  688. this.ServeJSON()
  689. }()
  690. date := this.GetString("Date")
  691. list, err := data_manage.GetEicDataV2(date)
  692. if err != nil {
  693. br.Msg = "获取天然气数据失败"
  694. br.ErrMsg = "获取天然气数据失败,Err:" + err.Error()
  695. return
  696. }
  697. var continentItems []data_manage.BaseFromTradeEicIndexV2
  698. var countryItems []data_manage.BaseFromTradeEicIndexV2
  699. var ssoItems []data_manage.BaseFromTradeEicIndexV2
  700. var facItems []data_manage.BaseFromTradeEicIndexV2
  701. for _, item := range list {
  702. switch item.Type {
  703. case "continent":
  704. continentItems = append(continentItems, *item)
  705. case "country":
  706. countryItems = append(countryItems, *item)
  707. case "sso":
  708. ssoItems = append(ssoItems, *item)
  709. case "fac":
  710. facItems = append(facItems, *item)
  711. default:
  712. continue
  713. }
  714. }
  715. var data []data_manage.BaseFromTradeEicIndexV2
  716. data = continentItems
  717. for i, continentItem := range continentItems {
  718. for _, countryItem := range countryItems {
  719. if countryItem.Parent == continentItem.Name {
  720. data[i].Children = append(data[i].Children, countryItem)
  721. }
  722. }
  723. for j, country := range data[i].Children {
  724. for _, ssoItem := range ssoItems {
  725. if country.Name == ssoItem.Parent {
  726. data[i].Children[j].Children = append(data[i].Children[j].Children, ssoItem)
  727. }
  728. }
  729. for k, sso := range data[i].Children[j].Children {
  730. for _, facItem := range facItems {
  731. if sso.Name == facItem.Parent {
  732. data[i].Children[j].Children[k].Children = append(data[i].Children[j].Children[k].Children, facItem)
  733. }
  734. }
  735. }
  736. }
  737. }
  738. br.Ret = 200
  739. br.Msg = "获取成功"
  740. br.Data = data
  741. }
  742. // EicHistoryDataV2
  743. // @title 获取欧洲天然气历史列表
  744. // @Description 获取欧洲天然气历史列表接口
  745. // @Param Code query string true "Code"
  746. // @Param StartDate query string false "开始时间"
  747. // @Param EndDate query string false "结束时间"
  748. // @Success 200 {object} []EicDataV2
  749. // @router /data/eicHistoryDataV2 [get]
  750. func (this *TradeCommonController) EicHistoryDataV2() {
  751. br := new(models.BaseResponse).Init()
  752. defer func() {
  753. this.Data["json"] = br
  754. this.ServeJSON()
  755. }()
  756. code := this.GetString("Code")
  757. startDate := this.GetString("StartDate")
  758. endDate := this.GetString("EndDate")
  759. var eicList []*data_manage.BaseFromTradeEicIndexV2
  760. var err error
  761. if endDate != "" {
  762. eicList, err = data_manage.GetEicHistoryDateByDateV2(code, startDate, endDate)
  763. if err != nil {
  764. br.Msg = "获取持仓排名失败"
  765. br.ErrMsg = "获取持仓排名失败,Err:" + err.Error()
  766. return
  767. }
  768. } else {
  769. eicList, err = data_manage.GetEicHistoryDateV2(code)
  770. if err != nil {
  771. br.Msg = "获取持仓排名失败"
  772. br.ErrMsg = "获取持仓排名失败,Err:" + err.Error()
  773. return
  774. }
  775. }
  776. var data []EicDataV2
  777. for _, eic := range eicList {
  778. item := EicDataV2{
  779. Name: eic.Name,
  780. Code: eic.EicCode,
  781. GasDayStart: eic.GasDayStart,
  782. GasInStorage: eic.GasInStorage,
  783. Consumption: eic.Consumption,
  784. ConsumptionFull: eic.ConsumptionFull,
  785. Injection: eic.Injection,
  786. Withdrawal: eic.Withdrawal,
  787. WorkingGasVolume: eic.WorkingGasVolume,
  788. InjectionCapacity: eic.InjectionCapacity,
  789. WithdrawalCapacity: eic.WithdrawalCapacity,
  790. Status: eic.Status,
  791. Trend: eic.Trend,
  792. Full: eic.Full,
  793. Info: eic.Info,
  794. }
  795. data = append(data, item)
  796. }
  797. br.Ret = 200
  798. br.Msg = "获取成功"
  799. br.Data = data
  800. }
  801. // eicContinentV2 欧洲天然气洲际及国家级列表
  802. // @title 欧洲天然气洲际及国家级列表
  803. // @Description 欧洲天然气洲际及国家级列表
  804. // @Param Date query string true "查询日期"
  805. // @Success 200 {object} []data_manage.BaseFromTradeEicIndexV2
  806. // @router /data/eicContinentV2 [get]
  807. func (this *TradeCommonController) EicContinentListV2() {
  808. br := new(models.BaseResponse).Init()
  809. defer func() {
  810. this.Data["json"] = br
  811. this.ServeJSON()
  812. }()
  813. date := this.GetString("Date")
  814. list, err := data_manage.GetContinentAndCountryEicDateV2(date)
  815. if err != nil {
  816. br.Msg = "获取天然气数据失败"
  817. br.ErrMsg = "获取天然气数据失败,Err:" + err.Error()
  818. return
  819. }
  820. var continentItems []data_manage.BaseFromTradeEicIndexV2
  821. var countryItems []data_manage.BaseFromTradeEicIndexV2
  822. for _, item := range list {
  823. switch item.Type {
  824. case "continent":
  825. continentItems = append(continentItems, *item)
  826. case "country":
  827. countryItems = append(countryItems, *item)
  828. default:
  829. continue
  830. }
  831. }
  832. var data []data_manage.BaseFromTradeEicIndexV2
  833. data = continentItems
  834. for i, continentItem := range continentItems {
  835. for _, countryItem := range countryItems {
  836. if countryItem.Parent == continentItem.Name {
  837. data[i].Children = append(data[i].Children, countryItem)
  838. }
  839. }
  840. }
  841. br.Ret = 200
  842. br.Msg = "获取成功"
  843. br.Data = data
  844. }
  845. // EicDataListV2 欧洲天然气细节列表
  846. // @title 欧洲天然气细节列表
  847. // @Description 欧洲天然气细节列表
  848. // @Param Date query string true "查询日期"
  849. // @Param Name query string true "国家"
  850. // @Success 200 {object} []data_manage.BaseFromTradeEicIndexV2
  851. // @router /data/eicSSODataV2 [get]
  852. func (this *TradeCommonController) EicDataListV2() {
  853. br := new(models.BaseResponse).Init()
  854. defer func() {
  855. this.Data["json"] = br
  856. this.ServeJSON()
  857. }()
  858. date := this.GetString("Date")
  859. name := this.GetString("Name")
  860. list, err := data_manage.GetSSOAndFacEicDateV2(date, name)
  861. if err != nil {
  862. br.Msg = "获取天然气数据失败"
  863. br.ErrMsg = "获取天然气数据失败,Err:" + err.Error()
  864. return
  865. }
  866. var ssoItems []data_manage.BaseFromTradeEicIndexV2
  867. var facItems []data_manage.BaseFromTradeEicIndexV2
  868. for _, item := range list {
  869. switch item.Type {
  870. case "sso":
  871. ssoItems = append(ssoItems, *item)
  872. case "fac":
  873. facItems = append(facItems, *item)
  874. default:
  875. continue
  876. }
  877. }
  878. i := 0
  879. var data []data_manage.BaseFromTradeEicIndexV2
  880. for _, ssoItem := range ssoItems {
  881. if ssoItem.Parent == name {
  882. data = append(data, ssoItem)
  883. for _, facItem := range facItems {
  884. if facItem.Parent == ssoItem.Name {
  885. data[i].Children = append(data[i].Children, facItem)
  886. }
  887. }
  888. i++
  889. }
  890. }
  891. br.Ret = 200
  892. br.Msg = "获取成功"
  893. br.Data = data
  894. }