operation_log.go 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. package controller
  2. import (
  3. "gas-cylinder-api/app/admin/model"
  4. "gas-cylinder-api/app/admin/service"
  5. "gas-cylinder-api/app/admin/service/dto"
  6. "gas-cylinder-api/common/actions"
  7. "github.com/gin-gonic/gin"
  8. "github.com/gin-gonic/gin/binding"
  9. "gogs.baozhida.cn/zoie/OAuth-core/api"
  10. _ "gogs.baozhida.cn/zoie/OAuth-core/pkg/response"
  11. )
  12. type OperationLogController struct {
  13. api.Api
  14. }
  15. // GetPage 获取操作记录列表
  16. // @Summary 获取操作记录列表
  17. // @Description 获取操作记录列表
  18. // @Tags 操作记录
  19. // @Param deptName query string false "操作记录名称"
  20. // @Success 200 {object} response.Response{data=response.Page{list=[]model.OperationLog}} "{"code": 200, "data": [...]}"
  21. // @Router /api/operation-log [get]
  22. // @Security Bearer
  23. func (e OperationLogController) GetPage(c *gin.Context) {
  24. s := service.OperationLog{}
  25. req := dto.OperationLogGetPageReq{}
  26. err := e.MakeContext(c).
  27. MakeOrm().
  28. Bind(&req, binding.Query).
  29. MakeService(&s.Service).
  30. Errors
  31. if err != nil {
  32. e.Logger.Error(err)
  33. e.Error(500, err, err.Error())
  34. return
  35. }
  36. //数据权限检查
  37. p := actions.GetPermissionFromContext(c)
  38. list := make([]model.OperationLog, 0)
  39. var count int64
  40. err = s.GetPage(&req, &list, &count, p)
  41. if err != nil {
  42. e.Error(500, err, err.Error())
  43. return
  44. }
  45. e.PageOK(list, int(count), req.GetPageIndex(), req.GetPageSize(), "查询成功")
  46. }
  47. // Get 通过id获取操作记录
  48. // @Summary 通过id获取操作记录
  49. // @Description 通过id获取操作记录
  50. // @Tags 操作记录
  51. // @Param id path string true "操作记录id"
  52. // @Success 200 {object} response.Response{data=model.OperationLog} "{"code": 200, "data": [...]}"
  53. // @Router /api/operation-log/{id} [get]
  54. // @Security Bearer
  55. func (e OperationLogController) Get(c *gin.Context) {
  56. s := service.OperationLog{}
  57. req := dto.OperationLogGetReq{}
  58. err := e.MakeContext(c).
  59. MakeOrm().
  60. Bind(&req, nil).
  61. MakeService(&s.Service).
  62. Errors
  63. if err != nil {
  64. e.Logger.Error(err)
  65. e.Error(500, err, err.Error())
  66. return
  67. }
  68. var object model.OperationLog
  69. p := actions.GetPermissionFromContext(c)
  70. //数据权限检查
  71. err = s.Get(&req, &object, p)
  72. if err != nil {
  73. e.Error(500, err, err.Error())
  74. return
  75. }
  76. e.OK(object, "查询成功")
  77. }
  78. // Insert 添加操作记录
  79. // @Summary 添加操作记录
  80. // @Description 添加操作记录
  81. // @Tags 操作记录
  82. // @Accept application/json
  83. // @Product application/json
  84. // @Param data body dto.OperationLogInsertReq true "data"
  85. // @Success 200 {string} string "{"code": 200, "message": "添加成功"}"
  86. // @Success 200 {string} string "{"code": -1, "message": "添加失败"}"
  87. // @Router /api/operation-log [post]
  88. // @Security Bearer
  89. func (e OperationLogController) Insert(c *gin.Context) {
  90. s := service.OperationLog{}
  91. req := dto.OperationLogInsertReq{}
  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. //数据权限检查
  103. p := actions.GetPermissionFromContext(c)
  104. err = s.Insert(&req, p)
  105. if err != nil {
  106. e.Error(500, err, err.Error())
  107. return
  108. }
  109. e.OK(req.GetId(), "创建成功")
  110. }
  111. // InsertForGasStation 添加气站操作记录
  112. // @Summary 添加气站操作记录
  113. // @Description 添加气站操作记录
  114. // @Tags 操作记录
  115. // @Accept application/json
  116. // @Product application/json
  117. // @Param data body dto.OperationLogInsertForGasStationReq true "data"
  118. // @Success 200 {string} string "{"code": 200, "message": "添加成功"}"
  119. // @Success 200 {string} string "{"code": -1, "message": "添加失败"}"
  120. // @Router /api/operation-log/gas-station [post]
  121. // @Security Bearer
  122. func (e OperationLogController) InsertForGasStation(c *gin.Context) {
  123. s := service.OperationLog{}
  124. req := dto.OperationLogInsertForGasStationReq{}
  125. err := e.MakeContext(c).
  126. MakeOrm().
  127. Bind(&req, binding.JSON).
  128. MakeService(&s.Service).
  129. Errors
  130. if err != nil {
  131. e.Logger.Error(err)
  132. e.Error(500, err, err.Error())
  133. return
  134. }
  135. err = s.InsertForGasStation(&req)
  136. if err != nil {
  137. e.Error(500, err, err.Error())
  138. return
  139. }
  140. e.OK(req.GetId(), "创建成功")
  141. }