commodity_trade_base_index.go 86 KB

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