|
@@ -16,6 +16,7 @@ import java.util.UUID;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
import javax.annotation.Resource;
|
|
|
|
|
|
|
|
+import org.apache.commons.io.FileUtils;
|
|
import org.apache.commons.lang3.RandomStringUtils;
|
|
import org.apache.commons.lang3.RandomStringUtils;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.Logger;
|
|
@@ -49,6 +50,7 @@ import com.qmth.themis.common.util.Result;
|
|
import com.qmth.themis.common.util.ResultUtil;
|
|
import com.qmth.themis.common.util.ResultUtil;
|
|
|
|
|
|
import cn.hutool.core.date.DateUtil;
|
|
import cn.hutool.core.date.DateUtil;
|
|
|
|
+import sun.misc.BASE64Decoder;
|
|
|
|
|
|
/**
|
|
/**
|
|
* @Description: 试卷导入
|
|
* @Description: 试卷导入
|
|
@@ -244,15 +246,109 @@ public class TaskExamPaperImportTemplete implements TaskImportTemplete {
|
|
if (processPaper) {
|
|
if (processPaper) {
|
|
disposePaper(rootDir, paper, paperFile, attachmentDir);
|
|
disposePaper(rootDir, paper, paperFile, attachmentDir);
|
|
disposeStruct(rootDir, paper, paperFile);
|
|
disposeStruct(rootDir, paper, paperFile);
|
|
|
|
+ disposeViewPaper(rootDir, paper, paperFile, attachmentDir);
|
|
}
|
|
}
|
|
if (processAnswer) {
|
|
if (processAnswer) {
|
|
- disposeAnswer(rootDir, paper, answerFile);
|
|
|
|
|
|
+ File structFile;
|
|
|
|
+ if(processPaper) {
|
|
|
|
+ structFile=paperFile;
|
|
|
|
+ }else {
|
|
|
|
+ String structPath = paper.getStructPath();
|
|
|
|
+ SystemConfig systemConfig = SpringContextHolder.getBean(SystemConfig.class);
|
|
|
|
+ String url = OssUtil.getUrlForPrivateBucket(systemConfig.getOssEnv(3), structPath);
|
|
|
|
+ structFile = new File(rootDir + uuid() + ".json");
|
|
|
|
+ FileUtil.saveUrlAsFile(url, structFile);
|
|
|
|
+ }
|
|
|
|
+ disposeAnswer(rootDir, paper, answerFile,structFile,attachmentDir);
|
|
}
|
|
}
|
|
Integer audioPlayCount = (Integer) map.get("audioPlayCount");
|
|
Integer audioPlayCount = (Integer) map.get("audioPlayCount");
|
|
paper.setAudioPlayCount(audioPlayCount);
|
|
paper.setAudioPlayCount(audioPlayCount);
|
|
teExamPaperService.saveOrUpdate(paper);
|
|
teExamPaperService.saveOrUpdate(paper);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ private void disposeViewPaper(String rootDir, TEExamPaper paper, File paperFile, File attachmentDir) {
|
|
|
|
+ File urlPaperFile = new File(rootDir + uuid() + ".json");
|
|
|
|
+ JSONObject structJson = JSONObject.parseObject(FileUtil.readFileContent(paperFile));
|
|
|
|
+ JSONArray structdetails = structJson.getJSONArray("details");
|
|
|
|
+ if(structdetails==null||structdetails.size()==0) {
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ for (int i = 0; i < structdetails.size(); i++) {
|
|
|
|
+ JSONArray structdetailquestions = structdetails.getJSONObject(i).getJSONArray("questions");
|
|
|
|
+ if(structdetailquestions!=null&&structdetailquestions.size()>=0) {
|
|
|
|
+ for (int j = 0; j < structdetailquestions.size(); j++) {
|
|
|
|
+ JSONObject structquestion = structdetailquestions.getJSONObject(j);
|
|
|
|
+ JSONObject body = structquestion.getJSONObject("body");
|
|
|
|
+ disposeQuestionBodyUrl(rootDir, body, paper.getId(), attachmentDir);
|
|
|
|
+ if (structquestion.getInteger("structType").intValue() == 6) {
|
|
|
|
+ JSONArray structsubQuestions = structquestion.getJSONArray("subQuestions");
|
|
|
|
+ for (int k = 0; k < structsubQuestions.size(); k++) {
|
|
|
|
+ JSONObject structsubquestion = structsubQuestions.getJSONObject(k);
|
|
|
|
+ JSONArray options = structsubquestion.getJSONArray("options");
|
|
|
|
+ disposeQuestionOptionsUrl(rootDir, options, paper.getId(), attachmentDir);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ FileUtil.saveAsFile(urlPaperFile.getAbsolutePath(), structJson.toJSONString());
|
|
|
|
+ String filePath = sdf.format(new Date()) + "/" + uuid() + ".json";
|
|
|
|
+ paper.setPaperViewPath(filePath);
|
|
|
|
+ SystemConfig systemConfig = SpringContextHolder.getBean(SystemConfig.class);
|
|
|
|
+ OssUtil.ossUpload(systemConfig.getOssEnv(3), filePath, urlPaperFile);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private void disposeQuestionBodyUrl(String rootDir,JSONObject body,Long paperId,File attachmentDir) {
|
|
|
|
+ if(body==null) {
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ JSONArray sections = body.getJSONArray("sections");
|
|
|
|
+ if(sections==null||sections.size()==0) {
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ for(int j=0;j<sections.size();j++) {
|
|
|
|
+ JSONObject block = sections.getJSONObject(j);
|
|
|
|
+ if(block!=null) {
|
|
|
|
+ JSONArray blocks = block.getJSONArray("blocks");
|
|
|
|
+ if(blocks!=null&&blocks.size()>0) {
|
|
|
|
+ for(int m=0;m<blocks.size();m++) {
|
|
|
|
+ JSONObject blockInfo = blocks.getJSONObject(m);
|
|
|
|
+ uploadImageAndAudio(rootDir,blockInfo, paperId, attachmentDir);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private void disposeQuestionOptionsUrl(String rootDir,JSONArray options,Long paperId,File attachmentDir) {
|
|
|
|
+ if(options==null||options.size()==0) {
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ for(int i=0;i<options.size();i++) {
|
|
|
|
+ JSONObject option = options.getJSONObject(i);
|
|
|
|
+ if(option!=null) {
|
|
|
|
+ JSONObject body = option.getJSONObject("body");
|
|
|
|
+ if(body!=null) {
|
|
|
|
+ JSONArray sections = body.getJSONArray("sections");
|
|
|
|
+ if(sections!=null&§ions.size()>0) {
|
|
|
|
+ for(int j=0;j<sections.size();j++) {
|
|
|
|
+ JSONObject block = sections.getJSONObject(j);
|
|
|
|
+ if(block!=null) {
|
|
|
|
+ JSONArray blocks = block.getJSONArray("blocks");
|
|
|
|
+ if(blocks!=null&&blocks.size()>0) {
|
|
|
|
+ for(int m=0;m<blocks.size();m++) {
|
|
|
|
+ JSONObject blockInfo = blocks.getJSONObject(m);
|
|
|
|
+ uploadImageAndAudio(rootDir,blockInfo, paperId, attachmentDir);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
private void disposePaper(String rootDir, TEExamPaper paper, File paperFile, File attachmentDir) {
|
|
private void disposePaper(String rootDir, TEExamPaper paper, File paperFile, File attachmentDir) {
|
|
if (paperFile == null) {
|
|
if (paperFile == null) {
|
|
return;
|
|
return;
|
|
@@ -303,18 +399,108 @@ public class TaskExamPaperImportTemplete implements TaskImportTemplete {
|
|
OssUtil.ossUpload(systemConfig.getOssEnv(3), filePath, file);
|
|
OssUtil.ossUpload(systemConfig.getOssEnv(3), filePath, file);
|
|
}
|
|
}
|
|
|
|
|
|
- private void disposeAnswer(String rootDir, TEExamPaper paper, File answerFile) {
|
|
|
|
|
|
+ private void disposeAnswer(String rootDir, TEExamPaper paper, File answerFile,File structFile,File attachmentDir) {
|
|
if (answerFile == null) {
|
|
if (answerFile == null) {
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
-// File encryptFile = new File(rootDir + uuid() + ".json");
|
|
|
|
-// FileUtil.encryptFile(answerFile, encryptFile, paper.getDecryptSecret(), paper.getDecryptVector());
|
|
|
|
|
|
+ File urlAnswerFile = new File(rootDir + uuid() + ".json");
|
|
|
|
+ JSONObject answerJson = JSONObject.parseObject(FileUtil.readFileContent(answerFile));
|
|
|
|
+ JSONArray answerdetails = answerJson.getJSONArray("details");
|
|
|
|
+ JSONObject structJson = JSONObject.parseObject(FileUtil.readFileContent(structFile));
|
|
|
|
+ JSONArray structdetails = structJson.getJSONArray("details");
|
|
|
|
+ for (int i = 0; i < answerdetails.size(); i++) {
|
|
|
|
+ JSONArray answerdetailquestions = answerdetails.getJSONObject(i).getJSONArray("questions");
|
|
|
|
+ JSONArray structdetailquestions = structdetails.getJSONObject(i).getJSONArray("questions");
|
|
|
|
+ for (int j = 0; j < answerdetailquestions.size(); j++) {
|
|
|
|
+ JSONObject answerquestion = answerdetailquestions.getJSONObject(j);
|
|
|
|
+ JSONObject structquestion = structdetailquestions.getJSONObject(j);
|
|
|
|
+ if (structquestion.getInteger("structType").intValue() != 1
|
|
|
|
+ && structquestion.getInteger("structType").intValue() != 2
|
|
|
|
+ && structquestion.getInteger("structType").intValue() != 3
|
|
|
|
+ && structquestion.getInteger("structType").intValue() != 6) {
|
|
|
|
+ JSONArray answer = answerquestion.getJSONArray("answer");
|
|
|
|
+ disposeAnswerUrl(rootDir,answer, paper.getId(), attachmentDir);
|
|
|
|
+ }
|
|
|
|
+ if (structquestion.getInteger("structType").intValue() == 6) {
|
|
|
|
+ JSONArray answersubQuestions = answerquestion.getJSONArray("subQuestions");
|
|
|
|
+ JSONArray structsubQuestions = structquestion.getJSONArray("subQuestions");
|
|
|
|
+ for (int k = 0; k < answersubQuestions.size(); k++) {
|
|
|
|
+ JSONObject answersubquestion = answersubQuestions.getJSONObject(k);
|
|
|
|
+ JSONObject structsubquestion = structsubQuestions.getJSONObject(k);
|
|
|
|
+ if (structsubquestion.getInteger("structType").intValue() != 1
|
|
|
|
+ && structsubquestion.getInteger("structType").intValue() != 2
|
|
|
|
+ && structsubquestion.getInteger("structType").intValue() != 3) {
|
|
|
|
+ JSONArray answer = answersubquestion.getJSONArray("answer");
|
|
|
|
+ disposeAnswerUrl(rootDir,answer, paper.getId(), attachmentDir);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ FileUtil.saveAsFile(urlAnswerFile.getAbsolutePath(), answerJson.toJSONString());
|
|
String filePath = sdf.format(new Date()) + "/" + uuid() + ".json";
|
|
String filePath = sdf.format(new Date()) + "/" + uuid() + ".json";
|
|
paper.setAnswerPath(filePath);
|
|
paper.setAnswerPath(filePath);
|
|
SystemConfig systemConfig = SpringContextHolder.getBean(SystemConfig.class);
|
|
SystemConfig systemConfig = SpringContextHolder.getBean(SystemConfig.class);
|
|
- OssUtil.ossUpload(systemConfig.getOssEnv(3), filePath, answerFile);
|
|
|
|
|
|
+ OssUtil.ossUpload(systemConfig.getOssEnv(3), filePath, urlAnswerFile);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ private void disposeAnswerUrl(String rootDir,JSONArray answer,Long paperId,File attachmentDir) {
|
|
|
|
+ if(answer!=null&&answer.size()>0) {
|
|
|
|
+ for(int i=0;i<answer.size();i++) {
|
|
|
|
+ JSONObject section = answer.getJSONObject(i);
|
|
|
|
+ if(section!=null) {
|
|
|
|
+ JSONArray sections = section.getJSONArray("sections");
|
|
|
|
+ if(sections!=null&§ions.size()>0) {
|
|
|
|
+ for(int j=0;j<sections.size();j++) {
|
|
|
|
+ JSONObject block = sections.getJSONObject(j);
|
|
|
|
+ if(block!=null) {
|
|
|
|
+ JSONArray blocks = block.getJSONArray("blocks");
|
|
|
|
+ if(blocks!=null&&blocks.size()>0) {
|
|
|
|
+ for(int m=0;m<blocks.size();m++) {
|
|
|
|
+ JSONObject blockInfo = blocks.getJSONObject(m);
|
|
|
|
+ uploadImageAndAudio(rootDir,blockInfo, paperId, attachmentDir);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private void uploadImageAndAudio(String rootDir,JSONObject blockInfo,Long paperId,File attachmentDir) {
|
|
|
|
+ String type=blockInfo.getString("type");
|
|
|
|
+ String value=blockInfo.getString("value");
|
|
|
|
+ if(("image".equals(type)||"audio".equals(type))
|
|
|
|
+ &&StringUtils.isNotBlank(value)
|
|
|
|
+ &&!value.toLowerCase().startsWith("https://")
|
|
|
|
+ &&!value.toLowerCase().startsWith("http://")) {
|
|
|
|
+ if("image".equals(type)&&value.contains("data:image")) {
|
|
|
|
+ String suff=value.substring(11, value.indexOf(";"));
|
|
|
|
+ File iamgeFile = new File(rootDir+uuid()+"."+suff);
|
|
|
|
+ BASE64Decoder decoder = new BASE64Decoder();
|
|
|
|
+ try {
|
|
|
|
+ byte[] bytes = decoder.decodeBuffer(value.substring(value.indexOf(",") + 1));
|
|
|
|
+ FileUtils.writeByteArrayToFile(iamgeFile, bytes);
|
|
|
|
+ } catch (IOException e) {
|
|
|
|
+ throw new BusinessException("媒体文件上传处理出错:"+blockInfo.toJSONString()+" errmsg:"+e.getMessage() );
|
|
|
|
+ }
|
|
|
|
+ String filePath = "upload/paper_file/"+paperId+"/" + uuid() +"."+ suff;
|
|
|
|
+ SystemConfig systemConfig = SpringContextHolder.getBean(SystemConfig.class);
|
|
|
|
+ OssUtil.ossUpload(systemConfig.getOssEnv(3), filePath, iamgeFile);
|
|
|
|
+ blockInfo.put("value", systemConfig.getProperty("aliyun.oss.url") + "/" +filePath);
|
|
|
|
+ }else{
|
|
|
|
+ String suff=value.substring(value.indexOf("."));
|
|
|
|
+ String filePath = "upload/paper_file/"+paperId+"/" + uuid() + suff;
|
|
|
|
+ File audioFile=new File(attachmentDir.getAbsolutePath()+"/"+value);
|
|
|
|
+ SystemConfig systemConfig = SpringContextHolder.getBean(SystemConfig.class);
|
|
|
|
+ OssUtil.ossUpload(systemConfig.getOssEnv(3), filePath, audioFile);
|
|
|
|
+ blockInfo.put("value", systemConfig.getProperty("aliyun.oss.url") + "/" +filePath);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
private void addResult(StringBuilder result, String msg) {
|
|
private void addResult(StringBuilder result, String msg) {
|
|
result.append(msg).append("\r\n");
|
|
result.append(msg).append("\r\n");
|
|
}
|
|
}
|