|
@@ -17,6 +17,7 @@ import com.qmth.cqb.utils.exception.PaperException;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.nlpcn.commons.lang.util.StringUtil;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.data.domain.Example;
|
|
|
import org.springframework.data.domain.Page;
|
|
|
import org.springframework.data.domain.PageImpl;
|
|
@@ -49,6 +50,7 @@ import com.qmth.cqb.question.dao.QuesRepo;
|
|
|
import com.qmth.cqb.question.model.QuesOption;
|
|
|
import com.qmth.cqb.question.model.Question;
|
|
|
import com.qmth.cqb.question.model.QuestionBak;
|
|
|
+import com.qmth.cqb.question.model.QuestionType;
|
|
|
import com.qmth.cqb.question.service.QuesService;
|
|
|
import com.qmth.cqb.utils.BeanCopierUtil;
|
|
|
import com.qmth.cqb.utils.CommonUtils;
|
|
@@ -99,6 +101,9 @@ public class PaperService {
|
|
|
|
|
|
@Autowired
|
|
|
private MongoTemplate mongoTemplate;
|
|
|
+
|
|
|
+ @Value("${upyun.radioType}")
|
|
|
+ protected String radioType;
|
|
|
|
|
|
/**
|
|
|
* 查询所有已导入试卷
|
|
@@ -856,4 +861,90 @@ public class PaperService {
|
|
|
}
|
|
|
return true;
|
|
|
}
|
|
|
+
|
|
|
+ public Map<String, String> checkRadioFile(String paperId,List<String> filesName){
|
|
|
+ Map<String, String> messageMap = new HashMap<String, String>();
|
|
|
+ //判断文件名中格式是否正确
|
|
|
+ for(String fileName: filesName){
|
|
|
+ String fileTpye[] = fileName.split("\\.");
|
|
|
+ String fileType = fileTpye[fileTpye.length-1];
|
|
|
+ if(radioType.indexOf(fileType)<0){
|
|
|
+ messageMap.put("errorMsg", fileName+"文件格式不对");
|
|
|
+ return messageMap;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //根据试卷id,查询该试卷
|
|
|
+ Paper paper = paperRepo.findOne(paperId);
|
|
|
+ //根据试卷查询所有的小题
|
|
|
+ List<PaperDetailUnit> paperDetailUnits = paperDetailUnitRepo.findByPaper(paper);
|
|
|
+ String names = "";
|
|
|
+ for(PaperDetailUnit paperDetailUnit:paperDetailUnits){
|
|
|
+ names = names + paperDetailUnit.getNumber().toString() + ",";
|
|
|
+ }
|
|
|
+ for(String fileName: filesName){
|
|
|
+ String fileNames[] = fileName.split("_");
|
|
|
+ //先判断小题号是否正确
|
|
|
+ String fileNameFirst = fileNames[0];
|
|
|
+ if(!names.contains(fileNameFirst)){
|
|
|
+ messageMap.put("errorMsg", fileName + "文件,试卷中没有对应的小题");
|
|
|
+ return messageMap;
|
|
|
+ }
|
|
|
+ //再判断题干中是否存在ABCD
|
|
|
+ String fileNameSecond = fileNames[1];
|
|
|
+ if(fileNameSecond.equals("1")){
|
|
|
+ if(fileNames.length>3){
|
|
|
+ Matcher m = Pattern.compile(".*[a-zA-Z]+.*").matcher(fileNames[2]);
|
|
|
+ if(m.matches()){
|
|
|
+ messageMap.put("errorMsg", fileName + "文件名称不对,文件名为题干,但存在选项");
|
|
|
+ return messageMap;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //判断选项
|
|
|
+ else if(fileNameSecond.equals("2")){
|
|
|
+ messageMap = checkOptions(paperDetailUnits, fileNames, fileName);
|
|
|
+ if(messageMap != null){
|
|
|
+ return messageMap;
|
|
|
+ }
|
|
|
+ continue;
|
|
|
+ }else {
|
|
|
+ messageMap.put("errorMsg", fileName + "文件名称不对,无法识别为题干或选项 ");
|
|
|
+ return messageMap;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ messageMap.put("message", "OK!");
|
|
|
+ return messageMap;
|
|
|
+ }
|
|
|
+
|
|
|
+ //判断选项
|
|
|
+ public Map<String, String> checkOptions(List<PaperDetailUnit> paperDetailUnits,String fileNames[],String fileName){
|
|
|
+ Map<String, String> messageMap = new HashMap<String, String>();
|
|
|
+ for(PaperDetailUnit paperDetailUnit:paperDetailUnits){
|
|
|
+ if(paperDetailUnit.getNumber().toString().equals(fileNames[0])){
|
|
|
+ //判断是否为选择题
|
|
|
+ if(paperDetailUnit.getQuestionType() != QuesStructType.SINGLE_ANSWER_QUESTION
|
|
|
+ &&paperDetailUnit.getQuestionType() != QuesStructType.MULTIPLE_ANSWER_QUESTION){
|
|
|
+ Matcher m = Pattern.compile(".*[a-zA-Z]+.*").matcher(fileNames[2]);
|
|
|
+ if(m.matches()){
|
|
|
+ messageMap.put("errorMsg", fileName + "文件名称有误,题目不是选择题");
|
|
|
+ return messageMap;
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ }else {
|
|
|
+ List<QuesOption> options = paperDetailUnit.getQuestion().getQuesOptions();
|
|
|
+ String option = "";
|
|
|
+ for(QuesOption quesOption:options){
|
|
|
+ option = option + quesOption.getNumber()+",";
|
|
|
+ }
|
|
|
+ Integer integer = CommonUtils.characterToNumber(fileNames[2]);
|
|
|
+ if(!option.contains(integer.toString())){
|
|
|
+ messageMap.put("errorMsg", fileName + "文件名称有误,题目中没有对应的"+fileNames[2]+"选项");
|
|
|
+ return messageMap;
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
}
|