123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110 |
- package data_manage
- import (
- "github.com/beego/beego/v2/client/orm"
- "hongze/hongze_chart_lib/services/alarm_msg"
- "time"
- )
- type PredictEdbConf struct {
- PredictEdbInfoId int `orm:"column(predict_edb_info_id);pk" description:"预测指标id"`
- SourceEdbInfoId int `description:"来源指标id"`
- RuleType int `description:"预测规则,1:最新,2:固定值"`
- FixedValue float64 `description:"固定值"`
- ModifyTime time.Time `description:"修改时间"`
- CreateTime time.Time `description:"添加时间"`
- }
- // GetPredictEdbConfById 根据预测指标id获取预测指标配置信息
- func GetPredictEdbConfById(edbInfoId int) (item *PredictEdbConf, err error) {
- o := orm.NewOrmUsingDB("data")
- sql := ` SELECT * FROM predict_edb_conf WHERE predict_edb_info_id=? `
- err = o.Raw(sql, edbInfoId).QueryRow(&item)
- return
- }
- // GetPredictEdbConfBySourceEdbInfoId 根据来源指标id获取配置
- func GetPredictEdbConfBySourceEdbInfoId(sourceEdbInfoId int) (item *PredictEdbConf, err error) {
- o := orm.NewOrmUsingDB("data")
- sql := ` SELECT * FROM predict_edb_conf WHERE source_edb_info_id=? `
- err = o.Raw(sql, sourceEdbInfoId).QueryRow(&item)
- return
- }
- // GetPredictEdbConfCount 根据来源指标id获取被引用的次数
- func GetPredictEdbConfCount(sourceEdbInfoId int) (count int, err error) {
- o := orm.NewOrmUsingDB("data")
- sql := ` SELECT COUNT(1) AS count FROM predict_edb_conf WHERE source_edb_info_id=? `
- err = o.Raw(sql, sourceEdbInfoId).QueryRow(&count)
- return
- }
- // AddPredictEdbConf 添加预测指标规则
- func AddPredictEdbConf(item *PredictEdbConf) (lastId int64, err error) {
- o := orm.NewOrmUsingDB("data")
- lastId, err = o.Insert(item)
- return
- }
- // AddPredictEdb 添加预测指标
- func AddPredictEdb(item *EdbInfo, predictEdbConf *PredictEdbConf) (err error) {
- o := orm.NewOrmUsingDB("data")
- tx, err := o.Begin()
- if err != nil {
- return
- }
- defer func() {
- if err != nil {
- tmpErr := tx.Rollback()
- if tmpErr != nil {
- go alarm_msg.SendAlarmMsg("AddPredictEdb 事务回滚失败,Err:"+tmpErr.Error(), 3)
- }
- } else {
- err = tx.Commit()
- }
- }()
- // 新增预测指标
- edbInfoId, err := o.Insert(item)
- if err != nil {
- return
- }
- item.EdbInfoId = int(edbInfoId)
- // 新增预测指标配置
- predictEdbConf.PredictEdbInfoId = item.EdbInfoId
- _, err = o.Insert(predictEdbConf)
- if err != nil {
- return
- }
- return
- }
- // EditPredictEdb 修改预测指标
- func EditPredictEdb(edbInfo *EdbInfo, predictEdbConf *PredictEdbConf, updateEdbInfoCol, updatePredictEdbConfCol []string) (err error) {
- o := orm.NewOrmUsingDB("data")
- tx, err := o.Begin()
- if err != nil {
- return
- }
- defer func() {
- if err != nil {
- tmpErr := tx.Rollback()
- if tmpErr != nil {
- go alarm_msg.SendAlarmMsg("AddPredictEdb 事务回滚失败,Err:"+tmpErr.Error(), 3)
- }
- } else {
- err = tx.Commit()
- }
- }()
- // 修改预测指标
- _, err = o.Update(edbInfo, updateEdbInfoCol...)
- if err != nil {
- return
- }
- // 修改预测指标配置
- _, err = o.Update(predictEdbConf, updatePredictEdbConfCol...)
- if err != nil {
- return
- }
- return
- }
|