liyong
17 小时以前 da0e9fff7f8ba1bd163836240ebb9935fa5c25ef
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,14 +40,29 @@
    @Value("${file.upload-dir}")
    private String uploadDir;
    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());
@@ -118,12 +134,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)