123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112 |
- package data_manage
- import (
- "github.com/rdlucklib/rdluck_tools/orm"
- "github.com/rdlucklib/rdluck_tools/paging"
- )
- type GlClassify struct {
- BreedShortName string `orm:"column(BREED_SHORT_NAME)" description:"分类名称"`
- }
- func GetGlSurveyClassify() (items []*GlClassify, err error) {
- sql := ` SELECT CASE WHEN BREED_SHORT_NAME IS NULL THEN '无' ELSE BREED_SHORT_NAME END BREED_SHORT_NAME FROM mb_index_main_info GROUP BY BREED_SHORT_NAME ORDER BY BREED_SHORT_NAME ASC `
- o := orm.NewOrm()
- o.Using("gl")
- o.Raw(sql).QueryRows(&items)
- return
- }
- type GlFrequency struct {
- Frequency string `description:"频度:1-日度 2-周度 3-月度 4-季度 5-年度 99-无固定频率"`
- }
- func GetGlFrequencyByClassifyId(breedShortName string) (items []*GlFrequency, err error) {
- o := orm.NewOrm()
- o.Using("gl")
- if breedShortName == "无" {
- sql := ` SELECT FREQUENCY_NAME AS frequency FROM mb_index_main_info WHERE BREED_SHORT_NAME IS NULL GROUP BY FREQUENCY_CODE ORDER BY FREQUENCY_CODE ASC `
- _, err = o.Raw(sql).QueryRows(&items)
- return
- } else {
- sql := ` SELECT FREQUENCY_NAME AS frequency FROM mb_index_main_info WHERE BREED_SHORT_NAME=? GROUP BY FREQUENCY_CODE ORDER BY FREQUENCY_CODE ASC `
- _, err = o.Raw(sql, breedShortName).QueryRows(&items)
- return
- }
- }
- type GlIndex struct {
- Id int `orm:"column(ID)"`
- IndexCode string `orm:"column(INDEX_CODE)"`
- IndexName string `orm:"column(INDEX_NAME)"`
- UnitName string `orm:"column(UNIT_NAME)"`
- FrequencyName string `orm:"column(FREQUENCY_NAME)"`
- UpdateTime string `orm:"column(UPDATE_TIME)"`
- }
- func GetGlIndex(breedShortName, frequency string) (items []*GlIndex, err error) {
- o := orm.NewOrm()
- o.Using("gl")
- if breedShortName == "无" {
- sql := ` SELECT * FROM mb_index_main_info WHERE BREED_SHORT_NAME IS NULL AND FREQUENCY_NAME=? ORDER BY INDEX_CODE ASC `
- _, err = o.Raw(sql, frequency).QueryRows(&items)
- return
- } else {
- sql := ` SELECT * FROM mb_index_main_info WHERE BREED_SHORT_NAME=? AND FREQUENCY_NAME=? ORDER BY INDEX_CODE ASC `
- _, err = o.Raw(sql, breedShortName, frequency).QueryRows(&items)
- return
- }
- }
- type GlIndexList struct {
- Id int `orm:"column(ID)"`
- IndexCode string `orm:"column(INDEX_CODE)"`
- IndexName string `orm:"column(INDEX_NAME)"`
- UnitName string `orm:"column(UNIT_NAME)"`
- FrequencyName string `orm:"column(FREQUENCY_NAME)"`
- UpdateTime string `orm:"column(UPDATE_TIME)"`
- Paging *paging.PagingItem `description:"分页数据"`
- DataList []*GlIndexData
- }
- type GlIndexData struct {
- InputValue string `orm:"column(DATA_VALUE)" description:"日期"`
- DataTime string `orm:"column(DATA_DATE)" description:"值"`
- }
- func GetGlIndexData(indexCode string, startSize, pageSize int) (items []*GlIndexData, err error) {
- //sql := ` SELECT * FROM mb_index_main_data WHERE INDEX_CODE=? ORDER BY DATA_DATE DESC,PUBLISH_TIME DESC LIMIT ?,?`
- sql := ` SELECT * FROM (
- SELECT DISTINCT a.INDEX_CODE,a.DATA_VALUE,a.DATA_DATE FROM mb_index_main_data AS a WHERE INDEX_CODE=?
- ORDER BY DATA_DATE DESC,PUBLISH_TIME DESC
- )AS t
- GROUP BY t.DATA_DATE
- ORDER BY t.DATA_DATE DESC LIMIT ?,? `
- o := orm.NewOrm()
- o.Using("gl")
- _, err = o.Raw(sql, indexCode, startSize, pageSize).QueryRows(&items)
- return
- }
- func GetGlIndexByCode(indexCode string) (items *GlIndex, err error) {
- sql := ` SELECT * FROM mb_index_main_info WHERE INDEX_CODE=? `
- o := orm.NewOrm()
- o.Using("gl")
- err = o.Raw(sql, indexCode).QueryRow(&items)
- return
- }
- func GetGlIndexDataCount(indexCode string) (count int, err error) {
- o := orm.NewOrm()
- o.Using("gl")
- sql := `SELECT COUNT(1) AS count FROM (
- SELECT * FROM (
- SELECT DISTINCT a.INDEX_CODE,a.DATA_VALUE,a.DATA_DATE FROM mb_index_main_data AS a WHERE INDEX_CODE=?
- ORDER BY DATA_DATE DESC,PUBLISH_TIME DESC
- )AS t
- GROUP BY t.DATA_DATE
- ORDER BY t.DATA_DATE DESC
- )AS n `
- err = o.Raw(sql, indexCode).QueryRow(&count)
- return
- }
|