| | |
| | | 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; |
| | |
| | | |
| | | @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 |
| | |
| | | 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())); |
| | |
| | | fileRecord.setCreateTime(LocalDateTime.now()); |
| | | fileRecord.setType(tempFile.getType()); |
| | | commonFileMapper.insert(fileRecord); |
| | | tempFileMapper.deleteById(tempFileId); |
| | | |
| | | log.info("文件迁移成功: {} -> {}", tempFile.getTempPath(), formalFilePath); |
| | | } catch (IOException e) { |