From bd46f203b0d30a3d33b7c51ae9a528e4807477e1 Mon Sep 17 00:00:00 2001
From: liding <756868258@qq.com>
Date: 星期四, 17 九月 2026 17:17:16 +0800
Subject: [PATCH] feat: 1.检验单详情温湿度 2.报告编制样品外观.平均值优化
---
inspect-server/src/main/java/com/ruoyi/inspect/service/impl/InsReportServiceImpl.java | 48 +++++++++++++++++++++++++++++++++++++++++++++++-
1 files changed, 47 insertions(+), 1 deletions(-)
diff --git a/inspect-server/src/main/java/com/ruoyi/inspect/service/impl/InsReportServiceImpl.java b/inspect-server/src/main/java/com/ruoyi/inspect/service/impl/InsReportServiceImpl.java
index 2354d4d..614153a 100644
--- a/inspect-server/src/main/java/com/ruoyi/inspect/service/impl/InsReportServiceImpl.java
+++ b/inspect-server/src/main/java/com/ruoyi/inspect/service/impl/InsReportServiceImpl.java
@@ -17,6 +17,7 @@
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.deepoove.poi.XWPFTemplate;
+import com.deepoove.poi.config.Configure;
import com.deepoove.poi.data.Pictures;
import com.itextpdf.text.BadElementException;
import com.itextpdf.text.DocumentException;
@@ -44,6 +45,7 @@
import com.ruoyi.inspect.service.InsOrderService;
import com.ruoyi.inspect.service.InsReportService;
import com.ruoyi.inspect.service.RawMaterialOrderService;
+import com.ruoyi.inspect.util.PreserveReportPicturePlaceholderHandler;
import com.ruoyi.system.mapper.UserMapper;
import com.ruoyi.system.service.InformationNotificationService;
import lombok.extern.slf4j.Slf4j;
@@ -523,7 +525,10 @@
@Override
public int wordInsertUrl(Map<String, Object> map, String url) {
- XWPFTemplate template = XWPFTemplate.compile(url).render(map);
+ Configure configure = Configure.builder()
+ .setValidErrorHandler(new PreserveReportPicturePlaceholderHandler())
+ .build();
+ XWPFTemplate template = XWPFTemplate.compile(url, configure).render(map);
try {
template.writeAndClose(Files.newOutputStream(Paths.get(url)));
} catch (IOException e) {
@@ -571,6 +576,47 @@
return "/word/zip/output.zip";
}
+ @Override
+ public void download(Integer id, Integer createOrderUser, HttpServletResponse response) {
+ if (id == null) {
+ throw new ErrorException("鎶ュ憡涓嶈兘涓虹┖");
+ }
+ InsReport report = insReportMapper.selectDownloadableReport(id, createOrderUser);
+ if (report == null) {
+ throw new ErrorException("鎶ュ憡涓嶅瓨鍦ㄣ�佸皻鏈敓鎴愭垨鏃犳潈涓嬭浇");
+ }
+ String reportUrl = StringUtils.isNotBlank(report.getUrlS()) ? report.getUrlS() : report.getUrl();
+ if (StringUtils.isBlank(reportUrl) || !reportUrl.replace('\\', '/').startsWith("/word/")) {
+ throw new ErrorException("鎶ュ憡鏂囦欢涓嶅瓨鍦紝璇疯仈绯荤鐞嗗憳");
+ }
+ Path root = Paths.get(wordUrl).toAbsolutePath().normalize();
+ Path file = root.resolve(reportUrl.replace('\\', '/').substring("/word/".length())).normalize();
+ if (!file.startsWith(root) || !Files.isRegularFile(file)) {
+ throw new ErrorException("鎶ュ憡鏂囦欢涓嶅瓨鍦紝璇疯仈绯荤鐞嗗憳");
+ }
+ try {
+ String filename = file.getFileName().toString();
+ String encodedName = URLEncoder.encode(filename, "UTF-8").replace("+", "%20");
+ response.setContentType("application/vnd.openxmlformats-officedocument.wordprocessingml.document");
+ response.setHeader("Content-Disposition", "attachment; filename*=UTF-8''" + encodedName);
+ response.setHeader("Access-Control-Expose-Headers", "Content-Disposition,download-filename");
+ response.setHeader("download-filename", encodedName);
+ response.setContentLengthLong(Files.size(file));
+ try (InputStream inputStream = Files.newInputStream(file);
+ OutputStream outputStream = response.getOutputStream()) {
+ byte[] buffer = new byte[8192];
+ int length;
+ while ((length = inputStream.read(buffer)) != -1) {
+ outputStream.write(buffer, 0, length);
+ }
+ outputStream.flush();
+ }
+ } catch (IOException e) {
+ log.error("涓嬭浇鎶ュ憡澶辫触锛宺eportId={}", id, e);
+ throw new ErrorException("鎶ュ憡涓嬭浇澶辫触");
+ }
+ }
+
//鎵归噺涓婁紶
@Override
@Transactional(rollbackFor = Exception.class)
--
Gitblit v1.9.3