fix(sj_1.1.1): 任务批次删除逻辑错误,参数验证异常
This commit is contained in:
parent
64296e53f0
commit
e114e5b5cb
@ -20,6 +20,7 @@ import org.springframework.web.bind.MissingServletRequestParameterException;
|
|||||||
import org.springframework.web.bind.annotation.ControllerAdvice;
|
import org.springframework.web.bind.annotation.ControllerAdvice;
|
||||||
import org.springframework.web.bind.annotation.ExceptionHandler;
|
import org.springframework.web.bind.annotation.ExceptionHandler;
|
||||||
import org.springframework.web.bind.annotation.ResponseBody;
|
import org.springframework.web.bind.annotation.ResponseBody;
|
||||||
|
import org.springframework.web.method.annotation.HandlerMethodValidationException;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
@ -133,6 +134,23 @@ public class RestExceptionHandler {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Contrller 参数检验错误
|
||||||
|
*
|
||||||
|
* @param e 异常对象
|
||||||
|
* @return HttpResult
|
||||||
|
*/
|
||||||
|
@ExceptionHandler(HandlerMethodValidationException.class)
|
||||||
|
public Result onHandlerMethodValidationException(HandlerMethodValidationException e) {
|
||||||
|
Object[] detailMessageArguments = e.getDetailMessageArguments();
|
||||||
|
if (detailMessageArguments != null && detailMessageArguments.length > 0) {
|
||||||
|
return new Result<String>(0, detailMessageArguments[0].toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
return new Result<>("参数校验失败");
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 400错误
|
* 400错误
|
||||||
*/
|
*/
|
||||||
|
@ -5,7 +5,6 @@ import com.aizuda.snailjob.server.web.model.base.PageResult;
|
|||||||
import com.aizuda.snailjob.server.web.model.request.JobBatchQueryVO;
|
import com.aizuda.snailjob.server.web.model.request.JobBatchQueryVO;
|
||||||
import com.aizuda.snailjob.server.web.model.response.JobBatchResponseVO;
|
import com.aizuda.snailjob.server.web.model.response.JobBatchResponseVO;
|
||||||
import com.aizuda.snailjob.server.web.service.JobBatchService;
|
import com.aizuda.snailjob.server.web.service.JobBatchService;
|
||||||
import jakarta.validation.Valid;
|
|
||||||
import jakarta.validation.constraints.NotEmpty;
|
import jakarta.validation.constraints.NotEmpty;
|
||||||
import jakarta.validation.constraints.Size;
|
import jakarta.validation.constraints.Size;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
@ -52,10 +51,10 @@ public class JobBatchController {
|
|||||||
|
|
||||||
@DeleteMapping("/ids")
|
@DeleteMapping("/ids")
|
||||||
@LoginRequired
|
@LoginRequired
|
||||||
public Boolean deleteJobBatchByIds(@RequestBody @Valid
|
public Boolean deleteJobBatchByIds(@RequestBody
|
||||||
@NotEmpty(message = "ids不能为空")
|
@NotEmpty(message = "ids不能为空")
|
||||||
@Size(max = 100, message = "最多删除5个")
|
@Size(max = 100, message = "最多删除 {max} 个")
|
||||||
Set<Long> ids) {
|
Set<Long> ids) {
|
||||||
return jobBatchService.deleteJobBatchByIds(ids);
|
return jobBatchService.deleteJobBatchByIds(ids);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -11,7 +11,6 @@ import com.aizuda.snailjob.server.web.model.response.JobResponseVO;
|
|||||||
import com.aizuda.snailjob.server.web.service.JobService;
|
import com.aizuda.snailjob.server.web.service.JobService;
|
||||||
import com.aizuda.snailjob.server.web.util.ExportUtils;
|
import com.aizuda.snailjob.server.web.util.ExportUtils;
|
||||||
import com.aizuda.snailjob.server.web.util.ImportUtils;
|
import com.aizuda.snailjob.server.web.util.ImportUtils;
|
||||||
import jakarta.validation.Valid;
|
|
||||||
import jakarta.validation.constraints.NotEmpty;
|
import jakarta.validation.constraints.NotEmpty;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.http.MediaType;
|
import org.springframework.http.MediaType;
|
||||||
@ -75,7 +74,7 @@ public class JobController {
|
|||||||
|
|
||||||
@DeleteMapping("/ids")
|
@DeleteMapping("/ids")
|
||||||
@LoginRequired
|
@LoginRequired
|
||||||
public Boolean deleteJobById(@RequestBody @Valid @NotEmpty(message = "ids不能为空") Set<Long> ids) {
|
public Boolean deleteJobById(@RequestBody @NotEmpty(message = "ids不能为空") Set<Long> ids) {
|
||||||
return jobService.deleteJobByIds(ids);
|
return jobService.deleteJobByIds(ids);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6,6 +6,7 @@ import com.aizuda.snailjob.server.web.model.request.NotifyConfigQueryVO;
|
|||||||
import com.aizuda.snailjob.server.web.model.request.NotifyConfigRequestVO;
|
import com.aizuda.snailjob.server.web.model.request.NotifyConfigRequestVO;
|
||||||
import com.aizuda.snailjob.server.web.model.response.NotifyConfigResponseVO;
|
import com.aizuda.snailjob.server.web.model.response.NotifyConfigResponseVO;
|
||||||
import com.aizuda.snailjob.server.web.service.NotifyConfigService;
|
import com.aizuda.snailjob.server.web.service.NotifyConfigService;
|
||||||
|
import jakarta.validation.constraints.NotEmpty;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import org.springframework.validation.annotation.Validated;
|
import org.springframework.validation.annotation.Validated;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
@ -57,7 +58,7 @@ public class NotifyConfigController {
|
|||||||
|
|
||||||
@LoginRequired
|
@LoginRequired
|
||||||
@DeleteMapping("ids")
|
@DeleteMapping("ids")
|
||||||
public Boolean batchDeleteNotify(@RequestBody Set<Long> ids) {
|
public Boolean batchDeleteNotify(@RequestBody @NotEmpty(message = "ids不能为空") Set<Long> ids) {
|
||||||
return notifyConfigService.batchDeleteNotify(ids);
|
return notifyConfigService.batchDeleteNotify(ids);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -12,6 +12,7 @@ import com.aizuda.snailjob.server.web.model.response.NotifyRecipientResponseVO;
|
|||||||
import com.aizuda.snailjob.server.web.service.NotifyRecipientService;
|
import com.aizuda.snailjob.server.web.service.NotifyRecipientService;
|
||||||
import com.aizuda.snailjob.server.web.util.ExportUtils;
|
import com.aizuda.snailjob.server.web.util.ExportUtils;
|
||||||
import com.aizuda.snailjob.server.web.util.ImportUtils;
|
import com.aizuda.snailjob.server.web.util.ImportUtils;
|
||||||
|
import jakarta.validation.constraints.NotEmpty;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import org.springframework.http.MediaType;
|
import org.springframework.http.MediaType;
|
||||||
import org.springframework.http.ResponseEntity;
|
import org.springframework.http.ResponseEntity;
|
||||||
@ -63,7 +64,7 @@ public class NotifyRecipientController {
|
|||||||
|
|
||||||
@DeleteMapping("/ids")
|
@DeleteMapping("/ids")
|
||||||
@LoginRequired
|
@LoginRequired
|
||||||
public Boolean batchDeleteByIds(@RequestBody Set<Long> ids) {
|
public Boolean batchDeleteByIds(@RequestBody @NotEmpty(message = "ids不能为空") Set<Long> ids) {
|
||||||
return notifyRecipientService.batchDeleteByIds(ids);
|
return notifyRecipientService.batchDeleteByIds(ids);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -7,7 +7,6 @@ import com.aizuda.snailjob.server.web.model.request.RetryTaskLogQueryVO;
|
|||||||
import com.aizuda.snailjob.server.web.model.response.RetryTaskLogMessageResponseVO;
|
import com.aizuda.snailjob.server.web.model.response.RetryTaskLogMessageResponseVO;
|
||||||
import com.aizuda.snailjob.server.web.model.response.RetryTaskLogResponseVO;
|
import com.aizuda.snailjob.server.web.model.response.RetryTaskLogResponseVO;
|
||||||
import com.aizuda.snailjob.server.web.service.RetryTaskLogService;
|
import com.aizuda.snailjob.server.web.service.RetryTaskLogService;
|
||||||
import jakarta.validation.Valid;
|
|
||||||
import jakarta.validation.constraints.NotEmpty;
|
import jakarta.validation.constraints.NotEmpty;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
@ -54,7 +53,7 @@ public class RetryTaskLogController {
|
|||||||
|
|
||||||
@LoginRequired
|
@LoginRequired
|
||||||
@DeleteMapping("ids")
|
@DeleteMapping("ids")
|
||||||
public Boolean batchDelete(@RequestBody @Valid @NotEmpty(message = "ids不能为空") Set<Long> ids) {
|
public Boolean batchDelete(@RequestBody @NotEmpty(message = "ids不能为空") Set<Long> ids) {
|
||||||
return retryTaskLogService.batchDelete(ids);
|
return retryTaskLogService.batchDelete(ids);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -10,7 +10,6 @@ import com.aizuda.snailjob.server.web.model.response.SceneConfigResponseVO;
|
|||||||
import com.aizuda.snailjob.server.web.service.SceneConfigService;
|
import com.aizuda.snailjob.server.web.service.SceneConfigService;
|
||||||
import com.aizuda.snailjob.server.web.util.ExportUtils;
|
import com.aizuda.snailjob.server.web.util.ExportUtils;
|
||||||
import com.aizuda.snailjob.server.web.util.ImportUtils;
|
import com.aizuda.snailjob.server.web.util.ImportUtils;
|
||||||
import jakarta.validation.Valid;
|
|
||||||
import jakarta.validation.constraints.NotEmpty;
|
import jakarta.validation.constraints.NotEmpty;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import org.springframework.http.MediaType;
|
import org.springframework.http.MediaType;
|
||||||
@ -87,7 +86,7 @@ public class SceneConfigController {
|
|||||||
|
|
||||||
@LoginRequired
|
@LoginRequired
|
||||||
@DeleteMapping("/ids")
|
@DeleteMapping("/ids")
|
||||||
public boolean deleteByIds(@RequestBody @Valid @NotEmpty(message = "ids不能为空") Set<Long> ids) {
|
public boolean deleteByIds(@RequestBody @NotEmpty(message = "ids不能为空") Set<Long> ids) {
|
||||||
return sceneConfigService.deleteByIds(ids);
|
return sceneConfigService.deleteByIds(ids);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,7 +7,6 @@ import com.aizuda.snailjob.server.web.model.request.WorkflowBatchQueryVO;
|
|||||||
import com.aizuda.snailjob.server.web.model.response.WorkflowBatchResponseVO;
|
import com.aizuda.snailjob.server.web.model.response.WorkflowBatchResponseVO;
|
||||||
import com.aizuda.snailjob.server.web.model.response.WorkflowDetailResponseVO;
|
import com.aizuda.snailjob.server.web.model.response.WorkflowDetailResponseVO;
|
||||||
import com.aizuda.snailjob.server.web.service.WorkflowBatchService;
|
import com.aizuda.snailjob.server.web.service.WorkflowBatchService;
|
||||||
import jakarta.validation.Valid;
|
|
||||||
import jakarta.validation.constraints.NotEmpty;
|
import jakarta.validation.constraints.NotEmpty;
|
||||||
import jakarta.validation.constraints.Size;
|
import jakarta.validation.constraints.Size;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
@ -47,10 +46,10 @@ public class WorkflowBatchController {
|
|||||||
|
|
||||||
@DeleteMapping("/ids")
|
@DeleteMapping("/ids")
|
||||||
@LoginRequired(role = RoleEnum.USER)
|
@LoginRequired(role = RoleEnum.USER)
|
||||||
public Boolean deleteByIds(@RequestBody @Valid
|
public Boolean deleteByIds(@RequestBody
|
||||||
@NotEmpty(message = "ids不能为空")
|
@NotEmpty(message = "ids不能为空")
|
||||||
@Size(max = 100, message = "最多删除5个")
|
@Size(max = 100, message = "最多删除 {max} 个")
|
||||||
Set<Long> ids) {
|
Set<Long> ids) {
|
||||||
return workflowBatchService.deleteByIds(ids);
|
return workflowBatchService.deleteByIds(ids);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,7 +2,6 @@ package com.aizuda.snailjob.server.web.controller;
|
|||||||
|
|
||||||
import cn.hutool.core.lang.Pair;
|
import cn.hutool.core.lang.Pair;
|
||||||
import com.aizuda.snailjob.common.core.annotation.OriginalControllerReturnValue;
|
import com.aizuda.snailjob.common.core.annotation.OriginalControllerReturnValue;
|
||||||
import com.aizuda.snailjob.server.common.dto.DecisionConfig;
|
|
||||||
import com.aizuda.snailjob.server.web.annotation.LoginRequired;
|
import com.aizuda.snailjob.server.web.annotation.LoginRequired;
|
||||||
import com.aizuda.snailjob.server.web.annotation.RoleEnum;
|
import com.aizuda.snailjob.server.web.annotation.RoleEnum;
|
||||||
import com.aizuda.snailjob.server.web.model.base.PageResult;
|
import com.aizuda.snailjob.server.web.model.base.PageResult;
|
||||||
@ -15,7 +14,6 @@ import com.aizuda.snailjob.server.web.model.response.WorkflowResponseVO;
|
|||||||
import com.aizuda.snailjob.server.web.service.WorkflowService;
|
import com.aizuda.snailjob.server.web.service.WorkflowService;
|
||||||
import com.aizuda.snailjob.server.web.util.ExportUtils;
|
import com.aizuda.snailjob.server.web.util.ExportUtils;
|
||||||
import com.aizuda.snailjob.server.web.util.ImportUtils;
|
import com.aizuda.snailjob.server.web.util.ImportUtils;
|
||||||
import jakarta.validation.Valid;
|
|
||||||
import jakarta.validation.constraints.NotEmpty;
|
import jakarta.validation.constraints.NotEmpty;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import org.springframework.http.MediaType;
|
import org.springframework.http.MediaType;
|
||||||
@ -72,7 +70,7 @@ public class WorkflowController {
|
|||||||
|
|
||||||
@DeleteMapping("/ids")
|
@DeleteMapping("/ids")
|
||||||
@LoginRequired(role = RoleEnum.USER)
|
@LoginRequired(role = RoleEnum.USER)
|
||||||
public Boolean deleteByIds(@RequestBody @Valid @NotEmpty(message = "ids不能为空") Set<Long> ids) {
|
public Boolean deleteByIds(@RequestBody @NotEmpty(message = "ids不能为空") Set<Long> ids) {
|
||||||
return workflowService.deleteByIds(ids);
|
return workflowService.deleteByIds(ids);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -155,9 +155,9 @@ public class JobHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
WorkflowTaskBatch workflowTaskBatch = workflowTaskBatchMapper.selectOne(
|
WorkflowTaskBatch workflowTaskBatch = workflowTaskBatchMapper.selectOne(
|
||||||
new LambdaQueryWrapper<WorkflowTaskBatch>()
|
new LambdaQueryWrapper<WorkflowTaskBatch>()
|
||||||
.select(WorkflowTaskBatch::getWfContext)
|
.select(WorkflowTaskBatch::getWfContext)
|
||||||
.eq(WorkflowTaskBatch::getId, workflowTaskBatchId)
|
.eq(WorkflowTaskBatch::getId, workflowTaskBatchId)
|
||||||
);
|
);
|
||||||
|
|
||||||
if (Objects.isNull(workflowTaskBatch)) {
|
if (Objects.isNull(workflowTaskBatch)) {
|
||||||
@ -170,29 +170,24 @@ public class JobHandler {
|
|||||||
/**
|
/**
|
||||||
* 批次删除定时任务批次
|
* 批次删除定时任务批次
|
||||||
*
|
*
|
||||||
* @param ids 任务批次id
|
* @param ids 任务批次id
|
||||||
* @param namespaceId 命名空间
|
* @param namespaceId 命名空间
|
||||||
*/
|
*/
|
||||||
@Transactional
|
@Transactional
|
||||||
public void deleteJobTaskBatchByIds(Set<Long> ids, String namespaceId) {
|
public void deleteJobTaskBatchByIds(Set<Long> ids, String namespaceId) {
|
||||||
|
// 1. 删除任务批次 job_task_batch
|
||||||
|
Assert.isTrue(ids.size() == jobTaskBatchMapper.deleteByIds(ids),
|
||||||
|
() -> new SnailJobServerException("删除任务批次失败"));
|
||||||
|
|
||||||
Assert.isTrue(ids.size() == jobTaskBatchMapper.delete(
|
// 2. 删除任务实例 job_task
|
||||||
new LambdaQueryWrapper<JobTaskBatch>()
|
jobTaskMapper.delete(new LambdaQueryWrapper<JobTask>()
|
||||||
.in(JobTaskBatch::getId, ids)
|
.eq(JobTask::getNamespaceId, namespaceId)
|
||||||
), () -> new SnailJobServerException("删除任务批次失败"));
|
.in(JobTask::getTaskBatchId, ids));
|
||||||
|
|
||||||
|
// 3. 删除调度日志 job_log_message
|
||||||
Assert.isTrue(ids.size() == jobTaskMapper.delete(
|
|
||||||
new LambdaQueryWrapper<JobTask>()
|
|
||||||
.eq(JobTask::getNamespaceId, namespaceId)
|
|
||||||
.in(JobTask::getId, ids)
|
|
||||||
), () -> new SnailJobServerException("删除任务批次失败"));
|
|
||||||
|
|
||||||
// 删除日志信息
|
|
||||||
jobLogMessageMapper.delete(new LambdaQueryWrapper<JobLogMessage>()
|
jobLogMessageMapper.delete(new LambdaQueryWrapper<JobLogMessage>()
|
||||||
.eq(JobLogMessage::getNamespaceId, namespaceId)
|
.eq(JobLogMessage::getNamespaceId, namespaceId)
|
||||||
.in(JobLogMessage::getTaskId, ids)
|
.in(JobLogMessage::getTaskBatchId, ids)
|
||||||
);
|
);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -233,11 +233,10 @@ public class WorkflowBatchServiceImpl implements WorkflowBatchService {
|
|||||||
public Boolean deleteByIds(Set<Long> ids) {
|
public Boolean deleteByIds(Set<Long> ids) {
|
||||||
String namespaceId = UserSessionUtils.currentUserSession().getNamespaceId();
|
String namespaceId = UserSessionUtils.currentUserSession().getNamespaceId();
|
||||||
|
|
||||||
Assert.isTrue(ids.size() == workflowTaskBatchMapper.delete(
|
Assert.isTrue(ids.size() == workflowTaskBatchMapper.delete(new LambdaQueryWrapper<WorkflowTaskBatch>()
|
||||||
new LambdaQueryWrapper<WorkflowTaskBatch>()
|
|
||||||
.eq(WorkflowTaskBatch::getNamespaceId, namespaceId)
|
.eq(WorkflowTaskBatch::getNamespaceId, namespaceId)
|
||||||
.in(WorkflowTaskBatch::getId, ids)
|
.in(WorkflowTaskBatch::getId, ids)),
|
||||||
), () -> new SnailJobServerException("删除工作流任务失败, 请检查任务状态是否关闭状态"));
|
() -> new SnailJobServerException("删除工作流任务失败, 请检查任务状态是否关闭状态"));
|
||||||
|
|
||||||
List<JobTaskBatch> jobTaskBatches = jobTaskBatchMapper.selectList(new LambdaQueryWrapper<JobTaskBatch>()
|
List<JobTaskBatch> jobTaskBatches = jobTaskBatchMapper.selectList(new LambdaQueryWrapper<JobTaskBatch>()
|
||||||
.eq(JobTaskBatch::getNamespaceId, namespaceId)
|
.eq(JobTaskBatch::getNamespaceId, namespaceId)
|
||||||
|
Loading…
Reference in New Issue
Block a user