|
@@ -72,10 +72,12 @@ public class CqdxService {
|
|
|
public void bulidPaper() throws Exception {
|
|
|
// 获取所有xml的路径
|
|
|
List<String> files = filePath();
|
|
|
+ int i = 1;
|
|
|
+ System.out.println("总文件个数:"+files.size());
|
|
|
for (String file : files) {
|
|
|
Map<Object, Object> paperInfoMap = readXml(file);
|
|
|
// 查询课程
|
|
|
- Course course = courseService.getCourse(7l, "00004");
|
|
|
+ Course course = courseService.getCourse(1407l, paperInfoMap.get("courseCode").toString());
|
|
|
// 初始化试卷
|
|
|
Paper paper = initPaper(paperInfoMap, course);
|
|
|
// 大题集合
|
|
@@ -84,6 +86,17 @@ public class CqdxService {
|
|
|
Map<Question, QuestionPkgPath> map2 = new HashMap<Question, QuestionPkgPath>();
|
|
|
// 定义小题集合
|
|
|
List<PaperDetailUnit> paperDetailUnits = initpaperDetailUnits(paper, paperDetails, map2, paperInfoMap, course);
|
|
|
+ /*List<PaperDetailUnit> paperDetailUnits = new ArrayList<PaperDetailUnit>();
|
|
|
+ try {
|
|
|
+ paperDetailUnits = initpaperDetailUnits(paper, paperDetails, map2, paperInfoMap, course);
|
|
|
+ if(paperDetailUnits == null){
|
|
|
+ System.out.println("有问题的xml:"+file);
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ System.out.println("有问题的xml:"+file);
|
|
|
+ continue;
|
|
|
+ }*/
|
|
|
// 保存试题资源
|
|
|
quesPkgPathRepo.save(map2.values());
|
|
|
for (Map.Entry<Question, QuestionPkgPath> entry : map2.entrySet()) {
|
|
@@ -93,6 +106,8 @@ public class CqdxService {
|
|
|
paperRepo.save(paper);
|
|
|
paperDetailRepo.save(paperDetails);
|
|
|
paperDetailUnitRepo.save(paperDetailUnits);
|
|
|
+ System.out.println("第"+i+"个xml文件已经处理完,文件名为:"+file);
|
|
|
+ i++;
|
|
|
}
|
|
|
System.out.println("保存成功...");
|
|
|
}
|
|
@@ -336,6 +351,7 @@ public class CqdxService {
|
|
|
Map<Object, Object> paperInfoMap, Course course) throws Exception {
|
|
|
List<PaperDetailUnit> paperDetailUnits = new ArrayList<PaperDetailUnit>();
|
|
|
int detailCount = paperDetails.size();
|
|
|
+ int nm = 0;
|
|
|
for (int i = 0; i < detailCount; i++) {
|
|
|
PaperDetail detail = paperDetails.get(i);
|
|
|
QuestionsTemp detailTemp = (QuestionsTemp) paperInfoMap.get(String
|
|
@@ -358,13 +374,22 @@ public class CqdxService {
|
|
|
question.setPublicity(true);
|
|
|
question.setQuestionType(quesTemp.getType());
|
|
|
question.setQuesBody(imgList(quesTemp.getBody()));
|
|
|
- question.setQuesBodyWord(DocxProcessUtil.html2Docx(wordMLPackage,CommonUtils.formatHtml(question.getQuesBody())));
|
|
|
+ try {
|
|
|
+ question.setQuesBodyWord(DocxProcessUtil.html2Docx(wordMLPackage,CommonUtils.formatHtml(question.getQuesBody())));
|
|
|
+ } catch (Exception e) {
|
|
|
+ System.out.println("错误题干信息:"+question.getQuesBody());
|
|
|
+ }
|
|
|
if(question.getQuestionType() == QuesStructType.BOOL_ANSWER_QUESTION){
|
|
|
question.setQuesAnswer(quesTemp.getAnswer());
|
|
|
question.setQuesAnswerWord(DocxProcessUtil.html2Docx(wordMLPackage,CommonUtils.formatHtml("<p>"+question.getQuesAnswer()+"</p>")));
|
|
|
}else {
|
|
|
question.setQuesAnswer(imgList(quesTemp.getAnswer()));
|
|
|
- question.setQuesAnswerWord(DocxProcessUtil.html2Docx(wordMLPackage,CommonUtils.formatHtml(question.getQuesAnswer())));
|
|
|
+ try {
|
|
|
+ question.setQuesAnswerWord(DocxProcessUtil.html2Docx(wordMLPackage,CommonUtils.formatHtml(question.getQuesAnswer())));
|
|
|
+ } catch (Exception e) {
|
|
|
+ System.out.println("错误题干信息:"+question.getQuesAnswer());
|
|
|
+ return null;
|
|
|
+ }
|
|
|
}
|
|
|
// 存在选项
|
|
|
if (question.getQuestionType() == QuesStructType.SINGLE_ANSWER_QUESTION
|
|
@@ -376,7 +401,11 @@ public class CqdxService {
|
|
|
QuesOption quesOption = new QuesOption();
|
|
|
quesOption.setNumber(String.valueOf(k + 1));
|
|
|
quesOption.setOptionBody(imgList((String) optionMap.get(String.valueOf(k + 1))));
|
|
|
- quesOption.setOptionBodyWord(DocxProcessUtil.html2Docx(wordMLPackage, CommonUtils.formatHtml(quesOption.getOptionBody())));
|
|
|
+ try {
|
|
|
+ quesOption.setOptionBodyWord(DocxProcessUtil.html2Docx(wordMLPackage, CommonUtils.formatHtml(quesOption.getOptionBody())));
|
|
|
+ } catch (Exception e) {
|
|
|
+ System.out.println("错误的选项:"+quesOption.getOptionBody());
|
|
|
+ }
|
|
|
if (question.getQuesAnswer().contains(String.valueOf(k+1))) {
|
|
|
quesOption.setIsCorrect((short) 1);
|
|
|
} else {
|
|
@@ -466,7 +495,7 @@ public class CqdxService {
|
|
|
// 包装小题
|
|
|
PaperDetailUnit paperDetailUnit = new PaperDetailUnit();
|
|
|
paperDetailUnit.setPaper(paper);
|
|
|
- paperDetailUnit.setNumber(j + 1);
|
|
|
+ paperDetailUnit.setNumber(nm + 1);
|
|
|
paperDetailUnit.setScore(question.getScore());
|
|
|
paperDetailUnit.setPaperDetail(detail);
|
|
|
paperDetailUnit.setQuestionType(question.getQuestionType());
|
|
@@ -474,6 +503,7 @@ public class CqdxService {
|
|
|
paperDetailUnit.setCreateTime(CommonUtils.getCurDateTime());
|
|
|
paperDetailUnit.setQuestion(question);
|
|
|
paperDetailUnits.add(paperDetailUnit);
|
|
|
+ nm++;
|
|
|
}
|
|
|
}
|
|
|
return paperDetailUnits;
|
|
@@ -483,17 +513,18 @@ public class CqdxService {
|
|
|
if (StringUtils.isBlank(str)) {
|
|
|
str = "<p></p>";
|
|
|
}
|
|
|
- str = str.trim().replace("<br>", "");
|
|
|
- if (!str.contains("<p>") && !str.contains("<P>")) {
|
|
|
+ str = str.trim().replace("<br>", "").replace("</br>", "");
|
|
|
+ if (!str.contains("<p>") && !str.contains("</P>")) {
|
|
|
str = "<p>" + str + "</p>";
|
|
|
}
|
|
|
//先处理span标签
|
|
|
List<String> spans = parseSpans(str);
|
|
|
if(spans != null && spans.size() > 0){
|
|
|
for(String span:spans){
|
|
|
- str = str.replace(span, "").replace("</span>", "");
|
|
|
+ str = str.replace(span, "").replace("</span>", "").replace("</SPAN>", "");
|
|
|
}
|
|
|
}
|
|
|
+ str = str.replace("<o:p>", "").replace("</o:p>", "").replace("border=0", "").replace("class=MsoNormal", "").replace("ϕ", "").replace("</SPAN>", "");
|
|
|
// 获取img标签
|
|
|
List<String> srcList = ImgDataUtils.parseImages(str);
|
|
|
if (srcList != null && srcList.size() > 0) {
|
|
@@ -504,7 +535,7 @@ public class CqdxService {
|
|
|
List<String> parseImageSrc = ImgDataUtils.parseImageSrc(img);
|
|
|
if (parseImageSrc != null && parseImageSrc.size() > 0) {
|
|
|
String src = parseImageSrc.get(0).replace("{ResourcePath}",
|
|
|
- "http://file.5any.com/estudy");
|
|
|
+ "http://file.5any.com/UniversityV4.0");
|
|
|
String url = regexCH(src);
|
|
|
String base64 = ImgDataUtils.loadImageToBase64(url);
|
|
|
if (base64 == null) {
|