从数据库读取待标准化输出
This commit is contained in:
+63
@@ -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<List<String>> 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<String> head = new ArrayList<>()
|
||||
for (String name: headArr) {
|
||||
List<String> temp = new ArrayList<>()
|
||||
temp.add(name)
|
||||
head.add(temp)
|
||||
}
|
||||
EasyExcel.write("F:\\工作\\基础建设\\标准化\\标准化融合后测试数据(标准化后).xlsx").head(head).sheet("测试数据").doWrite(data);
|
||||
|
||||
executorService.shutdown()
|
||||
}
|
||||
}
|
||||
+14
-11
@@ -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<List<String>> data = ExcelUtils.read("F:\\工作\\基础建设\\标准化\\标准化融合后测试数据.xlsx")
|
||||
CountDownLatch latch = new CountDownLatch(data.size())
|
||||
for (List<String> 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()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user