package data_manage import ( "eta/eta_api/utils" "time" "github.com/beego/beego/v2/client/orm" "github.com/rdlucklib/rdluck_tools/paging" ) // BaseFromEiaSteoIndex EiaSteo指标 type BaseFromEiaSteoIndex struct { BaseFromEiaSteoIndexId int `orm:"column(base_from_eia_steo_index_id);pk"` BaseFromEiaSteoClassifyId int `description:"指标分类id"` IndexCode string `description:"指标编码"` IndexName string `description:"指标名称(中文名称)"` IndexNameOriginal string `description:"指标名称(原始名称)"` Frequency string `description:"频度"` Level int `description:"指标层级(原始层级)"` Unit string `description:"单位"` Super string `description:"我也不知道是个啥,反正先存起来,万一用到了呢"` Precision int `description:"精度,我也不知道会不会用到,反正先存起来,万一用到了呢"` LastHistorical string `description:"最近的历史记录,我也不知道会不会用到,反正先存起来,万一用到了呢"` Description string `description:"备注信息,我也不知道会不会用到,反正先存起来,万一用到了呢"` IsMappable int `description:"是否可映射,我也不知道会不会用到,反正先存起来,万一用到了呢"` StartDate time.Time `description:"开始日期"` EndDate time.Time `description:"结束日期"` ModifyTime time.Time `description:"最新更新时间"` CreateTime time.Time `description:"创建时间"` } // BaseFromEiaSteoIndexItem EiaSteo指标 type BaseFromEiaSteoIndexItem struct { BaseFromEiaSteoIndexId int `orm:"column(base_from_eia_steo_index_id);pk"` BaseFromEiaSteoClassifyId int `description:"指标分类id"` IndexCode string `description:"指标编码"` IndexName string `description:"指标名称"` EdbInfoId int `description:"eta指标库的id"` EdbUniqueCode string `description:"指标库唯一编码"` EdbClassifyId int `description:"指标库分类ID"` EdbExist int `description:"指标库是否已添加:0-否;1-是"` } // BaseFromEiaSteoClassify EiaSteo分类 type BaseFromEiaSteoClassify struct { BaseFromEiaSteoClassifyId int `orm:"column(base_from_eia_steo_classify_id);pk"` ClassifyName string `description:"分类名称(中文名称)"` ClassifyNameOriginal string `description:"分类名称(原始名称)"` ParentId int `description:"父级id"` Level int `description:"层级"` ModifyTime time.Time `description:"最新更新时间"` CreateTime time.Time `description:"创建时间"` } type BaseFromEiaSteoClassifyView struct { BaseFromEiaSteoClassifyId int `orm:"column(base_from_eia_steo_classify_id);pk"` ClassifyName string `description:"分类名称(中文名称)"` ClassifyNameOriginal string `description:"分类名称(原始名称)"` ParentId int `description:"父级id"` Level int `description:"层级"` Child []*BaseFromEiaSteoClassifyView `description:"子级分类列表"` } // BaseFromEiaSteoData EiaSteo数据表 type BaseFromEiaSteoData struct { BaseFromEiaSteoDataId int `orm:"column(base_from_eia_steo_data_id);pk"` BaseFromEiaSteoIndexId int `description:"指标id"` IndexCode string `description:"指标编码"` DataTime time.Time `description:"数据日期"` Value float64 `description:"数据值"` ModifyTime time.Time `description:"最新更新时间"` CreateTime time.Time `description:"创建时间"` } // BaseFromEiaSteoDataItem EiaSteo数据 type BaseFromEiaSteoDataItem struct { BaseFromEiaSteoDataId int `orm:"column(base_from_eia_steo_data_id);pk"` BaseFromEiaSteoIndexId int `description:"指标id"` IndexCode string `description:"指标编码"` DataTime string `description:"数据日期"` Value float64 `description:"数据值"` ModifyTime string `description:"最新更新时间"` CreateTime string `description:"创建时间"` } // GetEiaSteoClassifyList 获取分类列表 func GetEiaSteoClassifyList() (items []*BaseFromEiaSteoClassifyView, err error) { sql := ` SELECT * FROM base_from_eia_steo_classify ORDER BY base_from_eia_steo_classify_id ASC ` o := orm.NewOrmUsingDB("data") o.Raw(sql).QueryRows(&items) return } // GetEiaSteoClassifyById 根据分类id获取分类 func GetEiaSteoClassifyById(classifyId int) (item *BaseFromEiaSteoClassify, err error) { sql := ` SELECT * FROM base_from_eia_steo_classify WHERE base_from_eia_steo_classify_id=? ` o := orm.NewOrmUsingDB("data") err = o.Raw(sql, classifyId).QueryRow(&item) return } // GetChildEiaSteoClassifyById 获取子分类列表 func GetChildEiaSteoClassifyById(classifyId int) (items []*BaseFromEiaSteoClassify, err error) { sql := ` SELECT * FROM base_from_eia_steo_classify WHERE parent_id=? ` o := orm.NewOrmUsingDB("data") _, err = o.Raw(sql, classifyId).QueryRows(&items) return } type EiaSteoIndexListResp struct { BaseFromEiaSteoIndexId int `orm:"column(base_from_eia_steo_index_id);pk"` BaseFromEiaSteoClassifyId int `description:"指标分类id"` IndexCode string `description:"指标编码"` IndexName string `description:"指标名称(中文名称)"` EdbInfoId int `description:"指标库id"` Unit string `description:"单位"` Frequency string `description:"频度"` StartDate string `description:"开始日期"` EndDate string `description:"结束日期"` ModifyTime string `description:"最新更新时间"` CreateTime string `description:"创建时间"` Paging *paging.PagingItem `description:"分页数据"` DataList []*BaseFromEiaSteoDataItem } // GetEiaSteoIndexList 获取指标列表 func GetEiaSteoIndexList(condition string, pars []interface{}) (items []*BaseFromEiaSteoIndex, err error) { sql := ` SELECT * FROM base_from_eia_steo_index WHERE 1=1 ` sql += condition sql += ` ORDER BY base_from_eia_steo_index_id ASC ` o := orm.NewOrmUsingDB("data") _, err = o.Raw(sql, pars).QueryRows(&items) return } // GetEiaSteoIndexDataCount 获取指标数据总数 func GetEiaSteoIndexDataCount(indexCode string) (count int, err error) { o := orm.NewOrmUsingDB("data") sql := `SELECT COUNT(1) AS count FROM base_from_eia_steo_data where index_code = ? ` err = o.Raw(sql, indexCode).QueryRow(&count) return } // GetEiaSteoIndexDataList 获取指标数据总数列表 func GetEiaSteoIndexDataList(indexCode string, startSize, pageSize int) (items []*BaseFromEiaSteoDataItem, err error) { //sql := ` SELECT * FROM mb_index_main_data WHERE INDEX_CODE=? ORDER BY DATA_DATE DESC,PUBLISH_TIME DESC LIMIT ?,?` sql := ` SELECT * FROM base_from_eia_steo_data AS a WHERE index_code=? ORDER BY data_time DESC LIMIT ?,? ` o := orm.NewOrmUsingDB("data") _, err = o.Raw(sql, indexCode, startSize, pageSize).QueryRows(&items) return } // GetEiaSteoItemList 模糊查询EiaSteo数据库指标列表 func GetEiaSteoItemList(keyword string) (items []*BaseFromEiaSteoIndexItem, err error) { o := orm.NewOrmUsingDB("data") sql := "SELECT * FROM base_from_eia_steo_index WHERE index_name LIKE ? OR index_code like ?" _, err = o.Raw(sql, utils.GetLikeKeyword(keyword), utils.GetLikeKeyword(keyword)).QueryRows(&items) return } // GetEiaSteoDateList 根据指标code获取日期数据 func GetEiaSteoDateList(indexCodeList []string) (items []*BaseFromEiaSteoDataItem, err error) { num := len(indexCodeList) if num <= 0 { return } sql := ` SELECT data_time FROM base_from_eia_steo_data WHERE index_code IN(` + utils.GetOrmInReplace(num) + `) GROUP BY data_time ORDER BY data_time DESC ` o := orm.NewOrmUsingDB("data") _, err = o.Raw(sql, indexCodeList).QueryRows(&items) return } // GetBaseFromEiaSteoIndexByCode 根据指标code获取指标信息 func GetBaseFromEiaSteoIndexByCode(indexCode string) (item *BaseFromEiaSteoIndex, err error) { o := orm.NewOrmUsingDB("data") sql := `SELECT * FROM base_from_eia_steo_index WHERE index_code=? ` err = o.Raw(sql, indexCode).QueryRow(&item) return }