自动交卷,不保证数据不丢失
parent
8949a60f38
commit
7cd4985fbc
@ -0,0 +1,13 @@
|
||||
package com.ibeetl.jlw.enums;
|
||||
|
||||
/**
|
||||
* 系统强制交卷的类型
|
||||
*/
|
||||
public enum QuestionQueueTypeEnum {
|
||||
|
||||
// 开课题目提交
|
||||
QUESTION_SETTING_QUEUE,
|
||||
// 通用题目提交
|
||||
GENERAL_QUESTION_SETTING_QUEUE
|
||||
|
||||
}
|
@ -0,0 +1,20 @@
|
||||
package com.ibeetl.jlw.service.questionQueue.generalQuestionSettingQueue;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 功能描述: <br>
|
||||
*
|
||||
* @author: mlx
|
||||
* @description:
|
||||
* @date: 2022/12/9 1:02
|
||||
* @version: 1.0
|
||||
*/
|
||||
@Data
|
||||
public class GeneralQuestionSettingDelayed {
|
||||
|
||||
/**
|
||||
* 题目配置ID
|
||||
*/
|
||||
private Long questionSettingId;
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
package com.ibeetl.jlw.service.questionSettingQueue;
|
||||
package com.ibeetl.jlw.service.questionQueue.questionSettingQueue;
|
||||
|
||||
import lombok.Data;
|
||||
|
@ -1,66 +0,0 @@
|
||||
package com.ibeetl.jlw.service.questionSettingQueue;
|
||||
|
||||
import com.ibeetl.jlw.dao.TeacherOpenCourseQuestionLogDao;
|
||||
import com.ibeetl.jlw.entity.TeacherOpenCourseQuestionLog;
|
||||
import com.ibeetl.jlw.enums.QuestionLogAddTypeEnum;
|
||||
import com.ibeetl.jlw.service.TeacherOpenCourseQuestionLogService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Lazy;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static com.ibeetl.jlw.enums.QuestionLogAddTypeEnum.PRE_SUBMIT;
|
||||
import static com.ibeetl.jlw.service.questionSettingQueue.RedisDelayQueue.QuestionQueueTypeEnum.questionSetting;
|
||||
|
||||
/**
|
||||
* 功能描述: <br>
|
||||
*
|
||||
* @author: mlx
|
||||
* @description:
|
||||
* @date: 2022/12/9 0:41
|
||||
* @version: 1.0
|
||||
*/
|
||||
@Service
|
||||
public class QuestionSettingRedisDelayQueueImpl extends RedisDelayQueue<QuestionSettingDelayed> {
|
||||
|
||||
@Autowired
|
||||
private TeacherOpenCourseQuestionLogDao teacherOpenCourseQuestionLogDao;
|
||||
@Autowired
|
||||
private TeacherOpenCourseQuestionLogService teacherOpenCourseQuestionLogService;
|
||||
@Autowired @Lazy
|
||||
private QuestionSettingRedisDelayQueueImpl questionSettingRedisDelayQueue;
|
||||
|
||||
public QuestionSettingRedisDelayQueueImpl(RedisTemplate redisTemplate) {
|
||||
super(redisTemplate);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleMsg(QuestionSettingDelayed msg) {
|
||||
final Long questionSettingId = msg.getQuestionSettingId();
|
||||
// 查询需要更新状态的题目日志
|
||||
List<TeacherOpenCourseQuestionLog> list = teacherOpenCourseQuestionLogDao.getByQuestionLogAddType(questionSettingId, PRE_SUBMIT.name(), null);
|
||||
|
||||
// 获取需要修改的日志IDs
|
||||
List<TeacherOpenCourseQuestionLog> logList = list.stream().map(item -> {
|
||||
TeacherOpenCourseQuestionLog questionLog = new TeacherOpenCourseQuestionLog();
|
||||
questionLog.setTeacherOpenCourseQuestionLogId(item.getTeacherOpenCourseQuestionLogId());
|
||||
// 更改为交卷状态
|
||||
questionLog.setQuestionLogAddType(QuestionLogAddTypeEnum.FINALLY_SUBMIT);
|
||||
return questionLog;
|
||||
}).collect(Collectors.toList());
|
||||
// 逻辑提交试卷
|
||||
teacherOpenCourseQuestionLogService.updateBatchTemplate(logList);
|
||||
}
|
||||
|
||||
@PostConstruct
|
||||
public void consumer() {
|
||||
new Thread(() -> {
|
||||
// 为了走异步
|
||||
questionSettingRedisDelayQueue.loop(questionSetting.name());
|
||||
}).start();
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue