瀏覽代碼

同步修改居委并返回居委编码

DESKTOP-6LTVLN7\Liumouren 4 周之前
父節點
當前提交
1e4ad8d4e7

+ 4 - 10
src/main/java/com/skyversation/poiaddr/addquery/AddressQueryEngine.java

@@ -8,7 +8,6 @@ import com.skyversation.poiaddr.bean.YyskDmdzAddressStandardization;
 import com.skyversation.poiaddr.entity.AddrBean;
 import com.skyversation.poiaddr.service.AreaService;
 import com.skyversation.poiaddr.util.AddrSplitLmrMap;
-import com.skyversation.poiaddr.util.AddressTools;
 import com.skyversation.poiaddr.util.ShanghaiAddressSplitUtil;
 import com.skyversation.poiaddr.util.SplitAddress;
 import com.skyversation.poiaddr.util.net.AddressNetTools;
@@ -274,15 +273,6 @@ public class AddressQueryEngine {
             AreaService areaService = AreaService.getInstance();
             for (AddressResult.ContentBean content : result.getData()) {
                 if (content.getLat() != null && content.getLon() != null) {
-//                  调整逻辑,不管有没有居委信息全部都以geojson的定位为准,如果有定位和地址不匹配的情况,就属于地址库中的脏数据(直接在数据库中找到这条记录并删除旧好了),这样调整之后就会导致普遍查询时间变长
-                    /*GeoJsonBean cjBean = areaService.isInResidentialCommitteePolygon(content.getLon(), content.getLat());
-                    if (cjBean != null && cjBean.getProperties() != null) {
-                        content.setPname("上海市");
-                        content.setCityname(cjBean.getProperties().getString("所属区"));
-                        content.setAdname(cjBean.getProperties().getString("所属街"));
-                        content.setCommunityCode(cjBean.getProperties().getString("居委会"));
-                        content.setCommunity(cjBean.getProperties().getString("居委_1"));
-                    }*/
 //                  判断是否存在村居数据
                     if (content.getCommunity() == null || content.getCommunity().isEmpty()) {
                         GeoJsonBean cjBean = areaService.isInResidentialCommitteePolygon(content.getLon(), content.getLat());
@@ -332,6 +322,10 @@ public class AddressQueryEngine {
                     e.printStackTrace();
                     System.err.println("getCjWgWgwByLoc方法获取路名室号等信息处理逻辑异常" + e);
                 }
+//              TODO 添加逻辑,(什么都有就是没有居委编码的话,要补全居委编码)
+                if (StringUtils.hasText(content.getCityname()) && StringUtils.hasText(content.getCommunity()) && StringUtils.hasText(content.getAdname()) && !StringUtils.hasText(content.getCommunityCode())) {
+                    content.setCommunityCode(AddrSplitLmrMap.outCommunityCodeByInfo(content.getCityname(), content.getAdname(), content.getCommunity()));
+                }
             }
             return result;
         }

+ 41 - 2
src/main/java/com/skyversation/poiaddr/service/AreaService.java

@@ -85,6 +85,44 @@ public class AreaService {
     public List<GeoJsonBean> zhwgPolygonList = new ArrayList<>();
     public StringBuffer geojsonStr = new StringBuffer();
 
+    /**
+     * 读取最新的村居geojson文件
+     * 读取数据并生成新的xlsx文件
+     */
+    public static void putNewXlsxCunju(){
+        String filePath = "C:\\Users\\Liumouren\\Desktop\\上海市_村居边界.geojson";
+        String outFilePath = "C:\\Users\\Liumouren\\Desktop\\上海市_村居边界.xlsx";
+        // 创建ObjectMapper实例
+        ObjectMapper objectMapper = new ObjectMapper();
+        List<Map<String,Object>> outFileDatas = new ArrayList<>();
+        try {
+            // 读取JSON文件并转换为String
+            String appendJsonContent = objectMapper.readTree(new File(filePath)).toString();
+//          暂存所有新松江数据
+            JSONArray appendFeatures = JSONObject.parseObject(appendJsonContent).getJSONArray("features");
+            for (int i = 0; i < appendFeatures.size(); i++) {
+                JSONObject featureItem = appendFeatures.getJSONObject(i);
+//              替换属性中的key,不影响旧代码使用
+                JSONObject properties = featureItem.getJSONObject("properties");
+                Map<String,Object> dataItem = new HashMap<>();
+                dataItem.put("区",properties.getString("所属区"));
+                dataItem.put("镇",properties.getString("所属街"));
+                dataItem.put("居委",properties.getString("居委_1"));
+                dataItem.put("居委编码",properties.getString("code"));
+                outFileDatas.add(dataItem);
+            }
+            try {
+                ExcelReaderUtils.writeToExcel(outFileDatas,outFilePath);
+                System.out.println("文件保存成功!路径:" + outFilePath);
+            } catch (IOException e) {
+                System.err.println("文件保存失败:" + e.getMessage());
+                e.printStackTrace();
+            }
+        } catch (IOException e) {
+            e.printStackTrace();
+        }
+    }
+
     /**
      * 加载村居边界geojson文件获取所有的居委并进行统计
      * 找出所有有问题(xx公司、xx工作站、xx区)的居委,并列出
@@ -92,7 +130,8 @@ public class AreaService {
      * @param args
      */
     public static void main(String[] args) {
-        // JSON文件路径
+        putNewXlsxCunju();
+        /*// JSON文件路径
         String appendFilePath = "C:\\Users\\Liumouren\\Desktop\\GWS84(国际通用)sj_jw_0416.json";
         String filePath = "C:\\Users\\Liumouren\\Desktop\\上海市_村居边界.geojson";
         // 创建ObjectMapper实例
@@ -138,7 +177,7 @@ public class AreaService {
             }
         } catch (IOException e) {
             e.printStackTrace();
-        }
+        }*/
     }
 
     @PostConstruct

+ 9 - 2
src/main/java/com/skyversation/poiaddr/util/AddrSplitLmrMap.java

@@ -29,7 +29,7 @@ public class AddrSplitLmrMap {
     private static HashMap<String, HashMap<String, Set<String>>> D_S_C_tree = new HashMap<>();
     //    非上海的《省-市-区》的对应关系
     private static HashMap<String, HashMap<String, Set<String>>> All_NO_SH_tree = new HashMap<>();
-    //  区和区代码的对应关系
+    //  区、街镇、居委和居委编码的对应关系
     private static HashMap<String, String> districtCodeMap = new HashMap<>();
 
     @PostConstruct
@@ -40,7 +40,7 @@ public class AddrSplitLmrMap {
         if (is == null) throw new RuntimeException("无法找到" + outPutFilePath);
         try {
             for (Map<String, Object> row : ExcelReaderUtils.readExcel(is)) {
-                districtCodeMap.put(row.get("区").toString(), row.get("区代码").toString());
+                districtCodeMap.put(row.get("区").toString() + row.get("镇").toString() + row.get("居委").toString(), row.get("居委编码").toString());
                 if (D_S_C_tree.containsKey(row.get("区").toString())) {
                     Map<String, Set<String>> SCT = D_S_C_tree.get(row.get("区").toString());
                     if (SCT.containsKey(row.get("镇").toString())) {
@@ -112,6 +112,13 @@ public class AddrSplitLmrMap {
     static Pattern pattern = Pattern.compile("市|区|镇|街道|大道|县");
     static Pattern spattern = Pattern.compile("路|街|大道|村");
 
+    public static String outCommunityCodeByInfo(String city, String adname, String community) {
+        if (districtCodeMap.containsKey(city + adname + community)) {
+            return districtCodeMap.get(city + adname + community);
+        }
+        return null;
+    }
+
     public static AddrBean outAddrMapInAddr(String addr) {
         AddrBean addrMap = new AddrBean();
         addrMap.setOldAddress(addr + "");

二進制
src/main/resources/geojson/上海市_村居边界.xlsx