gongchunyi
6 小时以前 965e2f40731a0635abe32fb237e5ed65819e8606
src/main/java/com/ruoyi/other/service/impl/TempFileServiceImpl.java
@@ -9,13 +9,16 @@
import com.ruoyi.sales.mapper.CommonFileMapper;
import com.ruoyi.sales.pojo.CommonFile;
import lombok.extern.slf4j.Slf4j;
import org.apache.catalina.util.URLEncoder;
import org.apache.commons.io.FilenameUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
@@ -101,7 +104,9 @@
        }
        // 构建正式目录路径(按业务类型和日期分组)
        Path formalDirPath = Paths.get(uploadDir, LocalDate.now().format(DateTimeFormatter.ISO_LOCAL_DATE));
        String formalDir = uploadDir + LocalDate.now().format(DateTimeFormatter.ISO_LOCAL_DATE);
        Path formalDirPath = Paths.get(formalDir);
        // 确保正式目录存在(递归创建)
        if (!Files.exists(formalDirPath)) {
@@ -160,7 +165,7 @@
        }
    }
//    @Scheduled(cron = "0 0 3 * * ?") // 每天凌晨3点执行
    //    @Scheduled(cron = "0 0 3 * * ?") // 每天凌晨3点执行
    public void cleanupExpiredTempFiles() {
        LambdaQueryWrapper<TempFile> wrapper = new LambdaQueryWrapper<>();
        wrapper.lt(TempFile::getExpireTime, LocalDateTime.now()); // expireTime < 当前时间