|
|
|
@ -57,17 +57,17 @@ public class FileService extends AbstractRedisService implements IFileService { |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
public List<FileVo.Upload> saveFileMultiple(String dir, List<Part> files) throws IOException, BaseException { |
|
|
|
public List<FileVo.Upload> saveFileMultiple(String dir, List<Part> files, long userId) throws IOException, BaseException { |
|
|
|
List<FileVo.Upload> fileList = new ArrayList<>(); |
|
|
|
String allowedExt = WebConstant.FILE_TYPE_ALL; |
|
|
|
for (Part file: files) { |
|
|
|
FileVo.Upload upload = getFileCommit(dir, allowedExt, file); |
|
|
|
FileVo.Upload upload = getFileCommit(dir, allowedExt, file, userId); |
|
|
|
fileList.add(upload); |
|
|
|
} |
|
|
|
return fileList; |
|
|
|
} |
|
|
|
|
|
|
|
private FileVo.Upload getFileCommit(String dir, String allowedExt, Part file) throws IOException { |
|
|
|
private FileVo.Upload getFileCommit(String dir, String allowedExt, Part file, Long userId) throws IOException { |
|
|
|
FileVo.Upload upload = new FileVo.Upload(); |
|
|
|
String fileName = file.getSubmittedFileName(); |
|
|
|
log.info("文件名:{}", fileName); |
|
|
|
@ -105,8 +105,7 @@ public class FileService extends AbstractRedisService implements IFileService { |
|
|
|
FileCommit fileCommit = initFileCommit(dir, fileName, md5, sha1, path); |
|
|
|
fileDao.insertSelective(fileCommit); |
|
|
|
log.info("保存文件:{}", fileCommit); |
|
|
|
// TODO 获取APP_ID
|
|
|
|
FileLink link = initFileLink(fileName, fileCommit.getId(), 0L); |
|
|
|
FileLink link = initFileLink(fileName, fileCommit.getId(), userId); |
|
|
|
fileLinkMapper.insertSelective(link); |
|
|
|
|
|
|
|
return getUpload(upload, fileName, fileCommit, link); |
|
|
|
@ -116,18 +115,23 @@ public class FileService extends AbstractRedisService implements IFileService { |
|
|
|
upload.setId(link.getId()); |
|
|
|
upload.setName(fileName); |
|
|
|
String visitPath = fileCommit.getVisitPath(); |
|
|
|
visitPath = getVisitUrl(link.getId(), visitPath); |
|
|
|
upload.setVisitUrl(visitPath); |
|
|
|
return upload; |
|
|
|
} |
|
|
|
|
|
|
|
private String getVisitUrl(Long linkId, String visitPath) { |
|
|
|
String fileDownload = "file/download/"; |
|
|
|
if (visitPath.contains(fileDownload)) { |
|
|
|
visitPath = visitPath.substring(0, visitPath.indexOf(fileDownload) + fileDownload.length()) + link.getId(); |
|
|
|
visitPath = visitPath.substring(0, visitPath.indexOf(fileDownload) + fileDownload.length()) + linkId; |
|
|
|
} |
|
|
|
upload.setVisitUrl(visitPath); |
|
|
|
return upload; |
|
|
|
return visitPath; |
|
|
|
} |
|
|
|
|
|
|
|
private FileLink initFileLink(String fileName, Long commitId, Long appId) { |
|
|
|
private FileLink initFileLink(String fileName, Long commitId, Long userId) { |
|
|
|
FileLink link = new FileLink(); |
|
|
|
link.setId(snowflake.nextId()); |
|
|
|
link.setAppId(appId); |
|
|
|
link.setUserId(userId); |
|
|
|
link.setName(fileName); |
|
|
|
link.setCommitId(commitId); |
|
|
|
return link; |
|
|
|
@ -226,45 +230,45 @@ public class FileService extends AbstractRedisService implements IFileService { |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public FileVo.Upload saveFileSingle(String dir, Part file) throws IOException, BaseException { |
|
|
|
public FileVo.Upload saveFileSingle(String dir, Part file, long userId) throws IOException, BaseException { |
|
|
|
String allowedExt = WebConstant.FILE_TYPE_ALL; |
|
|
|
return getFileCommit(dir, allowedExt, file); |
|
|
|
return getFileCommit(dir, allowedExt, file, userId); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public FileVo.BigFile uploadBigFile(FileDto.MultipartFileUpload fileUpload) throws IOException { |
|
|
|
public FileVo.BigFile uploadBigFile(FileDto.MultipartFileUpload fileUpload, long userId) throws IOException { |
|
|
|
long t1 = System.currentTimeMillis(); |
|
|
|
FileVo.BigFile bigFile = new FileVo.BigFile(); |
|
|
|
bigFile.setChunkNum(fileUpload.getChunkNum()); |
|
|
|
|
|
|
|
//查看文件是否上传
|
|
|
|
String key = String.format(WebConstant.RedisParam.RESULT_ID_KEY, fileUpload.getAppId() , fileUpload.getTaskId()); |
|
|
|
String pathKey = String.format(WebConstant.RedisParam.COMMIT_PATH_KEY, fileUpload.getAppId(), fileUpload.getTaskId()); |
|
|
|
String key = String.format(WebConstant.RedisParam.RESULT_ID_KEY, userId , fileUpload.getTaskId()); |
|
|
|
String pathKey = String.format(WebConstant.RedisParam.COMMIT_PATH_KEY, userId, fileUpload.getTaskId()); |
|
|
|
|
|
|
|
Object resultObj = queryRedis(key, WebConstant.RedisType.STRING, WebConstant.RedisParam.EXPIRE_SIXTY); |
|
|
|
log.info("查询resultId:{}", resultObj); |
|
|
|
MultipartFile file = fileUpload.getFile(); |
|
|
|
String filename = file.getOriginalFilename(); |
|
|
|
if (StrUtil.isEmpty(filename)) { |
|
|
|
log.info("没有获取到文件名,返回文件格式异常"); |
|
|
|
throw new BaseException(CodeEnum.FILE_FORMAT_ERROR); |
|
|
|
} |
|
|
|
long resultId = snowflake.nextId(); |
|
|
|
bigFile.setName(filename); |
|
|
|
String path; |
|
|
|
if (resultObj == null) { |
|
|
|
// 存redis resultId
|
|
|
|
path = initBigFile(fileUpload, key, pathKey, filename, resultId); |
|
|
|
} else { |
|
|
|
resultId = (Long)resultObj; |
|
|
|
throw new BaseException(CodeEnum.BIG_FILE_NO_CHECK); |
|
|
|
} |
|
|
|
long resultId = (Long)resultObj; |
|
|
|
Object pathObj = queryRedis(pathKey, WebConstant.RedisType.STRING, WebConstant.RedisParam.EXPIRE_SIXTY); |
|
|
|
if (pathObj == null) { |
|
|
|
path = getPathByRedis(pathKey, 0); |
|
|
|
} else { |
|
|
|
path = (String)pathObj; |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
if (StrUtil.isEmpty(path)) { |
|
|
|
throw new BaseException(CodeEnum.FILE_NOT_FOUND); |
|
|
|
} |
|
|
|
String visitPathKey = String.format(WebConstant.RedisParam.VISIT_PATH_KEY, userId, fileUpload.getTaskId()); |
|
|
|
String visitIdKey = String.format(WebConstant.RedisParam.VISIT_ID_KEY, userId, fileUpload.getTaskId()); |
|
|
|
bigFile.setId((Long)queryRedis(visitIdKey, WebConstant.RedisType.STRING, WebConstant.RedisParam.EXPIRE_SIXTY)); |
|
|
|
bigFile.setPath((String)queryRedis(visitPathKey, WebConstant.RedisType.STRING, WebConstant.RedisParam.EXPIRE_SIXTY)); |
|
|
|
//文件内容
|
|
|
|
byte[] content = file.getBytes(); |
|
|
|
String md5 = Md5Util.getFileMD5(content); |
|
|
|
@ -278,10 +282,6 @@ public class FileService extends AbstractRedisService implements IFileService { |
|
|
|
if (chunkLog.getChunkResultId() == resultId){ |
|
|
|
log.info("文件块已上传"); |
|
|
|
bigFile.setResult(WebConstant.FileMsg.FILE_UPLOAD_READY); |
|
|
|
//文件sha1
|
|
|
|
File file1 = new File(path); |
|
|
|
bigFile.setSha1(Sha1Util.getFileSha1(file1)); |
|
|
|
bigFile.setMd5(Md5Util.getFileMD5(file1)); |
|
|
|
return bigFile; |
|
|
|
} |
|
|
|
} |
|
|
|
@ -291,6 +291,34 @@ public class FileService extends AbstractRedisService implements IFileService { |
|
|
|
newChunkLog.setPath(chunkLog.getPath()); |
|
|
|
fileChunkLogMapper.insertSelective(newChunkLog); |
|
|
|
} else { |
|
|
|
saveChunkLog(fileUpload, filename, resultId, content, md5, sha1); |
|
|
|
} |
|
|
|
// 存储文件
|
|
|
|
writeFile(fileUpload, path, content); |
|
|
|
|
|
|
|
File generateFile = new File(path); |
|
|
|
String commitMd5Key = StrUtil.format(WebConstant.RedisParam.MD5_KEY, resultId); |
|
|
|
Object commitMd5 = queryRedis(commitMd5Key, WebConstant.RedisType.STRING, WebConstant.RedisParam.EXPIRE_SIXTY); |
|
|
|
String commitSha1Key = StrUtil.format(WebConstant.RedisParam.SHA1_KEY, resultId); |
|
|
|
Object commitSha1 = queryRedis(commitSha1Key, WebConstant.RedisType.STRING, WebConstant.RedisParam.EXPIRE_SIXTY); |
|
|
|
log.info("md5:{}", Md5Util.getFileMD5(generateFile)); |
|
|
|
log.info("sha1:{}", Sha1Util.getFileSha1(generateFile)); |
|
|
|
if (Md5Util.getFileMD5(generateFile).equals(commitMd5) && Sha1Util.getFileSha1(generateFile).equals(commitSha1)){ |
|
|
|
log.info("文件全部上传"); |
|
|
|
bigFile.setResult(WebConstant.FileMsg.FILE_UPLOAD_ALL); |
|
|
|
fileDao.updateCommitStatus(resultId); |
|
|
|
} else { |
|
|
|
log.info("文件上传成功但尚未全部上传"); |
|
|
|
bigFile.setResult(WebConstant.FileMsg.FILE_UPLOAD_SUC); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
log.info("响应时间:{}", System.currentTimeMillis() - t1); |
|
|
|
// 校验文件是否已经
|
|
|
|
return bigFile; |
|
|
|
} |
|
|
|
|
|
|
|
private void saveChunkLog(FileDto.MultipartFileUpload fileUpload, String filename, long resultId, byte[] content, String md5, String sha1) throws IOException { |
|
|
|
String dir = PropUtil.path + WebConstant.FILE_UPLOAD_CHUNK_DIR + File.separator + DateUtil.today(); |
|
|
|
File subFile = createFile(filename, dir); |
|
|
|
FileOutputStream os = null; |
|
|
|
@ -311,7 +339,8 @@ public class FileService extends AbstractRedisService implements IFileService { |
|
|
|
newChunkLog.setPath(subFile.getPath()); |
|
|
|
fileChunkLogMapper.insertSelective(newChunkLog); |
|
|
|
} |
|
|
|
// 存储文件
|
|
|
|
|
|
|
|
private void writeFile(FileDto.MultipartFileUpload fileUpload, String path, byte[] content) throws FileNotFoundException { |
|
|
|
RandomAccessFile raf = null; |
|
|
|
FileChannel channel = null; |
|
|
|
try { |
|
|
|
@ -339,71 +368,158 @@ public class FileService extends AbstractRedisService implements IFileService { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
File file1 = new File(path); |
|
|
|
bigFile.setSha1(Sha1Util.getFileSha1(file1)); |
|
|
|
bigFile.setMd5(Md5Util.getFileMD5(file1)); |
|
|
|
bigFile.setResult(WebConstant.FileMsg.FILE_UPLOAD_SUC); |
|
|
|
log.info("响应时间:{}", System.currentTimeMillis() - t1); |
|
|
|
return bigFile; |
|
|
|
} |
|
|
|
|
|
|
|
private MappedByteBuffer getMappedByteBuffer(byte[] content, FileChannel channel, long offset) throws InterruptedException { |
|
|
|
try { |
|
|
|
return channel.map(FileChannel.MapMode.READ_WRITE, offset, content.length); |
|
|
|
} catch (IOException e) { |
|
|
|
log.info("请求的操作无法在使用用户映射区域打开的文件上执行, 休眠后重新尝试"); |
|
|
|
Thread.sleep(100); |
|
|
|
return getMappedByteBuffer(content, channel, offset); |
|
|
|
} |
|
|
|
} |
|
|
|
@Override |
|
|
|
public FileVo.BigFileCheck bigFileCheck(FileDto.BigFileCheck fileCheck, long userId) throws IOException { |
|
|
|
log.info("文件检查:{},{}", fileCheck, userId); |
|
|
|
FileVo.BigFileCheck check = new FileVo.BigFileCheck(); |
|
|
|
|
|
|
|
private String getPathByRedis(String key, int count) { |
|
|
|
int max = 1000; |
|
|
|
if (count > max) { |
|
|
|
return null; |
|
|
|
} |
|
|
|
Object o = redisUtil.get(key); |
|
|
|
if (o != null) { |
|
|
|
return (String)o; |
|
|
|
} |
|
|
|
try { |
|
|
|
Thread.sleep(10); |
|
|
|
} catch (InterruptedException e) { |
|
|
|
log.error("查询pathByRedis休眠时出现异常", e); |
|
|
|
} |
|
|
|
return getPathByRedis(key, count + 1); |
|
|
|
FileCommitExample example = new FileCommitExample(); |
|
|
|
example.createCriteria().andMd5EqualTo(fileCheck.getMd5()).andSha1EqualTo(fileCheck.getSha1()).andStatusEqualTo(WebConstant.YES); |
|
|
|
List<FileCommit> fileCommits = fileDao.selectByExample(example); |
|
|
|
|
|
|
|
} |
|
|
|
FileCommit commit; |
|
|
|
if (CollectionUtil.isNotEmpty(fileCommits)) { |
|
|
|
commit = fileCommits.get(0); |
|
|
|
fileDao.addLinkCount(commit.getId()); |
|
|
|
check.setExist(WebConstant.YES); |
|
|
|
} else { |
|
|
|
// 记录文件信息
|
|
|
|
String dir = PropUtil.path + WebConstant.FILE_UPLOAD_DIR + File.separator + DateUtil.today(); |
|
|
|
File saveFile = createFile(fileCheck.getFileName(), dir); |
|
|
|
commit = initFileCommit(dir, saveFile.getName(), fileCheck.getMd5(), fileCheck.getSha1(), saveFile.getName()); |
|
|
|
commit.setStatus(WebConstant.NO); |
|
|
|
fileDao.insertSelective(commit); |
|
|
|
|
|
|
|
private String initBigFile(FileDto.MultipartFileUpload fileUpload, String key, String pathKey, String filename, long resultId) throws IOException { |
|
|
|
check.setExist(WebConstant.NO); |
|
|
|
|
|
|
|
boolean saveId = redisUtil.setNx(key, resultId, WebConstant.RedisParam.EXPIRE_SIXTY); |
|
|
|
if (!saveId) { |
|
|
|
return getPathByRedis(pathKey, 0); |
|
|
|
} |
|
|
|
String dir = PropUtil.path + WebConstant.FILE_UPLOAD_DIR + File.separator + DateUtil.today(); |
|
|
|
File saveFile = createFile(filename, dir); |
|
|
|
FileCommit commit = initFileCommit(dir, saveFile.getName(), null, null, saveFile.getName()); |
|
|
|
redisUtil.set(pathKey, commit.getPath(), WebConstant.RedisParam.EXPIRE_SIXTY); |
|
|
|
fileDao.insertSelective(commit); |
|
|
|
|
|
|
|
//关联
|
|
|
|
// TODO 如何获取appId
|
|
|
|
FileLink link = initFileLink(filename, commit.getId(), fileUpload.getAppId()); |
|
|
|
// 直接添加link,并添加commit被引用次数
|
|
|
|
FileLink link = new FileLink(); |
|
|
|
link.setId(snowflake.nextId()); |
|
|
|
link.setUserId(userId); |
|
|
|
link.setName(fileCheck.getFileName()); |
|
|
|
link.setCommitId(commit.getId()); |
|
|
|
fileLinkMapper.insertSelective(link); |
|
|
|
// 记录和文件的关联
|
|
|
|
// 获取访问路径
|
|
|
|
String visitPath = commit.getVisitPath(); |
|
|
|
visitPath = getVisitUrl(link.getId(), visitPath); |
|
|
|
// 记录文件
|
|
|
|
if (CollectionUtil.isEmpty(fileCommits)) { |
|
|
|
FileChunkResult result = new FileChunkResult(); |
|
|
|
result.setId(resultId); |
|
|
|
// TODO appId
|
|
|
|
result.setAppId(fileUpload.getAppId()); |
|
|
|
result.setTaskId(fileUpload.getTaskId()); |
|
|
|
result.setCommitId(commit.getId()); |
|
|
|
result.setTotal(fileUpload.getChunkTotal()); |
|
|
|
result.setId(snowflake.nextId()); |
|
|
|
result.setLinkId(link.getId()); |
|
|
|
result.setUserId(userId); |
|
|
|
result.setTaskId(fileCheck.getTaskId()); |
|
|
|
result.setTotal(fileCheck.getChunkTotal()); |
|
|
|
fileChunkResultMapper.insertSelective(result); |
|
|
|
String key = String.format(WebConstant.RedisParam.RESULT_ID_KEY, userId , fileCheck.getTaskId()); |
|
|
|
String pathKey = String.format(WebConstant.RedisParam.COMMIT_PATH_KEY, userId, fileCheck.getTaskId()); |
|
|
|
String visitPathKey = String.format(WebConstant.RedisParam.VISIT_PATH_KEY, userId, fileCheck.getTaskId()); |
|
|
|
String visitIdKey = String.format(WebConstant.RedisParam.VISIT_ID_KEY, userId, fileCheck.getTaskId()); |
|
|
|
redisUtil.set(key, result.getId()); |
|
|
|
redisUtil.set(pathKey, commit.getPath()); |
|
|
|
redisUtil.set(visitIdKey, link.getId()); |
|
|
|
redisUtil.set(visitPathKey, visitPath); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
check.setId(link.getId()); |
|
|
|
check.setName(fileCheck.getFileName()); |
|
|
|
check.setVisitUrl(visitPath); |
|
|
|
log.info("文件检查结果:{}", check); |
|
|
|
return check; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
// private boolean checkFull(FileDto.MultipartFileUpload fileUpload, FileVo.BigFile bigFile, Long userId) {
|
|
|
|
// FileCommitExample example = new FileCommitExample();
|
|
|
|
// example.createCriteria().andMd5EqualTo(fileUpload.getMd5()).andSha1EqualTo(fileUpload.getSha1());
|
|
|
|
// List<FileCommit> fileCommits = fileDao.selectByExample(example);
|
|
|
|
// if (CollectionUtil.isEmpty(fileCommits)) {
|
|
|
|
// return false;
|
|
|
|
// }
|
|
|
|
// FileCommit commit = fileCommits.get(0);
|
|
|
|
// FileLinkExample linkExample = new FileLinkExample();
|
|
|
|
// linkExample.createCriteria().andCommitIdEqualTo(commit.getId()).andUserIdEqualTo(userId);
|
|
|
|
// List<FileLink> fileLinks = fileLinkMapper.selectByExample(linkExample);
|
|
|
|
// if (CollectionUtil.isNotEmpty(fileLinks)) {
|
|
|
|
// FileLink link = fileLinks.get(0);
|
|
|
|
// bigFile.setId(link.getId());
|
|
|
|
// bigFile.setPath(getVisitUrl(link.getId(), commit.getVisitPath()));
|
|
|
|
// return true;
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
//
|
|
|
|
// return true;
|
|
|
|
// }
|
|
|
|
|
|
|
|
return commit.getPath(); |
|
|
|
private MappedByteBuffer getMappedByteBuffer(byte[] content, FileChannel channel, long offset) throws InterruptedException { |
|
|
|
try { |
|
|
|
return channel.map(FileChannel.MapMode.READ_WRITE, offset, content.length); |
|
|
|
} catch (IOException e) { |
|
|
|
log.info("请求的操作无法在使用用户映射区域打开的文件上执行, 休眠后重新尝试"); |
|
|
|
Thread.sleep(100); |
|
|
|
return getMappedByteBuffer(content, channel, offset); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// private String getPathByRedis(String key, int count) {
|
|
|
|
// int max = 1000;
|
|
|
|
// if (count > max) {
|
|
|
|
// return null;
|
|
|
|
// }
|
|
|
|
// Object o = redisUtil.get(key);
|
|
|
|
// if (o != null) {
|
|
|
|
// return (String)o;
|
|
|
|
// }
|
|
|
|
// try {
|
|
|
|
// Thread.sleep(10);
|
|
|
|
// } catch (InterruptedException e) {
|
|
|
|
// log.error("查询pathByRedis休眠时出现异常", e);
|
|
|
|
// }
|
|
|
|
// return getPathByRedis(key, count + 1);
|
|
|
|
//
|
|
|
|
// }
|
|
|
|
|
|
|
|
// private String initBigFile(FileDto.MultipartFileUpload fileUpload, String filename, long resultId, long userId) throws IOException {
|
|
|
|
// String key = String.format(WebConstant.RedisParam.RESULT_ID_KEY, userId , fileUpload.getTaskId());
|
|
|
|
// String pathKey = String.format(WebConstant.RedisParam.COMMIT_PATH_KEY, userId, fileUpload.getTaskId());
|
|
|
|
// String visitPathKey = String.format(WebConstant.RedisParam.VISIT_PATH_KEY, userId, fileUpload.getTaskId());
|
|
|
|
// String visitIdKey = String.format(WebConstant.RedisParam.VISIT_ID_KEY, userId, fileUpload.getTaskId());
|
|
|
|
//
|
|
|
|
// boolean saveId = redisUtil.setNx(key, resultId, WebConstant.RedisParam.EXPIRE_SIXTY);
|
|
|
|
// if (!saveId) {
|
|
|
|
// return getPathByRedis(pathKey, 0);
|
|
|
|
// }
|
|
|
|
// String dir = PropUtil.path + WebConstant.FILE_UPLOAD_DIR + File.separator + DateUtil.today();
|
|
|
|
// File saveFile = createFile(filename, dir);
|
|
|
|
// FileCommit commit = initFileCommit(dir, saveFile.getName(), null, null, saveFile.getName());
|
|
|
|
// redisUtil.set(pathKey, commit.getPath(), WebConstant.RedisParam.EXPIRE_SIXTY);
|
|
|
|
// fileDao.insertSelective(commit);
|
|
|
|
//
|
|
|
|
// //关联
|
|
|
|
// FileLink link = initFileLink(filename, commit.getId(), userId);
|
|
|
|
// // 记录文件引用ID和访问路径
|
|
|
|
// redisUtil.set(visitPathKey, getVisitUrl(link.getId(), commit.getVisitPath()), WebConstant.RedisParam.EXPIRE_SIXTY);
|
|
|
|
// redisUtil.set(visitIdKey, link.getId(), WebConstant.RedisParam.EXPIRE_SIXTY);
|
|
|
|
// fileLinkMapper.insertSelective(link);
|
|
|
|
//
|
|
|
|
//
|
|
|
|
// // 记录和文件的关联
|
|
|
|
// FileChunkResult result = new FileChunkResult();
|
|
|
|
// result.setId(resultId);
|
|
|
|
// result.setUserId(userId);
|
|
|
|
// result.setTaskId(fileUpload.getTaskId());
|
|
|
|
// result.setLinkId(link.getId());
|
|
|
|
//// result.setTotal(fileUpload.getChunkTotal());
|
|
|
|
// fileChunkResultMapper.insertSelective(result);
|
|
|
|
//
|
|
|
|
// return commit.getPath();
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
private FileChunkLog initFileChunkLog(FileDto.MultipartFileUpload fileUpload, long resultId, String md5, String sha1) { |
|
|
|
FileChunkLog newChunkLog = new FileChunkLog(); |
|
|
|
@ -454,19 +570,36 @@ public class FileService extends AbstractRedisService implements IFileService { |
|
|
|
|
|
|
|
String resultKey = String.format(WebConstant.RedisParam.RESULT_ID_KEY, "\\d+" , "\\d+"); |
|
|
|
String pathKey = String.format(WebConstant.RedisParam.COMMIT_PATH_KEY, "\\d+", "\\d+"); |
|
|
|
|
|
|
|
if (key.matches(resultKey)) { |
|
|
|
String visitPathKey = String.format(WebConstant.RedisParam.VISIT_PATH_KEY, "\\d+", "\\d+"); |
|
|
|
String visitIdKey = String.format(WebConstant.RedisParam.VISIT_ID_KEY, "\\d+", "\\d+"); |
|
|
|
String md5Key = StrUtil.format(WebConstant.RedisParam.MD5_KEY, "\\d+"); |
|
|
|
String sha1Key = StrUtil.format(WebConstant.RedisParam.SHA1_KEY, "\\d+"); |
|
|
|
String[] str = key.split("_"); |
|
|
|
if (key.matches(resultKey)) { |
|
|
|
|
|
|
|
FileChunkResultExample resultExample = new FileChunkResultExample(); |
|
|
|
resultExample.createCriteria().andAppIdEqualTo(Long.parseLong(str[1])).andTaskIdEqualTo(str[2]); |
|
|
|
resultExample.createCriteria().andUserIdEqualTo(Long.parseLong(str[1])).andTaskIdEqualTo(str[2]); |
|
|
|
List<FileChunkResult> chunkResults = fileChunkResultMapper.selectByExample(resultExample); |
|
|
|
return CollectionUtil.isEmpty(chunkResults) ? null : chunkResults.get(0).getId(); |
|
|
|
} else if (key.matches(pathKey)) { |
|
|
|
String[] str = key.split("_"); |
|
|
|
Long appId = Long.parseLong(str[1]); |
|
|
|
String taskId = str[2]; |
|
|
|
FileVo.FilePosition position = fileDao.getByAppIdAndTaskId(appId, taskId); |
|
|
|
return position == null ? null : position.getPath(); |
|
|
|
} else if (key.matches(visitIdKey)) { |
|
|
|
Long appId = Long.parseLong(str[1]); |
|
|
|
String taskId = str[2]; |
|
|
|
FileVo.FilePosition position = fileDao.getByAppIdAndTaskId(appId, taskId); |
|
|
|
return position == null ? null : position.getId(); |
|
|
|
} else if (key.matches(visitPathKey)) { |
|
|
|
Long appId = Long.parseLong(str[1]); |
|
|
|
String taskId = str[2]; |
|
|
|
FileVo.FilePosition position = fileDao.getByAppIdAndTaskId(appId, taskId); |
|
|
|
return position == null ? null : getVisitUrl(position.getId(), position.getVisitUrl()); |
|
|
|
} else if (key.matches(md5Key)) { |
|
|
|
return fileDao.getMd5ByResultId(Long.parseLong(str[1])); |
|
|
|
} else if (key.matches(sha1Key)) { |
|
|
|
return fileDao.getSha1ByResultId(Long.parseLong(str[1])); |
|
|
|
} |
|
|
|
return null; |
|
|
|
} |
|
|
|
|