BatchExamStudentsServiceImpl.java 2.44 KB
package com.meishu.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.meishu.model.BatchExamStudentsDO;
import com.meishu.mapper.BatchExamsStudentsMapper;
import com.meishu.service.BatchExamStudentsService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.meishu.vo.exam.BatchExamStudentScoreVO;
import com.meishu.vo.paper.PapersVO;
import com.meishu.vo.student.StudentExamsVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

/**
 * <p>
 * 学生考试映射表 服务实现类
 * </p>
 *
 * @author Tuyp
 * @since 2023-07-11
 */
@Service
public class BatchExamStudentsServiceImpl extends ServiceImpl<BatchExamsStudentsMapper, BatchExamStudentsDO> implements BatchExamStudentsService {

    public List<PapersVO> exams(BatchExamStudentsDO studentExamsDO) throws Exception{
        List<PapersVO> exams = this.baseMapper.exams(studentExamsDO.getStudentId());
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        for (PapersVO vo : exams) {
            //未开始  进行中 已结束
            if (simpleDateFormat.parse(vo.getStartDate()).after(new Date())) {
                vo.setStatus("未开始");
            } else if (simpleDateFormat.parse(vo.getEndDate()).before(new Date())) {
                vo.setStatus("已结束");
            } else {
                vo.setStatus("进行中");
            }
            //是否已经参加过考试了
            BatchExamStudentsDO batchExamStudentsDO = this.baseMapper.selectOne(new QueryWrapper<BatchExamStudentsDO>()
            .lambda()
            .eq(BatchExamStudentsDO::getBatchExamId,vo.getId())
            .eq(BatchExamStudentsDO::getStudentId,studentExamsDO.getStudentId()));
            if (null == batchExamStudentsDO.getScore()){
                vo.setSubmitStatus(false);
            }else {
                vo.setSubmitStatus(true);
            }
        }
        return exams;
    }

    public List<StudentExamsVO> studentExams(BatchExamStudentsDO studentExamsDO) {
        return this.baseMapper.studentScore(studentExamsDO.getStudentId());
    }

    public List<BatchExamStudentScoreVO> batchExamStudentScore(BatchExamStudentsDO batchExamStudentsDO) {
        return this.baseMapper.batchExamStudentScore(batchExamStudentsDO.getBatchExamId());
    }

}