lyhzzz 1 week ago
parent
commit
a3becc35dc

+ 45 - 4
src/main/java/com/fdkankan/fusion/controller/MapConfigController.java

@@ -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();
+    }
 }
 

+ 12 - 0
src/main/java/com/fdkankan/fusion/entity/MapConfig.java

@@ -34,6 +34,18 @@ public class MapConfig implements Serializable {
     @TableField("coord")
     private String coord;
 
+    @TableField("geocode_url")
+    private String geocodeUrl;
+
+    @TableField("resp_list_key")
+    private String respListKey;
+
+    @TableField("resp_location_key")
+    private String respLocationKey;
+
+    @TableField("resp_address_key")
+    private String respAddressKey;
+
 
     @TableField("tb_status")
     @TableLogic

+ 9 - 0
src/main/java/com/fdkankan/fusion/request/MapParam.java

@@ -0,0 +1,9 @@
+package com.fdkankan.fusion.request;
+
+import lombok.Data;
+
+@Data
+public class MapParam {
+    private String address;
+    private Integer mapId;
+}

+ 9 - 0
src/main/java/com/fdkankan/fusion/response/MapVo.java

@@ -0,0 +1,9 @@
+package com.fdkankan.fusion.response;
+
+import lombok.Data;
+
+@Data
+public class MapVo {
+    private String location;
+    private String address;
+}