|
|
@@ -1,4 +1,3 @@
|
|
|
-// UnifiedApiRespDTO.java
|
|
|
package com.ruoyi.api.domain.dto;
|
|
|
|
|
|
import java.util.HashMap;
|
|
|
@@ -8,16 +7,16 @@ import java.util.Map;
|
|
|
* 统一API响应DTO
|
|
|
*/
|
|
|
public class UnifiedApiRespDTO {
|
|
|
-
|
|
|
+
|
|
|
private Integer code;
|
|
|
private String msg;
|
|
|
private Boolean success;
|
|
|
private Map<String, Object> data;
|
|
|
-
|
|
|
+
|
|
|
public UnifiedApiRespDTO() {
|
|
|
this.data = new HashMap<>();
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
public static UnifiedApiRespDTO success() {
|
|
|
UnifiedApiRespDTO response = new UnifiedApiRespDTO();
|
|
|
response.setCode(200);
|
|
|
@@ -25,7 +24,7 @@ public class UnifiedApiRespDTO {
|
|
|
response.setSuccess(true);
|
|
|
return response;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
public static UnifiedApiRespDTO success(String msg) {
|
|
|
UnifiedApiRespDTO response = new UnifiedApiRespDTO();
|
|
|
response.setCode(200);
|
|
|
@@ -33,7 +32,7 @@ public class UnifiedApiRespDTO {
|
|
|
response.setSuccess(true);
|
|
|
return response;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
public static UnifiedApiRespDTO success(String msg, Map<String, Object> data) {
|
|
|
UnifiedApiRespDTO response = new UnifiedApiRespDTO();
|
|
|
response.setCode(200);
|
|
|
@@ -42,7 +41,24 @@ public class UnifiedApiRespDTO {
|
|
|
response.setData(data);
|
|
|
return response;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
+ // 新增:支持直接传入单个业务对象,自动封装到data中(替代原setResponseResult)
|
|
|
+ public static UnifiedApiRespDTO success(String msg, Object data) {
|
|
|
+ UnifiedApiRespDTO response = new UnifiedApiRespDTO();
|
|
|
+ response.setCode(200);
|
|
|
+ response.setMsg(msg);
|
|
|
+ response.setSuccess(true);
|
|
|
+ if (data != null) {
|
|
|
+ // 如果是Map类型,直接赋值;否则作为默认key的value(可根据业务调整默认key)
|
|
|
+ if (data instanceof Map) {
|
|
|
+ response.setData((Map<String, Object>) data);
|
|
|
+ } else {
|
|
|
+ response.addData("result", data);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return response;
|
|
|
+ }
|
|
|
+
|
|
|
public static UnifiedApiRespDTO error(String msg) {
|
|
|
UnifiedApiRespDTO response = new UnifiedApiRespDTO();
|
|
|
response.setCode(500);
|
|
|
@@ -50,16 +66,11 @@ public class UnifiedApiRespDTO {
|
|
|
response.setSuccess(false);
|
|
|
return response;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
public UnifiedApiRespDTO addData(String key, Object value) {
|
|
|
this.data.put(key, value);
|
|
|
return this;
|
|
|
}
|
|
|
-
|
|
|
- public UnifiedApiRespDTO setResponseResult(Object result) {
|
|
|
- this.data.put("responseResult", result);
|
|
|
- return this;
|
|
|
- }
|
|
|
|
|
|
public Integer getCode() {
|
|
|
return code;
|