sys_operation_record.go 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. package system
  2. import (
  3. "github.com/flipped-aurora/gin-vue-admin/server/global"
  4. "github.com/flipped-aurora/gin-vue-admin/server/model/common/request"
  5. "github.com/flipped-aurora/gin-vue-admin/server/model/system"
  6. systemReq "github.com/flipped-aurora/gin-vue-admin/server/model/system/request"
  7. )
  8. //@author: [granty1](https://github.com/granty1)
  9. //@function: CreateSysOperationRecord
  10. //@description: 创建记录
  11. //@param: sysOperationRecord model.SysOperationRecord
  12. //@return: err error
  13. type OperationRecordService struct{}
  14. var OperationRecordServiceApp = new(OperationRecordService)
  15. //@author: [granty1](https://github.com/granty1)
  16. //@author: [piexlmax](https://github.com/piexlmax)
  17. //@function: DeleteSysOperationRecordByIds
  18. //@description: 批量删除记录
  19. //@param: ids request.IdsReq
  20. //@return: err error
  21. func (operationRecordService *OperationRecordService) DeleteSysOperationRecordByIds(ids request.IdsReq) (err error) {
  22. err = global.GVA_DB.Delete(&[]system.SysOperationRecord{}, "id in (?)", ids.Ids).Error
  23. return err
  24. }
  25. //@author: [granty1](https://github.com/granty1)
  26. //@function: DeleteSysOperationRecord
  27. //@description: 删除操作记录
  28. //@param: sysOperationRecord model.SysOperationRecord
  29. //@return: err error
  30. func (operationRecordService *OperationRecordService) DeleteSysOperationRecord(sysOperationRecord system.SysOperationRecord) (err error) {
  31. err = global.GVA_DB.Delete(&sysOperationRecord).Error
  32. return err
  33. }
  34. //@author: [granty1](https://github.com/granty1)
  35. //@function: GetSysOperationRecord
  36. //@description: 根据id获取单条操作记录
  37. //@param: id uint
  38. //@return: sysOperationRecord system.SysOperationRecord, err error
  39. func (operationRecordService *OperationRecordService) GetSysOperationRecord(id uint) (sysOperationRecord system.SysOperationRecord, err error) {
  40. err = global.GVA_DB.Where("id = ?", id).First(&sysOperationRecord).Error
  41. return
  42. }
  43. //@author: [granty1](https://github.com/granty1)
  44. //@author: [piexlmax](https://github.com/piexlmax)
  45. //@function: GetSysOperationRecordInfoList
  46. //@description: 分页获取操作记录列表
  47. //@param: info systemReq.SysOperationRecordSearch
  48. //@return: list interface{}, total int64, err error
  49. func (operationRecordService *OperationRecordService) GetSysOperationRecordInfoList(info systemReq.SysOperationRecordSearch) (list interface{}, total int64, err error) {
  50. limit := info.PageSize
  51. offset := info.PageSize * (info.Page - 1)
  52. // 创建db
  53. db := global.GVA_DB.Model(&system.SysOperationRecord{})
  54. var sysOperationRecords []system.SysOperationRecord
  55. // 如果有条件搜索 下方会自动创建搜索语句
  56. if info.Method != "" {
  57. db = db.Where("method = ?", info.Method)
  58. }
  59. if info.Path != "" {
  60. db = db.Where("path LIKE ?", "%"+info.Path+"%")
  61. }
  62. if info.Status != 0 {
  63. db = db.Where("status = ?", info.Status)
  64. }
  65. err = db.Count(&total).Error
  66. if err != nil {
  67. return
  68. }
  69. err = db.Order("id desc").Limit(limit).Offset(offset).Preload("User").Find(&sysOperationRecords).Error
  70. return sysOperationRecords, total, err
  71. }