页面权限基础功能、树形
This commit is contained in:
parent
816cb211e4
commit
742ac7166c
@ -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();
|
||||
}
|
||||
|
||||
@ -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;
|
||||
|
||||
/**
|
||||
|
||||
@ -44,7 +44,6 @@ public class EbikePermissionVo implements Serializable {
|
||||
/**
|
||||
* 组件路径
|
||||
*/
|
||||
@NotBlank(message = "菜单标题不能为空")
|
||||
private String component;
|
||||
|
||||
/**
|
||||
|
||||
@ -67,19 +67,23 @@ public class EbikePermissionServiceImpl extends ServiceImpl<EbikePermissionMappe
|
||||
public List<EbikePermissionTreeNode> tree() {
|
||||
QueryWrapper queryWrapper = QueryWrapper.create()
|
||||
.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<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);
|
||||
queryWrapper.in(EbikePermission::getParentId, firstIds);
|
||||
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);
|
||||
queryWrapper.in(EbikePermission::getParentId, secondIds);
|
||||
third = ebikePermissionMapper.selectListByQueryAs(queryWrapper, EbikePermissionTreeNode.class);
|
||||
}
|
||||
}
|
||||
|
||||
TreeUtil.permissionTree(first,second,third);
|
||||
TreeUtil.permissionTree(first, second, third);
|
||||
return first;
|
||||
}
|
||||
|
||||
|
||||
@ -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 -> {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user