Browse Source

【报表】又要用多线程导出了

dev
wangxianzhang 3 years ago
parent
commit
0dfe9fb8b3
  1. 28
      epmet-module/oper-customize/oper-customize-server/src/main/java/com/epmet/service/impl/IcCustomerReportServiceImpl.java

28
epmet-module/oper-customize/oper-customize-server/src/main/java/com/epmet/service/impl/IcCustomerReportServiceImpl.java

@ -55,6 +55,8 @@ import java.nio.file.Path;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.*;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutorService;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@ -390,21 +392,20 @@ public class IcCustomerReportServiceImpl extends BaseServiceImpl<IcCustomerRepor
List<List<String>> idParts = ListUtils.partition(idList, 100);
// 1. 循环下载所有id对应的excel(积木报表的导出接口有并发问题,多线程会导出空表,暂时不用多线程了)
//CountDownLatch cdl = new CountDownLatch(idParts.size());
CountDownLatch cdl = new CountDownLatch(idParts.size());
for (List<String> idPart : idParts) {
downloadXlsByBatchByBizId(reportId, idPart, idAndNames, param, xlsxStorePath, files);
//CompletableFuture.runAsync(() -> {
// downloadXlsByBatchByBizId(reportId, idPart, idAndNames, param, xlsxStorePath, files, cdl);
//}, executorService);
CompletableFuture.runAsync(() -> {
downloadXlsByBatchByBizId(reportId, idPart, param, xlsxStorePath, files, cdl);
}, executorService);
}
// 等待多线程执行完成,再执行打包
//try {
// cdl.await();
//} catch (InterruptedException e) {
// log.error(ExceptionUtils.getErrorStackTrace(e));
// throw new EpmetException("【报表批量导出】CountDownLatch等待被中断");
//}
try {
cdl.await();
} catch (InterruptedException e) {
log.error(ExceptionUtils.getErrorStackTrace(e));
throw new EpmetException("【报表批量导出】CountDownLatch等待被中断");
}
// 2,打包
Path zipFile = storePath.resolve(reportName + "_" + currentTimeStr + ".zip");
@ -472,7 +473,8 @@ public class IcCustomerReportServiceImpl extends BaseServiceImpl<IcCustomerRepor
* @param xlsxStorePath
* @param files
*/
public void downloadXlsByBatchByBizId(String reportId, List<String> bizIds, Map<String, String> idAndNames, JimuReportExportRequestDTO param, Path xlsxStorePath, Map<String, File> files) {
public void downloadXlsByBatchByBizId(String reportId, List<String> bizIds, JimuReportExportRequestDTO param,
Path xlsxStorePath, Map<String, File> files, CountDownLatch cdl) {
for (String id : bizIds) {
try {
@ -506,7 +508,7 @@ public class IcCustomerReportServiceImpl extends BaseServiceImpl<IcCustomerRepor
}
}
//cdl.countDown();
cdl.countDown();
}
/**

Loading…
Cancel
Save