|
@@ -11,6 +11,8 @@ import cn.com.qmth.examcloud.core.questions.service.impl.CourseService;
|
|
import org.apache.commons.collections4.map.HashedMap;
|
|
import org.apache.commons.collections4.map.HashedMap;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
import org.docx4j.openpackaging.packages.WordprocessingMLPackage;
|
|
import org.docx4j.openpackaging.packages.WordprocessingMLPackage;
|
|
|
|
+import org.slf4j.Logger;
|
|
|
|
+import org.slf4j.LoggerFactory;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.stereotype.Component;
|
|
import org.springframework.stereotype.Component;
|
|
import org.w3c.dom.Document;
|
|
import org.w3c.dom.Document;
|
|
@@ -29,6 +31,9 @@ import java.util.regex.Pattern;
|
|
|
|
|
|
@Component
|
|
@Component
|
|
public class CqdxService {
|
|
public class CqdxService {
|
|
|
|
+ private static final Logger log = LoggerFactory.getLogger(CqdxService.class);
|
|
|
|
+ final Long rootOrgId = 1407L;
|
|
|
|
+ final String rootDir = "D:/paper";
|
|
|
|
|
|
@Autowired
|
|
@Autowired
|
|
CourseService courseService;
|
|
CourseService courseService;
|
|
@@ -58,10 +63,11 @@ public class CqdxService {
|
|
List<String> files = filePath();
|
|
List<String> files = filePath();
|
|
int i = 1;
|
|
int i = 1;
|
|
System.out.println("总文件个数:" + files.size());
|
|
System.out.println("总文件个数:" + files.size());
|
|
- for (String file : files) {
|
|
|
|
- Map<Object, Object> paperInfoMap = readXml(file);
|
|
|
|
|
|
+ for (String filePath : files) {
|
|
|
|
+ System.out.println("第" + i + "个xml文件开始处理,文件名为:" + filePath);
|
|
|
|
+ Map<Object, Object> paperInfoMap = readXml(filePath);
|
|
// 查询课程
|
|
// 查询课程
|
|
- Course course = courseService.getCourse(1407l, paperInfoMap.get("courseCode").toString());
|
|
|
|
|
|
+ Course course = courseService.getCourse(rootOrgId, paperInfoMap.get("courseCode").toString());
|
|
// 初始化试卷
|
|
// 初始化试卷
|
|
Paper paper = initPaper(paperInfoMap, course);
|
|
Paper paper = initPaper(paperInfoMap, course);
|
|
// 大题集合
|
|
// 大题集合
|
|
@@ -81,6 +87,7 @@ public class CqdxService {
|
|
System.out.println("有问题的xml:"+file);
|
|
System.out.println("有问题的xml:"+file);
|
|
continue;
|
|
continue;
|
|
}*/
|
|
}*/
|
|
|
|
+
|
|
// 保存试题资源
|
|
// 保存试题资源
|
|
quesPkgPathRepo.save(map2.values());
|
|
quesPkgPathRepo.save(map2.values());
|
|
for (Map.Entry<Question, QuestionPkgPath> entry : map2.entrySet()) {
|
|
for (Map.Entry<Question, QuestionPkgPath> entry : map2.entrySet()) {
|
|
@@ -90,7 +97,14 @@ public class CqdxService {
|
|
paperRepo.save(paper);
|
|
paperRepo.save(paper);
|
|
paperDetailRepo.save(paperDetails);
|
|
paperDetailRepo.save(paperDetails);
|
|
paperDetailUnitRepo.save(paperDetailUnits);
|
|
paperDetailUnitRepo.save(paperDetailUnits);
|
|
- System.out.println("第" + i + "个xml文件已经处理完,文件名为:" + file);
|
|
|
|
|
|
+
|
|
|
|
+ // 将正常文件移动到新目录
|
|
|
|
+ /*File okFile = new File(rootDir + "/" + filePath);
|
|
|
|
+ String newFilePath = rootDir + "/ok/" + okFile.getName();
|
|
|
|
+ File newFile = new File(newFilePath);
|
|
|
|
+ okFile.renameTo(newFile);*/
|
|
|
|
+
|
|
|
|
+ System.out.println("第" + i + "个xml文件已经处理完,文件名为:" + filePath);
|
|
i++;
|
|
i++;
|
|
}
|
|
}
|
|
System.out.println("保存成功...");
|
|
System.out.println("保存成功...");
|
|
@@ -134,7 +148,7 @@ public class CqdxService {
|
|
paperDetail.setName(detailInfo.getName());
|
|
paperDetail.setName(detailInfo.getName());
|
|
paperDetail.setScore(Double.valueOf(detailInfo.getTotalScore()));
|
|
paperDetail.setScore(Double.valueOf(detailInfo.getTotalScore()));
|
|
paperDetail.setUnitCount(Integer.valueOf(detailInfo.getCount()));
|
|
paperDetail.setUnitCount(Integer.valueOf(detailInfo.getCount()));
|
|
- paperDetail.setCreator("wei");
|
|
|
|
|
|
+ paperDetail.setCreator("feng");
|
|
paperDetail.setCreateTime(CommonUtils.getCurDateTime());
|
|
paperDetail.setCreateTime(CommonUtils.getCurDateTime());
|
|
paperDetails.add(paperDetail);
|
|
paperDetails.add(paperDetail);
|
|
}
|
|
}
|
|
@@ -362,6 +376,7 @@ public class CqdxService {
|
|
question.setQuesBodyWord(DocxProcessUtil.html2Docx(wordMLPackage, CommonUtils.formatHtml(question.getQuesBody())));
|
|
question.setQuesBodyWord(DocxProcessUtil.html2Docx(wordMLPackage, CommonUtils.formatHtml(question.getQuesBody())));
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
System.out.println("错误题干信息:" + question.getQuesBody());
|
|
System.out.println("错误题干信息:" + question.getQuesBody());
|
|
|
|
+ throw new IllegalArgumentException("题干信息错误!");
|
|
}
|
|
}
|
|
if (question.getQuestionType() == QuesStructType.BOOL_ANSWER_QUESTION) {
|
|
if (question.getQuestionType() == QuesStructType.BOOL_ANSWER_QUESTION) {
|
|
question.setQuesAnswer(quesTemp.getAnswer());
|
|
question.setQuesAnswer(quesTemp.getAnswer());
|
|
@@ -372,7 +387,7 @@ public class CqdxService {
|
|
question.setQuesAnswerWord(DocxProcessUtil.html2Docx(wordMLPackage, CommonUtils.formatHtml(question.getQuesAnswer())));
|
|
question.setQuesAnswerWord(DocxProcessUtil.html2Docx(wordMLPackage, CommonUtils.formatHtml(question.getQuesAnswer())));
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
System.out.println("错误题干信息:" + question.getQuesAnswer());
|
|
System.out.println("错误题干信息:" + question.getQuesAnswer());
|
|
- return null;
|
|
|
|
|
|
+ throw new IllegalArgumentException("题干信息错误!");
|
|
}
|
|
}
|
|
}
|
|
}
|
|
// 存在选项
|
|
// 存在选项
|
|
@@ -483,7 +498,7 @@ public class CqdxService {
|
|
paperDetailUnit.setScore(question.getScore());
|
|
paperDetailUnit.setScore(question.getScore());
|
|
paperDetailUnit.setPaperDetail(detail);
|
|
paperDetailUnit.setPaperDetail(detail);
|
|
paperDetailUnit.setQuestionType(question.getQuestionType());
|
|
paperDetailUnit.setQuestionType(question.getQuestionType());
|
|
- paperDetailUnit.setCreator("wei");
|
|
|
|
|
|
+ paperDetailUnit.setCreator("feng");
|
|
paperDetailUnit.setCreateTime(CommonUtils.getCurDateTime());
|
|
paperDetailUnit.setCreateTime(CommonUtils.getCurDateTime());
|
|
paperDetailUnit.setQuestion(question);
|
|
paperDetailUnit.setQuestion(question);
|
|
paperDetailUnits.add(paperDetailUnit);
|
|
paperDetailUnits.add(paperDetailUnit);
|
|
@@ -521,6 +536,7 @@ public class CqdxService {
|
|
String src = parseImageSrc.get(0).replace("{ResourcePath}",
|
|
String src = parseImageSrc.get(0).replace("{ResourcePath}",
|
|
"http://file.5any.com/UniversityV4.0");
|
|
"http://file.5any.com/UniversityV4.0");
|
|
String url = regexCH(src);
|
|
String url = regexCH(src);
|
|
|
|
+ log.info("img url:" + url);
|
|
String base64 = ImgDataUtils.loadImageToBase64(url);
|
|
String base64 = ImgDataUtils.loadImageToBase64(url);
|
|
if (base64 == null) {
|
|
if (base64 == null) {
|
|
throw new Exception("图片下载失败" + url);
|
|
throw new Exception("图片下载失败" + url);
|
|
@@ -562,12 +578,12 @@ public class CqdxService {
|
|
// 获取所有xml的路径
|
|
// 获取所有xml的路径
|
|
public List<String> filePath() {
|
|
public List<String> filePath() {
|
|
List<String> files = new ArrayList<String>();
|
|
List<String> files = new ArrayList<String>();
|
|
- File file = new File("D:\\paper");
|
|
|
|
|
|
+ File file = new File(rootDir);
|
|
File[] fileList = file.listFiles();
|
|
File[] fileList = file.listFiles();
|
|
for (int i = 0; i < fileList.length; i++) {
|
|
for (int i = 0; i < fileList.length; i++) {
|
|
if (fileList[i].isFile()) {
|
|
if (fileList[i].isFile()) {
|
|
String fileName = fileList[i].getName();
|
|
String fileName = fileList[i].getName();
|
|
- files.add("file:///D:\\paper\\" + fileName);
|
|
|
|
|
|
+ files.add(rootDir + "/" + fileName);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return files;
|
|
return files;
|