fix(sync): 兼容用户离职无法查到用户
This commit is contained in:
parent
a2ceff5fcd
commit
215b3de5ff
@ -52,7 +52,11 @@ public class DingTalkUserAddEventHandler implements DingTalkEventHandler {
|
||||
}
|
||||
//获取用户详情后进行处理
|
||||
ThirdPartyUserDTO dto = thirdPartySyncProcessService.getUserById(context, userId);
|
||||
processService.handleNewUser(context, dto);
|
||||
if (dto == null) {
|
||||
log.error("no dingtalk user found in add event, userId:{}", userId);
|
||||
} else {
|
||||
processService.handleNewUser(context, dto);
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
log.error("handle DingTalk user add event error", ex);
|
||||
} finally {
|
||||
|
||||
@ -52,7 +52,11 @@ public class DingTalkUserModifyEventHandler implements DingTalkEventHandler {
|
||||
}
|
||||
//获取用户详情后进行处理
|
||||
ThirdPartyUserDTO dto = thirdPartySyncProcessService.getUserById(context, userId);
|
||||
processService.handleUserModify(context, dto);
|
||||
if (dto == null) {
|
||||
log.warn("no dingtalk user found in modify event, userId:{}", userId);
|
||||
} else {
|
||||
processService.handleUserModify(context, dto);
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
log.error("handle DingTalk user modify event error", ex);
|
||||
} finally {
|
||||
|
||||
@ -29,6 +29,7 @@ import com.dingtalk.api.response.OapiV2DepartmentListsubidResponse;
|
||||
import com.dingtalk.api.response.OapiV2UserGetResponse;
|
||||
import com.dingtalk.api.response.OapiV2UserListResponse;
|
||||
import com.taobao.api.ApiException;
|
||||
import com.taobao.api.internal.util.TaobaoLogger;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@ -57,6 +58,11 @@ public class DingTalkSyncApiService implements ThirdPartySyncApiService {
|
||||
public static final String URL_GET_DEPT = "https://oapi.dingtalk.com/topapi/v2/department/get";
|
||||
public static final String URL_LIST_DEPT_USER_ID = "https://oapi.dingtalk.com/topapi/user/listid";
|
||||
|
||||
{
|
||||
//关闭API自带的请求日志记录 - 防止打印ERROR日志触发报警
|
||||
TaobaoLogger.setNeedEnableLogger(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ThirdPartyAccessToken getAccessToken(ThirdPartyCredential credential) {
|
||||
DingTalkClient client = new DefaultDingTalkClient(URL_GET_TOKEN);
|
||||
@ -175,6 +181,10 @@ public class DingTalkSyncApiService implements ThirdPartySyncApiService {
|
||||
userDTO.setTitle(user.getTitle());
|
||||
userDTO.setManagerId(user.getManagerUserid());
|
||||
return userDTO;
|
||||
} else if (response.getErrcode().equals(60121L)) {
|
||||
//兼容用户已被删除
|
||||
log.warn("dingtalk user not found for:{}", userId);
|
||||
return null;
|
||||
} else {
|
||||
throw Throws.bizException(BaseCode.SERVER_ERROR, "获取钉钉用户信息失败");
|
||||
}
|
||||
|
||||
@ -113,6 +113,10 @@ public class ThirdPartySyncProcessServiceImpl implements ThirdPartySyncProcessSe
|
||||
ThreadUtil.safeSleep(200L);
|
||||
//循环同步用户
|
||||
ThirdPartyUserDTO userDTO = thirdPartyService.getUserById(context, userId);
|
||||
if (userDTO == null) {
|
||||
//用户已删除
|
||||
continue;
|
||||
}
|
||||
ThirdPartyUser user = this.convert2User(context, userDTO);
|
||||
userIdList.add(user.getUserId());
|
||||
user.setInnerDeptId(parentDept.getId());
|
||||
|
||||
Loading…
Reference in New Issue
Block a user