sys_opera_log.go 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. package apis
  2. import (
  3. "fmt"
  4. "github.com/gin-gonic/gin"
  5. "github.com/gin-gonic/gin/binding"
  6. "github.com/go-admin-team/go-admin-core/sdk/api"
  7. "go-admin/app/admin/models"
  8. "go-admin/app/admin/service"
  9. "go-admin/app/admin/service/dto"
  10. )
  11. type SysOperaLog struct {
  12. api.Api
  13. }
  14. // GetPage 操作日志列表
  15. // @Summary 操作日志列表
  16. // @Description 获取JSON
  17. // @Tags 操作日志
  18. // @Param title query string false "title"
  19. // @Param method query string false "method"
  20. // @Param requestMethod query string false "requestMethod"
  21. // @Param operUrl query string false "operUrl"
  22. // @Param operIp query string false "operIp"
  23. // @Param status query string false "status"
  24. // @Param beginTime query string false "beginTime"
  25. // @Param endTime query string false "endTime"
  26. // @Success 200 {object} response.Response "{"code": 200, "data": [...]}"
  27. // @Router /api/v1/sys-opera-log [get]
  28. // @Security Bearer
  29. func (e SysOperaLog) GetPage(c *gin.Context) {
  30. s := service.SysOperaLog{}
  31. req := new(dto.SysOperaLogGetPageReq)
  32. err := e.MakeContext(c).
  33. MakeOrm().
  34. Bind(req, binding.Form).
  35. MakeService(&s.Service).
  36. Errors
  37. if err != nil {
  38. e.Logger.Error(err)
  39. e.Error(500, err, err.Error())
  40. return
  41. }
  42. list := make([]models.SysOperaLog, 0)
  43. var count int64
  44. err = s.GetPage(req, &list, &count)
  45. if err != nil {
  46. e.Error(500, err, "查询失败")
  47. return
  48. }
  49. e.PageOK(list, int(count), req.GetPageIndex(), req.GetPageSize(), "查询成功")
  50. }
  51. // Get 操作日志通过id获取
  52. // @Summary 操作日志通过id获取
  53. // @Description 获取JSON
  54. // @Tags 操作日志
  55. // @Param id path string false "id"
  56. // @Success 200 {object} response.Response "{"code": 200, "data": [...]}"
  57. // @Router /api/v1/sys-opera-log/{id} [get]
  58. // @Security Bearer
  59. func (e SysOperaLog) Get(c *gin.Context) {
  60. s := new(service.SysOperaLog)
  61. req := dto.SysOperaLogGetReq{}
  62. err := e.MakeContext(c).
  63. MakeOrm().
  64. Bind(&req, nil).
  65. MakeService(&s.Service).
  66. Errors
  67. if err != nil {
  68. e.Logger.Error(err)
  69. e.Error(500, err, err.Error())
  70. return
  71. }
  72. var object models.SysOperaLog
  73. err = s.Get(&req, &object)
  74. if err != nil {
  75. e.Error(500, err, "查询失败")
  76. return
  77. }
  78. e.OK(object, "查询成功")
  79. }
  80. // Delete 操作日志删除
  81. // DeleteSysMenu 操作日志删除
  82. // @Summary 删除操作日志
  83. // @Description 删除数据
  84. // @Tags 操作日志
  85. // @Param data body dto.SysOperaLogDeleteReq true "body"
  86. // @Success 200 {object} response.Response "{"code": 200, "data": [...]}"
  87. // @Router /api/v1/sys-opera-log [delete]
  88. // @Security Bearer
  89. func (e SysOperaLog) Delete(c *gin.Context) {
  90. s := new(service.SysOperaLog)
  91. req := dto.SysOperaLogDeleteReq{}
  92. err := e.MakeContext(c).
  93. MakeOrm().
  94. Bind(&req, binding.JSON).
  95. MakeService(&s.Service).
  96. Errors
  97. if err != nil {
  98. e.Logger.Error(err)
  99. e.Error(500, err, err.Error())
  100. return
  101. }
  102. err = s.Remove(&req)
  103. if err != nil {
  104. e.Logger.Error(err)
  105. e.Error(500, err, fmt.Sprintf("删除失败!错误详情:%s", err.Error()))
  106. return
  107. }
  108. e.OK(req.GetId(), "删除成功")
  109. }