|
@@ -1,9 +1,13 @@
|
|
package cn.iselab.mooctest.site.service.impl;
|
|
package cn.iselab.mooctest.site.service.impl;
|
|
|
|
|
|
import cn.iselab.mooctest.site.service.OSSService;
|
|
import cn.iselab.mooctest.site.service.OSSService;
|
|
|
|
+import cn.iselab.mooctest.site.util.data.CacheUtil;
|
|
|
|
+import cn.iselab.mooctest.site.web.data.response.ResponseVO;
|
|
import com.aliyun.oss.OSSClient;
|
|
import com.aliyun.oss.OSSClient;
|
|
import com.aliyun.oss.model.*;
|
|
import com.aliyun.oss.model.*;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
+import org.slf4j.Logger;
|
|
|
|
+import org.slf4j.LoggerFactory;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
import javax.annotation.Resource;
|
|
@@ -28,13 +32,19 @@ public class OSSServiceImpl implements OSSService {
|
|
@Resource
|
|
@Resource
|
|
OSSClient ossClient;
|
|
OSSClient ossClient;
|
|
|
|
|
|
|
|
+ @Resource
|
|
|
|
+ CacheUtil cacheUtil;
|
|
|
|
+
|
|
|
|
+ private final Logger LOG = LoggerFactory.getLogger(getClass());
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* 1. 将contextPath下的文件批量打包成服务器上的临时文件.zip
|
|
* 1. 将contextPath下的文件批量打包成服务器上的临时文件.zip
|
|
* 2. 将临时文件上传到oss
|
|
* 2. 将临时文件上传到oss
|
|
* 3. 删除临时文件,返回oss上zip的下载链接
|
|
* 3. 删除临时文件,返回oss上zip的下载链接
|
|
*/
|
|
*/
|
|
@Override
|
|
@Override
|
|
- public String zipFolder(String bucket, String contextPath, String putBucket, String newFilePath) throws Exception {
|
|
|
|
|
|
+ public String zipFolder(String bucket, String contextPath, String putBucket,
|
|
|
|
+ String newFilePath, String cacheKey) throws Exception {
|
|
//打包zip
|
|
//打包zip
|
|
|
|
|
|
//列举contextPath下的所有文件
|
|
//列举contextPath下的所有文件
|
|
@@ -59,8 +69,14 @@ public class OSSServiceImpl implements OSSService {
|
|
CheckedOutputStream cos = new CheckedOutputStream(fos, new Adler32());
|
|
CheckedOutputStream cos = new CheckedOutputStream(fos, new Adler32());
|
|
ZipOutputStream zos = new ZipOutputStream(cos);
|
|
ZipOutputStream zos = new ZipOutputStream(cos);
|
|
|
|
|
|
- for(OSSObjectSummary summary: sums){
|
|
|
|
|
|
+ int totalNum = sums.size();
|
|
|
|
+ for(int i=0; i<totalNum;i++){
|
|
|
|
+ OSSObjectSummary summary = sums.get(i);
|
|
String fileName = summary.getKey();
|
|
String fileName = summary.getKey();
|
|
|
|
+ LOG.info(String.format("批量下载,共[%d]个文件,当前至第[%d]个文件,文件名为[%s]",
|
|
|
|
+ totalNum, i, fileName));
|
|
|
|
+ cacheUtil.setDownloadProcess(cacheKey, String.format("批量下载,共[%d]个文件,当前至第[%d]个文件,文件名为[%s]",
|
|
|
|
+ totalNum, i, fileName));
|
|
zos.putNextEntry(new ZipEntry(fileName.replace(contextPath, "")));
|
|
zos.putNextEntry(new ZipEntry(fileName.replace(contextPath, "")));
|
|
|
|
|
|
OSSObject ossObject = ossClient.getObject(bucket, fileName);
|
|
OSSObject ossObject = ossClient.getObject(bucket, fileName);
|
|
@@ -74,6 +90,7 @@ public class OSSServiceImpl implements OSSService {
|
|
zos.close();
|
|
zos.close();
|
|
|
|
|
|
// 上传到oss
|
|
// 上传到oss
|
|
|
|
+ cacheUtil.setDownloadProcess(cacheKey, "准备上传到oss");
|
|
PutObjectRequest putObjectRequest = new PutObjectRequest(putBucket, newFilePath, zipFile);
|
|
PutObjectRequest putObjectRequest = new PutObjectRequest(putBucket, newFilePath, zipFile);
|
|
PutObjectResult result = ossClient.putObject(putObjectRequest);
|
|
PutObjectResult result = ossClient.putObject(putObjectRequest);
|
|
|
|
|