add
This commit is contained in:
30
qiaoba-common/qiaoba-common-base/pom.xml
Normal file
30
qiaoba-common/qiaoba-common-base/pom.xml
Normal file
@ -0,0 +1,30 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<parent>
|
||||
<artifactId>qiaoba-common</artifactId>
|
||||
<groupId>com.qiaoba</groupId>
|
||||
<version>1.0</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>qiaoba-common-base</artifactId>
|
||||
|
||||
<description>通用-基础模块</description>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>cn.hutool</groupId>
|
||||
<artifactId>hutool-all</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-validation</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-aop</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
@ -0,0 +1,33 @@
|
||||
package com.qiaoba.common.base.code;
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
/**
|
||||
* 系统配置错误code
|
||||
*
|
||||
* @author ailanyin
|
||||
* @version 1.0
|
||||
* @since 2023/6/12 13:34
|
||||
*/
|
||||
@Getter
|
||||
public enum ConfigErrorCode {
|
||||
|
||||
/**
|
||||
* 系统内置-禁止删除
|
||||
*/
|
||||
SYS_NOT_ALLOW_DELETE(5020, "系统内置不允许删除!"),
|
||||
|
||||
/**
|
||||
* Key已存在
|
||||
*/
|
||||
KEY_EXIST(5021, "参数键名已存在, 操作失败!");
|
||||
|
||||
private final Integer code;
|
||||
private final String msg;
|
||||
|
||||
ConfigErrorCode(Integer code, String msg) {
|
||||
this.code = code;
|
||||
this.msg = msg;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,58 @@
|
||||
package com.qiaoba.common.base.code;
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
/**
|
||||
* 数据源错误信息
|
||||
*
|
||||
* @author ailanyin
|
||||
* @version 1.0
|
||||
* @since 2023/6/27 9:22
|
||||
*/
|
||||
@Getter
|
||||
public enum DatasourceErrorCode {
|
||||
|
||||
/**
|
||||
* 未找到
|
||||
*/
|
||||
NOT_FIND(50401, "未找到数据源信息 (可能未设置使用)"),
|
||||
|
||||
/**
|
||||
* 连接错误
|
||||
*/
|
||||
CONNECT_ERROR(50402, "数据源无法连接"),
|
||||
|
||||
/**
|
||||
* 切换模式错误
|
||||
*/
|
||||
SWITCH_SCHEMA_ERROR(50403, "切换模式错误"),
|
||||
|
||||
/**
|
||||
* 创建表错误
|
||||
*/
|
||||
CREATE_TABLE_ERROR(50404, "创建表错误"),
|
||||
|
||||
/**
|
||||
* 创建模式/库错误
|
||||
*/
|
||||
CREATE_SCHEMA_ERROR(50405, "创建模式/库错误"),
|
||||
|
||||
/**
|
||||
* 初始化数据错误
|
||||
*/
|
||||
INIT_DATA_ERROR(50406, "初始化数据错误"),
|
||||
|
||||
/**
|
||||
* schema 不存在
|
||||
*/
|
||||
SCHEMA_NOT_EXIST_ERROR(50407, "SCHEMA: {} 不存在");
|
||||
|
||||
private final Integer code;
|
||||
private final String msg;
|
||||
|
||||
DatasourceErrorCode(Integer code, String msg) {
|
||||
this.code = code;
|
||||
this.msg = msg;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,33 @@
|
||||
package com.qiaoba.common.base.code;
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
/**
|
||||
* 字典错误code
|
||||
*
|
||||
* @author ailanyin
|
||||
* @version 1.0
|
||||
* @since 2023/6/12 13:34
|
||||
*/
|
||||
@Getter
|
||||
public enum DictErrorCode {
|
||||
|
||||
/**
|
||||
* 类型已存在
|
||||
*/
|
||||
TYPE_EXIST(5030, "类型[{}]已存在, 不允许新增或修改!"),
|
||||
|
||||
/**
|
||||
* 存在数据
|
||||
*/
|
||||
HAS_DATA(5031, "字典[{}]已绑定数据, 请解绑后删除!");
|
||||
|
||||
private final Integer code;
|
||||
private final String msg;
|
||||
|
||||
DictErrorCode(Integer code, String msg) {
|
||||
this.code = code;
|
||||
this.msg = msg;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,52 @@
|
||||
package com.qiaoba.common.base.code;
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
/**
|
||||
* 租户错误code
|
||||
*
|
||||
* @author ailanyin
|
||||
* @version 1.0
|
||||
* @since 2023/6/12 13:33
|
||||
*/
|
||||
@Getter
|
||||
public enum TenantErrorCode {
|
||||
|
||||
/**
|
||||
* 未找到
|
||||
*/
|
||||
NOT_FIND(5010, "未找到租户信息"),
|
||||
|
||||
/**
|
||||
* 禁用
|
||||
*/
|
||||
DISABLE(5011, "租户被禁用"),
|
||||
|
||||
/**
|
||||
* 过期
|
||||
*/
|
||||
EXPIRE(5012, "租户已过期"),
|
||||
|
||||
/**
|
||||
* 租户模式不存在
|
||||
*/
|
||||
MODE_NOT_FIND(50103, "未找到租户模式"),
|
||||
|
||||
/**
|
||||
* 已初始化过
|
||||
*/
|
||||
INITIALIZED(50104, "已初始化过"),
|
||||
|
||||
/**
|
||||
* 租户名称已存在
|
||||
*/
|
||||
TENANT_NAME_EXIST(50105, "公司名称已存在");
|
||||
|
||||
private final Integer code;
|
||||
private final String msg;
|
||||
|
||||
TenantErrorCode(Integer code, String msg) {
|
||||
this.code = code;
|
||||
this.msg = msg;
|
||||
}
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
package com.qiaoba.common.base.code;
|
||||
|
||||
/**
|
||||
* 用户错误code
|
||||
*
|
||||
* @author ailanyin
|
||||
* @version 1.0
|
||||
* @since 2023/6/12 13:34
|
||||
*/
|
||||
public enum UserErrorCode {
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,82 @@
|
||||
package com.qiaoba.common.base.constant;
|
||||
|
||||
/**
|
||||
* BaseConstant
|
||||
*
|
||||
* @author ailanyin
|
||||
* @version 1.0
|
||||
* @since 2023-04-23 15:37:43
|
||||
*/
|
||||
public class BaseConstant {
|
||||
|
||||
/**
|
||||
* UTF-8 字符集
|
||||
*/
|
||||
public static final String UTF8 = "UTF-8";
|
||||
|
||||
/**
|
||||
* 默认的字符拼接/切割符号: ','(英文逗号)
|
||||
*/
|
||||
public static final String DEFAULT_SPLIT_STR = ",";
|
||||
|
||||
/**
|
||||
* 竖线拼接符号: '|'(英文竖线)
|
||||
*/
|
||||
public static final String LINE_JOIN_STR = "|";
|
||||
|
||||
/**
|
||||
* 冒号拼接符号: ':'(英文冒号)
|
||||
*/
|
||||
public static final String COLON_JOIN_STR = ":";
|
||||
|
||||
/**
|
||||
* 中划线拼接符号: '-'
|
||||
*/
|
||||
public static final String HYPHEN_JOIN_STR = "-";
|
||||
|
||||
/**
|
||||
* 树的key的命名
|
||||
*/
|
||||
public static final String TREE_KEY_NAME = "label";
|
||||
|
||||
/**
|
||||
* 默认的父ID = 0
|
||||
*/
|
||||
public static final String DEFAULT_PARENT_ID_VALUE = "0";
|
||||
|
||||
/**
|
||||
* http请求
|
||||
*/
|
||||
public static final String HTTP = "http://";
|
||||
|
||||
/**
|
||||
* https请求
|
||||
*/
|
||||
public static final String HTTPS = "https://";
|
||||
|
||||
/**
|
||||
* 资源映射路径 前缀
|
||||
*/
|
||||
public static final String RESOURCE_PREFIX = "/resource";
|
||||
|
||||
/**
|
||||
* 资源映射路径 正则
|
||||
*/
|
||||
public static final String RESOURCE_PATTERN = RESOURCE_PREFIX + "/**";
|
||||
|
||||
/**
|
||||
* 是
|
||||
*/
|
||||
public static final String YES = "Y";
|
||||
|
||||
/**
|
||||
* 否
|
||||
*/
|
||||
public static final String NO = "N";
|
||||
|
||||
/**
|
||||
* 处理失败 个数 0
|
||||
*/
|
||||
public static final Integer HANDLE_ERROR = 0;
|
||||
|
||||
}
|
@ -0,0 +1,76 @@
|
||||
package com.qiaoba.common.base.constant;
|
||||
|
||||
/**
|
||||
* 配置常量
|
||||
*
|
||||
* @author ailanyin
|
||||
* @version 1.0
|
||||
* @since 2023-04-23 15:37:43
|
||||
*/
|
||||
public class ConfigConstant {
|
||||
|
||||
/**
|
||||
* 参数管理 cache key 前缀
|
||||
*/
|
||||
public static final String SYS_CONFIG_KEY_PREFIX = "sys_config:";
|
||||
|
||||
/**
|
||||
* 参数配置-Token有效期
|
||||
*/
|
||||
public static final String TOKEN_EXPIRE_TIME_KEY = SYS_CONFIG_KEY_PREFIX + "sys.token.expireTime";
|
||||
|
||||
/**
|
||||
* 参数配置-允许同时在线
|
||||
*/
|
||||
public static final String ALLOW_BOTH_ONLINE_KEY = SYS_CONFIG_KEY_PREFIX + "sys.account.allowBothOnline";
|
||||
|
||||
/**
|
||||
* 参数配置-系统注册开关
|
||||
*/
|
||||
public static final String REGISTER_ON_OFF_KEY = SYS_CONFIG_KEY_PREFIX + "sys.account.registerUser";
|
||||
|
||||
/**
|
||||
* 参数配置-验证码开关
|
||||
*/
|
||||
public static final String CAPTCHA_ON_OFF_KEY = SYS_CONFIG_KEY_PREFIX + "sys.account.captchaOnOff";
|
||||
|
||||
/**
|
||||
* 参数配置-黑名单开关
|
||||
*/
|
||||
public static final String BLACKLIST_ON_OFF_KEY = SYS_CONFIG_KEY_PREFIX + "sys.account.blacklistOnOff";
|
||||
|
||||
/**
|
||||
* 参数配置-黑名单过期时间(拉黑时间), 单位:分钟
|
||||
*/
|
||||
public static final String BLACKLIST_EXPIRE_TIME_KEY = SYS_CONFIG_KEY_PREFIX + "sys.account.blacklistExpireTime";
|
||||
|
||||
/**
|
||||
* 参数配置-登陆最大错误次数
|
||||
*/
|
||||
public static final String LOGIN_ERROR_MAX_COUNT_KEY = SYS_CONFIG_KEY_PREFIX + "sys.account.loginErrorMaxCount";
|
||||
|
||||
/**
|
||||
* 参数配置-登录日志开关
|
||||
*/
|
||||
public static final String LOGIN_LOG_ON_OFF_KEY = SYS_CONFIG_KEY_PREFIX + "sys.login.loginLogOnOff";
|
||||
|
||||
/**
|
||||
* 开
|
||||
*/
|
||||
public static final String COMMON_ON_VALUE = "true";
|
||||
|
||||
/**
|
||||
* 关
|
||||
*/
|
||||
public static final String COMMON_OFF_VALUE = "false";
|
||||
|
||||
/**
|
||||
* 默认最大允许错误次数
|
||||
*/
|
||||
public static final Integer DEFAULT_LOGIN_ERROR_MAX_COUNT = 5;
|
||||
|
||||
/**
|
||||
* 默认最大黑名单过期时间(单位分钟)
|
||||
*/
|
||||
public static final Long DEFAULT_MAX_BLACKLIST_EXPIRE_TIME = 30L;
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
package com.qiaoba.common.base.constant;
|
||||
|
||||
/**
|
||||
* 字典常量
|
||||
*
|
||||
* @author ailanyin
|
||||
* @version 1.0
|
||||
* @since 2023-04-23 15:37:43
|
||||
*/
|
||||
public class DictConstant {
|
||||
|
||||
/**
|
||||
* 字典 redis key
|
||||
*/
|
||||
public static final String SYS_DICT_KEY = "sys_dict:";
|
||||
}
|
@ -0,0 +1,56 @@
|
||||
package com.qiaoba.common.base.constant;
|
||||
|
||||
/**
|
||||
* 菜单常量
|
||||
*
|
||||
* @author ailanyin
|
||||
* @version 1.0
|
||||
* @since 2023-04-23 15:37:43
|
||||
*/
|
||||
public class MenuConstant {
|
||||
|
||||
/**
|
||||
* 是否菜单外链(是)
|
||||
*/
|
||||
public static final String YES_FRAME = "1";
|
||||
|
||||
/**
|
||||
* 是否菜单外链(否)
|
||||
*/
|
||||
public static final String NO_FRAME = "0";
|
||||
|
||||
/**
|
||||
* 菜单类型(目录)
|
||||
*/
|
||||
public static final String TYPE_DIR = "M";
|
||||
|
||||
/**
|
||||
* 菜单类型(菜单)
|
||||
*/
|
||||
public static final String TYPE_MENU = "C";
|
||||
|
||||
/**
|
||||
* 菜单类型(按钮)
|
||||
*/
|
||||
public static final String TYPE_BUTTON = "F";
|
||||
|
||||
/**
|
||||
* Layout组件标识
|
||||
*/
|
||||
public final static String LAYOUT = "Layout";
|
||||
|
||||
/**
|
||||
* ParentView组件标识
|
||||
*/
|
||||
public final static String PARENT_VIEW = "ParentView";
|
||||
|
||||
/**
|
||||
* InnerLink组件标识
|
||||
*/
|
||||
public final static String INNER_LINK = "InnerLink";
|
||||
|
||||
/**
|
||||
* 不重定向
|
||||
*/
|
||||
public final static String NO_REDIRECT = "noRedirect";
|
||||
}
|
@ -0,0 +1,36 @@
|
||||
package com.qiaoba.common.base.constant;
|
||||
|
||||
/**
|
||||
* 租户常量
|
||||
*
|
||||
* @author ailanyin
|
||||
* @version 1.0
|
||||
* @since 2023-04-23 15:37:43
|
||||
*/
|
||||
public class TenantConstant {
|
||||
|
||||
/**
|
||||
* 租户 key 前缀
|
||||
*/
|
||||
public static final String TENANT_KEY_PREFIX = "tenant_";
|
||||
|
||||
/**
|
||||
* 租户信息 Redis Key
|
||||
*/
|
||||
public static final String TENANT_INFO_KEY_PREFIX = "tenant_info:";
|
||||
|
||||
/**
|
||||
* header 租户 key
|
||||
*/
|
||||
public static final String HEADER_KEY_TENANT = "tenant";
|
||||
|
||||
/**
|
||||
* 系统默认租户ID
|
||||
*/
|
||||
public static final String DEFAULT_TENANT_ID = "1";
|
||||
|
||||
/**
|
||||
* 登陆入口-获取正常的租户-Uri
|
||||
*/
|
||||
public static final String LOGIN_TENANT_LIST_URI = "/tenant/normal-list";
|
||||
}
|
@ -0,0 +1,113 @@
|
||||
package com.qiaoba.common.base.context;
|
||||
|
||||
/**
|
||||
* 全局上下文对象
|
||||
*
|
||||
* @author ailanyin
|
||||
* @version 1.0
|
||||
* @since 2023/5/22 17:24
|
||||
*/
|
||||
public class BaseContext {
|
||||
|
||||
/**
|
||||
* 数据库类型
|
||||
*/
|
||||
private static final ThreadLocal<String> DATABASE_TYPE_HOLDER = new ThreadLocal<>();
|
||||
|
||||
/**
|
||||
* SCHEMA
|
||||
*/
|
||||
private static final ThreadLocal<Boolean> SCHEMA_HOLDER = new ThreadLocal<>();
|
||||
|
||||
/**
|
||||
* 租户ID
|
||||
*/
|
||||
private static final ThreadLocal<String> TENANT_ID_HOLDER = new ThreadLocal<>();
|
||||
|
||||
/**
|
||||
* 数据源
|
||||
*/
|
||||
private static final ThreadLocal<String> DATASOURCE_HOLDER = new ThreadLocal<>();
|
||||
|
||||
/**
|
||||
* 获取上下文中数据库类型
|
||||
*/
|
||||
public static String getDatabaseType() {
|
||||
return DATABASE_TYPE_HOLDER.get();
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置上下文中数据库类型
|
||||
*/
|
||||
public static void setDatabaseType(String type) {
|
||||
DATABASE_TYPE_HOLDER.set(type);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取上下文中租户ID
|
||||
*/
|
||||
public static String getTenantId() {
|
||||
return TENANT_ID_HOLDER.get();
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置上下文中租户ID
|
||||
*/
|
||||
public static void setTenantId(String tenantId) {
|
||||
TENANT_ID_HOLDER.set(tenantId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 清除上下文中租户ID
|
||||
*/
|
||||
public static void clearTenantId() {
|
||||
TENANT_ID_HOLDER.remove();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取上下文中的数据源
|
||||
*/
|
||||
public static String getDataSource() {
|
||||
return DATASOURCE_HOLDER.get();
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置上下文中的数据源
|
||||
*/
|
||||
public static void setDataSource(String dataSource) {
|
||||
DATASOURCE_HOLDER.set(dataSource);
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否是 Schema模式
|
||||
*
|
||||
* @return Boolean
|
||||
*/
|
||||
public static Boolean isSchemaMode() {
|
||||
return SCHEMA_HOLDER.get();
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置是否是 Schema模式
|
||||
*
|
||||
* @param isSchema 是/否
|
||||
*/
|
||||
public static void setSchema(boolean isSchema) {
|
||||
SCHEMA_HOLDER.set(isSchema);
|
||||
}
|
||||
|
||||
/**
|
||||
* 清除所有的ThreadLocal
|
||||
*/
|
||||
public static void clearAllHolder() {
|
||||
// 清除上下文中数据源
|
||||
DATASOURCE_HOLDER.remove();
|
||||
// 清除上下文中租户ID
|
||||
TENANT_ID_HOLDER.remove();
|
||||
// 清除上下文中数据库类型
|
||||
DATABASE_TYPE_HOLDER.remove();
|
||||
// 清除上下文中 SCHEMA
|
||||
SCHEMA_HOLDER.remove();
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,52 @@
|
||||
package com.qiaoba.common.base.entity;
|
||||
|
||||
import com.qiaoba.common.base.validate.AddGroup;
|
||||
import com.qiaoba.common.base.validate.EditGroup;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
import javax.validation.constraints.Size;
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
|
||||
|
||||
/**
|
||||
* BaseEntity
|
||||
*
|
||||
* @author ailanyin
|
||||
* @version 1.0
|
||||
* @since 2023-04-23 15:37:43
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
public class BaseEntity implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 创建者
|
||||
*/
|
||||
private String createUser;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
private Date createTime;
|
||||
|
||||
/**
|
||||
* 更新者
|
||||
*/
|
||||
private String updateUser;
|
||||
|
||||
/**
|
||||
* 更新时间
|
||||
*/
|
||||
private Date updateTime;
|
||||
|
||||
/**
|
||||
* 备注
|
||||
*/
|
||||
@Size(max = 500, message = "备注不能超过{max}个字符", groups = {AddGroup.class, EditGroup.class})
|
||||
private String remark;
|
||||
|
||||
}
|
@ -0,0 +1,81 @@
|
||||
package com.qiaoba.common.base.entity;
|
||||
|
||||
import cn.hutool.http.HttpStatus;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 基础分页封装对象
|
||||
*
|
||||
* @author ailanyin
|
||||
* @version 1.0
|
||||
* @since 2023-04-23 15:37:43
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
@NoArgsConstructor
|
||||
public class BasePage<T> implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 总记录数
|
||||
*/
|
||||
public long total;
|
||||
|
||||
/**
|
||||
* 列表数据
|
||||
*/
|
||||
public List<T> rows;
|
||||
|
||||
/**
|
||||
* 消息状态码
|
||||
*/
|
||||
public int code;
|
||||
|
||||
/**
|
||||
* 消息内容
|
||||
*/
|
||||
public String msg;
|
||||
|
||||
/**
|
||||
* 分页
|
||||
*
|
||||
* @param list 列表数据
|
||||
* @param total 总记录数
|
||||
*/
|
||||
public BasePage(List<T> list, long total) {
|
||||
this.rows = list;
|
||||
this.total = total;
|
||||
}
|
||||
|
||||
|
||||
public static <T> BasePage<T> build(List<T> list) {
|
||||
BasePage<T> basePage = new BasePage<>();
|
||||
basePage.setCode(HttpStatus.HTTP_OK);
|
||||
basePage.setMsg("查询成功");
|
||||
basePage.setRows(list);
|
||||
basePage.setTotal(list.size());
|
||||
return basePage;
|
||||
}
|
||||
|
||||
public static <T> BasePage<T> build(Long total, List<T> list) {
|
||||
BasePage<T> basePage = new BasePage<>();
|
||||
basePage.setCode(HttpStatus.HTTP_OK);
|
||||
basePage.setMsg("查询成功");
|
||||
basePage.setRows(list);
|
||||
basePage.setTotal(total);
|
||||
return basePage;
|
||||
}
|
||||
|
||||
public static <T> BasePage<T> build() {
|
||||
BasePage<T> basePage = new BasePage<>();
|
||||
basePage.setCode(HttpStatus.HTTP_OK);
|
||||
basePage.setMsg("查询成功");
|
||||
return basePage;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,23 @@
|
||||
package com.qiaoba.common.base.entity;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* 数据权限
|
||||
*
|
||||
* @author ailanyin
|
||||
* @version 1.0
|
||||
* @since 2023/5/23 9:36
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
public class DataScopeParam implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private String dataScope;
|
||||
|
||||
}
|
@ -0,0 +1,31 @@
|
||||
package com.qiaoba.common.base.enums;
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
/**
|
||||
* BaseEnum
|
||||
*
|
||||
* @author ailanyin
|
||||
* @version 1.0
|
||||
* @since 2023-04-23 15:34:59
|
||||
*/
|
||||
@Getter
|
||||
public enum BaseEnum {
|
||||
|
||||
// 是
|
||||
YES("1", "是"),
|
||||
// 否
|
||||
NO("0", "否"),
|
||||
// 正常
|
||||
NORMAL("1", "正常"),
|
||||
// 不正常
|
||||
ABNORMAL("0", "不正常");
|
||||
|
||||
private final String code;
|
||||
private final String info;
|
||||
|
||||
BaseEnum(String code, String info) {
|
||||
this.code = code;
|
||||
this.info = info;
|
||||
}
|
||||
}
|
@ -0,0 +1,88 @@
|
||||
package com.qiaoba.common.base.enums;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.qiaoba.common.base.exception.ServiceException;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
/**
|
||||
* 数据库类型
|
||||
*
|
||||
* @author ailanyin
|
||||
* @version 1.0
|
||||
* @since 2023/5/22 16:41
|
||||
*/
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public enum DataBaseEnum {
|
||||
|
||||
// ip/port/database
|
||||
|
||||
/**
|
||||
* MySQL
|
||||
*/
|
||||
MY_SQL("MySQL",
|
||||
"jdbc:mysql://{}:{}/{}?databaseTerm=SCHEMA&useUnicode=true&characterEncoding=utf-8&serverTimezone=Asia/Shanghai&nullCatalogMeansCurrent=true&allowMultiQueries=true",
|
||||
"com.mysql.cj.jdbc.Driver",
|
||||
"SELECT 1"),
|
||||
|
||||
/**
|
||||
* PostgreSQL
|
||||
*/
|
||||
POSTGRE_SQL("PostgreSQL",
|
||||
"jdbc:postgresql://{}:{}/{}?currentSchema={}&useUnicode=true&characterEncoding=utf-8&serverTimezone=Asia/Shanghai&nullCatalogMeansCurrent=true&allowMultiQueries=true",
|
||||
"org.postgresql.Driver",
|
||||
"SELECT 1"),
|
||||
|
||||
/**
|
||||
* SQL Server
|
||||
*/
|
||||
SQL_SERVER("Microsoft SQL Server",
|
||||
"jdbc:sqlserver://localhost:1433;DatabaseName={};SelectMethod=cursor;encrypt=false;rewriteBatchedStatements=true",
|
||||
"com.microsoft.sqlserver.jdbc.SQLServerDriver",
|
||||
"SELECT 1");
|
||||
|
||||
private final String type;
|
||||
private final String url;
|
||||
private final String driver;
|
||||
private final String checkSql;
|
||||
|
||||
|
||||
public static String getDriver(String type) {
|
||||
for (DataBaseEnum dataBaseEnum : values()) {
|
||||
if (dataBaseEnum.getType().equals(type)) {
|
||||
return dataBaseEnum.driver;
|
||||
}
|
||||
}
|
||||
throw new ServiceException(StrUtil.format("未找到数据库驱动, Type: {}", type));
|
||||
}
|
||||
|
||||
public static String getUrl(String type, String ip, String port, String dbName, String schema) {
|
||||
for (DataBaseEnum dataBaseEnum : values()) {
|
||||
if (dataBaseEnum.getType().equals(type)) {
|
||||
return StrUtil.format(dataBaseEnum.url, ip, port, dbName, schema);
|
||||
}
|
||||
}
|
||||
throw new ServiceException(StrUtil.format("未找到数据库Url, Type: {}", type));
|
||||
}
|
||||
|
||||
public static String getCheckSql(String type) {
|
||||
for (DataBaseEnum dataBaseEnum : values()) {
|
||||
if (dataBaseEnum.getType().equals(type)) {
|
||||
return dataBaseEnum.checkSql;
|
||||
}
|
||||
}
|
||||
throw new ServiceException(StrUtil.format("未找到数据库checkSql, Type: {}", type));
|
||||
}
|
||||
|
||||
public static String getIp(String url, String driver) {
|
||||
for (DataBaseEnum dataBaseEnum : values()) {
|
||||
if (dataBaseEnum.getDriver().equals(driver)) {
|
||||
url = url.replaceFirst(url.substring(0, dataBaseEnum.url.indexOf(StrUtil.EMPTY_JSON)), "");
|
||||
return url.split(StrUtil.COLON)[0];
|
||||
}
|
||||
}
|
||||
throw new ServiceException(StrUtil.format("未找到数据库IP, Driver: {}", driver));
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,47 @@
|
||||
package com.qiaoba.common.base.exception;
|
||||
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
/**
|
||||
* 自定义 业务异常
|
||||
*
|
||||
* @author ailanyin
|
||||
* @version 1.0
|
||||
* @since 2021-08-31
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
public class ServiceException extends RuntimeException {
|
||||
|
||||
/**
|
||||
* 错误码
|
||||
*/
|
||||
private Integer errorCode;
|
||||
|
||||
/**
|
||||
* 错误信息
|
||||
*/
|
||||
private String message;
|
||||
|
||||
public ServiceException(String message) {
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
public ServiceException(Integer code, String message) {
|
||||
this.message = message;
|
||||
this.errorCode = code;
|
||||
}
|
||||
|
||||
/**
|
||||
* 控制台不打印自定义错误的堆栈信息, 提高性能
|
||||
*
|
||||
* @return this
|
||||
*/
|
||||
@Override
|
||||
public Throwable fillInStackTrace() {
|
||||
return this;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
package com.qiaoba.common.base.order;
|
||||
|
||||
/**
|
||||
* 过滤器执行顺序
|
||||
*
|
||||
* @author ailanyin
|
||||
* @version 1.0
|
||||
* @since 2023/7/6 9:22
|
||||
*/
|
||||
public interface FilterOrder {
|
||||
|
||||
/**
|
||||
* 动态数据源过滤器-执行顺序(最高)
|
||||
*/
|
||||
int DYNAMIC_DATASOURCE_FILTER_ORDER = -10000;
|
||||
|
||||
/**
|
||||
* 在线用户过滤器
|
||||
*/
|
||||
int ONLINE_USER_FILTER_ORDER = -9999;
|
||||
|
||||
}
|
@ -0,0 +1,167 @@
|
||||
package com.qiaoba.common.base.result;
|
||||
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
/**
|
||||
* 通用返回
|
||||
*
|
||||
* @author ailanyin
|
||||
* @version 1.0
|
||||
* @since 2021-08-31
|
||||
*/
|
||||
public class AjaxResult extends HashMap<String, Object> {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 状态码
|
||||
*/
|
||||
public static final String CODE_TAG = "code";
|
||||
|
||||
/**
|
||||
* 返回内容
|
||||
*/
|
||||
public static final String MSG_TAG = "msg";
|
||||
|
||||
/**
|
||||
* 数据对象
|
||||
*/
|
||||
public static final String DATA_TAG = "data";
|
||||
|
||||
/**
|
||||
* 初始化一个新创建的 AjaxResult 对象,使其表示一个空消息。
|
||||
*/
|
||||
public AjaxResult() {
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化一个新创建的 AjaxResult 对象
|
||||
*
|
||||
* @param code 状态码
|
||||
* @param msg 返回内容
|
||||
*/
|
||||
public AjaxResult(int code, String msg) {
|
||||
super.put(CODE_TAG, code);
|
||||
super.put(MSG_TAG, msg);
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化一个新创建的 AjaxResult 对象
|
||||
*
|
||||
* @param code 状态码
|
||||
* @param msg 返回内容
|
||||
* @param data 数据对象
|
||||
*/
|
||||
public AjaxResult(int code, String msg, Object data) {
|
||||
super.put(CODE_TAG, code);
|
||||
super.put(MSG_TAG, msg);
|
||||
super.put(DATA_TAG, data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回成功消息
|
||||
*
|
||||
* @return 成功消息
|
||||
*/
|
||||
public static AjaxResult success() {
|
||||
return AjaxResult.success("操作成功");
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回成功数据
|
||||
*
|
||||
* @return 成功消息
|
||||
*/
|
||||
public static AjaxResult success(Object data) {
|
||||
return AjaxResult.success("操作成功", data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回成功消息
|
||||
*
|
||||
* @param msg 返回内容
|
||||
* @return 成功消息
|
||||
*/
|
||||
public static AjaxResult success(String msg) {
|
||||
return AjaxResult.success(msg, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回成功消息
|
||||
*
|
||||
* @param msg 返回内容
|
||||
* @param data 数据对象
|
||||
* @return 成功消息
|
||||
*/
|
||||
public static AjaxResult success(String msg, Object data) {
|
||||
return new AjaxResult(200, msg, data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回错误消息
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static AjaxResult error() {
|
||||
return AjaxResult.error("操作失败");
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回错误消息
|
||||
*
|
||||
* @param msg 返回内容
|
||||
* @return 警告消息
|
||||
*/
|
||||
public static AjaxResult error(String msg) {
|
||||
return AjaxResult.error(msg, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回错误消息
|
||||
*
|
||||
* @param msg 返回内容
|
||||
* @param data 数据对象
|
||||
* @return 警告消息
|
||||
*/
|
||||
public static AjaxResult error(String msg, Object data) {
|
||||
return new AjaxResult(500, msg, data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回错误消息
|
||||
*
|
||||
* @param code 状态码
|
||||
* @param msg 返回内容
|
||||
* @return 警告消息
|
||||
*/
|
||||
public static AjaxResult error(int code, String msg) {
|
||||
return new AjaxResult(code, msg, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* 方便链式调用
|
||||
*
|
||||
* @param key 键
|
||||
* @param value 值
|
||||
* @return 数据对象
|
||||
*/
|
||||
@Override
|
||||
public AjaxResult put(String key, Object value) {
|
||||
super.put(key, value);
|
||||
return this;
|
||||
}
|
||||
|
||||
public static AjaxResult toAjax(int result) {
|
||||
return result > 0 ? AjaxResult.success() : AjaxResult.error();
|
||||
}
|
||||
|
||||
public static AjaxResult rateLimit() {
|
||||
return new AjaxResult(300, "您访问速度过快,系统繁忙!");
|
||||
}
|
||||
|
||||
public static AjaxResult noPermissionResult(String uri) {
|
||||
return new AjaxResult(401, "无 " + uri + " 路径访问权限");
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,33 @@
|
||||
package com.qiaoba.common.base.util;
|
||||
|
||||
import cn.hutool.core.util.ClassUtil;
|
||||
|
||||
import java.lang.annotation.Annotation;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
/**
|
||||
* 注解Util
|
||||
*
|
||||
* @author ailanyin
|
||||
* @version 1.0
|
||||
* @since 2023/6/21 9:53
|
||||
*/
|
||||
public class AnnotationUtil extends cn.hutool.core.annotation.AnnotationUtil {
|
||||
|
||||
public static boolean hasAnnotation(String referenceMethod, Class<? extends Annotation> annotation) {
|
||||
// com.qiaoba.common.base.util.AnnotationUtil.hasAnnotation
|
||||
StringBuilder sb = new StringBuilder(referenceMethod);
|
||||
int index = sb.lastIndexOf(".");
|
||||
// com.qiaoba.common.base.util.AnnotationUtil
|
||||
String clazzName = sb.substring(0, index);
|
||||
// hasAnnotation
|
||||
String methodName = sb.substring(index + 1, sb.length());
|
||||
Class<?> clazz = ClassUtil.loadClass(clazzName);
|
||||
for (Method method : clazz.getDeclaredMethods()) {
|
||||
if (methodName.equals(method.getName())) {
|
||||
return hasAnnotation(method, annotation);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
@ -0,0 +1,26 @@
|
||||
package com.qiaoba.common.base.util;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* ArrayUtil
|
||||
*
|
||||
* @author ailanyin
|
||||
* @version 1.0
|
||||
* @since 2023/5/22 16:41
|
||||
*/
|
||||
public class ArrayUtil extends cn.hutool.core.util.ArrayUtil {
|
||||
|
||||
public static boolean containsValueIgnoreCase(CharSequence[] array, CharSequence value) {
|
||||
if (Objects.nonNull(array)) {
|
||||
for (CharSequence charSequence : array) {
|
||||
if (StrUtil.containsIgnoreCase(value, charSequence)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
@ -0,0 +1,39 @@
|
||||
package com.qiaoba.common.base.util;
|
||||
|
||||
import cn.hutool.core.convert.Convert;
|
||||
import com.qiaoba.common.base.context.BaseContext;
|
||||
import com.qiaoba.common.base.enums.DataBaseEnum;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
/**
|
||||
* 数据库工具类
|
||||
*
|
||||
* @author ailanyin
|
||||
* @version 1.0
|
||||
* @since 2023/5/22 16:41
|
||||
*/
|
||||
@Slf4j
|
||||
public class DatabaseUtil {
|
||||
|
||||
/**
|
||||
* 根据数据库类型,处理find_in_set函数
|
||||
*
|
||||
* @param var1 参数1
|
||||
* @param var2 参数2
|
||||
* @return 处理后的sql
|
||||
*/
|
||||
public static String handleFindInSet(Object var1, String var2) {
|
||||
String databaseType = BaseContext.getDatabaseType();
|
||||
log.debug("租户ID: [{}], 数据源类型: {}", BaseContext.getTenantId(), databaseType);
|
||||
String var = Convert.toStr(var1);
|
||||
if (DataBaseEnum.SQL_SERVER.getType().equals(databaseType)) {
|
||||
// charindex(',100,' , ',0,100,101,') <> 0
|
||||
return "charindex('," + var + ",' , ','+" + var2 + "+',') <> 0";
|
||||
} else if (DataBaseEnum.POSTGRE_SQL.getType().equals(databaseType)) {
|
||||
// (select position(',100,' in ',0,100,101,')) <> 0
|
||||
return "(select position('," + var + ",' in ','||" + var2 + "||',')) <> 0";
|
||||
}
|
||||
// find_in_set(100 , '0,100,101')
|
||||
return "find_in_set(" + var + " , " + var2 + ") <> 0";
|
||||
}
|
||||
}
|
@ -0,0 +1,44 @@
|
||||
package com.qiaoba.common.base.util;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
/**
|
||||
* 对象工具类
|
||||
*
|
||||
* @author ailanyin
|
||||
* @version 1.0
|
||||
* @since 2023/5/18 14:59
|
||||
*/
|
||||
public class ObjectUtil {
|
||||
|
||||
/**
|
||||
* 判断对象所有属性是否都为空
|
||||
*
|
||||
* @param obj obj
|
||||
* @return 结果
|
||||
*/
|
||||
public static boolean isAllFieldNull(Object obj) {
|
||||
// 得到类对象
|
||||
Class clazz = (Class) obj.getClass();
|
||||
//得到属性集合
|
||||
Field[] fs = clazz.getDeclaredFields();
|
||||
boolean flag = true;
|
||||
//遍历属性
|
||||
for (Field f : fs) {
|
||||
try {
|
||||
// 设置属性是可以访问的(私有的也可以)
|
||||
f.setAccessible(true);
|
||||
// 得到此属性的值
|
||||
Object val = f.get(obj);
|
||||
// 只要有1个属性不为空,那么就不是所有的属性值都为空
|
||||
if (val != null) {
|
||||
flag = false;
|
||||
break;
|
||||
}
|
||||
} catch (IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
return flag;
|
||||
}
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
package com.qiaoba.common.base.validate;
|
||||
|
||||
/**
|
||||
* 新增-分组校验
|
||||
*
|
||||
* @author ailanyin
|
||||
* @version 1.0
|
||||
* @since 2023-5-30 10:14:28
|
||||
*/
|
||||
public interface AddGroup {
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
package com.qiaoba.common.base.validate;
|
||||
|
||||
/**
|
||||
* 修改-分组校验
|
||||
*
|
||||
* @author ailanyin
|
||||
* @version 1.0
|
||||
* @since 2023-5-30 10:14:28
|
||||
*/
|
||||
public interface EditGroup {
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
package com.qiaoba.common.base.validate;
|
||||
|
||||
/**
|
||||
* 查询-分组校验
|
||||
*
|
||||
* @author ailanyin
|
||||
* @version 1.0
|
||||
* @since 2023-5-30 10:14:28
|
||||
*/
|
||||
public interface QueryGroup {
|
||||
}
|
Reference in New Issue
Block a user