123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119 |
- package v1
- import (
- "context"
- "cp-organization-management-gateway/errors"
- param_v1 "cp-organization-management-gateway/param/v1"
- "cp-organization-management-gateway/pb"
- "cp-organization-management-gateway/pb/v1"
- "github.com/jaryhe/gopkgs/logger"
- "github.com/jaryhe/gopkgs/tasker/httptasker"
- "github.com/jaryhe/gopkgs/util"
- "net/http"
- "time"
- "github.com/gin-gonic/gin"
- "go.uber.org/zap"
- )
- //
- // @Summary 获取日志列表
- // @Description 获取日志列表
- // @Tags 操作日志
- // @Accept json
- // @Produce json
- // @Param token header string true "token"
- // @Param page query int64 false " "
- // @Param page_size query int64 false " "
- // @Success 200 {object} v1.ManagementLogListResponse
- // @Failure 500 {object} base.HTTPError
- // @Router /api/v1/log/list [get]
- func (c *Controller) ManagementLogList(ctx *gin.Context) {
- // 解析参数
- req := ¶m_v1.ManagementLogListRequest{}
- parseParamTask := func() error {
- err := util.ShouldBind(ctx, &req.Header, nil, &req.ManagementLogListQuery, 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.ManagementLogListResponse{}
- rpcReq := &v1.ManagementLogListRequest{
- Page:req.Page,
- PageSize:req.PageSize,
- }
- rpcRsp, err := pb.Organization.ManagementLogList(ctx, rpcReq)
- if err != nil {
- s, _ := json.MarshalToString(req)
- logger.Error("func",
- zap.String("call", "pb.Organization.ManagementLogList"),
- zap.String("params", s),
- zap.String("error", err.Error()))
- return errors.ErrorTransForm(err)
- }
- if rpcRsp.List == nil {
- rpcRsp.List = make([]*v1.ManagementLogItem, 0)
- }
- resp.Data = *rpcRsp
- ctx.JSON(http.StatusOK, resp)
- return nil
- }
- // 执行任务
- httptasker.Exec(ctx, parseParamTask, handleServiceTask)
- }
- type OperationLogRequest struct {
- Module string
- Action string
- UserName string
- Uid int64
- Origin interface{}
- Target interface{}
- OrganizationCode string
- }
- func OperationLogAdd(req *OperationLogRequest) {
- mreq := v1.ManagementLogAddRequest{
- Module:req.Module,
- Action:req.Action,
- Username:req.UserName,
- Uid:req.Uid,
- CreatedAt:time.Now().Unix(),
- OrganizationCode:req.OrganizationCode,
- }
- if req.Origin != nil {
- origin, _ := json.Marshal(req.Origin)
- mreq.Origin = string(origin)
- }
- if req.Target != nil {
- target, _ := json.Marshal(req.Target)
- mreq.Target = string(target)
- }
- _, err := pb.Organization.ManagementLogAdd(context.Background(), &mreq)
- if err != nil {
- s, _ := json.Marshal(mreq)
- logger.Error("func",
- zap.String("call", "pb.Organization.ManagementLogAdd"),
- zap.String("params", string(s)),
- zap.String("error", err.Error()))
- }
- }
|