高德行政区接入

This commit is contained in:
2024-04-03 15:28:50 +08:00
parent 976f63d09c
commit 106288497e
3 changed files with 52 additions and 1 deletions

View File

@@ -0,0 +1,37 @@
package com.chaozhanggui.system.cashierservice.controller;
import com.chaozhanggui.system.cashierservice.sign.CodeEnum;
import com.chaozhanggui.system.cashierservice.sign.Result;
import com.chaozhanggui.system.cashierservice.util.LocationUtils;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
@CrossOrigin(origins = "*")
@RestController
@Slf4j
@RequestMapping("/location")
public class LocationController {
/**
* 行政区域查询
*
* @param keywords citycode市、adcode区
* @return
*/
@GetMapping("/district")
public Result createOrder(String keywords) throws JsonProcessingException {
String district = LocationUtils.district(keywords);
ObjectMapper mapper = new ObjectMapper();
// 将 JSON 字符串解析为 JsonNode 对象
JsonNode jsonNode = mapper.readTree(district);
JsonNode districts = jsonNode.get("districts");
return Result.success(CodeEnum.SUCCESS, districts);
}
}