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.

79 lines
2.7 KiB

  1. package service
  2. import (
  3. "gin-vue-admin/global"
  4. "gin-vue-admin/model"
  5. "gin-vue-admin/model/request"
  6. )
  7. // @title CreateSysOperationRecord
  8. // @description create a SysOperationRecord
  9. // @param sysOperationRecord model.SysOperationRecord
  10. // @auth (2020/04/05 20:22)
  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. // @title DeleteSysOperationRecord
  17. // @description delete SysOperationRecords
  18. // @auth (2020/04/05 20:22)
  19. // @param sysOperationRecord request.IdsReq
  20. // @return error
  21. func DeleteSysOperationRecordByIds(ids request.IdsReq) (err error) {
  22. err = global.GVA_DB.Delete(&[]model.SysOperationRecord{}, "id in (?)", ids.Ids).Error
  23. return err
  24. }
  25. // @title DeleteSysOperationRecord
  26. // @description delete a SysOperationRecord
  27. // @auth (2020/04/05 20:22)
  28. // @param sysOperationRecord model.SysOperationRecord
  29. // @return error
  30. func DeleteSysOperationRecord(sysOperationRecord model.SysOperationRecord) (err error) {
  31. err = global.GVA_DB.Delete(sysOperationRecord).Error
  32. return err
  33. }
  34. // @title GetSysOperationRecord
  35. // @description get the info of a SysOperationRecord
  36. // @auth (2020/04/05 20:22)
  37. // @param id uint
  38. // @return error
  39. // @return SysOperationRecord 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. // @title GetSysOperationRecordInfoList
  45. // @description get SysOperationRecord list by pagination, 分页获取用户列表
  46. // @auth (2020/04/05 20:22)
  47. // @param info PageInfo
  48. // @return error
  49. func GetSysOperationRecordInfoList(info request.SysOperationRecordSearch) (err error, list interface{}, total int64) {
  50. limit := info.PageSize
  51. offset := info.PageSize * (info.Page - 1)
  52. // 创建db
  53. db := global.GVA_DB.Model(&model.SysOperationRecord{})
  54. var sysOperationRecords []model.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. err = db.Order("id desc").Limit(limit).Offset(offset).Preload("User").Find(&sysOperationRecords).Error
  67. return err, sysOperationRecords, total
  68. }