Эх сурвалжийг харах

exchange添加获取试卷结构接口

lideyin 5 жил өмнө
parent
commit
e6e6dd1efd

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

@@ -1,7 +1,6 @@
 package cn.com.qmth.examcloud.exchange.outer.api.provider;
 
 import cn.com.qmth.examcloud.commons.exception.StatusException;
-import cn.com.qmth.examcloud.commons.util.JsonUtil;
 import cn.com.qmth.examcloud.commons.util.RegExpUtil;
 import cn.com.qmth.examcloud.core.oe.admin.api.ExamRecordCloudService;
 import cn.com.qmth.examcloud.core.oe.admin.api.bean.PagedToBeMarkExamRecordBean;
@@ -10,18 +9,26 @@ import cn.com.qmth.examcloud.core.oe.admin.api.request.GetPagedToBeMarkExamRecor
 import cn.com.qmth.examcloud.core.oe.admin.api.response.GetPagedToBeMarkExamRecordResp;
 import cn.com.qmth.examcloud.exchange.outer.api.ExamQuestionOuterService;
 import cn.com.qmth.examcloud.exchange.outer.api.bean.*;
+import cn.com.qmth.examcloud.exchange.outer.api.request.OuterGetPaperStructReq;
 import cn.com.qmth.examcloud.exchange.outer.api.request.OuterGetQuestionAnswerReq;
 import cn.com.qmth.examcloud.exchange.outer.api.request.OuterGetSubjectivePaperStructReq;
 import cn.com.qmth.examcloud.exchange.outer.api.request.OuterGetSubjectiveQuestionReq;
+import cn.com.qmth.examcloud.exchange.outer.api.response.OuterGetPaperStructResp;
 import cn.com.qmth.examcloud.exchange.outer.api.response.OuterGetQuestionAnswerResp;
 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.paper.DefaultPaper;
+import cn.com.qmth.examcloud.question.commons.core.paper.DefaultQuestionGroup;
+import cn.com.qmth.examcloud.question.commons.core.paper.DefaultQuestionStructureWrapper;
+import cn.com.qmth.examcloud.question.commons.core.paper.DefaultQuestionUnitWrapper;
 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.cache.CacheHelper;
+import cn.com.qmth.examcloud.support.cache.bean.CourseCacheBean;
+import cn.com.qmth.examcloud.support.cache.bean.ExtractConfigPaperCacheBean;
 import cn.com.qmth.examcloud.support.cache.bean.QuestionAnswerCacheBean;
 import cn.com.qmth.examcloud.support.enums.BlockType;
 import cn.com.qmth.examcloud.support.handler.richText.RichTextHandler;
@@ -204,6 +211,94 @@ public class ExamQuestionOuterServiceProvider extends ControllerSupport implemen
         return resp;
     }
 
