From abd339106ed3a6465293edccd33e5f87bd43bdde Mon Sep 17 00:00:00 2001
From: gaoluyang <2820782392@qq.com>
Date: 星期二, 20 十月 2026 18:01:42 +0800
Subject: [PATCH] feat: 质量监控/人员培训对齐程序文件,体系文件控制附件格式放开

---
 cnas-manage/src/main/java/com/ruoyi/manage/service/impl/ManageDocumentListServiceImpl.java |   33 ++++++++++++++++++---------------
 1 files changed, 18 insertions(+), 15 deletions(-)

diff --git a/cnas-manage/src/main/java/com/ruoyi/manage/service/impl/ManageDocumentListServiceImpl.java b/cnas-manage/src/main/java/com/ruoyi/manage/service/impl/ManageDocumentListServiceImpl.java
index ef35755..6284493 100644
--- a/cnas-manage/src/main/java/com/ruoyi/manage/service/impl/ManageDocumentListServiceImpl.java
+++ b/cnas-manage/src/main/java/com/ruoyi/manage/service/impl/ManageDocumentListServiceImpl.java
@@ -11,6 +11,7 @@
 
 
 import com.ruoyi.common.utils.QueryWrappers;
+import com.ruoyi.framework.exception.ErrorException;
 import com.ruoyi.manage.mapper.ManageDocumentListMapper;
 import com.ruoyi.manage.pojo.ManageDocumentList;
 import com.ruoyi.manage.service.ManageDocumentListService;
@@ -25,6 +26,8 @@
 import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
+import java.nio.file.Files;
+import java.nio.file.StandardCopyOption;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
@@ -58,29 +61,29 @@
 
     @Override
     public int uploadFile(Integer id, MultipartFile file) {
-        String urlString;
         String pathName;
-        String path;
         ManageDocumentList manageDocumentList = manageDocumentListMapper.selectById(id);
-        if (ObjectUtils.isNotEmpty(manageDocumentList.getUrl())){
-            // 鍒犻櫎鏃ф枃浠�
-            File oldFile = new File(wordUrl + "/" + manageDocumentList.getUrl());
-            oldFile.delete();
+        if (manageDocumentList == null) {
+            throw new ErrorException("鏂囦欢娓呭崟涓嶅瓨鍦�");
         }
-        //涓婁紶鏂版枃浠�
-        path = wordUrl;
+        if (file == null || file.isEmpty()) {
+            throw new ErrorException("璇烽�夋嫨瑕佷笂浼犵殑鏂囦欢");
+        }
+        File realpath = new File(wordUrl).getAbsoluteFile();
         try {
-            File realpath = new File(path);
-            if (!realpath.exists()) {
-                realpath.mkdirs();
+            if (!realpath.exists() && !realpath.mkdirs()) {
+                throw new IOException("鐩綍鍒涘缓澶辫触: " + realpath);
             }
             pathName = UUID.randomUUID() + "_" + file.getOriginalFilename();
-            urlString = realpath + "/" + pathName;
-            file.transferTo(new File(urlString));
+            // 鐢� Files.copy 鑰屼笉鏄� transferTo锛歵ransferTo 閬囧埌鐩稿璺緞浼氭寜 Tomcat 涓存椂鐩綍瑙f瀽
+            Files.copy(file.getInputStream(), new File(realpath, pathName).toPath(), StandardCopyOption.REPLACE_EXISTING);
         } catch (Exception e) {
             e.printStackTrace();
-            System.err.println("闄勪欢涓婁紶閿欒");
-            return 0;
+            throw new ErrorException("闄勪欢涓婁紶閿欒: " + e.getMessage());
+        }
+        if (ObjectUtils.isNotEmpty(manageDocumentList.getUrl())) {
+            // 鍒犻櫎鏃ф枃浠�
+            new File(realpath, manageDocumentList.getUrl()).delete();
         }
         manageDocumentList.setUrl(pathName);
         return manageDocumentListMapper.updateById(manageDocumentList);

--
Gitblit v1.9.3