Skip to content

Commit cf9fca5

Browse files
committed
Fix cnarea.dat write && bump versions
1 parent ee464df commit cf9fca5

File tree

5 files changed

+24
-22
lines changed

5 files changed

+24
-22
lines changed

README.md

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -138,15 +138,8 @@ Address(
138138

139139
也可以采用[国家的标准地址库][2] (对应的github库, [中国5级行政区域mysql库][3])
140140

141-
### 2.1.1 导入中国5级行政区域mysql库注意事项
142-
0. 本测试配置基于Server version: 8.0.21 MySQL Community Server - GPL环境,其它可能略有差异,可通过下面两个SQL确认配置是否OK
143-
```
144-
show variables like '%CHARACTER%';
145-
show variables like '%max_allowed_packet%';
146-
```
147-
1. 设置max_allowed_packet,[mysqld]下max_allowed_packet = 2000M,[mysqldump]下max_allowed_packet = 2000M
148-
2. 设置字符集,[client]下default-character-set=utf8mb4,[mysqld]下character-set-server=utf8mb4和init_connect='SET NAMES utf8mb4',[mysql]下default-character-set=utf8mb4
149-
141+
## 2.2 导入中国5级行政区域mysql库注意事项
142+
[参考文档](https://github.com/IceMimosa/geocoding/blob/master/src/test/java/io/patamon/geocoding/region/README.md)
150143

151144
## 2.2 标准化
152145
1. 首先基于正则提取出道路、建筑物号等信息

pom.xml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@
1111
<properties>
1212
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
1313
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
14-
<kotlin.version>1.5.20</kotlin.version>
14+
<kotlin.version>1.6.10</kotlin.version>
1515
<lucene.version>8.5.2</lucene.version>
1616
<word.version>1.3</word.version>
17-
<gson.version>2.8.6</gson.version>
17+
<gson.version>2.8.9</gson.version>
1818
<ik.analyzer.version>2012_u6</ik.analyzer.version>
1919
<kotlin.compiler.incremental>true</kotlin.compiler.incremental>
2020
<kotlin.compiler.jvmTarget>1.8</kotlin.compiler.jvmTarget>
@@ -35,13 +35,13 @@
3535
<dependency>
3636
<groupId>commons-io</groupId>
3737
<artifactId>commons-io</artifactId>
38-
<version>2.10.0</version>
38+
<version>2.11.0</version>
3939
<scope>test</scope>
4040
</dependency>
4141
<dependency>
4242
<groupId>com.google.guava</groupId>
4343
<artifactId>guava</artifactId>
44-
<version>30.1.1-jre</version>
44+
<version>31.0.1-jre</version>
4545
<scope>test</scope>
4646
</dependency>
4747

src/test/java/io/patamon/geocoding/region/Main.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ public class Main {
1010
// 导入数据库成功后,执行china.sql,插入数据项:【中国】
1111
public static void main(String[] args) throws IOException {
1212
long start = System.currentTimeMillis();
13-
String pathname = "~/Documents/cnarea" + 20210707 + ".dat";
13+
String pathname = "/tmp/cnarea" + 20210707 + ".dat";
1414
RegionDatFileHelper.writeDatFile(pathname);
1515
long end = System.currentTimeMillis();
1616
OutUtil.info(String.format("cost %s ms", end - start));

src/test/java/io/patamon/geocoding/region/README.md

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,20 @@
66
本package下代码可将 [中国5级行政区域](!https://github.com/kakuilan/china_area_mysql) 处理为兼容geocoding的标准地址库。
77

88
### 使用步骤
9-
1、成功导入china_area_mysql到数据库
10-
2、执行本package下sql/china.sql插`中国`数据
11-
3、修改本package下util/JdbcUtil.java中的jdbc相关参数
12-
4、执行本package下Maine类中main方法
13-
5、将生成的dat文件改名为region.dat并放入`classpath:src/main/resources/core/`
9+
10+
1. 成功导入china_area_mysql到数据库
11+
2. 执行本package下sql/china.sql插`中国`数据
12+
3. 修改本package下util/JdbcUtil.java中的jdbc相关参数
13+
4. 执行本package下Maine类中main方法
14+
5. 将生成的dat文件改名为region.dat并放入`classpath:src/main/resources/core/`
1415

1516
### 注意事项
1617
本测试配置基于Server version: 8.0.21 MySQL Community Server - GPL环境,其它可能略有差异,可通过下面两个SQL确认配置是否OK
18+
1719
```
1820
show variables like '%CHARACTER%';
1921
show variables like '%max_allowed_packet%';
2022
```
23+
2124
1. 设置max_allowed_packet,[mysqld]下max_allowed_packet = 2000M,[mysqldump]下max_allowed_packet = 2000M
2225
2. 设置字符集,[client]下default-character-set=utf8mb4,[mysqld]下character-set-server=utf8mb4和init_connect='SET NAMES utf8mb4',[mysql]下default-character-set=utf8mb4

src/test/java/io/patamon/geocoding/region/RegionDatFileHelper.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ public class RegionDatFileHelper {
2626
final static List<String> provinceLevelCity1 = Lists.newArrayList("北京市", "天津市", "上海市", "重庆市");
2727

2828
public static void writeDatFile(String pathname) throws IOException {
29+
write(pathname, "");
2930
Connection conn = JdbcUtil.getConnection();
3031
if (conn == null) return;
3132
List<RegionEntity> china = Lists.newArrayList();
@@ -81,9 +82,14 @@ private static RegionEntity recursive(RegionEntity parent, List<RegionEntity> li
8182

8283
private static void write(final String fileName, final String contents) throws IOException {
8384
File file = new File(fileName);
84-
file.deleteOnExit();
85-
file.createNewFile();
86-
Files.write(contents.getBytes(), file);
85+
// file.deleteOnExit();
86+
if (!file.exists()) {
87+
Files.createParentDirs(file);
88+
file.createNewFile();
89+
}
90+
if (contents != null && !contents.trim().isEmpty()) {
91+
Files.write(contents.getBytes(), file);
92+
}
8793
}
8894

8995
private static RegionType of(Long id, int level, String name) {

0 commit comments

Comments
 (0)