maven
2025-12-25 1d48b3889cb66cc91b8d24e19d03022732615f27
src/main/java/com/ruoyi/sales/service/impl/CommonFileServiceImpl.java
@@ -1,5 +1,6 @@
package com.ruoyi.sales.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.other.mapper.TempFileMapper;
@@ -39,9 +40,21 @@
    @Value("${file.upload-dir}")
    private String uploadDir;
    public List<CommonFile> getFileList(Long id,Integer type) {
        LambdaQueryWrapper<CommonFile> commonFileLambdaQueryWrapper = new LambdaQueryWrapper<>();
        commonFileLambdaQueryWrapper.eq(CommonFile::getCommonId, id)
                .eq(CommonFile::getType, type);
        return list(commonFileLambdaQueryWrapper);
    }
    @Override
    public int deleteSalesLedgerByIds(Long[] ids) {
       for (Long id : ids) {
           if (id == null) {
               return 1;
           }
       }
        return commonFileMapper.deleteBatchIds(Arrays.asList(ids));
    }
@@ -117,13 +130,9 @@
            Path formalFilePath = formalDirPath.resolve(formalFilename);
            try {
                // 执行文件迁移(使用原子操作确保安全性)
                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)
@@ -134,6 +143,7 @@
                fileRecord.setCreateTime(LocalDateTime.now());
                fileRecord.setType(tempFile.getType());
                commonFileMapper.insert(fileRecord);
                tempFileMapper.deleteById(tempFileId);
                log.info("文件迁移成功: {} -> {}", tempFile.getTempPath(), formalFilePath);
            } catch (IOException e) {