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> getAllProvinces() { List provinces = streetService.getAllProvinces(); return Result.success(provinces); } /** * 根据父级ID获取子级地址 */ @Operation(summary = "根据父级ID获取子级地址") @GetMapping("/children/{parentId}") public Result> getChildren(@PathVariable Long parentId) { List children = streetService.getChildrenByParentId(parentId); return Result.success(children); } /** * 根据ID获取地址详情 */ @Operation(summary = "根据ID获取地址详情") @GetMapping("/{id}") public Result getById(@PathVariable Long id) { Street street = streetService.getById(id); return Result.success(street); } /** * 获取地址的完整路径 */ @Operation(summary = "获取地址完整路径") @GetMapping("/{id}/path") public Result> getAddressPath(@PathVariable Long id) { List path = streetService.getAddressPath(id); return Result.success(path); } /** * 搜索地址 */ @Operation(summary = "搜索地址") @GetMapping("/search") public Result> search(@RequestParam String keyword) { List results = streetService.search(keyword); return Result.success(results); } /** * 区域回退匹配 - 获取匹配范围 */ @Operation(summary = "区域回退匹配", description = "根据街道ID返回街道级、区县级、城市级的匹配范围") @GetMapping("/{id}/match") public Result> match(@PathVariable Long id) { Map matchResult = streetService.matchByStreetWithFallback(id); return Result.success(matchResult); } /** * 按区域统计 */ @Operation(summary = "按区域统计", description = "按指定层级统计地址数量") @GetMapping("/stats") public Result> getStatistics(@RequestParam(defaultValue = "4") Integer level) { Map stats = streetService.getStatisticsByLevel(level); return Result.success(stats); } }