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