|
@@ -51,7 +51,6 @@ public class ShiwanFileUploadServiceImpl extends ServiceImpl<ShiwanFileUploadMap
|
|
|
|
|
|
@Override
|
|
@Override
|
|
public ShiwanFileUpload saveOrUpdateFile(MultipartFile file, String userId, Long accountId, String fileType, Long parentId, String uuid) {
|
|
public ShiwanFileUpload saveOrUpdateFile(MultipartFile file, String userId, Long accountId, String fileType, Long parentId, String uuid) {
|
|
- ShiwanFileUpload existFiles = getExistFiles(userId, accountId, file.getOriginalFilename(), fileType, parentId);
|
|
|
|
StringBuffer path = new StringBuffer();
|
|
StringBuffer path = new StringBuffer();
|
|
path.append(downloadPath).append(DateUtils.getNowDate(DateUtils.WEB_FORMAT)).append("/").append(UUID.randomUUID().toString()).append("/");
|
|
path.append(downloadPath).append(DateUtils.getNowDate(DateUtils.WEB_FORMAT)).append("/").append(UUID.randomUUID().toString()).append("/");
|
|
log.info("-------下载到服务器地址:{}", path.toString());
|
|
log.info("-------下载到服务器地址:{}", path.toString());
|
|
@@ -63,6 +62,7 @@ public class ShiwanFileUploadServiceImpl extends ServiceImpl<ShiwanFileUploadMap
|
|
} catch (IOException e) {
|
|
} catch (IOException e) {
|
|
log.error("获取MD5签名失败", e);
|
|
log.error("获取MD5签名失败", e);
|
|
}
|
|
}
|
|
|
|
+ ShiwanFileUpload existFiles = getExistFiles(userId, accountId, file.getOriginalFilename(), fileType, parentId, md5);
|
|
if (!Check.isNull(existFiles)) {
|
|
if (!Check.isNull(existFiles)) {
|
|
long start = System.currentTimeMillis();
|
|
long start = System.currentTimeMillis();
|
|
existFiles.setSignature(md5);
|
|
existFiles.setSignature(md5);
|
|
@@ -84,9 +84,9 @@ public class ShiwanFileUploadServiceImpl extends ServiceImpl<ShiwanFileUploadMap
|
|
fileUpload.setUserId(userId);
|
|
fileUpload.setUserId(userId);
|
|
fileUpload.setAccountId(accountId);
|
|
fileUpload.setAccountId(accountId);
|
|
fileUpload.setFileType(fileType);
|
|
fileUpload.setFileType(fileType);
|
|
- fileUpload.setParentId(parentId);
|
|
|
|
try {
|
|
try {
|
|
- shiwanFileUpload = saveFile(file, fileUpload, uuid);
|
|
|
|
|
|
+ //新增zip包
|
|
|
|
+ shiwanFileUpload = saveFile(file, fileUpload, null);
|
|
} catch (IOException e) {
|
|
} catch (IOException e) {
|
|
log.error("新增文件,上传SOC异常", e);
|
|
log.error("新增文件,上传SOC异常", e);
|
|
}
|
|
}
|
|
@@ -121,11 +121,12 @@ public class ShiwanFileUploadServiceImpl extends ServiceImpl<ShiwanFileUploadMap
|
|
try {
|
|
try {
|
|
inputStream = file.getInputStream();
|
|
inputStream = file.getInputStream();
|
|
resultFile = CosUtils.uploadDetailInputStreamV2(inputStream, existFiles.getCfileName(), existFiles.getFileSuffix(), file.getSize(), url);
|
|
resultFile = CosUtils.uploadDetailInputStreamV2(inputStream, existFiles.getCfileName(), existFiles.getFileSuffix(), file.getSize(), url);
|
|
- inputStream.close();
|
|
|
|
} catch (IOException e) {
|
|
} catch (IOException e) {
|
|
log.error("更新文件,上传COS失败", e);
|
|
log.error("更新文件,上传COS失败", e);
|
|
} finally {
|
|
} finally {
|
|
- inputStream.close();
|
|
|
|
|
|
+ if (inputStream != null) {
|
|
|
|
+ inputStream.close();
|
|
|
|
+ }
|
|
}
|
|
}
|
|
QueryWrapper<ShiwanFileUpload> queryWrapper = new QueryWrapper<>();
|
|
QueryWrapper<ShiwanFileUpload> queryWrapper = new QueryWrapper<>();
|
|
queryWrapper.eq("id", existFiles.getId());
|
|
queryWrapper.eq("id", existFiles.getId());
|
|
@@ -158,12 +159,13 @@ public class ShiwanFileUploadServiceImpl extends ServiceImpl<ShiwanFileUploadMap
|
|
InputStream inputStream = null;
|
|
InputStream inputStream = null;
|
|
try {
|
|
try {
|
|
inputStream = file.getInputStream();
|
|
inputStream = file.getInputStream();
|
|
- resultFile = CosUtils.uploadDetailInputStream(inputStream, filename, fileSuffix, file.getSize(), url);
|
|
|
|
- inputStream.close();
|
|
|
|
|
|
+ resultFile = CosUtils.uploadDetailInputStreamV2(inputStream, filename, fileSuffix, file.getSize(), url);
|
|
} catch (IOException e) {
|
|
} catch (IOException e) {
|
|
log.error("上传COS异常", e);
|
|
log.error("上传COS异常", e);
|
|
} finally {
|
|
} finally {
|
|
- inputStream.close();
|
|
|
|
|
|
+ if (inputStream != null) {
|
|
|
|
+ inputStream.close();
|
|
|
|
+ }
|
|
}
|
|
}
|
|
if (!Check.isNull(resultFile)) {
|
|
if (!Check.isNull(resultFile)) {
|
|
fileUpload.setCfileName(resultFile.getCFileName());
|
|
fileUpload.setCfileName(resultFile.getCFileName());
|
|
@@ -325,6 +327,14 @@ public class ShiwanFileUploadServiceImpl extends ServiceImpl<ShiwanFileUploadMap
|
|
shiwanFileUpload.setAccountId(newZipEntity.getAccountId());
|
|
shiwanFileUpload.setAccountId(newZipEntity.getAccountId());
|
|
shiwanFileUpload.setFileType(newZipEntity.getFileType());
|
|
shiwanFileUpload.setFileType(newZipEntity.getFileType());
|
|
shiwanFileUpload.setParentId(newZipEntity.getId());
|
|
shiwanFileUpload.setParentId(newZipEntity.getId());
|
|
|
|
+ String urlpath = url.substring(0, url.lastIndexOf("/"));
|
|
|
|
+ String lastFileName = urlpath.substring(urlpath.lastIndexOf("/") + 1);
|
|
|
|
+ String cosFilePath = "";
|
|
|
|
+ if ("innerFiles".equals(lastFileName)) {
|
|
|
|
+ cosFilePath = newZipEntity.getCfileName();
|
|
|
|
+ } else {
|
|
|
|
+ cosFilePath = newZipEntity.getCfileName().concat("/").concat(lastFileName);
|
|
|
|
+ }
|
|
try {
|
|
try {
|
|
shiwanFileUpload.setSignature(LoadFileUtil.getMD5(url));
|
|
shiwanFileUpload.setSignature(LoadFileUtil.getMD5(url));
|
|
} catch (IOException e) {
|
|
} catch (IOException e) {
|
|
@@ -332,7 +342,7 @@ public class ShiwanFileUploadServiceImpl extends ServiceImpl<ShiwanFileUploadMap
|
|
}
|
|
}
|
|
mulFileByPath = FileUtil.getMulFileByPath(url);
|
|
mulFileByPath = FileUtil.getMulFileByPath(url);
|
|
try {
|
|
try {
|
|
- saveFile(mulFileByPath, shiwanFileUpload, newZipEntity.getCfileName());
|
|
|
|
|
|
+ saveFile(mulFileByPath, shiwanFileUpload, cosFilePath);
|
|
} catch (IOException e) {
|
|
} catch (IOException e) {
|
|
log.error("新增内部文件,上传SOC异常", e);
|
|
log.error("新增内部文件,上传SOC异常", e);
|
|
}
|
|
}
|
|
@@ -363,13 +373,14 @@ public class ShiwanFileUploadServiceImpl extends ServiceImpl<ShiwanFileUploadMap
|
|
* @throws
|
|
* @throws
|
|
* @author ZHAOXA
|
|
* @author ZHAOXA
|
|
*/
|
|
*/
|
|
- private ShiwanFileUpload getExistFiles(String userId, Long accountId, String fileName, String fileType, Long parentId) {
|
|
|
|
|
|
+ private ShiwanFileUpload getExistFiles(String userId, Long accountId, String fileName, String fileType, Long parentId, String md5) {
|
|
JSONObject job = new JSONObject();
|
|
JSONObject job = new JSONObject();
|
|
job.put("useId", userId);
|
|
job.put("useId", userId);
|
|
job.put("accountId", accountId);
|
|
job.put("accountId", accountId);
|
|
job.put("fileName", fileName);
|
|
job.put("fileName", fileName);
|
|
job.put("fileType", fileType);
|
|
job.put("fileType", fileType);
|
|
job.put("parentId", parentId);
|
|
job.put("parentId", parentId);
|
|
|
|
+ job.put("signature", md5);
|
|
ShiwanFileUpload fileEntity = shiwanFileUploadMapper.selectEntity(job);
|
|
ShiwanFileUpload fileEntity = shiwanFileUploadMapper.selectEntity(job);
|
|
if (Check.isNull(fileEntity)) {
|
|
if (Check.isNull(fileEntity)) {
|
|
return null;
|
|
return null;
|