package v1 import ( "net/http" "property-company-gateway/errors" param_v1 "property-company-gateway/param/v1" "property-company-gateway/pb" "property-company-gateway/pb/v1" "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 " " // @Success 200 {object} v1.ProvinceCityAreaResponse // @Failure 500 {object} base.HTTPError // @Router /api/v1/area/province_city_area [get] func (c *Controller) ProvinceCityArea(ctx *gin.Context) { // 解析参数 req := ¶m_v1.ProvinceCityAreaRequest{} 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 { // 响应数据 resp := param_v1.ProvinceCityAreaResponse{} rpcReq := &v1.ProvinceCityAreaRequest{ } rpcRsp, err := pb.Common.ProvinceCityArea(ctx, rpcReq) if err != nil { s, _ := json.MarshalToString(req) logger.Error("func", zap.String("call", "pb.Common.ProvinceCityArea"), zap.String("params", s), zap.String("error", err.Error())) return errors.ErrorTransForm(err) } if rpcRsp.ProvinceList == nil { rpcRsp.ProvinceList = make([]*v1.ProvinceData, 0) } if rpcRsp.CityList == nil { rpcRsp.CityList = make([]*v1.CityData, 0) } if rpcRsp.AreaList == nil { rpcRsp.AreaList = make([]*v1.AreaData, 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 " " // @Param area_code query string true "区域代码" // @Success 200 {object} v1.StreetCommitteeResponse // @Failure 500 {object} base.HTTPError // @Router /api/v1/area/street_committee [get] func (c *Controller) StreetCommittee(ctx *gin.Context) { // 解析参数 req := ¶m_v1.StreetCommitteeRequest{} parseParamTask := func() error { err := util.ShouldBind(ctx, &req.Header, nil, &req.StreetCommitteeQuery, 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 { // 响应数据 resp := param_v1.StreetCommitteeResponse{} rpcReq := &v1.StreetCommitteeRequest{ AreaCode:req.AreaCode, } rpcRsp, err := pb.Common.StreetCommittee(ctx, rpcReq) if err != nil { s, _ := json.MarshalToString(req) logger.Error("func", zap.String("call", "pb.Common.StreetCommittee"), zap.String("params", s), zap.String("error", err.Error())) return errors.ErrorTransForm(err) } if rpcRsp.StreetList == nil { rpcRsp.StreetList = make([]*v1.StreetData, 0) } if rpcRsp.CommitteeList == nil { rpcRsp.CommitteeList = make([]*v1.CommitteeData, 0) } resp.Data = *rpcRsp ctx.JSON(http.StatusOK, resp) return nil } // 执行任务 httptasker.Exec(ctx, parseParamTask, handleServiceTask) }