123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144 |
- // Copyright 2019 github.com. All rights reserved.
- // Use of this source code is governed by github.com.
- package v1
- import (
- "net/http"
- "strconv"
- "strings"
- "xingjia-management-gateway/apis"
- "xingjia-management-gateway/errors"
- "xingjia-management-gateway/impl/v1/operation_log"
- param_v1 "xingjia-management-gateway/param/v1"
- "xingjia-management-gateway/utils"
- "git.getensh.com/common/gopkgs/logger"
- "git.getensh.com/common/gopkgs/tasker/httptasker"
- "git.getensh.com/common/gopkgs/util"
- "github.com/gin-gonic/gin"
- "go.uber.org/zap"
- )
- //
- // @Summary 批量删除操作日志
- // @Description 批量删除操作日志
- // @Tags 操作日志
- // @Accept json
- // @Produce json
- // @Param token header string true " "
- // @Param ids query string true " 日志id,以英文分号分割"
- // @Success 200 {object} v1.OperationLogDelResponse
- // @Failure 500 {object} base.HTTPError
- // @Router /api/v1/operation_log [delete]
- func (c *Controller) OperationLogDel(ctx *gin.Context) {
- // 解析参数
- req := ¶m_v1.OperationLogDelRequest{}
- parseParamTask := func() error {
- err := util.ShouldBind(ctx, &req.Header, nil, &req.OperationLogDelQuery, nil)
- if err != nil {
- logger.Error("func",
- zap.String("call", "util.ShouldBind"),
- zap.String("error", err.Error()))
- return errors.ParamsError
- }
- return nil
- }
- // 业务处理
- handleServiceTask := func() error {
- tokenInfo, err := utils.GetJwtTokenFromCtx(ctx)
- if err != nil {
- return err
- }
- // 响应数据
- resp := param_v1.OperationLogDelResponse{}
- rpcReq := &apis.OperationLogDelRequest{
- SelfId: tokenInfo.Uid,
- }
- array := strings.Split(req.Ids, ";")
- rpcReq.Ids = make([]int64, len(array))
- for i, v := range array {
- rpcReq.Ids[i], _ = strconv.ParseInt(v, 10, 64)
- }
- _, err = operation_log.OperationLogDel(ctx, rpcReq)
- if err != nil {
- s, _ := json.MarshalToString(req)
- logger.Error("func",
- zap.String("call", "operation_log.OperationLogDel"),
- zap.String("params", s),
- zap.String("error", err.Error()))
- return errors.ErrorTransForm(err)
- }
- ctx.JSON(http.StatusOK, resp)
- return nil
- }
- // 执行任务
- httptasker.Exec(ctx, parseParamTask, handleServiceTask)
- }
- //
- // @Summary 操作日志列表
- // @Description 操作日志列表
- // @Tags 操作日志
- // @Accept json
- // @Produce json
- // @Param token header string true " "
- // @Param page query int false " "
- // @Param page_size query int false " "
- // @Success 200 {object} v1.OperationLogListResponse
- // @Failure 500 {object} base.HTTPError
- // @Router /api/v1/operation_log [get]
- func (c *Controller) OperationLogList(ctx *gin.Context) {
- // 解析参数
- req := ¶m_v1.OperationLogListRequest{}
- parseParamTask := func() error {
- err := util.ShouldBind(ctx, &req.Header, nil, &req.OperationLogListQuery, nil)
- if err != nil {
- logger.Error("func",
- zap.String("call", "util.ShouldBind"),
- zap.String("error", err.Error()))
- return errors.ParamsError
- }
- return nil
- }
- // 业务处理
- handleServiceTask := func() error {
- // 响应数据
- resp := param_v1.OperationLogListResponse{}
- rpcReq := &apis.OperationLogListRequest{
- PageSize: req.PageSize,
- Page: req.Page,
- Start: req.Start,
- End: req.End,
- }
- rpcRsp, err := operation_log.OperationLogList(ctx, rpcReq)
- if err != nil {
- s, _ := json.MarshalToString(req)
- logger.Error("func",
- zap.String("call", "operation_log.OperationLogList"),
- zap.String("params", s),
- zap.String("error", err.Error()))
- return errors.ErrorTransForm(err)
- }
- if rpcRsp.List == nil {
- rpcRsp.List = make([]*apis.OperationLogItem, 0)
- }
- resp.Data = *rpcRsp
- ctx.JSON(http.StatusOK, resp)
- return nil
- }
- // 执行任务
- httptasker.Exec(ctx, parseParamTask, handleServiceTask)
- }
|