| | |
| | | package com.ruoyi.order.controller; |
| | | |
| | | import com.ruoyi.order.api.vo.ChargingOrderListVO; |
| | | import org.apache.poi.hssf.usermodel.HSSFWorkbook; |
| | | import org.apache.poi.ss.usermodel.Sheet; |
| | | import org.apache.poi.ss.usermodel.Workbook; |
| | | import org.junit.jupiter.api.Test; |
| | | |
| | | import java.math.BigDecimal; |
| | | import java.util.Arrays; |
| | | |
| | | import static org.junit.jupiter.api.Assertions.assertEquals; |
| | | import static org.junit.jupiter.api.Assertions.assertTrue; |
| | | |
| | | class FinancialSettlementControllerTest { |
| | | |
| | |
| | | assertEquals("34.6", FinancialSettlementController.formatChargingDurationMinutes(2076L)); |
| | | assertEquals("", FinancialSettlementController.formatChargingDurationMinutes(null)); |
| | | } |
| | | |
| | | @Test |
| | | void shouldBuildChargingPeriodExportSummaryFromExportRows() { |
| | | ChargingOrderListVO first = new ChargingOrderListVO(); |
| | | first.setElectrovalence(new BigDecimal("10.12")); |
| | | first.setServiceCharge(new BigDecimal("2.34")); |
| | | first.setPaymentAmount(new BigDecimal("12.46")); |
| | | first.setElectricity(new BigDecimal("8.1234")); |
| | | first.setChargingSecond(90L); |
| | | first.setSharingAmount(new BigDecimal("0.46")); |
| | | first.setBalanceIncome(new BigDecimal("3.00")); |
| | | first.setBalanceGiftIncome(new BigDecimal("1.00")); |
| | | first.setVipDiscountAmount(new BigDecimal("0.50")); |
| | | |
| | | ChargingOrderListVO second = new ChargingOrderListVO(); |
| | | second.setElectrovalence(new BigDecimal("1.00")); |
| | | second.setServiceCharge(new BigDecimal("1.00")); |
| | | second.setPaymentAmount(new BigDecimal("2.00")); |
| | | second.setElectricity(new BigDecimal("1.0000")); |
| | | second.setChargingSecond(30L); |
| | | |
| | | String summary = FinancialSettlementController.buildChargingPeriodExportSummary(Arrays.asList(first, second)); |
| | | |
| | | assertTrue(summary.contains("总计:2条")); |
| | | assertTrue(summary.contains("充电电费:11.12元")); |
| | | assertTrue(summary.contains("充电服务费:3.34元")); |
| | | assertTrue(summary.contains("充电收入:14.46元")); |
| | | assertTrue(summary.contains("充电电量:9.123度")); |
| | | assertTrue(summary.contains("充电时长:2分钟")); |
| | | assertTrue(summary.contains("三方平台分佣:0.46元")); |
| | | assertTrue(summary.contains("余额收入:3.00元")); |
| | | assertTrue(summary.contains("余额赠送:1.00元")); |
| | | assertTrue(summary.contains("会员赠送:0.50元")); |
| | | } |
| | | |
| | | @Test |
| | | void shouldPrependMergedSummaryRowBeforeExportHeader() throws Exception { |
| | | try (Workbook workbook = new HSSFWorkbook()) { |
| | | Sheet sheet = workbook.createSheet("充电时段统计"); |
| | | sheet.createRow(0).createCell(0).setCellValue("订单编号"); |
| | | sheet.getRow(0).createCell(1).setCellValue("电站名称"); |
| | | sheet.createRow(1).createCell(0).setCellValue("ORDER-1"); |
| | | |
| | | FinancialSettlementController.prependChargingPeriodSummary(workbook, "总计:1条"); |
| | | |
| | | assertEquals("总计:1条", sheet.getRow(0).getCell(0).getStringCellValue()); |
| | | assertEquals("订单编号", sheet.getRow(1).getCell(0).getStringCellValue()); |
| | | assertEquals("ORDER-1", sheet.getRow(2).getCell(0).getStringCellValue()); |
| | | assertEquals(1, sheet.getNumMergedRegions()); |
| | | assertEquals("A1:B1", sheet.getMergedRegion(0).formatAsString()); |
| | | } |
| | | } |
| | | } |