Merge remote-tracking branch 'base-version/main' into dev
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,41 @@
|
||||
package com.zt.plat.module.system.controller.admin.permission.vo.permission;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 用户权限监督图响应 VO
|
||||
*/
|
||||
@Data
|
||||
public class PermissionUserSupervisionRespVO {
|
||||
|
||||
private Node root;
|
||||
|
||||
@Data
|
||||
public static class Node {
|
||||
|
||||
private String id;
|
||||
|
||||
private String label;
|
||||
|
||||
private String type;
|
||||
|
||||
private Integer status;
|
||||
|
||||
private Boolean assigned;
|
||||
|
||||
private String code;
|
||||
|
||||
private String permission;
|
||||
|
||||
private Integer totalPermissionCount;
|
||||
|
||||
private Integer incrementalPermissionCount;
|
||||
|
||||
private List<Node> children = new ArrayList<>();
|
||||
|
||||
private List<Node> buttonChildren = new ArrayList<>();
|
||||
}
|
||||
}
|
||||
@@ -9,6 +9,7 @@ import lombok.NoArgsConstructor;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
|
||||
import static com.zt.plat.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
|
||||
|
||||
@@ -38,4 +39,7 @@ public class UserPageReqVO extends PageParam {
|
||||
@Schema(description = "角色编号", example = "1024")
|
||||
private Long roleId;
|
||||
|
||||
@Schema(description = "用户编号集合", example = "[1, 2, 3]")
|
||||
private List<Long> ids;
|
||||
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import cn.hutool.core.util.ObjUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.google.common.annotations.VisibleForTesting;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||
import com.zt.plat.framework.common.enums.CommonStatusEnum;
|
||||
import com.zt.plat.framework.common.util.object.BeanUtils;
|
||||
import com.zt.plat.module.system.controller.admin.permission.vo.menu.MenuListReqVO;
|
||||
@@ -24,6 +25,7 @@ import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
|
||||
import static com.zt.plat.framework.common.exception.util.ServiceExceptionUtil.exception;
|
||||
import static com.zt.plat.framework.common.util.collection.CollectionUtils.convertList;
|
||||
import static com.zt.plat.framework.common.util.collection.CollectionUtils.convertMap;
|
||||
@@ -66,11 +68,13 @@ public class MenuServiceImpl implements MenuService {
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
@CacheEvict(value = RedisKeyConstants.PERMISSION_MENU_ID_LIST,
|
||||
allEntries = true) // allEntries 清空所有缓存,因为 permission 如果变更,涉及到新老两个 permission。直接清理,简单有效
|
||||
public void updateMenu(MenuSaveVO updateReqVO) {
|
||||
// 校验更新的菜单是否存在
|
||||
if (menuMapper.selectById(updateReqVO.getId()) == null) {
|
||||
MenuDO oldMenu = menuMapper.selectById(updateReqVO.getId());
|
||||
if (oldMenu == null) {
|
||||
throw exception(MENU_NOT_EXISTS);
|
||||
}
|
||||
// 校验父菜单存在
|
||||
@@ -83,6 +87,12 @@ public class MenuServiceImpl implements MenuService {
|
||||
MenuDO updateObj = BeanUtils.toBean(updateReqVO, MenuDO.class);
|
||||
initMenuProperty(updateObj);
|
||||
menuMapper.updateById(updateObj);
|
||||
|
||||
// 如果本次更新禁用了当前菜单,则联动禁用所有子菜单
|
||||
if (!CommonStatusEnum.isDisable(oldMenu.getStatus())
|
||||
&& CommonStatusEnum.isDisable(updateObj.getStatus())) {
|
||||
cascadeDisableChildMenus(updateObj.getId());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -190,6 +200,41 @@ public class MenuServiceImpl implements MenuService {
|
||||
return menuMapper.selectBatchIds(ids);
|
||||
}
|
||||
|
||||
// 禁用父级菜单时需级联禁用所有子菜单
|
||||
private void cascadeDisableChildMenus(Long parentId) {
|
||||
List<MenuDO> allMenus = menuMapper.selectList();
|
||||
if (CollUtil.isEmpty(allMenus)) {
|
||||
return;
|
||||
}
|
||||
Map<Long, List<MenuDO>> childrenMap = new HashMap<>();
|
||||
for (MenuDO menu : allMenus) {
|
||||
childrenMap.computeIfAbsent(menu.getParentId(), key -> new ArrayList<>()).add(menu);
|
||||
}
|
||||
|
||||
Deque<Long> queue = new ArrayDeque<>();
|
||||
queue.add(parentId);
|
||||
List<Long> toDisableIds = new ArrayList<>();
|
||||
while (!queue.isEmpty()) {
|
||||
Long current = queue.poll();
|
||||
List<MenuDO> children = childrenMap.get(current);
|
||||
if (CollUtil.isEmpty(children)) {
|
||||
continue;
|
||||
}
|
||||
for (MenuDO child : children) {
|
||||
if (!CommonStatusEnum.isDisable(child.getStatus())) {
|
||||
toDisableIds.add(child.getId());
|
||||
}
|
||||
queue.add(child.getId());
|
||||
}
|
||||
}
|
||||
if (CollUtil.isEmpty(toDisableIds)) {
|
||||
return;
|
||||
}
|
||||
menuMapper.update(null, new LambdaUpdateWrapper<MenuDO>()
|
||||
.in(MenuDO::getId, toDisableIds)
|
||||
.set(MenuDO::getStatus, CommonStatusEnum.DISABLE.getStatus()));
|
||||
}
|
||||
|
||||
/**
|
||||
* 校验父菜单是否合法
|
||||
* <p>
|
||||
|
||||
@@ -338,6 +338,18 @@ public class AdminUserServiceImpl implements AdminUserService {
|
||||
Set<Long> userIds = reqVO.getRoleId() != null ?
|
||||
permissionService.getUserRoleIdListByRoleId(singleton(reqVO.getRoleId())) : null;
|
||||
|
||||
if (CollUtil.isNotEmpty(reqVO.getIds())) {
|
||||
Set<Long> idFilter = new HashSet<>(reqVO.getIds());
|
||||
if (userIds == null) {
|
||||
userIds = idFilter;
|
||||
} else {
|
||||
userIds.retainAll(idFilter);
|
||||
}
|
||||
if (CollUtil.isEmpty(userIds)) {
|
||||
return PageResult.empty();
|
||||
}
|
||||
}
|
||||
|
||||
// 分页查询
|
||||
PageResult<AdminUserDO> pageResult = userMapper.selectPage(reqVO, getDeptCondition(reqVO.getDeptId()), userIds);
|
||||
fillUserDeptInfo(pageResult.getList());
|
||||
|
||||
Reference in New Issue
Block a user