announcement.go 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. package v1
  2. import (
  3. "git.getensh.com/common/gopkgs/logger"
  4. "git.getensh.com/common/gopkgs/tasker/httptasker"
  5. "git.getensh.com/common/gopkgs/util"
  6. "github.com/gin-gonic/gin"
  7. "go.uber.org/zap"
  8. "net/http"
  9. "property-household-gateway/errors"
  10. param_v1 "property-household-gateway/param/v1"
  11. "property-household-gateway/pb"
  12. "property-household-gateway/pb/v1"
  13. "property-household-gateway/utils"
  14. )
  15. //
  16. // @Summary 公告列表
  17. // @Description 公告列表
  18. // @Tags 公告
  19. // @Accept json
  20. // @Produce json
  21. // @Param token header string true "token"
  22. // @Param page query int false " "
  23. // @Param page_size query int false " "
  24. // @Param garden_id query int true "小区id"
  25. // @Success 200 {object} v1.AnnouncementListResponse
  26. // @Failure 500 {object} base.HTTPError
  27. // @Router /api/v1/service/announcement [get]
  28. func (c *Controller) AnnouncementList(ctx *gin.Context) {
  29. // 解析参数
  30. req := &param_v1.AnnouncementListRequest{}
  31. parseParamTask := func() error {
  32. err := util.ShouldBind(ctx, &req.Header, nil, &req.AnnouncementListQuery, nil)
  33. if err != nil {
  34. logger.Error("func",
  35. zap.String("call", "util.ShouldBind"),
  36. zap.String("error", err.Error()))
  37. return errors.ParamsError
  38. }
  39. return nil
  40. }
  41. // 业务处理
  42. handleServiceTask := func() error {
  43. tokenInfo, err := utils.GetJwtTokenInfo(ctx)
  44. if err != nil {
  45. return err
  46. }
  47. //响应数据
  48. resp := param_v1.AnnouncementListResponse{}
  49. rpcReq := &v1.AnnouncementListRequest{
  50. GardenId: req.GardenId,
  51. PageSize: req.PageSize,
  52. Page: req.Page,
  53. Uid: tokenInfo.Uid,
  54. }
  55. rpcRsp, err := pb.Garden.AnnouncementList(ctx, rpcReq)
  56. if err != nil {
  57. s, _ := json.MarshalToString(req)
  58. logger.Error("func",
  59. zap.String("call", "pb.Garden.AnnouncementList"),
  60. zap.String("params", s),
  61. zap.String("error", err.Error()))
  62. return errors.ErrorTransForm(err)
  63. }
  64. if rpcRsp.List == nil {
  65. rpcRsp.List = make([]*v1.AnnouncementItem, 0)
  66. }
  67. resp.Data = *rpcRsp
  68. ctx.JSON(http.StatusOK, resp)
  69. return nil
  70. }
  71. // 执行任务
  72. httptasker.Exec(ctx, parseParamTask, handleServiceTask)
  73. }
  74. //
  75. // @Summary 公告增加阅读次数
  76. // @Description 公告增加阅读次数
  77. // @Tags 公告
  78. // @Accept json
  79. // @Produce json
  80. // @Param token header string true "token"
  81. // @Param page query int false " "
  82. // @Param page_size query int false " "
  83. // @Param garden_id query int true "小区id"
  84. // @Param id query int true "公告id"
  85. // @Success 200 {object} v1.AnnouncementReadAddResponse
  86. // @Failure 500 {object} base.HTTPError
  87. // @Router /api/v1/service/announcement/read_count [put]
  88. func (c *Controller) AnnouncementReadAdd(ctx *gin.Context) {
  89. // 解析参数
  90. req := &param_v1.AnnouncementReadAddRequest{}
  91. parseParamTask := func() error {
  92. err := util.ShouldBind(ctx, &req.Header, nil, nil, &req.AnnouncementReadAddBody)
  93. if err != nil {
  94. logger.Error("func",
  95. zap.String("call", "util.ShouldBind"),
  96. zap.String("error", err.Error()))
  97. return errors.ParamsError
  98. }
  99. return nil
  100. }
  101. // 业务处理
  102. handleServiceTask := func() error {
  103. tokenInfo, err := utils.GetJwtTokenInfo(ctx)
  104. if err != nil {
  105. return err
  106. }
  107. //响应数据
  108. resp := param_v1.AnnouncementReadAddResponse{}
  109. rpcReq := &v1.AnnouncementReadAddRequest{
  110. GardenId: req.GardenId,
  111. Id: req.Id,
  112. Uid: tokenInfo.Uid,
  113. }
  114. _, err = pb.Garden.AnnouncementReadAdd(ctx, rpcReq)
  115. if err != nil {
  116. s, _ := json.MarshalToString(req)
  117. logger.Error("func",
  118. zap.String("call", "pb.Garden.AnnouncementReadAdd"),
  119. zap.String("params", s),
  120. zap.String("error", err.Error()))
  121. return errors.ErrorTransForm(err)
  122. }
  123. ctx.JSON(http.StatusOK, resp)
  124. return nil
  125. }
  126. // 执行任务
  127. httptasker.Exec(ctx, parseParamTask, handleServiceTask)
  128. }