chart_theme.go 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. package models
  2. import (
  3. "errors"
  4. "github.com/beego/beego/v2/client/orm"
  5. "time"
  6. )
  7. // ChartTheme
  8. // @Description: 图表主题表
  9. type ChartTheme struct {
  10. ChartThemeId int `description:"图表主题类型ID" orm:"column(chart_theme_id);pk"`
  11. ChartThemeName string `description:"图表主题名称"`
  12. ChartThemeTypeId int `description:"图表主题类型ID"`
  13. ChartImage string `description:"缩略图"`
  14. Config string `description:"配置"`
  15. IsDelete int `description:"是否删除,0:未删除;1:已删除"`
  16. SysUserId int `description:"操作人"`
  17. SysUserRealName string `description:"操作人的真实名称"`
  18. IsSystemTheme int `description:"是否是系统主题,0:不是;1:是"`
  19. ModifyTime time.Time `description:"修改时间"`
  20. CreateTime time.Time `description:"创建时间"`
  21. }
  22. // GetChartThemeId
  23. // @Description: 根据id获取主题
  24. // @author: Roc
  25. // @datetime 2023-12-14 16:05:36
  26. // @param chartThemeId int
  27. // @return item *ChartTheme
  28. // @return err error
  29. func GetChartThemeId(chartThemeId int) (item *ChartTheme, err error) {
  30. o := orm.NewOrm()
  31. sql := `SELECT * FROM chart_theme where chart_theme_id = ? AND is_delete = 0`
  32. err = o.Raw(sql, chartThemeId).QueryRow(&item)
  33. return
  34. }
  35. // Add
  36. // @Description: 添加
  37. // @author: Roc
  38. // @receiver m
  39. // @datetime 2023-12-14 16:11:10
  40. // @param cols []string
  41. // @return err error
  42. func (m *ChartTheme) Add() (err error) {
  43. if m.ChartThemeId > 0 {
  44. err = errors.New("该配置已存在")
  45. return
  46. }
  47. o := orm.NewOrm()
  48. lastId, err := o.Insert(m)
  49. if err != nil {
  50. return
  51. }
  52. m.ChartThemeId = int(lastId)
  53. return
  54. }
  55. // Update
  56. // @Description: 更新
  57. // @author: Roc
  58. // @receiver m
  59. // @datetime 2023-12-14 16:11:10
  60. // @param cols []string
  61. // @return err error
  62. func (m *ChartTheme) Update(cols []string) (err error) {
  63. o := orm.NewOrm()
  64. _, err = o.Update(m, cols...)
  65. return
  66. }
  67. // GetChartThemeListByTypeId
  68. // @Description: 根据图表类型获取关联的图表主题列表
  69. // @author: Roc
  70. // @datetime 2023-12-13 17:39:48
  71. // @return list []*ChartTheme
  72. // @return err error
  73. func GetChartThemeListByTypeId(chartThemeTypeId int) (list []*ChartTheme, err error) {
  74. o := orm.NewOrm()
  75. sql := `SELECT * FROM chart_theme WHERE chart_theme_type_id = ? AND is_delete=0 ORDER BY chart_theme_id ASC `
  76. _, err = o.Raw(sql, chartThemeTypeId).QueryRows(&list)
  77. return
  78. }
  79. // GetAllChartThemeList
  80. // @Description: 获取所有图表主题列表
  81. // @author: Roc
  82. // @datetime 2023-12-13 17:39:48
  83. // @return list []*ChartTheme
  84. // @return err error
  85. func GetAllChartThemeList() (list []*ChartTheme, err error) {
  86. o := orm.NewOrm()
  87. sql := `SELECT * FROM chart_theme WHERE is_delete=0 ORDER BY chart_theme_id ASC `
  88. _, err = o.Raw(sql).QueryRows(&list)
  89. return
  90. }
  91. // ChartThemeItem
  92. // @Description: 图表主题配置
  93. type ChartThemeItem struct {
  94. ChartThemeId int `description:"图表主题类型ID" orm:"column(chart_theme_id);pk"`
  95. ChartThemeName string `description:"图表主题名称"`
  96. ChartThemeTypeId int `description:"图表主题类型ID"`
  97. Config string `description:"配置"`
  98. ChartImage string `description:"缩略图"`
  99. //IsDelete int `description:"是否删除,0:未删除;1:已删除"`
  100. IsSystemTheme int `description:"是否是系统主题,0:不是;1:是"`
  101. SysUserId int `description:"操作人"`
  102. SysUserRealName string `description:"操作人的真实名称"`
  103. ModifyTime time.Time `description:"修改时间"`
  104. CreateTime time.Time `description:"创建时间"`
  105. DefaultChartThemeId int `description:"默认使用的图表主题ID"`
  106. }
  107. // GetChartThemeItemList
  108. // @Description: 根据图表类型id获取配置列表
  109. // @author: Roc
  110. // @datetime 2023-12-14 14:26:35
  111. // @param chartThemeTypeId int
  112. // @return list []*ChartThemeConfig
  113. // @return err error
  114. func GetChartThemeItemList(chartThemeTypeId int) (list []*ChartThemeItem, err error) {
  115. o := orm.NewOrm()
  116. sql := `SELECT a.*,b.default_chart_theme_id FROM chart_theme a
  117. JOIN chart_theme_type b on a.chart_theme_type_id =b.chart_theme_type_id
  118. WHERE a.chart_theme_type_id = ? AND a.is_delete=0 ORDER BY a.chart_theme_id ASC `
  119. _, err = o.Raw(sql, chartThemeTypeId).QueryRows(&list)
  120. return
  121. }
  122. // GetSystemChartTheme
  123. // @Description: 根据图表类型id获取系统配置
  124. // @author: Roc
  125. // @datetime 2023-12-14 14:26:35
  126. // @param chartThemeTypeId int
  127. // @return item *ChartTheme
  128. // @return err error
  129. func GetSystemChartTheme(chartThemeTypeId int) (item *ChartTheme, err error) {
  130. o := orm.NewOrm()
  131. sql := `SELECT a.* FROM chart_theme a
  132. WHERE a.chart_theme_type_id = ? AND a.is_system_theme=1 ORDER BY a.chart_theme_id ASC `
  133. err = o.Raw(sql, chartThemeTypeId).QueryRow(&item)
  134. return
  135. }