From 6ef4265f1859e88e3e5ff22ef1848e12fa849e26 Mon Sep 17 00:00:00 2001
From: gongchunyi <deslre0381@gmail.com>
Date: 星期二, 12 五月 2026 07:03:43 +0800
Subject: [PATCH] feat: 扫码出库修改为扫码发货

---
 src/main/java/com/ruoyi/sales/service/impl/CommonFileServiceImpl.java |   89 +++++++++++++++++++++++++++++++++++++++++---
 1 files changed, 82 insertions(+), 7 deletions(-)

diff --git a/src/main/java/com/ruoyi/sales/service/impl/CommonFileServiceImpl.java b/src/main/java/com/ruoyi/sales/service/impl/CommonFileServiceImpl.java
index f46d3ae..8d93b46 100644
--- a/src/main/java/com/ruoyi/sales/service/impl/CommonFileServiceImpl.java
+++ b/src/main/java/com/ruoyi/sales/service/impl/CommonFileServiceImpl.java
@@ -1,7 +1,12 @@
 package com.ruoyi.sales.service.impl;
 
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
+import com.ruoyi.common.enums.FileNameType;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.ruoyi.common.constant.Constants;
+import com.ruoyi.common.utils.StringUtils;
+import com.ruoyi.framework.config.RuoYiConfig;
 import com.ruoyi.other.mapper.TempFileMapper;
 import com.ruoyi.other.pojo.TempFile;
 import com.ruoyi.sales.mapper.CommonFileMapper;
@@ -26,6 +31,7 @@
 import java.util.Arrays;
 import java.util.List;
 import java.util.UUID;
+import java.util.stream.Collectors;
 
 @Service
 @RequiredArgsConstructor
@@ -39,9 +45,29 @@
     @Value("${file.upload-dir}")
     private String uploadDir;
 
+    public List<CommonFile> getFileListByBusinessId(Long businessId,Integer type) {
+        return commonFileMapper.selectList(new LambdaQueryWrapper<CommonFile>().eq(CommonFile::getCommonId, businessId)
+                .eq(CommonFile::getType, type));
+    }
+
+    public void deleteByBusinessId(Long businessId,Integer type) {
+        commonFileMapper.delete(new LambdaQueryWrapper<CommonFile>().eq(CommonFile::getCommonId, businessId)
+                .eq(CommonFile::getType, type));
+    }
+
+    public void deleteByBusinessIds(List<Long> businessId,Integer type) {
+        commonFileMapper.delete(new LambdaQueryWrapper<CommonFile>().in(CommonFile::getCommonId, businessId)
+                .eq(CommonFile::getType, type));
+    }
+
 
     @Override
     public int deleteSalesLedgerByIds(Long[] ids) {
+       for (Long id : ids) {
+           if (id == null) {
+               return 1;
+           }
+       }
         return commonFileMapper.deleteBatchIds(Arrays.asList(ids));
     }
 
@@ -65,6 +91,7 @@
         commonFile.setCommonId(id);
         commonFile.setName(file.getOriginalFilename());
         commonFile.setUrl(tempFilePath.toString());
+        commonFile.setLink(buildAccessLink(tempFilePath));
         commonFile.setType(type);
         commonFileMapper.insert(commonFile);
         return commonFile;
@@ -112,18 +139,21 @@
             String formalFilename = businessId + "_" +
                     System.currentTimeMillis() + "_" +
                     UUID.randomUUID().toString().substring(0, 8) +
-                    (com.ruoyi.common.utils.StringUtils.hasText(fileExtension) ? "." + fileExtension : "");
+                    (StringUtils.hasText(fileExtension) ? "." + fileExtension : "");
 
             Path formalFilePath = formalDirPath.resolve(formalFilename);
 
             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锛�
@@ -131,6 +161,7 @@
                 fileRecord.setCommonId(businessId);
                 fileRecord.setName(originalFilename);
                 fileRecord.setUrl(formalFilePath.toString());
+                fileRecord.setLink(buildAccessLink(formalFilePath));
                 fileRecord.setCreateTime(LocalDateTime.now());
                 fileRecord.setType(tempFile.getType());
                 commonFileMapper.insert(fileRecord);
@@ -143,4 +174,48 @@
             }
         }
     }
+
+    /**
+     * 灏嗗鎵瑰崟涓婄殑闄勪欢璁板綍澶嶅埗涓哄鏉″彂璐у彴璐﹂檮浠讹紙鍚屼竴鏂囦欢璺緞锛屾瘡鏉″彂璐у彴璐﹀悇涓�鏉¤褰曪級銆�
+     */
+    public void copyApproveProcessShipAttachmentsToShippingInfos(Long approveProcessId, List<Long> shippingInfoIds) {
+        if (approveProcessId == null || CollectionUtils.isEmpty(shippingInfoIds)) {
+            return;
+        }
+        List<CommonFile> files = commonFileMapper.selectList(new LambdaQueryWrapper<CommonFile>()
+                .eq(CommonFile::getCommonId, approveProcessId)
+                .eq(CommonFile::getType, FileNameType.ApproveProcess.getValue()));
+        if (CollectionUtils.isEmpty(files)) {
+            return;
+        }
+        List<Long> distinctTargets = shippingInfoIds.stream().filter(java.util.Objects::nonNull).distinct().collect(Collectors.toList());
+        for (Long sid : distinctTargets) {
+            for (CommonFile f : files) {
+                CommonFile copy = new CommonFile();
+                copy.setCommonId(sid);
+                copy.setName(f.getName());
+                copy.setUrl(f.getUrl());
+                copy.setLink(f.getLink());
+                copy.setType(FileNameType.SHIP.getValue());
+                copy.setCreateTime(LocalDateTime.now());
+                commonFileMapper.insert(copy);
+            }
+        }
+    }
+
+    private String buildAccessLink(Path formalFilePath) {
+        String normalizedPath = formalFilePath.toString().replace("\\", "/");
+        String profile = RuoYiConfig.getProfile();
+        String normalizedProfile = profile == null ? "" : profile.replace("\\", "/");
+
+        String relativePath = normalizedPath;
+        if (StringUtils.hasText(normalizedProfile) && normalizedPath.startsWith(normalizedProfile)) {
+            relativePath = normalizedPath.substring(normalizedProfile.length());
+        }
+        if (!relativePath.startsWith("/")) {
+            relativePath = "/" + relativePath;
+        }
+
+        return Constants.RESOURCE_PREFIX + relativePath;
+    }
 }

--
Gitblit v1.9.3