|
|
@@ -0,0 +1,88 @@
|
|
|
+package com.github.microservice.http;
|
|
|
+
|
|
|
+import cn.hutool.json.JSONObject;
|
|
|
+import cn.hutool.json.JSONUtil;
|
|
|
+import io.swagger.v3.oas.annotations.media.Schema;
|
|
|
+import lombok.AllArgsConstructor;
|
|
|
+import lombok.Data;
|
|
|
+import lombok.NoArgsConstructor;
|
|
|
+import org.apache.commons.lang3.ObjectUtils;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @author TRX
|
|
|
+ * @date 2024/6/25
|
|
|
+ */
|
|
|
+@Data
|
|
|
+@AllArgsConstructor
|
|
|
+@NoArgsConstructor
|
|
|
+public class APIResponseModel {
|
|
|
+
|
|
|
+ @Schema(description = "是否错误")
|
|
|
+ private boolean failed;
|
|
|
+
|
|
|
+ @Schema(description = "是否成功")
|
|
|
+ private boolean success;
|
|
|
+
|
|
|
+ @Schema(description = "返回消息")
|
|
|
+ private String msg;
|
|
|
+
|
|
|
+ private String state;
|
|
|
+
|
|
|
+ private String content;
|
|
|
+
|
|
|
+ @Schema(description = "访问的URL")
|
|
|
+ private Object param;
|
|
|
+
|
|
|
+ @Schema(description = "请求数据")
|
|
|
+ private Object data;
|
|
|
+
|
|
|
+ public void setRequestData(Object data) {
|
|
|
+ this.data = data;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Schema(description = "请求耗时:毫秒")
|
|
|
+ private Long millis;
|
|
|
+
|
|
|
+ public <T> T toBean(Class<T> tClass) {
|
|
|
+ if (content != null) {
|
|
|
+ return JSONUtil.toBean(content, tClass);
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ public JSONObject toJson() {
|
|
|
+ if (content != null) {
|
|
|
+ return JSONUtil.parseObj(content);
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ public boolean isSuccess() {
|
|
|
+ if (StringUtils.isNotEmpty(this.state) && "Fail".equals(state)) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ return success;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void setIsSuccess() {
|
|
|
+ this.success = Boolean.TRUE;
|
|
|
+ this.failed = Boolean.FALSE;
|
|
|
+ this.state = "success";
|
|
|
+ }
|
|
|
+
|
|
|
+ public boolean isFailed() {
|
|
|
+ return !this.isSuccess();
|
|
|
+ }
|
|
|
+
|
|
|
+ public void setIsFailed() {
|
|
|
+ this.success = Boolean.FALSE;
|
|
|
+ this.failed = Boolean.TRUE;
|
|
|
+ this.state = "Fail";
|
|
|
+ }
|
|
|
+
|
|
|
+ public void setIsFailed(String msg) {
|
|
|
+ this.setIsFailed();
|
|
|
+ this.msg = msg;
|
|
|
+ }
|
|
|
+}
|