|
@@ -33,39 +33,29 @@ import java.util.regex.Pattern;
|
|
|
public class CqdxService {
|
|
|
private static final Logger log = LoggerFactory.getLogger(CqdxService.class);
|
|
|
final Long rootOrgId = 1407L;
|
|
|
- final String rootDir = "D:/paper";
|
|
|
-
|
|
|
+ final String rootDir = "D:/paper/cqu/temps";
|
|
|
@Autowired
|
|
|
- CourseService courseService;
|
|
|
-
|
|
|
- public void test() {
|
|
|
-
|
|
|
- System.out.println("wwh");
|
|
|
- }
|
|
|
-
|
|
|
+ private CourseService courseService;
|
|
|
@Autowired
|
|
|
private QuesRepo quesRepo;
|
|
|
-
|
|
|
@Autowired
|
|
|
private PaperRepo paperRepo;
|
|
|
-
|
|
|
@Autowired
|
|
|
private PaperDetailRepo paperDetailRepo;
|
|
|
-
|
|
|
@Autowired
|
|
|
private PaperDetailUnitRepo paperDetailUnitRepo;
|
|
|
-
|
|
|
@Autowired
|
|
|
private QuesPkgPathRepo quesPkgPathRepo;
|
|
|
|
|
|
public void bulidPaper() throws Exception {
|
|
|
// 获取所有xml的路径
|
|
|
- List<String> files = filePath();
|
|
|
+ List<String> files = this.loadFiles();
|
|
|
+
|
|
|
int i = 1;
|
|
|
- System.out.println("总文件个数:" + files.size());
|
|
|
+ System.out.println("XML的文件数:" + files.size());
|
|
|
for (String filePath : files) {
|
|
|
System.out.println("第" + i + "个xml文件开始处理,文件名为:" + filePath);
|
|
|
- Map<Object, Object> paperInfoMap = readXml(filePath);
|
|
|
+ Map<Object, Object> paperInfoMap = this.readXml(filePath);
|
|
|
// 查询课程
|
|
|
Course course = courseService.getCourse(rootOrgId, paperInfoMap.get("courseCode").toString());
|
|
|
// 初始化试卷
|
|
@@ -73,30 +63,30 @@ public class CqdxService {
|
|
|
// 大题集合
|
|
|
List<PaperDetail> paperDetails = initPaperDetails(paperInfoMap, paper);
|
|
|
// 试题---资源 对应关系
|
|
|
- Map<Question, QuestionPkgPath> map2 = new HashMap<Question, QuestionPkgPath>();
|
|
|
+ Map<Question, QuestionPkgPath> map2 = new HashMap<>();
|
|
|
+
|
|
|
// 定义小题集合
|
|
|
- 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;
|
|
|
- }*/
|
|
|
+ List<PaperDetailUnit> paperDetailUnits;
|
|
|
+ try {
|
|
|
+ paperDetailUnits = initpaperDetailUnits(paper, paperDetails, map2, paperInfoMap, course);
|
|
|
+ if (paperDetailUnits == null) {
|
|
|
+ System.out.println("有问题的xml:" + filePath);
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ System.out.println("有问题的xml:" + filePath);
|
|
|
+ continue;
|
|
|
+ }
|
|
|
|
|
|
// 保存试题资源
|
|
|
- quesPkgPathRepo.saveAll(map2.values());
|
|
|
+ /*quesPkgPathRepo.saveAll(map2.values());
|
|
|
for (Map.Entry<Question, QuestionPkgPath> entry : map2.entrySet()) {
|
|
|
entry.getKey().setQuesPkgPathId(entry.getValue().getId());
|
|
|
}
|
|
|
quesRepo.saveAll(map2.keySet());
|
|
|
paperRepo.save(paper);
|
|
|
paperDetailRepo.saveAll(paperDetails);
|
|
|
- paperDetailUnitRepo.saveAll(paperDetailUnits);
|
|
|
+ paperDetailUnitRepo.saveAll(paperDetailUnits);*/
|
|
|
|
|
|
// 将正常文件移动到新目录
|
|
|
/*File okFile = new File(rootDir + "/" + filePath);
|
|
@@ -595,18 +585,30 @@ public class CqdxService {
|
|
|
return str.replace(s.toString(), url);
|
|
|
}
|
|
|
|
|
|
- // 获取所有xml的路径
|
|
|
- public List<String> filePath() {
|
|
|
- List<String> files = new ArrayList<String>();
|
|
|
- File file = new File(rootDir);
|
|
|
- File[] fileList = file.listFiles();
|
|
|
- for (int i = 0; i < fileList.length; i++) {
|
|
|
- if (fileList[i].isFile()) {
|
|
|
- String fileName = fileList[i].getName();
|
|
|
- files.add(rootDir + "/" + fileName);
|
|
|
+ public List<String> loadFiles() {
|
|
|
+ // 获取某文件夹下所有XML文件的路径
|
|
|
+ List<String> paths = new ArrayList<>();
|
|
|
+ File dir = new File(rootDir);
|
|
|
+ this.loadMoreFiles(dir, paths);
|
|
|
+ return paths;
|
|
|
+ }
|
|
|
+
|
|
|
+ private void loadMoreFiles(File file, List<String> paths) {
|
|
|
+ if (file.isDirectory()) {
|
|
|
+ File[] subFiles = file.listFiles();
|
|
|
+ for (File subFile : subFiles) {
|
|
|
+ this.loadMoreFiles(subFile, paths);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ String path = file.getPath()
|
|
|
+ .replaceAll("\\\\", "/");
|
|
|
+
|
|
|
+ if (file.getName().endsWith(".xml")) {
|
|
|
+ paths.add(path);
|
|
|
+ } else {
|
|
|
+ System.out.println("无效文件:" + path);
|
|
|
}
|
|
|
}
|
|
|
- return files;
|
|
|
}
|
|
|
|
|
|
public static List<String> parseSpans(String content) {
|