一. 架构设计
简单明了,没啥好说的
二. 代码分析
方法也不多,就一个判断权限的方法需要分析。
即 findWhoIAm 方法
代码如下
public IAmDto findWhoIAm(String userId) {
IAmDto iAmDto = IAmDto.builder()
.userId(userId)
.build();
GetWorkerOfResponse workerOfResponse = null;
try {
workerOfResponse = companyClient.getWorkerOf(AuthConstant.AUTHORIZATION_WHOAMI_SERVICE, userId);
} catch (Exception ex) {
String errMsg = "unable to get worker of list";
handleErrorAndThrowException(ex, errMsg);
}
if (!workerOfResponse.isSuccess()) {
handleErrorAndThrowException(workerOfResponse.getMessage());
}
WorkerOfList workerOfList = workerOfResponse.getWorkerOfList();
iAmDto.setWorkerOfList(workerOfList);
GetAdminOfResponse getAdminOfResponse = null;
try {
getAdminOfResponse = companyClient.getAdminOf(AuthConstant.AUTHORIZATION_WHOAMI_SERVICE, userId);
} catch (Exception ex) {
String errMsg = "unable to get admin of list";
handleErrorAndThrowException(ex, errMsg);
}
if (!getAdminOfResponse.isSuccess()) {
handleErrorAndThrowException(getAdminOfResponse.getMessage());
}
AdminOfList adminOfList = getAdminOfResponse.getAdminOfList();
iAmDto.setAdminOfList(adminOfList);
return iAmDto;
}
逻辑也不复杂
通过传入的 userId 生成 IAmDto 对象
再用 userId 从 CompanyClient 中找到 worker 对象
将 worker 对象嵌入 IAmDto 中
再用相同方法处理 admin 对象
然后将 IAmDto 返回
还有个 Intercom 方法 ,但属于第三方插件,不是关键,不分析。