package data_manage import ( "eta/eta_api/utils" "time" "github.com/beego/beego/v2/client/orm" ) type BaseFromSciHqData struct { SciHqDataId int `orm:"column(sci_hq_data_id);pk"` BaseFromSciHqIndexId int `description:"指标id"` IndexCode string `description:"指标编码"` DataTime string `description:"数据日期"` Value float64 `description:"数据值"` CreateTime time.Time `description:"创建时间"` ModifyTime time.Time `description:"修改时间"` DataTimestamp int64 `description:"数据时间戳"` } // GetSciHqDataByIndexId 根据指标id获取指标数据 func GetSciHqDataByIndexId(indexId int) (items []*BaseFromSciHqData, err error) { o := orm.NewOrmUsingDB("data") sql := ` SELECT * FROM base_from_sci_hq_data WHERE base_from_sci_hq_index_id=? ORDER BY data_time DESC` _, err = o.Raw(sql, indexId).QueryRows(&items) return } // GetSciHqDataDataTimeByIndexId 根据指标id获取指标数据的日期列表 func GetSciHqDataDataTimeByIndexId(indexIdList []int) (items []string, err error) { if len(indexIdList) == 0 { return } o := orm.NewOrmUsingDB("data") sql := ` SELECT DISTINCT data_time FROM base_from_sci_hq_data WHERE base_from_sci_hq_index_id IN (` + utils.GetOrmInReplace(len(indexIdList)) + `) ORDER BY data_time DESC` _, err = o.Raw(sql, indexIdList).QueryRows(&items) return } func GetSciHqIndexDataByCode(indexCode string) (items []*BaseFromSciHqData, err error) { o := orm.NewOrmUsingDB("data") sql := ` SELECT * FROM base_from_sci_hq_data WHERE index_code=? ORDER BY data_time DESC ` _, err = o.Raw(sql, indexCode).QueryRows(&items) return } func GetSciHqIndexDataCount(indexCode string) (count int, err error) { o := orm.NewOrmUsingDB("data") sql := ` SELECT COUNT(1) AS count FROM base_from_sci_hq_data WHERE index_code=? ` err = o.Raw(sql, indexCode).QueryRow(&count) return }