jt_vision.go 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. // Copyright 2019 github.com. All rights reserved.
  2. // Use of this source code is governed by github.com.
  3. package v1
  4. import (
  5. "git.getensh.com/common/gopkgs/logger"
  6. "git.getensh.com/common/gopkgs/tasker/httptasker"
  7. "git.getensh.com/common/gopkgs/util"
  8. "github.com/gin-gonic/gin"
  9. "go.uber.org/zap"
  10. "net/http"
  11. "xingjia-official-gateway/apis"
  12. "xingjia-official-gateway/consts"
  13. "xingjia-official-gateway/errors"
  14. "xingjia-official-gateway/impl/v1/jt"
  15. param_v1 "xingjia-official-gateway/param/v1"
  16. )
  17. //
  18. // @Summary 发展愿景信息
  19. // @Description 发展愿景信息
  20. // @Tags 发展愿景
  21. // @Accept json
  22. // @Produce json
  23. // @Success 200 {object} v1.JtContentInfoResponse
  24. // @Failure 500 {object} base.HTTPError
  25. // @Router /api/v1/jt/vision [get]
  26. func (c *Controller) JtVisionInfo(ctx *gin.Context) {
  27. // 解析参数
  28. req := &param_v1.JtContentInfoRequest{}
  29. parseParamTask := func() error {
  30. err := util.ShouldBind(ctx, nil, nil, nil, nil)
  31. if err != nil {
  32. logger.Error("func",
  33. zap.String("call", "util.ShouldBind"),
  34. zap.String("error", err.Error()))
  35. return errors.ParamsError
  36. }
  37. return nil
  38. }
  39. // 业务处理
  40. handleServiceTask := func() error {
  41. // 响应数据
  42. resp := param_v1.JtContentInfoResponse{}
  43. rpcReq := &apis.JtContentListRequest{
  44. ContentType: consts.OperationModuleVision,
  45. }
  46. rpcRsp, err := jt.JtContentList(ctx, rpcReq)
  47. if err != nil {
  48. s, _ := json.MarshalToString(req)
  49. logger.Error("func",
  50. zap.String("call", "jt.JtContentList"),
  51. zap.String("params", s),
  52. zap.String("error", err.Error()))
  53. return errors.ErrorTransForm(err)
  54. }
  55. if len(rpcRsp.List) == 0 {
  56. ctx.JSON(http.StatusOK, resp)
  57. return nil
  58. }
  59. resp.Data.FirstPics = rpcRsp.List[0].FirstPics
  60. resp.Data.Title = rpcRsp.List[0].Title
  61. resp.Data.Content = rpcRsp.List[0].Content
  62. resp.Data.CreatedAt = rpcRsp.List[0].CreatedAt
  63. resp.Data.Id = rpcRsp.List[0].Id
  64. resp.Data.PublishStatus = rpcRsp.List[0].PublishStatus
  65. ctx.JSON(http.StatusOK, resp)
  66. return nil
  67. }
  68. // 执行任务
  69. httptasker.Exec(ctx, parseParamTask, handleServiceTask)
  70. }