From 33d8416c5a16fee7464df9774678bc60e47ff956 Mon Sep 17 00:00:00 2001 From: 田源 <lastanimals@163.com> Date: 星期二, 19 三月 2024 09:53:25 +0800 Subject: [PATCH] Merge remote-tracking branch 'origin/master' --- Source/UBCS/ubcs-service/ubcs-system/src/main/java/com/vci/ubcs/system/service/impl/ClassifyAuthServiceImpl.java | 222 +++++++++++++++++++++++++++++++++++++++++++++++-------- 1 files changed, 188 insertions(+), 34 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 0eb2627..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 @@ -4,20 +4,23 @@ import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.vci.ubcs.code.feign.ICodeClassifyClient; import com.vci.ubcs.starter.web.util.VciBaseUtil; +import com.vci.ubcs.system.dto.ClassifyAuthDTO; import com.vci.ubcs.system.entity.ClassifyAuth; import com.vci.ubcs.system.entity.Menu; 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.vo.MenuVO; import com.vci.ubcs.system.wrapper.ClassifyAuthWrapper; import lombok.AllArgsConstructor; import org.springblade.core.log.exception.ServiceException; 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; @@ -25,7 +28,7 @@ import java.util.stream.Collectors; /** - * 鍒嗙被鎺堟潈 + * 鍒嗙被鎺堟潈,鏁版嵁鎺堟潈 * @author ludc * @date 2023/12/25 15:35 */ @@ -37,29 +40,64 @@ private final IMenuService menuService; + private final ICodeClassifyClient codeClassifyClient; + + private final IRoleService roleService; + + /** + * 涓夊憳绠$悊瑙掕壊缂栧彿閰嶇疆锛氬垎鍒负绯荤粺绠$悊鍛橈紝瀹夊叏绠$悊鍛橈紝瀹¤绠$悊鍛橀『搴� + */ + @Value("#{'${ssa.ssa-names}'.split(',')}") + private List<String> SSANAMES; + /** * 鍒嗙被鎺堟潈淇濆瓨鎺ュ彛 - * @param classifyAuthList + * @param classifyAuthListDTO * @return */ @Override @Transactional(rollbackFor = Exception.class) - public R submit(List<ClassifyAuth> classifyAuthList) { - if(classifyAuthList.isEmpty()){ + public R submit(ClassifyAuthDTO classifyAuthListDTO) throws ServiceException{ + // 鏄竻绌烘巿鏉冨垪琛� + if(classifyAuthListDTO.getIsCLear()){ + if(Func.isEmpty(classifyAuthListDTO.getClassifyId())){ + return R.fail("娓呯┖鎺堟潈鍒楄〃鏃讹紝鏈幏鍙栧埌鍒嗙被id"); + } + this.classifyAuthMapper.delete( + Wrappers.<ClassifyAuth>update() + .lambda().eq(ClassifyAuth::getClassifyId, classifyAuthListDTO.getClassifyId()) + .eq(ClassifyAuth::getAuthType,classifyAuthListDTO.getAuthType()) + ); + return R.success("鎺堟潈鍒楄〃娓呯┖鎴愬姛"); + } + + if(!classifyAuthListDTO.getIsCLear() && classifyAuthListDTO.getClassifyAuthList().isEmpty()){ R.fail("鎺堟潈鍒楄〃涓嶈兘涓虹┖锛�"); } + // 鍒ら噸锛屾煡鐪嬫槸鍚﹀瓨鍦ㄥ悓涓�涓猚lassid涓嬮厤缃簡鐩稿悓鐨勮鑹� + Map<String, Long> roleidCounts = classifyAuthListDTO.getClassifyAuthList().stream() + .collect(Collectors.groupingBy(ClassifyAuth::getRoleId, Collectors.counting())); + + // 妫�鏌ユ槸鍚︽湁roleid鍑虹幇娆℃暟澶т簬1鐨勬儏鍐� + boolean hasDuplicateRoleid = roleidCounts.values().stream() + .anyMatch(count -> count > 1); + if(hasDuplicateRoleid){ + R.fail("瑙掕壊鍜屽垎绫诲凡缁忓瓨鍦紝璇烽噸鏂伴厤缃紒"); + } + // 濡傛灉浼犺繃鏉ョ殑闆嗗悎涓鍒嗙被id涓嬪垹闄や簡閮ㄥ垎瑙掕壊鐨勬巿鏉冿紝灏遍渶瑕佸皢璇ュ簱涓璫lassifyId涓嬩笉瀛樺湪鐨勬暟鎹垹鎺� - List<String> roleIds = classifyAuthList.stream().map(ClassifyAuth::getRoleId).collect(Collectors.toList()); + List<String> roleIds = classifyAuthListDTO.getClassifyAuthList().stream().map(ClassifyAuth::getRoleId).collect(Collectors.toList()); // 鍒犻櫎 LambdaUpdateWrapper<ClassifyAuth> updateWrapper = Wrappers.<ClassifyAuth>update() - .lambda().eq(ClassifyAuth::getClassifyId, classifyAuthList.get(0).getClassifyId()) + .lambda().eq(ClassifyAuth::getClassifyId, classifyAuthListDTO.getClassifyAuthList().get(0).getClassifyId()) + .eq(ClassifyAuth::getAuthType,classifyAuthListDTO.getAuthType()) .notIn(ClassifyAuth::getRoleId, roleIds); try { this.classifyAuthMapper.delete(updateWrapper); }catch (Exception e){ throw new ServiceException("鍒嗙被鎺堟潈杩囩▼涓嚭鐜伴敊璇紝閿欒鍘熷洜锛�"+e.getMessage()); } - return R.status(saveOrUpdateBatch(classifyAuthList)); + return R.status(saveOrUpdateBatch(classifyAuthListDTO.getClassifyAuthList())); } /** @@ -73,41 +111,24 @@ throw new ServiceException("缂哄皯蹇呬紶鍙傛暟鍒嗙被id"); } LambdaQueryWrapper<ClassifyAuth> wrapper = Wrappers.<ClassifyAuth>query() - .lambda().eq(ClassifyAuth::getClassifyId,classifyAuthVO.getClassifyId()); + .lambda().eq(ClassifyAuth::getClassifyId,classifyAuthVO.getClassifyId()) + .eq(ClassifyAuth::getAuthType,classifyAuthVO.getAuthType()); List<ClassifyAuth> classifyAuths = this.classifyAuthMapper.selectList(wrapper); - if(!classifyAuths.isEmpty()){ - return ClassifyAuthWrapper.build().listVO(classifyAuths); + if(classifyAuths.isEmpty()){ + return new ArrayList<ClassifyAuthVO>(); } - return new ArrayList<ClassifyAuthVO>(); + return ClassifyAuthWrapper.build().listVO(classifyAuths); } /** * 鏌ヨ璇ュ垎绫讳笅锛屽綋鍓嶇櫥褰曠殑瑙掕壊鏈夊摢浜涙寜閽潈闄� * @param classifyId + * @param menuCode + * @param authType * @return */ - public Map<String,Boolean> getAuthButtonList(String classifyId){ - final String roleIds = AuthUtil.getUser().getRoleId(); - // 鍏堟煡璇㈡寜閽甶d鍒楄〃 - LambdaQueryWrapper<ClassifyAuth> wrapper = Wrappers.<ClassifyAuth>query() - .lambda().eq(ClassifyAuth::getClassifyId, classifyId) - .in(ClassifyAuth::getRoleId, roleIds); - List<ClassifyAuth> classifyAuths = this.classifyAuthMapper.selectList(wrapper); - if(classifyAuths.size()>1){ - throw new ServiceException("瑙掕壊鍜屽垎绫婚厤缃瓨鍦ㄥ鏉¤褰曪紝璇疯仈绯荤鐞嗕汉鍛樻竻鐞嗛敊璇厤缃紒"); - } - // 鏄惁涓鸿秴绠� - Boolean isAdmin = VciBaseUtil.checkAdminTenant(); - // 鏈厤缃寜閽潈闄� - if(!isAdmin && (classifyAuths.isEmpty() || Func.isBlank(classifyAuths.get(0).getButtonIds()))){ - return new HashMap<>(); - } - List<String> condition1 = new ArrayList<>(); - // 濡傛灉涓嶆槸瓒呯鐢ㄦ埛 - if(!isAdmin){ - condition1.addAll(Arrays.asList(classifyAuths.get(0).getButtonIds().split(","))); - } - List<Menu> menuList = menuService.getMenuListById(condition1,"1648879284590858241"); + public Map<String,Boolean> getAuthButtonList(String classifyId,String menuCode,String authType){ + List<Menu> menuList = this.getButtonList(classifyId, menuCode, authType); if(menuList.isEmpty()){ return new HashMap<>(); } @@ -116,4 +137,137 @@ return buttonMaps; } + /** + * 鏌ヨ璇ヤ富鏁版嵁涓嬶紝褰撳墠鐧诲綍鐨勮鑹叉湁鍝簺鎸夐挳鑿滃崟鏉冮檺 + * @param classifyId + * @param menuCode + * @param authType + * @return + */ + public List<Menu> getAuthMenuButtonList(String classifyId,String menuCode,String authType){ + List<Menu> buttonList = getButtonList(classifyId, menuCode, authType); + return buttonList; + } + + private List<Menu> getButtonList(String classifyId,String menuCode,String authType){ + if(Func.isBlank(classifyId)){ + throw new ServiceException("蹇呬紶鍙傛暟鍒嗙被oid涓嶈兘涓虹┖锛�"); + } + //鏌ヨ鍒嗙被鑺傜偣鐨勬墍鏈夌埗绾ц妭鐐� + R<List<String>> listR = codeClassifyClient.selectAllParentOid(classifyId); + if (!listR.isSuccess() && !listR.getData().isEmpty()) { + throw new ServiceException("鑾峰彇鍒嗙被淇℃伅澶辫触锛�"); + } + // 杩斿洖鐨勫垎绫籵id鏄綋鍓嶈妭鐐逛负绗竴涓紝鍚庨潰渚濇鏄粬鐨勪笂灞傝妭鐐� + List<String> classifyOidList = listR.getData(); + final List<String> roleIds = Func.toStrList(",",AuthUtil.getUser().getRoleId()); + // 鍏堟煡璇㈡寜閽甶d鍒楄〃 + LambdaQueryWrapper<ClassifyAuth> wrapper = Wrappers.<ClassifyAuth>query() + .lambda().eq(ClassifyAuth::getClassifyId, classifyId) + .eq(ClassifyAuth::getAuthType,authType) + .in(ClassifyAuth::getRoleId, roleIds); + List<ClassifyAuth> classifyAuths = this.classifyAuthMapper.selectList(wrapper); + //濡傛灉褰撳墠鍒嗙被娌℃湁鎵惧埌鎺堟潈閰嶇疆锛屽氨渚濇浠庡綋鍓嶈妭鐐瑰線涓婂眰鑺傜偣鎵炬巿鏉冮厤缃紝鎵惧埌浜嗗氨鍋滄锛屾病鎵惧埌灏变竴鐩存壘鍒版渶鍚� + if(classifyAuths.isEmpty()){ + // 涓嬫爣浠�1寮�濮嬪洜涓哄綋鍓嶈妭鐐�0宸茬粡鏌ヨ杩� + for (int i = 1; i < classifyOidList.size(); i++) { + classifyAuths = this.classifyAuthMapper.selectList( + Wrappers.<ClassifyAuth>query() + .lambda().eq(ClassifyAuth::getClassifyId, classifyOidList.get(i)) + .eq(ClassifyAuth::getAuthType,authType) + .in(ClassifyAuth::getRoleId, roleIds) + ); + //鍙褰撳墠鑺傜偣鐨勪笂灞傝妭鐐逛腑鎵惧埌浜嗗垎绫绘巿鏉冧俊鎭氨涓嶅啀缁х画寰�涓婃壘浜� + if(!classifyAuths.isEmpty()){ + break; + } + } + } + //鍑虹幇浜嗗鏉℃暟鎹� + if(classifyAuths.size()>1){ + // 鏍¢獙鏄惁瀛樺湪閿欒鏁版嵁锛屽悓涓�涓鑹插拰鍚屼竴涓垎绫籭d瀛樺湪澶氭潯鎺堟潈璁板綍 + List<ClassifyAuth> finalClassifyAuths = classifyAuths; + boolean hasDuplicate = classifyAuths.stream() + .anyMatch(auth1 -> finalClassifyAuths.stream() + .filter(auth2 -> auth1 != auth2) + .anyMatch(auth2 -> auth1.getRoleId().equals(auth2.getRoleId()) && auth1.getClassifyId().equals(auth2.getClassifyId()))); + if (hasDuplicate) { + throw new ServiceException("瑙掕壊鍜屽垎绫婚厤缃瓨鍦ㄥ鏉¤褰曪紝璇疯仈绯荤鐞嗕汉鍛樻竻鐞嗛敊璇厤缃紒"); + } + } + // 鏄惁涓鸿秴绠� + Boolean isAdmin = VciBaseUtil.checkAdminTenant(); + // 鏈厤缃寜閽潈闄� + if(!isAdmin && (classifyAuths.isEmpty() || Func.isBlank(classifyAuths.get(0).getButtonIds()))){ + return new ArrayList<>(); + } + List<String> ids = new ArrayList<>(); + // 濡傛灉涓嶆槸瓒呯鐢ㄦ埛 + if(!isAdmin){ + String concatenatedButtonIds = classifyAuths.stream() + .map(ClassifyAuth::getButtonIds) // 鑾峰彇姣忎釜classifyAuths瀵硅薄鐨刡uttonIds + .collect(Collectors.joining(",")); // 鐢ㄩ�楀彿鍒嗛殧鎷兼帴鎴愪竴涓瓧绗︿覆 + ids.addAll(Arrays.asList(concatenatedButtonIds.split(","))); + } + return menuService.getMenuListByCode(ids,menuCode,roleIds); + } + + /** + * 鏍规嵁瑙掕壊id鏌ョ湅鏈夊摢浜涘垎绫诲叿澶囨煡鐪嬫潈闄� + * @param roleIds + * @return + */ + @Override + public List<String> getViewClassByRoleIds(List<String> roleIds,String authType,String buttonCode,String menuCode) { + if(roleIds.isEmpty()){ + return new ArrayList<>(); + } + 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