You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

86 lines
3.1 KiB

3 years ago
3 years ago
3 years ago
  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. func (operationRecordService *OperationRecordService) CreateSysOperationRecord(sysOperationRecord system.SysOperationRecord) (err error) {
  15. err = global.GVA_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.GVA_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.GVA_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: err error, sysOperationRecord model.SysOperationRecord
  42. func (operationRecordService *OperationRecordService) GetSysOperationRecord(id uint) (err error, sysOperationRecord system.SysOperationRecord) {
  43. err = global.GVA_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: err error, list interface{}, total int64
  52. func (operationRecordService *OperationRecordService) GetSysOperationRecordInfoList(info systemReq.SysOperationRecordSearch) (err error, list interface{}, total int64) {
  53. limit := info.PageSize
  54. offset := info.PageSize * (info.Page - 1)
  55. // 创建db
  56. db := global.GVA_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 err, sysOperationRecords, total
  74. }