网络异常feign已熔断

This commit is contained in:
zhangqinbin
2021-12-08 16:35:08 +08:00
parent b27e5eea33
commit 164c034d4c

View File

@ -8,13 +8,19 @@ import com.chinaunicom.mall.ebtp.cloud.userinfo.starter.service.UserInfoService;
import com.chinaunicom.mall.ebtp.common.base.entity.BaseCacheUser; import com.chinaunicom.mall.ebtp.common.base.entity.BaseCacheUser;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.remoting.RemoteTimeoutException;
import org.springframework.security.access.AccessDeniedException;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Objects;
import java.util.Optional; import java.util.Optional;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import static com.chinaunicom.mall.ebtp.cloud.security.starter.common.Constants.REMOTE_ACCESS_FAILURE;
import static com.chinaunicom.mall.ebtp.cloud.security.starter.common.Constants.TOKEN_EXPIRED;
@Slf4j @Slf4j
@Service @Service
public class UserInfoServiceImpl implements UserInfoService { public class UserInfoServiceImpl implements UserInfoService {
@ -36,7 +42,13 @@ public class UserInfoServiceImpl implements UserInfoService {
*/ */
private BaseCacheUser convertToBusinessModel(SecurityEntity raw) { private BaseCacheUser convertToBusinessModel(SecurityEntity raw) {
log.debug("userinfo: {}", raw); log.debug("userinfo: {}", raw);
if (Objects.isNull(raw)) {// 对象为空, 则说明网络异常feign已熔断
throw new RemoteTimeoutException(REMOTE_ACCESS_FAILURE);
}
if (Objects.isNull(raw.getStaffId())) {// userid 为空则访问山分认证服务返回信息为null
throw new AccessDeniedException(TOKEN_EXPIRED);
}
BaseCacheUser user = new BaseCacheUser().setUserId(raw.getStaffId()).setFullName(raw.getStaffName()) BaseCacheUser user = new BaseCacheUser().setUserId(raw.getStaffId()).setFullName(raw.getStaffName())
.setLoginName(raw.getUsername()).setAuthorityList(filterByEBTP(raw.getAuthorityList())) .setLoginName(raw.getUsername()).setAuthorityList(filterByEBTP(raw.getAuthorityList()))
.setProvince(raw.getProvince()).setEmployeeNumber(raw.getExp()).setUserType(raw.getUserSource()); .setProvince(raw.getProvince()).setEmployeeNumber(raw.getExp()).setUserType(raw.getUserSource());