考试相关
This commit is contained in:
@@ -39,13 +39,12 @@ public class ClassExamController {
|
||||
public R importSubject(@RequestParam("file") MultipartFile file, @RequestParam("courseId") int courseId) {
|
||||
int num = 0;
|
||||
try (InputStream fis = file.getInputStream()) {
|
||||
List<ClassExamOption> optionList = new ArrayList<>();
|
||||
Long time = System.currentTimeMillis();
|
||||
//解析数据
|
||||
ExcelUtil example = new ExcelUtil();
|
||||
example.processOneSheet(fis);
|
||||
Long endtime = System.currentTimeMillis();
|
||||
LinkedHashMap<String, String> map = example.getRowContents();
|
||||
Iterator<Map.Entry<String, String>> it = map.entrySet().iterator();
|
||||
//处理数据
|
||||
int count = 0;
|
||||
while (it.hasNext()) {
|
||||
Map.Entry<String, String> entry = it.next();
|
||||
@@ -54,20 +53,54 @@ public class ClassExamController {
|
||||
count = Integer.parseInt(rowNo);
|
||||
// System.out.println(pos + ";" + entry.getValue());
|
||||
}
|
||||
List<ClassExamOption> optionList = new ArrayList<>();
|
||||
//先校验数据
|
||||
StringBuffer sb = new StringBuffer();
|
||||
for (int i=2;i<=count;i++){
|
||||
//类型
|
||||
String type = map.containsKey("A"+i)?map.get("A"+i):"";
|
||||
if (type.contains("单选")||type.contains("多选")){
|
||||
}else {
|
||||
sb.append("第"+i+"行题目类型出错\n");
|
||||
}
|
||||
String option1 = map.containsKey("C"+i)?map.get("C"+i):"";
|
||||
if (StringUtils.isBlank(option1)){
|
||||
sb.append("第"+i+"行无选项1\n");
|
||||
}
|
||||
String option2 = map.containsKey("D"+i)?map.get("D"+i):"";
|
||||
if (StringUtils.isBlank(option2)){
|
||||
sb.append("第"+i+"行无选项2\n");
|
||||
}
|
||||
String option3 = map.containsKey("E"+i)?map.get("E"+i):"";
|
||||
if (StringUtils.isBlank(option3)){
|
||||
sb.append("第"+i+"行无选项3\n");
|
||||
}
|
||||
String option4 = map.containsKey("F"+i)?map.get("F"+i):"";
|
||||
if (StringUtils.isBlank(option4)){
|
||||
sb.append("第"+i+"行无选项4\n");
|
||||
}
|
||||
String answer = map.containsKey("I"+i)?map.get("I"+i):"";
|
||||
if (StringUtils.isBlank(answer)){
|
||||
sb.append("第"+i+"行无答案\n");
|
||||
}
|
||||
//题目
|
||||
String content = map.containsKey("B"+i)?map.get("B"+i):"";
|
||||
if (StringUtils.isBlank(content)) {
|
||||
sb.append("第"+i+"行无题目\n");
|
||||
}
|
||||
}
|
||||
if (sb.length() > 0){
|
||||
throw new Exception(sb.toString());
|
||||
}
|
||||
for (int i=2;i<=count;i++){
|
||||
ClassExamSubject subject = new ClassExamSubject();
|
||||
subject.setCourseId(courseId);
|
||||
//类型
|
||||
String type = map.containsKey("A"+i)?map.get("A"+i):"";
|
||||
if (type.contains("单选")){
|
||||
if (map.get("A"+i).contains("单选")){
|
||||
subject.setType(0);
|
||||
}else if (type.contains("多选")){
|
||||
}else if (map.get("A"+i).contains("多选")){
|
||||
subject.setType(1);
|
||||
}else {
|
||||
throw new Exception("第"+i+"题无题目类型");
|
||||
}
|
||||
//题目
|
||||
subject.setContent(map.containsKey("B"+i)?map.get("B"+i):"");
|
||||
subject.setContent(map.get("B"+i));
|
||||
//所属章节
|
||||
subject.setChapter(map.containsKey("N"+i)?map.get("N"+i):"");
|
||||
//音视频序号
|
||||
@@ -78,15 +111,15 @@ public class ClassExamController {
|
||||
subject.setCreateUser(map.containsKey("Q"+i)?map.get("Q"+i):"");
|
||||
classExamSubjectService.save(subject);
|
||||
num++;
|
||||
insertOption(optionList,subject.getId(),map.containsKey("C"+i)?map.get("C"+i):"",map.containsKey("I"+i)?map.get("I"+i):"");
|
||||
insertOption(optionList,subject.getId(),map.containsKey("D"+i)?map.get("D"+i):"",map.containsKey("I"+i)?map.get("I"+i):"");
|
||||
insertOption(optionList,subject.getId(),map.containsKey("E"+i)?map.get("E"+i):"",map.containsKey("I"+i)?map.get("I"+i):"");
|
||||
insertOption(optionList,subject.getId(),map.containsKey("F"+i)?map.get("F"+i):"",map.containsKey("I"+i)?map.get("I"+i):"");
|
||||
insertOption(optionList,subject.getId(),map.containsKey("G"+i)?map.get("G"+i):"",map.containsKey("I"+i)?map.get("I"+i):"");
|
||||
insertOption(optionList,subject.getId(),map.containsKey("H"+i)?map.get("H"+i):"",map.containsKey("I"+i)?map.get("I"+i):"");
|
||||
//插入选项
|
||||
insertOption(optionList,subject.getId(),map.get("C"+i),map.get("I"+i));
|
||||
insertOption(optionList,subject.getId(),map.get("D"+i),map.get("I"+i));
|
||||
insertOption(optionList,subject.getId(),map.get("E"+i),map.get("I"+i));
|
||||
insertOption(optionList,subject.getId(),map.get("F"+i),map.get("I"+i));
|
||||
insertOption(optionList,subject.getId(),map.containsKey("G"+i)?map.get("G"+i):"",map.get("I"+i));
|
||||
insertOption(optionList,subject.getId(),map.containsKey("H"+i)?map.get("H"+i):"",map.get("I"+i));
|
||||
}
|
||||
classExamOptionService.saveBatch(optionList);
|
||||
System.out.println("解析数据" + count + "条;耗时" + (endtime - time) / 1000 + "秒");
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
|
||||
@@ -127,11 +160,10 @@ public class ClassExamController {
|
||||
return R.ok().put("page",classExamSubjectList);
|
||||
}
|
||||
|
||||
//考试题目列表
|
||||
//生成试卷
|
||||
@RequestMapping("/generateExamPaper")
|
||||
public R generateExamPaper(@RequestBody Map<String,Object> params){
|
||||
Object examPaper = classExamService.generateExamPaper(params);
|
||||
return R.ok().put("examPaper",examPaper);
|
||||
return classExamService.generateExamPaper(params);
|
||||
}
|
||||
|
||||
//提交考卷
|
||||
|
||||
@@ -2,6 +2,7 @@ package com.peanut.modules.common.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.peanut.common.utils.R;
|
||||
import com.peanut.modules.common.entity.ClassExam;
|
||||
import com.peanut.modules.common.entity.ClassExamOption;
|
||||
import com.peanut.modules.common.entity.ClassExamSubject;
|
||||
@@ -25,7 +26,7 @@ public interface ClassExamService extends IService<ClassExam> {
|
||||
|
||||
Page getClassExamSubjectList(Map<String,Object> params);
|
||||
|
||||
Object generateExamPaper(Map<String,Object> params);
|
||||
R generateExamPaper(Map<String,Object> params);
|
||||
|
||||
Object submitExamPaper(Map<String,Object> params);
|
||||
|
||||
|
||||
@@ -45,6 +45,8 @@ public class ClassEntityServiceImpl extends ServiceImpl<ClassEntityDao, ClassEnt
|
||||
private CourseDao courseDao;
|
||||
@Autowired
|
||||
private ClassExamUserDao classExamUserDao;
|
||||
@Autowired
|
||||
private CourseCatalogueChapterDao courseCatalogueChapterDao;
|
||||
|
||||
@Override
|
||||
public Page getClassModelList(Map<String, Object> params) {
|
||||
@@ -1067,10 +1069,78 @@ public class ClassEntityServiceImpl extends ServiceImpl<ClassEntityDao, ClassEnt
|
||||
map.put("examScore",examScore);
|
||||
}
|
||||
//处理分数占比
|
||||
|
||||
|
||||
BigDecimal userScore = new BigDecimal(0);;
|
||||
double staticScore = 2.5;
|
||||
if(classModel.getIsExam()==1){
|
||||
BigDecimal examScore = new BigDecimal(map.get("examScore").toString());
|
||||
examScore.divide(new BigDecimal(100));
|
||||
examScore.multiply(new BigDecimal(classModel.getQuestionScore()));
|
||||
examScore = examScore.setScale(2,RoundingMode.HALF_UP);
|
||||
map.put("examScore",examScore);
|
||||
userScore.add(examScore);
|
||||
}
|
||||
if(classModel.getIsQuestion()==1){
|
||||
BigDecimal questionScore = new BigDecimal(map.get("questionScore").toString());
|
||||
MPJLambdaWrapper<CourseCatalogueChapterEntity> wrapper = new MPJLambdaWrapper();
|
||||
wrapper.leftJoin(ClassCourse.class,ClassCourse::getCourseId,CourseCatalogueChapterEntity::getCourseId);
|
||||
wrapper.leftJoin(ClassModel.class,ClassModel::getId,ClassCourse::getModelId);
|
||||
wrapper.eq(ClassModel::getId,classModel.getId());
|
||||
wrapper.ne(CourseCatalogueChapterEntity::getQuestions,"");
|
||||
int count = courseCatalogueChapterDao.selectCount(wrapper);
|
||||
BigDecimal totalScore = new BigDecimal(staticScore*count);
|
||||
questionScore.divide(totalScore);
|
||||
questionScore.multiply(new BigDecimal(classModel.getQuestionScore()));
|
||||
questionScore = questionScore.setScale(2,RoundingMode.HALF_UP);
|
||||
map.put("questionScore",questionScore);
|
||||
userScore.add(questionScore);
|
||||
}
|
||||
if(classModel.getIsTask()==1){
|
||||
BigDecimal task0Score = new BigDecimal(map.get("task0Score").toString());
|
||||
MPJLambdaWrapper<ClassTask> wrapper = new MPJLambdaWrapper();
|
||||
wrapper.eq(ClassTask::getClassId,classEntity.getId());
|
||||
wrapper.eq(ClassTask::getType,"0");
|
||||
int count = classTaskDao.selectCount(wrapper);
|
||||
BigDecimal totalScore = new BigDecimal(staticScore*count);
|
||||
task0Score.divide(totalScore);
|
||||
task0Score.multiply(new BigDecimal(classModel.getTaskScore()));
|
||||
task0Score = task0Score.setScale(2,RoundingMode.HALF_UP);
|
||||
map.put("task0Score",task0Score);
|
||||
userScore.add(task0Score);
|
||||
}
|
||||
if(classModel.getIsMedicalcase()==1){
|
||||
BigDecimal task1Score = new BigDecimal(map.get("task1Score").toString());
|
||||
MPJLambdaWrapper<ClassTask> wrapper = new MPJLambdaWrapper();
|
||||
wrapper.eq(ClassTask::getClassId,classEntity.getId());
|
||||
wrapper.eq(ClassTask::getType,"1");
|
||||
int count = classTaskDao.selectCount(wrapper);
|
||||
BigDecimal totalScore = new BigDecimal(staticScore*count);
|
||||
task1Score.divide(totalScore);
|
||||
task1Score.multiply(new BigDecimal(classModel.getMedicalcaseScore()));
|
||||
task1Score = task1Score.setScale(2,RoundingMode.HALF_UP);
|
||||
map.put("task1Score",task1Score);
|
||||
userScore.add(task1Score);
|
||||
}
|
||||
if(classModel.getIsExperience()==1){
|
||||
BigDecimal experienceScore = new BigDecimal(map.get("experienceScore").toString());
|
||||
if (experienceScore.compareTo(new BigDecimal(classModel.getExperienceScore()))>-1){
|
||||
experienceScore = new BigDecimal(classModel.getExperienceScore());
|
||||
}
|
||||
map.put("experienceScore",experienceScore);
|
||||
userScore.add(experienceScore);
|
||||
}
|
||||
map.put("userScore",userScore);
|
||||
resultList.add(map);
|
||||
}
|
||||
Collections.sort(resultList, new Comparator<Map<String,Object>>() {
|
||||
@Override
|
||||
public int compare(Map<String,Object> m1, Map<String,Object> m2) {
|
||||
if((double)(m2.get("userScore")) > (double)(m1.get("userScore"))){
|
||||
return 1;
|
||||
}else {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
return resultList;
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.github.yulichang.wrapper.MPJLambdaWrapper;
|
||||
import com.peanut.common.utils.R;
|
||||
import com.peanut.common.utils.ShiroUtils;
|
||||
import com.peanut.modules.common.dao.*;
|
||||
import com.peanut.modules.common.entity.*;
|
||||
@@ -27,6 +28,8 @@ public class ClassExamServiceImpl extends ServiceImpl<ClassExamDao, ClassExam> i
|
||||
private ClassCourseDao classCourseDao;
|
||||
@Autowired
|
||||
private ClassExamUserDao classExamUserDao;
|
||||
@Autowired
|
||||
private CourseDao courseDao;
|
||||
|
||||
@Override
|
||||
public void addClassExamSubject(ClassExamSubject classExamSubject) {
|
||||
@@ -104,7 +107,7 @@ public class ClassExamServiceImpl extends ServiceImpl<ClassExamDao, ClassExam> i
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object generateExamPaper(Map<String, Object> params) {
|
||||
public R generateExamPaper(Map<String, Object> params) {
|
||||
MPJLambdaWrapper<ClassCourse> courseWrapper = new MPJLambdaWrapper<>();
|
||||
courseWrapper.leftJoin(ClassModel.class,ClassModel::getId,ClassCourse::getModelId);
|
||||
courseWrapper.leftJoin(ClassEntity.class,ClassEntity::getModelId,ClassModel::getId);
|
||||
@@ -119,26 +122,35 @@ public class ClassExamServiceImpl extends ServiceImpl<ClassExamDao, ClassExam> i
|
||||
int mtotal = 50;//多选题总数
|
||||
int snum = (int)Math.floor(stotal/courseList.size());
|
||||
int mnum = (int)Math.floor(mtotal/courseList.size());
|
||||
for (ClassCourse course:courseList){
|
||||
for (ClassCourse classCourse:courseList){
|
||||
CourseEntity course = courseDao.selectById(classCourse.getCourseId());
|
||||
//单选
|
||||
List<ClassExamSubject> singleList = classExamSubjectDao.selectList(new LambdaQueryWrapper<ClassExamSubject>()
|
||||
.eq(ClassExamSubject::getCourseId,course.getCourseId())
|
||||
.eq(ClassExamSubject::getCourseId,classCourse.getCourseId())
|
||||
.eq(ClassExamSubject::getType,0));
|
||||
Collections.shuffle(singleList);//打乱顺序
|
||||
if (sList.size()+snum>stotal){
|
||||
sList.addAll(singleList.subList(0,stotal-sList.size()));
|
||||
}else {
|
||||
sList.addAll(singleList.subList(0,snum));
|
||||
try {
|
||||
if (sList.size()+snum>stotal){
|
||||
sList.addAll(singleList.subList(0,stotal-sList.size()));
|
||||
}else {
|
||||
sList.addAll(singleList.subList(0,snum));
|
||||
}
|
||||
}catch (Exception e) {
|
||||
return R.error(course.getTitle()+"-单选题数量不足");
|
||||
}
|
||||
//多选
|
||||
List<ClassExamSubject> mulList = classExamSubjectDao.selectList(new LambdaQueryWrapper<ClassExamSubject>()
|
||||
.eq(ClassExamSubject::getCourseId,course.getCourseId())
|
||||
.eq(ClassExamSubject::getCourseId,classCourse.getCourseId())
|
||||
.eq(ClassExamSubject::getType,1));
|
||||
Collections.shuffle(mulList);//打乱顺序
|
||||
if (mList.size()+mnum>mtotal){
|
||||
mList.addAll(mulList.subList(0,mtotal-mList.size()));
|
||||
}else {
|
||||
mList.addAll(mulList.subList(0,mnum));
|
||||
try {
|
||||
if (mList.size()+mnum>mtotal){
|
||||
mList.addAll(mulList.subList(0,mtotal-mList.size()));
|
||||
}else {
|
||||
mList.addAll(mulList.subList(0,mnum));
|
||||
}
|
||||
}catch (Exception e) {
|
||||
return R.error(course.getTitle()+"-多选题数量不足");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -158,7 +170,8 @@ public class ClassExamServiceImpl extends ServiceImpl<ClassExamDao, ClassExam> i
|
||||
classExamUser.setSubject(JSONUtil.toJsonStr(resultList));
|
||||
classExamUser.setUserId(ShiroUtils.getUId());
|
||||
classExamUserDao.insert(classExamUser);
|
||||
return resultList;
|
||||
return R.ok().put("examPaper",resultList);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user