sys_operation_record.go 3.0 KB

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