|
@@ -6,6 +6,7 @@ import com.koobietech.eas.common.exception.EasException;
|
|
|
import com.koobietech.eas.common.utils.PasswordManager;
|
|
|
import com.koobietech.eas.mbg.mapper.EasArcArchivesMapper;
|
|
|
import com.koobietech.eas.mbg.model.EasArcArchives;
|
|
|
+import com.koobietech.eas.mbg.model.EasArcArchivesExample;
|
|
|
import com.koobietech.eas.service.EasArcArchiveRedisService;
|
|
|
import com.koobietech.eas.service.EasArchiveFileDownloadService;
|
|
|
import org.springframework.stereotype.Service;
|
|
@@ -31,19 +32,21 @@ public class EasArchiveFileDownloadServiceImpl implements EasArchiveFileDownload
|
|
|
|
|
|
|
|
|
@Override
|
|
|
- public String getArchiveToken(Integer archiveId) {
|
|
|
+ public String getArchiveToken(String archiveNumber) {
|
|
|
//在getArchiveToken中,使用UUID随机生成字符串作为k键,
|
|
|
// 为了保证每次生成的字符串不同,在生成的时候加上时间戳
|
|
|
// 使用根据id查询到的所需文件在本机上的地址file_path作为v值
|
|
|
- // 存入redis,时间设置成三分钟
|
|
|
// 获取当前时间戳
|
|
|
long timestamp = System.currentTimeMillis();
|
|
|
// 使用UUID生成一个唯一标识
|
|
|
String uniqueId = UUID.randomUUID().toString();
|
|
|
// 将用户传入的ID与时间戳和唯一标识拼接起来
|
|
|
- String token = archiveId + "_" + timestamp + "_" + uniqueId;
|
|
|
- System.out.println("生成的file token 拼接版:"+token);
|
|
|
- EasArcArchives easArcArchives = archivesMapper.selectByPrimaryKey(archiveId);
|
|
|
+ String token = archiveNumber + "_" + timestamp + "_" + uniqueId;
|
|
|
+
|
|
|
+ EasArcArchivesExample easArcArchivesExample = new EasArcArchivesExample();
|
|
|
+ easArcArchivesExample.createCriteria().andArchiveNumberEqualTo(archiveNumber);
|
|
|
+ EasArcArchives easArcArchives = archivesMapper.selectByExample(easArcArchivesExample)
|
|
|
+ .stream().findFirst().orElse(null);
|
|
|
|
|
|
if (Objects.isNull(easArcArchives)) {
|
|
|
throw new EasException("文件不存在");
|
|
@@ -55,7 +58,6 @@ public class EasArchiveFileDownloadServiceImpl implements EasArchiveFileDownload
|
|
|
archiveRedisService.saveArchiveToken(token,filePath);
|
|
|
// 将token返回给用户
|
|
|
String archiveToken = passwordManager.archiveEncryptPassword(token);
|
|
|
- System.out.println("加密生成的file token 加密版:"+archiveToken);
|
|
|
return archiveToken;
|
|
|
|
|
|
}
|
|
@@ -66,7 +68,6 @@ public class EasArchiveFileDownloadServiceImpl implements EasArchiveFileDownload
|
|
|
// 如果取出的值为空,说明token已经过期,返回null
|
|
|
// 如果取出的值不为空,说明token没有过期,返回v值
|
|
|
String token = passwordManager.archiveDecryptPassword(archiveToken);
|
|
|
- System.out.println("解密后的file token:"+token);
|
|
|
return archiveRedisService.getFilePathByToken(token);
|
|
|
}
|
|
|
|
|
@@ -82,8 +83,12 @@ public class EasArchiveFileDownloadServiceImpl implements EasArchiveFileDownload
|
|
|
if (filePath == null) {
|
|
|
throw new EasException("获取文件超时,请重新获取token", 4003);
|
|
|
}
|
|
|
+
|
|
|
+ System.out.println( "fileExtension" + filePath );
|
|
|
+
|
|
|
String fileExtension = getFileExtension(filePath);
|
|
|
- String archiveFileType = ArchiveFileType.getContentType(fileExtension);
|
|
|
+
|
|
|
+ String archiveFileType = ArchiveFileType.getContentType(fileExtension.toLowerCase());
|
|
|
|
|
|
|
|
|
if (archiveFileType != null) {
|
|
@@ -130,7 +135,6 @@ public class EasArchiveFileDownloadServiceImpl implements EasArchiveFileDownload
|
|
|
}
|
|
|
|
|
|
String extension = filePath.substring(dotIndex);
|
|
|
- System.out.println("文件后缀名:" + extension);
|
|
|
|
|
|
return extension;
|
|
|
}
|
|
@@ -147,7 +151,6 @@ public class EasArchiveFileDownloadServiceImpl implements EasArchiveFileDownload
|
|
|
}
|
|
|
|
|
|
String filename = filePath.substring(dotIndex + 1);
|
|
|
- System.out.println("文件名:" + filename);
|
|
|
|
|
|
return filename;
|
|
|
}
|