调度中心API

This commit is contained in:
XinWei 2024-07-10 23:48:22 +08:00
parent f6e2f92352
commit 5eff5433fe
4 changed files with 52 additions and 7 deletions

View File

@ -7,7 +7,6 @@ import com.xxl.job.admin.api.log.dto.JobLogPageReqDTO;
import com.xxl.job.admin.api.log.dto.JobLogRespDTO;
import com.xxl.job.admin.enums.ApiConstants;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;
@ -25,4 +24,8 @@ public interface JobLogApi {
@GetMapping(PREFIX + "/page")
@Operation(summary = "获得所有任务列表")
public CommonResult<PageResult<JobLogRespDTO>> getPage(@Valid JobLogPageReqDTO jobLogPageReqDTO);
@GetMapping(PREFIX + "/get")
@Operation(summary = "获得任务日志详情")
CommonResult<JobLogRespDTO> get(@RequestParam("id") Integer id);
}

View File

@ -53,4 +53,20 @@ public class JobLogApiImpl implements JobLogApi {
pageResult.setList(list);
return CommonResult.success(pageResult);
}
@Override
public CommonResult<JobLogRespDTO> get(Integer id) {
XxlJobLog load = xxlJobLogDao.load(id);
JobLogRespDTO jobLogRespDTO = new JobLogRespDTO();
jobLogRespDTO.setId(id);
jobLogRespDTO.setJobId(load.getJobId());
jobLogRespDTO.setDuration((int)(load.getHandleTime().getTime() - load.getTriggerTime().getTime()));
jobLogRespDTO.setBeginTime(load.getTriggerTime());
jobLogRespDTO.setEndTime(load.getHandleTime());
jobLogRespDTO.setHandlerName(load.getExecutorHandler());
jobLogRespDTO.setHandlerParam(load.getExecutorParam());
jobLogRespDTO.setStatus(load.getAlarmStatus());
jobLogRespDTO.setExecuteIndex(1);
return CommonResult.success(jobLogRespDTO);
}
}

View File

@ -1,7 +1,6 @@
package cn.iocoder.yudao.module.sampling.framework.security.config;
import cn.iocoder.yudao.framework.security.config.AuthorizeRequestsCustomizer;
import cn.iocoder.yudao.module.system.enums.ApiConstants;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
@ -28,7 +27,7 @@ public class SecurityConfiguration {
registry.antMatchers("/actuator").anonymous()
.antMatchers("/actuator/**").anonymous();
// RPC 服务的安全配置
registry.antMatchers(ApiConstants.PREFIX + "/**").permitAll();
// registry.antMatchers(ApiConstants.PREFIX + "/**").permitAll();
}
};

View File

@ -1,8 +1,12 @@
package cn.iocoder.yudao.module.infra.controller.admin.joblog;
import cn.iocoder.yudao.framework.apilog.core.annotation.ApiAccessLog;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
import com.xxl.job.admin.api.info.dto.JobInfoPageReqDTO;
import com.xxl.job.admin.api.info.dto.JobInfoRespDTO;
import com.xxl.job.admin.api.log.JobLogApi;
import com.xxl.job.admin.api.log.dto.JobLogPageReqDTO;
@ -11,12 +15,15 @@ import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.io.IOException;
import java.util.List;
import static cn.iocoder.yudao.framework.apilog.core.enums.OperateTypeEnum.EXPORT;
@Tag(name = "管理后台 - 定时任务日志")
@RestController
@ -25,9 +32,29 @@ import javax.validation.Valid;
public class JobLogController {
@Resource
private JobLogApi jobLogApi;
@RequestMapping("/page")
@GetMapping("/page")
@Operation(summary = "获得任务日志列表")
@PreAuthorize("@ss.hasPermission('infra:job-log:query')")
public CommonResult<PageResult<JobLogRespDTO>> getPage(@Valid JobLogPageReqDTO jobLogPageReqDTO){
return jobLogApi.getPage(jobLogPageReqDTO);
}
@GetMapping("/get")
@Operation(summary = "获取任务详情")
@PreAuthorize("@ss.hasPermission('infra:job-log:query')")
public CommonResult<JobLogRespDTO> get(@RequestParam("id") Integer id){
return jobLogApi.get(id);
}
@GetMapping("/export-excel")
@Operation(summary = "导出任务 Excel")
@PreAuthorize("@ss.hasPermission('infra:job-log:export')")
@ApiAccessLog(operateType = EXPORT)
public void exportJobInfoExcel(@Valid JobLogPageReqDTO pageReqVO,
HttpServletResponse response) throws IOException {
pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
List<JobLogRespDTO> list = jobLogApi.getPage(pageReqVO).getData().getList();
// 导出 Excel
ExcelUtils.write(response, "任务调度.xls", "数据", JobLogRespDTO.class,
list);
}
}