1.标准格式为 街道名称,起始门牌号,结束门牌号,单双号
客户输入名称 例:南苏州路1400号
结果:匹配到标准信息
可能出现情况,输入信息中有多个街道名称等 南苏州路xx路路口1400号
@Override
public boolean gather() {
//list 客户输入信息集
//mapList 道路信息集
//TT 信息实体类
List<TT> newlist = ppjd(list, mapList);
}
private List<TT> ppjd(List<tt> list, List<Map> mapList) {
List<TT> newlist = new ArrayList<>();
for (int i = 0; i < list.size(); i++) {
//将地址 拆分成 汉字和数字
String verify = list.get(i);
verify.replace(" ", "");
//全部拆开
List<String> lists = Stream.iterate(0, n -> ++n).limit(verify.length())
.map(n -> "" + verify.charAt(n))
.collect(Collectors.toList());
//用来进行判断数字的
String strNumbers = "0123456789";
int length = 0;//定义索引下标
String[] strs = new String[verify.length()];//再新建个数组,用来存放 当是连续数字时,把那个连续的数据当成一个数组
boolean bool = true;
//遍历拆开的字符串
for (String str : lists) {
int index = strNumbers.indexOf(str);
if (index == -1) {//表示当前值不是数字
strs[length] = str;//直接把当前的值 赋值 给 数组
length++;//索引下标 自增
bool = true; // 锁开启
} else {//表示当前值是数字
if (bool) {
strs[length] = str;
length++;
// sumInteter++;
bool = false;//锁关闭,使锁关闭的原因是当下一个字符是 也数字是运行下面else的操作
} else { //当前值和前一个值也是数字, 就运行这步
//因为之前的索引自增了, 索引必须要-1 ,使用concat把数字链接到前一个值的尾部
strs[length - 1] = strs[length - 1].concat(str);
}
}
}
//存放门牌号
int mp = -1;
for (String str : strs) {
if (str != null) {
if (str.matches("\\d+")) {//纯数字
mp = Integer.parseInt(str);
break;
}
}
}
//拆解 手写地址,和标准地址 进行比对
//存放包含的 标准地址对象
List<Map> mapList1 = new ArrayList<>();
// //存放不包含的 数据对象
// List<TT> ttlist2 = new ArrayList<>();
//是否匹配到社区
boolean ppd = false;
//是否匹配成功Ftt
boolean ppcg = false;
for (int j = 0; j < mapList.size(); j++) {
//将街道拆开
String jd = mapList.get(j).get("街道名称").toString();
jd.replace(" ", "");
List<String> jdList = Stream.iterate(0, n -> ++n).limit(jd.length())
.map(n -> "" + jd.charAt(n))
.collect(Collectors.toList());
//会出现一个地址中 有两个地址字段 例:新闸路石门二路口地面停车场内
if (lists.containsAll(jdList)) {
mapList1.add(mapList.get(j));
ppd = true;
}
}
//匹配到 社区
if (ppd) {
for (Map map : mapList1) {
map.get("");
//手写数据门牌号单双
// 单号
if (mp != -1 && mp % 2 != 0 && "0".equals(map.get("单双号").toString())) {
if (Integer.parseInt(map.get("起始门牌号").toString()) <= mp && mp <= Integer.parseInt(map.get("结束门牌号").toString())) {
list.get(i).setCommitteeId(map.get("居委会ID").toString());
list.get(i).setRoadId(map.get("街道ID").toString());
newlist.add(list.get(i));
ppcg = true;
break;
}
}
}
//没有门牌号 或者匹配失败,就确定居委会
if (!ppcg) {
//重名截取前四个进行比对 新闸路成都北路口 匹配成功跳出
for (int cs = 0; cs < verify.length() - 4; cs++) {
boolean cc = false;
for (Map map : mapList1) {
if (verify.substring(cs, cs+4).indexOf(map.get("街道名称").toString().replace(" ", "")) != -1) {
if (StringUtils.isNotEmpty(map.get("居委会ID").toString()) && StringUtils.isNotEmpty(map.get("街道ID").toString())) {
list.get(i).setCommitteeId(map.get("居委会ID").toString());
list.get(i).setRoadId(map.get("街道ID").toString());
newlist.add(list.get(i));
cc = true;
break;
}
}
}
if(cc){
break;
}
}
// list.get(i).setCommitteeId(mapList1.get(0).get("居委会ID").toString());
// list.get(i).setRoadId(mapList1.get(0).get("街道ID").toString());
// newlist.add(list.get(i));
}
// return newlist;
} else {
for (int cs = 0; cs < verify.length() - 4; cs++) {
TT tt = cfpp(list.get(i), mapList, verify, newlist, cs, mp);
if (StringUtils.isNotEmpty(tt.getRoadId()) ) {
newlist.add(tt);
break;
}
}
}
}
return newlist;
}
private TT cfpp(TT tt, List<Map> mapList, String verify, List<TT> newlist, int cs, int mp) {
// 1.截取0-4直接判断 改地址中 是否包含标准地址库地址
//存放居委会能匹配到的数据
List<Map> newlistmap = new ArrayList<>();
boolean cg = false;
for (int j = 0; j < mapList.size(); j++) {
String jd = mapList.get(j).get("街道名称").toString();
if (verify.substring(cs, cs + 4).indexOf(jd) != -1) {
//包含 是否包含门牌
//有门牌
if (mp != -1 && Integer.parseInt(mapList.get(j).get("起始门牌号").toString()) <= mp && mp <= Integer.parseInt(mapList.get(j).get("结束门牌号").toString())) {
tt.setCommitteeId(mapList.get(j).get("居委会ID").toString());
tt.setRoadId(mapList.get(j).get("街道ID").toString());
break;
}
newlistmap.add(mapList.get(j));
}
}
//没有门牌号能匹配到居委会 (都匹配不到就舍弃)
if (!cg && newlistmap.size() > 0) {
tt.setCommitteeId(newlistmap.get(0).get("居委会ID").toString());
tt.setRoadId(newlistmap.get(0).get("街道ID").toString());
}
return tt;
}