StreetController.java 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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. @GetMapping("/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. @GetMapping("/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. @GetMapping("/{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. @GetMapping("/{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. @GetMapping("/search")
  61. public Result<List<Street>> search(@RequestParam String keyword) {
  62. List<Street> results = streetService.search(keyword);
  63. return Result.success(results);
  64. }
  65. /**
  66. * 区域回退匹配 - 获取匹配范围
  67. */
  68. @Operation(summary = "区域回退匹配", description = "根据街道ID返回街道级、区县级、城市级的匹配范围")
  69. @GetMapping("/{id}/match")
  70. public Result<Map<String, Object>> match(@PathVariable Long id) {
  71. Map<String, Object> matchResult = streetService.matchByStreetWithFallback(id);
  72. return Result.success(matchResult);
  73. }
  74. /**
  75. * 按区域统计
  76. */
  77. @Operation(summary = "按区域统计", description = "按指定层级统计地址数量")
  78. @GetMapping("/stats")
  79. public Result<Map<String, Object>> getStatistics(@RequestParam(defaultValue = "4") Integer level) {
  80. Map<String, Object> stats = streetService.getStatisticsByLevel(level);
  81. return Result.success(stats);
  82. }
  83. }