我的考试查询考试
This commit is contained in:
parent
989d1db754
commit
1e0fb9883b
@ -20,14 +20,19 @@ import com.baomidou.mybatisplus.core.toolkit.IdWorker;
|
||||
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
|
||||
import org.apache.poi.ss.usermodel.Workbook;
|
||||
import org.jeecg.common.api.vo.Result;
|
||||
import org.jeecg.common.constant.CommonConstant;
|
||||
import org.jeecg.common.system.api.ISysBaseAPI;
|
||||
import org.jeecg.common.system.query.QueryGenerator;
|
||||
import org.jeecg.common.system.query.QueryRuleEnum;
|
||||
import org.jeecg.common.system.util.JwtUtil;
|
||||
import org.jeecg.common.system.vo.LoginUser;
|
||||
import org.jeecg.common.util.oConvertUtils;
|
||||
import org.jeecg.modules.aiol.dto.ExaminationResult;
|
||||
import org.jeecg.modules.aiol.dto.QuestionAnswerDTO;
|
||||
import org.jeecg.modules.aiol.dto.QuestionAnswerUser;
|
||||
import org.jeecg.modules.aiol.dto.QuestionExcelDTO;
|
||||
import org.jeecg.modules.aiol.entity.*;
|
||||
import org.jeecg.modules.aiol.mapper.AiolCourseSignupMapper;
|
||||
import org.jeecg.modules.aiol.service.*;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
@ -35,6 +40,7 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import org.jeecg.modules.system.service.ISysUserService;
|
||||
import org.jeecgframework.poi.excel.ExcelExportUtil;
|
||||
import org.jeecgframework.poi.excel.ExcelImportUtil;
|
||||
import org.jeecgframework.poi.excel.def.NormalExcelConstants;
|
||||
@ -43,6 +49,7 @@ import org.jeecgframework.poi.excel.entity.ImportParams;
|
||||
import org.jeecgframework.poi.excel.view.JeecgEntityExcelView;
|
||||
import org.jeecg.common.system.base.controller.JeecgController;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
@ -66,6 +73,16 @@ import org.apache.shiro.authz.annotation.RequiresPermissions;
|
||||
public class AiolExamController extends JeecgController<AiolExam, IAiolExamService> {
|
||||
@Autowired
|
||||
private IAiolExamService aiolExamService;
|
||||
@Autowired
|
||||
private IAiolCourseSectionService aiolCourseSectionService;
|
||||
@Autowired
|
||||
private ISysBaseAPI sysBaseApi;
|
||||
@Autowired
|
||||
private IAiolEntityLinkService aiolEntityLinkService;
|
||||
@Autowired
|
||||
private AiolCourseSignupMapper aiolCourseSignupMapper;
|
||||
@Autowired
|
||||
private IAiolExamRecordService aiolExamRecordService;
|
||||
|
||||
/**
|
||||
* 分页列表查询
|
||||
@ -1423,4 +1440,144 @@ public class AiolExamController extends JeecgController<AiolExam, IAiolExamServi
|
||||
deviceInfo.append(" | ").append(isMobile ? "Mobile" : "PC");
|
||||
return deviceInfo.toString();
|
||||
}
|
||||
}
|
||||
|
||||
@Operation(summary = "我的考试-考试查询")
|
||||
@GetMapping(value = "/myExamList")
|
||||
public Result<?> queryMyExamList(HttpServletRequest request,@RequestParam(name = "type" , defaultValue = "4" , required = false) Integer type) {
|
||||
// 尝试获取token,判断用户id
|
||||
String token = request.getHeader(CommonConstant.X_ACCESS_TOKEN);
|
||||
List<MyExamDTO> myExamDTOList = new ArrayList<>();
|
||||
if (token != null && !token.trim().isEmpty()) {
|
||||
try {
|
||||
String username = JwtUtil.getUsername(token);
|
||||
LoginUser sysUser = sysBaseApi.getUserByName(username);
|
||||
if (sysUser != null) {
|
||||
|
||||
//获取课程id列表
|
||||
List<AiolCourseSignup> courseSignupList = aiolCourseSignupMapper.selectList(
|
||||
new QueryWrapper<AiolCourseSignup>()
|
||||
.eq("user_id", sysUser.getId())
|
||||
.select("course_id")
|
||||
);
|
||||
|
||||
// 获取课程章节id列表
|
||||
List<AiolCourseSection> courseId = aiolCourseSectionService.list(
|
||||
new QueryWrapper<AiolCourseSection>()
|
||||
.in("course_id", courseSignupList.stream().map(AiolCourseSignup::getCourseId).collect(Collectors.toList()))
|
||||
.select("id"));
|
||||
List<String> courseIdList = courseId.stream()
|
||||
.map(AiolCourseSection::getId)
|
||||
.collect(Collectors.toList());
|
||||
|
||||
//获取实体列表里的考试
|
||||
List<String> list = new ArrayList<>();
|
||||
if (!courseIdList.isEmpty()) {
|
||||
list = aiolEntityLinkService.list(new QueryWrapper<AiolEntityLink>()
|
||||
.eq("source_type", "course_section")
|
||||
.in("source_id", courseIdList)
|
||||
.eq("target_type", "exam")
|
||||
.select("target_id")).stream().map(AiolEntityLink::getTargetId).collect(Collectors.toList());
|
||||
} else return Result.ok();
|
||||
|
||||
// 查询考试
|
||||
QueryWrapper<AiolExam> queryWrapper = new QueryWrapper<>();
|
||||
//正式考试
|
||||
queryWrapper.eq("type",1);
|
||||
if (type != 4) {
|
||||
queryWrapper.eq("status", type);
|
||||
}
|
||||
if (!list.isEmpty()) {
|
||||
queryWrapper.in("id", list);
|
||||
} else return Result.ok();
|
||||
|
||||
// 查询考试列表并去重
|
||||
List<AiolExam> examList = aiolExamService.list(queryWrapper)
|
||||
.stream()
|
||||
.distinct()
|
||||
.collect(Collectors.toList());
|
||||
|
||||
// 查询考试关联的考试记录
|
||||
if(examList.isEmpty()){
|
||||
return Result.ok();
|
||||
}
|
||||
List<AiolExamRecord> examRecordList = aiolExamRecordService.
|
||||
list(
|
||||
new QueryWrapper<AiolExamRecord>().
|
||||
in("exam_id", examList.stream().map(AiolExam::getId).collect(Collectors.toList()))
|
||||
);
|
||||
// 预先构建examId到examRecord的Map
|
||||
Map<String, AiolExamRecord> examRecordMap = examRecordList.stream()
|
||||
.collect(Collectors.toMap(
|
||||
AiolExamRecord::getExamId,
|
||||
record -> record,
|
||||
(existing, replacement) -> existing // 如果有重复key,保留第一个
|
||||
));
|
||||
for (AiolExam exam : examList) {
|
||||
MyExamDTO myExamDTO = new MyExamDTO();
|
||||
myExamDTO.setExamId(exam.getId());
|
||||
myExamDTO.setExamName(exam.getName());
|
||||
long currentTime = new Date().getTime();
|
||||
long startTime = 0 ;
|
||||
long endTime = 0 ;
|
||||
if (exam.getStartTime()!= null){
|
||||
startTime = exam.getStartTime().getTime();
|
||||
}
|
||||
if (exam.getEndTime()!= null){
|
||||
endTime = exam.getEndTime().getTime();
|
||||
}
|
||||
if(startTime==0||endTime==0){
|
||||
myExamDTO.setExamStatus("未设置起始时间或结束时间,请联系教师"); // 未开始
|
||||
} else if ( startTime > currentTime ) {
|
||||
myExamDTO.setExamStatus("未开始"); // 未开始
|
||||
} else if ( currentTime <= endTime ) {
|
||||
myExamDTO.setExamStatus("进行中"); // 进行中
|
||||
} else {
|
||||
myExamDTO.setExamStatus("已结束"); // 已结束
|
||||
}
|
||||
myExamDTO.setExamStartTime(exam.getStartTime());
|
||||
myExamDTO.setExamTime(exam.getTotalTime());
|
||||
AiolExamRecord examRecord = examRecordMap.get(exam.getId());
|
||||
if (examRecord != null) {
|
||||
myExamDTO.setExamScore(examRecord.getTotalScore());
|
||||
}
|
||||
myExamDTOList.add(myExamDTO);
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
return Result.error(e.getMessage());
|
||||
}
|
||||
}
|
||||
return Result.ok(myExamDTOList);
|
||||
}
|
||||
|
||||
@Scheduled(cron = "0 */5 * * * ?") // 每5分钟执行一次
|
||||
public void updateExamStatus() {
|
||||
// 获取当前时间
|
||||
Date now = new Date();
|
||||
log.info("\u001B[32m执行更新试卷状态------------开始\u001B[0m");
|
||||
// 查询所有需要更新的考试
|
||||
List<AiolExam> examsToUpdate = aiolExamService.list(new LambdaQueryWrapper<AiolExam>()
|
||||
.in(AiolExam::getStatus, Arrays.asList(1, 2))
|
||||
.and(wrapper -> wrapper
|
||||
.lt(AiolExam::getStartTime, now)
|
||||
.or()
|
||||
.lt(AiolExam::getEndTime, now)
|
||||
));
|
||||
|
||||
// 批量更新
|
||||
for (AiolExam exam : examsToUpdate) {
|
||||
if (exam.getStatus() == 1 && now.after(exam.getStartTime())) {
|
||||
exam.setStatus(2);
|
||||
} else if (exam.getStatus() == 2 && now.after(exam.getEndTime())) {
|
||||
exam.setStatus(3);
|
||||
}
|
||||
}
|
||||
|
||||
if (!examsToUpdate.isEmpty()) {
|
||||
aiolExamService.updateBatchById(examsToUpdate);
|
||||
}
|
||||
|
||||
log.info("\u001B[32m执行更新试卷状态------------结束\u001B[0m");
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,23 @@
|
||||
package org.jeecg.modules.aiol.entity;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
@Data
|
||||
public class MyExamDTO {
|
||||
@Schema(description = "试卷id")
|
||||
private String examId;
|
||||
@Schema(description = "试卷名")
|
||||
private String examName;
|
||||
@Schema(description = "试卷状态")
|
||||
private String examStatus;
|
||||
@Schema(description = "试卷开始时间")
|
||||
private Date examStartTime;
|
||||
@Schema(description = "试卷时长")
|
||||
private Integer examTime;
|
||||
@Schema(description = "试卷得分")
|
||||
private Double examScore;
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user