【修改】试题、人员、试卷任务删除提示xx编号不能删除

This commit is contained in:
YOHO\20373
2025-06-13 01:47:28 +08:00
parent a11877976c
commit ce02eb0a22
15 changed files with 200 additions and 44 deletions

View File

@@ -149,7 +149,7 @@ public class EducationPaperPersonController
*/
@Operation(summary = "删除场次学生")
@DeleteMapping("/removeSessionStu")
public CommonResult<Integer> removeSessionStu(@RequestBody StudentSessionReqVO reqVO) {
public CommonResult<String> removeSessionStu(@RequestBody StudentSessionReqVO reqVO) {
return CommonResult.success(educationPaperPersonService.removeSessionStu(reqVO));
}
@@ -161,7 +161,7 @@ public class EducationPaperPersonController
*/
@Operation(summary = "删除任务学生")
@DeleteMapping("/removeTaskStu")
public CommonResult<Integer> removeTaskStu(@RequestBody DeleteRequestVo deleteRequestVo) {
public CommonResult<String> removeTaskStu(@RequestBody DeleteRequestVo deleteRequestVo) {
return CommonResult.success(educationPaperPersonService.removeTaskStu(deleteRequestVo));
}

View File

@@ -173,5 +173,11 @@ public interface EducationPaperMapper extends BaseMapperX<EducationPaper>
*/
List<PaperIdAndNum> selectPaperIdAndNumByTaskId(String taskId);
int countPapersByTaskId(String taskId);
List<String> selectTaskNumByids(@Param("cannotDeleteTaskIds")List<String> cannotDeleteTaskIds);
}

View File

@@ -199,4 +199,10 @@ public interface EducationPaperPersonMapper
*/
long selectEducationPaperPersonBySessionIdNotInTotal(SessionStuPageReqVO sessionStuPageReqVO);
List<String> selectNameByids(@Param("ids")List<String> ids);
}

View File

@@ -100,7 +100,7 @@ public interface ExamQuestionMapper extends BaseMapperX<ExamQuestion>
* @param ids 需要删除的数据主键集合
* @return 结果
*/
public int deleteExamQuestionByQuIds(@Param("ids") String[] ids);
public String deleteExamQuestionByQuIds(@Param("ids") String[] ids);
/**
* 批量查找试题
@@ -206,4 +206,12 @@ public interface ExamQuestionMapper extends BaseMapperX<ExamQuestion>
* @return
*/
int selectCountQu();
/**
* 根据试题id找试题编号
* @param cannotDeleteIds
* @return
*/
List<String> selectQuNumBuIds(List<String> cannotDeleteIds);
}

View File

