sys_opera_log_controller.go 3.5 KB

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