| | |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.ruoyi.common.constant.Constants; |
| | | import com.ruoyi.common.utils.StringUtils; |
| | | import com.ruoyi.framework.config.RuoYiConfig; |
| | | import com.ruoyi.other.mapper.TempFileMapper; |
| | | import com.ruoyi.other.pojo.TempFile; |
| | | import com.ruoyi.other.service.TempFileService; |
| | | 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; |
| | |
| | | fileRecord.setCommonId(businessId); |
| | | fileRecord.setName(originalFilename); |
| | | fileRecord.setUrl(formalFilePath.toString()); |
| | | fileRecord.setLink(buildAccessLink(formalFilePath)); |
| | | fileRecord.setCreateTime(LocalDateTime.now()); |
| | | fileRecord.setType(fileType); |
| | | commonFileMapper.insert(fileRecord); |
| | |
| | | } |
| | | log.info("è¿æä¸´æ¶æä»¶æ¸
ç宿ï¼å
±æ¸
ç {} 个æä»¶", expiredFiles.size()); |
| | | } |
| | | |
| | | private String buildAccessLink(Path formalFilePath) { |
| | | String normalizedPath = formalFilePath.toString().replace("\\", "/"); |
| | | String profile = RuoYiConfig.getProfile(); |
| | | String normalizedProfile = profile == null ? "" : profile.replace("\\", "/"); |
| | | |
| | | String relativePath = normalizedPath; |
| | | if (StringUtils.hasText(normalizedProfile) && normalizedPath.startsWith(normalizedProfile)) { |
| | | relativePath = normalizedPath.substring(normalizedProfile.length()); |
| | | } |
| | | if (!relativePath.startsWith("/")) { |
| | | relativePath = "/" + relativePath; |
| | | } |
| | | |
| | | return Constants.RESOURCE_PREFIX + relativePath; |
| | | } |
| | | } |