feat:批量导出
This commit is contained in:
1 parent
5e089029a0
commit
d25929e461
3 files changed
+30
-22
No files matched your search
+10
-15
@@ -252,10 +252,9 @@ public class WalletTransactionController {
|
||||
|
||||
DataScope dataScope = null;
|
||||
Long count = walletTransactionMapper.count(dto, dataScope);
|
||||
if (count > 5000) throw new RuntimeException("导出数据超出5000条,请缩小查询范围");
|
||||
if (count > 3 * 10000) throw new RuntimeException("导出数据超出30000条,请缩小查询范围");
|
||||
|
||||
List<WalletTransactionVo> list = walletTransactionService.scopeList(dto, dataScope);
|
||||
walletTransactionService.exportByTemplate(response, dto, "file/个人充值明细.xlsx", list);
|
||||
walletTransactionService.exportByTemplate(response, dto, "file/个人充值明细.xlsx", dataScope);
|
||||
}
|
||||
|
||||
@Operation(summary = "充值统计", description = "充值统计")
|
||||
@@ -276,10 +275,9 @@ public class WalletTransactionController {
|
||||
|
||||
DataScope dataScope = null;
|
||||
Long count = walletTransactionMapper.count(dto, dataScope);
|
||||
if (count > 5000) throw new RuntimeException("导出数据超出5000条,请缩小查询范围");
|
||||
if (count > 3 * 10000) throw new RuntimeException("导出数据超出30000条,请缩小查询范围");
|
||||
|
||||
List<WalletTransactionVo> list = walletTransactionService.scopeList(dto, dataScope);
|
||||
walletTransactionService.exportByTemplate(response, dto, "file/个人记账扣款明细.xlsx", list);
|
||||
walletTransactionService.exportByTemplate(response, dto, "file/个人记账扣款明细.xlsx", dataScope);
|
||||
}
|
||||
|
||||
@Operation(summary = "记账扣款统计", description = "记账扣款统计")
|
||||
@@ -300,10 +298,9 @@ public class WalletTransactionController {
|
||||
|
||||
DataScope dataScope = null;
|
||||
Long count = walletTransactionMapper.count(dto, dataScope);
|
||||
if (count > 5000) throw new RuntimeException("导出数据超出5000条,请缩小查询范围");
|
||||
if (count > 3 * 10000) throw new RuntimeException("导出数据超出30000条,请缩小查询范围");
|
||||
|
||||
List<WalletTransactionVo> list = walletTransactionService.scopeList(dto, dataScope);
|
||||
walletTransactionService.exportByTemplate(response, dto, "file/个人消费明细.xlsx", list);
|
||||
walletTransactionService.exportByTemplate(response, dto, "file/个人消费明细.xlsx", dataScope);
|
||||
}
|
||||
|
||||
@Operation(summary = "消费统计", description = "消费统计")
|
||||
@@ -323,10 +320,9 @@ public class WalletTransactionController {
|
||||
|
||||
DataScope dataScope = null;
|
||||
Long count = walletTransactionMapper.count(dto, dataScope);
|
||||
if (count > 5000) throw new RuntimeException("导出数据超出5000条,请缩小查询范围");
|
||||
if (count > 3 * 10000) throw new RuntimeException("导出数据超出30000条,请缩小查询范围");
|
||||
|
||||
List<WalletTransactionVo> list = walletTransactionService.scopeList(dto, dataScope);
|
||||
walletTransactionService.exportByTemplate(response, dto, "file/个人退款明细.xlsx", list);
|
||||
walletTransactionService.exportByTemplate(response, dto, "file/个人退款明细.xlsx", dataScope);
|
||||
}
|
||||
|
||||
@Operation(summary = "退款统计", description = "退款统计")
|
||||
@@ -347,10 +343,9 @@ public class WalletTransactionController {
|
||||
|
||||
DataScope dataScope = null;
|
||||
Long count = walletTransactionMapper.count(dto, dataScope);
|
||||
if (count > 5000) throw new RuntimeException("导出数据超出5000条,请缩小查询范围");
|
||||
if (count > 3 * 10000) throw new RuntimeException("导出数据超出30000条,请缩小查询范围");
|
||||
|
||||
List<WalletTransactionVo> list = walletTransactionService.scopeList(dto, dataScope);
|
||||
walletTransactionService.exportByTemplate(response, dto, "file/退还各自食堂明细.xlsx", list);
|
||||
walletTransactionService.exportByTemplate(response, dto, "file/退还各自食堂明细.xlsx", dataScope);
|
||||
}
|
||||
|
||||
@Operation(summary = "退还各自食堂统计", description = "退还各自食堂统计")
|
||||
|
||||
+1
-1
@@ -67,7 +67,7 @@ public interface WalletTransactionService extends IService<WalletTransactionEnti
|
||||
*/
|
||||
Boolean updateWalletBalance(WalletTransactionDto dto);
|
||||
|
||||
void exportByTemplate(HttpServletResponse response, WalletTransactionDto dto, String fileName, List<WalletTransactionVo> list);
|
||||
void exportByTemplate(HttpServletResponse response, WalletTransactionDto dto, String fileName, DataScope dataScope);
|
||||
|
||||
/**
|
||||
* 后台充值统计(导出)
|
||||
|
||||
+19
-6
@@ -315,8 +315,10 @@ public class WalletTransactionServiceImpl extends ServiceImpl<WalletTransactionM
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public void exportByTemplate(HttpServletResponse response, WalletTransactionDto dto, String fileName, List<WalletTransactionVo> list) {
|
||||
public void exportByTemplate(HttpServletResponse response, WalletTransactionDto dto, String fileName, DataScope dataScope) {
|
||||
try (ExcelWriter excelWriter = EasyExcel.write(response.getOutputStream()).withTemplate(ResourceUtil.getStream(fileName)).build()) {
|
||||
WriteSheet writeSheet = EasyExcel.writerSheet().build();
|
||||
FillConfig fillConfig = FillConfig.builder().forceNewRow(Boolean.TRUE).build();
|
||||
@@ -326,9 +328,17 @@ public class WalletTransactionServiceImpl extends ServiceImpl<WalletTransactionM
|
||||
map.put("startTime", LocalDateTimeUtil.format(dto.getCreateTimeList()[0], DatePattern.NORM_DATETIME_PATTERN));
|
||||
map.put("endTime", LocalDateTimeUtil.format(dto.getCreateTimeList()[1], DatePattern.NORM_DATETIME_PATTERN));
|
||||
}
|
||||
if (ObjectUtil.isNotEmpty(list)) {
|
||||
BigDecimal priceTotal = BigDecimal.ZERO;
|
||||
Long lineNumber = 1L;
|
||||
long currentPage = 1;
|
||||
long pageSize = 1000;
|
||||
|
||||
BigDecimal priceTotal = BigDecimal.ZERO;
|
||||
Long lineNumber = 1L;
|
||||
// 轮训导出
|
||||
while (true) {
|
||||
Page<WalletTransactionVo> pageList = scopePageList(new Page(currentPage, pageSize), dto, dataScope);
|
||||
if (ObjectUtil.isEmpty(pageList) || ObjectUtil.isEmpty(pageList.getRecords())) break;
|
||||
List<WalletTransactionVo> list = pageList.getRecords();
|
||||
// 处理excel start
|
||||
for (WalletTransactionVo v : list) {
|
||||
v.setLineNumber(lineNumber);
|
||||
lineNumber++;
|
||||
@@ -340,10 +350,13 @@ public class WalletTransactionServiceImpl extends ServiceImpl<WalletTransactionM
|
||||
v.setBizType(WalletBizEnum.valueOfByType(v.getBizType()).getDesc());
|
||||
}
|
||||
}
|
||||
map.put("computeTotalPayPrice", priceTotal.divide(BigDecimal.valueOf(100)).setScale(2, RoundingMode.HALF_UP).toString());
|
||||
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);
|
||||
excelWriter.fill(list, fillConfig, writeSheet);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
log.error("|{}|导入错误,dto:|{}|,fileName:|{}|,error:|{}|", TAG, JSON.toJSONString(dto), fileName, e.getMessage());
|
||||
|
||||
Reference in new issue
Block a user