先看效果图
实现流程
整个过程可以分为三大步:
- 设计表头格式
- 根据表头对应的key填充数据
- 根据表头和数据导出Excel
实现代码
根据表头和数据导出Excel
// 设计表头格式
List<ExcelExportEntity> callTableHeaderList = getExportRebateOffsetTableHeader();
// 查询数据
List<RebateOffsetVO> list = rebateOffsetList(request);
// 根据表头对应的key填充数据
List<Map<String, Object>> callRecordList = getExportRebateOffsetCallRecord(list);
ExportParams exportParams = new ExportParams("title", DownloadTypeEnum.REBATE_OFFSET.getMeaning());
exportParams.setType(ExcelType.HSSF);
exportParams.setStyle(ExcelStyleHandler.class);
// 根据表头和数据导出Excel
Workbook workbook = ExcelExportUtil.exportExcel(exportParams, callTableHeaderList, callRecordList);
表头格式
/**
* @author lwh
* @date 2024/5/22
* @description 获取本月应冲返利导出的表头
**/
private List<ExcelExportEntity> getExportRebateOffsetTableHeader() {
// 表头设置
List<ExcelExportEntity> callList = new ArrayList<>();
// 支付信息
ExcelExportEntity callPayEntity = new ExcelExportEntity("支付信息", "payInfo");
List<ExcelExportEntity> payChildrenList = new ArrayList<>();
payChildrenList.add(new ExcelExportEntity("订单号", "orderNo"));
payChildrenList.add(new ExcelExportEntity("支付类型", "payType"));
payChildrenList.add(new ExcelExportEntity("订单总条数", "orderNumber"));
payChildrenList.add(new ExcelExportEntity("订单总金额", "orderTotalAmount"));
payChildrenList.add(new ExcelExportEntity("返利抵扣金额", "deductionAmount"));
payChildrenList.add(new ExcelExportEntity("现金支付金额", "thirdPartyAmount"));
payChildrenList.add(new ExcelExportEntity("授信支付金额", "creditAmount"));
callPayEntity.setList(payChildrenList);
// 扫码入库信息
ExcelExportEntity callScanInfoEntity = new ExcelExportEntity("扫码入库信息", "scanCodeInfo");
List<ExcelExportEntity> scanCodeChildrenList = new ArrayList<>();
scanCodeChildrenList.add(new ExcelExportEntity("扫码入库数", "scanNumber"));
scanCodeChildrenList.add(new ExcelExportEntity("退货数", "returnNumber"));
scanCodeChildrenList.add(new ExcelExportEntity("实际入库数(减退货)", "actualScanNumber"));
callScanInfoEntity.setList(scanCodeChildrenList);
// 客户退款信息
ExcelExportEntity callRefundInfoEntity = new ExcelExportEntity("客户退款信息", "refundInfo");
List<ExcelExportEntity> refundInfoChildrenList = new ArrayList<>();
refundInfoChildrenList.add(new ExcelExportEntity("退款数", "orderReturnNumber"));
refundInfoChildrenList.add(new ExcelExportEntity("退款总金额", "orderReturnAmount"));
refundInfoChildrenList.add(new ExcelExportEntity("退款返利金额", "rebateRefundAmount"));
refundInfoChildrenList.add(new ExcelExportEntity("退款现金金额", "cpcnRefundAmount"));
refundInfoChildrenList.add(new ExcelExportEntity("退款授信金额", "creditRefundAmount"));
callRefundInfoEntity.setList(refundInfoChildrenList);
// 未入库系统退回信息
ExcelExportEntity callNoReturnInfoEntity = new ExcelExportEntity("未入库系统退回信息", "noReturnInfo");
List<ExcelExportEntity> noReturnInfoChildrenList = new ArrayList<>();
noReturnInfoChildrenList.add(new ExcelExportEntity("未扫码入库数", "needReturnScanNumber"));
noReturnInfoChildrenList.add(new ExcelExportEntity("未入库退回总金额", "needReturnTotalAmount"));
noReturnInfoChildrenList.add(new ExcelExportEntity("返利退回金额", "rebateReturn"));
noReturnInfoChildrenList.add(new ExcelExportEntity("现金退回金额", "cpcnReturn"));
noReturnInfoChildrenList.add(new ExcelExportEntity("授信退回金额", "creditReturn"));
callNoReturnInfoEntity.setList(noReturnInfoChildrenList);
// 应冲返利金额
ExcelExportEntity callGrantRebateEntity = new ExcelExportEntity("应冲返利金额", "grantRebate");
callGrantRebateEntity.setMergeVertical(true);
// 支付信息
callList.add(callPayEntity);
// 扫码入库信息
callList.add(callScanInfoEntity);
// 客户退款信息
callList.add(callRefundInfoEntity);
// 未入库系统退回信息
callList.add(callNoReturnInfoEntity);
// 应冲返利金额
callList.add(callGrantRebateEntity);
return callList;
}
根据表头对应的key填充数据
/**
* @author lwh
* @date 2024/5/22
* @description 获取正向应冲返利导出数据
**/
private List<Map<String, Object>> getExportRebateOffsetCallRecord(List<RebateOffsetVO> list) {
List<Map<String, Object>> callRecordList = new ArrayList<>();
for (int i = 0; i < list.size(); i++) {
RebateOffsetVO vo = list.get(i);
Map<String, Object> callRecordMap = new HashMap<>();
// 支付信息
List<Map<String, Object>> listA = new ArrayList<>();
Map<String, Object> valueMapA = new HashMap<>();
valueMapA.put("orderNo", vo.getOrderNo());
valueMapA.put("payType", RebateOffsetPayTypeEnum.getDescByCode(vo.getPayType()));
valueMapA.put("orderNumber", vo.getOrderNumber());
valueMapA.put("orderTotalAmount", vo.getOrderTotalAmount());
valueMapA.put("deductionAmount", vo.getDeductionAmount());
valueMapA.put("thirdPartyAmount", vo.getThirdPartyAmount());
valueMapA.put("creditAmount", vo.getCreditAmount());
listA.add(valueMapA);
callRecordMap.put("payInfo", listA);
// 扫码入库信息
List<Map<String, Object>> listB = new ArrayList<>();
Map<String, Object> valueMapB = new HashMap<>();
valueMapB.put("scanNumber", vo.getScanNumber());
valueMapB.put("returnNumber", vo.getReturnNumber());
valueMapB.put("actualScanNumber", vo.getActualScanNumber());
listB.add(valueMapB);
callRecordMap.put("scanCodeInfo", listB);
// 客户退款信息
List<Map<String, Object>> listC = new ArrayList<>();
Map<String, Object> valueMapC = new HashMap<>();
valueMapC.put("orderReturnNumber", vo.getOrderReturnNumber());
valueMapC.put("orderReturnAmount", vo.getOrderReturnAmount());
valueMapC.put("rebateRefundAmount", vo.getRebateRefundAmount());
valueMapC.put("cpcnRefundAmount", vo.getCpcnRefundAmount());
valueMapC.put("creditRefundAmount", vo.getCreditRefundAmount());
listC.add(valueMapC);
callRecordMap.put("refundInfo", listC);
// 未入库系统退回信息
List<Map<String, Object>> listD = new ArrayList<>();
Map<String, Object> valueMapD = new HashMap<>();
valueMapD.put("needReturnScanNumber", vo.getNeedReturnScanNumber());
valueMapD.put("needReturnTotalAmount", vo.getNeedReturnTotalAmount());
valueMapD.put("rebateReturn", vo.getRebateReturn());
valueMapD.put("cpcnReturn", vo.getCpcnReturn());
valueMapD.put("creditReturn", vo.getCreditReturn());
listD.add(valueMapD);
callRecordMap.put("noReturnInfo", listD);
// 应冲返利金额
callRecordMap.put("grantRebate", vo.getGrantRebate());
callRecordList.add(callRecordMap);
}
return callRecordList;
}