fix(sj_1.1.1): 任务批次删除逻辑错误,参数验证异常
This commit is contained in:
		
							parent
							
								
									e6cac1a812
								
							
						
					
					
						commit
						e60136c933
					
				| @ -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) { |                                        Long[] ids) { | ||||||
|         return jobBatchService.deleteJobBatchByIds(ids); |         return jobBatchService.deleteJobBatchByIds(Set.of(ids)); | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  | |||||||
| @ -175,24 +175,19 @@ public class JobHandler { | |||||||
|      */ |      */ | ||||||
|     @Transactional |     @Transactional | ||||||
|     public void deleteJobTaskBatchByIds(Set<Long> ids, String namespaceId) { |     public void deleteJobTaskBatchByIds(Set<Long> ids, String namespaceId) { | ||||||
|  |         // 1. 删除任务批次 job_task_batch | ||||||
|  |         Assert.isTrue(jobTaskBatchMapper.deleteByIds(ids) > 0, | ||||||
|  |                 () -> new SnailJobServerException("删除任务批次失败")); | ||||||
| 
 | 
 | ||||||
|         Assert.isTrue(ids.size() == jobTaskBatchMapper.delete( |         // 2. 删除任务实例 job_task | ||||||
|                 new LambdaQueryWrapper<JobTaskBatch>() |         jobTaskMapper.delete(new LambdaQueryWrapper<JobTask>() | ||||||
|                         .in(JobTaskBatch::getId, ids) |  | ||||||
|         ), () -> new SnailJobServerException("删除任务批次失败")); |  | ||||||
| 
 |  | ||||||
| 
 |  | ||||||
|         Assert.isTrue(ids.size() == jobTaskMapper.delete( |  | ||||||
|                 new LambdaQueryWrapper<JobTask>() |  | ||||||
|                 .eq(JobTask::getNamespaceId, namespaceId) |                 .eq(JobTask::getNamespaceId, namespaceId) | ||||||
|                         .in(JobTask::getId, ids) |                 .in(JobTask::getTaskBatchId, ids)); | ||||||
|         ), () -> new SnailJobServerException("删除任务批次失败")); |  | ||||||
| 
 | 
 | ||||||
|         // 删除日志信息 |         // 3. 删除调度日志 job_log_message | ||||||
|         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) | ||||||
|         ); |         ); | ||||||
| 
 |  | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user
	 dhb52
						dhb52