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.

80 lines
2.6 KiB

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