123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338 |
- // Copyright 2019 github.com. All rights reserved.
- // Use of this source code is governed by github.com.
- package v1
- import (
- "net/http"
- "xingjia-management-gateway/apis"
- "xingjia-management-gateway/consts"
- "xingjia-management-gateway/errors"
- "xingjia-management-gateway/impl/v1/jt"
- param_v1 "xingjia-management-gateway/param/v1"
- "xingjia-management-gateway/utils"
- "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"
- )
- //
- // @Summary 添加发展愿景
- // @Description 添加发展愿景
- // @Tags 发展愿景
- // @Accept json
- // @Produce json
- // @Param token header string true " "
- // @Param body body v1.JtContentAddBody true " "
- // @Success 200 {object} v1.JtContentAddResponse
- // @Failure 500 {object} base.HTTPError
- // @Router /api/v1/jt/vision [post]
- func (c *Controller) JtVisionAdd(ctx *gin.Context) {
- // 解析参数
- req := ¶m_v1.JtContentAddRequest{}
- parseParamTask := func() error {
- err := util.ShouldBind(ctx, &req.Header, nil, nil, &req.JtContentAddBody)
- 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.GetJwtTokenFromCtx(ctx)
- if err != nil {
- return err
- }
- // 响应数据
- resp := param_v1.JtContentAddResponse{}
- rpcReq := &apis.JtContentAddRequest{
- FirstPics: req.FirstPics,
- ContentType: consts.OperationModuleVision,
- Content: req.Content,
- SelfId: tokenInfo.Uid,
- SelfName: tokenInfo.User,
- PublishStatus: req.PublishStatus,
- Title: req.Title,
- }
- _, err = jt.JtContentAdd(ctx, rpcReq)
- if err != nil {
- s, _ := json.MarshalToString(req)
- logger.Error("func",
- zap.String("call", "jt.JtContentAdd"),
- 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 " "
- // @Param body body v1.JtContentPublishBody true " "
- // @Success 200 {object} v1.JtContentPublishResponse
- // @Failure 500 {object} base.HTTPError
- // @Router /api/v1/jt/vision/publish [put]
- func (c *Controller) JtVisionPublish(ctx *gin.Context) {
- // 解析参数
- req := ¶m_v1.JtContentPublishRequest{}
- parseParamTask := func() error {
- err := util.ShouldBind(ctx, &req.Header, nil, nil, &req.JtContentPublishBody)
- 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.GetJwtTokenFromCtx(ctx)
- if err != nil {
- return err
- }
- // 响应数据
- resp := param_v1.JtContentPublishResponse{}
- rpcReq := &apis.JtContentPublishRequest{
- ContentType: consts.OperationModuleVision,
- SelfId: tokenInfo.Uid,
- SelfName: tokenInfo.User,
- Id: req.Id,
- PublishStatus: req.PublishStatus,
- }
- _, err = jt.JtContentPublish(ctx, rpcReq)
- if err != nil {
- s, _ := json.MarshalToString(req)
- logger.Error("func",
- zap.String("call", "jt.JtContentPublish"),
- 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 " "
- // @Param body body v1.JtContentUpdateBody true " "
- // @Success 200 {object} v1.JtContentUpdateResponse
- // @Failure 500 {object} base.HTTPError
- // @Router /api/v1/jt/vision [put]
- func (c *Controller) JtVisionUpdate(ctx *gin.Context) {
- // 解析参数
- req := ¶m_v1.JtContentUpdateRequest{}
- parseParamTask := func() error {
- err := util.ShouldBind(ctx, &req.Header, nil, nil, &req.JtContentUpdateBody)
- 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.GetJwtTokenFromCtx(ctx)
- if err != nil {
- return err
- }
- // 响应数据
- resp := param_v1.JtContentUpdateResponse{}
- rpcReq := &apis.JtContentUpdateRequest{
- FirstPics: req.FirstPics,
- ContentType: consts.OperationModuleVision,
- Content: req.Content,
- SelfId: tokenInfo.Uid,
- SelfName: tokenInfo.User,
- Id: req.Id,
- PublishStatus: req.PublishStatus,
- Title: req.Title,
- }
- _, err = jt.JtContentUpdate(ctx, rpcReq)
- if err != nil {
- s, _ := json.MarshalToString(req)
- logger.Error("func",
- zap.String("call", "jt.JtContentUpdate"),
- 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 " "
- // @Param id query int true " 记录id"
- // @Success 200 {object} v1.JtContentDelResponse
- // @Failure 500 {object} base.HTTPError
- // @Router /api/v1/jt/vision [delete]
- func (c *Controller) JtVisionDel(ctx *gin.Context) {
- // 解析参数
- req := ¶m_v1.JtContentDelRequest{}
- parseParamTask := func() error {
- err := util.ShouldBind(ctx, &req.Header, nil, &req.JtContentDelQuery, 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.GetJwtTokenFromCtx(ctx)
- if err != nil {
- return err
- }
- // 响应数据
- resp := param_v1.JtContentDelResponse{}
- rpcReq := &apis.JtContentDelRequest{
- ContentType: consts.OperationModuleVision,
- SelfId: tokenInfo.Uid,
- SelfName: tokenInfo.User,
- Id: req.Id,
- }
- _, err = jt.JtContentDel(ctx, rpcReq)
- if err != nil {
- s, _ := json.MarshalToString(req)
- logger.Error("func",
- zap.String("call", "jt.JtContentDel"),
- 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 " "
- // @Success 200 {object} v1.JtContentInfoResponse
- // @Failure 500 {object} base.HTTPError
- // @Router /api/v1/jt/vision [get]
- func (c *Controller) JtVisionInfo(ctx *gin.Context) {
- // 解析参数
- req := ¶m_v1.JtContentInfoRequest{}
- 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.GetJwtTokenFromCtx(ctx)
- if err != nil {
- return err
- }
- // 响应数据
- resp := param_v1.JtContentInfoResponse{}
- rpcReq := &apis.JtContentListRequest{
- ContentType: consts.OperationModuleVision,
- SelfId: tokenInfo.Uid,
- }
- rpcRsp, err := jt.JtContentList(ctx, rpcReq)
- if err != nil {
- s, _ := json.MarshalToString(req)
- logger.Error("func",
- zap.String("call", "jt.JtContentList"),
- zap.String("params", s),
- zap.String("error", err.Error()))
- return errors.ErrorTransForm(err)
- }
- if len(rpcRsp.List) == 0 {
- if len(resp.Data.FirstPics) == 0 {
- resp.Data.FirstPics = make([]string, 0)
- }
- ctx.JSON(http.StatusOK, resp)
- return nil
- }
- resp.Data.FirstPics = rpcRsp.List[0].FirstPics
- resp.Data.Title = rpcRsp.List[0].Title
- resp.Data.Content = rpcRsp.List[0].Content
- resp.Data.CreatedAt = rpcRsp.List[0].CreatedAt
- resp.Data.Id = rpcRsp.List[0].Id
- resp.Data.PublishStatus = rpcRsp.List[0].PublishStatus
- ctx.JSON(http.StatusOK, resp)
- return nil
- }
- // 执行任务
- httptasker.Exec(ctx, parseParamTask, handleServiceTask)
- }
|