area.go 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. package v1
  2. import (
  3. "net/http"
  4. "property-company-gateway/errors"
  5. param_v1 "property-company-gateway/param/v1"
  6. "property-company-gateway/pb"
  7. "property-company-gateway/pb/v1"
  8. "git.getensh.com/common/gopkgs/logger"
  9. "git.getensh.com/common/gopkgs/tasker/httptasker"
  10. "git.getensh.com/common/gopkgs/util"
  11. "github.com/gin-gonic/gin"
  12. "go.uber.org/zap"
  13. )
  14. //
  15. // @Summary 省市区列表
  16. // @Description 省市区列表
  17. // @Tags 区域
  18. // @Accept json
  19. // @Produce json
  20. // @Param token header string true " "
  21. // @Success 200 {object} v1.ProvinceCityAreaResponse
  22. // @Failure 500 {object} base.HTTPError
  23. // @Router /api/v1/area/province_city_area [get]
  24. func (c *Controller) ProvinceCityArea(ctx *gin.Context) {
  25. // 解析参数
  26. req := &param_v1.ProvinceCityAreaRequest{}
  27. parseParamTask := func() error {
  28. err := util.ShouldBind(ctx, &req.Header, nil, nil, nil)
  29. if err != nil {
  30. logger.Error("func",
  31. zap.String("call", "util.ShouldBind"),
  32. zap.String("error", err.Error()))
  33. return errors.ParamsError
  34. }
  35. return nil
  36. }
  37. // 业务处理
  38. handleServiceTask := func() error {
  39. // 响应数据
  40. resp := param_v1.ProvinceCityAreaResponse{}
  41. rpcReq := &v1.ProvinceCityAreaRequest{
  42. }
  43. rpcRsp, err := pb.Common.ProvinceCityArea(ctx, rpcReq)
  44. if err != nil {
  45. s, _ := json.MarshalToString(req)
  46. logger.Error("func",
  47. zap.String("call", "pb.Common.ProvinceCityArea"),
  48. zap.String("params", s),
  49. zap.String("error", err.Error()))
  50. return errors.ErrorTransForm(err)
  51. }
  52. if rpcRsp.ProvinceList == nil {
  53. rpcRsp.ProvinceList = make([]*v1.ProvinceData, 0)
  54. }
  55. if rpcRsp.CityList == nil {
  56. rpcRsp.CityList = make([]*v1.CityData, 0)
  57. }
  58. if rpcRsp.AreaList == nil {
  59. rpcRsp.AreaList = make([]*v1.AreaData, 0)
  60. }
  61. resp.Data = *rpcRsp
  62. ctx.JSON(http.StatusOK, resp)
  63. return nil
  64. }
  65. // 执行任务
  66. httptasker.Exec(ctx, parseParamTask, handleServiceTask)
  67. }
  68. //
  69. // @Summary 街道社区列表
  70. // @Description 街道社区列表
  71. // @Tags 区域
  72. // @Accept json
  73. // @Produce json
  74. // @Param token header string true " "
  75. // @Param area_code query string true "区域代码"
  76. // @Success 200 {object} v1.StreetCommitteeResponse
  77. // @Failure 500 {object} base.HTTPError
  78. // @Router /api/v1/area/street_committee [get]
  79. func (c *Controller) StreetCommittee(ctx *gin.Context) {
  80. // 解析参数
  81. req := &param_v1.StreetCommitteeRequest{}
  82. parseParamTask := func() error {
  83. err := util.ShouldBind(ctx, &req.Header, nil, &req.StreetCommitteeQuery, nil)
  84. if err != nil {
  85. logger.Error("func",
  86. zap.String("call", "util.ShouldBind"),
  87. zap.String("error", err.Error()))
  88. return errors.ParamsError
  89. }
  90. return nil
  91. }
  92. // 业务处理
  93. handleServiceTask := func() error {
  94. // 响应数据
  95. resp := param_v1.StreetCommitteeResponse{}
  96. rpcReq := &v1.StreetCommitteeRequest{
  97. AreaCode:req.AreaCode,
  98. }
  99. rpcRsp, err := pb.Common.StreetCommittee(ctx, rpcReq)
  100. if err != nil {
  101. s, _ := json.MarshalToString(req)
  102. logger.Error("func",
  103. zap.String("call", "pb.Common.StreetCommittee"),
  104. zap.String("params", s),
  105. zap.String("error", err.Error()))
  106. return errors.ErrorTransForm(err)
  107. }
  108. if rpcRsp.StreetList == nil {
  109. rpcRsp.StreetList = make([]*v1.StreetData, 0)
  110. }
  111. if rpcRsp.CommitteeList == nil {
  112. rpcRsp.CommitteeList = make([]*v1.CommitteeData, 0)
  113. }
  114. resp.Data = *rpcRsp
  115. ctx.JSON(http.StatusOK, resp)
  116. return nil
  117. }
  118. // 执行任务
  119. httptasker.Exec(ctx, parseParamTask, handleServiceTask)
  120. }