|
@@ -28,6 +28,7 @@ import com.qmth.cqb.paper.dao.PaperDetailRepo;
|
|
import com.qmth.cqb.paper.dao.PaperDetailUnitRepo;
|
|
import com.qmth.cqb.paper.dao.PaperDetailUnitRepo;
|
|
import com.qmth.cqb.paper.dao.PaperRepo;
|
|
import com.qmth.cqb.paper.dao.PaperRepo;
|
|
import com.qmth.cqb.paper.model.ImportPaperCheck;
|
|
import com.qmth.cqb.paper.model.ImportPaperCheck;
|
|
|
|
+import com.qmth.cqb.paper.model.ImportPaperMsg;
|
|
import com.qmth.cqb.paper.model.Paper;
|
|
import com.qmth.cqb.paper.model.Paper;
|
|
import com.qmth.cqb.paper.model.PaperDetail;
|
|
import com.qmth.cqb.paper.model.PaperDetail;
|
|
import com.qmth.cqb.paper.model.PaperDetailUnit;
|
|
import com.qmth.cqb.paper.model.PaperDetailUnit;
|
|
@@ -49,7 +50,6 @@ import cn.com.qmth.examcloud.common.uac.entity.AccessUser;
|
|
public class ImportPaperService {
|
|
public class ImportPaperService {
|
|
|
|
|
|
protected static final Logger log = LoggerFactory.getLogger(ImportPaperService.class);
|
|
protected static final Logger log = LoggerFactory.getLogger(ImportPaperService.class);
|
|
-
|
|
|
|
@Autowired
|
|
@Autowired
|
|
PaperRepo paperRepo;
|
|
PaperRepo paperRepo;
|
|
|
|
|
|
@@ -95,8 +95,7 @@ public class ImportPaperService {
|
|
* @param file
|
|
* @param file
|
|
* @return
|
|
* @return
|
|
*/
|
|
*/
|
|
- public Paper ImportPaper(Paper paper, AccessUser user,
|
|
|
|
- File file) throws Exception {
|
|
|
|
|
|
+ public Paper ImportPaper(Paper paper, AccessUser user,File file) throws Exception {
|
|
paperService.checkPaperNameNew(paper.getName(), user.getRootOrgId().toString());
|
|
paperService.checkPaperNameNew(paper.getName(), user.getRootOrgId().toString());
|
|
return processImportPaper(paper,user,file);
|
|
return processImportPaper(paper,user,file);
|
|
}
|
|
}
|
|
@@ -124,24 +123,18 @@ public class ImportPaperService {
|
|
checkUnitNum(paperDetailUnits,importPaperCheck);
|
|
checkUnitNum(paperDetailUnits,importPaperCheck);
|
|
//校验答案是否不全
|
|
//校验答案是否不全
|
|
checkAnswerISfull(paperDetailUnits,importPaperCheck);
|
|
checkAnswerISfull(paperDetailUnits,importPaperCheck);
|
|
-
|
|
|
|
tempPaper = paperRepo.save(paper);
|
|
tempPaper = paperRepo.save(paper);
|
|
}
|
|
}
|
|
-
|
|
|
|
if (paperDetails.size() > 0) {
|
|
if (paperDetails.size() > 0) {
|
|
paperDetailRepo.save(paperDetails);
|
|
paperDetailRepo.save(paperDetails);
|
|
}
|
|
}
|
|
-
|
|
|
|
if (questions.size() > 0) {
|
|
if (questions.size() > 0) {
|
|
quesService.saveImportQuesList(questions);
|
|
quesService.saveImportQuesList(questions);
|
|
}
|
|
}
|
|
-
|
|
|
|
if (paperDetailUnits.size() > 0) {
|
|
if (paperDetailUnits.size() > 0) {
|
|
paperDetailUnitRepo.save(paperDetailUnits);
|
|
paperDetailUnitRepo.save(paperDetailUnits);
|
|
}
|
|
}
|
|
-
|
|
|
|
paperService.formatPaper(tempPaper, null);
|
|
paperService.formatPaper(tempPaper, null);
|
|
-
|
|
|
|
return tempPaper;
|
|
return tempPaper;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -152,10 +145,7 @@ public class ImportPaperService {
|
|
* @param paperDetailUnits
|
|
* @param paperDetailUnits
|
|
* @param questions
|
|
* @param questions
|
|
*/
|
|
*/
|
|
- public void clearPaper(Paper paper,
|
|
|
|
- List<PaperDetail> paperDetails,
|
|
|
|
- List<PaperDetailUnit> paperDetailUnits,
|
|
|
|
- List<Question> questions){
|
|
|
|
|
|
+ public void clearPaper(Paper paper,List<PaperDetail> paperDetails,List<PaperDetailUnit> paperDetailUnits, List<Question> questions){
|
|
paper = null;
|
|
paper = null;
|
|
paperDetails.clear();
|
|
paperDetails.clear();
|
|
for(PaperDetailUnit paperDetailUnit:paperDetailUnits){
|
|
for(PaperDetailUnit paperDetailUnit:paperDetailUnits){
|
|
@@ -230,7 +220,7 @@ public class ImportPaperService {
|
|
// 设置当前索引,防止多余循环
|
|
// 设置当前索引,防止多余循环
|
|
i = importPaperCheck.index - 1;
|
|
i = importPaperCheck.index - 1;
|
|
} else if (pText.matches("^\\d{1,}\\.[\\s\\S]*")
|
|
} else if (pText.matches("^\\d{1,}\\.[\\s\\S]*")
|
|
- || (isNested(importPaperCheck) && !pText.startsWith("["))) {
|
|
|
|
|
|
+ || (isNested(importPaperCheck) && !pText.startsWith(ImportPaperMsg.left_bracket))) {
|
|
if(paperDetail == null){
|
|
if(paperDetail == null){
|
|
throw new PaperException("导入文件格式有误,必须有大题头信息,且以 [ 开头!");
|
|
throw new PaperException("导入文件格式有误,必须有大题头信息,且以 [ 开头!");
|
|
}
|
|
}
|
|
@@ -242,7 +232,7 @@ public class ImportPaperService {
|
|
// 初始化小题类和试题类
|
|
// 初始化小题类和试题类
|
|
initPaperDetail(paper, paperDetail, paperDetailUnit, question, subQuesNum , importPaperCheck);
|
|
initPaperDetail(paper, paperDetail, paperDetailUnit, question, subQuesNum , importPaperCheck);
|
|
// 处理客观题
|
|
// 处理客观题
|
|
- if (importPaperCheck.quesType.equals("单选") || importPaperCheck.quesType.equals("多选")) {
|
|
|
|
|
|
+ if (importPaperCheck.quesType.equals(ImportPaperMsg.singleSelection) || importPaperCheck.quesType.equals(ImportPaperMsg.multipleSelection)) {
|
|
// 处理题干
|
|
// 处理题干
|
|
processQuesBody(pList, importPaperCheck.index, subQuesNum, question, importPaperCheck, tmpWordMlPackage);
|
|
processQuesBody(pList, importPaperCheck.index, subQuesNum, question, importPaperCheck, tmpWordMlPackage);
|
|
// 处理选项
|
|
// 处理选项
|
|
@@ -253,15 +243,13 @@ public class ImportPaperService {
|
|
importPaperCheck, tmpWordMlPackage, false);
|
|
importPaperCheck, tmpWordMlPackage, false);
|
|
// 处理选择题的option--chenken 20170425
|
|
// 处理选择题的option--chenken 20170425
|
|
processSelectOption(question);
|
|
processSelectOption(question);
|
|
- } else if (importPaperCheck.quesType.equals("套题")) {
|
|
|
|
|
|
+ } else if (importPaperCheck.quesType.equals(ImportPaperMsg.nestedQuestion_word)) {
|
|
// 处理套题
|
|
// 处理套题
|
|
- processNestedQues(pList, importPaperCheck.index,question, paperDetailUnit, importPaperCheck,
|
|
|
|
- tmpWordMlPackage);
|
|
|
|
|
|
+ processNestedQues(pList, importPaperCheck.index,question, paperDetailUnit, importPaperCheck,tmpWordMlPackage);
|
|
} else {
|
|
} else {
|
|
// 处理其他题型
|
|
// 处理其他题型
|
|
processQuesBody(pList, importPaperCheck.index, subQuesNum,question, importPaperCheck, tmpWordMlPackage);
|
|
processQuesBody(pList, importPaperCheck.index, subQuesNum,question, importPaperCheck, tmpWordMlPackage);
|
|
- processQuesTail(pList, importPaperCheck.index, subQuesNum, question, paperDetailUnit,
|
|
|
|
- importPaperCheck, tmpWordMlPackage, false);
|
|
|
|
|
|
+ processQuesTail(pList, importPaperCheck.index, subQuesNum, question, paperDetailUnit,importPaperCheck, tmpWordMlPackage, false);
|
|
}
|
|
}
|
|
// 设置WordMlPackage二进制数据
|
|
// 设置WordMlPackage二进制数据
|
|
question.setQuesPkg(writeByte);
|
|
question.setQuesPkg(writeByte);
|
|
@@ -296,10 +284,10 @@ public class ImportPaperService {
|
|
}
|
|
}
|
|
|
|
|
|
public boolean isQuesHeader(String pText){
|
|
public boolean isQuesHeader(String pText){
|
|
- return pText.startsWith("[")
|
|
|
|
- && !pText.startsWith("[答案]")
|
|
|
|
- && !pText.startsWith("[小题分数]")
|
|
|
|
- && !pText.startsWith("[小题型]");
|
|
|
|
|
|
+ return pText.startsWith(ImportPaperMsg.left_bracket)
|
|
|
|
+ && !pText.startsWith(ImportPaperMsg.answer_word)
|
|
|
|
+ && !pText.startsWith(ImportPaperMsg.score_word)
|
|
|
|
+ && !pText.startsWith(ImportPaperMsg.subQuestionType_word);
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -370,26 +358,26 @@ public class ImportPaperService {
|
|
|
|
|
|
String tmpErrorInfo = "";
|
|
String tmpErrorInfo = "";
|
|
if (StringUtils.isEmpty(importPaperCheck.quesGroup)) {
|
|
if (StringUtils.isEmpty(importPaperCheck.quesGroup)) {
|
|
- tmpErrorInfo += "试题分类为空或格式不正确\n";
|
|
|
|
|
|
+ tmpErrorInfo += ImportPaperMsg.errMsg_04;
|
|
|
|
|
|
}
|
|
}
|
|
if (StringUtils.isEmpty(importPaperCheck.quesType)) {
|
|
if (StringUtils.isEmpty(importPaperCheck.quesType)) {
|
|
- tmpErrorInfo += "题型为空或格式不正确\n";
|
|
|
|
|
|
+ tmpErrorInfo += ImportPaperMsg.errMsg_05;
|
|
|
|
|
|
}
|
|
}
|
|
if (StringUtils.isEmpty(importPaperCheck.quesName)) {
|
|
if (StringUtils.isEmpty(importPaperCheck.quesName)) {
|
|
- tmpErrorInfo += "大题名称为空或格式不正确\n";
|
|
|
|
|
|
+ tmpErrorInfo += ImportPaperMsg.errMsg_06;
|
|
|
|
|
|
}
|
|
}
|
|
if (StringUtils.isEmpty(importPaperCheck.quesCount)) {
|
|
if (StringUtils.isEmpty(importPaperCheck.quesCount)) {
|
|
- tmpErrorInfo += "题目数量为空或格式不正确\n";
|
|
|
|
|
|
+ tmpErrorInfo += ImportPaperMsg.errMsg_07;
|
|
|
|
|
|
}
|
|
}
|
|
if (StringUtils.isEmpty(importPaperCheck.quesScore)) {
|
|
if (StringUtils.isEmpty(importPaperCheck.quesScore)) {
|
|
- tmpErrorInfo += "分数为空或格式不正确\n";
|
|
|
|
|
|
+ tmpErrorInfo += ImportPaperMsg.errMsg_08;
|
|
}
|
|
}
|
|
if (!StringUtils.isEmpty(importPaperCheck.quesType) && !CommonUtils.checkQuesType(importPaperCheck.quesType)) {
|
|
if (!StringUtils.isEmpty(importPaperCheck.quesType) && !CommonUtils.checkQuesType(importPaperCheck.quesType)) {
|
|
- tmpErrorInfo += "题型必须是单选、多选、判断、填空、问答、套题中的一种\n";
|
|
|
|
|
|
+ tmpErrorInfo += ImportPaperMsg.errMsg_09;
|
|
}
|
|
}
|
|
if (StringUtils.isEmpty(tmpErrorInfo)) {
|
|
if (StringUtils.isEmpty(tmpErrorInfo)) {
|
|
return true;
|
|
return true;
|
|
@@ -405,34 +393,41 @@ public class ImportPaperService {
|
|
* @param pList
|
|
* @param pList
|
|
* @param index
|
|
* @param index
|
|
* @param importPaperCheck
|
|
* @param importPaperCheck
|
|
|
|
+ * @throws PaperException
|
|
*/
|
|
*/
|
|
- public void processMainQuesHeader(List pList, int index, ImportPaperCheck importPaperCheck) {
|
|
|
|
-
|
|
|
|
|
|
+ public void processMainQuesHeader(List<Object> pList, int index, ImportPaperCheck importPaperCheck) throws PaperException {
|
|
int i = 0;
|
|
int i = 0;
|
|
-
|
|
|
|
for (i = index; i < pList.size(); i++) {
|
|
for (i = index; i < pList.size(); i++) {
|
|
P pHeader = (P) pList.get(i);
|
|
P pHeader = (P) pList.get(i);
|
|
|
|
+ P pNextHeader = (P) pList.get(i+1);
|
|
String tmpText = DocxProcessUtil.getPText(pHeader);
|
|
String tmpText = DocxProcessUtil.getPText(pHeader);
|
|
- if (tmpText.startsWith("[试题分类]")) {
|
|
|
|
-
|
|
|
|
- importPaperCheck.setQuesGroup(tmpText.replaceAll("\\[试题分类\\]", "").replaceAll("[:|:]", "").trim());
|
|
|
|
-
|
|
|
|
- } else if (tmpText.startsWith("[题型]")) {
|
|
|
|
-
|
|
|
|
- importPaperCheck.setQuesType(tmpText.replaceAll("\\[题型\\]", "").replaceAll("[:|:]", "").trim());
|
|
|
|
-
|
|
|
|
- } else if (tmpText.startsWith("[大题名称]")) {
|
|
|
|
-
|
|
|
|
- importPaperCheck.setQuesName(tmpText.replaceAll("\\[大题名称\\]", "").replaceAll("[:|:]", "").trim());
|
|
|
|
-
|
|
|
|
- } else if (tmpText.startsWith("[题目数量]")) {
|
|
|
|
-
|
|
|
|
- importPaperCheck.setQuesCount(tmpText.replaceAll("\\[题目数量\\]", "").replaceAll("[:|:]", "").trim());
|
|
|
|
-
|
|
|
|
- } else if (tmpText.startsWith("[分数]")) {
|
|
|
|
-
|
|
|
|
- importPaperCheck.setQuesScore(tmpText.replaceAll("\\[分数\\]", "").replaceAll("[:|:]", "").trim());
|
|
|
|
-
|
|
|
|
|
|
+ String nextTmpText = DocxProcessUtil.getPText(pNextHeader);
|
|
|
|
+ if (tmpText.startsWith(ImportPaperMsg.questionClassify_word)) {
|
|
|
|
+ if(!nextTmpText.startsWith(ImportPaperMsg.questionType_word)){
|
|
|
|
+ importPaperCheck.setErrorInfo("[试题分类]的下一题头应该是[题型],当前读到的信息为:“" +nextTmpText+"”,请检查word中格式问题");
|
|
|
|
+ throw new PaperException(importPaperCheck.errorInfo);
|
|
|
|
+ }
|
|
|
|
+ importPaperCheck.setQuesGroup(getContent(tmpText,ImportPaperMsg.questionClassify_word));
|
|
|
|
+ } else if (tmpText.startsWith(ImportPaperMsg.questionType_word)) {
|
|
|
|
+ if(!nextTmpText.startsWith(ImportPaperMsg.questionName_word)){
|
|
|
|
+ importPaperCheck.setErrorInfo("[题型]的下一题头应该是[大题名称],当前读到的信息为:“"+nextTmpText+"”,请检查word中格式问题");
|
|
|
|
+ throw new PaperException(importPaperCheck.errorInfo);
|
|
|
|
+ }
|
|
|
|
+ importPaperCheck.setQuesType(getContent(tmpText,ImportPaperMsg.questionType_word));
|
|
|
|
+ } else if (tmpText.startsWith(ImportPaperMsg.questionName_word)) {
|
|
|
|
+ if(!nextTmpText.startsWith(ImportPaperMsg.questionNum_word)){
|
|
|
|
+ importPaperCheck.setErrorInfo("[大题名称]的下一题头应该是[题目数量],当前读到的信息为:“"+nextTmpText+"”,请检查word中格式问题");
|
|
|
|
+ throw new PaperException(importPaperCheck.errorInfo);
|
|
|
|
+ }
|
|
|
|
+ importPaperCheck.setQuesName(getContent(tmpText,ImportPaperMsg.questionName_word));
|
|
|
|
+ } else if (tmpText.startsWith(ImportPaperMsg.questionNum_word)) {
|
|
|
|
+ if(!nextTmpText.startsWith(ImportPaperMsg.score_word)){
|
|
|
|
+ importPaperCheck.setErrorInfo("[题目数量]的下一题头应该是[分数],当前读到的信息为:“"+nextTmpText+"”,请检查word中格式问题");
|
|
|
|
+ throw new PaperException(importPaperCheck.errorInfo);
|
|
|
|
+ }
|
|
|
|
+ importPaperCheck.setQuesCount(getContent(tmpText,ImportPaperMsg.questionNum_word));
|
|
|
|
+ } else if (tmpText.startsWith(ImportPaperMsg.score_word)) {
|
|
|
|
+ importPaperCheck.setQuesScore(getContent(tmpText,ImportPaperMsg.score_word));
|
|
} else if (StringUtils.isEmpty(tmpText)) {
|
|
} else if (StringUtils.isEmpty(tmpText)) {
|
|
continue;
|
|
continue;
|
|
} else {
|
|
} else {
|
|
@@ -452,24 +447,21 @@ public class ImportPaperService {
|
|
* @param wordMLPackage
|
|
* @param wordMLPackage
|
|
* @throws Exception
|
|
* @throws Exception
|
|
*/
|
|
*/
|
|
- public void processQuesBody(List pList, int index, int subQuesNum,Question question, ImportPaperCheck importPaperCheck,
|
|
|
|
|
|
+ public void processQuesBody(List<Object> pList, int index, int subQuesNum,Question question, ImportPaperCheck importPaperCheck,
|
|
WordprocessingMLPackage wordMLPackage) throws Exception {
|
|
WordprocessingMLPackage wordMLPackage) throws Exception {
|
|
// 定义题干wordml和html
|
|
// 定义题干wordml和html
|
|
StringBuilder quesBodyWordMl = new StringBuilder();
|
|
StringBuilder quesBodyWordMl = new StringBuilder();
|
|
StringBuilder quesBodyHtml = new StringBuilder();
|
|
StringBuilder quesBodyHtml = new StringBuilder();
|
|
int i = 0;
|
|
int i = 0;
|
|
- boolean bodyStart = false;
|
|
|
|
for (i = index; i < pList.size(); i++) {
|
|
for (i = index; i < pList.size(); i++) {
|
|
P pBody = (P) pList.get(i);
|
|
P pBody = (P) pList.get(i);
|
|
String tmpText = DocxProcessUtil.getPText(pBody);
|
|
String tmpText = DocxProcessUtil.getPText(pBody);
|
|
-
|
|
|
|
if (StringUtils.isEmpty(tmpText) && DocxProcessUtil.isText(pBody)) {
|
|
if (StringUtils.isEmpty(tmpText) && DocxProcessUtil.isText(pBody)) {
|
|
// 跳过空白段落
|
|
// 跳过空白段落
|
|
continue;
|
|
continue;
|
|
} else if (tmpText.matches("^\\d{1,}\\.[\\s\\S]*")) {
|
|
} else if (tmpText.matches("^\\d{1,}\\.[\\s\\S]*")) {
|
|
// 题干第一段
|
|
// 题干第一段
|
|
// 过滤题干标题
|
|
// 过滤题干标题
|
|
- bodyStart = true;
|
|
|
|
pBody = DocxProcessUtil.formatP(pBody, QuesUnit.QUES_BODY);
|
|
pBody = DocxProcessUtil.formatP(pBody, QuesUnit.QUES_BODY);
|
|
String tmpWordMl = DocxProcessUtil.getPWordMl(pBody);
|
|
String tmpWordMl = DocxProcessUtil.getPWordMl(pBody);
|
|
tmpWordMl = DocxProcessUtil.formatPWordMl(tmpWordMl);
|
|
tmpWordMl = DocxProcessUtil.formatPWordMl(tmpWordMl);
|
|
@@ -488,11 +480,9 @@ public class ImportPaperService {
|
|
}
|
|
}
|
|
if(StringUtils.isEmpty(quesBodyHtml) || StringUtils.isEmpty(quesBodyWordMl)){
|
|
if(StringUtils.isEmpty(quesBodyHtml) || StringUtils.isEmpty(quesBodyWordMl)){
|
|
if(subQuesNum == 0){
|
|
if(subQuesNum == 0){
|
|
- importPaperCheck.setErrorInfo(importPaperCheck.quesName
|
|
|
|
- +"题干为空或格式不正确");
|
|
|
|
|
|
+ importPaperCheck.setErrorInfo(importPaperCheck.quesName+ImportPaperMsg.errMsg_01);
|
|
}else{
|
|
}else{
|
|
- importPaperCheck.setErrorInfo(getQuesNumInfo(importPaperCheck.quesName,subQuesNum)
|
|
|
|
- +"题干为空或格式不正确");
|
|
|
|
|
|
+ importPaperCheck.setErrorInfo(getQuesNumInfo(importPaperCheck.quesName,subQuesNum)+ImportPaperMsg.errMsg_01);
|
|
}
|
|
}
|
|
throw new PaperException(importPaperCheck.errorInfo);
|
|
throw new PaperException(importPaperCheck.errorInfo);
|
|
}
|
|
}
|
|
@@ -513,7 +503,7 @@ public class ImportPaperService {
|
|
* @return
|
|
* @return
|
|
* @throws Exception
|
|
* @throws Exception
|
|
*/
|
|
*/
|
|
- public String processQuesOption(List pList, int index, int subQuesNum, Question question,
|
|
|
|
|
|
+ public String processQuesOption(List<Object> pList, int index, int subQuesNum, Question question,
|
|
ImportPaperCheck importPaperCheck, WordprocessingMLPackage wordMLPackage) throws Exception {
|
|
ImportPaperCheck importPaperCheck, WordprocessingMLPackage wordMLPackage) throws Exception {
|
|
|
|
|
|
// 定义试题选项wordml和html
|
|
// 定义试题选项wordml和html
|
|
@@ -525,14 +515,12 @@ public class ImportPaperService {
|
|
int optionCount = 0;
|
|
int optionCount = 0;
|
|
// 当前所处的选项
|
|
// 当前所处的选项
|
|
QuesOption current = null;
|
|
QuesOption current = null;
|
|
-
|
|
|
|
int i = 0;
|
|
int i = 0;
|
|
int number = 0;
|
|
int number = 0;
|
|
for (i = index; i < pList.size(); i++) {
|
|
for (i = index; i < pList.size(); i++) {
|
|
number++;
|
|
number++;
|
|
P pOption = (P) pList.get(i);
|
|
P pOption = (P) pList.get(i);
|
|
String tmpText = DocxProcessUtil.getPText(pOption);
|
|
String tmpText = DocxProcessUtil.getPText(pOption);
|
|
-
|
|
|
|
if (StringUtils.isEmpty(tmpText) && DocxProcessUtil.isText(pOption)) {
|
|
if (StringUtils.isEmpty(tmpText) && DocxProcessUtil.isText(pOption)) {
|
|
// 跳过空白段落
|
|
// 跳过空白段落
|
|
continue;
|
|
continue;
|
|
@@ -540,9 +528,7 @@ public class ImportPaperService {
|
|
// 检测到选项开始段落
|
|
// 检测到选项开始段落
|
|
// 创建试题选项
|
|
// 创建试题选项
|
|
current = new QuesOption();
|
|
current = new QuesOption();
|
|
- String optionNumber = String.valueOf(number);// number设置
|
|
|
|
- // 为1,2,3,4--chenken
|
|
|
|
- // 2017.4.25
|
|
|
|
|
|
+ String optionNumber = String.valueOf(number);
|
|
current.setNumber(optionNumber);
|
|
current.setNumber(optionNumber);
|
|
current.setOptionBody("");
|
|
current.setOptionBody("");
|
|
current.setOptionBodyWord("");
|
|
current.setOptionBodyWord("");
|
|
@@ -553,7 +539,7 @@ public class ImportPaperService {
|
|
String tmpWordMl = DocxProcessUtil.getPWordMl(pOption);
|
|
String tmpWordMl = DocxProcessUtil.getPWordMl(pOption);
|
|
current.setOptionBody(current.getOptionBody() + DocxProcessUtil.docx2Html(tmpWordMl, wordMLPackage));
|
|
current.setOptionBody(current.getOptionBody() + DocxProcessUtil.docx2Html(tmpWordMl, wordMLPackage));
|
|
current.setOptionBodyWord(current.getOptionBodyWord() + DocxProcessUtil.formatPWordMl(tmpWordMl));
|
|
current.setOptionBodyWord(current.getOptionBodyWord() + DocxProcessUtil.formatPWordMl(tmpWordMl));
|
|
- } else if (tmpText.startsWith("[")) {
|
|
|
|
|
|
+ } else if (tmpText.startsWith(ImportPaperMsg.left_bracket)) {
|
|
// 非选项的其他内容直接退出
|
|
// 非选项的其他内容直接退出
|
|
break;
|
|
break;
|
|
} else if (current != null) {
|
|
} else if (current != null) {
|
|
@@ -567,8 +553,7 @@ public class ImportPaperService {
|
|
}
|
|
}
|
|
importPaperCheck.setIndex(i);
|
|
importPaperCheck.setIndex(i);
|
|
if (optionCount < 2) {
|
|
if (optionCount < 2) {
|
|
- importPaperCheck.setErrorInfo(getQuesNumInfo(importPaperCheck.quesName, subQuesNum)
|
|
|
|
- + "中选项格式不正确或有缺失\n");
|
|
|
|
|
|
+ importPaperCheck.setErrorInfo(getQuesNumInfo(importPaperCheck.quesName, subQuesNum)+ "中选项格式不正确或有缺失\n");
|
|
throw new PaperException(importPaperCheck.errorInfo);
|
|
throw new PaperException(importPaperCheck.errorInfo);
|
|
} else {
|
|
} else {
|
|
question.setQuesOptions(quesOptions);
|
|
question.setQuesOptions(quesOptions);
|
|
@@ -586,7 +571,7 @@ public class ImportPaperService {
|
|
* @param paperDetailUnit
|
|
* @param paperDetailUnit
|
|
* @param importPaperCheck
|
|
* @param importPaperCheck
|
|
*/
|
|
*/
|
|
- public void processQuesTail(List pList, int index, int subQuesNum, Question question,
|
|
|
|
|
|
+ public void processQuesTail(List<Object> pList, int index, int subQuesNum, Question question,
|
|
PaperDetailUnit paperDetailUnit, ImportPaperCheck importPaperCheck, WordprocessingMLPackage wordMLPackage,
|
|
PaperDetailUnit paperDetailUnit, ImportPaperCheck importPaperCheck, WordprocessingMLPackage wordMLPackage,
|
|
boolean isNested) throws Exception {
|
|
boolean isNested) throws Exception {
|
|
|
|
|
|
@@ -604,7 +589,7 @@ public class ImportPaperService {
|
|
if (StringUtils.isEmpty(tmpText) && DocxProcessUtil.isText(pAnswer)) {
|
|
if (StringUtils.isEmpty(tmpText) && DocxProcessUtil.isText(pAnswer)) {
|
|
// 跳过空白段落
|
|
// 跳过空白段落
|
|
continue;
|
|
continue;
|
|
- } else if (tmpText.startsWith("[答案]")) {
|
|
|
|
|
|
+ } else if (tmpText.startsWith(ImportPaperMsg.answer_word)) {
|
|
// 检测到答案开始段落
|
|
// 检测到答案开始段落
|
|
pAnswer = DocxProcessUtil.formatP(pAnswer, QuesUnit.QUES_ANSWER);
|
|
pAnswer = DocxProcessUtil.formatP(pAnswer, QuesUnit.QUES_ANSWER);
|
|
String tmpWordMl = DocxProcessUtil.getPWordMl(pAnswer);
|
|
String tmpWordMl = DocxProcessUtil.getPWordMl(pAnswer);
|
|
@@ -613,20 +598,20 @@ public class ImportPaperService {
|
|
//校验单选多选答案
|
|
//校验单选多选答案
|
|
checkAnswer(question,pList.get(i).toString(),importPaperCheck,subQuesNum);
|
|
checkAnswer(question,pList.get(i).toString(),importPaperCheck,subQuesNum);
|
|
answerWordML.append(DocxProcessUtil.formatPWordMl(tmpWordMl));
|
|
answerWordML.append(DocxProcessUtil.formatPWordMl(tmpWordMl));
|
|
- answerHTML.append(tmpText.replaceAll("\\[答案\\]", "").replaceAll("[:|:]", "").trim());
|
|
|
|
|
|
+ answerHTML.append(getContent(tmpText, ImportPaperMsg.answer_word));
|
|
}else if(question.getQuestionType() == QuesStructType.BOOL_ANSWER_QUESTION){
|
|
}else if(question.getQuestionType() == QuesStructType.BOOL_ANSWER_QUESTION){
|
|
answerWordML.append(DocxProcessUtil.formatPWordMl(tmpWordMl));
|
|
answerWordML.append(DocxProcessUtil.formatPWordMl(tmpWordMl));
|
|
- answerHTML.append(tmpText.replaceAll("\\[答案\\]", "").replaceAll("[:|:]", "").trim());
|
|
|
|
|
|
+ answerHTML.append(getContent(tmpText, ImportPaperMsg.answer_word));
|
|
}else{
|
|
}else{
|
|
answerWordML.append(DocxProcessUtil.formatPWordMl(tmpWordMl));
|
|
answerWordML.append(DocxProcessUtil.formatPWordMl(tmpWordMl));
|
|
answerHTML.append(DocxProcessUtil.docx2Html(tmpWordMl, wordMLPackage));
|
|
answerHTML.append(DocxProcessUtil.docx2Html(tmpWordMl, wordMLPackage));
|
|
}
|
|
}
|
|
answerStart = true;
|
|
answerStart = true;
|
|
- } else if (tmpText.startsWith("[小题分数]")) {
|
|
|
|
|
|
+ } else if (tmpText.startsWith(ImportPaperMsg.subQuesScore_word)) {
|
|
// 检测到分数开始段落
|
|
// 检测到分数开始段落
|
|
- quesScore = tmpText.replaceAll("\\[小题分数\\]", "").replaceAll("[:|:]", "").trim();
|
|
|
|
|
|
+ quesScore = getContent(tmpText, ImportPaperMsg.subQuesScore_word);
|
|
answerStart = false;
|
|
answerStart = false;
|
|
- } else if (tmpText.startsWith("[") || tmpText.matches("^\\d{1,}\\.[\\s\\S]*")) {
|
|
|
|
|
|
+ } else if (tmpText.startsWith(ImportPaperMsg.left_bracket) || tmpText.matches("^\\d{1,}\\.[\\s\\S]*")) {
|
|
// 检测到其他特殊段落或下一题直接退出
|
|
// 检测到其他特殊段落或下一题直接退出
|
|
break;
|
|
break;
|
|
} else if (answerStart) {
|
|
} else if (answerStart) {
|
|
@@ -685,93 +670,65 @@ public class ImportPaperService {
|
|
* @param importPaperCheck
|
|
* @param importPaperCheck
|
|
* @throws Exception
|
|
* @throws Exception
|
|
*/
|
|
*/
|
|
- public void processNestedQues(List pList, int index,Question question, PaperDetailUnit paperDetailUnit,
|
|
|
|
|
|
+ public void processNestedQues(List<Object> pList, int index,Question question, PaperDetailUnit paperDetailUnit,
|
|
ImportPaperCheck importPaperCheck, WordprocessingMLPackage wordMLPackage) throws Exception {
|
|
ImportPaperCheck importPaperCheck, WordprocessingMLPackage wordMLPackage) throws Exception {
|
|
// 题型
|
|
// 题型
|
|
String nestedQuesType = "";
|
|
String nestedQuesType = "";
|
|
-
|
|
|
|
// 设置套题题干
|
|
// 设置套题题干
|
|
processQuesBody(pList, index, 0,question, importPaperCheck, wordMLPackage);
|
|
processQuesBody(pList, index, 0,question, importPaperCheck, wordMLPackage);
|
|
-
|
|
|
|
// 创建小题集合
|
|
// 创建小题集合
|
|
List<Question> subQuesList = new ArrayList<Question>();
|
|
List<Question> subQuesList = new ArrayList<Question>();
|
|
-
|
|
|
|
Question subQues = null;
|
|
Question subQues = null;
|
|
-
|
|
|
|
int beginNum = importPaperCheck.index;
|
|
int beginNum = importPaperCheck.index;
|
|
-
|
|
|
|
int quesTypeNum = 0;
|
|
int quesTypeNum = 0;
|
|
-
|
|
|
|
int subQuesNum = 0;
|
|
int subQuesNum = 0;
|
|
for (int i = beginNum; i < pList.size(); i++) {
|
|
for (int i = beginNum; i < pList.size(); i++) {
|
|
P pSubQues = (P) pList.get(i);
|
|
P pSubQues = (P) pList.get(i);
|
|
String tmpText = DocxProcessUtil.getPText(pSubQues);
|
|
String tmpText = DocxProcessUtil.getPText(pSubQues);
|
|
-
|
|
|
|
if (StringUtils.isEmpty(tmpText)) {
|
|
if (StringUtils.isEmpty(tmpText)) {
|
|
continue;
|
|
continue;
|
|
}
|
|
}
|
|
- if (tmpText.startsWith("[小题型]")) {
|
|
|
|
-
|
|
|
|
- nestedQuesType = tmpText.replaceAll("\\[小题型\\]", "").replaceAll("[:|:]", "").trim();
|
|
|
|
|
|
+ if (tmpText.startsWith(ImportPaperMsg.subQuestionType_word)) {
|
|
|
|
+ nestedQuesType = getContent(tmpText, ImportPaperMsg.subQuestionType_word);
|
|
importPaperCheck.index++;
|
|
importPaperCheck.index++;
|
|
quesTypeNum++;
|
|
quesTypeNum++;
|
|
-
|
|
|
|
} else if (tmpText.matches("^\\d{1,}\\.[\\s\\S]*")) {
|
|
} else if (tmpText.matches("^\\d{1,}\\.[\\s\\S]*")) {
|
|
-
|
|
|
|
++subQuesNum;
|
|
++subQuesNum;
|
|
-
|
|
|
|
if (StringUtils.isEmpty(nestedQuesType)) {
|
|
if (StringUtils.isEmpty(nestedQuesType)) {
|
|
- importPaperCheck.setErrorInfo(getQuesNumInfo(importPaperCheck.quesName, subQuesNum)
|
|
|
|
- + "小题型为空或格式不正确\n");
|
|
|
|
|
|
+ importPaperCheck.setErrorInfo(getQuesNumInfo(importPaperCheck.quesName, subQuesNum) + ImportPaperMsg.errMsg_02);
|
|
throw new PaperException(importPaperCheck.errorInfo);
|
|
throw new PaperException(importPaperCheck.errorInfo);
|
|
}
|
|
}
|
|
-
|
|
|
|
subQues = new Question();
|
|
subQues = new Question();
|
|
subQues.setQuestionType(getQuesStructType(nestedQuesType));
|
|
subQues.setQuestionType(getQuesStructType(nestedQuesType));
|
|
if (StringUtils.isNumeric(importPaperCheck.getQuesScore())) {
|
|
if (StringUtils.isNumeric(importPaperCheck.getQuesScore())) {
|
|
subQues.setScore(Double.parseDouble(importPaperCheck.getQuesScore()));
|
|
subQues.setScore(Double.parseDouble(importPaperCheck.getQuesScore()));
|
|
}
|
|
}
|
|
-
|
|
|
|
// 处理客观题
|
|
// 处理客观题
|
|
- if (nestedQuesType.equals("单选") || nestedQuesType.equals("多选")) {
|
|
|
|
-
|
|
|
|
|
|
+ if (nestedQuesType.equals(ImportPaperMsg.singleSelection) || nestedQuesType.equals(ImportPaperMsg.multipleSelection)) {
|
|
// 处理题干
|
|
// 处理题干
|
|
processQuesBody(pList, importPaperCheck.index, subQuesNum,subQues, importPaperCheck, wordMLPackage);
|
|
processQuesBody(pList, importPaperCheck.index, subQuesNum,subQues, importPaperCheck, wordMLPackage);
|
|
-
|
|
|
|
// 处理选项
|
|
// 处理选项
|
|
- processQuesOption(pList, importPaperCheck.index, subQuesNum, subQues, importPaperCheck,
|
|
|
|
- wordMLPackage);
|
|
|
|
-
|
|
|
|
|
|
+ processQuesOption(pList, importPaperCheck.index, subQuesNum, subQues, importPaperCheck,wordMLPackage);
|
|
// 处理尾信息
|
|
// 处理尾信息
|
|
- processQuesTail(pList, importPaperCheck.index, subQuesNum, subQues, paperDetailUnit,
|
|
|
|
- importPaperCheck, wordMLPackage, true);
|
|
|
|
-
|
|
|
|
|
|
+ processQuesTail(pList, importPaperCheck.index, subQuesNum, subQues, paperDetailUnit,importPaperCheck, wordMLPackage, true);
|
|
// 处理选择题的option--chenken 20170426
|
|
// 处理选择题的option--chenken 20170426
|
|
processSelectOption(subQues);
|
|
processSelectOption(subQues);
|
|
-
|
|
|
|
} else {
|
|
} else {
|
|
// 处理其他题型
|
|
// 处理其他题型
|
|
processQuesBody(pList, importPaperCheck.index, subQuesNum, subQues, importPaperCheck, wordMLPackage);
|
|
processQuesBody(pList, importPaperCheck.index, subQuesNum, subQues, importPaperCheck, wordMLPackage);
|
|
-
|
|
|
|
- processQuesTail(pList, importPaperCheck.index, subQuesNum, subQues, paperDetailUnit,
|
|
|
|
- importPaperCheck, wordMLPackage, true);
|
|
|
|
|
|
+ processQuesTail(pList, importPaperCheck.index, subQuesNum, subQues, paperDetailUnit,importPaperCheck, wordMLPackage, true);
|
|
}
|
|
}
|
|
subQuesList.add(subQues);
|
|
subQuesList.add(subQues);
|
|
i = importPaperCheck.index - 1;
|
|
i = importPaperCheck.index - 1;
|
|
nestedQuesType = "";
|
|
nestedQuesType = "";
|
|
-
|
|
|
|
}else if(subQuesNum != quesTypeNum){
|
|
}else if(subQuesNum != quesTypeNum){
|
|
-
|
|
|
|
if (StringUtils.isEmpty(nestedQuesType)) {
|
|
if (StringUtils.isEmpty(nestedQuesType)) {
|
|
- importPaperCheck.setErrorInfo(getQuesNumInfo(importPaperCheck.quesName, quesTypeNum)
|
|
|
|
- + "小题型为空或格式不正确\n");
|
|
|
|
|
|
+ importPaperCheck.setErrorInfo(getQuesNumInfo(importPaperCheck.quesName, quesTypeNum) + ImportPaperMsg.errMsg_02);
|
|
}else{
|
|
}else{
|
|
- importPaperCheck.setErrorInfo(getQuesNumInfo(importPaperCheck.quesName, quesTypeNum)
|
|
|
|
- + "题干为空或格式不正确,必须以数字.开头\n");
|
|
|
|
|
|
+ importPaperCheck.setErrorInfo(getQuesNumInfo(importPaperCheck.quesName, quesTypeNum) + ImportPaperMsg.errMsg_03);
|
|
}
|
|
}
|
|
throw new PaperException(importPaperCheck.errorInfo);
|
|
throw new PaperException(importPaperCheck.errorInfo);
|
|
-
|
|
|
|
- }else if(tmpText.startsWith("[")){
|
|
|
|
|
|
+ }else if(tmpText.startsWith(ImportPaperMsg.left_bracket)){
|
|
break;
|
|
break;
|
|
}
|
|
}
|
|
if (!StringUtils.isEmpty(importPaperCheck.errorInfo)) {
|
|
if (!StringUtils.isEmpty(importPaperCheck.errorInfo)) {
|
|
@@ -845,7 +802,7 @@ public class ImportPaperService {
|
|
* @return
|
|
* @return
|
|
*/
|
|
*/
|
|
public static boolean isNested(ImportPaperCheck importPaperCheck) {
|
|
public static boolean isNested(ImportPaperCheck importPaperCheck) {
|
|
- if (importPaperCheck.getQuesType().equals("套题")) {
|
|
|
|
|
|
+ if (importPaperCheck.getQuesType().equals(ImportPaperMsg.nestedQuestion_word)) {
|
|
return true;
|
|
return true;
|
|
} else {
|
|
} else {
|
|
return false;
|
|
return false;
|
|
@@ -1057,9 +1014,15 @@ public class ImportPaperService {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- /*public static void main(String[] args) {
|
|
|
|
- String pattern = "\\s*([A-Z]|[a-z])\\s*";
|
|
|
|
- System.out.println(Pattern.matches(pattern, " C"));
|
|
|
|
- }*/
|
|
|
|
|
|
+ /**
|
|
|
|
+ * 替换字符串中的属性头得到属性值
|
|
|
|
+ * @param pText
|
|
|
|
+ * @param replaceContent
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ private static String getContent(String pText,String replaceContent){
|
|
|
|
+ String word = replaceContent.replace("[", "").replace("]", "");
|
|
|
|
+ return pText.replaceAll("\\["+word+"\\]","").replaceAll("[:|:]", "").trim();
|
|
|
|
+ }
|
|
|
|
|
|
}
|
|
}
|