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.

84 lines
3.1 KiB

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