123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203 |
- package data_manage
- import (
- "github.com/beego/beego/v2/client/orm"
- "github.com/rdlucklib/rdluck_tools/paging"
- )
- type BaiinfoClassify struct {
- TypeName string `orm:"column(type_name)" description:"分类名称"`
- TypeCode string `orm:"column(type_code)" description:"分类名称编码"`
- }
- func GetBaiinfoClassify() (items []*BaiinfoClassify, err error) {
- sql := `SELECT CONCAT(type_2,type_3) AS type_name,CONCAT(type_2,'#',type_3) type_code FROM base_from_baiinfo_index GROUP BY CONCAT(type_2,type_3) ORDER BY CONCAT(type_2,type_3) ASC `
- o := orm.NewOrmUsingDB("data")
- o.Raw(sql).QueryRows(&items)
- return
- }
- type BaiinfoFrequency struct {
- Frequency string `description:"频度"`
- }
- func GetBaiinfoFrequencyByClassifyId(classifyId int) (items []*GlFrequency, err error) {
- o := orm.NewOrmUsingDB("data")
- sql := ` SELECT frequency FROM base_from_baiinfo_index WHERE classify_id = ? `
- sql += ` GROUP BY frequency ORDER BY frequency ASC `
- _, err = o.Raw(sql, classifyId).QueryRows(&items)
- return
- }
- type BaiinfoIndex struct {
- BaseFromBaiinfoIndexId int `orm:"column(base_from_baiinfo_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 GetBaiinfoIndex(condition string, pars interface{}) (items []*BaiinfoIndex, err error) {
- o := orm.NewOrmUsingDB("data")
- sql := ` SELECT * FROM base_from_baiinfo_index WHERE 1=1 `
- if condition != "" {
- sql += condition
- }
- sql += `ORDER BY sort ASC, base_from_baiinfo_index_id asc`
- _, err = o.Raw(sql, pars).QueryRows(&items)
- return
- }
- type BaiinfoExportIndex struct {
- TypeName 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
- ModifyTime string
- }
- func GetExportBaiinfoIndex(typeCodes string) (items []*BaiinfoExportIndex, err error) {
- o := orm.NewOrmUsingDB("data")
- sql := ` SELECT *,CONCAT(type_2, "#", type_3) AS type_name FROM base_from_baiinfo_index WHERE CONCAT(type_2, "#", type_3) IN (` + typeCodes + `) ORDER BY frequency ASC,index_code ASC`
- _, err = o.Raw(sql).QueryRows(&items)
- return
- }
- func GetBaiinfoFrequency(classifyId int ) (items []*string,err error){
- sql := `SELECT DISTINCT frequency FROM base_from_baiinfo_index WHERE classify_id=? ORDER BY FIELD(frequency,'日度','周度','月度','季度','半年','年度') `
- o := orm.NewOrmUsingDB("data")
- _, err = o.Raw(sql, classifyId).QueryRows(&items)
- return
- }
- func GetBaiinfoFrequencyByCode(code string) (items []*string, err error) {
- sql := `SELECT DISTINCT frequency FROM base_from_baiinfo_index WHERE index_code=? ORDER BY FIELD(frequency,'日度','周度','月度','季度','半年','年度') `
- o := orm.NewOrmUsingDB("data")
- _, err = o.Raw(sql, code).QueryRows(&items)
- return
- }
- type BaiinfoIndexList struct {
- BaseFromBaiinfoIndexId int `orm:"column(base_from_baiinfo_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 []*BaiinfoIndexData
- Paging *paging.PagingItem `description:"分页数据"`
- }
- type BaiinfoIndexData struct {
- Value string `orm:"column(value)" description:"日期"`
- DataTime string `orm:"column(data_time)" description:"值"`
- }
- func GetBaiinfoIndexData(indexCode string, startSize, pageSize int) (items []*BaiinfoIndexData, err error) {
- o := orm.NewOrmUsingDB("data")
- sql := ` SELECT * FROM base_from_baiinfo_data WHERE index_code=? ORDER BY data_time DESC LIMIT ?,? `
- _, err = o.Raw(sql, indexCode, startSize, pageSize).QueryRows(&items)
- return
- }
- func GetBaiinfoIndexDataCount(indexCode string) (count int, err error) {
- o := orm.NewOrmUsingDB("data")
- sql := ` SELECT COUNT(1) AS count FROM base_from_baiinfo_data WHERE index_code=? `
- err = o.Raw(sql, indexCode).QueryRow(&count)
- return
- }
- // GetBaiinfoItemList 模糊查询Baiinfo数据库指标列表
- func GetBaiinfoItemList(keyword string) (items []*BaiinfoIndex, err error) {
- o := orm.NewOrmUsingDB("data")
- sql := "SELECT * FROM base_from_baiinfo_index WHERE CONCAT(index_name,index_code) LIKE '%" + keyword + "%'"
- _, err = o.Raw(sql).QueryRows(&items)
- return
- }
- func GetBaiinfoIndexDataByCode(indexCode string) (items []*BaiinfoIndexData, err error) {
- o := orm.NewOrmUsingDB("data")
- sql := ` SELECT * FROM base_from_baiinfo_data WHERE index_code=? ORDER BY data_time DESC `
- _, err = o.Raw(sql, indexCode).QueryRows(&items)
- return
- }
- func GetBaiinfoDataMaxCount(classifyId int) (count int, err error) {
- o := orm.NewOrmUsingDB("data")
- sql := `SELECT MAX(t.num) AS count FROM (
- SELECT COUNT(1) AS num FROM base_from_baiinfo_index AS a
- INNER JOIN base_from_baiinfo_data AS b ON a.index_code=b.index_code
- WHERE a.classify_id=?
- GROUP BY a.base_from_baiinfo_index_id
- )AS t `
- err = o.Raw(sql, classifyId).QueryRow(&count)
- return
- }
- type ExportBaiinfoDataMaxCount struct {
- TypeName string
- Count int
- }
- func GetExportBaiinfoDataMaxCount(typeCodes string) (items []*ExportBaiinfoDataMaxCount, err error) {
- o := orm.NewOrmUsingDB("data")
- sql := ` SELECT
- MAX(t.num) AS count,
- t.type_name
- FROM
- (
- SELECT
- COUNT(1) AS num,
- CONCAT(a.type_2, "#", a.type_3) AS type_name
- FROM
- base_from_baiinfo_index AS a
- INNER JOIN base_from_baiinfo_data AS b ON a.index_code = b.index_code
- WHERE
- CONCAT(a.type_2, "#", a.type_3) IN (` + typeCodes + `)
- GROUP BY
- a.base_from_baiinfo_index_id
- ) AS t
- GROUP BY
- type_name `
- _, err = o.Raw(sql).QueryRows(&items)
- return
- }
- type ExportBaiinfoIndexData struct {
- Value string `orm:"column(value)" description:"日期"`
- DataTime string `orm:"column(data_time)" description:"值"`
- IndexCode string `orm:"column(index_code)" description:"指标编码"`
- }
- func GetExportBaiinfoIndexDataByCodes(indexCodes string) (items []*ExportBaiinfoIndexData, err error) {
- o := orm.NewOrmUsingDB("data")
- sql := ` SELECT index_code,data_time,value FROM base_from_baiinfo_data WHERE index_code IN (` + indexCodes + `) ORDER BY data_time DESC `
- _, err = o.Raw(sql).QueryRows(&items)
- return
- }
|