commodity_trade_base_index.go 86 KB

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