123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597 |
- 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.ParkAddBody true "信息"
- // @Success 200 {object} v1.ParkAddResponse
- // @Failure 500 {object} base.HTTPError
- // @Router /api/v1/park [post]
- func (c *Controller) ParkAdd(ctx *gin.Context) {
- // 解析参数
- req := ¶m_v1.ParkAddRequest{}
- parseParamTask := func() error {
- err := util.ShouldBind(ctx, &req.Header, nil, nil, &req.ParkAddBody)
- 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.ParkAddResponse{}
- rpcReq := &v1.ParkAddRequest{
- GardenId:tokenInfo.GardenId,
- ParkName:req.ParkName,
- ParkNumber:req.ParkNumber,
- ParkType:req.ParkType,
- Comment:req.Comment,
- }
- rpcRsp, err := pb.Garden.ParkAdd(ctx, rpcReq)
- if err != nil {
- s, _ := json.MarshalToString(req)
- logger.Error("func",
- zap.String("call", "pb.Garden.ParkAdd"),
- zap.String("params", s),
- zap.String("error", err.Error()))
- return errors.ErrorTransForm(err)
- }
- resp.Data = *rpcRsp
- ctx.JSON(http.StatusOK, resp)
- logReq := OperationLogRequest{
- Module:ModulePark,
- Action:ActionParkAdd,
- Origin:nil,
- Target:req.ParkAddBody,
- 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.ParkUpdateBody true "信息"
- // @Success 200 {object} v1.ParkUpdateResponse
- // @Failure 500 {object} base.HTTPError
- // @Router /api/v1/park [put]
- func (c *Controller) ParkUpdate(ctx *gin.Context) {
- // 解析参数
- req := ¶m_v1.ParkUpdateRequest{}
- parseParamTask := func() error {
- err := util.ShouldBind(ctx, &req.Header, nil, nil, &req.ParkUpdateBody)
- 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.ParkUpdateResponse{}
- rpcReq := &v1.ParkUpdateRequest{
- GardenId:tokenInfo.GardenId,
- Comment:req.Comment,
- Id:req.Id,
- ParkName:req.ParkName,
- ParkNumber:req.ParkNumber,
- ParkType:req.ParkType,
- }
- rpcRsp, err := pb.Garden.ParkUpdate(ctx, rpcReq)
- if err != nil {
- s, _ := json.MarshalToString(req)
- logger.Error("func",
- zap.String("call", "pb.Garden.ParkUpdate"),
- zap.String("params", s),
- zap.String("error", err.Error()))
- return errors.ErrorTransForm(err)
- }
- ctx.JSON(http.StatusOK, resp)
- logReq := OperationLogRequest{
- Module:ModulePark,
- Action:ActionParkUpdate,
- Origin:rpcRsp.Origin,
- Target:req.ParkUpdateBody,
- 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 "id"
- // @Success 200 {object} v1.ParkDelResponse
- // @Failure 500 {object} base.HTTPError
- // @Router /api/v1/park [delete]
- func (c *Controller) ParkDel(ctx *gin.Context) {
- // 解析参数
- req := ¶m_v1.ParkDelRequest{}
- parseParamTask := func() error {
- err := util.ShouldBind(ctx, &req.Header, nil, &req.ParkDelQuery, 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.ParkDelResponse{}
- rpcReq := &v1.ParkDelRequest{
- GardenId:tokenInfo.GardenId,
- Id:req.Id,
- }
- rpcRsp, err := pb.Garden.ParkDel(ctx, rpcReq)
- if err != nil {
- s, _ := json.MarshalToString(req)
- logger.Error("func",
- zap.String("call", "pb.Garden.ParkDel"),
- zap.String("params", s),
- zap.String("error", err.Error()))
- return errors.ErrorTransForm(err)
- }
- ctx.JSON(http.StatusOK, resp)
- logReq := OperationLogRequest{
- Module:ModulePark,
- Action:ActionParkDel,
- 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"
- // @Success 200 {object} v1.ParkListResponse
- // @Failure 500 {object} base.HTTPError
- // @Router /api/v1/park [get]
- func (c *Controller) ParkList(ctx *gin.Context) {
- // 解析参数
- req := ¶m_v1.ParkListRequest{}
- 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.GetSubjectValue(ctx)
- if err != nil {
- return err
- }
- // 响应数据
- resp := param_v1.ParkListResponse{}
- rpcReq := &v1.ParkListRequest{
- GardenId:tokenInfo.GardenId,
- }
- rpcRsp, err := pb.Garden.ParkList(ctx, rpcReq)
- if err != nil {
- s, _ := json.MarshalToString(req)
- logger.Error("func",
- zap.String("call", "pb.Garden.ParkList"),
- zap.String("params", s),
- zap.String("error", err.Error()))
- return errors.ErrorTransForm(err)
- }
- if rpcRsp.List == nil {
- rpcRsp.List = make([]*v1.ParkItem, 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 body body v1.ParkSpaceAddBody true "信息"
- // @Success 200 {object} v1.ParkAddResponse
- // @Failure 500 {object} base.HTTPError
- // @Router /api/v1/park/space [post]
- func (c *Controller) ParkSpaceAdd(ctx *gin.Context) {
- // 解析参数
- req := ¶m_v1.ParkSpaceAddRequest{}
- parseParamTask := func() error {
- err := util.ShouldBind(ctx, &req.Header, nil, nil, &req.ParkSpaceAddBody)
- 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.ParkSpaceAddResponse{}
- rpcReq := &v1.ParkSpaceAddRequest{
- GardenId:tokenInfo.GardenId,
- ParkId: req.ParkId,
- SpaceArea:req.SpaceArea,
- SpaceType:req.SpaceType,
- SpaceNumber:req.SpaceNumber,
- Comment:req.Comment,
- HouseId:req.HouseId,
- }
- rpcRsp, err := pb.Garden.ParkSpaceAdd(ctx, rpcReq)
- if err != nil {
- s, _ := json.MarshalToString(req)
- logger.Error("func",
- zap.String("call", "pb.Garden.ParkSpaceAdd"),
- zap.String("params", s),
- zap.String("error", err.Error()))
- return errors.ErrorTransForm(err)
- }
- resp.Data = *rpcRsp
- ctx.JSON(http.StatusOK, resp)
- logReq := OperationLogRequest{
- Module:ModulePark,
- Action:ActionParkSpaceAdd,
- Origin:nil,
- Target:req.ParkSpaceAddBody,
- 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.ParkSpaceUpdateBody true "信息"
- // @Success 200 {object} v1.ParkSpaceUpdateResponse
- // @Failure 500 {object} base.HTTPError
- // @Router /api/v1/park/space [put]
- func (c *Controller) ParkSpaceUpdate(ctx *gin.Context) {
- // 解析参数
- req := ¶m_v1.ParkSpaceUpdateRequest{}
- parseParamTask := func() error {
- err := util.ShouldBind(ctx, &req.Header, nil, nil, &req.ParkSpaceUpdateBody)
- 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.ParkSpaceUpdateResponse{}
- rpcReq := &v1.ParkSpaceUpdateRequest{
- GardenId:tokenInfo.GardenId,
- Comment:req.Comment,
- Id:req.Id,
- ParkId: req.ParkId,
- SpaceArea:req.SpaceArea,
- SpaceType:req.SpaceType,
- SpaceNumber:req.SpaceNumber,
- HouseId:req.HouseId,
- }
- rpcRsp, err := pb.Garden.ParkSpaceUpdate(ctx, rpcReq)
- if err != nil {
- s, _ := json.MarshalToString(req)
- logger.Error("func",
- zap.String("call", "pb.Garden.ParkSpaceUpdate"),
- zap.String("params", s),
- zap.String("error", err.Error()))
- return errors.ErrorTransForm(err)
- }
- ctx.JSON(http.StatusOK, resp)
- logReq := OperationLogRequest{
- Module:ModulePark,
- Action:ActionParkSpaceUpdate,
- Origin:rpcRsp.Origin,
- Target:req.ParkSpaceUpdateBody,
- 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 "id"
- // @Success 200 {object} v1.ParkSpaceDelResponse
- // @Failure 500 {object} base.HTTPError
- // @Router /api/v1/park/space [delete]
- func (c *Controller) ParkSpaceDel(ctx *gin.Context) {
- // 解析参数
- req := ¶m_v1.ParkSpaceDelRequest{}
- parseParamTask := func() error {
- err := util.ShouldBind(ctx, &req.Header, nil, &req.ParkSpaceDelQuery, 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.ParkSpaceDelResponse{}
- rpcReq := &v1.ParkSpaceDelRequest{
- GardenId:tokenInfo.GardenId,
- Id:req.Id,
- }
- rpcRsp, err := pb.Garden.ParkSpaceDel(ctx, rpcReq)
- if err != nil {
- s, _ := json.MarshalToString(req)
- logger.Error("func",
- zap.String("call", "pb.Garden.ParkSpaceDel"),
- zap.String("params", s),
- zap.String("error", err.Error()))
- return errors.ErrorTransForm(err)
- }
- ctx.JSON(http.StatusOK, resp)
- logReq := OperationLogRequest{
- Module:ModulePark,
- Action:ActionParkSpaceDel,
- 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 " "
- // @Param space_number query string false "车位编号 "
- // @Param park_id query int false "停车场id "
- // @Param space_type query int false "车位类型 1 普通车位 2 子母车位 3 豪华车位 "
- // @Param household_uid query int false "业主uid"
- // @Param bind_type query int false "车辆的绑定类型"
- // @Param bind_space_id query int false "车辆已绑定的车位id"
- // @Success 200 {object} v1.ParkSpaceListResponse
- // @Failure 500 {object} base.HTTPError
- // @Router /api/v1/park/space [get]
- func (c *Controller) ParkSpaceList(ctx *gin.Context) {
- // 解析参数
- req := ¶m_v1.ParkSpaceListRequest{}
- parseParamTask := func() error {
- err := util.ShouldBind(ctx, &req.Header, nil, &req.ParkSpaceListQuery, 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.ParkSpaceListResponse{}
- rpcReq := &v1.ParkSpaceListRequest{
- GardenId:tokenInfo.GardenId,
- Page:req.Page,
- PageSize:req.PageSize,
- ParkId:req.ParkId,
- SpaceNumber:req.SpaceNumber,
- SpaceType:req.SpaceType,
- HouseholdUid:req.HouseholdUid,
- BindType:req.BindType,
- BindSpaceId:req.BindSpaceId,
- }
- rpcRsp, err := pb.Garden.ParkSpaceList(ctx, rpcReq)
- if err != nil {
- s, _ := json.MarshalToString(req)
- logger.Error("func",
- zap.String("call", "pb.Garden.ParkSpaceList"),
- zap.String("params", s),
- zap.String("error", err.Error()))
- return errors.ErrorTransForm(err)
- }
- if rpcRsp.List == nil {
- rpcRsp.List = make([]*v1.ParkSpaceItem, 0)
- }
- resp.Data = *rpcRsp
- ctx.JSON(http.StatusOK, resp)
- return nil
- }
- // 执行任务
- httptasker.Exec(ctx, parseParamTask, handleServiceTask)
- }
|