123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145 |
- 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-household-gateway/errors"
- param_v1 "property-household-gateway/param/v1"
- "property-household-gateway/pb"
- "property-household-gateway/pb/v1"
- "property-household-gateway/utils"
- )
- //
- // @Summary 公告列表
- // @Description 公告列表
- // @Tags 公告
- // @Accept json
- // @Produce json
- // @Param token header string true "token"
- // @Param page query int false " "
- // @Param page_size query int false " "
- // @Param garden_id query int true "小区id"
- // @Success 200 {object} v1.AnnouncementListResponse
- // @Failure 500 {object} base.HTTPError
- // @Router /api/v1/service/announcement [get]
- func (c *Controller) AnnouncementList(ctx *gin.Context) {
- // 解析参数
- req := ¶m_v1.AnnouncementListRequest{}
- parseParamTask := func() error {
- err := util.ShouldBind(ctx, &req.Header, nil, &req.AnnouncementListQuery, 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.GetJwtTokenInfo(ctx)
- if err != nil {
- return err
- }
- //响应数据
- resp := param_v1.AnnouncementListResponse{}
- rpcReq := &v1.AnnouncementListRequest{
- GardenId: req.GardenId,
- PageSize: req.PageSize,
- Page: req.Page,
- Uid: tokenInfo.Uid,
- }
- rpcRsp, err := pb.Garden.AnnouncementList(ctx, rpcReq)
- if err != nil {
- s, _ := json.MarshalToString(req)
- logger.Error("func",
- zap.String("call", "pb.Garden.AnnouncementList"),
- zap.String("params", s),
- zap.String("error", err.Error()))
- return errors.ErrorTransForm(err)
- }
- if rpcRsp.List == nil {
- rpcRsp.List = make([]*v1.AnnouncementItem, 0)
- }
- 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 " "
- // @Param garden_id query int true "小区id"
- // @Param id query int true "公告id"
- // @Success 200 {object} v1.AnnouncementReadAddResponse
- // @Failure 500 {object} base.HTTPError
- // @Router /api/v1/service/announcement/read_count [put]
- func (c *Controller) AnnouncementReadAdd(ctx *gin.Context) {
- // 解析参数
- req := ¶m_v1.AnnouncementReadAddRequest{}
- parseParamTask := func() error {
- err := util.ShouldBind(ctx, &req.Header, nil, nil, &req.AnnouncementReadAddBody)
- 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.GetJwtTokenInfo(ctx)
- if err != nil {
- return err
- }
- //响应数据
- resp := param_v1.AnnouncementReadAddResponse{}
- rpcReq := &v1.AnnouncementReadAddRequest{
- GardenId: req.GardenId,
- Id: req.Id,
- Uid: tokenInfo.Uid,
- }
- _, err = pb.Garden.AnnouncementReadAdd(ctx, rpcReq)
- if err != nil {
- s, _ := json.MarshalToString(req)
- logger.Error("func",
- zap.String("call", "pb.Garden.AnnouncementReadAdd"),
- 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)
- }
|