|
@@ -3,16 +3,35 @@ package cn.com.qmth.examcloud.core.oe.admin.api.provider;
|
|
import cn.com.qmth.examcloud.core.oe.admin.api.ExamRecordQuestionsCloudService;
|
|
import cn.com.qmth.examcloud.core.oe.admin.api.ExamRecordQuestionsCloudService;
|
|
import cn.com.qmth.examcloud.core.oe.admin.api.bean.QuerySubjectiveAnswerBean;
|
|
import cn.com.qmth.examcloud.core.oe.admin.api.bean.QuerySubjectiveAnswerBean;
|
|
import cn.com.qmth.examcloud.core.oe.admin.api.bean.SaveSubjectiveQuestionScoreBean;
|
|
import cn.com.qmth.examcloud.core.oe.admin.api.bean.SaveSubjectiveQuestionScoreBean;
|
|
|
|
+import cn.com.qmth.examcloud.core.oe.admin.api.bean.SubjectiveAnswerBean;
|
|
|
|
+import cn.com.qmth.examcloud.core.oe.admin.api.request.GetSubjectiveAnswerReq;
|
|
import cn.com.qmth.examcloud.core.oe.admin.api.request.QuerySubjectiveAnswerListReq;
|
|
import cn.com.qmth.examcloud.core.oe.admin.api.request.QuerySubjectiveAnswerListReq;
|
|
import cn.com.qmth.examcloud.core.oe.admin.api.request.SaveSubjectiveQuestionScoreReq;
|
|
import cn.com.qmth.examcloud.core.oe.admin.api.request.SaveSubjectiveQuestionScoreReq;
|
|
|
|
+import cn.com.qmth.examcloud.core.oe.admin.api.response.GetSubjectiveAnswerResp;
|
|
import cn.com.qmth.examcloud.core.oe.admin.api.response.QuerySubjectiveAnswerListResp;
|
|
import cn.com.qmth.examcloud.core.oe.admin.api.response.QuerySubjectiveAnswerListResp;
|
|
import cn.com.qmth.examcloud.core.oe.admin.service.ExamRecordQuestionsService;
|
|
import cn.com.qmth.examcloud.core.oe.admin.service.ExamRecordQuestionsService;
|
|
import cn.com.qmth.examcloud.core.oe.admin.service.bean.SubjectiveQuestionScoreInfo;
|
|
import cn.com.qmth.examcloud.core.oe.admin.service.bean.SubjectiveQuestionScoreInfo;
|
|
import cn.com.qmth.examcloud.core.oe.common.base.utils.Check;
|
|
import cn.com.qmth.examcloud.core.oe.common.base.utils.Check;
|
|
import cn.com.qmth.examcloud.core.oe.common.entity.ExamQuestionEntity;
|
|
import cn.com.qmth.examcloud.core.oe.common.entity.ExamQuestionEntity;
|
|
|
|
+import cn.com.qmth.examcloud.core.oe.common.entity.ExamRecordDataEntity;
|
|
|
|
+import cn.com.qmth.examcloud.core.oe.common.entity.ExamRecordQuestionsEntity;
|
|
|
|
+import cn.com.qmth.examcloud.core.oe.common.repository.ExamRecordDataRepo;
|
|
|
|
+import cn.com.qmth.examcloud.core.oe.common.repository.ExamRecordQuestionsRepo;
|
|
|
|
+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.web.helpers.GlobalHelper;
|
|
import cn.com.qmth.examcloud.web.support.ControllerSupport;
|
|
import cn.com.qmth.examcloud.web.support.ControllerSupport;
|
|
|
|
+import cn.com.qmth.examcloud.web.support.SpringContextHolder;
|
|
|
|
+import com.google.common.collect.Lists;
|
|
|
|
+import com.mysql.cj.util.StringUtils;
|
|
import io.swagger.annotations.Api;
|
|
import io.swagger.annotations.Api;
|
|
import io.swagger.annotations.ApiOperation;
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
|
+import org.jsoup.Jsoup;
|
|
|
|
+import org.jsoup.nodes.Document;
|
|
|
|
+import org.jsoup.nodes.Element;
|
|
|
|
+import org.jsoup.select.Elements;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.web.bind.annotation.PostMapping;
|
|
import org.springframework.web.bind.annotation.PostMapping;
|
|
import org.springframework.web.bind.annotation.RequestBody;
|
|
import org.springframework.web.bind.annotation.RequestBody;
|
|
@@ -20,70 +39,186 @@ import org.springframework.web.bind.annotation.RequestMapping;
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.ArrayList;
|
|
|
|
+import java.util.Arrays;
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
+import java.util.stream.Stream;
|
|
|
|
|
|
/**
|
|
/**
|
|
- *
|
|
|
|
- * @author chenken
|
|
|
|
- * @date 2018年9月27日 上午11:02:55
|
|
|
|
- * @company QMTH
|
|
|
|
|
|
+ * @author chenken
|
|
|
|
+ * @date 2018年9月27日 上午11:02:55
|
|
|
|
+ * @company QMTH
|
|
* @description 学生作答答案相关接口
|
|
* @description 学生作答答案相关接口
|
|
*/
|
|
*/
|
|
@Api(tags = "学生作答答案相关接口")
|
|
@Api(tags = "学生作答答案相关接口")
|
|
@RestController
|
|
@RestController
|
|
@RequestMapping("${$rmp.cloud.oe}/examRecordQuestions")
|
|
@RequestMapping("${$rmp.cloud.oe}/examRecordQuestions")
|
|
-public class ExamRecordQuestionsCloudServiceProvider extends ControllerSupport implements ExamRecordQuestionsCloudService{
|
|
|
|
-
|
|
|
|
- private static final long serialVersionUID = -1058894529829651231L;
|
|
|
|
-
|
|
|
|
- @Autowired
|
|
|
|
- private ExamRecordQuestionsService examRecordQuestionsService;
|
|
|
|
-
|
|
|
|
- /**
|
|
|
|
- * 阅卷获取考试记录主观题答案信息
|
|
|
|
- */
|
|
|
|
- @Override
|
|
|
|
- @ApiOperation(value = "阅卷获取考试记录主观题答案信息")
|
|
|
|
- @PostMapping("/querySubjectiveAnswerList")
|
|
|
|
- public QuerySubjectiveAnswerListResp querySubjectiveAnswerList(@RequestBody QuerySubjectiveAnswerListReq req) {
|
|
|
|
- List<ExamQuestionEntity> examQuestionList = examRecordQuestionsService.querySubjectiveAnswerList(req.getExamRecordDataId());
|
|
|
|
- QuerySubjectiveAnswerListResp resp = new QuerySubjectiveAnswerListResp();
|
|
|
|
- List<QuerySubjectiveAnswerBean> querySubjectiveAnswerBeanList = new ArrayList<QuerySubjectiveAnswerBean>();
|
|
|
|
- for(ExamQuestionEntity examQuestionEntity:examQuestionList){
|
|
|
|
- QuerySubjectiveAnswerBean querySubjectiveAnswerBean = new QuerySubjectiveAnswerBean();
|
|
|
|
- querySubjectiveAnswerBean.setExamRecordDataId(examQuestionEntity.getExamRecordDataId());
|
|
|
|
- querySubjectiveAnswerBean.setMainNumber(examQuestionEntity.getMainNumber());
|
|
|
|
- querySubjectiveAnswerBean.setOrder(examQuestionEntity.getOrder());
|
|
|
|
- querySubjectiveAnswerBean.setQuestionId(examQuestionEntity.getQuestionId());
|
|
|
|
- querySubjectiveAnswerBean.setStudentAnswer(examQuestionEntity.getStudentAnswer());
|
|
|
|
- querySubjectiveAnswerBean.setAnswerType(examQuestionEntity.getAnswerType());
|
|
|
|
- querySubjectiveAnswerBeanList.add(querySubjectiveAnswerBean);
|
|
|
|
- }
|
|
|
|
- resp.setQuerySubjectiveAnswerBeanList(querySubjectiveAnswerBeanList);
|
|
|
|
- return resp;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- @Override
|
|
|
|
- @ApiOperation(value = "阅卷回传主观题得分")
|
|
|
|
- @PostMapping("/saveSubjectiveQuestionScore")
|
|
|
|
- public void saveSubjectiveQuestionScore(@RequestBody SaveSubjectiveQuestionScoreReq req) {
|
|
|
|
- Check.isNull(req.getExamRecordDataId(), "examRecordDataId 不能为空");
|
|
|
|
- List<SaveSubjectiveQuestionScoreBean> saveSubjectiveQuestionScoreList = req.getSaveSubjectiveQuestionScoreList();
|
|
|
|
- if(saveSubjectiveQuestionScoreList == null || saveSubjectiveQuestionScoreList.size() == 0){
|
|
|
|
- return;
|
|
|
|
- }
|
|
|
|
- long examRecordDataId = req.getExamRecordDataId();
|
|
|
|
- List<SubjectiveQuestionScoreInfo> subjectiveQuestionScoreInfoList = new ArrayList<SubjectiveQuestionScoreInfo>();
|
|
|
|
- for(SaveSubjectiveQuestionScoreBean bean:saveSubjectiveQuestionScoreList){
|
|
|
|
- SubjectiveQuestionScoreInfo info = new SubjectiveQuestionScoreInfo();
|
|
|
|
- info.setExamRecordDataId(bean.getExamRecordDataId());
|
|
|
|
- info.setOrder(bean.getOrder());
|
|
|
|
- info.setQuestionId(bean.getQuestionId());
|
|
|
|
- info.setScore(bean.getScore());
|
|
|
|
- subjectiveQuestionScoreInfoList.add(info);
|
|
|
|
- }
|
|
|
|
- examRecordQuestionsService.saveSubjectiveQuestionScore(examRecordDataId, subjectiveQuestionScoreInfoList);
|
|
|
|
-
|
|
|
|
- }
|
|
|
|
|
|
+public class ExamRecordQuestionsCloudServiceProvider extends ControllerSupport implements ExamRecordQuestionsCloudService {
|
|
|
|
|
|
|
|
+ private static final long serialVersionUID = -1058894529829651231L;
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ private ExamRecordQuestionsService examRecordQuestionsService;
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ private ExamRecordDataRepo examRecordDataRepo;
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ private ExamRecordQuestionsRepo examRecordQuestionsRepo;
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 阅卷获取考试记录主观题答案信息
|
|
|
|
+ */
|
|
|
|
+ @Override
|
|
|
|
+ @ApiOperation(value = "阅卷获取考试记录主观题答案信息")
|
|
|
|
+ @PostMapping("/querySubjectiveAnswerList")
|
|
|
|
+ public QuerySubjectiveAnswerListResp querySubjectiveAnswerList(@RequestBody QuerySubjectiveAnswerListReq req) {
|
|
|
|
+ List<ExamQuestionEntity> examQuestionList = examRecordQuestionsService.querySubjectiveAnswerList(req.getExamRecordDataId());
|
|
|
|
+ QuerySubjectiveAnswerListResp resp = new QuerySubjectiveAnswerListResp();
|
|
|
|
+ List<QuerySubjectiveAnswerBean> querySubjectiveAnswerBeanList = new ArrayList<QuerySubjectiveAnswerBean>();
|
|
|
|
+ for (ExamQuestionEntity examQuestionEntity : examQuestionList) {
|
|
|
|
+ QuerySubjectiveAnswerBean querySubjectiveAnswerBean = new QuerySubjectiveAnswerBean();
|
|
|
|
+ querySubjectiveAnswerBean.setExamRecordDataId(examQuestionEntity.getExamRecordDataId());
|
|
|
|
+ querySubjectiveAnswerBean.setMainNumber(examQuestionEntity.getMainNumber());
|
|
|
|
+ querySubjectiveAnswerBean.setOrder(examQuestionEntity.getOrder());
|
|
|
|
+ querySubjectiveAnswerBean.setQuestionId(examQuestionEntity.getQuestionId());
|
|
|
|
+ querySubjectiveAnswerBean.setStudentAnswer(examQuestionEntity.getStudentAnswer());
|
|
|
|
+ querySubjectiveAnswerBean.setAnswerType(examQuestionEntity.getAnswerType());
|
|
|
|
+ querySubjectiveAnswerBeanList.add(querySubjectiveAnswerBean);
|
|
|
|
+ }
|
|
|
|
+ resp.setQuerySubjectiveAnswerBeanList(querySubjectiveAnswerBeanList);
|
|
|
|
+ return resp;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ @ApiOperation(value = "阅卷回传主观题得分")
|
|
|
|
+ @PostMapping("/saveSubjectiveQuestionScore")
|
|
|
|
+ public void saveSubjectiveQuestionScore(@RequestBody SaveSubjectiveQuestionScoreReq req) {
|
|
|
|
+ Check.isNull(req.getExamRecordDataId(), "examRecordDataId 不能为空");
|
|
|
|
+ List<SaveSubjectiveQuestionScoreBean> saveSubjectiveQuestionScoreList = req.getSaveSubjectiveQuestionScoreList();
|
|
|
|
+ if (saveSubjectiveQuestionScoreList == null || saveSubjectiveQuestionScoreList.size() == 0) {
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ long examRecordDataId = req.getExamRecordDataId();
|
|
|
|
+ List<SubjectiveQuestionScoreInfo> subjectiveQuestionScoreInfoList = new ArrayList<SubjectiveQuestionScoreInfo>();
|
|
|
|
+ for (SaveSubjectiveQuestionScoreBean bean : saveSubjectiveQuestionScoreList) {
|
|
|
|
+ SubjectiveQuestionScoreInfo info = new SubjectiveQuestionScoreInfo();
|
|
|
|
+ info.setExamRecordDataId(bean.getExamRecordDataId());
|
|
|
|
+ info.setOrder(bean.getOrder());
|
|
|
|
+ info.setQuestionId(bean.getQuestionId());
|
|
|
|
+ info.setScore(bean.getScore());
|
|
|
|
+ subjectiveQuestionScoreInfoList.add(info);
|
|
|
|
+ }
|
|
|
|
+ examRecordQuestionsService.saveSubjectiveQuestionScore(examRecordDataId, subjectiveQuestionScoreInfoList);
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 阅卷获取考试记录主观题答案信息
|
|
|
|
+ */
|
|
|
|
+ @Override
|
|
|
|
+ @ApiOperation(value = "阅卷获取考试记录主观题答案信息")
|
|
|
|
+ @PostMapping("/getSubjectiveAnswerList")
|
|
|
|
+ public GetSubjectiveAnswerResp getSubjectiveAnswerList(@RequestBody GetSubjectiveAnswerReq req) {
|
|
|
|
+ int rowCount = 100;
|
|
|
|
+ List<ExamRecordDataEntity> examRecordDataList =
|
|
|
|
+ examRecordDataRepo.findLimitedDataByExamIdAndIdMoreThan(req.getExamId(), req.getStartExamRecordId(), rowCount);
|
|
|
|
+
|
|
|
|
+ if (null == examRecordDataList || examRecordDataList.isEmpty()) {
|
|
|
|
+ return new GetSubjectiveAnswerResp(req.getStartExamRecordId(), null);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ List<SubjectiveAnswerBean> subjectiveAnswerBeanList = new ArrayList<>();
|
|
|
|
+
|
|
|
|
+ for (ExamRecordDataEntity record : examRecordDataList) {
|
|
|
|
+ String recordQuestionsId = record.getExamRecordQuestionsId();
|
|
|
|
+ CourseCacheBean course = CacheHelper.getCourse(record.getCourseId());
|
|
|
|
+ ExamRecordQuestionsEntity questionsEntity;
|
|
|
|
+ if (null != recordQuestionsId) {
|
|
|
|
+ questionsEntity = GlobalHelper.getEntity(examRecordQuestionsRepo, recordQuestionsId, ExamRecordQuestionsEntity.class);
|
|
|
|
+ } else {
|
|
|
|
+ questionsEntity = examRecordQuestionsRepo.findByExamRecordDataId(record.getId());
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ List<ExamQuestionEntity> examQuestionList = questionsEntity.getExamQuestionEntities();
|
|
|
|
+ //获取所有的主观题
|
|
|
|
+ List<ExamQuestionEntity> subjectiveQuestionList = examQuestionList.stream().filter(p -> p.getQuestionType() == QuestionType.ESSAY ||
|
|
|
|
+ p.getQuestionType() == QuestionType.FILL_UP).collect(Collectors.toList());
|
|
|
|
+
|
|
|
|
+ for (ExamQuestionEntity sq : subjectiveQuestionList) {
|
|
|
|
+ SubjectiveAnswerBean subjectiveAnswerBean = new SubjectiveAnswerBean();
|
|
|
|
+ subjectiveAnswerBean.setAnswerType(sq.getAnswerType());
|
|
|
|
+ subjectiveAnswerBean.setRealAnswerType(transformedAnswerType(sq.getAnswerType(),sq.getQuestionType(),record.getExamId()));//实际的作答类型
|
|
|
|
+ subjectiveAnswerBean.setCourseCode(course.getCode());
|
|
|
|
+ subjectiveAnswerBean.setExamId(req.getExamId());
|
|
|
|
+ subjectiveAnswerBean.setExamRecordDataId(record.getId());
|
|
|
|
+ subjectiveAnswerBean.setExamStudentId(record.getExamStudentId());
|
|
|
|
+ subjectiveAnswerBean.setMainNumber(sq.getMainNumber());
|
|
|
|
+ subjectiveAnswerBean.setOrder(sq.getOrder());
|
|
|
|
+ subjectiveAnswerBean.setQuestionId(sq.getQuestionId());
|
|
|
|
+ subjectiveAnswerBean.setStudentAnswer(transformedStudentAnswer(sq.getStudentAnswer()));
|
|
|
|
+ subjectiveAnswerBeanList.add(subjectiveAnswerBean);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ ExamRecordDataEntity lastExamRecordData = examRecordDataList.get(examRecordDataList.size() - 1);
|
|
|
|
+ Long nextId = lastExamRecordData.getId() + 1;
|
|
|
|
+ return new GetSubjectiveAnswerResp(nextId, subjectiveAnswerBeanList);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 根据原始作答类型和学生实际作答推断出真实的作答类型
|
|
|
|
+ * @param answerType 原始作答类型
|
|
|
|
+ * @param questionType 题型
|
|
|
|
+ * @param examId 考试id
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ private String transformedAnswerType(AnswerType answerType, QuestionType questionType,Long examId) {
|
|
|
|
+ //需要图片作答的考试id(以英文逗号分隔)
|
|
|
|
+ Object oExamId = CacheHelper.getSysProperty("oe.imgAnswer.examId").getValue();
|
|
|
|
+ if (null !=oExamId){
|
|
|
|
+ String strExamId = String.valueOf(oExamId);
|
|
|
|
+ List<String> examIdList = Arrays.asList(strExamId.split(","));
|
|
|
|
+ //如果题型为问答题,且作答类型不为音频作答,且考试为需要图片作答,则此题为图片作答题
|
|
|
|
+ if (questionType == QuestionType.ESSAY &&
|
|
|
|
+ (null == answerType || (null != answerType && answerType != AnswerType.SINGLE_AUDIO))) {
|
|
|
|
+ if (examIdList.stream().anyMatch(eid->eid.equals(String.valueOf(examId)))){
|
|
|
|
+ return "image";
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (null != answerType && answerType==AnswerType.SINGLE_AUDIO){
|
|
|
|
+ return "audio";
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return "text";
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 转化过的作答
|
|
|
|
+ *
|
|
|
|
+ * @param studentAnswer
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ private String transformedStudentAnswer(String studentAnswer) {
|
|
|
|
+ if (StringUtils.isNullOrEmpty(studentAnswer)) {
|
|
|
|
+ return studentAnswer;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ //图片题特殊处理(因为图片作答题中有html标签)
|
|
|
|
+ Document doc = Jsoup.parse(studentAnswer);
|
|
|
|
+ Elements imgElements = doc.select("img[src]");
|
|
|
|
+ String imgStudentAnswer = "";
|
|
|
|
+ for (Element el : imgElements) {
|
|
|
|
+ String src = el.attr("src");
|
|
|
|
+ if (!StringUtils.isNullOrEmpty(src)) {
|
|
|
|
+ imgStudentAnswer += src + "|";
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ if (!StringUtils.isNullOrEmpty(imgStudentAnswer)) {
|
|
|
|
+ return imgStudentAnswer.substring(0, imgStudentAnswer.length() - 1);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return studentAnswer;
|
|
|
|
+ }
|
|
}
|
|
}
|