edb_info_stat_column.go 2.7 KB

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