@@ -271,21 +271,27 @@ public class EducationPaperPersonServiceImpl implements IEducationPaperPersonSer
@Override
@Transactional(rollbackFor = Exception.class) // 所有异常都回滚
public int removeSessionStu(StudentSessionReqVO reqVO) {
public String removeSessionStu(StudentSessionReqVO reqVO) {
//获取前端传入的学生ID列表
List<String> studentIds = reqVO.getStudentIds();
if (studentIds == null || studentIds.isEmpty()) {
return 0; // 无操作
return "请选择删除的学生!"; // 无操作
}
//筛选出当前任务中状态为"代考"的学生ID只允许删除这些学生
List<String> proxyStuIds = monitorMapper.selectStuIdByTaskId(reqVO.getTaskId());
//筛选出当前任务中状态为"代考"的学生ID只允许删除这些学生
List<String> intersection = studentIds.stream()
.filter(proxyStuIds::contains)
.collect(Collectors.toList());
// 不需要删除的学生ID差集
List<String> notToDeleteIds = studentIds.stream()
.filter(id -> !proxyStuIds.contains(id))
.collect(Collectors.toList());
if (intersection.isEmpty()) {
return 0; // 无符合条件的学生
return "选择的所有学生的状态都为待考,不能删除!"; // 无符合条件的学生
}
//删除监控管理学生
DeleteRequestVo deleteRequestVo=new DeleteRequestVo();
@@ -300,16 +306,21 @@ public class EducationPaperPersonServiceImpl implements IEducationPaperPersonSer
}
//删除考场学生
reqVO.setStudentIds(intersection);
return educationPaperPersonMapper.removeSessionStu(reqVO);
educationPaperPersonMapper.removeSessionStu(reqVO);
if (!notToDeleteIds.isEmpty()) {
List<String> names= educationPaperPersonMapper.selectNameByids(notToDeleteIds);
return "以下选择学生的状态为待考:"+names+",不能删除!"; // 无符合条件的学生
}
return "删除成功";
}
@Override
@Transactional(rollbackFor = Exception.class) // 所有异常都回滚
public int removeTaskStu(DeleteRequestVo deleteRequestVo) {
public String removeTaskStu(DeleteRequestVo deleteRequestVo) {
//获取前端传入的学生ID列表
List<String> studentIds = deleteRequestVo.getStudentIds();
if (studentIds == null || studentIds.isEmpty()) {
return 0; // 无操作
return "请选择删除的学生!"; // 无操作
}
//筛选出当前任务中状态为"代考"的学生ID只允许删除这些学生
List<String> proxyStuIds = monitorMapper.selectStuIdByTaskId(deleteRequestVo.getTaskId());
@@ -319,8 +330,14 @@ public class EducationPaperPersonServiceImpl implements IEducationPaperPersonSer
.collect(Collectors.toList());
if (intersection.isEmpty()) {
return 0; // 无符合条件的学生
return "选择的所有学生的状态都为待考,不能删除!"; // 无符合条件的学生
}
// 不需要删除的学生ID差集
List<String> notToDeleteIds = studentIds.stream()
.filter(id -> !proxyStuIds.contains(id))
.collect(Collectors.toList());
deleteRequestVo.setStudentIds(intersection);
@@ -329,8 +346,12 @@ public class EducationPaperPersonServiceImpl implements IEducationPaperPersonSer
String key = "userCache:" + deleteRequestVo.getTaskId()+":"+studentId;
redisTemplate.delete(key);
}
return educationPaperPersonMapper.removeTaskStu(deleteRequestVo);
educationPaperPersonMapper.removeTaskStu(deleteRequestVo);
if (!notToDeleteIds.isEmpty()) {
List<String> names= educationPaperPersonMapper.selectNameByids(notToDeleteIds);
return "以下选择学生的状态为待考:"+names+",不能删除!"; // 无符合条件的学生
}
return "删除成功";
}
@Override

View File

@@ -205,6 +205,8 @@ public class EducationPaperServiceImpl implements IEducationPaperService
// 格式化为8位不足前面补0
String formattedNumber = String.format("%08d", ++number);
//根据任务查找任务里面是否有试卷,如果没有给新创建的试卷 抽卷方式为 随机
List<EducationPaper> educationPapers = educationPaperMapper.selectPaperListByTaskId(taskid);
//构建试卷
@@ -215,8 +217,15 @@ public class EducationPaperServiceImpl implements IEducationPaperService
educationPaper.setTaskId(taskid);
educationPaper.setNum(formattedNumber);
educationPaper.setTenantId(TenantContextHolder.getRequiredTenantId());
if (educationPapers.size() == 0){
educationPaper.setRollUp("2");
EducationPaperTask educationPaperTask = educationPaperTaskMapper.selectEducationPaperTaskByTaskId(taskid);
educationPaperTask.setIsOne("1");
}
educationPaperMapper.insertEducationPaper(educationPaper);
System.out.println(examQuestionIds+"examQuestionIdsexamQuestionIds");
//构建试卷试题对象
@@ -918,7 +927,8 @@ public class EducationPaperServiceImpl implements IEducationPaperService
String formattedNumber = String.format("%08d", ++number);
System.out.println(examQuestionIds);
List<EducationPaper> educationPapers = educationPaperMapper.selectPaperListByTaskId(taskId);
//构建试卷
EducationPaper educationPaper =new EducationPaper();
String uuid = IdUtils.simpleUUID();
@@ -927,6 +937,12 @@ public class EducationPaperServiceImpl implements IEducationPaperService
educationPaper.setTaskId(taskId);
educationPaper.setNum(formattedNumber);
educationPaper.setTenantId(TenantContextHolder.getRequiredTenantId());
if (educationPapers.size()==0){
educationPaper.setRollUp("2");
EducationPaperTask educationPaperTask = educationPaperTaskMapper.selectEducationPaperTaskByTaskId(taskId);
educationPaperTask.setIsOne("1");
}
educationPaperMapper.insertEducationPaper(educationPaper);

