完成序列号生成功能

This commit is contained in:
AlanScipio
2024-02-19 13:50:33 +08:00
parent 7a257eb264
commit a327ff26ba
46 changed files with 2163 additions and 200 deletions

View File

@@ -0,0 +1,39 @@
package com.ruoyi.common.core.constant;
import java.util.NoSuchElementException;
/**
* @author Alan Scipio
* created on 2024/2/18
*/
public interface IEnum {
int getCode();
String getName();
static IEnum getByCode(IEnum[] enums, int code) {
if (enums == null || enums.length == 0) {
throw new IllegalArgumentException("enums is empty");
}
for (IEnum value : enums) {
if (value.getCode() == code) {
return value;
}
}
throw new NoSuchElementException("No such enum with code: [" + code + "], enum type: [" + enums[0].getClass().getName() + "]");
}
static IEnum getByName(IEnum[] enums, String name) {
if (enums == null || enums.length == 0) {
throw new IllegalArgumentException("enums is empty");
}
for (IEnum value : enums) {
if (value.getName().equals(name)) {
return value;
}
}
throw new NoSuchElementException("No such enum with name: [" + name + "], enum type: [" + enums[0].getClass().getName() + "]");
}
}

View File

@@ -1,16 +1,17 @@
package com.ruoyi.common.core.exception;
import java.io.Serial;
/**
* 验证码错误异常类
*
*
* @author ruoyi
*/
public class CaptchaException extends RuntimeException
{
public class CaptchaException extends RuntimeException {
@Serial
private static final long serialVersionUID = 1L;
public CaptchaException(String msg)
{
public CaptchaException(String msg) {
super(msg);
}
}

View File

@@ -1,31 +1,29 @@
package com.ruoyi.common.core.exception;
import java.io.Serial;
/**
* 检查异常
*
*
* @author ruoyi
*/
public class CheckedException extends RuntimeException
{
public class CheckedException extends RuntimeException {
@Serial
private static final long serialVersionUID = 1L;
public CheckedException(String message)
{
public CheckedException(String message) {
super(message);
}
public CheckedException(Throwable cause)
{
public CheckedException(Throwable cause) {
super(cause);
}
public CheckedException(String message, Throwable cause)
{
public CheckedException(String message, Throwable cause) {
super(message, cause);
}
public CheckedException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace)
{
public CheckedException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
super(message, cause, enableSuppression, writableStackTrace);
}
}

View File

@@ -1,15 +1,16 @@
package com.ruoyi.common.core.exception;
import java.io.Serial;
/**
* 演示模式异常
*
*
* @author ruoyi
*/
public class DemoModeException extends RuntimeException
{
public class DemoModeException extends RuntimeException {
@Serial
private static final long serialVersionUID = 1L;
public DemoModeException()
{
public DemoModeException() {
}
}

View File

@@ -1,12 +1,14 @@
package com.ruoyi.common.core.exception;
import java.io.Serial;
/**
* 全局异常
*
*
* @author ruoyi
*/
public class GlobalException extends RuntimeException
{
public class GlobalException extends RuntimeException {
@Serial
private static final long serialVersionUID = 1L;
/**
@@ -16,42 +18,34 @@ public class GlobalException extends RuntimeException
/**
* 错误明细,内部调试错误
*
* 和 {@link CommonResult#getDetailMessage()} 一致的设计
*/
private String detailMessage;
/**
* 空构造方法,避免反序列化问题
*/
public GlobalException()
{
public GlobalException() {
}
public GlobalException(String message)
{
public GlobalException(String message) {
this.message = message;
}
public String getDetailMessage()
{
public String getDetailMessage() {
return detailMessage;
}
public GlobalException setDetailMessage(String detailMessage)
{
public GlobalException setDetailMessage(String detailMessage) {
this.detailMessage = detailMessage;
return this;
}
@Override
public String getMessage()
{
public String getMessage() {
return message;
}
public GlobalException setMessage(String message)
{
public GlobalException setMessage(String message) {
this.message = message;
return this;
}

View File

@@ -1,16 +1,17 @@
package com.ruoyi.common.core.exception;
import java.io.Serial;
/**
* 内部认证异常
*
*
* @author ruoyi
*/
public class InnerAuthException extends RuntimeException
{
public class InnerAuthException extends RuntimeException {
@Serial
private static final long serialVersionUID = 1L;
public InnerAuthException(String message)
{
public InnerAuthException(String message) {
super(message);
}
}

View File

@@ -0,0 +1,34 @@
package com.ruoyi.common.core.exception;
import com.ruoyi.common.core.exception.base.BaseException;
import java.io.Serial;
/**
* @author Alan Scipio
* created on 2024/2/19
*/
public class NoSuchDataException extends BaseException {
@Serial
private static final long serialVersionUID = 1L;
public NoSuchDataException(String module, String code, Object[] args, String defaultMessage) {
super(module, code, args, defaultMessage);
}
public NoSuchDataException(String module, String code, Object[] args) {
super(module, code, args);
}
public NoSuchDataException(String module, String defaultMessage) {
super(module, defaultMessage);
}
public NoSuchDataException(String code, Object[] args) {
super(code, args);
}
public NoSuchDataException(String defaultMessage) {
super(defaultMessage);
}
}

View File

@@ -1,15 +1,16 @@
package com.ruoyi.common.core.exception;
import java.io.Serial;
/**
* 权限异常
*
*
* @author ruoyi
*/
public class PreAuthorizeException extends RuntimeException
{
public class PreAuthorizeException extends RuntimeException {
@Serial
private static final long serialVersionUID = 1L;
public PreAuthorizeException()
{
public PreAuthorizeException() {
}
}

View File

@@ -1,12 +1,14 @@
package com.ruoyi.common.core.exception;
import java.io.Serial;
/**
* 业务异常
*
*
* @author ruoyi
*/
public final class ServiceException extends RuntimeException
{
public final class ServiceException extends RuntimeException {
@Serial
private static final long serialVersionUID = 1L;
/**
@@ -21,53 +23,43 @@ public final class ServiceException extends RuntimeException
/**
* 错误明细,内部调试错误
*
* 和 {@link CommonResult#getDetailMessage()} 一致的设计
*/
private String detailMessage;
/**
* 空构造方法,避免反序列化问题
*/
public ServiceException()
{
public ServiceException() {
}
public ServiceException(String message)
{
public ServiceException(String message) {
this.message = message;
}
public ServiceException(String message, Integer code)
{
public ServiceException(String message, Integer code) {
this.message = message;
this.code = code;
}
public String getDetailMessage()
{
public String getDetailMessage() {
return detailMessage;
}
@Override
public String getMessage()
{
public String getMessage() {
return message;
}
public Integer getCode()
{
public Integer getCode() {
return code;
}
public ServiceException setMessage(String message)
{
public ServiceException setMessage(String message) {
this.message = message;
return this;
}
public ServiceException setDetailMessage(String detailMessage)
{
public ServiceException setDetailMessage(String detailMessage) {
this.detailMessage = detailMessage;
return this;
}

View File

@@ -1,26 +1,25 @@
package com.ruoyi.common.core.exception;
import java.io.Serial;
/**
* 工具类异常
*
*
* @author ruoyi
*/
public class UtilException extends RuntimeException
{
public class UtilException extends RuntimeException {
@Serial
private static final long serialVersionUID = 8247610319171014183L;
public UtilException(Throwable e)
{
public UtilException(Throwable e) {
super(e.getMessage(), e);
}
public UtilException(String message)
{
public UtilException(String message) {
super(message);
}
public UtilException(String message, Throwable throwable)
{
public UtilException(String message, Throwable throwable) {
super(message, throwable);
}
}

View File

@@ -14,22 +14,22 @@ public class BaseException extends RuntimeException {
/**
* 所属模块
*/
private final String module;
protected final String module;
/**
* 错误码
*/
private final String code;
protected final String code;
/**
* 错误码对应的参数
*/
private final Object[] args;
protected final Object[] args;
/**
* 错误消息
*/
private final String defaultMessage;
protected final String defaultMessage;
public BaseException(String module, String code, Object[] args, String defaultMessage) {
this.module = module;

View File

@@ -1,34 +1,37 @@
package com.ruoyi.common.core.exception.job;
import java.io.Serial;
/**
* 计划策略异常
*
*
* @author ruoyi
*/
public class TaskException extends Exception
{
public class TaskException extends Exception {
@Serial
private static final long serialVersionUID = 1L;
private Code code;
private final Code code;
public TaskException(String msg, Code code)
{
public TaskException(String msg, Code code) {
this(msg, code, null);
}
public TaskException(String msg, Code code, Exception nestedEx)
{
public TaskException(String msg, Code code, Exception nestedEx) {
super(msg, nestedEx);
this.code = code;
}
public Code getCode()
{
public Code getCode() {
return code;
}
public enum Code
{
TASK_EXISTS, NO_TASK_EXISTS, TASK_ALREADY_STARTED, UNKNOWN, CONFIG_ERROR, TASK_NODE_NOT_AVAILABLE
public enum Code {
TASK_EXISTS,
NO_TASK_EXISTS,
TASK_ALREADY_STARTED,
UNKNOWN,
CONFIG_ERROR,
TASK_NODE_NOT_AVAILABLE
}
}

View File

@@ -23,7 +23,7 @@ public class SnowFlakeIdGenerator {
*/
private static SequenceBuilder defaultBuilder() {
return SequenceBuilder.builder()
.setTwepoch(1657864986440L) //起始时间戳
.setTwepoch(1657864986451L) //起始时间戳
.setTimestampBits(40L) //时间戳的bit位数
.setDatacenterIdBits(1L) //数据中心的bit位数
.setWorkerIdBits(2L) //机器id的bit位数