|
@@ -0,0 +1,86 @@
|
|
|
+package com.abi.platform.Base;
|
|
|
+
|
|
|
+import com.abi.platform.enums.ErrorCodeEnum;
|
|
|
+import io.swagger.annotations.ApiModel;
|
|
|
+import io.swagger.annotations.ApiModelProperty;
|
|
|
+import lombok.Data;
|
|
|
+import lombok.ToString;
|
|
|
+
|
|
|
+import java.io.Serializable;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 公共返回类
|
|
|
+ *
|
|
|
+ * @param <T>
|
|
|
+ */
|
|
|
+@Data
|
|
|
+@ToString
|
|
|
+@ApiModel(value = "公共返回类")
|
|
|
+public class BaseResponse<T extends Object> implements Serializable {
|
|
|
+
|
|
|
+ private static final long serialVersionUID = 4192965340654225152L;
|
|
|
+
|
|
|
+ private static final Integer SUCCESS = 200;
|
|
|
+ private static final Integer FAIL = 999;
|
|
|
+
|
|
|
+ @ApiModelProperty(value = "返回码: 0000成功, 其他失败")
|
|
|
+ private Integer code;
|
|
|
+
|
|
|
+ @ApiModelProperty(value = "错误信息")
|
|
|
+ private String message;
|
|
|
+
|
|
|
+ @ApiModelProperty(value = "返回内容")
|
|
|
+ private T data;
|
|
|
+
|
|
|
+ @ApiModelProperty(value = "当前时间戳")
|
|
|
+ private Long timeStamp;
|
|
|
+
|
|
|
+ public BaseResponse() {
|
|
|
+ this.timeStamp = System.currentTimeMillis();
|
|
|
+ }
|
|
|
+
|
|
|
+ public BaseResponse(T data) {
|
|
|
+ this(SUCCESS, data);
|
|
|
+ }
|
|
|
+
|
|
|
+ public BaseResponse(Integer code, T data) {
|
|
|
+ this(code, null, data);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public BaseResponse(Integer code, String message, T data) {
|
|
|
+ this(code, message, data, System.currentTimeMillis());
|
|
|
+ }
|
|
|
+
|
|
|
+ public BaseResponse(Integer code, String message, T data, Long timeStamp) {
|
|
|
+ this.code = code;
|
|
|
+ this.message = message;
|
|
|
+ this.data = data;
|
|
|
+ this.timeStamp = timeStamp;
|
|
|
+ }
|
|
|
+
|
|
|
+ public static BaseResponse create() {
|
|
|
+ return new BaseResponse(null);
|
|
|
+ }
|
|
|
+
|
|
|
+ public static <T extends Object> BaseResponse<T> create(T t) {
|
|
|
+ return new BaseResponse(t);
|
|
|
+ }
|
|
|
+
|
|
|
+ public static <T extends Object> BaseResponse<T> create(T t, Integer code, String msg) {
|
|
|
+ return new BaseResponse(code, msg, t);
|
|
|
+ }
|
|
|
+
|
|
|
+ public static <T extends Object> BaseResponse<T> createFail(T t, ErrorCodeEnum errorCodeEnum) {
|
|
|
+ return new BaseResponse(FAIL, errorCodeEnum.getMessage(), t);
|
|
|
+ }
|
|
|
+
|
|
|
+ public static <T extends Object> BaseResponse<T> createFail(T t, String msg) {
|
|
|
+ return new BaseResponse(FAIL, msg, t);
|
|
|
+ }
|
|
|
+
|
|
|
+ public static <T extends Object> BaseResponse<T> createFail(T t, Integer code, String msg) {
|
|
|
+ return new BaseResponse(code, msg, t);
|
|
|
+ }
|
|
|
+
|
|
|
+}
|