View File

@@ -2,7 +2,6 @@ package pc.exam.pp.module.exam.service.paper;
import com.alibaba.excel.util.StringUtils;
import org.checkerframework.checker.units.qual.A;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@@ -25,7 +24,6 @@ import pc.exam.pp.module.exam.dal.mysql.question.SysFileMapper;
import pc.exam.pp.module.exam.utils.date.DateUtils;
import pc.exam.pp.module.exam.utils.uuid.IdUtils;
import java.sql.Time;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.*;
@@ -192,8 +190,39 @@ public class EducationPaperTaskServiceImpl implements IEducationPaperTaskService
* @return 结果
*/
@Override
public int deleteEducationPaperTaskByTaskIds(String[] taskIds) {
return educationPaperTaskMapper.deleteEducationPaperTaskByTaskIds(taskIds);
public String deleteEducationPaperTaskByTaskIds(String[] taskIds) {
if (taskIds == null || taskIds.length == 0) {
return "请选择删除数据!";
}
// 1. 找出没有关联试卷的任务ID
List<String> canDeleteTaskIds = new ArrayList<>();
List<String> cannotDeleteTaskIds = new ArrayList<>();
for (String taskId : taskIds) {
// 查询该任务下是否有试卷
int paperCount = educationPaperMapper.countPapersByTaskId(taskId);
if (paperCount == 0) {
canDeleteTaskIds.add(taskId);
}else {
cannotDeleteTaskIds.add(taskId);
}
}
// 2. 如果没有可删除的任务,直接返回
if (canDeleteTaskIds.isEmpty()) {
return ("所选的任务下都有试卷,不能删除!");
}
// 3. 执行删除操作
educationPaperTaskMapper.deleteEducationPaperTaskByTaskIds(
canDeleteTaskIds.toArray(new String[0]));
if (!cannotDeleteTaskIds.isEmpty()){
List<String> taskNum= educationPaperMapper.selectTaskNumByids(cannotDeleteTaskIds);
return ("以下任务下有试卷:"+taskNum+",不能删除!");
}
return "删除成功";
}
/**

View File

@@ -73,9 +73,9 @@ public interface IEducationPaperPersonService
String setStuAndSession(StudentSessionReqVO reqVO);
int removeSessionStu(StudentSessionReqVO reqVO);
String removeSessionStu(StudentSessionReqVO reqVO);
int removeTaskStu(DeleteRequestVo deleteRequestVo);
String removeTaskStu(DeleteRequestVo deleteRequestVo);
List<String> selectStuIdByTaskId(String taskid);

View File

@@ -59,7 +59,7 @@ public interface IEducationPaperTaskService
* @param taskIds 需要删除的试卷任务主键集合
* @return 结果
*/
public int deleteEducationPaperTaskByTaskIds(String[] taskIds);
public String deleteEducationPaperTaskByTaskIds(String[] taskIds);
/**
* 删除试卷任务信息

View File

@@ -1,22 +1,17 @@
package pc.exam.pp.module.exam.service.question;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.StrUtil;
import com.alibaba.excel.util.StringUtils;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.google.common.annotations.VisibleForTesting;
import jakarta.validation.ConstraintViolationException;
import org.apache.commons.collections4.CollectionUtils;
import org.checkerframework.checker.units.qual.A;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import pc.exam.pp.framework.common.exception.ServiceException;
import pc.exam.pp.framework.common.pojo.PageResult;
import pc.exam.pp.framework.common.util.object.BeanUtils;
import pc.exam.pp.framework.common.util.validation.ValidationUtils;
import pc.exam.pp.framework.security.core.util.SecurityFrameworkUtils;
import pc.exam.pp.module.exam.controller.admin.question.dto.ExamQuestionDto;
import pc.exam.pp.module.exam.controller.admin.question.dto.TenantDto;
import pc.exam.pp.module.exam.controller.admin.question.vo.*;
import pc.exam.pp.module.exam.controller.admin.questionexamine.vo.QuestionExaminePageReqVO;
@@ -30,12 +25,10 @@ import pc.exam.pp.module.exam.dal.mysql.paper.EducationPaperQuMapper;
import pc.exam.pp.module.exam.dal.mysql.question.*;
import pc.exam.pp.module.exam.dal.mysql.questionexamine.QuestionExamineMapper;
import pc.exam.pp.module.exam.dal.mysql.specialty.ExamSpecialtyMapper;
import pc.exam.pp.module.exam.service.questionexamine.QuestionExamineService;
import pc.exam.pp.module.exam.utils.date.DateUtils;
import pc.exam.pp.module.exam.utils.rabbitmq.RabbitmqUtils;
import pc.exam.pp.module.exam.utils.uuid.IdUtils;
import java.time.LocalDateTime;
import java.util.*;
import java.util.stream.Collectors;
@@ -335,8 +328,7 @@ public class ExamQuestionServiceImpl implements IExamQuestionService
*/
@Override
@Transactional(rollbackFor = Exception.class) // 所有异常都回滚
public int deleteExamQuestionByQuIds(String[] ids)
{
public String deleteExamQuestionByQuIds(String[] ids) {
// 查询出被使用的题目ID
List<String> usedIds = educationPaperQuMapper.selectUsedQuestionIds(ids);
Set<String> usedIdSet = new HashSet<>(usedIds);
@@ -347,9 +339,15 @@ public class ExamQuestionServiceImpl implements IExamQuestionService
.collect(Collectors.toList());
if (canDeleteIds.isEmpty()) {
// 全部试题都已被引用,不能删除
return 0;
return ("全部试题都已被引用,不能删除!");
}
String[] deleteIds = canDeleteIds.toArray(new String[0]);
//判断deleteIds和ids是否相等
// 判断 deleteIds 和 ids 是否相等(即是否所有题目都可以删除)
boolean allCanBeDeleted = (deleteIds.length == ids.length);
//删除试题答案
examQuestionAnswerMapper.deleteExamQuestionAnswerByQuesIds(deleteIds);
//删除试题文件
@@ -358,8 +356,18 @@ public class ExamQuestionServiceImpl implements IExamQuestionService
examQuestionScoreMapper.deleteExamQuestionScoreByQuesIds(deleteIds);
//删除试题关键字
examQuestionKeywordMapper.deleteExamQuestionScoreByQuesIds(deleteIds);
examQuestionMapper.deleteExamQuestionByQuIds(deleteIds);
if (!allCanBeDeleted) {
// 找出不能删除的ID
List<String> cannotDeleteIds = Arrays.stream(ids)
.filter(usedIdSet::contains)
.collect(Collectors.toList());
List<String> quNumList=examQuestionMapper.selectQuNumBuIds(cannotDeleteIds);
return ("部分试题已参与组卷无法删除: " + quNumList);
}
return "删除成功";
return examQuestionMapper.deleteExamQuestionByQuIds(deleteIds);
}
/**

View File

@@ -60,7 +60,7 @@ public interface IExamQuestionService
* @param ids 需要删除的试题(hyc)主键集合
* @return 结果
*/
public int deleteExamQuestionByQuIds(String[] ids);
public String deleteExamQuestionByQuIds(String[] ids);
/**
* 删除试题(hyc)信息

View File

@@ -2,9 +2,7 @@ package pc.exam.pp.module.exam.utils.file;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.*;
import java.nio.file.attribute.BasicFileAttributes;
import java.util.Collections;
import java.util.LinkedHashMap;
@@ -68,6 +66,46 @@ public class GetDifferencesBetweenFolders {
}
}
public static Map<String, String> listFilesAndFoldersWithAttributes(Path folder, String excludeFolderName) throws IOException {
if (!Files.exists(folder)) return Collections.emptyMap();
Map<String, String> result = new LinkedHashMap<>();
Files.walkFileTree(folder, new SimpleFileVisitor<Path>() {
@Override
public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) {
// 如果遇到需要排除的文件夹,跳过整个目录
if (dir.getFileName().toString().equals(excludeFolderName) && !dir.equals(folder)) {
return FileVisitResult.SKIP_SUBTREE;
}
return FileVisitResult.CONTINUE;
}
@Override
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) {
String relativePath = folder.relativize(file).toString();
result.put(relativePath, GetDifferencesBetweenFolders.getFileAttributes(file));
return FileVisitResult.CONTINUE;
}
@Override
public FileVisitResult postVisitDirectory(Path dir, IOException exc) {
// 也可以记录文件夹本身的属性
if (!dir.equals(folder)) { // 排除根目录自身
String relativePath = folder.relativize(dir).toString();
result.put(relativePath, GetDifferencesBetweenFolders.getFileAttributes(dir));
}
return FileVisitResult.CONTINUE;
}
});
return result;
}
// 返回文件和文件夹的属性
static String getFileAttributes(Path path) {
try {

View File

@@ -127,6 +127,16 @@ select task_id from education_paper where paper_id=#{paperId}
<select id="selectPaperIdAndNumByTaskId" resultMap="PaperIdAndNumResult">
select paper_id ,num from education_paper where task_id=#{taskId} and deleted ='0'
</select>
<select id="countPapersByTaskId" resultType="java.lang.Integer">
select count(*) from education_paper where task_id =#{taskId}
</select>
<select id="selectTaskNumByids" resultType="java.lang.String">
select task_num from education_paper_task
WHERE task_id IN
<foreach collection="cannotDeleteTaskIds" item="taskId" open="(" separator="," close=")">
#{taskId}
</foreach>
</select>
<insert id="insertEducationPaper" parameterType="EducationPaper">

View File

@@ -182,6 +182,12 @@
AND s.class_id = #{classId}
</if>
</select>
<select id="selectNameByids" resultType="java.lang.String">
select username from system_users where id in
<foreach collection="ids" item="id" open="(" separator="," close=")">
#{id}
</foreach>
</select>
<insert id="insertEducationPaperPerson" parameterType="EducationPaperPerson">

View File

@@ -133,6 +133,13 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<select id="selectCountQu" resultType="java.lang.Integer">
select count(*) from exam_question
</select>
<select id="selectQuNumBuIds" resultType="java.lang.String">
select qu_num from exam_question where qu_id
IN
<foreach collection="list" item="id" open="(" separator="," close=")">
#{id}
</foreach>
</select>
<insert id="insertExamQuestion" parameterType="ExamQuestion">
@@ -249,15 +256,16 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<delete id="deleteExamQuestionByQuId" parameterType="String">
UPDATE exam_question set deleted ='2' where qu_id = #{quId}
</delete>
<delete id="deleteExamQuestionByQuIds">
UPDATE exam_question
SET deleted = '2'
WHERE qu_id IN
<foreach collection="ids" item="id" open="(" separator="," close=")">
#{id}
</foreach>
</delete>
<update id="deleteExamQuestionByQuIds" parameterType="String">
UPDATE exam_question
SET deleted = '2'
WHERE qu_id IN
<foreach collection="ids" item="id" open="(" separator="," close=")">
#{id}
</foreach>
</update>
<update id="setQuestionAuditByids">
UPDATE exam_question
SET audit = '2'