Merge remote-tracking branch 'origin/script_develop' into script_develop

This commit is contained in:
沈健
2021-08-16 15:55:30 +08:00
2 changed files with 79 additions and 14 deletions
@@ -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<List<String>> schools = ExcelUtils.read(new FileInputStream("D:\\Users\\Domi\\Desktop\\房价网\\项目\\模型\\学校\\" + name + ".xlsx"));
Map<String, List<String>> result = new ConcurrentHashMap<>();
CountDownLatch latch = new CountDownLatch(schools.size());
for (List<String> schoolTemp : schools) {
final List<String> 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<List<String>> head = new ArrayList<>()
for (List<String> 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()
}
}
@@ -13,36 +13,36 @@ import com.alibaba.excel.event.AnalysisEventListener
*/
class ExcelUtils {
static List<List<String>> read(String filePath) {
SimpleExcelListener listener = new SimpleExcelListener(filePath);
ExcelReader excelReader = EasyExcelFactory.read(filePath, null, listener).headRowNumber(0).build();
excelReader.readAll()
public static List<List<String>> read(InputStream inputStream) {
SimpleExcelListener listener = new SimpleExcelListener();
ExcelReader excelReader = EasyExcelFactory.read(inputStream, null, listener)
.headRowNumber(1).build();
excelReader.readAll();
List<List<String>> dataList = listener.getDataList();
excelReader.finish()
excelReader.finish();
return dataList;
}
class SimpleExcelListener extends AnalysisEventListener {
private List<List<String>> dataList = new ArrayList<>()
public static class SimpleExcelListener extends AnalysisEventListener {
private List<List<String>> dataList = new ArrayList<>();
@Override
void invoke(Object o, AnalysisContext analysisContext) {
Map<String, String> map = o;
dataList.add(new ArrayList<String>(map.values()))
public void invoke(Object o, AnalysisContext analysisContext) {
Map<String, String> map = (Map<String, String>) o;
dataList.add(new ArrayList<>(map.values()));
}
@Override
void doAfterAllAnalysed(AnalysisContext analysisContext) {
public void doAfterAllAnalysed(AnalysisContext analysisContext) {
}
List<List<String>> getDataList() {
return dataList
return dataList;
}
void setDataList(List<List<String>> dataList) {
this.dataList = dataList
this.dataList = dataList;
}
}
}