|
@@ -92,7 +92,8 @@ public class ExportThemisPaperServiceImpl implements ExportThemisPaperService {
|
|
if (blocks != null && blocks.size() > 0) {
|
|
if (blocks != null && blocks.size() > 0) {
|
|
for (ThemisBlock block : blocks) {
|
|
for (ThemisBlock block : blocks) {
|
|
if (block.getType().equals("audio")) {
|
|
if (block.getType().equals("audio")) {
|
|
- String id = block.getValue().substring(0, block.getValue().lastIndexOf("."));
|
|
|
|
|
|
+ String val=block.getValue().toString();
|
|
|
|
+ String id = val.substring(0, val.lastIndexOf("."));
|
|
QuestionAudio questionAudio = Model.of(questionAudioRepo.findById(id));
|
|
QuestionAudio questionAudio = Model.of(questionAudioRepo.findById(id));
|
|
String audioFileName = questionAudio.getId() + "."
|
|
String audioFileName = questionAudio.getId() + "."
|
|
+ questionAudio.getFileSuffixes();
|
|
+ questionAudio.getFileSuffixes();
|
|
@@ -120,7 +121,8 @@ public class ExportThemisPaperServiceImpl implements ExportThemisPaperService {
|
|
if (blocks != null && blocks.size() > 0) {
|
|
if (blocks != null && blocks.size() > 0) {
|
|
for (ThemisBlock block : blocks) {
|
|
for (ThemisBlock block : blocks) {
|
|
if (block.getType().equals("audio")) {
|
|
if (block.getType().equals("audio")) {
|
|
- String id = block.getValue().substring(0, block.getValue().lastIndexOf("."));
|
|
|
|
|
|
+ String val=block.getValue().toString();
|
|
|
|
+ String id = val.substring(0, val.lastIndexOf("."));
|
|
QuestionAudio questionAudio = Model
|
|
QuestionAudio questionAudio = Model
|
|
.of(questionAudioRepo.findById(id));
|
|
.of(questionAudioRepo.findById(id));
|
|
String audioFileName = questionAudio.getId() + "."
|
|
String audioFileName = questionAudio.getId() + "."
|
|
@@ -153,6 +155,7 @@ public class ExportThemisPaperServiceImpl implements ExportThemisPaperService {
|
|
makePaperToJsonFile(pa.getPaper(), jsonDirectoryPath);
|
|
makePaperToJsonFile(pa.getPaper(), jsonDirectoryPath);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ @SuppressWarnings("deprecation")
|
|
private void makeAnswerToJsonFile(ThemisAnswer pa, String jsonDirectoryPath) {
|
|
private void makeAnswerToJsonFile(ThemisAnswer pa, String jsonDirectoryPath) {
|
|
// 创建新的JSON文件
|
|
// 创建新的JSON文件
|
|
File file = new File(jsonDirectoryPath + File.separator + "answer.json");
|
|
File file = new File(jsonDirectoryPath + File.separator + "answer.json");
|
|
@@ -165,7 +168,7 @@ public class ExportThemisPaperServiceImpl implements ExportThemisPaperService {
|
|
FileOutputStream outputStream = null;
|
|
FileOutputStream outputStream = null;
|
|
try {
|
|
try {
|
|
outputStream = new FileOutputStream(file);
|
|
outputStream = new FileOutputStream(file);
|
|
- byte b[] = strJSON.getBytes();
|
|
|
|
|
|
+ byte b[] = strJSON.getBytes("UTF-8");
|
|
outputStream.write(b);
|
|
outputStream.write(b);
|
|
outputStream.flush();
|
|
outputStream.flush();
|
|
} catch (FileNotFoundException e) {
|
|
} catch (FileNotFoundException e) {
|
|
@@ -177,6 +180,7 @@ public class ExportThemisPaperServiceImpl implements ExportThemisPaperService {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ @SuppressWarnings("deprecation")
|
|
private void makePaperToJsonFile(ThemisPaper pa, String jsonDirectoryPath) {
|
|
private void makePaperToJsonFile(ThemisPaper pa, String jsonDirectoryPath) {
|
|
// 创建新的JSON文件
|
|
// 创建新的JSON文件
|
|
File file = new File(jsonDirectoryPath + File.separator + "paper.json");
|
|
File file = new File(jsonDirectoryPath + File.separator + "paper.json");
|
|
@@ -189,7 +193,7 @@ public class ExportThemisPaperServiceImpl implements ExportThemisPaperService {
|
|
FileOutputStream outputStream = null;
|
|
FileOutputStream outputStream = null;
|
|
try {
|
|
try {
|
|
outputStream = new FileOutputStream(file);
|
|
outputStream = new FileOutputStream(file);
|
|
- byte b[] = strJSON.getBytes();
|
|
|
|
|
|
+ byte b[] = strJSON.getBytes("UTF-8");
|
|
outputStream.write(b);
|
|
outputStream.write(b);
|
|
outputStream.flush();
|
|
outputStream.flush();
|
|
} catch (FileNotFoundException e) {
|
|
} catch (FileNotFoundException e) {
|
|
@@ -227,7 +231,13 @@ public class ExportThemisPaperServiceImpl implements ExportThemisPaperService {
|
|
computerTestQuestion.setNumber(i + 1);
|
|
computerTestQuestion.setNumber(i + 1);
|
|
themisAnswerContent.setNumber(i + 1);
|
|
themisAnswerContent.setNumber(i + 1);
|
|
// 得到小题题干
|
|
// 得到小题题干
|
|
- computerTestQuestion.setBody(getBody(paperDetailUnit.getQuestion().getQuesBody(), computerTestPaper));
|
|
|
|
|
|
+ if(computerTestQuestion.getStructType()==4) {
|
|
|
|
+ computerTestQuestion.setBody(getFillBlankBody(paperDetailUnit.getQuestion().getQuesBody(), computerTestPaper));
|
|
|
|
+ }else if(computerTestQuestion.getStructType()==6){
|
|
|
|
+ computerTestQuestion.setBody(getNestedBody(paperDetailUnit.getQuestion().getQuesBody(), computerTestPaper));
|
|
|
|
+ }else {
|
|
|
|
+ computerTestQuestion.setBody(getBody(paperDetailUnit.getQuestion().getQuesBody(), computerTestPaper));
|
|
|
|
+ }
|
|
// 得到小题所有选项
|
|
// 得到小题所有选项
|
|
computerTestQuestion.setOptions(getOption(paperDetailUnit.getQuestion(), computerTestPaper));
|
|
computerTestQuestion.setOptions(getOption(paperDetailUnit.getQuestion(), computerTestPaper));
|
|
// 得到小题的答案
|
|
// 得到小题的答案
|
|
@@ -256,7 +266,14 @@ public class ExportThemisPaperServiceImpl implements ExportThemisPaperService {
|
|
// 设置套题中小题题号
|
|
// 设置套题中小题题号
|
|
subcomputerTestQuestion.setNumber(j + 1);
|
|
subcomputerTestQuestion.setNumber(j + 1);
|
|
subthemisAnswerContent.setNumber(j + 1);
|
|
subthemisAnswerContent.setNumber(j + 1);
|
|
- subcomputerTestQuestion.setBody(getBody(subQuestion.getQuesBody(), computerTestPaper));
|
|
|
|
|
|
+
|
|
|
|
+ if(subcomputerTestQuestion.getStructType()==4) {
|
|
|
|
+ subcomputerTestQuestion.setBody(getFillBlankBody(subQuestion.getQuesBody(), computerTestPaper));
|
|
|
|
+ }else if(computerTestQuestion.getStructType()==6){
|
|
|
|
+ subcomputerTestQuestion.setBody(getNestedBody(subQuestion.getQuesBody(), computerTestPaper));
|
|
|
|
+ }else {
|
|
|
|
+ subcomputerTestQuestion.setBody(getBody(subQuestion.getQuesBody(), computerTestPaper));
|
|
|
|
+ }
|
|
subcomputerTestQuestion.setOptions(getOption(subQuestion, computerTestPaper));
|
|
subcomputerTestQuestion.setOptions(getOption(subQuestion, computerTestPaper));
|
|
if (subQuestion.getQuestionType() == QuesStructType.SINGLE_ANSWER_QUESTION
|
|
if (subQuestion.getQuestionType() == QuesStructType.SINGLE_ANSWER_QUESTION
|
|
|| subQuestion.getQuestionType() == QuesStructType.MULTIPLE_ANSWER_QUESTION) {
|
|
|| subQuestion.getQuestionType() == QuesStructType.MULTIPLE_ANSWER_QUESTION) {
|
|
@@ -293,7 +310,6 @@ public class ExportThemisPaperServiceImpl implements ExportThemisPaperService {
|
|
ret.setAnswer(themisAnswer);
|
|
ret.setAnswer(themisAnswer);
|
|
return ret;
|
|
return ret;
|
|
}
|
|
}
|
|
-
|
|
|
|
private ThemisSections getBody(String str, ThemisPaper computerTestPaper) {
|
|
private ThemisSections getBody(String str, ThemisPaper computerTestPaper) {
|
|
ThemisSections body = new ThemisSections();
|
|
ThemisSections body = new ThemisSections();
|
|
List<ThemisSection> sections = new ArrayList<>();
|
|
List<ThemisSection> sections = new ArrayList<>();
|
|
@@ -314,7 +330,27 @@ public class ExportThemisPaperServiceImpl implements ExportThemisPaperService {
|
|
body.setSections(sections);
|
|
body.setSections(sections);
|
|
return body;
|
|
return body;
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+ private ThemisSections getFillBlankBody(String str, ThemisPaper computerTestPaper) {
|
|
|
|
+ ThemisSections body = new ThemisSections();
|
|
|
|
+ List<ThemisSection> sections = new ArrayList<>();
|
|
|
|
+ // 得到小题题干或者答案行数
|
|
|
|
+ if (StringUtils.isBlank(str)) {
|
|
|
|
+ return body;
|
|
|
|
+ }
|
|
|
|
+ String[] questionRowStrings = str.split("</p>");
|
|
|
|
+ for (int i = 0; i < questionRowStrings.length; i++) {
|
|
|
|
+ List<ThemisBlock> blocks = disposeFillBlankQuestionBody(questionRowStrings[i], computerTestPaper);
|
|
|
|
+ if (blocks != null && blocks.size() > 0) {
|
|
|
|
+ ThemisSection section = new ThemisSection();
|
|
|
|
+ // 将小题题干拆分为Block集合
|
|
|
|
+ section.setBlocks(blocks);
|
|
|
|
+ sections.add(section);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ body.setSections(sections);
|
|
|
|
+ return body;
|
|
|
|
+ }
|
|
|
|
+
|
|
private List<ThemisSubjectiveAnswer> getAnswer(String str, ThemisPaper computerTestPaper) {
|
|
private List<ThemisSubjectiveAnswer> getAnswer(String str, ThemisPaper computerTestPaper) {
|
|
List<ThemisSection> sections = new ArrayList<>();
|
|
List<ThemisSection> sections = new ArrayList<>();
|
|
// 得到小题题干或者答案行数
|
|
// 得到小题题干或者答案行数
|
|
@@ -338,6 +374,192 @@ public class ExportThemisPaperServiceImpl implements ExportThemisPaperService {
|
|
an.setSections(sections);
|
|
an.setSections(sections);
|
|
return ans;
|
|
return ans;
|
|
}
|
|
}
|
|
|
|
+ private String changeCloze(String text) {
|
|
|
|
+ StringBuffer buffer = new StringBuffer();
|
|
|
|
+ String regex = "##(\\d)##";
|
|
|
|
+
|
|
|
|
+ Pattern pattern = Pattern.compile(regex);
|
|
|
|
+ Matcher matcher = pattern.matcher(text);
|
|
|
|
+ // 使用find()方法查找匹配项
|
|
|
|
+ while (matcher.find()) {
|
|
|
|
+ matcher.appendReplacement(buffer, "__"+matcher.group(1)+"__");
|
|
|
|
+ }
|
|
|
|
+ return buffer.toString();
|
|
|
|
+ }
|
|
|
|
+ private ThemisSections getNestedBody(String str, ThemisPaper computerTestPaper) {
|
|
|
|
+ ThemisSections body = new ThemisSections();
|
|
|
|
+ List<ThemisSection> sections = new ArrayList<>();
|
|
|
|
+ // 得到小题题干或者答案行数
|
|
|
|
+ if (StringUtils.isBlank(str)) {
|
|
|
|
+ return body;
|
|
|
|
+ }
|
|
|
|
+ String[] questionRowStrings = str.split("</p>");
|
|
|
|
+ for (int i = 0; i < questionRowStrings.length; i++) {
|
|
|
|
+ List<ThemisBlock> blocks = disposeNestedQuestionBody(questionRowStrings[i], computerTestPaper);
|
|
|
|
+ if (blocks != null && blocks.size() > 0) {
|
|
|
|
+ ThemisSection section = new ThemisSection();
|
|
|
|
+ // 将小题题干拆分为Block集合
|
|
|
|
+ section.setBlocks(blocks);
|
|
|
|
+ sections.add(section);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ body.setSections(sections);
|
|
|
|
+ return body;
|
|
|
|
+ }
|
|
|
|
+ private List<ThemisBlock> disposeNestedQuestionBody(String questionRow, ThemisPaper computerTestPaper) {
|
|
|
|
+ List<ThemisBlock> blocks = new ArrayList<>();
|
|
|
|
+ // 去掉每行里面的<p>,<span>,</span>标签
|
|
|
|
+ questionRow = questionRow.replaceAll("<p>", "").replaceAll("</p>", "").replaceAll("<span>", "")
|
|
|
|
+ .replaceAll("</span>", "").replaceAll("</a>", "");
|
|
|
|
+ String[] questionRowStrings = questionRow.split("<|/>|>");
|
|
|
|
+ boolean hasAudio = false;
|
|
|
|
+ for (int i = 0; i < questionRowStrings.length; i++) {
|
|
|
|
+ ThemisBlock block = new ThemisBlock();
|
|
|
|
+ String rowStr = questionRowStrings[i];
|
|
|
|
+ // 判断是否有图片
|
|
|
|
+ if (rowStr.startsWith("img")) {
|
|
|
|
+ rowStr = "<" + rowStr + ">";
|
|
|
|
+ Map<String, Object> param = new HashMap<>();
|
|
|
|
+ // 需要继续做截取,取到Parma
|
|
|
|
+ block.setType("image");
|
|
|
|
+ // 获取图片的路径
|
|
|
|
+ List<String> strSrcList = getImg(rowStr, "src");
|
|
|
|
+ if (strSrcList.size() > 0) {
|
|
|
|
+ String strSrc = strSrcList.get(0).replaceAll("src=\"", "").replaceAll("\"", "");
|
|
|
|
+ block.setValue(strSrc);
|
|
|
|
+ }
|
|
|
|
+ // 获取图片的高度
|
|
|
|
+ List<String> strHeightList = getImg(rowStr, "height");
|
|
|
|
+ if (strHeightList.size() > 0) {
|
|
|
|
+ String strHeight = strHeightList.get(0).replaceAll("height=\"", "").replaceAll("\"", "");
|
|
|
|
+ param.put("height", strHeight);
|
|
|
|
+ }
|
|
|
|
+ // 获取图片的宽度
|
|
|
|
+ List<String> strWidthList = getImg(rowStr, "width");
|
|
|
|
+ if (strHeightList.size() > 0) {
|
|
|
|
+ String strWidth = strWidthList.get(0).replaceAll("width=\"", "").replaceAll("\"", "");
|
|
|
|
+ param.put("width", strWidth);
|
|
|
|
+ }
|
|
|
|
+ block.setParam(param);
|
|
|
|
+ blocks.add(block);
|
|
|
|
+ } else if (rowStr.startsWith("a") && rowStr.contains("id") && rowStr.contains("name")) { // 处理音频
|
|
|
|
+ rowStr = "<" + rowStr + ">";
|
|
|
|
+ block.setType("audio");
|
|
|
|
+ String id=CommonUtils.getAttrValue(rowStr, "id");
|
|
|
|
+ QuestionAudio questionAudio = Model.of(questionAudioRepo.findById(id));
|
|
|
|
+ block.setValue(questionAudio.getId() + "."+ questionAudio.getFileSuffixes());
|
|
|
|
+ blocks.add(block);
|
|
|
|
+ hasAudio = true;
|
|
|
|
+ } else {
|
|
|
|
+ block.setType("text");
|
|
|
|
+ rowStr = rowStr.replace(" ", "");// 消除空格
|
|
|
|
+ rowStr = rowStr.replace(""", "\"");// 将"转换成\"
|
|
|
|
+ rowStr = rowStr.replace("<", "<");// 将<转换成<
|
|
|
|
+ rowStr = rowStr.replace(">", ">");// 将>转换成>
|
|
|
|
+ rowStr = rowStr.replace("&", "&");// 将&转换成&
|
|
|
|
+ if (StringUtils.isNotBlank(rowStr)) {
|
|
|
|
+ block.setValue(changeCloze(rowStr));
|
|
|
|
+ blocks.add(block);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ if (hasAudio) {
|
|
|
|
+ computerTestPaper.setHasAudio(hasAudio);
|
|
|
|
+ }
|
|
|
|
+ return blocks;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private List<ThemisBlock> disposeFillBlankQuestionBody(String questionRow, ThemisPaper computerTestPaper) {
|
|
|
|
+ List<ThemisBlock> blocks = new ArrayList<>();
|
|
|
|
+ // 去掉每行里面的<p>,<span>,</span>标签
|
|
|
|
+ questionRow = questionRow.replaceAll("<p>", "").replaceAll("</p>", "").replaceAll("<span>", "")
|
|
|
|
+ .replaceAll("</span>", "").replaceAll("</a>", "");
|
|
|
|
+ String[] questionRowStrings = questionRow.split("<|/>|>");
|
|
|
|
+ boolean hasAudio = false;
|
|
|
|
+ int blankIndex=0;
|
|
|
|
+ for (int i = 0; i < questionRowStrings.length; i++) {
|
|
|
|
+ ThemisBlock block = new ThemisBlock();
|
|
|
|
+ String rowStr = questionRowStrings[i];
|
|
|
|
+ // 判断是否有图片
|
|
|
|
+ if (rowStr.startsWith("img")) {
|
|
|
|
+ rowStr = "<" + rowStr + ">";
|
|
|
|
+ Map<String, Object> param = new HashMap<>();
|
|
|
|
+ // 需要继续做截取,取到Parma
|
|
|
|
+ block.setType("image");
|
|
|
|
+ // 获取图片的路径
|
|
|
|
+ List<String> strSrcList = getImg(rowStr, "src");
|
|
|
|
+ if (strSrcList.size() > 0) {
|
|
|
|
+ String strSrc = strSrcList.get(0).replaceAll("src=\"", "").replaceAll("\"", "");
|
|
|
|
+ block.setValue(strSrc);
|
|
|
|
+ }
|
|
|
|
+ // 获取图片的高度
|
|
|
|
+ List<String> strHeightList = getImg(rowStr, "height");
|
|
|
|
+ if (strHeightList.size() > 0) {
|
|
|
|
+ String strHeight = strHeightList.get(0).replaceAll("height=\"", "").replaceAll("\"", "");
|
|
|
|
+ param.put("height", strHeight);
|
|
|
|
+ }
|
|
|
|
+ // 获取图片的宽度
|
|
|
|
+ List<String> strWidthList = getImg(rowStr, "width");
|
|
|
|
+ if (strHeightList.size() > 0) {
|
|
|
|
+ String strWidth = strWidthList.get(0).replaceAll("width=\"", "").replaceAll("\"", "");
|
|
|
|
+ param.put("width", strWidth);
|
|
|
|
+ }
|
|
|
|
+ block.setParam(param);
|
|
|
|
+ blocks.add(block);
|
|
|
|
+ } else if (rowStr.startsWith("a") && rowStr.contains("id") && rowStr.contains("name")) { // 处理音频
|
|
|
|
+ rowStr = "<" + rowStr + ">";
|
|
|
|
+ block.setType("audio");
|
|
|
|
+ String id=CommonUtils.getAttrValue(rowStr, "id");
|
|
|
|
+ QuestionAudio questionAudio = Model.of(questionAudioRepo.findById(id));
|
|
|
|
+ block.setValue(questionAudio.getId() + "."+ questionAudio.getFileSuffixes());
|
|
|
|
+ blocks.add(block);
|
|
|
|
+ hasAudio = true;
|
|
|
|
+ } else {
|
|
|
|
+ rowStr = rowStr.replace(" ", "");// 消除空格
|
|
|
|
+ rowStr = rowStr.replace(""", "\"");// 将"转换成\"
|
|
|
|
+ rowStr = rowStr.replace("<", "<");// 将<转换成<
|
|
|
|
+ rowStr = rowStr.replace(">", ">");// 将>转换成>
|
|
|
|
+ rowStr = rowStr.replace("&", "&");// 将&转换成&
|
|
|
|
+
|
|
|
|
+ String regex = "###";
|
|
|
|
+
|
|
|
|
+ Pattern pattern = Pattern.compile(regex);
|
|
|
|
+ Matcher matcher = pattern.matcher(rowStr);
|
|
|
|
+ int indexStart=0;
|
|
|
|
+ // 使用find()方法查找匹配项
|
|
|
|
+ while (matcher.find()) {
|
|
|
|
+ blankIndex++;
|
|
|
|
+ String content=rowStr.substring(indexStart, matcher.start());
|
|
|
|
+ if(StringUtils.isNotEmpty(content)) {
|
|
|
|
+ ThemisBlock temblock = new ThemisBlock();
|
|
|
|
+ temblock.setType("text");
|
|
|
|
+ temblock.setValue(content);
|
|
|
|
+ blocks.add(temblock);
|
|
|
|
+ }
|
|
|
|
+ ThemisBlock blankblock = new ThemisBlock();
|
|
|
|
+ blankblock.setType("cloze");
|
|
|
|
+ blankblock.setValue(blankIndex);
|
|
|
|
+ blocks.add(blankblock);
|
|
|
|
+ indexStart=matcher.start()+regex.length();
|
|
|
|
+ }
|
|
|
|
+ if(indexStart<rowStr.length()) {
|
|
|
|
+ // 输出最后一个分隔符之后的字符串
|
|
|
|
+ String content=rowStr.substring(indexStart, rowStr.length());
|
|
|
|
+ if(StringUtils.isNotEmpty(content)) {
|
|
|
|
+ ThemisBlock temblock = new ThemisBlock();
|
|
|
|
+ temblock.setType("text");
|
|
|
|
+ temblock.setValue(content);
|
|
|
|
+ blocks.add(temblock);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ if (hasAudio) {
|
|
|
|
+ computerTestPaper.setHasAudio(hasAudio);
|
|
|
|
+ }
|
|
|
|
+ return blocks;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
|
|
private List<ThemisBlock> disposeQuestionBodyOrOption(String questionRow, ThemisPaper computerTestPaper) {
|
|
private List<ThemisBlock> disposeQuestionBodyOrOption(String questionRow, ThemisPaper computerTestPaper) {
|
|
List<ThemisBlock> blocks = new ArrayList<>();
|
|
List<ThemisBlock> blocks = new ArrayList<>();
|