|
@@ -12,6 +12,7 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.xxl.job.core.enums.NoEn;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.jeecg.common.api.vo.Result;
|
|
|
import org.jeecg.common.util.DateUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
@@ -120,7 +121,7 @@ public class ShiwanFileUploadServiceImpl extends ServiceImpl<ShiwanFileUploadMap
|
|
|
InputStream inputStream = null;
|
|
|
try {
|
|
|
inputStream = file.getInputStream();
|
|
|
- resultFile = CosUtils.uploadDetailInputStreamV2(inputStream, existFiles.getCfileName(), existFiles.getFileSuffix(), file.getSize(), url);
|
|
|
+ resultFile = CosUtils.uploadDetailInputStreamV2(inputStream, existFiles.getFileName(), existFiles.getFileSuffix(), file.getSize(), url);
|
|
|
} catch (IOException e) {
|
|
|
log.error("更新文件,上传COS失败", e);
|
|
|
} finally {
|
|
@@ -132,6 +133,8 @@ public class ShiwanFileUploadServiceImpl extends ServiceImpl<ShiwanFileUploadMap
|
|
|
queryWrapper.eq("id", existFiles.getId());
|
|
|
existFiles.setFileSize(resultFile.getFileSize() + "B");
|
|
|
existFiles.setUploadTime(new Date());
|
|
|
+ existFiles.setFileUrl(resultFile.getFileUrl());
|
|
|
+ existFiles.setCfileName(resultFile.getCFileName());
|
|
|
shiwanFileUploadMapper.update(existFiles, queryWrapper);
|
|
|
shiwanFileUploadMapper.deleteByParentId(existFiles.getId());
|
|
|
return existFiles;
|
|
@@ -187,14 +190,17 @@ public class ShiwanFileUploadServiceImpl extends ServiceImpl<ShiwanFileUploadMap
|
|
|
|
|
|
|
|
|
@Override
|
|
|
- public ShiwanFileUpload createNewZipFile(MultipartFile file, String id, String updateName, String userId, Long accountId, String fileType) throws IOException {
|
|
|
- ShiwanFileUpload fileUpload = shiwanFileUploadMapper.selectById(id);
|
|
|
+ public Result<Object> createNewZipFile(MultipartFile file, String id, String updateName, String userId, Long accountId, String fileType, String isCreate, String newFileName) throws IOException {
|
|
|
+ ShiwanFileUpload oldFile = shiwanFileUploadMapper.selectById(id);
|
|
|
+ if (Check.isNull(oldFile)) {
|
|
|
+ return Result.error("查询原文件数据失败");
|
|
|
+ }
|
|
|
StringBuffer path = new StringBuffer();
|
|
|
String uuid = UUID.randomUUID().toString();
|
|
|
path.append(downloadPath).append(DateUtils.getNowDate(DateUtils.WEB_FORMAT)).append("/").append(uuid).append("/");
|
|
|
log.info("----------服务器下载地址:{}", path.toString());
|
|
|
//解压zip文件
|
|
|
- List<String> urlList = unzipFiles(fileUpload, path.toString(), null);
|
|
|
+ List<String> urlList = unzipFiles(oldFile, path.toString(), null);
|
|
|
String newFilePath = "";
|
|
|
if (null != urlList && urlList.size() > 0) {
|
|
|
Iterator it = urlList.iterator();
|
|
@@ -210,12 +216,27 @@ public class ShiwanFileUploadServiceImpl extends ServiceImpl<ShiwanFileUploadMap
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+ if (Check.isNull(newFilePath)) {
|
|
|
+ return Result.error("被替换文件名称有误");
|
|
|
+ }
|
|
|
//添加上新的对象
|
|
|
String newUrl = FileUtil.approvalFile(file, newFilePath);
|
|
|
urlList.add(newUrl);
|
|
|
//压缩zip文件
|
|
|
- String newFileName = DateUtils.getNowDate(DateUtils.LONG_FORMAT).concat("_COPY-FROM_").concat(fileUpload.getFileName());
|
|
|
- return createNewZipFiles(urlList, path.toString(), newFileName, updateName, userId, accountId, fileType);
|
|
|
+ if (Check.isNull(newFileName) && NoEn.NO1.valueStr().equals(isCreate)) {
|
|
|
+ newFileName = DateUtils.getNowDate(DateUtils.LONG_FORMAT).concat("_COPY-FROM_").concat(oldFile.getFileName());
|
|
|
+ }
|
|
|
+ ShiwanFileUpload newFile = new ShiwanFileUpload();
|
|
|
+ newFile.setUserId(userId);
|
|
|
+ newFile.setAccountId(accountId);
|
|
|
+ newFile.setFileType(fileType);
|
|
|
+ newFile.setFileName(newFileName);
|
|
|
+ oldFile.setUserId(userId);
|
|
|
+ oldFile.setAccountId(accountId);
|
|
|
+ oldFile.setFileType(fileType);
|
|
|
+ oldFile.setFileName(newFileName);
|
|
|
+ ShiwanFileUpload newZipFiles = createNewZipFiles(urlList, path.toString(), newFile, isCreate, oldFile);
|
|
|
+ return Result.ok(newZipFiles);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -291,22 +312,30 @@ public class ShiwanFileUploadServiceImpl extends ServiceImpl<ShiwanFileUploadMap
|
|
|
* @throws
|
|
|
* @author ZHAOXA
|
|
|
*/
|
|
|
- private ShiwanFileUpload createNewZipFiles(List<String> list, String path, String zipfilename, String updateName, String userId, Long accountId, String fileType) throws IOException {
|
|
|
- String zipUrl = FileUtil.zipCompress(path.concat(zipfilename), new File(path.concat("innerFiles/")));
|
|
|
- ShiwanFileUpload shiwanFileUpload = new ShiwanFileUpload();
|
|
|
- shiwanFileUpload.setUserId(userId);
|
|
|
- shiwanFileUpload.setAccountId(accountId);
|
|
|
- shiwanFileUpload.setFileType(fileType);
|
|
|
+ private ShiwanFileUpload createNewZipFiles(List<String> list, String path, ShiwanFileUpload addFile, String isCreate, ShiwanFileUpload updateFile) throws IOException {
|
|
|
+ String zipUrl = FileUtil.zipCompress(path.concat(addFile.getFileName()), new File(path.concat("innerFiles/")));
|
|
|
try {
|
|
|
- shiwanFileUpload.setSignature(LoadFileUtil.getMD5(zipUrl));
|
|
|
+ String md5 = LoadFileUtil.getMD5(zipUrl);
|
|
|
+ addFile.setSignature(md5);
|
|
|
+ updateFile.setSignature(md5);
|
|
|
} catch (IOException e) {
|
|
|
log.error("获取MD5签名失败", e);
|
|
|
}
|
|
|
- //存储新ZIP包
|
|
|
- ShiwanFileUpload newZipEntity = saveFile(FileUtil.getMulFileByPath(zipUrl), shiwanFileUpload, null);
|
|
|
- deletelocalFiles(zipUrl);
|
|
|
- if (!Check.isNull(newZipEntity)) {
|
|
|
- saveInnerFiles(newZipEntity, list);
|
|
|
+ ShiwanFileUpload newZipEntity = null;
|
|
|
+ //判断是新增还是更新
|
|
|
+ if (NoEn.NO1.valueStr().equals(isCreate)) {
|
|
|
+ //存储新ZIP包
|
|
|
+ newZipEntity = saveFile(FileUtil.getMulFileByPath(zipUrl), addFile, null);
|
|
|
+ deletelocalFiles(zipUrl);
|
|
|
+ if (!Check.isNull(newZipEntity)) {
|
|
|
+ saveInnerFiles(newZipEntity, list);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ newZipEntity = updateFile(FileUtil.getMulFileByPath(zipUrl), updateFile);
|
|
|
+ deletelocalFiles(zipUrl);
|
|
|
+ if (!Check.isNull(newZipEntity)) {
|
|
|
+ saveInnerFiles(newZipEntity, list);
|
|
|
+ }
|
|
|
}
|
|
|
return newZipEntity;
|
|
|
}
|