| | |
| | | package com.gkhy.exam.system.service.impl; |
| | | |
| | | import cn.hutool.core.util.ObjectUtil; |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.gkhy.exam.common.api.CommonPage; |
| | | import com.gkhy.exam.common.domain.entity.SysUser; |
| | |
| | | import com.gkhy.exam.common.utils.SecurityUtils; |
| | | import com.gkhy.exam.system.domain.ExExamPaper; |
| | | import com.gkhy.exam.system.domain.ExPaperStudent; |
| | | import com.gkhy.exam.system.domain.ExPhaseStudent; |
| | | import com.gkhy.exam.system.domain.ExStudent; |
| | | import com.gkhy.exam.system.mapper.ExExamPaperMapper; |
| | | import com.gkhy.exam.system.mapper.ExPaperStudentMapper; |
| | | import com.gkhy.exam.system.mapper.ExStudentAnswerMapper; |
| | | import com.gkhy.exam.system.mapper.ExStudentMapper; |
| | | import com.gkhy.exam.system.mapper.*; |
| | | import com.gkhy.exam.system.service.ExPaperStudentService; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import java.util.Collections; |
| | | import java.util.List; |
| | | import java.util.Objects; |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | | * <p> |
| | |
| | | private ExStudentAnswerMapper studentAnswerMapper; |
| | | @Autowired |
| | | private ExStudentMapper studentMapper; |
| | | @Autowired |
| | | private ExPhaseStudentMapper phaseStudentMapper; |
| | | |
| | | |
| | | @Override |
| | |
| | | |
| | | @Override |
| | | public int addPaperStudent(ExPaperStudent paperStudent) { |
| | | checkUserAllowed(paperStudent); |
| | | checkStudentUnique(Collections.singletonList(paperStudent)); |
| | | paperStudent.setCreateId(SecurityUtils.getUserId()); |
| | | int row=baseMapper.insert(paperStudent); |
| | |
| | | } |
| | | |
| | | @Override |
| | | public int batchAddPaperStudent(List<ExPaperStudent> paperStudents) { |
| | | public int batchAddPaperStudent(Map<String,Object> paperStudentMap) { |
| | | List<Long> phaseIds= (List<Long>) paperStudentMap.get("phaseIds"); |
| | | List<Long> studentIds= (List<Long>) paperStudentMap.get("studentIds"); |
| | | if(ObjectUtil.isEmpty(phaseIds) && ObjectUtil.isEmpty(studentIds)){ |
| | | throw new ApiException("批次id与学员id不能同时为空"); |
| | | } |
| | | Long paperId= (Long) paperStudentMap.get("paperId"); |
| | | if(paperId==null){ |
| | | throw new ApiException("考卷id不能为空"); |
| | | } |
| | | //按批次绑定用户 |
| | | if(phaseIds.size()>0){ |
| | | List<ExPhaseStudent> phaseStudentList=phaseStudentMapper.selectList( Wrappers.<ExPhaseStudent>lambdaQuery() |
| | | .in(ExPhaseStudent::getPhaseId, phaseIds)); |
| | | studentIds=phaseStudentList.stream().map(item -> item.getStudentId()).distinct().collect(Collectors.toList()); |
| | | } |
| | | List<ExPaperStudent> paperStudents=studentIds.stream().map(item -> { |
| | | return new ExPaperStudent().setPaperId(paperId).setStudentId(item); |
| | | }).collect(Collectors.toList()); |
| | | checkStudentUnique(paperStudents); |
| | | int row=baseMapper.batchInsert(paperStudents); |
| | | if(row<1){ |
| | |
| | | @Override |
| | | public CommonPage selectPaperStudentList(ExPaperStudent paperStudent) { |
| | | if(paperStudent.getPaperId()==null){ |
| | | throw new ApiException("试卷id不能为空"); |
| | | throw new ApiException("考卷id不能为空"); |
| | | } |
| | | PageUtils.startPage(); |
| | | List<ExPaperStudent> paperStudentList=baseMapper.selectPaperStudentList(paperStudent); |
| | |
| | | |
| | | @Override |
| | | public int deletePaperStudent(Long paperStudentId) { |
| | | ExPaperStudent paperStudent=baseMapper.selectPaperStudentById(paperStudentId); |
| | | ExPaperStudent paperStudent=baseMapper.selectSimplePaperStudentById(paperStudentId); |
| | | if(ObjectUtil.isNull(paperStudent)){ |
| | | throw new ApiException(String.format("该试卷下不存在该学员<>",paperStudent.getStudentName())); |
| | | throw new ApiException("学员与试卷关系不存在"); |
| | | } |
| | | checkUserAllowed(paperStudent); |
| | | int studentAnswerCount=studentAnswerMapper.countByPaperId(paperStudent.getPaperId(),paperStudent.getStudentId()); |
| | | if(studentAnswerCount>0){ |
| | | throw new ApiException(String.format("学员<%s>已进行答题,不能删除",paperStudent.getStudentName())); |
| | | throw new ApiException("学员已进行答题,不能删除"); |
| | | } |
| | | //删除学员与试卷关系 |
| | | return baseMapper.deleteById(paperStudentId); |
| | |
| | | } |
| | | |
| | | |
| | | public void checkUserAllowed(ExPaperStudent paperStudent) { |
| | | SysUser currentUser= SecurityUtils.getLoginUser().getUser(); |
| | | if(currentUser.getUserType().equals(UserTypeEnum.SYSTEM_USER.getCode())){ |
| | | return; |
| | | } |
| | | if(currentUser.getUserType().equals(UserTypeEnum.STUDENT.getCode())){ |
| | | throw new ApiException("没有权限操作"); |
| | | } |
| | | ExExamPaper examPaper=examPaperMapper.selectById(paperStudent.getPaperId()); |
| | | if(!currentUser.getCompanyId().equals(examPaper.getCompanyId())){ |
| | | throw new ApiException("没有权限操作其他企业考卷"); |
| | | } |
| | | |
| | | } |
| | | |
| | | @Override |
| | | public void endExam(ExPaperStudent paperStudent) { |