commodity_trade_base_index.go 26 KB

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