|
@@ -6,16 +6,15 @@ import cn.hfln.framework.redis.util.RedisUtil;
|
|
import com.alibaba.fastjson2.JSONArray;
|
|
import com.alibaba.fastjson2.JSONArray;
|
|
import com.hfln.portal.common.constant.UserConstants;
|
|
import com.hfln.portal.common.constant.UserConstants;
|
|
import com.hfln.portal.common.constant.redis.RedisCacheConstant;
|
|
import com.hfln.portal.common.constant.redis.RedisCacheConstant;
|
|
-import com.hfln.portal.infrastructure.po.TblRole;
|
|
|
|
-import com.hfln.portal.infrastructure.po.TblRoleMenuMap;
|
|
|
|
-import com.hfln.portal.infrastructure.po.TblSystemMenu;
|
|
|
|
-import com.hfln.portal.infrastructure.po.TblUserRole;
|
|
|
|
-import com.hfln.portal.infrastructure.service.*;
|
|
|
|
|
|
+import com.hfln.portal.infrastructure.po.*;
|
|
|
|
+import com.hfln.portal.infrastructure.service.TblRoleMenuMapService;
|
|
|
|
+import com.hfln.portal.infrastructure.service.TblRoleService;
|
|
|
|
+import com.hfln.portal.infrastructure.service.TblSystemMenuService;
|
|
|
|
+import com.hfln.portal.infrastructure.service.UserRoleService;
|
|
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.stereotype.Component;
|
|
import org.springframework.stereotype.Component;
|
|
import org.springframework.util.CollectionUtils;
|
|
import org.springframework.util.CollectionUtils;
|
|
-import org.springframework.util.StringUtils;
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.ArrayList;
|
|
import java.util.List;
|
|
import java.util.List;
|
|
@@ -47,17 +46,17 @@ public class UserAuthService {
|
|
@Autowired
|
|
@Autowired
|
|
private TblSystemMenuService tblSystemMenuService;
|
|
private TblSystemMenuService tblSystemMenuService;
|
|
|
|
|
|
- public void cacheRolesAndPermissions(String tenantCode) {
|
|
|
|
|
|
+ public void cacheRolesAndPermissions(TblTenant tenant) {
|
|
|
|
|
|
List<String> roleCodeList = this.getRoleCodeList(StpUtil.getLoginId(), StpUtil.getLoginType());
|
|
List<String> roleCodeList = this.getRoleCodeList(StpUtil.getLoginId(), StpUtil.getLoginType());
|
|
if (!CollectionUtils.isEmpty(roleCodeList)) {
|
|
if (!CollectionUtils.isEmpty(roleCodeList)) {
|
|
|
|
|
|
List<String> newRoleCodeList = new ArrayList<>();
|
|
List<String> newRoleCodeList = new ArrayList<>();
|
|
for (String roleCode : roleCodeList) {
|
|
for (String roleCode : roleCodeList) {
|
|
- String newRoleCode = StringUtils.hasText(tenantCode) ? tenantCode + "_" + roleCode : roleCode;
|
|
|
|
|
|
+ String newRoleCode = tenant != null ? tenant.getTenantCode() + "_" + roleCode : roleCode;
|
|
newRoleCodeList.add(newRoleCode);
|
|
newRoleCodeList.add(newRoleCode);
|
|
if (!redisService.hasKey(RedisCacheConstant.ROLE_PERM_KEY_PRE + newRoleCode)) {
|
|
if (!redisService.hasKey(RedisCacheConstant.ROLE_PERM_KEY_PRE + newRoleCode)) {
|
|
- List<String> permCodeList = this.getPermCodeList(roleCode);
|
|
|
|
|
|
+ List<String> permCodeList = this.getPermCodeList(roleCode, tenant == null ? null : tenant.getTenantId());
|
|
if (!CollectionUtils.isEmpty(permCodeList)) {
|
|
if (!CollectionUtils.isEmpty(permCodeList)) {
|
|
// 永久期限
|
|
// 永久期限
|
|
redisService.setForever(RedisCacheConstant.ROLE_PERM_KEY_PRE + newRoleCode, JSONArray.toJSONString(permCodeList));
|
|
redisService.setForever(RedisCacheConstant.ROLE_PERM_KEY_PRE + newRoleCode, JSONArray.toJSONString(permCodeList));
|
|
@@ -94,11 +93,11 @@ public class UserAuthService {
|
|
/**
|
|
/**
|
|
* 返回当前角色所拥有的权限码集合
|
|
* 返回当前角色所拥有的权限码集合
|
|
*/
|
|
*/
|
|
- public List<String> getPermCodeList(String roleCode) {
|
|
|
|
|
|
+ public List<String> getPermCodeList(String roleCode, Long tenantId) {
|
|
|
|
|
|
List<String> list = new ArrayList<>();
|
|
List<String> list = new ArrayList<>();
|
|
|
|
|
|
- TblRole role = tblRoleService.findAvailableByCode(roleCode);
|
|
|
|
|
|
+ TblRole role = tblRoleService.queryRole(tenantId, roleCode);
|
|
if (role == null) {
|
|
if (role == null) {
|
|
log.info("角色配置异常, userIds :{}", role);
|
|
log.info("角色配置异常, userIds :{}", role);
|
|
return list;
|
|
return list;
|