update
This commit is contained in:
@@ -25,6 +25,7 @@ public class RegionData implements PriorityOrdered {
|
||||
private final static Logger LOGGER = LoggerFactory.getLogger(RegionData.class);
|
||||
private final static long REGION_RELOAD_INTERVAL = 1000;
|
||||
private static DBCollection REGION_CONN = null;
|
||||
private static DBCollection TOWN_CONN = null;
|
||||
private static Set<String> ALL_CITY = new HashSet<String>();
|
||||
private static Map<String,List<String>> cityAndAliasMap = new HashMap<String,List<String>>();
|
||||
|
||||
@@ -32,12 +33,15 @@ public class RegionData implements PriorityOrdered {
|
||||
* 城市对应级别Map
|
||||
*/
|
||||
private static Map<String, Integer> cityGradeMap = new HashMap<String, Integer>();
|
||||
|
||||
protected final static Map<String, Map<String, Map<String, Map<String, List<String>>>>> townDataMap = new HashMap<String, Map<String, Map<String, Map<String, List<String>>>>>();
|
||||
|
||||
private static void init() {
|
||||
|
||||
try {
|
||||
REGION_CONN = MongoUtils.getCollectionByName("fangjia", "region_block", MongoUtils.MongoDB_Domain_mongo, MongoUtils.MongoDB_Port_28017);
|
||||
DBCollection SERVER_AREA = MongoUtils.getCollectionByName("fangjia", "server_area", MongoUtils.MongoDB_Domain_mongo, MongoUtils.MongoDB_Port_28017);
|
||||
TOWN_CONN = MongoUtils.getCollectionByName("fangjia", "township", MongoUtils.MongoDB_Domain_mongo, MongoUtils.MongoDB_Port_28017);
|
||||
DBCollection SERVER_AREA = MongoUtils.getCollectionByName("fangjia", "server_area", MongoUtils.MongoDB_Domain_mongo, MongoUtils.MongoDB_Port_28017);
|
||||
DBCursor cursor = SERVER_AREA.find(new BasicDBObject(), new BasicDBObject("display", 1).append("city_grade", 1).append("alias", 1));
|
||||
BasicDBObject dbo;
|
||||
while(cursor.hasNext()){
|
||||
@@ -58,6 +62,7 @@ public class RegionData implements PriorityOrdered {
|
||||
|
||||
start(REGION_RELOAD_INTERVAL);
|
||||
reload();
|
||||
// reloadTown();
|
||||
}
|
||||
|
||||
private static void start(long time) {
|
||||
@@ -114,6 +119,66 @@ public class RegionData implements PriorityOrdered {
|
||||
|
||||
LOGGER.info("RegionData reload() size [" + regionDataMap.size() + "]");
|
||||
}
|
||||
public static void reloadTown(){
|
||||
DBObject query = new BasicDBObject();
|
||||
query.put("year", 2022);
|
||||
|
||||
DBObject fields = new BasicDBObject();
|
||||
fields.put("fangjia_city", 1);
|
||||
fields.put("fangjia_area", 1);
|
||||
fields.put("street_name", 1);
|
||||
fields.put("alias", 1);
|
||||
|
||||
|
||||
DBCursor cursor = TOWN_CONN.find(query, fields);
|
||||
while (cursor.hasNext()) {
|
||||
DBObject dbo = cursor.next();
|
||||
String city = (String) dbo.get("fangjia_city");
|
||||
String region = (String) dbo.get("fangjia_area");
|
||||
String street = (String) dbo.get("street_name");
|
||||
List<String> ps = (List<String>) dbo.get("alias");
|
||||
if(!ALL_CITY.contains(city)){
|
||||
continue;
|
||||
}
|
||||
Map<String, Map<String, Map<String, List<String>>>> cityRegionMap = townDataMap.get(city);
|
||||
if(cityRegionMap == null){
|
||||
cityRegionMap = new HashMap<String, Map<String, Map<String, List<String>>>>();
|
||||
townDataMap.put(city, cityRegionMap);
|
||||
}
|
||||
|
||||
Map<String, Map<String, List<String>>> regoinMap = cityRegionMap.get(region);
|
||||
if(regoinMap == null){
|
||||
regoinMap = new HashMap<String, Map<String, List<String>>>();
|
||||
cityRegionMap.put(region, regoinMap);
|
||||
}
|
||||
|
||||
Map<String, List<String>> townMap = regoinMap.get("street");
|
||||
if(townMap == null){
|
||||
townMap = new HashMap<String, List<String>>();
|
||||
regoinMap.put(street, townMap);
|
||||
}
|
||||
if (CollectionUtils.isNotEmpty(ps) && ps.size() > 1) {
|
||||
Collections.sort(ps, new Comparator<String>() {
|
||||
public int compare(String arg0, String arg1) {
|
||||
if (StringUtils.isBlank(arg0)) {
|
||||
return 1;
|
||||
}
|
||||
if (StringUtils.isBlank(arg1)) {
|
||||
return -1;
|
||||
}
|
||||
return arg1.length() - arg0.length();
|
||||
}
|
||||
});
|
||||
}
|
||||
if(null != ps && !ps.contains(street)){
|
||||
ps.add(street);
|
||||
}
|
||||
townMap.put(street, ps);
|
||||
|
||||
}
|
||||
|
||||
LOGGER.info("TownData reload() size [" + townDataMap.size() + "]");
|
||||
}
|
||||
|
||||
static class ScheduleRunTask extends TimerTask {
|
||||
private int nextScheduleHour;
|
||||
@@ -174,6 +239,28 @@ public class RegionData implements PriorityOrdered {
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
public static String formatStreet(String city, String region, String street) {
|
||||
if (StringUtils.isBlank(region) || StringUtils.isBlank(city) || StringUtils.isBlank(street)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
String ret = null;
|
||||
Map<String, Map<String, Map<String, List<String>>>> cityRegionMap = townDataMap.get(city);
|
||||
if(MapUtils.isNotEmpty(cityRegionMap)){
|
||||
Map<String, Map<String, List<String>>> streetMap = cityRegionMap.get(region);
|
||||
if (MapUtils.isNotEmpty(streetMap)) {
|
||||
for (Map<String, List<String>> crm : streetMap.values()) {
|
||||
if (null != ret) {
|
||||
break;
|
||||
}
|
||||
ret = format(crm, street);
|
||||
}
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
public static String parseRegionFormAddress(String city, String address){
|
||||
if(StringUtils.isBlank(address)){
|
||||
return null;
|
||||
|
||||
Reference in New Issue
Block a user