Commit 38be1e4e authored by yanzg's avatar yanzg

修改实例化关系

parent 73081c15
...@@ -60,7 +60,7 @@ public class AreaHelper { ...@@ -60,7 +60,7 @@ public class AreaHelper {
String city = fromAreaId.substring(3); String city = fromAreaId.substring(3);
String ret = city.substring(0, length - 3); String ret = city.substring(0, length - 3);
String retSimple = getSimple(ret); String retSimple = getSimple(ret, false);
if (StringHelper.compare(ret, retSimple)) { if (StringHelper.compare(ret, retSimple)) {
return getFull(country + retSimple); return getFull(country + retSimple);
} }
...@@ -74,11 +74,21 @@ public class AreaHelper { ...@@ -74,11 +74,21 @@ public class AreaHelper {
* @return * @return
*/ */
public static String getSimple(String fromAreaId) { public static String getSimple(String fromAreaId) {
return getSimple(fromAreaId, true);
}
/**
* 获取简写Id
*
* @param fromAreaId
* @return
*/
public static String getSimple(String fromAreaId, boolean isFull) {
if (StringHelper.isEmpty(fromAreaId) || fromAreaId.length() <= 3) { if (StringHelper.isEmpty(fromAreaId) || fromAreaId.length() <= 3) {
return fromAreaId; return fromAreaId;
} }
String to = StringHelper.trimEnd(fromAreaId, "00"); String to = StringHelper.trimEnd(fromAreaId, "00");
if (to.length() < COUNTRY_LENGTH) { if (to.length() < COUNTRY_LENGTH && isFull) {
to = getFull(to).substring(0, COUNTRY_LENGTH); to = getFull(to).substring(0, COUNTRY_LENGTH);
} }
return to; return to;
...@@ -115,7 +125,7 @@ public class AreaHelper { ...@@ -115,7 +125,7 @@ public class AreaHelper {
if (StringHelper.isEmpty(fromAreaId)) { if (StringHelper.isEmpty(fromAreaId)) {
return fromAreaId; return fromAreaId;
} }
String simpleId = getSimple(fromAreaId); String simpleId = getSimple(fromAreaId, true);
String parentSimpleId = StringHelper.EMPTY; String parentSimpleId = StringHelper.EMPTY;
if (simpleId.length() > COUNTRY_LENGTH) { if (simpleId.length() > COUNTRY_LENGTH) {
parentSimpleId = simpleId.substring(0, simpleId.length() - 2); parentSimpleId = simpleId.substring(0, simpleId.length() - 2);
......
...@@ -8,6 +8,7 @@ public class TestAreaHelper { ...@@ -8,6 +8,7 @@ public class TestAreaHelper {
public void test() { public void test() {
System.out.println(AreaHelper.getSimple("100000000")); System.out.println(AreaHelper.getSimple("100000000"));
System.out.println(AreaHelper.getFull("100")); System.out.println(AreaHelper.getFull("100"));
System.out.println(AreaHelper.getAreaId("100000000"));
String from = "100500103"; String from = "100500103";
// from = 1999; // from = 1999;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment