♻️ Refactoring code. 简化租户套餐维护功能,删除 sys_tenant_menu表
This commit is contained in:
1 parent
8b123902b2
commit
2e90388a4f
9 files changed
+117
-278
No files matched your search
+1
-25
@@ -1100,7 +1100,7 @@ CREATE TABLE `sys_tenant` (
|
||||
`update_by` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL DEFAULT ' ' COMMENT '修改人',
|
||||
`create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
|
||||
`update_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
|
||||
`menu_id` bigint(20) DEFAULT NULL COMMENT '菜单ID',
|
||||
`menu_id` text CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci COMMENT '租户菜单ID',
|
||||
PRIMARY KEY (`id`) USING BTREE
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci ROW_FORMAT=DYNAMIC COMMENT='租户表';
|
||||
|
||||
@@ -1112,30 +1112,6 @@ INSERT INTO `sys_tenant` VALUES (1, '北京分公司', '1', '', NULL, NULL, NULL
|
||||
COMMIT;
|
||||
|
||||
|
||||
-- ----------------------------
|
||||
-- Table structure for sys_tenant_menu
|
||||
-- ----------------------------
|
||||
DROP TABLE IF EXISTS `sys_tenant_menu`;
|
||||
CREATE TABLE `sys_tenant_menu` (
|
||||
`id` bigint(20) NOT NULL,
|
||||
`name` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '租户菜单名称',
|
||||
`menu_ids` text CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '菜单id集合',
|
||||
`status` char(1) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL DEFAULT '0' COMMENT '租户菜单,9:冻结,0:正常',
|
||||
`del_flag` char(1) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT '0',
|
||||
`create_by` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL DEFAULT ' ' COMMENT '创建人',
|
||||
`update_by` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL DEFAULT ' ' COMMENT '修改人',
|
||||
`create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建',
|
||||
`update_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
|
||||
PRIMARY KEY (`id`) USING BTREE
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci ROW_FORMAT=DYNAMIC;
|
||||
|
||||
-- ----------------------------
|
||||
-- Records of sys_tenant_menu
|
||||
-- ----------------------------
|
||||
BEGIN;
|
||||
INSERT INTO `sys_tenant_menu` VALUES (1642752536722997250, '基础功能', '1000,1100,1101,1102,1103,1104,1200,1201,1202,1203,1300,1301,1302,1303,1304,1305,1400,1401,1402,1403,1404,1600,1601,1602,1603,1604,1605,1500,1501,1508,1502,1504,1505,1506,1507,1503,2000,2001,2103,2104,2105,2100,2101,2102,2200,2201,2202,2203,2906,2907,2210,2211,2212,2213,2800,2810,2820,2830,2840,2850,2860,2870,2871,2900,2901,2902,2903,2904,2905,2400,2401,2402,2403,2500,2501,2502,2503,2600,2601', '0', '0', 'admin', ' ', '2023-04-03 12:55:00', '2023-04-03 04:55:00');
|
||||
COMMIT;
|
||||
|
||||
-- ----------------------------
|
||||
-- Table structure for sys_user
|
||||
-- ----------------------------
|
||||
|
||||
-80
@@ -1,80 +0,0 @@
|
||||
package com.pig4cloud.pigx.admin.api.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.*;
|
||||
import com.baomidou.mybatisplus.extension.activerecord.Model;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* 租户菜单
|
||||
*/
|
||||
@Data
|
||||
@Schema(description = "租户菜单")
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public class SysTenantMenu extends Model<SysTenantMenu> {
|
||||
|
||||
/**
|
||||
* id
|
||||
*/
|
||||
@TableId(type = IdType.ASSIGN_ID)
|
||||
@Schema(description = "id")
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 租户菜单名称
|
||||
*/
|
||||
@Schema(description = "租户菜单名称")
|
||||
private String name;
|
||||
|
||||
/**
|
||||
* 菜单id集合
|
||||
*/
|
||||
@Schema(description = "菜单id集合")
|
||||
private String menuIds;
|
||||
|
||||
/**
|
||||
* 0正常 9-冻结
|
||||
*/
|
||||
@Schema(description = "租户菜单,9:冻结,0:正常")
|
||||
private String status;
|
||||
|
||||
/**
|
||||
* 创建人
|
||||
*/
|
||||
@TableField(fill = FieldFill.INSERT)
|
||||
@Schema(description = "创建人")
|
||||
private String createBy;
|
||||
|
||||
/**
|
||||
* 修改人
|
||||
*/
|
||||
@TableField(fill = FieldFill.UPDATE)
|
||||
@Schema(description = "修改人")
|
||||
private String updateBy;
|
||||
|
||||
/**
|
||||
* 删除标记
|
||||
*/
|
||||
@TableLogic
|
||||
@TableField(fill = FieldFill.INSERT)
|
||||
@Schema(description = "删除标记,1:已删除,0:正常")
|
||||
private String delFlag;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
@TableField(fill = FieldFill.INSERT)
|
||||
@Schema(description = "创建时间")
|
||||
private LocalDateTime createTime;
|
||||
|
||||
/**
|
||||
* 更新时间
|
||||
*/
|
||||
@TableField(fill = FieldFill.UPDATE)
|
||||
@Schema(description = "更新时间")
|
||||
private LocalDateTime updateTime;
|
||||
|
||||
}
|
||||
+23
-4
@@ -18,13 +18,18 @@
|
||||
package com.pig4cloud.pigx.admin.controller;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.lang.tree.Tree;
|
||||
import cn.hutool.core.util.ArrayUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.pig4cloud.pigx.admin.api.entity.SysTenant;
|
||||
import com.pig4cloud.pigx.admin.service.SysMenuService;
|
||||
import com.pig4cloud.pigx.admin.service.SysTenantService;
|
||||
import com.pig4cloud.pigx.common.core.constant.CacheConstants;
|
||||
import com.pig4cloud.pigx.common.core.util.R;
|
||||
import com.pig4cloud.pigx.common.data.resolver.ParamResolver;
|
||||
import com.pig4cloud.pigx.common.data.tenant.TenantBroker;
|
||||
import com.pig4cloud.pigx.common.excel.annotation.ResponseExcel;
|
||||
import com.pig4cloud.pigx.common.log.annotation.SysLog;
|
||||
import com.pig4cloud.pigx.common.security.annotation.Inner;
|
||||
@@ -38,6 +43,7 @@ import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@@ -56,6 +62,8 @@ public class SysTenantController {
|
||||
|
||||
private final SysTenantService sysTenantService;
|
||||
|
||||
private final SysMenuService sysMenuService;
|
||||
|
||||
/**
|
||||
* 分页查询
|
||||
* @param page 分页对象
|
||||
@@ -109,9 +117,8 @@ public class SysTenantController {
|
||||
@SysLog("修改租户")
|
||||
@PutMapping
|
||||
@PreAuthorize("@pms.hasPermission('sys_systenant_edit')")
|
||||
@CacheEvict(value = CacheConstants.TENANT_DETAILS, allEntries = true)
|
||||
public R updateById(@RequestBody SysTenant sysTenant) {
|
||||
return R.ok(sysTenantService.updateById(sysTenant));
|
||||
return R.ok(sysTenantService.updateTenant(sysTenant));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -151,8 +158,20 @@ public class SysTenantController {
|
||||
@ResponseExcel
|
||||
@GetMapping("/export")
|
||||
@PreAuthorize("@pms.hasPermission('sys_systenant_export')")
|
||||
public List<SysTenant> export(SysTenant sysTenant) {
|
||||
return sysTenantService.list(Wrappers.query(sysTenant));
|
||||
public List<SysTenant> export(SysTenant sysTenant, Long[] ids) {
|
||||
return sysTenantService
|
||||
.list(Wrappers.lambdaQuery(sysTenant).in(ArrayUtil.isNotEmpty(ids), SysTenant::getId, ids));
|
||||
}
|
||||
|
||||
@GetMapping(value = "/tree/menu")
|
||||
public R getTree() {
|
||||
Long defaultId = ParamResolver.getLong("TENANT_DEFAULT_ID", 1L);
|
||||
List<Tree<Long>> trees = new ArrayList<>();
|
||||
TenantBroker.runAs(defaultId, (id) -> {
|
||||
trees.addAll(sysMenuService.treeMenu(null, null, null));
|
||||
});
|
||||
|
||||
return R.ok(trees);
|
||||
}
|
||||
|
||||
}
|
||||
-122
@@ -1,122 +0,0 @@
|
||||
package com.pig4cloud.pigx.admin.controller;
|
||||
|
||||
import cn.hutool.core.lang.tree.Tree;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.pig4cloud.pigx.admin.api.entity.SysTenantMenu;
|
||||
import com.pig4cloud.pigx.admin.service.SysMenuService;
|
||||
import com.pig4cloud.pigx.admin.service.SysTenantMenuService;
|
||||
import com.pig4cloud.pigx.common.core.constant.CacheConstants;
|
||||
import com.pig4cloud.pigx.common.core.constant.CommonConstants;
|
||||
import com.pig4cloud.pigx.common.core.util.R;
|
||||
import com.pig4cloud.pigx.common.data.resolver.ParamResolver;
|
||||
import com.pig4cloud.pigx.common.data.tenant.TenantBroker;
|
||||
import com.pig4cloud.pigx.common.log.annotation.SysLog;
|
||||
import com.pig4cloud.pigx.common.security.annotation.Inner;
|
||||
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springdoc.core.annotations.ParameterObject;
|
||||
import org.springframework.cache.annotation.CacheEvict;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@RestController
|
||||
@RequiredArgsConstructor
|
||||
@RequestMapping("/tenant-menu")
|
||||
@Tag(description = "tenant", name = "租户菜单管理")
|
||||
@SecurityRequirement(name = HttpHeaders.AUTHORIZATION)
|
||||
public class SysTenantMenuController {
|
||||
|
||||
private final SysTenantMenuService sysTenantMenuService;
|
||||
|
||||
private final SysMenuService sysMenuService;
|
||||
|
||||
/**
|
||||
* 分页查询
|
||||
* @param page 分页对象
|
||||
* @param sysTenantMenu 租户菜单
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/page")
|
||||
public R getSysTenantPage(@ParameterObject Page page, @ParameterObject SysTenantMenu sysTenantMenu) {
|
||||
return R.ok(sysTenantMenuService.page(page, Wrappers.query(sysTenantMenu)));
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询租户信息
|
||||
* @param sysTenantMenu 查询条件
|
||||
* @return 租户信息
|
||||
*/
|
||||
@GetMapping
|
||||
public R getByObj(@ParameterObject SysTenantMenu sysTenantMenu) {
|
||||
return R.ok(sysTenantMenuService.list(Wrappers.query(sysTenantMenu)));
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增租户
|
||||
* @param sysTenantMenu 租户
|
||||
* @return R
|
||||
*/
|
||||
@SysLog("新增租户")
|
||||
@PostMapping
|
||||
@PreAuthorize("@pms.hasPermission('sys_systenantmenu_add')")
|
||||
@CacheEvict(value = CacheConstants.TENANT_DETAILS, allEntries = true)
|
||||
public R save(@RequestBody SysTenantMenu sysTenantMenu) {
|
||||
return R.ok(sysTenantMenuService.saveTenant(sysTenantMenu));
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改租户
|
||||
* @param sysTenantMenu 租户
|
||||
* @return R
|
||||
*/
|
||||
@SysLog("修改租户")
|
||||
@PutMapping
|
||||
@PreAuthorize("@pms.hasPermission('sys_systenantmenu_edit')")
|
||||
@CacheEvict(value = CacheConstants.TENANT_DETAILS, allEntries = true)
|
||||
public R updateById(@RequestBody SysTenantMenu sysTenantMenu) {
|
||||
return R.ok(sysTenantMenuService.updateById(sysTenantMenu));
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过id删除租户
|
||||
* @param id id
|
||||
* @return R
|
||||
*/
|
||||
@SysLog("删除租户")
|
||||
@DeleteMapping("/{id}")
|
||||
@PreAuthorize("@pms.hasPermission('sys_systenantmenu_del')")
|
||||
@CacheEvict(value = CacheConstants.TENANT_DETAILS, allEntries = true)
|
||||
public R removeById(@PathVariable Long id) {
|
||||
return R.ok(sysTenantMenuService.removeById(id));
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询全部有效的租户
|
||||
* @return
|
||||
*/
|
||||
@Inner(value = false)
|
||||
@GetMapping("/list")
|
||||
public R list() {
|
||||
List<SysTenantMenu> tenants = sysTenantMenuService
|
||||
.list(Wrappers.<SysTenantMenu>lambdaQuery().eq(SysTenantMenu::getStatus, CommonConstants.STATUS_NORMAL));
|
||||
return R.ok(tenants);
|
||||
}
|
||||
|
||||
@GetMapping(value = "/tree/menu")
|
||||
public R getTree() {
|
||||
Long defaultId = ParamResolver.getLong("TENANT_DEFAULT_ID", 1L);
|
||||
List<Tree<Long>> trees = new ArrayList<>();
|
||||
TenantBroker.runAs(defaultId, (id) -> {
|
||||
trees.addAll(sysMenuService.treeMenu(null, null, null));
|
||||
});
|
||||
|
||||
return R.ok(trees);
|
||||
}
|
||||
|
||||
}
|
||||
-10
@@ -1,10 +0,0 @@
|
||||
package com.pig4cloud.pigx.admin.mapper;
|
||||
|
||||
import com.pig4cloud.pigx.admin.api.entity.SysTenantMenu;
|
||||
import com.pig4cloud.pigx.common.data.datascope.PigxBaseMapper;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
@Mapper
|
||||
public interface SysTenantMenuMapper extends PigxBaseMapper<SysTenantMenu> {
|
||||
|
||||
}
|
||||
-10
@@ -1,10 +0,0 @@
|
||||
package com.pig4cloud.pigx.admin.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.pig4cloud.pigx.admin.api.entity.SysTenantMenu;
|
||||
|
||||
public interface SysTenantMenuService extends IService<SysTenantMenu> {
|
||||
|
||||
Boolean saveTenant(SysTenantMenu sysTenantMenu);
|
||||
|
||||
}
|
||||
+7
@@ -43,4 +43,11 @@ public interface SysTenantService extends IService<SysTenant> {
|
||||
*/
|
||||
Boolean saveTenant(SysTenant sysTenant);
|
||||
|
||||
/**
|
||||
* 修改租户
|
||||
* @param sysTenant
|
||||
* @return
|
||||
*/
|
||||
Boolean updateTenant(SysTenant sysTenant);
|
||||
|
||||
}
|
||||
-21
@@ -1,21 +0,0 @@
|
||||
package com.pig4cloud.pigx.admin.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.pig4cloud.pigx.admin.api.entity.SysTenantMenu;
|
||||
import com.pig4cloud.pigx.admin.mapper.SysTenantMenuMapper;
|
||||
import com.pig4cloud.pigx.admin.service.SysTenantMenuService;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* 租户菜单管理
|
||||
*/
|
||||
@Service
|
||||
public class SysTenantMenuServiceImpl extends ServiceImpl<SysTenantMenuMapper, SysTenantMenu>
|
||||
implements SysTenantMenuService {
|
||||
|
||||
@Override
|
||||
public Boolean saveTenant(SysTenantMenu sysTenantMenu) {
|
||||
return this.save(sysTenantMenu);
|
||||
}
|
||||
|
||||
}
|
||||
+86
-6
@@ -16,6 +16,8 @@
|
||||
*/
|
||||
package com.pig4cloud.pigx.admin.service.impl;
|
||||
|
||||
import cn.hutool.core.util.CharUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.pig4cloud.pigx.admin.api.entity.*;
|
||||
@@ -30,6 +32,7 @@ import com.pig4cloud.pigx.common.data.datascope.DataScopeTypeEnum;
|
||||
import com.pig4cloud.pigx.common.data.resolver.ParamResolver;
|
||||
import com.pig4cloud.pigx.common.data.tenant.TenantBroker;
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.springframework.cache.CacheManager;
|
||||
import org.springframework.cache.annotation.CacheEvict;
|
||||
import org.springframework.cache.annotation.Cacheable;
|
||||
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
|
||||
@@ -75,7 +78,7 @@ public class SysTenantServiceImpl extends ServiceImpl<SysTenantMapper, SysTenant
|
||||
|
||||
private final SysDictService dictService;
|
||||
|
||||
private final SysTenantMenuService sysTenantMenuService;
|
||||
private final CacheManager cacheManager;
|
||||
|
||||
/**
|
||||
* 获取正常状态租户
|
||||
@@ -124,12 +127,11 @@ public class SysTenantServiceImpl extends ServiceImpl<SysTenantMapper, SysTenant
|
||||
// 查询系统内置字典
|
||||
dictList.addAll(dictService.list());
|
||||
// 查询系统内置字典项目
|
||||
dictIdList.addAll(dictList.stream().map(SysDict::getId).collect(Collectors.toList()));
|
||||
dictIdList.addAll(dictList.stream().map(SysDict::getId).toList());
|
||||
dictItemList.addAll(
|
||||
dictItemService.list(Wrappers.<SysDictItem>lambdaQuery().in(SysDictItem::getDictId, dictIdList)));
|
||||
SysTenantMenu tenantMenu = sysTenantMenuService.getById(sysTenant.getMenuId());
|
||||
String[] split = tenantMenu.getMenuIds().split(",");
|
||||
List<SysMenu> newMenuList = menuService.list(Wrappers.<SysMenu>lambdaQuery().in(SysMenu::getMenuId, split));
|
||||
List<SysMenu> newMenuList = menuService.list(Wrappers.<SysMenu>lambdaQuery()
|
||||
.in(SysMenu::getMenuId, StrUtil.split(sysTenant.getMenuId(), CharUtil.COMMA)));
|
||||
// 查询当前租户菜单
|
||||
menuList.addAll(newMenuList);
|
||||
// 查询客户端配置
|
||||
@@ -182,7 +184,7 @@ public class SysTenantServiceImpl extends ServiceImpl<SysTenantMapper, SysTenant
|
||||
roleMenu.setRoleId(role.getRoleId());
|
||||
roleMenu.setMenuId(menu.getMenuId());
|
||||
return roleMenu;
|
||||
}).collect(Collectors.toList());
|
||||
}).toList();
|
||||
roleMenuList.forEach(roleMenuMapper::insert);
|
||||
// 插入系统字典
|
||||
dictService.saveBatch(dictList.stream().peek(d -> d.setId(null)).collect(Collectors.toList()));
|
||||
@@ -209,6 +211,84 @@ public class SysTenantServiceImpl extends ServiceImpl<SysTenantMapper, SysTenant
|
||||
return Boolean.TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改租户
|
||||
* @param tenantDTO
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
@CacheEvict(value = CacheConstants.TENANT_DETAILS, allEntries = true)
|
||||
public Boolean updateTenant(SysTenant tenantDTO) {
|
||||
SysTenant tenant = baseMapper.selectById(tenantDTO.getId());
|
||||
// 更新租户数据
|
||||
updateById(tenantDTO);
|
||||
|
||||
// 如果没有修改租户套餐
|
||||
Long defaultId = ParamResolver.getLong("TENANT_DEFAULT_ID", 1L);
|
||||
if (defaultId.equals(tenantDTO.getId())) {
|
||||
return Boolean.TRUE;
|
||||
}
|
||||
if (tenant.getMenuId().equals(tenantDTO.getMenuId())) {
|
||||
return Boolean.TRUE;
|
||||
}
|
||||
|
||||
List<SysMenu> sysMenuList = TenantBroker.applyAs(defaultId,
|
||||
id -> menuService.list(Wrappers.<SysMenu>lambdaQuery()
|
||||
.in(SysMenu::getMenuId, StrUtil.split(tenantDTO.getMenuId(), CharUtil.COMMA))));
|
||||
|
||||
TenantBroker.runAs(tenantDTO.getId(), (tenantId -> {
|
||||
// 查询当前租户的所有菜单
|
||||
List<SysMenu> menuList = menuService.list(Wrappers.emptyWrapper());
|
||||
|
||||
// 套餐功能对比和已有菜单对比 (新增)
|
||||
List<SysMenu> addMenuList = new ArrayList<>();
|
||||
List<SysMenu> delMenuList = new ArrayList<>();
|
||||
|
||||
// 判断新增的菜单列表
|
||||
menuExist(sysMenuList, menuList, addMenuList);
|
||||
|
||||
// 判断删除的菜单列表
|
||||
menuExist(menuList, sysMenuList, delMenuList);
|
||||
|
||||
// 新增的菜单
|
||||
this.saveTenantMenu(addMenuList, CommonConstants.MENU_TREE_ROOT_ID, CommonConstants.MENU_TREE_ROOT_ID);
|
||||
// 套餐删除的菜单
|
||||
List<Long> menuIdList = delMenuList.stream().map(SysMenu::getMenuId).toList();
|
||||
menuService.removeBatchByIds(menuIdList);
|
||||
|
||||
// 清空菜单权限
|
||||
cacheManager.getCache(CacheConstants.MENU_DETAILS).clear();
|
||||
}));
|
||||
|
||||
return Boolean.TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断菜单是否存在
|
||||
* @param sysMenuList 要判断的菜单列表
|
||||
* @param menuList 已有菜单列表
|
||||
* @param addMenuList 待添加的菜单列表
|
||||
*/
|
||||
private void menuExist(List<SysMenu> sysMenuList, List<SysMenu> menuList, List<SysMenu> addMenuList) {
|
||||
for (SysMenu sysMenu : sysMenuList) {
|
||||
|
||||
if (StrUtil.isNotBlank(sysMenu.getPath())) {
|
||||
// 根据菜单path名称,查询套餐菜单是否存在
|
||||
if (menuList.stream().noneMatch(menu -> sysMenu.getPath().equals(menu.getPath()))) {
|
||||
addMenuList.add(sysMenu);
|
||||
}
|
||||
}
|
||||
|
||||
if (StrUtil.isNotBlank(sysMenu.getPermission())) {
|
||||
// 根据菜单permission名称,查询套餐菜单是否存在
|
||||
if (menuList.stream().noneMatch(menu -> sysMenu.getPermission().equals(menu.getPermission()))) {
|
||||
addMenuList.add(sysMenu);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存新的租户菜单,维护成新的菜单
|
||||
* @param menuList 菜单列表
|
||||
|
||||
Reference in new issue
Block a user