页面权限基础功能、树形
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.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();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -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;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -44,7 +44,6 @@ public class EbikePermissionVo implements Serializable {
|
|||||||
/**
|
/**
|
||||||
* 组件路径
|
* 组件路径
|
||||||
*/
|
*/
|
||||||
@NotBlank(message = "菜单标题不能为空")
|
|
||||||
private String component;
|
private String component;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -66,20 +66,24 @@ public class EbikePermissionServiceImpl extends ServiceImpl<EbikePermissionMappe
|
|||||||
@Override
|
@Override
|
||||||
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.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);
|
||||||
|
third = ebikePermissionMapper.selectListByQueryAs(queryWrapper, EbikePermissionTreeNode.class);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
queryWrapper.clear();
|
TreeUtil.permissionTree(first, second, third);
|
||||||
queryWrapper.in(EbikePermission::getParentId,firstIds);
|
|
||||||
List<EbikePermissionTreeNode> second = ebikePermissionMapper.selectListByQueryAs(queryWrapper,EbikePermissionTreeNode.class);
|
|
||||||
List<Long> secondIds = second.stream().map(EbikePermissionTreeNode::getPermissionId).toList();
|
|
||||||
|
|
||||||
queryWrapper.clear();
|
|
||||||
queryWrapper.in(EbikePermission::getParentId,secondIds);
|
|
||||||
List<EbikePermissionTreeNode> third = ebikePermissionMapper.selectListByQueryAs(queryWrapper,EbikePermissionTreeNode.class);
|
|
||||||
|
|
||||||
TreeUtil.permissionTree(first,second,third);
|
|
||||||
return first;
|
return first;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -19,8 +19,12 @@ 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) {
|
||||||
buildTree(second, third);
|
if (third != null && !third.isEmpty()) {
|
||||||
buildTree(first, second);
|
buildTree(second, third);
|
||||||
|
}
|
||||||
|
if (second != null && !second.isEmpty()) {
|
||||||
|
buildTree(first, second);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void buildTree(List<EbikePermissionTreeNode> parent, List<EbikePermissionTreeNode> child) {
|
public static void buildTree(List<EbikePermissionTreeNode> parent, List<EbikePermissionTreeNode> child) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user