From f4bd346bb43a0b733fb8519df3a6f272b75afabf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B2=88=E5=81=A5?= Date: Tue, 22 Jun 2021 14:21:37 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BB=8E=E6=95=B0=E6=8D=AE=E5=BA=93=E8=AF=BB?= =?UTF-8?q?=E5=8F=96=E5=BE=85=E6=A0=87=E5=87=86=E5=8C=96=E8=BE=93=E5=87=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../address/ExportStandardResult.groovy | 63 +++++++++++++++++++ .../temp/shenjian/address/StandardTest.groovy | 25 ++++---- 2 files changed, 77 insertions(+), 11 deletions(-) create mode 100644 projects/fangjia-script/src/main/groovy/com/fangjia/script/temp/shenjian/address/ExportStandardResult.groovy diff --git a/projects/fangjia-script/src/main/groovy/com/fangjia/script/temp/shenjian/address/ExportStandardResult.groovy b/projects/fangjia-script/src/main/groovy/com/fangjia/script/temp/shenjian/address/ExportStandardResult.groovy new file mode 100644 index 000000000..bc2365983 --- /dev/null +++ b/projects/fangjia-script/src/main/groovy/com/fangjia/script/temp/shenjian/address/ExportStandardResult.groovy @@ -0,0 +1,63 @@ +package com.fangjia.script.temp.shenjian.address + +import com.alibaba.excel.EasyExcel +import com.fangjia.script.util.MongoUtils +import com.mongodb.BasicDBObject +import com.mongodb.DBCollection + +import java.util.concurrent.ConcurrentHashMap +import java.util.concurrent.CountDownLatch +import java.util.concurrent.ExecutorService +import java.util.concurrent.Executors + +/** + * 导出标准化输出结果 + * + * @author shenjian + * @since 2021/6/22 + */ +class ExportStandardResult { + static ExecutorService executorService = Executors.newFixedThreadPool(30) + static DBCollection conn136 = MongoUtils.getCollectionByName("fangjia", "address_standard", "192.168.0.136", 27017) + + static void main(String[] args) { + List> data = new ArrayList<>() + def map = new ConcurrentHashMap() + CountDownLatch latch = new CountDownLatch(conn136.count().intValue()) + conn136.find(new BasicDBObject(), new BasicDBObject("address", 1).append("city", 1) + .append("format_address", 1).append("order", 1)).batchSize(10000).each { + objT -> + final obj = objT + executorService.submit(new Runnable() { + @Override + void run() { + try { + def ret = [] + ret[0] = obj.city + ret[1] = obj.address + ret[2] = obj.format_address + map.put(obj.order, ret) + } catch (Exception ex) { + ex.printStackTrace() + } finally { + latch.countDown() + } + } + }) + } + latch.await() + for (int i = 0; i < map.size(); i++) { + data.add(map.get(i)) + } + def headArr = ["城市", "地址", "标准化输出"] + List head = new ArrayList<>() + for (String name: headArr) { + List temp = new ArrayList<>() + temp.add(name) + head.add(temp) + } + EasyExcel.write("F:\\工作\\基础建设\\标准化\\标准化融合后测试数据(标准化后).xlsx").head(head).sheet("测试数据").doWrite(data); + + executorService.shutdown() + } +} diff --git a/projects/fangjia-script/src/main/groovy/com/fangjia/script/temp/shenjian/address/StandardTest.groovy b/projects/fangjia-script/src/main/groovy/com/fangjia/script/temp/shenjian/address/StandardTest.groovy index 3b3cca4f5..b42c0b70d 100644 --- a/projects/fangjia-script/src/main/groovy/com/fangjia/script/temp/shenjian/address/StandardTest.groovy +++ b/projects/fangjia-script/src/main/groovy/com/fangjia/script/temp/shenjian/address/StandardTest.groovy @@ -3,6 +3,9 @@ package com.fangjia.script.temp.shenjian.address import com.alibaba.fastjson.JSONObject import com.fangjia.core.util.HttpRequest import com.fangjia.script.util.ExcelUtils +import com.fangjia.script.util.MongoUtils +import com.mongodb.BasicDBObject +import com.mongodb.DBCollection import java.util.concurrent.CountDownLatch import java.util.concurrent.ExecutorService @@ -18,25 +21,28 @@ import java.util.concurrent.atomic.AtomicLong class StandardTest { static ExecutorService executorService = Executors.newFixedThreadPool(10) + static DBCollection conn136 = MongoUtils.getCollectionByName("fangjia", "address_standard", "192.168.0.136", 27017) static void main(String[] args) { AtomicLong count = new AtomicLong(0) - List> data = ExcelUtils.read("F:\\工作\\基础建设\\标准化\\标准化融合后测试数据.xlsx") - CountDownLatch latch = new CountDownLatch(data.size()) - for (List rowT : data) { - final row = rowT; + CountDownLatch latch = new CountDownLatch(conn136.count(new BasicDBObject('status', 1)).intValue()) + conn136.find(new BasicDBObject('status', 1)).batchSize(3000).each {objT -> + final def obj = objT executorService.submit(new Runnable() { @Override void run() { try { - def address = row[0] - def city = row[2] + def address = obj.address + def city = obj.city == null ? "" : obj.city HttpRequest request = new HttpRequest() String result = request.get("http://192.168.20.86:8082/structure?city=" + URLEncoder.encode(city, "utf-8") + "&address=" + URLEncoder.encode(address, "utf-8"), "utf-8") JSONObject object = JSONObject.parse(result); if (object.get("status") == 0) { - row[7] = (((JSONObject) object.get("result")).get("formatAddress")) + def format_address = (((JSONObject) object.get("result")).get("formatAddress")) + conn136.update(new BasicDBObject("_id", obj._id), new BasicDBObject('$set', new BasicDBObject("status", 0).append("format_address", format_address).append("flag", "已标准化输出"))) + } else { + conn136.update(new BasicDBObject("_id", obj._id), new BasicDBObject('$set', new BasicDBObject("status", 2).append("flag", "标准化输出异常"))) } } catch(Exception ex) { ex.printStackTrace() @@ -50,11 +56,8 @@ class StandardTest { } } }) - } + }; latch.await() - def headers = ["原始地址", "XH", "城市", "区域","小区名", "标注", "备注", "标准化地址"] - data.add(0, headers) - ExcelUtils.write("F:\\工作\\基础建设\\标准化\\标准化融合后测试数据(标准化后).xlsx", data, "测试数据") executorService.shutdown() } }