multiple_graph_config_edb_mapping.go 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. package data_manage
  2. import (
  3. "eta/eta_api/utils"
  4. "github.com/beego/beego/v2/client/orm"
  5. "time"
  6. )
  7. // MultipleGraphConfigEdbMapping 指标与多图配置的关系表
  8. type MultipleGraphConfigEdbMapping struct {
  9. Id int `orm:"column(id);pk"`
  10. MultipleGraphConfigId int `description:"多图配置id"`
  11. EdbInfoId int `description:"指标id"`
  12. Source int `description:"来源,1:曲线图,2:相关性图;3:滚动相关性图1;4:滚动相关性图2;10:区间计算指标"`
  13. ModifyTime time.Time `description:"最近一次修改时间"`
  14. CreateTime time.Time `description:"添加时间"`
  15. }
  16. // AddMultipleGraphConfigEdbMapping 新增多图配置
  17. func AddMultipleGraphConfigEdbMapping(item *MultipleGraphConfigEdbMapping) (err error) {
  18. o := orm.NewOrmUsingDB("data")
  19. // 表格信息入库
  20. lastId, err := o.Insert(item)
  21. if err != nil {
  22. return
  23. }
  24. item.Id = int(lastId)
  25. return
  26. }
  27. // Update 更新 基础信息
  28. func (item *MultipleGraphConfigEdbMapping) Update(cols []string) (err error) {
  29. o := orm.NewOrmUsingDB("data")
  30. _, err = o.Update(item, cols...)
  31. return
  32. }
  33. // GetMultipleGraphConfigEdbMappingByIdAndSource 根据配置id和来源获取关联关系
  34. func GetMultipleGraphConfigEdbMappingByIdAndSource(configId, source int) (item *MultipleGraphConfigEdbMapping, err error) {
  35. o := orm.NewOrmUsingDB("data")
  36. sql := `SELECT * FROM multiple_graph_config_edb_mapping WHERE multiple_graph_config_id = ? AND source = ? `
  37. err = o.Raw(sql, configId, source).QueryRow(&item)
  38. return
  39. }
  40. // GetMultipleGraphConfigEdbMappingListById 根据配置id获取所有关联关系
  41. func GetMultipleGraphConfigEdbMappingListById(configId int) (items []*MultipleGraphConfigEdbMapping, err error) {
  42. o := orm.NewOrmUsingDB("data")
  43. sql := `SELECT * FROM multiple_graph_config_edb_mapping WHERE multiple_graph_config_id = ? `
  44. _, err = o.Raw(sql, configId).QueryRows(&items)
  45. return
  46. }
  47. func GetMultipleGraphConfigEdbMappingListByIdAndSource(configId, source int) (items []*MultipleGraphConfigEdbMapping, err error) {
  48. o := orm.NewOrmUsingDB("data")
  49. sql := `SELECT * FROM multiple_graph_config_edb_mapping WHERE multiple_graph_config_id = ? AND source = ? `
  50. _, err = o.Raw(sql, configId, source).QueryRows(&items)
  51. return
  52. }
  53. // AddMultipleGraphConfigEdbMappingList 新增多图配置
  54. func AddMultipleGraphConfigEdbMappingList(items []*MultipleGraphConfigEdbMapping) (err error) {
  55. o := orm.NewOrmUsingDB("data")
  56. _, err = o.InsertMulti(len(items), items)
  57. return
  58. }
  59. func DeleteMultipleGraphConfigEdbMappingByEdbIds(configId, source int, edbIds []int) (err error) {
  60. o := orm.NewOrmUsingDB("data")
  61. sql := `DELETE FROM multiple_graph_config_edb_mapping WHERE multiple_graph_config_id = ? AND source = ? AND edb_info_id IN (` + utils.GetOrmInReplace(len(edbIds)) + `) `
  62. _, err = o.Raw(sql, configId, source, edbIds).Exec()
  63. return
  64. }
  65. func DeleteMultipleGraphConfigByChartInfoId(chartInfoId, configId, source int) (err error) {
  66. o := orm.NewOrmUsingDB("data")
  67. to, err := o.Begin()
  68. if err != nil {
  69. return
  70. }
  71. defer func() {
  72. if err != nil {
  73. _ = to.Rollback()
  74. } else {
  75. _ = to.Commit()
  76. }
  77. }()
  78. sql := ` DELETE FROM multiple_graph_config WHERE multiple_graph_config_id = ?`
  79. _, err = to.Raw(sql, configId).Exec()
  80. if err != nil {
  81. return
  82. }
  83. sql = ` DELETE FROM multiple_graph_config_chart_mapping WHERE chart_info_id=? and multiple_graph_config_id = ? and source=?`
  84. _, err = to.Raw(sql, chartInfoId, configId, source).Exec()
  85. if err != nil {
  86. return
  87. }
  88. sql = ` DELETE FROM multiple_graph_config_edb_mapping WHERE multiple_graph_config_id = ? and source=? `
  89. _, err = to.Raw(sql, configId, source).Exec()
  90. return
  91. }