package v1 import ( "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" "net/http" "property-system-gateway/errors" param_v1 "property-system-gateway/param/v1" "property-system-gateway/pb" "property-system-gateway/pb/v1" "property-system-gateway/utils" ) // // @Summary 设置消息为已读 // @Description 设置消息为已读 // @Tags 系统消息 // @Accept json // @Produce json // @Param token header string true "token" // @Param body body v1.SystemMsgReadedBody true "信息" // @Success 200 {object} v1.VehicleAddResponse // @Failure 500 {object} base.HTTPError // @Router /api/v1/system_msg [put] func (c *Controller) SystemMsgReaded(ctx *gin.Context) { // 解析参数 req := ¶m_v1.SystemMsgReadedRequest{} parseParamTask := func() error { err := util.ShouldBind(ctx, &req.Header, nil, nil, &req.SystemMsgReadedBody) 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.GetSubjectValue(ctx) if err != nil { return err } // 响应数据 resp := param_v1.SystemMsgReadedResponse{} rpcReq := &v1.SystemMsgReadedRequest{ GardenId: tokenInfo.GardenId, Id: req.Id, } _, err = pb.Garden.SystemMsgReaded(ctx, rpcReq) if err != nil { s, _ := json.MarshalToString(req) logger.Error("func", zap.String("call", "pb.Garden.SystemMsgReaded"), 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 "token" // @Param page query int false " " // @Param page_size query int false " " // @Success 200 {object} v1.SystemMsgListResponse // @Failure 500 {object} base.HTTPError // @Router /api/v1/system_msg/list [get] func (c *Controller) SystemMsgList(ctx *gin.Context) { // 解析参数 req := ¶m_v1.SystemMsgListRequest{} parseParamTask := func() error { err := util.ShouldBind(ctx, &req.Header, nil, &req.SystemMsgListQuery, 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.GetSubjectValue(ctx) if err != nil { return err } // 响应数据 resp := param_v1.SystemMsgListResponse{} rpcReq := &v1.SystemMsgListRequest{ GardenId: tokenInfo.GardenId, Uid: tokenInfo.Uid, Page: req.Page, PageSize: req.PageSize, } rpcRsp, err := pb.Garden.SystemMsgList(ctx, rpcReq) if err != nil { s, _ := json.MarshalToString(req) logger.Error("func", zap.String("call", "pb.Garden.SystemMsgList"), zap.String("params", s), zap.String("error", err.Error())) return errors.ErrorTransForm(err) } if rpcRsp.List == nil { rpcRsp.List = make([]*v1.SystemMsgItem, 0) } resp.Data = *rpcRsp ctx.JSON(http.StatusOK, resp) return nil } // 执行任务 httptasker.Exec(ctx, parseParamTask, handleServiceTask) }