chart_theme.go 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. package services
  2. import (
  3. "eta/eta_forum_hub/models"
  4. "eta/eta_forum_hub/utils"
  5. "fmt"
  6. "time"
  7. )
  8. func AddOrUpdateChartTheme(req models.ChartTheme) (err error) {
  9. // 查询主题信息是否存在
  10. chartTheme := new(models.ChartTheme)
  11. if req.ChartThemeId > 0 {
  12. var e error
  13. chartTheme, e = models.GetChartThemeId(req.ChartThemeId)
  14. if e != nil && e.Error() != utils.ErrNoRow() {
  15. err = fmt.Errorf("查询主题信息失败 %v", e)
  16. return
  17. }
  18. if e == nil {
  19. if chartTheme.BusinessCode != chartTheme.BusinessCode {
  20. err = fmt.Errorf("更新主题信息失败")
  21. }
  22. chartTheme.ChartThemeName = req.ChartThemeName
  23. chartTheme.ChartThemeTypeId = req.ChartThemeTypeId
  24. chartTheme.Config = req.Config
  25. chartTheme.ChartImage = req.ChartImage
  26. chartTheme.IsDelete = req.IsDelete
  27. chartTheme.SysUserId = req.SysUserId
  28. chartTheme.SysUserRealName = req.SysUserRealName
  29. chartTheme.ModifyTime = time.Now()
  30. // 添加入库
  31. err = chartTheme.Update([]string{})
  32. if err != nil {
  33. err = fmt.Errorf("添加或更新图表主题失败,%v", err)
  34. return
  35. }
  36. return
  37. }
  38. }
  39. chartTheme = &models.ChartTheme{
  40. ChartThemeId: req.ChartThemeId,
  41. ChartThemeName: req.ChartThemeName,
  42. ChartThemeTypeId: req.ChartThemeTypeId,
  43. Config: req.Config,
  44. ChartImage: req.ChartImage,
  45. IsDelete: req.IsDelete,
  46. SysUserId: req.SysUserId,
  47. SysUserRealName: req.SysUserRealName,
  48. ModifyTime: time.Now(),
  49. CreateTime: time.Now(),
  50. BusinessCode: req.BusinessCode,
  51. }
  52. // 添加入库
  53. err = chartTheme.Add()
  54. if err != nil {
  55. err = fmt.Errorf("添加或更新图表主题失败,%v", err)
  56. return
  57. }
  58. return
  59. }
  60. func AddOrUpdateChartThemeType(req models.ChartThemeType) (err error) {
  61. // 查询主题信息是否存在
  62. chartThemeType := new(models.ChartThemeType)
  63. if req.ChartThemeTypeId > 0 {
  64. var e error
  65. chartThemeType, e = models.GetChartThemeTypeById(req.ChartThemeTypeId)
  66. if e != nil && e.Error() != utils.ErrNoRow() {
  67. err = fmt.Errorf("查询主题信息失败 %v", e)
  68. return
  69. }
  70. if e == nil {
  71. // 添加入库
  72. chartThemeType.ChartTypeName = req.ChartTypeName
  73. chartThemeType.ChartType = req.ChartType
  74. chartThemeType.DefaultChartThemeId = req.DefaultChartThemeId
  75. chartThemeType.ChartSource = req.ChartSource
  76. chartThemeType.ModifyTime = time.Now()
  77. err = chartThemeType.Update([]string{})
  78. if err != nil {
  79. err = fmt.Errorf("添加或更新图表主题失败,%v", err)
  80. return
  81. }
  82. return
  83. }
  84. }
  85. chartThemeType = &models.ChartThemeType{
  86. ChartTypeName: req.ChartTypeName,
  87. ChartType: req.ChartType,
  88. ChartSource: req.ChartSource,
  89. DefaultChartThemeId: req.DefaultChartThemeId,
  90. ModifyTime: time.Now(),
  91. CreateTime: time.Now(),
  92. }
  93. // 添加入库
  94. err = chartThemeType.Add()
  95. if err != nil {
  96. err = fmt.Errorf("添加或更新图表主题失败,%v", err)
  97. return
  98. }
  99. return
  100. }