123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057 |
- package controllers
- import (
- "eta/eta_mobile/models"
- "eta/eta_mobile/models/data_manage"
- "eta/eta_mobile/utils"
- "fmt"
- "github.com/rdlucklib/rdluck_tools/paging"
- "github.com/tealeg/xlsx"
- "os"
- "path/filepath"
- "strconv"
- "strings"
- "time"
- )
- type TradeCommonController struct {
- BaseAuthController
- }
- type Data []struct {
- Title string
- ItemList []ShanghaiList
- }
- type ShanghaiList struct {
- Code string
- Item []*data_manage.BaseFromTradeShanghaiIndex
- }
- type EicData struct {
- Country string
- Type string
- EicCode string
- ShortName string
- Name string
- Status string
- GasDayStartedOn string
- GasInStorage float64
- GasInStorageCode string
- Full float64
- FullCode string
- Trend float64
- TrendCode string
- Injection float64
- InjectionCode string
- Withdrawal float64
- WithdrawalCode string
- WorkingGasVolume float64
- WorkingGasVolumeCode string
- InjectionCapacity float64
- InjectionCapacityCode string
- WithdrawalCapacity float64
- WithdrawalCapacityCode string
- Info string
- Children []*data_manage.BaseFromTradeEicIndex
- }
- // ExchangeClassify
- // @title 获取交易所种类列表
- // @Description 获取交易所种类列表接口
- // @Param Exchange query string true "交易所名称"
- // @Success 200 {object} models.
- // @router /data/exchange/classify [get]
- func (this *TradeCommonController) ExchangeClassify() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- exchange := this.GetString("Exchange")
- date := this.GetString("DataTime")
- var respItem [][]string
- latestData, err := data_manage.GetLatestDate(exchange)
- if err != nil {
- br.Msg = "获取失败"
- return
- }
- if latestData == "" {
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = respItem
- return
- }
- if date == "" {
- date = latestData
- }
- classifyName, err := data_manage.GetExchangeClassify(exchange, date)
- if err != nil {
- br.Msg = "获取种类失败"
- br.ErrMsg = "获取种类失败,Err:" + err.Error()
- return
- }
- respItem = append(respItem, classifyName)
- respItem = append(respItem, []string{latestData})
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = respItem
- }
- // ExchangeClassifyContract
- // @title 获取交易所种类合约列表
- // @Description 获取交易所种类合约列表接口
- // @Param Exchange query string true "交易所名称"
- // @Param Classify query string true "种类名称"
- // @Param DataTime query string true "时间"
- // @Success 200 {object} models.
- // @router /data/exchange/classifyContract [get]
- func (this *TradeCommonController) ExchangeClassifyContract() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- exchange := this.GetString("Exchange")
- classify := this.GetString("Classify")
- dataTime := this.GetString("DataTime")
- classifyName, err := data_manage.GetExchangeClassifyContract(exchange, classify, dataTime)
- if err != nil {
- br.Msg = "获取种类失败"
- br.ErrMsg = "获取种类失败,Err:" + err.Error()
- return
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = classifyName
- }
- // ShfeDataList
- // @title 获取上期所列表
- // @Description 获取上期所列表接口
- // @Param Date query string true "查询日期"
- // @Param ClassifyName query string false "分类名称"
- // @Param ClassifyType query string false "分类合约"
- // @Success 200 {object} models.
- // @router /data/shfe [get]
- func (this *TradeCommonController) ShfeDataList() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- date := this.GetString("Date")
- classifyName := this.GetString("ClassifyName")
- classifyType := this.GetString("ClassifyType")
- frequencyList, err := data_manage.GetBaseFromTradeIndexByParam("shanghai", date, classifyName, classifyType)
- if err != nil {
- br.Msg = "获取持仓排名失败"
- br.ErrMsg = "获取持仓排名失败,Err:" + err.Error()
- return
- }
- var data Data
- var j, k int
- if len(frequencyList) == 0 {
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = data
- } else {
- if classifyName == "" {
- data = make(Data, 50)
- for i, item := range frequencyList {
- if item.DealCode == "" {
- item.DealValue = ""
- item.DealChange = ""
- }
- if item.BuyCode == "" {
- item.BuyValue = ""
- item.BuyChange = ""
- }
- if item.SoldCode == "" {
- item.SoldValue = ""
- item.SoldChange = ""
- }
- if data[j].Title == item.ClassifyName {
- if data[j].ItemList[k].Code == item.ClassifyType {
- data[j].ItemList[k].Item = append(data[j].ItemList[k].Item, item)
- continue
- }
- if i > 0 {
- k++
- }
- data[j].ItemList[k].Code = item.ClassifyType
- data[j].ItemList[k].Item = append(data[j].ItemList[k].Item, item)
- continue
- }
- if i != 0 {
- if k == 0 {
- data[j].ItemList = data[j].ItemList[:k+1]
- } else {
- data[j].ItemList = data[j].ItemList[:k]
- }
- j++
- k = 0
- }
- if data[j].ItemList == nil {
- list := make([]ShanghaiList, 930)
- data[j].ItemList = list
- }
- data[j].Title = item.ClassifyName
- data[j].ItemList[k].Code = item.ClassifyType
- data[j].ItemList[k].Item = append(data[j].ItemList[k].Item, item)
- }
- data = data[:j]
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = data
- } else {
- data = make(Data, 1)
- for i, item := range frequencyList {
- if item.DealCode == "" {
- item.DealValue = ""
- item.DealChange = ""
- }
- if item.BuyCode == "" {
- item.BuyValue = ""
- item.BuyChange = ""
- }
- if item.SoldCode == "" {
- item.SoldValue = ""
- item.SoldChange = ""
- }
- data[0].Title = classifyName
- if data[0].ItemList == nil {
- list := make([]ShanghaiList, 200)
- data[0].ItemList = list
- }
- if data[0].ItemList[k].Code == item.ClassifyType {
- data[0].ItemList[k].Item = append(data[0].ItemList[k].Item, item)
- continue
- }
- if i > 0 {
- k++
- }
- data[0].ItemList[k].Code = item.ClassifyType
- data[0].ItemList[k].Item = append(data[0].ItemList[k].Item, item)
- }
- data[0].ItemList = data[0].ItemList[:k+1]
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = data
- }
- }
- }
- // IneDataList
- // @title 获取上海国际能源交易所列表
- // @Description 获取上海国际能源交易所列表接口
- // @Param Date query string true "查询日期"
- // @Param ClassifyName query string false "分类名称"
- // @Param ClassifyType query string false "分类合约"
- // @Success 200 {object} models.
- // @router /data/ine [get]
- func (this *TradeCommonController) IneDataList() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- date := this.GetString("Date")
- classifyName := this.GetString("ClassifyName")
- classifyType := this.GetString("ClassifyType")
- frequencyList, err := data_manage.GetBaseFromTradeIndexByParam("ine", date, classifyName, classifyType)
- if err != nil {
- br.Msg = "获取持仓排名失败"
- br.ErrMsg = "获取持仓排名失败,Err:" + err.Error()
- return
- }
- var data Data
- var k int
- if len(frequencyList) == 0 {
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = data
- } else {
- data = make(Data, 1)
- if len(frequencyList) > 20 {
- for i, item := range frequencyList {
- if item.DealCode == "" {
- item.DealValue = ""
- item.DealChange = ""
- }
- if item.BuyCode == "" {
- item.BuyValue = ""
- item.BuyChange = ""
- }
- if item.SoldCode == "" {
- item.SoldValue = ""
- item.SoldChange = ""
- }
- data[0].Title = classifyName
- if data[0].ItemList == nil {
- list := make([]ShanghaiList, 200)
- data[0].ItemList = list
- }
- if data[0].ItemList[k].Code == item.ClassifyType {
- data[0].ItemList[k].Item = append(data[0].ItemList[k].Item, item)
- continue
- }
- if i > 0 {
- k++
- }
- data[0].ItemList[k].Code = item.ClassifyType
- data[0].ItemList[k].Item = append(data[0].ItemList[k].Item, item)
- }
- data[0].ItemList = data[0].ItemList[:k+1]
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = data
- } else {
- for _, item := range frequencyList {
- if item.DealCode == "" {
- item.DealValue = ""
- item.DealChange = ""
- }
- if item.BuyCode == "" {
- item.BuyValue = ""
- item.BuyChange = ""
- }
- if item.SoldCode == "" {
- item.SoldValue = ""
- item.SoldChange = ""
- }
- data[0].Title = item.ClassifyName
- if data[0].ItemList == nil {
- list := make([]ShanghaiList, 1)
- data[0].ItemList = list
- }
- if data[0].ItemList[0].Code == item.ClassifyType {
- data[0].ItemList[0].Item = append(data[0].ItemList[0].Item, item)
- continue
- }
- //if i != 0 {
- // k++
- // fmt.Println(k)
- //}
- data[0].ItemList[0].Code = item.ClassifyType
- data[0].ItemList[0].Item = append(data[0].ItemList[0].Item, item)
- }
- //data[0].ItemList = data[0].ItemList[:k]
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = data
- }
- }
- }
- // CffexDataList
- // @title 获取中金所所列表
- // @Description 获取中金所列表接口
- // @Param Date query string true "查询日期"
- // @Param ClassifyName query string false "分类名称"
- // @Param ClassifyType query string false "分类合约"
- // @Success 200 {object} models.
- // @router /data/cffex [get]
- func (this *TradeCommonController) CffexDataList() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- date := this.GetString("Date")
- date = strings.Replace(date, "-", "", -1)
- classifyName := this.GetString("ClassifyName")
- classifyType := this.GetString("ClassifyType")
- frequencyList, err := data_manage.GetBaseFromTradeIndexByParam("cffex", date, classifyName, classifyType)
- if err != nil {
- br.Msg = "获取持仓排名失败"
- br.ErrMsg = "获取持仓排名失败,Err:" + err.Error()
- return
- }
- var data Data
- var k int
- if len(frequencyList) == 0 {
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = data
- } else {
- data = make(Data, 1)
- if len(frequencyList) > 20 {
- for i, item := range frequencyList {
- if item.DealCode == "" {
- item.DealValue = ""
- item.DealChange = ""
- }
- if item.BuyCode == "" {
- item.BuyValue = ""
- item.BuyChange = ""
- }
- if item.SoldCode == "" {
- item.SoldValue = ""
- item.SoldChange = ""
- }
- data[0].Title = classifyName
- if data[0].ItemList == nil {
- list := make([]ShanghaiList, 200)
- data[0].ItemList = list
- }
- if data[0].ItemList[k].Code == item.ClassifyType {
- data[0].ItemList[k].Item = append(data[0].ItemList[k].Item, item)
- continue
- }
- if i > 0 {
- k++
- }
- data[0].ItemList[k].Code = item.ClassifyType
- data[0].ItemList[k].Item = append(data[0].ItemList[k].Item, item)
- }
- data[0].ItemList = data[0].ItemList[:k+1]
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = data
- } else {
- for _, item := range frequencyList {
- if item.DealCode == "" {
- item.DealValue = ""
- item.DealChange = ""
- }
- if item.BuyCode == "" {
- item.BuyValue = ""
- item.BuyChange = ""
- }
- if item.SoldCode == "" {
- item.SoldValue = ""
- item.SoldChange = ""
- }
- data[0].Title = item.ClassifyName
- if data[0].ItemList == nil {
- list := make([]ShanghaiList, 1)
- data[0].ItemList = list
- }
- if data[0].ItemList[0].Code == item.ClassifyType {
- data[0].ItemList[0].Item = append(data[0].ItemList[0].Item, item)
- continue
- }
- //if i != 0 {
- // k++
- // fmt.Println(k)
- //}
- data[0].ItemList[0].Code = item.ClassifyType
- data[0].ItemList[0].Item = append(data[0].ItemList[0].Item, item)
- }
- //data[0].ItemList = data[0].ItemList[:20]
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = data
- }
- }
- }
- // ZhengzhouDataList
- // @title 获取郑州交易所列表
- // @Description 获取郑州交易所列表接口
- // @Param Date query string true "查询日期"
- // @Param ClassifyName query string false "分类名称"
- // @Param ClassifyType query string false "分类合约"
- // @Success 200 {object} models.
- // @router /data/zhengzhou [get]
- func (this *TradeCommonController) ZhengzhouDataList() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- date := this.GetString("Date")
- fmt.Println(date)
- date = strings.Replace(date, "-", "", -1)
- fmt.Println(date)
- classifyName := this.GetString("ClassifyName")
- classifyType := this.GetString("ClassifyType")
- frequencyList, err := data_manage.GetBaseFromTradeIndexByParam("zhengzhou", date, classifyName, classifyType)
- if err != nil {
- br.Msg = "获取持仓排名失败"
- br.ErrMsg = "获取持仓排名失败,Err:" + err.Error()
- return
- }
- var data Data
- var k int
- if len(frequencyList) == 0 {
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = data
- } else {
- data = make(Data, 1)
- fmt.Println(len(frequencyList))
- if len(frequencyList) > 21 {
- for i, item := range frequencyList {
- if item.DealCode == "" {
- item.DealValue = ""
- item.DealChange = ""
- }
- if item.BuyCode == "" {
- item.BuyValue = ""
- item.BuyChange = ""
- }
- if item.SoldCode == "" {
- item.SoldValue = ""
- item.SoldChange = ""
- }
- data[0].Title = classifyName
- if data[0].ItemList == nil {
- list := make([]ShanghaiList, 200)
- data[0].ItemList = list
- }
- if data[0].ItemList[k].Code == item.ClassifyType {
- data[0].ItemList[k].Item = append(data[0].ItemList[k].Item, item)
- continue
- }
- if i > 0 {
- k++
- }
- data[0].ItemList[k].Code = item.ClassifyType
- data[0].ItemList[k].Item = append(data[0].ItemList[k].Item, item)
- }
- data[0].ItemList = data[0].ItemList[:k]
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = data
- } else {
- for _, item := range frequencyList {
- if item.DealCode == "" {
- item.DealValue = ""
- item.DealChange = ""
- }
- if item.BuyCode == "" {
- item.BuyValue = ""
- item.BuyChange = ""
- }
- if item.SoldCode == "" {
- item.SoldValue = ""
- item.SoldChange = ""
- }
- data[0].Title = item.ClassifyName
- if data[0].ItemList == nil {
- list := make([]ShanghaiList, 1)
- data[0].ItemList = list
- }
- if data[0].ItemList[0].Code == item.ClassifyType {
- data[0].ItemList[0].Item = append(data[0].ItemList[0].Item, item)
- continue
- }
- //if i != 0 {
- // k++
- // fmt.Println(k)
- //}
- data[0].ItemList[0].Code = item.ClassifyType
- data[0].ItemList[0].Item = append(data[0].ItemList[0].Item, item)
- }
- //data[0].ItemList = data[0].ItemList[:k]
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = data
- }
- }
- }
- // DalianDataList
- // @title 获取大连交易所列表
- // @Description 获取大连交易所列表接口
- // @Param Date query string true "查询日期"
- // @Param ClassifyName query string false "分类名称"
- // @Param ClassifyType query string false "分类合约"
- // @Success 200 {object} models.
- // @router /data/dalian [get]
- func (this *TradeCommonController) DalianDataList() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- date := this.GetString("Date")
- classifyName := this.GetString("ClassifyName")
- classifyType := this.GetString("ClassifyType")
- frequencyList, err := data_manage.GetBaseFromTradeIndexByParam("dalian", date, classifyName, classifyType)
- if err != nil {
- br.Msg = "获取持仓排名失败"
- br.ErrMsg = "获取持仓排名失败,Err:" + err.Error()
- return
- }
- var data Data
- var k int
- if len(frequencyList) == 0 {
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = data
- } else {
- data = make(Data, 1)
- fmt.Println("len:", len(frequencyList))
- if len(frequencyList) > 21 {
- for i, item := range frequencyList {
- if item.DealCode == "" {
- item.DealValue = ""
- item.DealChange = ""
- }
- if item.BuyCode == "" {
- item.BuyValue = ""
- item.BuyChange = ""
- }
- if item.SoldCode == "" {
- item.SoldValue = ""
- item.SoldChange = ""
- }
- data[0].Title = classifyName
- if data[0].ItemList == nil {
- list := make([]ShanghaiList, 200)
- data[0].ItemList = list
- }
- if data[0].ItemList[k].Code == item.ClassifyType {
- data[0].ItemList[k].Item = append(data[0].ItemList[k].Item, item)
- continue
- }
- if i > 0 {
- k++
- }
- data[0].ItemList[k].Code = item.ClassifyType
- data[0].ItemList[k].Item = append(data[0].ItemList[k].Item, item)
- }
- data[0].ItemList = data[0].ItemList[:k]
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = data
- } else {
- for _, item := range frequencyList {
- if item.DealCode == "" {
- item.DealValue = ""
- item.DealChange = ""
- }
- if item.BuyCode == "" {
- item.BuyValue = ""
- item.BuyChange = ""
- }
- if item.SoldCode == "" {
- item.SoldValue = ""
- item.SoldChange = ""
- }
- data[0].Title = item.ClassifyName
- if data[0].ItemList == nil {
- list := make([]ShanghaiList, 1)
- data[0].ItemList = list
- }
- if data[0].ItemList[0].Code == item.ClassifyType {
- data[0].ItemList[0].Item = append(data[0].ItemList[0].Item, item)
- continue
- }
- //if i != 0 {
- // k++
- // fmt.Println(k)
- //}
- data[0].ItemList[0].Code = item.ClassifyType
- data[0].ItemList[0].Item = append(data[0].ItemList[0].Item, item)
- }
- //data[0].ItemList = data[0].ItemList[:k]
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = data
- }
- }
- }
- // EicLatestDate
- // @title 获取欧洲天然气最新日期
- // @Description 获取欧洲天然气最新日期接口
- // @Success 200 {object} models.
- // @router /data/eicLatestDate [get]
- func (this *TradeCommonController) EicLatestDate() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- latestData, err := data_manage.GetEicDate()
- if err != nil {
- br.Msg = "获取日期失败"
- br.ErrMsg = "获取日期失败,Err:" + err.Error()
- return
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = latestData[0].GasDayStartedOn
- }
- // EicContinentList 欧洲天然气洲际及国家级列表
- // @title 获取欧洲天然气列表
- // @Description 获取欧洲天然气列表接口
- // @Param Date query string true "查询日期"
- // @Success 200 {object} models.
- // @router /data/eicContinent [get]
- func (this *TradeCommonController) EicContinentList() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- date := this.GetString("Date")
- continentList, err := data_manage.GetContinentEicDate(date)
- if err != nil {
- br.Msg = "获取持仓排名失败"
- br.ErrMsg = "获取持仓排名失败,Err:" + err.Error()
- return
- }
- countryList, err := data_manage.GetCountryEicDate(date)
- if err != nil {
- br.Msg = "获取持仓排名失败"
- br.ErrMsg = "获取持仓排名失败,Err:" + err.Error()
- return
- }
- if len(countryList) == 0 || len(continentList) < 1 {
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = []EicData{}
- } else {
- countryLen := len(countryList)
- var euData = EicData{
- Country: "eu",
- Type: "continent",
- EicCode: "eu",
- ShortName: "eu",
- Name: "eu",
- Status: "N",
- GasDayStartedOn: "",
- GasInStorage: 0,
- GasInStorageCode: "euGS",
- Full: 0,
- FullCode: "euF",
- Trend: 0,
- TrendCode: "euT",
- Injection: 0,
- InjectionCode: "euIn",
- Withdrawal: 0,
- WithdrawalCode: "euOut",
- WorkingGasVolume: 0,
- WorkingGasVolumeCode: "euWGV",
- InjectionCapacity: 0,
- InjectionCapacityCode: "euIC",
- WithdrawalCapacity: 0,
- WithdrawalCapacityCode: "euWC",
- Info: "",
- Children: countryList[:countryLen-2],
- }
- var neData = EicData{
- Country: "ne",
- Type: "continent",
- EicCode: "ne",
- ShortName: "ne",
- Name: "ne",
- Status: "N",
- GasDayStartedOn: "",
- GasInStorage: 0,
- GasInStorageCode: "neGS",
- Full: 0,
- FullCode: "neF",
- Trend: 0,
- TrendCode: "neT",
- Injection: 0,
- InjectionCode: "neIn",
- Withdrawal: 0,
- WithdrawalCode: "neOut",
- WorkingGasVolume: 0,
- WorkingGasVolumeCode: "neWGV",
- InjectionCapacity: 0,
- InjectionCapacityCode: "neIC",
- WithdrawalCapacity: 0,
- WithdrawalCapacityCode: "neWC",
- Info: "",
- Children: countryList[countryLen-2:],
- }
- //如果洲际数据正常
- if continentList[0].Country == "eu" {
- gasInStorage, _ := strconv.ParseFloat(continentList[0].GasInStorage, 64)
- full, _ := strconv.ParseFloat(continentList[0].Full, 64)
- trend, _ := strconv.ParseFloat(continentList[0].Trend, 64)
- injection, _ := strconv.ParseFloat(continentList[0].Injection, 64)
- withdrawal, _ := strconv.ParseFloat(continentList[0].Withdrawal, 64)
- workingGasVolume, _ := strconv.ParseFloat(continentList[0].WorkingGasVolume, 64)
- injectionCapacity, _ := strconv.ParseFloat(continentList[0].InjectionCapacity, 64)
- withdrawalCapacity, _ := strconv.ParseFloat(continentList[0].WithdrawalCapacity, 64)
- euData = EicData{
- continentList[0].Country,
- continentList[0].Type,
- continentList[0].EicCode,
- continentList[0].ShortName,
- continentList[0].Name,
- continentList[0].Status,
- continentList[0].GasDayStartedOn,
- gasInStorage,
- continentList[0].GasInStorageCode,
- full,
- continentList[0].FullCode,
- trend,
- continentList[0].TrendCode,
- injection,
- continentList[0].InjectionCode,
- withdrawal,
- continentList[0].WithdrawalCode,
- workingGasVolume,
- continentList[0].WorkingGasVolumeCode,
- injectionCapacity,
- continentList[0].InjectionCapacityCode,
- withdrawalCapacity,
- continentList[0].WithdrawalCapacityCode,
- continentList[0].Info,
- countryList[:countryLen-2],
- }
- if len(continentList) > 1 {
- gasInStorage1, _ := strconv.ParseFloat(continentList[1].GasInStorage, 64)
- full1, _ := strconv.ParseFloat(continentList[1].Full, 64)
- trend1, _ := strconv.ParseFloat(continentList[1].Trend, 64)
- injection1, _ := strconv.ParseFloat(continentList[1].Injection, 64)
- withdrawal1, _ := strconv.ParseFloat(continentList[1].Withdrawal, 64)
- workingGasVolume1, _ := strconv.ParseFloat(continentList[1].WorkingGasVolume, 64)
- injectionCapacity1, _ := strconv.ParseFloat(continentList[1].InjectionCapacity, 64)
- withdrawalCapacity1, _ := strconv.ParseFloat(continentList[1].WithdrawalCapacity, 64)
- neData = EicData{
- continentList[1].Country,
- continentList[1].Type,
- continentList[1].EicCode,
- continentList[1].ShortName,
- continentList[1].Name,
- continentList[1].Status,
- continentList[1].GasDayStartedOn,
- gasInStorage1,
- continentList[1].GasInStorageCode,
- full1,
- continentList[1].FullCode,
- trend1,
- continentList[1].TrendCode,
- injection1,
- continentList[1].InjectionCode,
- withdrawal1,
- continentList[1].WithdrawalCode,
- workingGasVolume1,
- continentList[1].WorkingGasVolumeCode,
- injectionCapacity1,
- continentList[1].InjectionCapacityCode,
- withdrawalCapacity1,
- continentList[1].WithdrawalCapacityCode,
- continentList[1].Info,
- countryList[countryLen-2:],
- }
- }
- } else {
- //数据不正常,只有一个洲际数据时
- if continentList[0].Country == "eu" {
- gasInStorage, _ := strconv.ParseFloat(continentList[0].GasInStorage, 64)
- full, _ := strconv.ParseFloat(continentList[0].Full, 64)
- trend, _ := strconv.ParseFloat(continentList[0].Trend, 64)
- injection, _ := strconv.ParseFloat(continentList[0].Injection, 64)
- withdrawal, _ := strconv.ParseFloat(continentList[0].Withdrawal, 64)
- workingGasVolume, _ := strconv.ParseFloat(continentList[0].WorkingGasVolume, 64)
- injectionCapacity, _ := strconv.ParseFloat(continentList[0].InjectionCapacity, 64)
- withdrawalCapacity, _ := strconv.ParseFloat(continentList[0].WithdrawalCapacity, 64)
- euData = EicData{
- continentList[0].Country,
- continentList[0].Type,
- continentList[0].EicCode,
- continentList[0].ShortName,
- continentList[0].Name,
- continentList[0].Status,
- continentList[0].GasDayStartedOn,
- gasInStorage,
- continentList[0].GasInStorageCode,
- full,
- continentList[0].FullCode,
- trend,
- continentList[0].TrendCode,
- injection,
- continentList[0].InjectionCode,
- withdrawal,
- continentList[0].WithdrawalCode,
- workingGasVolume,
- continentList[0].WorkingGasVolumeCode,
- injectionCapacity,
- continentList[0].InjectionCapacityCode,
- withdrawalCapacity,
- continentList[0].WithdrawalCapacityCode,
- continentList[0].Info,
- countryList[:countryLen-2],
- }
- } else {
- gasInStorage1, _ := strconv.ParseFloat(continentList[0].GasInStorage, 64)
- full1, _ := strconv.ParseFloat(continentList[0].Full, 64)
- trend1, _ := strconv.ParseFloat(continentList[0].Trend, 64)
- injection1, _ := strconv.ParseFloat(continentList[0].Injection, 64)
- withdrawal1, _ := strconv.ParseFloat(continentList[0].Withdrawal, 64)
- workingGasVolume1, _ := strconv.ParseFloat(continentList[0].WorkingGasVolume, 64)
- injectionCapacity1, _ := strconv.ParseFloat(continentList[0].InjectionCapacity, 64)
- withdrawalCapacity1, _ := strconv.ParseFloat(continentList[0].WithdrawalCapacity, 64)
- neData = EicData{
- continentList[0].Country,
- continentList[0].Type,
- continentList[0].EicCode,
- continentList[0].ShortName,
- continentList[0].Name,
- continentList[0].Status,
- continentList[0].GasDayStartedOn,
- gasInStorage1,
- continentList[0].GasInStorageCode,
- full1,
- continentList[0].FullCode,
- trend1,
- continentList[0].TrendCode,
- injection1,
- continentList[0].InjectionCode,
- withdrawal1,
- continentList[0].WithdrawalCode,
- workingGasVolume1,
- continentList[0].WorkingGasVolumeCode,
- injectionCapacity1,
- continentList[0].InjectionCapacityCode,
- withdrawalCapacity1,
- continentList[0].WithdrawalCapacityCode,
- continentList[0].Info,
- countryList[countryLen-2:],
- }
- }
- }
- var data []EicData
- data = append(data, euData)
- data = append(data, neData)
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = data
- }
- }
- // EicDataList 欧洲天然气细节列表
- // @title 获取欧洲天然气列表
- // @Description 获取欧洲天然气列表接口
- // @Param Date query string true "查询日期"
- // @Param Country query string true "国家"
- // @Success 200 {object} models.
- // @router /data/eicData [get]
- func (this *TradeCommonController) EicDataList() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- date := this.GetString("Date")
- country := this.GetString("Country")
- ssoList, err := data_manage.GetSSOEicDate(date, country)
- if err != nil {
- br.Msg = "获取持仓排名失败"
- br.ErrMsg = "获取持仓排名失败,Err:" + err.Error()
- return
- }
- storageList, err := data_manage.GetStorageEicDate(date, country)
- if err != nil {
- br.Msg = "获取持仓排名失败"
- br.ErrMsg = "获取持仓排名失败,Err:" + err.Error()
- return
- }
- var data []EicData
- for _, sso := range ssoList {
- gasInStorage, _ := strconv.ParseFloat(sso.GasInStorage, 64)
- full, _ := strconv.ParseFloat(sso.Full, 64)
- trend, _ := strconv.ParseFloat(sso.Trend, 64)
- injection, _ := strconv.ParseFloat(sso.Injection, 64)
- withdrawal, _ := strconv.ParseFloat(sso.Withdrawal, 64)
- workingGasVolume, _ := strconv.ParseFloat(sso.WorkingGasVolume, 64)
- injectionCapacity, _ := strconv.ParseFloat(sso.InjectionCapacity, 64)
- withdrawalCapacity, _ := strconv.ParseFloat(sso.WithdrawalCapacity, 64)
- item := EicData{
- sso.Country,
- sso.Type,
- sso.EicCode,
- sso.ShortName,
- sso.Name,
- sso.Status,
- sso.GasDayStartedOn,
- gasInStorage,
- sso.GasInStorageCode,
- full,
- sso.FullCode,
- trend,
- sso.TrendCode,
- injection,
- sso.InjectionCode,
- withdrawal,
- sso.WithdrawalCode,
- workingGasVolume,
- sso.WorkingGasVolumeCode,
- injectionCapacity,
- sso.InjectionCapacityCode,
- withdrawalCapacity,
- sso.WithdrawalCapacityCode,
- sso.Info,
- []*data_manage.BaseFromTradeEicIndex{},
- }
- for _, st := range storageList {
- if item.ShortName == st.ShortName {
- item.Children = append(item.Children, st)
- }
- }
- data = append(data, item)
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = data
- }
- // EicHistoryData
- // @title 获取欧洲天然气历史列表
- // @Description 获取欧洲天然气历史列表接口
- // @Param Code query string true "Code"
- // @Param StartDate query string false "开始时间"
- // @Param EndDate query string false "结束时间"
- // @Success 200 {object} models.
- // @router /data/eicHistoryData [get]
- func (this *TradeCommonController) EicHistoryData() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- code := this.GetString("Code")
- startDate := this.GetString("StartDate")
- endDate := this.GetString("EndDate")
- var eicList []*data_manage.BaseFromTradeEicIndex
- var err error
- if endDate != "" {
- eicList, err = data_manage.GetEicHistoryDateByDate(code, startDate, endDate)
- if err != nil {
- br.Msg = "获取持仓排名失败"
- br.ErrMsg = "获取持仓排名失败,Err:" + err.Error()
- return
- }
- } else {
- eicList, err = data_manage.GetEicHistoryDate(code)
- if err != nil {
- br.Msg = "获取持仓排名失败"
- br.ErrMsg = "获取持仓排名失败,Err:" + err.Error()
- return
- }
- }
- var data []EicData
- for _, eic := range eicList {
- gasInStorage, _ := strconv.ParseFloat(eic.GasInStorage, 64)
- full, _ := strconv.ParseFloat(eic.Full, 64)
- trend, _ := strconv.ParseFloat(eic.Trend, 64)
- injection, _ := strconv.ParseFloat(eic.Injection, 64)
- withdrawal, _ := strconv.ParseFloat(eic.Withdrawal, 64)
- workingGasVolume, _ := strconv.ParseFloat(eic.WorkingGasVolume, 64)
- injectionCapacity, _ := strconv.ParseFloat(eic.InjectionCapacity, 64)
- withdrawalCapacity, _ := strconv.ParseFloat(eic.WithdrawalCapacity, 64)
- item := EicData{
- eic.Country,
- eic.Type,
- eic.EicCode,
- eic.ShortName,
- eic.Name,
- eic.Status,
- eic.GasDayStartedOn,
- gasInStorage,
- eic.GasInStorageCode,
- full,
- eic.FullCode,
- trend,
- eic.TrendCode,
- injection,
- eic.InjectionCode,
- withdrawal,
- eic.WithdrawalCode,
- workingGasVolume,
- eic.WorkingGasVolumeCode,
- injectionCapacity,
- eic.InjectionCapacityCode,
- withdrawalCapacity,
- eic.WithdrawalCapacityCode,
- eic.Info,
- []*data_manage.BaseFromTradeEicIndex{},
- }
- data = append(data, item)
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = data
- }
- //// EicHistoryDataByDate
- //// @title 根据时间获取欧洲天然气历史列表
- //// @Description 根据时间获取欧洲天然气历史列表
- //// @Param Code query string true "Code"
- //// @Param Date1 query string true "时间1"
- //// @Param Date2 query string true "时间2"
- //// @Success 200 {object} models.
- //// @router /data/eicHistoryDataByDate [get]
- //func (this *TradeCommonController) EicHistoryDataByDate() {
- // br := new(models.BaseResponse).Init()
- // defer func() {
- // this.Data["json"] = br
- // this.ServeJSON()
- // }()
- // code := this.GetString("Code")
- // date1 := this.GetString("Date1")
- // date2 := this.GetString("Date2")
- // eicList, err := data_manage.GetEicHistoryDateByDate(code,date1,date2)
- // if err != nil {
- // br.Msg = "获取持仓排名失败"
- // br.ErrMsg = "获取持仓排名失败,Err:" + err.Error()
- // return
- // }
- // var data []EicData
- // for _, eic := range eicList {
- // gasInStorage, _ := strconv.ParseFloat(eic.GasInStorage, 64)
- // full, _ := strconv.ParseFloat(eic.Full, 64)
- // trend, _ := strconv.ParseFloat(eic.Trend, 64)
- // injection, _ := strconv.ParseFloat(eic.Injection, 64)
- // withdrawal, _ := strconv.ParseFloat(eic.Withdrawal, 64)
- // workingGasVolume, _ := strconv.ParseFloat(eic.WorkingGasVolume, 64)
- // injectionCapacity, _ := strconv.ParseFloat(eic.InjectionCapacity, 64)
- // withdrawalCapacity, _ := strconv.ParseFloat(eic.WithdrawalCapacity, 64)
- // item := EicData{
- // eic.Country,
- // eic.Type,
- // eic.EicCode,
- // eic.ShortName,
- // eic.Name,
- // eic.Status,
- // eic.GasDayStartedOn,
- // gasInStorage,
- // eic.GasInStorageCode,
- // full,
- // eic.FullCode,
- // trend,
- // eic.TrendCode,
- // injection,
- // eic.InjectionCode,
- // withdrawal,
- // eic.WithdrawalCode,
- // workingGasVolume,
- // eic.WorkingGasVolumeCode,
- // injectionCapacity,
- // eic.InjectionCapacityCode,
- // withdrawalCapacity,
- // eic.WithdrawalCapacityCode,
- // eic.Info,
- // []*data_manage.BaseFromTradeEicIndex{},
- // }
- // data = append(data, item)
- // }
- //
- // br.Ret = 200
- // br.Success = true
- // br.Msg = "获取成功"
- // br.Data = data
- //}
- // CoalMineClassify
- // @title 获取中国煤炭市场网分类列表
- // @Description 获取中国煤炭市场网分类列表
- // @Success 200 {object} models.
- // @router /data/coalMineData/classify [get]
- func (this *TradeCommonController) CoalMineClassify() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- var coalList []data_manage.BaseFromCoalmineClassifyItem
- var suffix string
- var coal data_manage.BaseFromCoalmineClassifyItem
- groups := []*string{}
- var childs []data_manage.CoalChild
- var child data_manage.CoalChild
- list, err := data_manage.GetCoalmineClassifyList()
- if err != nil {
- br.Msg = "获取煤炭分类数据失败"
- br.ErrMsg = "获取煤炭度分类数据失败,Err: " + err.Error()
- return
- }
- for _, v := range list {
- if v.Suffix == "jsm_index" {
- suffix = "jsm_index"
- groups, err = data_manage.GetProvinceFromCoalmineIndex(suffix)
- if err != nil {
- br.Msg = "获取煤炭分类数据失败"
- br.ErrMsg = "获取煤炭度分类数据失败,Err: " + err.Error()
- return
- }
- coal.ClassifyId = 1
- coal.ClassifyName = "晋陕蒙三省煤矿产量周度数据"
- jsmId := 100
- for _, group := range groups {
- jsmId++
- child.ClassifyId = jsmId
- child.ClassifyName = *group
- childs = append(childs, child)
- }
- coal.Child = childs
- coalList = append(coalList, coal)
- }
- if v.Suffix == "company_index" {
- suffix = "company_index"
- groups = []*string{}
- childs = []data_manage.CoalChild{}
- groups, err = data_manage.GetGroupNameFromCoalmineIndex(suffix)
- if err != nil {
- br.Msg = "获取煤炭分类数据失败"
- br.ErrMsg = "获取煤炭度分类数据失败,Err: " + err.Error()
- return
- }
- coal.ClassifyId = 2
- coal.ClassifyName = "442家晋陕蒙煤矿周度产量"
- companyId := 200
- for _, group := range groups {
- companyId++
- child.ClassifyId = companyId
- child.ClassifyName = *group
- childs = append(childs, child)
- }
- coal.Child = childs
- coalList = append(coalList, coal)
- }
- if v.Suffix == "firm_index" {
- suffix = "firm_index"
- groups = []*string{}
- childs = []data_manage.CoalChild{}
- groups, err = data_manage.GetGroupNameFromCoalmineIndex(suffix)
- if err != nil {
- br.Msg = "获取煤炭分类数据失败"
- br.ErrMsg = "获取煤炭度分类数据失败,Err: " + err.Error()
- return
- }
- coal.ClassifyId = 3
- coal.ClassifyName = "全国分企业煤炭产量旬度数据"
- firmId := 300
- for _, group := range groups {
- firmId++
- child.ClassifyId = firmId
- child.ClassifyName = *group
- childs = append(childs, child)
- }
- coal.Child = childs
- coalList = append(coalList, coal)
- }
- if v.Suffix == "coastal_index" {
- suffix = "coastal_index"
- groups = []*string{}
- childs = []data_manage.CoalChild{}
- groups, err = data_manage.GetGroupNameFromCoalmineIndex(suffix)
- if err != nil {
- br.Msg = "获取煤炭分类数据失败"
- br.ErrMsg = "获取煤炭度分类数据失败,Err: " + err.Error()
- return
- }
- coal.ClassifyId = 4
- coal.ClassifyName = "沿海八省动力煤终端用户供耗存"
- coastalId := 400
- for _, group := range groups {
- coastalId++
- child.ClassifyId = coastalId
- child.ClassifyName = *group
- childs = append(childs, child)
- }
- coal.Child = childs
- coalList = append(coalList, coal)
- }
- if v.Suffix == "inland_index" {
- suffix = "inland_index"
- groups = []*string{}
- childs = []data_manage.CoalChild{}
- groups, err = data_manage.GetGroupNameFromCoalmineIndex(suffix)
- if err != nil {
- br.Msg = "获取煤炭分类数据失败"
- br.ErrMsg = "获取煤炭度分类数据失败,Err: " + err.Error()
- return
- }
- coal.ClassifyId = 5
- coal.ClassifyName = "内陆17省动力煤终端用户供耗存"
- inlandId := 500
- for _, group := range groups {
- inlandId++
- child.ClassifyId = inlandId
- child.ClassifyName = *group
- childs = append(childs, child)
- }
- coal.Child = childs
- coalList = append(coalList, coal)
- }
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = coalList
- }
- // CoalMineFrequency
- // @title 获取中国煤炭市场网频度
- // @Description 获取中国煤炭市场网频度
- // @Param ClassifyId query int true "数据id"
- // @Success 200 {object} models.
- // @router /data/coalMineData/frequency [get]
- func (this *TradeCommonController) CoalMineFrequency() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- classifyId, _ := this.GetInt("ClassifyId")
- var suffix string
- if classifyId == 1 {
- suffix = "jsm_index"
- } else if classifyId == 2 {
- suffix = "company_index"
- } else if classifyId == 3 {
- suffix = "firm_index"
- } else if classifyId == 4 {
- suffix = "coastal_index"
- } else if classifyId == 5 {
- suffix = "inland_index"
- }
- frequency, err := data_manage.GetFrequencyFromCoal(suffix)
- if err != nil {
- br.Msg = "获取煤炭频度数据失败"
- br.ErrMsg = "获取煤炭频度数据失败,Err:" + err.Error()
- return
- }
- var resp data_manage.FrequencyResp
- switch *frequency {
- case "日度":
- resp.Frequency = 1
- case "周度":
- resp.Frequency = 2
- case "旬度":
- resp.Frequency = 3
- case "月度":
- resp.Frequency = 4
- case "季度":
- resp.Frequency = 5
- case "年度":
- resp.Frequency = 6
- default:
- resp.Frequency = 99
- }
- var list []data_manage.FrequencyResp
- list = append(list, resp)
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = list
- }
- // CoalMineData
- // @title 获取中国煤炭市场网详细数据列表
- // @Description 获取中国煤炭市场网详细数据接口
- // @Param ClassifyId query int true "数据id"
- // @Param GroupName query string true "分组名"
- // @Param Frequency query string true "频度"
- // @Param PageSize query int true "每页数据条数"
- // @Param CurrentIndex query int true "当前页页码,从1开始"
- // @Success 200 {object} []data_manage.CoalmineDataResp
- // @router /data/coalMineData/data [get]
- func (this *TradeCommonController) CoalMineData() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- classifyId, _ := this.GetInt("ClassifyId")
- frequency := this.GetString("Frequency")
- groupName := this.GetString("GroupName")
- pageSize, _ := this.GetInt("PageSize")
- currentIndex, _ := this.GetInt("CurrentIndex")
- var startSize int
- if pageSize <= 0 {
- pageSize = utils.PageSize20
- }
- if currentIndex <= 0 {
- currentIndex = 1
- }
- startSize = utils.StartIndex(currentIndex, pageSize)
- //var groups []*string
- //var err error
- //var suffix string
- //if classifyId == 1 {
- // suffix = "jsm_index"
- //} else if classifyId == 2 {
- // suffix = "company_index"
- //} else if classifyId == 3 {
- // suffix = "firm_index"
- //} else if classifyId == 4 {
- // suffix = "coastal_index"
- //} else if classifyId == 5 {
- // suffix = "inland_index"
- //}
- switch classifyId {
- case 1:
- classifies, err := data_manage.GetClassifyCoalmineIndexByGroupName(groupName)
- if err != nil {
- br.Msg = "获取煤炭数据失败"
- br.ErrMsg = "获取煤炭度数据失败,Err:" + err.Error()
- return
- }
- var lists []data_manage.CoalmineDataPageResp
- for _, classify := range classifies {
- items, err := data_manage.GetPageFromCoalmineIndexByFrequency(frequency, *classify, startSize, pageSize)
- if err != nil {
- br.Msg = "获取煤炭数据失败"
- br.ErrMsg = "获取煤炭度数据失败,Err:" + err.Error()
- return
- }
- total, err := data_manage.GetCountFromJsm(*classify)
- if err != nil {
- br.Msg = "获取煤炭数据失败"
- br.ErrMsg = "获取煤炭度数据失败,Err:" + err.Error()
- return
- }
- page := paging.GetPaging(currentIndex, pageSize, total)
- var resp data_manage.CoalmineDataPageResp
- for i, item := range items {
- if i == 0 {
- resp.ModifyTime = item.CreateTime
- }
- resp.Paging = page
- resp.IndexName = item.IndexName
- resp.IndexCode = item.IndexCode
- resp.Unit = item.Unit
- resp.Frequency = item.Frequency
- //组装dataList
- var dataItem data_manage.DataList
- dataItem.DataTime = item.DataTime
- dataItem.Value = item.DealValue
- resp.DataList = append(resp.DataList, dataItem)
- }
- lists = append(lists, resp)
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = lists
- case 2:
- classifies, err := data_manage.GetClassifyCompanyByGroupName(groupName)
- if err != nil {
- br.Msg = "获取煤炭数据失败"
- br.ErrMsg = "获取煤炭度数据失败,Err:" + err.Error()
- return
- }
- var lists []data_manage.CoalmineDataPageResp
- for _, classify := range classifies {
- items, err := data_manage.GetPageFromCoalmineCompanyIndexByFrequency(frequency, *classify, startSize, pageSize)
- if err != nil {
- br.Msg = "获取煤炭数据失败"
- br.ErrMsg = "获取煤炭度数据失败,Err:" + err.Error()
- return
- }
- total, err := data_manage.GetCountFromCompany(*classify)
- if err != nil {
- br.Msg = "获取煤炭数据失败"
- br.ErrMsg = "获取煤炭度数据失败,Err:" + err.Error()
- return
- }
- page := paging.GetPaging(currentIndex, pageSize, total)
- var resp data_manage.CoalmineDataPageResp
- for i, item := range items {
- if i == 0 {
- resp.ModifyTime = item.CreateTime
- }
- resp.Paging = page
- resp.IndexName = item.IndexName
- resp.IndexCode = item.IndexCode
- resp.Unit = item.Unit
- resp.Frequency = item.Frequency
- //组装dataList
- var dataItem data_manage.DataList
- dataItem.DataTime = item.DataTime
- dataItem.Value = item.DealValue
- resp.DataList = append(resp.DataList, dataItem)
- }
- lists = append(lists, resp)
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = lists
- case 3:
- classifies, err := data_manage.GetClassifyFirmByGroupName(groupName)
- if err != nil {
- br.Msg = "获取煤炭数据失败"
- br.ErrMsg = "获取煤炭度数据失败,Err:" + err.Error()
- return
- }
- var lists []data_manage.CoalmineDataPageResp
- for _, classify := range classifies {
- items, err := data_manage.GetPageFromCoalmineFirmIndexByFrequency(frequency, *classify, startSize, pageSize)
- if err != nil {
- br.Msg = "获取煤炭数据失败"
- br.ErrMsg = "获取煤炭度数据失败,Err:" + err.Error()
- return
- }
- total, err := data_manage.GetCountFromFirm(*classify)
- if err != nil {
- br.Msg = "获取煤炭数据失败"
- br.ErrMsg = "获取煤炭度数据失败,Err:" + err.Error()
- return
- }
- page := paging.GetPaging(currentIndex, pageSize, total)
- var resp data_manage.CoalmineDataPageResp
- for i, item := range items {
- if i == 0 {
- resp.ModifyTime = item.CreateTime
- }
- resp.Paging = page
- resp.IndexName = item.IndexName
- resp.IndexCode = item.IndexCode
- resp.Unit = item.Unit
- resp.Frequency = item.Frequency
- //组装dataList
- var dataItem data_manage.DataList
- dataItem.DataTime = item.DataTime
- dataItem.Value = item.DealValue
- resp.DataList = append(resp.DataList, dataItem)
- }
- lists = append(lists, resp)
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = lists
- case 4:
- classifies, err := data_manage.GetClassifyCoastalByGroupName(groupName)
- if err != nil {
- br.Msg = "获取煤炭数据失败"
- br.ErrMsg = "获取煤炭度数据失败,Err:" + err.Error()
- return
- }
- var lists []data_manage.CoalmineDataPageResp
- for _, classify := range classifies {
- items, err := data_manage.GetPageFromCoalmineCoastalIndexByFrequency(frequency, *classify, startSize, pageSize)
- if err != nil {
- br.Msg = "获取煤炭数据失败"
- br.ErrMsg = "获取煤炭度数据失败,Err:" + err.Error()
- return
- }
- total, err := data_manage.GetCountFromCoastal(*classify)
- if err != nil {
- br.Msg = "获取煤炭数据失败"
- br.ErrMsg = "获取煤炭度数据失败,Err:" + err.Error()
- return
- }
- page := paging.GetPaging(currentIndex, pageSize, total)
- var resp data_manage.CoalmineDataPageResp
- for i, item := range items {
- if i == 0 {
- resp.ModifyTime = item.CreateTime
- }
- resp.Paging = page
- resp.IndexName = item.IndexName
- resp.IndexCode = item.IndexCode
- resp.Unit = item.Unit
- resp.Frequency = item.Frequency
- //组装dataList
- var dataItem data_manage.DataList
- dataItem.DataTime = item.DataTime
- dataItem.Value = item.DealValue
- resp.DataList = append(resp.DataList, dataItem)
- }
- lists = append(lists, resp)
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = lists
- case 5:
- classifies, err := data_manage.GetClassifyInlandByGroupName(groupName)
- if err != nil {
- br.Msg = "获取煤炭数据失败"
- br.ErrMsg = "获取煤炭度数据失败,Err:" + err.Error()
- return
- }
- var lists []data_manage.CoalmineDataPageResp
- for _, classify := range classifies {
- items, err := data_manage.GetPageFromCoalmineInlandIndexByFrequency(frequency, *classify, startSize, pageSize)
- if err != nil {
- br.Msg = "获取煤炭数据失败"
- br.ErrMsg = "获取煤炭度数据失败,Err:" + err.Error()
- return
- }
- total, err := data_manage.GetCountFromInland(*classify)
- if err != nil {
- br.Msg = "获取煤炭数据失败"
- br.ErrMsg = "获取煤炭度数据失败,Err:" + err.Error()
- return
- }
- page := paging.GetPaging(currentIndex, pageSize, total)
- var resp data_manage.CoalmineDataPageResp
- for i, item := range items {
- if i == 0 {
- resp.ModifyTime = item.CreateTime
- }
- resp.Paging = page
- resp.IndexName = item.IndexName
- resp.IndexCode = item.IndexCode
- resp.Unit = item.Unit
- resp.Frequency = item.Frequency
- //组装dataList
- var dataItem data_manage.DataList
- dataItem.DataTime = item.DataTime
- dataItem.Value = item.DealValue
- resp.DataList = append(resp.DataList, dataItem)
- }
- lists = append(lists, resp)
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = lists
- default:
- br.Ret = 200
- br.Success = true
- br.Msg = "获取煤炭数据失败"
- br.ErrMsg = "获取煤炭度数据失败,Err: classifyId 错误"
- return
- }
- }
- // CoalSearchList
- // @Title 煤炭网模糊搜索
- // @Description 煤炭网模糊搜索
- // @Param Keyword query string ture "关键字搜索"
- // @Success 200 {object} models.BaseResponse
- // @router /data/coalMineData/search [get]
- func (this *TradeCommonController) CoalSearchList() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- //关键字
- keyword := this.GetString("Keyword")
- list, err := data_manage.GetCoalItemList(keyword)
- if err != nil {
- br.ErrMsg = "获取失败,Err:" + err.Error()
- br.Msg = "获取失败"
- return
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = list
- }
- // CoalSingleData
- // @Title 获取煤炭单条数据
- // @Description 获取煤炭单条数据
- // @Param IndexCode query string true "指标唯一编码"
- // @Success 200 {object} []data_manage.CoalmineSingalDataResp
- // @router /data/coalMineData/single_data [get]
- func (this *TradeCommonController) CoalSingleData() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- indexCode := this.GetString("IndexCode")
- var classifyId int
- var suffix string
- if strings.Contains(indexCode, "jsm") {
- classifyId = 1
- suffix = "jsm_index"
- } else if strings.Contains(indexCode, "company") {
- classifyId = 2
- suffix = "company_index"
- } else if strings.Contains(indexCode, "firm") {
- classifyId = 3
- suffix = "firm_index"
- } else if strings.Contains(indexCode, "coastal") {
- classifyId = 4
- suffix = "coastal_index"
- } else if strings.Contains(indexCode, "inland") {
- classifyId = 5
- suffix = "inland_index"
- }
- switch classifyId {
- case 1:
- items, err := data_manage.GetBaseFromCoalmineIndexByCode(indexCode)
- if err != nil {
- br.Msg = "获取煤炭数据失败"
- br.ErrMsg = "获取煤炭度数据失败,Err:" + err.Error()
- return
- }
- groups, err := data_manage.GetProvinceFromCoalmineIndex(suffix)
- if err != nil {
- br.Msg = "获取煤炭分类数据失败"
- br.ErrMsg = "获取煤炭度分类数据失败,Err: " + err.Error()
- return
- }
- groupMap := make(map[string]int)
- jsmId := 100
- for _, group := range groups {
- jsmId++
- groupMap[*group] = jsmId
- }
- var lists []data_manage.CoalmineSingalDataResp
- var resp data_manage.CoalmineSingalDataResp
- classify := items[0].IndexName
- for i, item := range items {
- if item.IndexName != classify {
- lists = append(lists, resp)
- classify = item.IndexName
- }
- resp.IndexName = item.IndexName
- resp.IndexCode = item.IndexCode
- resp.GroupId = groupMap[item.Province]
- resp.GroupName = item.Province
- resp.Unit = item.Unit
- resp.Frequency = item.Frequency
- resp.ModifyTime = item.ModifyTime
- resp.ClassifyId = classifyId
- //组装dataList
- var dataItem data_manage.DataList
- dataItem.DataTime = item.DataTime
- dataItem.Value = item.DealValue
- resp.DataList = append(resp.DataList, dataItem)
- if i == len(items)-1 {
- lists = append(lists, resp)
- }
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = lists
- case 2:
- items, err := data_manage.GetBaseFromCoalmineCompanyIndexByCode(indexCode)
- if err != nil {
- br.Msg = "获取煤炭数据失败"
- br.ErrMsg = "获取煤炭度数据失败,Err:" + err.Error()
- return
- }
- groups, err := data_manage.GetGroupNameFromCoalmineIndex(suffix)
- if err != nil {
- br.Msg = "获取煤炭分类数据失败"
- br.ErrMsg = "获取煤炭度分类数据失败,Err: " + err.Error()
- return
- }
- groupMap := make(map[string]int)
- companyId := 200
- for _, group := range groups {
- companyId++
- groupMap[*group] = companyId
- }
- var lists []data_manage.CoalmineSingalDataResp
- var resp data_manage.CoalmineSingalDataResp
- classify := items[0].IndexName
- for i, item := range items {
- if item.IndexName != classify {
- lists = append(lists, resp)
- classify = item.IndexName
- }
- resp.IndexName = item.IndexName
- resp.IndexCode = item.IndexCode
- resp.Unit = item.Unit
- resp.GroupId = groupMap[item.GroupName]
- resp.GroupName = item.GroupName
- resp.Frequency = item.Frequency
- resp.ModifyTime = item.ModifyTime
- resp.ClassifyId = classifyId
- //组装dataList
- var dataItem data_manage.DataList
- dataItem.DataTime = item.DataTime
- dataItem.Value = item.DealValue
- resp.DataList = append(resp.DataList, dataItem)
- if i == len(items)-1 {
- lists = append(lists, resp)
- }
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = lists
- case 3:
- items, err := data_manage.GetBaseFromCoalmineFirmIndexByCode(indexCode)
- if err != nil {
- br.Msg = "获取煤炭数据失败"
- br.ErrMsg = "获取煤炭度数据失败,Err:" + err.Error()
- return
- }
- groups, err := data_manage.GetGroupNameFromCoalmineIndex(suffix)
- if err != nil {
- br.Msg = "获取煤炭分类数据失败"
- br.ErrMsg = "获取煤炭度分类数据失败,Err: " + err.Error()
- return
- }
- groupMap := make(map[string]int)
- firmId := 300
- for _, group := range groups {
- firmId++
- groupMap[*group] = firmId
- }
- var lists []data_manage.CoalmineSingalDataResp
- var resp data_manage.CoalmineSingalDataResp
- classify := items[0].IndexName
- for i, item := range items {
- if item.IndexName != classify {
- lists = append(lists, resp)
- classify = item.IndexName
- }
- resp.IndexName = item.IndexName
- resp.IndexCode = item.IndexCode
- resp.Unit = item.Unit
- resp.GroupId = groupMap[item.GroupName]
- resp.GroupName = item.GroupName
- resp.Frequency = item.Frequency
- resp.ModifyTime = item.ModifyTime
- resp.ClassifyId = classifyId
- //组装dataList
- var dataItem data_manage.DataList
- dataItem.DataTime = item.DataTime
- dataItem.Value = item.DealValue
- resp.DataList = append(resp.DataList, dataItem)
- if i == len(items)-1 {
- lists = append(lists, resp)
- }
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = lists
- case 4:
- items, err := data_manage.GetBaseFromCoalmineCoastalIndexByCode(indexCode)
- if err != nil {
- br.Msg = "获取煤炭数据失败"
- br.ErrMsg = "获取煤炭度数据失败,Err:" + err.Error()
- return
- }
- groups, err := data_manage.GetGroupNameFromCoalmineIndex(suffix)
- if err != nil {
- br.Msg = "获取煤炭分类数据失败"
- br.ErrMsg = "获取煤炭度分类数据失败,Err: " + err.Error()
- return
- }
- groupMap := make(map[string]int)
- coastalId := 400
- for _, group := range groups {
- coastalId++
- groupMap[*group] = coastalId
- }
- var lists []data_manage.CoalmineSingalDataResp
- var resp data_manage.CoalmineSingalDataResp
- classify := items[0].IndexName
- for i, item := range items {
- if item.IndexName != classify {
- lists = append(lists, resp)
- classify = item.IndexName
- }
- resp.IndexName = item.IndexName
- resp.IndexCode = item.IndexCode
- resp.Unit = item.Unit
- resp.GroupId = groupMap[item.GroupName]
- resp.GroupName = item.GroupName
- resp.Frequency = item.Frequency
- resp.ModifyTime = item.ModifyTime
- resp.ClassifyId = classifyId
- //组装dataList
- var dataItem data_manage.DataList
- dataItem.DataTime = item.DataTime
- dataItem.Value = item.DealValue
- resp.DataList = append(resp.DataList, dataItem)
- if i == len(items)-1 {
- lists = append(lists, resp)
- }
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = lists
- case 5:
- items, err := data_manage.GetBaseFromCoalmineInlandIndexByCode(indexCode)
- if err != nil {
- br.Msg = "获取煤炭数据失败"
- br.ErrMsg = "获取煤炭度数据失败,Err:" + err.Error()
- return
- }
- groups, err := data_manage.GetGroupNameFromCoalmineIndex(suffix)
- if err != nil {
- br.Msg = "获取煤炭分类数据失败"
- br.ErrMsg = "获取煤炭度分类数据失败,Err: " + err.Error()
- return
- }
- groupMap := make(map[string]int)
- inlandId := 500
- for _, group := range groups {
- inlandId++
- groupMap[*group] = inlandId
- }
- var lists []data_manage.CoalmineSingalDataResp
- var resp data_manage.CoalmineSingalDataResp
- classify := items[0].IndexName
- for i, item := range items {
- if item.IndexName != classify {
- lists = append(lists, resp)
- classify = item.IndexName
- }
- resp.IndexName = item.IndexName
- resp.IndexCode = item.IndexCode
- resp.Unit = item.Unit
- resp.GroupId = groupMap[item.GroupName]
- resp.GroupName = item.GroupName
- resp.Frequency = item.Frequency
- resp.ModifyTime = item.ModifyTime
- resp.ClassifyId = classifyId
- //组装dataList
- var dataItem data_manage.DataList
- dataItem.DataTime = item.DataTime
- dataItem.Value = item.DealValue
- resp.DataList = append(resp.DataList, dataItem)
- if i == len(items)-1 {
- lists = append(lists, resp)
- }
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = lists
- default:
- br.Msg = "获取煤炭数据失败"
- br.ErrMsg = "获取煤炭度数据失败,Err: indexCode 错误"
- return
- }
- }
- // ExportCoalList
- // @Title 导出煤炭数据
- // @Description 导出煤炭数据
- // @Param ClassifyId query int true "数据id"
- // @Param IndexName query string true "名称关键词"
- // @Param IndexCode query string true "指标唯一编码"
- // @Param TypeName query string true "分类"
- // @Param Frequency query string false "频度"
- // @Param UnitName query string false "单位"
- // @Success 200 导出成功
- // @router /export/coalList [get]
- func (this *TradeCommonController) ExportCoalList() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- classifyId, _ := this.GetInt("ClassifyId")
- var suffix string
- if classifyId == 1 {
- suffix = "jsm_index"
- } else if classifyId == 2 {
- suffix = "company_index"
- } else if classifyId == 3 {
- suffix = "firm_index"
- } else if classifyId == 4 {
- suffix = "coastal_index"
- } else if classifyId == 5 {
- suffix = "inland_index"
- }
- breedName := this.GetString("TypeName") //分类
- secNameList := make([]*models.EdbdataExportList, 0)
- dir, _ := os.Executable()
- exPath := filepath.Dir(dir)
- downLoadnFilePath := exPath + "/" + time.Now().Format(utils.FormatDateTimeUnSpace) + ".xlsx"
- xlsxFile := xlsx.NewFile()
- //不为空就是导出分类表
- if breedName != "" {
- //获取指标
- var secNameList []*string
- var err error
- if classifyId == 1 {
- secNameList, err = data_manage.GetClassifyJsmByGroupName(breedName)
- if err != nil {
- fmt.Println("获取数据失败,Err:" + err.Error())
- return
- }
- } else {
- secNameList, err = data_manage.GetClassifyFromCoalByGroupName(suffix, breedName)
- if err != nil {
- fmt.Println("获取数据失败,Err:" + err.Error())
- return
- }
- }
- if len(secNameList) <= 0 {
- fmt.Println("secNameList长度为0")
- return
- }
- sheetNew, err := xlsxFile.AddSheet(breedName)
- if err != nil {
- fmt.Println("新增Sheet失败", err.Error())
- return
- }
- //sheetNew.SetColWidth()
- //获取指标数据
- windRow := sheetNew.AddRow()
- secNameRow := sheetNew.AddRow()
- indexCodeRow := sheetNew.AddRow()
- frequencyRow := sheetNew.AddRow()
- unitRow := sheetNew.AddRow()
- lastModifyDateRow := sheetNew.AddRow()
- //获取分类下指标最大数据量
- var dataMax int
- if classifyId == 1 {
- dataMax, err = data_manage.GetCoalJsmMaxCount(breedName)
- if err != nil {
- fmt.Println("获取指标最大数据量失败", err.Error())
- return
- }
- } else {
- dataMax, err = data_manage.GetCoalCompanyMaxCount(suffix, breedName)
- if err != nil {
- fmt.Println("获取指标最大数据量失败", err.Error())
- return
- }
- }
- setRowIndex := 6
- for k, sv := range secNameList {
- //获取数据
- dataList, err := data_manage.GetBaseFromCoalIndexByCode(suffix, *sv)
- if err != nil {
- br.Msg = "获取数据失败"
- br.ErrMsg = "获取数据失败,Err:" + err.Error()
- return
- }
- windRow.AddCell().SetValue(breedName)
- secNameRow.AddCell().SetValue("指标名称")
- indexCodeRow.AddCell().SetValue("指标ID")
- frequencyRow.AddCell().SetValue("频率")
- unitRow.AddCell().SetValue("单位")
- lastModifyDateRow.AddCell().SetValue("更新时间")
- secNameRow.AddCell().SetValue(dataList[0].IndexName)
- indexCodeRow.AddCell().SetValue(dataList[0].IndexCode)
- frequencyRow.AddCell().SetValue(dataList[0].Frequency)
- unitRow.AddCell().SetValue(dataList[0].Unit)
- lastModifyDateRow.AddCell().SetValue(dataList[0].ModifyTime)
- windRow.AddCell()
- windRow.AddCell()
- secNameRow.AddCell()
- indexCodeRow.AddCell()
- frequencyRow.AddCell()
- unitRow.AddCell()
- lastModifyDateRow.AddCell()
- min := k * 3
- sheetNew.SetColWidth(min, min, 15)
- if len(dataList) <= 0 {
- for n := 0; n < dataMax; n++ {
- rowIndex := setRowIndex + n
- row := sheetNew.Row(rowIndex)
- row.AddCell()
- row.AddCell()
- row.AddCell()
- }
- } else {
- endRowIndex := 0
- for rk, dv := range dataList {
- rowIndex := setRowIndex + rk
- row := sheetNew.Row(rowIndex)
- if classifyId == 3 {
- displayDateCell := row.AddCell()
- displayDateCell.SetValue(dv.DataTime)
- } else {
- displayDate, _ := time.Parse(utils.FormatDate, dv.DataTime)
- displayDateCell := row.AddCell()
- style := new(xlsx.Style)
- style.ApplyAlignment = true
- style.Alignment.WrapText = true
- displayDateCell.SetStyle(style)
- displayDateCell.SetDate(displayDate)
- }
- row.AddCell().SetValue(dv.DealValue)
- row.AddCell()
- endRowIndex = rowIndex
- }
- if len(dataList) < dataMax {
- dataLen := dataMax - len(dataList)
- for n := 0; n < dataLen; n++ {
- rowIndex := (endRowIndex + 1) + n
- row := sheetNew.Row(rowIndex)
- row.AddCell()
- row.AddCell()
- row.AddCell()
- }
- }
- }
- }
- } else {
- name := this.GetString("IndexName")
- indexCode := this.GetString("IndexCode") //指标唯一编码
- unit := this.GetString("UnitName")
- modifyTime := this.GetString("ModifyTime")
- sheet, err := xlsxFile.AddSheet("指标")
- if err != nil {
- br.Msg = "新增Sheet失败"
- br.ErrMsg = "新增Sheet失败,Err:" + err.Error()
- return
- }
- //获取数据
- dataList, err := data_manage.GetBaseFromCoalIndexByCode(suffix, indexCode)
- if err != nil {
- br.Msg = "获取数据失败"
- br.ErrMsg = "获取数据失败,Err:" + err.Error()
- return
- }
- //获取指标数据
- windRow := sheet.AddRow()
- windRow.AddCell().SetValue("中国煤炭市场网")
- rowSecName := sheet.AddRow()
- celSecName := rowSecName.AddCell()
- celSecName.SetValue("指标名称")
- cellSenName := rowSecName.AddCell()
- cellSenName.SetValue(name)
- indexCodeRow := sheet.AddRow()
- indexCodeRow.AddCell().SetValue("指标ID")
- indexCodeRow.AddCell().SetValue(indexCode)
- rowFrequency := sheet.AddRow()
- celFrequency := rowFrequency.AddCell()
- celFrequency.SetValue("频率")
- rowFrequency.AddCell().SetValue(dataList[0].Frequency)
- rowUnit := sheet.AddRow()
- celUnit := rowUnit.AddCell()
- celUnit.SetValue("单位")
- cellUnit := rowUnit.AddCell()
- cellUnit.SetValue(unit)
- rowModifyDate := sheet.AddRow()
- rowModifyCell := rowModifyDate.AddCell()
- rowModifyCell.SetValue("更新时间")
- rowModifyCell = rowModifyDate.AddCell()
- rowModifyCell.SetValue(modifyTime)
- fmt.Println("len(dataList):", len(dataList))
- dataMax, err := data_manage.GetCoalCount(suffix, breedName)
- if err != nil {
- fmt.Println("获取指标最大数据量失败", err.Error())
- return
- }
- fmt.Println("dataMax:", dataMax)
- if len(dataList) <= 0 {
- for n := 0; n < dataMax; n++ {
- rowIndex := 6 + n
- row := sheet.Row(rowIndex)
- row.AddCell()
- row.AddCell()
- row.AddCell()
- }
- } else {
- endRowIndex := 0
- for rk, dv := range dataList {
- rowIndex := 6 + rk
- row := sheet.Row(rowIndex)
- displayDate, _ := time.Parse(utils.FormatDate, dv.DataTime)
- displayDateCell := row.AddCell()
- style := new(xlsx.Style)
- style.ApplyAlignment = true
- style.Alignment.WrapText = true
- displayDateCell.SetStyle(style)
- displayDateCell.SetDate(displayDate)
- row.AddCell().SetValue(dv.DealValue)
- row.AddCell()
- endRowIndex = rowIndex
- }
- if len(dataList) < dataMax {
- dataLen := dataMax - len(dataList)
- for n := 0; n < dataLen; n++ {
- rowIndex := (endRowIndex + 1) + n
- row := sheet.Row(rowIndex)
- row.AddCell()
- row.AddCell()
- row.AddCell()
- }
- }
- }
- }
- err := xlsxFile.Save(downLoadnFilePath)
- if err != nil {
- br.Msg = "保存文件失败"
- br.ErrMsg = "保存文件失败"
- return
- }
- fileName := `中国煤炭市场网数据`
- if len(secNameList) > 0 {
- fileName = secNameList[0].ClassifyName
- }
- fileName += time.Now().Format("06.01.02") + `.xlsx` //文件名称
- this.Ctx.Output.Download(downLoadnFilePath, fileName)
- defer func() {
- os.Remove(downLoadnFilePath)
- }()
- br.Ret = 200
- br.Success = true
- br.Msg = "success"
- }
- // EicLatestDateV2
- // @title 获取欧洲天然气最新日期V2
- // @Description 获取欧洲天然气最新日期接口
- // @Success 200 {object} models.
- // @router /data/eicLatestDateV2 [get]
- func (this *TradeCommonController) EicLatestDateV2() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- latestData, err := data_manage.GetEicDateV2()
- if err != nil {
- br.Msg = "获取日期失败"
- br.ErrMsg = "获取日期失败,Err:" + err.Error()
- return
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = latestData[0].GasDayStart
- }
- type EicDataV2 struct {
- Name string `json:"name" description:"指标名称"`
- Code string `json:"code" description:"指标编码"`
- GasDayStart string `json:"gasDayStart" description:"指标日期"`
- GasInStorage float64 `json:"gasInStorage" description:"储存容量"`
- Consumption string `json:"consumption" description:"消耗"`
- ConsumptionFull string `json:"consumptionFull" description:"消耗百分比"`
- Injection float64 `json:"injection" description:"注入量"`
- Withdrawal float64 `json:"withdrawal" description:"减少量"`
- WorkingGasVolume float64 `json:"workingGasVolume" description:"工作气体量"`
- InjectionCapacity float64 `json:"injectionCapacity" description:"注入速度"`
- WithdrawalCapacity float64 `json:"withdrawalCapacity" description:"减少速度"`
- Status string `json:"status" description:"状态"`
- Trend float64 `json:"trend" description:"较前日对比"`
- Full float64 `json:"full" description:"储存容量百分比"`
- Info string `json:"info" description:"信息"`
- Children []EicDataV2 `json:"children"`
- }
- // eicDataV2
- // @title 获取欧洲天然气列表
- // @Description 获取欧洲天然气列表接口
- // @Param Date query string true "查询日期"
- // @Success 200 {object} models.
- // @router /data/eicDataV2 [get]
- func (this *TradeCommonController) EicDataV2() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- date := this.GetString("Date")
- list, err := data_manage.GetEicDataV2(date)
- if err != nil {
- br.Msg = "获取天然气数据失败"
- br.ErrMsg = "获取天然气数据失败,Err:" + err.Error()
- return
- }
- var continentItems []data_manage.BaseFromTradeEicIndexV2
- var countryItems []data_manage.BaseFromTradeEicIndexV2
- var ssoItems []data_manage.BaseFromTradeEicIndexV2
- var facItems []data_manage.BaseFromTradeEicIndexV2
- for _, item := range list {
- switch item.Type {
- case "continent":
- continentItems = append(continentItems, *item)
- case "country":
- countryItems = append(countryItems, *item)
- case "sso":
- ssoItems = append(ssoItems, *item)
- case "fac":
- facItems = append(facItems, *item)
- default:
- continue
- }
- }
- var data []data_manage.BaseFromTradeEicIndexV2
- data = continentItems
- for i, continentItem := range continentItems {
- for _, countryItem := range countryItems {
- if countryItem.Parent == continentItem.Name {
- data[i].Children = append(data[i].Children, countryItem)
- }
- }
- for j, country := range data[i].Children {
- for _, ssoItem := range ssoItems {
- if country.Name == ssoItem.Parent {
- data[i].Children[j].Children = append(data[i].Children[j].Children, ssoItem)
- }
- }
- for k, sso := range data[i].Children[j].Children {
- for _, facItem := range facItems {
- if sso.Name == facItem.Parent {
- data[i].Children[j].Children[k].Children = append(data[i].Children[j].Children[k].Children, facItem)
- }
- }
- }
- }
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = data
- }
- // EicHistoryDataV2
- // @title 获取欧洲天然气历史列表
- // @Description 获取欧洲天然气历史列表接口
- // @Param Code query string true "Code"
- // @Param StartDate query string false "开始时间"
- // @Param EndDate query string false "结束时间"
- // @Success 200 {object} []EicDataV2
- // @router /data/eicHistoryDataV2 [get]
- func (this *TradeCommonController) EicHistoryDataV2() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- code := this.GetString("Code")
- startDate := this.GetString("StartDate")
- endDate := this.GetString("EndDate")
- var eicList []*data_manage.BaseFromTradeEicIndexV2
- var err error
- if endDate != "" {
- eicList, err = data_manage.GetEicHistoryDateByDateV2(code, startDate, endDate)
- if err != nil {
- br.Msg = "获取持仓排名失败"
- br.ErrMsg = "获取持仓排名失败,Err:" + err.Error()
- return
- }
- } else {
- eicList, err = data_manage.GetEicHistoryDateV2(code)
- if err != nil {
- br.Msg = "获取持仓排名失败"
- br.ErrMsg = "获取持仓排名失败,Err:" + err.Error()
- return
- }
- }
- var data []EicDataV2
- for _, eic := range eicList {
- item := EicDataV2{
- Name: eic.Name,
- Code: eic.EicCode,
- GasDayStart: eic.GasDayStart,
- GasInStorage: eic.GasInStorage,
- Consumption: eic.Consumption,
- ConsumptionFull: eic.ConsumptionFull,
- Injection: eic.Injection,
- Withdrawal: eic.Withdrawal,
- WorkingGasVolume: eic.WorkingGasVolume,
- InjectionCapacity: eic.InjectionCapacity,
- WithdrawalCapacity: eic.WithdrawalCapacity,
- Status: eic.Status,
- Trend: eic.Trend,
- Full: eic.Full,
- Info: eic.Info,
- }
- data = append(data, item)
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = data
- }
- // eicContinentV2 欧洲天然气洲际及国家级列表
- // @title 欧洲天然气洲际及国家级列表
- // @Description 欧洲天然气洲际及国家级列表
- // @Param Date query string true "查询日期"
- // @Success 200 {object} []data_manage.BaseFromTradeEicIndexV2
- // @router /data/eicContinentV2 [get]
- func (this *TradeCommonController) EicContinentListV2() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- date := this.GetString("Date")
- list, err := data_manage.GetContinentAndCountryEicDateV2(date)
- if err != nil {
- br.Msg = "获取天然气数据失败"
- br.ErrMsg = "获取天然气数据失败,Err:" + err.Error()
- return
- }
- var continentItems []data_manage.BaseFromTradeEicIndexV2
- var countryItems []data_manage.BaseFromTradeEicIndexV2
- for _, item := range list {
- switch item.Type {
- case "continent":
- continentItems = append(continentItems, *item)
- case "country":
- countryItems = append(countryItems, *item)
- default:
- continue
- }
- }
- var data []data_manage.BaseFromTradeEicIndexV2
- data = continentItems
- for i, continentItem := range continentItems {
- for _, countryItem := range countryItems {
- if countryItem.Parent == continentItem.Name {
- data[i].Children = append(data[i].Children, countryItem)
- }
- }
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = data
- }
- // EicDataListV2 欧洲天然气细节列表
- // @title 欧洲天然气细节列表
- // @Description 欧洲天然气细节列表
- // @Param Date query string true "查询日期"
- // @Param Name query string true "国家"
- // @Success 200 {object} []data_manage.BaseFromTradeEicIndexV2
- // @router /data/eicSSODataV2 [get]
- func (this *TradeCommonController) EicDataListV2() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- date := this.GetString("Date")
- name := this.GetString("Name")
- list, err := data_manage.GetSSOAndFacEicDateV2(date, name)
- if err != nil {
- br.Msg = "获取天然气数据失败"
- br.ErrMsg = "获取天然气数据失败,Err:" + err.Error()
- return
- }
- var ssoItems []data_manage.BaseFromTradeEicIndexV2
- var facItems []data_manage.BaseFromTradeEicIndexV2
- for _, item := range list {
- switch item.Type {
- case "sso":
- ssoItems = append(ssoItems, *item)
- case "fac":
- facItems = append(facItems, *item)
- default:
- continue
- }
- }
- i := 0
- var data []data_manage.BaseFromTradeEicIndexV2
- for _, ssoItem := range ssoItems {
- if ssoItem.Parent == name {
- data = append(data, ssoItem)
- for _, facItem := range facItems {
- if facItem.Parent == ssoItem.Name {
- data[i].Children = append(data[i].Children, facItem)
- }
- }
- i++
- }
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = data
- }
- // CoalMineClassify
- // @title 获取煤炭江湖分类列表
- // @Description 获取煤炭江湖分类列表
- // @Success 200 {object} models.
- // @router /data/mtjh/classify [get]
- func (this *TradeCommonController) MtjhClassify() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- list, err := data_manage.GetMtjhClassifyList()
- if err != nil {
- br.Msg = "获取煤炭分类数据失败"
- br.ErrMsg = "获取煤炭度分类数据失败,Err: " + err.Error()
- return
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = list
- }
- // CoalMineData
- // @title 获取煤炭江湖详细数据列表
- // @Description 获取煤炭江湖详细数据接口
- // @Param ClassifyId query int true "数据id"
- // @Param GroupName query string true "分组名"
- // @Param Frequency query string true "频度"
- // @Param PageSize query int true "每页数据条数"
- // @Param CurrentIndex query int true "当前页页码,从1开始"
- // @Success 200 {object} []data_manage.CoalmineDataResp
- // @router /data/mtjh/data [get]
- func (this *TradeCommonController) MtjhData() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- pageSize, _ := this.GetInt("PageSize")
- currentIndex, _ := this.GetInt("CurrentIndex")
- var startSize int
- if pageSize <= 0 {
- pageSize = utils.PageSize20
- }
- if currentIndex <= 0 {
- currentIndex = 1
- }
- startSize = utils.StartIndex(currentIndex, pageSize)
- area := this.GetString("Area")
- if area == "" {
- br.Msg = "请选择分类"
- br.ErrMsg = "请选择分类"
- return
- }
- //获取指标
- var condition string
- var pars []interface{}
- if area != "" {
- condition += ` AND area=? `
- pars = append(pars, area)
- }
- mtjhList, err := data_manage.GetMtjhMapping(condition, pars)
- if err != nil {
- br.Msg = "获取数据失败"
- br.ErrMsg = "获取数据失败,Err:" + err.Error()
- return
- }
- resultList := make([]*data_manage.BaseFromMtjhIndexList, 0)
- for _, v := range mtjhList {
- product := new(data_manage.BaseFromMtjhIndexList)
- product.BaseFromMtjhMappingId = v.BaseFromMtjhMappingId
- product.Unit = v.Unit
- product.IndexCode = v.IndexCode
- product.IndexName = v.IndexName
- product.Port = v.Port
- product.Area = v.Area
- product.Variety = v.Variety
- product.Frequency = v.Frequency
- product.CreateTime = v.CreateTime
- modifyTime, err := data_manage.GetMtjhIndexLatestDate(v.IndexCode)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取更新时间失败"
- br.ErrMsg = "获取更新时间失败,Err:" + err.Error()
- return
- }
- product.ModifyTime = modifyTime
- total, err := data_manage.GetMtjhIndexDataCount(v.IndexCode)
- if err != nil {
- br.Msg = "获取总数失败"
- br.ErrMsg = "获取总数失败,Err:" + err.Error()
- return
- }
- page := paging.GetPaging(currentIndex, pageSize, total)
- dataList, err := data_manage.GetMtjhIndexData(v.IndexCode, startSize, pageSize)
- if err != nil {
- br.Msg = "获取数据失败"
- br.ErrMsg = "获取指标数据失败,Err:" + err.Error()
- return
- }
- if dataList == nil {
- dataList = make([]*data_manage.BaseFromMtjhIndexItem, 0)
- }
- product.DataList = dataList
- product.Paging = page
- resultList = append(resultList, product)
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resultList
- return
- }
- // CoalSearchList
- // @Title 煤炭江湖模糊搜索
- // @Description 煤炭江湖模糊搜索
- // @Param Keyword query string ture "关键字搜索"
- // @Success 200 {object} models.BaseResponse
- // @router /data/mtjh/search [get]
- func (this *TradeCommonController) MtjhSearchList() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- //关键字
- keyword := this.GetString("Keyword")
- list, err := data_manage.GetMtjhItemList(keyword)
- if err != nil {
- br.ErrMsg = "获取失败,Err:" + err.Error()
- br.Msg = "获取失败"
- return
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = list
- }
- // CoalSingleData
- // @Title 获取煤炭江湖单条数据
- // @Description 获取煤炭江湖单条数据
- // @Param IndexCode query string true "指标唯一编码"
- // @Success 200 {object} []data_manage.CoalmineSingalDataResp
- // @router /data/mtjh/single_data [get]
- func (this *TradeCommonController) MtjhSingleData() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- indexCode := this.GetString("IndexCode")
- pageSize, _ := this.GetInt("PageSize")
- currentIndex, _ := this.GetInt("CurrentIndex")
- var startSize int
- if pageSize <= 0 {
- pageSize = utils.PageSize20
- }
- if currentIndex <= 0 {
- currentIndex = 1
- }
- startSize = utils.StartIndex(currentIndex, pageSize)
- mapping, err := data_manage.GetMtjhMappingItemByCode(indexCode)
- if err != nil {
- br.Msg = "获取煤炭数据失败"
- br.ErrMsg = "获取煤炭度数据失败,Err:" + err.Error()
- return
- }
- items, err := data_manage.GetMtjhIndexData(indexCode, startSize, pageSize)
- if err != nil {
- br.Msg = "获取煤炭数据失败"
- br.ErrMsg = "获取煤炭度数据失败,Err:" + err.Error()
- return
- }
- modifyTime, err := data_manage.GetMtjhIndexLatestDate(indexCode)
- if err != nil {
- br.Msg = "获取更新时间失败"
- br.ErrMsg = "获取更新时间失败,Err:" + err.Error()
- return
- }
- total, err := data_manage.GetMtjhIndexDataCount(indexCode)
- if err != nil {
- br.Msg = "获取总数失败"
- br.ErrMsg = "获取总数失败,Err:" + err.Error()
- return
- }
- page := paging.GetPaging(currentIndex, pageSize, total)
- resp := data_manage.BaseFromMtjhIndexList{
- BaseFromMtjhMappingId: mapping.BaseFromMtjhMappingId,
- IndexName: mapping.IndexName,
- IndexCode: mapping.IndexCode,
- Area: mapping.Area,
- Port: mapping.Port,
- Unit: mapping.Unit,
- Frequency: mapping.Frequency,
- CreateTime: mapping.CreateTime,
- ModifyTime: modifyTime,
- Variety: mapping.Variety,
- DataList: items,
- Paging: page,
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- return
- }
- // MtjhFrequency
- // @title 获取煤炭江湖频度
- // @Description 获取煤炭江湖频度
- // @Param ClassifyId query int true "数据id"
- // @Success 200 {object} models.
- // @router /data/mtjh/frequency [get]
- func (this *TradeCommonController) MtjhFrequency() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- area := this.GetString("Area")
- list, err := data_manage.GetMtjhFrequencyByArea(area)
- if err != nil {
- br.Msg = "获取煤炭频度数据失败"
- br.ErrMsg = "获取煤炭频度数据失败,Err:" + err.Error()
- return
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = list
- }
- // ExportCoalList
- // @Title 导出煤炭江湖数据
- // @Description 导出煤炭江湖数据
- // @Param ClassifyId query int true "数据id"
- // @Param IndexName query string true "名称关键词"
- // @Param IndexCode query string true "指标唯一编码"
- // @Param TypeName query string true "分类"
- // @Param Frequency query string false "频度"
- // @Param UnitName query string false "单位"
- // @Success 200 导出成功
- // @router /export/mtjh [get]
- func (this *TradeCommonController) ExportMtjhList() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- area := this.GetString("Area")
- indexCode := this.GetString("IndexCode") //指标唯一编码
- secNameList := make([]*models.EdbdataExportList, 0)
- dir, _ := os.Executable()
- exPath := filepath.Dir(dir)
- downLoadnFilePath := exPath + "/" + time.Now().Format(utils.FormatDateTimeUnSpace) + ".xlsx"
- xlsxFile := xlsx.NewFile()
- //不为空就是导出分类表
- if indexCode == "" {
- //获取指标
- var secNameList []*string
- var err error
- secNameList, err = data_manage.GetClassifyMtjhByArea(area)
- if err != nil {
- fmt.Println("获取数据失败,Err:" + err.Error())
- return
- }
- if len(secNameList) <= 0 {
- fmt.Println("secNameList长度为0")
- return
- }
- sheetNew, err := xlsxFile.AddSheet(area)
- if err != nil {
- fmt.Println("新增Sheet失败", err.Error())
- return
- }
- //sheetNew.SetColWidth()
- //获取指标数据
- windRow := sheetNew.AddRow()
- secNameRow := sheetNew.AddRow()
- indexCodeRow := sheetNew.AddRow()
- frequencyRow := sheetNew.AddRow()
- unitRow := sheetNew.AddRow()
- lastModifyDateRow := sheetNew.AddRow()
- //获取分类下指标最大数据量
- var dataMax int
- dataMax, err = data_manage.GetCoalMtjhMaxCount(area)
- if err != nil {
- fmt.Println("获取指标最大数据量失败", err.Error())
- return
- }
- setRowIndex := 6
- for k, sv := range secNameList {
- //获取数据
- dataList, err := data_manage.GetBaseFromMtjhIndexByCode(*sv)
- if err != nil {
- br.Msg = "获取数据失败"
- br.ErrMsg = "获取数据失败,Err:" + err.Error()
- return
- }
- windRow.AddCell().SetValue(area)
- secNameRow.AddCell().SetValue("指标名称")
- indexCodeRow.AddCell().SetValue("指标ID")
- frequencyRow.AddCell().SetValue("频率")
- unitRow.AddCell().SetValue("单位")
- lastModifyDateRow.AddCell().SetValue("更新时间")
- secNameRow.AddCell().SetValue(dataList[0].IndexName)
- indexCodeRow.AddCell().SetValue(dataList[0].IndexCode)
- frequencyRow.AddCell().SetValue(dataList[0].Frequency)
- unitRow.AddCell().SetValue(dataList[0].Unit)
- lastModifyDateRow.AddCell().SetValue(dataList[0].ModifyTime)
- windRow.AddCell()
- windRow.AddCell()
- secNameRow.AddCell()
- indexCodeRow.AddCell()
- frequencyRow.AddCell()
- unitRow.AddCell()
- lastModifyDateRow.AddCell()
- min := k * 3
- sheetNew.SetColWidth(min, min, 15)
- if len(dataList) <= 0 {
- for n := 0; n < dataMax; n++ {
- rowIndex := setRowIndex + n
- row := sheetNew.Row(rowIndex)
- row.AddCell()
- row.AddCell()
- row.AddCell()
- }
- } else {
- endRowIndex := 0
- for rk, dv := range dataList {
- rowIndex := setRowIndex + rk
- row := sheetNew.Row(rowIndex)
- displayDate, _ := time.Parse(utils.FormatDate, dv.DataTime)
- displayDateCell := row.AddCell()
- style := new(xlsx.Style)
- style.ApplyAlignment = true
- style.Alignment.WrapText = true
- displayDateCell.SetStyle(style)
- displayDateCell.SetDate(displayDate)
- row.AddCell().SetValue(dv.DealValue)
- row.AddCell()
- endRowIndex = rowIndex
- }
- if len(dataList) < dataMax {
- dataLen := dataMax - len(dataList)
- for n := 0; n < dataLen; n++ {
- rowIndex := (endRowIndex + 1) + n
- row := sheetNew.Row(rowIndex)
- row.AddCell()
- row.AddCell()
- row.AddCell()
- }
- }
- }
- }
- } else {
- sheet, err := xlsxFile.AddSheet("指标")
- if err != nil {
- br.Msg = "新增Sheet失败"
- br.ErrMsg = "新增Sheet失败,Err:" + err.Error()
- return
- }
- //获取数据
- dataList, err := data_manage.GetBaseFromMtjhIndexByCode(indexCode)
- if err != nil {
- br.Msg = "获取数据失败"
- br.ErrMsg = "获取数据失败,Err:" + err.Error()
- return
- }
- mapping, err := data_manage.GetMtjhMappingItemByCode(indexCode)
- if err != nil {
- br.Msg = "获取煤炭数据失败"
- br.ErrMsg = "获取煤炭度数据失败,Err:" + err.Error()
- return
- }
- //获取指标数据
- windRow := sheet.AddRow()
- windRow.AddCell().SetValue("煤炭江湖")
- rowSecName := sheet.AddRow()
- celSecName := rowSecName.AddCell()
- celSecName.SetValue("指标名称")
- cellSenName := rowSecName.AddCell()
- cellSenName.SetValue(mapping.IndexName)
- indexCodeRow := sheet.AddRow()
- indexCodeRow.AddCell().SetValue("指标ID")
- indexCodeRow.AddCell().SetValue(indexCode)
- rowFrequency := sheet.AddRow()
- celFrequency := rowFrequency.AddCell()
- celFrequency.SetValue("频率")
- rowFrequency.AddCell().SetValue(mapping.Frequency)
- rowUnit := sheet.AddRow()
- celUnit := rowUnit.AddCell()
- celUnit.SetValue("单位")
- cellUnit := rowUnit.AddCell()
- cellUnit.SetValue(mapping.Unit)
- rowModifyDate := sheet.AddRow()
- rowModifyCell := rowModifyDate.AddCell()
- rowModifyCell.SetValue("更新时间")
- rowModifyCell = rowModifyDate.AddCell()
- rowModifyCell.SetValue(dataList[len(dataList)-1].ModifyTime)
- fmt.Println("len(dataList):", len(dataList))
- dataMax, err := data_manage.GetMtjhCount(indexCode)
- if err != nil {
- fmt.Println("获取指标最大数据量失败", err.Error())
- return
- }
- fmt.Println("dataMax:", dataMax)
- if len(dataList) <= 0 {
- for n := 0; n < dataMax; n++ {
- rowIndex := 6 + n
- row := sheet.Row(rowIndex)
- row.AddCell()
- row.AddCell()
- row.AddCell()
- }
- } else {
- endRowIndex := 0
- for rk, dv := range dataList {
- rowIndex := 6 + rk
- row := sheet.Row(rowIndex)
- displayDate, _ := time.Parse(utils.FormatDate, dv.DataTime)
- displayDateCell := row.AddCell()
- style := new(xlsx.Style)
- style.ApplyAlignment = true
- style.Alignment.WrapText = true
- displayDateCell.SetStyle(style)
- displayDateCell.SetDate(displayDate)
- row.AddCell().SetValue(dv.DealValue)
- row.AddCell()
- endRowIndex = rowIndex
- }
- if len(dataList) < dataMax {
- dataLen := dataMax - len(dataList)
- for n := 0; n < dataLen; n++ {
- rowIndex := (endRowIndex + 1) + n
- row := sheet.Row(rowIndex)
- row.AddCell()
- row.AddCell()
- row.AddCell()
- }
- }
- }
- }
- err := xlsxFile.Save(downLoadnFilePath)
- if err != nil {
- br.Msg = "保存文件失败"
- br.ErrMsg = "保存文件失败"
- return
- }
- fileName := `煤炭江湖数据`
- if len(secNameList) > 0 {
- fileName = secNameList[0].ClassifyName
- }
- fileName += time.Now().Format(utils.FormatDateUnSpace) + `.xlsx` //文件名称
- this.Ctx.Output.Download(downLoadnFilePath, fileName)
- defer func() {
- os.Remove(downLoadnFilePath)
- }()
- br.Ret = 200
- br.Success = true
- br.Msg = "success"
- }
|