🔨 拆分出 common-model 模块

🎨 重命名 SpringUtils -> ApplicationContextHolder
 调整 json 序列化使用 JsonUtils
This commit is contained in:
b2baccline
2021-03-02 19:02:43 +08:00
parent 93b1e5836e
commit a22fec3493
119 changed files with 391 additions and 330 deletions

View File

@@ -0,0 +1,34 @@
<?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>ballcat-common</artifactId>
<groupId>com.hccake</groupId>
<version>${revision}</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>ballcat-common-model</artifactId>
<dependencies>
<dependency>
<groupId>io.swagger</groupId>
<artifactId>swagger-annotations</artifactId>
</dependency>
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
</dependency>
<dependency>
<groupId>org.hibernate.validator</groupId>
<artifactId>hibernate-validator</artifactId>
</dependency>
</dependencies>
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
</properties>
</project>

View File

@@ -0,0 +1,63 @@
package com.hccake.ballcat.common.model.domain;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.Getter;
import lombok.Setter;
import org.hibernate.validator.constraints.Range;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotNull;
import java.util.ArrayList;
import java.util.List;
/**
* 分页查询参数
*
* @author Hccake 2021/1/18
* @version 1.0
*/
@Data
@ApiModel("分页查询参数")
public class PageParam {
/**
* 当前页
*/
@ApiModelProperty(value = "当前页码,从 1 开始", required = true, example = "1")
@NotNull(message = "当前页码不能为空")
@Min(value = 1, message = "当前页不能小于 1")
private long current = 1;
/**
* 每页显示条数,默认 10
*/
@ApiModelProperty(value = "每页条数,最大值为 100", required = true, example = "10")
@NotNull(message = "每页条数不能为空")
@Range(min = 1, max = 100, message = "条数范围为 [1, 100]")
private long size = 10;
@ApiModelProperty(value = "排序规则")
private List<Sort> sorts = new ArrayList<>();
@Getter
@Setter
@ApiModel("排序元素载体")
public static class Sort {
/**
* 排序字段
*/
@ApiModelProperty(value = "排序字段")
private String field;
/**
* 是否正序排序
*/
@ApiModelProperty(value = "是否正序排序")
private boolean asc;
}
}

View File

@@ -0,0 +1,44 @@
package com.hccake.ballcat.common.model.domain;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.util.Collections;
import java.util.List;
/**
* 分页返回结果
*
* @author Hccake 2021/1/18
* @version 1.0
*/
@Data
@ApiModel("分页返回结果")
public class PageResult<T> {
/**
* 查询数据列表
*/
@ApiModelProperty(value = "分页数据", required = true)
protected List<T> records = Collections.emptyList();
/**
* 总数
*/
@ApiModelProperty(value = "数据总量", required = true)
protected Long total = 0L;
public PageResult() {
}
public PageResult(long total) {
this.total = total;
}
public PageResult(List<T> records, long total) {
this.records = records;
this.total = total;
}
}

View File

@@ -0,0 +1,52 @@
package com.hccake.ballcat.common.model.domain;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
/**
* 下拉框所对应的视图类
*
* @author Hccake
*/
@Data
@ApiModel("下拉框数据")
public class SelectData<T> {
/**
* 显示的数据
*/
@ApiModelProperty(value = "显示的数据", required = true)
private String name;
/**
* 选中获取的属性
*/
@ApiModelProperty(value = "选中获取的属性", required = true)
private String value;
/**
* 是否被选中
*/
@ApiModelProperty(value = "是否被选中")
private String selected;
/**
* 是否禁用
*/
@ApiModelProperty(value = "是否禁用")
private String disabled;
/**
* 分组标识
*/
@ApiModelProperty(value = "分组标识")
private String type;
/**
* 扩展对象
*/
@ApiModelProperty(value = "扩展对象")
private T extendObj;
}

View File

@@ -0,0 +1,44 @@
package com.hccake.ballcat.common.model.result;
import lombok.AllArgsConstructor;
import lombok.Getter;
/**
* @author Hccake
* @version 1.0
* @date 2019/9/12 12:19
*/
@Getter
@AllArgsConstructor
public enum BaseResultCode implements ResultCode {
/**
* 数据库保存/更新异常
*/
UPDATE_DATABASE_ERROR(90001, "Update Database Error"),
/**
* 通用的逻辑校验异常
*/
LOGIC_CHECK_ERROR(90004, "Logic Check Error"),
/**
* 恶意请求
*/
MALICIOUS_REQUEST(90005, "Malicious Request"),
/**
* 文件上传异常
*/
FILE_UPLOAD_ERROR(90006, "File Upload Error"),
/**
* 未知异常
*/
UNKNOWN_ERROR(99999, "Unknown Error");
private final Integer code;
private final String message;
}

