123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190 |
- 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-household-gateway/errors"
- param_v1 "property-household-gateway/param/v1"
- "property-household-gateway/pb"
- "property-household-gateway/pb/v1"
- )
- //
- // @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)
- }
- //
- // @Summary 用城市名换取城市code
- // @Description 用城市名换取城市code
- // @Tags 区域
- // @Accept json
- // @Produce json
- // @Param token header string true " "
- // @Param city_name query string true "城市名称"
- // @Success 200 {object} v1.CityResponse
- // @Failure 500 {object} base.HTTPError
- // @Router /api/v1/area/city [get]
- func (c *Controller) City(ctx *gin.Context) {
- // 解析参数
- req := ¶m_v1.CityRequest{}
- parseParamTask := func() error {
- err := util.ShouldBind(ctx, &req.Header, nil, &req.CityQuery, 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.CityResponse{}
- rpcReq := &v1.CityRequest{CityName: req.CityName}
- rpcRsp, err := pb.Common.City(ctx, rpcReq)
- if err != nil {
- s, _ := json.MarshalToString(req)
- logger.Error("func",
- zap.String("call", "pb.Common.City"),
- 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)
- }
|