package data_manage import ( "eta/eta_api/utils" "time" "github.com/beego/beego/v2/client/orm" "github.com/rdlucklib/rdluck_tools/paging" ) type BaseFromUsdaFasIndex struct { BaseFromUsdaFasIndexId int `orm:"column(base_from_usda_fas_index_id);pk"` ClassifyId int IndexCode string IndexName string Frequency string Unit string Sort int StartDate string `description:"开始日期"` EndDate string `description:"结束日期"` EndValue float64 CreateTime time.Time ModifyTime time.Time } type BaseFromUsdaFasIndexList struct { BaseFromUsdaFasIndexId int `orm:"column(base_from_usda_fas_index_id);pk"` ClassifyId int Interface string EdbInfoId int EdbUniqueCode string `description:"指标库唯一编码"` EdbClassifyId int `description:"指标库分类ID"` StartDate string EndDate string EndValue float64 IndexCode string IndexName string Frequency string Unit string Sort int CreateTime string ModifyTime string EdbExist int `description:"指标库是否已添加:0-否;1-是"` DataList []*BaseFromUsdaFasData Paging *paging.PagingItem `description:"分页数据"` } type BaseFromUsdaFasIndexSearchList struct { List []*BaseFromUsdaFasIndexList Paging *paging.PagingItem `description:"分页数据"` } type UsdaFasSingleDataResp struct { BaseFromUsdaFasIndexId int ClassifyId int EdbInfoId int IndexCode string IndexName string Frequency string Unit string StartTime string CreateTime string ModifyTime string EdbExist int `description:"指标库是否已添加:0-否;1-是"` Data []*UsdaFasSingleData } type UsdaFasSingleData struct { Value string `orm:"column(value)" description:"日期"` DataTime string `orm:"column(data_time)" description:"值"` } func GetUsdaFasIndexByClassifyId(classifyId int) (items []*BaseFromUsdaFasIndex, err error) { o := orm.NewOrmUsingDB("data") sql := ` SELECT base_from_usda_fas_index_id, classify_id, index_code, index_name FROM base_from_usda_fas_index WHERE classify_id=? ORDER BY sort ASC, base_from_usda_fas_index_id ASC ` _, err = o.Raw(sql, classifyId).QueryRows(&items) return } func GetUsdaFasIndex(condition string, pars interface{}) (items []*BaseFromUsdaFasIndexList, err error) { o := orm.NewOrmUsingDB("data") sql := ` SELECT * FROM base_from_usda_fas_index WHERE 1=1 ` if condition != "" { sql += condition } sql += ` ORDER BY sort ASC, base_from_usda_fas_index_id asc` _, err = o.Raw(sql, pars).QueryRows(&items) return } func GetUsdaFasIndexPage(condition string, pars interface{}, startSize, pageSize int) (items []*BaseFromUsdaFasIndexList, err error) { o := orm.NewOrmUsingDB("data") sql := ` SELECT * FROM base_from_usda_fas_index WHERE 1=1 ` if condition != "" { sql += condition } sql += ` ORDER BY sort ASC, base_from_usda_fas_index_id asc LIMIT ?,?` _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items) return } func GetUsdaFasIndexPageCount(condition string, pars interface{}) (count int, err error) { o := orm.NewOrmUsingDB("data") sql := ` SELECT COUNT(1) AS count FROM base_from_usda_fas_index WHERE 1=1 ` if condition != "" { sql += condition } err = o.Raw(sql, pars).QueryRow(&count) return } func GetUsdaFasIndexDataCount(indexCode string) (count int, err error) { o := orm.NewOrmUsingDB("data") sql := ` SELECT COUNT(1) AS count FROM base_from_usda_fas_data WHERE index_code=? ` err = o.Raw(sql, indexCode).QueryRow(&count) return } func GetUsdaFasIndexDataByDataTime(indexCodes []string, startDate, endDate string) (items []*BaseFromUsdaFasData, err error) { o := orm.NewOrmUsingDB("data") sql := ` SELECT * FROM base_from_usda_fas_data WHERE index_code in (` + utils.GetOrmInReplace(len(indexCodes)) + `) and data_time >=? and data_time