operation_log.go 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  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 optType query int false "气瓶流转步骤"
  20. // @Param innerCode query string false "单位内编码"
  21. // @Param pageSize query int false "页条数"
  22. // @Param page query int false "页码"
  23. // @Success 200 {object} response.Response{data=response.Page{list=[]model.OperationLog}} "{"code": 200, "data": [...]}"
  24. // @Router /api/operation-log [get]
  25. // @Security Bearer
  26. func (e OperationLogController) GetPage(c *gin.Context) {
  27. s := service.OperationLog{}
  28. req := dto.OperationLogGetPageReq{}
  29. err := e.MakeContext(c).
  30. MakeOrm().
  31. Bind(&req, binding.Query).
  32. MakeService(&s.Service).
  33. Errors
  34. if err != nil {
  35. e.Logger.Error(err)
  36. e.Error(500, err, err.Error())
  37. return
  38. }
  39. //数据权限检查
  40. p := actions.GetPermissionFromContext(c)
  41. list := make([]model.OperationLog, 0)
  42. var count int64
  43. err = s.GetPage(&req, &list, &count, p)
  44. if err != nil {
  45. e.Error(500, err, err.Error())
  46. return
  47. }
  48. e.PageOK(list, int(count), req.GetPageIndex(), req.GetPageSize(), "查询成功")
  49. }
  50. // Get 通过id获取操作记录
  51. // @Summary 通过id获取操作记录
  52. // @Description 通过id获取操作记录
  53. // @Tags 操作记录
  54. // @Param id path string true "操作记录id"
  55. // @Success 200 {object} response.Response{data=model.OperationLog} "{"code": 200, "data": [...]}"
  56. // @Router /api/operation-log/{id} [get]
  57. // @Security Bearer
  58. func (e OperationLogController) Get(c *gin.Context) {
  59. s := service.OperationLog{}
  60. req := dto.OperationLogGetReq{}
  61. err := e.MakeContext(c).
  62. MakeOrm().
  63. Bind(&req, nil).
  64. MakeService(&s.Service).
  65. Errors
  66. if err != nil {
  67. e.Logger.Error(err)
  68. e.Error(500, err, err.Error())
  69. return
  70. }
  71. var object model.OperationLog
  72. p := actions.GetPermissionFromContext(c)
  73. //数据权限检查
  74. err = s.Get(&req, &object, p)
  75. if err != nil {
  76. e.Error(500, err, err.Error())
  77. return
  78. }
  79. e.OK(object, "查询成功")
  80. }
  81. // Insert 添加操作记录
  82. // @Summary 添加操作记录
  83. // @Description 添加操作记录
  84. // @Tags 操作记录
  85. // @Accept application/json
  86. // @Product application/json
  87. // @Param data body dto.OperationLogInsertReq true "data"
  88. // @Success 200 {string} string "{"code": 200, "message": "添加成功"}"
  89. // @Success 200 {string} string "{"code": -1, "message": "添加失败"}"
  90. // @Router /api/operation-log [post]
  91. // @Security Bearer
  92. func (e OperationLogController) Insert(c *gin.Context) {
  93. s := service.OperationLog{}
  94. req := dto.OperationLogInsertReq{}
  95. err := e.MakeContext(c).
  96. MakeOrm().
  97. Bind(&req, binding.JSON).
  98. MakeService(&s.Service).
  99. Errors
  100. if err != nil {
  101. e.Logger.Error(err)
  102. e.Error(500, err, err.Error())
  103. return
  104. }
  105. //数据权限检查
  106. p := actions.GetPermissionFromContext(c)
  107. err = s.Insert(&req, p)
  108. if err != nil {
  109. e.Error(500, err, err.Error())
  110. return
  111. }
  112. e.OK(req.GetId(), "创建成功")
  113. }
  114. // InsertForGasStation 添加气站操作记录
  115. // @Summary 添加气站操作记录
  116. // @Description 添加气站操作记录
  117. // @Tags 操作记录
  118. // @Accept application/json
  119. // @Product application/json
  120. // @Param data body dto.OperationLogInsertForGasStationReq true "data"
  121. // @Success 200 {string} string "{"code": 200, "message": "添加成功"}"
  122. // @Success 200 {string} string "{"code": -1, "message": "添加失败"}"
  123. // @Router /api/operation-log/gas-station [post]
  124. // @Security Bearer
  125. func (e OperationLogController) InsertForGasStation(c *gin.Context) {
  126. s := service.OperationLog{}
  127. req := dto.OperationLogInsertForGasStationReq{}
  128. err := e.MakeContext(c).
  129. MakeOrm().
  130. Bind(&req, binding.JSON).
  131. MakeService(&s.Service).
  132. Errors
  133. if err != nil {
  134. e.Logger.Error(err)
  135. e.Error(500, err, err.Error())
  136. return
  137. }
  138. err = s.InsertForGasStation(&req)
  139. if err != nil {
  140. e.Error(500, err, err.Error())
  141. return
  142. }
  143. e.OK(req.GetId(), "创建成功")
  144. }