ot_app_dashboard.go 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. package service
  2. import (
  3. "errors"
  4. "github.com/go-admin-team/go-admin-core/sdk/service"
  5. "gorm.io/gorm"
  6. "go-admin/app/admin/models"
  7. "go-admin/app/admin/service/dto"
  8. "go-admin/common/actions"
  9. cDto "go-admin/common/dto"
  10. )
  11. type OtAppDashboard struct {
  12. service.Service
  13. }
  14. // GetPage 获取OtAppDashboard列表
  15. func (e *OtAppDashboard) GetPage(c *dto.OtAppDashboardGetPageReq, p *actions.DataPermission, list *[]models.OtAppDashboard, count *int64) error {
  16. var err error
  17. var data models.OtAppDashboard
  18. err = e.Orm.Model(&data).
  19. Scopes(
  20. cDto.MakeCondition(c.GetNeedSearch()),
  21. cDto.Paginate(c.GetPageSize(), c.GetPageIndex()),
  22. actions.Permission(data.TableName(), p),
  23. ).
  24. Find(list).Limit(-1).Offset(-1).
  25. Count(count).Error
  26. if err != nil {
  27. e.Log.Errorf("OtAppDashboardService GetPage error:%s \r\n", err)
  28. return err
  29. }
  30. return nil
  31. }
  32. // Get 获取OtAppDashboard对象
  33. func (e *OtAppDashboard) Get(d *dto.OtAppDashboardGetReq, p *actions.DataPermission, model *models.OtAppDashboard) error {
  34. var data models.OtAppDashboard
  35. err := e.Orm.Model(&data).
  36. Scopes(
  37. actions.Permission(data.TableName(), p),
  38. ).
  39. First(model, d.GetId()).Error
  40. if err != nil && errors.Is(err, gorm.ErrRecordNotFound) {
  41. err = errors.New("查看对象不存在或无权查看")
  42. e.Log.Errorf("Service GetOtAppDashboard error:%s \r\n", err)
  43. return err
  44. }
  45. if err != nil {
  46. e.Log.Errorf("db error:%s", err)
  47. return err
  48. }
  49. return nil
  50. }
  51. // Insert 创建OtAppDashboard对象
  52. func (e *OtAppDashboard) Insert(c *dto.OtAppDashboardInsertReq) error {
  53. var err error
  54. var data models.OtAppDashboard
  55. c.Generate(&data)
  56. err = e.Orm.Create(&data).Error
  57. if err != nil {
  58. e.Log.Errorf("OtAppDashboardService Insert error:%s \r\n", err)
  59. return err
  60. }
  61. return nil
  62. }
  63. // Update 修改OtAppDashboard对象
  64. func (e *OtAppDashboard) Update(c *dto.OtAppDashboardUpdateReq, p *actions.DataPermission) error {
  65. var err error
  66. var data = models.OtAppDashboard{}
  67. e.Orm.Scopes(
  68. actions.Permission(data.TableName(), p),
  69. ).First(&data, c.GetId())
  70. c.Generate(&data)
  71. db := e.Orm.Save(&data)
  72. if err = db.Error; err != nil {
  73. e.Log.Errorf("OtAppDashboardService Save error:%s \r\n", err)
  74. return err
  75. }
  76. if db.RowsAffected == 0 {
  77. return errors.New("无权更新该数据")
  78. }
  79. return nil
  80. }
  81. // Remove 删除OtAppDashboard
  82. func (e *OtAppDashboard) Remove(d *dto.OtAppDashboardDeleteReq, p *actions.DataPermission) error {
  83. var data models.OtAppDashboard
  84. db := e.Orm.Model(&data).
  85. Scopes(
  86. actions.Permission(data.TableName(), p),
  87. ).Delete(&data, d.GetId())
  88. if err := db.Error; err != nil {
  89. e.Log.Errorf("Service RemoveOtAppDashboard error:%s \r\n", err)
  90. return err
  91. }
  92. if db.RowsAffected == 0 {
  93. return errors.New("无权删除该数据")
  94. }
  95. return nil
  96. }
  97. func (e *OtAppDashboard) GetByAppId(m *models.OtAppDashboard) error {
  98. err := e.Orm.Model(m).
  99. Where("app_id = ?", m.AppId).
  100. First(m).Error
  101. if err != nil {
  102. if errors.Is(err, gorm.ErrRecordNotFound) {
  103. return nil
  104. } else {
  105. e.Log.Errorf("db error:%s", err)
  106. return err
  107. }
  108. }
  109. return nil
  110. }