mirror of
https://codeup.aliyun.com/67c68d4e484ca2f0a13ac3c1/ydc/jsowell-charger-web.git
synced 2026-04-21 11:35:12 +08:00
update
This commit is contained in:
@@ -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;
|
||||
|
||||
/**
|
||||
* 商家推送充电设备动态数据
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user