| | |
| | | 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; |
| | |
| | | import java.time.LocalDate; |
| | | import java.time.LocalDateTime; |
| | | import java.time.format.DateTimeFormatter; |
| | | import java.util.Collections; |
| | | import java.util.List; |
| | | import java.util.UUID; |
| | | |
| | |
| | | tempFileRecord.setExpireTime(LocalDateTime.now().plusHours(2)); // 2小时后过期 |
| | | tempFileRecord.setType(type); |
| | | tempFileMapper.insert(tempFileRecord); |
| | | |
| | | return tempFileRecord; |
| | | } |
| | | |
| | | @Override |
| | | public String uploadByCommon(MultipartFile file, Integer type, Long id) throws IOException{ |
| | | TempFile tempFile = uploadFile(file, type); |
| | | if (tempFile != null) { |
| | | migrateTempFilesToFormal(id, Collections.singletonList(tempFile.getTempId()), type); |
| | | return tempFile.getTempPath(); |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | /** |
| | |
| | | * @param fileType 文件类型(来自FileNameType) |
| | | * @throws IOException 文件操作异常 |
| | | */ |
| | | @Override |
| | | public void migrateTempFilesToFormal(Long businessId, List<String> tempFileIds, Integer fileType) throws IOException { |
| | | if (com.baomidou.mybatisplus.core.toolkit.CollectionUtils.isEmpty(tempFileIds)) { |
| | | return; |