package data_source import ( "eta_gn/eta_api/global" "github.com/rdlucklib/rdluck_tools/paging" "time" ) type BaseFromIcpiIndex struct { BaseFromIcpiIndexId int `gorm:"primaryKey;column:base_from_icpi_index_id;type:int(11);not null"` BaseFromIcpiClassifyId int `gorm:"column:base_from_icpi_classify_id;type:int(11);default:0"` // 分类 IndexCode string `gorm:"unique;column:index_code;type:varchar(100);default:''"` // 指标编码 IndexName string `gorm:"column:index_name;type:varchar(100);default:''"` // 指标名称 Frequency string `gorm:"column:frequency;type:varchar(20);default:''"` // 频度 Unit string `gorm:"column:unit;type:varchar(20);default:''"` // 单位 StartDate time.Time `gorm:"column:start_date;type:date"` // 开始日期 EndDate time.Time `gorm:"column:end_date;type:date"` // 结束日期 CreateTime time.Time `gorm:"column:create_time;type:datetime"` // 创建时间 ModifyTime time.Time `gorm:"column:modify_time;type:datetime"` // 修改时间 } type BaseFromIcpiData struct { BaseFromIcpiDataId int `gorm:"primaryKey;column:base_from_icpi_data_id;type:int(11);not null"` BaseFromIcpiIndexId int `gorm:"index:idx_base_from_icpi_index_id;column:base_from_icpi_index_id;type:int(11);default:0"` // 指标id IndexCode string `gorm:"uniqueIndex:idex_code_date;index:idx_index_code;column:index_code;type:varchar(100);default:''"` // 指标编码 DataTime string `gorm:"uniqueIndex:idex_code_date;column:data_time;type:date"` // 数据日期 Value float64 `gorm:"column:value;type:double"` // 数据值 CreateTime time.Time `gorm:"column:create_time;type:datetime"` // 创建时间 ModifyTime time.Time `gorm:"column:modify_time;type:datetime"` // 修改时间 } type BaseFromIcpiClassify struct { BaseFromIcpiClassifyId int `gorm:"primaryKey;column:base_from_icpi_classify_id;type:int(11);not null"` ClassifyName string `gorm:"column:classify_name;type:varchar(255);not null;default:''"` // 分类名称 ClassifyNameEn string `gorm:"column:classify_name_en;type:varchar(255);default:''"` // 英文名称 ParentId int `gorm:"column:parent_id;type:int(11) unsigned;default:0"` // 上级id ModifyTime string `gorm:"column:modify_time;type:datetime"` // 修改时间 CreateTime string `gorm:"column:create_time;type:datetime"` // 创建时间 } func (obj *BaseFromIcpiIndex) GetBaseFromIcpiClassifyAll() (list []*BaseFromIcpiClassify, err error) { sql := `SELECT * FROM base_from_icpi_classify ` err = global.DmSQL["data"].Raw(sql).Find(&list).Error return } type BaseFromIcpiDataView struct { BaseFromIcpiDataId int `gorm:"primaryKey;column:base_from_icpi_data_id;type:int(11);not null"` BaseFromIcpiIndexId int `gorm:"index:idx_base_from_icpi_index_id;column:base_from_icpi_index_id;type:int(11);default:0"` // 指标id IndexCode string `gorm:"uniqueIndex:idex_code_date;index:idx_index_code;column:index_code;type:varchar(100);default:''"` // 指标编码 DataTime string `gorm:"uniqueIndex:idex_code_date;column:data_time;type:date"` // 数据日期 Value string `gorm:"column:value;type:double"` // 数据值 CreateTime time.Time `gorm:"column:create_time;type:datetime"` // 创建时间 ModifyTime time.Time `gorm:"column:modify_time;type:datetime"` // 修改时间 } type BaseFromIcpiIndexView struct { BaseFromIcpiIndexId int `gorm:"primaryKey;column:base_from_icpi_index_id;type:int(11);not null"` BaseFromIcpiClassifyId int `gorm:"column:base_from_icpi_classify_id;type:int(11);default:0"` // 分类 IndexCode string `gorm:"unique;column:index_code;type:varchar(100);default:''"` // 指标编码 IndexName string `gorm:"column:index_name;type:varchar(100);default:''"` // 指标名称 Frequency string `gorm:"column:frequency;type:varchar(20);default:''"` // 频度 Unit string `gorm:"column:unit;type:varchar(20);default:''"` // 单位 StartDate string `gorm:"column:start_date;type:date"` // 开始日期 EndDate string `gorm:"column:end_date;type:date"` // 结束日期 CreateTime string `gorm:"column:create_time;type:datetime"` // 创建时间 ModifyTime string `gorm:"column:modify_time;type:datetime"` // 修改时间 DataList []*BaseFromIcpiDataView `gorm:"-"` Paging *paging.PagingItem `description:"分页数据" gorm:"-"` } func (obj *BaseFromIcpiIndex) GetIcpiIndex(condition string, pars []interface{}) (items []*BaseFromIcpiIndexView, err error) { sql := ` SELECT * FROM base_from_icpi_index WHERE 1=1 ` if condition != "" { sql += condition } sql += `ORDER BY base_from_icpi_index_id ASC ` err = global.DmSQL["data"].Raw(sql, pars...).Find(&items).Error return } func (obj *BaseFromIcpiIndex) GetIcpiIndexDataCount(indexCode string) (count int, err error) { sql := ` SELECT COUNT(1) AS count FROM base_from_icpi_data WHERE index_code=? ` err = global.DmSQL["data"].Raw(sql, indexCode).Scan(&count).Error return } func (obj *BaseFromIcpiIndex) GetIcpiIndexData(indexCode string, startSize, pageSize int) (items []*BaseFromIcpiDataView, err error) { sql := ` SELECT * FROM base_from_icpi_data WHERE index_code=? ORDER BY data_time DESC LIMIT ?,? ` err = global.DmSQL["data"].Raw(sql, indexCode, startSize, pageSize).Find(&items).Error return } func (obj *BaseFromIcpiIndex) GetIcpiDataMaxCount(classifyId int) (count int, err error) { sql := `SELECT MAX(t.num) AS count FROM ( SELECT COUNT(1) AS num FROM base_from_icpi_index AS a INNER JOIN base_from_icpi_data AS b ON a.base_from_icpi_index_id=b.base_from_icpi_index_id WHERE a.base_from_icpi_classify_id=? GROUP BY a.base_from_icpi_index_id )AS t ` err = global.DmSQL["data"].Raw(sql, classifyId).Scan(&count).Error return } func (obj *BaseFromIcpiIndex) GetIcpiIndexDataByCode(indexCode string) (items []*BaseFromIcpiDataView, err error) { sql := ` SELECT * FROM base_from_icpi_data WHERE index_code=? ORDER BY data_time DESC ` err = global.DmSQL["data"].Raw(sql, indexCode).Find(&items).Error return }