From 3d397976d08f0359b8cfeb4e4f22403ae5d0c04f Mon Sep 17 00:00:00 2001
From: 吴羡 <16976746+Xian-TT3@user.noreply.gitee.com>
Date: 星期六, 24 十月 2026 20:44:14 +0800
Subject: [PATCH] feat(device): 设备核查计划附件与设备使用记录联动改造
---
inspect-server/src/main/java/com/ruoyi/inspect/service/impl/InsReportServiceImpl.java | 90 ++++++++++++++++++++++++++++++++++++---------
1 files changed, 72 insertions(+), 18 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 797a172..8401156 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
@@ -1,6 +1,5 @@
package com.ruoyi.inspect.service.impl;
-import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONUtil;
import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.ExcelWriter;
@@ -36,6 +35,7 @@
import com.ruoyi.common.constant.InsOrderTypeConstants;
import com.ruoyi.common.constant.MenuJumpPathConstants;
import com.ruoyi.common.core.domain.Result;
+import com.ruoyi.common.core.domain.entity.SysMenu;
import com.ruoyi.common.core.domain.entity.InformationNotification;
import com.ruoyi.common.utils.DateImageUtil;
import com.ruoyi.common.utils.QueryWrappers;
@@ -54,7 +54,10 @@
import com.ruoyi.inspect.util.ReportSealLayoutUtil;
import com.ruoyi.inspect.util.ReportSignaturePictureUtils;
import com.ruoyi.system.mapper.UserMapper;
+import com.ruoyi.system.service.ISysMenuService;
import com.ruoyi.system.service.InformationNotificationService;
+import jakarta.annotation.Resource;
+import jakarta.servlet.http.HttpServletResponse;
import lombok.extern.slf4j.Slf4j;
import org.apache.poi.xwpf.usermodel.*;
import org.springframework.beans.factory.annotation.Autowired;
@@ -66,9 +69,7 @@
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;
-import jakarta.annotation.Resource;
import javax.imageio.ImageIO;
-import jakarta.servlet.http.HttpServletResponse;
import java.awt.image.BufferedImage;
import java.io.*;
import java.net.URLEncoder;
@@ -112,6 +113,8 @@
private InsProductMapper insProductMapper;
@Resource
private InformationNotificationService informationNotificationService;
+ @Resource
+ private ISysMenuService menuService;
@Value("${wordUrl}")
private String wordUrl;
@Value("${file.path}")
@@ -199,6 +202,7 @@
if (userId == null) {
throw new ErrorException("缂哄皯瀹℃牳浜�");
}
+ ensureReportPreparationPermission(userId, "瀹℃牳浜�");
insReport.setExamineUserId(userId);//瀹℃牳浜�
insReport.setWriteTime(LocalDateTime.now());//鎻愪氦鏃堕棿
//鑾峰彇鎻愪氦浜虹殑绛惧悕鍦板潃
@@ -227,8 +231,6 @@
info.setViewStatus(false);
info.setJumpPath(MenuJumpPathConstants.REPORT_PREPARATION);
informationNotificationService.addInformationNotification(info);
- String primaryReportUrl = getPrimaryReportUrl(insReport);
-
// 鍒ゆ柇鏄惁鏄師鏉愭枡 闇�瑕佹浛鎹�****鎴愪緵搴斿晢
IfsInventoryQuantity one = ifsInventoryQuantityMapper.selectOne(new LambdaQueryWrapper<IfsInventoryQuantity>()
.eq(IfsInventoryQuantity::getId, order.getIfsInventoryId()));
@@ -249,9 +251,7 @@
}};
writeMarksToReportFiles(insReport, writeMarks);
- // 淇敼涓存椂pdf
- String tempUrlPdf = wordToPdfTemp(primaryReportUrl.replace("/word", wordUrl));
- insReport.setTempUrlPdf("/word/" + tempUrlPdf);
+ refreshTemporaryPreviews(insReport);
insReportMapper.updateById(insReport);
@@ -264,6 +264,33 @@
.set(InsReport::getIsExamine, null));
return 1;
+ }
+
+ /**
+ * 鎸囧畾瀹℃牳浜�/鎵瑰噯浜烘椂锛岀‘璁ゅ鏂圭櫥褰曞悗鑳界湅鍒般�屾姤鍛婄紪鍒躲�嶉〉闈紝
+ * 閬垮厤鎸囧畾鍚庣櫥褰曞彧鍓╅椤点�佹棤娉曠户缁鎵广��
+ */
+ private void ensureReportPreparationPermission(Integer userId, String userLabel) {
+ List<SysMenu> menus = menuService.selectMenuTreeByUserId(userId.longValue());
+ if (!containsReportPreparation(menus)) {
+ throw new ErrorException("鎵�閫�" + userLabel + "娌℃湁銆屼笟鍔$鐞� 鈫� 鎶ュ憡缂栧埗銆嶉〉闈㈡潈闄愶紝璇峰厛鍦ㄣ�岀郴缁熺鐞� 鈫� 鐢ㄦ埛绠$悊銆嶄负鍏跺垎閰嶅搴旇鑹�");
+ }
+ }
+
+ private boolean containsReportPreparation(List<SysMenu> menus) {
+ if (CollectionUtils.isEmpty(menus)) {
+ return false;
+ }
+ for (SysMenu menu : menus) {
+ if (Long.valueOf(1129L).equals(menu.getMenuId())
+ || "reportPreparation".equals(menu.getPath())) {
+ return true;
+ }
+ if (containsReportPreparation(menu.getChildren())) {
+ return true;
+ }
+ }
+ return false;
}
//瀹℃牳
@@ -321,6 +348,7 @@
if (userId == null) {
throw new ErrorException("缂哄皯鎵瑰噯浜�");
}
+ ensureReportPreparationPermission(userId, "鎵瑰噯浜�");
if (Objects.equals(insReport.getExamineUserId(), userId)) {
throw new ErrorException("瀹℃牳浜哄拰鎵瑰噯浜轰笉鑳戒负鍚屼竴浜猴紝璇烽噸鏂伴�夋嫨鎵瑰噯浜�");
}
@@ -351,16 +379,13 @@
info.setViewStatus(false);
info.setJumpPath(MenuJumpPathConstants.REPORT_PREPARATION);
informationNotificationService.addInformationNotification(info);
- String primaryReportUrl = getPrimaryReportUrl(insReport);
Map<String, Object> examineMarks = new HashMap<String, Object>() {{
put("examineUrl", ReportSignaturePictureUtils.create(imgUrl, signatureUrl));
put("examineDateUrl", Pictures.ofStream(DateImageUtil.createDateImage(null)).create());
}};
writeMarksToReportFiles(insReport, examineMarks);
- // 淇敼涓存椂pdf
- String tempUrlPdf = wordToPdfTemp(primaryReportUrl.replace("/word", wordUrl));
- insReport.setTempUrlPdf("/word/" + tempUrlPdf);
+ refreshTemporaryPreviews(insReport);
// 鍙戦�佷紒涓氬井淇¢�氱煡(閫氱煡鎵瑰噯浜哄鎵�)
threadPoolTaskExecutor.execute(() -> {
@@ -384,11 +409,11 @@
message += "\n鎵规鍙�: " + ifsInventoryQuantity.getUpdateBatchNo();
}
//鍙戦�佷紒涓氬井淇℃秷鎭�氱煡 鎻愪氦澶嶆牳
- try {
- WxCpUtils.inform(sendUserAccount, message, null);
- } catch (Exception e) {
- throw new RuntimeException(e);
- }
+// try {
+// WxCpUtils.inform(sendUserAccount, message, null);
+// } catch (Exception e) {
+// throw new RuntimeException(e);
+// }
});
insReportMapper.updateById(insReport);
@@ -696,6 +721,30 @@
.collect(Collectors.toList());
}
+ private void refreshTemporaryPreviews(InsReport report) {
+ String primaryPdf = wordToPdfTemp(getPrimaryReportUrl(report).replace("/word", wordUrl));
+ if (StringUtils.isBlank(primaryPdf)) {
+ throw new ErrorException("妫�娴嬫姤鍛婇瑙堢敓鎴愬け璐�");
+ }
+ report.setTempUrlPdf("/word/" + primaryPdf);
+ if (StringUtils.isNotBlank(report.getInspectionUrl())) {
+ String inspectionPdf = wordToPdfTemp(report.getInspectionUrl().replace("/word", wordUrl));
+ if (StringUtils.isBlank(inspectionPdf)) {
+ throw new ErrorException("妫�楠屾姤鍛婇瑙堢敓鎴愬け璐�");
+ }
+ report.setInspectionTempUrlPdf("/word/" + inspectionPdf);
+ }
+ }
+
+ @Override
+ public String prepareEditedReportPreview(String absoluteDocxPath) {
+ String pdfName = wordToPdfTemp(absoluteDocxPath);
+ if (StringUtils.isBlank(pdfName)) {
+ throw new ErrorException("鎶ュ憡棰勮鐢熸垚澶辫触");
+ }
+ return "/word/" + pdfName;
+ }
+
private void writeMarksToReportFiles(InsReport report, Map<String, Object> marks) {
for (String reportUrl : getApprovalReportUrls(report)) {
wordInsertUrl(marks, reportUrl.replace("/word", wordUrl));
@@ -772,7 +821,12 @@
throw new ErrorException("鎶ュ憡鏂囦欢涓嶅瓨鍦紝璇疯仈绯荤鐞嗗憳");
}
try {
- String filename = file.getFileName().toString();
+ // 鐗╃悊鏂囦欢鍙兘鏄� reviewed/edited UUID锛涘鐢ㄦ埛濮嬬粓浣跨敤涓氬姟鎶ュ憡缂栧彿銆�
+ String reportNumber = StringUtils.isBlank(report.getCode()) ? "鎶ュ憡" : report.getCode();
+ reportNumber = reportNumber.replaceAll("[\\\\/:*?\"<>|\\p{Cntrl}]", "-").trim();
+ String suffix = StringUtils.isNotBlank(report.getInspectionUrl())
+ ? (Objects.equals(reportType, INSPECTION_REPORT) ? "-妫�楠屾姤鍛�" : "-妫�娴嬫姤鍛�") : "";
+ String filename = reportNumber + suffix + ".docx";
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);
--
Gitblit v1.9.3