| | |
| | | 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.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.sales.mapper.CommonFileMapper; |
| | |
| | | commonFile.setCommonId(id); |
| | | commonFile.setName(file.getOriginalFilename()); |
| | | commonFile.setUrl(tempFilePath.toString()); |
| | | commonFile.setLink(buildAccessLink(tempFilePath)); |
| | | commonFile.setType(type); |
| | | commonFileMapper.insert(commonFile); |
| | | return commonFile; |
| | |
| | | String formalFilename = businessId + "_" + |
| | | System.currentTimeMillis() + "_" + |
| | | UUID.randomUUID().toString().substring(0, 8) + |
| | | (com.ruoyi.common.utils.StringUtils.hasText(fileExtension) ? "." + fileExtension : ""); |
| | | (StringUtils.hasText(fileExtension) ? "." + fileExtension : ""); |
| | | |
| | | Path formalFilePath = formalDirPath.resolve(formalFilename); |
| | | |
| | |
| | | fileRecord.setCommonId(businessId); |
| | | fileRecord.setName(originalFilename); |
| | | fileRecord.setUrl(formalFilePath.toString()); |
| | | fileRecord.setLink(buildAccessLink(formalFilePath)); |
| | | fileRecord.setCreateTime(LocalDateTime.now()); |
| | | fileRecord.setType(tempFile.getType()); |
| | | commonFileMapper.insert(fileRecord); |
| | |
| | | } |
| | | } |
| | | } |
| | | |
| | | 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; |
| | | } |
| | | } |