diff --git a/ebike-staff/src/main/java/com/cdzy/staff/component/EbikeTenantFactory.java b/ebike-staff/src/main/java/com/cdzy/staff/component/EbikeTenantFactory.java index 244bcb3..cddbc6e 100644 --- a/ebike-staff/src/main/java/com/cdzy/staff/component/EbikeTenantFactory.java +++ b/ebike-staff/src/main/java/com/cdzy/staff/component/EbikeTenantFactory.java @@ -16,35 +16,43 @@ import java.util.TimeZone; public class EbikeTenantFactory implements TenantFactory { public Object[] getTenantIds() { - if (StpUtil.isLogin()) { - RequestAttributes attributes = RequestContextHolder.getRequestAttributes(); - Object attribute = attributes.getAttribute("tenantId", RequestAttributes.SCOPE_REQUEST); - if (attribute != null) { - String id = (String) StpUtil.getLoginId(); - Object object = StpUtil.getSessionByLoginId(id).get(id); - ObjectMapper objectMapper = new ObjectMapper() - .registerModule(new JavaTimeModule()) - .disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS) - .setTimeZone(TimeZone.getTimeZone("Asia/Shanghai")); - CommonStaffInfo staffInfo = objectMapper.convertValue(object, CommonStaffInfo.class); - List roles = staffInfo.getRoles(); - boolean isSysAdmin = false; - for (CommonEbikeRole role : roles) { - if (role.getSysAdmin()) { - isSysAdmin = true; - break; + try { + if (StpUtil.isLogin()) { + RequestAttributes attributes = RequestContextHolder.getRequestAttributes(); + if (attributes != null) { + Object attribute = attributes.getAttribute("tenantId", RequestAttributes.SCOPE_REQUEST); + String id = (String) StpUtil.getLoginId(); + Object object = StpUtil.getSessionByLoginId(id).get(id); + ObjectMapper objectMapper = new ObjectMapper() + .registerModule(new JavaTimeModule()) + .disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS) + .setTimeZone(TimeZone.getTimeZone("Asia/Shanghai")); + CommonStaffInfo staffInfo = objectMapper.convertValue(object, CommonStaffInfo.class); + List roles = staffInfo.getRoles(); + boolean isSysAdmin = false; + for (CommonEbikeRole role : roles) { + if (role.getSysAdmin()) { + isSysAdmin = true; + break; + } + } + long tenantId = 0; + if (attribute != null) { + tenantId = Long.parseLong(attribute.toString()); + } + //系统管理员 + if (isSysAdmin) { + return null; + } else { + return new Object[]{tenantId}; } } - long tenantId = Long.parseLong(attribute.toString()); - //系统管理员 - if (isSysAdmin) { - return null; - } else { - return new Object[]{tenantId}; - } - } + } + return null; + } catch (Exception e) { + return null; } - return null; + } } \ No newline at end of file