sys_opera_log_service.go 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. package service
  2. import (
  3. "cold-delivery/common/actions"
  4. cDto "cold-delivery/common/dto"
  5. "cold-delivery/common/global"
  6. "errors"
  7. "gogs.baozhida.cn/zoie/OAuth-core/service"
  8. "gorm.io/gorm"
  9. "cold-delivery/app/admin/model"
  10. "cold-delivery/app/admin/service/dto"
  11. )
  12. type SysOperaLog struct {
  13. service.Service
  14. }
  15. // GetPage 获取SysOperaLog列表
  16. func (e *SysOperaLog) GetPage(c *dto.SysOperaLogGetPageReq, list *[]model.SysOperaLog, count *int64, p *actions.DataPermission) error {
  17. var err error
  18. var data model.SysOperaLog
  19. err = e.Orm.Model(&data).
  20. Scopes(
  21. cDto.MakeCondition(c.GetNeedSearch()),
  22. cDto.Paginate(c.GetPageSize(), c.GetPageIndex()),
  23. actions.Permission(data.TableName(), p),
  24. ).
  25. Find(list).Limit(-1).Offset(-1).
  26. Count(count).Error
  27. if err != nil {
  28. e.Log.Errorf("Service GetSysOperaLogPage error: %s", err.Error())
  29. return global.GetFailedErr
  30. }
  31. return nil
  32. }
  33. // Get 获取SysOperaLog对象
  34. func (e *SysOperaLog) Get(d *dto.SysOperaLogGetReq, operaLogModel *model.SysOperaLog, p *actions.DataPermission) error {
  35. err := e.Orm.
  36. Scopes(actions.Permission(operaLogModel.TableName(), p)).
  37. First(operaLogModel, d.GetId()).Error
  38. if err != nil {
  39. e.Log.Errorf("db error: %s", err)
  40. if errors.Is(err, gorm.ErrRecordNotFound) {
  41. return global.GetNotFoundOrNoPermissionErr
  42. }
  43. return global.GetFailedErr
  44. }
  45. return nil
  46. }
  47. // Insert 创建SysOperaLog对象
  48. func (e *SysOperaLog) Insert(operaLogModel *model.SysOperaLog) error {
  49. var err error
  50. var data model.SysOperaLog
  51. err = e.Orm.Model(&data).
  52. Create(operaLogModel).Error
  53. if err != nil {
  54. e.Log.Errorf("Service InsertSysOperaLog error: %s", err.Error())
  55. return global.CreateFailedErr
  56. }
  57. return nil
  58. }
  59. // Remove 删除SysOperaLog
  60. func (e *SysOperaLog) Remove(d *dto.SysOperaLogDeleteReq, p *actions.DataPermission) error {
  61. var err error
  62. var data model.SysOperaLog
  63. db := e.Orm.
  64. Scopes(actions.Permission(data.TableName(), p)).
  65. Delete(&data, d.GetId())
  66. if err = db.Error; err != nil {
  67. e.Log.Errorf("Service RemoveSysOperaLog error: %s", err.Error())
  68. return global.DeleteFailedErr
  69. }
  70. if db.RowsAffected == 0 {
  71. return global.DeleteNotFoundOrNoPermissionErr
  72. }
  73. return nil
  74. }