From 5eff5433fe252bc37c2c1fca115eb363d2ad169b Mon Sep 17 00:00:00 2001 From: XinWei <2718030729@qq.com> Date: Wed, 10 Jul 2024 23:48:22 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E5=BA=A6=E4=B8=AD=E5=BF=83API?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/xxl/job/admin/api/log/JobLogApi.java | 5 ++- .../xxl/job/admin/api/log/JobLogApiImpl.java | 16 +++++++++ .../config/SecurityConfiguration.java | 3 +- .../admin/joblog/JobLogController.java | 35 ++++++++++++++++--- 4 files changed, 52 insertions(+), 7 deletions(-) diff --git a/ludu-job-admin/ludu-job-admin-api/src/main/java/com/xxl/job/admin/api/log/JobLogApi.java b/ludu-job-admin/ludu-job-admin-api/src/main/java/com/xxl/job/admin/api/log/JobLogApi.java index c538c694d..960f1018f 100644 --- a/ludu-job-admin/ludu-job-admin-api/src/main/java/com/xxl/job/admin/api/log/JobLogApi.java +++ b/ludu-job-admin/ludu-job-admin-api/src/main/java/com/xxl/job/admin/api/log/JobLogApi.java @@ -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> getPage(@Valid JobLogPageReqDTO jobLogPageReqDTO); + + @GetMapping(PREFIX + "/get") + @Operation(summary = "获得任务日志详情") + CommonResult get(@RequestParam("id") Integer id); } diff --git a/ludu-job-admin/ludu-job-admin-biz/src/main/java/com/xxl/job/admin/api/log/JobLogApiImpl.java b/ludu-job-admin/ludu-job-admin-biz/src/main/java/com/xxl/job/admin/api/log/JobLogApiImpl.java index 75627a42a..2a47c1a27 100644 --- a/ludu-job-admin/ludu-job-admin-biz/src/main/java/com/xxl/job/admin/api/log/JobLogApiImpl.java +++ b/ludu-job-admin/ludu-job-admin-biz/src/main/java/com/xxl/job/admin/api/log/JobLogApiImpl.java @@ -53,4 +53,20 @@ public class JobLogApiImpl implements JobLogApi { pageResult.setList(list); return CommonResult.success(pageResult); } + + @Override + public CommonResult 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); + } } diff --git a/ludu-module-sampling/ludu-module-sampling-biz/src/main/java/cn/iocoder/yudao/module/sampling/framework/security/config/SecurityConfiguration.java b/ludu-module-sampling/ludu-module-sampling-biz/src/main/java/cn/iocoder/yudao/module/sampling/framework/security/config/SecurityConfiguration.java index c9e63afcd..1b0c050b6 100644 --- a/ludu-module-sampling/ludu-module-sampling-biz/src/main/java/cn/iocoder/yudao/module/sampling/framework/security/config/SecurityConfiguration.java +++ b/ludu-module-sampling/ludu-module-sampling-biz/src/main/java/cn/iocoder/yudao/module/sampling/framework/security/config/SecurityConfiguration.java @@ -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(); } }; diff --git a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/joblog/JobLogController.java b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/joblog/JobLogController.java index 0a1255ffb..c56b8db53 100644 --- a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/joblog/JobLogController.java +++ b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/joblog/JobLogController.java @@ -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> getPage(@Valid JobLogPageReqDTO jobLogPageReqDTO){ return jobLogApi.getPage(jobLogPageReqDTO); } + + @GetMapping("/get") + @Operation(summary = "获取任务详情") + @PreAuthorize("@ss.hasPermission('infra:job-log:query')") + public CommonResult 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 list = jobLogApi.getPage(pageReqVO).getData().getList(); + // 导出 Excel + ExcelUtils.write(response, "任务调度.xls", "数据", JobLogRespDTO.class, + list); + } }