123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465 |
- package controllers
- import (
- "eta/eta_api/models"
- "eta/eta_api/models/data_manage"
- "eta/eta_api/utils"
- "github.com/rdlucklib/rdluck_tools/paging"
- )
- // OilchemClassify
- // @title 获取隆众资讯分类列表
- // @Description 获取隆众资讯分类列表
- // @Success 200 {object} models.
- // @router /data/oilchem/classify [get]
- func (this *TradeCommonController) OilchemClassify() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- classifies, e := data_manage.GetOilchemClassifyList()
- if e != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取隆众资讯分类数据分类失败, Err: " + e.Error()
- return
- }
- br.Data = classifies
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- }
- // OilchemIndexList
- // @title 获取隆众资讯指标列表
- // @Description 获取隆众资讯指标列表
- // @Success 200 {object} models.
- // @router /data/oilchem/indexList [get]
- func (this *TradeCommonController) OilchemIndexList() {
- 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)
- classifyId, _ := this.GetInt("ClassifyId")
- var condition string
- var pars []interface{}
- if classifyId > 0{
- condition += ` AND classify_id=? `
- pars = append(pars, classifyId)
- }
- keyword := this.GetString("KeyWord")
- if keyword != "" {
- condition += ` AND (index_code =? OR index_name LIKE ?) `
- pars = append(pars, keyword)
- pars = append(pars, "%"+keyword+"%")
- }
- indexList, e := data_manage.GetOilchemIndexList(condition, pars, startSize, pageSize)
- if e != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取隆众资讯分类数据分类失败, Err: " + e.Error()
- return
- }
- total, err := data_manage.GetOilchemIndexListCount(condition, pars)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取隆众资讯分类数据分类失败, Err: " + err.Error()
- return
- }
- page := paging.GetPaging(currentIndex, pageSize, total)
- resp := data_manage.BaseFromOilchemIndexListResp{}
- resp.List = indexList
- resp.Paging = page
- br.Data = indexList
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- }
- // OilchemMineData
- // @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/oilchem/data [get]
- func (this *TradeCommonController) OilchemData() {
- 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)
- indexCode := this.GetString("IndexCode")
- if indexCode == "" {
- br.Msg = "请选择指标"
- br.ErrMsg = "请选择指标"
- return
- }
- //获取指标
- var condition string
- var pars []interface{}
- condition += ` AND index_code =? `
- pars = append(pars, indexCode)
- index, err := data_manage.GetOilchemIndexByCode(indexCode)
- if err != nil {
- br.Msg = "获取数据失败"
- br.ErrMsg = "获取数据失败,Err:" + err.Error()
- return
- }
- dataList, err := data_manage.GetOilchemIndexData(condition, pars, startSize, pageSize)
- if err != nil {
- br.Msg = "获取数据失败"
- br.ErrMsg = "获取数据失败,Err:" + err.Error()
- return
- }
- resp := data_manage.BaseFromOilchemIndexList{}
- resp.BaseFromOilchemIndexId = index.BaseFromOilchemIndexId
- resp.ClassifyId = index.ClassifyId
- resp.IndexCode = index.IndexCode
- resp.IndexName = index.IndexName
- resp.Frequency = index.Frequency
- resp.Unit = index.Unit
- total, err := data_manage.GetOilchemDataListCount(condition, pars)
- page := paging.GetPaging(currentIndex, pageSize, total)
- if len(dataList) > 0 {
- resp.ModifyTime = dataList[0].ModifyTime
- }
- resp.Paging = page
- resp.DataList = dataList
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- }
- // CoalSearchList
- // @Title 隆众资讯模糊搜索
- // @Description 隆众资讯模糊搜索
- // @Param Keyword query string ture "关键字搜索"
- // @Success 200 {object} models.BaseResponse
- // @router /data/oilchem/search [get]
- func (this *TradeCommonController) OilchemSearchList() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- //关键字
- keyword := this.GetString("Keyword")
- list, err := data_manage.GetOilchemItemList(keyword)
- if err != nil {
- br.ErrMsg = "获取失败,Err:" + err.Error()
- br.Msg = "获取失败"
- 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"
- //
- //}
|