|
@@ -1,38 +1,46 @@
|
|
|
package cn.com.qmth.examcloud.exchange.outer.api.provider;
|
|
|
|
|
|
import cn.com.qmth.examcloud.commons.exception.StatusException;
|
|
|
-import cn.com.qmth.examcloud.commons.util.StringUtil;
|
|
|
-import cn.com.qmth.examcloud.core.oe.admin.api.ExamScoreObtainQueueCloudService;
|
|
|
-import cn.com.qmth.examcloud.core.oe.admin.api.request.DeleteExamScoreQueueReq;
|
|
|
-import cn.com.qmth.examcloud.core.oe.admin.api.request.GetTopExamScoreQueueReq;
|
|
|
-import cn.com.qmth.examcloud.core.oe.admin.api.response.GetTopExamScoreQueueResp;
|
|
|
-import cn.com.qmth.examcloud.examwork.api.ExamCloudService;
|
|
|
-import cn.com.qmth.examcloud.examwork.api.bean.ExamBean;
|
|
|
-import cn.com.qmth.examcloud.examwork.api.request.GetExamReq;
|
|
|
-import cn.com.qmth.examcloud.examwork.api.response.GetExamResp;
|
|
|
+import cn.com.qmth.examcloud.commons.util.RegExpUtil;
|
|
|
+import cn.com.qmth.examcloud.core.oe.admin.api.ExamRecordCloudService;
|
|
|
+import cn.com.qmth.examcloud.core.oe.admin.api.bean.PagedToBeMarkExamRecordBean;
|
|
|
+import cn.com.qmth.examcloud.core.oe.admin.api.bean.PagedToBeMarkSubjectiveAnswerBean;
|
|
|
+import cn.com.qmth.examcloud.core.oe.admin.api.request.GetPagedToBeMarkExamRecordReq;
|
|
|
+import cn.com.qmth.examcloud.core.oe.admin.api.response.GetPagedToBeMarkExamRecordResp;
|
|
|
import cn.com.qmth.examcloud.exchange.outer.api.ExamQuestionOuterService;
|
|
|
-import cn.com.qmth.examcloud.exchange.outer.api.ScoreQueueService;
|
|
|
-import cn.com.qmth.examcloud.exchange.outer.api.request.OuterDeleteScoreQueueTopReq;
|
|
|
-import cn.com.qmth.examcloud.exchange.outer.api.request.OuterGetScoreQueueTopReq;
|
|
|
+import cn.com.qmth.examcloud.exchange.outer.api.bean.*;
|
|
|
import cn.com.qmth.examcloud.exchange.outer.api.request.OuterGetSubjectivePaperStructReq;
|
|
|
import cn.com.qmth.examcloud.exchange.outer.api.request.OuterGetSubjectiveQuestionReq;
|
|
|
-import cn.com.qmth.examcloud.exchange.outer.api.response.OuterDeleteScoreQueueTopResp;
|
|
|
import cn.com.qmth.examcloud.exchange.outer.api.response.OuterGetScoreQueueTopResp;
|
|
|
import cn.com.qmth.examcloud.exchange.outer.api.response.OuterGetSubjectivePaperStructResp;
|
|
|
import cn.com.qmth.examcloud.exchange.outer.api.response.OuterGetSubjectiveQuestionResp;
|
|
|
+import cn.com.qmth.examcloud.question.commons.core.question.AnswerType;
|
|
|
+import cn.com.qmth.examcloud.question.commons.core.question.QuestionType;
|
|
|
+import cn.com.qmth.examcloud.support.helper.ExamCacheTransferHelper;
|
|
|
import cn.com.qmth.examcloud.web.support.ControllerSupport;
|
|
|
import cn.com.qmth.examcloud.web.support.StatusResponse;
|
|
|
+import com.google.common.collect.Maps;
|
|
|
import com.mysql.cj.util.StringUtils;
|
|
|
import io.swagger.annotations.Api;
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
import io.swagger.annotations.ApiResponse;
|
|
|
import io.swagger.annotations.ApiResponses;
|
|
|
+import org.jsoup.Jsoup;
|
|
|
+import org.jsoup.nodes.Document;
|
|
|
+import org.jsoup.nodes.Element;
|
|
|
+import org.jsoup.select.Elements;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.web.bind.annotation.PostMapping;
|
|
|
-import org.springframework.web.bind.annotation.RequestBody;
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.regex.Matcher;
|
|
|
+import java.util.regex.Pattern;
|
|
|
+
|
|
|
/**
|
|
|
* @Description 考试作答服务
|
|
|
* @Author lideyin
|
|
@@ -46,6 +54,9 @@ public class ExamQuestionOuterServiceProvider extends ControllerSupport implemen
|
|
|
|
|
|
private static final long serialVersionUID = 7607495598308348018L;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ ExamRecordCloudService examRecordCloudService;
|
|
|
+
|
|
|
/**
|
|
|
* 获取主观题试卷结构
|
|
|
*
|
|
@@ -67,24 +78,412 @@ public class ExamQuestionOuterServiceProvider extends ControllerSupport implemen
|
|
|
@PostMapping("/getSubjectiveQuestion")
|
|
|
@Override
|
|
|
public OuterGetSubjectiveQuestionResp getSubjectiveQuestion(OuterGetSubjectiveQuestionReq req) {
|
|
|
- if (null == req.getExamId()) {
|
|
|
+ Long examId = req.getExamId();
|
|
|
+ if (null == examId) {
|
|
|
throw new StatusException("101001", "考试id不允许为空");
|
|
|
}
|
|
|
|
|
|
- if (StringUtils.isNullOrEmpty(req.getSubjectCode())) {
|
|
|
+ String subjectCode = req.getSubjectCode();
|
|
|
+ if (StringUtils.isNullOrEmpty(subjectCode)) {
|
|
|
throw new StatusException("101002", "科目代码不允许为空");
|
|
|
}
|
|
|
|
|
|
- if (null == req.getStartId()) {
|
|
|
- throw new StatusException("101003", "考试记录id不允许为空");
|
|
|
+ Long startId = req.getStartId();
|
|
|
+ if (null == startId) {
|
|
|
+ throw new StatusException("101003", "考生id不允许为空");
|
|
|
}
|
|
|
|
|
|
- if (null == req.getSize()) {
|
|
|
+ Integer size = req.getSize();
|
|
|
+ if (null == size) {
|
|
|
throw new StatusException("101004", "数据量大小不允许为空");
|
|
|
}
|
|
|
|
|
|
+ if (size.intValue() > 500) {
|
|
|
+ throw new StatusException("101005", "数据量最大不得超过500");
|
|
|
+ }
|
|
|
|
|
|
+ GetPagedToBeMarkExamRecordReq pagedReq = new GetPagedToBeMarkExamRecordReq();
|
|
|
+ pagedReq.setExamId(examId);
|
|
|
+ pagedReq.setSubjectCode(subjectCode);
|
|
|
+ pagedReq.setStartId(startId);
|
|
|
+ pagedReq.setSize(size);
|
|
|
+ GetPagedToBeMarkExamRecordResp pagedResp = examRecordCloudService.getPagedToBeMarkExamRecord(pagedReq);
|
|
|
|
|
|
- return null;
|
|
|
+ OuterGetSubjectiveQuestionResp resp = new OuterGetSubjectiveQuestionResp();
|
|
|
+ resp.setNextId(pagedResp.getNextId());
|
|
|
+ resp.setDataList(getOuterExamRecordBean(pagedResp.getToBeMarkExamRecordBeanList()));
|
|
|
+
|
|
|
+ return resp;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 构造满足条件的考试记录集合
|
|
|
+ *
|
|
|
+ * @param toBeMarkExamRecordBeanList
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private List<OuterExamRecordBean> getOuterExamRecordBean(List<PagedToBeMarkExamRecordBean> toBeMarkExamRecordBeanList) {
|
|
|
+ if (null == toBeMarkExamRecordBeanList || toBeMarkExamRecordBeanList.isEmpty()) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ List<OuterExamRecordBean> resultList = new ArrayList<>();
|
|
|
+ for (PagedToBeMarkExamRecordBean pb : toBeMarkExamRecordBeanList) {
|
|
|
+ OuterExamRecordBean resultBean = new OuterExamRecordBean();
|
|
|
+ resultBean.setExamId(pb.getExamId());
|
|
|
+ resultBean.setStudentCode(pb.getStudentCode());
|
|
|
+ resultBean.setName(pb.getStudentName());
|
|
|
+ resultBean.setCollege(pb.getGrade());
|
|
|
+ resultBean.setClassName(null);
|
|
|
+ resultBean.setTeacher(null);
|
|
|
+ resultBean.setSubjectCode(pb.getCourseCode());
|
|
|
+ resultBean.setSubjectName(pb.getCourseName());
|
|
|
+ resultBean.setExamNumber(String.valueOf(pb.getExamRecordDataId()));
|
|
|
+
|
|
|
+ resultBean.setSubjectives(getSubjectives(pb.getExamId(), pb.getSubjectiveAnswerList()));
|
|
|
+
|
|
|
+ resultList.add(resultBean);
|
|
|
+ }
|
|
|
+
|
|
|
+ return resultList;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 构造满足条件的主观题集合
|
|
|
+ *
|
|
|
+ * @param subjectiveAnswerList
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private List<OuterSubjectiveQuestionRecordBean> getSubjectives(Long examId,
|
|
|
+ List<PagedToBeMarkSubjectiveAnswerBean> subjectiveAnswerList) {
|
|
|
+ List<OuterSubjectiveQuestionRecordBean> resultList = new ArrayList<>();
|
|
|
+
|
|
|
+ for (PagedToBeMarkSubjectiveAnswerBean pb : subjectiveAnswerList) {
|
|
|
+ OuterSubjectiveQuestionRecordBean resultBean = new OuterSubjectiveQuestionRecordBean();
|
|
|
+ resultBean.setMainNumber(pb.getMainNumber());
|
|
|
+ resultBean.setSubNumber(pb.getOrder());
|
|
|
+ resultBean.setQuestionId(pb.getQuestionId());
|
|
|
+
|
|
|
+ resultBean.setAnswer(getFormattedAnswer(pb.getAnswer()));
|
|
|
+ resultBean.setStudentAnswer(
|
|
|
+ getFormattedStudentAnswer(pb.getStudentAnswer(), pb.getAnswerType(), pb.getQuestionType(), examId));
|
|
|
+ resultBean.setBody(getFormattedBody(pb.getBody()));
|
|
|
+ resultBean.setParentBody(getFormattedParentBody(pb.getParentBody()));
|
|
|
+
|
|
|
+ resultList.add(resultBean);
|
|
|
+ }
|
|
|
+
|
|
|
+ return resultList;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 格式化父题干
|
|
|
+ *
|
|
|
+ * @param parentBody
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private OuterSectionCollectionBean getFormattedParentBody(String parentBody) {
|
|
|
+ if (StringUtils.isNullOrEmpty(parentBody)) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ return getBodyOrAnswer(parentBody);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 格式化小题题干
|
|
|
+ *
|
|
|
+ * @param body
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private OuterSectionCollectionBean getFormattedBody(String body) {
|
|
|
+ if (StringUtils.isNullOrEmpty(body)) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ return getBodyOrAnswer(body);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 格式化学生答案
|
|
|
+ *
|
|
|
+ * @param studentAnswer
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private OuterSectionCollectionBean getFormattedStudentAnswer(String studentAnswer,
|
|
|
+ AnswerType answerType,
|
|
|
+ QuestionType questionType, Long examId) {
|
|
|
+ String transformedAnswerType = getTransformedAnswerType(answerType, questionType, examId);
|
|
|
+ String transformedStudentAnswer = getTransformedStudentAnswer(studentAnswer);
|
|
|
+
|
|
|
+ List<OuterSectionBean> sectionBeanList = new ArrayList<>();
|
|
|
+ List<OuterBlockBean> blockBeanList = new ArrayList<>();
|
|
|
+
|
|
|
+ //校验答案格式,校验成功才追加至集合,否则不追加
|
|
|
+ if (validateAnswer(transformedAnswerType, transformedStudentAnswer)) {
|
|
|
+ //图片文件特殊处理
|
|
|
+ if (!StringUtils.isNullOrEmpty(transformedStudentAnswer) && "image".equals(transformedAnswerType)) {
|
|
|
+ if (transformedStudentAnswer.indexOf("|") > -1) {
|
|
|
+
|
|
|
+ String[] imgAnswers = transformedStudentAnswer.split("\\|");
|
|
|
+
|
|
|
+ for (int i = 0; i < imgAnswers.length; i++) {
|
|
|
+ OuterBlockBean blockBean = new OuterBlockBean();
|
|
|
+ blockBean.setType(transformedAnswerType);
|
|
|
+ blockBean.setValue(getSimpleTransformedAnswer(transformedAnswerType, imgAnswers[i]));
|
|
|
+
|
|
|
+ //又拍云图片的宽*高
|
|
|
+ String imgWH = RegExpUtil.find(imgAnswers[i], "(\\d+)x(\\d+)");
|
|
|
+ if (!StringUtils.isNullOrEmpty(imgWH)) {
|
|
|
+ Map<String, Object> paramMap = new HashMap<>();
|
|
|
+ paramMap.put("width", Integer.valueOf(imgWH.split("x")[0]));
|
|
|
+ paramMap.put("height", Integer.valueOf(imgWH.split("x")[1]));
|
|
|
+ blockBean.setParam(paramMap);
|
|
|
+ }
|
|
|
+
|
|
|
+ blockBeanList.add (blockBean);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ OuterBlockBean blockBean = new OuterBlockBean();
|
|
|
+ blockBean.setType(transformedAnswerType);
|
|
|
+ blockBean.setValue(getSimpleTransformedAnswer(transformedAnswerType, transformedStudentAnswer));
|
|
|
+ blockBeanList.add(blockBean);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ OuterSectionBean sectionBean = new OuterSectionBean();
|
|
|
+ sectionBean.setBlocks(blockBeanList);
|
|
|
+ sectionBeanList.add(sectionBean);
|
|
|
+
|
|
|
+ OuterSectionCollectionBean resultBean = new OuterSectionCollectionBean();
|
|
|
+ resultBean.setSections(sectionBeanList);
|
|
|
+ return resultBean;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 格式化标准答案
|
|
|
+ *
|
|
|
+ * @param answer
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private OuterSectionCollectionBean getFormattedAnswer(String answer) {
|
|
|
+ if (StringUtils.isNullOrEmpty(answer)) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ return getBodyOrAnswer(answer);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 根据原始作答类型和学生实际作答推断出真实的作答类型
|
|
|
+ *
|
|
|
+ * @param answerType 原始作答类型
|
|
|
+ * @param questionType 题型
|
|
|
+ * @param examId 考试id
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private String getTransformedAnswerType(AnswerType answerType, QuestionType questionType, Long examId) {
|
|
|
+ //如果题型为问答题,且作答类型不为音频作答,且开启微信作答,则此题为图片作答题
|
|
|
+ if (questionType == QuestionType.ESSAY &&
|
|
|
+ (null == answerType || (null != answerType && answerType != AnswerType.SINGLE_AUDIO))) {
|
|
|
+ if (ExamCacheTransferHelper.weixinAnswerEnabled(examId)) {
|
|
|
+ return "image";
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (null != answerType && answerType == AnswerType.SINGLE_AUDIO) {
|
|
|
+ return "audio";
|
|
|
+ }
|
|
|
+
|
|
|
+ return "text";
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 转化过的作答
|
|
|
+ *
|
|
|
+ * @param studentAnswer
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private String getTransformedStudentAnswer(String studentAnswer) {
|
|
|
+ if (StringUtils.isNullOrEmpty(studentAnswer)) {
|
|
|
+ return studentAnswer;
|
|
|
+ }
|
|
|
+
|
|
|
+ //图片题特殊处理(因为图片作答题中有html标签)
|
|
|
+ Document doc = Jsoup.parse(studentAnswer);
|
|
|
+ Elements imgElements = doc.select("img[src]");
|
|
|
+ String imgStudentAnswer = "";
|
|
|
+ for (Element el : imgElements) {
|
|
|
+ String src = el.attr("src");
|
|
|
+ if (!StringUtils.isNullOrEmpty(src)) {
|
|
|
+ imgStudentAnswer += src + "|";
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (!StringUtils.isNullOrEmpty(imgStudentAnswer)) {
|
|
|
+ return imgStudentAnswer.substring(0, imgStudentAnswer.length() - 1);
|
|
|
+ }
|
|
|
+
|
|
|
+ return studentAnswer;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 单个答案再次格式化,去除地址中的多余后缀
|
|
|
+ * @param answerType
|
|
|
+ * @param studentAnswer
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private String getSimpleTransformedAnswer(String answerType, String studentAnswer) {
|
|
|
+ if ("image".equals(answerType)) {
|
|
|
+ String regExp = "(ftp|https?)\\:\\/\\/([\\w\\_\\-]+)\\.([\\w\\-]+[\\.]?)*[\\w]+\\.[a-zA-Z]{2,10}(.*)\\.(png|jpg|gif|jpeg)";
|
|
|
+ return RegExpUtil.find(studentAnswer, regExp);
|
|
|
+ }
|
|
|
+ return studentAnswer;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取格式化后后的题干或标准答案
|
|
|
+ *
|
|
|
+ * @param str
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private OuterSectionCollectionBean getBodyOrAnswer(String str) {
|
|
|
+ OuterSectionCollectionBean body = new OuterSectionCollectionBean();
|
|
|
+ List<OuterSectionBean> sections = new ArrayList<>();
|
|
|
+ // 得到小题题干或者答案行数
|
|
|
+ if (org.apache.commons.lang3.StringUtils.isBlank(str)) {
|
|
|
+ return body;
|
|
|
+ }
|
|
|
+ String[] questionRowStrings = str.split("</p>");
|
|
|
+ for (int i = 0; i < questionRowStrings.length; i++) {
|
|
|
+ List<OuterBlockBean> blocks = disposeQuestionBodyOrOption(questionRowStrings[i]);
|
|
|
+ if (blocks != null && blocks.size() > 0) {
|
|
|
+ OuterSectionBean section = new OuterSectionBean();
|
|
|
+ // 将小题题干拆分为Block集合
|
|
|
+ section.setBlocks(blocks);
|
|
|
+ sections.add(section);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ body.setSections(sections);
|
|
|
+ return body;
|
|
|
+ }
|
|
|
+
|
|
|
+ private List<OuterBlockBean> disposeQuestionBodyOrOption(String questionRow) {
|
|
|
+ List<OuterBlockBean> blocks = new ArrayList<>();
|
|
|
+ // 去掉每行里面的<p>,<span>,</span>标签
|
|
|
+ questionRow = questionRow.replaceAll("<p>", "").replaceAll("</p>", "").replaceAll("<span>", "")
|
|
|
+ .replaceAll("</span>", "").replaceAll("</a>", "");
|
|
|
+ String[] questionRowStrings = questionRow.split("<|/>|>");
|
|
|
+ for (int i = 0; i < questionRowStrings.length; i++) {
|
|
|
+ OuterBlockBean block = new OuterBlockBean();
|
|
|
+ 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.setPlayTime(1);
|
|
|
+ block.setType("audio");
|
|
|
+ block.setValue(this.getAttrValue(rowStr, "id"));
|
|
|
+ blocks.add(block);
|
|
|
+ } else {
|
|
|
+ block.setType("text");
|
|
|
+ rowStr = rowStr.replace(" ", "");// 消除空格
|
|
|
+ rowStr = rowStr.replace(""", "\"");// 将"转换成\"
|
|
|
+ rowStr = rowStr.replace("<", "<");// 将<转换成<
|
|
|
+ rowStr = rowStr.replace(">", ">");// 将>转换成>
|
|
|
+ rowStr = rowStr.replace("&", "&");// 将&转换成&
|
|
|
+ if (org.apache.commons.lang3.StringUtils.isNotBlank(rowStr)) {
|
|
|
+ block.setValue(rowStr);
|
|
|
+ blocks.add(block);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return blocks;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取图片里面的路径,长度,宽度
|
|
|
+ */
|
|
|
+ private List<String> getImg(String s, String str) {
|
|
|
+ String regex;
|
|
|
+ List<String> list = new ArrayList<>();
|
|
|
+ regex = str + "=\"(.*?)\"";
|
|
|
+ Pattern pa = Pattern.compile(regex, Pattern.DOTALL);
|
|
|
+ Matcher ma = pa.matcher(s);
|
|
|
+ while (ma.find()) {
|
|
|
+ list.add(ma.group());
|
|
|
+ }
|
|
|
+ return list;
|
|
|
+ }
|
|
|
+
|
|
|
+ private String getAttrValue(String questionStr, String attrName) {
|
|
|
+ Pattern aPattern = Pattern.compile("a.*");
|
|
|
+ Matcher aMatcher = aPattern.matcher(questionStr);
|
|
|
+
|
|
|
+ if (aMatcher.find()) {
|
|
|
+ String idRegex = attrName + "=\".*?\"";
|
|
|
+ Pattern idPattern = Pattern.compile(idRegex);
|
|
|
+ Matcher idMatcher = idPattern.matcher(aMatcher.group());
|
|
|
+ if (idMatcher.find()) {
|
|
|
+ return idMatcher.group()
|
|
|
+ .replaceAll(attrName + "=\"", "")
|
|
|
+ .replaceAll("\"", "");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return "";
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 校验答案格式是否正确
|
|
|
+ *
|
|
|
+ * @param realAnswerType
|
|
|
+ * @param studentAnswer
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private boolean validateAnswer(String realAnswerType, String studentAnswer) {
|
|
|
+ if (StringUtils.isNullOrEmpty(studentAnswer)) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ String regExp;
|
|
|
+ switch (realAnswerType) {
|
|
|
+ case "image":
|
|
|
+ //图片必须包含.png|jpg|gif|jpeg
|
|
|
+ regExp = "^(ftp|https?)\\:\\/\\/([\\w\\_\\-]+)\\.([\\w\\-]+[\\.]?)*[\\w]+\\.[a-zA-Z]{2,10}(.*)\\.(png|jpg|gif|jpeg).*$";
|
|
|
+ return studentAnswer.matches(regExp);
|
|
|
+ case "audio":
|
|
|
+ //音频必须包含.mp3
|
|
|
+ regExp = "^(ftp|https?)\\:\\/\\/([\\w\\_\\-]+)\\.([\\w\\-]+[\\.]?)*[\\w]+\\.[a-zA-Z]{2,10}(.*)\\.(mp3)";
|
|
|
+ return studentAnswer.matches(regExp);
|
|
|
+ }
|
|
|
+
|
|
|
+ return true;
|
|
|
}
|
|
|
}
|