|
@ -2,18 +2,19 @@ package org.dromara.demo.domain; |
|
|
|
|
|
|
|
|
import cn.hutool.json.JSONUtil; |
|
|
import cn.hutool.json.JSONUtil; |
|
|
import org.apache.poi.xwpf.usermodel.*; |
|
|
import org.apache.poi.xwpf.usermodel.*; |
|
|
import org.dromara.demo.domain.ReportData; |
|
|
|
|
|
import org.dromara.demo.domain.CheckItem; |
|
|
|
|
|
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTblWidth; |
|
|
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTblWidth; |
|
|
import org.openxmlformats.schemas.wordprocessingml.x2006.main.STTblWidth; |
|
|
import org.openxmlformats.schemas.wordprocessingml.x2006.main.STTblWidth; |
|
|
|
|
|
|
|
|
|
|
|
import java.io.File; |
|
|
import java.io.FileOutputStream; |
|
|
import java.io.FileOutputStream; |
|
|
import java.io.IOException; |
|
|
import java.io.IOException; |
|
|
import java.io.File; |
|
|
|
|
|
import java.math.BigInteger; |
|
|
import java.math.BigInteger; |
|
|
|
|
|
import java.time.LocalDateTime; |
|
|
import java.time.format.DateTimeFormatter; |
|
|
import java.time.format.DateTimeFormatter; |
|
|
|
|
|
import java.util.Comparator; |
|
|
import java.util.List; |
|
|
import java.util.List; |
|
|
import java.util.Map; |
|
|
import java.util.Map; |
|
|
|
|
|
import java.util.TreeMap; |
|
|
import java.util.stream.Collectors; |
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
|
|
public class WordReportExporter { |
|
|
public class WordReportExporter { |
|
@ -70,7 +71,7 @@ public class WordReportExporter { |
|
|
XWPFRun label = p.createRun(); |
|
|
XWPFRun label = p.createRun(); |
|
|
label.setFontFamily("宋体"); |
|
|
label.setFontFamily("宋体"); |
|
|
label.setFontSize(12); |
|
|
label.setFontSize(12); |
|
|
label.setBold(true); |
|
|
label.setBold(false); |
|
|
label.setText("站点名称:"); |
|
|
label.setText("站点名称:"); |
|
|
|
|
|
|
|
|
XWPFRun value = p.createRun(); |
|
|
XWPFRun value = p.createRun(); |
|
@ -79,37 +80,37 @@ public class WordReportExporter { |
|
|
value.setBold(false); |
|
|
value.setBold(false); |
|
|
value.setText(reportData.getSiteName()); |
|
|
value.setText(reportData.getSiteName()); |
|
|
|
|
|
|
|
|
// 区(管委会)
|
|
|
// // 区(管委会)
|
|
|
p = document.createParagraph(); |
|
|
// p = document.createParagraph();
|
|
|
p.setSpacingAfter(10); |
|
|
// p.setSpacingAfter(10);
|
|
|
|
|
|
//
|
|
|
label = p.createRun(); |
|
|
// label = p.createRun();
|
|
|
label.setFontFamily("宋体"); |
|
|
// label.setFontFamily("宋体");
|
|
|
label.setFontSize(12); |
|
|
// label.setFontSize(12);
|
|
|
label.setBold(true); |
|
|
// label.setBold(false);
|
|
|
label.setText("区(管委会):"); |
|
|
// label.setText("区(管委会):");
|
|
|
|
|
|
//
|
|
|
value = p.createRun(); |
|
|
// value = p.createRun();
|
|
|
value.setFontFamily("宋体"); |
|
|
// value.setFontFamily("宋体");
|
|
|
value.setFontSize(12); |
|
|
// value.setFontSize(12);
|
|
|
value.setBold(false); |
|
|
// value.setBold(false);
|
|
|
value.setText(reportData.getDistrict()); |
|
|
// value.setText(reportData.getDistrict());
|
|
|
|
|
|
//
|
|
|
// 街道(乡、镇)
|
|
|
// // 街道(乡、镇)
|
|
|
p = document.createParagraph(); |
|
|
// p = document.createParagraph();
|
|
|
p.setSpacingAfter(10); |
|
|
// p.setSpacingAfter(10);
|
|
|
|
|
|
//
|
|
|
label = p.createRun(); |
|
|
// label = p.createRun();
|
|
|
label.setFontFamily("宋体"); |
|
|
// label.setFontFamily("宋体");
|
|
|
label.setFontSize(12); |
|
|
// label.setFontSize(12);
|
|
|
label.setBold(true); |
|
|
// label.setBold(false);
|
|
|
label.setText("街道(乡、镇):"); |
|
|
// label.setText("街道(乡、镇):");
|
|
|
|
|
|
//
|
|
|
value = p.createRun(); |
|
|
// value = p.createRun();
|
|
|
value.setFontFamily("宋体"); |
|
|
// value.setFontFamily("宋体");
|
|
|
value.setFontSize(12); |
|
|
// value.setFontSize(12);
|
|
|
value.setBold(false); |
|
|
// value.setBold(false);
|
|
|
value.setText(reportData.getStreet()); |
|
|
// value.setText(reportData.getStreet());
|
|
|
|
|
|
|
|
|
// 运维单位
|
|
|
// 运维单位
|
|
|
p = document.createParagraph(); |
|
|
p = document.createParagraph(); |
|
@ -118,7 +119,7 @@ public class WordReportExporter { |
|
|
label = p.createRun(); |
|
|
label = p.createRun(); |
|
|
label.setFontFamily("宋体"); |
|
|
label.setFontFamily("宋体"); |
|
|
label.setFontSize(12); |
|
|
label.setFontSize(12); |
|
|
label.setBold(true); |
|
|
label.setBold(false); |
|
|
label.setText("运维单位:"); |
|
|
label.setText("运维单位:"); |
|
|
|
|
|
|
|
|
value = p.createRun(); |
|
|
value = p.createRun(); |
|
@ -127,37 +128,6 @@ public class WordReportExporter { |
|
|
value.setBold(false); |
|
|
value.setBold(false); |
|
|
value.setText(reportData.getOperationUnit()); |
|
|
value.setText(reportData.getOperationUnit()); |
|
|
|
|
|
|
|
|
// 检查时间
|
|
|
|
|
|
p = document.createParagraph(); |
|
|
|
|
|
p.setSpacingAfter(10); |
|
|
|
|
|
|
|
|
|
|
|
label = p.createRun(); |
|
|
|
|
|
label.setFontFamily("宋体"); |
|
|
|
|
|
label.setFontSize(12); |
|
|
|
|
|
label.setBold(true); |
|
|
|
|
|
label.setText("检查时间:"); |
|
|
|
|
|
|
|
|
|
|
|
value = p.createRun(); |
|
|
|
|
|
value.setFontFamily("宋体"); |
|
|
|
|
|
value.setFontSize(12); |
|
|
|
|
|
value.setBold(false); |
|
|
|
|
|
value.setText(reportData.getCheckTime().format(formatter)); |
|
|
|
|
|
|
|
|
|
|
|
// 检查人员
|
|
|
|
|
|
p = document.createParagraph(); |
|
|
|
|
|
p.setSpacingAfter(10); |
|
|
|
|
|
|
|
|
|
|
|
label = p.createRun(); |
|
|
|
|
|
label.setFontFamily("宋体"); |
|
|
|
|
|
label.setFontSize(12); |
|
|
|
|
|
label.setBold(true); |
|
|
|
|
|
label.setText("检查人员:"); |
|
|
|
|
|
|
|
|
|
|
|
value = p.createRun(); |
|
|
|
|
|
value.setFontFamily("宋体"); |
|
|
|
|
|
value.setFontSize(12); |
|
|
|
|
|
value.setBold(false); |
|
|
|
|
|
value.setText(reportData.getCheckPersonnel()); |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
private static void addScoreTable(XWPFDocument document, ReportData reportData) { |
|
|
private static void addScoreTable(XWPFDocument document, ReportData reportData) { |
|
@ -173,17 +143,22 @@ public class WordReportExporter { |
|
|
XWPFTableRow header = table.getRow(0); |
|
|
XWPFTableRow header = table.getRow(0); |
|
|
setCellTextAndStyle(header.getCell(0), "检查项目", true); |
|
|
setCellTextAndStyle(header.getCell(0), "检查项目", true); |
|
|
header.addNewTableCell(); |
|
|
header.addNewTableCell(); |
|
|
setCellTextAndStyle(header.getCell(1), "检查子项", true); |
|
|
setCellTextAndStyle(header.getCell(1), "检查要点", true); |
|
|
header.addNewTableCell(); |
|
|
header.addNewTableCell(); |
|
|
setCellTextAndStyle(header.getCell(2), "满分分数", true); |
|
|
setCellTextAndStyle(header.getCell(2), "单项分值", true); |
|
|
header.addNewTableCell(); |
|
|
header.addNewTableCell(); |
|
|
setCellTextAndStyle(header.getCell(3), "实际得分", true); |
|
|
setCellTextAndStyle(header.getCell(3), "得分", true); |
|
|
header.addNewTableCell(); |
|
|
header.addNewTableCell(); |
|
|
setCellTextAndStyle(header.getCell(4), "评分说明", true); |
|
|
setCellTextAndStyle(header.getCell(4), "评分说明", true); |
|
|
|
|
|
|
|
|
// 按 checkProject 分组
|
|
|
// 按 checkProject 分组,并按项目编号排序
|
|
|
Map<String, List<CheckItem>> grouped = items.stream() |
|
|
Map<String, List<CheckItem>> grouped = items.stream() |
|
|
.collect(Collectors.groupingBy(CheckItem::getCheckProject)); |
|
|
.sorted(Comparator.comparing(CheckItem::getCheckProject)) |
|
|
|
|
|
.collect(Collectors.groupingBy( |
|
|
|
|
|
CheckItem::getCheckProject, // 分组依据
|
|
|
|
|
|
TreeMap::new, // ✅ 用 TreeMap 保持 key 有序
|
|
|
|
|
|
Collectors.toList() // 每组是一个 List
|
|
|
|
|
|
)); |
|
|
|
|
|
|
|
|
for (Map.Entry<String, List<CheckItem>> entry : grouped.entrySet()) { |
|
|
for (Map.Entry<String, List<CheckItem>> entry : grouped.entrySet()) { |
|
|
List<CheckItem> groupItems = entry.getValue(); |
|
|
List<CheckItem> groupItems = entry.getValue(); |
|
@ -225,15 +200,33 @@ public class WordReportExporter { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
private static void addTotalAndRemarks(XWPFDocument document, ReportData reportData) { |
|
|
private static void addTotalAndRemarks(XWPFDocument document, ReportData reportData) { |
|
|
|
|
|
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); |
|
|
|
|
|
|
|
|
|
|
|
// 1. 总分
|
|
|
XWPFParagraph totalPara = document.createParagraph(); |
|
|
XWPFParagraph totalPara = document.createParagraph(); |
|
|
XWPFRun totalRun = totalPara.createRun(); |
|
|
XWPFRun totalRun = totalPara.createRun(); |
|
|
totalRun.setBold(true); |
|
|
totalRun.setBold(false); |
|
|
totalRun.setText("总分:" + reportData.getTotalScore()); |
|
|
totalRun.setText("总分:" + reportData.getTotalScore()); |
|
|
|
|
|
totalRun.setFontFamily("宋体"); |
|
|
|
|
|
totalRun.setFontSize(12); |
|
|
|
|
|
|
|
|
|
|
|
// 2. 备注
|
|
|
XWPFParagraph remarksPara = document.createParagraph(); |
|
|
XWPFParagraph remarksPara = document.createParagraph(); |
|
|
XWPFRun remarksRun = remarksPara.createRun(); |
|
|
XWPFRun remarksRun = remarksPara.createRun(); |
|
|
remarksRun.setText("备注:" + reportData.getRemarks()); |
|
|
remarksRun.setText("备注:" + reportData.getRemarks()); |
|
|
|
|
|
remarksRun.setFontFamily("宋体"); |
|
|
|
|
|
remarksRun.setFontSize(12); |
|
|
|
|
|
|
|
|
|
|
|
// 3. 检查时间(左) + 检查人员(右)
|
|
|
|
|
|
XWPFParagraph p = document.createParagraph(); |
|
|
|
|
|
p.setAlignment(ParagraphAlignment.BOTH); // 两端对齐
|
|
|
|
|
|
|
|
|
|
|
|
XWPFRun run = p.createRun(); |
|
|
|
|
|
run.setText("检查时间:" + reportData.getCheckTime().format(formatter) + |
|
|
|
|
|
" " + // 多个空格
|
|
|
|
|
|
"检查人员:" + reportData.getCheckPersonnel()); |
|
|
|
|
|
run.setFontFamily("宋体"); |
|
|
|
|
|
run.setFontSize(12); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// ==================== 测试入口 ====================
|
|
|
// ==================== 测试入口 ====================
|
|
@ -242,11 +235,11 @@ public class WordReportExporter { |
|
|
ReportData report = new ReportData(); |
|
|
ReportData report = new ReportData(); |
|
|
|
|
|
|
|
|
report.setReportTitle("数据购买监理服务现场技术核查评分表"); |
|
|
report.setReportTitle("数据购买监理服务现场技术核查评分表"); |
|
|
report.setSiteName("杭州西湖空气质量监测站"); |
|
|
report.setSiteName("临安区龙岗镇站"); |
|
|
report.setDistrict("西湖区"); |
|
|
// report.setDistrict("西湖区");
|
|
|
report.setStreet("龙翔桥"); |
|
|
// report.setStreet("龙翔桥");
|
|
|
report.setOperationUnit("国研信息"); |
|
|
report.setOperationUnit("国研信息"); |
|
|
report.setCheckTime(java.time.LocalDate.now()); |
|
|
report.setCheckTime(LocalDateTime.now()); |
|
|
report.setCheckPersonnel("张三、李四"); |
|
|
report.setCheckPersonnel("张三、李四"); |
|
|
//report.setTotalScore(95);
|
|
|
//report.setTotalScore(95);
|
|
|
report.setRemarks("注1:《环境空气环境空气气态污染物(SO2、NO2、O3、CO)连续自动监测系统技术要求及检测方法HJ654-2013》\n" + |
|
|
report.setRemarks("注1:《环境空气环境空气气态污染物(SO2、NO2、O3、CO)连续自动监测系统技术要求及检测方法HJ654-2013》\n" + |
|
@ -254,8 +247,8 @@ public class WordReportExporter { |
|
|
"04质量控制效果中相关质控因子有缺项的,分值按比例分摊。\n"); |
|
|
"04质量控制效果中相关质控因子有缺项的,分值按比例分摊。\n"); |
|
|
|
|
|
|
|
|
CheckItem item1 = new CheckItem(); |
|
|
CheckItem item1 = new CheckItem(); |
|
|
item1.setCheckProject("01 站房环境保障情况"); |
|
|
item1.setCheckProject("01站房环境保障情况(5分)"); |
|
|
item1.setCheckItem("站房清洁与规范管理"); |
|
|
item1.setCheckItem("站房环境是否清洁,是否符合监测要求"); |
|
|
item1.setItemScore(2); |
|
|
item1.setItemScore(2); |
|
|
item1.setObtainedScore(1); |
|
|
item1.setObtainedScore(1); |
|
|
item1.setScoringBasis(List.of( |
|
|
item1.setScoringBasis(List.of( |
|
@ -265,16 +258,16 @@ public class WordReportExporter { |
|
|
item1.setDeductionRule("一项不合格扣0.5分,扣完为止(评分规则)"); |
|
|
item1.setDeductionRule("一项不合格扣0.5分,扣完为止(评分规则)"); |
|
|
|
|
|
|
|
|
CheckItem item2 = new CheckItem(); |
|
|
CheckItem item2 = new CheckItem(); |
|
|
item2.setCheckProject("01 站房环境保障情况"); |
|
|
item2.setCheckProject("01站房环境保障情况(5分)"); |
|
|
item2.setCheckItem("仪器运行状态检查"); |
|
|
item2.setCheckItem("站房温度是否控制在25±5℃,相对湿度控制在80%以下)"); |
|
|
item2.setItemScore(3); |
|
|
item2.setItemScore(3); |
|
|
item2.setObtainedScore(3); |
|
|
item2.setObtainedScore(3); |
|
|
item2.setScoringBasis(List.of("1)仪器运行正常;")); |
|
|
item2.setScoringBasis(List.of("1)仪器运行正常;")); |
|
|
item2.setDeductionRule("发现异常未处理扣1分"); |
|
|
item2.setDeductionRule("发现异常未处理扣1分"); |
|
|
|
|
|
|
|
|
CheckItem item3 = new CheckItem(); |
|
|
CheckItem item3 = new CheckItem(); |
|
|
item3.setCheckProject("02 站房环境保障情况"); |
|
|
item3.setCheckProject("02采样系统维护效果(10分)"); |
|
|
item3.setCheckItem("仪器运行状态检查"); |
|
|
item3.setCheckItem("采样口距离地面、房顶高度、周围空间是否符合《规范》(注1)要求"); |
|
|
item3.setItemScore(3); |
|
|
item3.setItemScore(3); |
|
|
item3.setObtainedScore(3); |
|
|
item3.setObtainedScore(3); |
|
|
item3.setScoringBasis(List.of("1)仪器运行正常;")); |
|
|
item3.setScoringBasis(List.of("1)仪器运行正常;")); |
|
|