优化代码
This commit is contained in:
parent
4ac9e33739
commit
7f2bac7d76
|
@ -22,9 +22,9 @@ public class ScheduleUtils {
|
|||
* 获取quartz任务类
|
||||
*/
|
||||
public static Class<? extends Job> getJobClass(ScheduleJobEntity scheduleJob) {
|
||||
if(scheduleJob.getConcurrent().equals(ScheduleConcurrentEnum.NO.getValue())){
|
||||
if (scheduleJob.getConcurrent().equals(ScheduleConcurrentEnum.NO.getValue())) {
|
||||
return ScheduleDisallowConcurrentExecution.class;
|
||||
}else {
|
||||
} else {
|
||||
return ScheduleConcurrentExecution.class;
|
||||
}
|
||||
}
|
||||
|
@ -63,23 +63,23 @@ public class ScheduleUtils {
|
|||
|
||||
// 放入参数,运行时的方法可以获取
|
||||
jobDetail.getJobDataMap().put(JOB_PARAM_KEY, scheduleJob);
|
||||
|
||||
// 把任务添加到Quartz中
|
||||
scheduler.scheduleJob(jobDetail, trigger);
|
||||
|
||||
// 判断是否存在
|
||||
if (scheduler.checkExists(jobKey)){
|
||||
if (scheduler.checkExists(jobKey)) {
|
||||
// 防止创建时存在数据问题,先移除,然后再执行创建操作
|
||||
scheduler.deleteJob(jobKey);
|
||||
}
|
||||
|
||||
// 判断任务是否过期
|
||||
if (CronUtils.getNextExecution(scheduleJob.getCronExpression()) != null){
|
||||
if (CronUtils.getNextExecution(scheduleJob.getCronExpression()) != null) {
|
||||
// 执行调度任务
|
||||
scheduler.scheduleJob(jobDetail, trigger);
|
||||
}
|
||||
|
||||
// 暂停任务
|
||||
if (scheduleJob.getStatus().equals(ScheduleStatusEnum.PAUSE.getValue())){
|
||||
if (scheduleJob.getStatus().equals(ScheduleStatusEnum.PAUSE.getValue())) {
|
||||
scheduler.pauseJob(jobKey);
|
||||
}
|
||||
} catch (SchedulerException e) {
|
||||
|
@ -88,7 +88,6 @@ public class ScheduleUtils {
|
|||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 立即执行任务
|
||||
*/
|
||||
|
@ -141,7 +140,7 @@ public class ScheduleUtils {
|
|||
if (scheduler.checkExists(jobKey)) {
|
||||
scheduler.deleteJob(jobKey);
|
||||
}
|
||||
}catch (SchedulerException e){
|
||||
} catch (SchedulerException e) {
|
||||
throw new ServerException("更新定时任务失败", e);
|
||||
}
|
||||
|
||||
|
|
|
@ -7,14 +7,13 @@ import lombok.Getter;
|
|||
* 错误编码
|
||||
*
|
||||
* @author 阿沐 babamu@126.com
|
||||
*/
|
||||
*/
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public enum ErrorCode {
|
||||
UNAUTHORIZED(401, "还未授权,不能访问"),
|
||||
FORBIDDEN(403, "没有权限,禁止访问"),
|
||||
INTERNAL_SERVER_ERROR(500, "服务器异常,请稍后再试"),
|
||||
ACCOUNT_PASSWORD_ERROR(1001, "账号或密码错误");
|
||||
INTERNAL_SERVER_ERROR(500, "服务器异常,请稍后再试");
|
||||
|
||||
private final int code;
|
||||
private final String msg;
|
||||
|
|
|
@ -21,7 +21,7 @@ public class ServerExceptionHandler {
|
|||
* 处理自定义异常
|
||||
*/
|
||||
@ExceptionHandler(ServerException.class)
|
||||
public Result<String> handleException(ServerException ex){
|
||||
public Result<String> handleException(ServerException ex) {
|
||||
|
||||
return Result.error(ex.getCode(), ex.getMsg());
|
||||
}
|
||||
|
@ -37,13 +37,13 @@ public class ServerExceptionHandler {
|
|||
}
|
||||
|
||||
@ExceptionHandler(AccessDeniedException.class)
|
||||
public Result<String> handleAccessDeniedException(Exception ex){
|
||||
public Result<String> handleAccessDeniedException(Exception ex) {
|
||||
|
||||
return Result.error(ErrorCode.FORBIDDEN);
|
||||
}
|
||||
|
||||
@ExceptionHandler(Exception.class)
|
||||
public Result<String> handleException(Exception ex){
|
||||
public Result<String> handleException(Exception ex) {
|
||||
log.error(ex.getMessage(), ex);
|
||||
return Result.error(ErrorCode.INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
|
|
|
@ -14,12 +14,12 @@ import org.springframework.context.annotation.Configuration;
|
|||
* @author 阿沐 babamu@126.com
|
||||
*/
|
||||
@Configuration
|
||||
public class SwaggerConfig{
|
||||
public class SwaggerConfig {
|
||||
|
||||
@Bean
|
||||
public GroupedOpenApi userApi(){
|
||||
String[] paths = { "/**" };
|
||||
String[] packagedToMatch = { "net.maku" };
|
||||
public GroupedOpenApi userApi() {
|
||||
String[] paths = {"/**"};
|
||||
String[] packagedToMatch = {"net.maku"};
|
||||
return GroupedOpenApi.builder().group("MakuBoot")
|
||||
.pathsToMatch(paths)
|
||||
.packagesToScan(packagedToMatch).build();
|
||||
|
@ -27,14 +27,14 @@ public class SwaggerConfig{
|
|||
|
||||
@Bean
|
||||
public OpenAPI customOpenAPI() {
|
||||
Contact contact= new Contact();
|
||||
Contact contact = new Contact();
|
||||
contact.setName("阿沐 babamu@126.com");
|
||||
|
||||
return new OpenAPI().info(new Info()
|
||||
.title("MakuBoot")
|
||||
.description( "MakuBoot")
|
||||
.description("MakuBoot")
|
||||
.contact(contact)
|
||||
.version("1.0")
|
||||
.version("2.0")
|
||||
.termsOfService("https://maku.net")
|
||||
.license(new License().name("MIT")
|
||||
.url("https://maku.net")));
|
||||
|
|
Loading…
Reference in New Issue
Block a user