// 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) }