页面权限基础功能、树形

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

View File

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

View File

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

View File

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

View File

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