area.go 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. package v1
  2. import (
  3. "git.getensh.com/common/gopkgs/logger"
  4. "git.getensh.com/common/gopkgs/tasker/httptasker"
  5. "git.getensh.com/common/gopkgs/util"
  6. "github.com/gin-gonic/gin"
  7. "go.uber.org/zap"
  8. "net/http"
  9. "property-household-gateway/errors"
  10. param_v1 "property-household-gateway/param/v1"
  11. "property-household-gateway/pb"
  12. "property-household-gateway/pb/v1"
  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. rpcRsp, err := pb.Common.ProvinceCityArea(ctx, rpcReq)
  43. if err != nil {
  44. s, _ := json.MarshalToString(req)
  45. logger.Error("func",
  46. zap.String("call", "pb.Common.ProvinceCityArea"),
  47. zap.String("params", s),
  48. zap.String("error", err.Error()))
  49. return errors.ErrorTransForm(err)
  50. }
  51. if rpcRsp.ProvinceList == nil {
  52. rpcRsp.ProvinceList = make([]*v1.ProvinceData, 0)
  53. }
  54. if rpcRsp.CityList == nil {
  55. rpcRsp.CityList = make([]*v1.CityData, 0)
  56. }
  57. if rpcRsp.AreaList == nil {
  58. rpcRsp.AreaList = make([]*v1.AreaData, 0)
  59. }
  60. resp.Data = *rpcRsp
  61. ctx.JSON(http.StatusOK, resp)
  62. return nil
  63. }
  64. // 执行任务
  65. httptasker.Exec(ctx, parseParamTask, handleServiceTask)
  66. }
  67. //
  68. // @Summary 街道社区列表
  69. // @Description 街道社区列表
  70. // @Tags 区域
  71. // @Accept json
  72. // @Produce json
  73. // @Param token header string true " "
  74. // @Param area_code query string true "区域代码"
  75. // @Success 200 {object} v1.StreetCommitteeResponse
  76. // @Failure 500 {object} base.HTTPError
  77. // @Router /api/v1/area/street_committee [get]
  78. func (c *Controller) StreetCommittee(ctx *gin.Context) {
  79. // 解析参数
  80. req := &param_v1.StreetCommitteeRequest{}
  81. parseParamTask := func() error {
  82. err := util.ShouldBind(ctx, &req.Header, nil, &req.StreetCommitteeQuery, nil)
  83. if err != nil {
  84. logger.Error("func",
  85. zap.String("call", "util.ShouldBind"),
  86. zap.String("error", err.Error()))
  87. return errors.ParamsError
  88. }
  89. return nil
  90. }
  91. // 业务处理
  92. handleServiceTask := func() error {
  93. // 响应数据
  94. resp := param_v1.StreetCommitteeResponse{}
  95. rpcReq := &v1.StreetCommitteeRequest{
  96. AreaCode: req.AreaCode,
  97. }
  98. rpcRsp, err := pb.Common.StreetCommittee(ctx, rpcReq)
  99. if err != nil {
  100. s, _ := json.MarshalToString(req)
  101. logger.Error("func",
  102. zap.String("call", "pb.Common.StreetCommittee"),
  103. zap.String("params", s),
  104. zap.String("error", err.Error()))
  105. return errors.ErrorTransForm(err)
  106. }
  107. if rpcRsp.StreetList == nil {
  108. rpcRsp.StreetList = make([]*v1.StreetData, 0)
  109. }
  110. if rpcRsp.CommitteeList == nil {
  111. rpcRsp.CommitteeList = make([]*v1.CommitteeData, 0)
  112. }
  113. resp.Data = *rpcRsp
  114. ctx.JSON(http.StatusOK, resp)
  115. return nil
  116. }
  117. // 执行任务
  118. httptasker.Exec(ctx, parseParamTask, handleServiceTask)
  119. }
  120. //
  121. // @Summary 用城市名换取城市code
  122. // @Description 用城市名换取城市code
  123. // @Tags 区域
  124. // @Accept json
  125. // @Produce json
  126. // @Param token header string true " "
  127. // @Param city_name query string true "城市名称"
  128. // @Success 200 {object} v1.CityResponse
  129. // @Failure 500 {object} base.HTTPError
  130. // @Router /api/v1/area/city [get]
  131. func (c *Controller) City(ctx *gin.Context) {
  132. // 解析参数
  133. req := &param_v1.CityRequest{}
  134. parseParamTask := func() error {
  135. err := util.ShouldBind(ctx, &req.Header, nil, &req.CityQuery, nil)
  136. if err != nil {
  137. logger.Error("func",
  138. zap.String("call", "util.ShouldBind"),
  139. zap.String("error", err.Error()))
  140. return errors.ParamsError
  141. }
  142. return nil
  143. }
  144. // 业务处理
  145. handleServiceTask := func() error {
  146. // 响应数据
  147. resp := param_v1.CityResponse{}
  148. rpcReq := &v1.CityRequest{CityName: req.CityName}
  149. rpcRsp, err := pb.Common.City(ctx, rpcReq)
  150. if err != nil {
  151. s, _ := json.MarshalToString(req)
  152. logger.Error("func",
  153. zap.String("call", "pb.Common.City"),
  154. zap.String("params", s),
  155. zap.String("error", err.Error()))
  156. return errors.ErrorTransForm(err)
  157. }
  158. resp.Data = *rpcRsp
  159. ctx.JSON(http.StatusOK, resp)
  160. return nil
  161. }
  162. // 执行任务
  163. httptasker.Exec(ctx, parseParamTask, handleServiceTask)
  164. }