feat:[REQ-3282] 编写调用二方SDK的demo
This commit is contained in:
parent
0a914876ef
commit
01ebd01ab0
@ -4,7 +4,7 @@ import cn.axzo.apollo.api.ApolloGroupTaskOrderApi;
|
|||||||
import cn.axzo.apollo.api.res.CheckWorkerIsFinishGroupRes;
|
import cn.axzo.apollo.api.res.CheckWorkerIsFinishGroupRes;
|
||||||
import cn.axzo.orgmanax.infra.client.apollo.ApolloGroupTaskOrderClient;
|
import cn.axzo.orgmanax.infra.client.apollo.ApolloGroupTaskOrderClient;
|
||||||
import cn.axzo.orgmanax.infra.client.apollo.dto.CheckProjectTeamWorkerIsFinishGroupTaskResp;
|
import cn.axzo.orgmanax.infra.client.apollo.dto.CheckProjectTeamWorkerIsFinishGroupTaskResp;
|
||||||
import cn.axzo.orgmanax.integration.core.RpcUtils;
|
import cn.axzo.orgmanax.integration.core.RpcWrapper;
|
||||||
import cn.hutool.core.bean.BeanUtil;
|
import cn.hutool.core.bean.BeanUtil;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
@ -22,7 +22,7 @@ public class ApolloGroupTaskOrderClientImpl implements ApolloGroupTaskOrderClien
|
|||||||
* @return 任务单详情
|
* @return 任务单详情
|
||||||
*/
|
*/
|
||||||
public List<CheckProjectTeamWorkerIsFinishGroupTaskResp> checkProjectTeamWorkerIsFinishGroupTask(Long projectTeamId, List<Long> workerIds) {
|
public List<CheckProjectTeamWorkerIsFinishGroupTaskResp> checkProjectTeamWorkerIsFinishGroupTask(Long projectTeamId, List<Long> workerIds) {
|
||||||
List<CheckWorkerIsFinishGroupRes> result = RpcUtils.getResult(groupTaskOrderApi.checkProjectTeamWorkerIsFinishGroupTask(projectTeamId, workerIds));
|
List<CheckWorkerIsFinishGroupRes> result = RpcWrapper.wrapApolloResult(() -> groupTaskOrderApi.checkProjectTeamWorkerIsFinishGroupTask(projectTeamId, workerIds));
|
||||||
return BeanUtil.copyToList(result, CheckProjectTeamWorkerIsFinishGroupTaskResp.class);
|
return BeanUtil.copyToList(result, CheckProjectTeamWorkerIsFinishGroupTaskResp.class);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,44 +0,0 @@
|
|||||||
package cn.axzo.orgmanax.integration.core;
|
|
||||||
|
|
||||||
import cn.axzo.foundation.exception.BusinessException;
|
|
||||||
import cn.axzo.framework.domain.web.BizException;
|
|
||||||
import cn.axzo.framework.domain.web.result.ApiListResult;
|
|
||||||
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 java.util.List;
|
|
||||||
import java.util.Objects;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* rpc调用结果封装
|
|
||||||
*/
|
|
||||||
public class RpcUtils {
|
|
||||||
|
|
||||||
|
|
||||||
public static <T> T getResult(CommonResponse<T> result) {
|
|
||||||
return getResult(result, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static <T> T getResult(CommonResponse<T> result, Boolean throwException) {
|
|
||||||
if (result == null) {
|
|
||||||
throw new BusinessException(BizResultCode.RPC_ERROR);
|
|
||||||
}
|
|
||||||
if (!Objects.equals(Convert.toStr(result.getCode()), BizResultCode.SUCCESS.getErrorCode()) && Boolean.TRUE.equals(throwException)) {
|
|
||||||
throw new BusinessException(Convert.toStr(result.getCode(), null), result.getMsg(), null);
|
|
||||||
}
|
|
||||||
return result.getData();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public static <T> T getResult(cn.axzo.apollo.core.web.Result<T> result) {
|
|
||||||
if (result == null) {
|
|
||||||
throw new BusinessException(BizResultCode.RPC_ERROR);
|
|
||||||
}
|
|
||||||
if (!Objects.equals(Convert.toStr(result.getCode()), BizResultCode.SUCCESS.getErrorCode())) {
|
|
||||||
throw new BusinessException(Convert.toStr(result.getCode()), result.getMsg(), null);
|
|
||||||
}
|
|
||||||
return result.getData();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -0,0 +1,32 @@
|
|||||||
|
package cn.axzo.orgmanax.integration.core;
|
||||||
|
|
||||||
|
import cn.axzo.apollo.core.web.Result;
|
||||||
|
import cn.axzo.foundation.exception.BusinessException;
|
||||||
|
import cn.axzo.orgmanax.common.config.BizResultCode;
|
||||||
|
import cn.hutool.core.convert.Convert;
|
||||||
|
import cn.hutool.http.HttpStatus;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
|
public class RpcWrapper {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* apollo 包使用
|
||||||
|
* @param supplier
|
||||||
|
* @return
|
||||||
|
* @param <T>
|
||||||
|
*/
|
||||||
|
public static <T> T wrapApolloResult(Supplier<Result<T>> supplier) {
|
||||||
|
Result<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