|
@@ -0,0 +1,112 @@
|
|
|
+package com.tuigai.tuigai_tongcheng_api.dto;
|
|
|
+
|
|
|
+import com.fasterxml.jackson.annotation.JsonInclude;
|
|
|
+
|
|
|
+import java.io.Serializable;
|
|
|
+import java.util.Collection;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+/**
|
|
|
+ * Created by longtc on 2019/12/10.
|
|
|
+ */
|
|
|
+public class RestMessage implements Serializable {
|
|
|
+
|
|
|
+ public int status;
|
|
|
+ public String message;
|
|
|
+
|
|
|
+ public Object result;
|
|
|
+
|
|
|
+ public RestMessage() {
|
|
|
+ this(200, "ok");
|
|
|
+ }
|
|
|
+
|
|
|
+ public RestMessage(Object result) {
|
|
|
+ this(200, "ok", result);
|
|
|
+ }
|
|
|
+
|
|
|
+ public RestMessage(int status, String message) {
|
|
|
+ this(status, message, null);
|
|
|
+ }
|
|
|
+
|
|
|
+ public RestMessage(int status, String message, Object result) {
|
|
|
+ this.status = status;
|
|
|
+ this.message = message;
|
|
|
+ this.result = result;
|
|
|
+ }
|
|
|
+
|
|
|
+ public static RestMessage collectionResult(List<?> data) {
|
|
|
+ return collectionResult(0, data);
|
|
|
+ }
|
|
|
+
|
|
|
+ public static RestMessage collectionResult(long total, Collection<?> data) {
|
|
|
+ return new RestMessage(new CollectionBody((total <= 0 ? 0 : total), data));
|
|
|
+ }
|
|
|
+
|
|
|
+ public static <T> RestMessage collectionResult(long total, Collection<?> data,T t) {
|
|
|
+ return new RestMessage(new CollectionBody((total <= 0 ? 0 : total), data,t));
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 登录验证调用,401前端跳转登录页面,其他错误请不要调用此方法
|
|
|
+ * @param message
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public static RestMessage fail401(String message){
|
|
|
+ return new RestMessage(401,message);
|
|
|
+ }
|
|
|
+ public static RestMessage result(Object result) {
|
|
|
+ Class cls = result.getClass();
|
|
|
+ String name = cls.getName();
|
|
|
+ if (name.endsWith("byte")
|
|
|
+ || name.endsWith("Byte")
|
|
|
+ || name.endsWith("short")
|
|
|
+ || name.endsWith("Short")
|
|
|
+ || name.endsWith("int")
|
|
|
+ || name.endsWith("Integer")
|
|
|
+ || name.endsWith("float")
|
|
|
+ || name.endsWith("Float")
|
|
|
+ || name.endsWith("long")
|
|
|
+ || name.endsWith("Long")
|
|
|
+ || name.endsWith("double")
|
|
|
+ || name.endsWith("Double")
|
|
|
+ || name.endsWith("boolean")
|
|
|
+ || name.endsWith("Boolean")
|
|
|
+ || name.endsWith("String")) {
|
|
|
+ return new RestMessage(new WrapBody(result));
|
|
|
+ } else {
|
|
|
+ return new RestMessage(result);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @JsonInclude(JsonInclude.Include.NON_NULL)
|
|
|
+ public static class CollectionBody<T> implements Serializable {
|
|
|
+
|
|
|
+
|
|
|
+ public CollectionBody(long total, Collection<?> data) {
|
|
|
+ this.total = total;
|
|
|
+ this.data = data;
|
|
|
+ }
|
|
|
+
|
|
|
+ public CollectionBody(long total, Collection<?> data,T t) {
|
|
|
+ this.total = total;
|
|
|
+ this.data = data;
|
|
|
+ this.extend = t;
|
|
|
+ }
|
|
|
+
|
|
|
+ public long total;
|
|
|
+
|
|
|
+ public T extend;
|
|
|
+
|
|
|
+ public Collection<?> data;
|
|
|
+ }
|
|
|
+
|
|
|
+ @JsonInclude(JsonInclude.Include.NON_NULL)
|
|
|
+ public static class WrapBody implements Serializable {
|
|
|
+
|
|
|
+ public Object result;
|
|
|
+
|
|
|
+ public WrapBody(Object result) {
|
|
|
+ this.result = result;
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|