|
@@ -28,6 +28,8 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.qmth.boot.core.exception.StatusException;
|
|
|
+import com.qmth.boot.tools.crypto.AES;
|
|
|
+import com.qmth.boot.tools.models.ByteArray;
|
|
|
import org.apache.commons.collections4.CollectionUtils;
|
|
|
import org.apache.commons.lang.StringUtils;
|
|
|
import org.springframework.stereotype.Service;
|
|
@@ -39,6 +41,7 @@ import javax.annotation.Resource;
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
import java.io.File;
|
|
|
import java.io.IOException;
|
|
|
+import java.nio.charset.StandardCharsets;
|
|
|
import java.util.*;
|
|
|
import java.util.concurrent.atomic.AtomicLong;
|
|
|
import java.util.stream.Collectors;
|
|
@@ -186,25 +189,28 @@ public class ExamStudentServiceImpl extends ServiceImpl<ExamStudentDao, ExamStud
|
|
|
|
|
|
@Transactional
|
|
|
@Override
|
|
|
- public Object analyzeZipAndImportStudents(Long examId, MultipartFile file) throws IOException {
|
|
|
- String tempPath = sysProperty.getTempDir() + "/examStudent";
|
|
|
+ public Object analyzeZipAndImportStudents(Long examId, MultipartFile file) {
|
|
|
+ String tempPath = sysProperty.getTempDir() + "/importExamStudent";
|
|
|
try {
|
|
|
- File tempZipFile = new File(tempPath + "/examStudent.zip");
|
|
|
- if (!tempZipFile.exists()) {
|
|
|
- tempZipFile.mkdirs();
|
|
|
- }
|
|
|
- file.transferTo(tempZipFile);
|
|
|
- String zipPath = tempZipFile.getPath();
|
|
|
- String dirPath = tempPath + "/examStudent";
|
|
|
+ byte[] bytes = file.getBytes();
|
|
|
+ byte[] keyArr = Arrays.copyOfRange(bytes, 0, 16);
|
|
|
+ byte[] ivArr = Arrays.copyOfRange(bytes, 16, 32);
|
|
|
+ byte[] contentArr = Arrays.copyOfRange(bytes, 32, bytes.length);
|
|
|
+ String key = new String(keyArr, StandardCharsets.UTF_8);
|
|
|
+ String iv = new String(ivArr, StandardCharsets.UTF_8);
|
|
|
+ ByteArray byteArray = AES.decrypt(contentArr, key, iv);
|
|
|
|
|
|
- Zip4jUtil.unzipEncryptFile(zipPath, dirPath, "qmth!@#");
|
|
|
+ File decrypt = new File(tempPath + "/decrypt.zip");
|
|
|
+ if (!decrypt.getParentFile().exists()) {
|
|
|
+ decrypt.getParentFile().mkdirs();
|
|
|
+ }
|
|
|
+ byteArray.toFile(decrypt);
|
|
|
+ String dirPath = tempPath + "/unzip";
|
|
|
+ Zip4jUtil.unzip(decrypt.getPath(), dirPath);
|
|
|
|
|
|
File zipDir = new File(dirPath);
|
|
|
File[] firstDirArr = zipDir.listFiles();
|
|
|
- if (Objects.isNull(firstDirArr) || firstDirArr.length != 1) {
|
|
|
- throw new StatusException("文件解析失败:未找到一级目录");
|
|
|
- }
|
|
|
- List<File> studentFileList = Arrays.stream(Objects.requireNonNull(firstDirArr[0].listFiles()))
|
|
|
+ List<File> studentFileList = Arrays.stream(Objects.requireNonNull(firstDirArr))
|
|
|
.filter(e -> e.getName().endsWith("xlsx"))
|
|
|
.collect(Collectors.toList());
|
|
|
if (CollectionUtils.isEmpty(studentFileList)) {
|
|
@@ -254,6 +260,9 @@ public class ExamStudentServiceImpl extends ServiceImpl<ExamStudentDao, ExamStud
|
|
|
insertData(examEntity, studentList);
|
|
|
}
|
|
|
return excelErrors;
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ throw new StatusException(e.getMessage());
|
|
|
} finally {
|
|
|
FileUtil.del(tempPath);
|
|
|
}
|
|
@@ -347,4 +356,4 @@ public class ExamStudentServiceImpl extends ServiceImpl<ExamStudentDao, ExamStud
|
|
|
}
|
|
|
return sj.toString();
|
|
|
}
|
|
|
-}
|
|
|
+}
|