123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139 |
- 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)
- }
|