Compare commits
14
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4376af0601 | ||
|
|
3d6e4abbaa | ||
|
|
33f983bead | ||
|
|
ce24d9a80f | ||
|
|
86c701d208 | ||
|
|
249a593fbe | ||
|
|
616fa00e9e | ||
|
|
99261624ab | ||
|
|
2026a75301 | ||
|
|
ad63d614cc | ||
|
|
459b9be347 | ||
|
|
ef314e8708 | ||
|
|
aab0b3ae32 | ||
|
|
1528fb49b9 |
@@ -0,0 +1,46 @@
|
||||
<?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">
|
||||
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<parent>
|
||||
<artifactId>aos-dependencies-external</artifactId>
|
||||
<groupId>com.aos</groupId>
|
||||
<version>${revision}</version>
|
||||
<relativePath>../aos-dependencies-external/pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
<artifactId>aos-build</artifactId>
|
||||
<packaging>pom</packaging>
|
||||
|
||||
<properties>
|
||||
<global.version>2023.1.1-SNAPSHOT</global.version>
|
||||
<!--endregion-->
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<!-- lombok 插件, 简化代码 (在 package 阶段排除) -->
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<!-- 使用 fkh-supreme 中的版本, 如果不加 version 将使用 spring-boot-dependencies 的依赖版本 -->
|
||||
<version>${lombok.version}</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<!-- idea 提供的用于编译时检查 null 的工具包 (在 package 阶段排除) -->
|
||||
<dependency>
|
||||
<groupId>org.jetbrains</groupId>
|
||||
<artifactId>annotations</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<!-- mapstruct 注解处理器 (在 package 阶段排除) -->
|
||||
<dependency>
|
||||
<groupId>org.mapstruct</groupId>
|
||||
<artifactId>mapstruct-processor</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,55 @@
|
||||
<?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>aos-build</artifactId>
|
||||
<groupId>com.aos</groupId>
|
||||
<version>${revision}</version>
|
||||
<relativePath>../aos-build/pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>aos-starter-parent</artifactId>
|
||||
<packaging>pom</packaging>
|
||||
<description>作为 starter 组件项目的父依赖</description>
|
||||
|
||||
<build>
|
||||
<resources>
|
||||
<resource>
|
||||
<directory>src/main/resources</directory>
|
||||
<includes>
|
||||
<include>**</include>
|
||||
</includes>
|
||||
<filtering>true</filtering>
|
||||
<excludes>
|
||||
<!--排除 jrebel 配置文件 -->
|
||||
<exclude>rebel.xml</exclude>
|
||||
<exclude>.rebel.xml.bak</exclude>
|
||||
</excludes>
|
||||
</resource>
|
||||
</resources>
|
||||
<testResources>
|
||||
<testResource>
|
||||
<directory>src/test/resources</directory>
|
||||
<includes>
|
||||
<include>**</include>
|
||||
</includes>
|
||||
<excludes>
|
||||
<!--排除 jrebel 配置文件-->
|
||||
<exclude>rebel.xml</exclude>
|
||||
<exclude>.rebel.xml.bak</exclude>
|
||||
</excludes>
|
||||
</testResource>
|
||||
</testResources>
|
||||
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-source-plugin</artifactId>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
</project>
|
||||
@@ -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">
|
||||
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<parent>
|
||||
<artifactId>aos-supreme</artifactId>
|
||||
<groupId>com.aos</groupId>
|
||||
<version>2023.1.1-SNAPSHOT</version>
|
||||
<relativePath>../aos-supreme/pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
<artifactId>aos-framework-build</artifactId>
|
||||
|
||||
<packaging>pom</packaging>
|
||||
<version>${revision}</version>
|
||||
|
||||
<properties>
|
||||
<revision>2023.1.1-SNAPSHOT</revision>
|
||||
</properties>
|
||||
|
||||
<modules>
|
||||
<module>aos-dependencies-external</module>
|
||||
<module>aos-build</module>
|
||||
<module>aos-starter-parent</module>
|
||||
</modules>
|
||||
|
||||
</project>
|
||||
@@ -0,0 +1,162 @@
|
||||
<?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">
|
||||
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>com.aos</groupId>
|
||||
<version>2023.1.1-SNAPSHOT</version>
|
||||
<packaging>pom</packaging>
|
||||
<artifactId>aos-supreme</artifactId>
|
||||
|
||||
<organization>
|
||||
<name>AOS科学研究院-顶层项目</name>
|
||||
</organization>
|
||||
|
||||
<properties>
|
||||
<!-- 默认跳过 test -->
|
||||
<maven.test.skip>true</maven.test.skip>
|
||||
<!-- 跳过 javadoc -->
|
||||
<maven.javadoc.skip>true</maven.javadoc.skip>
|
||||
<!-- 全局设置 jdk 版本 -->
|
||||
<java.version>1.8</java.version>
|
||||
<maven.compile.source>${java.version}</maven.compile.source>
|
||||
<maven.compile.target>${java.version}</maven.compile.target>
|
||||
<!-- 关闭 API 过时警告 -->
|
||||
<maven.compile.deprecation>off</maven.compile.deprecation>
|
||||
<project.encoding>UTF-8</project.encoding>
|
||||
<project.build.sourceEncoding>${project.encoding}</project.build.sourceEncoding>
|
||||
<!--endregion-->
|
||||
<!--region maven plugin version -->
|
||||
<maven-checkstyle-plugin.version>3.1.1</maven-checkstyle-plugin.version>
|
||||
<build-helper-maven-plugin.version>3.1.0</build-helper-maven-plugin.version>
|
||||
<maven-pmd-plugin.version>3.13.0</maven-pmd-plugin.version>
|
||||
<maven-jxr-plugin.version>3.1.1</maven-jxr-plugin.version>
|
||||
<maven-project-info-reports-plugin.version>3.0.0</maven-project-info-reports-plugin.version>
|
||||
<maven-antrun-plugin.version>1.8</maven-antrun-plugin.version>
|
||||
<maven-assembly-plugin.version>3.3.0</maven-assembly-plugin.version>
|
||||
<maven-clean-plugin.version>3.1.0</maven-clean-plugin.version>
|
||||
<maven-compiler-plugin.version>3.8.1</maven-compiler-plugin.version>
|
||||
<maven-dependency-plugin.version>3.1.2</maven-dependency-plugin.version>
|
||||
<maven-deploy-plugin.version>2.8.2</maven-deploy-plugin.version>
|
||||
<maven-enforcer-plugin.version>3.0.0-M3</maven-enforcer-plugin.version>
|
||||
<maven-failsafe-plugin.version>2.22.2</maven-failsafe-plugin.version>
|
||||
<maven-help-plugin.version>3.2.0</maven-help-plugin.version>
|
||||
<maven-install-plugin.version>2.5.2</maven-install-plugin.version>
|
||||
<maven-invoker-plugin.version>3.2.1</maven-invoker-plugin.version>
|
||||
<maven-jar-plugin.version>3.2.0</maven-jar-plugin.version>
|
||||
<maven-javadoc-plugin.version>3.2.0</maven-javadoc-plugin.version>
|
||||
<maven-resources-plugin.version>3.1.0</maven-resources-plugin.version>
|
||||
<maven-shade-plugin.version>3.2.4</maven-shade-plugin.version>
|
||||
<maven-source-plugin.version>3.2.1</maven-source-plugin.version>
|
||||
<maven-surefire-plugin.version>2.22.2</maven-surefire-plugin.version>
|
||||
<maven-war-plugin.version>3.2.3</maven-war-plugin.version>
|
||||
<flatten-maven-plugin.version>1.2.4</flatten-maven-plugin.version>
|
||||
<p3c-pmd.version>2.0.1</p3c-pmd.version>
|
||||
<doxia-site-renderer.version>1.9.2</doxia-site-renderer.version>
|
||||
<git-commit-id-plugin.version>2.2.6</git-commit-id-plugin.version>
|
||||
<jacoco-maven-plugin.version>0.8.3</jacoco-maven-plugin.version>
|
||||
<!--endregion-->
|
||||
|
||||
<!--region 自定义依赖 version-->
|
||||
<mapstruct.version>1.4.2.Final</mapstruct.version>
|
||||
<annotations.version>19.0.0</annotations.version>
|
||||
<lombok.version>1.18.22</lombok.version>
|
||||
<junit.version>5.6.0</junit.version>
|
||||
|
||||
<maven-model.version>3.6.3</maven-model.version>
|
||||
<guava.version>27.1-jre</guava.version>
|
||||
<spring-framework.version>5.2.8.RELEASE</spring-framework.version>
|
||||
<spring-boot.version>2.3.2.RELEASE</spring-boot.version>
|
||||
<commons-io.version>2.7</commons-io.version>
|
||||
<commons-lang3.version>3.12.0</commons-lang3.version>
|
||||
<slf4j.version>1.7.30</slf4j.version>
|
||||
|
||||
<commons-compress.version>1.19</commons-compress.version>
|
||||
<hutool.version>5.8.10</hutool.version>
|
||||
<!--endregion-->
|
||||
</properties>
|
||||
|
||||
<dependencyManagement>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.junit</groupId>
|
||||
<artifactId>junit-bom</artifactId>
|
||||
<version>${junit.version}</version>
|
||||
<type>pom</type>
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
<!-- lombok 插件, 简化代码 (在 package 阶段排除) -->
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<version>${lombok.version}</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<!-- idea 提供的用于编译时检查 null 的工具包 (在 package 阶段排除) -->
|
||||
<dependency>
|
||||
<groupId>org.jetbrains</groupId>
|
||||
<artifactId>annotations</artifactId>
|
||||
<version>${annotations.version}</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<!-- 处理 revision 版本问题 -->
|
||||
<plugin>
|
||||
<groupId>org.codehaus.mojo</groupId>
|
||||
<artifactId>flatten-maven-plugin</artifactId>
|
||||
<version>${flatten-maven-plugin.version}</version>
|
||||
<configuration>
|
||||
<updatePomFile>true</updatePomFile>
|
||||
<flattenMode>resolveCiFriendliesOnly</flattenMode>
|
||||
</configuration>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>flatten</id>
|
||||
<phase>process-resources</phase>
|
||||
<goals>
|
||||
<goal>flatten</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
<execution>
|
||||
<id>flatten.clean</id>
|
||||
<phase>clean</phase>
|
||||
<goals>
|
||||
<goal>clean</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>${maven-compiler-plugin.version}</version>
|
||||
<configuration>
|
||||
<source>${java.version}</source>
|
||||
<target>${java.version}</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
<distributionManagement>
|
||||
<repository>
|
||||
<id>nexus</id>
|
||||
<name>releases</name>
|
||||
<url>https://maven.wylgyx.top/repository/maven-releases/</url>
|
||||
</repository>
|
||||
<snapshotRepository>
|
||||
<id>nexus</id>
|
||||
<name>snapshots</name>
|
||||
<url>https://maven.wylgyx.top/repository/maven-snapshots/</url>
|
||||
</snapshotRepository>
|
||||
</distributionManagement>
|
||||
|
||||
</project>
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
#!/bin/bash
|
||||
|
||||
source ./path.sh
|
||||
|
||||
cd "${CURRENT_PATH}"/../aos-supreme && git checkout $1 && \
|
||||
cd "${CURRENT_PATH}"/../aos-framework-build && git checkout $1 && \
|
||||
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
#!/bin/bash
|
||||
|
||||
source ./path.sh
|
||||
|
||||
cd "${CURRENT_PATH}"/../aos-supreme && ./mvnw clean -Dmaven.test.skip=true &
|
||||
cd "${CURRENT_PATH}"/../aos-framework-build && ./mvnw clean -Dmaven.test.skip=true &
|
||||
@@ -0,0 +1,8 @@
|
||||
#!/bin/bash
|
||||
|
||||
source ./path.sh
|
||||
|
||||
cd "${CURRENT_PATH}"/.. && \
|
||||
git clone git@gitlab.server:v5-framework/fkh-supreme.git fkh-supreme && \
|
||||
git clone git@gitlab.server:v5-framework/fkh-framework-build.git fkh-framework-build
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
#!/bin/bash
|
||||
|
||||
source ./path.sh
|
||||
|
||||
cd "${CURRENT_PATH}"/../aos-supreme && ./mvnw clean compile -Dmaven.test.skip=true
|
||||
cd "${CURRENT_PATH}"/../aos-framework-build && ./mvnw clean compile -Dmaven.test.skip=true
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
#!/bin/bash
|
||||
|
||||
source ./path.sh
|
||||
|
||||
cd "${CURRENT_PATH}"/../aos-supreme && ./mvnw -T 2C clean deploy -Dmaven.test.skip=true
|
||||
cd "${CURRENT_PATH}"/../fkh-starter-processor && ./mvnw -T 2C clean deploy -Dmaven.test.skip=true
|
||||
cd "${CURRENT_PATH}"/../fkh-plugin && ./mvnw -T 2C clean deploy -Dmaven.test.skip=true
|
||||
cd "${CURRENT_PATH}"/../aos-framework-build && ./mvnw -T 2C clean deploy -Dmaven.test.skip=true
|
||||
@@ -0,0 +1,6 @@
|
||||
#!/bin/bash
|
||||
|
||||
source ./path.sh
|
||||
|
||||
cd "${CURRENT_PATH}"/../aos-supreme && ./mvnw -T 2C clean install -Dmaven.test.skip=true
|
||||
cd "${CURRENT_PATH}"/../aos-framework-build && ./mvnw -T 2C clean install -Dmaven.test.skip=true
|
||||
@@ -0,0 +1,15 @@
|
||||
#!/bin/bash
|
||||
|
||||
CURRENT_PATH=$(pwd)
|
||||
dirname $0 | grep "^/" >/dev/null
|
||||
if [[ $? -eq 0 ]]; then
|
||||
CURRENT_PATH=$(dirname $0)
|
||||
else
|
||||
dirname $0 | grep "^\." >/dev/null
|
||||
retval=$?
|
||||
if [[ ${retval} -eq 0 ]]; then
|
||||
CURRENT_PATH=$(dirname $0 | sed "s#^.#$CURRENT_PATH#")
|
||||
else
|
||||
CURRENT_PATH=$(dirname $0 | sed "s#^#$CURRENT_PATH/#")
|
||||
fi
|
||||
fi
|
||||
@@ -0,0 +1,9 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
source ./path.sh
|
||||
|
||||
ORIGIN="$1"
|
||||
BRANCH="$2"
|
||||
|
||||
cd "${CURRENT_PATH}"/../aos-supreme && git -c credential.helper= -c core.quotepath=false -c log.showSignature=false -c core.commentChar= pull --no-stat -v --progress ${ORIGIN} ${BRANCH}
|
||||
cd "${CURRENT_PATH}"/../aos-framework-build && git -c credential.helper= -c core.quotepath=false -c log.showSignature=false -c core.commentChar= pull --no-stat -v --progress ${ORIGIN} ${BRANCH}
|
||||
@@ -0,0 +1,6 @@
|
||||
#!/bin/bash
|
||||
|
||||
source ./path.sh
|
||||
|
||||
cd "${CURRENT_PATH}"/../aos-supreme && git push --tags
|
||||
cd "${CURRENT_PATH}"/../aos-framework-build && git push --tags
|
||||
@@ -0,0 +1,12 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
source ./path.sh
|
||||
|
||||
ORIGIN="$1"
|
||||
BRANCH="$2"
|
||||
|
||||
cd "${CURRENT_PATH}"/../aos-supreme && git -c credential.helper= -c core.quotepath=false -c log.showSignature=false -c core.commentChar= pull --no-stat -v --progress ${ORIGIN} ${BRANCH}
|
||||
cd "${CURRENT_PATH}"/../aos-supreme && git -c credential.helper= -c core.quotepath=false -c log.showSignature=false push --progress --porcelain ${ORIGIN} refs/heads/${BRANCH}:${BRANCH} --tags
|
||||
|
||||
cd "${CURRENT_PATH}"/../aos-framework-build && git -c credential.helper= -c core.quotepath=false -c log.showSignature=false -c core.commentChar= pull --no-stat -v --progress ${ORIGIN} ${BRANCH}
|
||||
cd "${CURRENT_PATH}"/../aos-framework-build && git -c credential.helper= -c core.quotepath=false -c log.showSignature=false push --progress --porcelain ${ORIGIN} refs/heads/${BRANCH}:${BRANCH} --tags
|
||||
@@ -0,0 +1,8 @@
|
||||
#!/bin/bash
|
||||
|
||||
source ./path.sh
|
||||
|
||||
TAG_NAME="$1"
|
||||
|
||||
cd "${CURRENT_PATH}"/../aos-supreme && git tag "${TAG_NAME}"
|
||||
cd "${CURRENT_PATH}"/../aos-framework-build && git tag "${TAG_NAME}"
|
||||
@@ -0,0 +1,6 @@
|
||||
#!/bin/bash
|
||||
|
||||
source ./path.sh
|
||||
|
||||
cd "${CURRENT_PATH}"/../aos-supreme && ./mvnw -T 2C clean validate -Dmaven.test.skip=true
|
||||
cd "${CURRENT_PATH}"/../aos-framework-build && ./mvnw -T 2C clean validate -Dmaven.test.skip=true
|
||||
@@ -0,0 +1,21 @@
|
||||
<?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">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>ability</artifactId>
|
||||
<groupId>com.aos</groupId>
|
||||
<version>stable</version>
|
||||
<packaging>pom</packaging>
|
||||
|
||||
<modules>
|
||||
<module>aos-framework-build</module>
|
||||
</modules>
|
||||
|
||||
<properties>
|
||||
<maven.install.skip>true</maven.install.skip>
|
||||
<maven.deploy.skip>true</maven.deploy.skip>
|
||||
</properties>
|
||||
|
||||
</project>
|
||||
@@ -1,237 +0,0 @@
|
||||
package com.aos.common.encrypt;
|
||||
|
||||
import com.google.common.base.Charsets;
|
||||
import lombok.experimental.UtilityClass;
|
||||
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Base64;
|
||||
|
||||
/**
|
||||
* <p>Company: 成都返空汇网络技术有限公司</p>
|
||||
* <p>Description: Base64工具 </p>
|
||||
*
|
||||
* @author dong4j
|
||||
* @version 1.2.3
|
||||
* @email "mailto:dongshijie@fkhwl.com"
|
||||
* @date 2019.12.26 21:45
|
||||
* @since 1.0.0
|
||||
*/
|
||||
@UtilityClass
|
||||
public class Base64Utils {
|
||||
private static final Charset DEFAULT_CHARSET = StandardCharsets.UTF_8;
|
||||
|
||||
/**
|
||||
* 编码
|
||||
*
|
||||
* @param value 字符串
|
||||
* @return {String}
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public static String encode(String value) {
|
||||
return encode(value, DEFAULT_CHARSET);
|
||||
}
|
||||
|
||||
/**
|
||||
* 编码
|
||||
*
|
||||
* @param value 字符串
|
||||
* @param charset 字符集
|
||||
* @return {String}
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public static String encode(String value, Charset charset) {
|
||||
byte[] val = value.getBytes(charset);
|
||||
return new String(encode(val), charset);
|
||||
}
|
||||
|
||||
/**
|
||||
* Base64 编码
|
||||
*
|
||||
* @param src
|
||||
* @return byte[]
|
||||
* @Date 2022/12/3
|
||||
* @Author wangyl
|
||||
*/
|
||||
public static byte[] encode(byte[] src) {
|
||||
if (src.length == 0) {
|
||||
return src;
|
||||
}
|
||||
return Base64.getEncoder().encode(src);
|
||||
}
|
||||
|
||||
/**
|
||||
* Base64 编码成String
|
||||
*
|
||||
* @param src
|
||||
* @return java.lang.String
|
||||
* @Date 2022/12/3
|
||||
* @Author wangyl
|
||||
*/
|
||||
public static String encodeToString(byte[] src) {
|
||||
if (src.length == 0) {
|
||||
return "";
|
||||
}
|
||||
return new String(encode(src), DEFAULT_CHARSET);
|
||||
}
|
||||
|
||||
/**
|
||||
* Base64 url编码
|
||||
*
|
||||
* @param src
|
||||
* @return byte[]
|
||||
* @Date 2022/12/3
|
||||
* @Author wangyl
|
||||
*/
|
||||
public static byte[] encodeUrlSafe(byte[] src) {
|
||||
if (src.length == 0) {
|
||||
return src;
|
||||
}
|
||||
return Base64.getUrlEncoder().encode(src);
|
||||
}
|
||||
|
||||
/**
|
||||
* 编码URL安全
|
||||
*
|
||||
* @param value 字符串
|
||||
* @return {String}
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public static String encodeUrlSafe(String value) {
|
||||
return encodeUrlSafe(value, Charsets.UTF_8);
|
||||
}
|
||||
|
||||
/**
|
||||
* Base64 编码url返回String
|
||||
*
|
||||
* @param src
|
||||
* @return java.lang.String
|
||||
* @Date 2022/12/3
|
||||
* @Author wangyl
|
||||
*/
|
||||
public static String encodeToUrlSafeString(byte[] src) {
|
||||
return new String(encodeUrlSafe(src), DEFAULT_CHARSET);
|
||||
}
|
||||
|
||||
/**
|
||||
* 编码URL安全
|
||||
*
|
||||
* @param value 字符串
|
||||
* @param charset 字符集
|
||||
* @return {String}
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public static String encodeUrlSafe(String value, Charset charset) {
|
||||
byte[] val = value.getBytes(charset);
|
||||
return new String(encodeUrlSafe(val), charset);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 解码
|
||||
*
|
||||
* @param value 字符串
|
||||
* @return {String}
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public static String decode(String value) {
|
||||
return Base64Utils.decode(value, Charsets.UTF_8);
|
||||
}
|
||||
|
||||
/**
|
||||
* 解码
|
||||
*
|
||||
* @param value 字符串
|
||||
* @param charset 字符集
|
||||
* @return {String}
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public static String decode(String value, java.nio.charset.Charset charset) {
|
||||
byte[] val = value.getBytes(charset);
|
||||
byte[] decodedValue = Base64Utils.decode(val);
|
||||
return new String(decodedValue, charset);
|
||||
}
|
||||
|
||||
/**
|
||||
* 解码URL安全
|
||||
*
|
||||
* @param value 字符串
|
||||
* @return {String}
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public static String decodeUrlSafe(String value) {
|
||||
return Base64Utils.decodeUrlSafe(value, Charsets.UTF_8);
|
||||
}
|
||||
|
||||
/**
|
||||
* 解码URL安全
|
||||
*
|
||||
* @param value 字符串
|
||||
* @param charset 字符集
|
||||
* @return {String}
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public static String decodeUrlSafe(String value, java.nio.charset.Charset charset) {
|
||||
byte[] val = value.getBytes(charset);
|
||||
byte[] decodedValue = Base64Utils.decodeUrlSafe(val);
|
||||
return new String(decodedValue, charset);
|
||||
}
|
||||
|
||||
/**
|
||||
* Base64 解码
|
||||
*
|
||||
* @param src
|
||||
* @return byte[]
|
||||
* @Date 2022/12/3
|
||||
* @Author wangyl
|
||||
*/
|
||||
public static byte[] decode(byte[] src) {
|
||||
if (src.length == 0) {
|
||||
return src;
|
||||
}
|
||||
return Base64.getDecoder().decode(src);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Base64 url解码
|
||||
*
|
||||
* @param src
|
||||
* @return byte[]
|
||||
* @Date 2022/12/3
|
||||
* @Author wangyl
|
||||
*/
|
||||
public static byte[] decodeUrlSafe(byte[] src) {
|
||||
if (src.length == 0) {
|
||||
return src;
|
||||
}
|
||||
return Base64.getUrlDecoder().decode(src);
|
||||
}
|
||||
|
||||
/**
|
||||
* Base64 从String解码为byte
|
||||
*
|
||||
* @param src
|
||||
* @return byte[]
|
||||
* @Date 2022/12/3
|
||||
* @Author wangyl
|
||||
*/
|
||||
public static byte[] decodeFromString(String src) {
|
||||
if (src.isEmpty()) {
|
||||
return new byte[0];
|
||||
}
|
||||
return decode(src.getBytes(DEFAULT_CHARSET));
|
||||
}
|
||||
|
||||
/**
|
||||
* Base64 解码返回byte
|
||||
*
|
||||
* @param src
|
||||
* @return byte[]
|
||||
* @Date 2022/12/3
|
||||
* @Author wangyl
|
||||
*/
|
||||
public static byte[] decodeFromUrlSafeString(String src) {
|
||||
return decodeUrlSafe(src.getBytes(DEFAULT_CHARSET));
|
||||
}
|
||||
}
|
||||
@@ -1,75 +0,0 @@
|
||||
package com.aos.common.model.result;
|
||||
|
||||
import com.aos.common.model.ResultCodeInterface;
|
||||
import lombok.AllArgsConstructor;
|
||||
|
||||
@AllArgsConstructor
|
||||
@SuppressWarnings("unchecked")
|
||||
public enum WebResponse {
|
||||
/**
|
||||
*
|
||||
*/
|
||||
WebResponse;
|
||||
|
||||
public <T> WebResult buildWebResult(ResultCodeInterface resultCode, T data, String traceId) {
|
||||
return new WebResult(resultCode, data, traceId);
|
||||
}
|
||||
|
||||
public <T> WebResult ok(ResultCodeInterface resultCode, T data) {
|
||||
return this.buildWebResult(resultCode, data, null);
|
||||
}
|
||||
|
||||
public <T> WebResult ok(ResultCodeInterface resultCode, String traceId) {
|
||||
return this.buildWebResult(resultCode, null, traceId);
|
||||
}
|
||||
|
||||
public <T> WebResult ok(ResultCodeInterface resultCode) {
|
||||
return this.buildWebResult(resultCode, null, null);
|
||||
}
|
||||
|
||||
public <T> WebResult ok(T data) {
|
||||
return this.buildWebResult(ResultCode.SUCCEED, data, null);
|
||||
}
|
||||
|
||||
public <T> WebResult ok(String traceId) {
|
||||
return this.buildWebResult(ResultCode.SUCCEED, null, traceId);
|
||||
}
|
||||
|
||||
public <T> WebResult ok(T data, String traceId) {
|
||||
return this.buildWebResult(ResultCode.SUCCEED, data, traceId);
|
||||
}
|
||||
|
||||
public <T> WebResult ok() {
|
||||
return this.ok(ResultCode.SUCCEED, null);
|
||||
}
|
||||
|
||||
|
||||
public <T> WebResult error(ResultCodeInterface resultCode, T data) {
|
||||
return this.buildWebResult(resultCode, data, null);
|
||||
}
|
||||
|
||||
public <T> WebResult error(ResultCodeInterface resultCode, String traceId) {
|
||||
return this.buildWebResult(resultCode, null, traceId);
|
||||
}
|
||||
|
||||
public <T> WebResult error(ResultCodeInterface resultCode) {
|
||||
return this.buildWebResult(resultCode, null, null);
|
||||
}
|
||||
|
||||
public <T> WebResult error(T data) {
|
||||
return this.buildWebResult(ResultCode.FAILED, data, null);
|
||||
}
|
||||
|
||||
public <T> WebResult error(String traceId) {
|
||||
return this.buildWebResult(ResultCode.FAILED, null, traceId);
|
||||
}
|
||||
|
||||
public <T> WebResult error(T data, String traceId) {
|
||||
return this.buildWebResult(ResultCode.FAILED, data, traceId);
|
||||
}
|
||||
|
||||
public <T> WebResult error() {
|
||||
return this.ok(ResultCode.FAILED, null);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,78 +0,0 @@
|
||||
package com.aos.common.model.result;
|
||||
|
||||
import com.aos.common.model.ResultCodeInterface;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
/**
|
||||
* @author wangyl
|
||||
* @version V1.0
|
||||
* @ClassName: WebResult
|
||||
* @Function: 返回对象
|
||||
* @Date: 2020/3/27 10:49
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
public class WebResult<T> {
|
||||
/**
|
||||
* 返回码
|
||||
*/
|
||||
private String code;
|
||||
/**
|
||||
* 描述信息
|
||||
*/
|
||||
private String msg;
|
||||
/**
|
||||
* 返回数据
|
||||
*/
|
||||
private T data;
|
||||
|
||||
/**
|
||||
* 链路追踪id
|
||||
*/
|
||||
private String traceId;
|
||||
|
||||
public WebResult() {
|
||||
|
||||
}
|
||||
|
||||
public WebResult(String code, String msg, T data, String traceId) {
|
||||
this.code = code;
|
||||
this.msg = msg;
|
||||
this.data = data;
|
||||
this.traceId = traceId;
|
||||
}
|
||||
|
||||
public WebResult(String code, String msg, T data) {
|
||||
this(code, msg, data, null);
|
||||
}
|
||||
|
||||
public WebResult(String code, String msg, String traceId) {
|
||||
this(code, msg, null, traceId);
|
||||
}
|
||||
|
||||
public WebResult(String code, String msg) {
|
||||
this(code, msg, null, null);
|
||||
}
|
||||
|
||||
public WebResult(String code, T data) {
|
||||
this(code, null, data, null);
|
||||
}
|
||||
|
||||
public WebResult(ResultCodeInterface resultCode, T data, String traceId) {
|
||||
this(resultCode.getCode(), resultCode.getMsg(), data, traceId);
|
||||
}
|
||||
|
||||
public WebResult(ResultCodeInterface resultCode, T data) {
|
||||
this(resultCode.getCode(), resultCode.getMsg(), data, null);
|
||||
}
|
||||
|
||||
public WebResult(ResultCodeInterface resultCode, String traceId) {
|
||||
this(resultCode, null, traceId);
|
||||
}
|
||||
|
||||
public WebResult(ResultCodeInterface resultCode) {
|
||||
this(resultCode, null, null);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,198 +0,0 @@
|
||||
<?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>aos-core</artifactId>
|
||||
<groupId>com.aos</groupId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>aos-dependencies</artifactId>
|
||||
<packaging>pom</packaging>
|
||||
<properties>
|
||||
<!-- 默认跳过 test -->
|
||||
<maven.test.skip>true</maven.test.skip>
|
||||
<!-- 跳过 javadoc -->
|
||||
<maven.javadoc.skip>true</maven.javadoc.skip>
|
||||
<!-- 关闭 API 过时警告 -->
|
||||
<maven.compile.deprecation>off</maven.compile.deprecation>
|
||||
<project.encoding>UTF-8</project.encoding>
|
||||
<project.build.sourceEncoding>${project.encoding}</project.build.sourceEncoding>
|
||||
<maven.compiler.source>1.8</maven.compiler.source>
|
||||
<maven.compiler.target>1.8</maven.compiler.target>
|
||||
<mybatis-plus.version>3.4.3</mybatis-plus.version>
|
||||
<guava.version>30.0-jre</guava.version>
|
||||
<swagger-ui.version>2.9.2</swagger-ui.version>
|
||||
<swagger2.version>2.9.2</swagger2.version>
|
||||
<swagger-bootstrap-ui.knife4j.version>3.0.3</swagger-bootstrap-ui.knife4j.version>
|
||||
<swagger-annotations.version>1.5.20</swagger-annotations.version>
|
||||
<spring-cloud-alibaba.version>2.2.7.RELEASE</spring-cloud-alibaba.version>
|
||||
<spring.cloud.version>Hoxton.SR12</spring.cloud.version>
|
||||
<spring.boot.vsersion>2.3.12.RELEASE</spring.boot.vsersion>
|
||||
<jjwt.version>0.9.1</jjwt.version>
|
||||
<ttl.version>2.11.4</ttl.version>
|
||||
<hutools.version>5.8.9</hutools.version>
|
||||
</properties>
|
||||
<dependencyManagement>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.alibaba.cloud</groupId>
|
||||
<artifactId>spring-cloud-alibaba-dependencies</artifactId>
|
||||
<version>${spring-cloud-alibaba.version}</version>
|
||||
<type>pom</type>
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-dependencies</artifactId>
|
||||
<version>${spring.cloud.version}</version>
|
||||
<type>pom</type>
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-dependencies</artifactId>
|
||||
<version>${spring.boot.vsersion}</version>
|
||||
<type>pom</type>
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
<!-- https://mvnrepository.com/artifact/cn.hutool/hutool-bom -->
|
||||
<dependency>
|
||||
<groupId>cn.hutool</groupId>
|
||||
<artifactId>hutool-bom</artifactId>
|
||||
<version>${hutools.version}</version>
|
||||
<type>pom</type>
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
|
||||
<!--Mybatis plus-->
|
||||
<dependency>
|
||||
<groupId>com.baomidou</groupId>
|
||||
<artifactId>mybatis-plus-boot-starter</artifactId>
|
||||
<version>${mybatis-plus.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.baomidou</groupId>
|
||||
<artifactId>mybatis-plus-annotation</artifactId>
|
||||
<version>${mybatis-plus.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.baomidou</groupId>
|
||||
<artifactId>mybatis-plus-core</artifactId>
|
||||
<version>${mybatis-plus.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.baomidou</groupId>
|
||||
<artifactId>mybatis-plus-extension</artifactId>
|
||||
<version>${mybatis-plus.version}</version>
|
||||
</dependency>
|
||||
<!--tools-->
|
||||
<dependency>
|
||||
<groupId>com.google.guava</groupId>
|
||||
<artifactId>guava</artifactId>
|
||||
<version>${guava.version}</version>
|
||||
</dependency>
|
||||
<!-- swagger2 -->
|
||||
<dependency>
|
||||
<groupId>io.springfox</groupId>
|
||||
<artifactId>springfox-swagger2</artifactId>
|
||||
<version>${swagger2.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.swagger</groupId>
|
||||
<artifactId>swagger-annotations</artifactId>
|
||||
<version>${swagger-annotations.version}</version>
|
||||
</dependency>
|
||||
<!-- swagger-bootstrap-ui-->
|
||||
<dependency>
|
||||
<groupId>io.springfox</groupId>
|
||||
<artifactId>springfox-swagger-ui</artifactId>
|
||||
<version>${swagger-ui.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.springfox</groupId>
|
||||
<artifactId>springfox-swagger-common</artifactId>
|
||||
<version>${swagger-ui.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.github.xiaoymin</groupId>
|
||||
<artifactId>knife4j-spring-ui</artifactId>
|
||||
<version>${swagger-bootstrap-ui.knife4j.version}</version>
|
||||
</dependency>
|
||||
<!--JWT-->
|
||||
<dependency>
|
||||
<groupId>io.jsonwebtoken</groupId>
|
||||
<artifactId>jjwt</artifactId>
|
||||
<version>${jjwt.version}</version>
|
||||
</dependency>
|
||||
<!--thread-->
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>transmittable-thread-local</artifactId>
|
||||
<version>${ttl.version}</version>
|
||||
</dependency>
|
||||
<!--aos-->
|
||||
<dependency>
|
||||
<groupId>com.aos</groupId>
|
||||
<artifactId>aos-common</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.aos</groupId>
|
||||
<artifactId>aos-web</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.aos</groupId>
|
||||
<artifactId>aos-mybatis-plus</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.aos</groupId>
|
||||
<artifactId>aos-swagger</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.aos</groupId>
|
||||
<artifactId>aos-log</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<version>1.18.24</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-api</artifactId>
|
||||
<version>1.7.30</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-source-plugin</artifactId>
|
||||
<version>3.0.0</version>
|
||||
<configuration>
|
||||
<attach>true</attach>
|
||||
</configuration>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>compile</phase>
|
||||
<goals>
|
||||
<goal>jar</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
|
||||
</project>
|
||||
@@ -2,25 +2,19 @@
|
||||
<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>aos-dependencies</artifactId>
|
||||
<groupId>com.aos</groupId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
<relativePath>../aos-dependencies/pom.xml</relativePath>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>aos-feign</artifactId>
|
||||
<parent>
|
||||
<artifactId>aos-element</artifactId>
|
||||
<groupId>com.aos</groupId>
|
||||
<version>${revision}</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>aos-element-autoconfigure</artifactId>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>8</maven.compiler.source>
|
||||
<maven.compiler.target>8</maven.compiler.target>
|
||||
</properties>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-openfeign</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
@@ -0,0 +1,107 @@
|
||||
<?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">
|
||||
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<parent>
|
||||
<artifactId>aos-element</artifactId>
|
||||
<groupId>com.aos</groupId>
|
||||
<version>${revision}</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>aos-element-basic</artifactId>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.google.guava</groupId>
|
||||
<artifactId>guava</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.google.code.gson</groupId>
|
||||
<artifactId>gson</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.swagger</groupId>
|
||||
<artifactId>swagger-annotations</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.reflections</groupId>
|
||||
<artifactId>reflections</artifactId>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>org.javassist</groupId>
|
||||
<artifactId>javassist</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>cn.hutool</groupId>
|
||||
<artifactId>hutool-http</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.javassist</groupId>
|
||||
<artifactId>javassist</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-lang3</artifactId>
|
||||
</dependency>
|
||||
<!-- 父子线程参数透传 -->
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>transmittable-thread-local</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- 由业务端指定版本, 最低版本支持 2.8.0 -->
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.core</groupId>
|
||||
<artifactId>jackson-databind</artifactId>
|
||||
</dependency>
|
||||
<!-- 由业务端指定版本 -->
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-context</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<!-- 由业务端指定版本, 最低版本要求 2.0.1.Final -->
|
||||
<dependency>
|
||||
<groupId>javax.validation</groupId>
|
||||
<artifactId>validation-api</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<!-- 修复 未知的枚举常量 javax.annotation.meta.When.MAYBE 警告 -->
|
||||
<dependency>
|
||||
<groupId>com.google.code.findbugs</groupId>
|
||||
<artifactId>jsr305</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<!-- 禁用依赖传递, 作为本模块的日志依赖 -->
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-simple</artifactId>
|
||||
<scope>provided</scope>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
<!-- 处理 jdk8 时间类型在反序列化的异常 -->
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.datatype</groupId>
|
||||
<artifactId>jackson-datatype-jsr310</artifactId>
|
||||
<scope>test</scope>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-web</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>javax.servlet</groupId>
|
||||
<artifactId>javax.servlet-api</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
+108
@@ -0,0 +1,108 @@
|
||||
package com.aos.element.basic.basic;
|
||||
|
||||
import com.aos.element.basic.basic.util.SecurityUtils;
|
||||
import com.aos.element.basic.basic.util.StringPool;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.AntPathMatcher;
|
||||
import org.springframework.util.PathMatcher;
|
||||
import org.springframework.web.filter.OncePerRequestFilter;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
/**
|
||||
* <p>Company: 成都返空汇网络技术有限公司</p>
|
||||
* <p>Description: 能够配置需要跳过的 url 的抽象 filter, 子类
|
||||
*
|
||||
* @author dong4j
|
||||
* @version 1.2.3
|
||||
* @email "mailto:dongshijie@fkhwl.com"
|
||||
* @date 2019.11.26 15:48
|
||||
* @since 1.0.0
|
||||
*/
|
||||
@Slf4j
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public abstract class AbstractSkipFilter extends OncePerRequestFilter {
|
||||
/** Path matcher */
|
||||
protected PathMatcher pathMatcher = new AntPathMatcher();
|
||||
/** 需要执行过滤器逻辑的 url */
|
||||
@Nullable
|
||||
protected String[] includePatterns;
|
||||
/** 不需要执行过滤器逻辑的 url */
|
||||
@Nullable
|
||||
protected String[] excludePatterns;
|
||||
/** 业务自定义需要忽略的 url, 最终会写入到 {@link AbstractSkipFilter#includePatterns} */
|
||||
protected String skipUrl;
|
||||
|
||||
/**
|
||||
* Abstract skip filter
|
||||
*
|
||||
* @since 2.1.0
|
||||
*/
|
||||
public AbstractSkipFilter() {
|
||||
init();
|
||||
}
|
||||
|
||||
/**
|
||||
* Abstract skip filter
|
||||
*
|
||||
* @param skipUrl skip url
|
||||
* @since 2.1.0
|
||||
*/
|
||||
public AbstractSkipFilter(String skipUrl) {
|
||||
this.skipUrl = skipUrl;
|
||||
merge();
|
||||
}
|
||||
|
||||
/**
|
||||
* Init
|
||||
*
|
||||
* @since 1.5.0
|
||||
*/
|
||||
@PostConstruct
|
||||
public void init() {
|
||||
merge();
|
||||
}
|
||||
|
||||
/**
|
||||
* Merge
|
||||
*
|
||||
* @since 2.1.0
|
||||
*/
|
||||
private void merge() {
|
||||
if (this.includePatterns == null) {
|
||||
this.includePatterns = new String[] {StringPool.ANY_PATH};
|
||||
}
|
||||
|
||||
if (this.excludePatterns == null) {
|
||||
this.excludePatterns = SecurityUtils.mergeSkipPatterns(this.skipUrl).toArray(new String[0]);
|
||||
} else {
|
||||
Set<String> excluded = new HashSet<>(Arrays.asList(this.excludePatterns));
|
||||
this.excludePatterns = SecurityUtils.mergeSkipPatterns(excluded, this.skipUrl).toArray(new String[0]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 不需要拦截的 url
|
||||
*
|
||||
* @param request request
|
||||
* @return the boolean
|
||||
* @since 1.5.0
|
||||
*/
|
||||
@Override
|
||||
protected boolean shouldNotFilter(@NotNull HttpServletRequest request) {
|
||||
return SecurityUtils.matches(request.getRequestURI(), this.includePatterns, this.excludePatterns, this.pathMatcher);
|
||||
}
|
||||
|
||||
}
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
package com.aos.element.basic.basic;
|
||||
|
||||
/**
|
||||
* <p>Company: 成都返空汇网络技术有限公司 </p>
|
||||
* <p>Description: </p>
|
||||
*
|
||||
* @author dong4j
|
||||
* @version 1.0.0
|
||||
* @email "mailto:dongshijie@fkhwl.com"
|
||||
* @date 2020.05.19 14:33
|
||||
* @since 1.4.0
|
||||
*/
|
||||
public interface ApplicationInitializedListener {
|
||||
|
||||
/**
|
||||
* 当所有应用程序级组件都在组件初始化的同一线程中初始化时调用
|
||||
*
|
||||
* @since 1.4.0
|
||||
*/
|
||||
void componentsInitialized();
|
||||
}
|
||||
+77
@@ -0,0 +1,77 @@
|
||||
package com.aos.element.basic.basic;
|
||||
|
||||
import com.aos.element.basic.basic.bundle.BundleBase;
|
||||
import com.aos.element.basic.basic.bundle.BundleUtils;
|
||||
|
||||
import org.jetbrains.annotations.Nls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.ResourceBundle;
|
||||
|
||||
/**
|
||||
* <p>Company: 成都返空汇网络技术有限公司 </p>
|
||||
* <p>Description: </p>
|
||||
*
|
||||
* @author dong4j
|
||||
* @version 1.0.0
|
||||
* @email "mailto:dongshijie@fkhwl.com"
|
||||
* @date 2020.05.19 10:22
|
||||
* @since 1.4.0
|
||||
*/
|
||||
@SuppressWarnings("all")
|
||||
public final class BasicBundle extends BundleBase {
|
||||
/** BUNDLE */
|
||||
private static final String BUNDLE = "messages.BasicBundle";
|
||||
/** ourBundle */
|
||||
private static ResourceBundle ourBundle;
|
||||
|
||||
/**
|
||||
* Util bundle
|
||||
*
|
||||
* @since 1.4.0
|
||||
*/
|
||||
private BasicBundle() { }
|
||||
|
||||
/**
|
||||
* Message
|
||||
*
|
||||
* @param key key
|
||||
* @param params params
|
||||
* @return the string
|
||||
* @since 1.4.0
|
||||
*/
|
||||
@Nls
|
||||
@NotNull
|
||||
public static String message(@NotNull String key, Object... params) {
|
||||
return message(getUtilBundle(), key, params);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets util bundle *
|
||||
*
|
||||
* @return the util bundle
|
||||
* @since 1.4.0
|
||||
*/
|
||||
@NotNull
|
||||
private static ResourceBundle getUtilBundle() {
|
||||
if (ourBundle != null) {
|
||||
return ourBundle;
|
||||
}
|
||||
ourBundle = ResourceBundle.getBundle(BUNDLE);
|
||||
return ourBundle;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load bundle from plugin
|
||||
*
|
||||
* @param pluginClassLoader plugin class loader
|
||||
* @since 1.4.0
|
||||
*/
|
||||
public static void loadBundleFromPlugin(@Nullable ClassLoader pluginClassLoader) {
|
||||
ResourceBundle bundle = BundleUtils.loadLanguageBundle(pluginClassLoader, BUNDLE);
|
||||
if (bundle != null) {
|
||||
ourBundle = bundle;
|
||||
}
|
||||
}
|
||||
}
|
||||
+118
@@ -0,0 +1,118 @@
|
||||
package com.aos.element.basic.basic;
|
||||
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.io.File;
|
||||
import java.nio.file.Path;
|
||||
|
||||
/**
|
||||
* <p>Company: 成都返空汇网络技术有限公司 </p>
|
||||
* <p>Description: 插件元数据接口</p>
|
||||
*
|
||||
* @author dong4j
|
||||
* @version 1.0.0
|
||||
* @email "mailto:dongshijie@fkhwl.com"
|
||||
* @date 2020.05.19 14:39
|
||||
* @since 1.4.0
|
||||
*/
|
||||
public interface PluginDescriptor {
|
||||
|
||||
/**
|
||||
* Gets plugin id *
|
||||
*
|
||||
* @return the plugin id
|
||||
* @since 1.4.0
|
||||
*/
|
||||
PluginId getPluginId();
|
||||
|
||||
/**
|
||||
* Gets plugin class loader *
|
||||
*
|
||||
* @return the plugin class loader
|
||||
* @since 1.4.0
|
||||
*/
|
||||
ClassLoader getPluginClassLoader();
|
||||
|
||||
/**
|
||||
* Is bundled
|
||||
*
|
||||
* @return the boolean
|
||||
* @since 1.4.0
|
||||
*/
|
||||
default boolean isBundled() {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets path *
|
||||
*
|
||||
* @return the path
|
||||
* @since 1.4.0
|
||||
*/
|
||||
File getPath();
|
||||
|
||||
/**
|
||||
* Gets plugin path *
|
||||
*
|
||||
* @return the plugin path
|
||||
* @since 1.4.0
|
||||
*/
|
||||
Path getPluginPath();
|
||||
|
||||
/**
|
||||
* Gets description *
|
||||
*
|
||||
* @return the description
|
||||
* @since 1.4.0
|
||||
*/
|
||||
@Nullable
|
||||
String getDescription();
|
||||
|
||||
/**
|
||||
* Gets change notes *
|
||||
*
|
||||
* @return the change notes
|
||||
* @since 1.4.0
|
||||
*/
|
||||
String getChangeNotes();
|
||||
|
||||
/**
|
||||
* Gets name *
|
||||
*
|
||||
* @return the name
|
||||
* @since 1.4.0
|
||||
*/
|
||||
String getName();
|
||||
|
||||
/**
|
||||
* Gets vendor *
|
||||
*
|
||||
* @return the vendor
|
||||
* @since 1.4.0
|
||||
*/
|
||||
String getVendor();
|
||||
|
||||
/**
|
||||
* Gets version *
|
||||
*
|
||||
* @return the version
|
||||
* @since 1.4.0
|
||||
*/
|
||||
String getVersion();
|
||||
|
||||
/**
|
||||
* Is enabled
|
||||
*
|
||||
* @return the boolean
|
||||
* @since 1.4.0
|
||||
*/
|
||||
boolean isEnabled();
|
||||
|
||||
/**
|
||||
* Sets enabled *
|
||||
*
|
||||
* @param enabled enabled
|
||||
* @since 1.4.0
|
||||
*/
|
||||
void setEnabled(boolean enabled);
|
||||
}
|
||||
+118
@@ -0,0 +1,118 @@
|
||||
package com.aos.element.basic.basic;
|
||||
|
||||
import org.jetbrains.annotations.Contract;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* <p>Company: 成都返空汇网络技术有限公司 </p>
|
||||
* <p>Description: 插件 Id 定义 </p>
|
||||
*
|
||||
* @author dong4j
|
||||
* @version 1.0.0
|
||||
* @email "mailto:dongshijie@fkhwl.com"
|
||||
* @date 2020.05.19 14:38
|
||||
* @since 1.4.0
|
||||
*/
|
||||
public final class PluginId implements Comparable<PluginId> {
|
||||
/** EMPTY_ARRAY */
|
||||
public static final PluginId[] EMPTY_ARRAY = new PluginId[0];
|
||||
|
||||
/** ourRegisteredIds */
|
||||
private static final Map<String, PluginId> PLUGIN_ID_MAP = new HashMap<>(16);
|
||||
/** My id string */
|
||||
private final String myIdString;
|
||||
|
||||
/**
|
||||
* Gets id *
|
||||
*
|
||||
* @param idString id string
|
||||
* @return the id
|
||||
* @since 1.4.0
|
||||
*/
|
||||
@NotNull
|
||||
public static synchronized PluginId getId(@NotNull String idString) {
|
||||
return PLUGIN_ID_MAP.computeIfAbsent(idString, PluginId::new);
|
||||
}
|
||||
|
||||
/**
|
||||
* Plugin id
|
||||
*
|
||||
* @param idString id string
|
||||
* @since 1.4.0
|
||||
*/
|
||||
@Contract(pure = true)
|
||||
private PluginId(@NotNull String idString) {
|
||||
this.myIdString = idString;
|
||||
}
|
||||
|
||||
/**
|
||||
* Find id
|
||||
*
|
||||
* @param idStrings id strings
|
||||
* @return the plugin id
|
||||
* @since 1.4.0
|
||||
*/
|
||||
@Nullable
|
||||
public static synchronized PluginId findId(@NotNull String... idStrings) {
|
||||
for (String idString : idStrings) {
|
||||
PluginId pluginId = PLUGIN_ID_MAP.get(idString);
|
||||
if (pluginId != null) {
|
||||
return pluginId;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets registered ids *
|
||||
*
|
||||
* @return the registered ids
|
||||
* @since 1.4.0
|
||||
*/
|
||||
@Contract(" -> new")
|
||||
@NotNull
|
||||
public static synchronized Map<String, PluginId> getRegisteredIds() {
|
||||
return new HashMap<>(PLUGIN_ID_MAP);
|
||||
}
|
||||
|
||||
/**
|
||||
* Compare to
|
||||
*
|
||||
* @param o o
|
||||
* @return the int
|
||||
* @since 1.4.0
|
||||
*/
|
||||
@Contract(pure = true)
|
||||
@Override
|
||||
public int compareTo(@NotNull PluginId o) {
|
||||
return this.myIdString.compareTo(o.myIdString);
|
||||
}
|
||||
|
||||
/**
|
||||
* To string
|
||||
*
|
||||
* @return the string
|
||||
* @since 1.4.0
|
||||
*/
|
||||
@Contract(pure = true)
|
||||
@Override
|
||||
public @NotNull String toString() {
|
||||
return this.getIdString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets id string *
|
||||
*
|
||||
* @return the id string
|
||||
* @since 1.4.0
|
||||
*/
|
||||
@Contract(pure = true)
|
||||
@NotNull
|
||||
public String getIdString() {
|
||||
return this.myIdString;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,171 @@
|
||||
package com.aos.element.basic.basic;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import com.fasterxml.jackson.annotation.JsonTypeInfo;
|
||||
import com.aos.element.basic.basic.util.StringPool;
|
||||
import com.aos.element.basic.basic.util.StringUtils;
|
||||
|
||||
import org.jetbrains.annotations.Contract;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
|
||||
/**
|
||||
* <p>Company: 成都返空汇网络技术有限公司</p>
|
||||
* <p>Description: 请求响应返回结构封装, 所有请求都要求返回此类.
|
||||
* 为避免在 v4 中引入过多的 v5 依赖, 我们将 {@link Result} 分为了 2 个子类, 分别是 {@link StandardResult} 和 {@link com.fkhwl.starter.core.api.R},
|
||||
* StandardResult 在 v4 使用, R 在 v5 使用.
|
||||
* {@code
|
||||
* Result<Data> result = StandardResult.success(data);
|
||||
* Result<Data> result = R.success(data);
|
||||
* <p>
|
||||
* 反序列化:
|
||||
* Result<Data> result = JsonUtils.parse(json, new TypeReference<Result<Data>>(){});
|
||||
* Result result = JsonUtils.parse(json, Result.class);
|
||||
* }*
|
||||
* <p>
|
||||
* 由于 jackson 在反序列化抽象类时存在多态问题, 我们使用 {@link Result#TYPE_NAME} 来标识 json 需要被反序列化的 class, 为了避免 v5 的响应 json 数据在 v4 中反序列化失败,
|
||||
* 我们将所有的 json 都添加了 {@link Result#TYPE_NAME}, 全部都将反序列化为 {@link StandardResult}, 业务端在处理 json 结果时, 应该忽略 'type' 字段.
|
||||
* 比较推荐的反序列化方式是根据不同的框架来进行反序列化, 避免使用 {@link Result}:
|
||||
* {@code
|
||||
* v4: Result result = JsonUtils.parse(json, StandardResult.class);
|
||||
* v5: Result result = JsonUtils.parse(json, R.class);
|
||||
* }*
|
||||
* </p>
|
||||
*
|
||||
* @param <T> parameter
|
||||
* @author dong4j
|
||||
* @version 1.2.4
|
||||
* @email "mailto:dongshijie@gmail.com"
|
||||
* @date 2020.02.06 17:44
|
||||
* @since 1.0.0
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
@ToString
|
||||
@NoArgsConstructor
|
||||
@SuppressWarnings("all")
|
||||
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, property = "type", defaultImpl = StandardResult.class)
|
||||
public abstract class Result<T> implements Serializable {
|
||||
|
||||
/** serialVersionUID */
|
||||
public static final long serialVersionUID = 1L;
|
||||
/** CODE */
|
||||
public static final String CODE = "code";
|
||||
/** SUCCESS */
|
||||
public static final String SUCCESS = "success";
|
||||
/** DATA */
|
||||
public static final String DATA = "data";
|
||||
/** MESSAGE */
|
||||
public static final String MESSAGE = "message";
|
||||
/** TRACE_ID */
|
||||
public static final String TRACE_ID = "traceId";
|
||||
/** EXTEND */
|
||||
public static final String EXTEND = "extend";
|
||||
/** 反序列化时处理多态问题的标识 */
|
||||
public static final String TYPE_NAME = "StandardResult";
|
||||
/** 请求成功代码 */
|
||||
public static final String SUCCESS_CODE = "2000";
|
||||
/** 请求成功消息 */
|
||||
public static final String SUCCESS_MESSAGE = BasicBundle.message("success.message");
|
||||
/** 默认的失败代码 */
|
||||
public static final String FAILURE_CODE = "4000";
|
||||
/** 默认的失败消息 */
|
||||
public static final String FAILURE_MESSAGE = BasicBundle.message("failure.message");
|
||||
|
||||
/** 请求响应状态码 */
|
||||
@ApiModelProperty(value = "状态码", required = true, example = "2000")
|
||||
protected String code;
|
||||
/** 请求响应成功标识 */
|
||||
@ApiModelProperty(value = "请求成功的状态", required = true, example = "true")
|
||||
protected boolean success;
|
||||
/** 请求响应的数据 */
|
||||
@ApiModelProperty(value = "承载的数据", required = true)
|
||||
protected T data;
|
||||
/** 请求响应的消息 */
|
||||
@ApiModelProperty(value = "返回的消息", required = true, example = "操作成功")
|
||||
protected String message = "";
|
||||
/** 请求响应的溯源标识 */
|
||||
@ApiModelProperty(value = "溯源标识(业务无需关心此字段)", required = true, example = "1484501823002316800")
|
||||
protected String traceId;
|
||||
/** 扩展字段 */
|
||||
@ApiModelProperty(value = "扩展字段(业务无需关心此字段, 非生产环境的异常信息会写入到此字段)", required = true, example = "N/A")
|
||||
protected Object extend = StringPool.NULL_STRING;
|
||||
|
||||
/**
|
||||
* Result
|
||||
*
|
||||
* @param code code
|
||||
* @param message message
|
||||
* @param data data
|
||||
* @param traceId trace id
|
||||
* @since 1.0.0
|
||||
*/
|
||||
@Contract(pure = true)
|
||||
protected Result(@NotNull String code, String message, T data, String traceId) {
|
||||
this.code = code;
|
||||
if (!SUCCESS_CODE.equals(code) && !code.contains(StringPool.DASH) && !code.contains(StringPool.DOT)) {
|
||||
this.code = "S.F-" + code;
|
||||
}
|
||||
this.data = data;
|
||||
this.message = message;
|
||||
this.success = (SUCCESS_CODE.equals(code));
|
||||
this.traceId = StringUtils.isBlank(traceId)
|
||||
? StringPool.NULL_STRING
|
||||
: traceId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Is ok boolean
|
||||
*
|
||||
* @return the boolean
|
||||
* @since 1.0.0
|
||||
*/
|
||||
@JsonIgnore
|
||||
public boolean isOk() {
|
||||
return isOk(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* 请求是否成功
|
||||
*
|
||||
* @param result result
|
||||
* @return the boolean
|
||||
* @since 1.0.0
|
||||
*/
|
||||
@Contract("null -> false")
|
||||
public static boolean isOk(@Nullable Result<?> result) {
|
||||
return result != null && (SUCCESS_CODE.equals(result.getCode()) && result.isSuccess());
|
||||
}
|
||||
|
||||
/**
|
||||
* Is fail boolean
|
||||
*
|
||||
* @return the boolean
|
||||
* @since 1.0.0
|
||||
*/
|
||||
@JsonIgnore
|
||||
public boolean isFail() {
|
||||
return isFail(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* 请求是否失败
|
||||
*
|
||||
* @param result result
|
||||
* @return the boolean
|
||||
* @since 1.0.0
|
||||
*/
|
||||
@Contract("null -> true")
|
||||
public static boolean isFail(@Nullable Result<?> result) {
|
||||
return !isOk(result);
|
||||
}
|
||||
|
||||
}
|
||||
+180
@@ -0,0 +1,180 @@
|
||||
package com.aos.element.basic.basic;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonTypeName;
|
||||
import com.aos.element.basic.basic.context.Trace;
|
||||
|
||||
import org.jetbrains.annotations.Contract;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Collections;
|
||||
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* <p>Company: 成都返空汇网络技术有限公司</p>
|
||||
* <p>Description: 将标准返回的字段全部放在了 {@link Result},此类在 v4 使用 </p>
|
||||
*
|
||||
* @param <T> parameter
|
||||
* @author dong4j
|
||||
* @version 1.2.4
|
||||
* @email "mailto:dongshijie@gmail.com"
|
||||
* @date 2020.02.06 18:23
|
||||
* @since 1.0.0
|
||||
* @deprecated 在 v4 全部迁移到 v5 或 v4 全部升级到 JDK8 之后, {@link StandardResult} 将被废除.
|
||||
*/
|
||||
@Deprecated
|
||||
@NoArgsConstructor
|
||||
@JsonTypeName(value = Result.TYPE_NAME)
|
||||
public final class StandardResult<T> extends Result<T> {
|
||||
|
||||
/** serialVersionUID */
|
||||
private static final long serialVersionUID = 988958733744949964L;
|
||||
|
||||
/**
|
||||
* Standard result
|
||||
*
|
||||
* @param code code
|
||||
* @param message message
|
||||
* @param data data
|
||||
* @since 1.0.0
|
||||
*/
|
||||
@Contract(pure = true)
|
||||
private StandardResult(String code, String message, T data) {
|
||||
super(code, message, data, Trace.context().get());
|
||||
}
|
||||
|
||||
/**
|
||||
* Succeed result
|
||||
*
|
||||
* @param <T> parameter
|
||||
* @return the result
|
||||
* @since 1.0.0
|
||||
*/
|
||||
@Contract(pure = true)
|
||||
@NotNull
|
||||
@SuppressWarnings("unchecked")
|
||||
public static <T> Result<T> succeed() {
|
||||
return succeed((T) Collections.emptyMap());
|
||||
}
|
||||
|
||||
/**
|
||||
* Succeed result
|
||||
*
|
||||
* @param <T> parameter
|
||||
* @param data data
|
||||
* @return the result
|
||||
* @since 1.0.0
|
||||
*/
|
||||
@Contract(pure = true)
|
||||
@NotNull
|
||||
public static <T> Result<T> succeed(T data) {
|
||||
return succeed(SUCCESS_CODE, SUCCESS_MESSAGE, data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Succeed result
|
||||
*
|
||||
* @param <T> parameter
|
||||
* @param code code
|
||||
* @param msg msg
|
||||
* @param data data
|
||||
* @return the result
|
||||
* @since 1.0.0
|
||||
*/
|
||||
@Contract(pure = true)
|
||||
@NotNull
|
||||
public static <T> Result<T> succeed(String code, String msg, T data) {
|
||||
return build(code, msg, data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Build result
|
||||
*
|
||||
* @param <T> parameter
|
||||
* @param code code
|
||||
* @param msg msg
|
||||
* @param data data
|
||||
* @return the result
|
||||
* @since 1.0.0
|
||||
*/
|
||||
@Contract(value = "_, _, _ -> new", pure = true)
|
||||
@NotNull
|
||||
public static <T> Result<T> build(String code, String msg, T data) {
|
||||
return new StandardResult<>(code, msg, data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Build result
|
||||
*
|
||||
* @param <T> parameter
|
||||
* @param code code
|
||||
* @param msg msg
|
||||
* @return the result
|
||||
* @since 1.7.0
|
||||
*/
|
||||
@Contract("_, _ -> new")
|
||||
@SuppressWarnings("unchecked")
|
||||
public static <T> @NotNull Result<T> build(String code, String msg) {
|
||||
return build(code, msg, (T) Collections.emptyMap());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Failed result
|
||||
*
|
||||
* @param <T> parameter
|
||||
* @return the result
|
||||
* @since 1.0.0
|
||||
*/
|
||||
@Contract(pure = true)
|
||||
@NotNull
|
||||
public static <T> Result<T> failed() {
|
||||
return failed(FAILURE_MESSAGE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Failed result
|
||||
*
|
||||
* @param <T> parameter
|
||||
* @param msg msg
|
||||
* @return the result
|
||||
* @since 1.0.0
|
||||
*/
|
||||
@Contract(pure = true)
|
||||
@NotNull
|
||||
public static <T> Result<T> failed(String msg) {
|
||||
return failed(FAILURE_CODE, msg);
|
||||
}
|
||||
|
||||
/**
|
||||
* Failed result
|
||||
*
|
||||
* @param <T> parameter
|
||||
* @param code code
|
||||
* @param msg msg
|
||||
* @return the result
|
||||
* @since 1.0.0
|
||||
*/
|
||||
@NotNull
|
||||
@Contract(pure = true)
|
||||
@SuppressWarnings("unchecked")
|
||||
public static <T> Result<T> failed(String code, String msg) {
|
||||
return failed(code, msg, (T) Collections.emptyMap());
|
||||
}
|
||||
|
||||
/**
|
||||
* Failed result
|
||||
*
|
||||
* @param <T> parameter
|
||||
* @param code code
|
||||
* @param msg msg
|
||||
* @param data data
|
||||
* @return the result
|
||||
* @since 1.0.0
|
||||
*/
|
||||
@NotNull
|
||||
@Contract(value = "_, _, _ -> new", pure = true)
|
||||
public static <T> Result<T> failed(String code, String msg, T data) {
|
||||
return build(code, msg, data);
|
||||
}
|
||||
}
|
||||
+63
@@ -0,0 +1,63 @@
|
||||
package com.aos.element.basic.basic;
|
||||
|
||||
import com.aos.element.basic.basic.bundle.DynamicBundle;
|
||||
|
||||
import org.jetbrains.annotations.Contract;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
/**
|
||||
* <p>Company: 成都返空汇网络技术有限公司</p>
|
||||
* <p>Description: 框架版本, 通过 maven 编译时将 ${project.version} 替换为当前版本, 因此不需要每次手动修改 </p>
|
||||
*
|
||||
* @author dong4j
|
||||
* @version 1.4.0
|
||||
* @email "mailto:dongshijie@fkhwl.com"
|
||||
* @date 2020.05.22 14:55
|
||||
* @since 1.4.0
|
||||
*/
|
||||
public final class VersionBundle extends DynamicBundle {
|
||||
/** BUNDLE */
|
||||
@NonNls
|
||||
private static final String BUNDLE = "messages.VersionBundle";
|
||||
/** INSTANCE */
|
||||
private static final VersionBundle INSTANCE = new VersionBundle();
|
||||
|
||||
/**
|
||||
* Plugin bundle
|
||||
*
|
||||
* @since 0.0.1
|
||||
*/
|
||||
@Contract(pure = true)
|
||||
private VersionBundle() {
|
||||
super(BUNDLE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Message
|
||||
*
|
||||
* @param key key
|
||||
* @param params params
|
||||
* @return the string
|
||||
* @since 1.4.0
|
||||
*/
|
||||
@NotNull
|
||||
public static String message(@NotNull String key, Object... params) {
|
||||
return INSTANCE.getMessage(key, params);
|
||||
}
|
||||
|
||||
/**
|
||||
* Message pointer
|
||||
*
|
||||
* @param key key
|
||||
* @param params params
|
||||
* @return the supplier
|
||||
* @since 1.4.0
|
||||
*/
|
||||
public static @NotNull Supplier<String> messagePointer(@NotNull String key, Object... params) {
|
||||
return INSTANCE.getLazyMessage(key, params);
|
||||
}
|
||||
}
|
||||
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
package com.aos.element.basic.basic.annotation;
|
||||
|
||||
import java.lang.annotation.Documented;
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
/**
|
||||
* <p>Company: 成都返空汇网络技术有限公司 </p>
|
||||
* <p>Description: 错误码来源 </p>
|
||||
* <p>A: 来源用户 (比如: 参数错误) </p>
|
||||
* <p>B: 来源系统 (比如: 空指针异常等) </p>
|
||||
* <p>C: 来源第三方服务 (比如: 调用短信或者邮件等三方服务)
|
||||
* </p>
|
||||
*
|
||||
* @author zhubo
|
||||
* @version 1.0.0
|
||||
* @email "mailto:zhubo@fkhwl.com"
|
||||
* @date 2020.06.10 16:09
|
||||
* @since 1.5.0
|
||||
*/
|
||||
@Documented
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target(ElementType.FIELD)
|
||||
public @interface BusinessLevel {
|
||||
|
||||
}
|
||||
+45
@@ -0,0 +1,45 @@
|
||||
package com.aos.element.basic.basic.annotation;
|
||||
|
||||
import org.springframework.core.annotation.AliasFor;
|
||||
|
||||
import java.lang.annotation.Documented;
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
/**
|
||||
* <p>Company: 成都返空汇网络技术有限公司</p>
|
||||
* <p>Description: 项目标识 </p>
|
||||
*
|
||||
* @author zhubo
|
||||
* @version 1.0.0
|
||||
* @email "mailto:zhubo@fkhwl.com"
|
||||
* @date 2020.06.10 16:16
|
||||
* @since 1.5.0
|
||||
*/
|
||||
@Documented
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target(ElementType.TYPE)
|
||||
public @interface ModelSerial {
|
||||
/** DEFAULT */
|
||||
String DEFAULT = "F";
|
||||
|
||||
/**
|
||||
* Model name
|
||||
*
|
||||
* @return the module name
|
||||
* @since 1.5.0
|
||||
*/
|
||||
@AliasFor("value")
|
||||
String modelName() default DEFAULT;
|
||||
|
||||
/**
|
||||
* Value
|
||||
*
|
||||
* @return the string
|
||||
* @since 1.6.0
|
||||
*/
|
||||
@AliasFor("modelName")
|
||||
String value() default DEFAULT;
|
||||
}
|
||||
+43
@@ -0,0 +1,43 @@
|
||||
package com.aos.element.basic.basic.annotation;
|
||||
|
||||
import java.lang.annotation.Documented;
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
/**
|
||||
* 支持普通枚举类字段, 只用在enum类的字段上
|
||||
* <p>当实体类的属性是普通枚举, 且是其中一个字段, 使用该注解来标注枚举类里的那个属性对应字段</p>
|
||||
* {@code
|
||||
* TableName("student")
|
||||
* class Student {
|
||||
* private Integer id;
|
||||
* private String name;
|
||||
* private GradeEnum grade;//数据库grade字段类型为int
|
||||
* }
|
||||
* <p>
|
||||
* public enum GradeEnum {
|
||||
* PRIMARY(1,"小学"),
|
||||
* SECONDORY("2", "中学"),
|
||||
* HIGH(3, "高中");
|
||||
* <p>
|
||||
* @SerializeValue
|
||||
* private final int code;
|
||||
* private final String descp;
|
||||
* }
|
||||
* }*
|
||||
* </p>
|
||||
*
|
||||
* @author yuxiaobin
|
||||
* @version 1.3.0
|
||||
* @email "mailto:dongshijie@fkhwl.com"
|
||||
* @date 2020.03.23 19:10
|
||||
* @since 1.0.0
|
||||
*/
|
||||
@Documented
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target(ElementType.FIELD)
|
||||
public @interface SerializeValue {
|
||||
|
||||
}
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
package com.aos.element.basic.basic.annotation;
|
||||
|
||||
import java.lang.annotation.Documented;
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
/**
|
||||
* <p>Company: 成都返空汇网络技术有限公司 </p>
|
||||
* <p>Description: 错误码来源 </p>
|
||||
* <p>A: 来源用户 (比如: 参数错误) </p>
|
||||
* <p>B: 来源系统 (比如: 空指针异常等) </p>
|
||||
* <p>C: 来源第三方服务 (比如: 调用短信或者邮件等三方服务)
|
||||
* </p>
|
||||
*
|
||||
* @author zhubo
|
||||
* @version 1.0.0
|
||||
* @email "mailto:zhubo@fkhwl.com"
|
||||
* @date 2020.06.10 16:09
|
||||
* @since 1.5.0
|
||||
*/
|
||||
@Documented
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target(ElementType.FIELD)
|
||||
public @interface SystemLevel {
|
||||
|
||||
}
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
package com.aos.element.basic.basic.annotation;
|
||||
|
||||
import java.lang.annotation.Documented;
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
/**
|
||||
* <p>Company: 成都返空汇网络技术有限公司 </p>
|
||||
* <p>Description: 错误码来源 </p>
|
||||
* <p>A: 来源用户 (比如: 参数错误) </p>
|
||||
* <p>B: 来源系统 (比如: 空指针异常等) </p>
|
||||
* <p>C: 来源第三方服务 (比如: 调用短信或者邮件等三方服务) </p>
|
||||
*
|
||||
* @author zhubo
|
||||
* @version 1.0.0
|
||||
* @email "mailto:zhubo@fkhwl.com"
|
||||
* @date 2020.06.10 16:09
|
||||
* @since 1.5.0
|
||||
*/
|
||||
@Documented
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target(ElementType.FIELD)
|
||||
public @interface ThirdLevel {
|
||||
}
|
||||
+452
@@ -0,0 +1,452 @@
|
||||
package com.aos.element.basic.basic.asserts;
|
||||
|
||||
import com.aos.element.basic.basic.exception.AssertionFailedException;
|
||||
import com.aos.element.basic.core.function.CheckedRunnable;
|
||||
|
||||
import org.jetbrains.annotations.Contract;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
/**
|
||||
* <p>Company: 成都返空汇网络技术有限公司 </p>
|
||||
* <p>Description: </p>
|
||||
*
|
||||
* @author dong4j
|
||||
* @version 1.0.0
|
||||
* @email "mailto:dongshijie@fkhwl.com"
|
||||
* @date 2020.11.18 18:06
|
||||
* @since 1.7.0
|
||||
*/
|
||||
@SuppressWarnings("all")
|
||||
final class AssertEquals {
|
||||
|
||||
/** default_message */
|
||||
private static final String DEFAULT_MESSAGE = "2 个参数不相等";
|
||||
|
||||
/**
|
||||
* Assert equals
|
||||
*
|
||||
* @since 1.7.0
|
||||
*/
|
||||
private AssertEquals() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Equals
|
||||
*
|
||||
* @param expected expected
|
||||
* @param actual actual
|
||||
* @since 1.7.0
|
||||
*/
|
||||
static void equals(byte expected, byte actual) {
|
||||
equals(expected, actual, DEFAULT_MESSAGE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Equals
|
||||
*
|
||||
* @param expected expected
|
||||
* @param actual actual
|
||||
* @param message message
|
||||
* @since 1.7.0
|
||||
*/
|
||||
static void equals(byte expected, byte actual, String message) {
|
||||
equals(expected, actual, () -> new AssertionFailedException(message));
|
||||
}
|
||||
|
||||
/**
|
||||
* Equals
|
||||
*
|
||||
* @param expected expected
|
||||
* @param actual actual
|
||||
* @param messageSupplier message supplier
|
||||
* @since 1.7.0
|
||||
*/
|
||||
static void equals(byte expected, byte actual, Supplier<? extends RuntimeException> messageSupplier) {
|
||||
if (expected != actual) {
|
||||
failNotEqual(expected, actual, messageSupplier);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Equals
|
||||
*
|
||||
* @param expected expected
|
||||
* @param actual actual
|
||||
* @since 1.7.0
|
||||
*/
|
||||
static void equals(char expected, char actual) {
|
||||
equals(expected, actual, DEFAULT_MESSAGE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Equals
|
||||
*
|
||||
* @param expected expected
|
||||
* @param actual actual
|
||||
* @param message message
|
||||
* @since 1.7.0
|
||||
*/
|
||||
static void equals(char expected, char actual, String message) {
|
||||
equals(expected, actual, () -> new AssertionFailedException(message));
|
||||
}
|
||||
|
||||
/**
|
||||
* Equals
|
||||
*
|
||||
* @param expected expected
|
||||
* @param actual actual
|
||||
* @param messageSupplier message supplier
|
||||
* @since 1.7.0
|
||||
*/
|
||||
static void equals(char expected, char actual, Supplier<? extends RuntimeException> messageSupplier) {
|
||||
equals(expected, actual, messageSupplier, () -> {});
|
||||
}
|
||||
|
||||
/**
|
||||
* Equals
|
||||
*
|
||||
* @param expected expected
|
||||
* @param actual actual
|
||||
* @param messageSupplier message supplier
|
||||
* @param runnable runnable
|
||||
* @since 1.7.0
|
||||
*/
|
||||
static void equals(char expected, char actual, Supplier<? extends RuntimeException> messageSupplier, CheckedRunnable runnable) {
|
||||
if (expected != actual) {
|
||||
failNotEqual(expected, actual, messageSupplier, runnable);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Equals
|
||||
*
|
||||
* @param expected expected
|
||||
* @param actual actual
|
||||
* @since 1.7.0
|
||||
*/
|
||||
static void equals(double expected, double actual) {
|
||||
equals(expected, actual, DEFAULT_MESSAGE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Equals
|
||||
*
|
||||
* @param expected expected
|
||||
* @param actual actual
|
||||
* @param message message
|
||||
* @since 1.7.0
|
||||
*/
|
||||
static void equals(double expected, double actual, String message) {
|
||||
equals(expected, actual, () -> new AssertionFailedException(message));
|
||||
}
|
||||
|
||||
/**
|
||||
* Equals
|
||||
*
|
||||
* @param expected expected
|
||||
* @param actual actual
|
||||
* @param messageSupplier message supplier
|
||||
* @since 1.7.0
|
||||
*/
|
||||
static void equals(double expected, double actual, Supplier<? extends RuntimeException> messageSupplier) {
|
||||
if (!AssertUtils.doublesAreEqual(expected, actual)) {
|
||||
failNotEqual(expected, actual, messageSupplier);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Equals
|
||||
*
|
||||
* @param expected expected
|
||||
* @param actual actual
|
||||
* @param delta delta
|
||||
* @since 1.7.0
|
||||
*/
|
||||
static void equals(double expected, double actual, double delta) {
|
||||
equals(expected, actual, delta, DEFAULT_MESSAGE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Equals
|
||||
*
|
||||
* @param expected expected
|
||||
* @param actual actual
|
||||
* @param delta delta
|
||||
* @param message message
|
||||
* @since 1.7.0
|
||||
*/
|
||||
static void equals(double expected, double actual, double delta, String message) {
|
||||
equals(expected, actual, () -> new AssertionFailedException(message));
|
||||
}
|
||||
|
||||
/**
|
||||
* Equals
|
||||
*
|
||||
* @param expected expected
|
||||
* @param actual actual
|
||||
* @param delta delta
|
||||
* @param messageSupplier message supplier
|
||||
* @since 1.7.0
|
||||
*/
|
||||
static void equals(double expected, double actual, double delta, Supplier<? extends RuntimeException> messageSupplier) {
|
||||
if (!AssertUtils.doublesAreEqual(expected, actual, delta)) {
|
||||
failNotEqual(expected, actual, messageSupplier);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Equals
|
||||
*
|
||||
* @param expected expected
|
||||
* @param actual actual
|
||||
* @since 1.7.0
|
||||
*/
|
||||
static void equals(float expected, float actual) {
|
||||
equals(expected, actual, DEFAULT_MESSAGE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Equals
|
||||
*
|
||||
* @param expected expected
|
||||
* @param actual actual
|
||||
* @param message message
|
||||
* @since 1.7.0
|
||||
*/
|
||||
static void equals(float expected, float actual, String message) {
|
||||
equals(expected, actual, () -> new AssertionFailedException(message));
|
||||
}
|
||||
|
||||
/**
|
||||
* Equals
|
||||
*
|
||||
* @param expected expected
|
||||
* @param actual actual
|
||||
* @param messageSupplier message supplier
|
||||
* @since 1.7.0
|
||||
*/
|
||||
static void equals(float expected, float actual, Supplier<? extends RuntimeException> messageSupplier) {
|
||||
if (!AssertUtils.floatsAreEqual(expected, actual)) {
|
||||
failNotEqual(expected, actual, messageSupplier);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Equals
|
||||
*
|
||||
* @param expected expected
|
||||
* @param actual actual
|
||||
* @param delta delta
|
||||
* @since 1.7.0
|
||||
*/
|
||||
static void equals(float expected, float actual, float delta) {
|
||||
equals(expected, actual, delta, DEFAULT_MESSAGE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Equals
|
||||
*
|
||||
* @param expected expected
|
||||
* @param actual actual
|
||||
* @param delta delta
|
||||
* @param message message
|
||||
* @since 1.7.0
|
||||
*/
|
||||
static void equals(float expected, float actual, float delta, String message) {
|
||||
equals(expected, actual, () -> new AssertionFailedException(message));
|
||||
}
|
||||
|
||||
/**
|
||||
* Equals
|
||||
*
|
||||
* @param expected expected
|
||||
* @param actual actual
|
||||
* @param delta delta
|
||||
* @param messageSupplier message supplier
|
||||
* @since 1.7.0
|
||||
*/
|
||||
static void equals(float expected, float actual, float delta, Supplier<? extends RuntimeException> messageSupplier) {
|
||||
if (!AssertUtils.floatsAreEqual(expected, actual, delta)) {
|
||||
failNotEqual(expected, actual, messageSupplier);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Equals
|
||||
*
|
||||
* @param expected expected
|
||||
* @param actual actual
|
||||
* @since 1.7.0
|
||||
*/
|
||||
static void equals(short expected, short actual) {
|
||||
equals(expected, actual, DEFAULT_MESSAGE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Equals
|
||||
*
|
||||
* @param expected expected
|
||||
* @param actual actual
|
||||
* @param message message
|
||||
* @since 1.7.0
|
||||
*/
|
||||
static void equals(short expected, short actual, String message) {
|
||||
equals(expected, actual, () -> new AssertionFailedException(message));
|
||||
}
|
||||
|
||||
/**
|
||||
* Equals
|
||||
*
|
||||
* @param expected expected
|
||||
* @param actual actual
|
||||
* @param messageSupplier message supplier
|
||||
* @since 1.7.0
|
||||
*/
|
||||
static void equals(short expected, short actual, Supplier<? extends RuntimeException> messageSupplier) {
|
||||
if (expected != actual) {
|
||||
failNotEqual(expected, actual, messageSupplier);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Equals
|
||||
*
|
||||
* @param expected expected
|
||||
* @param actual actual
|
||||
* @since 1.7.0
|
||||
*/
|
||||
static void equals(int expected, int actual) {
|
||||
equals(expected, actual, DEFAULT_MESSAGE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Equals
|
||||
*
|
||||
* @param expected expected
|
||||
* @param actual actual
|
||||
* @param message message
|
||||
* @since 1.7.0
|
||||
*/
|
||||
static void equals(int expected, int actual, String message) {
|
||||
equals(expected, actual, () -> new AssertionFailedException(message));
|
||||
}
|
||||
|
||||
/**
|
||||
* Equals
|
||||
*
|
||||
* @param expected expected
|
||||
* @param actual actual
|
||||
* @param messageSupplier message supplier
|
||||
* @since 1.7.0
|
||||
*/
|
||||
static void equals(int expected, int actual, Supplier<? extends RuntimeException> messageSupplier) {
|
||||
if (expected != actual) {
|
||||
failNotEqual(expected, actual, messageSupplier);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Equals
|
||||
*
|
||||
* @param expected expected
|
||||
* @param actual actual
|
||||
* @since 1.7.0
|
||||
*/
|
||||
static void equals(long expected, long actual) {
|
||||
equals(expected, actual, DEFAULT_MESSAGE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Equals
|
||||
*
|
||||
* @param expected expected
|
||||
* @param actual actual
|
||||
* @param message message
|
||||
* @since 1.7.0
|
||||
*/
|
||||
static void equals(long expected, long actual, String message) {
|
||||
equals(expected, actual, () -> new AssertionFailedException(message));
|
||||
}
|
||||
|
||||
/**
|
||||
* Equals
|
||||
*
|
||||
* @param expected expected
|
||||
* @param actual actual
|
||||
* @param messageSupplier message supplier
|
||||
* @since 1.7.0
|
||||
*/
|
||||
static void equals(long expected, long actual, Supplier<? extends RuntimeException> messageSupplier) {
|
||||
if (expected != actual) {
|
||||
failNotEqual(expected, actual, messageSupplier);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Equals
|
||||
*
|
||||
* @param expected expected
|
||||
* @param actual actual
|
||||
* @since 1.7.0
|
||||
*/
|
||||
static void equals(Object expected, Object actual) {
|
||||
equals(expected, actual, DEFAULT_MESSAGE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Equals
|
||||
*
|
||||
* @param expected expected
|
||||
* @param actual actual
|
||||
* @param message message
|
||||
* @since 1.7.0
|
||||
*/
|
||||
static void equals(Object expected, Object actual, String message) {
|
||||
equals(expected, actual, () -> new AssertionFailedException(message));
|
||||
}
|
||||
|
||||
/**
|
||||
* Equals
|
||||
*
|
||||
* @param expected expected
|
||||
* @param actual actual
|
||||
* @param messageSupplier message supplier
|
||||
* @since 1.7.0
|
||||
*/
|
||||
static void equals(Object expected, Object actual, Supplier<? extends RuntimeException> messageSupplier) {
|
||||
if (!AssertUtils.objectsAreEqual(expected, actual)) {
|
||||
failNotEqual(expected, actual, messageSupplier);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Fail not equal
|
||||
*
|
||||
* @param expected expected
|
||||
* @param actual actual
|
||||
* @param messageSupplier message supplier
|
||||
* @since 1.7.0
|
||||
*/
|
||||
@Contract("_, _, _ -> fail")
|
||||
static void failNotEqual(Object expected, Object actual, Supplier<? extends RuntimeException> messageSupplier) {
|
||||
failNotEqual(expected, actual, messageSupplier, () -> {});
|
||||
}
|
||||
|
||||
/**
|
||||
* Fail not equal
|
||||
*
|
||||
* @param expected expected
|
||||
* @param actual actual
|
||||
* @param messageSupplier message supplier
|
||||
* @param runnable runnable
|
||||
* @since 1.7.0
|
||||
*/
|
||||
static void failNotEqual(Object expected,
|
||||
Object actual,
|
||||
Supplier<? extends RuntimeException> messageSupplier,
|
||||
CheckedRunnable runnable) {
|
||||
AssertUtils.fail(messageSupplier, runnable);
|
||||
}
|
||||
|
||||
}
|
||||
+105
@@ -0,0 +1,105 @@
|
||||
package com.aos.element.basic.basic.asserts;
|
||||
|
||||
import com.aos.element.basic.basic.exception.AssertionFailedException;
|
||||
import com.aos.element.basic.core.function.CheckedRunnable;
|
||||
|
||||
import java.util.function.BooleanSupplier;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
/**
|
||||
* <p>Company: 成都返空汇网络技术有限公司 </p>
|
||||
* <p>Description: </p>
|
||||
*
|
||||
* @author dong4j
|
||||
* @version 1.0.0
|
||||
* @email "mailto:dongshijie@fkhwl.com"
|
||||
* @date 2020.11.18 16:55
|
||||
* @since 1.7.0
|
||||
*/
|
||||
final class AssertFalse {
|
||||
/**
|
||||
* Assert false
|
||||
*
|
||||
* @since 1.7.0
|
||||
*/
|
||||
private AssertFalse() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Is false
|
||||
*
|
||||
* @param booleanSupplier boolean supplier
|
||||
* @since 1.7.0
|
||||
*/
|
||||
static void isFalse(BooleanSupplier booleanSupplier) {
|
||||
isFalse(booleanSupplier.getAsBoolean());
|
||||
}
|
||||
|
||||
/**
|
||||
* Is false
|
||||
*
|
||||
* @param booleanSupplier boolean supplier
|
||||
* @param message message
|
||||
* @since 1.7.0
|
||||
*/
|
||||
static void isFalse(BooleanSupplier booleanSupplier, String message) {
|
||||
isFalse(booleanSupplier.getAsBoolean(), message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Is false
|
||||
*
|
||||
* @param booleanSupplier boolean supplier
|
||||
* @param messageSupplier message supplier
|
||||
* @since 1.7.0
|
||||
*/
|
||||
static void isFalse(BooleanSupplier booleanSupplier, Supplier<? extends RuntimeException> messageSupplier) {
|
||||
isFalse(booleanSupplier.getAsBoolean(), messageSupplier);
|
||||
}
|
||||
|
||||
/**
|
||||
* Is true
|
||||
*
|
||||
* @param condition condition
|
||||
* @since 1.7.0
|
||||
*/
|
||||
static void isFalse(boolean condition) {
|
||||
isFalse(condition, "表达式必须是 false");
|
||||
}
|
||||
|
||||
/**
|
||||
* Is true
|
||||
*
|
||||
* @param condition condition
|
||||
* @param message message
|
||||
* @since 1.7.0
|
||||
*/
|
||||
static void isFalse(boolean condition, String message) {
|
||||
isFalse(condition, () -> new AssertionFailedException(message));
|
||||
}
|
||||
|
||||
/**
|
||||
* Is true
|
||||
*
|
||||
* @param condition condition
|
||||
* @param exceptionSupplier exception supplier
|
||||
* @since 1.7.0
|
||||
*/
|
||||
static void isFalse(boolean condition, Supplier<? extends RuntimeException> exceptionSupplier) {
|
||||
isFalse(condition, exceptionSupplier, () -> {});
|
||||
}
|
||||
|
||||
/**
|
||||
* Is false
|
||||
*
|
||||
* @param condition condition
|
||||
* @param exceptionSupplier exception supplier
|
||||
* @param runnable runnable
|
||||
* @since 1.7.0
|
||||
*/
|
||||
static void isFalse(boolean condition, Supplier<? extends RuntimeException> exceptionSupplier, CheckedRunnable runnable) {
|
||||
if (condition) {
|
||||
AssertUtils.fail(exceptionSupplier, runnable);
|
||||
}
|
||||
}
|
||||
}
|
||||
+81
@@ -0,0 +1,81 @@
|
||||
package com.aos.element.basic.basic.asserts;
|
||||
|
||||
import com.aos.element.basic.basic.exception.AssertionFailedException;
|
||||
import com.aos.element.basic.core.function.CheckedRunnable;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* <p>Company: 成都返空汇网络技术有限公司 </p>
|
||||
* <p>Description: </p>
|
||||
*
|
||||
* @author dong4j
|
||||
* @version 1.0.0
|
||||
* @email "mailto:dongshijie@fkhwl.com"
|
||||
* @date 2020.11.18 17:12
|
||||
* @since 1.7.0
|
||||
*/
|
||||
final class AssertMatch {
|
||||
|
||||
/**
|
||||
* Assert not null
|
||||
*
|
||||
* @since 1.7.0
|
||||
*/
|
||||
private AssertMatch() {
|
||||
}
|
||||
|
||||
/**
|
||||
* 编译传入正则表达式和字符串去匹配,忽略大小写
|
||||
*
|
||||
* @param regex 正则
|
||||
* @param beTestString 字符串
|
||||
* @since 1.0.0
|
||||
*/
|
||||
static void isMatch(String regex, String beTestString) {
|
||||
isMatch(regex, beTestString, "字符串无法与指定正则匹配");
|
||||
}
|
||||
|
||||
/**
|
||||
* Is match
|
||||
*
|
||||
* @param regex regex
|
||||
* @param beTestString be test string
|
||||
* @param message message
|
||||
* @since 1.7.0
|
||||
*/
|
||||
static void isMatch(String regex, String beTestString, String message) {
|
||||
isMatch(regex, beTestString, () -> new AssertionFailedException(message));
|
||||
}
|
||||
|
||||
/**
|
||||
* Is match
|
||||
*
|
||||
* @param regex regex
|
||||
* @param beTestString be test string
|
||||
* @param messageSupplier message supplier
|
||||
* @since 1.7.0
|
||||
*/
|
||||
static void isMatch(String regex, String beTestString, Supplier<? extends RuntimeException> messageSupplier) {
|
||||
isMatch(regex, beTestString, messageSupplier, () -> {});
|
||||
}
|
||||
|
||||
/**
|
||||
* Is match
|
||||
*
|
||||
* @param regex regex
|
||||
* @param beTestString be test string
|
||||
* @param messageSupplier message supplier
|
||||
* @param runnable runnable
|
||||
* @since 1.7.0
|
||||
*/
|
||||
static void isMatch(String regex, String beTestString, Supplier<? extends RuntimeException> messageSupplier, CheckedRunnable runnable) {
|
||||
Pattern pattern = Pattern.compile(regex, Pattern.CASE_INSENSITIVE);
|
||||
Matcher matcher = pattern.matcher(beTestString);
|
||||
if (!matcher.matches()) {
|
||||
AssertUtils.fail(messageSupplier, runnable);
|
||||
}
|
||||
}
|
||||
}
|
||||
+417
@@ -0,0 +1,417 @@
|
||||
package com.aos.element.basic.basic.asserts;
|
||||
|
||||
import com.aos.element.basic.basic.exception.AssertionFailedException;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
/**
|
||||
* <p>Company: 成都返空汇网络技术有限公司 </p>
|
||||
* <p>Description: </p>
|
||||
*
|
||||
* @author dong4j
|
||||
* @version 1.0.0
|
||||
* @email "mailto:dongshijie@fkhwl.com"
|
||||
* @date 2020.11.18 18:06
|
||||
* @since 1.7.0
|
||||
*/
|
||||
@SuppressWarnings("all")
|
||||
final class AssertNotEquals {
|
||||
/** DEFAULT_MESSAGE */
|
||||
private static final String DEFAULT_MESSAGE = "2 个参数不能相等";
|
||||
|
||||
/**
|
||||
* Assert not equals
|
||||
*
|
||||
* @since 1.7.0
|
||||
*/
|
||||
private AssertNotEquals() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Not equals
|
||||
*
|
||||
* @param unexpected unexpected
|
||||
* @param actual actual
|
||||
* @since 1.7.0
|
||||
*/
|
||||
static void notEquals(byte unexpected, byte actual) {
|
||||
notEquals(unexpected, actual, DEFAULT_MESSAGE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Not equals
|
||||
*
|
||||
* @param unexpected unexpected
|
||||
* @param actual actual
|
||||
* @param message message
|
||||
* @since 1.7.0
|
||||
*/
|
||||
static void notEquals(byte unexpected, byte actual, String message) {
|
||||
notEquals(unexpected, actual, () -> new AssertionFailedException(message));
|
||||
}
|
||||
|
||||
/**
|
||||
* Not equals
|
||||
*
|
||||
* @param unexpected unexpected
|
||||
* @param actual actual
|
||||
* @param messageSupplier message supplier
|
||||
* @since 1.7.0
|
||||
*/
|
||||
static void notEquals(byte unexpected, byte actual, Supplier<? extends RuntimeException> messageSupplier) {
|
||||
if (unexpected == actual) {
|
||||
failEqual(actual, messageSupplier);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Not equals
|
||||
*
|
||||
* @param unexpected unexpected
|
||||
* @param actual actual
|
||||
* @since 1.7.0
|
||||
*/
|
||||
static void notEquals(short unexpected, short actual) {
|
||||
notEquals(unexpected, actual, DEFAULT_MESSAGE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Not equals
|
||||
*
|
||||
* @param unexpected unexpected
|
||||
* @param actual actual
|
||||
* @param message message
|
||||
* @since 1.7.0
|
||||
*/
|
||||
static void notEquals(short unexpected, short actual, String message) {
|
||||
notEquals(unexpected, actual, () -> new AssertionFailedException(message));
|
||||
}
|
||||
|
||||
/**
|
||||
* Not equals
|
||||
*
|
||||
* @param unexpected unexpected
|
||||
* @param actual actual
|
||||
* @param messageSupplier message supplier
|
||||
* @since 1.7.0
|
||||
*/
|
||||
static void notEquals(short unexpected, short actual, Supplier<? extends RuntimeException> messageSupplier) {
|
||||
if (unexpected == actual) {
|
||||
failEqual(actual, messageSupplier);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Not equals
|
||||
*
|
||||
* @param unexpected unexpected
|
||||
* @param actual actual
|
||||
* @since 1.7.0
|
||||
*/
|
||||
static void notEquals(int unexpected, int actual) {
|
||||
notEquals(unexpected, actual, DEFAULT_MESSAGE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Not equals
|
||||
*
|
||||
* @param unexpected unexpected
|
||||
* @param actual actual
|
||||
* @param message message
|
||||
* @since 1.7.0
|
||||
*/
|
||||
static void notEquals(int unexpected, int actual, String message) {
|
||||
notEquals(unexpected, actual, () -> new AssertionFailedException(message));
|
||||
}
|
||||
|
||||
/**
|
||||
* Not equals
|
||||
*
|
||||
* @param unexpected unexpected
|
||||
* @param actual actual
|
||||
* @param messageSupplier message supplier
|
||||
* @since 1.7.0
|
||||
*/
|
||||
static void notEquals(int unexpected, int actual, Supplier<? extends RuntimeException> messageSupplier) {
|
||||
if (unexpected == actual) {
|
||||
failEqual(actual, messageSupplier);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Not equals
|
||||
*
|
||||
* @param unexpected unexpected
|
||||
* @param actual actual
|
||||
* @since 1.7.0
|
||||
*/
|
||||
static void notEquals(long unexpected, long actual) {
|
||||
notEquals(unexpected, actual, DEFAULT_MESSAGE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Not equals
|
||||
*
|
||||
* @param unexpected unexpected
|
||||
* @param actual actual
|
||||
* @param message message
|
||||
* @since 1.7.0
|
||||
*/
|
||||
static void notEquals(long unexpected, long actual, String message) {
|
||||
notEquals(unexpected, actual, () -> new AssertionFailedException(message));
|
||||
}
|
||||
|
||||
/**
|
||||
* Not equals
|
||||
*
|
||||
* @param unexpected unexpected
|
||||
* @param actual actual
|
||||
* @param messageSupplier message supplier
|
||||
* @since 1.7.0
|
||||
*/
|
||||
static void notEquals(long unexpected, long actual, Supplier<? extends RuntimeException> messageSupplier) {
|
||||
if (unexpected == actual) {
|
||||
failEqual(actual, messageSupplier);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Not equals
|
||||
*
|
||||
* @param unexpected unexpected
|
||||
* @param actual actual
|
||||
* @since 1.7.0
|
||||
*/
|
||||
static void notEquals(float unexpected, float actual) {
|
||||
notEquals(unexpected, actual, DEFAULT_MESSAGE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Not equals
|
||||
*
|
||||
* @param unexpected unexpected
|
||||
* @param actual actual
|
||||
* @param message message
|
||||
* @since 1.7.0
|
||||
*/
|
||||
static void notEquals(float unexpected, float actual, String message) {
|
||||
notEquals(unexpected, actual, () -> new AssertionFailedException(message));
|
||||
}
|
||||
|
||||
/**
|
||||
* Not equals
|
||||
*
|
||||
* @param unexpected unexpected
|
||||
* @param actual actual
|
||||
* @param messageSupplier message supplier
|
||||
* @since 1.7.0
|
||||
*/
|
||||
static void notEquals(float unexpected, float actual, Supplier<? extends RuntimeException> messageSupplier) {
|
||||
if (AssertUtils.floatsAreEqual(unexpected, actual)) {
|
||||
failEqual(actual, messageSupplier);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Not equals
|
||||
*
|
||||
* @param unexpected unexpected
|
||||
* @param actual actual
|
||||
* @param delta delta
|
||||
* @since 1.7.0
|
||||
*/
|
||||
static void notEquals(float unexpected, float actual, float delta) {
|
||||
notEquals(unexpected, actual, delta, DEFAULT_MESSAGE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Not equals
|
||||
*
|
||||
* @param unexpected unexpected
|
||||
* @param actual actual
|
||||
* @param delta delta
|
||||
* @param message message
|
||||
* @since 1.7.0
|
||||
*/
|
||||
static void notEquals(float unexpected, float actual, float delta, String message) {
|
||||
notEquals(unexpected, actual, () -> new AssertionFailedException(message));
|
||||
}
|
||||
|
||||
/**
|
||||
* Not equals
|
||||
*
|
||||
* @param unexpected unexpected
|
||||
* @param actual actual
|
||||
* @param delta delta
|
||||
* @param messageSupplier message supplier
|
||||
* @since 1.7.0
|
||||
*/
|
||||
static void notEquals(float unexpected, float actual, float delta, Supplier<? extends RuntimeException> messageSupplier) {
|
||||
if (AssertUtils.floatsAreEqual(unexpected, actual, delta)) {
|
||||
failEqual(actual, messageSupplier);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Not equals
|
||||
*
|
||||
* @param unexpected unexpected
|
||||
* @param actual actual
|
||||
* @since 1.7.0
|
||||
*/
|
||||
static void notEquals(double unexpected, double actual) {
|
||||
notEquals(unexpected, actual, DEFAULT_MESSAGE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Not equals
|
||||
*
|
||||
* @param unexpected unexpected
|
||||
* @param actual actual
|
||||
* @param message message
|
||||
* @since 1.7.0
|
||||
*/
|
||||
static void notEquals(double unexpected, double actual, String message) {
|
||||
notEquals(unexpected, actual, () -> new AssertionFailedException(message));
|
||||
}
|
||||
|
||||
/**
|
||||
* Not equals
|
||||
*
|
||||
* @param unexpected unexpected
|
||||
* @param actual actual
|
||||
* @param messageSupplier message supplier
|
||||
* @since 1.7.0
|
||||
*/
|
||||
static void notEquals(double unexpected, double actual, Supplier<? extends RuntimeException> messageSupplier) {
|
||||
if (AssertUtils.doublesAreEqual(unexpected, actual)) {
|
||||
failEqual(actual, messageSupplier);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Not equals
|
||||
*
|
||||
* @param unexpected unexpected
|
||||
* @param actual actual
|
||||
* @param delta delta
|
||||
* @since 1.7.0
|
||||
*/
|
||||
static void notEquals(double unexpected, double actual, double delta) {
|
||||
notEquals(unexpected, actual, delta, DEFAULT_MESSAGE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Not equals
|
||||
*
|
||||
* @param unexpected unexpected
|
||||
* @param actual actual
|
||||
* @param delta delta
|
||||
* @param message message
|
||||
* @since 1.7.0
|
||||
*/
|
||||
static void notEquals(double unexpected, double actual, double delta, String message) {
|
||||
notEquals(unexpected, actual, () -> new AssertionFailedException(message));
|
||||
}
|
||||
|
||||
/**
|
||||
* Not equals
|
||||
*
|
||||
* @param unexpected unexpected
|
||||
* @param actual actual
|
||||
* @param delta delta
|
||||
* @param messageSupplier message supplier
|
||||
* @since 1.7.0
|
||||
*/
|
||||
static void notEquals(double unexpected, double actual, double delta, Supplier<? extends RuntimeException> messageSupplier) {
|
||||
if (AssertUtils.doublesAreEqual(unexpected, actual, delta)) {
|
||||
failEqual(actual, messageSupplier);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Not equals
|
||||
*
|
||||
* @param unexpected unexpected
|
||||
* @param actual actual
|
||||
* @since 1.7.0
|
||||
*/
|
||||
static void notEquals(char unexpected, char actual) {
|
||||
notEquals(unexpected, actual, DEFAULT_MESSAGE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Not equals
|
||||
*
|
||||
* @param unexpected unexpected
|
||||
* @param actual actual
|
||||
* @param message message
|
||||
* @since 1.7.0
|
||||
*/
|
||||
static void notEquals(char unexpected, char actual, String message) {
|
||||
notEquals(unexpected, actual, () -> new AssertionFailedException(message));
|
||||
}
|
||||
|
||||
/**
|
||||
* Not equals
|
||||
*
|
||||
* @param unexpected unexpected
|
||||
* @param actual actual
|
||||
* @param messageSupplier message supplier
|
||||
* @since 1.7.0
|
||||
*/
|
||||
static void notEquals(char unexpected, char actual, Supplier<? extends RuntimeException> messageSupplier) {
|
||||
if (unexpected == actual) {
|
||||
failEqual(actual, messageSupplier);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Not equals
|
||||
*
|
||||
* @param unexpected unexpected
|
||||
* @param actual actual
|
||||
* @since 1.7.0
|
||||
*/
|
||||
static void notEquals(Object unexpected, Object actual) {
|
||||
notEquals(unexpected, actual, DEFAULT_MESSAGE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Not equals
|
||||
*
|
||||
* @param unexpected unexpected
|
||||
* @param actual actual
|
||||
* @param message message
|
||||
* @since 1.7.0
|
||||
*/
|
||||
static void notEquals(Object unexpected, Object actual, String message) {
|
||||
notEquals(unexpected, actual, () -> new AssertionFailedException(message));
|
||||
}
|
||||
|
||||
/**
|
||||
* Not equals
|
||||
*
|
||||
* @param unexpected unexpected
|
||||
* @param actual actual
|
||||
* @param messageSupplier message supplier
|
||||
* @since 1.7.0
|
||||
*/
|
||||
static void notEquals(Object unexpected, Object actual, Supplier<? extends RuntimeException> messageSupplier) {
|
||||
if (AssertUtils.objectsAreEqual(unexpected, actual)) {
|
||||
AssertUtils.fail(messageSupplier);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Fail equal
|
||||
*
|
||||
* @param actual actual
|
||||
* @param messageSupplier message supplier
|
||||
* @since 1.7.0
|
||||
*/
|
||||
private static void failEqual(Object actual, Supplier<? extends RuntimeException> messageSupplier) {
|
||||
AssertUtils.fail(messageSupplier);
|
||||
}
|
||||
|
||||
}
|
||||
+82
@@ -0,0 +1,82 @@
|
||||
package com.aos.element.basic.basic.asserts;
|
||||
|
||||
import com.aos.element.basic.basic.exception.AssertionFailedException;
|
||||
import com.aos.element.basic.core.function.CheckedRunnable;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* <p>Company: 成都返空汇网络技术有限公司 </p>
|
||||
* <p>Description: </p>
|
||||
*
|
||||
* @author dong4j
|
||||
* @version 1.0.0
|
||||
* @email "mailto:dongshijie@fkhwl.com"
|
||||
* @date 2020.11.18 17:12
|
||||
* @since 1.7.0
|
||||
*/
|
||||
final class AssertNotMatch {
|
||||
|
||||
/**
|
||||
* Assert not null
|
||||
*
|
||||
* @since 1.7.0
|
||||
*/
|
||||
private AssertNotMatch() {
|
||||
}
|
||||
|
||||
/**
|
||||
* 编译传入正则表达式和字符串去匹配,忽略大小写
|
||||
*
|
||||
* @param regex 正则
|
||||
* @param beTestString 字符串
|
||||
* @since 1.0.0
|
||||
*/
|
||||
static void notMatch(String regex, String beTestString) {
|
||||
notMatch(regex, beTestString, "字符串与指定正则匹配");
|
||||
}
|
||||
|
||||
/**
|
||||
* Is match
|
||||
*
|
||||
* @param regex regex
|
||||
* @param beTestString be test string
|
||||
* @param message message
|
||||
* @since 1.7.0
|
||||
*/
|
||||
static void notMatch(String regex, String beTestString, String message) {
|
||||
notMatch(regex, beTestString, () -> new AssertionFailedException(message));
|
||||
}
|
||||
|
||||
/**
|
||||
* Is match
|
||||
*
|
||||
* @param regex regex
|
||||
* @param beTestString be test string
|
||||
* @param messageSupplier message supplier
|
||||
* @since 1.7.0
|
||||
*/
|
||||
static void notMatch(String regex, String beTestString, Supplier<? extends RuntimeException> messageSupplier) {
|
||||
notMatch(regex, beTestString, messageSupplier, () -> {});
|
||||
}
|
||||
|
||||
/**
|
||||
* Is match
|
||||
*
|
||||
* @param regex regex
|
||||
* @param beTestString be test string
|
||||
* @param messageSupplier message supplier
|
||||
* @param runnable runnable
|
||||
* @since 1.7.0
|
||||
*/
|
||||
static void notMatch(String regex, String beTestString, Supplier<? extends RuntimeException> messageSupplier,
|
||||
CheckedRunnable runnable) {
|
||||
Pattern pattern = Pattern.compile(regex, Pattern.CASE_INSENSITIVE);
|
||||
Matcher matcher = pattern.matcher(beTestString);
|
||||
if (matcher.matches()) {
|
||||
AssertUtils.fail(messageSupplier, runnable);
|
||||
}
|
||||
}
|
||||
}
|
||||
+76
@@ -0,0 +1,76 @@
|
||||
package com.aos.element.basic.basic.asserts;
|
||||
|
||||
import com.aos.element.basic.basic.exception.AssertionFailedException;
|
||||
import com.aos.element.basic.core.function.CheckedRunnable;
|
||||
|
||||
import org.springframework.lang.Nullable;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
/**
|
||||
* <p>Company: 成都返空汇网络技术有限公司 </p>
|
||||
* <p>Description: </p>
|
||||
*
|
||||
* @author dong4j
|
||||
* @version 1.0.0
|
||||
* @email "mailto:dongshijie@fkhwl.com"
|
||||
* @date 2020.11.18 17:12
|
||||
* @since 1.7.0
|
||||
*/
|
||||
final class AssertNotNull {
|
||||
|
||||
/**
|
||||
* Assert not null
|
||||
*
|
||||
* @since 1.7.0
|
||||
*/
|
||||
private AssertNotNull() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Not null
|
||||
*
|
||||
* @param actual actual
|
||||
* @since 1.7.0
|
||||
*/
|
||||
static void notNull(Object actual) {
|
||||
notNull(actual, "参数不能为 null");
|
||||
}
|
||||
|
||||
/**
|
||||
* Not null
|
||||
*
|
||||
* @param actual actual
|
||||
* @param message message
|
||||
* @since 1.7.0
|
||||
*/
|
||||
static void notNull(Object actual, String message) {
|
||||
notNull(actual, () -> new AssertionFailedException(message));
|
||||
}
|
||||
|
||||
/**
|
||||
* Not null
|
||||
*
|
||||
* @param actual actual
|
||||
* @param messageSupplier message supplier
|
||||
* @since 1.7.0
|
||||
*/
|
||||
static void notNull(Object actual, Supplier<? extends RuntimeException> messageSupplier) {
|
||||
notNull(actual, messageSupplier, () -> {});
|
||||
}
|
||||
|
||||
/**
|
||||
* Not null
|
||||
*
|
||||
* @param object object
|
||||
* @param exceptionSupplier exception supplier
|
||||
* @param runnable runnable
|
||||
* @since 1.7.0
|
||||
*/
|
||||
static void notNull(@Nullable Object object, Supplier<? extends RuntimeException> exceptionSupplier, CheckedRunnable runnable) {
|
||||
if (object == null) {
|
||||
AssertUtils.fail(exceptionSupplier, runnable);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
+75
@@ -0,0 +1,75 @@
|
||||
package com.aos.element.basic.basic.asserts;
|
||||
|
||||
import com.aos.element.basic.basic.exception.AssertionFailedException;
|
||||
import com.aos.element.basic.core.function.CheckedRunnable;
|
||||
|
||||
import org.springframework.lang.Nullable;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
/**
|
||||
* <p>Company: 成都返空汇网络技术有限公司 </p>
|
||||
* <p>Description: </p>
|
||||
*
|
||||
* @author dong4j
|
||||
* @version 1.0.0
|
||||
* @email "mailto:dongshijie@fkhwl.com"
|
||||
* @date 2020.11.18 17:03
|
||||
* @since 1.7.0
|
||||
*/
|
||||
final class AssertNull {
|
||||
|
||||
/**
|
||||
* Assert null
|
||||
*
|
||||
* @since 1.7.0
|
||||
*/
|
||||
private AssertNull() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Is null
|
||||
*
|
||||
* @param object object
|
||||
* @since 1.6.0
|
||||
*/
|
||||
static void isNull(@Nullable Object object) {
|
||||
isNull(object, "参数必须是 null");
|
||||
}
|
||||
|
||||
/**
|
||||
* Is null
|
||||
*
|
||||
* @param object object
|
||||
* @param message message
|
||||
* @since 1.6.0
|
||||
*/
|
||||
static void isNull(@Nullable Object object, String message) {
|
||||
isNull(object, () -> new AssertionFailedException(message));
|
||||
}
|
||||
|
||||
/**
|
||||
* Is null
|
||||
*
|
||||
* @param object object
|
||||
* @param exceptionSupplier message supplier
|
||||
* @since 1.6.0
|
||||
*/
|
||||
static void isNull(@Nullable Object object, Supplier<? extends RuntimeException> exceptionSupplier) {
|
||||
isNull(object, exceptionSupplier, () -> {});
|
||||
}
|
||||
|
||||
/**
|
||||
* Is null
|
||||
*
|
||||
* @param object object
|
||||
* @param exceptionSupplier exception supplier
|
||||
* @param runnable runnable
|
||||
* @since 1.7.0
|
||||
*/
|
||||
static void isNull(@Nullable Object object, Supplier<? extends RuntimeException> exceptionSupplier, CheckedRunnable runnable) {
|
||||
if (object != null) {
|
||||
AssertUtils.fail(exceptionSupplier, runnable);
|
||||
}
|
||||
}
|
||||
}
|
||||
+106
@@ -0,0 +1,106 @@
|
||||
package com.aos.element.basic.basic.asserts;
|
||||
|
||||
import com.aos.element.basic.basic.exception.AssertionFailedException;
|
||||
import com.aos.element.basic.core.function.CheckedRunnable;
|
||||
|
||||
import java.util.function.BooleanSupplier;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
/**
|
||||
* <p>Company: 成都返空汇网络技术有限公司 </p>
|
||||
* <p>Description: </p>
|
||||
*
|
||||
* @author dong4j
|
||||
* @version 1.0.0
|
||||
* @email "mailto:dongshijie@fkhwl.com"
|
||||
* @date 2020.11.18 00:26
|
||||
* @since 1.7.0
|
||||
*/
|
||||
final class AssertTrue {
|
||||
/**
|
||||
* Assert true
|
||||
*
|
||||
* @since 1.7.0
|
||||
*/
|
||||
private AssertTrue() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Is true
|
||||
*
|
||||
* @param booleanSupplier boolean supplier
|
||||
* @since 1.7.0
|
||||
*/
|
||||
static void isTrue(BooleanSupplier booleanSupplier) {
|
||||
isTrue(booleanSupplier.getAsBoolean());
|
||||
}
|
||||
|
||||
/**
|
||||
* Is true
|
||||
*
|
||||
* @param booleanSupplier boolean supplier
|
||||
* @param message message
|
||||
* @since 1.7.0
|
||||
*/
|
||||
static void isTrue(BooleanSupplier booleanSupplier, String message) {
|
||||
isTrue(booleanSupplier.getAsBoolean(), message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Is true
|
||||
*
|
||||
* @param booleanSupplier boolean supplier
|
||||
* @param exceptionSupplier message supplier
|
||||
* @since 1.7.0
|
||||
*/
|
||||
static void isTrue(BooleanSupplier booleanSupplier, Supplier<? extends RuntimeException> exceptionSupplier) {
|
||||
isTrue(booleanSupplier.getAsBoolean(), exceptionSupplier);
|
||||
}
|
||||
|
||||
/**
|
||||
* Is true
|
||||
*
|
||||
* @param condition condition
|
||||
* @since 1.6.0
|
||||
*/
|
||||
static void isTrue(boolean condition) {
|
||||
isTrue(condition, "表达式必须是 true");
|
||||
}
|
||||
|
||||
/**
|
||||
* Is true
|
||||
*
|
||||
* @param condition condition
|
||||
* @param message message
|
||||
* @since 1.6.0
|
||||
*/
|
||||
static void isTrue(boolean condition, String message) {
|
||||
isTrue(condition, () -> new AssertionFailedException(message));
|
||||
}
|
||||
|
||||
/**
|
||||
* Is true
|
||||
*
|
||||
* @param condition condition
|
||||
* @param exceptionSupplier exception supplier
|
||||
* @since 1.6.0
|
||||
*/
|
||||
static void isTrue(boolean condition, Supplier<? extends RuntimeException> exceptionSupplier) {
|
||||
isTrue(condition, exceptionSupplier, () -> {});
|
||||
}
|
||||
|
||||
/**
|
||||
* Is true
|
||||
*
|
||||
* @param condition condition
|
||||
* @param exceptionSupplier exception supplier
|
||||
* @param runnable runnable
|
||||
* @since 1.7.0
|
||||
*/
|
||||
static void isTrue(boolean condition, Supplier<? extends RuntimeException> exceptionSupplier, CheckedRunnable runnable) {
|
||||
if (!condition) {
|
||||
AssertUtils.fail(exceptionSupplier, runnable);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
+248
@@ -0,0 +1,248 @@
|
||||
package com.aos.element.basic.basic.asserts;
|
||||
|
||||
import com.aos.element.basic.basic.exception.AssertionFailedException;
|
||||
import com.aos.element.basic.basic.exception.BasicException;
|
||||
import com.aos.element.basic.core.function.CheckedRunnable;
|
||||
|
||||
import org.jetbrains.annotations.Contract;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import lombok.SneakyThrows;
|
||||
import lombok.experimental.UtilityClass;
|
||||
|
||||
/**
|
||||
* <p>Company: 成都返空汇网络技术有限公司</p>
|
||||
* <p>Description: </p>
|
||||
*
|
||||
* @author dong4j
|
||||
* @version 1.0.0
|
||||
* @email "mailto:dongshijie@fkhwl.com"
|
||||
* @date 2020.11.18 17:19
|
||||
* @since 1.7.0
|
||||
*/
|
||||
@UtilityClass
|
||||
@SuppressWarnings("all")
|
||||
class AssertUtils {
|
||||
|
||||
/**
|
||||
* Fail
|
||||
*
|
||||
* @param message message
|
||||
* @since 1.6.0
|
||||
*/
|
||||
@Contract("_ -> fail")
|
||||
static void fail(String message) {
|
||||
fail(() -> new AssertionFailedException(message));
|
||||
}
|
||||
|
||||
/**
|
||||
* Fail
|
||||
*
|
||||
* @param exceptionSupplier exception supplier
|
||||
* @since 1.6.0
|
||||
*/
|
||||
@Contract("_ -> fail")
|
||||
@SneakyThrows
|
||||
static void fail(Supplier<? extends RuntimeException> exceptionSupplier) {
|
||||
throw nullSafeGetException(exceptionSupplier);
|
||||
}
|
||||
|
||||
/**
|
||||
* Fail
|
||||
*
|
||||
* @param exceptionSupplier exception supplier
|
||||
* @param runnable runnable
|
||||
* @since 1.7.0
|
||||
*/
|
||||
@SneakyThrows
|
||||
static void fail(Supplier<? extends RuntimeException> exceptionSupplier, CheckedRunnable runnable) {
|
||||
try {
|
||||
runnable.run();
|
||||
} catch (Throwable throwable) {
|
||||
throw nullSafeGetException(exceptionSupplier).initCause(throwable);
|
||||
}
|
||||
|
||||
throw nullSafeGetException(exceptionSupplier);
|
||||
}
|
||||
|
||||
/**
|
||||
* Null safe get exception
|
||||
*
|
||||
* @param exceptionSupplier message supplier
|
||||
* @return the exception
|
||||
* @since 1.6.0
|
||||
*/
|
||||
@Contract("null -> new")
|
||||
static Exception nullSafeGetException(@Nullable Supplier<? extends RuntimeException> exceptionSupplier) {
|
||||
return (exceptionSupplier != null ? exceptionSupplier.get() : new AssertionFailedException());
|
||||
}
|
||||
|
||||
/**
|
||||
* Instance check failed
|
||||
*
|
||||
* @param type type
|
||||
* @param obj obj
|
||||
* @param message message
|
||||
* @since 1.6.0
|
||||
*/
|
||||
static void instanceCheckFailed(Class<?> type, @Nullable Object obj, @Nullable String message) {
|
||||
String className = (obj != null ? obj.getClass().getName() : "null");
|
||||
String result = "";
|
||||
boolean defaultMessage = true;
|
||||
if (StringUtils.hasLength(message)) {
|
||||
if (endsWithSeparator(message)) {
|
||||
result = message + " ";
|
||||
} else {
|
||||
result = messageWithTypeName(message, className);
|
||||
defaultMessage = false;
|
||||
}
|
||||
}
|
||||
if (defaultMessage) {
|
||||
result = result + ("Object 类型 [" + className + "] 不是: " + type);
|
||||
}
|
||||
throw new BasicException(result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Assignable check failed
|
||||
*
|
||||
* @param superType super type
|
||||
* @param subType sub type
|
||||
* @param message message
|
||||
* @since 1.6.0
|
||||
*/
|
||||
static void assignableCheckFailed(Class<?> superType, @Nullable Class<?> subType, @Nullable String message) {
|
||||
String result = "";
|
||||
boolean defaultMessage = true;
|
||||
if (StringUtils.hasLength(message)) {
|
||||
if (endsWithSeparator(message)) {
|
||||
result = message + " ";
|
||||
} else {
|
||||
result = messageWithTypeName(message, subType);
|
||||
defaultMessage = false;
|
||||
}
|
||||
}
|
||||
if (defaultMessage) {
|
||||
result = result + (subType + " 不是 " + superType + "的子类");
|
||||
}
|
||||
throw new BasicException(result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Ends with separator
|
||||
*
|
||||
* @param message message
|
||||
* @return the boolean
|
||||
* @since 1.6.0
|
||||
*/
|
||||
static boolean endsWithSeparator(@NotNull String message) {
|
||||
return (message.endsWith(":") || message.endsWith(";") || message.endsWith(",") || message.endsWith("."));
|
||||
}
|
||||
|
||||
/**
|
||||
* Message with type name
|
||||
*
|
||||
* @param message message
|
||||
* @param typeName type name
|
||||
* @return the string
|
||||
* @since 1.6.0
|
||||
*/
|
||||
@Contract(pure = true)
|
||||
static @NotNull String messageWithTypeName(@NotNull String message, @Nullable Object typeName) {
|
||||
return message + (message.endsWith(" ") ? "" : ": ") + typeName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Floats are equal
|
||||
*
|
||||
* @param value1 value 1
|
||||
* @param value2 value 2
|
||||
* @return the boolean
|
||||
* @since 1.7.0
|
||||
*/
|
||||
static boolean floatsAreEqual(float value1, float value2) {
|
||||
return Float.floatToIntBits(value1) == Float.floatToIntBits(value2);
|
||||
}
|
||||
|
||||
/**
|
||||
* Floats are equal
|
||||
*
|
||||
* @param value1 value 1
|
||||
* @param value2 value 2
|
||||
* @param delta delta
|
||||
* @return the boolean
|
||||
* @since 1.7.0
|
||||
*/
|
||||
static boolean floatsAreEqual(float value1, float value2, float delta) {
|
||||
assertValidDelta(delta);
|
||||
return floatsAreEqual(value1, value2) || Math.abs(value1 - value2) <= delta;
|
||||
}
|
||||
|
||||
/**
|
||||
* Doubles are equal
|
||||
*
|
||||
* @param value1 value 1
|
||||
* @param value2 value 2
|
||||
* @param delta delta
|
||||
* @return the boolean
|
||||
* @since 1.7.0
|
||||
*/
|
||||
static boolean doublesAreEqual(double value1, double value2, double delta) {
|
||||
assertValidDelta(delta);
|
||||
return doublesAreEqual(value1, value2) || Math.abs(value1 - value2) <= delta;
|
||||
}
|
||||
|
||||
/**
|
||||
* Assert valid delta
|
||||
*
|
||||
* @param delta delta
|
||||
* @since 1.7.0
|
||||
*/
|
||||
static void assertValidDelta(double delta) {
|
||||
if (Double.isNaN(delta) || delta < 0.0) {
|
||||
failIllegalDelta(String.valueOf(delta));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Fail illegal delta
|
||||
*
|
||||
* @param delta delta
|
||||
* @since 1.7.0
|
||||
*/
|
||||
private static void failIllegalDelta(String delta) {
|
||||
fail("positive delta expected but was: <" + delta + ">");
|
||||
}
|
||||
|
||||
/**
|
||||
* Doubles are equal
|
||||
*
|
||||
* @param value1 value 1
|
||||
* @param value2 value 2
|
||||
* @return the boolean
|
||||
* @since 1.7.0
|
||||
*/
|
||||
static boolean doublesAreEqual(double value1, double value2) {
|
||||
return Double.doubleToLongBits(value1) == Double.doubleToLongBits(value2);
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断 2 个对象是否相等
|
||||
*
|
||||
* @param o1 待判断对象, 同时为 null 则为 true
|
||||
* @param o2 待判断对象
|
||||
* @return the boolean
|
||||
* @since 1.7.0
|
||||
*/
|
||||
@Contract(value = "null, null -> true; null, !null -> false", pure = true)
|
||||
static boolean objectsAreEqual(Object o1, Object o2) {
|
||||
if (o1 == null) {
|
||||
return (o2 == null);
|
||||
}
|
||||
return o1.equals(o2);
|
||||
}
|
||||
}
|
||||
+1518
File diff suppressed because it is too large
Load Diff
+241
@@ -0,0 +1,241 @@
|
||||
package com.aos.element.basic.basic.bundle;
|
||||
|
||||
import com.aos.element.basic.basic.support.ConcurrentFactoryMap;
|
||||
import com.aos.element.basic.basic.support.ConcurrentSoftValueHashMap;
|
||||
import com.aos.element.basic.basic.support.SoftReference;
|
||||
|
||||
import org.jetbrains.annotations.Contract;
|
||||
import org.jetbrains.annotations.Nls;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.lang.ref.Reference;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.MissingResourceException;
|
||||
import java.util.ResourceBundle;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
/**
|
||||
* <p>Company: 成都返空汇网络技术有限公司 </p>
|
||||
* <p>Description: 国际化配置文件绑定抽象类 </p>
|
||||
*
|
||||
* @author dong4j
|
||||
* @version 1.0.0
|
||||
* @email "mailto:dongshijie@fkhwl.com"
|
||||
* @date 2020.05.19 10:22
|
||||
* @since 1.4.0
|
||||
*/
|
||||
@Slf4j
|
||||
public abstract class AbstractBundle {
|
||||
/** ourCache */
|
||||
private static final Map<ClassLoader, Map<String, ResourceBundle>> CACHE =
|
||||
ConcurrentFactoryMap.createWeakMap(k -> new ConcurrentSoftValueHashMap<>());
|
||||
/** My path to bundle */
|
||||
@NonNls
|
||||
private final String myPathToBundle;
|
||||
/** My bundle */
|
||||
private Reference<ResourceBundle> myBundle;
|
||||
|
||||
/**
|
||||
* Abstract bundle
|
||||
*
|
||||
* @param pathToBundle path to bundle
|
||||
* @since 1.4.0
|
||||
*/
|
||||
@Contract(pure = true)
|
||||
protected AbstractBundle(@NonNls @NotNull String pathToBundle) {
|
||||
this.myPathToBundle = pathToBundle;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets lazy message *
|
||||
*
|
||||
* @param key key
|
||||
* @param params params
|
||||
* @return the lazy message
|
||||
* @since 1.4.0
|
||||
*/
|
||||
@NotNull
|
||||
public Supplier<String> getLazyMessage(@NotNull String key, Object... params) {
|
||||
return () -> this.getMessage(key, params);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets message *
|
||||
*
|
||||
* @param key key
|
||||
* @param params params
|
||||
* @return the message
|
||||
* @since 1.4.0
|
||||
*/
|
||||
@NotNull
|
||||
public String getMessage(@NotNull String key, Object... params) {
|
||||
return message(this.getResourceBundle(), key, params);
|
||||
}
|
||||
|
||||
/**
|
||||
* Message
|
||||
*
|
||||
* @param bundle bundle
|
||||
* @param key key
|
||||
* @param params params
|
||||
* @return the string
|
||||
* @since 1.4.0
|
||||
*/
|
||||
@Nls
|
||||
@NotNull
|
||||
public static String message(@NotNull ResourceBundle bundle, @NotNull String key, Object... params) {
|
||||
return BundleBase.message(bundle, key, params);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets resource bundle *
|
||||
*
|
||||
* @return the resource bundle
|
||||
* @since 1.4.0
|
||||
*/
|
||||
public ResourceBundle getResourceBundle() {
|
||||
return this.getResourceBundle(null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets resource bundle *
|
||||
*
|
||||
* @param classLoader class loader
|
||||
* @return the resource bundle
|
||||
* @since 1.4.0
|
||||
*/
|
||||
@NotNull
|
||||
protected ResourceBundle getResourceBundle(@Nullable ClassLoader classLoader) {
|
||||
ResourceBundle bundle = SoftReference.dereference(this.myBundle);
|
||||
if (bundle == null) {
|
||||
bundle = this.getResourceBundle(this.myPathToBundle, classLoader == null ? this.getClass().getClassLoader() : classLoader);
|
||||
this.myBundle = new SoftReference<>(bundle);
|
||||
}
|
||||
return bundle;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets resource bundle *
|
||||
*
|
||||
* @param pathToBundle path to bundle
|
||||
* @param loader loader
|
||||
* @return the resource bundle
|
||||
* @since 1.4.0
|
||||
*/
|
||||
@NotNull
|
||||
public ResourceBundle getResourceBundle(@NotNull String pathToBundle, @NotNull ClassLoader loader) {
|
||||
Map<String, ResourceBundle> map = CACHE.get(loader);
|
||||
ResourceBundle result = map.get(pathToBundle);
|
||||
if (result == null) {
|
||||
try {
|
||||
ResourceBundle.Control control = ResourceBundle.Control.getControl(ResourceBundle.Control.FORMAT_PROPERTIES);
|
||||
result = this.findBundle(pathToBundle, loader, control);
|
||||
} catch (MissingResourceException e) {
|
||||
log.info("Cannot load resource bundle from *.properties file, falling back to slow class loading: " + pathToBundle);
|
||||
ResourceBundle.clearCache(loader);
|
||||
result = ResourceBundle.getBundle(pathToBundle, Locale.getDefault(), loader);
|
||||
}
|
||||
map.put(pathToBundle, result);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Find bundle
|
||||
*
|
||||
* @param pathToBundle path to bundle
|
||||
* @param loader loader
|
||||
* @param control control
|
||||
* @return the resource bundle
|
||||
* @since 1.4.0
|
||||
*/
|
||||
protected ResourceBundle findBundle(@NotNull String pathToBundle, @NotNull ClassLoader loader,
|
||||
@NotNull ResourceBundle.Control control) {
|
||||
return ResourceBundle.getBundle(pathToBundle, Locale.getDefault(), loader, control);
|
||||
}
|
||||
|
||||
/**
|
||||
* Message of null
|
||||
*
|
||||
* @param key key
|
||||
* @param params params
|
||||
* @return the string
|
||||
* @since 1.4.0
|
||||
*/
|
||||
@Nullable
|
||||
public String messageOfNull(@NotNull String key, Object... params) {
|
||||
return messageOrNull(this.getResourceBundle(), key, params);
|
||||
}
|
||||
|
||||
/**
|
||||
* Message or null
|
||||
*
|
||||
* @param bundle bundle
|
||||
* @param key key
|
||||
* @param params params
|
||||
* @return the string
|
||||
* @since 1.4.0
|
||||
*/
|
||||
@Nullable
|
||||
public static String messageOrNull(@NotNull ResourceBundle bundle, @NotNull String key, Object... params) {
|
||||
String value = messageOrDefault(bundle, key, key, params);
|
||||
if (key.equals(value)) {
|
||||
return null;
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Message or default
|
||||
*
|
||||
* @param bundle bundle
|
||||
* @param key key
|
||||
* @param defaultValue default value
|
||||
* @param params params
|
||||
* @return the string
|
||||
* @since 1.4.0
|
||||
*/
|
||||
@Contract("null, _, _, _ -> param3")
|
||||
public static String messageOrDefault(@Nullable ResourceBundle bundle,
|
||||
@NotNull String key,
|
||||
@Nullable String defaultValue,
|
||||
Object... params) {
|
||||
if (bundle == null) {
|
||||
return defaultValue;
|
||||
} else if (!bundle.containsKey(key)) {
|
||||
return BundleBase.postprocessValue(bundle, BundleBase.useDefaultValue(bundle, key, defaultValue), params);
|
||||
}
|
||||
return BundleBase.messageOrDefault(bundle, key, defaultValue, params);
|
||||
}
|
||||
|
||||
/**
|
||||
* Message or default
|
||||
*
|
||||
* @param key key
|
||||
* @param defaultValue default value
|
||||
* @param params params
|
||||
* @return the string
|
||||
* @since 1.4.0
|
||||
*/
|
||||
public String messageOrDefault(@NotNull String key,
|
||||
@Nullable String defaultValue,
|
||||
Object... params) {
|
||||
return messageOrDefault(this.getResourceBundle(), key, defaultValue, params);
|
||||
}
|
||||
|
||||
/**
|
||||
* Contains key
|
||||
*
|
||||
* @param key key
|
||||
* @return the boolean
|
||||
* @since 1.4.0
|
||||
*/
|
||||
public boolean containsKey(@NotNull String key) {
|
||||
return this.getResourceBundle().containsKey(key);
|
||||
}
|
||||
}
|
||||
+211
@@ -0,0 +1,211 @@
|
||||
package com.aos.element.basic.basic.bundle;
|
||||
|
||||
import com.aos.element.basic.basic.support.OrdinalFormat;
|
||||
import com.aos.element.basic.basic.support.StrFormatter;
|
||||
import com.aos.element.basic.basic.support.SystemInfoRt;
|
||||
|
||||
import org.jetbrains.annotations.Contract;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.text.MessageFormat;
|
||||
import java.util.Locale;
|
||||
import java.util.MissingResourceException;
|
||||
import java.util.ResourceBundle;
|
||||
|
||||
/**
|
||||
* <p>Company: 成都返空汇网络技术有限公司 </p>
|
||||
* <p>Description: 国际化配置文件绑定基类</p>
|
||||
*
|
||||
* @author dong4j
|
||||
* @version 1.0.0
|
||||
* @email "mailto:dongshijie@fkhwl.com"
|
||||
* @date 2020.05.19 09:44
|
||||
* @since 1.4.0
|
||||
*/
|
||||
@SuppressWarnings("java:S1118")
|
||||
public abstract class BundleBase {
|
||||
|
||||
/** MNEMONIC */
|
||||
public static final char MNEMONIC = 0x1B;
|
||||
/** MNEMONIC_STRING */
|
||||
public static final String MNEMONIC_STRING = Character.toString(MNEMONIC);
|
||||
/** L10N_MARKER */
|
||||
public static final String L10N_MARKER = "";
|
||||
/** SHOW_LOCALIZED_MESSAGES */
|
||||
public static final boolean SHOW_LOCALIZED_MESSAGES = Boolean.getBoolean("idea.l10n");
|
||||
/** SUFFIXES */
|
||||
private static final String[] SUFFIXES = {"</body></html>", "</html>"};
|
||||
/** assertOnMissedKeys */
|
||||
private static boolean assertOnMissedKeys = true;
|
||||
|
||||
/**
|
||||
* Assert on missed keys
|
||||
*
|
||||
* @param doAssert do assert
|
||||
* @since 1.4.0
|
||||
*/
|
||||
public static void assertOnMissedKeys(boolean doAssert) {
|
||||
assertOnMissedKeys = doAssert;
|
||||
}
|
||||
|
||||
/**
|
||||
* Message
|
||||
*
|
||||
* @param bundle bundle
|
||||
* @param key key
|
||||
* @param params params
|
||||
* @return the string
|
||||
* @since 1.4.0
|
||||
*/
|
||||
@NotNull
|
||||
public static String message(@NotNull ResourceBundle bundle, @NotNull String key, @NotNull Object... params) {
|
||||
return messageOrDefault(bundle, key, null, params);
|
||||
}
|
||||
|
||||
/**
|
||||
* Message or default
|
||||
*
|
||||
* @param bundle bundle
|
||||
* @param key key
|
||||
* @param defaultValue default value
|
||||
* @param params params
|
||||
* @return the string
|
||||
* @since 1.4.0
|
||||
*/
|
||||
@Contract("null, _, _, _ -> param3")
|
||||
public static String messageOrDefault(@Nullable ResourceBundle bundle,
|
||||
@NotNull String key,
|
||||
@Nullable String defaultValue,
|
||||
@NotNull Object... params) {
|
||||
if (bundle != null) {
|
||||
String value;
|
||||
try {
|
||||
value = bundle.getString(key);
|
||||
} catch (MissingResourceException e) {
|
||||
value = useDefaultValue(bundle, key, defaultValue);
|
||||
}
|
||||
|
||||
String result = postprocessValue(bundle, value, params);
|
||||
|
||||
if (SHOW_LOCALIZED_MESSAGES) {
|
||||
return appendLocalizationMarker(result);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* Use default value
|
||||
*
|
||||
* @param bundle bundle
|
||||
* @param key key
|
||||
* @param defaultValue default value
|
||||
* @return the string
|
||||
* @since 1.4.0
|
||||
*/
|
||||
@Contract(value = "_, _, !null -> param3", pure = true)
|
||||
@NotNull
|
||||
static String useDefaultValue(ResourceBundle bundle, @NotNull String key, @Nullable String defaultValue) {
|
||||
if (defaultValue != null) {
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
if (assertOnMissedKeys) {
|
||||
return "'" + key + "' is not found in " + bundle.getBaseBundleName();
|
||||
}
|
||||
return "!" + key + "!";
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理占位符, 同时兼容 {} 和 {0} 格式
|
||||
*
|
||||
* @param bundle bundle
|
||||
* @param value value
|
||||
* @param params params
|
||||
* @return the string
|
||||
* @since 1.4.0
|
||||
*/
|
||||
static String postprocessValue(@NotNull ResourceBundle bundle, @NotNull String value, @NotNull Object[] params) {
|
||||
value = replaceMnemonicAmpersand(value);
|
||||
|
||||
if (params.length > 0 && value.indexOf('{') >= 0) {
|
||||
if (value.contains("{0")) {
|
||||
Locale locale = bundle.getLocale();
|
||||
try {
|
||||
MessageFormat format = locale != null ? new MessageFormat(value, locale) : new MessageFormat(value);
|
||||
OrdinalFormat.apply(format);
|
||||
value = format.format(params);
|
||||
} catch (IllegalArgumentException e) {
|
||||
value = "!invalid format: `" + value + "`!";
|
||||
}
|
||||
} else {
|
||||
value = StrFormatter.format(value, params);
|
||||
}
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Append localization marker
|
||||
*
|
||||
* @param result result
|
||||
* @return the string
|
||||
* @since 1.4.0
|
||||
*/
|
||||
@NotNull
|
||||
protected static String appendLocalizationMarker(@NotNull String result) {
|
||||
for (String suffix : SUFFIXES) {
|
||||
if (result.endsWith(suffix)) {
|
||||
return result.substring(0, result.length() - suffix.length()) + L10N_MARKER + suffix;
|
||||
}
|
||||
}
|
||||
return result + L10N_MARKER;
|
||||
}
|
||||
|
||||
/**
|
||||
* Replace mnemonic ampersand
|
||||
*
|
||||
* @param value value
|
||||
* @return the string
|
||||
* @since 1.4.0
|
||||
*/
|
||||
@Contract("null -> null")
|
||||
@SuppressWarnings("java:S3776")
|
||||
public static String replaceMnemonicAmpersand(@Nullable String value) {
|
||||
if (value == null || value.indexOf('&') < 0) {
|
||||
return value;
|
||||
}
|
||||
|
||||
StringBuilder builder = new StringBuilder();
|
||||
boolean macMnemonic = value.contains("&&");
|
||||
int i = 0;
|
||||
while (i < value.length()) {
|
||||
char c = value.charAt(i);
|
||||
if (c == '\\') {
|
||||
if (i < value.length() - 1 && value.charAt(i + 1) == '&') {
|
||||
builder.append('&');
|
||||
i++;
|
||||
} else {
|
||||
builder.append(c);
|
||||
}
|
||||
} else if (c == '&') {
|
||||
if (i < value.length() - 1 && value.charAt(i + 1) == '&') {
|
||||
if (SystemInfoRt.IS_MAC) {
|
||||
builder.append(MNEMONIC);
|
||||
}
|
||||
i++;
|
||||
} else if (!SystemInfoRt.IS_MAC || !macMnemonic) {
|
||||
builder.append(MNEMONIC);
|
||||
}
|
||||
} else {
|
||||
builder.append(c);
|
||||
}
|
||||
i++;
|
||||
}
|
||||
return builder.toString();
|
||||
}
|
||||
}
|
||||
+97
@@ -0,0 +1,97 @@
|
||||
package com.aos.element.basic.basic.bundle;
|
||||
|
||||
import org.jetbrains.annotations.Contract;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Locale;
|
||||
import java.util.ResourceBundle;
|
||||
|
||||
import lombok.experimental.UtilityClass;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
/**
|
||||
* <p>Company: 成都返空汇网络技术有限公司 </p>
|
||||
* <p>Description: 国际化配置文件绑定工具类 </p>
|
||||
*
|
||||
* @author dong4j
|
||||
* @version 1.0.0
|
||||
* @email "mailto:dongshijie@fkhwl.com"
|
||||
* @date 2020.05.19 09:40
|
||||
* @since 1.4.0
|
||||
*/
|
||||
@Slf4j
|
||||
@UtilityClass
|
||||
@SuppressWarnings("checkstyle:ModifierOrder")
|
||||
public class BundleUtils {
|
||||
/** SET_PARENT */
|
||||
private static final Method SET_PARENT = getDeclaredMethod(ResourceBundle.class, "setParent", ResourceBundle.class);
|
||||
|
||||
/**
|
||||
* Load language bundle
|
||||
*
|
||||
* @param pluginClassLoader plugin class loader
|
||||
* @param name name
|
||||
* @return the resource bundle
|
||||
* @since 1.4.0
|
||||
*/
|
||||
@Contract("null, _ -> null")
|
||||
@Nullable
|
||||
public static ResourceBundle loadLanguageBundle(@Nullable ClassLoader pluginClassLoader, String name) {
|
||||
if (pluginClassLoader == null) {
|
||||
return null;
|
||||
}
|
||||
ResourceBundle.Control control = ResourceBundle.Control.getControl(ResourceBundle.Control.FORMAT_PROPERTIES);
|
||||
ResourceBundle pluginBundle = ResourceBundle.getBundle(name, Locale.getDefault(), pluginClassLoader, control);
|
||||
|
||||
if (pluginBundle == null) {
|
||||
return null;
|
||||
}
|
||||
ResourceBundle base = ResourceBundle.getBundle(name);
|
||||
try {
|
||||
if (SET_PARENT != null) {
|
||||
SET_PARENT.invoke(pluginBundle, base);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.warn("", e);
|
||||
return null;
|
||||
}
|
||||
|
||||
return pluginBundle;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets declared method *
|
||||
*
|
||||
* @param clazz a class
|
||||
* @param name name
|
||||
* @param parameters parameters
|
||||
* @return the declared method
|
||||
* @since 1.4.0
|
||||
*/
|
||||
@Nullable
|
||||
public static Method getDeclaredMethod(@NotNull Class<?> clazz, @NonNls @NotNull String name, Class<?>... parameters) {
|
||||
try {
|
||||
return makeAccessible(clazz.getDeclaredMethod(name, parameters));
|
||||
} catch (NoSuchMethodException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Make accessible
|
||||
*
|
||||
* @param method method
|
||||
* @return the method
|
||||
* @since 1.4.0
|
||||
*/
|
||||
@Contract("_ -> param1")
|
||||
@SuppressWarnings("java:S3011")
|
||||
private static @NotNull Method makeAccessible(@NotNull Method method) {
|
||||
method.setAccessible(true);
|
||||
return method;
|
||||
}
|
||||
|
||||
}
|
||||
+83
@@ -0,0 +1,83 @@
|
||||
package com.aos.element.basic.basic.bundle;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
/**
|
||||
* <p>Company: 成都返空汇网络技术有限公司 </p>
|
||||
* <p>Description: 国际化配置文件动态绑定基类, 所有的业务端都继承此类实现自己的业务配置</p>
|
||||
*
|
||||
* @author dong4j
|
||||
* @version 1.0.0
|
||||
* @email "mailto:dongshijie@fkhwl.com"
|
||||
* @date 2020.05.19 11:22
|
||||
* @since 1.4.0
|
||||
*/
|
||||
@Slf4j
|
||||
public abstract class DynamicBundle extends AbstractBundle {
|
||||
|
||||
/** INSTANCE */
|
||||
public static final DynamicBundle INSTANCE = new DynamicBundle("") {
|
||||
};
|
||||
|
||||
/**
|
||||
* Dynamic bundle
|
||||
*
|
||||
* @param pathToBundle path to bundle
|
||||
* @since 1.4.0
|
||||
*/
|
||||
protected DynamicBundle(@NotNull String pathToBundle) {
|
||||
super(pathToBundle);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the class this method was called 'framesToSkip' frames up the caller hierarchy.
|
||||
* <p>
|
||||
* NOTE:
|
||||
* <b>Extremely expensive!
|
||||
* Please consider not using it.
|
||||
* These aren't the droids you're looking for!</b>
|
||||
*
|
||||
* @param framesToSkip frames to skip
|
||||
* @return the class
|
||||
* @since 1.4.0
|
||||
*/
|
||||
@Nullable
|
||||
public static Class<?> findCallerClass(int framesToSkip) {
|
||||
try {
|
||||
Class<?>[] stack = MySecurityManager.INSTANCE.getStack();
|
||||
int indexFromTop = 1 + framesToSkip;
|
||||
return stack.length > indexFromTop ? stack[indexFromTop] : null;
|
||||
} catch (Exception e) {
|
||||
log.warn("", e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>Company: 成都返空汇网络技术有限公司 </p>
|
||||
* <p>Description: </p>
|
||||
*
|
||||
* @author dong4j
|
||||
* @version 1.0.0
|
||||
* @email "mailto:dongshijie@fkhwl.com"
|
||||
* @date 2020.05.19 11:22
|
||||
* @since 1.4.0
|
||||
*/
|
||||
private static final class MySecurityManager extends SecurityManager {
|
||||
/** INSTANCE */
|
||||
private static final MySecurityManager INSTANCE = new MySecurityManager();
|
||||
|
||||
/**
|
||||
* Get stack
|
||||
*
|
||||
* @return the class [ ]
|
||||
* @since 1.4.0
|
||||
*/
|
||||
Class<?>[] getStack() {
|
||||
return this.getClassContext();
|
||||
}
|
||||
}
|
||||
}
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
package com.aos.element.basic.basic.bundle;
|
||||
|
||||
import com.aos.element.basic.basic.ApplicationInitializedListener;
|
||||
|
||||
/**
|
||||
* <p>Company: 成都返空汇网络技术有限公司 </p>
|
||||
* <p>Description: 国际化配置文件绑定监听器, 暂未使用 </p>
|
||||
*
|
||||
* @author dong4j
|
||||
* @version 1.0.0
|
||||
* @email "mailto:dongshijie@fkhwl.com"
|
||||
* @date 2020.05.19 14:36
|
||||
* @since 1.4.0
|
||||
*/
|
||||
public class LanguageBundleListener implements ApplicationInitializedListener {
|
||||
/**
|
||||
* Components initialized
|
||||
*
|
||||
* @since 1.4.0
|
||||
*/
|
||||
@Override
|
||||
public void componentsInitialized() {
|
||||
|
||||
}
|
||||
}
|
||||
+98
@@ -0,0 +1,98 @@
|
||||
package com.aos.element.basic.basic.constant;
|
||||
|
||||
import lombok.experimental.UtilityClass;
|
||||
|
||||
/**
|
||||
* <p>Company: 成都返空汇网络技术有限公司</p>
|
||||
* <p>Description: </p>
|
||||
*
|
||||
* @author dong4j
|
||||
* @version 1.2.4
|
||||
* @email "mailto:dongshijie@gmail.com"
|
||||
* @date 2020.02.13 16:00
|
||||
* @since 1.0.0
|
||||
*/
|
||||
@UtilityClass
|
||||
public final class BasicConstant {
|
||||
/** BOOST_EXECUTOR */
|
||||
public static final String BOOST_EXECUTOR = "boostExecutor";
|
||||
/** DYNAMIC_EXECUTOR */
|
||||
public static final String DYNAMIC_EXECUTOR = "dynamicExecutor";
|
||||
/** BOOST_EXECUTORSERVICE */
|
||||
public static final String BOOST_EXECUTORSERVICE = "boostExecutorService";
|
||||
/** JSON */
|
||||
public static final String JSON = "json";
|
||||
/** TRACE_ID */
|
||||
public static final String TRACE_ID = "traceId";
|
||||
/** 客户端标识 */
|
||||
public static final String HEADER_CLIENT_ID = "X-Client-Id";
|
||||
/** 网关写入的原始请求地址 */
|
||||
public static final String X_GATEWAY_ORIGINAL = "X-Gatetay-Original";
|
||||
/** 网关写入的路由日志 */
|
||||
public static final String X_GATEWAY_ROUTER = "X-Gatetay-Router";
|
||||
/** 对 rest 和 agent 结果进行解包/装包 的字段名 */
|
||||
public static final String RESULT_WRAPPER_VALUE_KEY = "value";
|
||||
|
||||
/** REQUEST_EXCEPTION_INFO_ATTR */
|
||||
public static final String REQUEST_EXCEPTION_INFO_ATTR = "javax.servlet.error.exception";
|
||||
|
||||
/**
|
||||
* <p>Company: 成都返空汇网络技术有限公司 </p>
|
||||
* <p>Description: agent service 通用接口命名规则 </p>
|
||||
*
|
||||
* @author dong4j
|
||||
* @version 1.0.0
|
||||
* @email "mailto:dongshijie@fkhwl.com"
|
||||
* @date 2020.11.22 12:16
|
||||
* @since 1.7.0
|
||||
*/
|
||||
@UtilityClass
|
||||
public static class Agent {
|
||||
|
||||
/** 通过id */
|
||||
public static final String FIND = "0100";
|
||||
/** 通过id */
|
||||
public static final String FIND_BATCH = "0101";
|
||||
/** 通过查询 */
|
||||
public static final String FIND_BY_QUERY = "0102";
|
||||
/** 所有 */
|
||||
public static final String FIND_ALL = "0103";
|
||||
/** 得到数 */
|
||||
public static final String COUNTS = "0104";
|
||||
/** 被查询数 */
|
||||
public static final String COUNTS_BY_QUERY = "0105";
|
||||
/** 列表 */
|
||||
public static final String LIST = "0106";
|
||||
/** 页面 */
|
||||
public static final String PAGE = "0107";
|
||||
|
||||
/** 保存 */
|
||||
public static final String CREATE = "0200";
|
||||
/** 批量保存 */
|
||||
public static final String CREATE_BATCH = "0201";
|
||||
/** 保存忽略 */
|
||||
public static final String CREATE_IGNORE = "0202";
|
||||
/** 批量保存忽略 */
|
||||
public static final String CREATE_IGNORE_BATCH = "0203";
|
||||
/** 保存替换 */
|
||||
public static final String CREATE_REPLACE = "0204";
|
||||
/** 批量保存取代 */
|
||||
public static final String CREATE_REPLACE_BATCH = "0205";
|
||||
/** 保存更新 */
|
||||
public static final String CREATE_UPDATE = "0206";
|
||||
/** 批量保存更新 */
|
||||
public static final String CREATE_UPDATE_BATCH = "0207";
|
||||
|
||||
/** 更新 */
|
||||
public static final String UPDATE = "0300";
|
||||
/** 批处理更新 */
|
||||
public static final String UPDATE_BATCH = "0301";
|
||||
|
||||
/** 删除 */
|
||||
public static final String DELETE = "0400";
|
||||
/** 多删除 */
|
||||
public static final String DELETE_BATCH = "0401";
|
||||
/** 删除的条件 */
|
||||
public static final String DELETE_BY_CONDITION = "0402";
|
||||
}
|
||||
}
|
||||
+56
@@ -0,0 +1,56 @@
|
||||
package com.aos.element.basic.basic.constant;
|
||||
|
||||
import com.aos.element.basic.basic.util.StringPool;
|
||||
import lombok.experimental.UtilityClass;
|
||||
|
||||
/**
|
||||
* <p>Company: 成都返空汇网络技术有限公司</p>
|
||||
* <p>Description: 常用的配置默认值</p>
|
||||
*
|
||||
* @author dong4j
|
||||
* @version 1.2.4
|
||||
* @email "mailto:dongshijie@gmail.com"
|
||||
* @date 2020.02.04 16:03
|
||||
* @since 1.0.0
|
||||
*/
|
||||
@UtilityClass
|
||||
public final class ConfigDefaultValue {
|
||||
|
||||
/** DEFAULT_PROPERTY_INCLUSION_VALUE */
|
||||
public static final String DEFAULT_PROPERTY_INCLUSION_VALUE = "non_null";
|
||||
/** DEFAULT_ENCRYPTOR_PASSWORD */
|
||||
public static final String DEFAULT_ENCRYPTOR_PASSWORD = "06020986-3127-40be-9134-90fd033896a1";
|
||||
/** DEFAULT_TIME_ZONE */
|
||||
public static final String DEFAULT_TIME_ZONE = "GMT+8";
|
||||
/** DEFAULT_DATE_FORMAT */
|
||||
public static final String DEFAULT_DATE_FORMAT = "yyyy-MM-dd HH:mm:ss";
|
||||
/** TRUE_STRING */
|
||||
public static final String TRUE_STRING = "true";
|
||||
/** TRUE */
|
||||
public static final Boolean TRUE = Boolean.TRUE;
|
||||
/** FALSE_STRING */
|
||||
public static final String FALSE_STRING = "false";
|
||||
/** FALSE */
|
||||
public static final Boolean FALSE = Boolean.FALSE;
|
||||
/** EMPTY */
|
||||
public static final String EMPTY = StringPool.EMPTY;
|
||||
/** 应用启动成功后, 将在此路径下创建一个 app.pid 文件, 内容是当前应用的 pid */
|
||||
public static final String PROP_PID_FILE = "./app.pid";
|
||||
/** NACOS_SERVER */
|
||||
public static final String NACOS_HOST = "nacos.server";
|
||||
/** NACOS_PORT */
|
||||
public static final String NACOS_PORT = "8848";
|
||||
/** NACOS_SERVER */
|
||||
public static final String NACOS_SERVER = NACOS_HOST + StringPool.COLON + NACOS_PORT;
|
||||
/** RIBBON_NAME */
|
||||
public static final String RIBBON_NAME = "gateway";
|
||||
/** BASE_PACKAGES */
|
||||
public static final String BASE_PACKAGES = System.getProperty("PARENT_PACKAGE_NAME", "com.fkhwl");
|
||||
/** CONTAINER_LOCATION */
|
||||
public static final String CONTAINER_LOCATION = "/mnt/tmp";
|
||||
/** v5 服务默认的日志主目录 */
|
||||
public static final String DEFAULT_LOGGING_LOCATION = "/mnt/syslogs/v5";
|
||||
/** 容器日志的默认目录 */
|
||||
public static final String DEFAULE_ACCESS_LOG_DIR = "container";
|
||||
|
||||
}
|
||||
+720
@@ -0,0 +1,720 @@
|
||||
package com.aos.element.basic.basic.constant;
|
||||
|
||||
import com.aos.element.basic.basic.util.StringPool;
|
||||
|
||||
import lombok.experimental.UtilityClass;
|
||||
|
||||
/**
|
||||
* <p>Company: 成都返空汇网络技术有限公司</p>
|
||||
* <p>Description: 所有的配置常量</p>
|
||||
*
|
||||
* @author dong4j
|
||||
* @version 1.2.4
|
||||
* @email "mailto:dongshijie@gmail.com"
|
||||
* @date 2020.02.04 15:51
|
||||
* @since 1.0.0
|
||||
*/
|
||||
@UtilityClass
|
||||
@SuppressWarnings("all")
|
||||
public final class ConfigKey {
|
||||
/** PARENT_PACKAGE_NAME */
|
||||
public static final String PARENT_PACKAGE_NAME = "PARENT_PACKAGE_NAME";
|
||||
/** 框架版本 */
|
||||
public static final String APPLICATION_FRAMEWORK_VERSION = "fkh.framework.version";
|
||||
/** EXTEND_ENABLE_AUTOWIRED_IS_NULL */
|
||||
public static final String EXTEND_ENABLE_AUTOWIRED_IS_NULL = "fkh.extend.enable-autowired-is-null";
|
||||
/** EXTEND_ENABLE_RESOURCE_IS_NULL */
|
||||
public static final String EXTEND_ENABLE_RESOURCE_IS_NULL = "fkh.extend.enable-resource-is-null";
|
||||
/** REST_ENABLE_GLOBAL_CACHE_FILTER */
|
||||
public static final String WEB_ENABLE_GLOBAL_CACHE_FILTER = "fkh.web.enable-global-cache-filter";
|
||||
/** REST_ENABLE_EXCEPTION_FILTER */
|
||||
public static final String WEB_ENABLE_EXCEPTION_FILTER = "fkh.web.enable-exception-filter";
|
||||
/** REST_ENABLE_REQUEST_LOG */
|
||||
public static final String REST_ENABLE_REQUEST_LOG = "fkh.rest.enable-request-log";
|
||||
/** REST_ENABLE_GLOBAL_PARAMETER_FILTER */
|
||||
public static final String REST_ENABLE_GLOBAL_PARAMETER_FILTER = "fkh.rest.enable-global-parameter-filter";
|
||||
/** XSS_ENABLE_XSS_FILTER */
|
||||
public static final String XSS_ENABLE_XSS_FILTER = "fkh.xss.enable-xss-filter";
|
||||
/** JSON_TIME_ZONE */
|
||||
public static final String JSON_TIME_ZONE = "fkh.rest.json.time-zone";
|
||||
/** JSON_DATE_FORMAT */
|
||||
public static final String JSON_DATE_FORMAT = "fkh.rest.json.date-formate";
|
||||
/** jackson null 处理配置 */
|
||||
public static final String JSON_SERIALIZE_NULL = "fkh.rest.json.default-property-inclusion";
|
||||
/** MYBATIS_ENABLE_ILLEGAL_SQL_INTERCEPTOR */
|
||||
public static final String MYBATIS_ENABLE_ILLEGAL_SQL_INTERCEPTOR = "fkh.mybatis.enable-illegal-sql-interceptor";
|
||||
/** MYBATIS_ENABLE_SQL_EXPLAIN_INTERCEPTOR */
|
||||
public static final String MYBATIS_ENABLE_SQL_EXPLAIN_INTERCEPTOR = "fkh.mybatis.enable-sql-explain-interceptor";
|
||||
/** POM_INFO_VERSION */
|
||||
public static final String POM_INFO_VERSION = "info.version";
|
||||
/** POM_INFO_GROUPID */
|
||||
public static final String POM_INFO_GROUPID = "info.groupId";
|
||||
/** POM_INFO_ARTIFACTID */
|
||||
public static final String POM_INFO_ARTIFACTID = "info.artifactId";
|
||||
/** SERVICE_VERSION */
|
||||
public static final String SERVICE_VERSION = "fkh.service.version";
|
||||
/** JASYPT_ENCRYPTOR_PASSWORD */
|
||||
public static final String JASYPT_ENCRYPTOR_PASSWORD = "jasypt.encryptor.password";
|
||||
/** 是否开启 banner */
|
||||
public static final String FKH_ENABLE_BANNER = "fkh.enable-banner";
|
||||
/** 应用分组 */
|
||||
public static final String FKH_APP_GROUP = "fkh.app.group";
|
||||
/** FKH_APP_CONFIG_GROUP */
|
||||
public static final String FKH_APP_CONFIG_GROUP = "fkh.app.config-group";
|
||||
/** DISCOVERY_GROUP */
|
||||
public static final String FKH_APP_DISCOVERY_GROUP = "fkh.app.discovery-group";
|
||||
|
||||
/**
|
||||
* <p>Company: 成都返空汇网络技术有限公司 </p>
|
||||
* <p>Description: </p>
|
||||
*
|
||||
* @author dong4j
|
||||
* @version 1.3.0
|
||||
* @email "mailto:dongshijie@fkhwl.com"
|
||||
* @date 2020.02.26 17:13
|
||||
* @since 1.0.0
|
||||
*/
|
||||
@UtilityClass
|
||||
public static class JvmConfigKey {
|
||||
/** TMP_DIR */
|
||||
public static final String TMP_DIR = "java.io.tmpdir";
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>Company: 成都返空汇网络技术有限公司 </p>
|
||||
* <p>Description: </p>
|
||||
*
|
||||
* @author dong4j
|
||||
* @version 1.3.0
|
||||
* @email "mailto:dongshijie@fkhwl.com"
|
||||
* @date 2020.02.26 10:01
|
||||
* @since 1.0.0
|
||||
*/
|
||||
@UtilityClass
|
||||
public static class LogSystemConfigKey {
|
||||
/** 日志应用名 */
|
||||
public static final String LOG_APP_NAME = "fkh.logging.app-name";
|
||||
/** 是否现在 location 信息 */
|
||||
public static final String SHOW_LOG_LOCATION = "fkh.logging.enable-show-location";
|
||||
|
||||
/** 日志等级 */
|
||||
public static final String LOG_LEVEL = "fkh.logging.level";
|
||||
/** 日志分组 */
|
||||
public static final String LOG_GROUP = "fkh.logging.group";
|
||||
/** 日志系统配置文件 */
|
||||
public static final String LOG_CONFIG = "fkh.logging.config";
|
||||
|
||||
/** LOG_FILE */
|
||||
public static final String LOG_FILE = "fkh.logging.file";
|
||||
/** 日志文件名 */
|
||||
public static final String LOG_FILE_NAME = "fkh.logging.file.name";
|
||||
/** 日志文件保存路径 */
|
||||
public static final String LOG_FILE_PATH = "fkh.logging.file.path";
|
||||
/** 是否在启动应用时清理历史日志 */
|
||||
public static final String LOG_FILE_CLEAN_HISTORY = "fkh.logging.file.clean-history-on-start";
|
||||
/** 最大允许保存的日志历史 */
|
||||
public static final String LOG_FILE_MAX_HISTORY = "fkh.logging.file.max-history";
|
||||
/** 日志文件最大容量 */
|
||||
public static final String LOG_FILE_MAX_SIZE = "fkh.logging.file.max-size";
|
||||
/** 日志文件最大数量 */
|
||||
public static final String LOG_FILE_TOTAL_SIZE_CAP = "fkh.logging.file.total-size-cap";
|
||||
|
||||
/** LOG_PATTERN */
|
||||
public static final String LOG_PATTERN = "fkh.logging.pattern";
|
||||
/** LOG_PATTERN_CONSOLE */
|
||||
public static final String LOG_PATTERN_CONSOLE = "fkh.logging.pattern.console";
|
||||
/** LOG_PATTERN_FILE */
|
||||
public static final String LOG_PATTERN_FILE = "fkh.logging.pattern.file";
|
||||
/** LOG_PATTERN_LEVEL */
|
||||
public static final String LOG_PATTERN_LEVEL = "fkh.logging.pattern.level";
|
||||
/** LOG_PATTERN_DATEFORMAT */
|
||||
public static final String LOG_PATTERN_DATEFORMAT = "fkh.logging.pattern.dateformat";
|
||||
/** ROLLING_FILE_NAME */
|
||||
public static final String ROLLING_FILE_NAME = "fkh.logging.pattern.rolling-file-name";
|
||||
/** MARKER_PATTERN */
|
||||
public static final String MARKER_PATTERN = "fkh.logging.pattern.marker";
|
||||
|
||||
/** 日志路由 key */
|
||||
public static final String ROUTING_APPENDER_KEY = "ROUTING_APPENDER_KEY";
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>Company: 成都返空汇网络技术有限公司 </p>
|
||||
* <p>Description: </p>
|
||||
*
|
||||
* @author dong4j
|
||||
* @version 1.2.4
|
||||
* @email "mailto:dongshijie@fkhwl.com"
|
||||
* @date 2020.02.04 17:05
|
||||
* @since 1.0.0
|
||||
*/
|
||||
@UtilityClass
|
||||
public static class SpringConfigKey {
|
||||
/** SERVER_CONTEXT_PATH */
|
||||
public static final String SERVER_CONTEXT_PATH = "server.servlet.context-path";
|
||||
/** SERVER_PORT */
|
||||
public static final String SERVER_PORT = "server.port";
|
||||
/** MANAGEMENT_SERVER_PORT */
|
||||
public static final String MANAGEMENT_SERVER_PORT = "management.server.port";
|
||||
/** PROP_APPLICATION_NAME */
|
||||
public static final String APPLICATION_NAME = "spring.application.name";
|
||||
/** PACKAGE_NAME */
|
||||
public static final String PACKAGE_NAME = "package.name";
|
||||
/** PROFILE_ACTIVE */
|
||||
public static final String PROFILE_ACTIVE = "spring.profiles.active";
|
||||
/** MAIN_ALLOW_BEAN_DEFINITION_OVERRIDING */
|
||||
public static final String MAIN_ALLOW_BEAN_DEFINITION_OVERRIDING = "spring.main.allow-bean-definition-overriding";
|
||||
/** 根据此配置判断是否创建 pid 文件 */
|
||||
public static final String PID_FILE = "spring.pid.file";
|
||||
/** 排除的自动装配类 */
|
||||
public static final String AUTOCONFIGURE_EXCLUDE = "spring.autoconfigure.exclude";
|
||||
/** jackson 序列化配置 */
|
||||
public static final String JACKSON_DEFAULT_PROPERTY_INCLUSION = "spring.jackson.default-property-inclusion";
|
||||
/** DATASOURCE_URL */
|
||||
public static final String DATASOURCE_URL = "spring.datasource.url";
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>Company: 成都返空汇网络技术有限公司 </p>
|
||||
* <p>Description: </p>
|
||||
*
|
||||
* @author dong4j
|
||||
* @version 1.2.4
|
||||
* @email "mailto:dongshijie@fkhwl.com"
|
||||
* @date 2020.02.04 18:07
|
||||
* @since 1.0.0
|
||||
*/
|
||||
@UtilityClass
|
||||
public static class MvcConfigKey {
|
||||
/** NO_HANDLER_FOUND */
|
||||
public static final String NO_HANDLER_FOUND = "spring.mvc.throw-exception-if-no-handler-found";
|
||||
/** ENCODING_FORCE */
|
||||
public static final String ENCODING_FORCE = "spring.http.encoding.force";
|
||||
/** ENCODING_CHARSET */
|
||||
public static final String ENCODING_CHARSET = "spring.http.encoding.charset";
|
||||
/** ENCODING_ENABLED */
|
||||
public static final String ENCODING_ENABLED = "spring.http.encoding.enabled";
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>Company: 成都返空汇网络技术有限公司 </p>
|
||||
* <p>Description: Undertow 请求日志配置 </p>
|
||||
*
|
||||
* @author dong4j
|
||||
* @version 1.3.0
|
||||
* @email "mailto:dongshijie@fkhwl.com"
|
||||
* @date 2020.03.10 12:46
|
||||
* @since 1.0.0
|
||||
*/
|
||||
@UtilityClass
|
||||
public static class UndertowConfigKye {
|
||||
/** 日志存放目录 */
|
||||
public static final String ACCESSLOG_DIR = "server.undertow.accesslog.dir";
|
||||
/** 是否启动日志 */
|
||||
public static final String ENABLE_ACCESSLOG = "server.undertow.accesslog.enabled";
|
||||
/** 日志文件名前缀 */
|
||||
public static final String ACCESSLOG_PREFIX = "server.undertow.accesslog.prefix";
|
||||
/** 日志文件名后缀 */
|
||||
public static final String ACCESSLOG_SUFFIX = "server.undertow.accesslog.suffix";
|
||||
/** 日志格式 */
|
||||
public static final String ACCESSLOG_PATTERN = "server.undertow.accesslog.pattern";
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>Company: 成都返空汇网络技术有限公司 </p>
|
||||
* <p>Description: </p>
|
||||
*
|
||||
* @author dong4j
|
||||
* @version 1.2.4
|
||||
* @email "mailto:dongshijie@fkhwl.com"
|
||||
* @date 2020.02.04 17:31
|
||||
* @since 1.0.0
|
||||
*/
|
||||
@UtilityClass
|
||||
public static class CloudConfigKey {
|
||||
/** 是否加载配置中心配置 */
|
||||
public static final String CONFIG_OVERRIDE_NONE = "spring.cloud.config.override-none";
|
||||
/** CONFIG */
|
||||
public static final String NACOS_CONFIG = "spring.cloud.nacos.config.";
|
||||
/** nacos config 的配置 key */
|
||||
public static final String CONFIG_SERVER_ADDRESS = NACOS_CONFIG + "server-addr";
|
||||
/** CONFIG_FILE_EXTENSION */
|
||||
public static final String CONFIG_FILE_EXTENSION = NACOS_CONFIG + "file-extension";
|
||||
/** CONFIG_ENCODE */
|
||||
public static final String CONFIG_ENCODE = NACOS_CONFIG + "encode";
|
||||
/** nacos readtimeout */
|
||||
public static final String TIMEOUT = NACOS_CONFIG + "timeout";
|
||||
/** CONFIG_NAMESPACE */
|
||||
public static final String CONFIG_NAMESPACE = NACOS_CONFIG + "namespace";
|
||||
/** CONFIG_GROUP */
|
||||
public static final String CONFIG_GROUP = NACOS_CONFIG + "group";
|
||||
/** EXT_CONFIG_1_DATA_ID */
|
||||
public static final String EXT_CONFIG_1_DATA_ID = NACOS_CONFIG + "ext-config.data-id";
|
||||
/** EXT_CONFIG_1_GROUP */
|
||||
public static final String EXT_CONFIG_1_GROUP = NACOS_CONFIG + "ext-config.group";
|
||||
/** EXT_CONFIG_1_NAMESPACE */
|
||||
public static final String EXT_CONFIG_1_NAMESPACE = NACOS_CONFIG + "ext-config.namespace";
|
||||
/** EXT_CONFIG_1_REFRESH */
|
||||
public static final String EXT_CONFIG_1_REFRESH = NACOS_CONFIG + "ext-config.refresh";
|
||||
/** DISCOVERY_NAMESPACE */
|
||||
public static final String DISCOVERY = "spring.cloud.nacos.discovery.";
|
||||
/** DISCOVERY_NAMESPACE */
|
||||
public static final String DISCOVERY_NAMESPACE = DISCOVERY + "namespace";
|
||||
/** DISCOVERY_SERVER_ADDRESS */
|
||||
public static final String DISCOVERY_SERVER_ADDRESS = DISCOVERY + "server-addr";
|
||||
/** DISCOVERY_GROUP */
|
||||
public static final String DISCOVERY_GROUP = DISCOVERY + "group";
|
||||
/** DISCOVERY_IP */
|
||||
public static final String DISCOVERY_IP = DISCOVERY + "ip";
|
||||
/** DISCOVERY_METADATA */
|
||||
public static final String DISCOVERY_METADATA = DISCOVERY + "metadata";
|
||||
/** INETUTILS_PREFERRED_NETWORKS */
|
||||
public static final String INETUTILS_PREFERRED_NETWORKS = "spring.cloud.inetutils.preferred-networks";
|
||||
/** USE_ONLY_SITE_LOCAL_INTERFACES */
|
||||
public static final String USE_ONLY_SITE_LOCAL_INTERFACES = "spring.cloud.inetutils.use-only-site-local-interfaces";
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>Company: 成都返空汇网络技术有限公司 </p>
|
||||
* <p>Description: 自定义 nacos 配置, 用于访问自定义配置和服务 </p>
|
||||
*
|
||||
* @author dong4j
|
||||
* @version 1.3.0
|
||||
* @email "mailto:dongshijie@fkhwl.com"
|
||||
* @date 2020.03.20 17:39
|
||||
* @since 1.0.0
|
||||
*/
|
||||
@UtilityClass
|
||||
public static class NacosConfigKey {
|
||||
/** 配置中心地址 */
|
||||
public static final String FKH_CONFIG = "fkh.nacos.config.";
|
||||
/** CONFIG_SERVER_ADDRESS */
|
||||
public static final String CONFIG_SERVER_ADDRESS = FKH_CONFIG + "server-addr";
|
||||
/** 配置中心 namespace */
|
||||
public static final String CONFIG_NAMESPACE = FKH_CONFIG + "namespace";
|
||||
/** 配置中心 dataId */
|
||||
public static final String CONFIG_DATA_ID = FKH_CONFIG + "data-id";
|
||||
/** 配置中心 分组 */
|
||||
public static final String CONFIG_GROUP = FKH_CONFIG + "group";
|
||||
/** FKH_DISCOVERY */
|
||||
public static final String FKH_DISCOVERY = "fkh.nacos.discovery.";
|
||||
/** 服务注册与发现地址 */
|
||||
public static final String DISCOVERY_SERVER_ADDR = FKH_DISCOVERY + "server-addr";
|
||||
/** 服务注册与发现 namespace */
|
||||
public static final String DISCOVERY_NAMESPACE = FKH_DISCOVERY + "namespace";
|
||||
/** 服务注册与发现 分组 */
|
||||
public static final String DISCOVERY_GROUP = FKH_DISCOVERY + "group";
|
||||
/** 是否自动创建配置 */
|
||||
public static final String ENABLE_AUTO_CREATE_CONFIG = "fkh.nacos.enable-auto-create-config";
|
||||
/** 是否使用 Nacos 配置 */
|
||||
public static final String ENABLE_NACOS_CONFIG = "fkh.nacos.enable-nacos-config";
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>Company: 成都返空汇网络技术有限公司 </p>
|
||||
* <p>Description: </p>
|
||||
*
|
||||
* @author dong4j
|
||||
* @version 1.2.4
|
||||
* @email "mailto:dongshijie@fkhwl.com"
|
||||
* @date 2020.02.04 17:42
|
||||
* @since 1.0.0
|
||||
*/
|
||||
@UtilityClass
|
||||
public static class ManagementConfigKey {
|
||||
/** ENABLED */
|
||||
public static final String ENABLED = "management.endpoint.env.enabled";
|
||||
/** HEALTH_DETAILS */
|
||||
public static final String HEALTH_DETAILS = "management.endpoint.health.show-details";
|
||||
/** GIT_MODE */
|
||||
public static final String GIT_MODE = "management.info.git.mode";
|
||||
/** EXPOSURE_INCLUDE */
|
||||
public static final String EXPOSURE_INCLUDE = "management.endpoints.web.exposure.include";
|
||||
/** BASE_URL */
|
||||
public static final String BASE_URL = "management.endpoints.web.base-path";
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>Company: 成都返空汇网络技术有限公司 </p>
|
||||
* <p>Description: </p>
|
||||
*
|
||||
* @author dong4j
|
||||
* @version 1.2.4
|
||||
* @email "mailto:dongshijie@fkhwl.com"
|
||||
* @date 2020.02.04 17:50
|
||||
* @since 1.0.0
|
||||
*/
|
||||
@UtilityClass
|
||||
public static class DubboConfigKey {
|
||||
/** APPLICATION_LOGGER */
|
||||
public static final String APPLICATION_LOGGER = "dubbo.application.logger";
|
||||
/** DUBBO_HOST */
|
||||
public static final String DUBBO_HOST = "dubbo.protocol.host";
|
||||
/** REGISTRY_ADDRESS */
|
||||
public static final String REGISTRY_ADDRESS = "dubbo.registry.address";
|
||||
/** PROTOCOL_NAME */
|
||||
public static final String PROTOCOL_NAME = "dubbo.protocol.name";
|
||||
/** CONSUMER_CHECK */
|
||||
public static final String CONSUMER_CHECK = "dubbo.consumer.check";
|
||||
/** CONSUMER_VALIDATION */
|
||||
public static final String CONSUMER_VALIDATION = "dubbo.consumer.validation";
|
||||
/** PROVIDER_TIMEOUT */
|
||||
public static final String PROVIDER_TIMEOUT = "dubbo.provider.timeout";
|
||||
/** PROTOCOL_PORT */
|
||||
public static final String PROTOCOL_PORT = "dubbo.protocol.port";
|
||||
/** 元数据中心地址 */
|
||||
public static final String METADATA_REPORT_ADDRESS = "dubbo.metadata-report.address";
|
||||
/** DUBBO_CONSUMER_FILTER */
|
||||
public static final String DUBBO_CONSUMER_FILTER = "dubbo.consumer.filter";
|
||||
/** DUBBO_PROVIDER_FILTER */
|
||||
public static final String DUBBO_PROVIDER_FILTER = "dubbo.provider.filter";
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>Company: 成都返空汇网络技术有限公司 </p>
|
||||
* <p>Description: </p>
|
||||
*
|
||||
* @author dong4j
|
||||
* @version 1.2.4
|
||||
* @email "mailto:dongshijie@fkhwl.com"
|
||||
* @date 2020.02.04 17:54
|
||||
* @since 1.0.0
|
||||
*/
|
||||
@UtilityClass
|
||||
public static class MongoConfigKey {
|
||||
/** ENABLE_AUTO_INCREMENT_KEY */
|
||||
public static final String ENABLE_AUTO_INCREMENT_KEY = "fkh.mongo.enable-auto-increment-key";
|
||||
/** ENABLE_AUTO_CREATE_INDEX */
|
||||
public static final String ENABLE_AUTO_CREATE_INDEX = "fkh.mongo.enable-auto-create-index";
|
||||
/** ENABLE_AUTO_CREATE_KEY */
|
||||
public static final String ENABLE_AUTO_CREATE_KEY = "fkh.mongo.enable-auto-create-key";
|
||||
/** ENABLE_AUTO_CREATE_TIME */
|
||||
public static final String ENABLE_AUTO_CREATE_TIME = "fkh.mongo.enable-auto-create-time";
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>Company: 成都返空汇网络技术有限公司 </p>
|
||||
* <p>Description: </p>
|
||||
*
|
||||
* @author dong4j
|
||||
* @version 1.2.4
|
||||
* @email "mailto:dongshijie@fkhwl.com"
|
||||
* @date 2020.02.04 18:10
|
||||
* @since 1.0.0
|
||||
*/
|
||||
@UtilityClass
|
||||
public static class MybatisConfigKey {
|
||||
/** PAGE */
|
||||
public static final String PAGE = "fkh.mybatis.page";
|
||||
/** LIMIT */
|
||||
public static final String LIMIT = "fkh.mybatis.limit";
|
||||
/** MYBATIS_ENABLE_LOG */
|
||||
public static final String MYBATIS_ENABLE_LOG = "fkh.mybatis.enable-log";
|
||||
/** MYBATIS_ENABLE_SENSITIVE */
|
||||
public static final String MYBATIS_ENABLE_SENSITIVE = "fkh.mybatis.enable-sensitive";
|
||||
/** MAPPER_LOCATIONS */
|
||||
public static final String MAPPER_LOCATIONS = "mybatis-plus.mapper-locations";
|
||||
/** CONFIGURATION_LOG_IMPL */
|
||||
public static final String CONFIGURATION_LOG_IMPL = "mybatis-plus.configuration.log-impl";
|
||||
/** CONFIGURATION_CALL_SETTERS_ON_NULLS */
|
||||
public static final String CONFIGURATION_CALL_SETTERS_ON_NULLS = "mybatis-plus.configuration.call-setters-on-nulls";
|
||||
/** CONFIGURATION_CACHE_ENABLED */
|
||||
public static final String CONFIGURATION_CACHE_ENABLED = "mybatis-plus.configuration.cache-enabled";
|
||||
/** CONFIGURATION_MAP_UNDERSCORE_TO_CAMEL_CASE */
|
||||
public static final String CONFIGURATION_MAP_UNDERSCORE_TO_CAMEL_CASE = "mybatis-plus.configuration.map-underscore-to-camel-case";
|
||||
/** GLOBAL_LOGIC_DELETE_VALUE */
|
||||
public static final String GLOBAL_LOGIC_DELETE_VALUE = "mybatis-plus.global-config.db-config.logic-delete-value";
|
||||
/** GLOBAL_LOGIC_NOT_DELETE_VALUE */
|
||||
public static final String GLOBAL_LOGIC_NOT_DELETE_VALUE = "mybatis-plus.global-config.db-config.logic-not-delete-value";
|
||||
/** 组件类型 */
|
||||
public static final String GLOBAL_ID_TYPE = "mybatis-plus.global-config.db-config.id-type";
|
||||
/** GLOBAL_LOGIC_BANNER */
|
||||
public static final String GLOBAL_LOGIC_BANNER = "mybatis-plus.global-config.banner";
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>Company: 成都返空汇网络技术有限公司 </p>
|
||||
* <p>Description: </p>
|
||||
* todo-dong4j : (2020年02月28日 12:38) [重构]
|
||||
*
|
||||
* @author dong4j
|
||||
* @version 1.2.4
|
||||
* @email "mailto:dongshijie@fkhwl.com"
|
||||
* @date 2020.02.04 18:13
|
||||
* @since 1.0.0
|
||||
*/
|
||||
@UtilityClass
|
||||
public static class DruidConfigKey {
|
||||
/** TYPE */
|
||||
public static final String TYPE = "spring.datasource.type";
|
||||
/** DB_TYPE */
|
||||
public static final String DB_TYPE = "spring.datasource.druid.db-type";
|
||||
/** DRIVER_CLASS */
|
||||
public static final String DRIVER_CLASS = "spring.datasource.driver-class-name";
|
||||
/** INITIALSIZE */
|
||||
public static final String INITIALSIZE = "spring.datasource.druid.initialSize";
|
||||
/** MINIDLE */
|
||||
public static final String MINIDLE = "spring.datasource.druid.minIdle";
|
||||
/** MAXACTIVE */
|
||||
public static final String MAXACTIVE = "spring.datasource.druid.maxActive";
|
||||
/** MAXWAIT */
|
||||
public static final String MAXWAIT = "spring.datasource.druid.maxWait";
|
||||
/** TIMEBETWEENEVICTIONRUNSMILLIS */
|
||||
public static final String TIMEBETWEENEVICTIONRUNSMILLIS = "spring.datasource.druid.timeBetweenEvictionRunsMillis";
|
||||
/** MINEVICTABLEIDLETIMEMILLIS */
|
||||
public static final String MINEVICTABLEIDLETIMEMILLIS = "spring.datasource.druid.minEvictableIdleTimeMillis";
|
||||
/** VALIDATIONQUERY */
|
||||
public static final String VALIDATIONQUERY = "spring.datasource.druid.validationQuery";
|
||||
/** TESTWHILEIDLE */
|
||||
public static final String TESTWHILEIDLE = "spring.datasource.druid.testWhileIdle";
|
||||
/** TESTONBORROW */
|
||||
public static final String TESTONBORROW = "spring.datasource.druid.testOnBorrow";
|
||||
/** TESTONRETURN */
|
||||
public static final String TESTONRETURN = "spring.datasource.druid.testOnReturn";
|
||||
/** POOLPREPAREDSTATEMENTS */
|
||||
public static final String POOLPREPAREDSTATEMENTS = "spring.datasource.druid.poolPreparedStatements";
|
||||
/** MAXPOOLPREPAREDSTATEMENTPERCONNECTIONSIZE */
|
||||
public static final String MAXPOOLPREPAREDSTATEMENTPERCONNECTIONSIZE =
|
||||
"spring.datasource.druid.maxPoolPreparedStatementPerConnectionSize";
|
||||
/** FILTERS */
|
||||
public static final String FILTERS = "spring.datasource.druid.filters";
|
||||
/** CONNECTIONPROPERTIES */
|
||||
public static final String CONNECTIONPROPERTIES = "spring.datasource.druid.connectionProperties";
|
||||
/** USUEGLOBALDATASOURCESTAT */
|
||||
public static final String USUEGLOBALDATASOURCESTAT = "spring.datasource.druid.useGlobalDataSourceStat";
|
||||
/** WEB_FILTER */
|
||||
public static final String WEB_FILTER = "spring.datasource.druid.web-stat-filter.enabled";
|
||||
/** WEB_FILTER_URL_PATTERN */
|
||||
public static final String WEB_FILTER_URL_PATTERN = "spring.datasource.druid.web-stat-filter.url-pattern";
|
||||
/** WEB_FILTER_EXCLUSIONS */
|
||||
public static final String WEB_FILTER_EXCLUSIONS = "spring.datasource.druid.web-stat-filter.exclusions";
|
||||
/** STAT */
|
||||
public static final String STAT = "spring.datasource.druid.stat-view-servlet.enabled";
|
||||
/** STAT_URL_PATTERN */
|
||||
public static final String STAT_URL_PATTERN = "spring.datasource.druid.stat-view-servlet.url-pattern";
|
||||
/** STAT_ALLOW */
|
||||
public static final String STAT_ALLOW = "spring.datasource.druid.stat-view-servlet.allow";
|
||||
/** STAT_DENY */
|
||||
public static final String STAT_DENY = "spring.datasource.druid.stat-view-servlet.deny";
|
||||
/** STAT_RESET */
|
||||
public static final String STAT_RESET = "spring.datasource.druid.stat-view-servlet.reset-enable";
|
||||
/** STAT_USERNAME */
|
||||
public static final String STAT_USERNAME = "spring.datasource.druid.stat-view-servlet.login-username";
|
||||
/** STAT_PASSWORD */
|
||||
public static final String STAT_PASSWORD = "spring.datasource.druid.stat-view-servlet.login-password";
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>Company: 成都返空汇网络技术有限公司 </p>
|
||||
* <p>Description: </p>
|
||||
*
|
||||
* @author dong4j
|
||||
* @version 1.2.4
|
||||
* @email "mailto:dongshijie@fkhwl.com"
|
||||
* @date 2020.02.04 18:59
|
||||
* @since 1.0.0
|
||||
*/
|
||||
@UtilityClass
|
||||
public static class FeignConfigKey {
|
||||
/** FEIGN_URL_PROFIX */
|
||||
public static final String FEIGN_URL_PROFIX = "fkh.feign.url.";
|
||||
/** RIBBON_SERVICE_LIST */
|
||||
public static final String RIBBON_SERVICE_LIST = "fkh.feign.ribbon.list-of-servers";
|
||||
/** MAX_AUTO_RETRIES */
|
||||
public static final String MAX_AUTO_RETRIES = "fkh.feign.ribbon.max-auto-retries";
|
||||
/** MAX_AUTO_RETRIES_NEXT_SERVER */
|
||||
public static final String MAX_AUTO_RETRIES_NEXT_SERVER = "fkh.feign.ribbon.max-auto-retries-next-server";
|
||||
/** OK_TO_RETRY_ON_ALL_OPERATIONS */
|
||||
public static final String OK_TO_RETRY_ON_ALL_OPERATIONS = "fkh.feign.ribbon.ok-to-retry-on-all-operations";
|
||||
/** SERVER_LIST_REFRESH_INTERVAL */
|
||||
public static final String SERVER_LIST_REFRESH_INTERVAL = "fkh.feign.ribbon.server-list-refresh-interval";
|
||||
/** CONNECT_TIMEOUT */
|
||||
public static final String CONNECT_TIMEOUT = "fkh.feign.ribbon.connect-timeout";
|
||||
/** READ_TIMEOUT */
|
||||
public static final String READ_TIMEOUT = "fkh.feign.ribbon.read-timeout";
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>Company: 成都返空汇网络技术有限公司 </p>
|
||||
* <p>Description: </p>
|
||||
*
|
||||
* @author dong4j
|
||||
* @version 1.2.4
|
||||
* @email "mailto:dongshijie@fkhwl.com"
|
||||
* @date 2020.02.07 16:30
|
||||
* @since 1.0.0
|
||||
*/
|
||||
@UtilityClass
|
||||
public static class AgentConfigKey {
|
||||
/** agent 路由服务后缀, 服务端需要依赖 fkh-agent-spring-boot-starter */
|
||||
public static final String AGENT_SUFFIX = "/agent";
|
||||
/** 网关地址前缀, 发起请求时将使用 fkh.feign.ribbon.list-of-servers 配置的 ip 地址替换此字符串 */
|
||||
public static final String GATEWAY_PREFIX = "http://" + RibbonConfigKey.CLIENT_NAME + StringPool.SLASH;
|
||||
/** FEIGN_URL_PROFIX */
|
||||
public static final String FEIGN_URL_PROFIX = "fkh.agent.url.";
|
||||
|
||||
/**
|
||||
* RIBBON_SERVICE_LIST
|
||||
*
|
||||
* @deprecated 使用 {@link AgentConfigKey#GATEWAY_SERVICE_LIST} 替换
|
||||
*/
|
||||
@Deprecated
|
||||
public static final String RIBBON_SERVICE_LIST = "fkh.agent.ribbon.list-of-servers";
|
||||
/** GATEWAY_SERVICE_LIST */
|
||||
public static final String GATEWAY_SERVICE_LIST = "fkh.gateway.servers";
|
||||
/**
|
||||
* SERVER_LIST_REFRESH_INTERVAL
|
||||
*
|
||||
* @deprecated 使用 {@link AgentConfigKey#GATEWAY_SERVER_LIST_REFRESH_INTERVAL} 替换
|
||||
*/
|
||||
@Deprecated
|
||||
public static final String SERVER_LIST_REFRESH_INTERVAL = "fkh.agent.ribbon.server-list-refresh-interval";
|
||||
/** GATEWAY_SERVER_LIST_REFRESH_INTERVAL */
|
||||
public static final String GATEWAY_SERVER_LIST_REFRESH_INTERVAL = "fkh.gateway.server-list-refresh-interval";
|
||||
/**
|
||||
* CONNECT_TIMEOUT
|
||||
*
|
||||
* @deprecated 使用 {@link AgentConfigKey#GATEWAY_CONNECT_TIMEOUT} 替换
|
||||
*/
|
||||
@Deprecated
|
||||
public static final String CONNECT_TIMEOUT = "fkh.agent.ribbon.connect-timeout";
|
||||
/** GATEWAY_CONNECT_TIMEOUT */
|
||||
public static final String GATEWAY_CONNECT_TIMEOUT = "fkh.gateway.connect-timeout";
|
||||
/**
|
||||
* READ_TIMEOUT
|
||||
*
|
||||
* @deprecated 使用 {@link AgentConfigKey#GATEWAY_READ_TIMEOUT} 替换
|
||||
*/
|
||||
@Deprecated
|
||||
public static final String READ_TIMEOUT = "fkh.agent.ribbon.read-timeout";
|
||||
/** GATEWAY_READ_TIMEOUT */
|
||||
public static final String GATEWAY_READ_TIMEOUT = "fkh.gateway.read-timeout";
|
||||
/**
|
||||
* 是否开启路由转发
|
||||
*
|
||||
* @deprecated 使用 {@link AgentConfigKey#GATEWAY_REST_ENABLE_ROUTER} 替换
|
||||
*/
|
||||
@Deprecated
|
||||
public static final String REST_ENABLE_ROUTER = "fkh.agent.rest.enable-router";
|
||||
/** GATEWAY_REST_ENABLE_ROUTER */
|
||||
public static final String GATEWAY_REST_ENABLE_ROUTER = "fkh.gateway.enable-router";
|
||||
/** GATEWAY_REST_ENABLE_endpoint */
|
||||
public static final String GATEWAY_REST_ENABLE_ENDPOINT = "fkh.gateway.enable-endpoint";
|
||||
/**
|
||||
* request 请求最大长度限制
|
||||
*
|
||||
* @deprecated 使用 {@link AgentConfigKey#GATEWAY_REQUEST_MAX_LINE_LENGTH} 替换
|
||||
*/
|
||||
@Deprecated
|
||||
public static final String REQUEST_MAX_LINE_LENGTH = "fkh.agent.rest.request-max-line-length";
|
||||
/** GATEWAY_REQUEST_MAX_LINE_LENGTH */
|
||||
public static final String GATEWAY_REQUEST_MAX_LINE_LENGTH = "fkh.gateway.request-max-line-length";
|
||||
|
||||
|
||||
/** 全局重复提交检查 (如果为 false, 则不再检查每个 agent 服务是否需要检查) */
|
||||
public static final String ENABLE_REPLY_CHECK = "fkh.agent.endpoint.enable-reply-check";
|
||||
/** 全局签名检查 (如果为 false, 则不再检查每个 agent 服务是否需要检查) */
|
||||
public static final String ENABLE_SIGN_CHECK = "fkh.agent.endpoint.enable-sign-check";
|
||||
/** 启动时检查 agent service 写法是否正确 */
|
||||
public static final String ENABLE_FAIL_FAST = "fkh.agent.endpoint.enable-fail-fast";
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>Company: 成都返空汇网络技术有限公司 </p>
|
||||
* <p>Description: </p>
|
||||
*
|
||||
* @author dong4j
|
||||
* @version 1.2.4
|
||||
* @email "mailto:dongshijie@fkhwl.com"
|
||||
* @date 2020.02.07 16:39
|
||||
* @since 1.0.0
|
||||
*/
|
||||
@UtilityClass
|
||||
public static class RibbonConfigKey {
|
||||
/** ribbon 的负载 url 必须以 http://gateway 开始, 可通过 JVM 参数替换 */
|
||||
public static final String CLIENT_NAME = System.getProperty("ribbon.prefix", ConfigDefaultValue.RIBBON_NAME);
|
||||
/** MAX_AUTO_RETRIES */
|
||||
public static final String MAX_AUTO_RETRIES = CLIENT_NAME + ".ribbon.MaxAutoRetries";
|
||||
/** MAX_AUTO_RETRIES_NEXT_SERVER */
|
||||
public static final String MAX_AUTO_RETRIES_NEXT_SERVER = CLIENT_NAME + ".ribbon.MaxAutoRetriesNextServer";
|
||||
/** OK_TO_RETRY_ON_ALL_OPERATIONS */
|
||||
public static final String OK_TO_RETRY_ON_ALL_OPERATIONS = CLIENT_NAME + ".ribbon.OkToRetryOnAllOperations";
|
||||
/** SERVER_LIST_REFRESH_INTERVAL */
|
||||
public static final String SERVER_LIST_REFRESH_INTERVAL = CLIENT_NAME + ".ribbon.ServerListRefreshInterval";
|
||||
/** CONNECT_TIMEOUT */
|
||||
public static final String CONNECT_TIMEOUT = CLIENT_NAME + ".ribbon.ConnectTimeout";
|
||||
/** READ_TIMEOUT */
|
||||
public static final String READ_TIMEOUT = CLIENT_NAME + ".ribbon.ReadTimeout";
|
||||
/** LIST_OF_SERVERS */
|
||||
public static final String LIST_OF_SERVERS = CLIENT_NAME + ".ribbon.listOfServers";
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>Company: 成都返空汇网络技术有限公司 </p>
|
||||
* <p>Description: </p>
|
||||
*
|
||||
* @author dong4j
|
||||
* @version 1.3.0
|
||||
* @email "mailto:dongshijie@fkhwl.com"
|
||||
* @date 2020.04.03 11:40
|
||||
* @since 1.0.0
|
||||
*/
|
||||
@UtilityClass
|
||||
public static class ScheduleConfigKey {
|
||||
/** ENABLE */
|
||||
public static final String ENABLE = "fkh.schedule.enable";
|
||||
/** EXECUTOR_APP_NAME */
|
||||
public static final String EXECUTOR_APP_NAME = "fkh.schedule.executor.app-name";
|
||||
/** EXECUTOR_APP_IP */
|
||||
public static final String EXECUTOR_APP_IP = "fkh.schedule.executor.id";
|
||||
/** EXECUTOR_APP_PORT */
|
||||
public static final String EXECUTOR_APP_PORT = "fkh.schedule.executor.port";
|
||||
/** EXECUTOR_APP_LOG_PATH */
|
||||
public static final String EXECUTOR_APP_LOG_PATH = "fkh.schedule.executor.log-path";
|
||||
/** EXECUTOR_APP_LOG_RETENTIONDAYS */
|
||||
public static final String EXECUTOR_APP_LOG_RETENTIONDAYS = "fkh.schedule.executor.log-retention-days";
|
||||
/** SCHEDULE_ACCESSTOKEN */
|
||||
public static final String SCHEDULE_ACCESSTOKEN = "fkh.schedule.access-token";
|
||||
/** SCHEDULE_ADMIN_ADDRESSES */
|
||||
public static final String SCHEDULE_ADMIN_ADDRESSES = "fkh.schedule.admin-addresses";
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>Company: 成都返空汇网络技术有限公司 </p>
|
||||
* <p>Description: </p>
|
||||
*
|
||||
* @author wanghao
|
||||
* @version 1.7.0
|
||||
* @email "mailto:wanghao@fkhwl.com"
|
||||
* @date 2020.12.08 12:08
|
||||
* @since 1.7.0
|
||||
*/
|
||||
@UtilityClass
|
||||
public static class MqConfigKey {
|
||||
|
||||
/** BOOTSTRAP_SERVERS */
|
||||
public static final String BOOTSTRAP_SERVERS = "fkh.mq.kafka.bootstrap-servers";
|
||||
/** NAME_SERVER_ADDRESS */
|
||||
public static final String NAME_SERVER_ADDRESS = "fkh.mq.rocketmq.name-server-address";
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>Company: 成都返空汇网络技术有限公司 </p>
|
||||
* <p>Description: </p>
|
||||
*
|
||||
* @author dong4j
|
||||
* @version 1.0.0
|
||||
* @email "mailto:dongshijie@fkhwl.com"
|
||||
* @date 2022.01.21 11:38
|
||||
* @since 2022.1.1
|
||||
*/
|
||||
public static class LogcatConfigKey {
|
||||
/** ADMIN_URL */
|
||||
public static final String ADMIN_URL = "fkh.logcat.server.url";
|
||||
}
|
||||
}
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
package com.aos.element.basic.basic.constant;
|
||||
|
||||
/**
|
||||
* <p>Company: 成都返空汇网络技术有限公司</p>
|
||||
* <p>Description: </p>
|
||||
*
|
||||
* @author dong4j
|
||||
* @version 1.0.0
|
||||
* @email "mailto:dongshijie@fkhwl.com"
|
||||
* @date 2020.08.31 21:51
|
||||
* @since 1.6.0
|
||||
*/
|
||||
public final class TraceConstant {
|
||||
/** TRACE_ID */
|
||||
public static final String TRACE_ID = BasicConstant.TRACE_ID;
|
||||
/** X_TRACE_ID */
|
||||
public static final String X_TRACE_ID = "X-Trace-Id";
|
||||
}
|
||||
+78
@@ -0,0 +1,78 @@
|
||||
package com.aos.element.basic.basic.context;
|
||||
|
||||
import com.alibaba.ttl.TransmittableThreadLocal;
|
||||
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.web.context.request.RequestAttributes;
|
||||
|
||||
import lombok.experimental.UtilityClass;
|
||||
|
||||
/**
|
||||
* <p>Company: 成都返空汇网络技术有限公司</p>
|
||||
* <p>Description: 处理 agent 服务层在多线程的情况下正确获取 HttpServletRequest 的问题 </p>
|
||||
*
|
||||
* @author dong4j
|
||||
* @version 1.0.0
|
||||
* @email "mailto:dongshijie@fkhwl.com"
|
||||
* @date 2021.03.11 11:39
|
||||
* @since 1.8.0
|
||||
*/
|
||||
@UtilityClass
|
||||
public class AgentRequestContextHolder {
|
||||
|
||||
/** inheritableRequestAttributesHolder */
|
||||
private static final TransmittableThreadLocal<RequestAttributes> INHERITABLE_REQUEST_ATTRIBUTES_HOLDER
|
||||
= new TransmittableThreadLocal<>();
|
||||
|
||||
/**
|
||||
* Reset the RequestAttributes for the current thread.
|
||||
*
|
||||
* @since 1.8.0
|
||||
*/
|
||||
public static void resetRequestAttributes() {
|
||||
INHERITABLE_REQUEST_ATTRIBUTES_HOLDER.remove();
|
||||
}
|
||||
|
||||
/**
|
||||
* Bind the given RequestAttributes to the current thread,
|
||||
* <i>not</i> exposing it as inheritable for child threads.
|
||||
*
|
||||
* @param attributes the RequestAttributes to expose
|
||||
* @since 1.8.0
|
||||
*/
|
||||
public static void setRequestAttributes(@Nullable RequestAttributes attributes) {
|
||||
if (attributes == null) {
|
||||
resetRequestAttributes();
|
||||
} else {
|
||||
INHERITABLE_REQUEST_ATTRIBUTES_HOLDER.set(attributes);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the RequestAttributes currently bound to the thread.
|
||||
*
|
||||
* @return the RequestAttributes currently bound to the thread, or {@code null} if none bound
|
||||
* @since 1.8.0
|
||||
*/
|
||||
@Nullable
|
||||
public static RequestAttributes getRequestAttributes() {
|
||||
return INHERITABLE_REQUEST_ATTRIBUTES_HOLDER.get();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Current request attributes
|
||||
*
|
||||
* @return the request attributes
|
||||
* @throws IllegalStateException illegal state exception
|
||||
* @since 1.8.0
|
||||
*/
|
||||
public static RequestAttributes currentRequestAttributes() throws IllegalStateException {
|
||||
RequestAttributes attributes = getRequestAttributes();
|
||||
if (attributes == null) {
|
||||
throw new IllegalStateException("当前线程不存在 Request 对象");
|
||||
}
|
||||
return attributes;
|
||||
}
|
||||
|
||||
}
|
||||
+55
@@ -0,0 +1,55 @@
|
||||
package com.aos.element.basic.basic.context;
|
||||
|
||||
import com.alibaba.ttl.TransmittableThreadLocal;
|
||||
|
||||
import org.jetbrains.annotations.Contract;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import lombok.experimental.UtilityClass;
|
||||
|
||||
/**
|
||||
* <p>Company: 成都返空汇网络技术有限公司</p>
|
||||
* <p>Description: </p>
|
||||
* todo-dong4j : (2021.10.31 17:24) [重构, 只用来保存 agent service]
|
||||
*
|
||||
* @author dong4j
|
||||
* @version 1.0.0
|
||||
* @email "mailto:dongshijie@fkhwl.com"
|
||||
* @date 2021.01.20 15:53
|
||||
* @since 1.7.1
|
||||
*/
|
||||
@UtilityClass
|
||||
public class ComponentThreadLocal {
|
||||
/** AGENT_SERVICES */
|
||||
public static final String AGENT_SERVICES = "agentService";
|
||||
/** AGENT_API */
|
||||
public static final String AGENT_API = "api.value";
|
||||
/** AGENT_CODE */
|
||||
public static final String AGENT_CODE = "api.code";
|
||||
|
||||
/** context */
|
||||
private static final TransmittableThreadLocal<Map<String, Object>> CONTEXT = new TransmittableThreadLocal<>();
|
||||
|
||||
/**
|
||||
* Context
|
||||
*
|
||||
* @return the thread context map
|
||||
* @since 1.7.1
|
||||
*/
|
||||
@Contract(pure = true)
|
||||
public static TransmittableThreadLocal<Map<String, Object>> context() {
|
||||
return CONTEXT;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear
|
||||
*
|
||||
* @since 1.7.1
|
||||
*/
|
||||
@Contract(pure = true)
|
||||
public static void clear() {
|
||||
CONTEXT.remove();
|
||||
}
|
||||
|
||||
}
|
||||
+78
@@ -0,0 +1,78 @@
|
||||
package com.aos.element.basic.basic.context;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* <p>Company: 成都返空汇网络技术有限公司</p>
|
||||
* <p>Description: 扩展出来的tenantId clientId </p>
|
||||
* @author wanghao
|
||||
* @version 1.8.0
|
||||
* @email "mailto:wanghao@fkhwl.com"
|
||||
* @date 2021.03.08 15:04
|
||||
* @since 1.8.0
|
||||
*/
|
||||
public class ExpandIds implements Serializable {
|
||||
|
||||
/** serialVersionUID */
|
||||
private static final long serialVersionUID = -1449027854558101307L;
|
||||
|
||||
/**
|
||||
* 如果 header 中存在 AgentConstant#X_AGENT_TENANTID, 则会在接收到请求后自动写入到此字段中.
|
||||
*
|
||||
* @since 1.8.0
|
||||
*/
|
||||
@Nullable
|
||||
private Long tenantId;
|
||||
|
||||
/**
|
||||
* 如果 header 中存在 AgentConstant#X_AGENT_APPID, 则会在接收到请求后自动写入到此字段中.
|
||||
*
|
||||
* @since 1.8.0
|
||||
*/
|
||||
@Nullable
|
||||
private String clientId;
|
||||
|
||||
/**
|
||||
* Get tenant id
|
||||
*
|
||||
* @return the long
|
||||
* @since 1.8.0
|
||||
*/
|
||||
public Optional<Long> getTenantId() {
|
||||
return Optional.ofNullable(this.tenantId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get client id
|
||||
*
|
||||
* @return the string
|
||||
* @since 1.8.0
|
||||
*/
|
||||
public Optional<String> getClientId() {
|
||||
return Optional.ofNullable(this.clientId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets tenant id *
|
||||
*
|
||||
* @param tenantId tenant id
|
||||
* @since 1.8.0
|
||||
*/
|
||||
public void setTenantId(@NotNull Long tenantId) {
|
||||
this.tenantId = tenantId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets client id *
|
||||
*
|
||||
* @param clientId client id
|
||||
* @since 1.8.0
|
||||
*/
|
||||
public void setClientId(@NotNull String clientId) {
|
||||
this.clientId = clientId;
|
||||
}
|
||||
}
|
||||
+47
@@ -0,0 +1,47 @@
|
||||
package com.aos.element.basic.basic.context;
|
||||
|
||||
import com.alibaba.ttl.TransmittableThreadLocal;
|
||||
|
||||
import org.jetbrains.annotations.Contract;
|
||||
|
||||
import lombok.experimental.UtilityClass;
|
||||
|
||||
/**
|
||||
* <p>Company: 成都返空汇网络技术有限公司 </p>
|
||||
* <p>Description: ExpandIdsContext 用来存储 clientId、tenantId 相关信息 </p>
|
||||
*
|
||||
* @author wanghao
|
||||
* @version 1.8.0
|
||||
* @email "mailto:wanghao@fkhwl.com"
|
||||
* @date 2021.03.08 14:59
|
||||
* @since 1.8.0
|
||||
*/
|
||||
@UtilityClass
|
||||
public class ExpandIdsContext {
|
||||
|
||||
/** CONTEXT */
|
||||
private static final TransmittableThreadLocal<ExpandIds> CONTEXT = new TransmittableThreadLocal<>();
|
||||
|
||||
|
||||
/**
|
||||
* Context
|
||||
*
|
||||
* @return the transmittable thread local
|
||||
* @since 1.8.0
|
||||
*/
|
||||
@Contract(pure = true)
|
||||
public static TransmittableThreadLocal<ExpandIds> context() {
|
||||
return CONTEXT;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear
|
||||
*
|
||||
* @since 1.8.0
|
||||
*/
|
||||
@Contract(pure = true)
|
||||
public static void clear() {
|
||||
CONTEXT.remove();
|
||||
}
|
||||
|
||||
}
|
||||
+79
@@ -0,0 +1,79 @@
|
||||
package com.aos.element.basic.basic.context;
|
||||
|
||||
import com.alibaba.ttl.TransmittableThreadLocal;
|
||||
|
||||
import org.jetbrains.annotations.Contract;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
/**
|
||||
* <p>Company: 成都返空汇网络技术有限公司 </p>
|
||||
* <p>Description: 全局上下文 </p>
|
||||
*
|
||||
* @author dong4j
|
||||
* @version 1.0.0
|
||||
* @email "mailto:dongshijie@fkhwl.com"
|
||||
* @date 2022.01.20 23:53
|
||||
* @since 2022.1.1
|
||||
*/
|
||||
@Slf4j
|
||||
public final class GlobalContext {
|
||||
|
||||
/** 公共使用 */
|
||||
private static final TransmittableThreadLocal<Map<String, Object>> COMMON = new TransmittableThreadLocal<>();
|
||||
|
||||
/**
|
||||
* common
|
||||
*
|
||||
* @param key key
|
||||
* @return the transmittable thread local
|
||||
* @since 2022.1.1
|
||||
*/
|
||||
@Contract(pure = true)
|
||||
public static @Nullable Object get(String key) {
|
||||
Map<String, Object> cache = COMMON.get();
|
||||
if (cache == null) {
|
||||
return null;
|
||||
} else {
|
||||
return cache.get(key);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Put
|
||||
*
|
||||
* @param key key
|
||||
* @param value value
|
||||
* @since 2022.1.1
|
||||
*/
|
||||
@Contract(pure = true)
|
||||
public static void put(String key, Object value) {
|
||||
Map<String, Object> cache = COMMON.get();
|
||||
if (cache == null) {
|
||||
cache = new HashMap<>(8);
|
||||
cache.put(key, value);
|
||||
COMMON.set(cache);
|
||||
} else if (cache.get(key) != null) {
|
||||
// 直接覆盖
|
||||
cache.put(key, value);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear
|
||||
*
|
||||
* @param key key
|
||||
* @since 2022.1.1
|
||||
*/
|
||||
@Contract(pure = true)
|
||||
public static void clear(String key) {
|
||||
final Map<String, Object> cache = COMMON.get();
|
||||
if (cache != null) {
|
||||
cache.remove(key);
|
||||
}
|
||||
}
|
||||
}
|
||||
+45
@@ -0,0 +1,45 @@
|
||||
package com.aos.element.basic.basic.context;
|
||||
|
||||
import com.alibaba.ttl.TransmittableThreadLocal;
|
||||
|
||||
import org.jetbrains.annotations.Contract;
|
||||
|
||||
import lombok.experimental.UtilityClass;
|
||||
|
||||
/**
|
||||
* <p>Company: 成都返空汇网络技术有限公司</p>
|
||||
* <p>Description: TraceId 用来存储traceID相关信息 </p>
|
||||
*
|
||||
* @author dong4j
|
||||
* @version 1.0.0
|
||||
* @email "mailto:dongshijie@fkhwl.com"
|
||||
* @date 2020.06.23 23:54
|
||||
* @since 1.6.0
|
||||
*/
|
||||
@UtilityClass
|
||||
public class Trace {
|
||||
/** context */
|
||||
private static final TransmittableThreadLocal<String> CONTEXT = new TransmittableThreadLocal<>();
|
||||
|
||||
/**
|
||||
* Context
|
||||
*
|
||||
* @return the thread context map
|
||||
* @since 1.6.0
|
||||
*/
|
||||
@Contract(pure = true)
|
||||
public static TransmittableThreadLocal<String> context() {
|
||||
return CONTEXT;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear
|
||||
*
|
||||
* @since 1.6.0
|
||||
*/
|
||||
@Contract(pure = true)
|
||||
public static void clear() {
|
||||
CONTEXT.remove();
|
||||
}
|
||||
|
||||
}
|
||||
+37
@@ -0,0 +1,37 @@
|
||||
package com.aos.element.basic.basic.exception;
|
||||
|
||||
/**
|
||||
* <p>Company: 成都返空汇网络技术有限公司 </p>
|
||||
* <p>Description: </p>
|
||||
*
|
||||
* @author dong4j
|
||||
* @version 1.0.0
|
||||
* @email "mailto:dongshijie@fkhwl.com"
|
||||
* @date 2020.11.18 00:26
|
||||
* @since 1.7.0
|
||||
*/
|
||||
public class AssertionFailedException extends ServiceInternalException {
|
||||
/** serialVersionUID */
|
||||
private static final long serialVersionUID = 7198353389256089258L;
|
||||
/** DEFAULT_MESSAGE */
|
||||
private static final String DEFAULT_MESSAGE = "服务内部错误: ";
|
||||
|
||||
/**
|
||||
* Basic exception
|
||||
*
|
||||
* @since 1.7.0
|
||||
*/
|
||||
public AssertionFailedException() {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* Base exception
|
||||
*
|
||||
* @param describe describe
|
||||
* @since 1.7.0
|
||||
*/
|
||||
public AssertionFailedException(String describe) {
|
||||
super(DEFAULT_MESSAGE + describe);
|
||||
}
|
||||
}
|
||||
+150
@@ -0,0 +1,150 @@
|
||||
package com.aos.element.basic.basic.exception;
|
||||
|
||||
import com.aos.element.basic.basic.context.Trace;
|
||||
import com.aos.element.basic.basic.support.StrFormatter;
|
||||
|
||||
import java.io.PrintStream;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
/**
|
||||
* <p>Company: 成都返空汇网络技术有限公司</p>
|
||||
* <p>Description: 框架基础异常基类 </p>
|
||||
*
|
||||
* @author dong4j
|
||||
* @version 1.0.4
|
||||
* @email "mailto:dongshijie@gmail.com"
|
||||
* @date 2020.02.09 16:50
|
||||
* @since 1.0.4
|
||||
*/
|
||||
@Slf4j
|
||||
@SuppressWarnings("java:S1165")
|
||||
public class BasicException extends RuntimeException {
|
||||
/** serialVersionUID */
|
||||
private static final long serialVersionUID = 3076052230646484392L;
|
||||
/** 异常消息参数 */
|
||||
protected transient Object[] args;
|
||||
/** Code */
|
||||
@Getter
|
||||
protected String code;
|
||||
/** Message */
|
||||
protected String message;
|
||||
/** Trace id */
|
||||
@Getter
|
||||
protected String traceId;
|
||||
/** DEFAULT_ERROR_CODE */
|
||||
public static final String DEFAULT_ERROR_CODE = "B.F-5000";
|
||||
/** DEFAULT_MESSAGE */
|
||||
public static final String DEFAULT_MESSAGE = "服务内部错误";
|
||||
|
||||
/**
|
||||
* Basic exception
|
||||
*
|
||||
* @since 1.4.0
|
||||
*/
|
||||
public BasicException() {
|
||||
this(DEFAULT_MESSAGE);
|
||||
}
|
||||
|
||||
/**
|
||||
* msg 占位符替换
|
||||
*
|
||||
* @param message message
|
||||
* @param args args
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public BasicException(String message, Object... args) {
|
||||
this(StrFormatter.mergeFormat(message, args));
|
||||
}
|
||||
|
||||
/**
|
||||
* Instantiates a new Base exception.
|
||||
*
|
||||
* @param message message
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public BasicException(String message) {
|
||||
this(DEFAULT_ERROR_CODE, message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Basic exception
|
||||
*
|
||||
* @param code code
|
||||
* @param message message
|
||||
* @since 1.6.0
|
||||
*/
|
||||
public BasicException(String code, String message) {
|
||||
super(message);
|
||||
this.init(code, message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Base exception
|
||||
*
|
||||
* @param cause cause
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public BasicException(Throwable cause) {
|
||||
this(DEFAULT_MESSAGE, cause);
|
||||
}
|
||||
|
||||
/**
|
||||
* Base exception
|
||||
*
|
||||
* @param message message
|
||||
* @param cause cause
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public BasicException(String message, Throwable cause) {
|
||||
this(DEFAULT_ERROR_CODE, message, cause);
|
||||
}
|
||||
|
||||
/**
|
||||
* Basic exception
|
||||
*
|
||||
* @param code code
|
||||
* @param message message
|
||||
* @param cause cause
|
||||
* @since 1.6.0
|
||||
*/
|
||||
public BasicException(String code, String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
this.init(code, message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Init
|
||||
*
|
||||
* @param code code
|
||||
* @param message message
|
||||
* @since 1.9.0
|
||||
*/
|
||||
private void init(String code, String message) {
|
||||
this.code = code;
|
||||
this.message = message;
|
||||
this.traceId = Trace.context().get();
|
||||
}
|
||||
|
||||
/**
|
||||
* 重写打印异常堆栈, 转为日志输出.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
@Override
|
||||
public void printStackTrace() {
|
||||
log.error("", this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Prints this throwable and its backtrace to the specified print stream.
|
||||
*
|
||||
* @param s {@code PrintStream} to use for output
|
||||
* @since 1.6.0
|
||||
*/
|
||||
@Override
|
||||
public void printStackTrace(PrintStream s) {
|
||||
log.error("", this);
|
||||
}
|
||||
}
|
||||
+132
@@ -0,0 +1,132 @@
|
||||
package com.aos.element.basic.basic.exception;
|
||||
|
||||
import com.aos.element.basic.basic.util.StringUtils;
|
||||
|
||||
import java.io.PrintStream;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
/**
|
||||
* <p>Company: 成都返空汇网络技术有限公司</p>
|
||||
* <p>Description: 服务内部错误异常, 会输出堆栈信息, traceId, 当前应用名和 ip </p>
|
||||
*
|
||||
* @author dong4j
|
||||
* @version 1.0.0
|
||||
* @email "mailto:dongshijie@fkhwl.com"
|
||||
* @date 2020.11.18 16:11
|
||||
* @since 1.7.0
|
||||
*/
|
||||
@Slf4j
|
||||
public class ServiceInternalException extends RuntimeException {
|
||||
/** serialVersionUID */
|
||||
private static final long serialVersionUID = -3466744408568354601L;
|
||||
|
||||
/** 应用名 */
|
||||
@Setter
|
||||
@Getter
|
||||
protected String applicationName;
|
||||
/** 应用 ip */
|
||||
@Setter
|
||||
@Getter
|
||||
protected String ip;
|
||||
/** 应用端口 */
|
||||
@Setter
|
||||
@Getter
|
||||
protected Integer port;
|
||||
/** 当前环境 */
|
||||
@Setter
|
||||
@Getter
|
||||
protected String env;
|
||||
/** Rpc */
|
||||
@Setter
|
||||
@Getter
|
||||
protected boolean rpc;
|
||||
/** Trace id */
|
||||
@Setter
|
||||
@Getter
|
||||
protected String traceId;
|
||||
/** DEFAULT_ERROR_CODE */
|
||||
public static final String DEFAULT_ERROR_CODE = "S.I-5000";
|
||||
/** DEFAULT_MESSAGE */
|
||||
public static final String DEFAULT_MESSAGE = "服务内部错误";
|
||||
|
||||
/**
|
||||
* Basic exception
|
||||
*
|
||||
* @since 1.7.0
|
||||
*/
|
||||
public ServiceInternalException() {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* Service internal exception
|
||||
*
|
||||
* @param throwable throwable
|
||||
* @since 1.7.0
|
||||
*/
|
||||
public ServiceInternalException(Throwable throwable) {
|
||||
super(DEFAULT_MESSAGE, throwable);
|
||||
}
|
||||
|
||||
/**
|
||||
* Service internal exception
|
||||
*
|
||||
* @param message message
|
||||
* @since 1.7.0
|
||||
*/
|
||||
public ServiceInternalException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Service internal exception
|
||||
*
|
||||
* @param message message
|
||||
* @param throwable throwable
|
||||
* @since 1.7.0
|
||||
*/
|
||||
public ServiceInternalException(String message, Throwable throwable) {
|
||||
super(message, throwable);
|
||||
}
|
||||
|
||||
/**
|
||||
* 重写打印异常堆栈, 转为日志输出.
|
||||
*
|
||||
* @since 1.7.0
|
||||
*/
|
||||
@Override
|
||||
public void printStackTrace() {
|
||||
log.error("", this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Prints this throwable and its backtrace to the specified print stream.
|
||||
*
|
||||
* @param s {@code PrintStream} to use for output
|
||||
* @since 1.7.0
|
||||
*/
|
||||
@Override
|
||||
public void printStackTrace(PrintStream s) {
|
||||
log.error("", this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets message *
|
||||
*
|
||||
* @return the message
|
||||
* @since 1.7.0
|
||||
*/
|
||||
@Override
|
||||
public String getMessage() {
|
||||
return super.getMessage()
|
||||
+ (StringUtils.isBlank(this.applicationName) ? "" : ": applicationName='" + this.applicationName + '\'')
|
||||
+ (StringUtils.isBlank(this.ip) ? "" : ", ip='" + this.ip + '\'')
|
||||
+ (this.port == null ? "" : ", port='" + this.port + '\'')
|
||||
+ (StringUtils.isBlank(this.env) ? "" : ", env='" + this.env + '\'')
|
||||
+ (StringUtils.isBlank(this.traceId) ? "" : ", traceId='" + this.traceId);
|
||||
}
|
||||
|
||||
}
|
||||
+27
@@ -0,0 +1,27 @@
|
||||
package com.aos.element.basic.basic.exception;
|
||||
|
||||
/**
|
||||
* <p>Company: 成都返空汇网络技术有限公司</p>
|
||||
* <p>Description: </p>
|
||||
*
|
||||
* @author dong4j
|
||||
* @version 1.0.0
|
||||
* @email "mailto:dongshijie@fkhwl.com"
|
||||
* @date 2021.01.26 13:22
|
||||
* @since 1.7.1
|
||||
*/
|
||||
public class TimeoutUtilsExecuteException extends Exception {
|
||||
/** serialVersionUID */
|
||||
private static final long serialVersionUID = 5896555103722435483L;
|
||||
|
||||
/**
|
||||
* Timeout utils execute exception
|
||||
*
|
||||
* @param message message
|
||||
* @since 1.7.1
|
||||
*/
|
||||
public TimeoutUtilsExecuteException(String message) {
|
||||
super(message);
|
||||
|
||||
}
|
||||
}
|
||||
+37
@@ -0,0 +1,37 @@
|
||||
package com.aos.element.basic.basic.serialize;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonParser;
|
||||
import com.fasterxml.jackson.databind.DeserializationContext;
|
||||
import com.fasterxml.jackson.databind.JsonDeserializer;
|
||||
import com.aos.element.basic.basic.util.StringUtils;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* <p>Company: 成都返空汇网络技术有限公司</p>
|
||||
* <p>Description: </p>
|
||||
*
|
||||
* @author dong4j
|
||||
* @version 1.0.0
|
||||
* @email "mailto:dongshijie@fkhwl.com"
|
||||
* @date 2021.05.26 16:40
|
||||
* @since 1.9.0
|
||||
*/
|
||||
public class StringTrimmerDeserializer extends JsonDeserializer<String> {
|
||||
|
||||
/**
|
||||
* Deserialize
|
||||
*
|
||||
* @param jsonParser json parser
|
||||
* @param deserializationContext deserialization context
|
||||
* @return the string
|
||||
* @throws IOException io exception
|
||||
* @since 1.9.0
|
||||
*/
|
||||
@Override
|
||||
@SuppressWarnings("java:S3252")
|
||||
public String deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException {
|
||||
return StringUtils.trimWhitespace(jsonParser.getValueAsString());
|
||||
}
|
||||
|
||||
}
|
||||
+36
@@ -0,0 +1,36 @@
|
||||
package com.aos.element.basic.basic.serialize;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonGenerator;
|
||||
import com.fasterxml.jackson.databind.JsonSerializer;
|
||||
import com.fasterxml.jackson.databind.SerializerProvider;
|
||||
import com.aos.element.basic.basic.util.StringUtils;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* <p>Company: 成都返空汇网络技术有限公司</p>
|
||||
* <p>Description: </p>
|
||||
*
|
||||
* @author dong4j
|
||||
* @version 1.0.0
|
||||
* @email "mailto:dongshijie@fkhwl.com"
|
||||
* @date 2021.05.26 16:40
|
||||
* @since 1.9.0
|
||||
*/
|
||||
public class StringTrimmerSerializer extends JsonSerializer<String> {
|
||||
|
||||
/**
|
||||
* Serialize
|
||||
*
|
||||
* @param s s
|
||||
* @param jsonGenerator json generator
|
||||
* @param serializerProvider serializer provider
|
||||
* @throws IOException io exception
|
||||
* @since 1.9.0
|
||||
*/
|
||||
@Override
|
||||
@SuppressWarnings("java:S3252")
|
||||
public void serialize(String s, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException {
|
||||
jsonGenerator.writeString(StringUtils.trimWhitespace(s));
|
||||
}
|
||||
}
|
||||
+59
@@ -0,0 +1,59 @@
|
||||
package com.aos.element.basic.basic.ssl;
|
||||
|
||||
import java.security.cert.X509Certificate;
|
||||
|
||||
import javax.net.ssl.X509TrustManager;
|
||||
|
||||
/**
|
||||
* <p>Company: 成都返空汇网络技术有限公司</p>
|
||||
* <p>Description: 不进行证书校验 </p>
|
||||
*
|
||||
* @author dong4j
|
||||
* @version 1.0.0
|
||||
* @email "mailto:dongshijie@fkhwl.com"
|
||||
* @date 2020.01.27 17:31
|
||||
* @since 1.0.0
|
||||
*/
|
||||
@SuppressWarnings("java:S4830")
|
||||
public class DisableValidationTrustManager implements X509TrustManager {
|
||||
|
||||
/**
|
||||
* The constant INSTANCE.
|
||||
*/
|
||||
public static final X509TrustManager INSTANCE = new DisableValidationTrustManager();
|
||||
|
||||
/**
|
||||
* Check client trusted *
|
||||
*
|
||||
* @param x509Certificates x 509 certificates
|
||||
* @param s s
|
||||
* @since 1.0.0
|
||||
*/
|
||||
@Override
|
||||
public void checkClientTrusted(X509Certificate[] x509Certificates, String s) {
|
||||
// nothing do to
|
||||
}
|
||||
|
||||
/**
|
||||
* Check server trusted *
|
||||
*
|
||||
* @param x509Certificates x 509 certificates
|
||||
* @param s s
|
||||
* @since 1.0.0
|
||||
*/
|
||||
@Override
|
||||
public void checkServerTrusted(X509Certificate[] x509Certificates, String s) {
|
||||
// nothing do to
|
||||
}
|
||||
|
||||
/**
|
||||
* Get accepted issuers x 509 certificate [ ]
|
||||
*
|
||||
* @return the x 509 certificate [ ]
|
||||
* @since 1.0.0
|
||||
*/
|
||||
@Override
|
||||
public X509Certificate[] getAcceptedIssuers() {
|
||||
return new X509Certificate[0];
|
||||
}
|
||||
}
|
||||
+34
@@ -0,0 +1,34 @@
|
||||
package com.aos.element.basic.basic.ssl;
|
||||
|
||||
import javax.net.ssl.HostnameVerifier;
|
||||
import javax.net.ssl.SSLSession;
|
||||
|
||||
/**
|
||||
* <p>Company: 成都返空汇网络技术有限公司</p>
|
||||
* <p>Description: 信任所有 host name </p>
|
||||
*
|
||||
* @author dong4j
|
||||
* @version 1.0.0
|
||||
* @email "mailto:dongshijie@fkhwl.com"
|
||||
* @date 2020.01.27 18:10
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public class TrustAllHostNames implements HostnameVerifier {
|
||||
/**
|
||||
* The constant INSTANCE.
|
||||
*/
|
||||
public static final TrustAllHostNames INSTANCE = new TrustAllHostNames();
|
||||
|
||||
/**
|
||||
* Verify boolean
|
||||
*
|
||||
* @param s s
|
||||
* @param sslSession ssl session
|
||||
* @return the boolean
|
||||
* @since 1.0.0
|
||||
*/
|
||||
@Override
|
||||
public boolean verify(String s, SSLSession sslSession) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
+709
@@ -0,0 +1,709 @@
|
||||
package com.aos.element.basic.basic.support;
|
||||
|
||||
import com.google.common.collect.Maps;
|
||||
|
||||
import org.jetbrains.annotations.Contract;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.AbstractCollection;
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.ConcurrentMap;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
/**
|
||||
* <p>Company: 成都返空汇网络技术有限公司 </p>
|
||||
* <p>Description: 线程安全的 Map 工厂类</p>
|
||||
*
|
||||
* @param <K> parameter
|
||||
* @param <V> parameter
|
||||
* @author dong4j
|
||||
* @version 1.0.0
|
||||
* @email "mailto:dongshijie@fkhwl.com"
|
||||
* @date 2020.05.19 10:04
|
||||
* @since 1.4.0
|
||||
*/
|
||||
@SuppressWarnings("checkstyle:ModifierOrder")
|
||||
public abstract class ConcurrentFactoryMap<K, V> implements ConcurrentMap<K, V> {
|
||||
/** NULL */
|
||||
private static final Object NULL = sentinel("ObjectUtils.NULL");
|
||||
/** My map */
|
||||
private final ConcurrentMap<K, V> myMap = this.createMap();
|
||||
|
||||
/**
|
||||
* Concurrent factory map
|
||||
*
|
||||
* @since 1.4.0
|
||||
*/
|
||||
private ConcurrentFactoryMap() {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Sentinel
|
||||
*
|
||||
* @param name name
|
||||
* @return the object
|
||||
* @since 1.4.0
|
||||
*/
|
||||
@Contract(value = "_ -> new", pure = true)
|
||||
@NotNull
|
||||
public static Object sentinel(@NotNull @NonNls String name) {
|
||||
return new Sentinel(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create map
|
||||
*
|
||||
* @param <T> parameter
|
||||
* @param <V> parameter
|
||||
* @param computeValue compute value
|
||||
* @return the concurrent map
|
||||
* @since 1.4.0
|
||||
*/
|
||||
@Contract("_ -> new")
|
||||
@NotNull
|
||||
public static <T, V> ConcurrentMap<T, V> createMap(@NotNull Function<? super T, ? extends V> computeValue) {
|
||||
return new ConcurrentFactoryMap<T, V>() {
|
||||
@Nullable
|
||||
@Override
|
||||
protected V create(T key) {
|
||||
return computeValue.apply(key);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Create weak map
|
||||
*
|
||||
* @param <T> parameter
|
||||
* @param <V> parameter
|
||||
* @param compute compute
|
||||
* @return Concurrent factory map with weak keys, strong values
|
||||
* @since 1.4.0
|
||||
*/
|
||||
@NotNull
|
||||
public static <T, V> ConcurrentMap<T, V> createWeakMap(@NotNull Function<? super T, ? extends V> compute) {
|
||||
return create(compute, ConcurrentHashMap::new);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create
|
||||
*
|
||||
* @param <K> parameter
|
||||
* @param <V> parameter
|
||||
* @param computeValue compute value
|
||||
* @param mapCreator map creator
|
||||
* @return the concurrent map
|
||||
* @since 1.4.0
|
||||
*/
|
||||
@Contract("_, _ -> new")
|
||||
@NotNull
|
||||
public static <K, V> ConcurrentMap<K, V> create(@NotNull Function<? super K, ? extends V> computeValue,
|
||||
@NotNull Supplier<? extends ConcurrentMap<K, V>> mapCreator) {
|
||||
return new ConcurrentFactoryMap<K, V>() {
|
||||
@Nullable
|
||||
@Override
|
||||
protected V create(K key) {
|
||||
return computeValue.apply(key);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
protected ConcurrentMap<K, V> createMap() {
|
||||
return mapCreator.get();
|
||||
}
|
||||
};
|
||||
}
|
||||
/**
|
||||
* Remove value
|
||||
*
|
||||
* @param value value
|
||||
* @return the boolean
|
||||
* @since 1.4.0
|
||||
*/
|
||||
public boolean removeValue(Object value) {
|
||||
Object t = notNull(value);
|
||||
//noinspection SuspiciousMethodCalls
|
||||
return this.myMap.values().remove(t);
|
||||
}
|
||||
|
||||
/**
|
||||
* Size
|
||||
*
|
||||
* @return the int
|
||||
* @since 1.4.0
|
||||
*/
|
||||
@Override
|
||||
public int size() {
|
||||
return this.myMap.size();
|
||||
}
|
||||
|
||||
/**
|
||||
* Is empty
|
||||
*
|
||||
* @return the boolean
|
||||
* @since 1.4.0
|
||||
*/
|
||||
@Contract(pure = true)
|
||||
@Override
|
||||
public boolean isEmpty() {
|
||||
return this.myMap.isEmpty();
|
||||
}
|
||||
|
||||
/**
|
||||
* Contains key
|
||||
*
|
||||
* @param key key
|
||||
* @return the boolean
|
||||
* @since 1.4.0
|
||||
*/
|
||||
@Contract(pure = true)
|
||||
@Override
|
||||
public final boolean containsKey(Object key) {
|
||||
return this.myMap.containsKey(notNull(key));
|
||||
}
|
||||
|
||||
/**
|
||||
* Contains value
|
||||
*
|
||||
* @param value value
|
||||
* @return the boolean
|
||||
* @since 1.4.0
|
||||
*/
|
||||
@Contract(pure = true)
|
||||
@Override
|
||||
public boolean containsValue(Object value) {
|
||||
return this.myMap.containsValue(notNull(value));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get
|
||||
*
|
||||
* @param key key
|
||||
* @return the v
|
||||
* @since 1.4.0
|
||||
*/
|
||||
@Override
|
||||
public V get(Object key) {
|
||||
ConcurrentMap<K, V> map = this.myMap;
|
||||
K k = notNull(key);
|
||||
V value = map.get(k);
|
||||
if (value == null) {
|
||||
//noinspection unchecked
|
||||
value = this.create((K) key);
|
||||
V v = notNull(value);
|
||||
value = cacheOrGet(map, k, v);
|
||||
}
|
||||
return nullize(value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Not null
|
||||
*
|
||||
* @param <T> parameter
|
||||
* @param key key
|
||||
* @return the t
|
||||
* @since 1.4.0
|
||||
*/
|
||||
@Contract(value = "!null -> param1", pure = true)
|
||||
private static <T> T notNull(Object key) {
|
||||
//noinspection unchecked
|
||||
return key == null ? fakeNull() : (T) key;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create
|
||||
*
|
||||
* @param key key
|
||||
* @return the v
|
||||
* @since 1.4.0
|
||||
*/
|
||||
@Nullable
|
||||
protected abstract V create(K key);
|
||||
|
||||
/**
|
||||
* Cache or get
|
||||
*
|
||||
* @param <K> parameter
|
||||
* @param <V> parameter
|
||||
* @param map map
|
||||
* @param key key
|
||||
* @param defaultValue default value
|
||||
* @return the v
|
||||
* @since 1.4.0
|
||||
*/
|
||||
@NotNull
|
||||
public static <K, V> V cacheOrGet(@NotNull ConcurrentMap<K, V> map, @NotNull K key, @NotNull V defaultValue) {
|
||||
V v = map.get(key);
|
||||
if (v != null) {
|
||||
return v;
|
||||
}
|
||||
V prev = map.putIfAbsent(key, defaultValue);
|
||||
return prev == null ? defaultValue : prev;
|
||||
}
|
||||
|
||||
/**
|
||||
* Nullize
|
||||
*
|
||||
* @param <T> parameter
|
||||
* @param value value
|
||||
* @return the t
|
||||
* @since 1.4.0
|
||||
*/
|
||||
@Contract(pure = true)
|
||||
@Nullable
|
||||
private static <T> T nullize(T value) {
|
||||
return value == fakeNull() ? null : value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fake null
|
||||
*
|
||||
* @param <T> parameter
|
||||
* @return the t
|
||||
* @since 1.4.0
|
||||
*/
|
||||
@Contract(pure = true)
|
||||
@SuppressWarnings("unchecked")
|
||||
private static <T> T fakeNull() {
|
||||
return (T) NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* Put
|
||||
*
|
||||
* @param key key
|
||||
* @param value value
|
||||
* @return the v
|
||||
* @since 1.4.0
|
||||
*/
|
||||
@Override
|
||||
public V put(K key, V value) {
|
||||
K k = notNull(key);
|
||||
V v = notNull(value);
|
||||
v = this.myMap.put(k, v);
|
||||
return nullize(v);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove
|
||||
*
|
||||
* @param key key
|
||||
* @return the v
|
||||
* @since 1.4.0
|
||||
*/
|
||||
@Override
|
||||
public V remove(Object key) {
|
||||
V v = this.myMap.remove(notNull(key));
|
||||
return nullize(v);
|
||||
}
|
||||
|
||||
/**
|
||||
* Put all
|
||||
*
|
||||
* @param m m
|
||||
* @since 1.4.0
|
||||
*/
|
||||
@Override
|
||||
public void putAll(@NotNull Map<? extends K, ? extends V> m) {
|
||||
for (Entry<? extends K, ? extends V> entry : m.entrySet()) {
|
||||
this.put(entry.getKey(), entry.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear
|
||||
*
|
||||
* @since 1.4.0
|
||||
*/
|
||||
@Override
|
||||
public void clear() {
|
||||
this.myMap.clear();
|
||||
}
|
||||
|
||||
/**
|
||||
* Key set
|
||||
*
|
||||
* @return the set
|
||||
* @since 1.4.0
|
||||
*/
|
||||
@NotNull
|
||||
@Override
|
||||
public Set<K> keySet() {
|
||||
return new CollectionWrapper.Set<>(this.myMap.keySet());
|
||||
}
|
||||
|
||||
/**
|
||||
* Values
|
||||
*
|
||||
* @return the collection
|
||||
* @since 1.4.0
|
||||
*/
|
||||
@NotNull
|
||||
@Override
|
||||
public Collection<V> values() {
|
||||
return new CollectionWrapper<>(this.myMap.values());
|
||||
}
|
||||
|
||||
/**
|
||||
* Entry set
|
||||
*
|
||||
* @return the set
|
||||
* @since 1.4.0
|
||||
*/
|
||||
@NotNull
|
||||
@Override
|
||||
public Set<Entry<K, V>> entrySet() {
|
||||
return new CollectionWrapper.Set<Entry<K, V>>(this.myMap.entrySet()) {
|
||||
@Override
|
||||
public Object wrap(Object val) {
|
||||
//noinspection unchecked
|
||||
return val instanceof EntryWrapper ? ((EntryWrapper<K, V>) val).myEntry : val;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Entry<K, V> unwrap(Entry<K, V> val) {
|
||||
return val.getKey() == fakeNull() || val.getValue() == fakeNull() ? new EntryWrapper<>(val) : val;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Create map
|
||||
*
|
||||
* @return the concurrent map
|
||||
* @since 1.4.0
|
||||
*/
|
||||
@NotNull
|
||||
protected ConcurrentMap<K, V> createMap() {
|
||||
return Maps.newConcurrentMap();
|
||||
}
|
||||
|
||||
/**
|
||||
* Put if absent
|
||||
*
|
||||
* @param key key
|
||||
* @param value value
|
||||
* @return the v
|
||||
* @since 1.4.0
|
||||
*/
|
||||
@Override
|
||||
public V putIfAbsent(@NotNull K key, V value) {
|
||||
return nullize(this.myMap.putIfAbsent(notNull(key), notNull(value)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove
|
||||
*
|
||||
* @param key key
|
||||
* @param value value
|
||||
* @return the boolean
|
||||
* @since 1.4.0
|
||||
*/
|
||||
@Override
|
||||
public boolean remove(@NotNull Object key, Object value) {
|
||||
return this.myMap.remove(ConcurrentFactoryMap.<K>notNull(key), ConcurrentFactoryMap.<V>notNull(value));
|
||||
}
|
||||
|
||||
/**
|
||||
* Replace
|
||||
*
|
||||
* @param key key
|
||||
* @param oldValue old value
|
||||
* @param newValue new value
|
||||
* @return the boolean
|
||||
* @since 1.4.0
|
||||
*/
|
||||
@Override
|
||||
public boolean replace(@NotNull K key, @NotNull V oldValue, @NotNull V newValue) {
|
||||
return this.myMap.replace(notNull(key), notNull(oldValue), notNull(newValue));
|
||||
}
|
||||
|
||||
/**
|
||||
* Replace
|
||||
*
|
||||
* @param key key
|
||||
* @param value value
|
||||
* @return the v
|
||||
* @since 1.4.0
|
||||
*/
|
||||
@Override
|
||||
public V replace(@NotNull K key, @NotNull V value) {
|
||||
return nullize(this.myMap.replace(notNull(key), notNull(value)));
|
||||
}
|
||||
|
||||
/**
|
||||
* To string
|
||||
*
|
||||
* @return the string
|
||||
* @since 1.4.0
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
return this.myMap.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>Company: 成都返空汇网络技术有限公司 </p>
|
||||
* <p>Description: </p>
|
||||
*
|
||||
* @param <K> parameter
|
||||
* @author dong4j
|
||||
* @version 1.0.0
|
||||
* @email "mailto:dongshijie@fkhwl.com"
|
||||
* @date 2020.05.19 10:04
|
||||
* @since 1.4.0
|
||||
*/
|
||||
private static class CollectionWrapper<K> extends AbstractCollection<K> {
|
||||
/** My delegate */
|
||||
private final Collection<K> myDelegate;
|
||||
|
||||
/**
|
||||
* Collection wrapper
|
||||
*
|
||||
* @param delegate delegate
|
||||
* @since 1.4.0
|
||||
*/
|
||||
CollectionWrapper(Collection<K> delegate) {
|
||||
this.myDelegate = delegate;
|
||||
}
|
||||
|
||||
/**
|
||||
* Iterator
|
||||
*
|
||||
* @return the iterator
|
||||
* @since 1.4.0
|
||||
*/
|
||||
@NotNull
|
||||
@Override
|
||||
public Iterator<K> iterator() {
|
||||
return new Iterator<K>() {
|
||||
final Iterator<K> it = CollectionWrapper.this.myDelegate.iterator();
|
||||
|
||||
@Override
|
||||
public boolean hasNext() {
|
||||
return this.it.hasNext();
|
||||
}
|
||||
|
||||
@Override
|
||||
public K next() {
|
||||
return CollectionWrapper.this.unwrap(this.it.next());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void remove() {
|
||||
this.it.remove();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Size
|
||||
*
|
||||
* @return the int
|
||||
* @since 1.4.0
|
||||
*/
|
||||
@Override
|
||||
public int size() {
|
||||
return this.myDelegate.size();
|
||||
}
|
||||
|
||||
/**
|
||||
* Contains
|
||||
*
|
||||
* @param o o
|
||||
* @return the boolean
|
||||
* @since 1.4.0
|
||||
*/
|
||||
@Override
|
||||
public boolean contains(Object o) {
|
||||
return this.myDelegate.contains(this.wrap(o));
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove
|
||||
*
|
||||
* @param o o
|
||||
* @return the boolean
|
||||
* @since 1.4.0
|
||||
*/
|
||||
@Override
|
||||
public boolean remove(Object o) {
|
||||
return this.myDelegate.remove(this.wrap(o));
|
||||
}
|
||||
|
||||
/**
|
||||
* Wrap
|
||||
*
|
||||
* @param val val
|
||||
* @return the object
|
||||
* @since 1.4.0
|
||||
*/
|
||||
protected Object wrap(Object val) {
|
||||
return notNull(val);
|
||||
}
|
||||
|
||||
/**
|
||||
* Unwrap
|
||||
*
|
||||
* @param val val
|
||||
* @return the k
|
||||
* @since 1.4.0
|
||||
*/
|
||||
protected K unwrap(K val) {
|
||||
return nullize(val);
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>Company: 成都返空汇网络技术有限公司 </p>
|
||||
* <p>Description: </p>
|
||||
*
|
||||
* @param <K> parameter
|
||||
* @author dong4j
|
||||
* @version 1.0.0
|
||||
* @email "mailto:dongshijie@fkhwl.com"
|
||||
* @date 2020.05.19 10:04
|
||||
* @since 1.4.0
|
||||
*/
|
||||
private static class Set<K> extends CollectionWrapper<K> implements java.util.Set<K> {
|
||||
/**
|
||||
* Set
|
||||
*
|
||||
* @param delegate delegate
|
||||
* @since 1.4.0
|
||||
*/
|
||||
Set(Collection<K> delegate) {
|
||||
super(delegate);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>Company: 成都返空汇网络技术有限公司 </p>
|
||||
* <p>Description: </p>
|
||||
*
|
||||
* @param <K> parameter
|
||||
* @param <V> parameter
|
||||
* @author dong4j
|
||||
* @version 1.0.0
|
||||
* @email "mailto:dongshijie@fkhwl.com"
|
||||
* @date 2020.05.19 10:04
|
||||
* @since 1.4.0
|
||||
*/
|
||||
protected static final class EntryWrapper<K, V> implements Entry<K, V> {
|
||||
/** My entry */
|
||||
final Entry<? extends K, ? extends V> myEntry;
|
||||
|
||||
/**
|
||||
* Entry wrapper
|
||||
*
|
||||
* @param entry entry
|
||||
* @since 1.4.0
|
||||
*/
|
||||
@Contract(pure = true)
|
||||
private EntryWrapper(Entry<? extends K, ? extends V> entry) {
|
||||
this.myEntry = entry;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets key *
|
||||
*
|
||||
* @return the key
|
||||
* @since 1.4.0
|
||||
*/
|
||||
@Override
|
||||
public K getKey() {
|
||||
return nullize(this.myEntry.getKey());
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets value *
|
||||
*
|
||||
* @return the value
|
||||
* @since 1.4.0
|
||||
*/
|
||||
@Override
|
||||
public V getValue() {
|
||||
return nullize(this.myEntry.getValue());
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets value *
|
||||
*
|
||||
* @param value value
|
||||
* @return the value
|
||||
* @since 1.4.0
|
||||
*/
|
||||
@Override
|
||||
public V setValue(V value) {
|
||||
return this.myEntry.setValue(notNull(value));
|
||||
}
|
||||
|
||||
/**
|
||||
* Hash code
|
||||
*
|
||||
* @return the int
|
||||
* @since 1.4.0
|
||||
*/
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return this.myEntry.hashCode();
|
||||
}
|
||||
|
||||
/**
|
||||
* Equals
|
||||
*
|
||||
* @param obj obj
|
||||
* @return the boolean
|
||||
* @since 1.4.0
|
||||
*/
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
//noinspection unchecked
|
||||
return this.myEntry.equals(obj instanceof EntryWrapper ? ((EntryWrapper<K, V>) obj).myEntry : obj);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>Company: 成都返空汇网络技术有限公司 </p>
|
||||
* <p>Description: </p>
|
||||
*
|
||||
* @author dong4j
|
||||
* @version 1.0.0
|
||||
* @email "mailto:dongshijie@fkhwl.com"
|
||||
* @date 2020.05.19 10:04
|
||||
* @since 1.4.0
|
||||
*/
|
||||
private static final class Sentinel {
|
||||
/** My name */
|
||||
private final String myName;
|
||||
|
||||
/**
|
||||
* Sentinel
|
||||
*
|
||||
* @param name name
|
||||
* @since 1.4.0
|
||||
*/
|
||||
Sentinel(@NotNull String name) {
|
||||
this.myName = name;
|
||||
}
|
||||
|
||||
/**
|
||||
* To string
|
||||
*
|
||||
* @return the string
|
||||
* @since 1.4.0
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
return this.myName;
|
||||
}
|
||||
}
|
||||
}
|
||||
+403
@@ -0,0 +1,403 @@
|
||||
package com.aos.element.basic.basic.support;
|
||||
|
||||
import com.aos.element.basic.basic.exception.BasicException;
|
||||
|
||||
import org.jetbrains.annotations.Contract;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.lang.ref.ReferenceQueue;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.ConcurrentMap;
|
||||
|
||||
/**
|
||||
* <p>Company: 成都返空汇网络技术有限公司 </p>
|
||||
* <p>Description: </p>
|
||||
*
|
||||
* @param <K> parameter
|
||||
* @param <V> parameter
|
||||
* @author dong4j
|
||||
* @version 1.0.0
|
||||
* @email "mailto:dongshijie@fkhwl.com"
|
||||
* @date 2020.05.19 10:22
|
||||
* @since 1.4.0
|
||||
*/
|
||||
abstract class ConcurrentRefValueHashMap<K, V> implements ConcurrentMap<K, V> {
|
||||
/** My queue */
|
||||
protected final ReferenceQueue<V> myQueue = new ReferenceQueue<>();
|
||||
/** My map */
|
||||
private final ConcurrentMap<K, ValueReference<K, V>> myMap = new ConcurrentHashMap<>();
|
||||
|
||||
/**
|
||||
* Put if absent
|
||||
*
|
||||
* @param key key
|
||||
* @param value value
|
||||
* @return the v
|
||||
* @since 1.4.0
|
||||
*/
|
||||
@Override
|
||||
public V putIfAbsent(@NotNull K key, @NotNull V value) {
|
||||
ValueReference<K, V> newRef = this.createValueReference(key, value);
|
||||
while (true) {
|
||||
this.processQueue();
|
||||
ValueReference<K, V> oldRef = this.myMap.putIfAbsent(key, newRef);
|
||||
if (oldRef == null) {
|
||||
return null;
|
||||
}
|
||||
V oldVal = oldRef.get();
|
||||
if (oldVal == null) {
|
||||
if (this.myMap.replace(key, oldRef, newRef)) {
|
||||
return null;
|
||||
}
|
||||
} else {
|
||||
return oldVal;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create value reference
|
||||
*
|
||||
* @param key key
|
||||
* @param value value
|
||||
* @return the value reference
|
||||
* @since 1.4.0
|
||||
*/
|
||||
@NotNull
|
||||
abstract ValueReference<K, V> createValueReference(@NotNull K key, @NotNull V value);
|
||||
|
||||
/**
|
||||
* Process queue
|
||||
*
|
||||
* @return the boolean
|
||||
* @since 1.4.0
|
||||
*/
|
||||
boolean processQueue() {
|
||||
boolean processed = false;
|
||||
|
||||
while (true) {
|
||||
@SuppressWarnings("unchecked")
|
||||
ValueReference<K, V> ref = (ValueReference<K, V>) this.myQueue.poll();
|
||||
if (ref == null) {
|
||||
break;
|
||||
}
|
||||
this.myMap.remove(ref.getKey(), ref);
|
||||
processed = true;
|
||||
}
|
||||
return processed;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove
|
||||
*
|
||||
* @param key key
|
||||
* @param value value
|
||||
* @return the boolean
|
||||
* @since 1.4.0
|
||||
*/
|
||||
@Override
|
||||
public boolean remove(@NotNull Object key, @NotNull Object value) {
|
||||
this.processQueue();
|
||||
//noinspection unchecked
|
||||
return this.myMap.remove(key, this.createValueReference((K) key, (V) value));
|
||||
}
|
||||
|
||||
/**
|
||||
* Replace
|
||||
*
|
||||
* @param key key
|
||||
* @param oldValue old value
|
||||
* @param newValue new value
|
||||
* @return the boolean
|
||||
* @since 1.4.0
|
||||
*/
|
||||
@Override
|
||||
public boolean replace(@NotNull K key, @NotNull V oldValue, @NotNull V newValue) {
|
||||
this.processQueue();
|
||||
return this.myMap.replace(key, this.createValueReference(key, oldValue), this.createValueReference(key, newValue));
|
||||
}
|
||||
|
||||
/**
|
||||
* Replace
|
||||
*
|
||||
* @param key key
|
||||
* @param value value
|
||||
* @return the v
|
||||
* @since 1.4.0
|
||||
*/
|
||||
@Override
|
||||
public V replace(@NotNull K key, @NotNull V value) {
|
||||
this.processQueue();
|
||||
ValueReference<K, V> ref = this.myMap.replace(key, this.createValueReference(key, value));
|
||||
return ref == null ? null : ref.get();
|
||||
}
|
||||
|
||||
/**
|
||||
* To string
|
||||
*
|
||||
* @return the string
|
||||
* @since 1.4.0
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
return "map size:" + this.size() + " [" + join(this.entrySet(), ",") + "]";
|
||||
}
|
||||
|
||||
/**
|
||||
* Size
|
||||
*
|
||||
* @return the int
|
||||
* @since 1.4.0
|
||||
*/
|
||||
@Override
|
||||
public int size() {
|
||||
this.processQueue();
|
||||
return this.myMap.size();
|
||||
}
|
||||
|
||||
/**
|
||||
* Is empty
|
||||
*
|
||||
* @return the boolean
|
||||
* @since 1.4.0
|
||||
*/
|
||||
@Contract(pure = true)
|
||||
@Override
|
||||
public boolean isEmpty() {
|
||||
this.processQueue();
|
||||
return this.myMap.isEmpty();
|
||||
}
|
||||
|
||||
/**
|
||||
* Contains key
|
||||
*
|
||||
* @param key key
|
||||
* @return the boolean
|
||||
* @since 1.4.0
|
||||
*/
|
||||
@Contract(pure = true)
|
||||
@Override
|
||||
public boolean containsKey(@NotNull Object key) {
|
||||
throw new BasicException("containsKey() makes no sense for weak/soft map because GC can clear the value any moment now");
|
||||
}
|
||||
|
||||
/**
|
||||
* Contains value
|
||||
*
|
||||
* @param value value
|
||||
* @return the boolean
|
||||
* @since 1.4.0
|
||||
*/
|
||||
@Contract(pure = true)
|
||||
@Override
|
||||
public boolean containsValue(@NotNull Object value) {
|
||||
throw new BasicException("containsValue() makes no sense for weak/soft map because GC can clear the key any moment now");
|
||||
}
|
||||
|
||||
/**
|
||||
* Get
|
||||
*
|
||||
* @param key key
|
||||
* @return the v
|
||||
* @since 1.4.0
|
||||
*/
|
||||
@Override
|
||||
public V get(@NotNull Object key) {
|
||||
ValueReference<K, V> ref = this.myMap.get(key);
|
||||
if (ref == null) {
|
||||
return null;
|
||||
}
|
||||
return ref.get();
|
||||
}
|
||||
|
||||
/**
|
||||
* Put
|
||||
*
|
||||
* @param key key
|
||||
* @param value value
|
||||
* @return the v
|
||||
* @since 1.4.0
|
||||
*/
|
||||
@Override
|
||||
public V put(@NotNull K key, @NotNull V value) {
|
||||
this.processQueue();
|
||||
ValueReference<K, V> oldRef = this.myMap.put(key, this.createValueReference(key, value));
|
||||
return oldRef != null ? oldRef.get() : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove
|
||||
*
|
||||
* @param key key
|
||||
* @return the v
|
||||
* @since 1.4.0
|
||||
*/
|
||||
@Override
|
||||
public V remove(@NotNull Object key) {
|
||||
this.processQueue();
|
||||
ValueReference<K, V> ref = this.myMap.remove(key);
|
||||
return ref == null ? null : ref.get();
|
||||
}
|
||||
|
||||
/**
|
||||
* Put all
|
||||
*
|
||||
* @param t t
|
||||
* @since 1.4.0
|
||||
*/
|
||||
@Override
|
||||
public void putAll(@NotNull Map<? extends K, ? extends V> t) {
|
||||
this.processQueue();
|
||||
for (Entry<? extends K, ? extends V> entry : t.entrySet()) {
|
||||
V v = entry.getValue();
|
||||
if (v != null) {
|
||||
K key = entry.getKey();
|
||||
this.put(key, v);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear
|
||||
*
|
||||
* @since 1.4.0
|
||||
*/
|
||||
@Override
|
||||
public void clear() {
|
||||
this.myMap.clear();
|
||||
this.processQueue();
|
||||
}
|
||||
|
||||
/**
|
||||
* Key set
|
||||
*
|
||||
* @return the set
|
||||
* @since 1.4.0
|
||||
*/
|
||||
@NotNull
|
||||
@Override
|
||||
public Set<K> keySet() {
|
||||
return this.myMap.keySet();
|
||||
}
|
||||
|
||||
/**
|
||||
* Values
|
||||
*
|
||||
* @return the collection
|
||||
* @since 1.4.0
|
||||
*/
|
||||
@NotNull
|
||||
@Override
|
||||
public Collection<V> values() {
|
||||
Collection<V> result = new ArrayList<>();
|
||||
Collection<ValueReference<K, V>> refs = this.myMap.values();
|
||||
for (ValueReference<K, V> ref : refs) {
|
||||
V value = ref.get();
|
||||
if (value != null) {
|
||||
result.add(value);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Entry set
|
||||
*
|
||||
* @return the set
|
||||
* @since 1.4.0
|
||||
*/
|
||||
@NotNull
|
||||
@Override
|
||||
public Set<Entry<K, V>> entrySet() {
|
||||
Set<K> keys = this.keySet();
|
||||
Set<Entry<K, V>> entries = new HashSet<>();
|
||||
|
||||
for (K key : keys) {
|
||||
V value = this.get(key);
|
||||
if (value != null) {
|
||||
entries.add(new Entry<K, V>() {
|
||||
@Override
|
||||
public String toString() {
|
||||
return "(" + this.getKey() + " : " + this.getValue() + ")";
|
||||
}
|
||||
|
||||
@Contract(pure = true)
|
||||
@Override
|
||||
public K getKey() {
|
||||
return key;
|
||||
}
|
||||
|
||||
@Contract(pure = true)
|
||||
@Override
|
||||
public V getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public V setValue(@NotNull V value) {
|
||||
throw new UnsupportedOperationException("setValue is not implemented");
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return entries;
|
||||
}
|
||||
|
||||
/**
|
||||
* Join
|
||||
*
|
||||
* @param items items
|
||||
* @param separator separator
|
||||
* @return the string
|
||||
* @since 1.4.0
|
||||
*/
|
||||
@NotNull
|
||||
@Contract(pure = true)
|
||||
public static String join(@NotNull Iterable<?> items, @NotNull String separator) {
|
||||
StringBuilder result = new StringBuilder();
|
||||
for (Object item : items) {
|
||||
result.append(item).append(separator);
|
||||
}
|
||||
if (result.length() > 0) {
|
||||
result.setLength(result.length() - separator.length());
|
||||
}
|
||||
return result.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>Company: 成都返空汇网络技术有限公司 </p>
|
||||
* <p>Description: </p>
|
||||
*
|
||||
* @param <K> parameter
|
||||
* @param <V> parameter
|
||||
* @author dong4j
|
||||
* @version 1.0.0
|
||||
* @email "mailto:dongshijie@fkhwl.com"
|
||||
* @date 2020.05.19 10:22
|
||||
* @since 1.4.0
|
||||
*/
|
||||
interface ValueReference<K, V> {
|
||||
/**
|
||||
* Gets key *
|
||||
*
|
||||
* @return the key
|
||||
* @since 1.4.0
|
||||
*/
|
||||
@NotNull
|
||||
K getKey();
|
||||
|
||||
/**
|
||||
* Get
|
||||
*
|
||||
* @return the v
|
||||
* @since 1.4.0
|
||||
*/
|
||||
V get();
|
||||
}
|
||||
}
|
||||
+120
@@ -0,0 +1,120 @@
|
||||
package com.aos.element.basic.basic.support;
|
||||
|
||||
import org.jetbrains.annotations.Contract;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.lang.ref.ReferenceQueue;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* Concurrent strong key:K -> soft value:V map
|
||||
* 不允许使用空键;
|
||||
* 不允许使用空值;
|
||||
*
|
||||
* @param <K> parameter
|
||||
* @param <V> parameter
|
||||
* @author dong4j
|
||||
* @version 1.0.0
|
||||
* @email "mailto:dongshijie@fkhwl.com"
|
||||
* @date 2020.05.19 10:22
|
||||
* @since 1.4.0
|
||||
*/
|
||||
@SuppressWarnings(value = {"checkstyle:EqualsHashCode", "checkstyle:ModifierOrder"})
|
||||
public final class ConcurrentSoftValueHashMap<K, V> extends ConcurrentRefValueHashMap<K, V> {
|
||||
/**
|
||||
* Create value reference
|
||||
*
|
||||
* @param key key
|
||||
* @param value value
|
||||
* @return the value reference
|
||||
* @since 1.4.0
|
||||
*/
|
||||
@Contract("_, _ -> new")
|
||||
@NotNull
|
||||
@Override
|
||||
ValueReference<K, V> createValueReference(@NotNull K key, @NotNull V value) {
|
||||
return new MySoftReference<>(key, value, this.myQueue);
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>Company: 成都返空汇网络技术有限公司 </p>
|
||||
* <p>Description: </p>
|
||||
*
|
||||
* @param <K> parameter
|
||||
* @param <V> parameter
|
||||
* @author dong4j
|
||||
* @version 1.0.0
|
||||
* @email "mailto:dongshijie@fkhwl.com"
|
||||
* @date 2020.05.19 10:22
|
||||
* @since 1.4.0
|
||||
*/
|
||||
private final static class MySoftReference<K, V> extends SoftReference<V> implements ValueReference<K, V> {
|
||||
|
||||
/** Key */
|
||||
private final K key;
|
||||
|
||||
/**
|
||||
* My soft reference
|
||||
*
|
||||
* @param key key
|
||||
* @param referent referent
|
||||
* @param q q
|
||||
* @since 1.4.0
|
||||
*/
|
||||
private MySoftReference(@NotNull K key, @NotNull V referent, @NotNull ReferenceQueue<V> q) {
|
||||
super(referent, q);
|
||||
this.key = key;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets key *
|
||||
*
|
||||
* @return the key
|
||||
* @since 1.4.0
|
||||
*/
|
||||
@Contract(pure = true)
|
||||
@NotNull
|
||||
@Override
|
||||
public K getKey() {
|
||||
return this.key;
|
||||
}
|
||||
|
||||
/**
|
||||
* When referent is collected, equality should be identity-based (for the processQueues() remove this very same SoftValue)
|
||||
* otherwise it's just canonical equals on referents for replace(K,V,V) to work
|
||||
*
|
||||
* @param o o
|
||||
* @return the boolean
|
||||
* @since 1.4.0
|
||||
*/
|
||||
@Contract(value = "null -> false", pure = true)
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) {
|
||||
return true;
|
||||
}
|
||||
if (o == null || this.getClass() != o.getClass()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
//noinspection unchecked
|
||||
ValueReference<K, V> that = (ValueReference<K, V>) o;
|
||||
|
||||
V v = this.get();
|
||||
V thatV = that.get();
|
||||
return this.key.equals(that.getKey()) && v != null && v.equals(thatV);
|
||||
}
|
||||
|
||||
/**
|
||||
* Hash code
|
||||
*
|
||||
* @return the int
|
||||
* @since 1.5.0
|
||||
*/
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(this.key);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
+197
@@ -0,0 +1,197 @@
|
||||
package com.aos.element.basic.basic.support;
|
||||
|
||||
import com.aos.element.basic.basic.util.StringPool;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.springframework.lang.Nullable;
|
||||
|
||||
import java.io.*;
|
||||
|
||||
/**
|
||||
* <p>Company: 成都返空汇网络技术有限公司</p>
|
||||
* <p>Description: 借助 StringBuilder 提供快读的字符串写出, 相比 jdk 的 StringWriter 非线程安全, 速度更快. </p>
|
||||
*
|
||||
* @author dong4j
|
||||
* @version 1.2.3
|
||||
* @email "mailto:dongshijie@fkhwl.com"
|
||||
* @date 2020.01.27 14:47
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public class FastStringWriter extends Writer {
|
||||
/** Builder */
|
||||
private final StringBuilder builder;
|
||||
|
||||
/**
|
||||
* Instantiates a new Fast string writer.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public FastStringWriter() {
|
||||
this.builder = new StringBuilder(64);
|
||||
}
|
||||
|
||||
/**
|
||||
* Instantiates a new Fast string writer.
|
||||
*
|
||||
* @param capacity the capacity
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public FastStringWriter(int capacity) {
|
||||
if (capacity < 0) {
|
||||
throw new IllegalArgumentException("Negative builderfer size");
|
||||
}
|
||||
this.builder = new StringBuilder(capacity);
|
||||
}
|
||||
|
||||
/**
|
||||
* Instantiates a new Fast string writer.
|
||||
*
|
||||
* @param builder the builder
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public FastStringWriter(@Nullable StringBuilder builder) {
|
||||
this.builder = builder != null ? builder : new StringBuilder(64);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the underlying StringBuilder.
|
||||
*
|
||||
* @return StringBuilder builder
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public StringBuilder getBuilder() {
|
||||
return this.builder;
|
||||
}
|
||||
|
||||
/**
|
||||
* To string string
|
||||
*
|
||||
* @return the string
|
||||
* @since 1.0.0
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
return this.builder.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Write *
|
||||
*
|
||||
* @param c c
|
||||
* @since 1.0.0
|
||||
*/
|
||||
@Override
|
||||
public void write(int c) {
|
||||
this.builder.append((char) c);
|
||||
}
|
||||
|
||||
/**
|
||||
* Write *
|
||||
*
|
||||
* @param cbuilder cbuilder
|
||||
* @param off off
|
||||
* @param len len
|
||||
* @since 1.0.0
|
||||
*/
|
||||
@Override
|
||||
public void write(char[] cbuilder, int off, int len) {
|
||||
if ((off < 0) || (off > cbuilder.length)
|
||||
|| (len < 0) || ((off + len) > cbuilder.length) || ((off + len) < 0)) {
|
||||
throw new IndexOutOfBoundsException();
|
||||
} else if (len == 0) {
|
||||
return;
|
||||
}
|
||||
this.builder.append(cbuilder, off, len);
|
||||
}
|
||||
|
||||
/**
|
||||
* Write *
|
||||
*
|
||||
* @param str str
|
||||
* @since 1.0.0
|
||||
*/
|
||||
@Override
|
||||
public void write(String str) {
|
||||
this.builder.append(str);
|
||||
}
|
||||
|
||||
/**
|
||||
* Write *
|
||||
*
|
||||
* @param str str
|
||||
* @param off off
|
||||
* @param len len
|
||||
* @since 1.0.0
|
||||
*/
|
||||
@Override
|
||||
public void write(@NotNull String str, int off, int len) {
|
||||
this.builder.append(str, off, off + len);
|
||||
}
|
||||
|
||||
/**
|
||||
* Append fast string writer
|
||||
*
|
||||
* @param csq csq
|
||||
* @return the fast string writer
|
||||
* @since 1.0.0
|
||||
*/
|
||||
@Override
|
||||
public FastStringWriter append(CharSequence csq) {
|
||||
if (csq == null) {
|
||||
this.write(StringPool.NULL);
|
||||
} else {
|
||||
this.write(csq.toString());
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Append fast string writer
|
||||
*
|
||||
* @param csq csq
|
||||
* @param start start
|
||||
* @param end end
|
||||
* @return the fast string writer
|
||||
* @since 1.0.0
|
||||
*/
|
||||
@Override
|
||||
public FastStringWriter append(CharSequence csq, int start, int end) {
|
||||
CharSequence cs = (csq == null ? StringPool.NULL : csq);
|
||||
this.write(cs.subSequence(start, end).toString());
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Append fast string writer
|
||||
*
|
||||
* @param c c
|
||||
* @return the fast string writer
|
||||
* @since 1.0.0
|
||||
*/
|
||||
@Override
|
||||
public FastStringWriter append(char c) {
|
||||
this.write(c);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Flush
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
@Override
|
||||
public void flush() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Close
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
@Override
|
||||
public void close() {
|
||||
this.builder.setLength(0);
|
||||
this.builder.trimToSize();
|
||||
}
|
||||
}
|
||||
+93
@@ -0,0 +1,93 @@
|
||||
package com.aos.element.basic.basic.support;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.concurrent.ThreadFactory;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
/**
|
||||
* <p>Company: 成都返空汇网络技术有限公司 </p>
|
||||
* <p>Description: </p>
|
||||
*
|
||||
* @author dong4j
|
||||
* @version 1.0.0
|
||||
* @email "mailto:dongshijie@fkhwl.com"
|
||||
* @date 2021.12.09 22:10
|
||||
* @since 2.1.0
|
||||
*/
|
||||
@SuppressWarnings("all")
|
||||
public class NamedThreadFactory implements ThreadFactory {
|
||||
|
||||
/** POOL_SEQ */
|
||||
protected static final AtomicInteger POOL_SEQ = new AtomicInteger(1);
|
||||
|
||||
/** M thread num */
|
||||
protected final AtomicInteger mThreadNum = new AtomicInteger(1);
|
||||
|
||||
/** M prefix */
|
||||
protected final String mPrefix;
|
||||
|
||||
/** M daemon */
|
||||
protected final boolean mDaemon;
|
||||
|
||||
/** M group */
|
||||
protected final ThreadGroup mGroup;
|
||||
|
||||
/**
|
||||
* Named thread factory
|
||||
*
|
||||
* @since 2.1.0
|
||||
*/
|
||||
public NamedThreadFactory() {
|
||||
this("pool-" + POOL_SEQ.getAndIncrement(), false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Named thread factory
|
||||
*
|
||||
* @param prefix prefix
|
||||
* @since 2.1.0
|
||||
*/
|
||||
public NamedThreadFactory(String prefix) {
|
||||
this(prefix, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Named thread factory
|
||||
*
|
||||
* @param prefix prefix
|
||||
* @param daemon daemon
|
||||
* @since 2.1.0
|
||||
*/
|
||||
public NamedThreadFactory(String prefix, boolean daemon) {
|
||||
mPrefix = prefix + "-thread-";
|
||||
mDaemon = daemon;
|
||||
SecurityManager s = System.getSecurityManager();
|
||||
mGroup = (s == null) ? Thread.currentThread().getThreadGroup() : s.getThreadGroup();
|
||||
}
|
||||
|
||||
/**
|
||||
* New thread
|
||||
*
|
||||
* @param runnable runnable
|
||||
* @return the thread
|
||||
* @since 2.1.0
|
||||
*/
|
||||
@Override
|
||||
public Thread newThread(@NotNull Runnable runnable) {
|
||||
String name = mPrefix + mThreadNum.getAndIncrement();
|
||||
Thread ret = new Thread(mGroup, runnable, name, 0);
|
||||
ret.setDaemon(mDaemon);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets thread group *
|
||||
*
|
||||
* @return the thread group
|
||||
* @since 2.1.0
|
||||
*/
|
||||
public ThreadGroup getThreadGroup() {
|
||||
return mGroup;
|
||||
}
|
||||
}
|
||||
+149
@@ -0,0 +1,149 @@
|
||||
package com.aos.element.basic.basic.support;
|
||||
|
||||
import org.jetbrains.annotations.Contract;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import java.text.DecimalFormat;
|
||||
import java.text.FieldPosition;
|
||||
import java.text.Format;
|
||||
import java.text.MessageFormat;
|
||||
import java.text.NumberFormat;
|
||||
import java.text.ParsePosition;
|
||||
import java.util.Locale;
|
||||
|
||||
/**
|
||||
* <p>Company: 成都返空汇网络技术有限公司 </p>
|
||||
* <p>Description: 占位符替换 </p>
|
||||
*
|
||||
* @author dong4j
|
||||
* @version 1.0.0
|
||||
* @email "mailto:dongshijie@fkhwl.com"
|
||||
* @date 2020.05.19 09:42
|
||||
* @since 1.4.0
|
||||
*/
|
||||
public class OrdinalFormat {
|
||||
/** LOCATION_EN */
|
||||
private static final String LOCATION_EN = "en";
|
||||
|
||||
/**
|
||||
* Replaces all instances of {@code "{?,number,ordinal}"} format elements with the ordinal format for the locale.
|
||||
*
|
||||
* @param format format
|
||||
* @since 1.4.0
|
||||
*/
|
||||
public static void apply(@NotNull MessageFormat format) {
|
||||
Format[] formats = format.getFormats();
|
||||
NumberFormat ordinal = null;
|
||||
for (int i = 0; i < formats.length; i++) {
|
||||
Format element = formats[i];
|
||||
if (element instanceof DecimalFormat && "ordinal".equals(((DecimalFormat) element).getPositivePrefix())) {
|
||||
if (ordinal == null) {
|
||||
ordinal = getOrdinalFormat(format.getLocale());
|
||||
}
|
||||
format.setFormat(i, ordinal);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets ordinal format *
|
||||
*
|
||||
* @param locale locale
|
||||
* @return the ordinal format
|
||||
* @since 1.4.0
|
||||
*/
|
||||
@Contract("null -> new")
|
||||
private static @NotNull NumberFormat getOrdinalFormat(Locale locale) {
|
||||
if (locale != null) {
|
||||
String language = locale.getLanguage();
|
||||
if (LOCATION_EN.equals(language) || !StringUtils.hasText(language)) {
|
||||
return new EnglishOrdinalFormat();
|
||||
}
|
||||
}
|
||||
|
||||
return new DecimalFormat();
|
||||
}
|
||||
|
||||
/**
|
||||
* Format english
|
||||
*
|
||||
* @param num num
|
||||
* @return the string
|
||||
* @since 1.4.0
|
||||
*/
|
||||
@Contract(pure = true)
|
||||
@SuppressWarnings("PMD.UndefineMagicConstantRule")
|
||||
public static @NotNull String formatEnglish(long num) {
|
||||
long mod = Math.abs(num) % 100;
|
||||
if (mod < 11 || mod > 13) {
|
||||
mod = mod % 10;
|
||||
if (mod == 1) {
|
||||
return num + "st";
|
||||
}
|
||||
if (mod == 2) {
|
||||
return num + "nd";
|
||||
}
|
||||
if (mod == 3) {
|
||||
return num + "rd";
|
||||
}
|
||||
}
|
||||
return num + "th";
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>Company: 成都返空汇网络技术有限公司 </p>
|
||||
* <p>Description: </p>
|
||||
*
|
||||
* @author dong4j
|
||||
* @version 1.0.0
|
||||
* @email "mailto:dongshijie@fkhwl.com"
|
||||
* @date 2020.05.19 09:42
|
||||
* @since 1.4.0
|
||||
*/
|
||||
private static class EnglishOrdinalFormat extends NumberFormat {
|
||||
/** serialVersionUID */
|
||||
private static final long serialVersionUID = 6915075795861536376L;
|
||||
|
||||
/**
|
||||
* Format
|
||||
*
|
||||
* @param number number
|
||||
* @param toAppendTo to append to
|
||||
* @param pos pos
|
||||
* @return the string buffer
|
||||
* @since 1.4.0
|
||||
*/
|
||||
@Override
|
||||
public StringBuffer format(double number, StringBuffer toAppendTo, FieldPosition pos) {
|
||||
throw new IllegalArgumentException("Cannot format non-integer number");
|
||||
}
|
||||
|
||||
/**
|
||||
* Format
|
||||
*
|
||||
* @param number number
|
||||
* @param toAppendTo to append to
|
||||
* @param pos pos
|
||||
* @return the string buffer
|
||||
* @since 1.4.0
|
||||
*/
|
||||
@Override
|
||||
public StringBuffer format(long number, StringBuffer toAppendTo, FieldPosition pos) {
|
||||
return new MessageFormat("{0}").format(new Object[] {formatEnglish(number)}, toAppendTo, pos);
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse
|
||||
*
|
||||
* @param source source
|
||||
* @param parsePosition parse position
|
||||
* @return the number
|
||||
* @since 1.4.0
|
||||
*/
|
||||
@Override
|
||||
public Number parse(String source, ParsePosition parsePosition) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
}
|
||||
}
|
||||
+58
@@ -0,0 +1,58 @@
|
||||
package com.aos.element.basic.basic.support;
|
||||
|
||||
import org.jetbrains.annotations.Contract;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.lang.ref.Reference;
|
||||
import java.lang.ref.ReferenceQueue;
|
||||
|
||||
/**
|
||||
* <p>Company: 成都返空汇网络技术有限公司 </p>
|
||||
* <p>Description: </p>
|
||||
*
|
||||
* @param <T> parameter
|
||||
* @author dong4j
|
||||
* @version 1.0.0
|
||||
* @email "mailto:dongshijie@fkhwl.com"
|
||||
* @date 2020.05.19 09:29
|
||||
* @since 1.4.0
|
||||
*/
|
||||
@SuppressWarnings("ClassNameSameAsAncestorName")
|
||||
public class SoftReference<T> extends java.lang.ref.SoftReference<T> {
|
||||
|
||||
/**
|
||||
* Soft reference
|
||||
*
|
||||
* @param referent referent
|
||||
* @since 1.4.0
|
||||
*/
|
||||
public SoftReference(T referent) {
|
||||
super(referent);
|
||||
}
|
||||
|
||||
/**
|
||||
* Soft reference
|
||||
*
|
||||
* @param referent referent
|
||||
* @param q q
|
||||
* @since 1.4.0
|
||||
*/
|
||||
public SoftReference(T referent, ReferenceQueue<? super T> q) {
|
||||
super(referent, q);
|
||||
}
|
||||
|
||||
/**
|
||||
* Dereference
|
||||
*
|
||||
* @param <T> parameter
|
||||
* @param ref ref
|
||||
* @return the t
|
||||
* @since 1.4.0
|
||||
*/
|
||||
@Contract("null -> null")
|
||||
@Nullable
|
||||
public static <T> T dereference(@Nullable Reference<T> ref) {
|
||||
return ref == null ? null : ref.get();
|
||||
}
|
||||
|
||||
}
|
||||
+138
@@ -0,0 +1,138 @@
|
||||
package com.aos.element.basic.basic.support;
|
||||
|
||||
import com.aos.element.basic.basic.util.CharPool;
|
||||
import com.aos.element.basic.basic.util.StringPool;
|
||||
|
||||
import org.jetbrains.annotations.Contract;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import java.text.MessageFormat;
|
||||
|
||||
import lombok.experimental.UtilityClass;
|
||||
|
||||
/**
|
||||
* <p>Company: 成都返空汇网络技术有限公司</p>
|
||||
* <p>Description: 字符串格式化 </p>
|
||||
*
|
||||
* @author dong4j
|
||||
* @version 1.2.3
|
||||
* @email "mailto:dongshijie@fkhwl.com"
|
||||
* @date 2020.01.26 20:42
|
||||
* @since 1.0.0
|
||||
*/
|
||||
@UtilityClass
|
||||
public class StrFormatter {
|
||||
|
||||
/**
|
||||
* 格式化字符串<br>
|
||||
* 此方法只是简单将占位符 {} 按照顺序替换为参数<br>
|
||||
* 如果想输出 {} 使用 \\转义 { 即可,如果想输出 {} 之前的 \ 使用双转义符 \\\\ 即可<br>
|
||||
* 例: <br>
|
||||
* 通常使用: format("this is {} for {}", "a", "b") =》 this is a for b<br>
|
||||
* 转义{}: format("this is \\{} for {}", "a", "b") =》 this is \{} for a<br>
|
||||
* 转义\: format("this is \\\\{} for {}", "a", "b") =》 this is \a for b<br>
|
||||
*
|
||||
* @param strPattern 字符串模板
|
||||
* @param argArray 参数列表
|
||||
* @return 结果 string
|
||||
* @since 1.0.0
|
||||
*/
|
||||
@SuppressWarnings("checkstyle:ReturnCount")
|
||||
public static String format(String strPattern, Object... argArray) {
|
||||
boolean isEmpty = argArray == null || argArray.length == 0;
|
||||
if (!StringUtils.hasText(strPattern) || isEmpty) {
|
||||
return strPattern;
|
||||
}
|
||||
int strPatternLength = strPattern.length();
|
||||
// 初始化定义好的长度以获得更好的性能
|
||||
StringBuilder sbuf = new StringBuilder(strPatternLength + 50);
|
||||
// 记录已经处理到的位置
|
||||
int handledPosition = 0;
|
||||
// 占位符所在位置
|
||||
int delimIndex;
|
||||
for (int argIndex = 0, length = argArray.length; argIndex < length; argIndex++) {
|
||||
delimIndex = strPattern.indexOf(StringPool.EMPTY_JSON, handledPosition);
|
||||
// 剩余部分无占位符
|
||||
if (delimIndex == -1) {
|
||||
// 不带占位符的模板直接返回
|
||||
if (handledPosition == 0) {
|
||||
return strPattern;
|
||||
} else {
|
||||
sbuf.append(strPattern, handledPosition, strPatternLength);
|
||||
return sbuf.toString();
|
||||
}
|
||||
} else {
|
||||
// 转义符
|
||||
if (delimIndex > 0 && strPattern.charAt(delimIndex - 1) == CharPool.BACK_SLASH) {
|
||||
// 双转义符
|
||||
if (delimIndex > 1 && strPattern.charAt(delimIndex - 2) == CharPool.BACK_SLASH) {
|
||||
// 转义符之前还有一个转义符,占位符依旧有效
|
||||
sbuf.append(strPattern, handledPosition, delimIndex - 1);
|
||||
sbuf.append(toStr(argArray[argIndex]));
|
||||
handledPosition = delimIndex + 2;
|
||||
} else {
|
||||
//占位符被转义
|
||||
argIndex--;
|
||||
sbuf.append(strPattern, handledPosition, delimIndex - 1);
|
||||
sbuf.append(StringPool.LEFT_BRACE);
|
||||
handledPosition = delimIndex + 1;
|
||||
}
|
||||
} else {
|
||||
// 正常占位符
|
||||
sbuf.append(strPattern, handledPosition, delimIndex);
|
||||
sbuf.append(toStr(argArray[argIndex]));
|
||||
handledPosition = delimIndex + 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
// 加入最后一个占位符后所有的字符
|
||||
sbuf.append(strPattern, handledPosition, strPattern.length());
|
||||
return sbuf.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* To str string
|
||||
*
|
||||
* @param str str
|
||||
* @return the string
|
||||
* @since 1.0.0
|
||||
*/
|
||||
@Contract(pure = true)
|
||||
public static String toStr(Object str) {
|
||||
return toStr(str, "");
|
||||
}
|
||||
|
||||
/**
|
||||
* 强转string,并去掉多余空格
|
||||
*
|
||||
* @param str 字符串
|
||||
* @param defaultValue 默认值
|
||||
* @return String string
|
||||
* @since 1.0.0
|
||||
*/
|
||||
@Contract(value = "null, _ -> param2", pure = true)
|
||||
public static String toStr(Object str, String defaultValue) {
|
||||
if (null == str) {
|
||||
return defaultValue;
|
||||
}
|
||||
return String.valueOf(str);
|
||||
}
|
||||
|
||||
/**
|
||||
* 同时兼容 {} 和 {0} 2 种格式
|
||||
*
|
||||
* @param value value
|
||||
* @param params params
|
||||
* @return the string
|
||||
* @since 1.4.0
|
||||
*/
|
||||
@NotNull
|
||||
public static String mergeFormat(@NotNull String value, @NotNull Object... params) {
|
||||
return params.length > 0 && value.indexOf('{') >= 0
|
||||
? value.contains("{0")
|
||||
? MessageFormat.format(value, params)
|
||||
: format(value, params)
|
||||
: value;
|
||||
}
|
||||
}
|
||||
+56
@@ -0,0 +1,56 @@
|
||||
package com.aos.element.basic.basic.support;
|
||||
|
||||
import org.jetbrains.annotations.Contract;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
/**
|
||||
* <p>Company: 成都返空汇网络技术有限公司 </p>
|
||||
* <p>Description: </p>
|
||||
*
|
||||
* @author dong4j
|
||||
* @version 1.0.0
|
||||
* @email "mailto:dongshijie@fkhwl.com"
|
||||
* @date 2020.05.19 09:43
|
||||
* @since 1.4.0
|
||||
*/
|
||||
public final class SystemInfoRt {
|
||||
/** OS_NAME */
|
||||
public static final String OS_NAME = System.getProperty("os.name");
|
||||
/** OS_VERSION */
|
||||
public static final String OS_VERSION = System.getProperty("os.version").toLowerCase(Locale.ENGLISH);
|
||||
/** IS_AT_LEAST_JAVA9 */
|
||||
public static final boolean IS_AT_LEAST_JAVA9 = isModularJava();
|
||||
/** _OS_NAME */
|
||||
private static final String OS_NAME_LOWERCASE = OS_NAME.toLowerCase(Locale.ENGLISH);
|
||||
/** isWindows */
|
||||
public static final boolean IS_WINDOWS = OS_NAME_LOWERCASE.startsWith("windows");
|
||||
/** isMac */
|
||||
public static final boolean IS_MAC = OS_NAME_LOWERCASE.startsWith("mac");
|
||||
/** isLinux */
|
||||
public static final boolean IS_LINUX = OS_NAME_LOWERCASE.startsWith("linux");
|
||||
/** ARCH_DATA_MODEL */
|
||||
private static final String ARCH_DATA_MODEL = System.getProperty("sun.arch.data.model");
|
||||
/** isUnix */
|
||||
public static final boolean IS_UNIX = !IS_WINDOWS;
|
||||
/** 系统是否大小写敏感 */
|
||||
public static final boolean IS_FILE_SYSTEM_CASE_SENSITIVE =
|
||||
IS_UNIX && !IS_MAC || "true".equalsIgnoreCase(System.getProperty("idea.case.sensitive.fs"));
|
||||
|
||||
/**
|
||||
* Is modular java
|
||||
*
|
||||
* @return the boolean
|
||||
* @since 1.4.0
|
||||
*/
|
||||
@Contract(pure = true)
|
||||
@SuppressWarnings("JavaReflectionMemberAccess")
|
||||
private static boolean isModularJava() {
|
||||
try {
|
||||
Class.class.getMethod("getModule");
|
||||
return true;
|
||||
} catch (Throwable t) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
+99
@@ -0,0 +1,99 @@
|
||||
package com.aos.element.basic.basic.support;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.springframework.util.StopWatch;
|
||||
|
||||
import java.text.NumberFormat;
|
||||
|
||||
/**
|
||||
* <p>Company: 成都返空汇网络技术有限公司 </p>
|
||||
* <p>Description: </p>
|
||||
*
|
||||
* @author dong4j
|
||||
* @version 1.0.0
|
||||
* @email "mailto:dongshijie@fkhwl.com"
|
||||
* @date 2021.05.11 15:19
|
||||
* @since 1.8.0
|
||||
*/
|
||||
public class TraceWatch extends StopWatch implements AutoCloseable {
|
||||
/** Keep task list */
|
||||
private boolean keepTaskList = true;
|
||||
|
||||
/**
|
||||
* Startings
|
||||
*
|
||||
* @param taskName task name
|
||||
* @return the trace watch
|
||||
* @throws IllegalStateException illegal state exception
|
||||
* @since 1.8.0
|
||||
*/
|
||||
public TraceWatch startings(String taskName) throws IllegalStateException {
|
||||
super.start(taskName);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@link AutoCloseable} 自动关闭
|
||||
*
|
||||
* @since 1.8.0
|
||||
*/
|
||||
@Override
|
||||
public void close() {
|
||||
super.stop();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets keep task list *
|
||||
*
|
||||
* @param keepTaskList keep task list
|
||||
* @since 1.8.0
|
||||
*/
|
||||
@Override
|
||||
public void setKeepTaskList(boolean keepTaskList) {
|
||||
super.setKeepTaskList(keepTaskList);
|
||||
this.keepTaskList = keepTaskList;
|
||||
}
|
||||
|
||||
/**
|
||||
* Short summary
|
||||
*
|
||||
* @return the string
|
||||
* @since 1.8.0
|
||||
*/
|
||||
@Override
|
||||
public @NotNull String shortSummary() {
|
||||
return "StopWatch '" + this.getId() + "': running time = " + this.getTotalTimeMillis() + " ms";
|
||||
}
|
||||
|
||||
/**
|
||||
* Pretty print
|
||||
*
|
||||
* @return the string
|
||||
* @since 1.8.0
|
||||
*/
|
||||
@Override
|
||||
public @NotNull String prettyPrint() {
|
||||
StringBuilder sb = new StringBuilder(this.shortSummary());
|
||||
sb.append('\n');
|
||||
if (!this.keepTaskList) {
|
||||
sb.append("No task info kept");
|
||||
} else {
|
||||
sb.append("---------------------------------------------\n");
|
||||
sb.append("ms % Task name\n");
|
||||
sb.append("---------------------------------------------\n");
|
||||
NumberFormat nf = NumberFormat.getNumberInstance();
|
||||
nf.setMinimumIntegerDigits(9);
|
||||
nf.setGroupingUsed(false);
|
||||
NumberFormat pf = NumberFormat.getPercentInstance();
|
||||
pf.setMinimumIntegerDigits(3);
|
||||
pf.setGroupingUsed(false);
|
||||
for (TaskInfo task : this.getTaskInfo()) {
|
||||
sb.append(nf.format(task.getTimeMillis())).append(" ");
|
||||
sb.append(pf.format((double) task.getTimeMillis() / this.getTotalTimeMillis())).append(" ");
|
||||
sb.append(task.getTaskName()).append("\n");
|
||||
}
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
}
|
||||
+53
@@ -0,0 +1,53 @@
|
||||
package com.aos.element.basic.basic.support;
|
||||
|
||||
import org.springframework.util.StopWatch;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
/**
|
||||
* <p>Company: 成都返空汇网络技术有限公司 </p>
|
||||
* <p>Description: </p>
|
||||
*
|
||||
* @author dong4j
|
||||
* @version 1.0.0
|
||||
* @email "mailto:dongshijie@fkhwl.com"
|
||||
* @date 2021.05.11 15:19
|
||||
* @since 1.8.0
|
||||
*/
|
||||
public class TraceWatchHolder {
|
||||
/**
|
||||
* 有返回值调用
|
||||
*
|
||||
* @param <T> parameter
|
||||
* @param traceWatch trace watch
|
||||
* @param taskName task name
|
||||
* @param supplier supplier
|
||||
* @return the t
|
||||
* @since 1.8.0
|
||||
*/
|
||||
public static <T> T run(StopWatch traceWatch, String taskName, Supplier<T> supplier) {
|
||||
try {
|
||||
traceWatch.start(taskName);
|
||||
return supplier.get();
|
||||
} finally {
|
||||
traceWatch.stop();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 无返回值调用
|
||||
*
|
||||
* @param traceWatch trace watch
|
||||
* @param taskName task name
|
||||
* @param function function
|
||||
* @since 1.8.0
|
||||
*/
|
||||
public static void run(StopWatch traceWatch, String taskName, Runnable function) {
|
||||
try {
|
||||
traceWatch.start(taskName);
|
||||
function.run();
|
||||
} finally {
|
||||
traceWatch.stop();
|
||||
}
|
||||
}
|
||||
}
|
||||
+95
@@ -0,0 +1,95 @@
|
||||
package com.aos.element.basic.basic.util;
|
||||
|
||||
import com.aos.element.basic.basic.constant.ConfigKey;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import lombok.experimental.UtilityClass;
|
||||
|
||||
/**
|
||||
* <p>Company: 成都返空汇网络技术有限公司</p>
|
||||
* <p>Description: </p>
|
||||
*
|
||||
* @author dong4j
|
||||
* @version 1.0.0
|
||||
* @email "mailto:dongshijie@fkhwl.com"
|
||||
* @date 2020.06.19 15:27
|
||||
* @since 1.5.0
|
||||
*/
|
||||
@UtilityClass
|
||||
public class BasicUtils {
|
||||
|
||||
/**
|
||||
* Is v 5 framework
|
||||
*
|
||||
* @return the boolean
|
||||
* @since 1.4.0
|
||||
*/
|
||||
public static boolean isV5Framework() {
|
||||
String frameworkVersion = System.getProperty(ConfigKey.APPLICATION_FRAMEWORK_VERSION);
|
||||
return StringUtils.hasText(frameworkVersion)
|
||||
&& frameworkVersion.startsWith("V5_");
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets app version *
|
||||
*
|
||||
* @return the app version
|
||||
* @since 1.4.0
|
||||
*/
|
||||
public static String getAppVersion() {
|
||||
return getVersion(ConfigKey.SERVICE_VERSION);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets framework version *
|
||||
*
|
||||
* @return the framework version
|
||||
* @since 1.4.0
|
||||
*/
|
||||
public static String getFrameworkVersion() {
|
||||
return getVersion(ConfigKey.APPLICATION_FRAMEWORK_VERSION);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get version
|
||||
*
|
||||
* @param key key
|
||||
* @return the string
|
||||
* @since 1.4.0
|
||||
*/
|
||||
private static String getVersion(String key) {
|
||||
if (!isV5Framework()) {
|
||||
return StringPool.NULL_STRING;
|
||||
}
|
||||
return System.getProperty(key, StringPool.NULL_STRING);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取启动模式
|
||||
* 本地开发模式还是服务器部署模式
|
||||
*
|
||||
* @return the string
|
||||
* @since 1.0.0
|
||||
* @deprecated 将在 v4 全部迁移到 v5 后删除, v5 请使用 ConfigKit
|
||||
*/
|
||||
@NotNull
|
||||
@Deprecated
|
||||
public static Boolean isLocalLaunch() {
|
||||
return !notLocalLaunch();
|
||||
}
|
||||
|
||||
/**
|
||||
* 非本地开发环境 (只要 start.type = shell 都认为是非开发环境)
|
||||
*
|
||||
* @return the boolean
|
||||
* @since 1.0.0
|
||||
* @deprecated 将在 v4 全部迁移到 v5 后删除, v5 请使用 ConfigKit
|
||||
*/
|
||||
@NotNull
|
||||
@Deprecated
|
||||
public static Boolean notLocalLaunch() {
|
||||
return "shell".equals(System.getProperty("start.type"));
|
||||
}
|
||||
}
|
||||
+108
@@ -0,0 +1,108 @@
|
||||
package com.aos.element.basic.basic.util;
|
||||
|
||||
import lombok.experimental.UtilityClass;
|
||||
|
||||
/**
|
||||
* <p>Company: 成都返空汇网络技术有限公司</p>
|
||||
* <p>Description: char 常量池</p>
|
||||
*
|
||||
* @author dong4j
|
||||
* @version 1.2.3
|
||||
* @email "mailto:dongshijie@fkhwl.com"
|
||||
* @date 2020.01.27 18:18
|
||||
* @since 1.0.0
|
||||
*/
|
||||
@UtilityClass
|
||||
@SuppressWarnings("all")
|
||||
public class CharPool {
|
||||
/** UPPER_A */
|
||||
public static final char UPPER_A = 'A';
|
||||
/** LOWER_A */
|
||||
public static final char LOWER_A = 'a';
|
||||
/** UPPER_Z */
|
||||
public static final char UPPER_Z = 'Z';
|
||||
/** LOWER_Z */
|
||||
public static final char LOWER_Z = 'z';
|
||||
/** DOT */
|
||||
public static final char DOT = '.';
|
||||
/** AT */
|
||||
public static final char AT = '@';
|
||||
/** LEFT_BRACE */
|
||||
public static final char LEFT_BRACE = '{';
|
||||
/** RIGHT_BRACE */
|
||||
public static final char RIGHT_BRACE = '}';
|
||||
/** LEFT_BRACKET */
|
||||
public static final char LEFT_BRACKET = '(';
|
||||
/** RIGHT_BRACKET */
|
||||
public static final char RIGHT_BRACKET = ')';
|
||||
/** DASH */
|
||||
public static final char DASH = '-';
|
||||
/** PERCENT */
|
||||
public static final char PERCENT = '%';
|
||||
/** PIPE */
|
||||
public static final char PIPE = '|';
|
||||
/** PLUS */
|
||||
public static final char PLUS = '+';
|
||||
/** QUESTION_MARK */
|
||||
public static final char QUESTION_MARK = '?';
|
||||
/** EXCLAMATION_MARK */
|
||||
public static final char EXCLAMATION_MARK = '!';
|
||||
/** EQUALS */
|
||||
public static final char EQUALS = '=';
|
||||
/** AMPERSAND */
|
||||
public static final char AMPERSAND = '&';
|
||||
/** ASTERISK */
|
||||
public static final char ASTERISK = '*';
|
||||
/** STAR */
|
||||
public static final char STAR = ASTERISK;
|
||||
/** BACK_SLASH */
|
||||
public static final char BACK_SLASH = '\\';
|
||||
/** COLON */
|
||||
public static final char COLON = ':';
|
||||
/** COMMA */
|
||||
public static final char COMMA = ',';
|
||||
/** DOLLAR */
|
||||
public static final char DOLLAR = '$';
|
||||
/** SLASH */
|
||||
public static final char SLASH = '/';
|
||||
/** HASH */
|
||||
public static final char HASH = '#';
|
||||
/** HAT */
|
||||
public static final char HAT = '^';
|
||||
/** LEFT_CHEV */
|
||||
public static final char LEFT_CHEV = '<';
|
||||
/** NEWLINE */
|
||||
public static final char NEWLINE = '\n';
|
||||
/** N */
|
||||
public static final char N = 'n';
|
||||
/** Y */
|
||||
public static final char Y = 'y';
|
||||
/** QUOTE */
|
||||
public static final char QUOTE = '\"';
|
||||
/** RETURN */
|
||||
public static final char RETURN = '\r';
|
||||
/** TAB */
|
||||
public static final char TAB = '\t';
|
||||
/** RIGHT_CHEV */
|
||||
public static final char RIGHT_CHEV = '>';
|
||||
/** SEMICOLON */
|
||||
public static final char SEMICOLON = ';';
|
||||
/** SINGLE_QUOTE */
|
||||
public static final char SINGLE_QUOTE = '\'';
|
||||
/** BACKTICK */
|
||||
public static final char BACKTICK = '`';
|
||||
/** SPACE */
|
||||
public static final char SPACE = ' ';
|
||||
/** TILDA */
|
||||
public static final char TILDA = '~';
|
||||
/** LEFT_SQ_BRACKET */
|
||||
public static final char LEFT_SQ_BRACKET = '[';
|
||||
/** RIGHT_SQ_BRACKET */
|
||||
public static final char RIGHT_SQ_BRACKET = ']';
|
||||
/** UNDERSCORE */
|
||||
public static final char UNDERSCORE = '_';
|
||||
/** ONE */
|
||||
public static final char ONE = '1';
|
||||
/** ZERO */
|
||||
public static final char ZERO = '0';
|
||||
}
|
||||
+49
@@ -0,0 +1,49 @@
|
||||
package com.aos.element.basic.basic.util;
|
||||
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.charset.UnsupportedCharsetException;
|
||||
|
||||
import lombok.experimental.UtilityClass;
|
||||
|
||||
/**
|
||||
* <p>Company: 成都返空汇网络技术有限公司</p>
|
||||
* <p>Description: 字符集工具类 </p>
|
||||
*
|
||||
* @author dong4j
|
||||
* @version 1.2.3
|
||||
* @email "mailto:dongshijie@fkhwl.com"
|
||||
* @date 2020.01.27 14:55
|
||||
* @since 1.0.0
|
||||
*/
|
||||
@UtilityClass
|
||||
public class Charsets {
|
||||
|
||||
/** 字符集ISO-8859-1 */
|
||||
public static final Charset ISO_8859_1 = StandardCharsets.ISO_8859_1;
|
||||
/** The constant ISO_8859_1_NAME. */
|
||||
public static final String ISO_8859_1_NAME = ISO_8859_1.name();
|
||||
/** 字符集GBK */
|
||||
public static final Charset GBK = of("GBK");
|
||||
/** The constant GBK_NAME. */
|
||||
public static final String GBK_NAME = GBK.name();
|
||||
/** 字符集utf-8 */
|
||||
public static final Charset UTF_8 = StandardCharsets.UTF_8;
|
||||
/** The constant UTF_8_NAME. */
|
||||
public static final String UTF_8_NAME = UTF_8.name();
|
||||
|
||||
/**
|
||||
* 转换为Charset对象
|
||||
*
|
||||
* @param charsetName 字符集,为空则返回默认字符集
|
||||
* @return Charsets charset
|
||||
* @throws UnsupportedCharsetException 编码不支持
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public static Charset of(String charsetName) throws UnsupportedCharsetException {
|
||||
return StringUtils.hasText(charsetName) ? Charset.forName(charsetName) : Charset.defaultCharset();
|
||||
}
|
||||
|
||||
}
|
||||
+298
@@ -0,0 +1,298 @@
|
||||
package com.aos.element.basic.basic.util;
|
||||
|
||||
import com.aos.element.basic.basic.exception.BasicException;
|
||||
|
||||
import org.jetbrains.annotations.Contract;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.springframework.core.BridgeMethodResolver;
|
||||
import org.springframework.core.DefaultParameterNameDiscoverer;
|
||||
import org.springframework.core.MethodParameter;
|
||||
import org.springframework.core.ParameterNameDiscoverer;
|
||||
import org.springframework.core.annotation.AnnotatedElementUtils;
|
||||
import org.springframework.core.annotation.SynthesizingMethodParameter;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.web.method.HandlerMethod;
|
||||
|
||||
import java.lang.annotation.Annotation;
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.ParameterizedType;
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
/**
|
||||
* <p>Company: 成都返空汇网络技术有限公司</p>
|
||||
* <p>Description: 类工具类 </p>
|
||||
*
|
||||
* @author dong4j
|
||||
* @version 1.2.3
|
||||
* @email "mailto:dongshijie@fkhwl.com"
|
||||
* @date 2019.12.30 22:37
|
||||
* @since 1.0.0
|
||||
*/
|
||||
@Slf4j
|
||||
@SuppressWarnings("all")
|
||||
public abstract class ClassUtils extends org.springframework.util.ClassUtils {
|
||||
|
||||
/** PARAMETER_NAME_DISCOVERER */
|
||||
public static final ParameterNameDiscoverer PARAMETER_NAME_DISCOVERER = new DefaultParameterNameDiscoverer();
|
||||
/** PACKAGE_SEPARATOR */
|
||||
public static final char PACKAGE_SEPARATOR = '.';
|
||||
/** 代理 class 的名称 */
|
||||
protected static final List<String> PROXY_CLASS_NAMES = Arrays.asList(
|
||||
"net.sf.cglib.proxy.Factory",
|
||||
"org.springframework.cglib.proxy.Factory",
|
||||
"javassist.util.proxy.ProxyObject",
|
||||
"org.apache.ibatis.javassist.util.proxy.ProxyObject");
|
||||
|
||||
/**
|
||||
* 获取方法参数信息
|
||||
*
|
||||
* @param constructor 构造器
|
||||
* @param parameterIndex 参数序号
|
||||
* @return {MethodParameter}
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public static @NotNull MethodParameter getMethodParameter(Constructor<?> constructor, int parameterIndex) {
|
||||
MethodParameter methodParameter = new SynthesizingMethodParameter(constructor, parameterIndex);
|
||||
methodParameter.initParameterNameDiscovery(PARAMETER_NAME_DISCOVERER);
|
||||
return methodParameter;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取方法参数信息
|
||||
*
|
||||
* @param method 方法
|
||||
* @param parameterIndex 参数序号
|
||||
* @return {MethodParameter}
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public static @NotNull MethodParameter getMethodParameter(Method method, int parameterIndex) {
|
||||
MethodParameter methodParameter = new SynthesizingMethodParameter(method, parameterIndex);
|
||||
methodParameter.initParameterNameDiscovery(PARAMETER_NAME_DISCOVERER);
|
||||
return methodParameter;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取Annotation
|
||||
*
|
||||
* @param <A> 泛型标记
|
||||
* @param method Method
|
||||
* @param annotationType 注解类
|
||||
* @return {Annotation}
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public static <A extends Annotation> A getAnnotation(@NotNull Method method, Class<A> annotationType) {
|
||||
Class<?> targetClass = method.getDeclaringClass();
|
||||
// The method may be on an interface, but we need attributes from the target class.
|
||||
// If the target class is null, the method will be unchanged.
|
||||
Method specificMethod = ClassUtils.getMostSpecificMethod(method, targetClass);
|
||||
// If we are dealing with method with generic parameters, find the original method.
|
||||
specificMethod = BridgeMethodResolver.findBridgedMethod(specificMethod);
|
||||
// 先找方法,再找方法上的类
|
||||
A annotation = AnnotatedElementUtils.findMergedAnnotation(specificMethod, annotationType);
|
||||
if (null != annotation) {
|
||||
return annotation;
|
||||
}
|
||||
// 获取类上面的Annotation,可能包含组合注解,故采用spring的工具类
|
||||
return AnnotatedElementUtils.findMergedAnnotation(specificMethod.getDeclaringClass(), annotationType);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取Annotation
|
||||
*
|
||||
* @param <A> 泛型标记
|
||||
* @param handlerMethod HandlerMethod
|
||||
* @param annotationType 注解类
|
||||
* @return {Annotation}
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public static <A extends Annotation> A getAnnotation(@NotNull HandlerMethod handlerMethod, Class<A> annotationType) {
|
||||
// 先找方法,再找方法上的类
|
||||
A annotation = handlerMethod.getMethodAnnotation(annotationType);
|
||||
if (null != annotation) {
|
||||
return annotation;
|
||||
}
|
||||
// 获取类上面的Annotation,可能包含组合注解,故采用spring的工具类
|
||||
Class<?> beanType = handlerMethod.getBeanType();
|
||||
return AnnotatedElementUtils.findMergedAnnotation(beanType, annotationType);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取接口上的泛型T
|
||||
*
|
||||
* @param clazz clazz
|
||||
* @param interfaceClass interface class
|
||||
* @param index 泛型索引
|
||||
* @return the interface t
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public static @NotNull Class<?> getInterfaceT(@NotNull Class<?> clazz, Class<?> interfaceClass, int index) {
|
||||
Type[] types = clazz.getGenericInterfaces();
|
||||
Type targetType = Arrays.stream(types).filter(type -> type.toString().contains(interfaceClass.getName())).findAny().orElse(null);
|
||||
if (targetType == null) {
|
||||
throw new BasicException("[{}] 未实现 [{}] 接口", clazz, interfaceClass);
|
||||
}
|
||||
ParameterizedType parameterizedType = (ParameterizedType) targetType;
|
||||
Type type = parameterizedType.getActualTypeArguments()[index];
|
||||
return checkType(type, index);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取父类上的泛型
|
||||
*
|
||||
* @param clazz clazz
|
||||
* @param index index
|
||||
* @return the class
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public static @NotNull Class<?> getSuperClassT(@NotNull Class<?> clazz, @NotNull Integer index) {
|
||||
Type type = clazz.getGenericSuperclass();
|
||||
ParameterizedType parameterizedType = (ParameterizedType) type;
|
||||
Type actType = parameterizedType.getActualTypeArguments()[index];
|
||||
return checkType(actType, index);
|
||||
}
|
||||
|
||||
/**
|
||||
* 递归获取泛型类型
|
||||
*
|
||||
* @param type type
|
||||
* @param index index
|
||||
* @return the class
|
||||
* @since 1.0.0
|
||||
*/
|
||||
@Contract("null, _ -> fail")
|
||||
private static @NotNull Class<?> checkType(Type type, int index) {
|
||||
if (type instanceof Class<?>) {
|
||||
return (Class<?>) type;
|
||||
} else if (type instanceof ParameterizedType) {
|
||||
ParameterizedType parameterizedType = (ParameterizedType) type;
|
||||
Type t = parameterizedType.getActualTypeArguments()[index];
|
||||
return checkType(t, index);
|
||||
} else {
|
||||
String className = type == null ? "null" : type.getClass().getName();
|
||||
throw new BasicException("Expected a Class, ParameterizedType" + ", but <" + type + "> is of type " + className);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断传入的类型是否是布尔类型
|
||||
*
|
||||
* @param type 类型
|
||||
* @return 如果是原生布尔或者包装类型布尔 , 均返回 true
|
||||
* @since 1.0.0
|
||||
*/
|
||||
@Contract(pure = true)
|
||||
public static boolean isBoolean(Class<?> type) {
|
||||
return type == boolean.class || Boolean.class == type;
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断是否为代理对象
|
||||
*
|
||||
* @param clazz 传入 class 对象
|
||||
* @return 如果对象class是代理 class, 返回 true
|
||||
* @since 1.0.0
|
||||
*/
|
||||
@Contract("null -> false")
|
||||
public static boolean isProxy(Class<?> clazz) {
|
||||
if (clazz != null) {
|
||||
for (Class<?> cls : clazz.getInterfaces()) {
|
||||
if (PROXY_CLASS_NAMES.contains(cls.getName())) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前对象的 class
|
||||
*
|
||||
* @param clazz 传入
|
||||
* @return 如果是代理的class , 返回父 class, 否则返回自身
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public static @NotNull Class<?> getClass(Class<?> clazz) {
|
||||
return isProxy(clazz) ? clazz.getSuperclass() : clazz;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前对象的class
|
||||
*
|
||||
* @param object 对象
|
||||
* @return 返回对象的 user class
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public static @NotNull Class<?> getClass(Object object) {
|
||||
Assert.notNull(object, "Error: Instance must not be null");
|
||||
return getClass(object.getClass());
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据指定的 class , 实例化一个对象, 根据构造参数来实例化
|
||||
* 在 java9 及其之后的版本 Class.newInstance() 方法已被废弃
|
||||
*
|
||||
* @param <T> 类型, 由输入类型决定
|
||||
* @param clazz 需要实例化的对象
|
||||
* @return 返回新的实例 @ not null t
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public static <T> @NotNull T newInstance(@NotNull Class<T> clazz) {
|
||||
try {
|
||||
Constructor<T> constructor = clazz.getDeclaredConstructor();
|
||||
constructor.setAccessible(true);
|
||||
return constructor.newInstance();
|
||||
} catch (InstantiationException | IllegalAccessException | InvocationTargetException | NoSuchMethodException e) {
|
||||
throw new BasicException("实例化对象时出现错误,请尝试给 %s 添加无参的构造方法", e, clazz.getName());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 请仅在确定类存在的情况下调用该方法
|
||||
*
|
||||
* @param name 类名称
|
||||
* @return 返回转换后的 Class
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public static @NotNull Class<?> toClassConfident(String name) {
|
||||
try {
|
||||
return Class.forName(name);
|
||||
} catch (ClassNotFoundException e) {
|
||||
throw new BasicException("找不到指定的class!请仅在明确确定会有 class 的时候, 调用该方法", e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Determine the name of the package of the given class,
|
||||
* e.g. "java.lang" for the {@code java.lang.String} class.
|
||||
*
|
||||
* @param clazz the class
|
||||
* @return the package name, or the empty String if the class is defined in the default package
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public static @NotNull String getPackageName(Class<?> clazz) {
|
||||
Assert.notNull(clazz, "Class must not be null");
|
||||
return getPackageName(clazz.getName());
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine the name of the package of the given fully-qualified class name,
|
||||
* e.g. "java.lang" for the {@code java.lang.String} class name.
|
||||
*
|
||||
* @param fqClassName the fully-qualified class name
|
||||
* @return the package name, or the empty String if the class is defined in the default package
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public static @NotNull String getPackageName(String fqClassName) {
|
||||
Assert.notNull(fqClassName, "Class name must not be null");
|
||||
int lastDotIndex = fqClassName.lastIndexOf(PACKAGE_SEPARATOR);
|
||||
return (lastDotIndex != -1 ? fqClassName.substring(0, lastDotIndex) : "");
|
||||
}
|
||||
|
||||
}
|
||||
+143
@@ -0,0 +1,143 @@
|
||||
package com.aos.element.basic.basic.util;
|
||||
|
||||
import org.jetbrains.annotations.Contract;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.Locale;
|
||||
import java.util.Queue;
|
||||
import java.util.TimeZone;
|
||||
import java.util.concurrent.ConcurrentLinkedQueue;
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
/**
|
||||
* <p>Company: 成都返空汇网络技术有限公司</p>
|
||||
* <p>Description: 安全的时间格式化</p>
|
||||
* 参考 tomcat8 中的并发 DateFormat, {@link SimpleDateFormat}的线程安全包装器. 不使用ThreadLocal,创建足够的SimpleDateFormat对象来满足并发性要求.
|
||||
*
|
||||
* @author dong4j
|
||||
* @version 1.2.3
|
||||
* @email "mailto:dongshijie@fkhwl.com"
|
||||
* @date 2020.01.27 18:18
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public final class ConcurrentDateFormat {
|
||||
/** Format */
|
||||
@Getter
|
||||
private final String format;
|
||||
/** Locale */
|
||||
private final Locale locale;
|
||||
/** Timezone */
|
||||
private final TimeZone timezone;
|
||||
/** Queue */
|
||||
private final Queue<SimpleDateFormat> queue = new ConcurrentLinkedQueue<>();
|
||||
|
||||
/**
|
||||
* Concurrent date format
|
||||
*
|
||||
* @param format format
|
||||
* @param locale locale
|
||||
* @param timezone timezone
|
||||
* @since 1.0.0
|
||||
*/
|
||||
private ConcurrentDateFormat(String format, Locale locale, TimeZone timezone) {
|
||||
this.format = format;
|
||||
this.locale = locale;
|
||||
this.timezone = timezone;
|
||||
SimpleDateFormat initial = this.createInstance();
|
||||
this.queue.add(initial);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create instance simple date format
|
||||
*
|
||||
* @return the simple date format
|
||||
* @since 1.0.0
|
||||
*/
|
||||
@NotNull
|
||||
private SimpleDateFormat createInstance() {
|
||||
SimpleDateFormat sdf = new SimpleDateFormat(this.format, this.locale);
|
||||
sdf.setTimeZone(this.timezone);
|
||||
return sdf;
|
||||
}
|
||||
|
||||
/**
|
||||
* Of concurrent date format.
|
||||
*
|
||||
* @param format the format
|
||||
* @return the concurrent date format
|
||||
* @since 1.0.0
|
||||
*/
|
||||
@NotNull
|
||||
@Contract("_ -> new")
|
||||
public static ConcurrentDateFormat of(String format) {
|
||||
return new ConcurrentDateFormat(format, Locale.getDefault(), TimeZone.getDefault());
|
||||
}
|
||||
|
||||
/**
|
||||
* Of concurrent date format.
|
||||
*
|
||||
* @param format the format
|
||||
* @param timezone the timezone
|
||||
* @return the concurrent date format
|
||||
* @since 1.0.0
|
||||
*/
|
||||
@NotNull
|
||||
@Contract("_, _ -> new")
|
||||
public static ConcurrentDateFormat of(String format, TimeZone timezone) {
|
||||
return new ConcurrentDateFormat(format, Locale.getDefault(), timezone);
|
||||
}
|
||||
|
||||
/**
|
||||
* Of concurrent date format
|
||||
*
|
||||
* @param format format
|
||||
* @param locale locale
|
||||
* @param timezone timezone
|
||||
* @return the concurrent date format
|
||||
* @since 1.0.0
|
||||
*/
|
||||
@NotNull
|
||||
@Contract("_, _, _ -> new")
|
||||
public static ConcurrentDateFormat of(String format, Locale locale, TimeZone timezone) {
|
||||
return new ConcurrentDateFormat(format, locale, timezone);
|
||||
}
|
||||
|
||||
/**
|
||||
* Format string
|
||||
*
|
||||
* @param date date
|
||||
* @return the string
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public @NotNull String format(Date date) {
|
||||
SimpleDateFormat sdf = this.queue.poll();
|
||||
if (sdf == null) {
|
||||
sdf = this.createInstance();
|
||||
}
|
||||
String result = sdf.format(date);
|
||||
this.queue.add(sdf);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse date
|
||||
*
|
||||
* @param source source
|
||||
* @return the date
|
||||
* @throws ParseException parse exception
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public Date parse(String source) throws ParseException {
|
||||
SimpleDateFormat sdf = this.queue.poll();
|
||||
if (sdf == null) {
|
||||
sdf = this.createInstance();
|
||||
}
|
||||
Date result = sdf.parse(source);
|
||||
this.queue.add(sdf);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
+117
@@ -0,0 +1,117 @@
|
||||
package com.aos.element.basic.basic.util;
|
||||
|
||||
import com.aos.element.basic.basic.exception.BasicException;
|
||||
import com.aos.element.basic.basic.support.FastStringWriter;
|
||||
|
||||
import org.jetbrains.annotations.Contract;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.io.*;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.UndeclaredThrowableException;
|
||||
|
||||
import cn.hutool.core.exceptions.ExceptionUtil;
|
||||
import lombok.experimental.UtilityClass;
|
||||
|
||||
/**
|
||||
* <p>Company: 成都返空汇网络技术有限公司</p>
|
||||
* <p>Description: 异常处理工具类 </p>
|
||||
*
|
||||
* @author dong4j
|
||||
* @version 1.2.3
|
||||
* @email "mailto:dongshijie@fkhwl.com"
|
||||
* @date 2019.11.21 09:59
|
||||
* @since 1.0.0
|
||||
*/
|
||||
@UtilityClass
|
||||
public class Exceptions extends ExceptionUtil {
|
||||
|
||||
/**
|
||||
* 将 CheckedException 转换为 UncheckedException.
|
||||
*
|
||||
* @param e Throwable
|
||||
* @return {RuntimeException}
|
||||
* @since 1.0.0
|
||||
*/
|
||||
@NotNull
|
||||
@Contract("null -> new")
|
||||
public static RuntimeException unchecked(Throwable e) {
|
||||
return unchecked(e.getMessage(), e);
|
||||
}
|
||||
|
||||
/**
|
||||
* 将受检异常转换为 unchecked 异常
|
||||
*
|
||||
* @param message message
|
||||
* @param e e
|
||||
* @return the runtime exception
|
||||
* @since 1.0.0
|
||||
*/
|
||||
@NotNull
|
||||
public static RuntimeException unchecked(String message, Throwable e) {
|
||||
RuntimeException runtimeException;
|
||||
if (e instanceof IllegalAccessException || e instanceof IllegalArgumentException
|
||||
|| e instanceof NoSuchMethodException) {
|
||||
runtimeException = new IllegalArgumentException(e);
|
||||
} else if (e instanceof InvocationTargetException) {
|
||||
runtimeException = new RuntimeException(((InvocationTargetException) e).getTargetException());
|
||||
} else if (e instanceof BasicException) {
|
||||
runtimeException = (BasicException) e;
|
||||
} else if (e instanceof RuntimeException) {
|
||||
runtimeException = (RuntimeException) e;
|
||||
} else {
|
||||
runtimeException = new RuntimeException(e);
|
||||
}
|
||||
return runtimeException;
|
||||
}
|
||||
|
||||
/**
|
||||
* 代理异常解包
|
||||
*
|
||||
* @param wrapped 包装过得异常
|
||||
* @return 解包后的异常 throwable
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public static Throwable unwrap(Throwable wrapped) {
|
||||
Throwable unwrapped = wrapped;
|
||||
while (true) {
|
||||
if (unwrapped instanceof InvocationTargetException) {
|
||||
unwrapped = ((InvocationTargetException) unwrapped).getTargetException();
|
||||
} else if (unwrapped instanceof UndeclaredThrowableException) {
|
||||
unwrapped = ((UndeclaredThrowableException) unwrapped).getUndeclaredThrowable();
|
||||
} else {
|
||||
return unwrapped;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 将 ErrorStack 转化为 String.
|
||||
*
|
||||
* @param ex Throwable
|
||||
* @return {String}
|
||||
* @since 1.0.0
|
||||
*/
|
||||
@SuppressWarnings("all")
|
||||
public static String getStackTraceAsString(@NotNull Throwable ex) {
|
||||
FastStringWriter stringWriter = new FastStringWriter();
|
||||
ex.printStackTrace(new PrintWriter(stringWriter));
|
||||
return stringWriter.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* 不采用 RuntimeException 包装,直接抛出,使异常更加精准
|
||||
*
|
||||
* @param <T> 泛型标记
|
||||
* @param throwable Throwable
|
||||
* @return Throwable t
|
||||
* @throws T 泛型
|
||||
* @since 1.0.0
|
||||
*/
|
||||
@Contract("_ -> fail")
|
||||
@SuppressWarnings("unchecked")
|
||||
private static <T extends Throwable> T runtime(Throwable throwable) throws T {
|
||||
throw (T) throwable;
|
||||
}
|
||||
|
||||
}
|
||||
+221
@@ -0,0 +1,221 @@
|
||||
package com.aos.element.basic.basic.util;
|
||||
|
||||
import com.aos.element.basic.basic.support.StrFormatter;
|
||||
|
||||
import org.apache.commons.lang3.SystemUtils;
|
||||
import org.jetbrains.annotations.Contract;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import cn.hutool.core.io.FileUtil;
|
||||
|
||||
/**
|
||||
* <p>Company: 成都返空汇网络技术有限公司</p>
|
||||
* <p>Description: 修改 hosts 文件 </p>
|
||||
*
|
||||
* @author dong4j
|
||||
* @version 1.0.0
|
||||
* @email "mailto:dongshijie@fkhwl.com"
|
||||
* @date 2020.07.14 22:56
|
||||
* @since 1.5.0
|
||||
*/
|
||||
public abstract class HostUtils {
|
||||
|
||||
/** SPLITTER */
|
||||
private static final String SPLITTER = " ";
|
||||
|
||||
/**
|
||||
* 读取 hosts, 排除注释项, 将一行记录解析为 [ip + 空格 + domain}
|
||||
*
|
||||
* @return the set
|
||||
* @since 1.5.0
|
||||
*/
|
||||
public static Set<String> read() {
|
||||
return FileUtil.readLines(getHostFile(), Charsets.UTF_8).stream()
|
||||
.filter(it -> !it.trim().matches("(^#.*)|(\\s*)"))
|
||||
.map(it -> it.replaceAll("#.*", "").trim().replaceAll("\\s+", SPLITTER))
|
||||
.collect(Collectors.toSet());
|
||||
}
|
||||
|
||||
/**
|
||||
* Combine
|
||||
*
|
||||
* @param ip ip
|
||||
* @param domain domain
|
||||
* @return the string
|
||||
* @since 1.5.0
|
||||
*/
|
||||
@Contract(pure = true)
|
||||
public static @NotNull String combine(String ip, String domain) {
|
||||
if (StringUtils.isBlank(domain)) {
|
||||
throw new IllegalArgumentException("ERROR: domain must be specified");
|
||||
}
|
||||
return (ip + SPLITTER + domain).trim();
|
||||
}
|
||||
|
||||
/**
|
||||
* Exists
|
||||
*
|
||||
* @param domain domain
|
||||
* @return the boolean
|
||||
* @since 1.5.0
|
||||
*/
|
||||
public static boolean exists(String domain) {
|
||||
return exists(StringPool.EMPTY, domain);
|
||||
}
|
||||
|
||||
/**
|
||||
* Exists
|
||||
*
|
||||
* @param ip ip
|
||||
* @param domain domain
|
||||
* @return the boolean
|
||||
* @since 1.5.0
|
||||
*/
|
||||
public static boolean exists(String ip, String domain) {
|
||||
return exists(read(), ip, domain);
|
||||
}
|
||||
|
||||
/**
|
||||
* Exists
|
||||
*
|
||||
* @param records records
|
||||
* @param ip ip
|
||||
* @param domain domain
|
||||
* @return the boolean
|
||||
* @since 1.5.0
|
||||
*/
|
||||
public static boolean exists(@NotNull Set<String> records, String ip, String domain) {
|
||||
String combine = combine(ip, domain);
|
||||
for (String record : records) {
|
||||
if (record.contains(combine)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get ips
|
||||
*
|
||||
* @param records records
|
||||
* @param domain domain
|
||||
* @return the set
|
||||
* @since 1.5.0
|
||||
*/
|
||||
public static @NotNull Set<String> getIps(@NotNull Set<String> records, String domain) {
|
||||
Set<String> ips = new HashSet<>(4);
|
||||
|
||||
String combine = combine(StringPool.EMPTY, domain);
|
||||
for (String record : records) {
|
||||
if (record.contains(combine)) {
|
||||
ips.add(ip(record));
|
||||
}
|
||||
}
|
||||
|
||||
return ips;
|
||||
}
|
||||
|
||||
/**
|
||||
* Ip
|
||||
*
|
||||
* @param record record
|
||||
* @return the string
|
||||
* @since 1.5.0
|
||||
*/
|
||||
public static String ip(@NotNull String record) {
|
||||
String[] split = check(record);
|
||||
return split[0];
|
||||
}
|
||||
|
||||
/**
|
||||
* Doamin
|
||||
*
|
||||
* @param record record
|
||||
* @return the string
|
||||
* @since 1.5.0
|
||||
*/
|
||||
public static String doamin(@NotNull String record) {
|
||||
String[] split = check(record);
|
||||
return split[1];
|
||||
}
|
||||
|
||||
/**
|
||||
* Check
|
||||
*
|
||||
* @param record record
|
||||
* @return the string [ ]
|
||||
* @since 1.5.0
|
||||
*/
|
||||
@NotNull
|
||||
@SuppressWarnings("PMD.UndefineMagicConstantRule")
|
||||
private static String[] check(@NotNull String record) {
|
||||
String[] split = record.split(SPLITTER);
|
||||
if (split.length != 2) {
|
||||
throw new IllegalArgumentException("ERROR: ip & domain must be specified");
|
||||
}
|
||||
return split;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取 host 文件路径
|
||||
*
|
||||
* @return host file
|
||||
* @since 1.5.0
|
||||
*/
|
||||
public static @NotNull String getHostFile() {
|
||||
String fileName;
|
||||
|
||||
// 判断系统
|
||||
if (SystemUtils.IS_OS_LINUX || SystemUtils.IS_OS_MAC) {
|
||||
fileName = "/etc/hosts";
|
||||
} else {
|
||||
fileName = System.getenv("windir") + "\\system32\\drivers\\etc\\hosts";
|
||||
}
|
||||
return fileName;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据输入 IP 和 Domain, 删除 host 文件中的某个 host 配置
|
||||
*
|
||||
* @param ip ip
|
||||
* @param domain domain
|
||||
* @since 1.5.0
|
||||
*/
|
||||
public static synchronized void deleteHost(String ip, String domain) {
|
||||
String record = combine(ip, domain);
|
||||
|
||||
if (exists(ip, domain)) {
|
||||
Set<String> lines = read();
|
||||
lines.removeIf(s -> s.equals(record));
|
||||
FileUtil.writeLines(lines, getHostFile(), Charsets.UTF_8);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据输入 IP 和 Domain, 更新 host 文件中的某个 host 配置
|
||||
*
|
||||
* @param ip ip
|
||||
* @param domain domain
|
||||
* @since 1.5.0
|
||||
*/
|
||||
public static synchronized void updateHost(String ip, String domain) {
|
||||
if (StringUtils.isAnyBlank(ip, domain)) {
|
||||
throw new IllegalArgumentException("ERROR: ip & domain must be specified");
|
||||
}
|
||||
|
||||
String record = combine(ip, domain);
|
||||
// 先删除, 如果不存在则不操作
|
||||
deleteHost(ip, domain);
|
||||
|
||||
Set<String> lines = read();
|
||||
lines.add(record);
|
||||
FileUtil.writeLines(lines, getHostFile(), Charsets.UTF_8);
|
||||
|
||||
System.err.println(StrFormatter.format("更新 hosts: {} {}", ip, domain));
|
||||
}
|
||||
|
||||
}
|
||||
+41
@@ -0,0 +1,41 @@
|
||||
package com.aos.element.basic.basic.util;
|
||||
|
||||
import com.aos.element.basic.basic.ssl.DisableValidationTrustManager;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.security.KeyManagementException;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
|
||||
import javax.net.ssl.SSLContext;
|
||||
import javax.net.ssl.TrustManager;
|
||||
|
||||
import lombok.experimental.UtilityClass;
|
||||
|
||||
/**
|
||||
* <p>Company: 成都返空汇网络技术有限公司</p>
|
||||
* <p>Description: </p>
|
||||
*
|
||||
* @author dong4j
|
||||
* @version 1.0.0
|
||||
* @email "mailto:dongshijie@gmail.com"
|
||||
* @date 2020.01.27 17:22
|
||||
* @since 1.0.0
|
||||
*/
|
||||
@UtilityClass
|
||||
public class HttpsUtils {
|
||||
|
||||
/**
|
||||
* 返回忽略 https 证书的 SSLContext
|
||||
*
|
||||
* @return the ssl context
|
||||
* @throws NoSuchAlgorithmException no such algorithm exception
|
||||
* @throws KeyManagementException key management exception
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public static @NotNull SSLContext getSslContext() throws NoSuchAlgorithmException, KeyManagementException {
|
||||
SSLContext sslContext = SSLContext.getInstance("TLS");
|
||||
sslContext.init(null, new TrustManager[] {DisableValidationTrustManager.INSTANCE}, null);
|
||||
return sslContext;
|
||||
}
|
||||
}
|
||||
+136
@@ -0,0 +1,136 @@
|
||||
package com.aos.element.basic.basic.util;
|
||||
|
||||
import org.jetbrains.annotations.Contract;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.springframework.lang.Nullable;
|
||||
|
||||
import java.io.Closeable;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
|
||||
import lombok.experimental.UtilityClass;
|
||||
|
||||
/**
|
||||
* <p>Company: 成都返空汇网络技术有限公司</p>
|
||||
* <p>Description: IoUtil </p>
|
||||
*
|
||||
* @author dong4j
|
||||
* @version 1.2.3
|
||||
* @email "mailto:dongshijie@fkhwl.com"
|
||||
* @date 2019.12.26 21:37
|
||||
* @since 1.0.0
|
||||
*/
|
||||
@UtilityClass
|
||||
public class IoUtils extends org.springframework.util.StreamUtils {
|
||||
|
||||
/**
|
||||
* byte[] 转 String, 编码默认 UTF-8
|
||||
*
|
||||
* @param input input
|
||||
* @return the string
|
||||
* @since 1.0.0
|
||||
*/
|
||||
@NotNull
|
||||
public static String toString(byte[] input) {
|
||||
return toString(input, Charsets.UTF_8_NAME);
|
||||
}
|
||||
|
||||
/**
|
||||
* 使用指定的字符编码以字符串形式获取 byte[] 的内容
|
||||
*
|
||||
* @param input the byte array to read from
|
||||
* @param encoding the encoding to use, null means platform default
|
||||
* @return the requested String
|
||||
* @throws NullPointerException if the input is null
|
||||
* @throws IOException if an I/O error occurs (never occurs)
|
||||
* @since 1.0.0
|
||||
*/
|
||||
@NotNull
|
||||
@Contract("_, _ -> new")
|
||||
public static String toString(byte[] input, String encoding) {
|
||||
return new String(input, Charsets.of(encoding));
|
||||
}
|
||||
|
||||
/**
|
||||
* InputStream to String utf-8
|
||||
*
|
||||
* @param input the <code>InputStream</code> to read from
|
||||
* @return the requested String
|
||||
* @since 1.0.0
|
||||
*/
|
||||
@NotNull
|
||||
public static String toString(InputStream input) {
|
||||
return toString(input, Charsets.UTF_8);
|
||||
}
|
||||
|
||||
/**
|
||||
* InputStream to String
|
||||
*
|
||||
* @param input the <code>InputStream</code> to read from
|
||||
* @param charset the <code>Charsets</code>
|
||||
* @return the requested String
|
||||
* @since 1.0.0
|
||||
*/
|
||||
@NotNull
|
||||
public static String toString(@Nullable InputStream input, java.nio.charset.Charset charset) {
|
||||
try {
|
||||
return IoUtils.copyToString(input, charset);
|
||||
} catch (IOException e) {
|
||||
throw Exceptions.unchecked(e);
|
||||
} finally {
|
||||
IoUtils.closeQuietly(input);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* closeQuietly
|
||||
*
|
||||
* @param closeable 自动关闭
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public static void closeQuietly(@Nullable Closeable closeable) {
|
||||
try {
|
||||
if (closeable != null) {
|
||||
closeable.close();
|
||||
}
|
||||
} catch (IOException ioe) {
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* To byte array byte [ ].
|
||||
*
|
||||
* @param input the input
|
||||
* @return the byte [ ]
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public static byte[] toByteArray(@Nullable InputStream input) {
|
||||
try {
|
||||
return IoUtils.copyToByteArray(input);
|
||||
} catch (IOException e) {
|
||||
throw Exceptions.unchecked(e);
|
||||
} finally {
|
||||
IoUtils.closeQuietly(input);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes chars from a <code>String</code> to bytes on an
|
||||
* <code>OutputStream</code> using the specified character encoding.
|
||||
* <p>
|
||||
* This method uses {@link String#getBytes(String)}.
|
||||
*
|
||||
* @param data the <code>String</code> to write, null ignored
|
||||
* @param output the <code>OutputStream</code> to write to
|
||||
* @param encoding the encoding to use, null means platform default
|
||||
* @throws IOException if an I/O error occurs
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public static void write(@Nullable String data, OutputStream output, java.nio.charset.Charset encoding) throws IOException {
|
||||
if (data != null) {
|
||||
output.write(data.getBytes(encoding));
|
||||
}
|
||||
}
|
||||
}
|
||||
+1156
File diff suppressed because it is too large
Load Diff
+127
@@ -0,0 +1,127 @@
|
||||
package com.aos.element.basic.basic.util;
|
||||
|
||||
import com.aos.element.basic.common.enums.LibraryEnum;
|
||||
|
||||
import com.google.common.collect.Sets;
|
||||
import lombok.experimental.UtilityClass;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
import org.springframework.util.PathMatcher;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* <p>Company: 成都返空汇网络技术有限公司</p>
|
||||
* <p>Description: </p>
|
||||
*
|
||||
* @author dong4j
|
||||
* @version 1.0.0
|
||||
* @email "mailto:dongshijie@fkhwl.com"
|
||||
* @date 2020.06.19 23:44
|
||||
* @since 1.5.0
|
||||
*/
|
||||
@UtilityClass
|
||||
public class SecurityUtils {
|
||||
/** 应用默认的忽略 url 列表 */
|
||||
public static final Set<String> DEFAULT_SKIP_URL = Sets.newHashSetWithExpectedSize(32);
|
||||
|
||||
static {
|
||||
// 忽略启动信息接口
|
||||
DEFAULT_SKIP_URL.add(LibraryEnum.DRUID.getUri() + StringPool.DOUBLE_ASTERISK);
|
||||
// 忽略应用检查接口
|
||||
DEFAULT_SKIP_URL.add("/actuator/**");
|
||||
// 忽略 swagger 相关接口
|
||||
DEFAULT_SKIP_URL.add("/v2/api-docs/**");
|
||||
DEFAULT_SKIP_URL.add("/v2/api-docs-ext/**");
|
||||
DEFAULT_SKIP_URL.add("/swagger-resources/**");
|
||||
DEFAULT_SKIP_URL.add("/swagger-dubbo/**");
|
||||
DEFAULT_SKIP_URL.add("/doc.html");
|
||||
// 忽略验证码相关接口
|
||||
DEFAULT_SKIP_URL.add("/captcha/**");
|
||||
DEFAULT_SKIP_URL.add("/request-urls");
|
||||
// 检查是否需要验证码
|
||||
DEFAULT_SKIP_URL.add("/check");
|
||||
// 忽略 oauth 相关接口
|
||||
DEFAULT_SKIP_URL.add("/oauth/**");
|
||||
// 忽略日志相关接口
|
||||
DEFAULT_SKIP_URL.add("/log/**");
|
||||
// 忽略错误接口
|
||||
DEFAULT_SKIP_URL.add("/error/**");
|
||||
// 忽略静态资源
|
||||
DEFAULT_SKIP_URL.add("/**/*.ico");
|
||||
DEFAULT_SKIP_URL.add("/**/*.css");
|
||||
DEFAULT_SKIP_URL.add("/**/*.js");
|
||||
DEFAULT_SKIP_URL.add("/**/*.html");
|
||||
DEFAULT_SKIP_URL.add("/**/*.map");
|
||||
DEFAULT_SKIP_URL.add("/**/*.svg");
|
||||
DEFAULT_SKIP_URL.add("/**/*.png");
|
||||
DEFAULT_SKIP_URL.add("/**/*.gif");
|
||||
DEFAULT_SKIP_URL.add("/**/*.bmp");
|
||||
}
|
||||
|
||||
/**
|
||||
* 将自定义需要忽略的 url 和默认被忽略的 url 合并
|
||||
*
|
||||
* @param consumterIgnoreUrls 自定义的需要忽略的 url
|
||||
* @return the set 合并后的 url
|
||||
* @since 1.5.0
|
||||
*/
|
||||
public static @NotNull Set<String> mergeSkipPatterns(String consumterIgnoreUrls) {
|
||||
return mergeSkipPatterns(SecurityUtils.DEFAULT_SKIP_URL, consumterIgnoreUrls);
|
||||
}
|
||||
|
||||
/**
|
||||
* Merge skip patterns
|
||||
*
|
||||
* @param defaultSkipUrl default skip url
|
||||
* @param consumterIgnoreUrls consumter ignore urls
|
||||
* @return the set
|
||||
* @since 1.5.0
|
||||
*/
|
||||
public static @NotNull Set<String> mergeSkipPatterns(Collection<String> defaultSkipUrl, String consumterIgnoreUrls) {
|
||||
Set<String> ignores = new HashSet<>(defaultSkipUrl);
|
||||
|
||||
if (StringUtils.isNotBlank(consumterIgnoreUrls)) {
|
||||
String[] split = consumterIgnoreUrls.split(StringPool.COMMA);
|
||||
ignores.addAll(Arrays.stream(split).filter(url -> StringUtils.hasText(url.trim())).collect(Collectors.toSet()));
|
||||
}
|
||||
|
||||
return ignores;
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回 true 则不进入 filter, 否则进入 filter
|
||||
*
|
||||
* @param lookupPath lookup path
|
||||
* @param includePatterns include patterns
|
||||
* @param excludePatterns exclude patterns
|
||||
* @param pathMatcher path matcher
|
||||
* @return the boolean
|
||||
* @since 1.5.0
|
||||
*/
|
||||
public static boolean matches(String lookupPath,
|
||||
String[] includePatterns,
|
||||
String[] excludePatterns,
|
||||
PathMatcher pathMatcher) {
|
||||
if (!ObjectUtils.isEmpty(excludePatterns)) {
|
||||
for (String pattern : excludePatterns) {
|
||||
if (pathMatcher.match(pattern, lookupPath)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (ObjectUtils.isEmpty(includePatterns)) {
|
||||
return false;
|
||||
}
|
||||
for (String pattern : includePatterns) {
|
||||
if (pathMatcher.match(pattern, lookupPath)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
+138
@@ -0,0 +1,138 @@
|
||||
package com.aos.element.basic.basic.util;
|
||||
|
||||
import lombok.experimental.UtilityClass;
|
||||
|
||||
/**
|
||||
* <p>Company: 成都返空汇网络技术有限公司</p>
|
||||
* <p>Description: 静态 String 池 </p>
|
||||
*
|
||||
* @author dong4j
|
||||
* @version 1.2.3
|
||||
* @email "mailto:dongshijie@fkhwl.com"
|
||||
* @date 2020.01.26 22:06
|
||||
* @since 1.0.0
|
||||
*/
|
||||
@UtilityClass
|
||||
public final class StringPool {
|
||||
|
||||
/** AMPERSAND */
|
||||
public static final String AMPERSAND = "&";
|
||||
/** AND */
|
||||
public static final String AND = "and";
|
||||
/** AT */
|
||||
public static final String AT = "@";
|
||||
/** ASTERISK */
|
||||
public static final String ASTERISK = "*";
|
||||
/** STAR */
|
||||
public static final String STAR = ASTERISK;
|
||||
/** SLASH */
|
||||
public static final String SLASH = "/";
|
||||
/** DOUBLE_SLASH */
|
||||
public static final String DOUBLE_SLASH = "#//";
|
||||
/** COLON */
|
||||
public static final String COLON = ":";
|
||||
/** COMMA */
|
||||
public static final String COMMA = ",";
|
||||
/** DASH */
|
||||
public static final String DASH = "-";
|
||||
/** DOLLAR */
|
||||
public static final String DOLLAR = "$";
|
||||
/** DOT */
|
||||
public static final String DOT = ".";
|
||||
/** EMPTY */
|
||||
public static final String EMPTY = "";
|
||||
/** EMPTY_JSON */
|
||||
public static final String EMPTY_JSON = "{}";
|
||||
/** EQUALS */
|
||||
public static final String EQUALS = "=";
|
||||
/** FALSE */
|
||||
public static final String FALSE = "false";
|
||||
/** HASH */
|
||||
public static final String HASH = "#";
|
||||
/** HAT */
|
||||
public static final String HAT = "^";
|
||||
/** LEFT_BRACE */
|
||||
public static final String LEFT_BRACE = "{";
|
||||
/** LEFT_BRACKET */
|
||||
public static final String LEFT_BRACKET = "(";
|
||||
/** LEFT_CHEV */
|
||||
public static final String LEFT_CHEV = "<";
|
||||
/** NEWLINE */
|
||||
public static final String NEWLINE = "\n";
|
||||
/** N */
|
||||
public static final String N = "n";
|
||||
/** NO */
|
||||
public static final String NO = "no";
|
||||
/** NULL */
|
||||
public static final String NULL = "null";
|
||||
/** OFF */
|
||||
public static final String OFF = "off";
|
||||
/** ON */
|
||||
public static final String ON = "on";
|
||||
/** PERCENT */
|
||||
public static final String PERCENT = "%";
|
||||
/** PIPE */
|
||||
public static final String PIPE = "|";
|
||||
/** PLUS */
|
||||
public static final String PLUS = "+";
|
||||
/** QUESTION_MARK */
|
||||
public static final String QUESTION_MARK = "?";
|
||||
/** EXCLAMATION_MARK */
|
||||
public static final String EXCLAMATION_MARK = "!";
|
||||
/** QUOTE */
|
||||
public static final String QUOTE = "\"";
|
||||
/** RETURN */
|
||||
public static final String RETURN = "\r";
|
||||
/** TAB */
|
||||
public static final String TAB = "\t";
|
||||
/** RIGHT_BRACE */
|
||||
public static final String RIGHT_BRACE = "}";
|
||||
/** RIGHT_BRACKET */
|
||||
public static final String RIGHT_BRACKET = ")";
|
||||
/** RIGHT_CHEV */
|
||||
public static final String RIGHT_CHEV = ">";
|
||||
/** SEMICOLON */
|
||||
public static final String SEMICOLON = ";";
|
||||
/** SINGLE_QUOTE */
|
||||
public static final String SINGLE_QUOTE = "'";
|
||||
/** BACKTICK */
|
||||
public static final String BACKTICK = "`";
|
||||
/** SPACE */
|
||||
public static final String SPACE = " ";
|
||||
/** TILDA */
|
||||
public static final String TILDA = "~";
|
||||
/** SQ_BRACKET */
|
||||
public static final String SQ_BRACKET = "[]";
|
||||
/** LEFT_SQ_BRACKET */
|
||||
public static final String LEFT_SQ_BRACKET = "[";
|
||||
/** RIGHT_SQ_BRACKET */
|
||||
public static final String RIGHT_SQ_BRACKET = "]";
|
||||
/** TRUE */
|
||||
public static final String TRUE = "true";
|
||||
/** UNDERSCORE */
|
||||
public static final String UNDERSCORE = "_";
|
||||
/** UTF_8 */
|
||||
public static final String UTF_8 = Charsets.UTF_8_NAME;
|
||||
/** GBK */
|
||||
public static final String GBK = Charsets.GBK_NAME;
|
||||
/** ISO_8859_1 */
|
||||
public static final String ISO_8859_1 = Charsets.ISO_8859_1_NAME;
|
||||
/** Y */
|
||||
public static final String Y = "y";
|
||||
/** YES */
|
||||
public static final String YES = "yes";
|
||||
/** ONE */
|
||||
public static final String ONE = "1";
|
||||
/** ZERO */
|
||||
public static final String ZERO = "0";
|
||||
/** DOLLAR_LEFT_BRACE */
|
||||
public static final String DOLLAR_LEFT_BRACE = "${";
|
||||
/** NULL_STRING */
|
||||
public static final String NULL_STRING = "N/A";
|
||||
/** any_Url_Patterns */
|
||||
public static final String ANY_URL_PATTERNS = SLASH + ASTERISK;
|
||||
/** DOUBLE_ASTERISK */
|
||||
public static final String DOUBLE_ASTERISK = ASTERISK + ASTERISK;
|
||||
/** any_PATH */
|
||||
public static final String ANY_PATH = SLASH + DOUBLE_ASTERISK;
|
||||
}
|
||||
+1625
File diff suppressed because it is too large
Load Diff
+111
@@ -0,0 +1,111 @@
|
||||
package com.aos.element.basic.basic.util;
|
||||
|
||||
import com.aos.element.basic.basic.exception.TimeoutUtilsExecuteException;
|
||||
|
||||
import org.jetbrains.annotations.Contract;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.Future;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
|
||||
import lombok.experimental.UtilityClass;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
/**
|
||||
* <p>Company: 成都返空汇网络技术有限公司 </p>
|
||||
* <p>Description: 简单超时工具类</p>
|
||||
*
|
||||
* @author dong4j
|
||||
* @version 1.0.0
|
||||
* @email "mailto:dongshijie@fkhwl.com"
|
||||
* @date 2020.07.02 23:10
|
||||
* @since 1.5.0
|
||||
*/
|
||||
@Slf4j
|
||||
@UtilityClass
|
||||
@SuppressWarnings("PMD.ThreadPoolCreationRule")
|
||||
public final class TimeoutUtils {
|
||||
/** executor */
|
||||
private static final ExecutorService TIMEOUT_EXECUTOR = Executors.newSingleThreadExecutor();
|
||||
|
||||
/**
|
||||
* Process
|
||||
*
|
||||
* @param <T> parameter
|
||||
* @param task task
|
||||
* @param timeout timeout
|
||||
* @return the t
|
||||
* @throws TimeoutUtilsExecuteException timeout utils execute exception
|
||||
* @since 1.5.0
|
||||
*/
|
||||
@Contract("null, _ -> null")
|
||||
public static <T> T process(Callable<T> task, long timeout) throws Exception {
|
||||
return process(task, timeout, TimeUnit.SECONDS);
|
||||
}
|
||||
|
||||
/**
|
||||
* Process
|
||||
*
|
||||
* @param <T> parameter
|
||||
* @param task task
|
||||
* @param timeout timeout
|
||||
* @param unit unit
|
||||
* @return the t
|
||||
* @throws TimeoutUtilsExecuteException timeout utils execute exception
|
||||
* @since 1.7.1
|
||||
*/
|
||||
@Contract("null, _, _ -> null")
|
||||
public static <T> T process(Callable<T> task, long timeout, TimeUnit unit) throws Exception {
|
||||
return process(TIMEOUT_EXECUTOR, task, timeout, unit);
|
||||
}
|
||||
|
||||
/**
|
||||
* Process
|
||||
* todo-dong4j : (2021.09.18 16:17) [executorService.submit(TtlCallable.get(task))]
|
||||
*
|
||||
* @param <T> parameter
|
||||
* @param executorService executor service
|
||||
* @param task task
|
||||
* @param timeout timeout
|
||||
* @param unit unit
|
||||
* @return the t
|
||||
* @throws TimeoutUtilsExecuteException timeout utils execute exception
|
||||
* @since 1.7.1
|
||||
*/
|
||||
@Contract("_, null, _, _ -> null")
|
||||
public static <T> T process(ExecutorService executorService,
|
||||
Callable<T> task,
|
||||
long timeout,
|
||||
TimeUnit unit) throws Exception {
|
||||
if (task == null) {
|
||||
return null;
|
||||
}
|
||||
Future<T> futureRet = executorService.submit(task);
|
||||
try {
|
||||
return futureRet.get(timeout, unit);
|
||||
} catch (InterruptedException e) {
|
||||
log.error("任务被中断: {}", e.getMessage());
|
||||
throw e;
|
||||
} catch (ExecutionException e) {
|
||||
// 任务抛出异常时将被包装为 ExecutionException
|
||||
Throwable cause = e.getCause();
|
||||
if (cause instanceof InvocationTargetException) {
|
||||
// 如果通过反射调用将会抛出 InvocationTargetException, 这里抛出原始异常
|
||||
throw (InvocationTargetException) cause;
|
||||
}
|
||||
// 否则抛出 ExecutionException, 由业务端处理
|
||||
throw e;
|
||||
} catch (TimeoutException e) {
|
||||
if (!futureRet.isCancelled()) {
|
||||
futureRet.cancel(true);
|
||||
}
|
||||
}
|
||||
|
||||
throw new TimeoutUtilsExecuteException("process timeout: [" + timeout + " " + unit.name().toLowerCase() + "]");
|
||||
}
|
||||
}
|
||||
+48
@@ -0,0 +1,48 @@
|
||||
package com.aos.element.basic.common.base;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.ToString;
|
||||
import lombok.experimental.Accessors;
|
||||
import lombok.experimental.SuperBuilder;
|
||||
|
||||
/**
|
||||
* <p>Company: 成都返空汇网络技术有限公司</p>
|
||||
* <p>Description: </p>
|
||||
*
|
||||
* @param <T> parameter
|
||||
* @author dong4j
|
||||
* @version 1.2.3
|
||||
* @email "mailto:dongshijie@fkhwl.com"
|
||||
* @date 2019.12.18 16:11
|
||||
* @since 1.0.0
|
||||
*/
|
||||
@Data
|
||||
@SuperBuilder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Accessors(chain = true)
|
||||
@ToString(callSuper = true)
|
||||
public abstract class AbstractBaseEntity<T extends Serializable> implements IBaseEntity<T> {
|
||||
/** serialVersionUID */
|
||||
private static final long serialVersionUID = -3550589993340031894L;
|
||||
|
||||
/** 实体 Id */
|
||||
@ApiModelProperty(value = "实体 ID", notes = "新增时可不填,修改时必填")
|
||||
private T id;
|
||||
|
||||
/**
|
||||
* Pk val serializable
|
||||
*
|
||||
* @return the serializable
|
||||
* @since 1.0.0
|
||||
*/
|
||||
@Override
|
||||
public T getId() {
|
||||
return this.id;
|
||||
}
|
||||
}
|
||||
+39
@@ -0,0 +1,39 @@
|
||||
package com.aos.element.basic.common.base;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.ToString;
|
||||
import lombok.experimental.Accessors;
|
||||
import lombok.experimental.SuperBuilder;
|
||||
|
||||
/**
|
||||
* <p>Company: 成都返空汇网络技术有限公司 </p>
|
||||
* <p>Description: mservice层的dto父类, 创建原因是创建统一的CRUD方法</p>
|
||||
*
|
||||
* @param <T> parameter
|
||||
* @author sujian
|
||||
* @version 1.5.0
|
||||
* @email "mailto:sujian@fkhwl.com"
|
||||
* @date 2020.07.01 17:49
|
||||
* @since 1.5.0
|
||||
*/
|
||||
@Data
|
||||
@SuperBuilder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Accessors(chain = true)
|
||||
@ToString(callSuper = true)
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public abstract class AbstractServiceDTO<T extends Serializable> extends BaseDTO<T> {
|
||||
/** serialVersionUID */
|
||||
private static final long serialVersionUID = 1L;
|
||||
/** Create time */
|
||||
private Date createTime;
|
||||
/** Update time */
|
||||
private Date updateTime;
|
||||
}
|
||||
+33
@@ -0,0 +1,33 @@
|
||||
package com.aos.element.basic.common.base;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.ToString;
|
||||
import lombok.experimental.Accessors;
|
||||
import lombok.experimental.SuperBuilder;
|
||||
|
||||
/**
|
||||
* <p>Company: 成都返空汇网络技术有限公司</p>
|
||||
* <p>Description: 服务层的数据交换实体, 只能存在于服务层 </p>
|
||||
*
|
||||
* @param <T> parameter
|
||||
* @author dong4j
|
||||
* @version 1.2.3
|
||||
* @email "mailto:dongshijie@fkhwl.com"
|
||||
* @date 2019.12.08 21:49
|
||||
* @since 1.0.0
|
||||
*/
|
||||
@Data
|
||||
@SuperBuilder
|
||||
@NoArgsConstructor
|
||||
@Accessors(chain = true)
|
||||
@ToString(callSuper = true)
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public abstract class BaseDTO<T extends Serializable> extends AbstractBaseEntity<T> {
|
||||
/** serialVersionUID */
|
||||
private static final long serialVersionUID = 4484918372546552703L;
|
||||
|
||||
}
|
||||
+33
@@ -0,0 +1,33 @@
|
||||
package com.aos.element.basic.common.base;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.ToString;
|
||||
import lombok.experimental.Accessors;
|
||||
import lombok.experimental.SuperBuilder;
|
||||
|
||||
/**
|
||||
* <p>Company: 成都返空汇网络技术有限公司</p>
|
||||
* <p>Description: controller 入参, 必须使用 validation 相关注解对字段进行标识, 只能在视图层 </p>
|
||||
*
|
||||
* @param <T> parameter
|
||||
* @author dong4j
|
||||
* @version 1.2.3
|
||||
* @email "mailto:dongshijie@fkhwl.com"
|
||||
* @date 2019.12.18 16:11
|
||||
* @since 1.0.0
|
||||
*/
|
||||
@Data
|
||||
@SuperBuilder
|
||||
@NoArgsConstructor
|
||||
@Accessors(chain = true)
|
||||
@ToString(callSuper = true)
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public abstract class BaseForm<T extends Serializable> extends AbstractBaseEntity<T> {
|
||||
/** serialVersionUID */
|
||||
private static final long serialVersionUID = -3550589993340031894L;
|
||||
|
||||
}
|
||||
+55
@@ -0,0 +1,55 @@
|
||||
package com.aos.element.basic.common.base;
|
||||
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.ToString;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
/**
|
||||
* <p>Company: 成都返空汇网络技术有限公司</p>
|
||||
* <p>Description: 分页数据基类 </p>
|
||||
*
|
||||
* @param <T> parameter
|
||||
* @author dong4j
|
||||
* @version 1.0.0
|
||||
* @email "mailto:dongshijie@fkhwl.com"
|
||||
* @date 2020.09.04 14:29
|
||||
* @since 1.6.0
|
||||
*/
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@Accessors(chain = true)
|
||||
@ToString(callSuper = true)
|
||||
public abstract class BasePage<T extends AbstractBaseEntity<?>> implements Serializable {
|
||||
|
||||
/** serialVersionUID */
|
||||
private static final long serialVersionUID = 5982670181085815965L;
|
||||
/** Pagination */
|
||||
private IPage<T> pagination;
|
||||
|
||||
/**
|
||||
* Build
|
||||
*
|
||||
* @param <T> parameter
|
||||
* @param pagination pagination
|
||||
* @return the template user page
|
||||
* @since 1.6.0
|
||||
* @deprecated 使用 {@link com.baomidou.mybatisplus.core.metadata.IPage#wrapper} 代替
|
||||
*/
|
||||
@Deprecated
|
||||
public static <T extends AbstractBaseEntity<?>> @NotNull BasePage<T> build(IPage<T> pagination) {
|
||||
BasePage<T> basePage = new BasePage<T>() {
|
||||
private static final long serialVersionUID = -6820396419783198219L;
|
||||
};
|
||||
|
||||
// 由于 json 反序列化不能使用抽象类和接口, 这里强转为 Page
|
||||
basePage.setPagination(pagination);
|
||||
return basePage;
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user