package com.ruoyi.order.export; import com.ruoyi.order.api.vo.TOrderInvoiceVO; import org.apache.poi.ss.usermodel.Sheet; import org.apache.poi.ss.usermodel.Workbook; import org.apache.poi.ss.usermodel.WorkbookFactory; import org.junit.jupiter.api.Test; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.math.BigDecimal; import java.time.LocalDateTime; import static org.junit.jupiter.api.Assertions.assertEquals; class InvoiceApplicationWorkbookBuilderTest { @Test void buildsFixedInvoiceApplicationForm() throws Exception { TOrderInvoiceVO invoice = new TOrderInvoiceVO(); invoice.setCreateTime(LocalDateTime.of(2026, 4, 17, 10, 30)); invoice.setSiteName("三苏服务区A区充电站(洪雅方向)"); invoice.setName("深圳创维光伏科技有限公司"); invoice.setTaxIdentificationNumber("91440300MA5G209P3D"); invoice.setElectricityTariff(new BigDecimal("13")); invoice.setTotalAmount(new BigDecimal("21.51")); invoice.setInvoiceType("增值税普通发票"); try (Workbook workbook = InvoiceApplicationWorkbookBuilder.build(invoice)) { Sheet sheet = workbook.getSheetAt(0); assertEquals("开票申请表", sheet.getRow(0).getCell(0).getStringCellValue()); assertEquals("2026-04-17", sheet.getRow(1).getCell(2).getStringCellValue()); assertEquals("三苏服务区A区充电站(洪雅方向)", sheet.getRow(2).getCell(2).getStringCellValue()); assertEquals("13%", sheet.getRow(5).getCell(2).getStringCellValue()); assertEquals(21.51D, sheet.getRow(5).getCell(5).getNumericCellValue(), 0.001D); assertEquals("增值税普通发票", sheet.getRow(6).getCell(2).getStringCellValue()); assertEquals(10, sheet.getPhysicalNumberOfRows()); assertEquals(20, sheet.getNumMergedRegions()); ByteArrayOutputStream output = new ByteArrayOutputStream(); workbook.write(output); try (Workbook downloaded = WorkbookFactory.create(new ByteArrayInputStream(output.toByteArray()))) { assertEquals("开票申请表", downloaded.getSheetAt(0).getRow(0).getCell(0).getStringCellValue()); } } } }