123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965 |
- package controllers
- import (
- "eta/eta_hub/models"
- "eta/eta_hub/models/data_manage"
- "fmt"
- "strings"
- )
- type TradeCommonController struct {
- BaseAuthController
- }
- type SHData []struct {
- Title string
- ItemList []ShanghaiList
- }
- type ShanghaiList struct {
- Code string
- Item []*data_manage.BaseFromTradeShanghaiIndex
- }
- type CffexData []struct {
- Title string
- ItemList []CffexList
- }
- type CffexList struct {
- Code string
- Item []*data_manage.BaseFromTradeCffexIndex
- }
- type DLData []struct {
- Title string
- ItemList []DalianList
- }
- type DalianList struct {
- Code string
- Item []*data_manage.BaseFromTradeDalianIndex
- }
- type ZZData []struct {
- Title string
- ItemList []ZhengzhouList
- }
- type ZhengzhouList struct {
- Code string
- Item []*data_manage.BaseFromTradeZhengzhouIndex
- }
- type IneData []struct {
- Title string
- ItemList []IneList
- }
- type IneList struct {
- Code string
- Item []*data_manage.BaseFromTradeIneIndex
- }
- 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.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.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.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 SHData
- var j, k int
- if len(frequencyList) == 0 {
- br.Ret = 200
- br.Msg = "获取成功"
- br.Data = data
- } else {
- if classifyName == "" {
- data = make(SHData, 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.Msg = "获取成功"
- br.Data = data
- } else {
- data = make(SHData, 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.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.GetBaseFromTradeIneIndexByParam("ine", date, classifyName, classifyType)
- if err != nil {
- br.Msg = "获取持仓排名失败"
- br.ErrMsg = "获取持仓排名失败,Err:" + err.Error()
- return
- }
- var data IneData
- var k int
- if len(frequencyList) == 0 {
- br.Ret = 200
- br.Msg = "获取成功"
- br.Data = data
- } else {
- data = make(IneData, 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([]IneList, 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.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([]IneList, 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.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.GetBaseFromTradeCffexIndexByParam("cffex", date, classifyName, classifyType)
- if err != nil {
- br.Msg = "获取持仓排名失败"
- br.ErrMsg = "获取持仓排名失败,Err:" + err.Error()
- return
- }
- var data CffexData
- var k int
- if len(frequencyList) == 0 {
- br.Ret = 200
- br.Msg = "获取成功"
- br.Data = data
- } else {
- data = make(CffexData, 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([]CffexList, 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.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([]CffexList, 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.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.GetBaseFromTradeZhengzhouIndexByParam("zhengzhou", date, classifyName, classifyType)
- if err != nil {
- br.Msg = "获取持仓排名失败"
- br.ErrMsg = "获取持仓排名失败,Err:" + err.Error()
- return
- }
- var data ZZData
- var k int
- if len(frequencyList) == 0 {
- br.Ret = 200
- br.Msg = "获取成功"
- br.Data = data
- } else {
- data = make(ZZData, 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([]ZhengzhouList, 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.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([]ZhengzhouList, 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.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.GetBaseFromTradeDalianIndexByParam("dalian", date, classifyName, classifyType)
- if err != nil {
- br.Msg = "获取持仓排名失败"
- br.ErrMsg = "获取持仓排名失败,Err:" + err.Error()
- return
- }
- var data DLData
- var k int
- if len(frequencyList) == 0 {
- br.Ret = 200
- br.Msg = "获取成功"
- br.Data = data
- } else {
- data = make(DLData, 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([]DalianList, 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.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([]DalianList, 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.Msg = "获取成功"
- br.Data = data
- }
- }
- }
- // 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.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.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.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.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.Msg = "获取成功"
- br.Data = data
- }
|