feat(sj_1.3.0-beta1): 增加删除功能OpenApi
This commit is contained in:
parent
79dc4da700
commit
7afe46e851
@ -0,0 +1,48 @@
|
|||||||
|
package com.aizuda.snailjob.client.job.core.handler.delete;
|
||||||
|
|
||||||
|
import cn.hutool.core.lang.Assert;
|
||||||
|
import cn.hutool.core.lang.Pair;
|
||||||
|
import com.aizuda.snailjob.client.common.exception.SnailJobClientException;
|
||||||
|
import com.aizuda.snailjob.client.job.core.handler.AbstractRequestHandler;
|
||||||
|
import com.aizuda.snailjob.common.core.enums.StatusEnum;
|
||||||
|
import com.aizuda.snailjob.common.core.model.Result;
|
||||||
|
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author:srzou
|
||||||
|
* @Package:com.aizuda.snailjob.client.job.core.handler.delete
|
||||||
|
* @Project:snail-job
|
||||||
|
* @Date:2024/11/21 22:38
|
||||||
|
* @Filename:DeleteJobHandler
|
||||||
|
*/
|
||||||
|
public class DeleteJobHandler extends AbstractRequestHandler<Boolean> {
|
||||||
|
private final Set<Long> toDeleteIds;
|
||||||
|
|
||||||
|
public DeleteJobHandler(Set<Long> toDeleteIds) {
|
||||||
|
this.toDeleteIds = toDeleteIds;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void afterExecute(Boolean aBoolean) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void beforeExecute() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Boolean doExecute() {
|
||||||
|
Result<Object> result = client.deleteJob(toDeleteIds);
|
||||||
|
Assert.isTrue(StatusEnum.YES.getStatus() == result.getStatus(),
|
||||||
|
() -> new SnailJobClientException(result.getMessage()));
|
||||||
|
return (Boolean)result.getData();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Pair<Boolean, String> checkRequest() {
|
||||||
|
return Pair.of(toDeleteIds != null && !toDeleteIds.isEmpty() && !toDeleteIds.contains(0L), "toDeleteId不能为null或0");
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,48 @@
|
|||||||
|
package com.aizuda.snailjob.client.job.core.handler.delete;
|
||||||
|
|
||||||
|
import cn.hutool.core.lang.Assert;
|
||||||
|
import cn.hutool.core.lang.Pair;
|
||||||
|
import com.aizuda.snailjob.client.common.exception.SnailJobClientException;
|
||||||
|
import com.aizuda.snailjob.client.job.core.handler.AbstractRequestHandler;
|
||||||
|
import com.aizuda.snailjob.common.core.enums.StatusEnum;
|
||||||
|
import com.aizuda.snailjob.common.core.model.Result;
|
||||||
|
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author:srzou
|
||||||
|
* @Package:com.aizuda.snailjob.client.job.core.handler.delete
|
||||||
|
* @Project:snail-job
|
||||||
|
* @Date:2024/11/21 22:42
|
||||||
|
* @Filename:DeleteWorkflowHandler
|
||||||
|
*/
|
||||||
|
public class DeleteWorkflowHandler extends AbstractRequestHandler<Boolean> {
|
||||||
|
private final Set<Long> toDeleteIds;
|
||||||
|
|
||||||
|
public DeleteWorkflowHandler(Set<Long> toDeleteIds) {
|
||||||
|
this.toDeleteIds = toDeleteIds;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void afterExecute(Boolean aBoolean) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void beforeExecute() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Boolean doExecute() {
|
||||||
|
Result<Object> result = client.deleteWorkflow(toDeleteIds);
|
||||||
|
Assert.isTrue(StatusEnum.YES.getStatus() == result.getStatus(),
|
||||||
|
() -> new SnailJobClientException(result.getMessage()));
|
||||||
|
return (Boolean)result.getData();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Pair<Boolean, String> checkRequest() {
|
||||||
|
return Pair.of(toDeleteIds != null && !toDeleteIds.isEmpty() && !toDeleteIds.contains(0L), "toDeleteId不能为null或0");
|
||||||
|
}
|
||||||
|
}
|
@ -6,6 +6,8 @@ import com.aizuda.snailjob.client.job.core.dto.RequestAddOrUpdateJobDTO;
|
|||||||
import com.aizuda.snailjob.client.job.core.dto.RequestUpdateStatusDTO;
|
import com.aizuda.snailjob.client.job.core.dto.RequestUpdateStatusDTO;
|
||||||
import com.aizuda.snailjob.common.core.model.Result;
|
import com.aizuda.snailjob.common.core.model.Result;
|
||||||
|
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
public interface OpenApiClient {
|
public interface OpenApiClient {
|
||||||
@Mapping(method = RequestMethod.POST, path = "/api/job/add")
|
@Mapping(method = RequestMethod.POST, path = "/api/job/add")
|
||||||
Result<Object> addJob(RequestAddOrUpdateJobDTO requestAddOrUpdateJobDTO);
|
Result<Object> addJob(RequestAddOrUpdateJobDTO requestAddOrUpdateJobDTO);
|
||||||
@ -27,4 +29,10 @@ public interface OpenApiClient {
|
|||||||
|
|
||||||
@Mapping(method = RequestMethod.POST, path = "/api/job/updateWorkFlowStatus")
|
@Mapping(method = RequestMethod.POST, path = "/api/job/updateWorkFlowStatus")
|
||||||
Result<Object> updateWorkFlowStatus(RequestUpdateStatusDTO statusDTO);
|
Result<Object> updateWorkFlowStatus(RequestUpdateStatusDTO statusDTO);
|
||||||
|
|
||||||
|
@Mapping(method = RequestMethod.POST, path = "/api/job/deleteJob")
|
||||||
|
Result<Object> deleteJob(Set<Long> toDeleteIds);
|
||||||
|
|
||||||
|
@Mapping(method = RequestMethod.POST, path = "/api/job/deleteWorkFlow")
|
||||||
|
Result<Object> deleteWorkflow(Set<Long> toDeleteIds);
|
||||||
}
|
}
|
||||||
|
@ -1,11 +1,15 @@
|
|||||||
package com.aizuda.snailjob.client.job.core.openapi;
|
package com.aizuda.snailjob.client.job.core.openapi;
|
||||||
|
|
||||||
import com.aizuda.snailjob.client.job.core.handler.add.*;
|
import com.aizuda.snailjob.client.job.core.handler.add.*;
|
||||||
|
import com.aizuda.snailjob.client.job.core.handler.delete.DeleteJobHandler;
|
||||||
|
import com.aizuda.snailjob.client.job.core.handler.delete.DeleteWorkflowHandler;
|
||||||
import com.aizuda.snailjob.client.job.core.handler.query.RequestQueryHandler;
|
import com.aizuda.snailjob.client.job.core.handler.query.RequestQueryHandler;
|
||||||
import com.aizuda.snailjob.client.job.core.handler.trigger.TriggerJobHandler;
|
import com.aizuda.snailjob.client.job.core.handler.trigger.TriggerJobHandler;
|
||||||
import com.aizuda.snailjob.client.job.core.handler.trigger.TriggerWorkflowHandler;
|
import com.aizuda.snailjob.client.job.core.handler.trigger.TriggerWorkflowHandler;
|
||||||
import com.aizuda.snailjob.client.job.core.handler.update.*;
|
import com.aizuda.snailjob.client.job.core.handler.update.*;
|
||||||
|
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author opensnail
|
* @author opensnail
|
||||||
* @date 2024-09-21 21:35:34
|
* @date 2024-09-21 21:35:34
|
||||||
@ -159,4 +163,24 @@ public final class SnailJobOpenApi {
|
|||||||
public static UpdateWorkflowStatusHandler updateWorkFlowStatus(Long workFlowId) {
|
public static UpdateWorkflowStatusHandler updateWorkFlowStatus(Long workFlowId) {
|
||||||
return new UpdateWorkflowStatusHandler(workFlowId);
|
return new UpdateWorkflowStatusHandler(workFlowId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除任务
|
||||||
|
*
|
||||||
|
* @param toDeleteIds 待删除任务IDS
|
||||||
|
* @return {@link DeleteJobHandler}
|
||||||
|
*/
|
||||||
|
public static DeleteJobHandler deleteJob(Set<Long> toDeleteIds){
|
||||||
|
return new DeleteJobHandler(toDeleteIds);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除工作流任务
|
||||||
|
*
|
||||||
|
* @param toDeleteIds 待删除工作流任务IDS
|
||||||
|
* @return {@link DeleteWorkflowHandler}
|
||||||
|
*/
|
||||||
|
public static DeleteWorkflowHandler deleteWorkflow(Set<Long> toDeleteIds){
|
||||||
|
return new DeleteWorkflowHandler(toDeleteIds);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -139,6 +139,10 @@ public interface SystemConstants {
|
|||||||
|
|
||||||
String OPENAPI_UPDATE_WORKFLOW_STATUS = "/api/job/updateWorkFlowStatus";
|
String OPENAPI_UPDATE_WORKFLOW_STATUS = "/api/job/updateWorkFlowStatus";
|
||||||
|
|
||||||
|
String OPENAPI_DELETE_JOB = "/api/job/deleteJob";
|
||||||
|
|
||||||
|
String OPENAPI_DELETE_WORKFLOW = "/api/job/deleteWorkFlow";
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
String LOGO = """
|
String LOGO = """
|
||||||
|
@ -0,0 +1,78 @@
|
|||||||
|
package com.aizuda.snailjob.server.job.task.support.request;
|
||||||
|
|
||||||
|
import cn.hutool.core.collection.CollUtil;
|
||||||
|
import cn.hutool.core.lang.Assert;
|
||||||
|
import cn.hutool.core.net.url.UrlQuery;
|
||||||
|
import com.aizuda.snailjob.common.core.constant.SystemConstants.HTTP_PATH;
|
||||||
|
import com.aizuda.snailjob.common.core.enums.StatusEnum;
|
||||||
|
import com.aizuda.snailjob.common.core.model.SnailJobRequest;
|
||||||
|
import com.aizuda.snailjob.common.core.model.SnailJobRpcResult;
|
||||||
|
import com.aizuda.snailjob.common.core.util.JsonUtil;
|
||||||
|
import com.aizuda.snailjob.common.core.util.StreamUtils;
|
||||||
|
import com.aizuda.snailjob.common.log.SnailJobLog;
|
||||||
|
import com.aizuda.snailjob.server.common.enums.SyetemTaskTypeEnum;
|
||||||
|
import com.aizuda.snailjob.server.common.exception.SnailJobServerException;
|
||||||
|
import com.aizuda.snailjob.server.common.handler.PostHttpRequestHandler;
|
||||||
|
import com.aizuda.snailjob.server.common.util.HttpHeaderUtil;
|
||||||
|
import com.aizuda.snailjob.template.datasource.persistence.mapper.JobMapper;
|
||||||
|
import com.aizuda.snailjob.template.datasource.persistence.mapper.JobSummaryMapper;
|
||||||
|
import com.aizuda.snailjob.template.datasource.persistence.po.Job;
|
||||||
|
import com.aizuda.snailjob.template.datasource.persistence.po.JobSummary;
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
|
import io.netty.handler.codec.http.HttpHeaders;
|
||||||
|
import io.netty.handler.codec.http.HttpMethod;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* OPENAPI
|
||||||
|
* 删除定时任务
|
||||||
|
*/
|
||||||
|
@Component
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
public class OpenApiDeleteJobRequestHandler extends PostHttpRequestHandler {
|
||||||
|
private final JobMapper jobMapper;
|
||||||
|
private final JobSummaryMapper jobSummaryMapper;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean supports(String path) {
|
||||||
|
return HTTP_PATH.OPENAPI_DELETE_JOB.equals(path);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public HttpMethod method() {
|
||||||
|
return HttpMethod.POST;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public SnailJobRpcResult doHandler(String content, UrlQuery query, HttpHeaders headers) {
|
||||||
|
SnailJobLog.LOCAL.debug("Delete job content:[{}]", content);
|
||||||
|
SnailJobRequest request = JsonUtil.parseObject(content, SnailJobRequest.class);
|
||||||
|
Object[] args = request.getArgs();
|
||||||
|
Set<Long> ids = JsonUtil.parseObject(JsonUtil.toJsonString(args[0]), Set.class);
|
||||||
|
String namespaceId = HttpHeaderUtil.getNamespace(headers);
|
||||||
|
|
||||||
|
Assert.isTrue(ids.size() == jobMapper.delete(
|
||||||
|
new LambdaQueryWrapper<Job>()
|
||||||
|
.eq(Job::getNamespaceId, namespaceId)
|
||||||
|
.eq(Job::getJobStatus, StatusEnum.NO.getStatus())
|
||||||
|
.in(Job::getId, ids)
|
||||||
|
), () -> new SnailJobServerException("删除定时任务失败, 请检查任务状态是否关闭状态"));
|
||||||
|
|
||||||
|
List<JobSummary> jobSummaries = jobSummaryMapper.selectList(new LambdaQueryWrapper<JobSummary>()
|
||||||
|
.select(JobSummary::getId)
|
||||||
|
.in(JobSummary::getBusinessId, ids)
|
||||||
|
.eq(JobSummary::getNamespaceId, namespaceId)
|
||||||
|
.eq(JobSummary::getSystemTaskType, SyetemTaskTypeEnum.JOB.getType())
|
||||||
|
);
|
||||||
|
if (CollUtil.isNotEmpty(jobSummaries)) {
|
||||||
|
jobSummaryMapper.deleteByIds(StreamUtils.toSet(jobSummaries, JobSummary::getId));
|
||||||
|
}
|
||||||
|
|
||||||
|
return new SnailJobRpcResult(true, request.getReqId());
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,80 @@
|
|||||||
|
package com.aizuda.snailjob.server.job.task.support.request;
|
||||||
|
|
||||||
|
import cn.hutool.core.collection.CollUtil;
|
||||||
|
import cn.hutool.core.lang.Assert;
|
||||||
|
import cn.hutool.core.net.url.UrlQuery;
|
||||||
|
import com.aizuda.snailjob.common.core.constant.SystemConstants.HTTP_PATH;
|
||||||
|
import com.aizuda.snailjob.common.core.enums.StatusEnum;
|
||||||
|
import com.aizuda.snailjob.common.core.model.SnailJobRequest;
|
||||||
|
import com.aizuda.snailjob.common.core.model.SnailJobRpcResult;
|
||||||
|
import com.aizuda.snailjob.common.core.util.JsonUtil;
|
||||||
|
import com.aizuda.snailjob.common.core.util.StreamUtils;
|
||||||
|
import com.aizuda.snailjob.common.log.SnailJobLog;
|
||||||
|
import com.aizuda.snailjob.server.common.enums.SyetemTaskTypeEnum;
|
||||||
|
import com.aizuda.snailjob.server.common.exception.SnailJobServerException;
|
||||||
|
import com.aizuda.snailjob.server.common.handler.PostHttpRequestHandler;
|
||||||
|
import com.aizuda.snailjob.server.common.util.HttpHeaderUtil;
|
||||||
|
import com.aizuda.snailjob.template.datasource.persistence.mapper.JobSummaryMapper;
|
||||||
|
import com.aizuda.snailjob.template.datasource.persistence.mapper.WorkflowMapper;
|
||||||
|
import com.aizuda.snailjob.template.datasource.persistence.po.JobSummary;
|
||||||
|
import com.aizuda.snailjob.template.datasource.persistence.po.Workflow;
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
|
import io.netty.handler.codec.http.HttpHeaders;
|
||||||
|
import io.netty.handler.codec.http.HttpMethod;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* OPENAPI
|
||||||
|
* 删除工作流
|
||||||
|
*/
|
||||||
|
@Component
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
public class OpenApiDeleteWorkflowRequestHandler extends PostHttpRequestHandler {
|
||||||
|
private final WorkflowMapper workflowMapper;
|
||||||
|
private final JobSummaryMapper jobSummaryMapper;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean supports(String path) {
|
||||||
|
return HTTP_PATH.OPENAPI_DELETE_WORKFLOW.equals(path);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public HttpMethod method() {
|
||||||
|
return HttpMethod.POST;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public SnailJobRpcResult doHandler(String content, UrlQuery query, HttpHeaders headers) {
|
||||||
|
SnailJobLog.LOCAL.debug("Delete job content:[{}]", content);
|
||||||
|
SnailJobRequest request = JsonUtil.parseObject(content, SnailJobRequest.class);
|
||||||
|
Object[] args = request.getArgs();
|
||||||
|
Set<Long> ids = JsonUtil.parseObject(JsonUtil.toJsonString(args[0]), Set.class);
|
||||||
|
String namespaceId = HttpHeaderUtil.getNamespace(headers);
|
||||||
|
|
||||||
|
Assert.isTrue(ids.size() == workflowMapper.delete(
|
||||||
|
new LambdaQueryWrapper<Workflow>()
|
||||||
|
.eq(Workflow::getNamespaceId, namespaceId)
|
||||||
|
.eq(Workflow::getWorkflowStatus, StatusEnum.NO.getStatus())
|
||||||
|
.in(Workflow::getId, ids)
|
||||||
|
), () -> new SnailJobServerException("删除工作流任务失败, 请检查任务状态是否关闭状态"));
|
||||||
|
|
||||||
|
List<JobSummary> jobSummaries = jobSummaryMapper.selectList(new LambdaQueryWrapper<JobSummary>()
|
||||||
|
.select(JobSummary::getId)
|
||||||
|
.in(JobSummary::getBusinessId, ids)
|
||||||
|
.eq(JobSummary::getNamespaceId, namespaceId)
|
||||||
|
.eq(JobSummary::getSystemTaskType, SyetemTaskTypeEnum.WORKFLOW.getType())
|
||||||
|
);
|
||||||
|
if (CollUtil.isNotEmpty(jobSummaries)) {
|
||||||
|
Assert.isTrue(jobSummaries.size() ==
|
||||||
|
jobSummaryMapper.deleteByIds(StreamUtils.toSet(jobSummaries, JobSummary::getId)),
|
||||||
|
() -> new SnailJobServerException("汇总表删除失败")
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return new SnailJobRpcResult(true, request.getReqId());
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user