deason 5 éve
szülő
commit
4953d8e3d2

+ 54 - 11
examcloud-exchange-outer-api-provider/src/main/java/cn/com/qmth/examcloud/exchange/outer/api/provider/ExamQuestionOuterServiceProvider.java

@@ -14,17 +14,20 @@ import cn.com.qmth.examcloud.exchange.outer.api.request.OuterGetSubjectiveQuesti
 import cn.com.qmth.examcloud.exchange.outer.api.response.OuterGetScoreQueueTopResp;
 import cn.com.qmth.examcloud.exchange.outer.api.response.OuterGetSubjectivePaperStructResp;
 import cn.com.qmth.examcloud.exchange.outer.api.response.OuterGetSubjectiveQuestionResp;
+import cn.com.qmth.examcloud.exchange.outer.service.OutletPaperStructService;
+import cn.com.qmth.examcloud.exchange.outer.service.bean.OuterCourseBean;
+import cn.com.qmth.examcloud.exchange.outer.service.bean.OuterQuestionBean;
 import cn.com.qmth.examcloud.question.commons.core.question.AnswerType;
 import cn.com.qmth.examcloud.question.commons.core.question.QuestionType;
 import cn.com.qmth.examcloud.support.helper.ExamCacheTransferHelper;
 import cn.com.qmth.examcloud.web.support.ControllerSupport;
 import cn.com.qmth.examcloud.web.support.StatusResponse;
-import com.google.common.collect.Maps;
 import com.mysql.cj.util.StringUtils;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
 import io.swagger.annotations.ApiResponse;
 import io.swagger.annotations.ApiResponses;
+import org.apache.commons.collections.CollectionUtils;
 import org.jsoup.Jsoup;
 import org.jsoup.nodes.Document;
 import org.jsoup.nodes.Element;
@@ -55,21 +58,60 @@ public class ExamQuestionOuterServiceProvider extends ControllerSupport implemen
     private static final long serialVersionUID = 7607495598308348018L;
 
     @Autowired
-    ExamRecordCloudService examRecordCloudService;
+    private ExamRecordCloudService examRecordCloudService;
 
-    /**
-     * 获取主观题试卷结构
-     *
-     * @param req
-     * @return
-     */
+    @Autowired
+    private OutletPaperStructService outletPaperStructService;
+
+    @Override
     @ApiOperation(value = "获取主观题试卷结构", httpMethod = "POST")
     @ApiResponses({@ApiResponse(code = 200, message = "成功", response = OuterGetScoreQueueTopResp.class),
             @ApiResponse(code = 500, message = "系统异常(异常信息见响应体)", response = StatusResponse.class)})
     @PostMapping("/getSubjectivePaperStruct")
-    @Override
     public OuterGetSubjectivePaperStructResp getSubjectivePaperStruct(OuterGetSubjectivePaperStructReq req) {
-        return null;
+        if (req.getExamId() == null) {
+            throw new StatusException("101201", "考试ID不能为空");
+        }
+
+        // 获取考试相关联的课程列表
+        List<OuterCourseBean> courses = outletPaperStructService.getExamCourses(req.getExamId());
+        if (CollectionUtils.isEmpty(courses)) {
+            log.warn(String.format("getExamCourses is empty, examId = %s", req.getExamId()));
+            throw new StatusException("101202", "考试相关的课程列表为空");
+        }
+
+        List<OuterSubjectivePaperStructBean> paperStructList = new ArrayList<>();
+        for (OuterCourseBean course : courses) {
+            OuterSubjectivePaperStructBean paperStruct = new OuterSubjectivePaperStructBean();
+            paperStruct.setExamId(req.getExamId());
+            paperStruct.setSubjectCode(course.getCode());
+            paperStruct.setSubjectName(course.getName());
+
+            // 根据考试和课程获取调卷规则下试卷的试题列表
+            List<OuterQuestionBean> questions = outletPaperStructService.getPaperStructQuestions(req.getExamId(), course.getCode());
+            if (CollectionUtils.isEmpty(questions)) {
+                // 当前考试和课程对应的调卷规则不存在时,则获取不到试卷试题
+                log.warn(String.format("getPaperStructQuestions is empty, examId = %s, courseCode = %s", req.getExamId(), course.getCode()));
+                paperStruct.setQuestionList(new ArrayList<>());
+                continue;
+            }
+
+            List<OuterSubjectiveQuestionBean> questionList = new ArrayList<>();
+            for (OuterQuestionBean question : questions) {
+                OuterSubjectiveQuestionBean newQuestion = new OuterSubjectiveQuestionBean();
+                newQuestion.setMainNumber(question.getMainNumber());
+                newQuestion.setMainTitle(question.getMainTitle());
+                newQuestion.setSubNumber(question.getSubNumber());
+                newQuestion.setTotalScore(question.getTotalScore());
+                questionList.add(newQuestion);
+            }
+
+            paperStruct.setQuestionList(questionList);
+        }
+
+        OuterGetSubjectivePaperStructResp resp = new OuterGetSubjectivePaperStructResp();
+        resp.setPaperStructList(paperStructList);
+        return resp;
     }
 
     @ApiOperation(value = "获取主观题作答结果", httpMethod = "POST")
@@ -241,7 +283,7 @@ public class ExamQuestionOuterServiceProvider extends ControllerSupport implemen
                             blockBean.setParam(paramMap);
                         }
 
-                        blockBeanList.add (blockBean);
+                        blockBeanList.add(blockBean);
                     }
 
                 }
@@ -330,6 +372,7 @@ public class ExamQuestionOuterServiceProvider extends ControllerSupport implemen
 
     /**
      * 单个答案再次格式化,去除地址中的多余后缀
+     *
      * @param answerType
      * @param studentAnswer
      * @return