From 68a1227945170e1a662ead9f6d3597163a52e41a Mon Sep 17 00:00:00 2001 From: Charles7c Date: Sat, 25 Oct 2025 14:52:42 +0800 Subject: [PATCH] =?UTF-8?q?feat(schedule):=20=E4=BB=BB=E5=8A=A1=E8=B0=83?= =?UTF-8?q?=E5=BA=A6=E6=A8=A1=E5=9D=97=E6=9C=AA=E5=90=AF=E7=94=A8=E6=97=B6?= =?UTF-8?q?=EF=BC=8C=E5=A2=9E=E5=8A=A0=E9=BB=98=E8=AE=A4=E6=8F=90=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ConditionalOnDisabledScheduleJob.java | 35 ++++++++++++++++ .../controller/DefaultController.java | 41 +++++++++++++++++++ .../schedule/controller/JobController.java | 2 + .../schedule/controller/JobLogController.java | 2 + 4 files changed, 80 insertions(+) create mode 100644 continew-plugin/continew-plugin-schedule/src/main/java/top/continew/admin/schedule/annotation/ConditionalOnDisabledScheduleJob.java create mode 100644 continew-plugin/continew-plugin-schedule/src/main/java/top/continew/admin/schedule/controller/DefaultController.java diff --git a/continew-plugin/continew-plugin-schedule/src/main/java/top/continew/admin/schedule/annotation/ConditionalOnDisabledScheduleJob.java b/continew-plugin/continew-plugin-schedule/src/main/java/top/continew/admin/schedule/annotation/ConditionalOnDisabledScheduleJob.java new file mode 100644 index 00000000..b1e273d7 --- /dev/null +++ b/continew-plugin/continew-plugin-schedule/src/main/java/top/continew/admin/schedule/annotation/ConditionalOnDisabledScheduleJob.java @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2022-present Charles7c Authors. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package top.continew.admin.schedule.annotation; + +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; +import top.continew.starter.core.constant.PropertiesConstants; + +import java.lang.annotation.*; + +/** + * 是否禁用 Snail Job 判断注解 + * + * @author Charles7c + * @since 2025/10/25 12:28 + */ +@Retention(RetentionPolicy.RUNTIME) +@Target({ElementType.TYPE, ElementType.METHOD}) +@Documented +@ConditionalOnProperty(prefix = "snail-job", name = PropertiesConstants.ENABLED, havingValue = "false") +public @interface ConditionalOnDisabledScheduleJob { +} \ No newline at end of file diff --git a/continew-plugin/continew-plugin-schedule/src/main/java/top/continew/admin/schedule/controller/DefaultController.java b/continew-plugin/continew-plugin-schedule/src/main/java/top/continew/admin/schedule/controller/DefaultController.java new file mode 100644 index 00000000..1a9bfc19 --- /dev/null +++ b/continew-plugin/continew-plugin-schedule/src/main/java/top/continew/admin/schedule/controller/DefaultController.java @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2022-present Charles7c Authors. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package top.continew.admin.schedule.controller; + +import org.springframework.http.HttpStatus; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; +import top.continew.admin.schedule.annotation.ConditionalOnDisabledScheduleJob; +import top.continew.starter.web.model.R; + +/** + * 任务调度默认控制器 + * + * @author Charles7c + * @since 2025/10/25 12:28 + */ +@RestController +@ConditionalOnDisabledScheduleJob +@RequestMapping({"/schedule/job", "/schedule/log"}) +public class DefaultController { + + @RequestMapping("/**") + public R error() { + return R.fail(String.valueOf(HttpStatus.INTERNAL_SERVER_ERROR + .value()), "任务模块已禁用,请于对应环境配置文件中配置 snail-job.enabled 为 true 进行启用"); + } +} diff --git a/continew-plugin/continew-plugin-schedule/src/main/java/top/continew/admin/schedule/controller/JobController.java b/continew-plugin/continew-plugin-schedule/src/main/java/top/continew/admin/schedule/controller/JobController.java index 49842935..48438a38 100644 --- a/continew-plugin/continew-plugin-schedule/src/main/java/top/continew/admin/schedule/controller/JobController.java +++ b/continew-plugin/continew-plugin-schedule/src/main/java/top/continew/admin/schedule/controller/JobController.java @@ -25,6 +25,7 @@ import jakarta.validation.Valid; import lombok.RequiredArgsConstructor; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; +import top.continew.admin.schedule.annotation.ConditionalOnEnabledScheduleJob; import top.continew.admin.schedule.model.query.JobQuery; import top.continew.admin.schedule.model.req.JobReq; import top.continew.admin.schedule.model.req.JobStatusReq; @@ -48,6 +49,7 @@ import java.util.List; @Tag(name = " 任务 API") @RestController @RequiredArgsConstructor +@ConditionalOnEnabledScheduleJob @RequestMapping("/schedule/job") public class JobController { diff --git a/continew-plugin/continew-plugin-schedule/src/main/java/top/continew/admin/schedule/controller/JobLogController.java b/continew-plugin/continew-plugin-schedule/src/main/java/top/continew/admin/schedule/controller/JobLogController.java index 6a002c76..194a3363 100644 --- a/continew-plugin/continew-plugin-schedule/src/main/java/top/continew/admin/schedule/controller/JobLogController.java +++ b/continew-plugin/continew-plugin-schedule/src/main/java/top/continew/admin/schedule/controller/JobLogController.java @@ -24,6 +24,7 @@ import io.swagger.v3.oas.annotations.tags.Tag; import jakarta.validation.Valid; import lombok.RequiredArgsConstructor; import org.springframework.web.bind.annotation.*; +import top.continew.admin.schedule.annotation.ConditionalOnEnabledScheduleJob; import top.continew.admin.schedule.model.query.JobLogQuery; import top.continew.admin.schedule.model.resp.JobLogResp; import top.continew.admin.schedule.service.JobLogService; @@ -39,6 +40,7 @@ import top.continew.starter.extension.crud.model.resp.PageResp; @Tag(name = " 任务日志 API") @RestController @RequiredArgsConstructor +@ConditionalOnEnabledScheduleJob @RequestMapping("/schedule/log") public class JobLogController {