he2802 пре 2 година
родитељ
комит
11342987a0

+ 91 - 1
zhongzheng-system/src/main/java/com/zhongzheng/modules/bank/service/impl/QuestionServiceImpl.java

@@ -872,9 +872,66 @@ public class QuestionServiceImpl extends ServiceImpl<QuestionMapper, Question> i
         List<QuestionAddBo> attList = new ArrayList<>();
         List<QuestionAddBo> nqList = new ArrayList<>();
         boolean isAnLi = false; // 是否案例题
-    //    Map<String,Object> dataList =
+        Map<String,Object> idMap = new HashMap<>();
+        int startIndex = 0;
         for (QuestionImportV3 question : questionList) {
+            boolean hasError = false;
+            QuestionAddBo bo = new QuestionAddBo();
+            Integer type = null; //题目类型
+            boolean isFirst = true;
+            type = findTypeV3(question.getType());
+            if(!idMap.containsKey(question.getId())){
+                idMap.put(question.getId(),question.getId());
+                //题目主体
+                bo.setType(type);
+                bo.setContent(question.getContent());
+                bo.setAnalysisContent(question.getAnalysisContent());
+                if(Validator.isEmpty(type)){
+                    question.setCause("题目类型错误");
+                    errorList.add(question);
+                    hasError = true;
+                    break;
+                }
+                if(type==1||type==2){ //单选或多选
+                    Map<String,Object> rs = getOptionsListV3(startIndex,questionList,type);
+                    bo.setOptionsList((List<QuestionChildAddBo>)rs.get("optionsList"));
+                    bo.setAnswerQuestion((String) rs.get("answerStr"));
+                }
+                if(type==3){ //判断题
+                    if(question.getOption().equals("正确")&&question.getAnswer().equals("是")){
+                        bo.setAnswerQuestion("1");
+                    }
+                    else if(question.getOption().equals("错误")&&question.getAnswer().equals("否")){
+                        bo.setAnswerQuestion("1");
+                    }
+                    else{
+                        bo.setAnswerQuestion("0");
+                    }
+                }
+                if(type==4){
+                    isAnLi = true;
+                }
+                if(hasError){
+                    continue;
+                }
+                if(isAnLi){
+                    bo.setJsonStr(JSON.toJSONString(attList));
+                }
+                bo.setStatus(1);
+                bo.setPrefixName(question.getPrefixName());
+                bo.setCreateBy(operName);
+                bo.setImportNo(importNo);
+                bo.setPublishStatus(1);
+                bo.setImportSort(nowTime + i); //导入时间从小到大排
+                bo.setCreateTime(nowTime); //从大到小排
+                nqList.add(bo);
+                attList.clear();
+                isFirst = true;
+                isAnLi = false;
+                i++;
 
+            }
+            startIndex++;
         }
         map.put("errorList",errorList);
         map.put("questionList",nqList);
@@ -915,6 +972,39 @@ public class QuestionServiceImpl extends ServiceImpl<QuestionMapper, Question> i
         return map;
     }
 
+    private Map<String,Object> getOptionsListV3(int startIndex,List<QuestionImportV3> list,int type){
+        Map<String,Object> map = new HashMap<>();
+        String answerQuestion = "";
+        List<QuestionChildAddBo> optionsList = new ArrayList<>(); //题目选项
+        List<Long> answerList = new ArrayList<>(); //答案选项
+        Long j = 1L;
+        String tempTxt = list.get(startIndex).getContent();
+        for(int i = startIndex;i<list.size();i++){
+            QuestionImportV3 entity = list.get(i);
+            if(Validator.isNotEmpty(entity.getContent())&&i>startIndex){
+                if(!tempTxt.equals(entity.getContent())){
+                    break;
+                }
+            }
+            if(Validator.isEmpty(entity.getOption())){
+                continue;
+            }
+            QuestionChildAddBo addBo = new QuestionChildAddBo();
+            addBo.setContent(entity.getOption());
+            addBo.setOptionsId(j);
+            optionsList.add(addBo);
+            if("是".equals(entity.getAnswer())){
+                answerList.add(j);
+                /*if(type==1){ //单选
+                    break;
+                }*/
+            }
+            j++;
+        }
+        map.put("optionsList",optionsList);
+        map.put("answerStr",ToolsUtils.join(",", answerList));
+        return map;
+    }
 
 
     @Override