package v1 import ( "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" "net/http" "property-applete-gateway/errors" param_v1 "property-applete-gateway/param/v1" "property-applete-gateway/pb" "property-applete-gateway/pb/v1" "property-applete-gateway/utils" ) // // @Summary 添加公告 // @Description 添加公告 // @Tags 公告 // @Accept json // @Produce json // @Param token header string true "token" // @Param body body v1.AnnouncementAddBody true "信息" // @Success 200 {object} v1.AnnouncementAddResponse // @Failure 500 {object} base.HTTPError // @Router /api/v1/service/announcement [post] func (c *Controller) AnnouncementAdd(ctx *gin.Context) { // 解析参数 req := ¶m_v1.AnnouncementAddRequest{} parseParamTask := func() error { err := util.ShouldBind(ctx, &req.Header, nil, nil, &req.AnnouncementAddBody) 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.GetSubjectValue(ctx) if err != nil { return err } // 响应数据 resp := param_v1.AnnouncementAddResponse{} rpcReq := &v1.AnnouncementAddRequest{ GardenId:tokenInfo.GardenId, Content:req.Content, Title:req.Title, } rpcRsp, err := pb.Garden.AnnouncementAdd(ctx, rpcReq) if err != nil { s, _ := json.MarshalToString(req) logger.Error("func", zap.String("call", "pb.Garden.AnnouncementAdd"), zap.String("params", s), zap.String("error", err.Error())) return errors.ErrorTransForm(err) } resp.Data = *rpcRsp ctx.JSON(http.StatusOK, resp) logReq := OperationLogRequest{ Module:ModuleAnnouncement, Action:ActionAnnouncementAdd, Origin:nil, Target:req.AnnouncementAddBody, UserName:tokenInfo.UserName, Uid:tokenInfo.Uid, Cid:tokenInfo.Cid, GardenId:tokenInfo.GardenId, } go OperationLogAdd(&logReq) return nil } // 执行任务 httptasker.Exec(ctx, parseParamTask, handleServiceTask) } // // @Summary 修改公告 // @Description 修改公告 // @Tags 公告 // @Accept json // @Produce json // @Param token header string true "token" // @Param body body v1.AnnouncementUpdateBody true "信息" // @Success 200 {object} v1.AnnouncementUpdateResponse // @Failure 500 {object} base.HTTPError // @Router /api/v1/service/announcement [put] func (c *Controller) AnnouncementUpdate(ctx *gin.Context) { // 解析参数 req := ¶m_v1.AnnouncementUpdateRequest{} parseParamTask := func() error { err := util.ShouldBind(ctx, &req.Header, nil, nil, &req.AnnouncementUpdateBody) 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.GetSubjectValue(ctx) if err != nil { return err } // 响应数据 resp := param_v1.AnnouncementUpdateResponse{} rpcReq := &v1.AnnouncementUpdateRequest{ GardenId:tokenInfo.GardenId, Content:req.Content, Title:req.Title, Id:req.Id, } rpcRsp, err := pb.Garden.AnnouncementUpdate(ctx, rpcReq) if err != nil { s, _ := json.MarshalToString(req) logger.Error("func", zap.String("call", "pb.Garden.AnnouncementUpdate"), zap.String("params", s), zap.String("error", err.Error())) return errors.ErrorTransForm(err) } ctx.JSON(http.StatusOK, resp) logReq := OperationLogRequest{ Module:ModuleAnnouncement, Action:ActionAnnouncementUpdate, Origin:rpcRsp.Origin, Target:req.AnnouncementUpdateBody, UserName:tokenInfo.UserName, Uid:tokenInfo.Uid, Cid:tokenInfo.Cid, GardenId:tokenInfo.GardenId, } go OperationLogAdd(&logReq) return nil } // 执行任务 httptasker.Exec(ctx, parseParamTask, handleServiceTask) } // // @Summary 删除公告 // @Description 删除公告 // @Tags 公告 // @Accept json // @Produce json // @Param token header string true "token" // @Param id query int true " " // @Success 200 {object} v1.AnnouncementDelResponse // @Failure 500 {object} base.HTTPError // @Router /api/v1/service/announcement [delete] func (c *Controller) AnnouncementDel(ctx *gin.Context) { // 解析参数 req := ¶m_v1.AnnouncementDelRequest{} parseParamTask := func() error { err := util.ShouldBind(ctx, &req.Header, nil, &req.AnnouncementDelQuery, 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.GetSubjectValue(ctx) if err != nil { return err } // 响应数据 resp := param_v1.AnnouncementDelResponse{} rpcReq := &v1.AnnouncementDelRequest{ GardenId:tokenInfo.GardenId, Id:req.Id, } rpcRsp, err := pb.Garden.AnnouncementDel(ctx, rpcReq) if err != nil { s, _ := json.MarshalToString(req) logger.Error("func", zap.String("call", "pb.Garden.AnnouncementDel"), zap.String("params", s), zap.String("error", err.Error())) return errors.ErrorTransForm(err) } ctx.JSON(http.StatusOK, resp) logReq := OperationLogRequest{ Module:ModuleAnnouncement, Action:ActionAnnouncementDel, Origin:rpcRsp.Origin, Target:nil, UserName:tokenInfo.UserName, Uid:tokenInfo.Uid, Cid:tokenInfo.Cid, GardenId:tokenInfo.GardenId, } go OperationLogAdd(&logReq) return nil } // 执行任务 httptasker.Exec(ctx, parseParamTask, handleServiceTask) } // // @Summary 公告列表 // @Description 公告列表 // @Tags 公告 // @Accept json // @Produce json // @Param token header string true "token" // @Param page query int false " " // @Param page_size query int false " " // @Success 200 {object} v1.AnnouncementListResponse // @Failure 500 {object} base.HTTPError // @Router /api/v1/service/announcement [get] func (c *Controller) AnnouncementList(ctx *gin.Context) { // 解析参数 req := ¶m_v1.AnnouncementListRequest{} parseParamTask := func() error { err := util.ShouldBind(ctx, &req.Header, nil, &req.AnnouncementListQuery, 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.GetSubjectValue(ctx) if err != nil { return err } // 响应数据 resp := param_v1.AnnouncementListResponse{} rpcReq := &v1.AnnouncementListRequest{ GardenId:tokenInfo.GardenId, PageSize:req.PageSize, Page:req.Page, } rpcRsp, err := pb.Garden.AnnouncementList(ctx, rpcReq) if err != nil { s, _ := json.MarshalToString(req) logger.Error("func", zap.String("call", "pb.Garden.AnnouncementList"), zap.String("params", s), zap.String("error", err.Error())) return errors.ErrorTransForm(err) } if rpcRsp.List == nil { rpcRsp.List = make([]*v1.AnnouncementItem, 0) } resp.Data = *rpcRsp ctx.JSON(http.StatusOK, resp) return nil } // 执行任务 httptasker.Exec(ctx, parseParamTask, handleServiceTask) }