commodity_trade_base_index.go 71 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530
  1. package controllers
  2. import (
  3. "fmt"
  4. "github.com/rdlucklib/rdluck_tools/paging"
  5. "github.com/tealeg/xlsx"
  6. "eta/eta_api/models"
  7. "eta/eta_api/models/data_manage"
  8. "eta/eta_api/utils"
  9. "os"
  10. "path/filepath"
  11. "strconv"
  12. "strings"
  13. "time"
  14. )
  15. type TradeCommonController struct {
  16. BaseAuthController
  17. }
  18. type Data []struct {
  19. Title string
  20. ItemList []ShanghaiList
  21. }
  22. type ShanghaiList struct {
  23. Code string
  24. Item []*data_manage.BaseFromTradeShanghaiIndex
  25. }
  26. type EicData struct {
  27. Country string
  28. Type string
  29. EicCode string
  30. ShortName string
  31. Name string
  32. Status string
  33. GasDayStartedOn string
  34. GasInStorage float64
  35. GasInStorageCode string
  36. Full float64
  37. FullCode string
  38. Trend float64
  39. TrendCode string
  40. Injection float64
  41. InjectionCode string
  42. Withdrawal float64
  43. WithdrawalCode string
  44. WorkingGasVolume float64
  45. WorkingGasVolumeCode string
  46. InjectionCapacity float64
  47. InjectionCapacityCode string
  48. WithdrawalCapacity float64
  49. WithdrawalCapacityCode string
  50. Info string
  51. Children []*data_manage.BaseFromTradeEicIndex
  52. }
  53. // ExchangeClassify
  54. // @title 获取交易所种类列表
  55. // @Description 获取交易所种类列表接口
  56. // @Param Exchange query string true "交易所名称"
  57. // @Success 200 {object} models.
  58. // @router /data/exchange/classify [get]
  59. func (this *TradeCommonController) ExchangeClassify() {
  60. br := new(models.BaseResponse).Init()
  61. defer func() {
  62. this.Data["json"] = br
  63. this.ServeJSON()
  64. }()
  65. exchange := this.GetString("Exchange")
  66. date := this.GetString("DataTime")
  67. var respItem [][]string
  68. latestData, err := data_manage.GetLatestDate(exchange)
  69. if err != nil {
  70. br.Msg = "获取失败"
  71. return
  72. }
  73. if latestData == "" {
  74. br.Ret = 200
  75. br.Success = true
  76. br.Msg = "获取成功"
  77. br.Data = respItem
  78. return
  79. }
  80. if date == "" {
  81. date = latestData
  82. }
  83. classifyName, err := data_manage.GetExchangeClassify(exchange, date)
  84. if err != nil {
  85. br.Msg = "获取种类失败"
  86. br.ErrMsg = "获取种类失败,Err:" + err.Error()
  87. return
  88. }
  89. respItem = append(respItem, classifyName)
  90. respItem = append(respItem, []string{latestData})
  91. br.Ret = 200
  92. br.Success = true
  93. br.Msg = "获取成功"
  94. br.Data = respItem
  95. }
  96. // ExchangeClassifyContract
  97. // @title 获取交易所种类合约列表
  98. // @Description 获取交易所种类合约列表接口
  99. // @Param Exchange query string true "交易所名称"
  100. // @Param Classify query string true "种类名称"
  101. // @Param DataTime query string true "时间"
  102. // @Success 200 {object} models.
  103. // @router /data/exchange/classifyContract [get]
  104. func (this *TradeCommonController) ExchangeClassifyContract() {
  105. br := new(models.BaseResponse).Init()
  106. defer func() {
  107. this.Data["json"] = br
  108. this.ServeJSON()
  109. }()
  110. exchange := this.GetString("Exchange")
  111. classify := this.GetString("Classify")
  112. dataTime := this.GetString("DataTime")
  113. classifyName, err := data_manage.GetExchangeClassifyContract(exchange, classify, dataTime)
  114. if err != nil {
  115. br.Msg = "获取种类失败"
  116. br.ErrMsg = "获取种类失败,Err:" + err.Error()
  117. return
  118. }
  119. br.Ret = 200
  120. br.Success = true
  121. br.Msg = "获取成功"
  122. br.Data = classifyName
  123. }
  124. // ShfeDataList
  125. // @title 获取上期所列表
  126. // @Description 获取上期所列表接口
  127. // @Param Date query string true "查询日期"
  128. // @Param ClassifyName query string false "分类名称"
  129. // @Param ClassifyType query string false "分类合约"
  130. // @Success 200 {object} models.
  131. // @router /data/shfe [get]
  132. func (this *TradeCommonController) ShfeDataList() {
  133. br := new(models.BaseResponse).Init()
  134. defer func() {
  135. this.Data["json"] = br
  136. this.ServeJSON()
  137. }()
  138. date := this.GetString("Date")
  139. classifyName := this.GetString("ClassifyName")
  140. classifyType := this.GetString("ClassifyType")
  141. frequencyList, err := data_manage.GetBaseFromTradeIndexByParam("shanghai", date, classifyName, classifyType)
  142. if err != nil {
  143. br.Msg = "获取持仓排名失败"
  144. br.ErrMsg = "获取持仓排名失败,Err:" + err.Error()
  145. return
  146. }
  147. var data Data
  148. var j, k int
  149. if len(frequencyList) == 0 {
  150. br.Ret = 200
  151. br.Success = true
  152. br.Msg = "获取成功"
  153. br.Data = data
  154. } else {
  155. if classifyName == "" {
  156. data = make(Data, 50)
  157. for i, item := range frequencyList {
  158. if item.DealCode == "" {
  159. item.DealValue = ""
  160. item.DealChange = ""
  161. }
  162. if item.BuyCode == "" {
  163. item.BuyValue = ""
  164. item.BuyChange = ""
  165. }
  166. if item.SoldCode == "" {
  167. item.SoldValue = ""
  168. item.SoldChange = ""
  169. }
  170. if data[j].Title == item.ClassifyName {
  171. if data[j].ItemList[k].Code == item.ClassifyType {
  172. data[j].ItemList[k].Item = append(data[j].ItemList[k].Item, item)
  173. continue
  174. }
  175. if i > 0 {
  176. k++
  177. }
  178. data[j].ItemList[k].Code = item.ClassifyType
  179. data[j].ItemList[k].Item = append(data[j].ItemList[k].Item, item)
  180. continue
  181. }
  182. if i != 0 {
  183. if k == 0 {
  184. data[j].ItemList = data[j].ItemList[:k+1]
  185. } else {
  186. data[j].ItemList = data[j].ItemList[:k]
  187. }
  188. j++
  189. k = 0
  190. }
  191. if data[j].ItemList == nil {
  192. list := make([]ShanghaiList, 930)
  193. data[j].ItemList = list
  194. }
  195. data[j].Title = item.ClassifyName
  196. data[j].ItemList[k].Code = item.ClassifyType
  197. data[j].ItemList[k].Item = append(data[j].ItemList[k].Item, item)
  198. }
  199. data = data[:j]
  200. br.Ret = 200
  201. br.Success = true
  202. br.Msg = "获取成功"
  203. br.Data = data
  204. } else {
  205. data = make(Data, 1)
  206. for i, item := range frequencyList {
  207. if item.DealCode == "" {
  208. item.DealValue = ""
  209. item.DealChange = ""
  210. }
  211. if item.BuyCode == "" {
  212. item.BuyValue = ""
  213. item.BuyChange = ""
  214. }
  215. if item.SoldCode == "" {
  216. item.SoldValue = ""
  217. item.SoldChange = ""
  218. }
  219. data[0].Title = classifyName
  220. if data[0].ItemList == nil {
  221. list := make([]ShanghaiList, 200)
  222. data[0].ItemList = list
  223. }
  224. if data[0].ItemList[k].Code == item.ClassifyType {
  225. data[0].ItemList[k].Item = append(data[0].ItemList[k].Item, item)
  226. continue
  227. }
  228. if i > 0 {
  229. k++
  230. }
  231. data[0].ItemList[k].Code = item.ClassifyType
  232. data[0].ItemList[k].Item = append(data[0].ItemList[k].Item, item)
  233. }
  234. data[0].ItemList = data[0].ItemList[:k+1]
  235. br.Ret = 200
  236. br.Success = true
  237. br.Msg = "获取成功"
  238. br.Data = data
  239. }
  240. }
  241. }
  242. // IneDataList
  243. // @title 获取上海国际能源交易所列表
  244. // @Description 获取上海国际能源交易所列表接口
  245. // @Param Date query string true "查询日期"
  246. // @Param ClassifyName query string false "分类名称"
  247. // @Param ClassifyType query string false "分类合约"
  248. // @Success 200 {object} models.
  249. // @router /data/ine [get]
  250. func (this *TradeCommonController) IneDataList() {
  251. br := new(models.BaseResponse).Init()
  252. defer func() {
  253. this.Data["json"] = br
  254. this.ServeJSON()
  255. }()
  256. date := this.GetString("Date")
  257. classifyName := this.GetString("ClassifyName")
  258. classifyType := this.GetString("ClassifyType")
  259. frequencyList, err := data_manage.GetBaseFromTradeIndexByParam("ine", date, classifyName, classifyType)
  260. if err != nil {
  261. br.Msg = "获取持仓排名失败"
  262. br.ErrMsg = "获取持仓排名失败,Err:" + err.Error()
  263. return
  264. }
  265. var data Data
  266. var k int
  267. if len(frequencyList) == 0 {
  268. br.Ret = 200
  269. br.Success = true
  270. br.Msg = "获取成功"
  271. br.Data = data
  272. } else {
  273. data = make(Data, 1)
  274. if len(frequencyList) > 20 {
  275. for i, item := range frequencyList {
  276. if item.DealCode == "" {
  277. item.DealValue = ""
  278. item.DealChange = ""
  279. }
  280. if item.BuyCode == "" {
  281. item.BuyValue = ""
  282. item.BuyChange = ""
  283. }
  284. if item.SoldCode == "" {
  285. item.SoldValue = ""
  286. item.SoldChange = ""
  287. }
  288. data[0].Title = classifyName
  289. if data[0].ItemList == nil {
  290. list := make([]ShanghaiList, 200)
  291. data[0].ItemList = list
  292. }
  293. if data[0].ItemList[k].Code == item.ClassifyType {
  294. data[0].ItemList[k].Item = append(data[0].ItemList[k].Item, item)
  295. continue
  296. }
  297. if i > 0 {
  298. k++
  299. }
  300. data[0].ItemList[k].Code = item.ClassifyType
  301. data[0].ItemList[k].Item = append(data[0].ItemList[k].Item, item)
  302. }
  303. data[0].ItemList = data[0].ItemList[:k+1]
  304. br.Ret = 200
  305. br.Success = true
  306. br.Msg = "获取成功"
  307. br.Data = data
  308. } else {
  309. for _, item := range frequencyList {
  310. if item.DealCode == "" {
  311. item.DealValue = ""
  312. item.DealChange = ""
  313. }
  314. if item.BuyCode == "" {
  315. item.BuyValue = ""
  316. item.BuyChange = ""
  317. }
  318. if item.SoldCode == "" {
  319. item.SoldValue = ""
  320. item.SoldChange = ""
  321. }
  322. data[0].Title = item.ClassifyName
  323. if data[0].ItemList == nil {
  324. list := make([]ShanghaiList, 1)
  325. data[0].ItemList = list
  326. }
  327. if data[0].ItemList[0].Code == item.ClassifyType {
  328. data[0].ItemList[0].Item = append(data[0].ItemList[0].Item, item)
  329. continue
  330. }
  331. //if i != 0 {
  332. // k++
  333. // fmt.Println(k)
  334. //}
  335. data[0].ItemList[0].Code = item.ClassifyType
  336. data[0].ItemList[0].Item = append(data[0].ItemList[0].Item, item)
  337. }
  338. //data[0].ItemList = data[0].ItemList[:k]
  339. br.Ret = 200
  340. br.Success = true
  341. br.Msg = "获取成功"
  342. br.Data = data
  343. }
  344. }
  345. }
  346. // CffexDataList
  347. // @title 获取中金所所列表
  348. // @Description 获取中金所列表接口
  349. // @Param Date query string true "查询日期"
  350. // @Param ClassifyName query string false "分类名称"
  351. // @Param ClassifyType query string false "分类合约"
  352. // @Success 200 {object} models.
  353. // @router /data/cffex [get]
  354. func (this *TradeCommonController) CffexDataList() {
  355. br := new(models.BaseResponse).Init()
  356. defer func() {
  357. this.Data["json"] = br
  358. this.ServeJSON()
  359. }()
  360. date := this.GetString("Date")
  361. date = strings.Replace(date, "-", "", -1)
  362. classifyName := this.GetString("ClassifyName")
  363. classifyType := this.GetString("ClassifyType")
  364. frequencyList, err := data_manage.GetBaseFromTradeIndexByParam("cffex", date, classifyName, classifyType)
  365. if err != nil {
  366. br.Msg = "获取持仓排名失败"
  367. br.ErrMsg = "获取持仓排名失败,Err:" + err.Error()
  368. return
  369. }
  370. var data Data
  371. var k int
  372. if len(frequencyList) == 0 {
  373. br.Ret = 200
  374. br.Success = true
  375. br.Msg = "获取成功"
  376. br.Data = data
  377. } else {
  378. data = make(Data, 1)
  379. if len(frequencyList) > 20 {
  380. for i, item := range frequencyList {
  381. if item.DealCode == "" {
  382. item.DealValue = ""
  383. item.DealChange = ""
  384. }
  385. if item.BuyCode == "" {
  386. item.BuyValue = ""
  387. item.BuyChange = ""
  388. }
  389. if item.SoldCode == "" {
  390. item.SoldValue = ""
  391. item.SoldChange = ""
  392. }
  393. data[0].Title = classifyName
  394. if data[0].ItemList == nil {
  395. list := make([]ShanghaiList, 200)
  396. data[0].ItemList = list
  397. }
  398. if data[0].ItemList[k].Code == item.ClassifyType {
  399. data[0].ItemList[k].Item = append(data[0].ItemList[k].Item, item)
  400. continue
  401. }
  402. if i > 0 {
  403. k++
  404. }
  405. data[0].ItemList[k].Code = item.ClassifyType
  406. data[0].ItemList[k].Item = append(data[0].ItemList[k].Item, item)
  407. }
  408. data[0].ItemList = data[0].ItemList[:k+1]
  409. br.Ret = 200
  410. br.Success = true
  411. br.Msg = "获取成功"
  412. br.Data = data
  413. } else {
  414. for _, item := range frequencyList {
  415. if item.DealCode == "" {
  416. item.DealValue = ""
  417. item.DealChange = ""
  418. }
  419. if item.BuyCode == "" {
  420. item.BuyValue = ""
  421. item.BuyChange = ""
  422. }
  423. if item.SoldCode == "" {
  424. item.SoldValue = ""
  425. item.SoldChange = ""
  426. }
  427. data[0].Title = item.ClassifyName
  428. if data[0].ItemList == nil {
  429. list := make([]ShanghaiList, 1)
  430. data[0].ItemList = list
  431. }
  432. if data[0].ItemList[0].Code == item.ClassifyType {
  433. data[0].ItemList[0].Item = append(data[0].ItemList[0].Item, item)
  434. continue
  435. }
  436. //if i != 0 {
  437. // k++
  438. // fmt.Println(k)
  439. //}
  440. data[0].ItemList[0].Code = item.ClassifyType
  441. data[0].ItemList[0].Item = append(data[0].ItemList[0].Item, item)
  442. }
  443. //data[0].ItemList = data[0].ItemList[:20]
  444. br.Ret = 200
  445. br.Success = true
  446. br.Msg = "获取成功"
  447. br.Data = data
  448. }
  449. }
  450. }
  451. // ZhengzhouDataList
  452. // @title 获取郑州交易所列表
  453. // @Description 获取郑州交易所列表接口
  454. // @Param Date query string true "查询日期"
  455. // @Param ClassifyName query string false "分类名称"
  456. // @Param ClassifyType query string false "分类合约"
  457. // @Success 200 {object} models.
  458. // @router /data/zhengzhou [get]
  459. func (this *TradeCommonController) ZhengzhouDataList() {
  460. br := new(models.BaseResponse).Init()
  461. defer func() {
  462. this.Data["json"] = br
  463. this.ServeJSON()
  464. }()
  465. date := this.GetString("Date")
  466. fmt.Println(date)
  467. date = strings.Replace(date, "-", "", -1)
  468. fmt.Println(date)
  469. classifyName := this.GetString("ClassifyName")
  470. classifyType := this.GetString("ClassifyType")
  471. frequencyList, err := data_manage.GetBaseFromTradeIndexByParam("zhengzhou", date, classifyName, classifyType)
  472. if err != nil {
  473. br.Msg = "获取持仓排名失败"
  474. br.ErrMsg = "获取持仓排名失败,Err:" + err.Error()
  475. return
  476. }
  477. var data Data
  478. var k int
  479. if len(frequencyList) == 0 {
  480. br.Ret = 200
  481. br.Success = true
  482. br.Msg = "获取成功"
  483. br.Data = data
  484. } else {
  485. data = make(Data, 1)
  486. fmt.Println(len(frequencyList))
  487. if len(frequencyList) > 21 {
  488. for i, item := range frequencyList {
  489. if item.DealCode == "" {
  490. item.DealValue = ""
  491. item.DealChange = ""
  492. }
  493. if item.BuyCode == "" {
  494. item.BuyValue = ""
  495. item.BuyChange = ""
  496. }
  497. if item.SoldCode == "" {
  498. item.SoldValue = ""
  499. item.SoldChange = ""
  500. }
  501. data[0].Title = classifyName
  502. if data[0].ItemList == nil {
  503. list := make([]ShanghaiList, 200)
  504. data[0].ItemList = list
  505. }
  506. if data[0].ItemList[k].Code == item.ClassifyType {
  507. data[0].ItemList[k].Item = append(data[0].ItemList[k].Item, item)
  508. continue
  509. }
  510. if i > 0 {
  511. k++
  512. }
  513. data[0].ItemList[k].Code = item.ClassifyType
  514. data[0].ItemList[k].Item = append(data[0].ItemList[k].Item, item)
  515. }
  516. data[0].ItemList = data[0].ItemList[:k]
  517. br.Ret = 200
  518. br.Success = true
  519. br.Msg = "获取成功"
  520. br.Data = data
  521. } else {
  522. for _, item := range frequencyList {
  523. if item.DealCode == "" {
  524. item.DealValue = ""
  525. item.DealChange = ""
  526. }
  527. if item.BuyCode == "" {
  528. item.BuyValue = ""
  529. item.BuyChange = ""
  530. }
  531. if item.SoldCode == "" {
  532. item.SoldValue = ""
  533. item.SoldChange = ""
  534. }
  535. data[0].Title = item.ClassifyName
  536. if data[0].ItemList == nil {
  537. list := make([]ShanghaiList, 1)
  538. data[0].ItemList = list
  539. }
  540. if data[0].ItemList[0].Code == item.ClassifyType {
  541. data[0].ItemList[0].Item = append(data[0].ItemList[0].Item, item)
  542. continue
  543. }
  544. //if i != 0 {
  545. // k++
  546. // fmt.Println(k)
  547. //}
  548. data[0].ItemList[0].Code = item.ClassifyType
  549. data[0].ItemList[0].Item = append(data[0].ItemList[0].Item, item)
  550. }
  551. //data[0].ItemList = data[0].ItemList[:k]
  552. br.Ret = 200
  553. br.Success = true
  554. br.Msg = "获取成功"
  555. br.Data = data
  556. }
  557. }
  558. }
  559. // DalianDataList
  560. // @title 获取大连交易所列表
  561. // @Description 获取大连交易所列表接口
  562. // @Param Date query string true "查询日期"
  563. // @Param ClassifyName query string false "分类名称"
  564. // @Param ClassifyType query string false "分类合约"
  565. // @Success 200 {object} models.
  566. // @router /data/dalian [get]
  567. func (this *TradeCommonController) DalianDataList() {
  568. br := new(models.BaseResponse).Init()
  569. defer func() {
  570. this.Data["json"] = br
  571. this.ServeJSON()
  572. }()
  573. date := this.GetString("Date")
  574. classifyName := this.GetString("ClassifyName")
  575. classifyType := this.GetString("ClassifyType")
  576. frequencyList, err := data_manage.GetBaseFromTradeIndexByParam("dalian", date, classifyName, classifyType)
  577. if err != nil {
  578. br.Msg = "获取持仓排名失败"
  579. br.ErrMsg = "获取持仓排名失败,Err:" + err.Error()
  580. return
  581. }
  582. var data Data
  583. var k int
  584. if len(frequencyList) == 0 {
  585. br.Ret = 200
  586. br.Success = true
  587. br.Msg = "获取成功"
  588. br.Data = data
  589. } else {
  590. data = make(Data, 1)
  591. fmt.Println("len:", len(frequencyList))
  592. if len(frequencyList) > 21 {
  593. for i, item := range frequencyList {
  594. if item.DealCode == "" {
  595. item.DealValue = ""
  596. item.DealChange = ""
  597. }
  598. if item.BuyCode == "" {
  599. item.BuyValue = ""
  600. item.BuyChange = ""
  601. }
  602. if item.SoldCode == "" {
  603. item.SoldValue = ""
  604. item.SoldChange = ""
  605. }
  606. data[0].Title = classifyName
  607. if data[0].ItemList == nil {
  608. list := make([]ShanghaiList, 200)
  609. data[0].ItemList = list
  610. }
  611. if data[0].ItemList[k].Code == item.ClassifyType {
  612. data[0].ItemList[k].Item = append(data[0].ItemList[k].Item, item)
  613. continue
  614. }
  615. if i > 0 {
  616. k++
  617. }
  618. data[0].ItemList[k].Code = item.ClassifyType
  619. data[0].ItemList[k].Item = append(data[0].ItemList[k].Item, item)
  620. }
  621. data[0].ItemList = data[0].ItemList[:k]
  622. br.Ret = 200
  623. br.Success = true
  624. br.Msg = "获取成功"
  625. br.Data = data
  626. } else {
  627. for _, item := range frequencyList {
  628. if item.DealCode == "" {
  629. item.DealValue = ""
  630. item.DealChange = ""
  631. }
  632. if item.BuyCode == "" {
  633. item.BuyValue = ""
  634. item.BuyChange = ""
  635. }
  636. if item.SoldCode == "" {
  637. item.SoldValue = ""
  638. item.SoldChange = ""
  639. }
  640. data[0].Title = item.ClassifyName
  641. if data[0].ItemList == nil {
  642. list := make([]ShanghaiList, 1)
  643. data[0].ItemList = list
  644. }
  645. if data[0].ItemList[0].Code == item.ClassifyType {
  646. data[0].ItemList[0].Item = append(data[0].ItemList[0].Item, item)
  647. continue
  648. }
  649. //if i != 0 {
  650. // k++
  651. // fmt.Println(k)
  652. //}
  653. data[0].ItemList[0].Code = item.ClassifyType
  654. data[0].ItemList[0].Item = append(data[0].ItemList[0].Item, item)
  655. }
  656. //data[0].ItemList = data[0].ItemList[:k]
  657. br.Ret = 200
  658. br.Success = true
  659. br.Msg = "获取成功"
  660. br.Data = data
  661. }
  662. }
  663. }
  664. // EicLatestDate
  665. // @title 获取欧洲天然气最新日期
  666. // @Description 获取欧洲天然气最新日期接口
  667. // @Success 200 {object} models.
  668. // @router /data/eicLatestDate [get]
  669. func (this *TradeCommonController) EicLatestDate() {
  670. br := new(models.BaseResponse).Init()
  671. defer func() {
  672. this.Data["json"] = br
  673. this.ServeJSON()
  674. }()
  675. latestData, err := data_manage.GetEicDate()
  676. if err != nil {
  677. br.Msg = "获取日期失败"
  678. br.ErrMsg = "获取日期失败,Err:" + err.Error()
  679. return
  680. }
  681. br.Ret = 200
  682. br.Success = true
  683. br.Msg = "获取成功"
  684. br.Data = latestData[0].GasDayStartedOn
  685. }
  686. // EicContinentList 欧洲天然气洲际及国家级列表
  687. // @title 获取欧洲天然气列表
  688. // @Description 获取欧洲天然气列表接口
  689. // @Param Date query string true "查询日期"
  690. // @Success 200 {object} models.
  691. // @router /data/eicContinent [get]
  692. func (this *TradeCommonController) EicContinentList() {
  693. br := new(models.BaseResponse).Init()
  694. defer func() {
  695. this.Data["json"] = br
  696. this.ServeJSON()
  697. }()
  698. date := this.GetString("Date")
  699. continentList, err := data_manage.GetContinentEicDate(date)
  700. if err != nil {
  701. br.Msg = "获取持仓排名失败"
  702. br.ErrMsg = "获取持仓排名失败,Err:" + err.Error()
  703. return
  704. }
  705. countryList, err := data_manage.GetCountryEicDate(date)
  706. if err != nil {
  707. br.Msg = "获取持仓排名失败"
  708. br.ErrMsg = "获取持仓排名失败,Err:" + err.Error()
  709. return
  710. }
  711. if len(countryList) == 0 || len(continentList) < 1 {
  712. br.Ret = 200
  713. br.Success = true
  714. br.Msg = "获取成功"
  715. br.Data = []EicData{}
  716. } else {
  717. countryLen := len(countryList)
  718. var euData = EicData{
  719. Country: "eu",
  720. Type: "continent",
  721. EicCode: "eu",
  722. ShortName: "eu",
  723. Name: "eu",
  724. Status: "N",
  725. GasDayStartedOn: "",
  726. GasInStorage: 0,
  727. GasInStorageCode: "euGS",
  728. Full: 0,
  729. FullCode: "euF",
  730. Trend: 0,
  731. TrendCode: "euT",
  732. Injection: 0,
  733. InjectionCode: "euIn",
  734. Withdrawal: 0,
  735. WithdrawalCode: "euOut",
  736. WorkingGasVolume: 0,
  737. WorkingGasVolumeCode: "euWGV",
  738. InjectionCapacity: 0,
  739. InjectionCapacityCode: "euIC",
  740. WithdrawalCapacity: 0,
  741. WithdrawalCapacityCode: "euWC",
  742. Info: "",
  743. Children: countryList[:countryLen-2],
  744. }
  745. var neData = EicData{
  746. Country: "ne",
  747. Type: "continent",
  748. EicCode: "ne",
  749. ShortName: "ne",
  750. Name: "ne",
  751. Status: "N",
  752. GasDayStartedOn: "",
  753. GasInStorage: 0,
  754. GasInStorageCode: "neGS",
  755. Full: 0,
  756. FullCode: "neF",
  757. Trend: 0,
  758. TrendCode: "neT",
  759. Injection: 0,
  760. InjectionCode: "neIn",
  761. Withdrawal: 0,
  762. WithdrawalCode: "neOut",
  763. WorkingGasVolume: 0,
  764. WorkingGasVolumeCode: "neWGV",
  765. InjectionCapacity: 0,
  766. InjectionCapacityCode: "neIC",
  767. WithdrawalCapacity: 0,
  768. WithdrawalCapacityCode: "neWC",
  769. Info: "",
  770. Children: countryList[countryLen-2:],
  771. }
  772. //如果洲际数据正常
  773. if continentList[0].Country == "eu" {
  774. gasInStorage, _ := strconv.ParseFloat(continentList[0].GasInStorage, 64)
  775. full, _ := strconv.ParseFloat(continentList[0].Full, 64)
  776. trend, _ := strconv.ParseFloat(continentList[0].Trend, 64)
  777. injection, _ := strconv.ParseFloat(continentList[0].Injection, 64)
  778. withdrawal, _ := strconv.ParseFloat(continentList[0].Withdrawal, 64)
  779. workingGasVolume, _ := strconv.ParseFloat(continentList[0].WorkingGasVolume, 64)
  780. injectionCapacity, _ := strconv.ParseFloat(continentList[0].InjectionCapacity, 64)
  781. withdrawalCapacity, _ := strconv.ParseFloat(continentList[0].WithdrawalCapacity, 64)
  782. euData = EicData{
  783. continentList[0].Country,
  784. continentList[0].Type,
  785. continentList[0].EicCode,
  786. continentList[0].ShortName,
  787. continentList[0].Name,
  788. continentList[0].Status,
  789. continentList[0].GasDayStartedOn,
  790. gasInStorage,
  791. continentList[0].GasInStorageCode,
  792. full,
  793. continentList[0].FullCode,
  794. trend,
  795. continentList[0].TrendCode,
  796. injection,
  797. continentList[0].InjectionCode,
  798. withdrawal,
  799. continentList[0].WithdrawalCode,
  800. workingGasVolume,
  801. continentList[0].WorkingGasVolumeCode,
  802. injectionCapacity,
  803. continentList[0].InjectionCapacityCode,
  804. withdrawalCapacity,
  805. continentList[0].WithdrawalCapacityCode,
  806. continentList[0].Info,
  807. countryList[:countryLen-2],
  808. }
  809. if len(continentList) > 1 {
  810. gasInStorage1, _ := strconv.ParseFloat(continentList[1].GasInStorage, 64)
  811. full1, _ := strconv.ParseFloat(continentList[1].Full, 64)
  812. trend1, _ := strconv.ParseFloat(continentList[1].Trend, 64)
  813. injection1, _ := strconv.ParseFloat(continentList[1].Injection, 64)
  814. withdrawal1, _ := strconv.ParseFloat(continentList[1].Withdrawal, 64)
  815. workingGasVolume1, _ := strconv.ParseFloat(continentList[1].WorkingGasVolume, 64)
  816. injectionCapacity1, _ := strconv.ParseFloat(continentList[1].InjectionCapacity, 64)
  817. withdrawalCapacity1, _ := strconv.ParseFloat(continentList[1].WithdrawalCapacity, 64)
  818. neData = EicData{
  819. continentList[1].Country,
  820. continentList[1].Type,
  821. continentList[1].EicCode,
  822. continentList[1].ShortName,
  823. continentList[1].Name,
  824. continentList[1].Status,
  825. continentList[1].GasDayStartedOn,
  826. gasInStorage1,
  827. continentList[1].GasInStorageCode,
  828. full1,
  829. continentList[1].FullCode,
  830. trend1,
  831. continentList[1].TrendCode,
  832. injection1,
  833. continentList[1].InjectionCode,
  834. withdrawal1,
  835. continentList[1].WithdrawalCode,
  836. workingGasVolume1,
  837. continentList[1].WorkingGasVolumeCode,
  838. injectionCapacity1,
  839. continentList[1].InjectionCapacityCode,
  840. withdrawalCapacity1,
  841. continentList[1].WithdrawalCapacityCode,
  842. continentList[1].Info,
  843. countryList[countryLen-2:],
  844. }
  845. }
  846. } else {
  847. //数据不正常,只有一个洲际数据时
  848. if continentList[0].Country == "eu" {
  849. gasInStorage, _ := strconv.ParseFloat(continentList[0].GasInStorage, 64)
  850. full, _ := strconv.ParseFloat(continentList[0].Full, 64)
  851. trend, _ := strconv.ParseFloat(continentList[0].Trend, 64)
  852. injection, _ := strconv.ParseFloat(continentList[0].Injection, 64)
  853. withdrawal, _ := strconv.ParseFloat(continentList[0].Withdrawal, 64)
  854. workingGasVolume, _ := strconv.ParseFloat(continentList[0].WorkingGasVolume, 64)
  855. injectionCapacity, _ := strconv.ParseFloat(continentList[0].InjectionCapacity, 64)
  856. withdrawalCapacity, _ := strconv.ParseFloat(continentList[0].WithdrawalCapacity, 64)
  857. euData = EicData{
  858. continentList[0].Country,
  859. continentList[0].Type,
  860. continentList[0].EicCode,
  861. continentList[0].ShortName,
  862. continentList[0].Name,
  863. continentList[0].Status,
  864. continentList[0].GasDayStartedOn,
  865. gasInStorage,
  866. continentList[0].GasInStorageCode,
  867. full,
  868. continentList[0].FullCode,
  869. trend,
  870. continentList[0].TrendCode,
  871. injection,
  872. continentList[0].InjectionCode,
  873. withdrawal,
  874. continentList[0].WithdrawalCode,
  875. workingGasVolume,
  876. continentList[0].WorkingGasVolumeCode,
  877. injectionCapacity,
  878. continentList[0].InjectionCapacityCode,
  879. withdrawalCapacity,
  880. continentList[0].WithdrawalCapacityCode,
  881. continentList[0].Info,
  882. countryList[:countryLen-2],
  883. }
  884. } else {
  885. gasInStorage1, _ := strconv.ParseFloat(continentList[0].GasInStorage, 64)
  886. full1, _ := strconv.ParseFloat(continentList[0].Full, 64)
  887. trend1, _ := strconv.ParseFloat(continentList[0].Trend, 64)
  888. injection1, _ := strconv.ParseFloat(continentList[0].Injection, 64)
  889. withdrawal1, _ := strconv.ParseFloat(continentList[0].Withdrawal, 64)
  890. workingGasVolume1, _ := strconv.ParseFloat(continentList[0].WorkingGasVolume, 64)
  891. injectionCapacity1, _ := strconv.ParseFloat(continentList[0].InjectionCapacity, 64)
  892. withdrawalCapacity1, _ := strconv.ParseFloat(continentList[0].WithdrawalCapacity, 64)
  893. neData = EicData{
  894. continentList[0].Country,
  895. continentList[0].Type,
  896. continentList[0].EicCode,
  897. continentList[0].ShortName,
  898. continentList[0].Name,
  899. continentList[0].Status,
  900. continentList[0].GasDayStartedOn,
  901. gasInStorage1,
  902. continentList[0].GasInStorageCode,
  903. full1,
  904. continentList[0].FullCode,
  905. trend1,
  906. continentList[0].TrendCode,
  907. injection1,
  908. continentList[0].InjectionCode,
  909. withdrawal1,
  910. continentList[0].WithdrawalCode,
  911. workingGasVolume1,
  912. continentList[0].WorkingGasVolumeCode,
  913. injectionCapacity1,
  914. continentList[0].InjectionCapacityCode,
  915. withdrawalCapacity1,
  916. continentList[0].WithdrawalCapacityCode,
  917. continentList[0].Info,
  918. countryList[countryLen-2:],
  919. }
  920. }
  921. }
  922. var data []EicData
  923. data = append(data, euData)
  924. data = append(data, neData)
  925. br.Ret = 200
  926. br.Success = true
  927. br.Msg = "获取成功"
  928. br.Data = data
  929. }
  930. }
  931. // EicDataList 欧洲天然气细节列表
  932. // @title 获取欧洲天然气列表
  933. // @Description 获取欧洲天然气列表接口
  934. // @Param Date query string true "查询日期"
  935. // @Param Country query string true "国家"
  936. // @Success 200 {object} models.
  937. // @router /data/eicData [get]
  938. func (this *TradeCommonController) EicDataList() {
  939. br := new(models.BaseResponse).Init()
  940. defer func() {
  941. this.Data["json"] = br
  942. this.ServeJSON()
  943. }()
  944. date := this.GetString("Date")
  945. country := this.GetString("Country")
  946. ssoList, err := data_manage.GetSSOEicDate(date, country)
  947. if err != nil {
  948. br.Msg = "获取持仓排名失败"
  949. br.ErrMsg = "获取持仓排名失败,Err:" + err.Error()
  950. return
  951. }
  952. storageList, err := data_manage.GetStorageEicDate(date, country)
  953. if err != nil {
  954. br.Msg = "获取持仓排名失败"
  955. br.ErrMsg = "获取持仓排名失败,Err:" + err.Error()
  956. return
  957. }
  958. var data []EicData
  959. for _, sso := range ssoList {
  960. gasInStorage, _ := strconv.ParseFloat(sso.GasInStorage, 64)
  961. full, _ := strconv.ParseFloat(sso.Full, 64)
  962. trend, _ := strconv.ParseFloat(sso.Trend, 64)
  963. injection, _ := strconv.ParseFloat(sso.Injection, 64)
  964. withdrawal, _ := strconv.ParseFloat(sso.Withdrawal, 64)
  965. workingGasVolume, _ := strconv.ParseFloat(sso.WorkingGasVolume, 64)
  966. injectionCapacity, _ := strconv.ParseFloat(sso.InjectionCapacity, 64)
  967. withdrawalCapacity, _ := strconv.ParseFloat(sso.WithdrawalCapacity, 64)
  968. item := EicData{
  969. sso.Country,
  970. sso.Type,
  971. sso.EicCode,
  972. sso.ShortName,
  973. sso.Name,
  974. sso.Status,
  975. sso.GasDayStartedOn,
  976. gasInStorage,
  977. sso.GasInStorageCode,
  978. full,
  979. sso.FullCode,
  980. trend,
  981. sso.TrendCode,
  982. injection,
  983. sso.InjectionCode,
  984. withdrawal,
  985. sso.WithdrawalCode,
  986. workingGasVolume,
  987. sso.WorkingGasVolumeCode,
  988. injectionCapacity,
  989. sso.InjectionCapacityCode,
  990. withdrawalCapacity,
  991. sso.WithdrawalCapacityCode,
  992. sso.Info,
  993. []*data_manage.BaseFromTradeEicIndex{},
  994. }
  995. for _, st := range storageList {
  996. if item.ShortName == st.ShortName {
  997. item.Children = append(item.Children, st)
  998. }
  999. }
  1000. data = append(data, item)
  1001. }
  1002. br.Ret = 200
  1003. br.Success = true
  1004. br.Msg = "获取成功"
  1005. br.Data = data
  1006. }
  1007. // EicHistoryData
  1008. // @title 获取欧洲天然气历史列表
  1009. // @Description 获取欧洲天然气历史列表接口
  1010. // @Param Code query string true "Code"
  1011. // @Param StartDate query string false "开始时间"
  1012. // @Param EndDate query string false "结束时间"
  1013. // @Success 200 {object} models.
  1014. // @router /data/eicHistoryData [get]
  1015. func (this *TradeCommonController) EicHistoryData() {
  1016. br := new(models.BaseResponse).Init()
  1017. defer func() {
  1018. this.Data["json"] = br
  1019. this.ServeJSON()
  1020. }()
  1021. code := this.GetString("Code")
  1022. startDate := this.GetString("StartDate")
  1023. endDate := this.GetString("EndDate")
  1024. var eicList []*data_manage.BaseFromTradeEicIndex
  1025. var err error
  1026. if endDate != "" {
  1027. eicList, err = data_manage.GetEicHistoryDateByDate(code, startDate, endDate)
  1028. if err != nil {
  1029. br.Msg = "获取持仓排名失败"
  1030. br.ErrMsg = "获取持仓排名失败,Err:" + err.Error()
  1031. return
  1032. }
  1033. } else {
  1034. eicList, err = data_manage.GetEicHistoryDate(code)
  1035. if err != nil {
  1036. br.Msg = "获取持仓排名失败"
  1037. br.ErrMsg = "获取持仓排名失败,Err:" + err.Error()
  1038. return
  1039. }
  1040. }
  1041. var data []EicData
  1042. for _, eic := range eicList {
  1043. gasInStorage, _ := strconv.ParseFloat(eic.GasInStorage, 64)
  1044. full, _ := strconv.ParseFloat(eic.Full, 64)
  1045. trend, _ := strconv.ParseFloat(eic.Trend, 64)
  1046. injection, _ := strconv.ParseFloat(eic.Injection, 64)
  1047. withdrawal, _ := strconv.ParseFloat(eic.Withdrawal, 64)
  1048. workingGasVolume, _ := strconv.ParseFloat(eic.WorkingGasVolume, 64)
  1049. injectionCapacity, _ := strconv.ParseFloat(eic.InjectionCapacity, 64)
  1050. withdrawalCapacity, _ := strconv.ParseFloat(eic.WithdrawalCapacity, 64)
  1051. item := EicData{
  1052. eic.Country,
  1053. eic.Type,
  1054. eic.EicCode,
  1055. eic.ShortName,
  1056. eic.Name,
  1057. eic.Status,
  1058. eic.GasDayStartedOn,
  1059. gasInStorage,
  1060. eic.GasInStorageCode,
  1061. full,
  1062. eic.FullCode,
  1063. trend,
  1064. eic.TrendCode,
  1065. injection,
  1066. eic.InjectionCode,
  1067. withdrawal,
  1068. eic.WithdrawalCode,
  1069. workingGasVolume,
  1070. eic.WorkingGasVolumeCode,
  1071. injectionCapacity,
  1072. eic.InjectionCapacityCode,
  1073. withdrawalCapacity,
  1074. eic.WithdrawalCapacityCode,
  1075. eic.Info,
  1076. []*data_manage.BaseFromTradeEicIndex{},
  1077. }
  1078. data = append(data, item)
  1079. }
  1080. br.Ret = 200
  1081. br.Success = true
  1082. br.Msg = "获取成功"
  1083. br.Data = data
  1084. }
  1085. //// EicHistoryDataByDate
  1086. //// @title 根据时间获取欧洲天然气历史列表
  1087. //// @Description 根据时间获取欧洲天然气历史列表
  1088. //// @Param Code query string true "Code"
  1089. //// @Param Date1 query string true "时间1"
  1090. //// @Param Date2 query string true "时间2"
  1091. //// @Success 200 {object} models.
  1092. //// @router /data/eicHistoryDataByDate [get]
  1093. //func (this *TradeCommonController) EicHistoryDataByDate() {
  1094. // br := new(models.BaseResponse).Init()
  1095. // defer func() {
  1096. // this.Data["json"] = br
  1097. // this.ServeJSON()
  1098. // }()
  1099. // code := this.GetString("Code")
  1100. // date1 := this.GetString("Date1")
  1101. // date2 := this.GetString("Date2")
  1102. // eicList, err := data_manage.GetEicHistoryDateByDate(code,date1,date2)
  1103. // if err != nil {
  1104. // br.Msg = "获取持仓排名失败"
  1105. // br.ErrMsg = "获取持仓排名失败,Err:" + err.Error()
  1106. // return
  1107. // }
  1108. // var data []EicData
  1109. // for _, eic := range eicList {
  1110. // gasInStorage, _ := strconv.ParseFloat(eic.GasInStorage, 64)
  1111. // full, _ := strconv.ParseFloat(eic.Full, 64)
  1112. // trend, _ := strconv.ParseFloat(eic.Trend, 64)
  1113. // injection, _ := strconv.ParseFloat(eic.Injection, 64)
  1114. // withdrawal, _ := strconv.ParseFloat(eic.Withdrawal, 64)
  1115. // workingGasVolume, _ := strconv.ParseFloat(eic.WorkingGasVolume, 64)
  1116. // injectionCapacity, _ := strconv.ParseFloat(eic.InjectionCapacity, 64)
  1117. // withdrawalCapacity, _ := strconv.ParseFloat(eic.WithdrawalCapacity, 64)
  1118. // item := EicData{
  1119. // eic.Country,
  1120. // eic.Type,
  1121. // eic.EicCode,
  1122. // eic.ShortName,
  1123. // eic.Name,
  1124. // eic.Status,
  1125. // eic.GasDayStartedOn,
  1126. // gasInStorage,
  1127. // eic.GasInStorageCode,
  1128. // full,
  1129. // eic.FullCode,
  1130. // trend,
  1131. // eic.TrendCode,
  1132. // injection,
  1133. // eic.InjectionCode,
  1134. // withdrawal,
  1135. // eic.WithdrawalCode,
  1136. // workingGasVolume,
  1137. // eic.WorkingGasVolumeCode,
  1138. // injectionCapacity,
  1139. // eic.InjectionCapacityCode,
  1140. // withdrawalCapacity,
  1141. // eic.WithdrawalCapacityCode,
  1142. // eic.Info,
  1143. // []*data_manage.BaseFromTradeEicIndex{},
  1144. // }
  1145. // data = append(data, item)
  1146. // }
  1147. //
  1148. // br.Ret = 200
  1149. // br.Success = true
  1150. // br.Msg = "获取成功"
  1151. // br.Data = data
  1152. //}
  1153. // CoalMineClassify
  1154. // @title 获取中国煤炭网分类列表
  1155. // @Description 获取中国煤炭网分类列表
  1156. // @Success 200 {object} models.
  1157. // @router /data/coalMineData/classify [get]
  1158. func (this *TradeCommonController) CoalMineClassify() {
  1159. br := new(models.BaseResponse).Init()
  1160. defer func() {
  1161. this.Data["json"] = br
  1162. this.ServeJSON()
  1163. }()
  1164. var coalList []data_manage.BaseFromCoalmineClassify
  1165. var suffix string
  1166. var coal data_manage.BaseFromCoalmineClassify
  1167. var childs []data_manage.CoalChild
  1168. var child data_manage.CoalChild
  1169. suffix = "jsm_index"
  1170. groups, err := data_manage.GetProvinceFromCoalmineIndex(suffix)
  1171. if err != nil {
  1172. br.Msg = "获取煤炭分类数据失败"
  1173. br.ErrMsg = "获取煤炭度分类数据失败,Err: " + err.Error()
  1174. return
  1175. }
  1176. coal.ClassifyId = 1
  1177. coal.ClassifyName = "晋陕蒙三省煤矿产量周度数据"
  1178. jsmId := 100
  1179. for _, group := range groups {
  1180. jsmId++
  1181. child.ClassifyId = jsmId
  1182. child.ClassifyName = *group
  1183. childs = append(childs, child)
  1184. }
  1185. coal.Child = childs
  1186. coalList = append(coalList, coal)
  1187. suffix = "company_index"
  1188. groups = []*string{}
  1189. childs = []data_manage.CoalChild{}
  1190. groups, err = data_manage.GetGroupNameFromCoalmineIndex(suffix)
  1191. if err != nil {
  1192. br.Msg = "获取煤炭分类数据失败"
  1193. br.ErrMsg = "获取煤炭度分类数据失败,Err: " + err.Error()
  1194. return
  1195. }
  1196. coal.ClassifyId = 2
  1197. coal.ClassifyName = "442家晋陕蒙煤矿周度产量"
  1198. companyId := 200
  1199. for _, group := range groups {
  1200. companyId++
  1201. child.ClassifyId = companyId
  1202. child.ClassifyName = *group
  1203. childs = append(childs, child)
  1204. }
  1205. coal.Child = childs
  1206. coalList = append(coalList, coal)
  1207. suffix = "firm_index"
  1208. groups = []*string{}
  1209. childs = []data_manage.CoalChild{}
  1210. groups, err = data_manage.GetGroupNameFromCoalmineIndex(suffix)
  1211. if err != nil {
  1212. br.Msg = "获取煤炭分类数据失败"
  1213. br.ErrMsg = "获取煤炭度分类数据失败,Err: " + err.Error()
  1214. return
  1215. }
  1216. coal.ClassifyId = 3
  1217. coal.ClassifyName = "全国分企业煤炭产量旬度数据"
  1218. firmId := 300
  1219. for _, group := range groups {
  1220. firmId++
  1221. child.ClassifyId = firmId
  1222. child.ClassifyName = *group
  1223. childs = append(childs, child)
  1224. }
  1225. coal.Child = childs
  1226. coalList = append(coalList, coal)
  1227. suffix = "coastal_index"
  1228. groups = []*string{}
  1229. childs = []data_manage.CoalChild{}
  1230. groups, err = data_manage.GetGroupNameFromCoalmineIndex(suffix)
  1231. if err != nil {
  1232. br.Msg = "获取煤炭分类数据失败"
  1233. br.ErrMsg = "获取煤炭度分类数据失败,Err: " + err.Error()
  1234. return
  1235. }
  1236. coal.ClassifyId = 4
  1237. coal.ClassifyName = "沿海八省动力煤终端用户供耗存"
  1238. coastalId := 400
  1239. for _, group := range groups {
  1240. coastalId++
  1241. child.ClassifyId = coastalId
  1242. child.ClassifyName = *group
  1243. childs = append(childs, child)
  1244. }
  1245. coal.Child = childs
  1246. coalList = append(coalList, coal)
  1247. suffix = "inland_index"
  1248. groups = []*string{}
  1249. childs = []data_manage.CoalChild{}
  1250. groups, err = data_manage.GetGroupNameFromCoalmineIndex(suffix)
  1251. if err != nil {
  1252. br.Msg = "获取煤炭分类数据失败"
  1253. br.ErrMsg = "获取煤炭度分类数据失败,Err: " + err.Error()
  1254. return
  1255. }
  1256. coal.ClassifyId = 5
  1257. coal.ClassifyName = "内陆17省动力煤终端用户供耗存"
  1258. inlandId := 500
  1259. for _, group := range groups {
  1260. inlandId++
  1261. child.ClassifyId = inlandId
  1262. child.ClassifyName = *group
  1263. childs = append(childs, child)
  1264. }
  1265. coal.Child = childs
  1266. coalList = append(coalList, coal)
  1267. br.Ret = 200
  1268. br.Success = true
  1269. br.Msg = "获取成功"
  1270. br.Data = coalList
  1271. }
  1272. // CoalMineFrequency
  1273. // @title 获取中国煤炭网频度
  1274. // @Description 获取中国煤炭网频度
  1275. // @Param ClassifyId query int true "数据id"
  1276. // @Success 200 {object} models.
  1277. // @router /data/coalMineData/frequency [get]
  1278. func (this *TradeCommonController) CoalMineFrequency() {
  1279. br := new(models.BaseResponse).Init()
  1280. defer func() {
  1281. this.Data["json"] = br
  1282. this.ServeJSON()
  1283. }()
  1284. classifyId, _ := this.GetInt("ClassifyId")
  1285. var suffix string
  1286. if classifyId == 1 {
  1287. suffix = "jsm_index"
  1288. } else if classifyId == 2 {
  1289. suffix = "company_index"
  1290. } else if classifyId == 3 {
  1291. suffix = "firm_index"
  1292. } else if classifyId == 4 {
  1293. suffix = "coastal_index"
  1294. } else if classifyId == 5 {
  1295. suffix = "inland_index"
  1296. }
  1297. frequency, err := data_manage.GetFrequencyFromCoal(suffix)
  1298. if err != nil {
  1299. br.Msg = "获取煤炭频度数据失败"
  1300. br.ErrMsg = "获取煤炭频度数据失败,Err:" + err.Error()
  1301. return
  1302. }
  1303. var resp data_manage.FrequencyResp
  1304. switch *frequency {
  1305. case "日度":
  1306. resp.Frequency = 1
  1307. case "周度":
  1308. resp.Frequency = 2
  1309. case "旬度":
  1310. resp.Frequency = 3
  1311. case "月度":
  1312. resp.Frequency = 4
  1313. case "季度":
  1314. resp.Frequency = 5
  1315. case "年度":
  1316. resp.Frequency = 6
  1317. default:
  1318. resp.Frequency = 99
  1319. }
  1320. var list []data_manage.FrequencyResp
  1321. list = append(list, resp)
  1322. br.Ret = 200
  1323. br.Success = true
  1324. br.Msg = "获取成功"
  1325. br.Data = list
  1326. }
  1327. // CoalMineData
  1328. // @title 获取中国煤炭网详细数据列表
  1329. // @Description 获取中国煤炭网详细数据接口
  1330. // @Param ClassifyId query int true "数据id"
  1331. // @Param GroupName query string true "分组名"
  1332. // @Param Frequency query string true "频度"
  1333. // @Param PageSize query int true "每页数据条数"
  1334. // @Param CurrentIndex query int true "当前页页码,从1开始"
  1335. // @Success 200 {object} []data_manage.CoalmineDataResp
  1336. // @router /data/coalMineData/data [get]
  1337. func (this *TradeCommonController) CoalMineData() {
  1338. br := new(models.BaseResponse).Init()
  1339. defer func() {
  1340. this.Data["json"] = br
  1341. this.ServeJSON()
  1342. }()
  1343. classifyId, _ := this.GetInt("ClassifyId")
  1344. frequency := this.GetString("Frequency")
  1345. groupName := this.GetString("GroupName")
  1346. pageSize, _ := this.GetInt("PageSize")
  1347. currentIndex, _ := this.GetInt("CurrentIndex")
  1348. var startSize int
  1349. if pageSize <= 0 {
  1350. pageSize = utils.PageSize20
  1351. }
  1352. if currentIndex <= 0 {
  1353. currentIndex = 1
  1354. }
  1355. startSize = utils.StartIndex(currentIndex, pageSize)
  1356. //var groups []*string
  1357. //var err error
  1358. //var suffix string
  1359. //if classifyId == 1 {
  1360. // suffix = "jsm_index"
  1361. //} else if classifyId == 2 {
  1362. // suffix = "company_index"
  1363. //} else if classifyId == 3 {
  1364. // suffix = "firm_index"
  1365. //} else if classifyId == 4 {
  1366. // suffix = "coastal_index"
  1367. //} else if classifyId == 5 {
  1368. // suffix = "inland_index"
  1369. //}
  1370. switch classifyId {
  1371. case 1:
  1372. classifies, err := data_manage.GetClassifyCoalmineIndexByGroupName(groupName)
  1373. if err != nil {
  1374. br.Msg = "获取煤炭数据失败"
  1375. br.ErrMsg = "获取煤炭度数据失败,Err:" + err.Error()
  1376. return
  1377. }
  1378. var lists []data_manage.CoalmineDataPageResp
  1379. for _, classify := range classifies {
  1380. items, err := data_manage.GetPageFromCoalmineIndexByFrequency(frequency, *classify, startSize, pageSize)
  1381. if err != nil {
  1382. br.Msg = "获取煤炭数据失败"
  1383. br.ErrMsg = "获取煤炭度数据失败,Err:" + err.Error()
  1384. return
  1385. }
  1386. total, err := data_manage.GetCountFromJsm(*classify)
  1387. if err != nil {
  1388. br.Msg = "获取煤炭数据失败"
  1389. br.ErrMsg = "获取煤炭度数据失败,Err:" + err.Error()
  1390. return
  1391. }
  1392. page := paging.GetPaging(currentIndex, pageSize, total)
  1393. var resp data_manage.CoalmineDataPageResp
  1394. for i, item := range items {
  1395. if i == 0 {
  1396. resp.ModifyTime = item.CreateTime
  1397. }
  1398. resp.Paging = page
  1399. resp.IndexName = item.IndexName
  1400. resp.IndexCode = item.IndexCode
  1401. resp.Unit = item.Unit
  1402. resp.Frequency = item.Frequency
  1403. //组装dataList
  1404. var dataItem data_manage.DataList
  1405. dataItem.DataTime = item.DataTime
  1406. dataItem.Value = item.DealValue
  1407. resp.DataList = append(resp.DataList, dataItem)
  1408. }
  1409. lists = append(lists, resp)
  1410. }
  1411. br.Ret = 200
  1412. br.Success = true
  1413. br.Msg = "获取成功"
  1414. br.Data = lists
  1415. case 2:
  1416. classifies, err := data_manage.GetClassifyCompanyByGroupName(groupName)
  1417. if err != nil {
  1418. br.Msg = "获取煤炭数据失败"
  1419. br.ErrMsg = "获取煤炭度数据失败,Err:" + err.Error()
  1420. return
  1421. }
  1422. var lists []data_manage.CoalmineDataPageResp
  1423. for _, classify := range classifies {
  1424. items, err := data_manage.GetPageFromCoalmineCompanyIndexByFrequency(frequency, *classify, startSize, pageSize)
  1425. if err != nil {
  1426. br.Msg = "获取煤炭数据失败"
  1427. br.ErrMsg = "获取煤炭度数据失败,Err:" + err.Error()
  1428. return
  1429. }
  1430. total, err := data_manage.GetCountFromCompany(*classify)
  1431. if err != nil {
  1432. br.Msg = "获取煤炭数据失败"
  1433. br.ErrMsg = "获取煤炭度数据失败,Err:" + err.Error()
  1434. return
  1435. }
  1436. page := paging.GetPaging(currentIndex, pageSize, total)
  1437. var resp data_manage.CoalmineDataPageResp
  1438. for i, item := range items {
  1439. if i == 0 {
  1440. resp.ModifyTime = item.CreateTime
  1441. }
  1442. resp.Paging = page
  1443. resp.IndexName = item.IndexName
  1444. resp.IndexCode = item.IndexCode
  1445. resp.Unit = item.Unit
  1446. resp.Frequency = item.Frequency
  1447. //组装dataList
  1448. var dataItem data_manage.DataList
  1449. dataItem.DataTime = item.DataTime
  1450. dataItem.Value = item.DealValue
  1451. resp.DataList = append(resp.DataList, dataItem)
  1452. }
  1453. lists = append(lists, resp)
  1454. }
  1455. br.Ret = 200
  1456. br.Success = true
  1457. br.Msg = "获取成功"
  1458. br.Data = lists
  1459. case 3:
  1460. classifies, err := data_manage.GetClassifyFirmByGroupName(groupName)
  1461. if err != nil {
  1462. br.Msg = "获取煤炭数据失败"
  1463. br.ErrMsg = "获取煤炭度数据失败,Err:" + err.Error()
  1464. return
  1465. }
  1466. var lists []data_manage.CoalmineDataPageResp
  1467. for _, classify := range classifies {
  1468. items, err := data_manage.GetPageFromCoalmineFirmIndexByFrequency(frequency, *classify, startSize, pageSize)
  1469. if err != nil {
  1470. br.Msg = "获取煤炭数据失败"
  1471. br.ErrMsg = "获取煤炭度数据失败,Err:" + err.Error()
  1472. return
  1473. }
  1474. total, err := data_manage.GetCountFromFirm(*classify)
  1475. if err != nil {
  1476. br.Msg = "获取煤炭数据失败"
  1477. br.ErrMsg = "获取煤炭度数据失败,Err:" + err.Error()
  1478. return
  1479. }
  1480. page := paging.GetPaging(currentIndex, pageSize, total)
  1481. var resp data_manage.CoalmineDataPageResp
  1482. for i, item := range items {
  1483. if i == 0 {
  1484. resp.ModifyTime = item.CreateTime
  1485. }
  1486. resp.Paging = page
  1487. resp.IndexName = item.IndexName
  1488. resp.IndexCode = item.IndexCode
  1489. resp.Unit = item.Unit
  1490. resp.Frequency = item.Frequency
  1491. //组装dataList
  1492. var dataItem data_manage.DataList
  1493. dataItem.DataTime = item.DataTime
  1494. dataItem.Value = item.DealValue
  1495. resp.DataList = append(resp.DataList, dataItem)
  1496. }
  1497. lists = append(lists, resp)
  1498. }
  1499. br.Ret = 200
  1500. br.Success = true
  1501. br.Msg = "获取成功"
  1502. br.Data = lists
  1503. case 4:
  1504. classifies, err := data_manage.GetClassifyCoastalByGroupName(groupName)
  1505. if err != nil {
  1506. br.Msg = "获取煤炭数据失败"
  1507. br.ErrMsg = "获取煤炭度数据失败,Err:" + err.Error()
  1508. return
  1509. }
  1510. var lists []data_manage.CoalmineDataPageResp
  1511. for _, classify := range classifies {
  1512. items, err := data_manage.GetPageFromCoalmineCoastalIndexByFrequency(frequency, *classify, startSize, pageSize)
  1513. if err != nil {
  1514. br.Msg = "获取煤炭数据失败"
  1515. br.ErrMsg = "获取煤炭度数据失败,Err:" + err.Error()
  1516. return
  1517. }
  1518. total, err := data_manage.GetCountFromCoastal(*classify)
  1519. if err != nil {
  1520. br.Msg = "获取煤炭数据失败"
  1521. br.ErrMsg = "获取煤炭度数据失败,Err:" + err.Error()
  1522. return
  1523. }
  1524. page := paging.GetPaging(currentIndex, pageSize, total)
  1525. var resp data_manage.CoalmineDataPageResp
  1526. for i, item := range items {
  1527. if i == 0 {
  1528. resp.ModifyTime = item.CreateTime
  1529. }
  1530. resp.Paging = page
  1531. resp.IndexName = item.IndexName
  1532. resp.IndexCode = item.IndexCode
  1533. resp.Unit = item.Unit
  1534. resp.Frequency = item.Frequency
  1535. //组装dataList
  1536. var dataItem data_manage.DataList
  1537. dataItem.DataTime = item.DataTime
  1538. dataItem.Value = item.DealValue
  1539. resp.DataList = append(resp.DataList, dataItem)
  1540. }
  1541. lists = append(lists, resp)
  1542. }
  1543. br.Ret = 200
  1544. br.Success = true
  1545. br.Msg = "获取成功"
  1546. br.Data = lists
  1547. case 5:
  1548. classifies, err := data_manage.GetClassifyInlandByGroupName(groupName)
  1549. if err != nil {
  1550. br.Msg = "获取煤炭数据失败"
  1551. br.ErrMsg = "获取煤炭度数据失败,Err:" + err.Error()
  1552. return
  1553. }
  1554. var lists []data_manage.CoalmineDataPageResp
  1555. for _, classify := range classifies {
  1556. items, err := data_manage.GetPageFromCoalmineInlandIndexByFrequency(frequency, *classify, startSize, pageSize)
  1557. if err != nil {
  1558. br.Msg = "获取煤炭数据失败"
  1559. br.ErrMsg = "获取煤炭度数据失败,Err:" + err.Error()
  1560. return
  1561. }
  1562. total, err := data_manage.GetCountFromInland(*classify)
  1563. if err != nil {
  1564. br.Msg = "获取煤炭数据失败"
  1565. br.ErrMsg = "获取煤炭度数据失败,Err:" + err.Error()
  1566. return
  1567. }
  1568. page := paging.GetPaging(currentIndex, pageSize, total)
  1569. var resp data_manage.CoalmineDataPageResp
  1570. for i, item := range items {
  1571. if i == 0 {
  1572. resp.ModifyTime = item.CreateTime
  1573. }
  1574. resp.Paging = page
  1575. resp.IndexName = item.IndexName
  1576. resp.IndexCode = item.IndexCode
  1577. resp.Unit = item.Unit
  1578. resp.Frequency = item.Frequency
  1579. //组装dataList
  1580. var dataItem data_manage.DataList
  1581. dataItem.DataTime = item.DataTime
  1582. dataItem.Value = item.DealValue
  1583. resp.DataList = append(resp.DataList, dataItem)
  1584. }
  1585. lists = append(lists, resp)
  1586. }
  1587. br.Ret = 200
  1588. br.Success = true
  1589. br.Msg = "获取成功"
  1590. br.Data = lists
  1591. default:
  1592. br.Ret = 200
  1593. br.Success = true
  1594. br.Msg = "获取煤炭数据失败"
  1595. br.ErrMsg = "获取煤炭度数据失败,Err: classifyId 错误"
  1596. return
  1597. }
  1598. }
  1599. // CoalSearchList
  1600. // @Title 煤炭网模糊搜索
  1601. // @Description 煤炭网模糊搜索
  1602. // @Param Keyword query string ture "关键字搜索"
  1603. // @Success 200 {object} models.BaseResponse
  1604. // @router /data/coalMineData/search [get]
  1605. func (this *TradeCommonController) CoalSearchList() {
  1606. br := new(models.BaseResponse).Init()
  1607. defer func() {
  1608. this.Data["json"] = br
  1609. this.ServeJSON()
  1610. }()
  1611. //关键字
  1612. keyword := this.GetString("Keyword")
  1613. list, err := data_manage.GetCoalItemList(keyword)
  1614. if err != nil {
  1615. br.ErrMsg = "获取失败,Err:" + err.Error()
  1616. br.Msg = "获取失败"
  1617. return
  1618. }
  1619. br.Ret = 200
  1620. br.Success = true
  1621. br.Msg = "获取成功"
  1622. br.Data = list
  1623. }
  1624. // CoalSingleData
  1625. // @Title 获取煤炭单条数据
  1626. // @Description 获取煤炭单条数据
  1627. // @Param IndexCode query string true "指标唯一编码"
  1628. // @Success 200 {object} []data_manage.CoalmineSingalDataResp
  1629. // @router /data/coalMineData/single_data [get]
  1630. func (this *TradeCommonController) CoalSingleData() {
  1631. br := new(models.BaseResponse).Init()
  1632. defer func() {
  1633. this.Data["json"] = br
  1634. this.ServeJSON()
  1635. }()
  1636. indexCode := this.GetString("IndexCode")
  1637. var classifyId int
  1638. var suffix string
  1639. if strings.Contains(indexCode, "jsm") {
  1640. classifyId = 1
  1641. suffix = "jsm_index"
  1642. } else if strings.Contains(indexCode, "company") {
  1643. classifyId = 2
  1644. suffix = "company_index"
  1645. } else if strings.Contains(indexCode, "firm") {
  1646. classifyId = 3
  1647. suffix = "firm_index"
  1648. } else if strings.Contains(indexCode, "coastal") {
  1649. classifyId = 4
  1650. suffix = "coastal_index"
  1651. } else if strings.Contains(indexCode, "inland") {
  1652. classifyId = 5
  1653. suffix = "inland_index"
  1654. }
  1655. switch classifyId {
  1656. case 1:
  1657. items, err := data_manage.GetBaseFromCoalmineIndexByCode(indexCode)
  1658. if err != nil {
  1659. br.Msg = "获取煤炭数据失败"
  1660. br.ErrMsg = "获取煤炭度数据失败,Err:" + err.Error()
  1661. return
  1662. }
  1663. groups, err := data_manage.GetProvinceFromCoalmineIndex(suffix)
  1664. if err != nil {
  1665. br.Msg = "获取煤炭分类数据失败"
  1666. br.ErrMsg = "获取煤炭度分类数据失败,Err: " + err.Error()
  1667. return
  1668. }
  1669. groupMap := make(map[string]int)
  1670. jsmId := 100
  1671. for _, group := range groups {
  1672. jsmId++
  1673. groupMap[*group] = jsmId
  1674. }
  1675. var lists []data_manage.CoalmineSingalDataResp
  1676. var resp data_manage.CoalmineSingalDataResp
  1677. classify := items[0].IndexName
  1678. for i, item := range items {
  1679. if item.IndexName != classify {
  1680. lists = append(lists, resp)
  1681. classify = item.IndexName
  1682. }
  1683. resp.IndexName = item.IndexName
  1684. resp.IndexCode = item.IndexCode
  1685. resp.GroupId = groupMap[item.Province]
  1686. resp.GroupName = item.Province
  1687. resp.Unit = item.Unit
  1688. resp.Frequency = item.Frequency
  1689. resp.ModifyTime = item.ModifyTime
  1690. resp.ClassifyId = classifyId
  1691. //组装dataList
  1692. var dataItem data_manage.DataList
  1693. dataItem.DataTime = item.DataTime
  1694. dataItem.Value = item.DealValue
  1695. resp.DataList = append(resp.DataList, dataItem)
  1696. if i == len(items)-1 {
  1697. lists = append(lists, resp)
  1698. }
  1699. }
  1700. br.Ret = 200
  1701. br.Success = true
  1702. br.Msg = "获取成功"
  1703. br.Data = lists
  1704. case 2:
  1705. items, err := data_manage.GetBaseFromCoalmineCompanyIndexByCode(indexCode)
  1706. if err != nil {
  1707. br.Msg = "获取煤炭数据失败"
  1708. br.ErrMsg = "获取煤炭度数据失败,Err:" + err.Error()
  1709. return
  1710. }
  1711. groups, err := data_manage.GetGroupNameFromCoalmineIndex(suffix)
  1712. if err != nil {
  1713. br.Msg = "获取煤炭分类数据失败"
  1714. br.ErrMsg = "获取煤炭度分类数据失败,Err: " + err.Error()
  1715. return
  1716. }
  1717. groupMap := make(map[string]int)
  1718. companyId := 200
  1719. for _, group := range groups {
  1720. companyId++
  1721. groupMap[*group] = companyId
  1722. }
  1723. var lists []data_manage.CoalmineSingalDataResp
  1724. var resp data_manage.CoalmineSingalDataResp
  1725. classify := items[0].IndexName
  1726. for i, item := range items {
  1727. if item.IndexName != classify {
  1728. lists = append(lists, resp)
  1729. classify = item.IndexName
  1730. }
  1731. resp.IndexName = item.IndexName
  1732. resp.IndexCode = item.IndexCode
  1733. resp.Unit = item.Unit
  1734. resp.GroupId = groupMap[item.GroupName]
  1735. resp.GroupName = item.GroupName
  1736. resp.Frequency = item.Frequency
  1737. resp.ModifyTime = item.ModifyTime
  1738. resp.ClassifyId = classifyId
  1739. //组装dataList
  1740. var dataItem data_manage.DataList
  1741. dataItem.DataTime = item.DataTime
  1742. dataItem.Value = item.DealValue
  1743. resp.DataList = append(resp.DataList, dataItem)
  1744. if i == len(items)-1 {
  1745. lists = append(lists, resp)
  1746. }
  1747. }
  1748. br.Ret = 200
  1749. br.Success = true
  1750. br.Msg = "获取成功"
  1751. br.Data = lists
  1752. case 3:
  1753. items, err := data_manage.GetBaseFromCoalmineFirmIndexByCode(indexCode)
  1754. if err != nil {
  1755. br.Msg = "获取煤炭数据失败"
  1756. br.ErrMsg = "获取煤炭度数据失败,Err:" + err.Error()
  1757. return
  1758. }
  1759. groups, err := data_manage.GetGroupNameFromCoalmineIndex(suffix)
  1760. if err != nil {
  1761. br.Msg = "获取煤炭分类数据失败"
  1762. br.ErrMsg = "获取煤炭度分类数据失败,Err: " + err.Error()
  1763. return
  1764. }
  1765. groupMap := make(map[string]int)
  1766. firmId := 300
  1767. for _, group := range groups {
  1768. firmId++
  1769. groupMap[*group] = firmId
  1770. }
  1771. var lists []data_manage.CoalmineSingalDataResp
  1772. var resp data_manage.CoalmineSingalDataResp
  1773. classify := items[0].IndexName
  1774. for i, item := range items {
  1775. if item.IndexName != classify {
  1776. lists = append(lists, resp)
  1777. classify = item.IndexName
  1778. }
  1779. resp.IndexName = item.IndexName
  1780. resp.IndexCode = item.IndexCode
  1781. resp.Unit = item.Unit
  1782. resp.GroupId = groupMap[item.GroupName]
  1783. resp.GroupName = item.GroupName
  1784. resp.Frequency = item.Frequency
  1785. resp.ModifyTime = item.ModifyTime
  1786. resp.ClassifyId = classifyId
  1787. //组装dataList
  1788. var dataItem data_manage.DataList
  1789. dataItem.DataTime = item.DataTime
  1790. dataItem.Value = item.DealValue
  1791. resp.DataList = append(resp.DataList, dataItem)
  1792. if i == len(items)-1 {
  1793. lists = append(lists, resp)
  1794. }
  1795. }
  1796. br.Ret = 200
  1797. br.Success = true
  1798. br.Msg = "获取成功"
  1799. br.Data = lists
  1800. case 4:
  1801. items, err := data_manage.GetBaseFromCoalmineCoastalIndexByCode(indexCode)
  1802. if err != nil {
  1803. br.Msg = "获取煤炭数据失败"
  1804. br.ErrMsg = "获取煤炭度数据失败,Err:" + err.Error()
  1805. return
  1806. }
  1807. groups, err := data_manage.GetGroupNameFromCoalmineIndex(suffix)
  1808. if err != nil {
  1809. br.Msg = "获取煤炭分类数据失败"
  1810. br.ErrMsg = "获取煤炭度分类数据失败,Err: " + err.Error()
  1811. return
  1812. }
  1813. groupMap := make(map[string]int)
  1814. coastalId := 400
  1815. for _, group := range groups {
  1816. coastalId++
  1817. groupMap[*group] = coastalId
  1818. }
  1819. var lists []data_manage.CoalmineSingalDataResp
  1820. var resp data_manage.CoalmineSingalDataResp
  1821. classify := items[0].IndexName
  1822. for i, item := range items {
  1823. if item.IndexName != classify {
  1824. lists = append(lists, resp)
  1825. classify = item.IndexName
  1826. }
  1827. resp.IndexName = item.IndexName
  1828. resp.IndexCode = item.IndexCode
  1829. resp.Unit = item.Unit
  1830. resp.GroupId = groupMap[item.GroupName]
  1831. resp.GroupName = item.GroupName
  1832. resp.Frequency = item.Frequency
  1833. resp.ModifyTime = item.ModifyTime
  1834. resp.ClassifyId = classifyId
  1835. //组装dataList
  1836. var dataItem data_manage.DataList
  1837. dataItem.DataTime = item.DataTime
  1838. dataItem.Value = item.DealValue
  1839. resp.DataList = append(resp.DataList, dataItem)
  1840. if i == len(items)-1 {
  1841. lists = append(lists, resp)
  1842. }
  1843. }
  1844. br.Ret = 200
  1845. br.Success = true
  1846. br.Msg = "获取成功"
  1847. br.Data = lists
  1848. case 5:
  1849. items, err := data_manage.GetBaseFromCoalmineInlandIndexByCode(indexCode)
  1850. if err != nil {
  1851. br.Msg = "获取煤炭数据失败"
  1852. br.ErrMsg = "获取煤炭度数据失败,Err:" + err.Error()
  1853. return
  1854. }
  1855. groups, err := data_manage.GetGroupNameFromCoalmineIndex(suffix)
  1856. if err != nil {
  1857. br.Msg = "获取煤炭分类数据失败"
  1858. br.ErrMsg = "获取煤炭度分类数据失败,Err: " + err.Error()
  1859. return
  1860. }
  1861. groupMap := make(map[string]int)
  1862. inlandId := 500
  1863. for _, group := range groups {
  1864. inlandId++
  1865. groupMap[*group] = inlandId
  1866. }
  1867. var lists []data_manage.CoalmineSingalDataResp
  1868. var resp data_manage.CoalmineSingalDataResp
  1869. classify := items[0].IndexName
  1870. for i, item := range items {
  1871. if item.IndexName != classify {
  1872. lists = append(lists, resp)
  1873. classify = item.IndexName
  1874. }
  1875. resp.IndexName = item.IndexName
  1876. resp.IndexCode = item.IndexCode
  1877. resp.Unit = item.Unit
  1878. resp.GroupId = groupMap[item.GroupName]
  1879. resp.GroupName = item.GroupName
  1880. resp.Frequency = item.Frequency
  1881. resp.ModifyTime = item.ModifyTime
  1882. resp.ClassifyId = classifyId
  1883. //组装dataList
  1884. var dataItem data_manage.DataList
  1885. dataItem.DataTime = item.DataTime
  1886. dataItem.Value = item.DealValue
  1887. resp.DataList = append(resp.DataList, dataItem)
  1888. if i == len(items)-1 {
  1889. lists = append(lists, resp)
  1890. }
  1891. }
  1892. br.Ret = 200
  1893. br.Success = true
  1894. br.Msg = "获取成功"
  1895. br.Data = lists
  1896. default:
  1897. br.Msg = "获取煤炭数据失败"
  1898. br.ErrMsg = "获取煤炭度数据失败,Err: indexCode 错误"
  1899. return
  1900. }
  1901. }
  1902. // ExportCoalList
  1903. // @Title 导出煤炭数据
  1904. // @Description 导出煤炭数据
  1905. // @Param ClassifyId query int true "数据id"
  1906. // @Param IndexName query string true "名称关键词"
  1907. // @Param IndexCode query string true "指标唯一编码"
  1908. // @Param TypeName query string true "分类"
  1909. // @Param Frequency query string false "频度"
  1910. // @Param UnitName query string false "单位"
  1911. // @Success 200 导出成功
  1912. // @router /export/coalList [get]
  1913. func (this *TradeCommonController) ExportCoalList() {
  1914. br := new(models.BaseResponse).Init()
  1915. defer func() {
  1916. this.Data["json"] = br
  1917. this.ServeJSON()
  1918. }()
  1919. classifyId, _ := this.GetInt("ClassifyId")
  1920. var suffix string
  1921. if classifyId == 1 {
  1922. suffix = "jsm_index"
  1923. } else if classifyId == 2 {
  1924. suffix = "company_index"
  1925. } else if classifyId == 3 {
  1926. suffix = "firm_index"
  1927. } else if classifyId == 4 {
  1928. suffix = "coastal_index"
  1929. } else if classifyId == 5 {
  1930. suffix = "inland_index"
  1931. }
  1932. breedName := this.GetString("TypeName") //分类
  1933. secNameList := make([]*models.EdbdataExportList, 0)
  1934. dir, _ := os.Executable()
  1935. exPath := filepath.Dir(dir)
  1936. downLoadnFilePath := exPath + "/" + time.Now().Format(utils.FormatDateTimeUnSpace) + ".xlsx"
  1937. xlsxFile := xlsx.NewFile()
  1938. //不为空就是导出分类表
  1939. if breedName != "" {
  1940. //获取指标
  1941. var secNameList []*string
  1942. var err error
  1943. if classifyId == 1 {
  1944. secNameList, err = data_manage.GetClassifyJsmByGroupName(breedName)
  1945. if err != nil {
  1946. fmt.Println("获取数据失败,Err:" + err.Error())
  1947. return
  1948. }
  1949. } else {
  1950. secNameList, err = data_manage.GetClassifyFromCoalByGroupName(suffix, breedName)
  1951. if err != nil {
  1952. fmt.Println("获取数据失败,Err:" + err.Error())
  1953. return
  1954. }
  1955. }
  1956. if len(secNameList) <= 0 {
  1957. fmt.Println("secNameList长度为0")
  1958. return
  1959. }
  1960. sheetNew, err := xlsxFile.AddSheet(breedName)
  1961. if err != nil {
  1962. fmt.Println("新增Sheet失败", err.Error())
  1963. return
  1964. }
  1965. //sheetNew.SetColWidth()
  1966. //获取指标数据
  1967. windRow := sheetNew.AddRow()
  1968. secNameRow := sheetNew.AddRow()
  1969. indexCodeRow := sheetNew.AddRow()
  1970. frequencyRow := sheetNew.AddRow()
  1971. unitRow := sheetNew.AddRow()
  1972. lastModifyDateRow := sheetNew.AddRow()
  1973. //获取分类下指标最大数据量
  1974. var dataMax int
  1975. if classifyId == 1 {
  1976. dataMax, err = data_manage.GetCoalJsmMaxCount(breedName)
  1977. if err != nil {
  1978. fmt.Println("获取指标最大数据量失败", err.Error())
  1979. return
  1980. }
  1981. } else {
  1982. dataMax, err = data_manage.GetCoalCompanyMaxCount(suffix, breedName)
  1983. if err != nil {
  1984. fmt.Println("获取指标最大数据量失败", err.Error())
  1985. return
  1986. }
  1987. }
  1988. setRowIndex := 6
  1989. for k, sv := range secNameList {
  1990. //获取数据
  1991. dataList, err := data_manage.GetBaseFromCoalIndexByCode(suffix, *sv)
  1992. if err != nil {
  1993. br.Msg = "获取数据失败"
  1994. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  1995. return
  1996. }
  1997. windRow.AddCell().SetValue(breedName)
  1998. secNameRow.AddCell().SetValue("指标名称")
  1999. indexCodeRow.AddCell().SetValue("指标ID")
  2000. frequencyRow.AddCell().SetValue("频率")
  2001. unitRow.AddCell().SetValue("单位")
  2002. lastModifyDateRow.AddCell().SetValue("更新时间")
  2003. secNameRow.AddCell().SetValue(dataList[0].IndexName)
  2004. indexCodeRow.AddCell().SetValue(dataList[0].IndexCode)
  2005. frequencyRow.AddCell().SetValue(dataList[0].Frequency)
  2006. unitRow.AddCell().SetValue(dataList[0].Unit)
  2007. lastModifyDateRow.AddCell().SetValue(dataList[0].ModifyTime)
  2008. windRow.AddCell()
  2009. windRow.AddCell()
  2010. secNameRow.AddCell()
  2011. indexCodeRow.AddCell()
  2012. frequencyRow.AddCell()
  2013. unitRow.AddCell()
  2014. lastModifyDateRow.AddCell()
  2015. min := k * 3
  2016. sheetNew.SetColWidth(min, min, 15)
  2017. if len(dataList) <= 0 {
  2018. for n := 0; n < dataMax; n++ {
  2019. rowIndex := setRowIndex + n
  2020. row := sheetNew.Row(rowIndex)
  2021. row.AddCell()
  2022. row.AddCell()
  2023. row.AddCell()
  2024. }
  2025. } else {
  2026. endRowIndex := 0
  2027. for rk, dv := range dataList {
  2028. rowIndex := setRowIndex + rk
  2029. row := sheetNew.Row(rowIndex)
  2030. if classifyId == 3 {
  2031. displayDateCell := row.AddCell()
  2032. displayDateCell.SetValue(dv.DataTime)
  2033. } else {
  2034. displayDate, _ := time.Parse(utils.FormatDate, dv.DataTime)
  2035. displayDateCell := row.AddCell()
  2036. style := new(xlsx.Style)
  2037. style.ApplyAlignment = true
  2038. style.Alignment.WrapText = true
  2039. displayDateCell.SetStyle(style)
  2040. displayDateCell.SetDate(displayDate)
  2041. }
  2042. row.AddCell().SetValue(dv.DealValue)
  2043. row.AddCell()
  2044. endRowIndex = rowIndex
  2045. }
  2046. if len(dataList) < dataMax {
  2047. dataLen := dataMax - len(dataList)
  2048. for n := 0; n < dataLen; n++ {
  2049. rowIndex := (endRowIndex + 1) + n
  2050. row := sheetNew.Row(rowIndex)
  2051. row.AddCell()
  2052. row.AddCell()
  2053. row.AddCell()
  2054. }
  2055. }
  2056. }
  2057. }
  2058. } else {
  2059. name := this.GetString("IndexName")
  2060. indexCode := this.GetString("IndexCode") //指标唯一编码
  2061. unit := this.GetString("UnitName")
  2062. modifyTime := this.GetString("ModifyTime")
  2063. sheet, err := xlsxFile.AddSheet("指标")
  2064. if err != nil {
  2065. br.Msg = "新增Sheet失败"
  2066. br.ErrMsg = "新增Sheet失败,Err:" + err.Error()
  2067. return
  2068. }
  2069. //获取数据
  2070. dataList, err := data_manage.GetBaseFromCoalIndexByCode(suffix, indexCode)
  2071. if err != nil {
  2072. br.Msg = "获取数据失败"
  2073. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  2074. return
  2075. }
  2076. //获取指标数据
  2077. windRow := sheet.AddRow()
  2078. windRow.AddCell().SetValue("中国煤炭网")
  2079. rowSecName := sheet.AddRow()
  2080. celSecName := rowSecName.AddCell()
  2081. celSecName.SetValue("指标名称")
  2082. cellSenName := rowSecName.AddCell()
  2083. cellSenName.SetValue(name)
  2084. indexCodeRow := sheet.AddRow()
  2085. indexCodeRow.AddCell().SetValue("指标ID")
  2086. indexCodeRow.AddCell().SetValue(indexCode)
  2087. rowFrequency := sheet.AddRow()
  2088. celFrequency := rowFrequency.AddCell()
  2089. celFrequency.SetValue("频率")
  2090. rowFrequency.AddCell().SetValue(dataList[0].Frequency)
  2091. rowUnit := sheet.AddRow()
  2092. celUnit := rowUnit.AddCell()
  2093. celUnit.SetValue("单位")
  2094. cellUnit := rowUnit.AddCell()
  2095. cellUnit.SetValue(unit)
  2096. rowModifyDate := sheet.AddRow()
  2097. rowModifyCell := rowModifyDate.AddCell()
  2098. rowModifyCell.SetValue("更新时间")
  2099. rowModifyCell = rowModifyDate.AddCell()
  2100. rowModifyCell.SetValue(modifyTime)
  2101. fmt.Println("len(dataList):", len(dataList))
  2102. dataMax, err := data_manage.GetCoalCount(suffix, breedName)
  2103. if err != nil {
  2104. fmt.Println("获取指标最大数据量失败", err.Error())
  2105. return
  2106. }
  2107. fmt.Println("dataMax:", dataMax)
  2108. if len(dataList) <= 0 {
  2109. for n := 0; n < dataMax; n++ {
  2110. rowIndex := 6 + n
  2111. row := sheet.Row(rowIndex)
  2112. row.AddCell()
  2113. row.AddCell()
  2114. row.AddCell()
  2115. }
  2116. } else {
  2117. endRowIndex := 0
  2118. for rk, dv := range dataList {
  2119. rowIndex := 6 + rk
  2120. row := sheet.Row(rowIndex)
  2121. displayDate, _ := time.Parse(utils.FormatDate, dv.DataTime)
  2122. displayDateCell := row.AddCell()
  2123. style := new(xlsx.Style)
  2124. style.ApplyAlignment = true
  2125. style.Alignment.WrapText = true
  2126. displayDateCell.SetStyle(style)
  2127. displayDateCell.SetDate(displayDate)
  2128. row.AddCell().SetValue(dv.DealValue)
  2129. row.AddCell()
  2130. endRowIndex = rowIndex
  2131. }
  2132. if len(dataList) < dataMax {
  2133. dataLen := dataMax - len(dataList)
  2134. for n := 0; n < dataLen; n++ {
  2135. rowIndex := (endRowIndex + 1) + n
  2136. row := sheet.Row(rowIndex)
  2137. row.AddCell()
  2138. row.AddCell()
  2139. row.AddCell()
  2140. }
  2141. }
  2142. }
  2143. }
  2144. err := xlsxFile.Save(downLoadnFilePath)
  2145. if err != nil {
  2146. br.Msg = "保存文件失败"
  2147. br.ErrMsg = "保存文件失败"
  2148. return
  2149. }
  2150. fileName := `中国煤炭网数据`
  2151. if len(secNameList) > 0 {
  2152. fileName = secNameList[0].ClassifyName
  2153. }
  2154. fileName += time.Now().Format("06.01.02") + `.xlsx` //文件名称
  2155. this.Ctx.Output.Download(downLoadnFilePath, fileName)
  2156. defer func() {
  2157. os.Remove(downLoadnFilePath)
  2158. }()
  2159. br.Ret = 200
  2160. br.Success = true
  2161. br.Msg = "success"
  2162. }
  2163. // EicLatestDateV2
  2164. // @title 获取欧洲天然气最新日期V2
  2165. // @Description 获取欧洲天然气最新日期接口
  2166. // @Success 200 {object} models.
  2167. // @router /data/eicLatestDateV2 [get]
  2168. func (this *TradeCommonController) EicLatestDateV2() {
  2169. br := new(models.BaseResponse).Init()
  2170. defer func() {
  2171. this.Data["json"] = br
  2172. this.ServeJSON()
  2173. }()
  2174. latestData, err := data_manage.GetEicDateV2()
  2175. if err != nil {
  2176. br.Msg = "获取日期失败"
  2177. br.ErrMsg = "获取日期失败,Err:" + err.Error()
  2178. return
  2179. }
  2180. br.Ret = 200
  2181. br.Success = true
  2182. br.Msg = "获取成功"
  2183. br.Data = latestData[0].GasDayStart
  2184. }
  2185. type EicDataV2 struct {
  2186. Name string `json:"name" description:"指标名称"`
  2187. Code string `json:"code" description:"指标编码"`
  2188. GasDayStart string `json:"gasDayStart" description:"指标日期"`
  2189. GasInStorage float64 `json:"gasInStorage" description:"储存容量"`
  2190. Consumption string `json:"consumption" description:"消耗"`
  2191. ConsumptionFull string `json:"consumptionFull" description:"消耗百分比"`
  2192. Injection float64 `json:"injection" description:"注入量"`
  2193. Withdrawal float64 `json:"withdrawal" description:"减少量"`
  2194. WorkingGasVolume float64 `json:"workingGasVolume" description:"工作气体量"`
  2195. InjectionCapacity float64 `json:"injectionCapacity" description:"注入速度"`
  2196. WithdrawalCapacity float64 `json:"withdrawalCapacity" description:"减少速度"`
  2197. Status string `json:"status" description:"状态"`
  2198. Trend float64 `json:"trend" description:"较前日对比"`
  2199. Full float64 `json:"full" description:"储存容量百分比"`
  2200. Info string `json:"info" description:"信息"`
  2201. Children []EicDataV2 `json:"children"`
  2202. }
  2203. // eicDataV2
  2204. // @title 获取欧洲天然气列表
  2205. // @Description 获取欧洲天然气列表接口
  2206. // @Param Date query string true "查询日期"
  2207. // @Success 200 {object} models.
  2208. // @router /data/eicDataV2 [get]
  2209. func (this *TradeCommonController) EicDataV2() {
  2210. br := new(models.BaseResponse).Init()
  2211. defer func() {
  2212. this.Data["json"] = br
  2213. this.ServeJSON()
  2214. }()
  2215. date := this.GetString("Date")
  2216. list, err := data_manage.GetEicDataV2(date)
  2217. if err != nil {
  2218. br.Msg = "获取天然气数据失败"
  2219. br.ErrMsg = "获取天然气数据失败,Err:" + err.Error()
  2220. return
  2221. }
  2222. var continentItems []data_manage.BaseFromTradeEicIndexV2
  2223. var countryItems []data_manage.BaseFromTradeEicIndexV2
  2224. var ssoItems []data_manage.BaseFromTradeEicIndexV2
  2225. var facItems []data_manage.BaseFromTradeEicIndexV2
  2226. for _, item := range list {
  2227. switch item.Type {
  2228. case "continent":
  2229. continentItems = append(continentItems, *item)
  2230. case "country":
  2231. countryItems = append(countryItems, *item)
  2232. case "sso":
  2233. ssoItems = append(ssoItems, *item)
  2234. case "fac":
  2235. facItems = append(facItems, *item)
  2236. default:
  2237. continue
  2238. }
  2239. }
  2240. var data []data_manage.BaseFromTradeEicIndexV2
  2241. data = continentItems
  2242. for i, continentItem := range continentItems {
  2243. for _, countryItem := range countryItems {
  2244. if countryItem.Parent == continentItem.Name {
  2245. data[i].Children = append(data[i].Children, countryItem)
  2246. }
  2247. }
  2248. for j, country := range data[i].Children {
  2249. for _, ssoItem := range ssoItems {
  2250. if country.Name == ssoItem.Parent {
  2251. data[i].Children[j].Children = append(data[i].Children[j].Children, ssoItem)
  2252. }
  2253. }
  2254. for k, sso := range data[i].Children[j].Children {
  2255. for _, facItem := range facItems {
  2256. if sso.Name == facItem.Parent {
  2257. data[i].Children[j].Children[k].Children = append(data[i].Children[j].Children[k].Children, facItem)
  2258. }
  2259. }
  2260. }
  2261. }
  2262. }
  2263. br.Ret = 200
  2264. br.Success = true
  2265. br.Msg = "获取成功"
  2266. br.Data = data
  2267. }
  2268. // EicHistoryDataV2
  2269. // @title 获取欧洲天然气历史列表
  2270. // @Description 获取欧洲天然气历史列表接口
  2271. // @Param Code query string true "Code"
  2272. // @Param StartDate query string false "开始时间"
  2273. // @Param EndDate query string false "结束时间"
  2274. // @Success 200 {object} []EicDataV2
  2275. // @router /data/eicHistoryDataV2 [get]
  2276. func (this *TradeCommonController) EicHistoryDataV2() {
  2277. br := new(models.BaseResponse).Init()
  2278. defer func() {
  2279. this.Data["json"] = br
  2280. this.ServeJSON()
  2281. }()
  2282. code := this.GetString("Code")
  2283. startDate := this.GetString("StartDate")
  2284. endDate := this.GetString("EndDate")
  2285. var eicList []*data_manage.BaseFromTradeEicIndexV2
  2286. var err error
  2287. if endDate != "" {
  2288. eicList, err = data_manage.GetEicHistoryDateByDateV2(code, startDate, endDate)
  2289. if err != nil {
  2290. br.Msg = "获取持仓排名失败"
  2291. br.ErrMsg = "获取持仓排名失败,Err:" + err.Error()
  2292. return
  2293. }
  2294. } else {
  2295. eicList, err = data_manage.GetEicHistoryDateV2(code)
  2296. if err != nil {
  2297. br.Msg = "获取持仓排名失败"
  2298. br.ErrMsg = "获取持仓排名失败,Err:" + err.Error()
  2299. return
  2300. }
  2301. }
  2302. var data []EicDataV2
  2303. for _, eic := range eicList {
  2304. item := EicDataV2{
  2305. Name: eic.Name,
  2306. Code: eic.EicCode,
  2307. GasDayStart: eic.GasDayStart,
  2308. GasInStorage: eic.GasInStorage,
  2309. Consumption: eic.Consumption,
  2310. ConsumptionFull: eic.ConsumptionFull,
  2311. Injection: eic.Injection,
  2312. Withdrawal: eic.Withdrawal,
  2313. WorkingGasVolume: eic.WorkingGasVolume,
  2314. InjectionCapacity: eic.InjectionCapacity,
  2315. WithdrawalCapacity: eic.WithdrawalCapacity,
  2316. Status: eic.Status,
  2317. Trend: eic.Trend,
  2318. Full: eic.Full,
  2319. Info: eic.Info,
  2320. }
  2321. data = append(data, item)
  2322. }
  2323. br.Ret = 200
  2324. br.Success = true
  2325. br.Msg = "获取成功"
  2326. br.Data = data
  2327. }
  2328. // eicContinentV2 欧洲天然气洲际及国家级列表
  2329. // @title 欧洲天然气洲际及国家级列表
  2330. // @Description 欧洲天然气洲际及国家级列表
  2331. // @Param Date query string true "查询日期"
  2332. // @Success 200 {object} []data_manage.BaseFromTradeEicIndexV2
  2333. // @router /data/eicContinentV2 [get]
  2334. func (this *TradeCommonController) EicContinentListV2() {
  2335. br := new(models.BaseResponse).Init()
  2336. defer func() {
  2337. this.Data["json"] = br
  2338. this.ServeJSON()
  2339. }()
  2340. date := this.GetString("Date")
  2341. list, err := data_manage.GetContinentAndCountryEicDateV2(date)
  2342. if err != nil {
  2343. br.Msg = "获取天然气数据失败"
  2344. br.ErrMsg = "获取天然气数据失败,Err:" + err.Error()
  2345. return
  2346. }
  2347. var continentItems []data_manage.BaseFromTradeEicIndexV2
  2348. var countryItems []data_manage.BaseFromTradeEicIndexV2
  2349. for _, item := range list {
  2350. switch item.Type {
  2351. case "continent":
  2352. continentItems = append(continentItems, *item)
  2353. case "country":
  2354. countryItems = append(countryItems, *item)
  2355. default:
  2356. continue
  2357. }
  2358. }
  2359. var data []data_manage.BaseFromTradeEicIndexV2
  2360. data = continentItems
  2361. for i, continentItem := range continentItems {
  2362. for _, countryItem := range countryItems {
  2363. if countryItem.Parent == continentItem.Name {
  2364. data[i].Children = append(data[i].Children, countryItem)
  2365. }
  2366. }
  2367. }
  2368. br.Ret = 200
  2369. br.Success = true
  2370. br.Msg = "获取成功"
  2371. br.Data = data
  2372. }
  2373. // EicDataListV2 欧洲天然气细节列表
  2374. // @title 欧洲天然气细节列表
  2375. // @Description 欧洲天然气细节列表
  2376. // @Param Date query string true "查询日期"
  2377. // @Param Name query string true "国家"
  2378. // @Success 200 {object} []data_manage.BaseFromTradeEicIndexV2
  2379. // @router /data/eicSSODataV2 [get]
  2380. func (this *TradeCommonController) EicDataListV2() {
  2381. br := new(models.BaseResponse).Init()
  2382. defer func() {
  2383. this.Data["json"] = br
  2384. this.ServeJSON()
  2385. }()
  2386. date := this.GetString("Date")
  2387. name := this.GetString("Name")
  2388. list, err := data_manage.GetSSOAndFacEicDateV2(date, name)
  2389. if err != nil {
  2390. br.Msg = "获取天然气数据失败"
  2391. br.ErrMsg = "获取天然气数据失败,Err:" + err.Error()
  2392. return
  2393. }
  2394. var ssoItems []data_manage.BaseFromTradeEicIndexV2
  2395. var facItems []data_manage.BaseFromTradeEicIndexV2
  2396. for _, item := range list {
  2397. switch item.Type {
  2398. case "sso":
  2399. ssoItems = append(ssoItems, *item)
  2400. case "fac":
  2401. facItems = append(facItems, *item)
  2402. default:
  2403. continue
  2404. }
  2405. }
  2406. i := 0
  2407. var data []data_manage.BaseFromTradeEicIndexV2
  2408. for _, ssoItem := range ssoItems {
  2409. if ssoItem.Parent == name {
  2410. data = append(data, ssoItem)
  2411. for _, facItem := range facItems {
  2412. if facItem.Parent == ssoItem.Name {
  2413. data[i].Children = append(data[i].Children, facItem)
  2414. }
  2415. }
  2416. i++
  2417. }
  2418. }
  2419. br.Ret = 200
  2420. br.Success = true
  2421. br.Msg = "获取成功"
  2422. br.Data = data
  2423. }