【修改】试卷、试卷任务删除增加判断逻辑,ps增加注册表版本

This commit is contained in:
huababa1
2025-07-07 19:47:11 +08:00
parent 794697fdbc
commit 594056f6cc
7 changed files with 75 additions and 20 deletions

View File

@@ -127,9 +127,14 @@ public class EducationPaperController
*/
@Operation(summary = "删除试卷")
@DeleteMapping("/{paperIds}")
public CommonResult remove(@PathVariable String[] paperIds)
public CommonResult remove(@PathVariable String paperIds)
{
return CommonResult.success(educationPaperService.deleteEducationPaperByPaperIds(paperIds));
try {
return CommonResult.success(educationPaperService.deleteEducationPaperByPaperIds(paperIds));
} catch (RuntimeException e) {
return CommonResult.error(981,e.getMessage());
}
}
/**

View File

@@ -23,6 +23,7 @@ import pc.exam.pp.framework.common.pojo.PageResult;
import pc.exam.pp.framework.security.core.util.SecurityFrameworkUtils;
import pc.exam.pp.framework.tenant.core.aop.TenantIgnore;
import pc.exam.pp.framework.tenant.core.context.TenantContextHolder;
import pc.exam.pp.module.exam.controller.admin.exception.QueTypeException;
import pc.exam.pp.module.exam.controller.admin.paper.dto.*;
import pc.exam.pp.module.exam.controller.admin.paper.vo.ExamPaperVo;
import pc.exam.pp.module.exam.controller.admin.paper.vo.PaperPageVo;
@@ -128,16 +129,22 @@ public class EducationPaperServiceImpl implements IEducationPaperService
/**
* 批量删除试卷
*
* @param paperIds 需要删除的试卷主键
* @param paperId 需要删除的试卷主键
* @return 结果
*/
@Override
@Transactional(rollbackFor = Exception.class) // 所有异常都回滚
public int deleteEducationPaperByPaperIds(String[] paperIds)
public int deleteEducationPaperByPaperIds(String paperId) throws RuntimeException
{
EducationPaper educationPaper = educationPaperMapper.selectEducationPaperByPaperId(paperId);
String taskId = educationPaper.getTaskId();
long total = educationPaperPersonMapper.selectEducationPaperPersonByTaskIdTotal(taskId);
educationPaperQuMapper.deleteEducationPaperQuByPaperIds(paperIds);
return educationPaperMapper.deleteEducationPaperByPaperIds(paperIds);
if (total > 0) {
throw new QueTypeException("此任务已分配人员,无法删除!");
}
educationPaperQuMapper.deleteEducationPaperQuByPaperId(paperId);
return educationPaperMapper.deleteEducationPaperByPaperId(paperId);
}
/**

View File

@@ -132,7 +132,7 @@ public class EducationPaperTaskServiceImpl implements IEducationPaperTaskService
educationPaperParam.setIsExamPassword("1");
educationPaperParam.setUsb("1");
educationPaperParam.setSaveGrades("0");
educationPaperParam.setDriver("C");
educationPaperParam.setDriver("D");
educationPaperParam.setIsNumber("1");
educationPaperParam.setIsConnect("0");
educationPaperParam.setIsAnswerId("1");
@@ -199,13 +199,20 @@ public class EducationPaperTaskServiceImpl implements IEducationPaperTaskService
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);
EducationPaperTask educationPaperTask = educationPaperTaskMapper.selectById(taskId);
if (educationPaperTask.getTaskType().equals("0")||educationPaperTask.getTaskType().equals("1")||educationPaperTask.getTaskType().equals("3")){
// 查询该任务下是否有试卷
int paperCount = educationPaperMapper.countPapersByTaskId(taskId);
if (paperCount == 0) {
canDeleteTaskIds.add(taskId);
}else {
cannotDeleteTaskIds.add(taskId);
}
}else {
cannotDeleteTaskIds.add(taskId);
canDeleteTaskIds.add(taskId);
}
}
// 2. 如果没有可删除的任务,直接返回
@@ -233,9 +240,39 @@ public class EducationPaperTaskServiceImpl implements IEducationPaperTaskService
* @return 结果
*/
@Override
public int deleteEducationPaperTaskByTaskId(String taskId) {
monitorMapper.deleteByTaskId(taskId);
return educationPaperTaskMapper.deleteEducationPaperTaskByTaskId(taskId);
public String deleteEducationPaperTaskByTaskId(String taskId) {
EducationPaperTask educationPaperTask = educationPaperTaskMapper.selectById(taskId);
if (educationPaperTask.getTaskType().equals("0")||educationPaperTask.getTaskType().equals("1")||educationPaperTask.getTaskType().equals("3")){
// 1. 找出没有关联试卷的任务ID
List<String> canDeleteTaskIds = new ArrayList<>();
List<String> cannotDeleteTaskIds = new ArrayList<>();
// 查询该任务下是否有试卷
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]));
monitorMapper.deleteByTaskIds(canDeleteTaskIds.toArray(new String[0]));
if (!cannotDeleteTaskIds.isEmpty()){
List<String> taskNum= educationPaperMapper.selectTaskNumByids(cannotDeleteTaskIds);
return ("以下任务下有试卷:"+taskNum+",不能删除!");
}
}
// monitorMapper.deleteByTaskId(taskId);
// educationPaperTaskMapper.deleteEducationPaperTaskByTaskId(taskId);
return "删除成功";
}
@Override

View File

@@ -61,7 +61,7 @@ public interface IEducationPaperService
* @param paperIds 需要删除的试卷主键集合
* @return 结果
*/
public int deleteEducationPaperByPaperIds(String[] paperIds);
public int deleteEducationPaperByPaperIds(String paperIds) throws RuntimeException;
/**
* 删除试卷信息

View File

@@ -67,7 +67,7 @@ public interface IEducationPaperTaskService
* @param taskId 试卷任务主键
* @return 结果
*/
public int deleteEducationPaperTaskByTaskId(String taskId);
public String deleteEducationPaperTaskByTaskId(String taskId);
/**
* 获取专业列表
*/

View File

@@ -128,7 +128,7 @@ select task_id from education_paper where paper_id=#{paperId}
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 count(*) from education_paper where task_id =#{taskId} and deleted ='0'
</select>
<select id="selectTaskNumByids" resultType="java.lang.String">
select task_num from education_paper_task