xiangpei
2024-08-29 3e9a6da99aae968123ee7bca352fc08becd7f1f2
ycl-server/src/main/java/com/ycl/platform/service/impl/YwPointServiceImpl.java
@@ -287,17 +287,6 @@
            return point;
        }).collect(Collectors.toList());
        this.waitAllFinishAndGetResult(pointList);
//        for (PointExport pointExport : dataList) {
//            YwPoint point = new YwPoint();
//            point.setImportantCommandImageTag("是".equals(pointExport.getImportantCommandImageTagString()));
//            point.setProvinceTag("是".equals(pointExport.getProvinceTagString()));
//            point.setUnitId(Long.valueOf(unitId));
//            point.setStartTime(startTime);
//            point.setEndTime(endTime);
//            point.setPointName(pointExport.getPointName());
//            point.setSerialNumber(pointExport.getSerialNumber());
//            this.baseMapper.updatePoint(point);
//        }
    }
    public void waitAllFinishAndGetResult(List<YwPoint> dataList) throws InterruptedException, ExecutionException {
@@ -306,34 +295,18 @@
        int start = 0;
        Date startTime = new Date();
        while (true) {
            if (dataList.size() < start + 50) {
            if (dataList.size() < start + 100) {
                List<YwPoint> list = dataList.subList(start, dataList.size() - 1);
                Callable<Boolean> callable = new PointImportCallable(list, this.baseMapper);
                FutureTask<Boolean> futureTask = new FutureTask(callable);
                Thread thread = new Thread(futureTask);
                thread.start();
                // 不能直接调用Future的get方法,否则就变成串行执行了,失去多线程意义
                resultList.add(futureTask);
                this.baseMapper.updatePoint(list);
                break;
            } else {
                List<YwPoint> list = dataList.subList(start, start + 50);
                Callable<Boolean> callable = new PointImportCallable(list, this.baseMapper);
                FutureTask<Boolean> futureTask = new FutureTask(callable);
                Thread thread = new Thread(futureTask);
                thread.start();
                // 不能直接调用Future的get方法,否则就变成串行执行了,失去多线程意义
                resultList.add(futureTask);
                start += 50;
                List<YwPoint> list = dataList.subList(start, start + 100);
                this.baseMapper.updatePoint(list);
                start += 100;
            }
        }
        for (FutureTask<Boolean> futureTask : resultList) {
            data.add(futureTask.get());
        }
        Date endTime = new Date();
        log.error("总共耗时:" + (endTime.getTime() - startTime.getTime()) / 1000);
        if (data.stream().allMatch(item -> item == Boolean.TRUE)) {
            System.out.println("执行成功");
        }
        log.error("总共耗时:" + (endTime.getTime() - startTime.getTime()));
    }
}