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.

90 lines
3.1 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 UpdateSysOperationRecord
  35. // @description update a SysOperationRecord
  36. // @param sysOperationRecord *model.SysOperationRecord
  37. // @auth (2020/04/05 20:22)
  38. // @return error
  39. func UpdateSysOperationRecord(sysOperationRecord *model.SysOperationRecord) (err error) {
  40. err = global.GVA_DB.Save(sysOperationRecord).Error
  41. return err
  42. }
  43. // @title GetSysOperationRecord
  44. // @description get the info of a SysOperationRecord
  45. // @auth (2020/04/05 20:22)
  46. // @param id uint
  47. // @return error
  48. // @return SysOperationRecord SysOperationRecord
  49. func GetSysOperationRecord(id uint) (err error, sysOperationRecord model.SysOperationRecord) {
  50. err = global.GVA_DB.Where("id = ?", id).First(&sysOperationRecord).Error
  51. return
  52. }
  53. // @title GetSysOperationRecordInfoList
  54. // @description get SysOperationRecord list by pagination, 分页获取用户列表
  55. // @auth (2020/04/05 20:22)
  56. // @param info PageInfo
  57. // @return error
  58. func GetSysOperationRecordInfoList(info request.SysOperationRecordSearch) (err error, list interface{}, total int64) {
  59. limit := info.PageSize
  60. offset := info.PageSize * (info.Page - 1)
  61. // 创建db
  62. db := global.GVA_DB.Model(&model.SysOperationRecord{})
  63. var sysOperationRecords []model.SysOperationRecord
  64. // 如果有条件搜索 下方会自动创建搜索语句
  65. if info.Method != "" {
  66. db = db.Where("method = ?", info.Method)
  67. }
  68. if info.Path != "" {
  69. db = db.Where("path LIKE ?", "%"+info.Path+"%")
  70. }
  71. if info.Status != 0 {
  72. db = db.Where("status = ?", info.Status)
  73. }
  74. err = db.Count(&total).Error
  75. err = db.Order("id desc").Limit(limit).Offset(offset).Preload("User").Find(&sysOperationRecords).Error
  76. return err, sysOperationRecords, total
  77. }