123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400 |
- 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-system-gateway/errors"
- param_v1 "property-system-gateway/param/v1"
- "property-system-gateway/pb"
- "property-system-gateway/pb/v1"
- "property-system-gateway/utils"
- )
- //
- // @Summary 添加社区活动
- // @Description 添加社区活动
- // @Tags 社区活动
- // @Accept json
- // @Produce json
- // @Param token header string true "token"
- // @Param body body v1.EventAddBody true "信息"
- // @Success 200 {object} v1.EventAddResponse
- // @Failure 500 {object} base.HTTPError
- // @Router /api/v1/service/event [post]
- func (c *Controller) EventAdd(ctx *gin.Context) {
- // 解析参数
- req := ¶m_v1.EventAddRequest{}
- parseParamTask := func() error {
- err := util.ShouldBind(ctx, &req.Header, nil, nil, &req.EventAddBody)
- 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.EventAddResponse{}
- rpcReq := &v1.EventAddRequest{
- GardenId: tokenInfo.GardenId,
- Content: req.Content,
- Title: req.Title,
- Addr: req.Addr,
- Pic: req.Pic,
- PeopleLimit: req.PeopleLimit,
- Start: req.Start,
- End: req.End,
- SignUpEnd: req.SignUpEnd,
- Fee: req.Fee,
- }
- rpcRsp, err := pb.Garden.EventAdd(ctx, rpcReq)
- if err != nil {
- s, _ := json.MarshalToString(req)
- logger.Error("func",
- zap.String("call", "pb.Garden.EventAdd"),
- zap.String("params", s),
- zap.String("error", err.Error()))
- return errors.ErrorTransForm(err)
- }
- resp.Data = *rpcRsp
- ctx.JSON(http.StatusOK, resp)
- return nil
- }
- // 执行任务
- httptasker.Exec(ctx, parseParamTask, handleServiceTask)
- }
- //
- // @Summary 修改社区活动
- // @Description 修改社区活动
- // @Tags 社区活动
- // @Accept json
- // @Produce json
- // @Param token header string true "token"
- // @Param body body v1.EventUpdateBody true "信息"
- // @Success 200 {object} v1.EventUpdateResponse
- // @Failure 500 {object} base.HTTPError
- // @Router /api/v1/service/event [put]
- func (c *Controller) EventUpdate(ctx *gin.Context) {
- // 解析参数
- req := ¶m_v1.EventUpdateRequest{}
- parseParamTask := func() error {
- err := util.ShouldBind(ctx, &req.Header, nil, nil, &req.EventUpdateBody)
- 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.EventUpdateResponse{}
- rpcReq := &v1.EventUpdateRequest{
- GardenId: tokenInfo.GardenId,
- Content: req.Content,
- Title: req.Title,
- Addr: req.Addr,
- Pic: req.Pic,
- PeopleLimit: req.PeopleLimit,
- Start: req.Start,
- End: req.End,
- SignUpEnd: req.SignUpEnd,
- Id: req.Id,
- Fee: req.Fee,
- }
- _, err = pb.Garden.EventUpdate(ctx, rpcReq)
- if err != nil {
- s, _ := json.MarshalToString(req)
- logger.Error("func",
- zap.String("call", "pb.Garden.EventUpdate"),
- 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 "token"
- // @Param id query int true " "
- // @Success 200 {object} v1.EventDelResponse
- // @Failure 500 {object} base.HTTPError
- // @Router /api/v1/service/event [delete]
- func (c *Controller) EventDel(ctx *gin.Context) {
- // 解析参数
- req := ¶m_v1.EventDelRequest{}
- parseParamTask := func() error {
- err := util.ShouldBind(ctx, &req.Header, nil, &req.EventDelQuery, 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.EventDelResponse{}
- rpcReq := &v1.EventDelRequest{
- GardenId: tokenInfo.GardenId,
- Id: req.Id,
- }
- _, err = pb.Garden.EventDel(ctx, rpcReq)
- if err != nil {
- s, _ := json.MarshalToString(req)
- logger.Error("func",
- zap.String("call", "pb.Garden.EventDel"),
- 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 "token"
- // @Param page query int false " "
- // @Param page_size query int false " "
- // @Success 200 {object} v1.EventListResponse
- // @Failure 500 {object} base.HTTPError
- // @Router /api/v1/service/event [get]
- func (c *Controller) EventList(ctx *gin.Context) {
- // 解析参数
- req := ¶m_v1.EventListRequest{}
- parseParamTask := func() error {
- err := util.ShouldBind(ctx, &req.Header, nil, &req.EventListQuery, 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.EventListResponse{}
- rpcReq := &v1.EventListRequest{
- GardenId: tokenInfo.GardenId,
- PageSize: req.PageSize,
- Page: req.Page,
- }
- rpcRsp, err := pb.Garden.EventList(ctx, rpcReq)
- if err != nil {
- s, _ := json.MarshalToString(req)
- logger.Error("func",
- zap.String("call", "pb.Garden.EventList"),
- zap.String("params", s),
- zap.String("error", err.Error()))
- return errors.ErrorTransForm(err)
- }
- if rpcRsp.List == nil {
- rpcRsp.List = make([]*v1.EventItem, 0)
- }
- resp.Data = *rpcRsp
- ctx.JSON(http.StatusOK, resp)
- 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.EventSignDelResponse
- // @Failure 500 {object} base.HTTPError
- // @Router /api/v1/service/event/sign [delete]
- func (c *Controller) EventSignDel(ctx *gin.Context) {
- // 解析参数
- req := ¶m_v1.EventSignDelRequest{}
- parseParamTask := func() error {
- err := util.ShouldBind(ctx, &req.Header, nil, &req.EventSignDelQuery, 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.EventSignDelResponse{}
- rpcReq := &v1.EventSignDelRequest{
- GardenId: tokenInfo.GardenId,
- Id: req.Id,
- }
- _, err = pb.Garden.EventSignDel(ctx, rpcReq)
- if err != nil {
- s, _ := json.MarshalToString(req)
- logger.Error("func",
- zap.String("call", "pb.Garden.EventSignDel"),
- 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 "token"
- // @Param page query int false " "
- // @Param page_size query int false " "
- // @Param event_id query int true "活动id"
- // @Success 200 {object} v1.EventSignListResponse
- // @Failure 500 {object} base.HTTPError
- // @Router /api/v1/service/event/sign [get]
- func (c *Controller) EventSignList(ctx *gin.Context) {
- // 解析参数
- req := ¶m_v1.EventSignListRequest{}
- parseParamTask := func() error {
- err := util.ShouldBind(ctx, &req.Header, nil, &req.EventSignListQuery, 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.EventSignListResponse{}
- rpcReq := &v1.EventSignListRequest{
- GardenId: tokenInfo.GardenId,
- PageSize: req.PageSize,
- Page: req.Page,
- EventId: req.EventId,
- }
- rpcRsp, err := pb.Garden.EventSignList(ctx, rpcReq)
- if err != nil {
- s, _ := json.MarshalToString(req)
- logger.Error("func",
- zap.String("call", "pb.Garden.EventSignList"),
- zap.String("params", s),
- zap.String("error", err.Error()))
- return errors.ErrorTransForm(err)
- }
- if rpcRsp.List == nil {
- rpcRsp.List = make([]*v1.EventSignItem, 0)
- }
- resp.Data = *rpcRsp
- ctx.JSON(http.StatusOK, resp)
- return nil
- }
- // 执行任务
- httptasker.Exec(ctx, parseParamTask, handleServiceTask)
- }
|