|
@@ -0,0 +1,89 @@
|
|
|
|
+package cn.iselab.mooctest.site.service.common.impl;
|
|
|
|
+
|
|
|
|
+import cn.iselab.mooctest.site.models.fromKibug.CaseTake;
|
|
|
|
+import cn.iselab.mooctest.site.models.fromKibug.Report;
|
|
|
|
+import cn.iselab.mooctest.site.service.CaseService;
|
|
|
|
+import cn.iselab.mooctest.site.service.common.MongoAPIService;
|
|
|
|
+import cn.iselab.mooctest.site.service.common.ZipService;
|
|
|
|
+import cn.iselab.mooctest.site.service.fromKibug.KibugCaseService;
|
|
|
|
+import cn.iselab.mooctest.site.service.fromKibug.ReportService;
|
|
|
|
+import com.aliyun.oss.OSSClient;
|
|
|
|
+import com.aliyun.oss.model.GetObjectRequest;
|
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
|
+
|
|
|
|
+import java.io.File;
|
|
|
|
+import java.util.List;
|
|
|
|
+
|
|
|
|
+/**
|
|
|
|
+ * @Author ROKG
|
|
|
|
+ * @Description
|
|
|
|
+ * @Date: Created in 上午12:06 2018/1/2
|
|
|
|
+ * @Modified By:
|
|
|
|
+ */
|
|
|
|
+@Service
|
|
|
|
+public class ZipServiceImpl implements ZipService {
|
|
|
|
+
|
|
|
|
+ private final String MAIN_SITE="mooctest-site";
|
|
|
|
+ private final String APP_SITE="kikbug-public";
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ KibugCaseService kibugCaseService;
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ CaseService caseService;
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ MongoAPIService mongoAPIService;
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ ReportService reportService;
|
|
|
|
+
|
|
|
|
+ @Value("${aliOSS.endPoint}")
|
|
|
|
+ private String endPoint;
|
|
|
|
+ @Value("${aliOSS.accessKeyId}")
|
|
|
|
+ private String accessKeyId;
|
|
|
|
+ @Value("${aliOSS.accessKeySecret}")
|
|
|
|
+ private String accessKeySecret;
|
|
|
|
+ @Value("${aliOSS.bucketName.dev}")
|
|
|
|
+ private String bucketNameDev;
|
|
|
|
+ @Value("${aliOSS.bucketName.main}")
|
|
|
|
+ private String bucketName;
|
|
|
|
+ @Value("${aliOSS.bucketName.app}")
|
|
|
|
+ private String bucketNameApp;
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public void zipForReport(long examId,long participantId,String path) throws Exception{
|
|
|
|
+ OSSClient ossClient = new OSSClient(endPoint, accessKeyId, accessKeySecret);
|
|
|
|
+ List<CaseTake> caseTakes=kibugCaseService.getCaseTakeList2(examId,participantId);
|
|
|
|
+ for (CaseTake caseTake:caseTakes){
|
|
|
|
+ Report report=reportService.getReportByCaseTakeId(caseTake.getId());
|
|
|
|
+ if(report==null){
|
|
|
|
+ continue;
|
|
|
|
+ }
|
|
|
|
+ if(report.getScriptLocation()!=null&&!report.getScriptLocation().equals("")){
|
|
|
|
+ downloadFromOSS(path,report.getScriptLocation(),ossClient);
|
|
|
|
+ }
|
|
|
|
+ if(report.getReportLocation()!=null&&!report.getReportLocation().equals("")&&!report.getReportLocation().equals("empty")){
|
|
|
|
+ downloadFromOSS(path,report.getReportLocation(),ossClient);
|
|
|
|
+ }
|
|
|
|
+ if(report.getLogLocation()!=null&&!report.getLogLocation().equals("")){
|
|
|
|
+ String[] logs=report.getLogLocation().split(";");
|
|
|
|
+ for (String str:logs){
|
|
|
|
+ downloadFromOSS(path,str,ossClient);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ ossClient.shutdown();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private void downloadFromOSS(String path,String ossUrl,OSSClient ossClient){
|
|
|
|
+ String name=ossUrl.split("/")[ossUrl.split("/").length-1];
|
|
|
|
+ if(ossUrl.indexOf(MAIN_SITE)>-1){
|
|
|
|
+ ossClient.getObject(new GetObjectRequest(bucketName,ossUrl.substring(50)),new File(path+"/"+name));
|
|
|
|
+ }else if(ossUrl.indexOf(APP_SITE)>-1){
|
|
|
|
+ ossClient.getObject(new GetObjectRequest(bucketNameApp,name),new File(path+"/"+name));
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+}
|