1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058 |
- package controllers
- import (
- "eta_gn/eta_api/models"
- "eta_gn/eta_api/models/data_manage"
- "eta_gn/eta_api/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 = "获取失败"
- br.ErrMsg = "获取最新日期失败,Err:" + err.Error()
- 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"
- }
|