Merge remote-tracking branch 'origin/zcc'
This commit is contained in:
@@ -64,6 +64,11 @@ public class DelayQueueConfig {
|
||||
public static final String COURSE_EXCHANGE = "course_exchange";
|
||||
public static final String COURSE_ROUTING_KEY = "course_routingKey";
|
||||
|
||||
//通用队列
|
||||
public static final String COMMON_QUEUE = "common_queue";
|
||||
public static final String COMMON_EXCHANGE = "common_exchange";
|
||||
public static final String COMMON_ROUTING_KEY = "common_routingKey";
|
||||
|
||||
/**
|
||||
* 快递队列
|
||||
*/
|
||||
@@ -248,7 +253,6 @@ public class DelayQueueConfig {
|
||||
.noargs();
|
||||
}
|
||||
|
||||
|
||||
//课程过期延迟队列
|
||||
@Bean
|
||||
public Queue courseQueue() {
|
||||
@@ -270,6 +274,27 @@ public class DelayQueueConfig {
|
||||
.noargs();
|
||||
}
|
||||
|
||||
//通用延迟队列
|
||||
@Bean
|
||||
public Queue commonQueue() {
|
||||
return new Queue(COMMON_QUEUE, true, false, false);
|
||||
}
|
||||
@Bean
|
||||
public CustomExchange commonExchange() {
|
||||
Map<String, Object> args = new HashMap<>();
|
||||
//自定义交换机的类型
|
||||
args.put("x-delayed-type", "direct");
|
||||
return new CustomExchange(COMMON_EXCHANGE, "x-delayed-message", true, false,args);
|
||||
}
|
||||
@Bean
|
||||
public Binding commonBinding() {
|
||||
return BindingBuilder
|
||||
.bind(commonQueue())
|
||||
.to(commonExchange())
|
||||
.with(COMMON_ROUTING_KEY)
|
||||
.noargs();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Bean
|
||||
|
||||
@@ -274,6 +274,10 @@ public class ClassController {
|
||||
//新增作业
|
||||
@RequestMapping("/addClassTaskAndQuesReply")
|
||||
public R addClassTaskAndQuesReply(@RequestBody ClassTaskAndQuesReply classTaskAndQuesReply){
|
||||
ClassEntity classEntity = classEntityService.getById(classTaskAndQuesReply.getClassId());
|
||||
if ("3".equals(classEntity.getState())) {
|
||||
return R.error("考试周禁止提交作业");
|
||||
}
|
||||
classEntityService.addClassTaskAndQuesReply(classTaskAndQuesReply);
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import com.peanut.common.excel.ExcelUtil;
|
||||
import com.peanut.common.utils.R;
|
||||
import com.peanut.modules.common.entity.ClassExamOption;
|
||||
import com.peanut.modules.common.entity.ClassExamSubject;
|
||||
import com.peanut.modules.common.entity.ClassExamUser;
|
||||
import com.peanut.modules.common.service.ClassExamOptionService;
|
||||
import com.peanut.modules.common.service.ClassExamService;
|
||||
import com.peanut.modules.common.service.ClassExamSubjectService;
|
||||
@@ -160,12 +161,32 @@ public class ClassExamController {
|
||||
return R.ok().put("page",classExamSubjectList);
|
||||
}
|
||||
|
||||
//获取服务器时间
|
||||
@RequestMapping("/getServerTime")
|
||||
public R getServerTime(){
|
||||
return R.ok().put("serverTime",new Date().getTime());
|
||||
}
|
||||
|
||||
//生成试卷
|
||||
@RequestMapping("/generateExamPaper")
|
||||
public R generateExamPaper(@RequestBody Map<String,Object> params){
|
||||
return classExamService.generateExamPaper(params);
|
||||
}
|
||||
|
||||
//考试中的试卷
|
||||
@RequestMapping("/examingPaper")
|
||||
public R examingPaper(){
|
||||
ClassExamUser classExamUser = classExamService.examingPaper();
|
||||
return R.ok().put("classExamUser",classExamUser);
|
||||
}
|
||||
|
||||
//提交选项
|
||||
@RequestMapping("/submitOption")
|
||||
public R submitOption(@RequestBody Map<String,Object> params){
|
||||
classExamService.submitOption(params);
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
//提交试卷
|
||||
@RequestMapping("/submitExamPaper")
|
||||
public R submitExamPaper(@RequestBody Map<String,Object> params){
|
||||
@@ -173,6 +194,13 @@ public class ClassExamController {
|
||||
return R.ok().put("examPaper",examPaper);
|
||||
}
|
||||
|
||||
//试卷列表
|
||||
@RequestMapping("/getExamPaperList")
|
||||
public R getExamPaperList(@RequestBody Map<String,Object> params){
|
||||
Object examPaper = classExamService.getExamPaperList(params);
|
||||
return R.ok().put("examPaper",examPaper);
|
||||
}
|
||||
|
||||
//试卷详情
|
||||
@RequestMapping("/getExamPaperInfo")
|
||||
public R getExamPaperInfo(@RequestBody Map<String,Object> params){
|
||||
@@ -226,6 +254,13 @@ public class ClassExamController {
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
//删除课程下全部题目
|
||||
@RequestMapping("/delSubjectByCourseId")
|
||||
public R delSubjectByCourseId(@RequestBody Map<String,Object> params){
|
||||
classExamService.delSubjectByCourseId(params);
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
//删除选项
|
||||
@RequestMapping("/delClassExamOption")
|
||||
public R delClassExamOption(@RequestBody Map<String,Object> params){
|
||||
|
||||
@@ -20,7 +20,7 @@ public class ClassEntity {
|
||||
|
||||
private String title;
|
||||
|
||||
//小班状态 0待开班1进行中2完成
|
||||
//小班状态 0待开班1进行中2完成3考试中
|
||||
private String state;
|
||||
|
||||
private String icon;
|
||||
|
||||
@@ -5,6 +5,8 @@ import com.baomidou.mybatisplus.annotation.TableLogic;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
@Data
|
||||
@TableName("class_exam_user")
|
||||
public class ClassExamUser {
|
||||
@@ -24,6 +26,10 @@ public class ClassExamUser {
|
||||
|
||||
private String answer;
|
||||
|
||||
private Date startTime;
|
||||
|
||||
private Date endTime;
|
||||
|
||||
@TableLogic
|
||||
private Integer delFlag;
|
||||
}
|
||||
|
||||
@@ -25,6 +25,8 @@ public class ClassModel {
|
||||
|
||||
private Integer days;//教学天数
|
||||
|
||||
private Integer examDays;//考试周时长
|
||||
|
||||
private Integer isQuestion;
|
||||
private Integer questionScore;
|
||||
private Integer isTask;
|
||||
|
||||
@@ -6,6 +6,8 @@ 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;
|
||||
import com.peanut.modules.common.entity.ClassExamUser;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public interface ClassExamService extends IService<ClassExam> {
|
||||
@@ -22,14 +24,22 @@ public interface ClassExamService extends IService<ClassExam> {
|
||||
|
||||
void delClassExamSubject(Map<String,Object> params);
|
||||
|
||||
void delSubjectByCourseId(Map<String,Object> params);
|
||||
|
||||
void delClassExamOption(Map<String,Object> params);
|
||||
|
||||
Page getClassExamSubjectList(Map<String,Object> params);
|
||||
|
||||
R generateExamPaper(Map<String,Object> params);
|
||||
|
||||
ClassExamUser examingPaper();
|
||||
|
||||
void submitOption(Map<String,Object> params);
|
||||
|
||||
Object submitExamPaper(Map<String,Object> params);
|
||||
|
||||
Object getExamPaperList(Map<String,Object> params);
|
||||
|
||||
Object getExamPaperInfo(Map<String,Object> params);
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.peanut.modules.common.service.impl;
|
||||
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
@@ -8,6 +9,7 @@ import com.github.yulichang.wrapper.MPJLambdaWrapper;
|
||||
import com.peanut.common.utils.DateUtils;
|
||||
import com.peanut.common.utils.R;
|
||||
import com.peanut.common.utils.ShiroUtils;
|
||||
import com.peanut.config.DelayQueueConfig;
|
||||
import com.peanut.modules.common.dao.*;
|
||||
import com.peanut.modules.common.entity.*;
|
||||
import com.peanut.modules.common.service.ClassEntityService;
|
||||
@@ -15,12 +17,15 @@ import com.peanut.modules.sys.dao.SysUserDao;
|
||||
import com.peanut.modules.sys.entity.SysUserEntity;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.springframework.amqp.core.MessagePostProcessor;
|
||||
import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.math.RoundingMode;
|
||||
import java.time.LocalDate;
|
||||
import java.util.*;
|
||||
|
||||
@Slf4j
|
||||
@@ -49,6 +54,8 @@ public class ClassEntityServiceImpl extends ServiceImpl<ClassEntityDao, ClassEnt
|
||||
private ClassExamUserDao classExamUserDao;
|
||||
@Autowired
|
||||
private CourseCatalogueChapterDao courseCatalogueChapterDao;
|
||||
@Autowired
|
||||
private RabbitTemplate rabbitTemplate;
|
||||
|
||||
@Override
|
||||
public Page getClassModelList(Map<String, Object> params) {
|
||||
@@ -58,6 +65,9 @@ public class ClassEntityServiceImpl extends ServiceImpl<ClassEntityDao, ClassEnt
|
||||
if (StringUtils.isNotEmpty(params.get("title").toString())){
|
||||
wrapper.like(ClassModel::getTitle,params.get("title"));
|
||||
}
|
||||
if (StringUtils.isNotEmpty(params.get("type").toString())){
|
||||
wrapper.eq(ClassModel::getType,params.get("type"));
|
||||
}
|
||||
wrapper.orderByDesc(ClassModel::getId);
|
||||
Page<ClassModel> classModelPage = classModelDao.selectPage(new Page<>(page, limit), wrapper);
|
||||
for (ClassModel classModel:classModelPage.getRecords()){
|
||||
@@ -223,6 +233,7 @@ public class ClassEntityServiceImpl extends ServiceImpl<ClassEntityDao, ClassEnt
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public R updateClassState(Map<String, Object> params) {
|
||||
String state = params.get("state").toString();
|
||||
ClassEntity classEntity = this.getBaseMapper().selectById(params.get("classId").toString());
|
||||
@@ -296,11 +307,21 @@ public class ClassEntityServiceImpl extends ServiceImpl<ClassEntityDao, ClassEnt
|
||||
Date startTime = new Date();
|
||||
classEntity.setStartTime(startTime);
|
||||
classEntity.setEndTime(DateUtils.addDateDays(startTime,classModelDao.selectById(classEntity.getModelId()).getDays()));
|
||||
this.getBaseMapper().updateById(classEntity);
|
||||
if (classModel.getIsExam()==1){
|
||||
//根据设置的天数将班级状态从进行中设置成考试中
|
||||
rabbitTemplate.convertAndSend(
|
||||
DelayQueueConfig.COMMON_EXCHANGE,
|
||||
DelayQueueConfig.COMMON_ROUTING_KEY,
|
||||
"examDays"+","+classEntity.getId(),
|
||||
messagePostProcessor((classModel.getDays()-classModel.getExamDays())*24*60*60*1000)
|
||||
);
|
||||
}
|
||||
}else {
|
||||
classEntity.setState("2");
|
||||
classEntity.setEndTime(new Date());
|
||||
this.getBaseMapper().updateById(classEntity);
|
||||
}
|
||||
this.getBaseMapper().updateById(classEntity);
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
@@ -1072,27 +1093,31 @@ public class ClassEntityServiceImpl extends ServiceImpl<ClassEntityDao, ClassEnt
|
||||
Map<String,Object> map = getUserScore(params);
|
||||
map.put("user",myUserDao.selectById(classUser.getUserId()));
|
||||
if (classModel.getIsExam()==1){
|
||||
List<ClassExamUser> classExamUsers = classExamUserDao.selectList(new LambdaQueryWrapper<ClassExamUser>()
|
||||
List<Map<String,Object>> classExamUsers = classExamUserDao.selectMaps(new MPJLambdaWrapper<ClassExamUser>()
|
||||
.eq(ClassExamUser::getUserId,classUser.getUserId())
|
||||
.eq(ClassExamUser::getClassId,classEntity.getId()));
|
||||
.eq(ClassExamUser::getClassId,classEntity.getId())
|
||||
.eq(ClassExamUser::getScoreSuccess,1)
|
||||
.selectAs(ClassExamUser::getId,"id")
|
||||
.selectAs(ClassExamUser::getScore,"score")
|
||||
.orderByAsc(ClassExamUser::getStartTime));
|
||||
int examScore = 0;
|
||||
for (ClassExamUser classExamUser:classExamUsers){
|
||||
if (classExamUser.getScore()>examScore){
|
||||
examScore = classExamUser.getScore();
|
||||
if (classExamUsers.size() > 0){
|
||||
for (Map<String,Object> classExamUser:classExamUsers){
|
||||
if ((int)classExamUser.get("score")>examScore){
|
||||
examScore = (int)classExamUser.get("score");
|
||||
}
|
||||
}
|
||||
}
|
||||
map.put("examScore",examScore);
|
||||
map.put("classExamUsers",classExamUsers);
|
||||
}
|
||||
//处理分数占比
|
||||
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);
|
||||
userScore = userScore.add(examScore);
|
||||
}
|
||||
if(classModel.getIsQuestion()==1){
|
||||
BigDecimal questionScore = new BigDecimal(map.get("questionScore").toString());
|
||||
@@ -1103,11 +1128,11 @@ public class ClassEntityServiceImpl extends ServiceImpl<ClassEntityDao, ClassEnt
|
||||
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.divide(totalScore);
|
||||
questionScore = questionScore.multiply(new BigDecimal(classModel.getQuestionScore()));
|
||||
questionScore = questionScore.setScale(2,RoundingMode.HALF_UP);
|
||||
map.put("questionScore",questionScore);
|
||||
userScore.add(questionScore);
|
||||
userScore = userScore.add(questionScore);
|
||||
}
|
||||
if(classModel.getIsTask()==1){
|
||||
BigDecimal task0Score = new BigDecimal(map.get("task0Score").toString());
|
||||
@@ -1116,11 +1141,11 @@ public class ClassEntityServiceImpl extends ServiceImpl<ClassEntityDao, ClassEnt
|
||||
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.divide(totalScore);
|
||||
task0Score = task0Score.multiply(new BigDecimal(classModel.getTaskScore()));
|
||||
task0Score = task0Score.setScale(2,RoundingMode.HALF_UP);
|
||||
map.put("task0Score",task0Score);
|
||||
userScore.add(task0Score);
|
||||
userScore = userScore.add(task0Score);
|
||||
}
|
||||
if(classModel.getIsMedicalcase()==1){
|
||||
BigDecimal task1Score = new BigDecimal(map.get("task1Score").toString());
|
||||
@@ -1129,11 +1154,11 @@ public class ClassEntityServiceImpl extends ServiceImpl<ClassEntityDao, ClassEnt
|
||||
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.divide(totalScore);
|
||||
task1Score = task1Score.multiply(new BigDecimal(classModel.getMedicalcaseScore()));
|
||||
task1Score = task1Score.setScale(2,RoundingMode.HALF_UP);
|
||||
map.put("task1Score",task1Score);
|
||||
userScore.add(task1Score);
|
||||
userScore = userScore.add(task1Score);
|
||||
}
|
||||
if(classModel.getIsExperience()==1){
|
||||
BigDecimal experienceScore = new BigDecimal(map.get("experienceScore").toString());
|
||||
@@ -1141,7 +1166,7 @@ public class ClassEntityServiceImpl extends ServiceImpl<ClassEntityDao, ClassEnt
|
||||
experienceScore = new BigDecimal(classModel.getExperienceScore());
|
||||
}
|
||||
map.put("experienceScore",experienceScore);
|
||||
userScore.add(experienceScore);
|
||||
userScore = userScore.add(experienceScore);
|
||||
}
|
||||
map.put("userScore",userScore);
|
||||
resultList.add(map);
|
||||
@@ -1161,4 +1186,11 @@ public class ClassEntityServiceImpl extends ServiceImpl<ClassEntityDao, ClassEnt
|
||||
}
|
||||
|
||||
|
||||
|
||||
private MessagePostProcessor messagePostProcessor(long date) {
|
||||
return message -> {
|
||||
message.getMessageProperties().setDelay((int)date);
|
||||
return message;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,13 +5,17 @@ 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.DateUtils;
|
||||
import com.peanut.common.utils.R;
|
||||
import com.peanut.common.utils.ShiroUtils;
|
||||
import com.peanut.config.DelayQueueConfig;
|
||||
import com.peanut.modules.common.dao.*;
|
||||
import com.peanut.modules.common.entity.*;
|
||||
import com.peanut.modules.common.service.ClassExamService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.springframework.amqp.core.MessagePostProcessor;
|
||||
import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import java.util.*;
|
||||
@@ -30,6 +34,10 @@ public class ClassExamServiceImpl extends ServiceImpl<ClassExamDao, ClassExam> i
|
||||
private ClassExamUserDao classExamUserDao;
|
||||
@Autowired
|
||||
private CourseDao courseDao;
|
||||
@Autowired
|
||||
private ClassEntityDao classEntityDao;
|
||||
@Autowired
|
||||
private RabbitTemplate rabbitTemplate;
|
||||
|
||||
@Override
|
||||
public void addClassExamSubject(ClassExamSubject classExamSubject) {
|
||||
@@ -78,6 +86,30 @@ public class ClassExamServiceImpl extends ServiceImpl<ClassExamDao, ClassExam> i
|
||||
@Override
|
||||
public void delClassExamSubject(Map<String, Object> params) {
|
||||
classExamSubjectDao.deleteById(params.get("subjectId").toString());
|
||||
classExamOptionDao.delete(new LambdaQueryWrapper<ClassExamOption>()
|
||||
.eq(ClassExamOption::getSubjectId,params.get("subjectId").toString()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void delSubjectByCourseId(Map<String, Object> params) {
|
||||
List<ClassExamSubject> list = classExamSubjectDao.selectList(new LambdaQueryWrapper<ClassExamSubject>()
|
||||
.eq(ClassExamSubject::getCourseId,params.get("courseId").toString()).select(ClassExamSubject::getId));
|
||||
if (list.size() > 0) {
|
||||
List sids = new ArrayList<>();
|
||||
List oids = new ArrayList<>();
|
||||
for (ClassExamSubject subject:list) {
|
||||
sids.add(subject.getId());
|
||||
List<ClassExamOption> os = classExamOptionDao.selectList(new LambdaQueryWrapper<ClassExamOption>()
|
||||
.eq(ClassExamOption::getSubjectId,subject.getId()).select(ClassExamOption::getId));
|
||||
if (os.size() > 0) {
|
||||
for (ClassExamOption option:os) {
|
||||
oids.add(option.getId());
|
||||
}
|
||||
}
|
||||
}
|
||||
classExamSubjectDao.deleteBatchIds(sids);
|
||||
classExamOptionDao.deleteBatchIds(oids);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -108,16 +140,25 @@ public class ClassExamServiceImpl extends ServiceImpl<ClassExamDao, ClassExam> i
|
||||
|
||||
@Override
|
||||
public R generateExamPaper(Map<String, Object> params) {
|
||||
List list = classExamUserDao.selectList(new LambdaQueryWrapper<ClassExamUser>()
|
||||
.eq(ClassExamUser::getUserId,ShiroUtils.getUId()).eq(ClassExamUser::getScoreSuccess,0));
|
||||
if (list.size() > 0){
|
||||
return R.error("存在正在考试,请结束再试");
|
||||
}
|
||||
ClassEntity classEntity = classEntityDao.selectById(params.get("classId").toString());
|
||||
MPJLambdaWrapper<ClassCourse> courseWrapper = new MPJLambdaWrapper<>();
|
||||
courseWrapper.leftJoin(ClassModel.class,ClassModel::getId,ClassCourse::getModelId);
|
||||
courseWrapper.leftJoin(ClassEntity.class,ClassEntity::getModelId,ClassModel::getId);
|
||||
courseWrapper.eq(ClassEntity::getId,params.get("classId"));
|
||||
courseWrapper.eq(ClassEntity::getId,classEntity.getId());
|
||||
courseWrapper.selectAll(ClassCourse.class);
|
||||
List<ClassCourse> courseList = classCourseDao.selectList(courseWrapper);
|
||||
List<Map<String,Object>> resultList = new ArrayList<>();
|
||||
List<String> answerList = new ArrayList<>();
|
||||
List<Map<String,Object>> sList = new ArrayList<>();
|
||||
List<Map<String,Object>> mList = new ArrayList<>();
|
||||
if (courseList.size() > 0) {
|
||||
// int stotal = 60;//单选题总数
|
||||
// int mtotal = 40;//多选题总数
|
||||
int stotal = 5;//单选题总数
|
||||
int mtotal = 5;//多选题总数
|
||||
int snum = (int)Math.floor(stotal/courseList.size());
|
||||
@@ -165,6 +206,7 @@ public class ClassExamServiceImpl extends ServiceImpl<ClassExamDao, ClassExam> i
|
||||
//拼装选项
|
||||
if (resultList.size()>0){
|
||||
for (Map<String,Object> subject:resultList) {
|
||||
answerList.add("");//预留答案位置
|
||||
List<Map<String,Object>> options = classExamOptionDao.selectMaps(new MPJLambdaWrapper<ClassExamOption>()
|
||||
.selectAs(ClassExamOption::getId,"id")
|
||||
.selectAs(ClassExamOption::getContent,"content")
|
||||
@@ -175,28 +217,59 @@ public class ClassExamServiceImpl extends ServiceImpl<ClassExamDao, ClassExam> i
|
||||
}
|
||||
}
|
||||
ClassExamUser classExamUser = new ClassExamUser();
|
||||
classExamUser.setClassId(Integer.parseInt(params.get("classId").toString()));
|
||||
classExamUser.setClassId(classEntity.getId());
|
||||
classExamUser.setSubject(JSONUtil.toJsonStr(resultList));
|
||||
classExamUser.setAnswer(JSONUtil.toJsonStr(answerList));
|
||||
classExamUser.setUserId(ShiroUtils.getUId());
|
||||
Date startTime = new Date();
|
||||
classExamUser.setStartTime(startTime);
|
||||
classExamUserDao.insert(classExamUser);
|
||||
return R.ok().put("examPaper",resultList).put("id",classExamUser.getId());
|
||||
//在考试结束时检查是否提交,未完成者自动提交
|
||||
rabbitTemplate.convertAndSend(
|
||||
DelayQueueConfig.COMMON_EXCHANGE,
|
||||
DelayQueueConfig.COMMON_ROUTING_KEY,
|
||||
"examSubmit"+","+classExamUser.getId(),
|
||||
messagePostProcessor(60*60*1000+10000)//10秒延迟
|
||||
);
|
||||
return R.ok().put("examPaper",resultList).put("id",classExamUser.getId()).put("startTime",classExamUser.getStartTime());
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public ClassExamUser examingPaper() {
|
||||
ClassExamUser classExamUser = classExamUserDao.selectOne(new LambdaQueryWrapper<ClassExamUser>()
|
||||
.eq(ClassExamUser::getUserId,ShiroUtils.getUId()).eq(ClassExamUser::getScoreSuccess,0));
|
||||
return classExamUser;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void submitOption(Map<String, Object> params) {
|
||||
ClassExamUser classExamUser = classExamUserDao.selectById(params.get("id").toString());
|
||||
List<Object> answerList = JSONUtil.parseArray(classExamUser.getAnswer());
|
||||
answerList.set((Integer)params.get("no")-1, params.get("answer").toString());
|
||||
classExamUser.setAnswer(JSONUtil.toJsonStr(answerList));
|
||||
classExamUserDao.updateById(classExamUser);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object submitExamPaper(Map<String, Object> params) {
|
||||
ClassExamUser classExamUser = classExamUserDao.selectById(params.get("id").toString());
|
||||
List<String> answerList = (List)params.get("answer");
|
||||
List<String> resAnswerList = new ArrayList<>();
|
||||
List<Object> subjectList = JSONUtil.parseArray(classExamUser.getSubject());
|
||||
List<Object> answerList = JSONUtil.parseArray(classExamUser.getAnswer());
|
||||
List<String> resAnswerList = new ArrayList<>();
|
||||
int score = 0;
|
||||
for (int i=0;i<answerList.size(); i++){
|
||||
ClassExamSubject subject = JSONUtil.toBean(JSONUtil.toJsonStr(subjectList.get(i)),ClassExamSubject.class);
|
||||
if (subject.getType()==0){
|
||||
ClassExamOption option = classExamOptionDao.selectById(answerList.get(i));
|
||||
if (option.getRightWrong()==1){
|
||||
score++;
|
||||
resAnswerList.add(answerList.get(i)+":1");
|
||||
String optionId = answerList.get(i).toString();
|
||||
if (StringUtils.isNotBlank(optionId)){
|
||||
ClassExamOption option = classExamOptionDao.selectById(optionId);
|
||||
if (option.getRightWrong()==1){
|
||||
score++;
|
||||
resAnswerList.add(answerList.get(i)+":1");
|
||||
}else {
|
||||
resAnswerList.add(answerList.get(i)+":0");
|
||||
}
|
||||
}else {
|
||||
resAnswerList.add(answerList.get(i)+":0");
|
||||
}
|
||||
@@ -205,7 +278,7 @@ public class ClassExamServiceImpl extends ServiceImpl<ClassExamDao, ClassExam> i
|
||||
boolean flag = true;
|
||||
for (ClassExamOption o:options){
|
||||
if (o.getRightWrong()==1){
|
||||
if (answerList.get(i).contains(o.getId().toString())){
|
||||
if (answerList.get(i).toString().contains(o.getId().toString())){
|
||||
}else {
|
||||
flag = false;
|
||||
}
|
||||
@@ -222,12 +295,13 @@ public class ClassExamServiceImpl extends ServiceImpl<ClassExamDao, ClassExam> i
|
||||
classExamUser.setAnswer(JSONUtil.toJsonStr(resAnswerList));
|
||||
classExamUser.setScore(score);
|
||||
classExamUser.setScoreSuccess(1);
|
||||
classExamUser.setEndTime(new Date());
|
||||
classExamUserDao.updateById(classExamUser);
|
||||
return classExamUser;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getExamPaperInfo(Map<String, Object> params) {
|
||||
public Object getExamPaperList(Map<String, Object> params) {
|
||||
List<ClassExamUser> classExamUserList = classExamUserDao.selectList(new LambdaQueryWrapper<ClassExamUser>()
|
||||
.eq(ClassExamUser::getClassId,params.get("classId"))
|
||||
.eq(ClassExamUser::getUserId,params.get("userId"))
|
||||
@@ -235,4 +309,16 @@ public class ClassExamServiceImpl extends ServiceImpl<ClassExamDao, ClassExam> i
|
||||
return classExamUserList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getExamPaperInfo(Map<String, Object> params) {
|
||||
ClassExamUser classExamUser = classExamUserDao.selectById(params.get("id").toString());
|
||||
return classExamUser;
|
||||
}
|
||||
|
||||
private MessagePostProcessor messagePostProcessor(long date) {
|
||||
return message -> {
|
||||
message.getMessageProperties().setDelay((int)date);
|
||||
return message;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
package com.peanut.modules.mq.Consumer;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.peanut.common.utils.DateUtils;
|
||||
import com.peanut.config.DelayQueueConfig;
|
||||
import com.peanut.modules.common.dao.ClassEntityDao;
|
||||
import com.peanut.modules.common.dao.ClassExamUserDao;
|
||||
import com.peanut.modules.common.entity.ClassEntity;
|
||||
import com.peanut.modules.common.entity.ClassExamUser;
|
||||
import com.peanut.modules.common.service.ClassExamService;
|
||||
import org.springframework.amqp.rabbit.annotation.RabbitListener;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
//通用延迟队列
|
||||
@Component
|
||||
public class CommonConsumer {
|
||||
|
||||
@Autowired
|
||||
private ClassEntityDao classEntityDao;
|
||||
@Autowired
|
||||
private ClassExamUserDao classExamUserDao;
|
||||
@Autowired
|
||||
private ClassExamService classexamService;
|
||||
|
||||
@RabbitListener(queues = DelayQueueConfig.COMMON_QUEUE)
|
||||
public void commonConsumer(String typeAndParam) {
|
||||
//参数为 业务模块 + , + 参数
|
||||
String[] typeAndParams = typeAndParam.split(",");
|
||||
//考试周天数,根据设置的天数将班级状态从进行中设置成考试中
|
||||
if ("examDays".equals(typeAndParams[0])){
|
||||
ClassEntity classEntity = classEntityDao.selectById(typeAndParams[1]);
|
||||
if (classEntity!=null&&!"3".equals(classEntity.getState())){
|
||||
classEntity.setState("3");
|
||||
classEntityDao.updateById(classEntity);
|
||||
}
|
||||
}
|
||||
//在考试结束时检查是否提交,未完成者自动提交
|
||||
if ("examSubmit".equals(typeAndParams[0])){
|
||||
ClassExamUser classExamUser = classExamUserDao.selectById(typeAndParams[1]);
|
||||
if (classExamUser!=null&&classExamUser.getScoreSuccess()==0){
|
||||
Map<String,Object> map = new HashMap<>();
|
||||
map.put("id",classExamUser.getId());
|
||||
classexamService.submitExamPaper(map);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user