fix: 修复任务调度 API 使用错误(由1.1.0-beta => 1.1.0引发)

This commit is contained in:
2024-08-04 18:54:35 +08:00
parent 45545260a3
commit cef5cb4fa5
4 changed files with 30 additions and 37 deletions

View File

@@ -29,6 +29,7 @@ import top.continew.admin.job.model.req.JobStatusReq;
import top.continew.admin.job.model.resp.JobResp; import top.continew.admin.job.model.resp.JobResp;
import java.util.List; import java.util.List;
import java.util.Set;
/** /**
* 任务 REST API * 任务 REST API
@@ -87,11 +88,11 @@ public interface JobApi {
/** /**
* 删除 * 删除
* *
* @param id ID * @param ids ID 列表
* @return 响应信息 * @return 响应信息
*/ */
@DeleteExchange("/job/{id}") @DeleteExchange("/job/ids")
ResponseEntity<Result<Boolean>> delete(@PathVariable("id") Long id); ResponseEntity<Result<Boolean>> delete(@RequestBody Set<Long> ids);
/** /**
* 执行 * 执行

View File

@@ -75,18 +75,13 @@ public class JobClient {
* @return 响应信息 * @return 响应信息
*/ */
public <T> T request(Supplier<ResponseEntity<Result<T>>> apiSupplier) { public <T> T request(Supplier<ResponseEntity<Result<T>>> apiSupplier) {
try { ResponseEntity<Result<T>> responseEntity = apiSupplier.get();
ResponseEntity<Result<T>> responseEntity = apiSupplier.get(); this.checkResponse(responseEntity);
this.checkResponse(responseEntity); Result<T> result = responseEntity.getBody();
Result<T> result = responseEntity.getBody(); if (!STATUS_SUCCESS.equals(result.getStatus())) {
if (!STATUS_SUCCESS.equals(result.getStatus())) { throw new IllegalStateException(result.getMessage());
throw new IllegalStateException(result.getMessage());
}
return result.getData();
} catch (Exception e) {
log.error("Request job server failed, error msg: {}", e.getMessage(), e);
throw new IllegalStateException("连接任务调度中心异常");
} }
return result.getData();
} }
/** /**
@@ -97,21 +92,16 @@ public class JobClient {
* @return 分页列表信息 * @return 分页列表信息
*/ */
public <T> PageResp<T> requestPage(Supplier<ResponseEntity<JobPageResult<List<T>>>> apiSupplier) { public <T> PageResp<T> requestPage(Supplier<ResponseEntity<JobPageResult<List<T>>>> apiSupplier) {
try { ResponseEntity<JobPageResult<List<T>>> responseEntity = apiSupplier.get();
ResponseEntity<JobPageResult<List<T>>> responseEntity = apiSupplier.get(); this.checkResponse(responseEntity);
this.checkResponse(responseEntity); JobPageResult<List<T>> result = responseEntity.getBody();
JobPageResult<List<T>> result = responseEntity.getBody(); if (!STATUS_SUCCESS.equals(result.getStatus())) {
if (!STATUS_SUCCESS.equals(result.getStatus())) { throw new IllegalStateException(result.getMessage());
throw new IllegalStateException(result.getMessage());
}
PageResp<T> page = new PageResp<>();
page.setList(result.getData());
page.setTotal(result.getTotal());
return page;
} catch (Exception e) {
log.error("Request job server failed, error msg: {}", e.getMessage(), e);
throw new IllegalStateException("连接任务调度中心异常");
} }
PageResp<T> page = new PageResp<>();
page.setList(result.getData());
page.setTotal(result.getTotal());
return page;
} }
/** /**
@@ -147,8 +137,9 @@ public class JobClient {
} }
Result<?> result = JSONUtil.toBean(response.body(), Result.class); Result<?> result = JSONUtil.toBean(response.body(), Result.class);
if (!STATUS_SUCCESS.equals(result.getStatus())) { if (!STATUS_SUCCESS.equals(result.getStatus())) {
throw new IllegalStateException("Password Authentication failed, expected a successful response. error msg: %s" log.warn("Password Authentication failed, expected a successful response. error msg: {}", result
.formatted(result.getMessage())); .getMessage());
throw new IllegalStateException(result.getMessage());
} }
return JSONUtil.parseObj(result.getData()).getStr("token"); return JSONUtil.parseObj(result.getData()).getStr("token");
} }

View File

@@ -30,15 +30,15 @@ import top.continew.starter.core.enums.BaseEnum;
@RequiredArgsConstructor @RequiredArgsConstructor
public enum JobTriggerTypeEnum implements BaseEnum<Integer> { public enum JobTriggerTypeEnum implements BaseEnum<Integer> {
/**
* CRON
*/
CRON(1, "CRON"),
/** /**
* 固定时间 * 固定时间
*/ */
FIXED_TIME(2, "固定时间"),; FIXED_TIME(2, "固定时间"),
/**
* CRON
*/
CRON(3, "CRON");
private final Integer value; private final Integer value;
private final String description; private final String description;

View File

@@ -27,6 +27,7 @@ import top.continew.admin.job.model.resp.JobResp;
import top.continew.admin.job.service.JobService; import top.continew.admin.job.service.JobService;
import top.continew.starter.extension.crud.model.resp.PageResp; import top.continew.starter.extension.crud.model.resp.PageResp;
import java.util.Collections;
import java.util.List; import java.util.List;
/** /**
@@ -68,7 +69,7 @@ public class JobServiceImpl implements JobService {
@Override @Override
public boolean delete(Long id) { public boolean delete(Long id) {
return Boolean.TRUE.equals(jobClient.request(() -> jobApi.delete(id))); return Boolean.TRUE.equals(jobClient.request(() -> jobApi.delete(Collections.singleton(id))));
} }
@Override @Override