package data_manage import ( "eta/eta_api/utils" "github.com/beego/beego/v2/client/orm" "time" ) // MultipleGraphConfigEdbMapping 指标与多图配置的关系表 type MultipleGraphConfigEdbMapping struct { Id int `orm:"column(id);pk"` MultipleGraphConfigId int `description:"多图配置id"` EdbInfoId int `description:"指标id"` Source int `description:"来源,1:曲线图,2:相关性图;3:滚动相关性图1;4:滚动相关性图2;10:区间计算指标"` ModifyTime time.Time `description:"最近一次修改时间"` CreateTime time.Time `description:"添加时间"` } // AddMultipleGraphConfigEdbMapping 新增多图配置 func AddMultipleGraphConfigEdbMapping(item *MultipleGraphConfigEdbMapping) (err error) { o := orm.NewOrmUsingDB("data") // 表格信息入库 lastId, err := o.Insert(item) if err != nil { return } item.Id = int(lastId) return } // Update 更新 基础信息 func (item *MultipleGraphConfigEdbMapping) Update(cols []string) (err error) { o := orm.NewOrmUsingDB("data") _, err = o.Update(item, cols...) return } // GetMultipleGraphConfigEdbMappingByIdAndSource 根据配置id和来源获取关联关系 func GetMultipleGraphConfigEdbMappingByIdAndSource(configId, source int) (item *MultipleGraphConfigEdbMapping, err error) { o := orm.NewOrmUsingDB("data") sql := `SELECT * FROM multiple_graph_config_edb_mapping WHERE multiple_graph_config_id = ? AND source = ? ` err = o.Raw(sql, configId, source).QueryRow(&item) return } // GetMultipleGraphConfigEdbMappingListById 根据配置id获取所有关联关系 func GetMultipleGraphConfigEdbMappingListById(configId int) (items []*MultipleGraphConfigEdbMapping, err error) { o := orm.NewOrmUsingDB("data") sql := `SELECT * FROM multiple_graph_config_edb_mapping WHERE multiple_graph_config_id = ? ` _, err = o.Raw(sql, configId).QueryRows(&items) return } func GetMultipleGraphConfigEdbMappingListByIdAndSource(configId, source int) (items []*MultipleGraphConfigEdbMapping, err error) { o := orm.NewOrmUsingDB("data") sql := `SELECT * FROM multiple_graph_config_edb_mapping WHERE multiple_graph_config_id = ? AND source = ? ` _, err = o.Raw(sql, configId, source).QueryRows(&items) return } // AddMultipleGraphConfigEdbMappingList 新增多图配置 func AddMultipleGraphConfigEdbMappingList(items []*MultipleGraphConfigEdbMapping) (err error) { o := orm.NewOrmUsingDB("data") _, err = o.InsertMulti(len(items), items) return } func DeleteMultipleGraphConfigEdbMappingByEdbIds(configId, source int, edbIds []int) (err error) { o := orm.NewOrmUsingDB("data") sql := `DELETE FROM multiple_graph_config_edb_mapping WHERE multiple_graph_config_id = ? AND source = ? AND edb_info_id IN (` + utils.GetOrmInReplace(len(edbIds)) + `) ` _, err = o.Raw(sql, configId, source, edbIds).Exec() return } func DeleteMultipleGraphConfigByChartInfoId(chartInfoId, configId, source int) (err error) { o := orm.NewOrmUsingDB("data") to, err := o.Begin() if err != nil { return } defer func() { if err != nil { _ = to.Rollback() } else { _ = to.Commit() } }() sql := ` DELETE FROM multiple_graph_config WHERE multiple_graph_config_id = ?` _, err = to.Raw(sql, configId).Exec() if err != nil { return } sql = ` DELETE FROM multiple_graph_config_chart_mapping WHERE chart_info_id=? and multiple_graph_config_id = ? and source=?` _, err = to.Raw(sql, chartInfoId, configId, source).Exec() if err != nil { return } sql = ` DELETE FROM multiple_graph_config_edb_mapping WHERE multiple_graph_config_id = ? and source=? ` _, err = to.Raw(sql, configId, source).Exec() return }