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 {