package data_manage import ( "eta_gn/eta_chart_lib/global" "eta_gn/eta_chart_lib/services/alarm_msg" "eta_gn/eta_chart_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:"添加时间"` // } type PredictEdbConf struct { ConfigId int `gorm:"column:config_id;primaryKey" description:"规则id" orm:"column(config_id);pk"` PredictEdbInfoId int `gorm:"column:predict_edb_info_id" description:"预测指标id"` SourceEdbInfoId int `gorm:"column:source_edb_info_id" description:"来源指标id"` RuleType int `gorm:"column:rule_type" description:"预测规则,1:最新,2:固定值,3:同比,4:同差,5:环比,6:环差,7:N期移动均值,8:N期段线性外推值"` FixedValue float64 `gorm:"column:fixed_value" description:"固定值"` Value string `gorm:"column:value" description:"配置的值"` EndDate time.Time `gorm:"column:end_date" description:"截止日期"` ModifyTime time.Time `gorm:"column:modify_time" description:"修改时间"` CreateTime time.Time `gorm:"column:create_time" description:"添加时间"` } func (p *PredictEdbConf) TableName() string { return "predict_edb_conf" } // GetPredictEdbConfById 根据预测指标id获取预测指标配置信息 func GetPredictEdbConfById(edbInfoId int) (item *PredictEdbConf, err error) { o := global.DmSQL["data"] sql := ` SELECT * FROM predict_edb_conf WHERE predict_edb_info_id=? ` err = o.Raw(sql, edbInfoId).First(&item).Error return } // GetPredictEdbConfBySourceEdbInfoId 根据来源指标id获取配置 func GetPredictEdbConfBySourceEdbInfoId(sourceEdbInfoId int) (item *PredictEdbConf, err error) { o := global.DmSQL["data"] sql := ` SELECT * FROM predict_edb_conf WHERE source_edb_info_id=? ` err = o.Raw(sql, sourceEdbInfoId).First(&item).Error return } // GetPredictEdbConfCount 根据来源指标id获取被引用的次数 func GetPredictEdbConfCount(sourceEdbInfoId int) (count int, err error) { o := global.DmSQL["data"] sql := ` SELECT COUNT(1) AS count FROM predict_edb_conf WHERE source_edb_info_id=? ` err = o.Raw(sql, sourceEdbInfoId).Scan(&count).Error return } // AddPredictEdbConf 添加预测指标规则 func AddPredictEdbConf(item *PredictEdbConf) (lastId int64, err error) { o := global.DmSQL["data"] err = o.Create(item).Error return } // AddPredictEdb 添加预测指标 func AddPredictEdb(item *EdbInfo, predictEdbConf *PredictEdbConf) (err error) { o := global.DmSQL["data"] tx := o.Begin() defer func() { if err != nil { tmpErr := tx.Rollback().Error if tmpErr != nil { go alarm_msg.SendAlarmMsg("AddPredictEdb 事务回滚失败,Err:"+tmpErr.Error(), 3) } } else { _ = tx.Commit() } }() // 新增预测指标 err = o.Create(item).Error if err != nil { return } // 新增预测指标配置 predictEdbConf.PredictEdbInfoId = item.EdbInfoId err = o.Create(predictEdbConf).Error if err != nil { return } return } // EditPredictEdb 修改预测指标 func EditPredictEdb(edbInfo *EdbInfo, predictEdbConf *PredictEdbConf, updateEdbInfoCol, updatePredictEdbConfCol []string) (err error) { o := global.DmSQL["data"] tx := o.Begin() defer func() { if err != nil { tmpErr := tx.Rollback().Error if tmpErr != nil { go alarm_msg.SendAlarmMsg("AddPredictEdb 事务回滚失败,Err:"+tmpErr.Error(), 3) } } else { _ = tx.Commit() } }() // 修改预测指标 err = o.Model(edbInfo).Select(updateEdbInfoCol).Updates(edbInfo).Error if err != nil { return } // 修改预测指标配置 err = o.Model(predictEdbConf).Select(updatePredictEdbConfCol).Updates(predictEdbConf).Error if err != nil { return } return } // GetPredictEdbInfoAllCalculate 根据基础预测指标id集合 获取 所有的普通指标列表数据 func GetPredictEdbInfoAllCalculate(edbInfoIdList []int) (list []*EdbInfo, err error) { num := len(edbInfoIdList) if num <= 0 { return } o := global.DmSQL["data"] sql := ` SELECT b.* FROM predict_edb_conf AS a INNER JOIN edb_info AS b ON a.source_edb_info_id=b.edb_info_id WHERE a.predict_edb_info_id in (` + utils.GetGormInReplace(num) + `) GROUP BY a.source_edb_info_id ORDER BY a.source_edb_info_id ASC ` err = o.Raw(sql, edbInfoIdList).Scan(&list).Error return } // GetPredictEdbConfListById 根据预测指标id获取预测指标配置信息列表 func GetPredictEdbConfListById(edbInfoId int) (items []*PredictEdbConf, err error) { o := global.DmSQL["data"] sql := ` SELECT * FROM predict_edb_conf WHERE predict_edb_info_id=? ORDER BY config_id ASC` err = o.Raw(sql, edbInfoId).Scan(&items).Error return } // 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 // } // // GetPredictEdbInfoAllCalculate 根据基础预测指标id集合 获取 所有的普通指标列表数据 // func GetPredictEdbInfoAllCalculate(edbInfoIdList []int) (list []*EdbInfo, err error) { // num := len(edbInfoIdList) // if num <= 0 { // return // } // o := orm.NewOrmUsingDB("data") // sql := ` SELECT b.* FROM predict_edb_conf AS a // INNER JOIN edb_info AS b ON a.source_edb_info_id=b.edb_info_id // WHERE a.predict_edb_info_id in (` + utils.GetOrmInReplace(num) + `) // GROUP BY a.source_edb_info_id // ORDER BY a.source_edb_info_id ASC ` // _, err = o.Raw(sql, edbInfoIdList).QueryRows(&list) // 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 // }