package jnpf.limsController.export; import jnpf.base.entity.DictionaryDataEntity; import jnpf.limsEntity.LimsWendingxingFenxiRowVo; import org.apache.poi.ss.usermodel.CellType; import org.apache.poi.ss.usermodel.DataFormatter; import org.apache.poi.ss.usermodel.Row; import org.apache.poi.ss.usermodel.Workbook; import org.junit.Test; import java.text.SimpleDateFormat; import java.util.Arrays; import java.util.Collections; import static org.junit.Assert.assertEquals; public class LimsWendingxingFenxiWorkbookBuilderTest { private final DataFormatter formatter = new DataFormatter(); @Test public void formatsPeriodDateAndDictionaryUnit() throws Exception { LimsWendingxingFenxiRowVo source = row("18.000000000000000", "month"); DictionaryDataEntity month = new DictionaryDataEntity(); month.setEnCode("month"); month.setFullName("月"); try (Workbook workbook = new LimsWendingxingFenxiWorkbookBuilder() .build(Collections.singletonList(source), Collections.singletonList(month))) { Row exported = workbook.getSheetAt(0).getRow(1); assertEquals(CellType.NUMERIC, exported.getCell(0).getCellType()); assertEquals("0", formatter.formatCellValue(exported.getCell(0))); assertEquals("2026-07-30", formatter.formatCellValue(exported.getCell(4))); assertEquals(CellType.NUMERIC, exported.getCell(5).getCellType()); assertEquals("18", formatter.formatCellValue(exported.getCell(5))); assertEquals("月", exported.getCell(6).getStringCellValue()); assertEquals("6.70", exported.getCell(8).getStringCellValue()); assertEquals("7.0", exported.getCell(9).getStringCellValue()); } } @Test public void usesSlashForBaselineAndPreservesUnknownUnit() throws Exception { try (Workbook workbook = new LimsWendingxingFenxiWorkbookBuilder().build( Arrays.asList(row("0.000", "month"), row("3", "custom_unit")), Collections.emptyList())) { assertEquals("/", workbook.getSheetAt(0).getRow(1).getCell(6).getStringCellValue()); assertEquals("custom_unit", workbook.getSheetAt(0).getRow(2).getCell(6).getStringCellValue()); } } private LimsWendingxingFenxiRowVo row(String period, String periodUnit) throws Exception { LimsWendingxingFenxiRowVo row = new LimsWendingxingFenxiRowVo(); row.setYangpinMingcheng("阿莫西林胶囊"); row.setJihuaBianhao("AMXLJN-001"); row.setPihao("AMXLJN-001-01"); row.setJieguoLuruRiqi(new SimpleDateFormat("yyyy-MM-dd").parse("2026-07-30")); row.setZhouqi(period); row.setZhouqiDanwei(periodUnit); row.setXiangmuMingcheng("pH值"); row.setRawResult("6.70"); row.setShangxian("7.0"); row.setXiaxian("5.0"); row.setUnit("/"); return row; } }