|
@@ -1,17 +1,23 @@
|
|
|
package cn.com.qmth.examcloud.core.questions.api.controller;
|
|
|
|
|
|
+import cn.com.qmth.examcloud.api.commons.enums.ExamType;
|
|
|
import cn.com.qmth.examcloud.api.commons.security.bean.User;
|
|
|
import cn.com.qmth.examcloud.commons.exception.StatusException;
|
|
|
import cn.com.qmth.examcloud.core.questions.api.request.GetDefaultQuesionReq;
|
|
|
import cn.com.qmth.examcloud.core.questions.api.request.GetDefaultQuesionsReq;
|
|
|
import cn.com.qmth.examcloud.core.questions.api.request.GetQuestionListReq;
|
|
|
import cn.com.qmth.examcloud.core.questions.api.request.GetQuestionReq;
|
|
|
+import cn.com.qmth.examcloud.core.questions.dao.entity.ExtractConfig;
|
|
|
import cn.com.qmth.examcloud.core.questions.service.ExtractConfigProviderService;
|
|
|
+import cn.com.qmth.examcloud.core.questions.service.ExtractConfigService;
|
|
|
import cn.com.qmth.examcloud.core.questions.service.QuestionProviderService;
|
|
|
import cn.com.qmth.examcloud.question.commons.core.question.DefaultQuestion;
|
|
|
+import cn.com.qmth.examcloud.question.commons.core.question.DefaultQuestionStructure;
|
|
|
+import cn.com.qmth.examcloud.question.commons.core.question.DefaultQuestionUnit;
|
|
|
import cn.com.qmth.examcloud.support.handler.QuestionBodyHandler;
|
|
|
import cn.com.qmth.examcloud.web.support.ControllerSupport;
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
+import org.apache.commons.collections4.CollectionUtils;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
@@ -43,6 +49,9 @@ public class DefaultQuesionController extends ControllerSupport {
|
|
|
@Autowired
|
|
|
private ExtractConfigProviderService extractConfigExamService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private ExtractConfigService extractConfigService;
|
|
|
+
|
|
|
@ApiOperation(value = "外部接口保存单个试题", notes = "外部接口保存单个试题")
|
|
|
@PostMapping("/save")
|
|
|
public ResponseEntity<Object> save(@RequestBody GetDefaultQuesionReq req) {
|
|
@@ -102,22 +111,25 @@ public class DefaultQuesionController extends ControllerSupport {
|
|
|
|
|
|
@ApiOperation(value = "查询试题详细信息(管理端)")
|
|
|
@PostMapping("/question/detail")
|
|
|
- public ResponseEntity<Object> findForWebAdmin(@RequestBody GetQuestionReq questionReq) {
|
|
|
- DefaultQuestion defaultQuestion = this.getDefaultQuestion(questionReq, "webAdmin");
|
|
|
+ public ResponseEntity<Object> findForWebAdmin(@RequestBody GetQuestionReq req) {
|
|
|
+ DefaultQuestion defaultQuestion = this.getDefaultQuestion(req, "webAdmin");
|
|
|
return new ResponseEntity<>(defaultQuestion, HttpStatus.OK);
|
|
|
}
|
|
|
|
|
|
@ApiOperation(value = "查询试题详细信息(Web版客户端)")
|
|
|
@PostMapping("/question")
|
|
|
- public ResponseEntity<Object> findForWebClient(@RequestBody GetQuestionReq questionReq) {
|
|
|
- DefaultQuestion defaultQuestion = this.getDefaultQuestion(questionReq, "webClient");
|
|
|
+ public ResponseEntity<Object> findForWebClient(@RequestBody GetQuestionReq req) {
|
|
|
+ DefaultQuestion defaultQuestion = this.getDefaultQuestion(req, "webClient");
|
|
|
+ this.handeQuestionAnswer(req.getExamId(), req.getCourseCode(), defaultQuestion);
|
|
|
+
|
|
|
return new ResponseEntity<>(defaultQuestion, HttpStatus.OK);
|
|
|
}
|
|
|
|
|
|
@ApiOperation(value = "查询试题详细信息(C版客户端)")
|
|
|
@PostMapping("/question/for/client")
|
|
|
- public ResponseEntity<Object> findForClient(@RequestBody GetQuestionReq questionReq) {
|
|
|
- DefaultQuestion defaultQuestion = this.getDefaultQuestion(questionReq, "pcClient");
|
|
|
+ public ResponseEntity<Object> findForPcClient(@RequestBody GetQuestionReq req) {
|
|
|
+ DefaultQuestion defaultQuestion = this.getDefaultQuestion(req, "pcClient");
|
|
|
+ this.handeQuestionAnswer(req.getExamId(), req.getCourseCode(), defaultQuestion);
|
|
|
|
|
|
// 将题干、选项等 HTML结构转换为“富文本”JSON结构
|
|
|
QuestionBodyHandler.convertRichText(defaultQuestion);
|
|
@@ -146,4 +158,40 @@ public class DefaultQuesionController extends ControllerSupport {
|
|
|
req.getQuestionId(), fromBy);
|
|
|
}
|
|
|
|
|
|
+ private void handeQuestionAnswer(Long examId, String courseCode, DefaultQuestion defaultQuestion) {
|
|
|
+ ExtractConfig extractConfig = extractConfigService.findConfig(new ExtractConfig(examId, courseCode));
|
|
|
+
|
|
|
+ boolean hideAnswer = false;
|
|
|
+ if (extractConfig == null) {
|
|
|
+ // 不存在调卷规则,则业务数据不正常,屏蔽答案
|
|
|
+ hideAnswer = true;
|
|
|
+ log.warn("$$$异常行为,获取不存在调卷规则的试题敏感数据!questionId:{}", defaultQuestion.getId());
|
|
|
+ } else {
|
|
|
+ if (ExamType.ONLINE.name().equals(extractConfig.getExamType())
|
|
|
+ || ExamType.ONLINE_HOMEWORK.name().equals(extractConfig.getExamType())) {
|
|
|
+ // 目前除了“练习”,“在线考试、在线作业”在学生端使用中不需要显示答案
|
|
|
+ hideAnswer = true;
|
|
|
+ log.warn("$$$异常行为,获取考试类型为{}的试题敏感数据!questionId:{}", extractConfig.getExamType(), defaultQuestion.getId());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!hideAnswer) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ DefaultQuestionStructure structure = defaultQuestion.getMasterVersion();
|
|
|
+ if (structure == null) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ List<DefaultQuestionUnit> questionUnits = structure.getQuestionUnitList();
|
|
|
+ if (CollectionUtils.isEmpty(questionUnits)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ for (DefaultQuestionUnit questionUnit : questionUnits) {
|
|
|
+ // 清空答案
|
|
|
+ questionUnit.setRightAnswer(null);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
}
|