edb_info_stat_column.go 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. package data_stat
  2. import "github.com/beego/beego/v2/client/orm"
  3. // EdbInfoStatColumn 数据源统计表自定义列
  4. type EdbInfoStatColumn struct {
  5. Id int `orm:"column(id);pk" description:"自增id"`
  6. ColumnName string `description:"字段名称"`
  7. ColumnKey string `description:"字段"`
  8. CreateTime string `description:" 创建时间"`
  9. ModifyTime string `description:"修改时间"`
  10. Type int `description:"列表类型:1数据源明细表,2数据源统计表,3删除指标列表,4指标信息变更表"`
  11. Sort int `description:"列排序"`
  12. IsMust int `description:"是否必选列: 0非必选 1必须"`
  13. IsSort int `description:"是否是允许排序的列,0否,1是"`
  14. IsShow int `description:"是否展示:1展示,0不展示"`
  15. }
  16. type EdbInfoStatColumnListItem struct {
  17. Id int `description:"自增id"`
  18. ColumnName string `description:"字段名称"`
  19. ColumnKey string `description:"字段"`
  20. Type int `description:"列表类型:1数据源明细表,2数据源统计表,3删除指标列表,4指标信息变更表"`
  21. IsMust int `description:"是否必选列: 0非必选 1必须"`
  22. IsSort int `description:"是否是允许排序的列,0否,1是"`
  23. IsShow int `description:"是否展示:1展示,0不展示"`
  24. }
  25. type StatColumnList struct {
  26. List []*EdbInfoStatColumnListItem
  27. }
  28. type EditStatColumnReq struct {
  29. List []*EdbInfoStatColumnListReq
  30. }
  31. type EdbInfoStatColumnListReq struct {
  32. Id int `description:"自增id"`
  33. IsShow int `description:"是否展示:1展示,0不展示"`
  34. }
  35. // GetStatColumn 获取自定义列
  36. func GetStatColumn(columnType int) (list []EdbInfoStatColumn, err error) {
  37. o := orm.NewOrmUsingDB("data")
  38. sql := `SELECT * FROM edb_info_stat_column WHERE type=? ORDER BY sort asc, id asc `
  39. _, err = o.Raw(sql, columnType).QueryRows(&list)
  40. return
  41. }
  42. // GetAllStatColumn 获取所有自定义列
  43. func GetAllStatColumn() (list []EdbInfoStatColumn, err error) {
  44. o := orm.NewOrmUsingDB("data")
  45. sql := `SELECT * FROM edb_info_stat_column ORDER BY sort asc, id asc `
  46. _, err = o.Raw(sql).QueryRows(&list)
  47. return
  48. }
  49. // UpdateStatColumn 批量更新自定义列
  50. func UpdateStatColumn(list []*EdbInfoStatColumn) (err error) {
  51. o := orm.NewOrmUsingDB("data")
  52. p, err := o.Raw("UPDATE edb_info_stat_column SET is_show = ?, sort=? WHERE id = ?").Prepare()
  53. if err != nil {
  54. return
  55. }
  56. defer func() {
  57. _ = p.Close() // 别忘记关闭 statement
  58. }()
  59. for _, v := range list {
  60. _, err = p.Exec(v.IsShow, v.Sort, v.Id)
  61. if err != nil {
  62. return
  63. }
  64. }
  65. return
  66. }