|
|
@ -237,6 +237,67 @@ public class SiteEvaluationInfoServiceImpl implements ISiteEvaluationInfoService |
|
|
|
try (templateIs) { |
|
|
|
// 3. 创建临时文件 → 填充模板
|
|
|
|
File tempFile = File.createTempFile("temp", ".docx"); |
|
|
|
// 告诉 JVM:当程序正常退出时(JVM 关闭),自动删除这个临时文件。
|
|
|
|
tempFile.deleteOnExit(); |
|
|
|
Files.copy(templateIs, tempFile.toPath(), StandardCopyOption.REPLACE_EXISTING); |
|
|
|
|
|
|
|
XWPFDocument document = WordExportUtil.exportWord07(tempFile.getAbsolutePath(), data); |
|
|
|
AttachmentVo attachmentVo = new AttachmentVo(); |
|
|
|
List<Attachment> attachmentList = new ArrayList<>(); |
|
|
|
|
|
|
|
Attachment attachment1 = new Attachment(); |
|
|
|
attachment1.setDescription("描述1"); |
|
|
|
attachment1.setOssId("1964745602352324609"); |
|
|
|
attachment1.setName("故障图片.png"); |
|
|
|
attachmentList.add(attachment1); |
|
|
|
|
|
|
|
Attachment attachment2 = new Attachment(); |
|
|
|
attachment2.setDescription("描述2"); |
|
|
|
attachment2.setOssId("1964745602352324609"); |
|
|
|
attachment2.setName("故障图片.png"); |
|
|
|
attachmentList.add(attachment2); |
|
|
|
attachmentVo.setAttachmentList(attachmentList); |
|
|
|
|
|
|
|
appendImages(document,attachmentVo ,ossService); |
|
|
|
|
|
|
|
// ✅ 4. 设置响应头
|
|
|
|
String encodedFileName = URLEncoder.encode(fileName, "UTF-8").replaceAll("\\+", "%20"); |
|
|
|
|
|
|
|
response.setContentType("application/vnd.openxmlformats-officedocument.wordprocessingml.document"); |
|
|
|
response.setHeader("Content-Disposition", |
|
|
|
"attachment1; filename=\"" + encodedFileName + "\"; filename*=UTF-8''" + encodedFileName); |
|
|
|
response.setCharacterEncoding("UTF-8"); |
|
|
|
|
|
|
|
// ✅ 5. 写入输出流
|
|
|
|
document.write(response.getOutputStream()); |
|
|
|
|
|
|
|
// ✅ 6. 关闭 document
|
|
|
|
document.close(); |
|
|
|
|
|
|
|
// ✅ 7. 强制刷新输出缓冲区(关键!)
|
|
|
|
response.flushBuffer(); |
|
|
|
} |
|
|
|
// ✅ try 结束前,数据已发出
|
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public void download2(HttpServletResponse response) throws Exception { |
|
|
|
// 1. 准备数据
|
|
|
|
Map<String, Object> data = getHumanData(); |
|
|
|
String siteName = (String) data.get("siteName"); |
|
|
|
String fileName = siteName + "防人为干扰检查表.docx"; |
|
|
|
|
|
|
|
// 2. 加载模板
|
|
|
|
InputStream templateIs = this.getClass().getClassLoader() |
|
|
|
.getResourceAsStream("human_template.docx"); |
|
|
|
if (templateIs == null) { |
|
|
|
throw new FileNotFoundException("模板未找到"); |
|
|
|
} |
|
|
|
|
|
|
|
try (templateIs) { |
|
|
|
// 3. 创建临时文件 → 填充模板
|
|
|
|
File tempFile = File.createTempFile("temp", ".docx"); |
|
|
|
// 告诉 JVM:当程序正常退出时(JVM 关闭),自动删除这个临时文件。
|
|
|
|
tempFile.deleteOnExit(); |
|
|
|
Files.copy(templateIs, tempFile.toPath(), StandardCopyOption.REPLACE_EXISTING); |
|
|
|
|
|
|
@ -385,7 +446,6 @@ public class SiteEvaluationInfoServiceImpl implements ISiteEvaluationInfoService |
|
|
|
}; |
|
|
|
} |
|
|
|
|
|
|
|
@NotNull |
|
|
|
private static Map<String, Object> getData() { |
|
|
|
// 1. 准备数据(用户填写的内容)
|
|
|
|
Map<String, Object> data = new LinkedHashMap<>(); |
|
|
@ -522,6 +582,42 @@ public class SiteEvaluationInfoServiceImpl implements ISiteEvaluationInfoService |
|
|
|
return data; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private static Map<String, Object> getHumanData() { |
|
|
|
// 1. 准备数据(用户填写的内容)
|
|
|
|
Map<String, Object> data = new LinkedHashMap<>(); |
|
|
|
data.put("siteName", "临安区龙岗镇站"); |
|
|
|
data.put("operationUnit", "安徽蓝盾光电子股份有限公司"); |
|
|
|
// ✅ 自动生成当前时间,并格式化为 "yyyy-MM-dd HH:mm:ss"
|
|
|
|
String currentDateTime = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")); |
|
|
|
data.put("checkDateTime", currentDateTime); |
|
|
|
data.put("supervisor", "北京国研咨询"); |
|
|
|
data.put("checkPeople", "李工"); |
|
|
|
data.put("result", "无干扰"); |
|
|
|
data.put("yes_1", "√"); |
|
|
|
data.put("yes_2", "√"); |
|
|
|
data.put("yes_3", "√"); |
|
|
|
data.put("yes_4", "√"); |
|
|
|
data.put("no_1", "√"); |
|
|
|
data.put("no_2", "√"); |
|
|
|
data.put("no_3", "√"); |
|
|
|
data.put("no_4", "√"); |
|
|
|
data.put("trouble_1", "存在问题"); |
|
|
|
data.put("trouble_2", "存在问题"); |
|
|
|
data.put("trouble_3", "存在问题"); |
|
|
|
data.put("trouble_4", "存在问题"); |
|
|
|
data.put("remark_1", "备注测试"); |
|
|
|
data.put("remark_2", "备注测试"); |
|
|
|
data.put("remark_3", "备注测试"); |
|
|
|
data.put("remark_4", "备注测试"); |
|
|
|
|
|
|
|
System.out.println("✅ 数据准备完成!"); |
|
|
|
System.out.println(JSONUtil.toJsonStr(data)); |
|
|
|
JSONObject jsonObject = JSONUtil.parseObj(data); |
|
|
|
System.out.println(jsonObject.toStringPretty()); |
|
|
|
return data; |
|
|
|
} |
|
|
|
|
|
|
|
// 工具方法:计算相对误差,保留1位小数
|
|
|
|
private static String calcError(double mfcFlow, double stdFlow) { |
|
|
|
if (Math.abs(stdFlow) < 0.0001) return "0.0"; // 防止除0
|
|
|
|