|
@@ -3,14 +3,18 @@ package com.qmth.cqb.paper.service;
|
|
import java.io.File;
|
|
import java.io.File;
|
|
import java.io.FileOutputStream;
|
|
import java.io.FileOutputStream;
|
|
import java.io.OutputStream;
|
|
import java.io.OutputStream;
|
|
|
|
+import java.math.BigDecimal;
|
|
import java.util.ArrayList;
|
|
import java.util.ArrayList;
|
|
import java.util.Collections;
|
|
import java.util.Collections;
|
|
import java.util.HashMap;
|
|
import java.util.HashMap;
|
|
|
|
+import java.util.HashSet;
|
|
import java.util.List;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
import java.util.Map;
|
|
|
|
+import java.util.Set;
|
|
import java.util.UUID;
|
|
import java.util.UUID;
|
|
import java.util.regex.Pattern;
|
|
import java.util.regex.Pattern;
|
|
|
|
|
|
|
|
+import com.netflix.infix.lang.infix.antlr.EventFilterParser.null_predicate_return;
|
|
import com.qmth.cqb.base.dao.CourseRepo;
|
|
import com.qmth.cqb.base.dao.CourseRepo;
|
|
import com.qmth.cqb.base.model.Course;
|
|
import com.qmth.cqb.base.model.Course;
|
|
import com.qmth.cqb.question.dao.CoursePropertyRepo;
|
|
import com.qmth.cqb.question.dao.CoursePropertyRepo;
|
|
@@ -735,14 +739,14 @@ public class ImportPaperService {
|
|
else if (tmpText.startsWith(ImportPaperMsg.difficulty)) {
|
|
else if (tmpText.startsWith(ImportPaperMsg.difficulty)) {
|
|
// 检测到难度开始段落 difficultyDegree
|
|
// 检测到难度开始段落 difficultyDegree
|
|
String dif = getContent(tmpText, ImportPaperMsg.difficulty);
|
|
String dif = getContent(tmpText, ImportPaperMsg.difficulty);
|
|
- checkDiffculty(difficulty,dif,importPaperCheck,subQuesNum,question);
|
|
|
|
|
|
+ difficulty = checkDiffculty(difficulty,dif,importPaperCheck,subQuesNum,question);
|
|
question.setDifficultyDegree(difficulty);
|
|
question.setDifficultyDegree(difficulty);
|
|
answerStart = false;
|
|
answerStart = false;
|
|
}
|
|
}
|
|
else if (tmpText.startsWith(ImportPaperMsg.publicity)) {
|
|
else if (tmpText.startsWith(ImportPaperMsg.publicity)) {
|
|
// 检测到公安度开始段落
|
|
// 检测到公安度开始段落
|
|
String pub = getContent(tmpText, ImportPaperMsg.publicity);
|
|
String pub = getContent(tmpText, ImportPaperMsg.publicity);
|
|
- checkPublicity(publicity,pub,importPaperCheck,subQuesNum);
|
|
|
|
|
|
+ publicity = checkPublicity(publicity,pub,importPaperCheck,subQuesNum);
|
|
question.setPublicity(publicity);
|
|
question.setPublicity(publicity);
|
|
answerStart = false;
|
|
answerStart = false;
|
|
}
|
|
}
|
|
@@ -766,14 +770,14 @@ public class ImportPaperService {
|
|
}
|
|
}
|
|
|
|
|
|
// 设置预设分数
|
|
// 设置预设分数
|
|
- if (quesScore.matches("^\\d+(\\.\\d+)?$")) {
|
|
|
|
|
|
+ if (quesScore != null && quesScore.matches("^\\d+(\\.\\d+)?$")) {
|
|
question.setScore(Double.parseDouble(quesScore));
|
|
question.setScore(Double.parseDouble(quesScore));
|
|
}
|
|
}
|
|
// 一般大题明细需要设置分数
|
|
// 一般大题明细需要设置分数
|
|
- if (!isNested && quesScore.matches("^\\d+(\\.\\d+)?$")) {
|
|
|
|
|
|
+ if (!isNested && quesScore != null && quesScore.matches("^\\d+(\\.\\d+)?$")) {
|
|
paperDetailUnit.setScore(Double.parseDouble(quesScore));
|
|
paperDetailUnit.setScore(Double.parseDouble(quesScore));
|
|
}
|
|
}
|
|
- //校验小题尾信息是否含有"一节属性","二级属性","难度","公开"
|
|
|
|
|
|
+ //校验小题尾信息是否含有"一节属性","二级属性","难度","公开"
|
|
checkAttributeIsFull(firstProperty,secondProperty,difficulty,publicity,importPaperCheck,subQuesNum);
|
|
checkAttributeIsFull(firstProperty,secondProperty,difficulty,publicity,importPaperCheck,subQuesNum);
|
|
//试题一级属性与二级属性校验
|
|
//试题一级属性与二级属性校验
|
|
checkProperty(firstProperty,secondProperty,importPaperCheck,subQuesNum,paper,quesProperties);
|
|
checkProperty(firstProperty,secondProperty,importPaperCheck,subQuesNum,paper,quesProperties);
|
|
@@ -800,7 +804,11 @@ public class ImportPaperService {
|
|
//一级属性,二级属性都有值
|
|
//一级属性,二级属性都有值
|
|
else if(StringUtils.isNotBlank(firstProperty) && StringUtils.isNotBlank(secondProperty)){
|
|
else if(StringUtils.isNotBlank(firstProperty) && StringUtils.isNotBlank(secondProperty)){
|
|
//根据课程查询所有课程属性树
|
|
//根据课程查询所有课程属性树
|
|
- List<CourseProperty> courseProperties = coursePropertyRepo.findByCourseId(Long.parseLong(paper.getCourse().getId()));
|
|
|
|
|
|
+ List<CourseProperty> courseProperties = coursePropertyRepo.findByCourseCode(paper.getCourse().getCode());
|
|
|
|
+ if(courseProperties == null || courseProperties.size()<1){
|
|
|
|
+ importPaperCheck.setErrorInfo(getQuesNumInfo(importPaperCheck.quesName, subQuesNum)+"中,没有设置课程属性结构,请先设置课程属性结构");
|
|
|
|
+ throw new PaperException(importPaperCheck.errorInfo);
|
|
|
|
+ }
|
|
for(CourseProperty courseProperty:courseProperties){
|
|
for(CourseProperty courseProperty:courseProperties){
|
|
Property propertyParent = new Property(firstProperty,0l,courseProperty.getId());
|
|
Property propertyParent = new Property(firstProperty,0l,courseProperty.getId());
|
|
//查询一级属性是否存在
|
|
//查询一级属性是否存在
|
|
@@ -816,6 +824,8 @@ public class ImportPaperService {
|
|
for(Property proSon:propertieSons){
|
|
for(Property proSon:propertieSons){
|
|
//保存一级和二级属性
|
|
//保存一级和二级属性
|
|
QuesProperty quesProperty = new QuesProperty(proParent, proSon,courseProperty);
|
|
QuesProperty quesProperty = new QuesProperty(proParent, proSon,courseProperty);
|
|
|
|
+ String idNumber = quesProperty.getCoursePropertyName() + "-" + quesProperty.getFirstProperty().getId() + "-" + quesProperty.getSecondProperty().getId();
|
|
|
|
+ quesProperty.setId(idNumber);
|
|
quesProperties.add(quesProperty);
|
|
quesProperties.add(quesProperty);
|
|
}
|
|
}
|
|
}else{
|
|
}else{
|
|
@@ -832,7 +842,11 @@ public class ImportPaperService {
|
|
//一级属性有值,二级属性为空
|
|
//一级属性有值,二级属性为空
|
|
else {
|
|
else {
|
|
//根据课程查询所有课程属性树
|
|
//根据课程查询所有课程属性树
|
|
- List<CourseProperty> courseProperties = coursePropertyRepo.findByCourseId(Long.parseLong(paper.getCourse().getId()));
|
|
|
|
|
|
+ List<CourseProperty> courseProperties = coursePropertyRepo.findByCourseCode(paper.getCourse().getCode());
|
|
|
|
+ if(courseProperties == null || courseProperties.size()<1){
|
|
|
|
+ importPaperCheck.setErrorInfo(getQuesNumInfo(importPaperCheck.quesName, subQuesNum)+"中,没有设置课程属性结构,请先设置课程属性结构");
|
|
|
|
+ throw new PaperException(importPaperCheck.errorInfo);
|
|
|
|
+ }
|
|
for(CourseProperty courseProperty:courseProperties){
|
|
for(CourseProperty courseProperty:courseProperties){
|
|
//查询一级属性
|
|
//查询一级属性
|
|
Property propertyParent = new Property(firstProperty,0l,courseProperty.getId());
|
|
Property propertyParent = new Property(firstProperty,0l,courseProperty.getId());
|
|
@@ -849,6 +863,8 @@ public class ImportPaperService {
|
|
}else {
|
|
}else {
|
|
//保存试题属性
|
|
//保存试题属性
|
|
QuesProperty quesProperty = new QuesProperty(proParent, null,courseProperty);
|
|
QuesProperty quesProperty = new QuesProperty(proParent, null,courseProperty);
|
|
|
|
+ String idNumber = quesProperty.getCoursePropertyName() + "-" + quesProperty.getFirstProperty().getId();
|
|
|
|
+ quesProperty.setId(idNumber);
|
|
quesProperties.add(quesProperty);
|
|
quesProperties.add(quesProperty);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -947,6 +963,7 @@ public class ImportPaperService {
|
|
throw new PaperException(importPaperCheck.errorInfo);
|
|
throw new PaperException(importPaperCheck.errorInfo);
|
|
}
|
|
}
|
|
subQues = new Question();
|
|
subQues = new Question();
|
|
|
|
+ subQues.setId(UUID.randomUUID().toString());
|
|
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()));
|
|
@@ -984,6 +1001,8 @@ public class ImportPaperService {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
question.setSubQuestions(subQuesList);
|
|
question.setSubQuestions(subQuesList);
|
|
|
|
+ // 设置套题主题干的 难度,公开度,一级属性,二级属性
|
|
|
|
+ setAttributes(question,subQuesList);
|
|
// 计算套题总分
|
|
// 计算套题总分
|
|
double totalScore = 0;
|
|
double totalScore = 0;
|
|
List<Double> scoreList = new ArrayList<>();
|
|
List<Double> scoreList = new ArrayList<>();
|
|
@@ -1000,7 +1019,41 @@ public class ImportPaperService {
|
|
paperDetailUnit.setSubScoreList(scoreList);
|
|
paperDetailUnit.setSubScoreList(scoreList);
|
|
}
|
|
}
|
|
|
|
|
|
- /**
|
|
|
|
|
|
+ // 设置套题主题干的 难度,公开度,一级属性,二级属性
|
|
|
|
+ private void setAttributes(Question question,List<Question> subQuesList) {
|
|
|
|
+ if(subQuesList != null && subQuesList.size()>0){
|
|
|
|
+ Double sum = 0.0;
|
|
|
|
+ Boolean publicity = false;
|
|
|
|
+ List<QuesProperty> subQuesProperties = new ArrayList<QuesProperty>();
|
|
|
|
+ for(Question subQuestion:subQuesList){
|
|
|
|
+ //设置一级属性,二级属性
|
|
|
|
+ List<QuesProperty> quesProperties = subQuestion.getQuesProperties();
|
|
|
|
+ if(quesProperties!=null && quesProperties.size()>0){
|
|
|
|
+ for(QuesProperty quesProperty:quesProperties){
|
|
|
|
+ subQuesProperties.add(quesProperty);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ //设置公开度
|
|
|
|
+ if(subQuestion.getPublicity()){
|
|
|
|
+ publicity = true;
|
|
|
|
+ }
|
|
|
|
+ sum = subQuestion.getDifficultyDegree() + sum;
|
|
|
|
+ }
|
|
|
|
+ BigDecimal b = new BigDecimal(sum / (subQuesList.size()));
|
|
|
|
+ Double difficulty = b.setScale(2,BigDecimal.ROUND_HALF_UP).doubleValue();
|
|
|
|
+ //给属性去重
|
|
|
|
+ Set<QuesProperty> ts = new HashSet<QuesProperty>();
|
|
|
|
+ ts.addAll(subQuesProperties);
|
|
|
|
+ subQuesProperties.clear();
|
|
|
|
+ subQuesProperties.addAll(ts);
|
|
|
|
+ question.setDifficultyDegree(difficulty);
|
|
|
|
+ question.setPublicity(publicity);
|
|
|
|
+ question.setQuesProperties(subQuesProperties);
|
|
|
|
+ question.setDifficulty(setDiff(difficulty));
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
* 获取试题类型
|
|
* 获取试题类型
|
|
*
|
|
*
|
|
* @param quesType
|
|
* @param quesType
|
|
@@ -1059,7 +1112,6 @@ public class ImportPaperService {
|
|
|
|
|
|
/**
|
|
/**
|
|
* 获取课程代码
|
|
* 获取课程代码
|
|
- *
|
|
|
|
* @param importPaperCheck
|
|
* @param importPaperCheck
|
|
* @return
|
|
* @return
|
|
*/
|
|
*/
|
|
@@ -1235,7 +1287,7 @@ public class ImportPaperService {
|
|
* @param subQuesNum
|
|
* @param subQuesNum
|
|
* @throws Exception
|
|
* @throws Exception
|
|
*/
|
|
*/
|
|
- private void checkDiffculty(Double difficulty,String tmpText,ImportPaperCheck importPaperCheck,int subQuesNum,Question question)throws Exception{
|
|
|
|
|
|
+ private Double checkDiffculty(Double difficulty,String tmpText,ImportPaperCheck importPaperCheck,int subQuesNum,Question question)throws Exception{
|
|
if(StringUtils.isBlank(tmpText)){
|
|
if(StringUtils.isBlank(tmpText)){
|
|
//如果为空,默认难度0.5
|
|
//如果为空,默认难度0.5
|
|
difficulty = 0.5;
|
|
difficulty = 0.5;
|
|
@@ -1245,14 +1297,19 @@ public class ImportPaperService {
|
|
importPaperCheck.setErrorInfo(getQuesNumInfo(importPaperCheck.quesName, subQuesNum)+"中,试题难度只能是1到10之间整数");
|
|
importPaperCheck.setErrorInfo(getQuesNumInfo(importPaperCheck.quesName, subQuesNum)+"中,试题难度只能是1到10之间整数");
|
|
throw new PaperException(importPaperCheck.errorInfo);
|
|
throw new PaperException(importPaperCheck.errorInfo);
|
|
}else {
|
|
}else {
|
|
- difficulty = Double.parseDouble(tmpText)%10;
|
|
|
|
- if(difficulty>0 && difficulty<0.4){
|
|
|
|
- question.setDifficulty("易");
|
|
|
|
- }else if (difficulty>0.3 && difficulty<0.8) {
|
|
|
|
- question.setDifficulty("中");
|
|
|
|
- }else {
|
|
|
|
- question.setDifficulty("难");
|
|
|
|
- }
|
|
|
|
|
|
+ difficulty = Double.parseDouble(tmpText)/10;
|
|
|
|
+ question.setDifficulty(setDiff(difficulty));
|
|
|
|
+ }
|
|
|
|
+ return difficulty;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private String setDiff(Double difficulty){
|
|
|
|
+ if(difficulty>0 && difficulty<0.4){
|
|
|
|
+ return"难";
|
|
|
|
+ }else if (difficulty>0.3 && difficulty<0.8) {
|
|
|
|
+ return"中";
|
|
|
|
+ }else {
|
|
|
|
+ return"易";
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -1264,11 +1321,11 @@ public class ImportPaperService {
|
|
* @param subQuesNum
|
|
* @param subQuesNum
|
|
* @throws Exception
|
|
* @throws Exception
|
|
*/
|
|
*/
|
|
- private void checkPublicity(Boolean publicity,String tmpText,ImportPaperCheck importPaperCheck,int subQuesNum)throws Exception{
|
|
|
|
|
|
+ private Boolean checkPublicity(Boolean publicity,String tmpText,ImportPaperCheck importPaperCheck,int subQuesNum)throws Exception{
|
|
if(StringUtils.isBlank(tmpText)){
|
|
if(StringUtils.isBlank(tmpText)){
|
|
//如果为空,默认是公开
|
|
//如果为空,默认是公开
|
|
publicity = true;
|
|
publicity = true;
|
|
- }else if(!tmpText.equals("公开") || !tmpText.equals("非公开")){
|
|
|
|
|
|
+ }else if(!tmpText.equals("公开") && !tmpText.equals("非公开")){
|
|
//如果不是公开和非公开,就报错
|
|
//如果不是公开和非公开,就报错
|
|
importPaperCheck.setErrorInfo(getQuesNumInfo(importPaperCheck.quesName, subQuesNum)+"中,试题公开度只能是公开和非公开");
|
|
importPaperCheck.setErrorInfo(getQuesNumInfo(importPaperCheck.quesName, subQuesNum)+"中,试题公开度只能是公开和非公开");
|
|
throw new PaperException(importPaperCheck.errorInfo);
|
|
throw new PaperException(importPaperCheck.errorInfo);
|
|
@@ -1279,6 +1336,7 @@ public class ImportPaperService {
|
|
publicity = true;
|
|
publicity = true;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+ return publicity;
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|