页面权限基础功能、树形

This commit is contained in:
attiya 2025-09-05 11:43:35 +08:00
parent 816cb211e4
commit 742ac7166c
5 changed files with 29 additions and 17 deletions

View File

@ -10,6 +10,7 @@ import com.mybatisflex.core.paginate.Page;
import com.mybatisflex.core.query.QueryWrapper; import com.mybatisflex.core.query.QueryWrapper;
import com.mybatisflex.core.util.StringUtil; import com.mybatisflex.core.util.StringUtil;
import jakarta.annotation.Resource; import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import java.util.List; import java.util.List;
@ -35,7 +36,7 @@ public class EbikePermissionController {
* @return {@code true} 添加成功{@code false} 添加失败 * @return {@code true} 添加成功{@code false} 添加失败
*/ */
@PostMapping("save") @PostMapping("save")
public JsonResult<?> save(@RequestBody EbikePermissionVo ebikePermission) { public JsonResult<?> save(@Validated @RequestBody EbikePermissionVo ebikePermission) {
ebikePermissionService.savePermission(ebikePermission); ebikePermissionService.savePermission(ebikePermission);
return JsonResult.success(); return JsonResult.success();
} }
@ -59,7 +60,7 @@ public class EbikePermissionController {
* @return {@code true} 更新成功{@code false} 更新失败 * @return {@code true} 更新成功{@code false} 更新失败
*/ */
@PostMapping("update") @PostMapping("update")
public JsonResult<?> update(@RequestBody EbikePermissionVo ebikePermission) { public JsonResult<?> update(@Validated @RequestBody EbikePermissionVo ebikePermission) {
ebikePermissionService.updatePermission(ebikePermission); ebikePermissionService.updatePermission(ebikePermission);
return JsonResult.success(); return JsonResult.success();
} }

View File

@ -1,5 +1,6 @@
package com.cdzy.staff.model.entity; package com.cdzy.staff.model.entity;
import com.mybatisflex.annotation.Column;
import com.mybatisflex.annotation.Id; import com.mybatisflex.annotation.Id;
import com.mybatisflex.annotation.Table; import com.mybatisflex.annotation.Table;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
@ -47,12 +48,15 @@ public class EbikePermission implements Serializable {
private Long createBy; private Long createBy;
@Column(onInsertValue = "now()")
private LocalDateTime createTime; private LocalDateTime createTime;
private Long updateBy; private Long updateBy;
@Column(onUpdateValue = "now()")
private LocalDateTime updateTime; private LocalDateTime updateTime;
@Column(isLogicDelete = true)
private Boolean isDeleted; private Boolean isDeleted;
/** /**

View File

@ -44,7 +44,6 @@ public class EbikePermissionVo implements Serializable {
/** /**
* 组件路径 * 组件路径
*/ */
@NotBlank(message = "菜单标题不能为空")
private String component; private String component;
/** /**

View File

@ -67,19 +67,23 @@ public class EbikePermissionServiceImpl extends ServiceImpl<EbikePermissionMappe
public List<EbikePermissionTreeNode> tree() { public List<EbikePermissionTreeNode> tree() {
QueryWrapper queryWrapper = QueryWrapper.create() QueryWrapper queryWrapper = QueryWrapper.create()
.isNull(EbikePermission::getParentId); .isNull(EbikePermission::getParentId);
List<EbikePermissionTreeNode> first = ebikePermissionMapper.selectListByQueryAs(queryWrapper,EbikePermissionTreeNode.class); List<EbikePermissionTreeNode> first = ebikePermissionMapper.selectListByQueryAs(queryWrapper, EbikePermissionTreeNode.class);
List<Long> firstIds = first.stream().map(EbikePermissionTreeNode::getPermissionId).toList(); List<Long> firstIds = first.stream().map(EbikePermissionTreeNode::getPermissionId).toList();
List<EbikePermissionTreeNode> second = null;
List<EbikePermissionTreeNode> third = null;
if (!firstIds.isEmpty()) {
queryWrapper.clear(); queryWrapper.clear();
queryWrapper.in(EbikePermission::getParentId,firstIds); queryWrapper.in(EbikePermission::getParentId, firstIds);
List<EbikePermissionTreeNode> second = ebikePermissionMapper.selectListByQueryAs(queryWrapper,EbikePermissionTreeNode.class); second = ebikePermissionMapper.selectListByQueryAs(queryWrapper, EbikePermissionTreeNode.class);
List<Long> secondIds = second.stream().map(EbikePermissionTreeNode::getPermissionId).toList(); List<Long> secondIds = second.stream().map(EbikePermissionTreeNode::getPermissionId).toList();
if (!secondIds.isEmpty()) {
queryWrapper.clear(); queryWrapper.clear();
queryWrapper.in(EbikePermission::getParentId,secondIds); queryWrapper.in(EbikePermission::getParentId, secondIds);
List<EbikePermissionTreeNode> third = ebikePermissionMapper.selectListByQueryAs(queryWrapper,EbikePermissionTreeNode.class); third = ebikePermissionMapper.selectListByQueryAs(queryWrapper, EbikePermissionTreeNode.class);
}
}
TreeUtil.permissionTree(first,second,third); TreeUtil.permissionTree(first, second, third);
return first; return first;
} }

View File

@ -19,9 +19,13 @@ public class TreeUtil {
* @param third 三级 * @param third 三级
*/ */
public static void permissionTree(List<EbikePermissionTreeNode> first, List<EbikePermissionTreeNode> second, List<EbikePermissionTreeNode> third) { public static void permissionTree(List<EbikePermissionTreeNode> first, List<EbikePermissionTreeNode> second, List<EbikePermissionTreeNode> third) {
if (third != null && !third.isEmpty()) {
buildTree(second, third); buildTree(second, third);
}
if (second != null && !second.isEmpty()) {
buildTree(first, second); buildTree(first, second);
} }
}
public static void buildTree(List<EbikePermissionTreeNode> parent, List<EbikePermissionTreeNode> child) { public static void buildTree(List<EbikePermissionTreeNode> parent, List<EbikePermissionTreeNode> child) {
parent.forEach(parentNode -> { parent.forEach(parentNode -> {