mirror of
http://192.168.1.205:9980/cf_devdept2/cf_imes_server.git
synced 2026-08-12 21:02:08 +08:00
修改组织管理员角色逻辑
This commit is contained in:
+2
-1
@@ -48,7 +48,8 @@ public class SecurityFrameworkServiceImpl implements SecurityFrameworkService {
|
||||
|
||||
@Override
|
||||
public Boolean load(KeyValue<Long, List<String>> key) {
|
||||
return permissionApi.hasAnyPermissions(key.getKey(), key.getValue().toArray(new String[0])).getCheckedData();
|
||||
Boolean checkedData = permissionApi.hasAnyPermissions(key.getKey(), key.getValue().toArray(new String[0])).getCheckedData();
|
||||
return checkedData;
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
+1
@@ -87,6 +87,7 @@ public class GlobalExceptionHandler {
|
||||
return serviceExceptionHandler((ServiceException) ex);
|
||||
}
|
||||
if (ex instanceof AccessDeniedException) {
|
||||
ex.printStackTrace();
|
||||
return accessDeniedExceptionHandler(request, (AccessDeniedException) ex);
|
||||
}
|
||||
return defaultExceptionHandler(request, ex);
|
||||
|
||||
+1
-1
@@ -12,7 +12,7 @@ import java.util.List;
|
||||
public class BlockPlaceMessage {
|
||||
|
||||
@Schema(description = "自增板信息")
|
||||
private String zzInfo;
|
||||
private String incrInfo;
|
||||
@Schema(description = "大板ID")
|
||||
private Integer bi;
|
||||
@Schema(description = "小板号")
|
||||
|
||||
+3
-3
@@ -59,8 +59,8 @@ public class Material {
|
||||
private List<BlockPlaceMessage> blockPlaceMessageList;
|
||||
@Schema(description = "状态")
|
||||
private Integer state;
|
||||
@Schema(description = "有波纹")
|
||||
private Boolean hasWave;
|
||||
@Schema(description = "有纹路")
|
||||
private Boolean hasTexture;
|
||||
@Schema(description = "板材原宽")
|
||||
private Integer orgWidth;
|
||||
@Schema(description = "板材原长")
|
||||
@@ -72,7 +72,7 @@ public class Material {
|
||||
@Schema(description = "预洗值")
|
||||
private Integer preCutValue;
|
||||
@Schema(description = "废料板列表")
|
||||
private List<ScrapBoard> scrapBoardList;
|
||||
private List<ScrapBoard> remainBoardList;
|
||||
@Schema(description = "是否辅助开料")
|
||||
private Boolean helpCut;
|
||||
@Schema(description = "同刀辅助 厚度")
|
||||
|
||||
+4
-4
@@ -18,8 +18,8 @@ public class UsedBoardMessage {
|
||||
private Integer l;
|
||||
@Schema(description = "余料板ID")
|
||||
private Integer si;
|
||||
@Schema(description = "仓库号")
|
||||
private String so;
|
||||
/*@Schema(description = "仓库号")
|
||||
private String so;*/
|
||||
@Schema(description = "余料板号,大板为空")
|
||||
private String no;
|
||||
@Schema(description = "RM")
|
||||
@@ -27,9 +27,9 @@ public class UsedBoardMessage {
|
||||
@Schema(description = "是否锁定")
|
||||
private Boolean lK;
|
||||
@Schema(description = "余料母板")
|
||||
private List<ScrapPt> scrapPtList;
|
||||
private List<ScrapPt> remainPtList;
|
||||
@Schema(description = "余料空间")
|
||||
private List<ScrapBlock> scrapBlocks;
|
||||
private List<ScrapBlock> remainBlocks;
|
||||
@Schema(description = "左边不能加工区域,有造型")
|
||||
private Boolean le;
|
||||
@Schema(description = "右边不能加工区域,有造型")
|
||||
|
||||
+20
@@ -257,6 +257,16 @@ public class OrderInputProcessor {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量保存生产单小板五金数据
|
||||
* @param rawGoodsDOS
|
||||
* @param orderBodyDOS
|
||||
* @param orderGroupDOS
|
||||
* @param orderPartsDOS
|
||||
* @param plateDOS
|
||||
* @param orderModuleExtraDOS
|
||||
* @param itemDOS
|
||||
*/
|
||||
@Transactional
|
||||
public void batchInsert(Collection<RawGoodsDO> rawGoodsDOS, Collection<OrderBodyDO> orderBodyDOS,
|
||||
Collection<OrderGroupDO> orderGroupDOS, Collection<OrderPartsDO> orderPartsDOS,
|
||||
@@ -270,5 +280,15 @@ public class OrderInputProcessor {
|
||||
orderItemMapper.insertBatch(itemDOS);
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存生产单造型数据
|
||||
* @param sourceList
|
||||
* @param orderId
|
||||
*/
|
||||
public void saveModel(List<Detail> sourceList, Long orderId) {
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
+3
-3
@@ -34,13 +34,13 @@ public class OAuth2TokenApiImpl implements OAuth2TokenApi {
|
||||
@Override
|
||||
@Operation(description = "创建访问令牌")
|
||||
public CommonResult<OAuth2AccessTokenRespDTO> createAccessToken(OAuth2AccessTokenCreateReqDTO reqDTO) {
|
||||
Long organId = OrganContextHolder.getOrganId();
|
||||
/* Long organId = OrganContextHolder.getOrganId();
|
||||
OrganizationDO organ = organService.getOrgan(organId);
|
||||
if(Objects.isNull(organ)) {
|
||||
throw new ServerException(10023,"组织不存在");
|
||||
}
|
||||
}*/
|
||||
OAuth2AccessTokenDO accessTokenDO = oauth2TokenService.createAccessToken(
|
||||
reqDTO.getUserId(), reqDTO.getUserType(), reqDTO.getClientId(), reqDTO.getScopes(),organ.getLarge(), organ.getDbNo(), organ.getTableNo(), organ.getDataSourceCode());
|
||||
reqDTO.getUserId(), reqDTO.getUserType(), reqDTO.getClientId(), reqDTO.getScopes(), null, null, null, null);
|
||||
return success(BeanUtils.toBean(accessTokenDO, OAuth2AccessTokenRespDTO.class));
|
||||
}
|
||||
|
||||
|
||||
+2
-1
@@ -36,7 +36,8 @@ public class PermissionApiImpl implements PermissionApi {
|
||||
|
||||
@Override
|
||||
public CommonResult<DeptDataPermissionRespDTO> getDeptDataPermission(Long userId) {
|
||||
return success(permissionService.getDeptDataPermission(userId));
|
||||
DeptDataPermissionRespDTO deptDataPermission = permissionService.getDeptDataPermission(userId);
|
||||
return success(deptDataPermission);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+6
-3
@@ -113,12 +113,15 @@ public class AuthController {
|
||||
if (CollUtil.isEmpty(roleIds)) {
|
||||
return success(AuthConvert.INSTANCE.convert(user, Collections.emptyList(), Collections.emptyList()));
|
||||
}
|
||||
List<RoleDO> roles = roleService.getRoleList(roleIds);
|
||||
//List<RoleDO> roles = roleService.getRoleList(roleIds);
|
||||
List<RoleDO> roles = roleService.getRoleList1(roleIds);
|
||||
roles.removeIf(role -> !CommonStatusEnum.ENABLE.getStatus().equals(role.getStatus())); // 移除禁用的角色
|
||||
|
||||
// 1.3 获得菜单列表
|
||||
Set<Long> menuIds = permissionService.getRoleMenuListByRoleId(convertSet(roles, RoleDO::getId));
|
||||
List<MenuDO> menuList = menuService.getMenuList(menuIds);
|
||||
//Set<Long> menuIds = permissionService.getRoleMenuListByRoleId(convertSet(roles, RoleDO::getId));
|
||||
Set<Long> menuIds = permissionService.getRoleMenuListByRoleId2(convertSet(roles, RoleDO::getId));
|
||||
//List<MenuDO> menuList = menuService.getMenuList(menuIds);
|
||||
List<MenuDO> menuList = menuService.getMenuList1(menuIds);
|
||||
menuList.removeIf(menu -> !CommonStatusEnum.ENABLE.getStatus().equals(menu.getStatus())); // 移除禁用的菜单
|
||||
|
||||
// 2. 拼接结果返回
|
||||
|
||||
+2
@@ -44,6 +44,8 @@ public class AuthPermissionInfoRespVO {
|
||||
@Schema(description = "用户头像", requiredMode = Schema.RequiredMode.REQUIRED, example = "https://www.cf.com/xx.jpg")
|
||||
private String avatar;
|
||||
|
||||
@Schema(description = "组织id")
|
||||
private Long organId;
|
||||
}
|
||||
|
||||
@Schema(description = "管理后台 - 登录用户的菜单信息 Response VO")
|
||||
|
||||
+2
-1
@@ -2,6 +2,7 @@ package com.cf.imes.module.system.controller.admin.permission;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import com.cf.imes.framework.common.pojo.CommonResult;
|
||||
import com.cf.imes.framework.organ.core.context.OrganContextHolder;
|
||||
import com.cf.imes.module.system.controller.admin.permission.vo.permission.PermissionAssignRoleDataScopeReqVO;
|
||||
import com.cf.imes.module.system.controller.admin.permission.vo.permission.PermissionAssignRoleMenuReqVO;
|
||||
import com.cf.imes.module.system.controller.admin.permission.vo.permission.PermissionAssignUserRoleReqVO;
|
||||
@@ -75,7 +76,7 @@ public class PermissionController {
|
||||
@PostMapping("/assign-user-role")
|
||||
@PreAuthorize("@ss.hasPermission('system:permission:assign-user-role')")
|
||||
public CommonResult<Boolean> assignUserRole(@Validated @RequestBody PermissionAssignUserRoleReqVO reqVO) {
|
||||
permissionService.assignUserRole(reqVO.getUserId(), reqVO.getRoleIds());
|
||||
permissionService.assignUserRole(reqVO.getUserId(), reqVO.getRoleIds(),OrganContextHolder.getOrganId());
|
||||
return success(true);
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -33,7 +33,7 @@ public interface AuthConvert {
|
||||
|
||||
default AuthPermissionInfoRespVO convert(AdminUserDO user, List<RoleDO> roleList, List<MenuDO> menuList) {
|
||||
return AuthPermissionInfoRespVO.builder()
|
||||
.user(AuthPermissionInfoRespVO.UserVO.builder().id(user.getId()).nickname(user.getNickname()).avatar(user.getAvatar()).build())
|
||||
.user(AuthPermissionInfoRespVO.UserVO.builder().id(user.getId()).nickname(user.getNickname()).avatar(user.getAvatar()).organId(user.getOrganId()).build())
|
||||
.roles(convertSet(roleList, RoleDO::getCode))
|
||||
// 权限标识信息
|
||||
.permissions(convertSet(menuList, MenuDO::getPermission))
|
||||
|
||||
+6
-1
@@ -1,6 +1,7 @@
|
||||
package com.cf.imes.module.system.dal.dataobject.permission;
|
||||
|
||||
import com.cf.imes.framework.common.enums.CommonStatusEnum;
|
||||
import com.cf.imes.framework.mybatis.core.dataobject.BaseDO;
|
||||
import com.cf.imes.framework.mybatis.core.type.JsonLongSetTypeHandler;
|
||||
import com.cf.imes.module.system.enums.permission.DataScopeEnum;
|
||||
import com.cf.imes.framework.organ.core.db.OrganBaseDO;
|
||||
@@ -23,7 +24,7 @@ import java.util.Set;
|
||||
@KeySequence("system_role_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public class RoleDO extends OrganBaseDO {
|
||||
public class RoleDO extends BaseDO {
|
||||
|
||||
/**
|
||||
* 角色ID
|
||||
@@ -74,5 +75,9 @@ public class RoleDO extends OrganBaseDO {
|
||||
*/
|
||||
@TableField(typeHandler = JsonLongSetTypeHandler.class)
|
||||
private Set<Long> dataScopeDeptIds;
|
||||
/**
|
||||
* 组织id
|
||||
*/
|
||||
private Long organId;
|
||||
|
||||
}
|
||||
|
||||
+4
-1
@@ -31,5 +31,8 @@ public class UserRoleDO extends BaseDO {
|
||||
* 角色 ID
|
||||
*/
|
||||
private Long roleId;
|
||||
|
||||
/**
|
||||
* 组织 id
|
||||
*/
|
||||
private Long organId;
|
||||
}
|
||||
|
||||
+1
@@ -11,6 +11,7 @@ import org.apache.ibatis.annotations.Mapper;
|
||||
import org.springframework.lang.Nullable;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
|
||||
@Mapper
|
||||
|
||||
+3
-3
@@ -210,14 +210,14 @@ public class AdminAuthServiceImpl implements AdminAuthService {
|
||||
private AuthLoginRespVO createTokenAfterLoginSuccess(Long userId, String username, LoginLogTypeEnum logType) {
|
||||
// 插入登陆日志
|
||||
createLoginLog(userId, username, logType, LoginResultEnum.SUCCESS);
|
||||
Long organId = OrganContextHolder.getOrganId();
|
||||
/*Long organId = OrganContextHolder.getOrganId();
|
||||
OrganizationDO organ = organService.getOrgan(organId);
|
||||
if(Objects.isNull(organ)) {
|
||||
throw new ServerException(10023,"组织不存在");
|
||||
}
|
||||
}*/
|
||||
// 创建访问令牌
|
||||
OAuth2AccessTokenDO accessTokenDO = oauth2TokenService.createAccessToken(userId, getUserType().getValue(),
|
||||
OAuth2ClientConstants.CLIENT_ID_DEFAULT, null, organ.getLarge(), organ.getDbNo(), organ.getTableNo(), organ.getDataSourceCode());
|
||||
OAuth2ClientConstants.CLIENT_ID_DEFAULT, null, null, null, null, null);
|
||||
// 构建返回结果
|
||||
return AuthConvert.INSTANCE.convert(accessTokenDO);
|
||||
}
|
||||
|
||||
+9
-9
@@ -42,12 +42,12 @@ public class OAuth2GrantServiceImpl implements OAuth2GrantService {
|
||||
@Override
|
||||
public OAuth2AccessTokenDO grantImplicit(Long userId, Integer userType,
|
||||
String clientId, List<String> scopes) {
|
||||
Long organId = OrganContextHolder.getOrganId();
|
||||
/* Long organId = OrganContextHolder.getOrganId();
|
||||
OrganizationDO organ = organService.getOrgan(organId);
|
||||
if(Objects.isNull(organ)) {
|
||||
throw new ServerException(10023,"组织不存在");
|
||||
}
|
||||
return oauth2TokenService.createAccessToken(userId, userType, clientId, scopes, organ.getLarge(), organ.getDbNo(), organ.getTableNo(), organ.getDataSourceCode());
|
||||
}*/
|
||||
return oauth2TokenService.createAccessToken(userId, userType, clientId, scopes, null, null, null, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -77,15 +77,15 @@ public class OAuth2GrantServiceImpl implements OAuth2GrantService {
|
||||
throw exception(ErrorCodeConstants.OAUTH2_GRANT_STATE_MISMATCH);
|
||||
}
|
||||
|
||||
Long organId = OrganContextHolder.getOrganId();
|
||||
/* Long organId = OrganContextHolder.getOrganId();
|
||||
OrganizationDO organ = organService.getOrgan(organId);
|
||||
if(Objects.isNull(organ)) {
|
||||
throw new ServerException(10023,"组织不存在");
|
||||
}
|
||||
}*/
|
||||
|
||||
// 创建访问令牌
|
||||
return oauth2TokenService.createAccessToken(codeDO.getUserId(), codeDO.getUserType(),
|
||||
codeDO.getClientId(), codeDO.getScopes(), organ.getLarge(), organ.getDbNo(), organ.getTableNo(), organ.getDataSourceCode());
|
||||
codeDO.getClientId(), codeDO.getScopes(),null, null, null, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -93,13 +93,13 @@ public class OAuth2GrantServiceImpl implements OAuth2GrantService {
|
||||
// 使用账号 + 密码进行登录
|
||||
AdminUserDO user = adminAuthService.authenticate(username, password, null);
|
||||
Assert.notNull(user, "用户不能为空!"); // 防御性编程
|
||||
Long organId = OrganContextHolder.getOrganId();
|
||||
/*Long organId = OrganContextHolder.getOrganId();
|
||||
OrganizationDO organ = organService.getOrgan(organId);
|
||||
if(Objects.isNull(organ)) {
|
||||
throw new ServerException(10023,"组织不存在");
|
||||
}
|
||||
}*/
|
||||
// 创建访问令牌
|
||||
return oauth2TokenService.createAccessToken(user.getId(), UserTypeEnum.ADMIN.getValue(), clientId, scopes, organ.getLarge(), organ.getDbNo(), organ.getTableNo(), organ.getDataSourceCode());
|
||||
return oauth2TokenService.createAccessToken(user.getId(), UserTypeEnum.ADMIN.getValue(), clientId, scopes,null, null, null, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+7
-3
@@ -78,6 +78,10 @@ public class OrganServiceImpl implements OrganService {
|
||||
private MenuService menuService;
|
||||
@Resource
|
||||
private PermissionService permissionService;
|
||||
//组织管理员角色id
|
||||
private static final Long ORGAN_ADMIN_ROLE_ID = 165L;
|
||||
//组织员工角色id
|
||||
private static final Long ORGAN_STAFF_ROLE_ID = 166L;
|
||||
|
||||
@Override
|
||||
public List<Long> getOrganIdList() {
|
||||
@@ -137,9 +141,9 @@ public class OrganServiceImpl implements OrganService {
|
||||
// 创建组织的管理员
|
||||
OrganUtils.execute(organId, () -> {
|
||||
// 创建角色
|
||||
Long roleId = createRole(tenantPackage, organId);
|
||||
/*Long roleId = createRole(tenantPackage, organId);*/
|
||||
// 创建用户,并分配角色
|
||||
Long userId = createUser(roleId, createReqVO, organId);
|
||||
Long userId = createUser(ORGAN_ADMIN_ROLE_ID, createReqVO, organId);
|
||||
// 修改组织的管理员
|
||||
organMapper.updateById(new OrganizationDO().setId(tenant.getId()).setContactUserId(userId));
|
||||
});
|
||||
@@ -152,7 +156,7 @@ public class OrganServiceImpl implements OrganService {
|
||||
reqVO.setOrganId(organId);
|
||||
Long userId = userService.createUser(reqVO);
|
||||
// 分配角色
|
||||
permissionService.assignUserRole(userId, singleton(roleId));
|
||||
permissionService.assignUserRole(userId, singleton(roleId), organId);
|
||||
return userId;
|
||||
}
|
||||
|
||||
|
||||
+2
@@ -6,6 +6,7 @@ import com.cf.imes.module.system.dal.dataobject.permission.MenuDO;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* 菜单 Service 接口
|
||||
@@ -84,4 +85,5 @@ public interface MenuService {
|
||||
*/
|
||||
List<MenuDO> getMenuList(Collection<Long> ids);
|
||||
|
||||
List<MenuDO> getMenuList1(Collection<Long> ids);
|
||||
}
|
||||
|
||||
+7
-2
@@ -2,6 +2,7 @@ package com.cf.imes.module.system.service.permission;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import com.cf.imes.framework.common.util.object.BeanUtils;
|
||||
import com.cf.imes.framework.organ.core.aop.OrganIgnore;
|
||||
import com.cf.imes.module.system.controller.admin.permission.vo.menu.MenuListReqVO;
|
||||
import com.cf.imes.module.system.controller.admin.permission.vo.menu.MenuSaveVO;
|
||||
import com.cf.imes.module.system.dal.dataobject.permission.MenuDO;
|
||||
@@ -132,6 +133,12 @@ public class MenuServiceImpl implements MenuService {
|
||||
return menuMapper.selectBatchIds(ids);
|
||||
}
|
||||
|
||||
@Override
|
||||
@OrganIgnore
|
||||
public List<MenuDO> getMenuList1(Collection<Long> ids) {
|
||||
return menuMapper.selectBatchIds(ids);
|
||||
}
|
||||
|
||||
/**
|
||||
* 校验父菜单是否合法
|
||||
* <p>
|
||||
@@ -174,9 +181,7 @@ public class MenuServiceImpl implements MenuService {
|
||||
*/
|
||||
@VisibleForTesting
|
||||
void validateMenu(Long parentId, String name, Long id) {
|
||||
System.out.println("parentId = " + parentId+"name = "+ name);
|
||||
MenuDO menu = menuMapper.selectByParentIdAndName(parentId, name);
|
||||
System.out.println("!!!!!!!!!!!!!!!!" + menu);
|
||||
if (menu == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
+10
-1
@@ -83,6 +83,14 @@ public interface PermissionService {
|
||||
*/
|
||||
Set<Long> getMenuRoleIdListByMenuIdFromCache(Long menuId);
|
||||
|
||||
/**
|
||||
* 获得拥有指定菜单的角色编号数组,从缓存中获取
|
||||
*
|
||||
* @param menuId 菜单编号
|
||||
* @return 角色编号数组
|
||||
*/
|
||||
Set<Long> getMenuRoleIdListByMenuIdFromCache1(Long menuId);
|
||||
|
||||
// ========== 用户-角色的相关方法 ==========
|
||||
|
||||
/**
|
||||
@@ -91,7 +99,7 @@ public interface PermissionService {
|
||||
* @param userId 角色编号
|
||||
* @param roleIds 角色编号集合
|
||||
*/
|
||||
void assignUserRole(Long userId, Set<Long> roleIds);
|
||||
void assignUserRole(Long userId, Set<Long> roleIds, Long organId);
|
||||
|
||||
/**
|
||||
* 处理用户删除时,删除关联授权数据
|
||||
@@ -143,4 +151,5 @@ public interface PermissionService {
|
||||
*/
|
||||
DeptDataPermissionRespDTO getDeptDataPermission(Long userId);
|
||||
|
||||
Set<Long> getRoleMenuListByRoleId2(Set<Long> roleIds);
|
||||
}
|
||||
|
||||
+38
-3
@@ -7,6 +7,10 @@ import cn.hutool.extra.spring.SpringUtil;
|
||||
import com.cf.imes.framework.common.enums.CommonStatusEnum;
|
||||
import com.cf.imes.framework.common.util.collection.CollectionUtils;
|
||||
import com.cf.imes.framework.datapermission.core.annotation.DataPermission;
|
||||
import com.cf.imes.framework.mybatis.core.query.LambdaQueryWrapperX;
|
||||
import com.cf.imes.framework.organ.core.aop.OrganIgnore;
|
||||
import com.cf.imes.framework.organ.core.context.OrganContextHolder;
|
||||
import com.cf.imes.framework.organ.core.db.OrganBaseDO;
|
||||
import com.cf.imes.module.system.api.permission.dto.DeptDataPermissionRespDTO;
|
||||
import com.cf.imes.module.system.dal.dataobject.permission.MenuDO;
|
||||
import com.cf.imes.module.system.dal.dataobject.permission.RoleDO;
|
||||
@@ -101,7 +105,8 @@ public class PermissionServiceImpl implements PermissionService {
|
||||
Set<Long> roleIds = convertSet(roles, RoleDO::getId);
|
||||
for (Long menuId : menuIds) {
|
||||
// 获得拥有该菜单的角色编号集合
|
||||
Set<Long> menuRoleIds = getSelf().getMenuRoleIdListByMenuIdFromCache(menuId);
|
||||
//Set<Long> menuRoleIds = getSelf().getMenuRoleIdListByMenuIdFromCache(menuId);
|
||||
Set<Long> menuRoleIds = getSelf().getMenuRoleIdListByMenuIdFromCache1(menuId);
|
||||
// 如果有交集,说明有权限
|
||||
if (CollUtil.containsAny(menuRoleIds, roleIds)) {
|
||||
return true;
|
||||
@@ -187,7 +192,24 @@ public class PermissionServiceImpl implements PermissionService {
|
||||
return convertSet(menuService.getMenuList(), MenuDO::getId);
|
||||
}
|
||||
// 如果是非管理员的情况下,获得拥有的菜单编号
|
||||
return convertSet(roleMenuMapper.selectListByRoleId(roleIds), RoleMenuDO::getMenuId);
|
||||
List<RoleMenuDO> from = roleMenuMapper.selectListByRoleId(roleIds);
|
||||
return convertSet(from, RoleMenuDO::getMenuId);
|
||||
}
|
||||
|
||||
@Override
|
||||
@OrganIgnore
|
||||
public Set<Long> getRoleMenuListByRoleId2(Set<Long> roleIds) {
|
||||
if (CollUtil.isEmpty(roleIds)) {
|
||||
return Collections.emptySet();
|
||||
}
|
||||
|
||||
// 如果是管理员的情况下,获取全部菜单编号
|
||||
if (roleService.hasAnySuperAdmin(roleIds)) {
|
||||
return convertSet(menuService.getMenuList(), MenuDO::getId);
|
||||
}
|
||||
// 如果是非管理员的情况下,获得拥有的菜单编号
|
||||
List<RoleMenuDO> from = roleMenuMapper.selectListByRoleId(roleIds);
|
||||
return convertSet(from, RoleMenuDO::getMenuId);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -196,12 +218,23 @@ public class PermissionServiceImpl implements PermissionService {
|
||||
return convertSet(roleMenuMapper.selectListByMenuId(menuId), RoleMenuDO::getRoleId);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Cacheable(value = RedisKeyConstants.MENU_ROLE_ID_LIST, key = "#menuId")
|
||||
@OrganIgnore
|
||||
public Set<Long> getMenuRoleIdListByMenuIdFromCache1(Long menuId) {
|
||||
List<RoleMenuDO> roleMenuDOS = roleMenuMapper.selectList(new LambdaQueryWrapperX<RoleMenuDO>().in(RoleMenuDO::getOrganId, 0l, OrganContextHolder.getOrganId())
|
||||
.eq(RoleMenuDO::getMenuId, menuId)
|
||||
);
|
||||
return convertSet(roleMenuDOS, RoleMenuDO::getRoleId);
|
||||
// return convertSet(roleMenuMapper.selectListByMenuId(menuId), RoleMenuDO::getRoleId);
|
||||
}
|
||||
|
||||
// ========== 用户-角色的相关方法 ==========
|
||||
|
||||
@Override
|
||||
@DSTransactional // 多数据源,使用 @DSTransactional 保证本地事务,以及数据源的切换
|
||||
@CacheEvict(value = RedisKeyConstants.USER_ROLE_ID_LIST, key = "#userId")
|
||||
public void assignUserRole(Long userId, Set<Long> roleIds) {
|
||||
public void assignUserRole(Long userId, Set<Long> roleIds, Long organId) {
|
||||
// 获得角色拥有角色编号
|
||||
Set<Long> dbRoleIds = convertSet(userRoleMapper.selectListByUserId(userId),
|
||||
UserRoleDO::getRoleId);
|
||||
@@ -215,6 +248,7 @@ public class PermissionServiceImpl implements PermissionService {
|
||||
UserRoleDO entity = new UserRoleDO();
|
||||
entity.setUserId(userId);
|
||||
entity.setRoleId(roleId);
|
||||
entity.setOrganId(organId);
|
||||
return entity;
|
||||
}));
|
||||
}
|
||||
@@ -325,6 +359,7 @@ public class PermissionServiceImpl implements PermissionService {
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获得自身的代理对象,解决 AOP 生效问题
|
||||
*
|
||||
|
||||
+9
@@ -73,6 +73,14 @@ public interface RoleService {
|
||||
*/
|
||||
RoleDO getRoleFromCache(Long id);
|
||||
|
||||
/**
|
||||
* 获得角色,从缓存中 加上组织0
|
||||
*
|
||||
* @param id 角色编号
|
||||
* @return 角色
|
||||
*/
|
||||
RoleDO getRoleFromCache1(Long id);
|
||||
|
||||
/**
|
||||
* 获得角色列表
|
||||
*
|
||||
@@ -129,4 +137,5 @@ public interface RoleService {
|
||||
*/
|
||||
void validateRoleList(Collection<Long> ids);
|
||||
|
||||
List<RoleDO> getRoleList1(Set<Long> roleIds);
|
||||
}
|
||||
|
||||
+25
-2
@@ -8,6 +8,9 @@ import com.cf.imes.framework.common.enums.CommonStatusEnum;
|
||||
import com.cf.imes.framework.common.pojo.PageResult;
|
||||
import com.cf.imes.framework.common.util.collection.CollectionUtils;
|
||||
import com.cf.imes.framework.common.util.object.BeanUtils;
|
||||
import com.cf.imes.framework.mybatis.core.query.LambdaQueryWrapperX;
|
||||
import com.cf.imes.framework.organ.core.aop.OrganIgnore;
|
||||
import com.cf.imes.framework.organ.core.context.OrganContextHolder;
|
||||
import com.cf.imes.framework.security.core.util.SecurityFrameworkUtils;
|
||||
import com.cf.imes.module.system.controller.admin.permission.vo.role.RolePageReqVO;
|
||||
import com.cf.imes.module.system.controller.admin.permission.vo.role.RoleSaveReqVO;
|
||||
@@ -174,6 +177,15 @@ public class RoleServiceImpl implements RoleService {
|
||||
return roleMapper.selectById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Cacheable(value = RedisKeyConstants.ROLE, key = "#id",
|
||||
unless = "#result == null")
|
||||
@OrganIgnore
|
||||
public RoleDO getRoleFromCache1(Long id) {
|
||||
RoleDO roleDO = roleMapper.selectById(id);
|
||||
return roleDO;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public List<RoleDO> getRoleListByStatus(Collection<Integer> statuses) {
|
||||
@@ -190,7 +202,7 @@ public class RoleServiceImpl implements RoleService {
|
||||
if (CollectionUtil.isEmpty(ids)) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
return roleMapper.selectBatchIds(ids);
|
||||
return roleMapper.selectBatchIds(ids);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -200,10 +212,12 @@ public class RoleServiceImpl implements RoleService {
|
||||
}
|
||||
// 这里采用 for 循环从缓存中获取,主要考虑 Spring CacheManager 无法批量操作的问题
|
||||
RoleServiceImpl self = getSelf();
|
||||
return CollectionUtils.convertList(ids, self::getRoleFromCache);
|
||||
List<RoleDO> roleDOS = CollectionUtils.convertList(ids, self::getRoleFromCache1);
|
||||
return roleDOS;
|
||||
}
|
||||
|
||||
@Override
|
||||
//@OrganIgnore
|
||||
public PageResult<RoleDO> getRolePage(RolePageReqVO reqVO) {
|
||||
return roleMapper.selectPage(reqVO);
|
||||
}
|
||||
@@ -249,4 +263,13 @@ public class RoleServiceImpl implements RoleService {
|
||||
return SpringUtil.getBean(getClass());
|
||||
}
|
||||
|
||||
@Override
|
||||
@OrganIgnore
|
||||
public List<RoleDO> getRoleList1(Set<Long> roleIds) {
|
||||
if (CollectionUtil.isEmpty(roleIds)) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
return roleMapper.selectBatchIds(roleIds);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+1
@@ -95,6 +95,7 @@ public class AdminUserServiceImpl implements AdminUserService {
|
||||
createReqVO.getMobile(), createReqVO.getEmail(), createReqVO.getDeptId(), createReqVO.getPostIds(), createReqVO.getOrganId());
|
||||
// 插入用户
|
||||
AdminUserDO user = BeanUtils.toBean(createReqVO, AdminUserDO.class);
|
||||
user.setOrganId(createReqVO.getOrganId());
|
||||
user.setStatus(CommonStatusEnum.ENABLE.getStatus()); // 默认开启
|
||||
user.setPassword(encodePassword(createReqVO.getPassword())); // 加密密码
|
||||
|
||||
|
||||
@@ -182,7 +182,7 @@ chenfeng:
|
||||
- system_label_template
|
||||
- system_label_element_template
|
||||
- system_data_source
|
||||
- system_users
|
||||
|
||||
sms-code: # 短信验证码相关的配置项
|
||||
expire-times: 10m
|
||||
send-frequency: 1m
|
||||
|
||||
+1
-1
@@ -170,7 +170,7 @@ public class TenantServiceImplTest extends BaseDbUnitTest {
|
||||
// verify 分配权限
|
||||
verify(permissionService).assignRoleMenu(eq(200L), same(tenantPackage.getMenuIds()));
|
||||
// verify 分配角色
|
||||
verify(permissionService).assignUserRole(eq(300L), eq(singleton(200L)));
|
||||
verify(permissionService).assignUserRole(eq(300L), eq(singleton(200L)),1L);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
+1
-1
@@ -254,7 +254,7 @@ public class PermissionServiceTest extends BaseDbUnitTest {
|
||||
userRoleMapper.insert(userRole02);
|
||||
|
||||
// 调用
|
||||
permissionService.assignUserRole(userId, roleIds);
|
||||
permissionService.assignUserRole(userId, roleIds, 1L);
|
||||
// 断言
|
||||
List<UserRoleDO> userRoleDOList = userRoleMapper.selectList();
|
||||
assertEquals(2, userRoleDOList.size());
|
||||
|
||||
Reference in New Issue
Block a user