|
@@ -0,0 +1,91 @@
|
|
|
+package com.gyee.table.utils;
|
|
|
+import lombok.Data;
|
|
|
+
|
|
|
+import java.io.Serializable;
|
|
|
+import java.util.Collection;
|
|
|
+
|
|
|
+
|
|
|
+@Data
|
|
|
+public class ResponseWrapper<T> implements Serializable {
|
|
|
+ private static final long serialVersionUID = 1L;
|
|
|
+ private Boolean success;
|
|
|
+ private Integer status;
|
|
|
+ private Integer count;
|
|
|
+ private String msg;
|
|
|
+ private T data;
|
|
|
+ private static final int STATUS_SUCCESS = 20000;
|
|
|
+ private static final int STATUS_ERROR = 50000;
|
|
|
+ public static final int STATUS_ERROR_SYSTEM = 50100;
|
|
|
+
|
|
|
+ private String token;
|
|
|
+
|
|
|
+ public ResponseWrapper() {
|
|
|
+ }
|
|
|
+
|
|
|
+ private ResponseWrapper(Boolean success, Integer status, Integer count, String msg, Class entityType, T data) {
|
|
|
+ this.success = success;
|
|
|
+ this.status = status;
|
|
|
+ this.count = count;
|
|
|
+ this.msg = msg;
|
|
|
+ this.data = data;
|
|
|
+ }
|
|
|
+
|
|
|
+ private ResponseWrapper(Boolean success, Integer status, Integer count, String msg, T data) {
|
|
|
+ this.success = success;
|
|
|
+ this.status = status;
|
|
|
+ this.count = count;
|
|
|
+ this.msg = msg;
|
|
|
+ this.data = data;
|
|
|
+ }
|
|
|
+
|
|
|
+ public static ResponseWrapper success(int count, String msg, Object data) {
|
|
|
+ if (data != null) {
|
|
|
+ return data instanceof Collection ? new ResponseWrapper(true, 20000, ((Collection)data).size(), msg, data) : new ResponseWrapper(true, 20000, count, msg, data);
|
|
|
+ } else {
|
|
|
+ return count == -1 ? new ResponseWrapper(true, 20000, -1, msg, msg) : new ResponseWrapper(true, 20000, count, msg, count);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public static ResponseWrapper success(String msg, int count, Object data) {
|
|
|
+ return new ResponseWrapper(true, 20000, count, msg, data);
|
|
|
+ }
|
|
|
+
|
|
|
+ public static ResponseWrapper success(int count, String msg) {
|
|
|
+ return success(count, msg, (Object)null);
|
|
|
+ }
|
|
|
+
|
|
|
+ public static ResponseWrapper success(int count) {
|
|
|
+ return success(count, "count");
|
|
|
+ }
|
|
|
+
|
|
|
+ public static ResponseWrapper success(String msg) {
|
|
|
+ return success(-1, msg);
|
|
|
+ }
|
|
|
+
|
|
|
+ public ResponseWrapper<T> success(T data) {
|
|
|
+ this.data = data;
|
|
|
+ return this;
|
|
|
+ }
|
|
|
+
|
|
|
+ public static ResponseWrapper success(String msg, Object data) {
|
|
|
+ return success(1, msg, data);
|
|
|
+ }
|
|
|
+
|
|
|
+ public static ResponseWrapper error(String msg, Object data, int status) {
|
|
|
+ return new ResponseWrapper(false, status, 0, msg, data.getClass(), data);
|
|
|
+ }
|
|
|
+
|
|
|
+ public static ResponseWrapper error(String msg, Object data) {
|
|
|
+ return new ResponseWrapper(false, 50000, 0, msg, data.getClass(), data);
|
|
|
+ }
|
|
|
+
|
|
|
+ public static ResponseWrapper error(String msg, int status) {
|
|
|
+ return new ResponseWrapper(false, status, -1, msg, String.class, msg);
|
|
|
+ }
|
|
|
+
|
|
|
+ public static ResponseWrapper error(String msg) {
|
|
|
+ return error(msg, 50000);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+}
|