View File

@@ -0,0 +1,61 @@
package com.hccake.ballcat.common.model.result;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.*;
import lombok.experimental.Accessors;
import java.io.Serializable;
/**
* 响应信息主体
*
* @param <T>
* @author Hccake
*/
@Getter
@Setter
@ToString
@NoArgsConstructor
@AllArgsConstructor
@Accessors(chain = true)
@ApiModel(value = "返回体结构")
public class R<T> implements Serializable {
private static final long serialVersionUID = 1L;
@ApiModelProperty(value = "返回状态码")
private int code;
@ApiModelProperty(value = "返回信息")
private String message;
@ApiModelProperty(value = "数据")
private T data;
public static <T> R<T> ok() {
return ok(null);
}
public static <T> R<T> ok(T data) {
return new R<T>().setCode(SystemResultCode.SUCCESS.getCode()).setData(data)
.setMessage(SystemResultCode.SUCCESS.getMessage());
}
public static <T> R<T> ok(T data, String message) {
return new R<T>().setCode(SystemResultCode.SUCCESS.getCode()).setData(data).setMessage(message);
}
public static <T> R<T> failed(int code, String message) {
return new R<T>().setCode(code).setMessage(message);
}
public static <T> R<T> failed(ResultCode failMsg) {
return new R<T>().setCode(failMsg.getCode()).setMessage(failMsg.getMessage());
}
public static <T> R<T> failed(ResultCode failMsg, String message) {
return new R<T>().setCode(failMsg.getCode()).setMessage(message);
}
}

View File

@@ -0,0 +1,22 @@
package com.hccake.ballcat.common.model.result;
/**
* @author Hccake
* @version 1.0
* @date 2020/3/20 14:45
*/
public interface ResultCode {
/**
* 获取业务码
* @return 业务码
*/
Integer getCode();
/**
* 获取信息
* @return 返回结构体中的信息
*/
String getMessage();
}

View File

@@ -0,0 +1,41 @@
package com.hccake.ballcat.common.model.result;
import lombok.AllArgsConstructor;
import lombok.Getter;
/**
* @author Hccake
* @version 1.0
* @date 2019/9/12 12:19
*/
@Getter
@AllArgsConstructor
public enum SystemResultCode implements ResultCode {
// ================ 基础部分,参考 HttpStatus =============
/**
* 成功
*/
SUCCESS(200, "Success"),
/**
* 参数错误
*/
BAD_REQUEST(400, "Bad Request"),
/**
* 未认证
*/
UNAUTHORIZED(401, "Unauthorized"),
/**
* 未授权
*/
FORBIDDEN(403, "Forbidden"),
/**
* 服务异常
*/
SERVER_ERROR(500, "Internal Server Error");
private final Integer code;
private final String message;
}

View File

@@ -0,0 +1,30 @@
package com.hccake.ballcat.common.model.tree;
import lombok.Data;
import java.util.List;
/**
* @author Hccake
* @version 1.0
* @date 2020/6/21 17:08
*/
@Data
public class SimpleTreeNode<T> implements TreeNode<T> {
/**
* 节点ID
*/
private T id;
/**
* 父节点ID
*/
private T parentId;
/**
* 子节点集合
*/
private List<? extends TreeNode<T>> children;
}

View File

@@ -0,0 +1,36 @@
package com.hccake.ballcat.common.model.tree;
import java.util.List;
/**
* @author Hccake
* @version 1.0
* @date 2020/6/21 17:05
*/
public interface TreeNode<T> {
/**
* 获取节点id
* @return 树节点id
*/
T getId();
/**
* 获取该节点的父节点id
* @return 父节点id
*/
T getParentId();
/**
* 设置节点的子节点列表
* @param children 子节点
*/
void setChildren(List<? extends TreeNode<T>> children);
/**
* 获取所有子节点
* @return 子节点列表
*/
List<? extends TreeNode<T>> getChildren();
}