| | |
| | | import io.swagger.annotations.Api; |
| | | import io.swagger.annotations.ApiOperation; |
| | | import io.swagger.annotations.ApiParam; |
| | | import org.apache.poi.ss.usermodel.Workbook; |
| | | import org.apache.poi.ss.usermodel.*; |
| | | import org.apache.poi.ss.util.CellRangeAddress; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | import javax.annotation.Resource; |
| | |
| | | tChargingOrderExports.add(tChargingOrderExport); |
| | | } |
| | | Workbook workbook = ExcelExportUtil.exportExcel(new ExportParams(), TChargingOrderExport.class, tChargingOrderExports); |
| | | prependChargingPeriodSummary(workbook, buildChargingPeriodExportSummary(exportList)); |
| | | HttpServletResponse response = WebUtils.response(); |
| | | response.setContentType("application/vnd.ms-excel"); |
| | | response.setCharacterEncoding("utf-8"); |
| | |
| | | return nullToZero(amount).setScale(2, RoundingMode.HALF_UP).toPlainString(); |
| | | } |
| | | |
| | | static String buildChargingPeriodExportSummary(List<ChargingOrderListVO> list) { |
| | | BigDecimal electrovalence = BigDecimal.ZERO; |
| | | BigDecimal serviceCharge = BigDecimal.ZERO; |
| | | BigDecimal paymentAmount = BigDecimal.ZERO; |
| | | BigDecimal chargingCapacity = BigDecimal.ZERO; |
| | | BigDecimal tripartiteCommission = BigDecimal.ZERO; |
| | | BigDecimal balanceIncome = BigDecimal.ZERO; |
| | | BigDecimal balanceGiftIncome = BigDecimal.ZERO; |
| | | BigDecimal vipGiftAmount = BigDecimal.ZERO; |
| | | long chargingSeconds = 0L; |
| | | if (list != null) { |
| | | for (ChargingOrderListVO item : list) { |
| | | if (item == null) { |
| | | continue; |
| | | } |
| | | electrovalence = electrovalence.add(zero(item.getElectrovalence())); |
| | | serviceCharge = serviceCharge.add(zero(item.getServiceCharge())); |
| | | paymentAmount = paymentAmount.add(zero(item.getPaymentAmount())); |
| | | chargingCapacity = chargingCapacity.add(zero(item.getElectricity())); |
| | | tripartiteCommission = tripartiteCommission.add(zero(item.getSharingAmount())); |
| | | balanceIncome = balanceIncome.add(zero(item.getBalanceIncome())); |
| | | balanceGiftIncome = balanceGiftIncome.add(zero(item.getBalanceGiftIncome())); |
| | | vipGiftAmount = vipGiftAmount.add(zero(item.getVipDiscountAmount())); |
| | | chargingSeconds += item.getChargingSecond() == null ? 0L : item.getChargingSecond(); |
| | | } |
| | | } |
| | | int orderCount = list == null ? 0 : list.size(); |
| | | return "总计:" + orderCount + "条" |
| | | + " 充电电费:" + money(electrovalence) + "元" |
| | | + " 充电服务费:" + money(serviceCharge) + "元" |
| | | + " 充电收入:" + money(paymentAmount) + "元" |
| | | + " 充电电量:" + quantity(chargingCapacity) + "度" |
| | | + " 充电时长:" + formatChargingDurationMinutes(chargingSeconds) + "分钟" |
| | | + " 平台手续费:0.00元" |
| | | + " 三方平台分佣:" + money(tripartiteCommission) + "元" |
| | | + " 余额收入:" + money(balanceIncome) + "元" |
| | | + " 余额赠送:" + money(balanceGiftIncome) + "元" |
| | | + " 会员赠送:" + money(vipGiftAmount) + "元"; |
| | | } |
| | | |
| | | static void prependChargingPeriodSummary(Workbook workbook, String summary) { |
| | | if (workbook == null || workbook.getNumberOfSheets() == 0) { |
| | | return; |
| | | } |
| | | Sheet sheet = workbook.getSheetAt(0); |
| | | int lastRowNum = sheet.getLastRowNum(); |
| | | if (sheet.getPhysicalNumberOfRows() > 0) { |
| | | sheet.shiftRows(0, lastRowNum, 1, true, false); |
| | | } |
| | | Row summaryRow = sheet.createRow(0); |
| | | summaryRow.setHeightInPoints(24); |
| | | Cell summaryCell = summaryRow.createCell(0); |
| | | summaryCell.setCellValue(summary == null ? "" : summary); |
| | | |
| | | CellStyle style = workbook.createCellStyle(); |
| | | Font font = workbook.createFont(); |
| | | font.setBold(true); |
| | | style.setFont(font); |
| | | style.setVerticalAlignment(VerticalAlignment.CENTER); |
| | | style.setAlignment(HorizontalAlignment.LEFT); |
| | | summaryCell.setCellStyle(style); |
| | | |
| | | Row headerRow = sheet.getRow(1); |
| | | int lastColumn = headerRow == null ? 0 : headerRow.getLastCellNum() - 1; |
| | | if (lastColumn > 0) { |
| | | sheet.addMergedRegion(new CellRangeAddress(0, 0, 0, lastColumn)); |
| | | } |
| | | } |
| | | |
| | | private static BigDecimal zero(BigDecimal value) { |
| | | return value == null ? BigDecimal.ZERO : value; |
| | | } |
| | | |
| | | private static String money(BigDecimal value) { |
| | | return zero(value).setScale(2, RoundingMode.HALF_UP).toPlainString(); |
| | | } |
| | | |
| | | private static String quantity(BigDecimal value) { |
| | | return zero(value).setScale(3, RoundingMode.HALF_UP).stripTrailingZeros().toPlainString(); |
| | | } |
| | | |
| | | static String formatChargingDurationMinutes(Long chargingSeconds) { |
| | | if (chargingSeconds == null) { |
| | | return ""; |