predict_edb_conf.go 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. package models
  2. import (
  3. "github.com/beego/beego/v2/client/orm"
  4. "hongze/hongze_edb_lib/utils"
  5. "time"
  6. )
  7. type PredictEdbConf struct {
  8. ConfigId int `orm:"column(config_id);pk" description:"规则id"`
  9. PredictEdbInfoId int `orm:"column(predict_edb_info_id)" description:"预测指标id"`
  10. SourceEdbInfoId int `description:"来源指标id"`
  11. RuleType int `description:"预测规则,1:最新,2:固定值,3:同比,4:同差,5:环比,6:环差,7:N期移动均值,8:N期段线性外推值"`
  12. FixedValue float64 `description:"固定值"`
  13. Value string `description:"配置的值"`
  14. EndDate time.Time `description:"截止日期"`
  15. ModifyTime time.Time `description:"修改时间"`
  16. CreateTime time.Time `description:"添加时间"`
  17. }
  18. // GetPredictEdbConfById 根据预测指标id获取预测指标配置信息
  19. func GetPredictEdbConfById(edbInfoId int) (item *PredictEdbConf, err error) {
  20. o := orm.NewOrm()
  21. sql := ` SELECT * FROM predict_edb_conf WHERE predict_edb_info_id=? `
  22. err = o.Raw(sql, edbInfoId).QueryRow(&item)
  23. return
  24. }
  25. // GetPredictEdbConfCount 根据来源指标id获取被引用的次数
  26. func GetPredictEdbConfCount(sourceEdbInfoId int) (count int, err error) {
  27. o := orm.NewOrm()
  28. sql := ` SELECT COUNT(1) AS count FROM predict_edb_conf WHERE source_edb_info_id=? `
  29. err = o.Raw(sql, sourceEdbInfoId).QueryRow(&count)
  30. return
  31. }
  32. // GetPredictEdbConfListById 根据预测指标id获取预测指标配置信息列表
  33. func GetPredictEdbConfListById(edbInfoId int) (items []*PredictEdbConf, err error) {
  34. o := orm.NewOrm()
  35. sql := ` SELECT * FROM predict_edb_conf WHERE predict_edb_info_id=? ORDER BY config_id ASC`
  36. _, err = o.Raw(sql, edbInfoId).QueryRows(&items)
  37. return
  38. }
  39. // ModifyPredictEdbInfoMaxAndMinInfoBySourceEdbInfoId 根据来源指标修改预测指标的最新数据信息
  40. func ModifyPredictEdbInfoMaxAndMinInfoBySourceEdbInfoId(sourceEdbInfoId int, item *EdbInfoMaxAndMinInfo) (err error) {
  41. o := orm.NewOrm()
  42. var list []*PredictEdbConf
  43. sql := ` SELECT * FROM predict_edb_conf WHERE source_edb_info_id=? `
  44. total, err := o.Raw(sql, sourceEdbInfoId).QueryRows(&list)
  45. if err != nil {
  46. return
  47. }
  48. if total > 0 {
  49. idList := make([]int, 0)
  50. for _, v := range list {
  51. idList = append(idList, v.PredictEdbInfoId)
  52. }
  53. 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)) + `) `
  54. _, err = o.Raw(sql, item.MinDate, item.MinValue, item.MaxValue, item.MaxDate, item.LatestValue, idList).Exec()
  55. }
  56. return
  57. }