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" }