+    @ApiOperation(value = "获取试卷结构(题库中的原始试卷结构)", httpMethod = "POST")
+    @ApiResponses({@ApiResponse(code = 200, message = "成功", response = OuterGetQuestionAnswerResp.class),
+            @ApiResponse(code = 500, message = "系统异常(异常信息见响应体)", response = StatusResponse.class)})
+    @PostMapping("/getPaperStruct")
+    @Override
+    public OuterGetPaperStructResp getPaperStruct(@RequestBody OuterGetPaperStructReq req) {
+        if (null == req.getExamId()) {
+            throw new StatusException("103001", "考试记录id不允许为空");
+        }
+
+        if (null == req.getCourseId()) {
+            throw new StatusException("103002", "课程id不允许为空");
+        }
+
+        if (StringUtils.isNullOrEmpty(req.getPaperType())) {
+            throw new StatusException("103003", "试卷类型不允许为空");
+        }
+
+        if (StringUtils.isNullOrEmpty(req.getBasePaperId())) {
+            throw new StatusException("103004", "原始试卷id不允许为空");
+        }
+
+        CourseCacheBean course = CacheHelper.getCourse(req.getCourseId());
+        if (null == course) {
+            throw new StatusException("103005", "课程id不正确");
+        }
+
+        ExtractConfigPaperCacheBean extractConfigPaper = CacheHelper.getExtractConfigPaper(req.getExamId(),
+                course.getCode(), req.getPaperType(), req.getBasePaperId());
+
+        OuterGetPaperStructResp resp = new OuterGetPaperStructResp();
+        if (null != extractConfigPaper.getDefaultPaper()) {
+            resp.setDefaultPaper(transferPaperFrom(extractConfigPaper.getDefaultPaper()));
+        }
+
+        return resp;
+    }
+
+    private DefaultPaperBean transferPaperFrom(DefaultPaper defaultPaper) {
+        DefaultPaperBean defaultPaperBean = new DefaultPaperBean();
+        defaultPaperBean.setFullyObjective(defaultPaper.getFullyObjective());
+        defaultPaperBean.setName(defaultPaper.getName());
+
+        List<DefaultQuestionGroup> qgList = defaultPaper.getQuestionGroupList();
+        List<DefaultQuestionGroupBean> qgBeanList = new ArrayList<>();
+        for (DefaultQuestionGroup dqg : qgList) {
+            DefaultQuestionGroupBean dqgBean = new DefaultQuestionGroupBean();
+            dqgBean.setGroupName(dqg.getGroupName());
+            dqgBean.setGroupScore(dqg.getGroupScore());
+
+            List<DefaultQuestionStructureWrapper> qwList = dqg.getQuestionWrapperList();
+            List<DefaultQuestionStructureWrapperBean> qwBeanList = new ArrayList<>();
+            for (DefaultQuestionStructureWrapper qw : qwList) {
+                DefaultQuestionStructureWrapperBean qwBean = new DefaultQuestionStructureWrapperBean();
+                qwBean.setQuestionId(qw.getQuestionId());
+                qwBean.setVersion(qw.getVersion());
+                qwBean.setQuestionScore(qw.getQuestionScore());
+                qwBean.setLimitedPlayTimes(qw.getLimitedPlayTimes());
+                qwBean.setPlayedTimes(qw.getPlayedTimes());
+                qwBean.setTimeLimit(qw.getTimeLimit());
+
+                List<DefaultQuestionUnitWrapper> quwList = qw.getQuestionUnitWrapperList();
+                List<DefaultQuestionUnitWrapperBean> quwBeanList = new ArrayList<>();
+                for (DefaultQuestionUnitWrapper quw : quwList) {
+                    DefaultQuestionUnitWrapperBean quwBean = new DefaultQuestionUnitWrapperBean();
+                    quwBean.setOptionPermutation(quw.getOptionPermutation());
+                    quwBean.setQuestionScore(quw.getQuestionScore());
+                    quwBean.setQuestionType(quw.getQuestionType() == null ? null : quw.getQuestionType().name());
+                    quwBean.setAnswerType(quw.getAnswerType() == null ? null : quw.getAnswerType().name());
+
+                    quwBeanList.add(quwBean);
+                }
+
+                qwBean.setQuestionUnitWrapperList(quwBeanList);
+
+                qwBeanList.add(qwBean);
+            }
+
+            dqgBean.setQuestionWrapperList(qwBeanList);
+
+            qgBeanList.add(dqgBean);
+        }
+
+        defaultPaperBean.setQuestionGroupList(qgBeanList);
+
+        return defaultPaperBean;
+    }
+
 
     /**
      * 构造满足条件的考试记录集合
@@ -271,35 +366,35 @@ public class ExamQuestionOuterServiceProvider extends ControllerSupport implemen
 
                     int index;
                     if (StringUtils.isNullOrEmpty(firstMatch)) {
-                        index=-1;
-                    }else {
+                        index = -1;
+                    } else {
                         index = stuAnswer.indexOf(firstMatch);
                     }
 
                     //只有文字作答,处理文字
                     if (index == -1) {
                         richTextHandler = RichTextHandlerFactory.getHandler(BlockType.text.name());
-                        formattedStudentAnswer=richTextHandler.handle(stuAnswer);
+                        formattedStudentAnswer = richTextHandler.handle(stuAnswer);
                     } else {
                         //只有图片作答,处理图片
                         if (index == 0) {
                             richTextHandler = RichTextHandlerFactory.getHandler(BlockType.image.name());
-                            formattedStudentAnswer=richTextHandler.handle(stuAnswer);
+                            formattedStudentAnswer = richTextHandler.handle(stuAnswer);
                         }
                         //既有图片又有文字
                         else {
                             //文字部分
-                            String stuAnswer_text=stuAnswer.substring(0,index);
-                            SectionCollectionBean formattedStudentAnswer_text=
+                            String stuAnswer_text = stuAnswer.substring(0, index);
+                            SectionCollectionBean formattedStudentAnswer_text =
                                     RichTextHandlerFactory.getHandler(BlockType.text.name()).handle(stuAnswer_text);
 
                             //图片部分
-                            String stuAnswer_image=stuAnswer.substring(index);
-                            SectionCollectionBean formattedStudentAnswer_image=
+                            String stuAnswer_image = stuAnswer.substring(index);
+                            SectionCollectionBean formattedStudentAnswer_image =
                                     RichTextHandlerFactory.getHandler(BlockType.image.name()).handle(stuAnswer_image);
 
-                            formattedStudentAnswer=new SectionCollectionBean();
-                            List<SectionBean> sections=new ArrayList<>();
+                            formattedStudentAnswer = new SectionCollectionBean();
+                            List<SectionBean> sections = new ArrayList<>();
                             sections.addAll(formattedStudentAnswer_text.getSections());
                             sections.addAll(formattedStudentAnswer_image.getSections());
                             formattedStudentAnswer.setSections(sections);

+ 14 - 0
examcloud-exchange-outer-api/src/main/java/cn/com/qmth/examcloud/exchange/outer/api/ExamQuestionOuterService.java

@@ -1,12 +1,19 @@
 package cn.com.qmth.examcloud.exchange.outer.api;
 
 import cn.com.qmth.examcloud.api.commons.EnterpriseService;
+import cn.com.qmth.examcloud.exchange.outer.api.request.OuterGetPaperStructReq;
 import cn.com.qmth.examcloud.exchange.outer.api.request.OuterGetQuestionAnswerReq;
 import cn.com.qmth.examcloud.exchange.outer.api.request.OuterGetSubjectivePaperStructReq;
 import cn.com.qmth.examcloud.exchange.outer.api.request.OuterGetSubjectiveQuestionReq;
+import cn.com.qmth.examcloud.exchange.outer.api.response.OuterGetPaperStructResp;
 import cn.com.qmth.examcloud.exchange.outer.api.response.OuterGetQuestionAnswerResp;
 import cn.com.qmth.examcloud.exchange.outer.api.response.OuterGetSubjectivePaperStructResp;
 import cn.com.qmth.examcloud.exchange.outer.api.response.OuterGetSubjectiveQuestionResp;
+import io.swagger.annotations.ApiOperation;
+import io.swagger.annotations.ApiResponse;
+import io.swagger.annotations.ApiResponses;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestBody;
 
 
 /**
@@ -40,4 +47,11 @@ public interface ExamQuestionOuterService extends EnterpriseService {
      * @return
      */
     OuterGetQuestionAnswerResp getQuestionAnswer(OuterGetQuestionAnswerReq req);
