mirror of
https://codeup.aliyun.com/67762337eccfc218f6110e0e/per-boe/java-servers.git
synced 2025-12-06 17:36:47 +08:00
作业导出,考试随机选题
This commit is contained in:
@@ -4,13 +4,10 @@ import java.util.List;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
import com.xboe.common.utils.StringUtil;
|
||||
import com.xboe.core.log.AutoLog;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import com.xboe.core.JsonResponse;
|
||||
import com.xboe.core.api.ApiBaseController;
|
||||
@@ -77,7 +74,22 @@ public class CourseContentApi extends ApiBaseController{
|
||||
}
|
||||
return success(obj);
|
||||
}
|
||||
|
||||
|
||||
@GetMapping("/exam/paper-content")
|
||||
@AutoLog(module = "试卷",action = "查看试卷试题",info = "查看当前试题内容")
|
||||
public JsonResponse<Object> paperContent(String courseExamId){
|
||||
if(StringUtil.isBlank(courseExamId)){
|
||||
return badRequest("缺少必要参数");
|
||||
}
|
||||
try {
|
||||
Object paperContentOfOnline = ccontentService.getPaperContentOfOnline(courseExamId);
|
||||
return success(paperContentOfOnline);
|
||||
} catch (Exception e) {
|
||||
log.error("查询试卷内容json错误",e);
|
||||
return error("查询失败",e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取评估信息
|
||||
* @param ccid
|
||||
|
||||
@@ -85,4 +85,6 @@ public interface ICourseContentService{
|
||||
|
||||
void updateProcessVideo(String contentId, String courseId, Float processVideo);
|
||||
|
||||
Object getPaperContentOfOnline(String courseExamId);
|
||||
|
||||
}
|
||||
|
||||
@@ -1,23 +1,17 @@
|
||||
package com.xboe.module.course.service.impl;
|
||||
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.SQLException;
|
||||
import java.util.List;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.transaction.Transactional;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import com.xboe.common.OrderCondition;
|
||||
import com.xboe.core.cache.IXaskCache;
|
||||
import com.xboe.core.cache.XaskCacheProvider;
|
||||
import com.xboe.core.orm.FieldFilters;
|
||||
import com.xboe.core.orm.UpdateBuilder;
|
||||
import com.xboe.module.course.dao.CourseAssessDao;
|
||||
import com.xboe.module.course.dao.CourseContentDao;
|
||||
import com.xboe.module.course.dao.CourseExamDao;
|
||||
import com.xboe.module.course.dao.CourseHomeWorkDao;
|
||||
import com.xboe.module.course.dao.CourseSectionDao;
|
||||
import com.xboe.module.course.dao.*;
|
||||
import com.xboe.module.course.dto.CourseContentDto;
|
||||
import com.xboe.module.course.dto.SortItem;
|
||||
import com.xboe.module.course.entity.CourseAssess;
|
||||
@@ -25,8 +19,21 @@ import com.xboe.module.course.entity.CourseContent;
|
||||
import com.xboe.module.course.entity.CourseExam;
|
||||
import com.xboe.module.course.entity.CourseHomeWork;
|
||||
import com.xboe.module.course.service.ICourseContentService;
|
||||
import com.xboe.module.exam.dao.ExamPaperDao;
|
||||
import com.xboe.module.exam.vo.TestQuestionVo;
|
||||
import com.xboe.standard.enums.BoedxContentType;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.transaction.Transactional;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
@Slf4j
|
||||
@Service
|
||||
public class CourseContentServiceImpl implements ICourseContentService {
|
||||
|
||||
@@ -44,7 +51,13 @@ public class CourseContentServiceImpl implements ICourseContentService {
|
||||
|
||||
@Resource
|
||||
private CourseHomeWorkDao homeworkDao;
|
||||
|
||||
|
||||
@Resource
|
||||
private CourseExamDao courseExamDao;
|
||||
|
||||
@Resource
|
||||
private ExamPaperDao examPaperDao;
|
||||
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
@@ -78,6 +91,9 @@ public class CourseContentServiceImpl implements ICourseContentService {
|
||||
assessDao.saveOrUpdate(assess);
|
||||
}
|
||||
if(exam!=null) {
|
||||
if ((exam.getRandomMode() && !(exam.getQnum() > 0)) || (!exam.getRandomMode() && exam.getQnum() > 0)) {
|
||||
throw new RuntimeException("随机选题处参数错误");
|
||||
}
|
||||
exam.setCourseId(cc.getCourseId());
|
||||
exam.setContentId(cc.getId());
|
||||
if(exam.getPercentScore()==null) {
|
||||
@@ -188,4 +204,69 @@ public class CourseContentServiceImpl implements ICourseContentService {
|
||||
|
||||
return ccDao.sumDurationByCourseId(courseId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getPaperContentOfOnline(String courseExamId) {
|
||||
CourseExam courseExam = courseExamDao.findOne(FieldFilters.eq("id", courseExamId));
|
||||
if (courseExam == null) {
|
||||
throw new RuntimeException("课程考试不存在");
|
||||
}
|
||||
|
||||
String paperId = courseExam.getPaperId();
|
||||
Integer qnum = courseExam.getQnum();
|
||||
Boolean randomMode = courseExam.getRandomMode();
|
||||
|
||||
String paperJson = "";
|
||||
ObjectMapper objectMapper = new ObjectMapper();
|
||||
|
||||
try {
|
||||
// 判断试卷类型
|
||||
if (courseExam.getPaperType() == 1 && StringUtils.isNotBlank(courseExam.getPaperContent()) && randomMode && qnum != null && qnum > 0) {
|
||||
|
||||
paperJson = courseExam.getPaperContent();
|
||||
JsonNode rootNode = objectMapper.readTree(paperJson);
|
||||
JsonNode itemsNode = rootNode.path("items");
|
||||
List<JsonNode> itemsNodes = new ArrayList<>();
|
||||
itemsNode.forEach(itemsNodes::add);
|
||||
|
||||
if (randomMode && qnum != null && qnum > 0 && itemsNodes.size() > qnum) {
|
||||
Collections.shuffle(itemsNodes);
|
||||
itemsNodes = itemsNodes.subList(0, qnum);
|
||||
return itemsNodes;
|
||||
}
|
||||
} else if (courseExam.getPaperType() == 2 && randomMode && qnum != null && qnum > 0) {
|
||||
IXaskCache cache = XaskCacheProvider.getCache();
|
||||
String cacheKey = "course:exam:" + courseExamId + ":" + paperId;
|
||||
String cacheData = cache.getCacheObject(cacheKey);
|
||||
|
||||
if (StringUtils.isBlank(cacheData)) {
|
||||
paperJson = (String) examPaperDao.findField("paperContent", FieldFilters.eq("id", paperId));
|
||||
cache.setCacheObject(cacheKey, paperJson, 5, TimeUnit.HOURS);
|
||||
} else {
|
||||
paperJson = cacheData;
|
||||
}
|
||||
|
||||
objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
|
||||
List<TestQuestionVo> eqVoList = objectMapper.readValue(paperJson, new TypeReference<List<TestQuestionVo>>() {
|
||||
});
|
||||
|
||||
if (eqVoList.size() > qnum) {
|
||||
Collections.shuffle(eqVoList);
|
||||
eqVoList = eqVoList.subList(0, qnum);
|
||||
return eqVoList;
|
||||
}
|
||||
}
|
||||
|
||||
} catch (JsonProcessingException e) {
|
||||
log.error("JSON处理错误", e);
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
if (StringUtils.isBlank(paperJson)) {
|
||||
throw new RuntimeException("此考试无试卷内容,考试已经过期或试卷已被删除");
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user