|
@@ -389,6 +389,15 @@ public class QuestionServiceImpl extends ServiceImpl<QuestionMapper, Question> i
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
+ private boolean isLineStart(String content) {
|
|
|
+ if (Validator.isNotEmpty(content)) {
|
|
|
+ if(isQuestionStart(content)||content.startsWith("A.")||content.startsWith("B.")||content.startsWith("C.")||content.startsWith("D.")||content.startsWith("E.")
|
|
|
+ ||content.startsWith("F.")||content.startsWith("正确答案")||content.startsWith("解题思路")||content.startsWith("考查考点")||content.startsWith("老师解答")){
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+ }
|
|
|
|
|
|
@Override
|
|
|
public String importWordQuestion(MultipartFile file, Long eduId, Long projectId, Long businessId, Long subjectId) {
|
|
@@ -440,7 +449,8 @@ public class QuestionServiceImpl extends ServiceImpl<QuestionMapper, Question> i
|
|
|
List<QuestionAddBo> list3 = new ArrayList<>(); //简答列表
|
|
|
List<QuestionAddBo> list4 = new ArrayList<>(); //判断列表
|
|
|
|
|
|
- Integer nowPart = 0;//0正文 1选项A 2选项B 3选项C 4选项D 5选项E 6选项F
|
|
|
+ Integer nowPart = -1;//0正文 1选项A 2选项B 3选项C 4选项D 5选项E 6选项F
|
|
|
+ String strContent = "";
|
|
|
|
|
|
for (XWPFParagraph paragraph : paragraphList) {
|
|
|
List<XWPFRun> runs = paragraph.getRuns();
|
|
@@ -500,36 +510,154 @@ public class QuestionServiceImpl extends ServiceImpl<QuestionMapper, Question> i
|
|
|
if(Validator.isEmpty(content)||content.equals("")){
|
|
|
continue;
|
|
|
}
|
|
|
- if (isQuestionStart(content)) {
|
|
|
+ if (isQuestionStart(content)||(nowPart==0&&!isLineStart(content))) {
|
|
|
nowPart = 0;
|
|
|
//新题开头
|
|
|
QuestionAddBo addBo = new QuestionAddBo();
|
|
|
+ strContent = strContent + "<br />" + content;
|
|
|
}
|
|
|
//第一个选项
|
|
|
- if (content.startsWith("A.")) {
|
|
|
+ if(content.startsWith("A.")||(nowPart==1&&!isLineStart(content))) {
|
|
|
+ isOption = true; //是选择题
|
|
|
nowPart = 1;
|
|
|
+ strContent = strContent + "<br />" + content;
|
|
|
+ QuestionChildAddBo bo1;
|
|
|
+ if(optionsList.size()<1){
|
|
|
+ bo1 = new QuestionChildAddBo();
|
|
|
+ bo1.setOptionsId(1L);
|
|
|
+ bo1.setContent(strContent.replace("A.", ""));
|
|
|
+ optionsList.add(bo1);
|
|
|
+ }else{
|
|
|
+ bo1 = optionsList.get(0);
|
|
|
+ bo1.setContent(strContent.replace("A.", ""));
|
|
|
+ }
|
|
|
}
|
|
|
//第二个选项
|
|
|
- else if (content.startsWith("B.")) {
|
|
|
+ if (content.startsWith("B.")||(nowPart==2&&!isLineStart(content))) {
|
|
|
nowPart = 2;
|
|
|
+ strContent = strContent + "<br />" + content;
|
|
|
+ QuestionChildAddBo bo1;
|
|
|
+ if(optionsList.size()<2){
|
|
|
+ bo1 = new QuestionChildAddBo();
|
|
|
+ bo1.setOptionsId(2L);
|
|
|
+ bo1.setContent(strContent.replace("B.", ""));
|
|
|
+ optionsList.add(bo1);
|
|
|
+ }else{
|
|
|
+ bo1 = optionsList.get(1);
|
|
|
+ bo1.setContent(strContent.replace("B.", ""));
|
|
|
+ }
|
|
|
}
|
|
|
//第三个选项
|
|
|
- else if (content.startsWith("C.")) {
|
|
|
+ if (content.startsWith("C.")||(nowPart==3&&!isLineStart(content))) {
|
|
|
nowPart = 3;
|
|
|
+ strContent = strContent + "<br />" + content;
|
|
|
+ QuestionChildAddBo bo1;
|
|
|
+ if(optionsList.size()<3){
|
|
|
+ bo1 = new QuestionChildAddBo();
|
|
|
+ bo1.setOptionsId(3L);
|
|
|
+ bo1.setContent(strContent.replace("C.", ""));
|
|
|
+ optionsList.add(bo1);
|
|
|
+ }else{
|
|
|
+ bo1 = optionsList.get(2);
|
|
|
+ bo1.setContent(strContent.replace("C.", ""));
|
|
|
+ }
|
|
|
}
|
|
|
//第四个选项
|
|
|
- else if (content.startsWith("D.")) {
|
|
|
+ if (content.startsWith("D.")||(nowPart==4&&!isLineStart(content))) {
|
|
|
nowPart = 4;
|
|
|
+ strContent = strContent + "<br />" + content;
|
|
|
+ QuestionChildAddBo bo1;
|
|
|
+ if(optionsList.size()<4){
|
|
|
+ bo1 = new QuestionChildAddBo();
|
|
|
+ bo1.setOptionsId(4L);
|
|
|
+ bo1.setContent(strContent.replace("D.", ""));
|
|
|
+ optionsList.add(bo1);
|
|
|
+ }else{
|
|
|
+ bo1 = optionsList.get(3);
|
|
|
+ bo1.setContent(strContent.replace("D.", ""));
|
|
|
+ }
|
|
|
}
|
|
|
//第五个选项
|
|
|
- else if (content.startsWith("E.")) {
|
|
|
+ if (content.startsWith("E.")||(nowPart==5&&!isLineStart(content))) {
|
|
|
nowPart = 5;
|
|
|
+ strContent = strContent + "<br />" + content;
|
|
|
+ QuestionChildAddBo bo1;
|
|
|
+ if(optionsList.size()<5){
|
|
|
+ bo1 = new QuestionChildAddBo();
|
|
|
+ bo1.setOptionsId(5L);
|
|
|
+ bo1.setContent(strContent.replace("E.", ""));
|
|
|
+ optionsList.add(bo1);
|
|
|
+ }else{
|
|
|
+ bo1 = optionsList.get(4);
|
|
|
+ bo1.setContent(strContent.replace("E.", ""));
|
|
|
+ }
|
|
|
}
|
|
|
//第六个选项
|
|
|
- else if (content.startsWith("F.")) {
|
|
|
-
|
|
|
+ if (content.startsWith("F.")||(nowPart==6&&!isLineStart(content))) {
|
|
|
+ if(nowPart!=6){
|
|
|
+ strContent = "";
|
|
|
+ }
|
|
|
+ nowPart = 6;
|
|
|
+ strContent = strContent + "<br />" + content;
|
|
|
+ QuestionChildAddBo bo1;
|
|
|
+ if(optionsList.size()<6){
|
|
|
+ bo1 = new QuestionChildAddBo();
|
|
|
+ bo1.setOptionsId(6L);
|
|
|
+ bo1.setContent(strContent.replace("F.", ""));
|
|
|
+ optionsList.add(bo1);
|
|
|
+ }else{
|
|
|
+ bo1 = optionsList.get(5);
|
|
|
+ bo1.setContent(strContent.replace("F.", ""));
|
|
|
+ }
|
|
|
}
|
|
|
+ //答案和题型
|
|
|
+ if (content.startsWith("正确答案:")||(nowPart==7&&!isLineStart(content))) {
|
|
|
+ if(nowPart!=7){
|
|
|
+ strContent = "";
|
|
|
+ }
|
|
|
+ answerQuestion = content.replace("正确答案:", "");
|
|
|
+ if (Validator.isEmpty(answerQuestion)) {
|
|
|
+ throw new CustomException("正确答案错误");
|
|
|
+ }
|
|
|
+ nowPart = 7;
|
|
|
+ if (isOption) {
|
|
|
+ //选择题
|
|
|
+ answerQuestion = dealImportAnswer(answerQuestion);
|
|
|
+ if (answerQuestion.length() > 1) {
|
|
|
+ type = 2; //多选
|
|
|
+ } else {
|
|
|
+ type = 1; //单选
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ if ("正确".equals(answerQuestion)) {
|
|
|
+ answerQuestion = "1";
|
|
|
+ type = 3; //判断
|
|
|
+ } else if ("错误".equals(answerQuestion)) {
|
|
|
+ answerQuestion = "0";
|
|
|
+ type = 3;
|
|
|
+ } else {
|
|
|
+ answerQuestion = null;
|
|
|
+ type = 5; //简答题
|
|
|
+ strContent = strContent + "<br />" + content; //答案文本
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
+ }
|
|
|
+ else if (content.startsWith("解题思路")) {
|
|
|
+ if(nowPart!=8){
|
|
|
+ strContent = "";
|
|
|
+ }
|
|
|
+ nowPart = 8;
|
|
|
+ strContent = strContent + "<br />" + content;
|
|
|
+ }
|
|
|
+ else if (content.startsWith("考查考点")) {
|
|
|
+ nowPart = 9;
|
|
|
+ strContent = strContent + "<br />" + content;
|
|
|
+ }
|
|
|
+ else if (content.startsWith("老师解答")) {
|
|
|
+ nowPart = 10;
|
|
|
+ strContent = strContent + "<br />" + content;
|
|
|
+ }
|
|
|
|
|
|
if (Validator.isNotEmpty(content)) {
|
|
|
content = dealTxt(content);
|