diff --git a/projects/fangjia-script/src/main/groovy/com/fangjia/script/temp/shenjian/poi/SchoolLatLng.groovy b/projects/fangjia-script/src/main/groovy/com/fangjia/script/temp/shenjian/poi/SchoolLatLng.groovy new file mode 100644 index 000000000..219dd491c --- /dev/null +++ b/projects/fangjia-script/src/main/groovy/com/fangjia/script/temp/shenjian/poi/SchoolLatLng.groovy @@ -0,0 +1,65 @@ +package com.fangjia.script.temp.shenjian.poi + +import com.alibaba.excel.EasyExcel +import com.fangjia.script.temp.shenjian.util.ExcelUtils +import com.fangjia.script.temp.shenjian.util.GaoDeUtils + +import java.util.concurrent.ConcurrentHashMap +import java.util.concurrent.CountDownLatch +import java.util.concurrent.ExecutorService +import java.util.concurrent.Executors + +/** + * 学校经纬度获取 + * + * @author shenjian + * @since 2021/8/16 + */ +class SchoolLatLng { + + static ExecutorService executorService = Executors.newFixedThreadPool(30) + + static String name = "大连市义务教育学校名录test"; + + static void main(String[] args) { + List> schools = ExcelUtils.read(new FileInputStream("D:\\Users\\Domi\\Desktop\\房价网\\项目\\模型\\学校\\" + name + ".xlsx")); + Map> result = new ConcurrentHashMap<>(); + CountDownLatch latch = new CountDownLatch(schools.size()); + + for (List schoolTemp : schools) { + final List school = schoolTemp + executorService.submit(new Runnable() { + @Override + void run() { + try { + def city = "大连" + def list = new ArrayList(); + def address = school.get(4) + def location = GaoDeUtils.parserByGaode(city, address); + if (location && location.lng) { + def lng = Double.valueOf(location.lng) + def lat = Double.valueOf(location.lat) + list.add(lng) + list.add(lat) + result.put(address, list) + } + println("已处理:" + address) + } catch(Exception ex) { + ex.printStackTrace() + } finally { + latch.countDown() + } + } + }) + } + latch.await() + + List> head = new ArrayList<>() + for (List school : schools) { + def address = school.get(4) + school.addAll(result.get(address)) + } + EasyExcel.write("D:\\Users\\Domi\\Desktop\\房价网\\项目\\模型\\学校\\" + name + "结果.xlsx").head(head).sheet("小学").doWrite(schools) + executorService.shutdown() + } +} diff --git a/projects/fangjia-script/src/main/groovy/com/fangjia/script/temp/shenjian/util/ExcelUtils.groovy b/projects/fangjia-script/src/main/groovy/com/fangjia/script/temp/shenjian/util/ExcelUtils.groovy index 229499b80..fa0927eee 100644 --- a/projects/fangjia-script/src/main/groovy/com/fangjia/script/temp/shenjian/util/ExcelUtils.groovy +++ b/projects/fangjia-script/src/main/groovy/com/fangjia/script/temp/shenjian/util/ExcelUtils.groovy @@ -13,36 +13,36 @@ import com.alibaba.excel.event.AnalysisEventListener */ class ExcelUtils { - static List> read(String filePath) { - SimpleExcelListener listener = new SimpleExcelListener(filePath); - ExcelReader excelReader = EasyExcelFactory.read(filePath, null, listener).headRowNumber(0).build(); - excelReader.readAll() + public static List> read(InputStream inputStream) { + SimpleExcelListener listener = new SimpleExcelListener(); + ExcelReader excelReader = EasyExcelFactory.read(inputStream, null, listener) + .headRowNumber(1).build(); + excelReader.readAll(); List> dataList = listener.getDataList(); - excelReader.finish() + excelReader.finish(); return dataList; } - class SimpleExcelListener extends AnalysisEventListener { - - private List> dataList = new ArrayList<>() + public static class SimpleExcelListener extends AnalysisEventListener { + private List> dataList = new ArrayList<>(); @Override - void invoke(Object o, AnalysisContext analysisContext) { - Map map = o; - dataList.add(new ArrayList(map.values())) + public void invoke(Object o, AnalysisContext analysisContext) { + Map map = (Map) o; + dataList.add(new ArrayList<>(map.values())); } @Override - void doAfterAllAnalysed(AnalysisContext analysisContext) { + public void doAfterAllAnalysed(AnalysisContext analysisContext) { } List> getDataList() { - return dataList + return dataList; } void setDataList(List> dataList) { - this.dataList = dataList + this.dataList = dataList; } } }