+
+    /**
+     * 获取试卷结构(题库中的原始试卷结构)
+     * @param req
+     * @return
+     */
+    OuterGetPaperStructResp getPaperStruct(OuterGetPaperStructReq req);
 }

+ 56 - 0
examcloud-exchange-outer-api/src/main/java/cn/com/qmth/examcloud/exchange/outer/api/bean/DefaultPaperBean.java

@@ -0,0 +1,56 @@
+package cn.com.qmth.examcloud.exchange.outer.api.bean;
+
+import java.io.Serializable;
+import java.util.List;
+
+/**
+ * 试卷结构
+ *
+ * @author WANGWEI
+ * @date 2018年8月15日
+ * @Copyright (c) 2018-? http://qmth.com.cn All Rights Reserved.
+ */
+public class DefaultPaperBean implements Serializable {
+
+	private static final long serialVersionUID = -5979287118960427883L;
+
+	/**
+	 * 试卷名称
+	 */
+	private String name;
+
+	/**
+	 * 是否全是客观题
+	 */
+	private Boolean fullyObjective;
+
+	/**
+	 * 分组集合
+	 */
+	private List<DefaultQuestionGroupBean> questionGroupList;
+
+	public String getName() {
+		return name;
+	}
+
+	public void setName(String name) {
+		this.name = name;
+	}
+
+	public Boolean getFullyObjective() {
+		return fullyObjective;
+	}
+
+	public void setFullyObjective(Boolean fullyObjective) {
+		this.fullyObjective = fullyObjective;
+	}
+
+	public List<DefaultQuestionGroupBean> getQuestionGroupList() {
+		return questionGroupList;
+	}
+
+	public void setQuestionGroupList(List<DefaultQuestionGroupBean> questionGroupList) {
+		this.questionGroupList = questionGroupList;
+	}
+
+}

+ 56 - 0
examcloud-exchange-outer-api/src/main/java/cn/com/qmth/examcloud/exchange/outer/api/bean/DefaultQuestionGroupBean.java

