From 8ec375a6fab78e088b3c05e550c0581c9c57152e Mon Sep 17 00:00:00 2001
From: chenhj <1263187585@qq.com>
Date: 星期六, 14 三月 2026 15:31:37 +0800
Subject: [PATCH] 原料检测

---
 src/main/java/com/ruoyi/other/service/impl/TempFileServiceImpl.java |   33 ++++++++++++++++++++++-----------
 1 files changed, 22 insertions(+), 11 deletions(-)

diff --git a/src/main/java/com/ruoyi/other/service/impl/TempFileServiceImpl.java b/src/main/java/com/ruoyi/other/service/impl/TempFileServiceImpl.java
index ee26512..9290e6f 100644
--- a/src/main/java/com/ruoyi/other/service/impl/TempFileServiceImpl.java
+++ b/src/main/java/com/ruoyi/other/service/impl/TempFileServiceImpl.java
@@ -9,16 +9,13 @@
 import com.ruoyi.sales.mapper.CommonFileMapper;
 import com.ruoyi.sales.pojo.CommonFile;
 import lombok.extern.slf4j.Slf4j;
-import org.apache.catalina.util.URLEncoder;
 import org.apache.commons.io.FilenameUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
-import org.springframework.scheduling.annotation.Scheduled;
 import org.springframework.stereotype.Service;
 import org.springframework.web.multipart.MultipartFile;
 
 import java.io.IOException;
-import java.nio.charset.StandardCharsets;
 import java.nio.file.Files;
 import java.nio.file.Path;
 import java.nio.file.Paths;
@@ -26,6 +23,7 @@
 import java.time.LocalDate;
 import java.time.LocalDateTime;
 import java.time.format.DateTimeFormatter;
+import java.util.Collections;
 import java.util.List;
 import java.util.UUID;
 
@@ -76,8 +74,17 @@
         tempFileRecord.setExpireTime(LocalDateTime.now().plusHours(2)); // 2灏忔椂鍚庤繃鏈�
         tempFileRecord.setType(type);
         tempFileMapper.insert(tempFileRecord);
-
         return tempFileRecord;
+    }
+
+    @Override
+    public String uploadByCommon(MultipartFile file, Integer type, Long id) throws  IOException{
+        TempFile tempFile = uploadFile(file, type);
+        if (tempFile != null) {
+            migrateTempFilesToFormal(id, Collections.singletonList(tempFile.getTempId()), type);
+            return tempFile.getTempPath();
+        }
+        return null;
     }
 
     /**
@@ -88,6 +95,7 @@
      * @param fileType     鏂囦欢绫诲瀷(鏉ヨ嚜FileNameType)
      * @throws IOException 鏂囦欢鎿嶄綔寮傚父
      */
+    @Override
     public void migrateTempFilesToFormal(Long businessId, List<String> tempFileIds, Integer fileType) throws IOException {
         if (com.baomidou.mybatisplus.core.toolkit.CollectionUtils.isEmpty(tempFileIds)) {
             return;
@@ -123,12 +131,15 @@
 
             try {
                 // 鎵ц鏂囦欢杩佺Щ锛堜娇鐢ㄥ師瀛愭搷浣滅‘淇濆畨鍏ㄦ�э級
-                Files.move(
-                        Paths.get(tempFile.getTempPath()),
-                        formalFilePath,
-                        StandardCopyOption.REPLACE_EXISTING,
-                        StandardCopyOption.ATOMIC_MOVE
-                );
+//                Files.move(
+//                        Paths.get(tempFile.getTempPath()),
+//                        formalFilePath,
+//                        StandardCopyOption.REPLACE_EXISTING,
+//                        StandardCopyOption.ATOMIC_MOVE
+//                );
+                // 鍘熷瓙绉诲姩澶辫触锛屼娇鐢ㄥ鍒�+鍒犻櫎
+                Files.copy(Paths.get(tempFile.getTempPath()), formalFilePath, StandardCopyOption.REPLACE_EXISTING);
+                Files.deleteIfExists(Paths.get(tempFile.getTempPath()));
                 log.info("鏂囦欢杩佺Щ鎴愬姛: {} -> {}", tempFile.getTempPath(), formalFilePath);
 
                 // 鏇存柊鏂囦欢璁板綍锛堝叧鑱斿埌涓氬姟ID锛�
@@ -152,7 +163,7 @@
         }
     }
 
-    @Scheduled(cron = "0 0 3 * * ?") // 姣忓ぉ鍑屾櫒3鐐规墽琛�
+//    @Scheduled(cron = "0 0 3 * * ?") // 姣忓ぉ鍑屾櫒3鐐规墽琛�
     public void cleanupExpiredTempFiles() {
         LambdaQueryWrapper<TempFile> wrapper = new LambdaQueryWrapper<>();
         wrapper.lt(TempFile::getExpireTime, LocalDateTime.now()); // expireTime < 褰撳墠鏃堕棿

--
Gitblit v1.9.3