Init project
This commit is contained in:
3
.idea/.gitignore
generated
vendored
Normal file
3
.idea/.gitignore
generated
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
# Default ignored files
|
||||
/shelf/
|
||||
/workspace.xml
|
||||
13
.idea/compiler.xml
generated
Normal file
13
.idea/compiler.xml
generated
Normal file
@@ -0,0 +1,13 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="CompilerConfiguration">
|
||||
<annotationProcessing>
|
||||
<profile name="Maven default annotation processors profile" enabled="true">
|
||||
<sourceOutputDir name="target/generated-sources/annotations" />
|
||||
<sourceTestOutputDir name="target/generated-test-sources/test-annotations" />
|
||||
<outputRelativeToContentRoot value="true" />
|
||||
<module name="common4j" />
|
||||
</profile>
|
||||
</annotationProcessing>
|
||||
</component>
|
||||
</project>
|
||||
7
.idea/encodings.xml
generated
Normal file
7
.idea/encodings.xml
generated
Normal file
@@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="Encoding">
|
||||
<file url="file://$PROJECT_DIR$/src/main/java" charset="UTF-8" />
|
||||
<file url="file://$PROJECT_DIR$/src/main/resources" charset="UTF-8" />
|
||||
</component>
|
||||
</project>
|
||||
30
.idea/jarRepositories.xml
generated
Normal file
30
.idea/jarRepositories.xml
generated
Normal file
@@ -0,0 +1,30 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="RemoteRepositoriesConfiguration">
|
||||
<remote-repository>
|
||||
<option name="id" value="central" />
|
||||
<option name="name" value="Central Repository" />
|
||||
<option name="url" value="https://repo.maven.apache.org/maven2" />
|
||||
</remote-repository>
|
||||
<remote-repository>
|
||||
<option name="id" value="jtec_nexus" />
|
||||
<option name="name" value="jtec_nexus" />
|
||||
<option name="url" value="http://106.53.0.213:33232/repository/maven-public/" />
|
||||
</remote-repository>
|
||||
<remote-repository>
|
||||
<option name="id" value="timi_nexus" />
|
||||
<option name="name" value="timi_nexus" />
|
||||
<option name="url" value="https://nexus.imyeyu.com/repository/maven-public/" />
|
||||
</remote-repository>
|
||||
<remote-repository>
|
||||
<option name="id" value="central" />
|
||||
<option name="name" value="Maven Central repository" />
|
||||
<option name="url" value="https://repo1.maven.org/maven2" />
|
||||
</remote-repository>
|
||||
<remote-repository>
|
||||
<option name="id" value="jboss.community" />
|
||||
<option name="name" value="JBoss Community repository" />
|
||||
<option name="url" value="https://repository.jboss.org/nexus/content/repositories/public/" />
|
||||
</remote-repository>
|
||||
</component>
|
||||
</project>
|
||||
14
.idea/misc.xml
generated
Normal file
14
.idea/misc.xml
generated
Normal file
@@ -0,0 +1,14 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ExternalStorageConfigurationManager" enabled="true" />
|
||||
<component name="MavenProjectsManager">
|
||||
<option name="originalFiles">
|
||||
<list>
|
||||
<option value="$PROJECT_DIR$/pom.xml" />
|
||||
</list>
|
||||
</option>
|
||||
</component>
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_21" project-jdk-name="openjdk-17" project-jdk-type="JavaSDK">
|
||||
<output url="file://$PROJECT_DIR$/out" />
|
||||
</component>
|
||||
</project>
|
||||
6
.idea/vcs.xml
generated
Normal file
6
.idea/vcs.xml
generated
Normal file
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="" vcs="Git" />
|
||||
</component>
|
||||
</project>
|
||||
100
pom.xml
Normal file
100
pom.xml
Normal file
@@ -0,0 +1,100 @@
|
||||
<?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>work.imyeyu.common4j</groupId>
|
||||
<artifactId>common4j</artifactId>
|
||||
<version>0.0.1</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>21</maven.compiler.source>
|
||||
<maven.compiler.target>21</maven.compiler.target>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<maven.test.skip>true</maven.test.skip>
|
||||
</properties>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-deploy-plugin</artifactId>
|
||||
<version>3.1.3</version>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-source-plugin</artifactId>
|
||||
<version>3.3.1</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>attach-sources</id>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>jar-no-fork</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-javadoc-plugin</artifactId>
|
||||
<version>3.11.2</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>attach-javadocs</id>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>jar</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
<distributionManagement>
|
||||
<repository>
|
||||
<id>jtec_nexus</id>
|
||||
<url>http://106.53.0.213:33232/repository/maven-releases/</url>
|
||||
</repository>
|
||||
</distributionManagement>
|
||||
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>jtec_nexus</id>
|
||||
<url>http://106.53.0.213:33232/repository/maven-public/</url>
|
||||
<releases>
|
||||
<enabled>true</enabled>
|
||||
</releases>
|
||||
<snapshots>
|
||||
<enabled>true</enabled>
|
||||
</snapshots>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>timi_nexus</id>
|
||||
<url>https://nexus.imyeyu.com/repository/maven-public/</url>
|
||||
<releases>
|
||||
<enabled>true</enabled>
|
||||
</releases>
|
||||
<snapshots>
|
||||
<enabled>true</enabled>
|
||||
</snapshots>
|
||||
</repository>
|
||||
</repositories>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.junit.jupiter</groupId>
|
||||
<artifactId>junit-jupiter</artifactId>
|
||||
<version>5.10.3</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.imyeyu.java</groupId>
|
||||
<artifactId>timi-java</artifactId>
|
||||
<version>0.0.1</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
47
src/main/java/work/imyeyu/common4j/ApiResponse.java
Normal file
47
src/main/java/work/imyeyu/common4j/ApiResponse.java
Normal file
@@ -0,0 +1,47 @@
|
||||
package work.imyeyu.common4j;
|
||||
|
||||
import com.imyeyu.java.bean.timi.TimiResponse;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* 通用接口返回对象
|
||||
*
|
||||
* @author 夜雨
|
||||
* @since 2021-07-01 20:18
|
||||
*/
|
||||
public class ApiResponse<T> extends TimiResponse<T> {
|
||||
|
||||
public ApiResponse() {
|
||||
super();
|
||||
}
|
||||
|
||||
public ApiResponse(ResultCode code) {
|
||||
super(code.toTimiCode());
|
||||
}
|
||||
|
||||
public ApiResponse(ResultCode code, T data) {
|
||||
super(code.toTimiCode(), data);
|
||||
}
|
||||
|
||||
public ApiResponse(ResultCode code, T data, String msg) {
|
||||
super(code.toTimiCode(), data, msg);
|
||||
}
|
||||
|
||||
@Override
|
||||
public AppException toException() {
|
||||
return Objects.requireNonNull(ResultCode.fromCode(this.code)).toException(msg);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ApiResponse<T> msg(String msg) {
|
||||
super.msg(msg);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ApiResponse<T> msgKey(String msgKey) {
|
||||
super.msgKey(msgKey);
|
||||
return this;
|
||||
}
|
||||
}
|
||||
37
src/main/java/work/imyeyu/common4j/AppError.java
Normal file
37
src/main/java/work/imyeyu/common4j/AppError.java
Normal file
@@ -0,0 +1,37 @@
|
||||
package work.imyeyu.common4j;
|
||||
|
||||
import com.imyeyu.java.bean.timi.TimiError;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* 致命错误
|
||||
*
|
||||
* @author 夜雨
|
||||
* @since 2023-04-27 15:55
|
||||
*/
|
||||
public class AppError extends TimiError {
|
||||
|
||||
public AppError(ResultCode code) {
|
||||
super(code.toTimiCode());
|
||||
}
|
||||
|
||||
public AppError(ResultCode code, String msg) {
|
||||
super(code.toTimiCode(), msg);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ApiResponse<?> toResponse() {
|
||||
return new ApiResponse<>(Objects.requireNonNull(ResultCode.fromCode(code.getValue()))).msg(getMessage()).msgKey(msgKey);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TimiError msg(String msg) {
|
||||
return super.msg(msg);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TimiError msgKey(String msgKey) {
|
||||
return super.msgKey(msgKey);
|
||||
}
|
||||
}
|
||||
43
src/main/java/work/imyeyu/common4j/AppException.java
Normal file
43
src/main/java/work/imyeyu/common4j/AppException.java
Normal file
@@ -0,0 +1,43 @@
|
||||
package work.imyeyu.common4j;
|
||||
|
||||
import com.imyeyu.java.bean.timi.TimiException;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* 通用运行时异常,附加通用代码
|
||||
*
|
||||
* @author 夜雨
|
||||
* @since 2021-05-20 15:18
|
||||
*/
|
||||
public class AppException extends TimiException {
|
||||
|
||||
public AppException(ResultCode code) {
|
||||
super(code.toTimiCode());
|
||||
}
|
||||
|
||||
public AppException(ResultCode code, String msg) {
|
||||
super(code.toTimiCode(), msg);
|
||||
}
|
||||
|
||||
public AppException(ResultCode code, String msg, Throwable e) {
|
||||
super(code.toTimiCode(), msg, e);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ApiResponse<?> toResponse() {
|
||||
return new ApiResponse<>(Objects.requireNonNull(ResultCode.fromCode(code.getValue()))).msg(getMessage()).msgKey(msgKey);
|
||||
}
|
||||
|
||||
@Override
|
||||
public AppException msg(String msg) {
|
||||
super.msg(msg);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AppException msgKey(String msgKey) {
|
||||
super.msgKey(msgKey);
|
||||
return this;
|
||||
}
|
||||
}
|
||||
141
src/main/java/work/imyeyu/common4j/ResultCode.java
Normal file
141
src/main/java/work/imyeyu/common4j/ResultCode.java
Normal file
@@ -0,0 +1,141 @@
|
||||
package work.imyeyu.common4j;
|
||||
|
||||
import com.imyeyu.java.bean.timi.TimiCode;
|
||||
|
||||
/**
|
||||
* 通用代码(基于 HTTP 代码扩展)
|
||||
*
|
||||
* @author 夜雨
|
||||
* @since 2021-05-21 14:32
|
||||
*/
|
||||
public enum ResultCode {
|
||||
|
||||
// ---------- 200 正常 ----------
|
||||
|
||||
/** 执行成功 */
|
||||
SUCCESS(20000),
|
||||
|
||||
/** 执行成功,忽略请求 */
|
||||
IGNORE (20001),
|
||||
|
||||
// ---------- 400 参数异常 ----------
|
||||
|
||||
/** 缺少参数 */
|
||||
ARG_MISS(40000),
|
||||
|
||||
/** 不合法的参数 */
|
||||
ARG_BAD(40001),
|
||||
|
||||
/** 过期的参数 */
|
||||
ARG_EXPIRED(40002),
|
||||
|
||||
// ---------- 401 权限异常 ----------
|
||||
|
||||
/** 无权限 */
|
||||
PERMISSION_MISS(40100),
|
||||
|
||||
/** 无权限 */
|
||||
PERMISSION_ERROR (40101),
|
||||
|
||||
/** 非法请求 */
|
||||
REQUEST_BAD(40102),
|
||||
|
||||
// ---------- 403 数据异常 ----------
|
||||
|
||||
/** 数据已存在 */
|
||||
DATA_EXIST (40301),
|
||||
|
||||
// ---------- 404 资源异常 ----------
|
||||
|
||||
/** 无数据 */
|
||||
RESULT_NULL(40400),
|
||||
|
||||
/** 返回数据异常 */
|
||||
RESULT_BAD (40401),
|
||||
|
||||
/** 禁用的数据 */
|
||||
RESULT_BAN (40402),
|
||||
|
||||
/** 上游服务器连接超时 */
|
||||
RESULT_TIMEOUT (40403),
|
||||
|
||||
// ---------- 500 致命异常 ----------
|
||||
|
||||
/** 服务异常 */
|
||||
ERROR(50000),
|
||||
|
||||
/** 服务异常 */
|
||||
ERROR_NOT_SUPPORT(50001),
|
||||
|
||||
/** 服务异常 */
|
||||
ERROR_NPE_VARIABLE(50002),
|
||||
|
||||
/** 服务关闭 */
|
||||
ERROR_SERVICE_OFF(50003),
|
||||
|
||||
/** 服务繁忙 */
|
||||
ERROR_SERVICE_BUSY(50300);
|
||||
|
||||
final Integer value;
|
||||
|
||||
ResultCode(Integer value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* 转为通用异常
|
||||
*
|
||||
* @return 异常
|
||||
*/
|
||||
public AppException toException() {
|
||||
return toException(toString());
|
||||
}
|
||||
|
||||
/**
|
||||
* 转为通用异常
|
||||
*
|
||||
* @param msg 异常消息
|
||||
* @return 异常
|
||||
*/
|
||||
public AppException toException(String msg) {
|
||||
return new AppException(this, msg);
|
||||
}
|
||||
|
||||
/**
|
||||
* 转为通用返回对象
|
||||
*
|
||||
* @return 返回对象
|
||||
*/
|
||||
public ApiResponse<?> toResponse() {
|
||||
return new ApiResponse<>(this).msg(toString());
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取代码
|
||||
*
|
||||
* @return 代码
|
||||
*/
|
||||
public Integer getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据代码返回对象
|
||||
*
|
||||
* @param code 代码
|
||||
* @return 对象
|
||||
*/
|
||||
public static ResultCode fromCode(int code) {
|
||||
ResultCode[] codes = values();
|
||||
for (int i = 0; i < codes.length; i++) {
|
||||
if (codes[i].getValue() == code) {
|
||||
return codes[i];
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
TimiCode toTimiCode() {
|
||||
return TimiCode.fromCode(value);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user