announcement.go 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. package v1_0
  2. import (
  3. "adm-gateway/errors"
  4. param_v1 "adm-gateway/param/v1"
  5. "adm-gateway/pb"
  6. v1 "adm-gateway/pb/v1"
  7. "net/http"
  8. "github.com/gin-gonic/gin"
  9. "git.getensh.com/common/gopkgsv2/logger"
  10. "git.getensh.com/common/gopkgsv2/tasker/httptasker"
  11. "git.getensh.com/common/gopkgsv2/util"
  12. "go.uber.org/zap"
  13. )
  14. // 信息公告
  15. // AnnouncementList godoc
  16. // @Summary 信息公告
  17. // @Description 信息公告
  18. // @Tags announcement,v1.0
  19. // @Accept json
  20. // @Produce json
  21. // @Param token header string true "jwt token"
  22. // @Param vin_rule query string false "vin"
  23. // @Param brand_name query string false "品牌"
  24. // @Param model_no query string false "车辆型号"
  25. // @Param page query int32 false "页码"
  26. // @Param page_size query int32 false "每页数量,默认10"
  27. // @Success 200 {object} param_v1.GetAnnouncementResponse
  28. // @Failure 500 {object} base.HTTPError
  29. // @Router /api/v1.0/announcement [get]
  30. func (c *Controller) AnnouncementList(ctx *gin.Context) {
  31. // 解析参数
  32. req := &param_v1.GetAnnouncementRequest{}
  33. parseParamTask := func() error {
  34. err := util.ShouldBind(ctx, nil, nil, &req.GetAnnouncementQuery, nil)
  35. if err != nil {
  36. logger.Error("func",
  37. zap.String("call", "util.ShouldBind"),
  38. zap.String("error", err.Error()))
  39. return errors.ParamsError
  40. }
  41. return nil
  42. }
  43. // 业务处理
  44. handleServiceTask := func() error {
  45. // 响应数据
  46. resp := &param_v1.GetAnnouncementResponse{}
  47. r := v1.AnnouncementRequest{
  48. VinRule: req.VinRule,
  49. BrandName: req.BrandName,
  50. ModelNo: req.ModelNo,
  51. Page: req.Page,
  52. PageSize: req.PageSize,
  53. }
  54. reply, err := pb.Management.AnnouncementList(ctx.Request.Context(), &r)
  55. if err != nil {
  56. s, _ := json.MarshalToString(r)
  57. logger.Error("func",
  58. zap.String("call", "pb.management.AnnouncementList"),
  59. zap.String("params", s),
  60. zap.String("error", err.Error()))
  61. return errors.ErrorTransForm(err)
  62. }
  63. if reply.List == nil {
  64. reply.List = make([]*v1.AnnouncementList, 0)
  65. }
  66. resp.Data = reply
  67. ctx.JSON(http.StatusOK, resp)
  68. return nil
  69. }
  70. // 执行任务
  71. httptasker.Exec(ctx, parseParamTask, handleServiceTask)
  72. }
  73. // 编辑
  74. // EditList godoc
  75. // @Summary 编辑
  76. // @Description 编辑
  77. // @Tags announcement,v1.0
  78. // @Accept json
  79. // @Produce json
  80. // @Param token header string true "jwt token"
  81. // @Param vehicle_batch query string false "vehicle_batch"
  82. // @Param model_no query string false "model_no"
  83. // @Success 200 {object} param_v1.GetEditResponse
  84. // @Failure 500 {object} base.HTTPError
  85. // @Router /api/v1.0/announcement/edit [get]
  86. func (c *Controller) EditList(ctx *gin.Context) {
  87. // 解析参数
  88. req := &param_v1.GetEditRequest{}
  89. parseParamTask := func() error {
  90. err := util.ShouldBind(ctx, nil, nil, &req.GetEditQuery, nil)
  91. if err != nil {
  92. logger.Error("func",
  93. zap.String("call", "util.ShouldBind"),
  94. zap.String("error", err.Error()))
  95. return errors.ParamsError
  96. }
  97. return nil
  98. }
  99. // 业务处理
  100. handleServiceTask := func() error {
  101. // 响应数据
  102. resp := &param_v1.GetEditResponse{}
  103. r := v1.EditRequest{
  104. VehicleBatch: req.VehicleBatch,
  105. ModelNo: req.ModelNo,
  106. }
  107. reply, err := pb.Management.Edit(ctx.Request.Context(), &r)
  108. if err != nil {
  109. s, _ := json.MarshalToString(r)
  110. logger.Error("func",
  111. zap.String("call", "pb.management.Edit"),
  112. zap.String("params", s),
  113. zap.String("error", err.Error()))
  114. return errors.ErrorTransForm(err)
  115. }
  116. if reply.List == nil {
  117. reply.List = make([]*v1.EditList, 0)
  118. }
  119. resp.Data = reply
  120. ctx.JSON(http.StatusOK, resp)
  121. return nil
  122. }
  123. // 执行任务
  124. httptasker.Exec(ctx, parseParamTask, handleServiceTask)
  125. }