From 789d4071e8c84225dfae04b1c744fc587e982c00 Mon Sep 17 00:00:00 2001 From: dzc <2388224167@qq.com> Date: Wed, 4 Feb 2026 15:58:13 +0800 Subject: [PATCH] =?UTF-8?q?fix:=E5=A4=9A=E7=BA=BF=E7=A8=8B=E5=AF=BC?= =?UTF-8?q?=E5=87=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../WalletTransactionController.java | 10 +-- .../service/WalletTransactionService.java | 2 +- .../impl/WalletTransactionServiceImpl.java | 70 +++++++++++++------ 3 files changed, 54 insertions(+), 28 deletions(-) diff --git a/pjcloud-wallet/pjcloud-wallet-biz/src/main/java/com/bsd/pjcloud/wallet/controller/WalletTransactionController.java b/pjcloud-wallet/pjcloud-wallet-biz/src/main/java/com/bsd/pjcloud/wallet/controller/WalletTransactionController.java index 063e454a2..11315614e 100644 --- a/pjcloud-wallet/pjcloud-wallet-biz/src/main/java/com/bsd/pjcloud/wallet/controller/WalletTransactionController.java +++ b/pjcloud-wallet/pjcloud-wallet-biz/src/main/java/com/bsd/pjcloud/wallet/controller/WalletTransactionController.java @@ -254,7 +254,7 @@ public class WalletTransactionController { Long count = walletTransactionMapper.count(dto, dataScope); if (count > 3 * 10000) throw new RuntimeException("导出数据超出30000条,请缩小查询范围"); - walletTransactionService.exportByTemplate(response, dto, "file/个人充值明细.xlsx", dataScope); + walletTransactionService.exportByTemplate(response, dto, count, "file/个人充值明细.xlsx", dataScope); } @Operation(summary = "充值统计", description = "充值统计") @@ -277,7 +277,7 @@ public class WalletTransactionController { Long count = walletTransactionMapper.count(dto, dataScope); if (count > 3 * 10000) throw new RuntimeException("导出数据超出30000条,请缩小查询范围"); - walletTransactionService.exportByTemplate(response, dto, "file/个人记账扣款明细.xlsx", dataScope); + walletTransactionService.exportByTemplate(response, dto, count, "file/个人记账扣款明细.xlsx", dataScope); } @Operation(summary = "记账扣款统计", description = "记账扣款统计") @@ -300,7 +300,7 @@ public class WalletTransactionController { Long count = walletTransactionMapper.count(dto, dataScope); if (count > 3 * 10000) throw new RuntimeException("导出数据超出30000条,请缩小查询范围"); - walletTransactionService.exportByTemplate(response, dto, "file/个人消费明细.xlsx", dataScope); + walletTransactionService.exportByTemplate(response, dto, count, "file/个人消费明细.xlsx", dataScope); } @Operation(summary = "消费统计", description = "消费统计") @@ -322,7 +322,7 @@ public class WalletTransactionController { Long count = walletTransactionMapper.count(dto, dataScope); if (count > 3 * 10000) throw new RuntimeException("导出数据超出30000条,请缩小查询范围"); - walletTransactionService.exportByTemplate(response, dto, "file/个人退款明细.xlsx", dataScope); + walletTransactionService.exportByTemplate(response, dto, count, "file/个人退款明细.xlsx", dataScope); } @Operation(summary = "退款统计", description = "退款统计") @@ -345,7 +345,7 @@ public class WalletTransactionController { Long count = walletTransactionMapper.count(dto, dataScope); if (count > 3 * 10000) throw new RuntimeException("导出数据超出30000条,请缩小查询范围"); - walletTransactionService.exportByTemplate(response, dto, "file/退还各自食堂明细.xlsx", dataScope); + walletTransactionService.exportByTemplate(response, dto, count, "file/退还各自食堂明细.xlsx", dataScope); } @Operation(summary = "退还各自食堂统计", description = "退还各自食堂统计") diff --git a/pjcloud-wallet/pjcloud-wallet-biz/src/main/java/com/bsd/pjcloud/wallet/service/WalletTransactionService.java b/pjcloud-wallet/pjcloud-wallet-biz/src/main/java/com/bsd/pjcloud/wallet/service/WalletTransactionService.java index aa64d50c9..05a25fa45 100644 --- a/pjcloud-wallet/pjcloud-wallet-biz/src/main/java/com/bsd/pjcloud/wallet/service/WalletTransactionService.java +++ b/pjcloud-wallet/pjcloud-wallet-biz/src/main/java/com/bsd/pjcloud/wallet/service/WalletTransactionService.java @@ -67,7 +67,7 @@ public interface WalletTransactionService extends IService>> futures = new ArrayList<>(); + for (int i = 1; i <= pages; i++) { + long currentPage = i; + futures.add(CompletableFuture.supplyAsync(() -> { + RequestContextHolder.setRequestAttributes(requestAttributes); + Page pageList = scopePageList(new Page<>(currentPage, pageSize), dto, dataScope); + if (ObjectUtil.isEmpty(pageList) || ObjectUtil.isEmpty(pageList.getRecords())) { + return new ArrayList<>(); + } + List list = pageList.getRecords(); + for (WalletTransactionVo v : list) { + if (ObjectUtil.isNotEmpty(v.getPrice())) { + v.setPriceStr(BigDecimal.valueOf(v.getPrice()).divide(BigDecimal.valueOf(100)).setScale(2, RoundingMode.HALF_UP).toString()); + } + if (ObjectUtil.isNotEmpty(v.getBizType())) { + v.setBizType(WalletBizEnum.valueOfByType(v.getBizType()).getDesc()); + } + } + return list; + }, executor)); + } BigDecimal priceTotal = BigDecimal.ZERO; Long lineNumber = 1L; - // 轮训导出 - while (true) { - Page pageList = scopePageList(new Page(currentPage, pageSize), dto, dataScope); - if (ObjectUtil.isEmpty(pageList) || ObjectUtil.isEmpty(pageList.getRecords())) break; - List list = pageList.getRecords(); - // 处理excel start - for (WalletTransactionVo v : list) { - v.setLineNumber(lineNumber); - lineNumber++; - if (ObjectUtil.isNotEmpty(v.getPrice())) { - priceTotal = priceTotal.add(BigDecimal.valueOf(v.getPrice())); - v.setPriceStr(BigDecimal.valueOf(v.getPrice()).divide(BigDecimal.valueOf(100)).setScale(2, RoundingMode.HALF_UP).toString()); - } - if (ObjectUtil.isNotEmpty(v.getBizType())) { - v.setBizType(WalletBizEnum.valueOfByType(v.getBizType()).getDesc()); + + for (CompletableFuture> future : futures) { + try { + List list = future.get(); + if (ObjectUtil.isEmpty(list)) continue; + for (WalletTransactionVo v : list) { + v.setLineNumber(lineNumber++); + if (ObjectUtil.isNotEmpty(v.getPrice())) { + priceTotal = priceTotal.add(BigDecimal.valueOf(v.getPrice())); + } } + excelWriter.fill(list, fillConfig, writeSheet); + } catch (Exception e) { + log.error("|{}|多线程导出获取数据异常", TAG, e); } - excelWriter.fill(list, fillConfig, writeSheet); - // 处理excel end - if (pageList.getTotal() < pageSize) break; - currentPage++; } map.put("computeTotalPayPrice", priceTotal.divide(BigDecimal.valueOf(100)).setScale(2, RoundingMode.HALF_UP).toString()); excelWriter.fill(map, writeSheet); } catch (IOException e) { e.printStackTrace(); log.error("|{}|导入错误,dto:|{}|,fileName:|{}|,error:|{}|", TAG, JSON.toJSONString(dto), fileName, e.getMessage()); + } finally { + executor.shutdown(); } }