first version of aida_back
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
package com.ai.da.common.response;
|
||||
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @ClassName PageResponse
|
||||
* @Description 分页响应
|
||||
* @Author dwjian
|
||||
* @Date 2020/1/13 0:26
|
||||
*/
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@ApiModel("分页响应结果")
|
||||
public class PageBaseResponse<T>{
|
||||
@ApiModelProperty("页码")
|
||||
private long page;
|
||||
@ApiModelProperty("每页数量")
|
||||
private long size;
|
||||
@ApiModelProperty("总页数")
|
||||
private long pages;
|
||||
@ApiModelProperty("总条数")
|
||||
private long total;
|
||||
@ApiModelProperty("结果集")
|
||||
private List<T> content;
|
||||
|
||||
|
||||
|
||||
public PageBaseResponse(List<T> list, long page, long size, long total, long pages) {
|
||||
this.page = page;
|
||||
this.size = size;
|
||||
this.total = total;
|
||||
this.pages = pages;
|
||||
this.content = list;
|
||||
}
|
||||
|
||||
public static <T> PageBaseResponse<T> success(IPage<T> page){
|
||||
return new PageBaseResponse<>(page.getRecords() , page.getCurrent(), page.getSize(), page.getTotal(), page.getPages());
|
||||
}
|
||||
}
|
||||
52
src/main/java/com/ai/da/common/response/PageResponse.java
Normal file
52
src/main/java/com/ai/da/common/response/PageResponse.java
Normal file
@@ -0,0 +1,52 @@
|
||||
package com.ai.da.common.response;
|
||||
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @ClassName PageResponse
|
||||
* @Description 分页响应
|
||||
* @Author dwjian
|
||||
* @Date 2020/1/13 0:26
|
||||
*/
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@ApiModel("分页响应结果")
|
||||
public class PageResponse<T> extends Response<List<T>> {
|
||||
@ApiModelProperty("页码")
|
||||
private long page;
|
||||
@ApiModelProperty("每页数量")
|
||||
private long size;
|
||||
@ApiModelProperty("总页数")
|
||||
private long pages;
|
||||
@ApiModelProperty("总条数")
|
||||
private long total;
|
||||
|
||||
@ApiModelProperty("结果集")
|
||||
private List<T> content;
|
||||
|
||||
|
||||
|
||||
public PageResponse(Response<List<T>> response, long page, long size, long total, long pages) {
|
||||
if(response != null) {
|
||||
this.setData(response.getData());
|
||||
this.setErrCode(response.getErrCode());
|
||||
this.setErrMsg(response.getErrMsg());
|
||||
}
|
||||
this.page = page;
|
||||
this.size = size;
|
||||
this.total = total;
|
||||
this.pages = pages;
|
||||
this.content = response.getData();
|
||||
}
|
||||
|
||||
public static <T> PageResponse<T> success(IPage<T> page){
|
||||
Response<List<T>> response = success(page.getRecords());
|
||||
return new PageResponse<>(response , page.getCurrent(), page.getSize(), page.getTotal(), page.getPages());
|
||||
}
|
||||
}
|
||||
93
src/main/java/com/ai/da/common/response/Response.java
Normal file
93
src/main/java/com/ai/da/common/response/Response.java
Normal file
@@ -0,0 +1,93 @@
|
||||
package com.ai.da.common.response;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* @ClassName Response
|
||||
* @Description success代表响应成功 fail代表主动响应失败 error代表系统异常
|
||||
* @Author dwjian
|
||||
* @Date 2019/9/8 21:48
|
||||
*/
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@ApiModel("响应结果")
|
||||
public class Response<T> implements Serializable {
|
||||
|
||||
@ApiModelProperty("响应状态码 0:成功 -1:失败")
|
||||
private int errCode;
|
||||
@ApiModelProperty("提示消息")
|
||||
private String errMsg;
|
||||
@ApiModelProperty("数据结果")
|
||||
private T data;
|
||||
|
||||
public static <T> Response<T> success(){
|
||||
return success(ResultEnum.SUCCESS.getCode(), ResultEnum.SUCCESS.getMsg(), null);
|
||||
}
|
||||
|
||||
public static <T> Response<T> success(String msg){
|
||||
return success(ResultEnum.SUCCESS.getCode(), msg, null);
|
||||
}
|
||||
|
||||
public static <T> Response<T> success(T data){
|
||||
return success(ResultEnum.SUCCESS.getCode(), ResultEnum.SUCCESS.getMsg(), data);
|
||||
}
|
||||
|
||||
public static <T> Response<T> success(int code, T data){
|
||||
return success(code, ResultEnum.SUCCESS.getMsg(), data);
|
||||
}
|
||||
|
||||
public static <T> Response<T> success(int code, String msg, T data){
|
||||
return getResponse(code, msg, data);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static <T> Response<T> fail(String msg) {
|
||||
return fail(ResultEnum.FAIL.getCode(), msg);
|
||||
}
|
||||
|
||||
public static <T> Response<T> fail(T data) {
|
||||
return fail(ResultEnum.FAIL.getCode(), ResultEnum.FAIL.getMsg(), data);
|
||||
}
|
||||
|
||||
public static <T> Response<T> fail(ResultEnum resultEnum) {
|
||||
return fail(resultEnum.getCode(), resultEnum.getMsg(), null);
|
||||
}
|
||||
|
||||
public static <T> Response<T> fail(int code, String msg) {
|
||||
return fail(code, msg, null);
|
||||
}
|
||||
|
||||
public static <T> Response<T> fail(int code, String msg, T data) {
|
||||
return getResponse(code, msg, data);
|
||||
}
|
||||
|
||||
public static <T> Response<T> error(String msg) {
|
||||
return error(ResultEnum.ERROR.getCode(), msg);
|
||||
}
|
||||
|
||||
public static <T> Response<T> error(T data) {
|
||||
return error(ResultEnum.ERROR.getCode(), ResultEnum.ERROR.getMsg(), data);
|
||||
}
|
||||
|
||||
public static <T> Response<T> error(int code, String msg) {
|
||||
return error(code, msg, null);
|
||||
}
|
||||
|
||||
public static <T> Response<T> error(int code, String msg, T data) {
|
||||
return getResponse(code, msg, data);
|
||||
}
|
||||
|
||||
private static <T> Response<T> getResponse(int code, String msg, T data){
|
||||
return new Response<>(code, msg, data);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
55
src/main/java/com/ai/da/common/response/ResultEnum.java
Normal file
55
src/main/java/com/ai/da/common/response/ResultEnum.java
Normal file
@@ -0,0 +1,55 @@
|
||||
package com.ai.da.common.response;
|
||||
|
||||
/**
|
||||
* @ClassName ResultEnum
|
||||
* @Description 响应结果枚举
|
||||
* @Author dwjian
|
||||
* @Date 2019/9/8 21:58
|
||||
*/
|
||||
public enum ResultEnum {
|
||||
|
||||
SUCCESS(true, 0, "SUCCESS"),
|
||||
FAIL(false, -1, "FAIL"),
|
||||
ERROR(false, -1, "system error!"),
|
||||
PARAMETER_ERROR(false, -2, "parameter error!"),
|
||||
|
||||
NO_LOGIN(false,-100,"User not logged in"),
|
||||
NO_PERMISSION(false,-200,"No access"),
|
||||
ACCOUNT_LOCK(false,-300,"Account frozen");
|
||||
|
||||
private int code;
|
||||
private String msg;
|
||||
private boolean isOK;
|
||||
|
||||
|
||||
|
||||
ResultEnum(boolean isOK, int code, String msg){
|
||||
this.isOK = isOK;
|
||||
this.code = code;
|
||||
this.msg = msg;
|
||||
}
|
||||
|
||||
public int getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
public void setCode(int code) {
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
public String getMsg() {
|
||||
return msg;
|
||||
}
|
||||
|
||||
public void setMsg(String msg) {
|
||||
this.msg = msg;
|
||||
}
|
||||
|
||||
public boolean isOK() {
|
||||
return isOK;
|
||||
}
|
||||
|
||||
public void setOK(boolean OK) {
|
||||
isOK = OK;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user