|
@@ -1,15 +1,18 @@
|
|
package cn.com.qmth.examcloud.core.oe.student.service.impl;
|
|
package cn.com.qmth.examcloud.core.oe.student.service.impl;
|
|
|
|
|
|
import cn.com.qmth.examcloud.commons.exception.StatusException;
|
|
import cn.com.qmth.examcloud.commons.exception.StatusException;
|
|
|
|
+import cn.com.qmth.examcloud.commons.util.HttpClientUtil;
|
|
import cn.com.qmth.examcloud.core.basic.api.bean.CourseBean;
|
|
import cn.com.qmth.examcloud.core.basic.api.bean.CourseBean;
|
|
import cn.com.qmth.examcloud.core.oe.common.entity.ExamRecordDataEntity;
|
|
import cn.com.qmth.examcloud.core.oe.common.entity.ExamRecordDataEntity;
|
|
import cn.com.qmth.examcloud.core.oe.common.entity.ExamRecordForMarkingEntity;
|
|
import cn.com.qmth.examcloud.core.oe.common.entity.ExamRecordForMarkingEntity;
|
|
import cn.com.qmth.examcloud.core.oe.common.entity.ExamStudentEntity;
|
|
import cn.com.qmth.examcloud.core.oe.common.entity.ExamStudentEntity;
|
|
|
|
+import cn.com.qmth.examcloud.core.oe.common.entity.OfflineFileEntity;
|
|
import cn.com.qmth.examcloud.core.oe.common.enums.ExamRecordStatus;
|
|
import cn.com.qmth.examcloud.core.oe.common.enums.ExamRecordStatus;
|
|
import cn.com.qmth.examcloud.core.oe.common.enums.ExamType;
|
|
import cn.com.qmth.examcloud.core.oe.common.enums.ExamType;
|
|
import cn.com.qmth.examcloud.core.oe.common.repository.ExamRecordDataRepo;
|
|
import cn.com.qmth.examcloud.core.oe.common.repository.ExamRecordDataRepo;
|
|
import cn.com.qmth.examcloud.core.oe.common.repository.ExamRecordForMarkingRepo;
|
|
import cn.com.qmth.examcloud.core.oe.common.repository.ExamRecordForMarkingRepo;
|
|
import cn.com.qmth.examcloud.core.oe.common.repository.ExamStudentRepo;
|
|
import cn.com.qmth.examcloud.core.oe.common.repository.ExamStudentRepo;
|
|
|
|
+import cn.com.qmth.examcloud.core.oe.common.repository.OfflineFileRepo;
|
|
import cn.com.qmth.examcloud.core.oe.common.service.GainBaseDataService;
|
|
import cn.com.qmth.examcloud.core.oe.common.service.GainBaseDataService;
|
|
import cn.com.qmth.examcloud.core.oe.student.bean.OfflineExamCourseInfo;
|
|
import cn.com.qmth.examcloud.core.oe.student.bean.OfflineExamCourseInfo;
|
|
import cn.com.qmth.examcloud.core.oe.student.service.*;
|
|
import cn.com.qmth.examcloud.core.oe.student.service.*;
|
|
@@ -20,17 +23,35 @@ import cn.com.qmth.examcloud.examwork.api.bean.ExamBean;
|
|
import cn.com.qmth.examcloud.support.cache.CacheHelper;
|
|
import cn.com.qmth.examcloud.support.cache.CacheHelper;
|
|
import cn.com.qmth.examcloud.support.cache.bean.OrgCacheBean;
|
|
import cn.com.qmth.examcloud.support.cache.bean.OrgCacheBean;
|
|
import cn.com.qmth.examcloud.support.cache.bean.SysPropertyCacheBean;
|
|
import cn.com.qmth.examcloud.support.cache.bean.SysPropertyCacheBean;
|
|
|
|
+import cn.com.qmth.examcloud.web.facepp.FaceppClient;
|
|
import cn.com.qmth.examcloud.web.helpers.GlobalHelper;
|
|
import cn.com.qmth.examcloud.web.helpers.GlobalHelper;
|
|
import main.java.com.UpYun;
|
|
import main.java.com.UpYun;
|
|
|
|
+import org.apache.commons.codec.binary.Base64;
|
|
|
|
+import org.apache.commons.compress.utils.IOUtils;
|
|
|
|
+import org.apache.commons.io.FileUtils;
|
|
|
|
+import org.apache.http.HttpEntity;
|
|
|
|
+import org.apache.http.HttpStatus;
|
|
|
|
+import org.apache.http.client.HttpClient;
|
|
|
|
+import org.apache.http.client.config.CookieSpecs;
|
|
|
|
+import org.apache.http.client.config.RequestConfig;
|
|
|
|
+import org.apache.http.client.methods.CloseableHttpResponse;
|
|
|
|
+import org.apache.http.client.methods.HttpGet;
|
|
|
|
+import org.apache.http.impl.client.CloseableHttpClient;
|
|
|
|
+import org.apache.http.impl.client.HttpClients;
|
|
|
|
+import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
|
|
|
|
+import org.apache.http.util.EntityUtils;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import javax.transaction.Transactional;
|
|
import javax.transaction.Transactional;
|
|
-import java.io.File;
|
|
|
|
|
|
+import java.io.*;
|
|
import java.util.ArrayList;
|
|
import java.util.ArrayList;
|
|
import java.util.Date;
|
|
import java.util.Date;
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
|
+import java.util.concurrent.TimeUnit;
|
|
|
|
+import java.util.regex.Matcher;
|
|
|
|
+import java.util.regex.Pattern;
|
|
|
|
|
|
/**
|
|
/**
|
|
* @author chenken
|
|
* @author chenken
|
|
@@ -65,6 +86,9 @@ public class OfflineExamServiceImpl implements OfflineExamService {
|
|
@Autowired
|
|
@Autowired
|
|
private ExamRecordForMarkingRepo examRecordForMarkingRepo;
|
|
private ExamRecordForMarkingRepo examRecordForMarkingRepo;
|
|
|
|
|
|
|
|
+ @Autowired
|
|
|
|
+ private OfflineFileRepo offlineFileRepo;
|
|
|
|
+
|
|
@Value("${$upyun.site.1.bucketName}")
|
|
@Value("${$upyun.site.1.bucketName}")
|
|
private String bucketName;
|
|
private String bucketName;
|
|
|
|
|
|
@@ -237,6 +261,56 @@ public class OfflineExamServiceImpl implements OfflineExamService {
|
|
examRecordDataRepo.save(examRecordDataEntity);
|
|
examRecordDataRepo.save(examRecordDataEntity);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ @Override
|
|
|
|
+ public void downOfflineExam() {
|
|
|
|
+ List<OfflineFileEntity> list = offlineFileRepo.findAll();
|
|
|
|
+ for (int i = 0; i < list.size(); i++) {
|
|
|
|
+ OfflineFileEntity fileEntity = list.get(i);
|
|
|
|
+ String fileUrl = fileEntity.getFileUrl();
|
|
|
|
+ System.out.println((i + 1) + "开始下载文件:" + fileEntity.getFileUrl());
|
|
|
|
+
|
|
|
|
+ //对fileUrl中的中文进行编码
|
|
|
|
+ fileUrl = encode(fileUrl, "utf-8");
|
|
|
|
+
|
|
|
|
+ byte[] bs;
|
|
|
|
+ try {
|
|
|
|
+ bs = HttpClientUtil.get(fileUrl);
|
|
|
|
+ }catch (Exception e){
|
|
|
|
+ System.err.println((i + 1) + "文件:" + fileEntity.getFileUrl() + "下载失败,继续下一个文件...");
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ continue;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ String suffix = fileUrl.substring(fileUrl.lastIndexOf("."));
|
|
|
|
+ String filePath = "d:/data/" + fileEntity.getStudentCode() + "_" + fileEntity.getCourseCode() + suffix;
|
|
|
|
+ File file = new File(filePath);
|
|
|
|
+ try {
|
|
|
|
+ FileUtils.writeByteArrayToFile(file, bs);
|
|
|
|
+ System.out.println((i + 1) + "文件:" + fileEntity.getFileUrl() + "下载完毕...");
|
|
|
|
+ System.out.println("剩余" + (list.size() - i - 1) + "个文件待下载...");
|
|
|
|
+ } catch (IOException e) {
|
|
|
|
+ throw new StatusException("100003", "文件读写失败");
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private static String encode(String url, String chartSet) {
|
|
|
|
+ try {
|
|
|
|
+ Matcher matcher = Pattern.compile("[^\\x00-\\xff]").matcher(url);//双字节,包括中文和中文符号[^\x00-\xff] 中文[\u4e00-\u9fa5]
|
|
|
|
+ while (matcher.find()) {
|
|
|
|
+ String tmp = matcher.group();
|
|
|
|
+ url = url.replaceAll(tmp, java.net.URLEncoder.encode(tmp, chartSet));
|
|
|
|
+ }
|
|
|
|
+ } catch (UnsupportedEncodingException e) {
|
|
|
|
+ try {
|
|
|
|
+ throw e;
|
|
|
|
+ } catch (UnsupportedEncodingException e1) {
|
|
|
|
+ e1.printStackTrace();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return url;
|
|
|
|
+ }
|
|
|
|
+
|
|
private String createOfflineFileName(ExamRecordDataEntity examRecordDataEntity) {
|
|
private String createOfflineFileName(ExamRecordDataEntity examRecordDataEntity) {
|
|
long currentTime = System.currentTimeMillis();
|
|
long currentTime = System.currentTimeMillis();
|
|
|
|
|
|
@@ -249,4 +323,6 @@ public class OfflineExamServiceImpl implements OfflineExamService {
|
|
examRecordDataEntity.getStudentName() + "_" +
|
|
examRecordDataEntity.getStudentName() + "_" +
|
|
courseBean.getCode() + "_" + currentTime;
|
|
courseBean.getCode() + "_" + currentTime;
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+
|
|
}
|
|
}
|