123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384 |
- package models
- import (
- "fmt"
- "github.com/beego/beego/v2/client/orm"
- "hongze/hongze_edb_lib/utils"
- "time"
- )
- //指标检索数据
- type EdbDataItem struct {
- EdbCode string `description:"指标编码"`
- StartDate string `description:"起始日期"`
- EndDate string `description:"终止日期"`
- EdbName string `description:"指标名称"`
- Unit string `description:"单位"`
- Frequency string `description:"频率"`
- DataList []*EdbData
- }
- type EdbData struct {
- EdbDataId int `orm:"column(edb_data_id);pk"`
- EdbInfoId int
- EdbCode string
- DataTime string
- Value string
- Status int
- CreateTime time.Time
- ModifyTime time.Time
- DataTimestamp int64
- }
- func GetEdbDataAllByEdbCode(edbCode string, source, limit int) (items []*EdbData, err error) {
- var pars []interface{}
- pars = append(pars, edbCode)
- o := orm.NewOrm()
- tableName := GetEdbDataTableName(source)
- sql := ` SELECT * FROM %s WHERE edb_code=? ORDER BY data_time DESC`
- if limit > 0 {
- sql += ` LIMIT ? `
- pars = append(pars, limit)
- }
- sql = fmt.Sprintf(sql, tableName)
- _, err = o.Raw(sql, pars).QueryRows(&items)
- return
- }
- func GetAddSql(edbInfoId, edbCode, dataTime, timestampStr string, value string) (addSql string) {
- nowStr := time.Now().Format(utils.FormatDateTime)
- addSql += "("
- addSql += edbInfoId + "," + "'" + edbCode + "'" + "," + "'" + dataTime + "'" + "," + value + "," + "'" + nowStr + "'" +
- "," + "'" + nowStr + "'" + "," + "1"
- addSql += "," + "'" + timestampStr + "'"
- addSql += "),"
- return
- }
- type EdbDataMaxAndMinInfo struct {
- MinDate string `description:"最小日期"`
- MaxDate string `description:"最大日期"`
- MinValue float64 `description:"最小值"`
- MaxValue float64 `description:"最大值"`
- LatestValue float64 `description:"最新值"`
- }
- func GetEdbDataMaxAndMinInfo(source int, edbCode string) (item *EdbDataMaxAndMinInfo, err error) {
- o := orm.NewOrm()
- sql := ``
- tableName := GetEdbDataTableName(source)
- 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 %s WHERE edb_code=? `
- sql = fmt.Sprintf(sql, tableName)
- err = o.Raw(sql, edbCode).QueryRow(&item)
- var latest_value float64
- sql = ` SELECT value AS latest_value FROM %s WHERE edb_code=? ORDER BY data_time DESC LIMIT 1 `
- sql = fmt.Sprintf(sql, tableName)
- err = o.Raw(sql, edbCode).QueryRow(&latest_value)
- item.LatestValue = latest_value
- return
- }
- type AddEdbInfoReq struct {
- EdbCode string `description:"指标编码"`
- }
|