1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465 |
- package models
- import (
- "github.com/beego/beego/v2/client/orm"
- "hongze/hongze_edb_lib/utils"
- "time"
- )
- type PredictEdbConf struct {
- ConfigId int `orm:"column(config_id);pk" description:"规则id"`
- PredictEdbInfoId int `orm:"column(predict_edb_info_id)" description:"预测指标id"`
- SourceEdbInfoId int `description:"来源指标id"`
- RuleType int `description:"预测规则,1:最新,2:固定值,3:同比,4:同差,5:环比,6:环差,7:N期移动均值,8:N期段线性外推值"`
- FixedValue float64 `description:"固定值"`
- Value string `description:"配置的值"`
- EndDate time.Time `description:"截止日期"`
- ModifyTime time.Time `description:"修改时间"`
- CreateTime time.Time `description:"添加时间"`
- }
- // GetPredictEdbConfById 根据预测指标id获取预测指标配置信息
- func GetPredictEdbConfById(edbInfoId int) (item *PredictEdbConf, err error) {
- o := orm.NewOrm()
- sql := ` SELECT * FROM predict_edb_conf WHERE predict_edb_info_id=? `
- err = o.Raw(sql, edbInfoId).QueryRow(&item)
- return
- }
- // GetPredictEdbConfCount 根据来源指标id获取被引用的次数
- func GetPredictEdbConfCount(sourceEdbInfoId int) (count int, err error) {
- o := orm.NewOrm()
- sql := ` SELECT COUNT(1) AS count FROM predict_edb_conf WHERE source_edb_info_id=? `
- err = o.Raw(sql, sourceEdbInfoId).QueryRow(&count)
- return
- }
- // GetPredictEdbConfListById 根据预测指标id获取预测指标配置信息列表
- func GetPredictEdbConfListById(edbInfoId int) (items []*PredictEdbConf, err error) {
- o := orm.NewOrmUsingDB("data")
- sql := ` SELECT * FROM predict_edb_conf WHERE predict_edb_info_id=? ORDER BY config_id ASC`
- _, err = o.Raw(sql, edbInfoId).QueryRows(&items)
- return
- }
- // ModifyPredictEdbInfoMaxAndMinInfoBySourceEdbInfoId 根据来源指标修改预测指标的最新数据信息
- func ModifyPredictEdbInfoMaxAndMinInfoBySourceEdbInfoId(sourceEdbInfoId int, item *EdbInfoMaxAndMinInfo) (err error) {
- o := orm.NewOrm()
- var list []*PredictEdbConf
- sql := ` SELECT * FROM predict_edb_conf WHERE source_edb_info_id=? `
- total, err := o.Raw(sql, sourceEdbInfoId).QueryRows(&list)
- if err != nil {
- return
- }
- if total > 0 {
- idList := make([]int, 0)
- for _, v := range list {
- idList = append(idList, v.PredictEdbInfoId)
- }
- sql := ` UPDATE edb_info SET start_date=?,min_value=?,max_value=?,is_update=2,latest_date=?,latest_value=?,modify_time=NOW() WHERE edb_info_id in (` + utils.GetOrmInReplace(int(total)) + `) `
- _, err = o.Raw(sql, item.MinDate, item.MinValue, item.MaxValue, item.MaxDate, item.LatestValue, idList).Exec()
- }
- return
- }
|