yanlong 8 meses atrás
pai
commit
e088709ed8

+ 30 - 0
src/main/java/com/tuigai/tuigai_tongcheng_api/controller/OrderController.java

@@ -0,0 +1,30 @@
+package com.tuigai.tuigai_tongcheng_api.controller;
+
+import com.alibaba.fastjson.JSONObject;
+import com.tuigai.tuigai_tongcheng_api.dto.RestMessage;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+@RestController
+@RequestMapping("/order")
+@Slf4j
+public class OrderController {
+
+
+    @PostMapping("/saveChangeOrder")
+    public RestMessage saveChangeOrder(@RequestBody JSONObject jsonObject) {
+        log.info("改签订单:" + jsonObject.toJSONString());
+        return RestMessage.result("ok");
+    }
+
+
+    @PostMapping("/saveRefundOrder")
+    public RestMessage saveRefundOrder(@RequestBody JSONObject jsonObject) {
+        log.info("退票订单:" + jsonObject.toJSONString());
+        return RestMessage.result("ok");
+    }
+
+}

+ 112 - 0
src/main/java/com/tuigai/tuigai_tongcheng_api/dto/RestMessage.java

@@ -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;
+        }
+    }
+}

+ 26 - 0
src/main/java/com/tuigai/tuigai_tongcheng_api/dto/RestStatusCode.java

@@ -0,0 +1,26 @@
+package com.tuigai.tuigai_tongcheng_api.dto;
+
+public enum RestStatusCode {
+    //成功
+    SUCCESS(200),
+    //鉴权失败
+    AUTH_FAILED(201),
+    //参数错误
+    PARAM_FAILED(202),
+    //账户错误
+    ACCOUNT_FAILED(203),
+    //系统错误
+    SYS_ERROR(500),
+    //业务错误
+    BUSINESS_ERROR(204),
+
+    TIME_OUT(408);
+    int code;
+    RestStatusCode(int code){
+        this.code = code;
+    }
+
+    public int getCode() {
+        return code;
+    }
+}