5 天以前 d3a5c4420a7daf89bc9832f22ca8ed9d7e1adaf9
src/main/java/com/ruoyi/sales/service/impl/CommonFileServiceImpl.java
@@ -1,7 +1,9 @@
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.common.enums.FileNameType;
import com.ruoyi.other.mapper.TempFileMapper;
import com.ruoyi.other.pojo.TempFile;
import com.ruoyi.sales.mapper.CommonFileMapper;
@@ -39,14 +41,34 @@
    @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));
    }
    @Override
    public CommonFile uploadFile(MultipartFile file, Long id, String type) throws IOException {
    public CommonFile uploadFile(MultipartFile file, Long id, Integer type) throws IOException {
        // 1. 生成正式文件ID和路径
        String tempId = UUID.randomUUID().toString();
        Path tempFilePath = Paths.get(uploadDir, tempId + "_" + file.getOriginalFilename());
@@ -117,13 +139,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)