chart_theme.go 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. package chart_theme
  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.NewOrmUsingDB("data")
  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.NewOrmUsingDB("data")
  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.NewOrmUsingDB("data")
  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.NewOrmUsingDB("data")
  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.NewOrmUsingDB("data")
  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.NewOrmUsingDB("data")
  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.NewOrmUsingDB("data")
  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. }
  136. type ColorsOptions []string
  137. type LegendOptions struct {
  138. VerticalAlign string `json:"verticalAlign"`
  139. ItemStyle struct {
  140. Color string `json:"color"`
  141. FontSize int `json:"fontSize"`
  142. Cursor string `json:"cursor"`
  143. FontWeight string `json:"fontWeight"`
  144. TextOverflow string `json:"textOverflow"`
  145. } `json:"itemStyle"`
  146. }
  147. type TitleOptions struct {
  148. Align string `json:"align"`
  149. Style struct {
  150. Color string `json:"color"`
  151. FontSize int `json:"fontSize"`
  152. } `json:"style"`
  153. }
  154. type MarkerOptions struct {
  155. Style struct {
  156. Color string `json:"color"`
  157. FontSize int `json:"fontSize"`
  158. } `json:"style"`
  159. }
  160. type AxisOptions struct {
  161. Style struct {
  162. Color string `json:"color"`
  163. FontSize int `json:"fontSize"`
  164. } `json:"style"`
  165. }
  166. type DrawOption struct {
  167. PlotBackgroundColor string `json:"plotBackgroundColor"`
  168. }
  169. type LineOptions struct {
  170. DashStyle string `json:"dashStyle"`
  171. LineWidth float64 `json:"lineWidth"`
  172. LineType string `json:"lineType"`
  173. Radius float64 `json:"radius"`
  174. }
  175. type OldChartOptions struct {
  176. ColorsOptions []string `json:"colorsOptions"`
  177. LineOptions LineOptions `json:"lineOptions"`
  178. LegendOptions interface{} `json:"legendOptions"`
  179. TitleOptions interface{} `json:"titleOptions"`
  180. MarkerOptions interface{} `json:"markerOptions"`
  181. XAxisOptions interface{} `json:"xAxisOptions"`
  182. YAxisOptions interface{} `json:"yAxisOptions"`
  183. DrawOption interface{} `json:"drawOption"`
  184. LineOptionList []LineStyleOptions `json:"lineOptionList"`
  185. }
  186. type NewChartOptions struct {
  187. OldChartOptions
  188. LineOptionList []NewLineOptions `json:"lineOptionList"`
  189. }
  190. type NewLineOptions struct {
  191. LineOptions
  192. Color string `json:"color"`
  193. DataMark string `json:"dataMark"`
  194. MarkType string `json:"markType"`
  195. MarkSize int `json:"markSize"`
  196. MarkColor string `json:"markColor"`
  197. }
  198. type LineStyleOptions struct {
  199. DashStyle string `json:"dashStyle"`
  200. Color string `json:"color"`
  201. LineWidth float64 `json:"lineWidth"`
  202. LineType string `json:"lineType"`
  203. Radius int `json:"radius"`
  204. DataMark string `json:"dataMark"`
  205. MarkType string `json:"markType"`
  206. MarkSize int `json:"markSize"`
  207. MarkColor string `json:"markColor"`
  208. }