刘光辉
13 小时以前 34981c30a78e8bbd7791131059a9210f9928b62c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
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.<DictionaryDataEntity>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;
    }
}