feat: 添加任务状态枚举
This commit is contained in:
parent
f600eea680
commit
56d0805f6a
|
@ -1,7 +1,6 @@
|
||||||
package cn.bunny.common.service.exception;
|
package cn.bunny.common.service.exception;
|
||||||
|
|
||||||
|
|
||||||
import cn.bunny.dao.pojo.constant.ExceptionConstant;
|
|
||||||
import cn.bunny.dao.pojo.result.Result;
|
import cn.bunny.dao.pojo.result.Result;
|
||||||
import cn.bunny.dao.pojo.result.ResultCodeEnum;
|
import cn.bunny.dao.pojo.result.ResultCodeEnum;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
@ -121,13 +120,10 @@ public class GlobalExceptionHandler {
|
||||||
|
|
||||||
String message = exception.getMessage();
|
String message = exception.getMessage();
|
||||||
if (message.contains("Duplicate entry")) {
|
if (message.contains("Duplicate entry")) {
|
||||||
// 截取用户名
|
|
||||||
String username = message.split(" ")[2];
|
|
||||||
// 错误信息
|
// 错误信息
|
||||||
String errorMessage = username + ExceptionConstant.ALREADY_USER_EXCEPTION;
|
return Result.error(ResultCodeEnum.USER_IS_EMPTY);
|
||||||
return Result.error(errorMessage);
|
|
||||||
} else {
|
} else {
|
||||||
return Result.error(ExceptionConstant.UNKNOWN_EXCEPTION);
|
return Result.error(ResultCodeEnum.UNKNOWN_EXCEPTION);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,22 +0,0 @@
|
||||||
package cn.bunny.dao.pojo.constant;
|
|
||||||
|
|
||||||
import lombok.Data;
|
|
||||||
|
|
||||||
|
|
||||||
@Data
|
|
||||||
public class ExceptionConstant {
|
|
||||||
public static final String UNKNOWN_EXCEPTION = "未知错误";
|
|
||||||
|
|
||||||
// 用户相关
|
|
||||||
public static final String USER_NOT_LOGIN_EXCEPTION = "用户未登录";
|
|
||||||
public static final String USERNAME_IS_EMPTY_EXCEPTION = "用户名不能为空";
|
|
||||||
public static final String ALREADY_USER_EXCEPTION = "用户已存在";
|
|
||||||
public static final String USER_NOT_FOUND_EXCEPTION = "用户不存在";
|
|
||||||
|
|
||||||
// 密码相关
|
|
||||||
public static final String PASSWORD_EXCEPTION = "密码错误";
|
|
||||||
public static final String PASSWORD_NOT_EMPTY_EXCEPTION = "密码不能为空";
|
|
||||||
public static final String OLD_PASSWORD_EXCEPTION = "旧密码不匹配";
|
|
||||||
public static final String PASSWORD_EDIT_EXCEPTION = "密码修改失败";
|
|
||||||
public static final String OLD_PASSWORD_SAME_NEW_PASSWORD_EXCEPTION = "旧密码与新密码相同";
|
|
||||||
}
|
|
|
@ -12,6 +12,7 @@ public class MinioConstant {
|
||||||
public static final String article = "article";
|
public static final String article = "article";
|
||||||
public static final String carousel = "carousel";
|
public static final String carousel = "carousel";
|
||||||
public static final String feedback = "feedback";
|
public static final String feedback = "feedback";
|
||||||
|
public static final String backup = "backup";
|
||||||
public static final String articleCovers = "articleCovers";
|
public static final String articleCovers = "articleCovers";
|
||||||
public static final String articleAttachment = "articleAttachment";
|
public static final String articleAttachment = "articleAttachment";
|
||||||
public static final Map<String, String> typeMap = new HashMap<>();
|
public static final Map<String, String> typeMap = new HashMap<>();
|
||||||
|
@ -22,6 +23,7 @@ public class MinioConstant {
|
||||||
typeMap.put(article, "/article/");
|
typeMap.put(article, "/article/");
|
||||||
typeMap.put(carousel, "/carousel/");
|
typeMap.put(carousel, "/carousel/");
|
||||||
typeMap.put(feedback, "/feedback/");
|
typeMap.put(feedback, "/feedback/");
|
||||||
|
typeMap.put(backup, "/backup/");
|
||||||
typeMap.put("articleImages", "/articleImages/");
|
typeMap.put("articleImages", "/articleImages/");
|
||||||
typeMap.put("articleVideo", "/articleVideo/");
|
typeMap.put("articleVideo", "/articleVideo/");
|
||||||
typeMap.put(articleCovers, "/articleCovers/");
|
typeMap.put(articleCovers, "/articleCovers/");
|
||||||
|
|
|
@ -0,0 +1,20 @@
|
||||||
|
package cn.bunny.dao.pojo.enums;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
public enum JobEnums {
|
||||||
|
FINISH("finish", "完成"),
|
||||||
|
UNFINISHED("unfinished", "未完成"),
|
||||||
|
RUNNING("running", "正在运行"),
|
||||||
|
ERROR("error", "错误"),
|
||||||
|
;
|
||||||
|
|
||||||
|
private final String type;
|
||||||
|
private final String summary;
|
||||||
|
|
||||||
|
JobEnums(String type, String summary) {
|
||||||
|
this.type = type;
|
||||||
|
this.summary = summary;
|
||||||
|
}
|
||||||
|
}
|
|
@ -43,6 +43,7 @@ public enum ResultCodeEnum {
|
||||||
EMAIL_USER_IS_EMPTY(206, "关联邮件用户配置为空"),
|
EMAIL_USER_IS_EMPTY(206, "关联邮件用户配置为空"),
|
||||||
DATA_EXIST(206, "数据已存在"),
|
DATA_EXIST(206, "数据已存在"),
|
||||||
DATA_NOT_EXIST(206, "数据不存在"),
|
DATA_NOT_EXIST(206, "数据不存在"),
|
||||||
|
ALREADY_USER_EXCEPTION(206, "用户已存在"),
|
||||||
USER_IS_EMPTY(206, "用户不存在"),
|
USER_IS_EMPTY(206, "用户不存在"),
|
||||||
FILE_NOT_EXIST(206, "文件不存在"),
|
FILE_NOT_EXIST(206, "文件不存在"),
|
||||||
NEW_PASSWORD_SAME_OLD_PASSWORD(206, "新密码不能和旧密码相同"),
|
NEW_PASSWORD_SAME_OLD_PASSWORD(206, "新密码不能和旧密码相同"),
|
||||||
|
@ -70,6 +71,7 @@ public enum ResultCodeEnum {
|
||||||
LOGGED_IN_FROM_ANOTHER_DEVICE(403, "没有权限访问"),
|
LOGGED_IN_FROM_ANOTHER_DEVICE(403, "没有权限访问"),
|
||||||
|
|
||||||
// 系统错误 500
|
// 系统错误 500
|
||||||
|
UNKNOWN_EXCEPTION(500, "服务异常"),
|
||||||
SERVICE_ERROR(500, "服务异常"),
|
SERVICE_ERROR(500, "服务异常"),
|
||||||
UPDATE_ERROR(500, "上传文件失败"),
|
UPDATE_ERROR(500, "上传文件失败"),
|
||||||
FAIL(500, "失败"),
|
FAIL(500, "失败"),
|
||||||
|
|
|
@ -3,6 +3,7 @@ package cn.bunny.services.aop;
|
||||||
import cn.bunny.dao.entity.log.ScheduleExecuteLog;
|
import cn.bunny.dao.entity.log.ScheduleExecuteLog;
|
||||||
import cn.bunny.dao.entity.log.ScheduleExecuteLogJson;
|
import cn.bunny.dao.entity.log.ScheduleExecuteLogJson;
|
||||||
import cn.bunny.dao.pojo.constant.LocalDateTimeConstant;
|
import cn.bunny.dao.pojo.constant.LocalDateTimeConstant;
|
||||||
|
import cn.bunny.dao.pojo.enums.JobEnums;
|
||||||
import cn.bunny.services.mapper.ScheduleExecuteLogMapper;
|
import cn.bunny.services.mapper.ScheduleExecuteLogMapper;
|
||||||
import com.alibaba.fastjson2.JSON;
|
import com.alibaba.fastjson2.JSON;
|
||||||
import org.aspectj.lang.ProceedingJoinPoint;
|
import org.aspectj.lang.ProceedingJoinPoint;
|
||||||
|
@ -58,9 +59,9 @@ public class JobExecuteAop {
|
||||||
executeLog.setCronExpression(cronExpression);
|
executeLog.setCronExpression(cronExpression);
|
||||||
executeLog.setTriggerName(triggerName);
|
executeLog.setTriggerName(triggerName);
|
||||||
// 设置状态结果
|
// 设置状态结果
|
||||||
executeLogJson.setResult("unfinished");
|
executeLogJson.setResult(JobEnums.UNFINISHED.getType());
|
||||||
executeLogJson.setStatus("running");
|
executeLogJson.setStatus(JobEnums.RUNNING.getType());
|
||||||
executeLogJson.setMessage("running...");
|
executeLogJson.setMessage(JobEnums.RUNNING.getSummary());
|
||||||
executeLogJson.setOperationTime(startExecuteTIme);
|
executeLogJson.setOperationTime(startExecuteTIme);
|
||||||
executeLogJson.setExecuteParams(jobDataMap);
|
executeLogJson.setExecuteParams(jobDataMap);
|
||||||
executeLog.setExecuteResult(JSON.toJSONString(executeLogJson));
|
executeLog.setExecuteResult(JSON.toJSONString(executeLogJson));
|
||||||
|
@ -70,14 +71,14 @@ public class JobExecuteAop {
|
||||||
result = joinPoint.proceed();
|
result = joinPoint.proceed();
|
||||||
|
|
||||||
// 设置执行结果-执行任务的日志
|
// 设置执行结果-执行任务的日志
|
||||||
executeLogJson.setResult("finish");
|
executeLogJson.setResult(JobEnums.FINISH.getType());
|
||||||
executeLogJson.setStatus("finish");
|
executeLogJson.setStatus(JobEnums.FINISH.getType());
|
||||||
executeLogJson.setMessage("finish");
|
executeLogJson.setMessage(JobEnums.FINISH.getSummary());
|
||||||
setEndExecuteLog(executeLogJson, executeLog, startLocalDateTime);
|
setEndExecuteLog(executeLogJson, executeLog, startLocalDateTime);
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
// 设置执行结果-执行任务的日志
|
// 设置执行结果-执行任务的日志
|
||||||
executeLogJson.setResult("error");
|
executeLogJson.setResult(JobEnums.ERROR.getType());
|
||||||
executeLogJson.setStatus("error");
|
executeLogJson.setStatus(JobEnums.ERROR.getType());
|
||||||
executeLogJson.setMessage(e.getMessage());
|
executeLogJson.setMessage(e.getMessage());
|
||||||
setEndExecuteLog(executeLogJson, executeLog, startLocalDateTime);
|
setEndExecuteLog(executeLogJson, executeLog, startLocalDateTime);
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
|
|
Loading…
Reference in New Issue