This commit is contained in:
2023-06-25 09:37:22 +08:00
parent 077407ce31
commit 0f4467142d
2 changed files with 23 additions and 18 deletions

View File

@@ -5,6 +5,7 @@ import com.jsowell.pile.dto.amap.GetStationInfoDTO;
import com.jsowell.thirdparty.amap.domain.AMapStationInfo;
import java.util.List;
import java.util.concurrent.ExecutionException;
/**
* 高德地图Service
@@ -19,7 +20,7 @@ public interface AMapService {
* @param dto
* @return
*/
List<AMapStationInfo> getStationInfos(GetStationInfoDTO dto);
List<AMapStationInfo> getStationInfos(GetStationInfoDTO dto) throws ExecutionException, InterruptedException;
/**
* 商家推送充电设备动态数据

View File

@@ -29,9 +29,7 @@ import java.text.NumberFormat;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.*;
import java.util.stream.Collectors;
/**
@@ -73,7 +71,7 @@ public class AMapServiceImpl implements AMapService {
* @return
*/
@Override
public List<AMapStationInfo> getStationInfos(GetStationInfoDTO dto) {
public List<AMapStationInfo> getStationInfos(GetStationInfoDTO dto) throws ExecutionException, InterruptedException {
StopWatch sw = new StopWatch();
// List<AMapStationInfo> resultList = new ArrayList<>();
@@ -92,21 +90,27 @@ public class AMapServiceImpl implements AMapService {
}
// 拼装高德格式数据
sw.start("拼装高德格式数据");
// for (PileStationInfo stationInfo : stationInfos) {
//
// // AMapStationInfo aMapStationInfo = assembleAMapData(stationInfo);
// // resultList.add(aMapStationInfo);
// }
List<AMapStationInfo> collect = stationInfos.parallelStream().map(x -> {
try {
return assembleAMapData(x);
} catch (ExecutionException | InterruptedException e) {
throw new RuntimeException(e);
}
}).collect(Collectors.toList());
// 使用自定义ForkJoinPool
List<AMapStationInfo> resultList = new ForkJoinPool(10).submit(() ->
stationInfos.parallelStream().map(x -> {
try {
return assembleAMapData(x);
} catch (ExecutionException | InterruptedException e) {
throw new RuntimeException(e);
}
}).collect(Collectors.toList())
).fork().join();
// List<AMapStationInfo> collect = stationInfos.parallelStream().map(x -> {
// try {
// return assembleAMapData(x);
// } catch (ExecutionException | InterruptedException e) {
// throw new RuntimeException(e);
// }
// }).collect(Collectors.toList());
sw.stop();
log.info("接口耗时:{}, 详情:{}", sw.getTotalTimeMillis(), sw.prettyPrint());
return collect;
return resultList;
}
/**