|
@@ -1,5 +1,6 @@
|
|
|
package com.qmth.cqb.paper.service.impl;
|
|
|
|
|
|
+
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.Collections;
|
|
|
import java.util.HashMap;
|
|
@@ -10,10 +11,8 @@ import java.util.Random;
|
|
|
import java.util.Set;
|
|
|
|
|
|
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
+import java.util.regex.Matcher;
|
|
|
+import java.util.regex.Pattern;
|
|
|
|
|
|
import com.qmth.cqb.base.dao.CourseRepo;
|
|
|
import com.qmth.cqb.base.model.Course;
|
|
@@ -616,22 +615,37 @@ public class ExtractConfigServiceImpl implements ExtractConfigService {
|
|
|
|
|
|
//给题目和选项添加url
|
|
|
public String buildBody(String body,QuestionDto questionDto){
|
|
|
- String[] bodys = body.split("<a");
|
|
|
- if(bodys.length>1){
|
|
|
- //取到文件名
|
|
|
- String[] bodyStrings = bodys[1].split("\"");
|
|
|
- String fileName = bodyStrings[1];
|
|
|
- //获取url
|
|
|
- QuestionAudio questionAudio = questionAudioRepo.findByQuestionIdAndFileName(questionDto.getId(), fileName);
|
|
|
- String url = downloadUrl + questionAudio.getFileUrl();
|
|
|
- //添加url
|
|
|
- String[] queStrings = body.split("></a>");
|
|
|
- return queStrings[0] + " " + "question-audio url=\"" + url + "\"" + "></a>" + queStrings[1];
|
|
|
- }else {
|
|
|
+ String[] bodyStrings = body.split("></a>");
|
|
|
+ if(bodyStrings.length>1){
|
|
|
+ String resultBody = "";
|
|
|
+ for(int i = 0;i<bodyStrings.length;i++){
|
|
|
+ String containAStr = bodyStrings[i];
|
|
|
+ if(containAStr.indexOf("<a")>-1){
|
|
|
+ String fileName = matchAudioName(containAStr, "a", "id");
|
|
|
+ QuestionAudio questionAudio = questionAudioRepo.findByQuestionIdAndFileName(questionDto.getId(),fileName);
|
|
|
+ String url = downloadUrl + questionAudio.getFileUrl();
|
|
|
+ if(questionDto.getPlayTime()!=null){
|
|
|
+ containAStr += " question-audio url=\""+url+"\" playTime=\""+questionDto.getPlayTime()+"\""+"></a>";
|
|
|
+ }else{
|
|
|
+ containAStr += " question-audio url=\""+url+"\""+"></a>";
|
|
|
+ }
|
|
|
+ }
|
|
|
+ resultBody+=containAStr;
|
|
|
+ }
|
|
|
+ return resultBody;
|
|
|
+ }else{
|
|
|
return body;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ private String matchAudioName(String source, String element, String attr) {
|
|
|
+ String reg = "<" + element + "[^<>]*?\\s" + attr + "=['\"]?(.*?)['\"]?(\\s.*?)";
|
|
|
+ Matcher m = Pattern.compile(reg).matcher(source);
|
|
|
+ while (m.find()) {
|
|
|
+ return m.group(1);
|
|
|
+ }
|
|
|
+ return "";
|
|
|
+ }
|
|
|
|
|
|
/**
|
|
|
* 重新对选择题option进行排序(多选、单选、套题下选择题)
|
|
@@ -707,5 +721,5 @@ public class ExtractConfigServiceImpl implements ExtractConfigService {
|
|
|
}
|
|
|
return new PageImpl<ExtractConfig>(extractConfigs,new PageRequest(currentPage,pageSize),pageExamCourse.getTotalElements());
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
}
|