Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in / Register
Toggle navigation
Y
yzg-util
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
YZG
yzg-util
Commits
5043368e
Commit
5043368e
authored
Oct 14, 2020
by
yanzg
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
处理结果
parent
53f0815b
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
31 additions
and
5 deletions
+31
-5
AreaHelper.java
...src/main/java/com/yanzuoguang/util/helper/AreaHelper.java
+26
-5
TestAreaHelper.java
yzg-util-base/src/test/java/helper/TestAreaHelper.java
+5
-0
No files found.
yzg-util-base/src/main/java/com/yanzuoguang/util/helper/AreaHelper.java
View file @
5043368e
...
...
@@ -3,6 +3,9 @@ package com.yanzuoguang.util.helper;
import
com.yanzuoguang.util.exception.CodeException
;
public
class
AreaHelper
{
public
static
final
int
COUNTRY_LENGTH
=
3
;
public
static
final
int
PROVINCE_LENGTH
=
5
;
public
static
final
int
CITY_LENGTH
=
7
;
public
static
final
int
AREA_LENGTH
=
9
;
/**
...
...
@@ -12,7 +15,7 @@ public class AreaHelper {
* @return
*/
public
static
String
getCountryId
(
String
fromAreaId
)
{
return
getLengthId
(
fromAreaId
,
3
);
return
getLengthId
(
fromAreaId
,
COUNTRY_LENGTH
);
}
/**
...
...
@@ -22,7 +25,7 @@ public class AreaHelper {
* @return
*/
public
static
String
getProvinceId
(
String
fromAreaId
)
{
return
getLengthId
(
fromAreaId
,
5
);
return
getLengthId
(
fromAreaId
,
PROVINCE_LENGTH
);
}
/**
...
...
@@ -32,7 +35,7 @@ public class AreaHelper {
* @return
*/
public
static
String
getCityId
(
String
fromAreaId
)
{
return
getLengthId
(
fromAreaId
,
7
);
return
getLengthId
(
fromAreaId
,
CITY_LENGTH
);
}
/**
...
...
@@ -75,8 +78,8 @@ public class AreaHelper {
return
fromAreaId
;
}
String
to
=
StringHelper
.
trimEnd
(
fromAreaId
,
"00"
);
while
(
to
.
length
()
<
3
)
{
to
+=
"0"
;
if
(
to
.
length
()
<
COUNTRY_LENGTH
)
{
to
=
getFull
(
to
).
substring
(
0
,
COUNTRY_LENGTH
)
;
}
return
to
;
}
...
...
@@ -101,4 +104,22 @@ public class AreaHelper {
return
sb
.
toString
();
}
}
/**
* 获取上级目录Id
*
* @param fromAreaId
* @return
*/
public
static
String
getParentId
(
String
fromAreaId
)
{
if
(
StringHelper
.
isEmpty
(
fromAreaId
))
{
return
fromAreaId
;
}
String
simpleId
=
getSimple
(
fromAreaId
);
String
parentSimpleId
=
StringHelper
.
EMPTY
;
if
(
simpleId
.
length
()
>
COUNTRY_LENGTH
)
{
parentSimpleId
=
simpleId
.
substring
(
0
,
simpleId
.
length
()
-
2
);
}
return
getFull
(
parentSimpleId
);
}
}
yzg-util-base/src/test/java/helper/TestAreaHelper.java
View file @
5043368e
...
...
@@ -18,6 +18,11 @@ public class TestAreaHelper {
System
.
out
.
println
(
AreaHelper
.
getProvinceId
(
from
));
System
.
out
.
println
(
AreaHelper
.
getCountryId
(
from
));
System
.
out
.
println
(
AreaHelper
.
getFull
(
from
));
System
.
out
.
println
(
AreaHelper
.
getParentId
(
AreaHelper
.
getCountryId
(
from
)));
System
.
out
.
println
(
AreaHelper
.
getParentId
(
AreaHelper
.
getProvinceId
(
from
)));
System
.
out
.
println
(
AreaHelper
.
getParentId
(
AreaHelper
.
getCityId
(
from
)));
System
.
out
.
println
(
AreaHelper
.
getParentId
(
from
));
}
}
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