mirror of
https://github.com/PowerJob/PowerJob.git
synced 2025-07-17 00:00:04 +08:00
feat: support fetchAllJob in OpenAPI #158
This commit is contained in:
parent
bd8db1b9df
commit
7acc1e67e3
@ -5,6 +5,7 @@ import com.github.kfcfans.powerjob.common.InstanceStatus;
|
||||
import com.github.kfcfans.powerjob.common.OmsConstant;
|
||||
import com.github.kfcfans.powerjob.common.OpenAPIConstant;
|
||||
import com.github.kfcfans.powerjob.common.PowerJobException;
|
||||
import com.github.kfcfans.powerjob.common.request.http.JobQuery;
|
||||
import com.github.kfcfans.powerjob.common.request.http.SaveJobInfoRequest;
|
||||
import com.github.kfcfans.powerjob.common.request.http.SaveWorkflowRequest;
|
||||
import com.github.kfcfans.powerjob.common.response.*;
|
||||
@ -131,6 +132,31 @@ public class OhMyClient {
|
||||
return JSONObject.parseObject(post, JOB_RESULT_TYPE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Query all JobInfo
|
||||
* @return All JobInfo
|
||||
*/
|
||||
public ResultDTO<List<JobInfoDTO>> fetchAllJob() {
|
||||
RequestBody body = new FormBody.Builder()
|
||||
.add("appId", appId.toString())
|
||||
.build();
|
||||
String post = postHA(OpenAPIConstant.FETCH_ALL_JOB, body);
|
||||
return JSONObject.parseObject(post, LIST_JOB_RESULT_TYPE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Query JobInfo by query
|
||||
* @param jobQuery JobQuery
|
||||
* @return JobInfo
|
||||
*/
|
||||
public ResultDTO<List<JobInfoDTO>> queryJob(JobQuery jobQuery) {
|
||||
jobQuery.appIdEq(appId);
|
||||
MediaType jsonType = MediaType.parse("application/json; charset=utf-8");
|
||||
String json = JSONObject.toJSONString(jobQuery);
|
||||
String post = postHA(OpenAPIConstant.Query_JOB, RequestBody.create(jsonType, json));
|
||||
return JSONObject.parseObject(post, LIST_JOB_RESULT_TYPE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Disable one Job by jobId
|
||||
* @param jobId jobId
|
||||
|
@ -3,6 +3,8 @@ package com.github.kfcfans.powerjob.client;
|
||||
import com.alibaba.fastjson.TypeReference;
|
||||
import com.github.kfcfans.powerjob.common.response.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* TypeReference store.
|
||||
*
|
||||
@ -19,6 +21,8 @@ public class TypeStore {
|
||||
|
||||
public static final TypeReference<ResultDTO<JobInfoDTO>> JOB_RESULT_TYPE = new TypeReference<ResultDTO<JobInfoDTO>>(){};
|
||||
|
||||
public static final TypeReference<ResultDTO<List<JobInfoDTO>>> LIST_JOB_RESULT_TYPE = new TypeReference<ResultDTO<List<JobInfoDTO>>>(){};
|
||||
|
||||
public static final TypeReference<ResultDTO<InstanceInfoDTO>> INSTANCE_RESULT_TYPE = new TypeReference<ResultDTO<InstanceInfoDTO>>() {};
|
||||
|
||||
public static final TypeReference<ResultDTO<WorkflowInfoDTO>> WF_RESULT_TYPE = new TypeReference<ResultDTO<WorkflowInfoDTO>>() {};
|
||||
|
@ -15,6 +15,8 @@ public class OpenAPIConstant {
|
||||
/* ************* JOB 区 ************* */
|
||||
public static final String SAVE_JOB = "/saveJob";
|
||||
public static final String FETCH_JOB = "/fetchJob";
|
||||
public static final String FETCH_ALL_JOB = "/fetchAllJob";
|
||||
public static final String Query_JOB = "/queryJob";
|
||||
public static final String DISABLE_JOB = "/disableJob";
|
||||
public static final String ENABLE_JOB = "/enableJob";
|
||||
public static final String DELETE_JOB = "/deleteJob";
|
||||
|
@ -0,0 +1,36 @@
|
||||
package com.github.kfcfans.powerjob.common.request.http;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* JobQuery
|
||||
* eq: equals, =
|
||||
* gt: greater than, >
|
||||
* lt: less than, <
|
||||
*
|
||||
* @author tjq
|
||||
* @since 2021/1/15
|
||||
*/
|
||||
@Data
|
||||
@Accessors(fluent = true, chain = true)
|
||||
public class JobQuery {
|
||||
|
||||
private Long appIdEq;
|
||||
|
||||
private Long idEq;
|
||||
private Long idLt;
|
||||
private Long idGt;
|
||||
|
||||
private List<Integer> statusIn;
|
||||
private List<Integer> statusNotIn;
|
||||
|
||||
private Long nextTriggerTimeLt;
|
||||
private Long nextTriggerTimeGt;
|
||||
|
||||
private String nameLike;
|
||||
|
||||
private Long limit;
|
||||
}
|
@ -32,4 +32,6 @@ public interface JobInfoRepository extends JpaRepository<JobInfoDO, Long> {
|
||||
|
||||
long countByAppIdAndStatusNot(long appId, int status);
|
||||
|
||||
List<JobInfoDO> findByAppId(Long appId);
|
||||
|
||||
}
|
||||
|
@ -24,6 +24,7 @@ import javax.annotation.Resource;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 任务服务
|
||||
@ -89,10 +90,11 @@ public class JobService {
|
||||
}
|
||||
|
||||
public JobInfoDTO fetchJob(Long jobId) {
|
||||
JobInfoDO jobInfoDO = jobInfoRepository.findById(jobId).orElseThrow(() -> new IllegalArgumentException("can't find job by jobId: " + jobId));
|
||||
JobInfoDTO jobInfoDTO = new JobInfoDTO();
|
||||
BeanUtils.copyProperties(jobInfoDO, jobInfoDTO);
|
||||
return jobInfoDTO;
|
||||
return convert(jobInfoRepository.findById(jobId).orElseThrow(() -> new IllegalArgumentException("can't find job by jobId: " + jobId)));
|
||||
}
|
||||
|
||||
public List<JobInfoDTO> fetchAllJob(Long appId) {
|
||||
return jobInfoRepository.findByAppId(appId).stream().map(JobService::convert).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -225,4 +227,10 @@ public class JobService {
|
||||
}
|
||||
}
|
||||
|
||||
private static JobInfoDTO convert(JobInfoDO jobInfoDO) {
|
||||
JobInfoDTO jobInfoDTO = new JobInfoDTO();
|
||||
BeanUtils.copyProperties(jobInfoDO, jobInfoDTO);
|
||||
return jobInfoDTO;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -2,6 +2,7 @@ package com.github.kfcfans.powerjob.server.web.controller;
|
||||
|
||||
import com.github.kfcfans.powerjob.common.InstanceStatus;
|
||||
import com.github.kfcfans.powerjob.common.OpenAPIConstant;
|
||||
import com.github.kfcfans.powerjob.common.request.http.JobQuery;
|
||||
import com.github.kfcfans.powerjob.common.request.http.SaveWorkflowRequest;
|
||||
import com.github.kfcfans.powerjob.server.service.AppInfoService;
|
||||
import com.github.kfcfans.powerjob.server.service.CacheService;
|
||||
@ -14,6 +15,7 @@ import com.github.kfcfans.powerjob.common.response.*;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 开放接口(OpenAPI)控制器,对接 oms-client
|
||||
@ -60,6 +62,16 @@ public class OpenAPIController {
|
||||
return ResultDTO.success(jobService.fetchJob(jobId));
|
||||
}
|
||||
|
||||
@PostMapping(OpenAPIConstant.FETCH_ALL_JOB)
|
||||
public ResultDTO<List<JobInfoDTO>> fetchAllJob(Long appId) {
|
||||
return ResultDTO.success(jobService.fetchAllJob(appId));
|
||||
}
|
||||
|
||||
@PostMapping(OpenAPIConstant.Query_JOB)
|
||||
public ResultDTO<List<JobInfoDTO>> queryJob(@RequestBody JobQuery jobQuery) {
|
||||
return ResultDTO.failed("developing");
|
||||
}
|
||||
|
||||
@PostMapping(OpenAPIConstant.DELETE_JOB)
|
||||
public ResultDTO<Void> deleteJob(Long jobId, Long appId) {
|
||||
checkJobIdValid(jobId, appId);
|
||||
|
Loading…
x
Reference in New Issue
Block a user