sys_opera_log.go 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. package service
  2. import (
  3. "errors"
  4. "go-admin/app/admin/models"
  5. "go-admin/app/admin/service/dto"
  6. cDto "go-admin/common/dto"
  7. "github.com/go-admin-team/go-admin-core/sdk/service"
  8. "gorm.io/gorm"
  9. )
  10. type SysOperaLog struct {
  11. service.Service
  12. }
  13. // GetPage 获取SysOperaLog列表
  14. func (e *SysOperaLog) GetPage(c *dto.SysOperaLogGetPageReq, list *[]models.SysOperaLog, count *int64) error {
  15. var err error
  16. var data models.SysOperaLog
  17. err = e.Orm.Model(&data).
  18. Scopes(
  19. cDto.MakeCondition(c.GetNeedSearch()),
  20. cDto.Paginate(c.GetPageSize(), c.GetPageIndex()),
  21. ).
  22. Find(list).Limit(-1).Offset(-1).
  23. Count(count).Error
  24. if err != nil {
  25. e.Log.Errorf("Service GetSysOperaLogPage error:%s", err.Error())
  26. return err
  27. }
  28. return nil
  29. }
  30. // Get 获取SysOperaLog对象
  31. func (e *SysOperaLog) Get(d *dto.SysOperaLogGetReq, model *models.SysOperaLog) error {
  32. var data models.SysOperaLog
  33. err := e.Orm.Model(&data).
  34. First(model, d.GetId()).Error
  35. if err != nil && errors.Is(err, gorm.ErrRecordNotFound) {
  36. err = errors.New("查看对象不存在或无权查看")
  37. e.Log.Errorf("Service GetSysOperaLog error:%s", err.Error())
  38. return err
  39. }
  40. if err != nil {
  41. e.Log.Errorf("Service GetSysOperaLog error:%s", err.Error())
  42. return err
  43. }
  44. return nil
  45. }
  46. // Insert 创建SysOperaLog对象
  47. func (e *SysOperaLog) Insert(model *models.SysOperaLog) error {
  48. var err error
  49. var data models.SysOperaLog
  50. err = e.Orm.Model(&data).
  51. Create(model).Error
  52. if err != nil {
  53. e.Log.Errorf("Service InsertSysOperaLog error:%s", err.Error())
  54. return err
  55. }
  56. return nil
  57. }
  58. // Remove 删除SysOperaLog
  59. func (e *SysOperaLog) Remove(d *dto.SysOperaLogDeleteReq) error {
  60. var err error
  61. var data models.SysOperaLog
  62. db := e.Orm.Model(&data).Delete(&data, d.GetId())
  63. if err = db.Error; err != nil {
  64. e.Log.Errorf("Service RemoveSysOperaLog error:%s", err.Error())
  65. return err
  66. }
  67. if db.RowsAffected == 0 {
  68. return errors.New("无权删除该数据")
  69. }
  70. return nil
  71. }