From 633d328380d7788740d3eba54b33aa69dc9afb02 Mon Sep 17 00:00:00 2001 From: ludc Date: 星期四, 25 一月 2024 22:14:38 +0800 Subject: [PATCH] 点击分类不显示按钮(模板创建时绑定的业务类型id有问题):改成用functionid进行查询,也就是菜单上配置的id --- Source/UBCS/ubcs-service/ubcs-system/src/main/java/com/vci/ubcs/system/service/impl/ClassifyAuthServiceImpl.java | 79 ++++++++++++++++++++++++++++----------- 1 files changed, 57 insertions(+), 22 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 72cf41b..7bdaf05 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 @@ -2,10 +2,12 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; +import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; 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; @@ -19,6 +21,8 @@ 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.context.annotation.Lazy; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -26,7 +30,7 @@ import java.util.stream.Collectors; /** - * 鍒嗙被鎺堟潈 + * 鍒嗙被鎺堟潈,鏁版嵁鎺堟潈 * @author ludc * @date 2023/12/25 15:35 */ @@ -42,17 +46,28 @@ /** * 鍒嗙被鎺堟潈淇濆瓨鎺ュ彛 - * @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()) + ); + return R.success("鎺堟潈鍒楄〃娓呯┖鎴愬姛"); + } + + if(!classifyAuthListDTO.getIsCLear() && classifyAuthListDTO.getClassifyAuthList().isEmpty()){ R.fail("鎺堟潈鍒楄〃涓嶈兘涓虹┖锛�"); } // 鍒ら噸锛屾煡鐪嬫槸鍚﹀瓨鍦ㄥ悓涓�涓猚lassid涓嬮厤缃簡鐩稿悓鐨勮鑹� - Map<String, Long> roleidCounts = classifyAuthList.stream() + Map<String, Long> roleidCounts = classifyAuthListDTO.getClassifyAuthList().stream() .collect(Collectors.groupingBy(ClassifyAuth::getRoleId, Collectors.counting())); // 妫�鏌ユ槸鍚︽湁roleid鍑虹幇娆℃暟澶т簬1鐨勬儏鍐� @@ -63,17 +78,17 @@ } // 濡傛灉浼犺繃鏉ョ殑闆嗗悎涓鍒嗙被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()) .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())); } /** @@ -87,7 +102,8 @@ 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 new ArrayList<ClassifyAuthVO>(); @@ -98,9 +114,33 @@ /** * 鏌ヨ璇ュ垎绫讳笅锛屽綋鍓嶇櫥褰曠殑瑙掕壊鏈夊摢浜涙寜閽潈闄� * @param classifyId + * @param menuCode + * @param authType * @return */ - public Map<String,Boolean> getAuthButtonList(String classifyId){ + 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<>(); + } + Map<String, Boolean> buttonMaps = menuList.stream() + .collect(Collectors.toMap(Menu::getCode, menu -> true)); + 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涓嶈兘涓虹┖锛�"); } @@ -115,6 +155,7 @@ // 鍏堟煡璇㈡寜閽甶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); //濡傛灉褰撳墠鍒嗙被娌℃湁鎵惧埌鎺堟潈閰嶇疆锛屽氨渚濇浠庡綋鍓嶈妭鐐瑰線涓婂眰鑺傜偣鎵炬巿鏉冮厤缃紝鎵惧埌浜嗗氨鍋滄锛屾病鎵惧埌灏变竴鐩存壘鍒版渶鍚� @@ -139,20 +180,14 @@ Boolean isAdmin = VciBaseUtil.checkAdminTenant(); // 鏈厤缃寜閽潈闄� if(!isAdmin && (classifyAuths.isEmpty() || Func.isBlank(classifyAuths.get(0).getButtonIds()))){ - return new HashMap<>(); + return new ArrayList<>(); } - List<String> condition1 = new ArrayList<>(); + List<String> ids = new ArrayList<>(); // 濡傛灉涓嶆槸瓒呯鐢ㄦ埛 if(!isAdmin){ - condition1.addAll(Arrays.asList(classifyAuths.get(0).getButtonIds().split(","))); + ids.addAll(Arrays.asList(classifyAuths.get(0).getButtonIds().split(","))); } - List<Menu> menuList = menuService.getMenuListById(condition1,"1648879284590858241"); - if(menuList.isEmpty()){ - return new HashMap<>(); - } - Map<String, Boolean> buttonMaps = menuList.stream() - .collect(Collectors.toMap(Menu::getCode, menu -> true)); - return buttonMaps; + return menuService.getMenuListByCode(ids,menuCode,roleIds); } /** @@ -161,11 +196,11 @@ * @return */ @Override - public List<String> getViewClassByRoleIds(List<String> roleIds) { + public List<String> getViewClassByRoleIds(List<String> roleIds,String authType,String buttonCode,String menuCode) { if(roleIds.isEmpty()){ return new ArrayList<>(); } - return this.classifyAuthMapper.getViewClassByRoleIds(roleIds); + return this.classifyAuthMapper.getViewClassByRoleIds(roleIds, authType,buttonCode,menuCode); } } -- Gitblit v1.9.3