From 38c28bc2e9484f5ab40206f05dd3b550bee12b40 Mon Sep 17 00:00:00 2001 From: Jian Shen Date: Fri, 4 Mar 2022 17:27:25 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E9=87=8D=E5=BA=86=E5=86=9C?= =?UTF-8?q?=E5=95=86=E8=A1=8C=E6=B5=8B=E8=AF=95=E8=84=9A=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/fangjia/core/util/DataUtil.java | 19 +++++ .../FillTownshipAndCommunityFromExcel.groovy | 39 +++++++++ .../shenjian/address/GetAddressDetail.groovy | 79 +++++++++++++++++++ .../temp/shenjian/poi/GetCodeFromExcel.groovy | 48 +++++++++++ 4 files changed, 185 insertions(+) create mode 100644 projects/fangjia-script/src/main/groovy/com/fangjia/script/temp/shenjian/address/FillTownshipAndCommunityFromExcel.groovy create mode 100644 projects/fangjia-script/src/main/groovy/com/fangjia/script/temp/shenjian/address/GetAddressDetail.groovy create mode 100644 projects/fangjia-script/src/main/groovy/com/fangjia/script/temp/shenjian/poi/GetCodeFromExcel.groovy diff --git a/projects/fangjia-core/src/main/java/com/fangjia/core/util/DataUtil.java b/projects/fangjia-core/src/main/java/com/fangjia/core/util/DataUtil.java index 93218b265..c681c113d 100644 --- a/projects/fangjia-core/src/main/java/com/fangjia/core/util/DataUtil.java +++ b/projects/fangjia-core/src/main/java/com/fangjia/core/util/DataUtil.java @@ -1435,6 +1435,25 @@ public class DataUtil { return null; } + /** + * 匹配符合条件的字符串 + * + * @param str + * @param pattern + * @return + */ + public static List matchAll(String str, Pattern pattern) { + if (str == null) { + return null; + } + List list = new ArrayList(); + Matcher matcher = pattern.matcher(str); + while (matcher.find()) { + list.add(matcher.group()); + } + return list; + } + public static boolean isNumeric(String str) { try { Double.parseDouble(str); diff --git a/projects/fangjia-script/src/main/groovy/com/fangjia/script/temp/shenjian/address/FillTownshipAndCommunityFromExcel.groovy b/projects/fangjia-script/src/main/groovy/com/fangjia/script/temp/shenjian/address/FillTownshipAndCommunityFromExcel.groovy new file mode 100644 index 000000000..79cf910db --- /dev/null +++ b/projects/fangjia-script/src/main/groovy/com/fangjia/script/temp/shenjian/address/FillTownshipAndCommunityFromExcel.groovy @@ -0,0 +1,39 @@ +package com.fangjia.script.temp.shenjian.address + +import com.fangjia.script.util.ExcelUtils +import org.apache.commons.lang.StringUtils + +/** + * 补充详细地址中缺失的乡镇街道与居委社区 + */ +ExcelUtils.multiThreadingModify("D:\\Users\\Domi\\Documents\\知识库\\重庆农商行\\重庆农商行测试地址V11(优化详细地址) .xlsx", { + List item -> + def area = item['F'] + def township = item['G'] + def community = item['H'] + String detailAddr = item['I'] + + // 不包含街道与居委 + if (StringUtils.isNotBlank(township) && StringUtils.isNotBlank(community) && + !detailAddr.contains(township) && !detailAddr.contains(community) ) { + if (StringUtils.isNotBlank(area)) { + int index = detailAddr.indexOf(area + "区") + area.length() + 2 + item['K'] = detailAddr.substring(0, index) + township + community + + detailAddr.substring(index) + } + // 不包含社区 + } else if (StringUtils.isNotBlank(township) && StringUtils.isNotBlank(community) && + detailAddr.contains(township) && !detailAddr.contains(community)) { + int index = detailAddr.indexOf(township) + township.length() + 1 + item['K'] = detailAddr.substring(0, index) + community + + detailAddr.substring(index) + } // 只不包含街道 + else if (StringUtils.isNotBlank(township) && StringUtils.isNotBlank(community) && + !detailAddr.contains(township) && detailAddr.contains(community)) { + if (StringUtils.isNotBlank(area)) { + int index = detailAddr.indexOf(area + "区") + area.length() + 2 + item['K'] = detailAddr.substring(0, index) + township + + detailAddr.substring(index) + } + } +}) \ No newline at end of file diff --git a/projects/fangjia-script/src/main/groovy/com/fangjia/script/temp/shenjian/address/GetAddressDetail.groovy b/projects/fangjia-script/src/main/groovy/com/fangjia/script/temp/shenjian/address/GetAddressDetail.groovy new file mode 100644 index 000000000..b77b6d36c --- /dev/null +++ b/projects/fangjia-script/src/main/groovy/com/fangjia/script/temp/shenjian/address/GetAddressDetail.groovy @@ -0,0 +1,79 @@ +package com.fangjia.script.temp.shenjian.address + +import com.fangjia.core.util.DataUtil +import com.fangjia.script.util.ExcelUtils +import net.sf.json.JSONObject +import org.apache.commons.lang.StringUtils + +import java.util.regex.Pattern + +//ExcelUtils.removeEmptyRow("D:\\Users\\Domi\\Documents\\知识库\\重庆农商行\\重庆农商行测试地址V10(优化补充社区冗余信息).xlsx") +ners = ["houseno", "cellno", "floorno", "roomno"] +Pattern GROUP_PATTERN = Pattern.compile("[一二三四五六七八九十甲乙丙丁\\d]+组") +ExcelUtils.multiThreadingModify("D:\\Users\\Domi\\Documents\\知识库\\重庆农商行\\重庆农商行测试地址V11(优化详细地址) .xlsx",{List item-> + + if (StringUtils.isNotBlank(item["J"])) { + //item["I"] = item["J"] + //item["W"] = "详细地址替换" + } +// def addr = item["B"].toString() +// def detailAddr = item["I"]?.toString() +// def pd = item["C"] +// item['J'] = "" +// if (StringUtils.isNotBlank(pd)) { +// int len = addr.lastIndexOf(pd) +// if (len > 3) { +// String aim = addr.substring(len - 3, len) +// int aimIndex = detailAddr.lastIndexOf(aim) +// if (aimIndex > 0) { +// item['J'] = detailAddr.substring(0, aimIndex + 3) + pd +// } +// } +// } + +// if(detailAddr{ +// String group = DataUtil.match(pd, GROUP_PATTERN) +// if(group == null ){ +// return +// } +// def arabic_group = null +// if(!detailAddr.contains(group)){ +// arabic_group = CNNMFilter.qCNNumericToArabic(group) +// } +// if(group){ +// def flg = addr.substring(addr.indexOf(group) - 3, addr.indexOf(group)) +// flg = flg.replace("-", "") +// if(arabic_group != null){ +// group = arabic_group +// } +// if(!detailAddr.contains(flg + group)){ +// println(item) +// detailAddr = detailAddr.replace(group, '') +// def idx = detailAddr.lastIndexOf(flg) +// try{ +// detailAddr = detailAddr.substring(0, idx) + flg + group + detailAddr.substring(idx + flg.length()) +// item["j"] = detailAddr +// }catch(Exception e){ +// item["W"] ="组替换失败" +// } +// +// +// } +// } +// } + +// HttpRequest request = new HttpRequest() +// JSONObject result = request.getJsonContent("http://192.168.0.19:31080/FangJiaNlpService/ner",["address":addr], "utf-8") +// def index = Integer.MAX_VALUE +// for(JSONObject entity : result.entities){ +// if(entity.type in ners){ +// if(entity.start < index){ +// index = entity.start +// } +// } +// } +// if(index != Integer.MAX_VALUE){ +// item["C"] = addr.substring(index) +// println(item) +// } +}) diff --git a/projects/fangjia-script/src/main/groovy/com/fangjia/script/temp/shenjian/poi/GetCodeFromExcel.groovy b/projects/fangjia-script/src/main/groovy/com/fangjia/script/temp/shenjian/poi/GetCodeFromExcel.groovy new file mode 100644 index 000000000..f466ed3be --- /dev/null +++ b/projects/fangjia-script/src/main/groovy/com/fangjia/script/temp/shenjian/poi/GetCodeFromExcel.groovy @@ -0,0 +1,48 @@ +package com.fangjia.script.temp.shenjian.poi + +import com.fangjia.script.statistics.poi.AmapPoi +import com.fangjia.script.temp.shenjian.util.GaoDeUtils +import com.fangjia.script.util.MongoUtils +import com.mongodb.BasicDBObject +import com.mongodb.DBCollection +import com.mongodb.DBObject +import org.apache.commons.collections.CollectionUtils +import org.apache.commons.lang.StringUtils + +final DBCollection villagesConn = MongoUtils.getCollectionByName("fangjia", "villages", "192.168.0.43", 28017) + +/** + * 获取省市区编码 + */ +com.fangjia.script.util.ExcelUtils.multiThreadingModify("D:\\Users\\Domi\\Documents\\知识库\\重庆农商行\\重庆农商行测试地址V9(补全省市区代码).xlsx",{List item-> + + def province = item['C'] + def city = item['D'] + def area = item['E'] + if (StringUtils.isBlank(province) && city == '重庆' && item['K'] == null) { + item['J'] = '5000000' + if (StringUtils.isNotBlank(city) && StringUtils.isNotBlank(area)) { + villagesConn.find(new BasicDBObject("province_name", "重庆市") + .append("area_name", new BasicDBObject('$regex', '^' + area)), new BasicDBObject() ) + .limit(1).each {obj -> + item['J'] = obj.province_code + item['K'] = obj.area_code + } + } + } else if (StringUtils.isNotBlank(province) && StringUtils.isNotBlank(city) && StringUtils.isNotBlank(area) && item['K'] == null) { + villagesConn.find(new BasicDBObject("province_name", new BasicDBObject('$regex', '^' + province)) + .append("city_name", new BasicDBObject('$regex', '^' + city)) + .append("area_name", new BasicDBObject('$regex', '^' + area)), new BasicDBObject() ) + .limit(1).each {obj -> + item['I'] = obj.province_code + item['J'] = obj.city_code + item['K'] = obj.area_code + } + } + if (item['I'] != null) { + item['I'] = (String.valueOf(item['I']).replace(".0", "") + "000000").substring(0, 6); + } + if (item['J'] != null) { + item['J'] = (String.valueOf(item['J']).replace(".0", "") + "000000").substring(0, 6); + } +})