| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394 |
- package com.zxyj.controller;
- import com.zxyj.common.Result;
- import com.zxyj.entity.Street;
- import com.zxyj.service.StreetService;
- import io.swagger.v3.oas.annotations.Operation;
- import io.swagger.v3.oas.annotations.tags.Tag;
- import org.springframework.web.bind.annotation.*;
- import javax.annotation.Resource;
- import java.util.List;
- import java.util.Map;
- /**
- * 街道地址控制器 - 支持四级地址选择和匹配
- */
- @Tag(name = "街道地址", description = "四级地址选择、区域匹配、统计接口")
- @RestController
- @RequestMapping("/api/streets")
- public class StreetController {
- @Resource
- private StreetService streetService;
- /**
- * 获取所有省份
- */
- @Operation(summary = "获取所有省份")
- @GetMapping("/provinces")
- public Result<List<Street>> getAllProvinces() {
- List<Street> provinces = streetService.getAllProvinces();
- return Result.success(provinces);
- }
- /**
- * 根据父级ID获取子级地址
- */
- @Operation(summary = "根据父级ID获取子级地址")
- @GetMapping("/children/{parentId}")
- public Result<List<Street>> getChildren(@PathVariable Long parentId) {
- List<Street> children = streetService.getChildrenByParentId(parentId);
- return Result.success(children);
- }
- /**
- * 根据ID获取地址详情
- */
- @Operation(summary = "根据ID获取地址详情")
- @GetMapping("/{id}")
- public Result<Street> getById(@PathVariable Long id) {
- Street street = streetService.getById(id);
- return Result.success(street);
- }
- /**
- * 获取地址的完整路径
- */
- @Operation(summary = "获取地址完整路径")
- @GetMapping("/{id}/path")
- public Result<List<Street>> getAddressPath(@PathVariable Long id) {
- List<Street> path = streetService.getAddressPath(id);
- return Result.success(path);
- }
- /**
- * 搜索地址
- */
- @Operation(summary = "搜索地址")
- @GetMapping("/search")
- public Result<List<Street>> search(@RequestParam String keyword) {
- List<Street> results = streetService.search(keyword);
- return Result.success(results);
- }
- /**
- * 区域回退匹配 - 获取匹配范围
- */
- @Operation(summary = "区域回退匹配", description = "根据街道ID返回街道级、区县级、城市级的匹配范围")
- @GetMapping("/{id}/match")
- public Result<Map<String, Object>> match(@PathVariable Long id) {
- Map<String, Object> matchResult = streetService.matchByStreetWithFallback(id);
- return Result.success(matchResult);
- }
- /**
- * 按区域统计
- */
- @Operation(summary = "按区域统计", description = "按指定层级统计地址数量")
- @GetMapping("/stats")
- public Result<Map<String, Object>> getStatistics(@RequestParam(defaultValue = "4") Integer level) {
- Map<String, Object> stats = streetService.getStatisticsByLevel(level);
- return Result.success(stats);
- }
- }
|