package models import ( "github.com/beego/beego/v2/client/orm" "time" ) type BaseFromIcpiIndex struct { BaseFromIcpiIndexId int `orm:"column(base_from_icpi_index_id);pk"` BaseFromIcpiClassifyId int `description:"分类id"` IndexCode string `description:"指标编码"` IndexName string `description:"指标名称"` Frequency string `description:"频度"` Unit string `description:"单位"` StartDate time.Time `description:"开始日期"` EndDate time.Time `description:"结束日期"` CreateTime time.Time `description:"创建时间"` ModifyTime time.Time `description:"修改时间"` } type BaseFromIcpiData struct { BaseFromIcpiDataId int `orm:"column(base_from_icpi_data_id);pk"` BaseFromIcpiIndexId int `description:"指标id"` IndexCode string `description:"指标编码"` DataTime string `description:"日期"` Value string `description:"值"` CreateTime time.Time `description:"创建时间"` ModifyTime time.Time `description:"修改时间"` } type BaseFromIcpiClassify struct { BaseFromIcpiClassifyId int `orm:"column(base_from_icpi_classify_id);pk"` ClassifyName string `description:"分类名称"` ClassifyNameEn string `description:"英文名称"` ParentId int `description:"上级id"` CreateTime time.Time `description:"创建时间"` ModifyTime time.Time `description:"修改时间"` } func (obj *BaseFromIcpiIndex) GetBaseFromIcpiIndexAll() (list []*BaseFromIcpiIndex, err error) { o := orm.NewOrmUsingDB("data") sql := `SELECT * FROM base_from_icpi_index` _, err = o.Raw(sql).QueryRows(&list) return } func (m *BaseFromIcpiIndex) Add() (err error) { o := orm.NewOrmUsingDB("data") id, err := o.Insert(m) if err != nil { return } m.BaseFromIcpiIndexId = int(id) return } func (m *BaseFromIcpiIndex) AddClassify(classify *BaseFromIcpiClassify) (err error) { o := orm.NewOrmUsingDB("data") id, err := o.Insert(classify) if err != nil { return } m.BaseFromIcpiIndexId = int(id) return } func (obj *BaseFromIcpiIndex) GetBaseFromIcpiData(indexCode string, limit int) (list []*BaseFromIcpiData, err error) { o := orm.NewOrmUsingDB("data") sql := `SELECT * FROM base_from_icpi_data WHERE index_code=? ORDER BY data_time DESC LIMIT ?` _, err = o.Raw(sql, indexCode, limit).QueryRows(&list) return } func (m *BaseFromIcpiIndex) AddData(dataItem *BaseFromIcpiData) (err error) { o := orm.NewOrmUsingDB("data") _, err = o.Insert(dataItem) if err != nil { return } return } func (m *BaseFromIcpiIndex) ModifyData(indexCode, dataTime, value string) (err error) { o := orm.NewOrmUsingDB("data") sql := ` UPDATE base_from_icpi_data SET value=? WHERE index_code=? AND data_time=? ` _, err = o.Raw(sql, value, indexCode, dataTime).Exec() return } // EdbInfoMaxAndMinInfo 指标最新数据记录结构体 type IndexMaxAndMinInfo struct { MinDate string `description:"最小日期"` MaxDate string `description:"最大日期"` MinValue float64 `description:"最小值"` MaxValue float64 `description:"最大值"` LatestValue float64 `description:"最新值"` LatestDate string `description:"实际数据最新日期"` } // 获取指标的最新数据记录信息 func (m *BaseFromIcpiIndex) GetBaseFromIcpiIndexMaxAndMinInfo(indexCode string) (item *IndexMaxAndMinInfo, err error) { o := orm.NewOrmUsingDB("data") sql := ` SELECT MIN(data_time) AS min_date,MAX(data_time) AS max_date,MIN(value) AS min_value,MAX(value) AS max_value FROM base_from_icpi_data WHERE index_code=? ` err = o.Raw(sql, indexCode).QueryRow(&item) return } // 修改指标的最新数据信息 func (m *BaseFromIcpiIndex) ModifyEdbInfoMaxAndMinInfo(indexCode string, item *IndexMaxAndMinInfo) (err error) { o := orm.NewOrmUsingDB("data") sql := ` UPDATE base_from_icpi_index SET start_date=?,end_date=?,modify_time=NOW() WHERE index_code=? ` _, err = o.Raw(sql, item.MinDate, item.MaxDate, indexCode).Exec() return } type IcpiClassify struct { Id interface{} `json:"id"` Category string `json:"category"` Percentage interface{} `json:"percentage"` Categoryenglish string `json:"categoryenglish"` } func (obj *BaseFromIcpiIndex) GetBaseFromIcpiClassifyAll() (list []*BaseFromIcpiClassify, err error) { o := orm.NewOrmUsingDB("data") sql := `SELECT * FROM base_from_icpi_classify ` _, err = o.Raw(sql).QueryRows(&list) return }