From 4494a005613728c9dc22d018bca42ef5d3ebcf69 Mon Sep 17 00:00:00 2001
From: xiejun <xiejun@vci-tech.com>
Date: 星期二, 14 一月 2025 20:41:47 +0800
Subject: [PATCH] 产品型号集成,类型转换,人员组织加日志,申请接口引用码段值校验
---
Source/UBCS/ubcs-service/ubcs-system/src/main/java/com/vci/ubcs/system/service/impl/MenuServiceImpl.java | 193 ++++++++++++++++++++++++++++++++++++++++++++---
1 files changed, 178 insertions(+), 15 deletions(-)
diff --git a/Source/UBCS/ubcs-service/ubcs-system/src/main/java/com/vci/ubcs/system/service/impl/MenuServiceImpl.java b/Source/UBCS/ubcs-service/ubcs-system/src/main/java/com/vci/ubcs/system/service/impl/MenuServiceImpl.java
index 7a8879c..764c61d 100644
--- a/Source/UBCS/ubcs-service/ubcs-system/src/main/java/com/vci/ubcs/system/service/impl/MenuServiceImpl.java
+++ b/Source/UBCS/ubcs-service/ubcs-system/src/main/java/com/vci/ubcs/system/service/impl/MenuServiceImpl.java
@@ -16,20 +16,22 @@
*/
package com.vci.ubcs.system.service.impl;
+import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
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.util.MybatisParameterUtil;
+import com.vci.ubcs.starter.web.util.VciBaseUtil;
import com.vci.ubcs.system.cache.NacosConfigCache;
import com.vci.ubcs.system.cache.SysCache;
import com.vci.ubcs.system.dto.MenuDTO;
import com.vci.ubcs.system.entity.*;
+import com.vci.ubcs.system.mapper.ClassifyAuthMapper;
+import com.vci.ubcs.system.service.*;
import com.vci.ubcs.system.vo.MenuVO;
import com.vci.ubcs.system.mapper.MenuMapper;
-import com.vci.ubcs.system.service.IMenuService;
-import com.vci.ubcs.system.service.IRoleMenuService;
-import com.vci.ubcs.system.service.IRoleScopeService;
-import com.vci.ubcs.system.service.ITopMenuSettingService;
import com.vci.ubcs.system.wrapper.MenuWrapper;
import lombok.AllArgsConstructor;
import org.springblade.core.log.exception.ServiceException;
@@ -65,13 +67,16 @@
private final IRoleMenuService roleMenuService;
private final IRoleScopeService roleScopeService;
+ private final MenuMapper menuMapper;
private final ITopMenuSettingService topMenuSettingService;
+ private final ICodeClassifyClient codeClassifyClient;
+ private final ClassifyAuthMapper classifyAuthMapper;
private final static String PARENT_ID = "parentId";
private final static Integer MENU_CATEGORY = 1;
- private final NacosConfigCache nacosConfigCache;
@Override
public List<MenuVO> lazyList(Long parentId, Map<String, Object> param) {
+ //int i = 1 / 0;
if (Func.isEmpty(Func.toStr(param.get(PARENT_ID)))) {
parentId = null;
}
@@ -86,7 +91,6 @@
return baseMapper.lazyMenuPage(parentId, param, Condition.getPage(query));
}
-
@Override
public List<MenuVO> routes(String roleId, Long topMenuId) {
if (StringUtil.isBlank(roleId)) {
@@ -95,11 +99,11 @@
List<Menu> allMenus = baseMapper.allMenu();
List<Menu> roleMenus;
// 瓒呯骇绠$悊鍛樺苟涓斾笉鏄《閮ㄨ彍鍗曡姹傚垯杩斿洖鍏ㄩ儴鑿滃崟
- if (AuthUtil.isAdministrator() && Func.isEmpty(topMenuId)) {
+ if (VciBaseUtil.checkAdminTenant() && Func.isEmpty(topMenuId)) {
roleMenus = allMenus;
}
// 闈炶秴绾х鐞嗗憳骞朵笖涓嶆槸椤堕儴鑿滃崟璇锋眰鍒欒繑鍥炲搴旇鑹叉潈闄愯彍鍗�
- else if (!AuthUtil.isAdministrator() && Func.isEmpty(topMenuId)) {
+ else if (!VciBaseUtil.checkAdminTenant() && Func.isEmpty(topMenuId)) {
roleMenus = tenantPackageMenu(baseMapper.roleMenuByRoleId(Func.toLongList(roleId)));
}
// 椤堕儴鑿滃崟璇锋眰杩斿洖瀵瑰簲瑙掕壊鏉冮檺鑿滃崟
@@ -138,7 +142,7 @@
@Override
public List<MenuVO> buttons(String roleId) {
- List<Menu> buttons = (AuthUtil.isAdministrator()) ? baseMapper.allButtons() : baseMapper.buttons(Func.toLongList(roleId));
+ List<Menu> buttons = (VciBaseUtil.checkAdminTenant()) ? baseMapper.allButtons() : baseMapper.buttons(Func.toLongList(roleId));
MenuWrapper menuWrapper = new MenuWrapper();
return menuWrapper.listNodeVO(buttons);
}
@@ -150,13 +154,28 @@
@Override
public List<TreeNode> grantTree(BladeUser user) {
- List<TreeNode> menuTree = user.getTenantId().equals(nacosConfigCache.getAdminUserInfo().getTenantId()) ? baseMapper.grantTree() : baseMapper.grantTreeByRole(Func.toLongList(user.getRoleId()));
+ /*List<TreeNode> menuTree = user.getTenantId().equals(nacosConfigCache.getAdminUserInfo().getTenantId())
+ && user.getUserId().equals(nacosConfigCache.getAdminUserInfo().getUserId())
+ ? baseMapper.grantTree() : baseMapper.grantTreeByRole(Func.toLongList(user.getRoleId()));*/
+ // 淇敼涓烘墍鏈夌敤鎴烽兘鑳芥煡璇㈡墍鏈夛紝鍥犱负娌℃潈闄愮殑鐢ㄦ埛涓嶅叿澶囪繖涓彍鍗曢〉闈㈢殑鏉冮檺锛屼篃灏辨病蹇呰闄愬埗鐢ㄦ埛鏌ヨ嚜宸辩殑
+ List<TreeNode> menuTree = baseMapper.grantTree();
return ForestNodeMerger.merge(tenantPackageTree(menuTree, user.getTenantId()));
+ }
+
+ /**
+ * 鏍规嵁瑙掕壊id鑾峰彇鑿滃崟鏍戝舰缁撴瀯
+ * @param roleId
+ * @return
+ */
+ @Override
+ public List<TreeNode> grantTreeByRoleIds(List<Long> roleId) {
+ List<TreeNode> menuTree = baseMapper.grantTreeByRole(roleId);
+ return ForestNodeMerger.merge(menuTree);
}
@Override
public List<TreeNode> grantTopTree(BladeUser user) {
- List<TreeNode> menuTree = user.getTenantId().equals(nacosConfigCache.getAdminUserInfo().getTenantId()) ? baseMapper.grantTopTree() : baseMapper.grantTopTreeByRole(Func.toLongList(user.getRoleId()));
+ List<TreeNode> menuTree = user.getTenantId().equals(NacosConfigCache.getAdminUserInfo().getTenantId()) ? baseMapper.grantTopTree() : baseMapper.grantTopTreeByRole(Func.toLongList(user.getRoleId()));
return ForestNodeMerger.merge(tenantPackageTree(menuTree, user.getTenantId()));
}
@@ -209,6 +228,7 @@
* 绉熸埛鑿滃崟鏉冮檺鑷畾涔夌瓫閫�
*/
private List<Menu> tenantPackageMenu(List<Menu> menu) {
+ // 绉熸埛鍖呴厤缃煡璇�
TenantPackage tenantPackage = SysCache.getTenantPackage(AuthUtil.getTenantId());
if (Func.isNotEmpty(tenantPackage) && tenantPackage.getId() > 0L) {
List<Long> menuIds = Func.toLongList(tenantPackage.getMenuId());
@@ -219,12 +239,12 @@
@Override
public List<TreeNode> grantDataScopeTree(BladeUser user) {
- return ForestNodeMerger.merge(user.getTenantId().equals(nacosConfigCache.getAdminUserInfo().getTenantId()) ? baseMapper.grantDataScopeTree() : baseMapper.grantDataScopeTreeByRole(Func.toLongList(user.getRoleId())));
+ return ForestNodeMerger.merge(user.getTenantId().equals(NacosConfigCache.getAdminUserInfo().getTenantId()) ? baseMapper.grantDataScopeTree() : baseMapper.grantDataScopeTreeByRole(Func.toLongList(user.getRoleId())));
}
@Override
public List<TreeNode> grantApiScopeTree(BladeUser user) {
- return ForestNodeMerger.merge(user.getTenantId().equals(nacosConfigCache.getAdminUserInfo().getTenantId()) ? baseMapper.grantApiScopeTree() : baseMapper.grantApiScopeTreeByRole(Func.toLongList(user.getRoleId())));
+ return ForestNodeMerger.merge(user.getTenantId().equals(NacosConfigCache.getAdminUserInfo().getTenantId()) ? baseMapper.grantApiScopeTree() : baseMapper.grantApiScopeTreeByRole(Func.toLongList(user.getRoleId())));
}
@Override
@@ -304,10 +324,123 @@
return saveOrUpdate(menu);
}
+ /**
+ * 鑾峰彇鑿滃崟涓嬮潰鐨勬寜閽紝鍒贡璋冪敤锛岃繖涓柟娉曟槸閽堝涓绘暟鎹鐞嗘寜閽煡璇㈢殑
+ * @param classifyId
+ * @param btmType 涓氬姟绫诲瀷
+ * @param authType
+ * @return
+ */
@Override
- public List<Menu> getMenuButtonByType(String btmType) {
- return baseMapper.selectMenuChildByBtnType(btmType);
+ //@Cacheable(cacheNames = MENU_CACHE, key = "'auth:menuButton:'+ #btmType +':'+ #userId ")
+ public List<Menu> getMenuButtonByType(String classifyId,String btmType,String authType) {
+ // baseMapper.selectMenuChildByBtnType(btmType,roleIds);
+ 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 = classifyAuthMapper.selectList(wrapper);
+ //濡傛灉褰撳墠鍒嗙被娌℃湁鎵惧埌鎺堟潈閰嶇疆锛屽氨渚濇浠庡綋鍓嶈妭鐐瑰線涓婂眰鑺傜偣鎵炬巿鏉冮厤缃紝鎵惧埌浜嗗氨鍋滄锛屾病鎵惧埌灏变竴鐩存壘鍒版渶鍚�
+ if(classifyAuths.isEmpty()){
+ // 涓嬫爣浠�1寮�濮嬪洜涓哄綋鍓嶈妭鐐�0宸茬粡鏌ヨ杩�
+ for (int i = 1; i < classifyOidList.size(); i++) {
+ classifyAuths = 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 this.getMenuListByCode(ids,btmType,roleIds);
}
+
+ /**
+ * 鏍规嵁code鏌ヨ鑿滃崟淇℃伅
+ * @param codes
+ * @param userId
+ * @return
+ */
+ @Override
+ public List<Menu> getMenuByCodes(List<String> codes,Long userId) {
+ if(codes.isEmpty()){
+ return new ArrayList<>();
+ }
+ // 鏌ヨ鑿滃崟淇℃伅
+ LambdaQueryWrapper<Menu> wrapper = Wrappers.<Menu>query()
+ .lambda()
+ .in(Menu::getCode, codes)
+ .eq(Menu::getIsDeleted,BladeConstant.DB_NOT_DELETED) /*鏈鍒犻櫎*/
+ .eq(Menu::getCategory,1) /*鑿滃崟绫诲瀷涓嶈兘涓烘寜閽�*/
+ .orderByAsc(Menu::getCode); /*鏍规嵁code鎺掑簭涓巆lassify鐨刡tmtypeid瀵瑰簲*/
+ // 瓒呯涓嶇敤鏍规嵁瑙掕壊鏉ユ煡璇�
+ if(!VciBaseUtil.checkAdminTenant()){
+ if(Func.isBlank(userId.toString()) && Func.isBlank(AuthUtil.getUserId().toString())){
+ throw new ServiceException("鑾峰彇鐢ㄦ埛id澶辫触");
+ }
+ List<Long> menuIds = roleMenuService.getMenuIdByUserId(userId);
+ if(menuIds.isEmpty()){
+ return new ArrayList<>();
+ }
+ if(menuIds.size()>=1000){
+ MybatisParameterUtil.cutInParameter(wrapper,Menu::getId,menuIds);
+ }else {
+ wrapper.in(Menu::getId,menuIds);
+ }
+ }
+ return this.list(wrapper);
+ }
+
+ /**
+ * 鏍规嵁鐖剁骇鑿滃崟鐨刢ode鏌ヨ鎸夐挳淇℃伅
+ * @param code
+ * @return
+ */
+ @Override
+ public List<Menu> getButtonByParentCode(String code) {
+ return menuMapper.getButtonsByRoleIdAndCode(null,code);
+ }
/**
* 瀵筀eepAlive鍊艰浆鎹㈡垚甯冨皵绫诲瀷杩涜灏佽
@@ -365,4 +498,34 @@
return this.saveBatch(newButtons) ? R.success("鎸夐挳鍏嬮殕鎴愬姛锛�"):R.fail("鎸夐挳鍏嬮殕澶辫触锛�");
}
+ /**
+ * 鏍规嵁涓婚敭鑾峰彇鑿滃崟淇℃伅
+ * @param ids
+ * @param menuCode
+ * @param roleIds
+ * @return
+ */
+ @Override
+ public List<Menu> getMenuListByCode(List<String> ids,String menuCode,List<String> roleIds){
+ List<Menu> menuButtonList = null;
+ if(VciBaseUtil.checkAdminTenant()){
+ // 姝e父鎯呭喌涓嬫潵璇磋繖涓笉瀛樺湪涓虹┖鐨勬儏鍐�
+ // 鏌ヨ璇ヨ彍鍗曚笅鐨勬墍鏈夋寜閽�
+ menuButtonList = menuMapper.getButtonByIdsOrByParentCode(null, menuCode, null);
+ }else {
+ menuButtonList = menuMapper.getButtonByIdsOrByParentCode(roleIds,null,ids);
+ }
+ return menuButtonList;
+ }
+
+ /**
+ * 鏍规嵁瑙掕壊id鑾峰彇宸叉巿鏉冪殑鎸夐挳淇℃伅
+ * @param roleId
+ * @return
+ */
+ @Override
+ public List<Menu> getButtonsByRoleId(String roleId, String menuCode) {
+ return menuMapper.getButtonsByRoleIdAndCode(roleId,menuCode);
+ }
+
}
--
Gitblit v1.9.3