garden.go 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400
  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 "token"
  21. // @Param garden_id query int true "小区id 必填"
  22. // @Param house_id query int true "房屋id 必填"
  23. // @Success 200 {object} v1.BuildingManagerListResponse
  24. // @Failure 500 {object} base.HTTPError
  25. // @Router /api/v1/garden/buildings/manager [get]
  26. func (c *Controller) BuildingManagerList(ctx *gin.Context) {
  27. // 解析参数
  28. req := &param_v1.BuildingManagerListRequest{}
  29. parseParamTask := func() error {
  30. err := util.ShouldBind(ctx, &req.Header, nil, &req.BuildingManagerListQuery, nil)
  31. if err != nil {
  32. logger.Error("func",
  33. zap.String("call", "util.ShouldBind"),
  34. zap.String("error", err.Error()))
  35. return errors.ParamsError
  36. }
  37. return nil
  38. }
  39. // 业务处理
  40. handleServiceTask := func() error {
  41. // 响应数据
  42. resp := param_v1.BuildingManagerListResponse{}
  43. rpcReq := &v1.BuildingManagerListRequest{
  44. GardenId: req.GardenId,
  45. HouseId: req.HouseId,
  46. }
  47. rpcRsp, err := pb.Garden.BuildingManagerList(ctx, rpcReq)
  48. if err != nil {
  49. s, _ := json.MarshalToString(req)
  50. logger.Error("func",
  51. zap.String("call", "pb.Garden.BuildingManagerList"),
  52. zap.String("params", s),
  53. zap.String("error", err.Error()))
  54. return errors.ErrorTransForm(err)
  55. }
  56. if rpcRsp.List == nil {
  57. rpcRsp.List = make([]*v1.BuildingManagerItem, 0)
  58. }
  59. resp.Data = *rpcRsp
  60. ctx.JSON(http.StatusOK, resp)
  61. return nil
  62. }
  63. // 执行任务
  64. httptasker.Exec(ctx, parseParamTask, handleServiceTask)
  65. }
  66. //
  67. // @Summary 小区详情
  68. // @Description 小区详情
  69. // @Tags 小区
  70. // @Accept json
  71. // @Produce json
  72. // @Param token header string true " "
  73. // @Param garden_id query int true "小区id"
  74. // @Success 200 {object} v1.GardenInfoResponse
  75. // @Failure 500 {object} base.HTTPError
  76. // @Router /api/v1/garden/info [get]
  77. func (c *Controller) GardenInfo(ctx *gin.Context) {
  78. // 解析参数
  79. req := &param_v1.GardenInfoRequest{}
  80. parseParamTask := func() error {
  81. err := util.ShouldBind(ctx, &req.Header, nil, &req.GardenInfoQuery, nil)
  82. if err != nil {
  83. logger.Error("func",
  84. zap.String("call", "util.ShouldBind"),
  85. zap.String("error", err.Error()))
  86. return errors.ParamsError
  87. }
  88. return nil
  89. }
  90. // 业务处理
  91. handleServiceTask := func() error {
  92. resp := param_v1.GardenInfoResponse{}
  93. rpcReq := &v1.GardenInfosRequest{
  94. Ids: []int64{req.GardenId},
  95. }
  96. rpcRsp, err := pb.System.GardenInfos(ctx, rpcReq)
  97. if err != nil {
  98. s, _ := json.MarshalToString(req)
  99. logger.Error("func",
  100. zap.String("call", "System.GardenInfos"),
  101. zap.String("params", s),
  102. zap.String("error", err.Error()))
  103. return errors.ErrorTransForm(err)
  104. }
  105. if len(rpcRsp.List) > 0 {
  106. resp.Data = *rpcRsp.List[0]
  107. }
  108. ctx.JSON(http.StatusOK, resp)
  109. return nil
  110. }
  111. // 执行任务
  112. httptasker.Exec(ctx, parseParamTask, handleServiceTask)
  113. }
  114. //
  115. // @Summary 小区列表
  116. // @Description 小区列表
  117. // @Tags 小区
  118. // @Accept json
  119. // @Produce json
  120. // @Param token header string true " "
  121. // @Param province_code query string false "省份代码"
  122. // @Param city_code query string false "城市代码"
  123. // @Param area_code query string false "区域代码"
  124. // @Param committee_code query string false "社区代码"
  125. // @Param street_code query string false "街道代码"
  126. // @Param garden_name query string false "小区名字"
  127. // @Param building_type query int false " 1塔楼 2 板楼 3 塔板结合 4 其他"
  128. // @Param building_year_greater query int false " 楼龄年份大于"
  129. // @Param building_year_less query int false " 楼龄小于"
  130. // @Param price_greater query int false " 均价大于"
  131. // @Param price_less query int false " 均价小于"
  132. // @Success 200 {object} v1.GardenListResponse
  133. // @Failure 500 {object} base.HTTPError
  134. // @Router /api/v1/garden/list [get]
  135. func (c *Controller) GardenList(ctx *gin.Context) {
  136. // 解析参数
  137. req := &param_v1.GardenListRequest{}
  138. parseParamTask := func() error {
  139. err := util.ShouldBind(ctx, &req.Header, nil, &req.GardenListQuery, nil)
  140. if err != nil {
  141. logger.Error("func",
  142. zap.String("call", "util.ShouldBind"),
  143. zap.String("error", err.Error()))
  144. return errors.ParamsError
  145. }
  146. return nil
  147. }
  148. // 业务处理
  149. handleServiceTask := func() error {
  150. resp := param_v1.GardenListResponse{}
  151. rpcReq := &v1.GardenListRequest{
  152. Page: -1,
  153. PageSize: -1,
  154. CommitteeCode: req.CommitteeCode,
  155. StreetCode: req.StreetCode,
  156. GardenName: req.GardenName,
  157. BuildingYearGreater: req.BuildingYearGreater,
  158. BuildingYearLess: req.BuildingYearLess,
  159. BuildingType: req.BuildingType,
  160. ProvinceCode: req.ProvinceCode,
  161. AreaCode: req.AreaCode,
  162. CityCode: req.CityCode,
  163. PriceGreater: req.PriceGreater,
  164. PriceLess: req.PriceLess,
  165. Household: true,
  166. }
  167. rpcRsp, err := pb.System.GardenList(ctx, rpcReq)
  168. if err != nil {
  169. s, _ := json.MarshalToString(req)
  170. logger.Error("func",
  171. zap.String("call", "System.GardenList"),
  172. zap.String("params", s),
  173. zap.String("error", err.Error()))
  174. return errors.ErrorTransForm(err)
  175. }
  176. for i, v := range rpcRsp.List {
  177. if len(v.WaterType) == 0 {
  178. rpcRsp.List[i].WaterType = []int32{}
  179. }
  180. if len(v.ElectricType) == 0 {
  181. rpcRsp.List[i].ElectricType = []int32{}
  182. }
  183. if len(v.GardenPics) == 0 {
  184. rpcRsp.List[i].GardenPics = []string{}
  185. }
  186. }
  187. if rpcRsp.List == nil {
  188. rpcRsp.List = make([]*v1.GardenItem, 0)
  189. }
  190. resp.Data = *rpcRsp
  191. ctx.JSON(http.StatusOK, resp)
  192. return nil
  193. }
  194. // 执行任务
  195. httptasker.Exec(ctx, parseParamTask, handleServiceTask)
  196. }
  197. //
  198. // @Summary 楼栋列表
  199. // @Description 楼栋列表
  200. // @Tags 小区
  201. // @Accept json
  202. // @Produce json
  203. // @Param token header string true "token"
  204. // @Param garden_id query string true "小区id"
  205. // @Success 200 {object} v1.BuildingListResponse
  206. // @Failure 500 {object} base.HTTPError
  207. // @Router /api/v1/garden/building [get]
  208. func (c *Controller) BuildingList(ctx *gin.Context) {
  209. // 解析参数
  210. req := &param_v1.BuildingListRequest{}
  211. parseParamTask := func() error {
  212. err := util.ShouldBind(ctx, &req.Header, nil, &req.BuildingListQuery, nil)
  213. if err != nil {
  214. logger.Error("func",
  215. zap.String("call", "util.ShouldBind"),
  216. zap.String("error", err.Error()))
  217. return errors.ParamsError
  218. }
  219. return nil
  220. }
  221. // 业务处理
  222. handleServiceTask := func() error {
  223. // 响应数据
  224. resp := param_v1.BuildingListResponse{}
  225. rpcReq := &v1.BuildingListRequest{
  226. GardenId: req.GardenId,
  227. Page: -1,
  228. PageSize: -1,
  229. }
  230. rpcRsp, err := pb.Garden.BuildingList(ctx, rpcReq)
  231. if err != nil {
  232. s, _ := json.MarshalToString(req)
  233. logger.Error("func",
  234. zap.String("call", "pb.Garden.BuildingList"),
  235. zap.String("params", s),
  236. zap.String("error", err.Error()))
  237. return errors.ErrorTransForm(err)
  238. }
  239. if rpcRsp.List == nil {
  240. rpcRsp.List = make([]*v1.BuildingItem, 0)
  241. }
  242. resp.Data = *rpcRsp
  243. ctx.JSON(http.StatusOK, resp)
  244. return nil
  245. }
  246. // 执行任务
  247. httptasker.Exec(ctx, parseParamTask, handleServiceTask)
  248. }
  249. //
  250. // @Summary 单元列表
  251. // @Description 单元列表
  252. // @Tags 小区
  253. // @Accept json
  254. // @Produce json
  255. // @Param token header string true "token"
  256. // @Param building_id query int true "楼栋id"
  257. // @Param garden_id query string true "小区id"
  258. // @Success 200 {object} v1.UnitListResponse
  259. // @Failure 500 {object} base.HTTPError
  260. // @Router /api/v1/garden/unit [get]
  261. func (c *Controller) UnitList(ctx *gin.Context) {
  262. // 解析参数
  263. req := &param_v1.UnitListRequest{}
  264. parseParamTask := func() error {
  265. err := util.ShouldBind(ctx, &req.Header, nil, &req.UnitListQuery, nil)
  266. if err != nil {
  267. logger.Error("func",
  268. zap.String("call", "util.ShouldBind"),
  269. zap.String("error", err.Error()))
  270. return errors.ParamsError
  271. }
  272. return nil
  273. }
  274. // 业务处理
  275. handleServiceTask := func() error {
  276. // 响应数据
  277. resp := param_v1.UnitListResponse{}
  278. rpcReq := &v1.UnitListRequest{
  279. GardenId: req.GardenId,
  280. BuildingId: req.BuildingId,
  281. Page: -1,
  282. PageSize: -1,
  283. }
  284. rpcRsp, err := pb.Garden.UnitList(ctx, rpcReq)
  285. if err != nil {
  286. s, _ := json.MarshalToString(req)
  287. logger.Error("func",
  288. zap.String("call", "pb.Garden.UnitList"),
  289. zap.String("params", s),
  290. zap.String("error", err.Error()))
  291. return errors.ErrorTransForm(err)
  292. }
  293. if rpcRsp.List == nil {
  294. rpcRsp.List = make([]*v1.UnitItem, 0)
  295. }
  296. resp.Data = *rpcRsp
  297. ctx.JSON(http.StatusOK, resp)
  298. return nil
  299. }
  300. // 执行任务
  301. httptasker.Exec(ctx, parseParamTask, handleServiceTask)
  302. }
  303. //
  304. // @Summary 房屋列表
  305. // @Description 房屋列表
  306. // @Tags 小区
  307. // @Accept json
  308. // @Produce json
  309. // @Param token header string true "token"
  310. // @Param unit_id query int true "单元id"
  311. // @Param garden_id query string true "小区id"
  312. // @Param house_rent query bool false "true只返回还可以发布租房的房屋"
  313. // @Success 200 {object} v1.HouseListResponse
  314. // @Failure 500 {object} base.HTTPError
  315. // @Router /api/v1/garden/house [get]
  316. func (c *Controller) HouseList(ctx *gin.Context) {
  317. // 解析参数
  318. req := &param_v1.HouseListRequest{}
  319. parseParamTask := func() error {
  320. err := util.ShouldBind(ctx, &req.Header, nil, &req.HouseListQuery, nil)
  321. if err != nil {
  322. logger.Error("func",
  323. zap.String("call", "util.ShouldBind"),
  324. zap.String("error", err.Error()))
  325. return errors.ParamsError
  326. }
  327. return nil
  328. }
  329. // 业务处理
  330. handleServiceTask := func() error {
  331. // 响应数据
  332. resp := param_v1.HouseListResponse{}
  333. rpcReq := &v1.HouseListRequest{
  334. GardenId: req.GardenId,
  335. UnitId: req.UnitId,
  336. Page: -1,
  337. PageSize: -1,
  338. HouseRent: req.HouseRent,
  339. }
  340. rpcRsp, err := pb.Garden.HouseList(ctx, rpcReq)
  341. if err != nil {
  342. s, _ := json.MarshalToString(req)
  343. logger.Error("func",
  344. zap.String("call", "pb.Garden.HouseList"),
  345. zap.String("params", s),
  346. zap.String("error", err.Error()))
  347. return errors.ErrorTransForm(err)
  348. }
  349. if rpcRsp.List == nil {
  350. rpcRsp.List = make([]*v1.HouseItem, 0)
  351. }
  352. resp.Data = *rpcRsp
  353. ctx.JSON(http.StatusOK, resp)
  354. return nil
  355. }
  356. // 执行任务
  357. httptasker.Exec(ctx, parseParamTask, handleServiceTask)
  358. }