添加考试周时长

This commit is contained in:
wuchunlei
2024-09-04 17:15:25 +08:00
parent beb4ef6297
commit a316090e81
10 changed files with 239 additions and 14 deletions

View File

@@ -64,6 +64,11 @@ public class DelayQueueConfig {
public static final String COURSE_EXCHANGE = "course_exchange"; public static final String COURSE_EXCHANGE = "course_exchange";
public static final String COURSE_ROUTING_KEY = "course_routingKey"; 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(); .noargs();
} }
//课程过期延迟队列 //课程过期延迟队列
@Bean @Bean
public Queue courseQueue() { public Queue courseQueue() {
@@ -270,6 +274,27 @@ public class DelayQueueConfig {
.noargs(); .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 @Bean

View File

@@ -274,6 +274,10 @@ public class ClassController {
//新增作业 //新增作业
@RequestMapping("/addClassTaskAndQuesReply") @RequestMapping("/addClassTaskAndQuesReply")
public R addClassTaskAndQuesReply(@RequestBody ClassTaskAndQuesReply classTaskAndQuesReply){ public R addClassTaskAndQuesReply(@RequestBody ClassTaskAndQuesReply classTaskAndQuesReply){
ClassEntity classEntity = classEntityService.getById(classTaskAndQuesReply.getClassId());
if ("3".equals(classEntity.getState())) {
return R.error("考试周禁止提交作业");
}
classEntityService.addClassTaskAndQuesReply(classTaskAndQuesReply); classEntityService.addClassTaskAndQuesReply(classTaskAndQuesReply);
return R.ok(); return R.ok();
} }

View File

@@ -166,6 +166,13 @@ public class ClassExamController {
return classExamService.generateExamPaper(params); return classExamService.generateExamPaper(params);
} }
//提交选项
@RequestMapping("/submitOption")
public R submitOption(@RequestBody Map<String,Object> params){
classExamService.submitOption(params);
return R.ok();
}
//提交试卷 //提交试卷
@RequestMapping("/submitExamPaper") @RequestMapping("/submitExamPaper")
public R submitExamPaper(@RequestBody Map<String,Object> params){ public R submitExamPaper(@RequestBody Map<String,Object> params){
@@ -173,6 +180,13 @@ public class ClassExamController {
return R.ok().put("examPaper",examPaper); 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") @RequestMapping("/getExamPaperInfo")
public R getExamPaperInfo(@RequestBody Map<String,Object> params){ public R getExamPaperInfo(@RequestBody Map<String,Object> params){
@@ -226,6 +240,13 @@ public class ClassExamController {
return R.ok(); return R.ok();
} }
//删除课程下全部题目
@RequestMapping("/delSubjectByCourseId")
public R delSubjectByCourseId(@RequestBody Map<String,Object> params){
classExamService.delSubjectByCourseId(params);
return R.ok();
}
//删除选项 //删除选项
@RequestMapping("/delClassExamOption") @RequestMapping("/delClassExamOption")
public R delClassExamOption(@RequestBody Map<String,Object> params){ public R delClassExamOption(@RequestBody Map<String,Object> params){

View File

@@ -20,7 +20,7 @@ public class ClassEntity {
private String title; private String title;
//小班状态 0待开班1进行中2完成 //小班状态 0待开班1进行中2完成3考试中
private String state; private String state;
private String icon; private String icon;

View File

@@ -5,6 +5,8 @@ import com.baomidou.mybatisplus.annotation.TableLogic;
import com.baomidou.mybatisplus.annotation.TableName; import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data; import lombok.Data;
import java.util.Date;
@Data @Data
@TableName("class_exam_user") @TableName("class_exam_user")
public class ClassExamUser { public class ClassExamUser {
@@ -24,6 +26,10 @@ public class ClassExamUser {
private String answer; private String answer;
private Date startTime;
private Date endTime;
@TableLogic @TableLogic
private Integer delFlag; private Integer delFlag;
} }

View File

@@ -25,6 +25,8 @@ public class ClassModel {
private Integer days;//教学天数 private Integer days;//教学天数
private Integer examDays;//考试周时长
private Integer isQuestion; private Integer isQuestion;
private Integer questionScore; private Integer questionScore;
private Integer isTask; private Integer isTask;

View File

@@ -22,14 +22,20 @@ public interface ClassExamService extends IService<ClassExam> {
void delClassExamSubject(Map<String,Object> params); void delClassExamSubject(Map<String,Object> params);
void delSubjectByCourseId(Map<String,Object> params);
void delClassExamOption(Map<String,Object> params); void delClassExamOption(Map<String,Object> params);
Page getClassExamSubjectList(Map<String,Object> params); Page getClassExamSubjectList(Map<String,Object> params);
R generateExamPaper(Map<String,Object> params); R generateExamPaper(Map<String,Object> params);
void submitOption(Map<String,Object> params);
Object submitExamPaper(Map<String,Object> params); Object submitExamPaper(Map<String,Object> params);
Object getExamPaperList(Map<String,Object> params);
Object getExamPaperInfo(Map<String,Object> params); Object getExamPaperInfo(Map<String,Object> params);
} }

View File

@@ -1,5 +1,6 @@
package com.peanut.modules.common.service.impl; package com.peanut.modules.common.service.impl;
import cn.hutool.core.date.DateUtil;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; 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.DateUtils;
import com.peanut.common.utils.R; import com.peanut.common.utils.R;
import com.peanut.common.utils.ShiroUtils; import com.peanut.common.utils.ShiroUtils;
import com.peanut.config.DelayQueueConfig;
import com.peanut.modules.common.dao.*; import com.peanut.modules.common.dao.*;
import com.peanut.modules.common.entity.*; import com.peanut.modules.common.entity.*;
import com.peanut.modules.common.service.ClassEntityService; 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 com.peanut.modules.sys.entity.SysUserEntity;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils; 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.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.math.RoundingMode; import java.math.RoundingMode;
import java.time.LocalDate;
import java.util.*; import java.util.*;
@Slf4j @Slf4j
@@ -49,6 +54,8 @@ public class ClassEntityServiceImpl extends ServiceImpl<ClassEntityDao, ClassEnt
private ClassExamUserDao classExamUserDao; private ClassExamUserDao classExamUserDao;
@Autowired @Autowired
private CourseCatalogueChapterDao courseCatalogueChapterDao; private CourseCatalogueChapterDao courseCatalogueChapterDao;
@Autowired
private RabbitTemplate rabbitTemplate;
@Override @Override
public Page getClassModelList(Map<String, Object> params) { 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())){ if (StringUtils.isNotEmpty(params.get("title").toString())){
wrapper.like(ClassModel::getTitle,params.get("title")); 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); wrapper.orderByDesc(ClassModel::getId);
Page<ClassModel> classModelPage = classModelDao.selectPage(new Page<>(page, limit), wrapper); Page<ClassModel> classModelPage = classModelDao.selectPage(new Page<>(page, limit), wrapper);
for (ClassModel classModel:classModelPage.getRecords()){ for (ClassModel classModel:classModelPage.getRecords()){
@@ -223,6 +233,7 @@ public class ClassEntityServiceImpl extends ServiceImpl<ClassEntityDao, ClassEnt
} }
@Override @Override
@Transactional
public R updateClassState(Map<String, Object> params) { public R updateClassState(Map<String, Object> params) {
String state = params.get("state").toString(); String state = params.get("state").toString();
ClassEntity classEntity = this.getBaseMapper().selectById(params.get("classId").toString()); ClassEntity classEntity = this.getBaseMapper().selectById(params.get("classId").toString());
@@ -296,11 +307,24 @@ public class ClassEntityServiceImpl extends ServiceImpl<ClassEntityDao, ClassEnt
Date startTime = new Date(); Date startTime = new Date();
classEntity.setStartTime(startTime); classEntity.setStartTime(startTime);
classEntity.setEndTime(DateUtils.addDateDays(startTime,classModelDao.selectById(classEntity.getModelId()).getDays())); 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(DateUtils.addDateDays(
DateUtil.parseDate(LocalDate.now().toString()),
classModel.getDays()-classModel.getExamDays())
.getTime())
);
}
}else { }else {
classEntity.setState("2"); classEntity.setState("2");
classEntity.setEndTime(new Date()); classEntity.setEndTime(new Date());
this.getBaseMapper().updateById(classEntity);
} }
this.getBaseMapper().updateById(classEntity);
return R.ok(); return R.ok();
} }
@@ -1161,4 +1185,11 @@ public class ClassEntityServiceImpl extends ServiceImpl<ClassEntityDao, ClassEnt
} }
private MessagePostProcessor messagePostProcessor(long date) {
return message -> {
message.getMessageProperties().setDelay((int)date);
return message;
};
}
} }

View File

@@ -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.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.yulichang.wrapper.MPJLambdaWrapper; import com.github.yulichang.wrapper.MPJLambdaWrapper;
import com.peanut.common.utils.DateUtils;
import com.peanut.common.utils.R; import com.peanut.common.utils.R;
import com.peanut.common.utils.ShiroUtils; import com.peanut.common.utils.ShiroUtils;
import com.peanut.config.DelayQueueConfig;
import com.peanut.modules.common.dao.*; import com.peanut.modules.common.dao.*;
import com.peanut.modules.common.entity.*; import com.peanut.modules.common.entity.*;
import com.peanut.modules.common.service.ClassExamService; import com.peanut.modules.common.service.ClassExamService;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils; 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.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.*; import java.util.*;
@@ -30,6 +34,10 @@ public class ClassExamServiceImpl extends ServiceImpl<ClassExamDao, ClassExam> i
private ClassExamUserDao classExamUserDao; private ClassExamUserDao classExamUserDao;
@Autowired @Autowired
private CourseDao courseDao; private CourseDao courseDao;
@Autowired
private ClassEntityDao classEntityDao;
@Autowired
private RabbitTemplate rabbitTemplate;
@Override @Override
public void addClassExamSubject(ClassExamSubject classExamSubject) { public void addClassExamSubject(ClassExamSubject classExamSubject) {
@@ -78,6 +86,30 @@ public class ClassExamServiceImpl extends ServiceImpl<ClassExamDao, ClassExam> i
@Override @Override
public void delClassExamSubject(Map<String, Object> params) { public void delClassExamSubject(Map<String, Object> params) {
classExamSubjectDao.deleteById(params.get("subjectId").toString()); 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 @Override
@@ -108,16 +140,20 @@ public class ClassExamServiceImpl extends ServiceImpl<ClassExamDao, ClassExam> i
@Override @Override
public R generateExamPaper(Map<String, Object> params) { public R generateExamPaper(Map<String, Object> params) {
ClassEntity classEntity = classEntityDao.selectById(params.get("classId").toString());
MPJLambdaWrapper<ClassCourse> courseWrapper = new MPJLambdaWrapper<>(); MPJLambdaWrapper<ClassCourse> courseWrapper = new MPJLambdaWrapper<>();
courseWrapper.leftJoin(ClassModel.class,ClassModel::getId,ClassCourse::getModelId); courseWrapper.leftJoin(ClassModel.class,ClassModel::getId,ClassCourse::getModelId);
courseWrapper.leftJoin(ClassEntity.class,ClassEntity::getModelId,ClassModel::getId); 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); courseWrapper.selectAll(ClassCourse.class);
List<ClassCourse> courseList = classCourseDao.selectList(courseWrapper); List<ClassCourse> courseList = classCourseDao.selectList(courseWrapper);
List<Map<String,Object>> resultList = new ArrayList<>(); List<Map<String,Object>> resultList = new ArrayList<>();
List<String> answerList = new ArrayList<>();
List<Map<String,Object>> sList = new ArrayList<>(); List<Map<String,Object>> sList = new ArrayList<>();
List<Map<String,Object>> mList = new ArrayList<>(); List<Map<String,Object>> mList = new ArrayList<>();
if (courseList.size() > 0) { if (courseList.size() > 0) {
// int stotal = 60;//单选题总数
// int mtotal = 40;//多选题总数
int stotal = 5;//单选题总数 int stotal = 5;//单选题总数
int mtotal = 5;//多选题总数 int mtotal = 5;//多选题总数
int snum = (int)Math.floor(stotal/courseList.size()); int snum = (int)Math.floor(stotal/courseList.size());
@@ -165,6 +201,7 @@ public class ClassExamServiceImpl extends ServiceImpl<ClassExamDao, ClassExam> i
//拼装选项 //拼装选项
if (resultList.size()>0){ if (resultList.size()>0){
for (Map<String,Object> subject:resultList) { for (Map<String,Object> subject:resultList) {
answerList.add("");//预留答案位置
List<Map<String,Object>> options = classExamOptionDao.selectMaps(new MPJLambdaWrapper<ClassExamOption>() List<Map<String,Object>> options = classExamOptionDao.selectMaps(new MPJLambdaWrapper<ClassExamOption>()
.selectAs(ClassExamOption::getId,"id") .selectAs(ClassExamOption::getId,"id")
.selectAs(ClassExamOption::getContent,"content") .selectAs(ClassExamOption::getContent,"content")
@@ -175,28 +212,53 @@ public class ClassExamServiceImpl extends ServiceImpl<ClassExamDao, ClassExam> i
} }
} }
ClassExamUser classExamUser = new ClassExamUser(); ClassExamUser classExamUser = new ClassExamUser();
classExamUser.setClassId(Integer.parseInt(params.get("classId").toString())); classExamUser.setClassId(classEntity.getId());
classExamUser.setSubject(JSONUtil.toJsonStr(resultList)); classExamUser.setSubject(JSONUtil.toJsonStr(resultList));
classExamUser.setAnswer(JSONUtil.toJsonStr(answerList));
classExamUser.setUserId(ShiroUtils.getUId()); classExamUser.setUserId(ShiroUtils.getUId());
Date startTime = new Date();
classExamUser.setStartTime(startTime);
classExamUserDao.insert(classExamUser); classExamUserDao.insert(classExamUser);
return R.ok().put("examPaper",resultList).put("id",classExamUser.getId()); //在考试结束时检查是否提交,未完成者自动提交
//时间为2小时再队列执行中也有设置修改时要同步修改
rabbitTemplate.convertAndSend(
DelayQueueConfig.COMMON_EXCHANGE,
DelayQueueConfig.COMMON_ROUTING_KEY,
"examSubmit"+","+classExamUser.getId(),
messagePostProcessor(DateUtils.addDateHours(startTime,2).getTime())
);
return R.ok().put("examPaper",resultList).put("id",classExamUser.getId()).put("startTime",classExamUser.getStartTime());
} }
@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 @Override
public Object submitExamPaper(Map<String, Object> params) { public Object submitExamPaper(Map<String, Object> params) {
ClassExamUser classExamUser = classExamUserDao.selectById(params.get("id").toString()); 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> subjectList = JSONUtil.parseArray(classExamUser.getSubject());
List<Object> answerList = JSONUtil.parseArray(classExamUser.getAnswer());
List<String> resAnswerList = new ArrayList<>();
int score = 0; int score = 0;
for (int i=0;i<answerList.size(); i++){ for (int i=0;i<answerList.size(); i++){
ClassExamSubject subject = JSONUtil.toBean(JSONUtil.toJsonStr(subjectList.get(i)),ClassExamSubject.class); ClassExamSubject subject = JSONUtil.toBean(JSONUtil.toJsonStr(subjectList.get(i)),ClassExamSubject.class);
if (subject.getType()==0){ if (subject.getType()==0){
ClassExamOption option = classExamOptionDao.selectById(answerList.get(i)); String optionId = answerList.get(i).toString();
if (option.getRightWrong()==1){ if (StringUtils.isNotBlank(optionId)){
score++; ClassExamOption option = classExamOptionDao.selectById(optionId);
resAnswerList.add(answerList.get(i)+":1"); if (option.getRightWrong()==1){
score++;
resAnswerList.add(answerList.get(i)+":1");
}else {
resAnswerList.add(answerList.get(i)+":0");
}
}else { }else {
resAnswerList.add(answerList.get(i)+":0"); resAnswerList.add(answerList.get(i)+":0");
} }
@@ -205,7 +267,7 @@ public class ClassExamServiceImpl extends ServiceImpl<ClassExamDao, ClassExam> i
boolean flag = true; boolean flag = true;
for (ClassExamOption o:options){ for (ClassExamOption o:options){
if (o.getRightWrong()==1){ if (o.getRightWrong()==1){
if (answerList.get(i).contains(o.getId().toString())){ if (answerList.get(i).toString().contains(o.getId().toString())){
}else { }else {
flag = false; flag = false;
} }
@@ -222,12 +284,13 @@ public class ClassExamServiceImpl extends ServiceImpl<ClassExamDao, ClassExam> i
classExamUser.setAnswer(JSONUtil.toJsonStr(resAnswerList)); classExamUser.setAnswer(JSONUtil.toJsonStr(resAnswerList));
classExamUser.setScore(score); classExamUser.setScore(score);
classExamUser.setScoreSuccess(1); classExamUser.setScoreSuccess(1);
classExamUser.setEndTime(new Date());
classExamUserDao.updateById(classExamUser); classExamUserDao.updateById(classExamUser);
return classExamUser; return classExamUser;
} }
@Override @Override
public Object getExamPaperInfo(Map<String, Object> params) { public Object getExamPaperList(Map<String, Object> params) {
List<ClassExamUser> classExamUserList = classExamUserDao.selectList(new LambdaQueryWrapper<ClassExamUser>() List<ClassExamUser> classExamUserList = classExamUserDao.selectList(new LambdaQueryWrapper<ClassExamUser>()
.eq(ClassExamUser::getClassId,params.get("classId")) .eq(ClassExamUser::getClassId,params.get("classId"))
.eq(ClassExamUser::getUserId,params.get("userId")) .eq(ClassExamUser::getUserId,params.get("userId"))
@@ -235,4 +298,16 @@ public class ClassExamServiceImpl extends ServiceImpl<ClassExamDao, ClassExam> i
return classExamUserList; 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;
};
}
} }

View File

@@ -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.USERVIP_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);
}
}
}
}