From 34981c30a78e8bbd7791131059a9210f9928b62c Mon Sep 17 00:00:00 2001
From: 刘光辉 <347230014@qq.com>
Date: 星期四, 17 九月 2026 09:24:09 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/master' into master
---
jnpf-lims/jnpf-lims-controller/src/main/java/jnpf/limsController/export/LimsWendingxingFenxiWorkbookBuilder.java | 141 +++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 141 insertions(+), 0 deletions(-)
diff --git a/jnpf-lims/jnpf-lims-controller/src/main/java/jnpf/limsController/export/LimsWendingxingFenxiWorkbookBuilder.java b/jnpf-lims/jnpf-lims-controller/src/main/java/jnpf/limsController/export/LimsWendingxingFenxiWorkbookBuilder.java
new file mode 100644
index 0000000..1011129
--- /dev/null
+++ b/jnpf-lims/jnpf-lims-controller/src/main/java/jnpf/limsController/export/LimsWendingxingFenxiWorkbookBuilder.java
@@ -0,0 +1,141 @@
+package jnpf.limsController.export;
+
+import jnpf.base.entity.DictionaryDataEntity;
+import jnpf.limsEntity.LimsWendingxingFenxiRowVo;
+import org.apache.poi.hssf.usermodel.HSSFWorkbook;
+import org.apache.poi.ss.usermodel.Cell;
+import org.apache.poi.ss.usermodel.CellStyle;
+import org.apache.poi.ss.usermodel.FillPatternType;
+import org.apache.poi.ss.usermodel.Font;
+import org.apache.poi.ss.usermodel.IndexedColors;
+import org.apache.poi.ss.usermodel.Row;
+import org.apache.poi.ss.usermodel.Sheet;
+import org.apache.poi.ss.usermodel.Workbook;
+
+import java.math.BigDecimal;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Locale;
+import java.util.Map;
+
+public class LimsWendingxingFenxiWorkbookBuilder {
+
+ private static final String[] HEADERS = {
+ "搴忓彿", "鍝佸悕", "绋冲畾鎬ц�冨療缂栧彿", "鎵瑰彿", "褰曞叆鏃ユ湡", "鑰冨療鍛ㄦ湡",
+ "鍛ㄦ湡鍗曚綅", "椤圭洰鍚嶇О", "鏁版嵁", "涓婇檺", "涓嬮檺", "鍗曚綅"
+ };
+
+ public Workbook build(List<LimsWendingxingFenxiRowVo> rows,
+ List<DictionaryDataEntity> periodUnits) {
+ Workbook workbook = new HSSFWorkbook();
+ Sheet sheet = workbook.createSheet("Worksheet");
+ sheet.createFreezePane(0, 1);
+ CellStyle headerStyle = createHeaderStyle(workbook);
+ CellStyle dateStyle = workbook.createCellStyle();
+ dateStyle.setDataFormat(workbook.createDataFormat().getFormat("yyyy-MM-dd"));
+ CellStyle decimalStyle = workbook.createCellStyle();
+ decimalStyle.setDataFormat(workbook.createDataFormat().getFormat("0.################"));
+
+ Row header = sheet.createRow(0);
+ for (int column = 0; column < HEADERS.length; column++) {
+ Cell cell = header.createCell(column);
+ cell.setCellValue(HEADERS[column]);
+ cell.setCellStyle(headerStyle);
+ }
+
+ Map<String, String> unitLabels = unitLabels(periodUnits);
+ List<LimsWendingxingFenxiRowVo> safeRows = rows == null
+ ? Collections.<LimsWendingxingFenxiRowVo>emptyList() : rows;
+ for (int index = 0; index < safeRows.size(); index++) {
+ LimsWendingxingFenxiRowVo source = safeRows.get(index);
+ Row row = sheet.createRow(index + 1);
+ row.createCell(0).setCellValue(index);
+ setText(row, 1, source.getYangpinMingcheng());
+ setText(row, 2, source.getJihuaBianhao());
+ setText(row, 3, source.getPihao());
+ if (source.getJieguoLuruRiqi() != null) {
+ Cell dateCell = row.createCell(4);
+ dateCell.setCellValue(source.getJieguoLuruRiqi());
+ dateCell.setCellStyle(dateStyle);
+ } else {
+ setText(row, 4, null);
+ }
+ BigDecimal period = decimal(source.getZhouqi());
+ if (period != null) {
+ Cell periodCell = row.createCell(5);
+ periodCell.setCellValue(period.doubleValue());
+ periodCell.setCellStyle(decimalStyle);
+ } else {
+ setText(row, 5, source.getZhouqi());
+ }
+ setText(row, 6, periodUnit(period, source.getZhouqiDanwei(), unitLabels));
+ setText(row, 7, source.getXiangmuMingcheng());
+ setText(row, 8, source.getRawResult());
+ setText(row, 9, source.getShangxian());
+ setText(row, 10, source.getXiaxian());
+ setText(row, 11, source.getUnit());
+ }
+
+ int[] widths = {8, 24, 28, 18, 16, 12, 12, 24, 18, 14, 14, 12};
+ for (int column = 0; column < widths.length; column++) {
+ sheet.setColumnWidth(column, widths[column] * 256);
+ }
+ return workbook;
+ }
+
+ private CellStyle createHeaderStyle(Workbook workbook) {
+ CellStyle style = workbook.createCellStyle();
+ style.setFillForegroundColor(IndexedColors.LIGHT_CORNFLOWER_BLUE.getIndex());
+ style.setFillPattern(FillPatternType.SOLID_FOREGROUND);
+ Font font = workbook.createFont();
+ font.setBold(true);
+ style.setFont(font);
+ return style;
+ }
+
+ private Map<String, String> unitLabels(List<DictionaryDataEntity> units) {
+ Map<String, String> labels = new HashMap<>();
+ if (units == null) {
+ return labels;
+ }
+ for (DictionaryDataEntity unit : units) {
+ if (unit == null || blank(unit.getEnCode()) || blank(unit.getFullName())) {
+ continue;
+ }
+ labels.put(unit.getEnCode().trim().toLowerCase(Locale.ROOT), unit.getFullName().trim());
+ }
+ return labels;
+ }
+
+ private String periodUnit(BigDecimal period, String code, Map<String, String> labels) {
+ if (period != null && period.compareTo(BigDecimal.ZERO) == 0) {
+ return "/";
+ }
+ if (blank(code)) {
+ return "";
+ }
+ String normalized = code.trim();
+ String label = labels.get(normalized.toLowerCase(Locale.ROOT));
+ return label == null ? normalized : label;
+ }
+
+ private BigDecimal decimal(String value) {
+ if (blank(value)) {
+ return null;
+ }
+ try {
+ return new BigDecimal(value.trim());
+ } catch (NumberFormatException ignored) {
+ return null;
+ }
+ }
+
+ private void setText(Row row, int column, String value) {
+ row.createCell(column).setCellValue(value == null ? "" : value);
+ }
+
+ private boolean blank(String value) {
+ return value == null || value.trim().isEmpty();
+ }
+}
--
Gitblit v1.8.0