From 7cf54012c46c54bd701310cc29caaa94676ea570 Mon Sep 17 00:00:00 2001 From: ludc Date: 星期一, 18 三月 2024 23:04:51 +0800 Subject: [PATCH] 分类授权功能完善 --- Source/UBCS/ubcs-service/ubcs-system/src/main/java/com/vci/ubcs/system/service/impl/ClassifyAuthServiceImpl.java | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 55 insertions(+), 0 deletions(-) diff --git a/Source/UBCS/ubcs-service/ubcs-system/src/main/java/com/vci/ubcs/system/service/impl/ClassifyAuthServiceImpl.java b/Source/UBCS/ubcs-service/ubcs-system/src/main/java/com/vci/ubcs/system/service/impl/ClassifyAuthServiceImpl.java index a0c765f..40166e5 100644 --- a/Source/UBCS/ubcs-service/ubcs-system/src/main/java/com/vci/ubcs/system/service/impl/ClassifyAuthServiceImpl.java +++ b/Source/UBCS/ubcs-service/ubcs-system/src/main/java/com/vci/ubcs/system/service/impl/ClassifyAuthServiceImpl.java @@ -12,6 +12,7 @@ import com.vci.ubcs.system.mapper.ClassifyAuthMapper; import com.vci.ubcs.system.service.IClassifyAuthService; import com.vci.ubcs.system.service.IMenuService; +import com.vci.ubcs.system.service.IRoleService; import com.vci.ubcs.system.vo.ClassifyAuthVO; import com.vci.ubcs.system.wrapper.ClassifyAuthWrapper; import lombok.AllArgsConstructor; @@ -19,6 +20,7 @@ import org.springblade.core.secure.utils.AuthUtil; import org.springblade.core.tool.api.R; import org.springblade.core.tool.utils.Func; +import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -39,6 +41,14 @@ private final IMenuService menuService; private final ICodeClassifyClient codeClassifyClient; + + private final IRoleService roleService; + + /** + * 涓夊憳绠$悊瑙掕壊缂栧彿閰嶇疆锛氬垎鍒负绯荤粺绠$悊鍛橈紝瀹夊叏绠$悊鍛橈紝瀹¤绠$悊鍛橀『搴� + */ + @Value("#{'${ssa.ssa-names}'.split(',')}") + private List<String> SSANAMES; /** * 鍒嗙被鎺堟潈淇濆瓨鎺ュ彛 @@ -215,4 +225,49 @@ return this.classifyAuthMapper.getViewClassByRoleIds(roleIds, authType,buttonCode,menuCode); } + /** + * 鏍规嵁瑙掕壊鍚嶇О鍒嗙被id鎺堜簣榛樿鐨勫垎绫绘潈闄愬拰涓绘暟鎹闂潈闄� + * @param classifyAuthDTO + * @return + */ + @Transactional(rollbackFor = Exception.class) + public R saveAddClassifyDefaultAuth(ClassifyAuthDTO classifyAuthDTO) throws ServiceException{ + if (Func.isEmpty(classifyAuthDTO.getClassifyId())) { + return R.fail("鏈幏鍙栧埌鍒嗙被id"); + } + // 閰嶇疆鐨勭郴缁熺鐞嗗憳鍚嶇О + String sysAdmin = SSANAMES.get(0); + List<ClassifyAuth> classifyAuths = new ArrayList<>(); + //鍏堥粯璁ょ敓鎴愮郴缁熺鐞嗗憳鐨勬巿鏉冩暟鎹� + ClassifyAuth classifyAuth = new ClassifyAuth(); + classifyAuth.setClassifyId(classifyAuthDTO.getClassifyId()); + classifyAuth.setAuthType("classify_auth"); + String roleIds = roleService.getRoleIds(AuthUtil.getTenantId(), sysAdmin); + if(Func.isBlank(roleIds)){ + return R.fail(AuthUtil.getTenantId()+"绉熸埛涓嬫湭鎵惧埌锛屽悕涓�"+sysAdmin+"绯荤粺绠$悊鍛樿鑹诧紒"); + } + classifyAuth.setRoleId(roleIds); + List<Menu> classifyTreeMenus = menuService.getButtonsByRoleId(roleIds, "classifyTree"); + if(!classifyTreeMenus.isEmpty()){ + String menuIds = classifyTreeMenus.stream() + .map(menu -> String.valueOf(menu.getId())) + .collect(Collectors.joining(",")); + classifyAuth.setButtonIds(menuIds); + classifyAuths.add(classifyAuth); + } + /*ClassifyAuth dataAuth = new ClassifyAuth(); + dataAuth.setAuthType("data_auth"); + dataAuth.setClassifyId(classifyAuthDTO.getClassifyId()); + dataAuth.setRoleId(roleIds); + List<Menu> masterDatas = menuService.getButtonsByRoleId(roleIds, classifyAuthDTO.getClassId()); + if(!masterDatas.isEmpty()){ + String menuIds = masterDatas.stream() + .map(menu -> String.valueOf(menu.getId())) + .collect(Collectors.joining(",")); + dataAuth.setButtonIds(menuIds); + classifyAuths.add(dataAuth); + }*/ + return R.status(this.saveBatch(classifyAuths)); + } + } -- Gitblit v1.9.3