// 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/announcement [post] func (c *Controller) JtAnnouncementAdd(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.OperationModuleAnnouncement, 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.JtContentUpdateBody true " " // @Success 200 {object} v1.JtContentUpdateResponse // @Failure 500 {object} base.HTTPError // @Router /api/v1/jt/announcement [put] func (c *Controller) JtAnnouncementUpdate(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.OperationModuleAnnouncement, 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 body body v1.JtContentPublishBody true " " // @Success 200 {object} v1.JtContentPublishResponse // @Failure 500 {object} base.HTTPError // @Router /api/v1/jt/announcement/publish [put] func (c *Controller) JtAnnouncementPublish(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.OperationModuleAnnouncement, 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 id query int true " 记录id" // @Success 200 {object} v1.JtContentDelResponse // @Failure 500 {object} base.HTTPError // @Router /api/v1/jt/announcement [delete] func (c *Controller) JtAnnouncementDel(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.OperationModuleAnnouncement, 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 " " // @Param page query int false " " // @Param page_size query int false " " // @Success 200 {object} v1.JtContentListResponse // @Failure 500 {object} base.HTTPError // @Router /api/v1/jt/announcement [get] func (c *Controller) JtAnnouncementList(ctx *gin.Context) { // 解析参数 req := ¶m_v1.JtContentListRequest{} parseParamTask := func() error { err := util.ShouldBind(ctx, &req.Header, nil, &req.JtContentListQuery, 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.JtContentListResponse{} rpcReq := &apis.JtContentListRequest{ ContentType: consts.OperationModuleAnnouncement, PageSize: req.PageSize, Page: req.Page, 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 rpcRsp.List == nil { rpcRsp.List = make([]*apis.JtContentItem, 0) } resp.Data = *rpcRsp ctx.JSON(http.StatusOK, resp) return nil } // 执行任务 httptasker.Exec(ctx, parseParamTask, handleServiceTask) }