|
@@ -1,19 +1,28 @@
|
|
|
package com.fdkankan.fusion.controller;
|
|
|
|
|
|
|
|
|
+import cn.hutool.core.util.URLUtil;
|
|
|
+import cn.hutool.http.HttpUtil;
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
import com.fdkankan.fusion.common.ResultCode;
|
|
|
import com.fdkankan.fusion.common.ResultData;
|
|
|
import com.fdkankan.fusion.common.util.Openai;
|
|
|
import com.fdkankan.fusion.config.FusionConfig;
|
|
|
+import com.fdkankan.fusion.entity.MapConfig;
|
|
|
import com.fdkankan.fusion.exception.BusinessException;
|
|
|
import com.fdkankan.fusion.request.AiParam;
|
|
|
+import com.fdkankan.fusion.request.MapParam;
|
|
|
+import com.fdkankan.fusion.response.MapVo;
|
|
|
+import com.fdkankan.fusion.service.IMapConfigService;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
-import org.springframework.web.bind.annotation.PostMapping;
|
|
|
-import org.springframework.web.bind.annotation.RequestBody;
|
|
|
-import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
-import org.springframework.web.bind.annotation.RestController;
|
|
|
+import org.springframework.web.bind.annotation.*;
|
|
|
+
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.List;
|
|
|
|
|
|
/**
|
|
|
* <p>
|
|
@@ -29,5 +38,37 @@ import org.springframework.web.bind.annotation.RestController;
|
|
|
public class MapConfigController {
|
|
|
|
|
|
|
|
|
+ @Autowired
|
|
|
+ IMapConfigService mapConfigService;
|
|
|
+
|
|
|
+ @PostMapping("/geocode")
|
|
|
+ public ResultData geocode(@RequestBody MapParam param){
|
|
|
+ if(param.getMapId() == null || StringUtils.isBlank(param.getAddress())){
|
|
|
+ throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS);
|
|
|
+ }
|
|
|
+ MapConfig mapConfig = mapConfigService.getById(param.getMapId());
|
|
|
+ if(mapConfig == null || mapConfig.getGeocodeUrl() == null){
|
|
|
+ throw new BusinessException(ResultCode.RECORD_NOT_EXIST);
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ String url = mapConfig.getGeocodeUrl().replace("{address}",param.getAddress());
|
|
|
+ String s = HttpUtil.get(url);
|
|
|
+ JSONObject jsonObject = JSON.parseObject(s);
|
|
|
+ JSONArray jsonArray = jsonObject.getJSONArray(mapConfig.getRespListKey());
|
|
|
+ List<MapVo> mapVos = new ArrayList<>();
|
|
|
+ for (Object object : jsonArray) {
|
|
|
+ JSONObject jsonObject1 = (JSONObject) object;
|
|
|
+ MapVo vo = new MapVo();
|
|
|
+ vo.setLocation(jsonObject1.getString(mapConfig.getRespLocationKey()));
|
|
|
+ vo.setAddress(jsonObject1.getString(mapConfig.getRespAddressKey()));
|
|
|
+ mapVos.add(vo);
|
|
|
+ }
|
|
|
+ return ResultData.ok(mapVos);
|
|
|
+ }catch ( Exception e){
|
|
|
+ log.info("map-error:{}",e);
|
|
|
+ }
|
|
|
+
|
|
|
+ return ResultData.ok();
|
|
|
+ }
|
|
|
}
|
|
|
|