Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
J
java-demo
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Leona
W
web
backend
java-demo
Commits
116da754
Commit
116da754
authored
May 22, 2020
by
duanledexianxianxian
😁
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
省市脚本
parent
3c466c7d
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
208 additions
and
0 deletions
+208
-0
data-process/pom.xml
data-process/pom.xml
+40
-0
data-process/src/main/java/com/duanledexianxianxian/data/process/Application.java
...va/com/duanledexianxianxian/data/process/Application.java
+116
-0
data-process/src/main/java/com/duanledexianxianxian/data/process/Model.java
...ain/java/com/duanledexianxianxian/data/process/Model.java
+52
-0
No files found.
data-process/pom.xml
0 → 100644
View file @
116da754
<?xml version="1.0" encoding="UTF-8"?>
<project
xmlns=
"http://maven.apache.org/POM/4.0.0"
xmlns:xsi=
"http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation=
"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
>
<modelVersion>
4.0.0
</modelVersion>
<groupId>
com.duanledexianxianxian.data.process
</groupId>
<artifactId>
data-process
</artifactId>
<version>
1.0.0-SNAPSHOT
</version>
<dependencies>
<dependency>
<groupId>
commons-io
</groupId>
<artifactId>
commons-io
</artifactId>
<version>
2.6
</version>
</dependency>
<dependency>
<groupId>
org.apache.commons
</groupId>
<artifactId>
commons-lang3
</artifactId>
<version>
3.10
</version>
</dependency>
<dependency>
<groupId>
org.apache.commons
</groupId>
<artifactId>
commons-collections4
</artifactId>
<version>
4.4
</version>
</dependency>
<dependency>
<groupId>
com.google.guava
</groupId>
<artifactId>
guava
</artifactId>
<version>
23.0
</version>
</dependency>
<dependency>
<groupId>
org.projectlombok
</groupId>
<artifactId>
lombok
</artifactId>
<version>
1.18.12
</version>
<scope>
provided
</scope>
</dependency>
</dependencies>
</project>
\ No newline at end of file
data-process/src/main/java/com/duanledexianxianxian/data/process/Application.java
0 → 100644
View file @
116da754
package
com.duanledexianxianxian.data.process
;
import
com.google.common.collect.Lists
;
import
com.google.common.collect.Maps
;
import
com.google.common.collect.Sets
;
import
com.sun.org.apache.regexp.internal.RE
;
import
org.apache.commons.collections4.CollectionUtils
;
import
org.apache.commons.io.FileUtils
;
import
org.apache.commons.lang3.StringUtils
;
import
java.io.File
;
import
java.io.IOException
;
import
java.util.*
;
/**
* @author duanledexianxianxian
*/
public
class
Application
{
private
static
Set
<
Model
>
errorSet
=
Sets
.
newHashSet
();
public
static
void
main
(
String
[]
args
)
throws
IOException
{
List
<
String
>
lines
=
readData
();
// 中文数据
String
zh
=
processData
(
lines
,
0
);
writeData
(
"F:\\@project@\\@dianli@\\java-demo\\data-process\\src\\main\\resources\\zh.sql"
,
zh
);
// 英文数据
String
en
=
processData
(
lines
,
1
);
writeData
(
"F:\\@project@\\@dianli@\\java-demo\\data-process\\src\\main\\resources\\en.sql"
,
en
);
System
.
out
.
println
(
"error data"
);
for
(
Model
model:
errorSet
){
System
.
out
.
println
(
model
);
}
}
private
static
void
writeData
(
String
fileName
,
String
content
)
throws
IOException
{
FileUtils
.
write
(
new
File
(
fileName
),
content
,
"UTF-8"
);
}
private
static
List
<
String
>
readData
()
throws
IOException
{
File
file
=
new
File
(
"F:\\@project@\\@dianli@\\java-demo\\data-process\\src\\main\\resources\\省市区码表.csv"
);
List
<
String
>
lines
=
FileUtils
.
readLines
(
file
,
"UTF-8"
);
System
.
out
.
println
(
"lines:"
+
lines
);
return
lines
;
}
private
static
String
processData
(
List
<
String
>
lines
,
int
lang
)
{
List
<
Model
>
modelList
=
Lists
.
newLinkedList
();
Map
<
String
,
Model
>
provinceMap
=
Maps
.
newTreeMap
();
Map
<
String
,
Model
>
allMap
=
Maps
.
newHashMap
();
int
[]
index
=
{
lang
==
0
?
100000
:
200000
};
if
(
CollectionUtils
.
isNotEmpty
(
lines
))
{
lines
.
forEach
(
x
->
{
String
[]
words
=
StringUtils
.
split
(
x
,
"@"
);
System
.
out
.
println
(
"words:"
+
Arrays
.
toString
(
words
));
Model
model
;
model
=
new
Model
();
model
.
setId
((
long
)
index
[
0
]);
model
.
setGrade
(
words
[
0
]);
model
.
setType
(
Integer
.
parseInt
(
words
[
0
]));
model
.
setNameCn
(
words
[
1
]);
model
.
setNameEn
(
words
[
2
]);
model
.
setOrders
(
words
[
3
]);
model
.
setRegCode
(
words
[
4
]);
if
(
words
.
length
<=
5
)
{
model
.
setPId
(
lang
==
0
?
1L
:
242L
);
provinceMap
.
put
(
model
.
getRegCode
(),
model
);
}
else
{
model
.
setBelongTo
(
words
[
5
]);
model
.
setPRegCode
(
words
[
6
]);
}
allMap
.
put
(
model
.
getRegCode
(),
model
);
modelList
.
add
(
model
);
index
[
0
]++;
});
}
System
.
out
.
println
(
"modelList:"
+
modelList
);
System
.
out
.
println
(
"provinceMap:"
+
provinceMap
);
System
.
out
.
println
(
"allMap:"
+
allMap
);
modelList
.
forEach
(
x
->
{
if
(
allMap
.
containsKey
(
x
.
getPRegCode
()))
{
x
.
setPId
(
allMap
.
get
(
x
.
getPRegCode
()).
getId
());
}
});
// 排个序
System
.
out
.
println
(
"modelList:"
+
modelList
);
Collections
.
sort
(
modelList
,
(
o1
,
o2
)
->
{
Integer
result
=
o1
.
getType
()
-
o2
.
getType
();
if
(
result
.
equals
(
0
))
{
return
o1
.
getRegCode
().
compareTo
(
o2
.
getRegCode
());
}
return
result
;
});
System
.
out
.
println
(
"sort modelList"
+
modelList
);
StringBuffer
sb
=
new
StringBuffer
();
modelList
.
forEach
(
x
->
{
if
(
null
!=
x
.
getPId
())
{
sb
.
append
(
String
.
format
(
"INSERT INTO `tsys_business_parameter_geography`(`id`, `pId`, `local`, `district_code`, `district_name`, `type`, `is_delete`, `creator_id`, `create_time`, `editor_id`, `edit_time`) VALUES "
+
"(\"%d\", \"%d\", \"%s\", \"%s\", \"%s\", \"%d\", 0, 1, now(), NULL, NULL);\n"
,
x
.
getId
(),
x
.
getPId
(),
lang
==
0
?
"zh-cn"
:
"en-us"
,
x
.
getRegCode
(),
lang
==
0
?
x
.
getNameCn
()
:
x
.
getNameEn
(),
x
.
getType
()));
}
else
{
errorSet
.
add
(
x
);
}
});
System
.
out
.
println
(
sb
);
return
sb
.
toString
();
}
}
data-process/src/main/java/com/duanledexianxianxian/data/process/Model.java
0 → 100644
View file @
116da754
package
com.duanledexianxianxian.data.process
;
import
com.google.common.base.Objects
;
import
lombok.Data
;
import
lombok.EqualsAndHashCode
;
import
java.io.Serializable
;
/**
* The type Model.
*
* @author duanledexianxianxian
*/
@Data
public
class
Model
implements
Serializable
{
private
Long
id
;
private
Long
pId
;
private
String
grade
;
private
String
nameCn
;
private
String
nameEn
;
private
String
orders
;
private
String
regCode
;
private
String
belongTo
;
private
String
pRegCode
;
/**
* 0-国家
* 1-省
* 2-地级市/区
* 3-县/区
*/
private
Integer
type
;
@Override
public
boolean
equals
(
Object
o
)
{
if
(
this
==
o
)
return
true
;
if
(
o
==
null
||
getClass
()
!=
o
.
getClass
())
return
false
;
Model
model
=
(
Model
)
o
;
return
Objects
.
equal
(
grade
,
model
.
grade
)
&&
Objects
.
equal
(
nameCn
,
model
.
nameCn
)
&&
Objects
.
equal
(
nameEn
,
model
.
nameEn
)
&&
Objects
.
equal
(
orders
,
model
.
orders
)
&&
Objects
.
equal
(
regCode
,
model
.
regCode
)
&&
Objects
.
equal
(
belongTo
,
model
.
belongTo
)
&&
Objects
.
equal
(
pRegCode
,
model
.
pRegCode
)
&&
Objects
.
equal
(
type
,
model
.
type
);
}
@Override
public
int
hashCode
()
{
return
Objects
.
hashCode
(
grade
,
nameCn
,
nameEn
,
orders
,
regCode
,
belongTo
,
pRegCode
,
type
);
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment