operation_log.go 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. // Copyright 2019 github.com. All rights reserved.
  2. // Use of this source code is governed by github.com.
  3. package v1
  4. import (
  5. "net/http"
  6. "strconv"
  7. "strings"
  8. "xingjia-management-gateway/apis"
  9. "xingjia-management-gateway/errors"
  10. "xingjia-management-gateway/impl/v1/operation_log"
  11. param_v1 "xingjia-management-gateway/param/v1"
  12. "xingjia-management-gateway/utils"
  13. "git.getensh.com/common/gopkgs/logger"
  14. "git.getensh.com/common/gopkgs/tasker/httptasker"
  15. "git.getensh.com/common/gopkgs/util"
  16. "github.com/gin-gonic/gin"
  17. "go.uber.org/zap"
  18. )
  19. //
  20. // @Summary 批量删除操作日志
  21. // @Description 批量删除操作日志
  22. // @Tags 操作日志
  23. // @Accept json
  24. // @Produce json
  25. // @Param token header string true " "
  26. // @Param ids query string true " 日志id,以英文分号分割"
  27. // @Success 200 {object} v1.OperationLogDelResponse
  28. // @Failure 500 {object} base.HTTPError
  29. // @Router /api/v1/operation_log [delete]
  30. func (c *Controller) OperationLogDel(ctx *gin.Context) {
  31. // 解析参数
  32. req := &param_v1.OperationLogDelRequest{}
  33. parseParamTask := func() error {
  34. err := util.ShouldBind(ctx, &req.Header, nil, &req.OperationLogDelQuery, nil)
  35. if err != nil {
  36. logger.Error("func",
  37. zap.String("call", "util.ShouldBind"),
  38. zap.String("error", err.Error()))
  39. return errors.ParamsError
  40. }
  41. return nil
  42. }
  43. // 业务处理
  44. handleServiceTask := func() error {
  45. tokenInfo, err := utils.GetJwtTokenFromCtx(ctx)
  46. if err != nil {
  47. return err
  48. }
  49. // 响应数据
  50. resp := param_v1.OperationLogDelResponse{}
  51. rpcReq := &apis.OperationLogDelRequest{
  52. SelfId: tokenInfo.Uid,
  53. }
  54. array := strings.Split(req.Ids, ";")
  55. rpcReq.Ids = make([]int64, len(array))
  56. for i, v := range array {
  57. rpcReq.Ids[i], _ = strconv.ParseInt(v, 10, 64)
  58. }
  59. _, err = operation_log.OperationLogDel(ctx, rpcReq)
  60. if err != nil {
  61. s, _ := json.MarshalToString(req)
  62. logger.Error("func",
  63. zap.String("call", "operation_log.OperationLogDel"),
  64. zap.String("params", s),
  65. zap.String("error", err.Error()))
  66. return errors.ErrorTransForm(err)
  67. }
  68. ctx.JSON(http.StatusOK, resp)
  69. return nil
  70. }
  71. // 执行任务
  72. httptasker.Exec(ctx, parseParamTask, handleServiceTask)
  73. }
  74. //
  75. // @Summary 操作日志列表
  76. // @Description 操作日志列表
  77. // @Tags 操作日志
  78. // @Accept json
  79. // @Produce json
  80. // @Param token header string true " "
  81. // @Param page query int false " "
  82. // @Param page_size query int false " "
  83. // @Success 200 {object} v1.OperationLogListResponse
  84. // @Failure 500 {object} base.HTTPError
  85. // @Router /api/v1/operation_log [get]
  86. func (c *Controller) OperationLogList(ctx *gin.Context) {
  87. // 解析参数
  88. req := &param_v1.OperationLogListRequest{}
  89. parseParamTask := func() error {
  90. err := util.ShouldBind(ctx, &req.Header, nil, &req.OperationLogListQuery, nil)
  91. if err != nil {
  92. logger.Error("func",
  93. zap.String("call", "util.ShouldBind"),
  94. zap.String("error", err.Error()))
  95. return errors.ParamsError
  96. }
  97. return nil
  98. }
  99. // 业务处理
  100. handleServiceTask := func() error {
  101. // 响应数据
  102. resp := param_v1.OperationLogListResponse{}
  103. rpcReq := &apis.OperationLogListRequest{
  104. PageSize: req.PageSize,
  105. Page: req.Page,
  106. Start: req.Start,
  107. End: req.End,
  108. }
  109. rpcRsp, err := operation_log.OperationLogList(ctx, rpcReq)
  110. if err != nil {
  111. s, _ := json.MarshalToString(req)
  112. logger.Error("func",
  113. zap.String("call", "operation_log.OperationLogList"),
  114. zap.String("params", s),
  115. zap.String("error", err.Error()))
  116. return errors.ErrorTransForm(err)
  117. }
  118. if rpcRsp.List == nil {
  119. rpcRsp.List = make([]*apis.OperationLogItem, 0)
  120. }
  121. resp.Data = *rpcRsp
  122. ctx.JSON(http.StatusOK, resp)
  123. return nil
  124. }
  125. // 执行任务
  126. httptasker.Exec(ctx, parseParamTask, handleServiceTask)
  127. }