mirror of
http://192.168.1.205:9980/cf_devdept2/cf_imes_server.git
synced 2026-08-13 21:32:07 +08:00
1、线程池bean命名规范;2、菜单管理controller、service单元测试完善;3、已有controller单测替换mock static SecurityFrameworkUtils;
This commit is contained in:
+32
@@ -0,0 +1,32 @@
|
||||
package com.cf.imes.module.system.framework.executor.config;
|
||||
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
|
||||
|
||||
import java.util.concurrent.ThreadPoolExecutor;
|
||||
|
||||
/**
|
||||
* system服务线程池配置
|
||||
*
|
||||
* @author Gqr
|
||||
* @since 2026/1/26 14:29
|
||||
*/
|
||||
@Configuration(proxyBeanMethods = false)
|
||||
public class SystemThreadPoolConfiguration {
|
||||
public static final String SYSTEM_PERMISSION_THREAD_POOL_TASK_EXECUTOR = "systemPermissionThreadPoolTaskExecutor";
|
||||
|
||||
@Bean("systemPermissionThreadPoolTaskExecutor")
|
||||
public ThreadPoolTaskExecutor systemPermissionThreadPoolTaskExecutor() {
|
||||
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
|
||||
executor.setCorePoolSize(8); // 设置核心线程数
|
||||
executor.setMaxPoolSize(8); // 设置最大线程数
|
||||
executor.setKeepAliveSeconds(60); // 设置空闲时间
|
||||
executor.setQueueCapacity(100); // 设置队列大小
|
||||
executor.setThreadNamePrefix("system-permission-Executor-"); // 配置线程池的前缀
|
||||
executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
|
||||
// 进行加载
|
||||
executor.initialize();
|
||||
return executor;
|
||||
}
|
||||
}
|
||||
+28
-26
@@ -36,6 +36,7 @@ import org.springframework.context.annotation.Lazy;
|
||||
import org.springframework.data.redis.core.Cursor;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.data.redis.core.ScanOptions;
|
||||
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
@@ -53,6 +54,7 @@ import java.util.stream.IntStream;
|
||||
|
||||
import static com.cf.imes.framework.common.util.collection.CollectionUtils.convertList;
|
||||
import static com.cf.imes.module.system.enums.ErrorCodeConstants.*;
|
||||
import static com.cf.imes.module.system.framework.executor.config.SystemThreadPoolConfiguration.SYSTEM_PERMISSION_THREAD_POOL_TASK_EXECUTOR;
|
||||
|
||||
/**
|
||||
* 菜单 Service 实现
|
||||
@@ -80,6 +82,8 @@ public class MenuServiceImpl implements MenuService {
|
||||
@Resource
|
||||
private TransProperties transProperties;
|
||||
|
||||
@Resource(name = SYSTEM_PERMISSION_THREAD_POOL_TASK_EXECUTOR)
|
||||
private ThreadPoolTaskExecutor threadPoolTaskExecutor;
|
||||
|
||||
private static final String FIELD_CHARACTER = ":*:%s";
|
||||
|
||||
@@ -167,7 +171,7 @@ public class MenuServiceImpl implements MenuService {
|
||||
* @param sourceType
|
||||
*/
|
||||
private void validateManageSourceTypeOperatePermission(Integer sourceType) {
|
||||
if (!SecurityFrameworkUtils.isCfOrg() && sourceType.equals(MenuSourceTypeEnum.MANAGEMENT.getType())) {
|
||||
if (!SecurityFrameworkUtils.isCfOrg() && MenuSourceTypeEnum.MANAGEMENT.getType().equals(sourceType)) {
|
||||
throw new ServiceException(MANAGEMENT_MENU_OPERATION_PERMISSION_ERROR);
|
||||
}
|
||||
}
|
||||
@@ -181,33 +185,32 @@ public class MenuServiceImpl implements MenuService {
|
||||
*/
|
||||
private void flushCacheWhenOperateMenu(Long menuId, String newPermission, String oldPermission) {
|
||||
CompletableFuture.runAsync(() -> {
|
||||
if (ObjectUtil.isNotNull(oldPermission)) {
|
||||
// 移除 USER_ROLE_ID_LIST:*:旧的permission
|
||||
String oldMenuPerPattern = String.format(String.valueOf(new StringBuffer(RedisKeyConstants.PERMISSION_MENU_ID_LIST).append(FIELD_CHARACTER)), oldPermission);
|
||||
Long oldBatchDelPerNum = scanAndDelKeys(oldMenuPerPattern);
|
||||
log.info("[updateMenu] 批量删除redis[{}]数量:{}", oldMenuPerPattern, oldBatchDelPerNum);
|
||||
}
|
||||
try {
|
||||
if (ObjectUtil.isNotNull(oldPermission)) {
|
||||
// 移除 USER_ROLE_ID_LIST:*:旧的permission
|
||||
String oldMenuPerPattern = String.format(String.valueOf(new StringBuffer(RedisKeyConstants.PERMISSION_MENU_ID_LIST).append(FIELD_CHARACTER)), oldPermission);
|
||||
Long oldBatchDelPerNum = scanAndDelKeys(oldMenuPerPattern);
|
||||
log.info("[updateMenu] 批量删除redis[{}]数量:{}", oldMenuPerPattern, oldBatchDelPerNum);
|
||||
}
|
||||
|
||||
if (ObjectUtil.isNotNull(newPermission)) {
|
||||
// 移除 USER_ROLE_ID_LIST:*:新的permission
|
||||
String newMenuPerPattern = String.format(String.valueOf(new StringBuffer(RedisKeyConstants.PERMISSION_MENU_ID_LIST).append(FIELD_CHARACTER)), newPermission);
|
||||
Long newBatchDelPerNum = scanAndDelKeys(newMenuPerPattern);
|
||||
log.info("[updateMenu] 批量删除redis[{}]数量:{}", newMenuPerPattern, newBatchDelPerNum);
|
||||
}
|
||||
if (ObjectUtil.isNotNull(newPermission)) {
|
||||
// 移除 USER_ROLE_ID_LIST:*:新的permission
|
||||
String newMenuPerPattern = String.format(String.valueOf(new StringBuffer(RedisKeyConstants.PERMISSION_MENU_ID_LIST).append(FIELD_CHARACTER)), newPermission);
|
||||
Long newBatchDelPerNum = scanAndDelKeys(newMenuPerPattern);
|
||||
log.info("[updateMenu] 批量删除redis[{}]数量:{}", newMenuPerPattern, newBatchDelPerNum);
|
||||
}
|
||||
|
||||
if (ObjectUtil.isNotNull(menuId)) {
|
||||
// 移除 MENU_ROLE_ID_LIST:*:menuId
|
||||
String menuRolePattern = String.format(String.valueOf(new StringBuffer(RedisKeyConstants.MENU_ROLE_ID_LIST).append(FIELD_CHARACTER)), menuId);
|
||||
Long batchDelRoleNum = scanAndDelKeys(menuRolePattern);
|
||||
log.info("[deleteMenu] 批量删除redis[{}]数量:{}", menuRolePattern, batchDelRoleNum);
|
||||
}
|
||||
|
||||
// 清空本地缓存
|
||||
redisTemplate.convertAndSend(com.cf.imes.framework.redis.constants.RedisKeyConstants.PERMISSION_REFRESH, "");
|
||||
}).exceptionally(e -> {
|
||||
log.error("[deleteMenu] redis 清空PERMISSION_MENU_ID_LIST或message发送失败, topic:{}, 异常:{}", com.cf.imes.framework.redis.constants.RedisKeyConstants.PERMISSION_REFRESH, e);
|
||||
return null;
|
||||
});
|
||||
// 清空本地缓存
|
||||
redisTemplate.convertAndSend(com.cf.imes.framework.redis.constants.RedisKeyConstants.PERMISSION_REFRESH, "");
|
||||
} catch (Exception e) {
|
||||
log.error("[deleteMenu] redis 清空PERMISSION_MENU_ID_LIST或message发送失败, topic:{}, 异常:{}", com.cf.imes.framework.redis.constants.RedisKeyConstants.PERMISSION_REFRESH, e);
|
||||
}
|
||||
}, threadPoolTaskExecutor);
|
||||
}
|
||||
|
||||
|
||||
@@ -263,7 +266,7 @@ public class MenuServiceImpl implements MenuService {
|
||||
|
||||
@Override
|
||||
public List<MenuDO> getMenuList(Collection<Long> ids) {
|
||||
return menuMapper.selectBatchIds(ids);
|
||||
return menuMapper.selectByIds(ids);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -272,7 +275,7 @@ public class MenuServiceImpl implements MenuService {
|
||||
if(CollUtil.isEmpty(ids)) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
return menuMapper.selectBatchIds(ids);
|
||||
return menuMapper.selectByIds(ids);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -300,8 +303,7 @@ public class MenuServiceImpl implements MenuService {
|
||||
throw new ServiceException(MENU_PARENT_NOT_EXISTS);
|
||||
}
|
||||
// 父菜单必须是目录或者菜单类型
|
||||
if (!MenuTypeEnum.DIR.getType().equals(menu.getType())
|
||||
&& !MenuTypeEnum.MENU.getType().equals(menu.getType())) {
|
||||
if (MenuTypeEnum.BUTTON.getType().equals(menu.getType())) {
|
||||
throw new ServiceException(MENU_PARENT_NOT_DIR_OR_MENU);
|
||||
}
|
||||
}
|
||||
@@ -407,7 +409,7 @@ public class MenuServiceImpl implements MenuService {
|
||||
String src = item.getString("src");
|
||||
String dst = item.getString("dst");
|
||||
|
||||
if (menuDO == null || !menuDO.getName().equals(UnicodeUtil.toString(src))) {
|
||||
if (!menuDO.getName().equals(UnicodeUtil.toString(src))) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user