chart_theme.go 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. package chart_theme
  2. import (
  3. "errors"
  4. "eta_gn/eta_api/global"
  5. "time"
  6. )
  7. // ChartTheme
  8. // @Description: 图表主题表
  9. type ChartTheme struct {
  10. ChartThemeId int `description:"图表主题类型ID" orm:"column(chart_theme_id);pk" gorm:"primaryKey" `
  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. sql := `SELECT * FROM chart_theme where chart_theme_id = ? AND is_delete = 0`
  31. err = global.DmSQL["data"].Raw(sql, chartThemeId).First(&item).Error
  32. return
  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. err = global.DmSQL["data"].Create(m).Error
  48. return
  49. }
  50. // Update
  51. // @Description: 更新
  52. // @author: Roc
  53. // @receiver m
  54. // @datetime 2023-12-14 16:11:10
  55. // @param cols []string
  56. // @return err error
  57. func (m *ChartTheme) Update(cols []string) (err error) {
  58. err = global.DmSQL["data"].Select(cols).Updates(m).Error
  59. return
  60. }
  61. // ChartThemeItem
  62. // @Description: 图表主题配置
  63. type ChartThemeItem struct {
  64. ChartThemeId int `description:"图表主题类型ID" orm:"column(chart_theme_id);pk" gorm:"primaryKey" `
  65. ChartThemeName string `description:"图表主题名称"`
  66. ChartThemeTypeId int `description:"图表主题类型ID"`
  67. Config string `description:"配置"`
  68. ChartImage string `description:"缩略图"`
  69. IsSystemTheme int `description:"是否是系统主题,0:不是;1:是"`
  70. SysUserId int `description:"操作人"`
  71. SysUserRealName string `description:"操作人的真实名称"`
  72. ModifyTime time.Time `description:"修改时间"`
  73. CreateTime time.Time `description:"创建时间"`
  74. DefaultChartThemeId int `description:"默认使用的图表主题ID"`
  75. }
  76. // GetChartThemeItemList
  77. // @Description: 根据图表类型id获取配置列表
  78. // @author: Roc
  79. // @datetime 2023-12-14 14:26:35
  80. // @param chartThemeTypeId int
  81. // @return list []*ChartThemeConfig
  82. // @return err error
  83. func GetChartThemeItemList(chartThemeTypeId int) (list []*ChartThemeItem, err error) {
  84. sql := `SELECT a.*,b.default_chart_theme_id FROM chart_theme a
  85. JOIN chart_theme_type b on a.chart_theme_type_id =b.chart_theme_type_id
  86. WHERE a.chart_theme_type_id = ? AND a.is_delete=0 ORDER BY a.chart_theme_id ASC `
  87. err = global.DmSQL["data"].Raw(sql, chartThemeTypeId).Find(&list).Error
  88. return
  89. }
  90. // GetSystemChartTheme
  91. // @Description: 根据图表类型id获取系统配置
  92. // @author: Roc
  93. // @datetime 2023-12-14 14:26:35
  94. // @param chartThemeTypeId int
  95. // @return item *ChartTheme
  96. // @return err error
  97. func GetSystemChartTheme(chartThemeTypeId int) (item *ChartTheme, err error) {
  98. sql := `SELECT a.* FROM chart_theme a
  99. WHERE a.chart_theme_type_id = ? AND a.is_system_theme=1 ORDER BY a.chart_theme_id ASC `
  100. err = global.DmSQL["data"].Raw(sql, chartThemeTypeId).First(&item).Error
  101. return
  102. }