123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199 |
- package controllers
- import (
- "eta/eta_hub/models"
- "eta/eta_hub/models/data_manage"
- "eta/eta_hub/utils"
- "github.com/rdlucklib/rdluck_tools/paging"
- )
- // EdbInfoController 数据管理
- type EdbInfoController struct {
- BaseAuthController
- }
- // EiaSteoClassify
- // @Title EiaSteo数据分类
- // @Description EiaSteo数据分类接口
- // @Success 200 {object} data_manage.LzClassify
- // @router /eia_steo/classify [get]
- func (this *EdbInfoController) EiaSteoClassify() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- classifyList, err := data_manage.GetEiaSteoClassifyList()
- if err != nil {
- br.Msg = "获取分类失败"
- br.ErrMsg = "获取分类失败,Err:" + err.Error()
- return
- }
- for _, v := range classifyList {
- if v.ClassifyName == `` {
- v.ClassifyName = v.ClassifyNameOriginal
- }
- }
- br.Ret = 200
- br.Msg = "获取成功"
- br.Data = classifyList
- }
- // EiaSteoData
- // @Title 获取EiaSteo数据
- // @Description 获取EiaSteo数据接口
- // @Param BaseFromEiaSteoClassifyId query int true "指标分类id"
- // @Param IndexCode query string true "指标code"
- // @Param IsExport query bool false "是否导出excel,默认是false"
- // @Param PageSize query int true "每页数据条数"
- // @Param CurrentIndex query int true "当前页页码,从1开始"
- // @Success 200 {object} data_manage.LzFrequency
- // @router /eia_steo/data [get]
- func (this *EdbInfoController) EiaSteoData() {
- 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)
- var condition string
- var pars []interface{}
- indexCode := this.GetString("IndexCode")
- if indexCode != "" {
- condition += ` AND index_code = ? `
- pars = append(pars, utils.TrimStr(indexCode))
- }
- classifyId, _ := this.GetInt("BaseFromEiaSteoClassifyId")
- if classifyId > 0 {
- condition += ` AND base_from_eia_steo_classify_id = ? `
- pars = append(pars, classifyId)
- }
- //获取指标
- indexList, err := data_manage.GetEiaSteoIndexList(condition, pars)
- if err != nil {
- br.Msg = "获取数据失败"
- br.ErrMsg = "获取数据失败,Err:" + err.Error()
- return
- }
- resultList := make([]data_manage.EiaSteoIndexListResp, 0)
- for _, v := range indexList {
- indexName := v.IndexName
- if indexName == `` {
- indexName = v.IndexNameOriginal
- }
- product := data_manage.EiaSteoIndexListResp{
- BaseFromEiaSteoIndexId: v.BaseFromEiaSteoIndexId,
- BaseFromEiaSteoClassifyId: v.BaseFromEiaSteoClassifyId,
- IndexCode: v.IndexCode,
- IndexName: indexName,
- //IndexNameOriginal: v.IndexNameOriginal,
- Unit: v.Unit,
- Frequency: v.Frequency,
- StartDate: v.StartDate.Format(utils.FormatDate),
- EndDate: v.EndDate.Format(utils.FormatDate),
- ModifyTime: v.ModifyTime.Format(utils.FormatDateTime),
- CreateTime: v.CreateTime.Format(utils.FormatDateTime),
- //Paging: tmpPaging,
- //DataList: nil,
- }
- total, err := data_manage.GetEiaSteoIndexDataCount(v.IndexCode)
- page := paging.GetPaging(currentIndex, pageSize, total)
- dataList, err := data_manage.GetEiaSteoIndexDataList(v.IndexCode, startSize, pageSize)
- if err != nil {
- br.Msg = "获取数据失败"
- br.ErrMsg = "获取指标数据失败,Err:" + err.Error()
- return
- }
- if dataList == nil {
- dataList = make([]*data_manage.BaseFromEiaSteoDataItem, 0)
- }
- product.DataList = dataList
- product.Paging = page
- resultList = append(resultList, product)
- }
- br.Ret = 200
- br.Msg = "获取成功"
- br.Data = resultList
- }
- //func init() {
- // for i := 110; i < 115; i++ {
- // pushData(i)
- // }
- // //pushData(110)
- //}
- //func pushData(index int) {
- // edbOb := new(data_manage.EdbInfo)
- // dataOb := new(data_manage.EdbData)
- // cond := ``
- // pars := make([]interface{}, 0)
- // //cond += ` AND source in (1,2,3,9,10,11,15,16,17,18,19,20,21,25,26,34,57)`
- // cond += ` AND source in (1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,25,26,28,29,31,32,33,34,35,36,37,38,39,40,41,42,42,44,45,46,47,48,57)`
- // //cond += ` AND edb_code = "C2305235333"`
- // edbList, e := edbOb.GetItemsByCondition(cond, pars, []string{}, "sort ASC, create_time DESC")
- // if e != nil {
- // fmt.Println("EdbList GetItemsByCondition err: " + e.Error())
- // return
- // }
- //
- // count := len(edbList)
- // for k, edb := range edbList {
- // fmt.Println("当前第", index, "组,第", k+1, "条,剩余", count-k-1, "条")
- // req := data_manage.PushBusinessIndexReq{
- // IndexCode: fmt.Sprintf("Roc_%d_%s", index, edb.EdbCode),
- // IndexName: fmt.Sprintf("自有数据-%d-%s", index, edb.EdbName),
- // Unit: edb.Unit,
- // Frequency: edb.Frequency,
- // SourceName: edb.SourceName,
- // Remark: "",
- // DataList: nil,
- // }
- //
- // // 获取指标数据
- // tmpDataList := make([]data_manage.AddBusinessDataReq, 0)
- // dataList, e := dataOb.GetItemsBySourceAndCode(edb.Source, edb.SubSource, edb.EdbCode, "", []string{}, "")
- // if e != nil {
- // fmt.Println(edb.EdbCode + ";EdbData GetItemsBySourceAndCode err: " + e.Error())
- // continue
- // }
- // for _, v := range dataList {
- // tmpDataList = append(tmpDataList, data_manage.AddBusinessDataReq{
- // Value: v.Value,
- // Date: v.DataTime.Format(utils.FormatDate),
- // })
- // }
- // req.DataList = tmpDataList
- // reqJson, _ := json.Marshal(req)
- //
- // respItem, err := data.PushEdb(string(reqJson))
- // if err != nil {
- // fmt.Println(edb.EdbCode + "处理失败,Err:" + err.Error())
- // continue
- // }
- // if respItem.Ret != 200 {
- // fmt.Println(edb.EdbCode + "处理失败,Err:" + respItem.ErrMsg)
- // }
- // }
- //
- // fmt.Println("end")
- //}
|