package data_manage import ( "github.com/rdlucklib/rdluck_tools/orm" "github.com/rdlucklib/rdluck_tools/paging" "strings" ) type SmmClassify struct { TypeName string `orm:"column(type_name)" description:"分类名称"` TypeCode string `orm:"column(type_code)" description:"分类名称编码"` } func GetSmmClassify() (items []*SmmClassify, err error) { sql := `SELECT CONCAT(type_2,type_3) AS type_name,CONCAT(type_2,'#',type_3) type_code FROM base_from_smm_index GROUP BY CONCAT(type_2,type_3) ORDER BY CONCAT(type_2,type_3) ASC ` o := orm.NewOrm() o.Using("data") o.Raw(sql).QueryRows(&items) return } type SmmFrequency struct { Frequency string `description:"频度"` } func GetSmmFrequencyByClassifyId(typeCode string) (items []*GlFrequency, err error) { o := orm.NewOrm() o.Using("data") var type2, type3 string if strings.Contains(typeCode, "#") { typeArr := strings.Split(typeCode, "#") type2 = typeArr[0] type3 = typeArr[1] } else { type2 = typeCode } var condition string var pars []interface{} if type2 != "" { condition += ` AND type_2=? ` pars = append(pars, type2) } if type3 != "" { condition += ` AND type_3=? ` pars = append(pars, type3) } sql := ` SELECT frequency FROM base_from_smm_index WHERE 1=1 ` if condition != "" { sql += condition } sql += ` GROUP BY frequency ORDER BY frequency ASC ` _, err = o.Raw(sql, pars).QueryRows(&items) return } type SmmIndex struct { BaseFromSmmIndexId int `orm:"column(base_from_smm_index_id);pk"` Interface string Name string IndexCode string IndexName string Type1 string `orm:"column(type_1)"` Type2 string `orm:"column(type_2)"` Type3 string `orm:"column(type_3)"` Frequency string Unit string ApiStartTime string ApiUpdateTime string StartTime string FinishTime string CreateTime string ModifyTime string } func GetSmmIndex(condition string, pars interface{}) (items []*SmmIndex, err error) { o := orm.NewOrm() o.Using("data") sql := ` SELECT * FROM base_from_smm_index WHERE 1=1 ` if condition != "" { sql += condition } sql += `ORDER BY INDEX_CODE ASC` _, err = o.Raw(sql, pars).QueryRows(&items) return } type SmmIndexList struct { BaseFromSmmIndexId int `orm:"column(base_from_smm_index_id);pk"` Interface string Name string IndexCode string IndexName string Type1 string `orm:"column(type_1)"` Type2 string `orm:"column(type_2)"` Type3 string `orm:"column(type_3)"` Frequency string Unit string ApiStartTime string ApiUpdateTime string StartTime string FinishTime string ModifyTime string DataList []*SmmIndexData Paging *paging.PagingItem `description:"分页数据"` } type SmmIndexData struct { Value string `orm:"column(value)" description:"日期"` DataTime string `orm:"column(data_time)" description:"值"` } func GetSmmIndexData(indexCode string, startSize, pageSize int) (items []*SmmIndexData, err error) { o := orm.NewOrm() o.Using("data") sql := ` SELECT * FROM base_from_smm_data WHERE index_code=? ORDER BY data_time DESC LIMIT ?,? ` _, err = o.Raw(sql, indexCode, startSize, pageSize).QueryRows(&items) return } func GetSmmIndexDataCount(indexCode string) (count int, err error) { o := orm.NewOrm() o.Using("data") sql := ` SELECT COUNT(1) AS count FROM base_from_smm_data WHERE index_code=? ` err = o.Raw(sql, indexCode).QueryRow(&count) return }