StreetController.java 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. package com.zxyj.controller;
  2. import com.zxyj.common.Result;
  3. import com.zxyj.entity.Street;
  4. import com.zxyj.service.StreetService;
  5. import io.swagger.v3.oas.annotations.Operation;
  6. import io.swagger.v3.oas.annotations.tags.Tag;
  7. import org.springframework.web.bind.annotation.*;
  8. import javax.annotation.Resource;
  9. import java.util.List;
  10. import java.util.Map;
  11. /**
  12. * 街道地址控制器 - 支持四级地址选择和匹配
  13. */
  14. @Tag(name = "街道地址", description = "四级地址选择、区域匹配、统计接口")
  15. @RestController
  16. @RequestMapping("/api/streets")
  17. public class StreetController {
  18. @Resource
  19. private StreetService streetService;
  20. /**
  21. * 获取所有省份
  22. */
  23. @Operation(summary = "获取所有省份")
  24. @PostMapping("/provinces")
  25. public Result<List<Street>> getAllProvinces() {
  26. List<Street> provinces = streetService.getAllProvinces();
  27. return Result.success(provinces);
  28. }
  29. /**
  30. * 根据父级ID获取子级地址
  31. */
  32. @Operation(summary = "根据父级ID获取子级地址")
  33. @PostMapping("/children/{parentId}")
  34. public Result<List<Street>> getChildren(@PathVariable Long parentId) {
  35. List<Street> children = streetService.getChildrenByParentId(parentId);
  36. return Result.success(children);
  37. }
  38. /**
  39. * 根据ID获取地址详情
  40. */
  41. @Operation(summary = "根据ID获取地址详情")
  42. @PostMapping("/{id}")
  43. public Result<Street> getById(@PathVariable Long id) {
  44. Street street = streetService.getById(id);
  45. return Result.success(street);
  46. }
  47. /**
  48. * 获取地址的完整路径
  49. */
  50. @Operation(summary = "获取地址完整路径")
  51. @PostMapping("/{id}/path")
  52. public Result<List<Street>> getAddressPath(@PathVariable Long id) {
  53. List<Street> path = streetService.getAddressPath(id);
  54. return Result.success(path);
  55. }
  56. /**
  57. * 搜索地址
  58. */
  59. @Operation(summary = "搜索地址")
  60. @PostMapping("/search")
  61. public Result<List<Street>> search(@RequestBody Map<String, Object> params) {
  62. String keyword = params.get("keyword") != null ? params.get("keyword").toString() : null;
  63. List<Street> results = streetService.search(keyword);
  64. return Result.success(results);
  65. }
  66. /**
  67. * 区域回退匹配 - 获取匹配范围
  68. */
  69. @Operation(summary = "区域回退匹配", description = "根据街道ID返回街道级、区县级、城市级的匹配范围")
  70. @PostMapping("/{id}/match")
  71. public Result<Map<String, Object>> match(@PathVariable Long id) {
  72. Map<String, Object> matchResult = streetService.matchByStreetWithFallback(id);
  73. return Result.success(matchResult);
  74. }
  75. /**
  76. * 按区域统计
  77. */
  78. @Operation(summary = "按区域统计", description = "按指定层级统计地址数量")
  79. @PostMapping("/stats")
  80. public Result<Map<String, Object>> getStatistics(@RequestBody(required = false) Map<String, Object> params) {
  81. Integer level = params != null && params.get("level") != null ? Integer.valueOf(params.get("level").toString()) : 4;
  82. Map<String, Object> stats = streetService.getStatisticsByLevel(level);
  83. return Result.success(stats);
  84. }
  85. }