@@ -0,0 +1,56 @@
+package cn.com.qmth.examcloud.exchange.outer.api.bean;
+
+import java.io.Serializable;
+import java.util.List;
+
+/**
+ * 题分组集合
+ *
+ * @author WANGWEI
+ * @date 2018年8月15日
+ * @Copyright (c) 2018-? http://qmth.com.cn All Rights Reserved.
+ */
+public class DefaultQuestionGroupBean implements Serializable {
+
+	private static final long serialVersionUID = 2149814711274942645L;
+
+	/**
+	 * 题组名称
+	 */
+	private String groupName;
+
+	/**
+	 * 题包装器集合<br>
+	 */
+	private List<DefaultQuestionStructureWrapperBean> questionWrapperList;
+
+	/**
+	 * 题组总分
+	 */
+	private Double groupScore;
+
+	public String getGroupName() {
+		return groupName;
+	}
+
+	public void setGroupName(String groupName) {
+		this.groupName = groupName;
+	}
+
+	public List<DefaultQuestionStructureWrapperBean> getQuestionWrapperList() {
+		return questionWrapperList;
+	}
+
+	public void setQuestionWrapperList(List<DefaultQuestionStructureWrapperBean> questionWrapperList) {
+		this.questionWrapperList = questionWrapperList;
+	}
+
+	public Double getGroupScore() {
+		return groupScore;
+	}
+
+	public void setGroupScore(Double groupScore) {
+		this.groupScore = groupScore;
+	}
+
+}

+ 109 - 0
examcloud-exchange-outer-api/src/main/java/cn/com/qmth/examcloud/exchange/outer/api/bean/DefaultQuestionStructureWrapperBean.java

@@ -0,0 +1,109 @@
+package cn.com.qmth.examcloud.exchange.outer.api.bean;
+
+import java.io.Serializable;
+import java.util.List;
+
+/**
+ * 题结构包装器
+ *
+ * @author WANGWEI
+ * @date 2018年8月15日
+ * @Copyright (c) 2018-? http://qmth.com.cn All Rights Reserved.
+ */
+public class DefaultQuestionStructureWrapperBean implements Serializable {
+
+	private static final long serialVersionUID = 8423916951155451548L;
+
+	/**
+	 * 题ID
+	 */
+	private String questionId;
+
+	/**
+	 * 版本号
+	 */
+	private String version;
+
+	/**
+	 * 题分数
+	 */
+	private Double questionScore;
+
+	/**
+	 * 限制播放次数
+	 */
+	private Integer limitedPlayTimes;
+
+	/**
+	 * 已播放次数
+	 */
+	private Integer playedTimes;
+
+	/**
+	 * 作答限时
+	 */
+	private Long timeLimit;
+
+	/**
+	 * 题单元包装器
+	 */
+	private List<DefaultQuestionUnitWrapperBean> questionUnitWrapperList;
+
+	public String getQuestionId() {
+		return questionId;
+	}
+
+	public void setQuestionId(String questionId) {
+		this.questionId = questionId;
+	}
+
+	public String getVersion() {
+		return version;
+	}
+
+	public void setVersion(String version) {
+		this.version = version;
+	}
+
+	public Double getQuestionScore() {
+		return questionScore;
+	}
+
+	public void setQuestionScore(Double questionScore) {
+		this.questionScore = questionScore;
+	}
+
+	public Integer getLimitedPlayTimes() {
+		return limitedPlayTimes;
+	}
+
+	public void setLimitedPlayTimes(Integer limitedPlayTimes) {
+		this.limitedPlayTimes = limitedPlayTimes;
+	}
+
+	public Integer getPlayedTimes() {
+		return playedTimes;
+	}
+
+	public void setPlayedTimes(Integer playedTimes) {
+		this.playedTimes = playedTimes;
+	}
+
+	public Long getTimeLimit() {
+		return timeLimit;
+	}
+
+	public void setTimeLimit(Long timeLimit) {
+		this.timeLimit = timeLimit;
+	}
+
+	public List<DefaultQuestionUnitWrapperBean> getQuestionUnitWrapperList() {
+		return questionUnitWrapperList;
+	}
+
+	public void setQuestionUnitWrapperList(
+			List<DefaultQuestionUnitWrapperBean> questionUnitWrapperList) {
+		this.questionUnitWrapperList = questionUnitWrapperList;
+	}
+
+}

+ 67 - 0
examcloud-exchange-outer-api/src/main/java/cn/com/qmth/examcloud/exchange/outer/api/bean/DefaultQuestionUnitWrapperBean.java

