|
@@ -2,10 +2,8 @@ package com.persagy.dmp.common.utils;
|
|
|
|
|
|
|
|
|
import cn.hutool.core.collection.CollUtil;
|
|
|
-import com.persagy.dmp.common.constant.ResponseCode;
|
|
|
import com.persagy.dmp.common.exception.BusinessException;
|
|
|
import com.persagy.dmp.common.model.response.CommonResult;
|
|
|
-import com.persagy.dmp.common.model.response.PageList;
|
|
|
|
|
|
import java.util.List;
|
|
|
|
|
@@ -16,12 +14,18 @@ import java.util.List;
|
|
|
*/
|
|
|
public class ResultHelper {
|
|
|
|
|
|
+ /** 成功 */
|
|
|
+ private static final String SUCCESS = "success";
|
|
|
+ /** 失败 */
|
|
|
+ private static final String FAIL = "fail";
|
|
|
+
|
|
|
/**
|
|
|
* 成功消息
|
|
|
* @return
|
|
|
*/
|
|
|
public static CommonResult success(){
|
|
|
- return new CommonResult(ResponseCode.A00000.getCode(), ResponseCode.A00000.getDesc());
|
|
|
+// return new CommonResult(ResponseCode.A00000.getCode(), ResponseCode.A00000.getDesc());
|
|
|
+ return success(null);
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -29,7 +33,17 @@ public class ResultHelper {
|
|
|
* @return
|
|
|
*/
|
|
|
public static CommonResult success(String respMsg){
|
|
|
- return new CommonResult(ResponseCode.A00000.getCode(), respMsg);
|
|
|
+// return new CommonResult(ResponseCode.A00000.getCode(), respMsg);
|
|
|
+ return new CommonResult(SUCCESS, respMsg);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 失败消息
|
|
|
+ * @param respMsg
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public static CommonResult failure(String respMsg) {
|
|
|
+ return failure(FAIL, respMsg);
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -49,7 +63,7 @@ public class ResultHelper {
|
|
|
* @return
|
|
|
*/
|
|
|
public static <T> CommonResult<T> single(T content) {
|
|
|
- return new CommonResult(ResponseCode.A00000.getCode(), ResponseCode.A00000.getDesc(), content);
|
|
|
+ return single(content, null);
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -59,7 +73,8 @@ public class ResultHelper {
|
|
|
* @return
|
|
|
*/
|
|
|
public static <T> CommonResult<T> single(T content, String desc) {
|
|
|
- return new CommonResult(ResponseCode.A00000.getCode(), desc, content);
|
|
|
+// return new CommonResult(ResponseCode.A00000.getCode(), desc, content);
|
|
|
+ return new CommonResult(SUCCESS, desc, content);
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -68,7 +83,7 @@ public class ResultHelper {
|
|
|
* @param <T>
|
|
|
* @return
|
|
|
*/
|
|
|
- public static <T> CommonResult<PageList<T>> multi(List<T> records) {
|
|
|
+ public static <T> CommonResult<List<T>> multi(List<T> records) {
|
|
|
return multi(records, CollUtil.size(records));
|
|
|
}
|
|
|
|
|
@@ -91,14 +106,18 @@ public class ResultHelper {
|
|
|
* @param <T>
|
|
|
* @return
|
|
|
*/
|
|
|
- public static <T> CommonResult<PageList<T>> multi(List<T> records, long total) {
|
|
|
+ public static <T> CommonResult<List<T>> multi(List<T> records, long total) {
|
|
|
// 容错处理,出现总数比实际数少时,以实际数为准(page查询全部时,total为0)
|
|
|
int size = CollUtil.size(records);
|
|
|
if(total < CollUtil.size(records)) {
|
|
|
total = size;
|
|
|
}
|
|
|
- PageList<T> pageList = new PageList<>(records, total);
|
|
|
- return new CommonResult(ResponseCode.A00000.getCode(), ResponseCode.A00000.getDesc(), pageList);
|
|
|
+ CommonResult result = success();
|
|
|
+ result.setData(records);
|
|
|
+ result.setCount(total);
|
|
|
+ return result;
|
|
|
+// PageList<T> pageList = new PageList<>(records, total);
|
|
|
+// return new CommonResult(ResponseCode.A00000.getCode(), ResponseCode.A00000.getDesc(), pageList);
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -108,9 +127,13 @@ public class ResultHelper {
|
|
|
* @return 对应的结果
|
|
|
*/
|
|
|
public static <T> T getContent(CommonResult<T> result) {
|
|
|
- if(!ResponseCode.A00000.getCode().equals(result.getRespCode())) {
|
|
|
- throw new BusinessException(result.getRespCode(), result.getRespMsg());
|
|
|
+// if(!ResponseCode.A00000.getCode().equals(result.getRespCode())) {
|
|
|
+// throw new BusinessException(result.getRespCode(), result.getRespMsg());
|
|
|
+// }
|
|
|
+// return result.getContent();
|
|
|
+ if(!SUCCESS.equals(result.getResult())) {
|
|
|
+ throw new BusinessException(result.getResult(), result.getMessage());
|
|
|
}
|
|
|
- return result.getContent();
|
|
|
+ return result.getData();
|
|
|
}
|
|
|
}
|