diff --git a/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/amap/service/impl/AMapServiceImpl.java b/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/amap/service/impl/AMapServiceImpl.java index 8a9cec664..24b5f66d8 100644 --- a/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/amap/service/impl/AMapServiceImpl.java +++ b/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/amap/service/impl/AMapServiceImpl.java @@ -4,6 +4,7 @@ import com.alibaba.fastjson.JSONObject; import com.jsowell.common.exception.BusinessException; import com.jsowell.common.util.PageUtils; import com.jsowell.common.util.StringUtils; +import com.jsowell.common.util.spring.SpringUtils; import com.jsowell.pile.domain.OrderBasicInfo; import com.jsowell.pile.domain.PileBasicInfo; import com.jsowell.pile.domain.PileStationInfo; @@ -28,6 +29,9 @@ 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; /** * 高德地图Service @@ -57,6 +61,11 @@ public class AMapServiceImpl implements AMapService { @Autowired private IOrderBasicInfoService orderBasicInfoService; + /** + * 异步操作任务调度线程池 + */ + private ScheduledExecutorService executor = SpringUtils.getBean("scheduledExecutorService"); + /** * 高德拉取充电站静态数据 * @param dto @@ -83,8 +92,17 @@ public class AMapServiceImpl implements AMapService { // 拼装高德格式数据 sw.start("拼装高德格式数据"); for (PileStationInfo stationInfo : stationInfos) { - AMapStationInfo aMapStationInfo = assembleAMapData(stationInfo); - resultList.add(aMapStationInfo); + CompletableFuture completableFuture = CompletableFuture.supplyAsync(() -> assembleAMapData(stationInfo), executor); + try { + AMapStationInfo aMapStationInfo = completableFuture.get(); + resultList.add(aMapStationInfo); + } catch (InterruptedException e) { + throw new RuntimeException(e); + } catch (ExecutionException e) { + throw new RuntimeException(e); + } + // AMapStationInfo aMapStationInfo = assembleAMapData(stationInfo); + // resultList.add(aMapStationInfo); } sw.stop(); log.info("接口耗时:{}, 详情:{}", sw.getTotalTimeMillis(), sw.prettyPrint()); @@ -140,7 +158,7 @@ public class AMapServiceImpl implements AMapService { List aMapEquipmentInfos = getPileListByStationId(String.valueOf(stationInfo.getId())); aMapInfo.setEquipmentInfos(aMapEquipmentInfos); sw.stop(); - log.info("组装高德数据格式耗时详细:{}", prettyPrintBySecond(sw)); + log.info("组装高德数据格式耗时详细:{}, 线程名:{}", prettyPrintBySecond(sw), Thread.currentThread().getName()); return aMapInfo; }