feat(schedule): 任务调度模块未启用时,增加默认提示

This commit is contained in:
2025-10-25 14:52:42 +08:00
parent 5e7a2a4a74
commit 68a1227945
4 changed files with 80 additions and 0 deletions

View File

@@ -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 {
}

View File

@@ -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 进行启用");
}
}

View File

@@ -25,6 +25,7 @@ import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated; import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*; 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.query.JobQuery;
import top.continew.admin.schedule.model.req.JobReq; import top.continew.admin.schedule.model.req.JobReq;
import top.continew.admin.schedule.model.req.JobStatusReq; import top.continew.admin.schedule.model.req.JobStatusReq;
@@ -48,6 +49,7 @@ import java.util.List;
@Tag(name = " 任务 API") @Tag(name = " 任务 API")
@RestController @RestController
@RequiredArgsConstructor @RequiredArgsConstructor
@ConditionalOnEnabledScheduleJob
@RequestMapping("/schedule/job") @RequestMapping("/schedule/job")
public class JobController { public class JobController {

View File

@@ -24,6 +24,7 @@ import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid; import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*; 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.query.JobLogQuery;
import top.continew.admin.schedule.model.resp.JobLogResp; import top.continew.admin.schedule.model.resp.JobLogResp;
import top.continew.admin.schedule.service.JobLogService; import top.continew.admin.schedule.service.JobLogService;
@@ -39,6 +40,7 @@ import top.continew.starter.extension.crud.model.resp.PageResp;
@Tag(name = " 任务日志 API") @Tag(name = " 任务日志 API")
@RestController @RestController
@RequiredArgsConstructor @RequiredArgsConstructor
@ConditionalOnEnabledScheduleJob
@RequestMapping("/schedule/log") @RequestMapping("/schedule/log")
public class JobLogController { public class JobLogController {