@@ -0,0 +1,67 @@
+package cn.com.qmth.examcloud.exchange.outer.api.bean;
+
+import java.io.Serializable;
+
+/**
+ * 题单元包装器
+ *
+ * @author WANGWEI
+ * @date 2018年8月16日
+ * @Copyright (c) 2018-? http://qmth.com.cn All Rights Reserved.
+ */
+public class DefaultQuestionUnitWrapperBean implements Serializable {
+
+	private static final long serialVersionUID = 7584275153456817959L;
+
+	/**
+	 * 选项排序值
+	 */
+	private Integer[] optionPermutation;
+
+	/**
+	 * 题分数
+	 */
+	private Double questionScore;
+
+	/**
+	 * 题型
+	 */
+	private String questionType;
+
+	/**
+	 * 作答类型
+	 */
+	private String answerType;
+
+	public Integer[] getOptionPermutation() {
+		return optionPermutation;
+	}
+
+	public void setOptionPermutation(Integer[] optionPermutation) {
+		this.optionPermutation = optionPermutation;
+	}
+
+	public Double getQuestionScore() {
+		return questionScore;
+	}
+
+	public void setQuestionScore(Double questionScore) {
+		this.questionScore = questionScore;
+	}
+
+	public String getQuestionType() {
+		return questionType;
+	}
+
+	public void setQuestionType(String questionType) {
+		this.questionType = questionType;
+	}
+
+	public String getAnswerType() {
+		return answerType;
+	}
+
+	public void setAnswerType(String answerType) {
+		this.answerType = answerType;
+	}
+}

+ 59 - 0
examcloud-exchange-outer-api/src/main/java/cn/com/qmth/examcloud/exchange/outer/api/request/OuterGetPaperStructReq.java

@@ -0,0 +1,59 @@
+package cn.com.qmth.examcloud.exchange.outer.api.request;
+
+import cn.com.qmth.examcloud.api.commons.exchange.EnterpriseRequest;
+import io.swagger.annotations.ApiModelProperty;
+
+/**
+ * @Description 获取试卷结构
+ * @Author lideyin
+ * @Date 2020/5/25 15:56
+ * @Version 1.0
+ */
+public class OuterGetPaperStructReq extends EnterpriseRequest {
+
+    private static final long serialVersionUID = -8374755306658040184L;
+
+    @ApiModelProperty(value = "考试id", example = "123", required = true)
+    private Long examId;
+
+    @ApiModelProperty(value = "课程id", example = "123", required = true)
+    private Long courseId;
+
+    @ApiModelProperty(value = "卷型", example = "123", required = true)
+    private String paperType;
+
+    @ApiModelProperty(value = "原始试卷id", example = "123", required = true)
+    private String basePaperId;
+
+    public Long getExamId() {
+        return examId;
+    }
+
+    public void setExamId(Long examId) {
+        this.examId = examId;
+    }
+
+    public Long getCourseId() {
+        return courseId;
+    }
+
+    public void setCourseId(Long courseId) {
+        this.courseId = courseId;
+    }
+
+    public String getPaperType() {
+        return paperType;
+    }
+
+    public void setPaperType(String paperType) {
+        this.paperType = paperType;
+    }
+
+    public String getBasePaperId() {
+        return basePaperId;
+    }
+
+    public void setBasePaperId(String basePaperId) {
+        this.basePaperId = basePaperId;
+    }
+}

+ 28 - 0
examcloud-exchange-outer-api/src/main/java/cn/com/qmth/examcloud/exchange/outer/api/response/OuterGetPaperStructResp.java

@@ -0,0 +1,28 @@
+package cn.com.qmth.examcloud.exchange.outer.api.response;
+
+import cn.com.qmth.examcloud.api.commons.exchange.EnterpriseResponse;
+import cn.com.qmth.examcloud.exchange.outer.api.bean.DefaultPaperBean;
+
+/**
+ * @Description 获取试卷结构
+ * @Author lideyin
+ * @Date 2020/5/25 15:40
+ * @Version 1.0
+ */
+public class OuterGetPaperStructResp extends EnterpriseResponse {
+
+    private static final long serialVersionUID = 8290190579593586203L;
+
+    /**
+     * 试卷结构
+     */
+    private DefaultPaperBean defaultPaper;
+
+    public DefaultPaperBean getDefaultPaper() {
+        return defaultPaper;
+    }
+
+    public void setDefaultPaper(DefaultPaperBean defaultPaper) {
+        this.defaultPaper = defaultPaper;
+    }
+}