feat:[REQ-3282] 追加rpc wrapper 的能力
This commit is contained in:
parent
fd4d7a63b2
commit
87a84fcd14
@ -2,7 +2,9 @@ package cn.axzo.orgmanax.integration.core;
|
||||
|
||||
import cn.axzo.apollo.core.web.Result;
|
||||
import cn.axzo.foundation.exception.BusinessException;
|
||||
import cn.axzo.framework.domain.web.result.ApiResult;
|
||||
import cn.axzo.orgmanax.common.config.BizResultCode;
|
||||
import cn.azxo.framework.common.model.CommonResponse;
|
||||
import cn.hutool.core.convert.Convert;
|
||||
import cn.hutool.http.HttpStatus;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
@ -29,4 +31,38 @@ public class RpcWrapper {
|
||||
}
|
||||
return result.getData();
|
||||
}
|
||||
|
||||
/**
|
||||
* common res 返回
|
||||
* @param t
|
||||
* @return
|
||||
* @param <T>
|
||||
*/
|
||||
public static <T> T commonRes(Supplier<CommonResponse<T>> t) {
|
||||
CommonResponse<T> result = t.get();
|
||||
if (result == null) {
|
||||
throw new BusinessException(BizResultCode.RPC_ERROR);
|
||||
}
|
||||
if (!Objects.equals(result.getCode(), HttpStatus.HTTP_OK)) {
|
||||
throw new BusinessException(Convert.toStr(result.getCode()), result.getMsg(), null);
|
||||
}
|
||||
return result.getData();
|
||||
}
|
||||
|
||||
/**
|
||||
* Api result 返回
|
||||
* @param supplier
|
||||
* @return
|
||||
* @param <T>
|
||||
*/
|
||||
protected <T> T wrapApiResult(Supplier<ApiResult<T>> supplier) {
|
||||
ApiResult<T> result = supplier.get();
|
||||
if (result == null) {
|
||||
throw new BusinessException(BizResultCode.RPC_ERROR);
|
||||
}
|
||||
if (!Objects.equals(result.getCode(), HttpStatus.HTTP_OK)) {
|
||||
throw new BusinessException(Convert.toStr(result.getCode()), result.getMsg(), null);
|
||||
}
|
||||
return result.getData();
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user