123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209 |
- 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-applete-gateway/errors"
- param_v1 "property-applete-gateway/param/v1"
- "property-applete-gateway/pb"
- "property-applete-gateway/pb/v1"
- "property-applete-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"
- // @Success 200 {object} v1.SystemMsgCountResponse
- // @Failure 500 {object} base.HTTPError
- // @Router /api/v1/system_msg/count [get]
- func (c *Controller) SystemMsgCount(ctx *gin.Context) {
- // 解析参数
- req := ¶m_v1.SystemMsgCountRequest{}
- parseParamTask := func() error {
- err := util.ShouldBind(ctx, &req.Header, nil, nil, 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.SystemMsgCountResponse{}
- rpcReq := &v1.SystemMsgCountRequest{
- GardenId:tokenInfo.GardenId,
- Codes:tokenInfo.Codes,
- Super:tokenInfo.Super,
- }
- rpcRsp, err := pb.Garden.SystemMsgCount(ctx, rpcReq)
- if err != nil {
- s, _ := json.MarshalToString(req)
- logger.Error("func",
- zap.String("call", "pb.Garden.SystemMsgCount"),
- zap.String("params", s),
- zap.String("error", err.Error()))
- return errors.ErrorTransForm(err)
- }
- resp.Data = *rpcRsp
- 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,
- Codes:tokenInfo.Codes,
- Super:tokenInfo.Super,
- 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)
- }
|