Skip to content

Commit

Permalink
fix: 修复任务调度 API 使用错误(由1.1.0-beta => 1.1.0引发)
Browse files Browse the repository at this point in the history
  • Loading branch information
Charles7c committed Aug 4, 2024
1 parent 4554526 commit cef5cb4
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import top.continew.admin.job.model.resp.JobResp;

import java.util.List;
import java.util.Set;

/**
* 任务 REST API
Expand Down Expand Up @@ -87,11 +88,11 @@ ResponseEntity<JobPageResult<List<JobResp>>> page(@RequestParam(value = "groupNa
/**
* 删除
*
* @param id ID
* @param ids ID 列表
* @return 响应信息
*/
@DeleteExchange("/job/{id}")
ResponseEntity<Result<Boolean>> delete(@PathVariable("id") Long id);
@DeleteExchange("/job/ids")
ResponseEntity<Result<Boolean>> delete(@RequestBody Set<Long> ids);

/**
* 执行
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,18 +75,13 @@ public JobClient(String url, String username, String password) {
* @return 响应信息
*/
public <T> T request(Supplier<ResponseEntity<Result<T>>> apiSupplier) {
try {
ResponseEntity<Result<T>> responseEntity = apiSupplier.get();
this.checkResponse(responseEntity);
Result<T> result = responseEntity.getBody();
if (!STATUS_SUCCESS.equals(result.getStatus())) {
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("连接任务调度中心异常");
ResponseEntity<Result<T>> responseEntity = apiSupplier.get();
this.checkResponse(responseEntity);
Result<T> result = responseEntity.getBody();
if (!STATUS_SUCCESS.equals(result.getStatus())) {
throw new IllegalStateException(result.getMessage());
}
return result.getData();
}

/**
Expand All @@ -97,21 +92,16 @@ public <T> T request(Supplier<ResponseEntity<Result<T>>> apiSupplier) {
* @return 分页列表信息
*/
public <T> PageResp<T> requestPage(Supplier<ResponseEntity<JobPageResult<List<T>>>> apiSupplier) {
try {
ResponseEntity<JobPageResult<List<T>>> responseEntity = apiSupplier.get();
this.checkResponse(responseEntity);
JobPageResult<List<T>> result = responseEntity.getBody();
if (!STATUS_SUCCESS.equals(result.getStatus())) {
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("连接任务调度中心异常");
ResponseEntity<JobPageResult<List<T>>> responseEntity = apiSupplier.get();
this.checkResponse(responseEntity);
JobPageResult<List<T>> result = responseEntity.getBody();
if (!STATUS_SUCCESS.equals(result.getStatus())) {
throw new IllegalStateException(result.getMessage());
}
PageResp<T> page = new PageResp<>();
page.setList(result.getData());
page.setTotal(result.getTotal());
return page;
}

/**
Expand Down Expand Up @@ -147,8 +137,9 @@ private String authenticate() {
}
Result<?> result = JSONUtil.toBean(response.body(), Result.class);
if (!STATUS_SUCCESS.equals(result.getStatus())) {
throw new IllegalStateException("Password Authentication failed, expected a successful response. error msg: %s"
.formatted(result.getMessage()));
log.warn("Password Authentication failed, expected a successful response. error msg: {}", result
.getMessage());
throw new IllegalStateException(result.getMessage());
}
return JSONUtil.parseObj(result.getData()).getStr("token");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,14 @@
public enum JobTriggerTypeEnum implements BaseEnum<Integer> {

/**
* CRON
* 固定时间
*/
CRON(1, "CRON"),
FIXED_TIME(2, "固定时间"),

/**
* 固定时间
* CRON
*/
FIXED_TIME(2, "固定时间"),;
CRON(3, "CRON");

private final Integer value;
private final String description;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import top.continew.admin.job.service.JobService;
import top.continew.starter.extension.crud.model.resp.PageResp;

import java.util.Collections;
import java.util.List;

/**
Expand Down Expand Up @@ -68,7 +69,7 @@ public boolean updateStatus(JobStatusReq req, Long id) {

@Override
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
Expand Down

0 comments on commit cef5cb4

Please sign in to comment.