From 14821e28286d773ad5ff2c13510e39c5eb117daf Mon Sep 17 00:00:00 2001
From: kongzy <kongzy>
Date: Fri, 05 Jul 2024 13:46:32 +0800
Subject: [PATCH] update
---
exam-system/src/main/java/com/gkhy/exam/system/service/impl/ExPaperStudentServiceImpl.java | 57 +++++++++++++++++++++++++++++++++++++++++++++------------
1 files changed, 45 insertions(+), 12 deletions(-)
diff --git a/exam-system/src/main/java/com/gkhy/exam/system/service/impl/ExPaperStudentServiceImpl.java b/exam-system/src/main/java/com/gkhy/exam/system/service/impl/ExPaperStudentServiceImpl.java
index dea8694..cd57bf4 100644
--- a/exam-system/src/main/java/com/gkhy/exam/system/service/impl/ExPaperStudentServiceImpl.java
+++ b/exam-system/src/main/java/com/gkhy/exam/system/service/impl/ExPaperStudentServiceImpl.java
@@ -1,6 +1,7 @@
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;
@@ -11,19 +12,16 @@
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>
@@ -41,6 +39,8 @@
private ExStudentAnswerMapper studentAnswerMapper;
@Autowired
private ExStudentMapper studentMapper;
+ @Autowired
+ private ExPhaseStudentMapper phaseStudentMapper;
@Override
@@ -67,6 +67,7 @@
@Override
public int addPaperStudent(ExPaperStudent paperStudent) {
+ checkUserAllowed(paperStudent);
checkStudentUnique(Collections.singletonList(paperStudent));
paperStudent.setCreateId(SecurityUtils.getUserId());
int row=baseMapper.insert(paperStudent);
@@ -77,7 +78,25 @@
}
@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){
@@ -100,7 +119,7 @@
@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);
@@ -109,13 +128,14 @@
@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);
@@ -130,7 +150,20 @@
}
+ 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) {
--
Gitblit v1.9.2