diff --git a/ningda-generator/src/main/java/com/ningdatech/generator/config/GeneratorCodeKingbaseConfig.java b/ningda-generator/src/main/java/com/ningdatech/generator/config/GeneratorCodeKingbaseConfig.java index 6469612..f0e3436 100644 --- a/ningda-generator/src/main/java/com/ningdatech/generator/config/GeneratorCodeKingbaseConfig.java +++ b/ningda-generator/src/main/java/com/ningdatech/generator/config/GeneratorCodeKingbaseConfig.java @@ -14,7 +14,7 @@ import java.util.Collections; public class GeneratorCodeKingbaseConfig { private static final String PATH_LXX = "/Users/liuxinxin/IdeaProjects/project-management/pmapi/src/main/java"; - private static final String PATH_YYD = ""; + private static final String PATH_YYD = "/Users/wendy/code project/java/project-management/pmapi/src/main/java"; private static final String PATH_LS = ""; private static final String PATH_ZPF = "D:\\ningda\\project-management\\pmapi\\src\\main\\java"; private static final String PATH_CMM = ""; @@ -56,7 +56,7 @@ public class GeneratorCodeKingbaseConfig { } public static void main(String[] args) { - generate("ZPF", "testuser", PATH_ZPF, "wflow_users"); + generate("WendyYang", "sys", PATH_YYD, "nd_role_menu_datascope"); } } diff --git a/pmapi/pom.xml b/pmapi/pom.xml index e009967..b6b2ebf 100644 --- a/pmapi/pom.xml +++ b/pmapi/pom.xml @@ -61,18 +61,18 @@ org.springframework.boot spring-boot-starter-validation - - - - - - - - - - - - + + + + + + + + + + + + org.springframework.boot spring-boot-starter-web @@ -158,7 +158,7 @@ org.springframework.boot spring-boot-starter-test - + org.mapstruct @@ -187,10 +187,10 @@ org.slf4j slf4j-log4j12 - - - - + + + + @@ -233,6 +233,16 @@ nd-dict-starter + com.ningdatech + nd-cache-starter + 1.0.0 + + + com.ningdatech + nd-basic + 1.0.0 + + com.kingbase.dialect kingbase8-8.2.0 system diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/common/constant/DefValConstants.java b/pmapi/src/main/java/com/ningdatech/pmapi/common/constant/DefValConstants.java new file mode 100644 index 0000000..a11b052 --- /dev/null +++ b/pmapi/src/main/java/com/ningdatech/pmapi/common/constant/DefValConstants.java @@ -0,0 +1,57 @@ +package com.ningdatech.pmapi.common.constant; + + +import com.ningdatech.basic.util.StrPool; + +/** + * 默认值 + * + * @author PoffyZhang + */ +public interface DefValConstants { + + /** + * 默认的根节点path + */ + String ROOT_PATH = StrPool.COMMA; + /** + * 默认树层级 + */ + Integer TREE_GRADE = 0; + /** + * 默认的父id + */ + Long PARENT_ID = 0L; + /** + * 默认的排序 + */ + Integer SORT_VALUE = 0; + /** + * 字典占位符 + */ + String DICT_PLACEHOLDER = "###"; + /** + * 浙江省的region_id + */ + Long ZJREGION_ID = 116L; + + /** + * 城市 level + */ + Integer CITY_REGION_LEVEL = 2; + + /** + * 区的 level + */ + Integer QU_REGION_LEVEL = 3; + + /** + * 驾驶员异常数据GPS字符串起始偏移量 + */ + Integer GPS_START_OFFSET = 5; + + /** + * 驾驶员异常数据GPS字符串结尾偏移量 + */ + Integer GPS_END_OFFSET = 69; +} diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/common/model/entity/MenuTreeEntity.java b/pmapi/src/main/java/com/ningdatech/pmapi/common/model/entity/MenuTreeEntity.java new file mode 100644 index 0000000..9c25903 --- /dev/null +++ b/pmapi/src/main/java/com/ningdatech/pmapi/common/model/entity/MenuTreeEntity.java @@ -0,0 +1,125 @@ +package com.ningdatech.pmapi.common.model.entity; + +import cn.hutool.core.collection.CollUtil; +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableField; +import com.baomidou.mybatisplus.annotation.TableId; +import com.fasterxml.jackson.annotation.JsonIgnore; +import io.swagger.annotations.ApiModelProperty; +import lombok.Getter; +import lombok.Setter; +import lombok.ToString; +import lombok.experimental.Accessors; + +import javax.validation.constraints.NotEmpty; +import javax.validation.constraints.Size; +import java.io.Serializable; +import java.util.ArrayList; +import java.util.List; + +import static com.baomidou.mybatisplus.annotation.SqlCondition.LIKE; + +/** + * 包括id、create_time、created_by、updated_by、update_time、label、parent_id、sort_value 字段的表继承的树形实体 + * + * @author PoffyZhang + * @since 2022/09/30 + */ +@Getter +@Setter +@Accessors(chain = true) +@ToString(callSuper = true) +public class MenuTreeEntity { + + @TableId(value = "id", type = IdType.AUTO) + protected Long id; + + /** + * 名称 + */ + @ApiModelProperty(value = "名称") + @NotEmpty(message = "名称不能为空") + @Size(max = 255, message = "名称长度不能超过255") + @TableField(value = "name", condition = LIKE) + protected String name; + + /** + * 菜单标题 + */ + @ApiModelProperty(value = "菜单标题") + @NotEmpty(message = "菜单标题不能为空") + @Size(max = 255, message = "菜单标题长度不能超过255") + @TableField(value = "title", condition = LIKE) + protected String title; + + /** + * 父菜单ID + */ + @ApiModelProperty(value = "父ID") + @TableField(value = "pid") + protected Long pid; + + /** + * 排序 + */ + @ApiModelProperty(value = "排序号") + @TableField(value = "sort") + protected Integer sort; + + /** + * 顶层菜单 + */ + @ApiModelProperty(value = "顶层菜单") + @TableField(exist = false) + protected String topMenu; + + /** + * 路径 + */ + @ApiModelProperty(value = "路径") + @Size(max = 255, message = "路径长度不能超过255") + @TableField(value = "path", condition = LIKE) + protected String path; + + + @ApiModelProperty(value = "子节点", hidden = true) + @TableField(exist = false) + protected List children; + + + /** + * 层级 + */ + @ApiModelProperty(value = "层级") + @TableField(exist = false) + protected Integer level = 1; + + + /** + * 初始化子类 + */ + @JsonIgnore + public void initChildren() { + if (getChildren() == null) { + this.setChildren(new ArrayList<>()); + } + } + + @JsonIgnore + public void addChildren(E child) { + initChildren(); + children.add(child); + } + + public Integer getSize() { + if (CollUtil.isNotEmpty(getChildren())) { + return getChildren().size(); + } + return 0; + } + + @Override + public Object clone() throws CloneNotSupportedException { + return super.clone(); + } +} diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/common/utils/TreeUtil.java b/pmapi/src/main/java/com/ningdatech/pmapi/common/utils/TreeUtil.java new file mode 100644 index 0000000..1359135 --- /dev/null +++ b/pmapi/src/main/java/com/ningdatech/pmapi/common/utils/TreeUtil.java @@ -0,0 +1,442 @@ +package com.ningdatech.pmapi.common.utils; + + +import cn.hutool.core.collection.CollUtil; +import com.google.common.collect.Maps; +import com.ningdatech.basic.util.StrPool; +import com.ningdatech.pmapi.common.model.entity.MenuTreeEntity; +import com.ningdatech.pmapi.sys.entity.RoleMenu; +import com.ningdatech.pmapi.sys.entity.vo.MenuRoleVO; +import org.apache.commons.lang3.StringUtils; + +import java.io.Serializable; +import java.util.*; +import java.util.stream.Collectors; + +/** + * list列表 转换成tree列表 + * + * @author PoffyZhang + */ +public final class TreeUtil { + private TreeUtil() { + } + + private static Map nodeMap = Maps.newConcurrentMap(); + + /** + * 判断id是否为根节点 + * + * @param id + * @return + */ + public static boolean isRoot(Long id) { + return id == null || StrPool.DEF_PARENT_ID.equals(id); + } + + + public static String getTreePath(String parentTreePath, Long parentId) { + return StrPool.COMMA + parentId + parentTreePath; + } + + /** + * 构建Tree结构 + * + * @param treeList 待转换的集合 + * @return 树结构 + */ + public static > List buildTree(List treeList) { + if (CollUtil.isEmpty(treeList)) { + return treeList; + } + //记录自己是自己的父节点的id集合 + List selfIdEqSelfParent = new ArrayList<>(); + + // 遍历两次 + foreachNodes(treeList, selfIdEqSelfParent); + foreachNodesWithTopMenu(treeList); + + // 找出根节点集合 + List trees = new ArrayList<>(); + + List allIds = treeList.stream().map(node -> node.getId()).collect(Collectors.toList()); + for (E baseNode : treeList) { + if (!allIds.contains(baseNode.getPid()) || selfIdEqSelfParent.contains(baseNode.getPid())) { + baseNode.setPid(null); + baseNode.setTopMenu(baseNode.getName()); + trees.add(baseNode); + } + } + return trees; + } + + /** + * 构建Tree结构 + * + * @param treeList 待转换的集合 + * @param title 菜单名 + * @return 树结构 + */ + public static > List buildTree(List treeList, String title) { + if (CollUtil.isEmpty(treeList)) { + return treeList; + } + //记录自己是自己的父节点的id集合 + List selfIdEqSelfParent = new ArrayList<>(); + + // 遍历两次 + foreachNodes(treeList, selfIdEqSelfParent); + foreachNodesWithTopMenu(treeList); + + // 找出根节点集合 + List trees = new ArrayList<>(); + + List allIds = treeList.stream().map(node -> node.getId()).collect(Collectors.toList()); + for (E baseNode : treeList) { + if (!allIds.contains(baseNode.getPid()) || selfIdEqSelfParent.contains(baseNode.getPid())) { + baseNode.setPid(null); + baseNode.setTopMenu(baseNode.getName()); + trees.add(baseNode); + } + } +// checkTitle(trees,title); + return trees; + } + + private static > + void foreachNodes(List treeList, List selfIdEqSelfParent) { + nodeMap = Maps.newConcurrentMap(); + for (E parent : treeList) { + Serializable id = parent.getId(); + nodeMap.put(parent.getId(), parent); + for (E children : treeList) { + if (parent != children) { + //parent != children 这个来判断自己的孩子不允许是自己,因为有时候,根节点的parent会被设置成为自己 + if (id.equals(children.getPid())) { + parent.initChildren(); + if (0L == parent.getPid()) { + children.setTopMenu(parent.getName()); + children.setLevel(2); + } else { + children.setTopMenu(parent.getTopMenu()); + children.setLevel(parent.getLevel() + 1); + } + parent.getChildren().add(children); + } + } else if (id.equals(parent.getPid())) { + selfIdEqSelfParent.add(id); + } + } + } + } + + private static > void foreachNodesWithTopMenu(List treeList) { + for (E parent : treeList) { + Serializable id = parent.getId(); + for (E children : treeList) { + if (parent != children) { + if (id.equals(children.getPid())) { + if (0L == parent.getPid()) { + children.setTopMenu(parent.getName()); + children.setLevel(2); + } else { + children.setTopMenu(parent.getTopMenu()); + children.setLevel(parent.getLevel() + 1); + } + } + } + } + } + } + + private static > + void checkTitle(List trees, String title) { + if (StringUtils.isBlank(title)) { + return; + } + for (E tree : trees) { + //筛选 从顶级往下查 + //递归筛选 + checkTitleNode(tree, title, trees, trees); + } + } + + private static > void checkTitleNode(MenuTreeEntity node, String title, List parents, List tops) { + if (!node.getTitle().contains(title)) { + if (CollUtil.isEmpty(node.getChildren())) { + removeNode(parents, node, tops); + } else { + Iterator iterator = node.getChildren().iterator(); + while (iterator.hasNext()) { + checkTitleNode(iterator.next(), title, node.getChildren(), tops); + } + } + } else { + //匹配到了 + return; + } + } + + private static > + void removeNode(List parents, MenuTreeEntity node, List tops) { + parents.remove(node); + //如果该层节点都被删了 要删除父级 + if (Objects.nonNull(node.getPid())) { + MenuTreeEntity parent = nodeMap.get(node.getPid()); + if (Objects.nonNull(parent)) { + if (Objects.nonNull(parent.getPid())) { + MenuTreeEntity parentN = nodeMap.get(parent.getPid()); + removeNode(parentN.getChildren(), parent, tops); + } else { + tops.remove(parent); + } + } + } else { + tops.remove(node); + } + } + + public static List buildTree(List treeList, List roleMenus) { + if (CollUtil.isEmpty(treeList)) { + return treeList; + } + //记录自己是自己的父节点的id集合 + List selfIdEqSelfParent = new ArrayList<>(); + + // 遍历两次 + foreachNodesCheckRoleWithoutParent(treeList, selfIdEqSelfParent, roleMenus); + foreachNodesWithTopMenu(treeList); + + // 找出根节点集合 + List trees = new ArrayList<>(); + + List allIds = treeList.stream().map(MenuRoleVO::getId).collect(Collectors.toList()); + for (MenuRoleVO baseNode : treeList) { + if (!allIds.contains(baseNode.getPid()) || selfIdEqSelfParent.contains(baseNode.getPid())) { + baseNode.setPid(null); + for (RoleMenu roleMenu : roleMenus) { + if (baseNode.getId().equals(roleMenu.getMenuId()) && + 2 != baseNode.getHasPermission()) { + baseNode.setTopMenu(baseNode.getName()); + trees.add(baseNode); + } + } + } + } + return trees; + } + + private static void foreachNodesWithRole(List treeList, + List selfIdEqSelfParent, List roleMenus) { + nodeMap = Maps.newConcurrentMap(); + for (MenuRoleVO parent : treeList) { + Serializable id = parent.getId(); + nodeMap.put(parent.getId(), parent); + for (MenuRoleVO children : treeList) { + if (parent != children) { + //parent != children 这个来判断自己的孩子不允许是自己,因为有时候,根节点的parent会被设置成为自己 + if (id.equals(children.getPid())) { + parent.initChildren(); + if (0L == parent.getPid()) { + children.setTopMenu(parent.getPath()); + children.setLevel(2); + } else { + children.setTopMenu(parent.getTopMenu()); + children.setLevel(parent.getLevel() + 1); + } + parent.getChildren().add(children); + } + } else if (id.equals(parent.getPid())) { + selfIdEqSelfParent.add(id); + } + + for (RoleMenu roleMenu : roleMenus) { + if (children.getId().equals(roleMenu.getMenuId())) { + children.setHasPermission(1); + } + } + } + } + } + + public static List buildUserTree(List treeList, List roleMenus) { + if (CollUtil.isEmpty(treeList)) { + return Collections.emptyList(); + } + //记录自己是自己的父节点的id集合 + List selfIdEqSelfParent = new ArrayList<>(); + + // 遍历两次 + foreachNodesCheckRole(treeList, selfIdEqSelfParent, roleMenus); + foreachNodesWithTopMenu(treeList); + + // 找出根节点集合 + List trees = new ArrayList<>(); + + List allIds = treeList.stream().map(node -> node.getId()).collect(Collectors.toList()); + for (MenuRoleVO baseNode : treeList) { + if (!allIds.contains(baseNode.getPid()) || selfIdEqSelfParent.contains(baseNode.getPid())) { + baseNode.setPid(null); + Boolean isUserMenu = checkPermisson(baseNode.getId(), roleMenus); + if (isUserMenu) { + baseNode.setTopMenu(baseNode.getName()); + checkRedirect(baseNode); + trees.add(baseNode); + } else { + if (baseNode.getSize() > 0) { + baseNode.setTopMenu(baseNode.getName()); + checkRedirect(baseNode); + trees.add(baseNode); + } + } + } + } + return trees; + } + + //判断角色权限用 不用父级 + private static void foreachNodesCheckRoleWithoutParent(List treeList, List selfIdEqSelfParent, List roleMenus) { + nodeMap = Maps.newConcurrentMap(); + for (MenuRoleVO parent : treeList) { + Serializable id = parent.getId(); + nodeMap.put(parent.getId(), parent); + for (MenuRoleVO children : treeList) { + if (parent != children) { + //parent != children 这个来判断自己的孩子不允许是自己,因为有时候,根节点的parent会被设置成为自己 + if (id.equals(children.getPid())) { + parent.initChildren(); + + if (!checkPermisson(children.getId(), roleMenus)) { + continue; + } + + if (0L == parent.getPid()) { + children.setTopMenu(parent.getName()); + children.setLevel(2); + } else { + children.setTopMenu(parent.getTopMenu()); + children.setLevel(parent.getLevel() + 1); + } + parent.getChildren().add(children); + } + } else if (id.equals(parent.getPid())) { + selfIdEqSelfParent.add(id); + } + + for (RoleMenu roleMenu : roleMenus) { + if (children.getId().equals(roleMenu.getMenuId())) { + children.setHasPermission(1); + } + } + } + } + } + + //判断当前登录权限用 + private static void foreachNodesCheckRole(List treeList, List selfIdEqSelfParent, List roleMenus) { + nodeMap = Maps.newConcurrentMap(); + for (MenuRoleVO parent : treeList) { + Serializable id = parent.getId(); + nodeMap.put(parent.getId(), parent); + for (MenuRoleVO children : treeList) { + if (parent != children) { + //parent != children 这个来判断自己的孩子不允许是自己,因为有时候,根节点的parent会被设置成为自己 + if (id.equals(children.getPid())) { + parent.initChildren(); + + if (!checkPermisson(children.getId(), roleMenus)) { + continue; + } + + if (0L == parent.getPid()) { + children.setTopMenu(parent.getName()); + children.setLevel(2); + } else { + children.setTopMenu(parent.getTopMenu()); + children.setLevel(parent.getLevel() + 1); + } + parent.getChildren().add(children); + } + } else if (id.equals(parent.getPid())) { + selfIdEqSelfParent.add(id); + } + } + + //1层 2层 再加一下 + for (MenuRoleVO children : treeList) { + if (parent != children) { + if (id.equals(children.getPid())) { + + if (parent.getChildren().contains(children) || + children.getSize() == 0) { + continue; + } + + if (0L == parent.getPid()) { + children.setTopMenu(parent.getName()); + children.setLevel(2); + } else { + children.setTopMenu(parent.getTopMenu()); + children.setLevel(parent.getLevel() + 1); + } + parent.getChildren().add(children); + } + } + } + } + } + + /** + * 判断角色是否有该菜单权限 + * + * @param roleId + * @param roleMenus + * @return + */ + private static Boolean checkPermisson(Long roleId, List roleMenus) { + Boolean isUserMenu = false; + for (RoleMenu roleMenu : roleMenus) { + if (roleId.equals(roleMenu.getMenuId())) { + isUserMenu = true; + break; + } + } + return isUserMenu; + } + + /** + * 动态判断redirect + * + * @param baseNode + */ + private static void checkRedirect(MenuRoleVO baseNode) { + checkMenuRedirect(baseNode, baseNode.getChildren()); + } + + private static Boolean checkMenuRedirect(MenuRoleVO baseNode, List menus) { + if (baseNode.getSize() > 0) { + for (MenuRoleVO menu : menus) { + if (menu.getPath().endsWith("Datav")) { + baseNode.setRedirect(menu.getComponent()); + return Boolean.TRUE; + } + + if (menu.getSize() == 0 && 0 == menu.getHidden()) { + baseNode.setRedirect(menu.getComponent()); + return Boolean.TRUE; + } + } + + //一轮没有合适的菜单 去三级菜单找 + for (MenuRoleVO menu : menus) { + if (menu.getSize() > 0) { + if (checkMenuRedirect(baseNode, menu.getChildren())) { + return Boolean.TRUE; + } + } + } + } + + return Boolean.FALSE; + } +} diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/scheduler/task/InitProcessTask.java b/pmapi/src/main/java/com/ningdatech/pmapi/scheduler/task/InitProcessTask.java index aa310e0..af34f7c 100644 --- a/pmapi/src/main/java/com/ningdatech/pmapi/scheduler/task/InitProcessTask.java +++ b/pmapi/src/main/java/com/ningdatech/pmapi/scheduler/task/InitProcessTask.java @@ -4,33 +4,25 @@ import cn.hutool.core.bean.BeanUtil; import cn.hutool.core.collection.CollUtil; import cn.hutool.core.date.StopWatch; import cn.hutool.core.util.IdUtil; -import com.alibaba.fastjson.JSON; import com.baomidou.mybatisplus.core.toolkit.Wrappers; -import com.google.common.collect.Maps; import com.ningdatech.basic.exception.BizException; import com.ningdatech.pmapi.scheduler.contants.TaskContant; -import com.ningdatech.pmapi.sys.contants.RegionContant; +import com.ningdatech.pmapi.sys.contant.RegionConst; import com.ningdatech.pmapi.sys.entity.Region; import com.ningdatech.pmapi.sys.service.IRegionService; -import com.wflow.bean.entity.WflowForms; import com.wflow.bean.entity.WflowModelHistorys; import com.wflow.bean.entity.WflowModels; -import com.wflow.contants.WflowContant; import com.wflow.mapper.WflowModelHistorysMapper; import com.wflow.mapper.WflowModelsMapper; import com.wflow.workflow.service.ProcessModelService; import com.wflow.workflow.service.WflowFormsService; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; -import org.apache.commons.lang3.StringUtils; import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Component; -import javax.annotation.Resource; import java.net.InetAddress; import java.net.UnknownHostException; -import java.time.LocalDateTime; -import java.time.ZoneOffset; import java.util.*; /** @@ -63,7 +55,7 @@ public class InitProcessTask { //1.查出丽水市下的 区县 分别去初始化 表单和流程配置数据 List regions = regionService.list(Wrappers.lambdaQuery(Region.class) .eq(Region::getDeleted,Boolean.FALSE) - .eq(Region::getParentCode, RegionContant.LS_REGION_CODE)); + .eq(Region::getParentCode, RegionConst.LS_REGION_CODE)); if(CollUtil.isEmpty(regions)){ throw new BizException("丽水地区数据为空 任务结束!"); diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/sys/contant/RegionConst.java b/pmapi/src/main/java/com/ningdatech/pmapi/sys/contant/RegionConst.java new file mode 100644 index 0000000..f664939 --- /dev/null +++ b/pmapi/src/main/java/com/ningdatech/pmapi/sys/contant/RegionConst.java @@ -0,0 +1,26 @@ +package com.ningdatech.pmapi.sys.contant; + +/** + *

+ * 地区常量 + *

+ * + * @author WendyYang + * @since 18:54 2023/1/28 + */ +public interface RegionConst { + + Integer FIRST_LEVEL = 1; + + Integer SECOND_LEVEL = 2; + + Integer THIRD_LEVEL = 3; + + Long EMPTY_PARENT_ID = 0L; + + /** + * 丽水地区CODE + */ + String LS_REGION_CODE = "331100"; + +} diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/sys/contants/RegionContant.java b/pmapi/src/main/java/com/ningdatech/pmapi/sys/contants/RegionContant.java deleted file mode 100644 index ef900c6..0000000 --- a/pmapi/src/main/java/com/ningdatech/pmapi/sys/contants/RegionContant.java +++ /dev/null @@ -1,20 +0,0 @@ -package com.ningdatech.pmapi.sys.contants; - -/** - * @Classname RegionContant - * @Description - * @Date 2023/1/18 9:37 - * @Created by PoffyZhang - */ -public interface RegionContant { - - public static final Integer FIRST_LEVEL = 1; - - public static final Integer SECOND_LEVEL = 2; - - public static final Integer THIRD_LEVEL = 3; - - public static final Long EMPTY_PARENT_ID = 0L; - //丽水地区CODE - public static final String LS_REGION_CODE = "331100"; -} diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/sys/controller/MenuController.java b/pmapi/src/main/java/com/ningdatech/pmapi/sys/controller/MenuController.java new file mode 100644 index 0000000..5018ab1 --- /dev/null +++ b/pmapi/src/main/java/com/ningdatech/pmapi/sys/controller/MenuController.java @@ -0,0 +1,108 @@ +package com.ningdatech.pmapi.sys.controller; + +import cn.hutool.core.bean.BeanUtil; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.core.toolkit.Wrappers; +import com.ningdatech.basic.auth.AbstractLoginUserUtil; +import com.ningdatech.basic.util.CollUtils; +import com.ningdatech.log.annotation.WebLog; +import com.ningdatech.pmapi.common.model.entity.MenuTreeEntity; +import com.ningdatech.pmapi.common.utils.TreeUtil; +import com.ningdatech.pmapi.sys.entity.Menu; +import com.ningdatech.pmapi.sys.entity.dto.MenuQueryDTO; +import com.ningdatech.pmapi.sys.entity.dto.MenuSaveDTO; +import com.ningdatech.pmapi.sys.entity.dto.MenuUpdateDTO; +import com.ningdatech.pmapi.sys.entity.vo.MenuRoleVO; +import com.ningdatech.pmapi.sys.entity.vo.MenuVO; +import com.ningdatech.pmapi.sys.manage.MenuManage; +import com.ningdatech.pmapi.sys.service.IMenuService; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.*; + +import javax.validation.Valid; +import java.util.List; + +/** + *

+ * 前端控制器-菜单 + *

+ * + * @author WendyYang + * @since 2022-09-30 + */ +@Slf4j +@Validated +@RestController +@RequiredArgsConstructor +@RequestMapping("/api/v1/menu") +@Api(value = "Menu", tags = "系统管理-菜单") +public class MenuController { + + private final IMenuService menuService; + private final MenuManage menuManage; + + @ApiOperation("查询系统所有的菜单") + @GetMapping("/list") + public List allTree(@Valid @RequestParam(required = false, value = "title") String title) { + List list = menuService.list(Wrappers.lambdaQuery(Menu.class).orderByAsc(Menu::getSort)); + return TreeUtil.buildTree(list, title); + } + + @ApiOperation("查询系统所有数据权限的菜单") + @GetMapping("/listByDataScope") + public List allTreeByDataScope() { + LambdaQueryWrapper dsQuery = Wrappers.lambdaQuery(Menu.class) + .eq(Menu::getHasDataScope, Boolean.TRUE) + .orderByAsc(Menu::getSort); + List list = menuService.list(dsQuery); + if (!list.isEmpty()) { + List pidList = CollUtils.fieldList(list, MenuTreeEntity::getPid); + list.addAll(menuService.listByIds(pidList)); + } + return TreeUtil.buildTree(list); + } + + @ApiOperation(value = "查询当前登录用户的菜单", notes = "查询当前登录用户的菜单") + @GetMapping("/myMenu") + public List currentUserMenu() { + List list = menuService.list(Wrappers.lambdaQuery(Menu.class).orderByAsc(Menu::getSort)); + // TODO:登录用户信息 + return menuManage.buildUserMenu(list, null); + } + + @ApiOperation(value = "查询菜单", notes = "查询菜单") + @GetMapping("/details") + public MenuQueryDTO getDetails(@RequestParam Long id) { + Menu menu = menuService.getById(id); + return BeanUtil.toBean(menu, MenuQueryDTO.class); + } + + @ApiOperation(value = "保存新菜单", notes = "保存新菜单") + @PostMapping("/save") + @WebLog("保存菜单") + public MenuVO handlerSave(@Valid @RequestBody MenuSaveDTO data) { + // todo:创建人ID + menuService.save(data, 0L); + return BeanUtil.toBean(data, MenuVO.class); + } + + @ApiOperation(value = "编辑菜单", notes = "编辑菜单") + @PostMapping("/modify") + @WebLog("编辑菜单") + public MenuVO handlerUpdate(@RequestBody MenuUpdateDTO data) { + menuService.update(data, AbstractLoginUserUtil.getUserId()); + return BeanUtil.toBean(data, MenuVO.class); + } + + @ApiOperation(value = "删除菜单", notes = "删除菜单") + @PostMapping("/remove") + @WebLog("删除菜单") + public Boolean handlerDelete(@RequestBody List ids) { + return menuService.removeByIdWithCache(ids); + } + +} diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/sys/controller/RoleController.java b/pmapi/src/main/java/com/ningdatech/pmapi/sys/controller/RoleController.java new file mode 100644 index 0000000..09fd7c5 --- /dev/null +++ b/pmapi/src/main/java/com/ningdatech/pmapi/sys/controller/RoleController.java @@ -0,0 +1,93 @@ +package com.ningdatech.pmapi.sys.controller; + +import cn.hutool.core.bean.BeanUtil; +import com.ningdatech.basic.auth.AbstractLoginUserUtil; +import com.ningdatech.basic.model.PageVo; +import com.ningdatech.log.annotation.WebLog; +import com.ningdatech.pmapi.sys.entity.Role; +import com.ningdatech.pmapi.sys.entity.dto.RolePageReq; +import com.ningdatech.pmapi.sys.entity.dto.RoleSaveDTO; +import com.ningdatech.pmapi.sys.entity.dto.RoleUpdateDTO; +import com.ningdatech.pmapi.sys.entity.vo.RoleVO; +import com.ningdatech.pmapi.sys.manage.RoleManage; +import com.ningdatech.pmapi.sys.service.IRoleService; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.*; + +import javax.validation.Valid; +import java.util.List; +import java.util.Objects; + +/** + *

+ * 前端控制器-角色 + *

+ * + * @author WendyYang + * @since 2022-09-30 + */ +@Slf4j +@Validated +@RestController +@RequestMapping("/api/v1/role") +@Api(value = "Role", tags = "系统管理-角色") +@RequiredArgsConstructor +public class RoleController { + + private final IRoleService roleService; + private final RoleManage roleManage; + + + @ApiOperation(value = "角色列表查询", notes = "角色列表查询") + @GetMapping("/list") + public PageVo query(@Valid @ModelAttribute RolePageReq rolePageReq) { + return roleManage.queryList(rolePageReq); + } + + /** + * 查询角色 + * + * @param id 主键id + * @return 查询结果 + */ + @ApiOperation(value = "查询角色", notes = "查询角色") + @GetMapping("/details") + public RoleVO getDetails(@Valid @RequestParam Long id) { + Role role = roleService.getById(id); + RoleVO query = BeanUtil.toBean(role, RoleVO.class); + if (Objects.isNull(query)) { + return null; + } + //菜单 + roleManage.buildMenu(query); + return query; + } + + @ApiOperation(value = "保存新角色", notes = "保存新角色") + @PostMapping("/save") + @WebLog + public RoleVO handlerSave(@Valid @RequestBody RoleSaveDTO data) { + roleService.saveRole(data, null); + return BeanUtil.toBean(data, RoleVO.class); + } + + @ApiOperation(value = "编辑角色", notes = "编辑角色") + @PostMapping("/modify") + @WebLog + public RoleVO handlerUpdate(@Valid @RequestBody RoleUpdateDTO data) { + roleService.updateRole(data, AbstractLoginUserUtil.getUserId()); + return BeanUtil.toBean(data, RoleVO.class); + } + + @ApiOperation(value = "删除角色", notes = "删除角色") + @PostMapping("/remove") + @WebLog + public Boolean handlerDelete(@Valid @RequestBody List ids) { + return roleService.removeByIdWithCache(ids); + } + +} diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/sys/entity/BaseEntity.java b/pmapi/src/main/java/com/ningdatech/pmapi/sys/entity/BaseEntity.java new file mode 100644 index 0000000..00dd7c9 --- /dev/null +++ b/pmapi/src/main/java/com/ningdatech/pmapi/sys/entity/BaseEntity.java @@ -0,0 +1,34 @@ +package com.ningdatech.pmapi.sys.entity; + +import io.swagger.annotations.ApiModelProperty; +import lombok.Getter; +import lombok.Setter; + +import java.io.Serializable; +import java.time.LocalDateTime; + +/** + *

+ * 通用字段, is_del 根据需求自行添加 + *

+ * + * @author WendyYang + * @since 11:01 2023/1/28 + */ +@Getter +@Setter +public class BaseEntity implements Serializable { + + @ApiModelProperty("创建人userId") + protected Long createBy; + + @ApiModelProperty("最后修改人userId") + protected Long updateBy; + + @ApiModelProperty("创建时间") + protected LocalDateTime createOn; + + @ApiModelProperty("修改时间") + protected LocalDateTime updateOn; + +} diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/sys/entity/Menu.java b/pmapi/src/main/java/com/ningdatech/pmapi/sys/entity/Menu.java new file mode 100644 index 0000000..3db4378 --- /dev/null +++ b/pmapi/src/main/java/com/ningdatech/pmapi/sys/entity/Menu.java @@ -0,0 +1,73 @@ +package com.ningdatech.pmapi.sys.entity; + +import com.baomidou.mybatisplus.annotation.TableField; +import com.baomidou.mybatisplus.annotation.TableName; +import com.ningdatech.pmapi.common.model.entity.MenuTreeEntity; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.*; +import lombok.experimental.Accessors; + +import javax.validation.constraints.Size; +import java.time.LocalDateTime; + +import static com.baomidou.mybatisplus.annotation.SqlCondition.LIKE; + +/** + *

+ * 实体类 + * 菜单 + *

+ * + * @author PoffyZhang + * @since 2022-9-30 + */ +@Data +@NoArgsConstructor +@ToString(callSuper = true) +@EqualsAndHashCode(callSuper = true) +@Accessors(chain = true) +@TableName("nd_menu") +@ApiModel(value = "Menu", description = "菜单") +@AllArgsConstructor +public class Menu extends MenuTreeEntity { + + private static final long serialVersionUID = 1L; + + @ApiModelProperty(value = "组件") + @Size(max = 255, message = "组件长度不能超过255") + @TableField(value = "component", condition = LIKE) + private String component; + + @ApiModelProperty(value = "菜单图标") + @Size(max = 255, message = "菜单图标长度不能超过255") + @TableField(value = "icon", condition = LIKE) + private String icon; + + @ApiModelProperty(value = "是否隐藏") + @TableField(value = "hidden") + private Boolean hidden; + + @ApiModelProperty(value = "activeMenu") + @TableField(value = "active_menu") + private String activeMenu; + + @ApiModelProperty(value = "跳转") + @TableField(value = "redirect") + private String redirect; + + @ApiModelProperty("是否有数据权限") + private Boolean hasDataScope; + + @ApiModelProperty("数据权限选项") + private String dataScopeOption; + + private Long updateBy; + + private Long createBy; + + private LocalDateTime updateOn; + + private LocalDateTime createOn; + +} diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/sys/entity/Resource.java b/pmapi/src/main/java/com/ningdatech/pmapi/sys/entity/Resource.java new file mode 100644 index 0000000..7d7a379 --- /dev/null +++ b/pmapi/src/main/java/com/ningdatech/pmapi/sys/entity/Resource.java @@ -0,0 +1,94 @@ +package com.ningdatech.pmapi.sys.entity; + +import com.baomidou.mybatisplus.annotation.TableField; +import com.baomidou.mybatisplus.annotation.TableName; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.*; +import lombok.experimental.Accessors; + +import javax.validation.constraints.NotEmpty; +import javax.validation.constraints.Size; +import java.time.LocalDateTime; + +import static com.baomidou.mybatisplus.annotation.SqlCondition.LIKE; + +/** + *

+ * 实体类 + * 资源 + *

+ * + * @author PoffyZhang + */ +@Data +@NoArgsConstructor +@ToString(callSuper = true) +@EqualsAndHashCode(callSuper = true) +@Accessors(chain = true) +@TableName("c_resource") +@ApiModel(value = "Resource", description = "资源") +@AllArgsConstructor +public class Resource extends BaseEntity { + + private Long id; + + private static final long serialVersionUID = 1L; + + /** + * 编码 + */ + @ApiModelProperty(value = "编码") + @Size(max = 500, message = "编码长度不能超过500") + @TableField(value = "code", condition = LIKE) + private String code; + + /** + * 名称 + */ + @ApiModelProperty(value = "名称") + @NotEmpty(message = "名称不能为空") + @Size(max = 255, message = "名称长度不能超过255") + @TableField(value = "name", condition = LIKE) + private String name; + + /** + * 菜单ID + * #c_menu + */ + @ApiModelProperty(value = "菜单ID") + @TableField("menu_id") + private Long menuId; + + /** + * 描述 + */ + @ApiModelProperty(value = "描述") + @Size(max = 255, message = "描述长度不能超过255") + @TableField(value = "describe_", condition = LIKE) + private String describe; + + /** + * 内置 + */ + @ApiModelProperty(value = "内置") + @TableField("readonly_") + private Boolean readonly; + + + @Builder + public Resource(Long id, Long createdBy, LocalDateTime createTime, Long updatedBy, LocalDateTime updateTime, + String code, String name, Long menuId, String describe, Boolean readonly) { + this.id = id; + this.createBy = createdBy; + this.createOn = createTime; + this.updateBy = updatedBy; + this.updateOn = updateTime; + this.code = code; + this.name = name; + this.menuId = menuId; + this.describe = describe; + this.readonly = readonly; + } + +} diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/sys/entity/Role.java b/pmapi/src/main/java/com/ningdatech/pmapi/sys/entity/Role.java new file mode 100644 index 0000000..d69e997 --- /dev/null +++ b/pmapi/src/main/java/com/ningdatech/pmapi/sys/entity/Role.java @@ -0,0 +1,54 @@ +package com.ningdatech.pmapi.sys.entity; + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableField; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.*; +import lombok.experimental.Accessors; + +import javax.validation.constraints.NotEmpty; +import javax.validation.constraints.Size; + +import static com.baomidou.mybatisplus.annotation.SqlCondition.LIKE; + +/** + *

+ * 实体类 + * 角色 + *

+ * + * @author PoffyZhang + * @since 2022-09-30 + */ +@Data +@NoArgsConstructor +@ToString(callSuper = true) +@EqualsAndHashCode(callSuper = true) +@Accessors(chain = true) +@TableName("nd_role") +@ApiModel(value = "Role", description = "角色") +@AllArgsConstructor +public class Role extends BaseEntity { + + private static final long serialVersionUID = 1L; + + @TableId(value = "id",type = IdType.AUTO) + private Long id; + + @ApiModelProperty(value = "名称") + private String name; + + @ApiModelProperty("角色编码") + private String code; + + + @ApiModelProperty(value = "描述") + private String describe; + + @ApiModelProperty(value = "管理角色ID") + private String manageRoleIds; + +} diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/sys/entity/RoleAuthority.java b/pmapi/src/main/java/com/ningdatech/pmapi/sys/entity/RoleAuthority.java new file mode 100644 index 0000000..dfb720c --- /dev/null +++ b/pmapi/src/main/java/com/ningdatech/pmapi/sys/entity/RoleAuthority.java @@ -0,0 +1,74 @@ +package com.ningdatech.pmapi.sys.entity; + +import com.baomidou.mybatisplus.annotation.TableField; +import com.baomidou.mybatisplus.annotation.TableName; +import com.ningdatech.pmapi.sys.entity.enumeration.AuthorizeType; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.*; +import lombok.experimental.Accessors; + +import javax.validation.constraints.NotNull; +import java.time.LocalDateTime; + +/** + *

+ * 实体类 + * 角色的资源 + *

+ * + * @author PoffyZhang + */ +@Data +@NoArgsConstructor +@ToString(callSuper = true) +@EqualsAndHashCode(callSuper = true) +@Accessors(chain = true) +@TableName("nd_role_authority") +@ApiModel(value = "RoleAuthority", description = "角色的资源") +@AllArgsConstructor +public class RoleAuthority extends BaseEntity { + + private static final long serialVersionUID = 1L; + + private Long id; + + /** + * 资源id + */ + @ApiModelProperty(value = "资源id") + @NotNull(message = "资源id不能为空") + @TableField("authority_id") + private Long authorityId; + + /** + * 权限类型 + * #AuthorizeType{MENU:菜单;RESOURCE:资源;} + */ + @ApiModelProperty(value = "权限类型") + @NotNull(message = "权限类型不能为空") + @TableField("authority_type") + private AuthorizeType authorityType; + + /** + * 角色id + * #c_role + */ + @ApiModelProperty(value = "角色id") + @NotNull(message = "角色id不能为空") + @TableField("role_id") + private Long roleId; + + + @Builder + public RoleAuthority(Long id, LocalDateTime createTime, Long createdBy, + Long authorityId, AuthorizeType authorityType, Long roleId) { + this.id = id; + this.createOn = createTime; + this.createBy = createdBy; + this.authorityId = authorityId; + this.authorityType = authorityType; + this.roleId = roleId; + } + +} diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/sys/entity/RoleMenu.java b/pmapi/src/main/java/com/ningdatech/pmapi/sys/entity/RoleMenu.java new file mode 100644 index 0000000..54f9875 --- /dev/null +++ b/pmapi/src/main/java/com/ningdatech/pmapi/sys/entity/RoleMenu.java @@ -0,0 +1,40 @@ +package com.ningdatech.pmapi.sys.entity; + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.io.Serializable; + +/** + *

+ * + *

+ * + * @author PoffyZhang + * @since 2022-11-11 + */ +@TableName("nd_role_menu") +@Data +@ApiModel(value = "RoleMenu对象", description = "") +@AllArgsConstructor +@NoArgsConstructor +public class RoleMenu implements Serializable { + + private static final long serialVersionUID = 1L; + + @ApiModelProperty("id") + @TableId(value = "id", type = IdType.AUTO) + private Long id; + + @ApiModelProperty("menu_id") + private Long menuId; + + @ApiModelProperty("role_id") + private Long roleId; +} diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/sys/entity/RoleMenuDatascope.java b/pmapi/src/main/java/com/ningdatech/pmapi/sys/entity/RoleMenuDatascope.java new file mode 100644 index 0000000..83af92c --- /dev/null +++ b/pmapi/src/main/java/com/ningdatech/pmapi/sys/entity/RoleMenuDatascope.java @@ -0,0 +1,36 @@ +package com.ningdatech.pmapi.sys.entity; + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +/** + *

+ * 角色菜单数据权限关联表 + *

+ * + * @author WendyYang + * @since 2023-01-28 + */ +@Data +@TableName("nd_role_menu_datascope") +@ApiModel(value = "NdRoleMenuDatascope对象", description = "角色菜单数据权限关联表") +public class RoleMenuDatascope extends BaseEntity { + + @ApiModelProperty("主键") + @TableId(type = IdType.AUTO) + private Long id; + + @ApiModelProperty("角色ID") + private Long roleId; + + @ApiModelProperty("菜单ID") + private Long menuId; + + @ApiModelProperty("数据权限") + private Integer datascope; + +} diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/sys/entity/UserRole.java b/pmapi/src/main/java/com/ningdatech/pmapi/sys/entity/UserRole.java new file mode 100644 index 0000000..b6dabc1 --- /dev/null +++ b/pmapi/src/main/java/com/ningdatech/pmapi/sys/entity/UserRole.java @@ -0,0 +1,62 @@ +package com.ningdatech.pmapi.sys.entity; + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableField; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; +import lombok.ToString; +import lombok.experimental.Accessors; + +import javax.validation.constraints.NotNull; + +/** + *

+ * 实体类 + * 角色分配 + * 账号角色绑定 + *

+ * + * @author PoffyZhang + */ +@Data +@NoArgsConstructor +@ToString(callSuper = true) +@Accessors(chain = true) +@TableName("nd_user_role") +@ApiModel(value = "UserRole", description = "角色分配") +public class UserRole { + + private static final long serialVersionUID = 1L; + + @TableId(value = "id", type = IdType.AUTO) + private Long id; + + /** + * 角色ID + */ + @ApiModelProperty(value = "角色ID") + @NotNull(message = "角色ID不能为空") + @TableField("role_id") + private Long roleId; + + /** + * 用户ID + */ + @ApiModelProperty(value = "用户ID") + @NotNull(message = "用户ID不能为空") + @TableField("user_id") + private Long userId; + + + @Builder + public UserRole(Long roleId, Long userId) { + this.roleId = roleId; + this.userId = userId; + } + +} diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/sys/entity/dto/MenuDataScopeDTO.java b/pmapi/src/main/java/com/ningdatech/pmapi/sys/entity/dto/MenuDataScopeDTO.java new file mode 100644 index 0000000..0f9ddd0 --- /dev/null +++ b/pmapi/src/main/java/com/ningdatech/pmapi/sys/entity/dto/MenuDataScopeDTO.java @@ -0,0 +1,23 @@ +package com.ningdatech.pmapi.sys.entity.dto; + +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +/** + *

+ * MenuDataScopeDTO + *

+ * + * @author WendyYang + * @since 16:06 2023/1/28 + */ +@Data +public class MenuDataScopeDTO { + + @ApiModelProperty("菜单ID") + private Long menuId; + + @ApiModelProperty("数据权限") + private Integer dataScope; + +} diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/sys/entity/dto/MenuQueryDTO.java b/pmapi/src/main/java/com/ningdatech/pmapi/sys/entity/dto/MenuQueryDTO.java new file mode 100644 index 0000000..0571ff7 --- /dev/null +++ b/pmapi/src/main/java/com/ningdatech/pmapi/sys/entity/dto/MenuQueryDTO.java @@ -0,0 +1,97 @@ +package com.ningdatech.pmapi.sys.entity.dto; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.*; +import lombok.experimental.Accessors; + +import java.io.Serializable; + +/** + *

+ * 实体类 + * 菜单 + *

+ * + * @author PoffyZhang + */ +@Data +@NoArgsConstructor +@AllArgsConstructor +@Accessors(chain = true) +@ToString(callSuper = true) +@EqualsAndHashCode(callSuper = false) +@Builder +@ApiModel(value = "MenuQueryDTO", description = "菜单") +public class MenuQueryDTO implements Serializable { + + private static final long serialVersionUID = 1L; + + private Long id; + + /** + * 名称 + */ + @ApiModelProperty(value = "名称") + private String name; + + /** + * 标题 + */ + @ApiModelProperty(value = "标题") + private String title; + + /** + * 类型 + */ + @ApiModelProperty(value = "类型") + private Integer type; + + /** + * 页面路径 + */ + @ApiModelProperty(value = "页面路径") + private String path; + + /** + * 图标 + */ + @ApiModelProperty(value = "图标") + private String icon; + + /** + * 组件 + */ + @ApiModelProperty(value = "组件") + private String component; + + /** + * 权限 + */ + @ApiModelProperty(value = "权限") + private String permission; + + /** + * 排序 + */ + @ApiModelProperty(value = "排序") + private Integer sort; + + /** + * 父菜单ID + */ + @ApiModelProperty(value = "父菜单ID") + private Long pid; + + /** + * activeMenu + */ + @ApiModelProperty(value = "activeMenu") + private String activeMenu; + + /** + * 跳转 + */ + @ApiModelProperty(value = "跳转") + private String redirect; +} diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/sys/entity/dto/MenuSaveDTO.java b/pmapi/src/main/java/com/ningdatech/pmapi/sys/entity/dto/MenuSaveDTO.java new file mode 100644 index 0000000..7a5661b --- /dev/null +++ b/pmapi/src/main/java/com/ningdatech/pmapi/sys/entity/dto/MenuSaveDTO.java @@ -0,0 +1,92 @@ +package com.ningdatech.pmapi.sys.entity.dto; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.*; +import lombok.experimental.Accessors; + +import javax.validation.constraints.NotEmpty; +import javax.validation.constraints.NotNull; +import java.io.Serializable; + +/** + *

+ * 实体类 + * 菜单 + *

+ * + * @author WendyYang + */ +@Data +@NoArgsConstructor +@AllArgsConstructor +@Accessors(chain = true) +@ToString(callSuper = true) +@EqualsAndHashCode(callSuper = false) +@Builder +@ApiModel(value = "MenuSaveDTO", description = "菜单") +public class MenuSaveDTO implements Serializable { + + private static final long serialVersionUID = 1L; + + /** + * 名称 + */ + @ApiModelProperty(value = "名称") + private String name; + + /** + * 标题 + */ + @ApiModelProperty(value = "标题") + @NotEmpty(message = "请输入菜单标题") + private String title; + + /** + * 页面路径 + */ + @ApiModelProperty(value = "页面路径") + private String path; + + /** + * 图标 + */ + @ApiModelProperty(value = "图标") + private String icon; + + /** + * 组件 + */ + @ApiModelProperty(value = "组件") + private String component; + + /** + * 排序 + */ + @ApiModelProperty(value = "排序") + private Integer sort; + + /** + * 父菜单ID + */ + @ApiModelProperty(value = "父菜单ID") + private Long pid; + + /** + * 是否隐藏 0不隐藏 1隐藏 + */ + @ApiModelProperty(value = "是否隐藏") + private Integer hidden; + + /** + * activeMenu + */ + @ApiModelProperty(value = "activeMenu") + private String activeMenu; + + /** + * 跳转 + */ + @ApiModelProperty(value = "跳转") + private String redirect; +} diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/sys/entity/dto/MenuUpdateDTO.java b/pmapi/src/main/java/com/ningdatech/pmapi/sys/entity/dto/MenuUpdateDTO.java new file mode 100644 index 0000000..03163c2 --- /dev/null +++ b/pmapi/src/main/java/com/ningdatech/pmapi/sys/entity/dto/MenuUpdateDTO.java @@ -0,0 +1,100 @@ +package com.ningdatech.pmapi.sys.entity.dto; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.*; +import lombok.experimental.Accessors; + +import javax.validation.constraints.NotNull; +import java.io.Serializable; + +/** + *

+ * 实体类 + * 菜单 + *

+ * + * @author PoffyZhang + */ +@Data +@NoArgsConstructor +@AllArgsConstructor +@Accessors(chain = true) +@ToString(callSuper = true) +@EqualsAndHashCode(callSuper = false) +@Builder +@ApiModel(value = "MenuUpdateDTO", description = "菜单") +public class MenuUpdateDTO implements Serializable { + + private static final long serialVersionUID = 1L; + + @ApiModelProperty(value = "id") + @NotNull(message = "请传id") + private Long id; + + /** + * 名称 + */ + @ApiModelProperty(value = "名称") + private String name; + + /** + * 标题 + */ + @ApiModelProperty(value = "标题") + private String title; + + /** + * 类型 + */ + @ApiModelProperty(value = "类型") + private Integer type; + + /** + * 页面路径 + */ + @ApiModelProperty(value = "页面路径") + private String path; + + /** + * 图标 + */ + @ApiModelProperty(value = "图标") + private String icon; + + /** + * 组件 + */ + @ApiModelProperty(value = "组件") + private String component; + + /** + * 排序 + */ + @ApiModelProperty(value = "排序") + private Integer sort; + + /** + * 父菜单ID + */ + @ApiModelProperty(value = "父菜单ID") + private Long pid; + + /** + * 是否隐藏 0不隐藏 1隐藏 + */ + @ApiModelProperty(value = "是否隐藏") + private Integer hidden; + + /** + * activeMenu + */ + @ApiModelProperty(value = "activeMenu") + private String activeMenu; + + /** + * 跳转 + */ + @ApiModelProperty(value = "跳转") + private String redirect; +} diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/sys/entity/dto/ResourceQueryDTO.java b/pmapi/src/main/java/com/ningdatech/pmapi/sys/entity/dto/ResourceQueryDTO.java new file mode 100644 index 0000000..ff5f174 --- /dev/null +++ b/pmapi/src/main/java/com/ningdatech/pmapi/sys/entity/dto/ResourceQueryDTO.java @@ -0,0 +1,34 @@ +package com.ningdatech.pmapi.sys.entity.dto; + + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +/** + * 资源 查询DTO + * + * @author PoffyZhang + */ +@Data +@NoArgsConstructor +@AllArgsConstructor +@Builder +@ApiModel(value = "ResourceQueryDTO", description = "资源查询") +public class ResourceQueryDTO { + + /** + * 父资源id, 用于查询按钮 + */ + @ApiModelProperty(value = "菜单id", notes = "指定菜单id") + private Long menuId; + /** + * 登录人用户id + */ + @ApiModelProperty(value = "指定用户id", notes = "指定用户id,前端不传则自动获取") + private Long userId; + +} diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/sys/entity/dto/ResourceSaveDTO.java b/pmapi/src/main/java/com/ningdatech/pmapi/sys/entity/dto/ResourceSaveDTO.java new file mode 100644 index 0000000..008e733 --- /dev/null +++ b/pmapi/src/main/java/com/ningdatech/pmapi/sys/entity/dto/ResourceSaveDTO.java @@ -0,0 +1,63 @@ +package com.ningdatech.pmapi.sys.entity.dto; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.*; +import lombok.experimental.Accessors; + +import javax.validation.constraints.NotEmpty; +import javax.validation.constraints.Size; +import java.io.Serializable; + +/** + *

+ * 实体类 + * 资源 + *

+ * + * @author PoffyZhang + */ +@Data +@NoArgsConstructor +@AllArgsConstructor +@Accessors(chain = true) +@ToString(callSuper = true) +@EqualsAndHashCode(callSuper = false) +@Builder +@ApiModel(value = "ResourceSaveDTO", description = "资源") +public class ResourceSaveDTO implements Serializable { + + private static final long serialVersionUID = 1L; + + /** + * 编码 + */ + @ApiModelProperty(value = "编码") + @Size(max = 500, message = "编码长度不能超过500") + private String code; + /** + * 名称 + */ + @ApiModelProperty(value = "名称") + @NotEmpty(message = "名称不能为空") + @Size(max = 255, message = "名称长度不能超过255") + private String name; + /** + * 菜单ID + * #c_menu + */ + @ApiModelProperty(value = "菜单ID") + private Long menuId; + /** + * 描述 + */ + @ApiModelProperty(value = "描述") + @Size(max = 255, message = "描述长度不能超过255") + private String describe; + /** + * 内置 + */ + @ApiModelProperty(value = "内置") + private Boolean readonly; + +} diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/sys/entity/dto/ResourceUpdateDTO.java b/pmapi/src/main/java/com/ningdatech/pmapi/sys/entity/dto/ResourceUpdateDTO.java new file mode 100644 index 0000000..3394406 --- /dev/null +++ b/pmapi/src/main/java/com/ningdatech/pmapi/sys/entity/dto/ResourceUpdateDTO.java @@ -0,0 +1,68 @@ +package com.ningdatech.pmapi.sys.entity.dto; + +import com.baomidou.mybatisplus.core.conditions.update.Update; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.*; +import lombok.experimental.Accessors; + +import javax.validation.constraints.NotEmpty; +import javax.validation.constraints.NotNull; +import javax.validation.constraints.Size; +import java.io.Serializable; + +/** + *

+ * 实体类 + * 资源 + *

+ * + * @author PoffyZhang + */ +@Data +@NoArgsConstructor +@AllArgsConstructor +@Accessors(chain = true) +@ToString(callSuper = true) +@EqualsAndHashCode(callSuper = false) +@Builder +@ApiModel(value = "ResourceUpdateDTO", description = "资源") +public class ResourceUpdateDTO implements Serializable { + + private static final long serialVersionUID = 1L; + + @ApiModelProperty(value = "主键") + @NotNull(message = "id不能为空", groups = Update.class) + private Long id; + + /** + * 编码 + */ + @ApiModelProperty(value = "编码") + @Size(max = 500, message = "编码长度不能超过500") + private String code; + /** + * 名称 + */ + @ApiModelProperty(value = "名称") + @NotEmpty(message = "名称不能为空") + @Size(max = 255, message = "名称长度不能超过255") + private String name; + /** + * 菜单ID + * #c_menu + */ + @ApiModelProperty(value = "菜单ID") + private Long menuId; + /** + * 描述 + */ + @ApiModelProperty(value = "描述") + @Size(max = 255, message = "描述长度不能超过255") + private String describe; + /** + * 内置 + */ + @ApiModelProperty(value = "内置") + private Boolean readonly; +} diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/sys/entity/dto/RoleAuthoritySaveDTO.java b/pmapi/src/main/java/com/ningdatech/pmapi/sys/entity/dto/RoleAuthoritySaveDTO.java new file mode 100644 index 0000000..0644697 --- /dev/null +++ b/pmapi/src/main/java/com/ningdatech/pmapi/sys/entity/dto/RoleAuthoritySaveDTO.java @@ -0,0 +1,53 @@ +package com.ningdatech.pmapi.sys.entity.dto; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.*; +import lombok.experimental.Accessors; + +import javax.validation.constraints.NotNull; +import java.io.Serializable; +import java.util.List; + +/** + *

+ * 实体类 + * 角色的资源 + *

+ * + * @author PoffyZhang + */ +@Data +@NoArgsConstructor +@AllArgsConstructor +@Accessors(chain = true) +@ToString(callSuper = true) +@EqualsAndHashCode(callSuper = false) +@Builder +@ApiModel(value = "RoleAuthoritySaveDTO", description = "角色的资源") +public class RoleAuthoritySaveDTO implements Serializable { + + private static final long serialVersionUID = 1L; + + /** + * 菜单ID + * #c_menu + */ + @ApiModelProperty(value = "资源ID") + private List menuIdList; + + /** + * 资源id + * #c_resource + */ + private List resourceIdList; + + /** + * 角色id + * #c_role + */ + @ApiModelProperty(value = "角色id") + @NotNull(message = "角色id不能为空") + private Long roleId; + +} diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/sys/entity/dto/RolePageReq.java b/pmapi/src/main/java/com/ningdatech/pmapi/sys/entity/dto/RolePageReq.java new file mode 100644 index 0000000..95dda52 --- /dev/null +++ b/pmapi/src/main/java/com/ningdatech/pmapi/sys/entity/dto/RolePageReq.java @@ -0,0 +1,37 @@ +package com.ningdatech.pmapi.sys.entity.dto; + +import com.ningdatech.basic.model.PagePo; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.*; +import lombok.experimental.Accessors; + +import java.io.Serializable; + +/** + *

+ * 实体类 + * 角色 + *

+ * + * @author PoffyZhang + */ +@Data +@NoArgsConstructor +@AllArgsConstructor +@Accessors(chain = true) +@ToString(callSuper = true) +@EqualsAndHashCode(callSuper = false) +@Builder +@ApiModel(value = "RolePageQuery", description = "角色") +public class RolePageReq extends PagePo implements Serializable { + + private static final long serialVersionUID = 1L; + + /** + * 名称 + */ + @ApiModelProperty(value = "名称") + private String name; + +} diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/sys/entity/dto/RoleQueryDTO.java b/pmapi/src/main/java/com/ningdatech/pmapi/sys/entity/dto/RoleQueryDTO.java new file mode 100644 index 0000000..b4eb942 --- /dev/null +++ b/pmapi/src/main/java/com/ningdatech/pmapi/sys/entity/dto/RoleQueryDTO.java @@ -0,0 +1,48 @@ +package com.ningdatech.pmapi.sys.entity.dto; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.*; +import lombok.experimental.Accessors; + +import java.io.Serializable; + +/** + *

+ * 实体类 + * 角色 + *

+ * + * @author PoffyZhang + */ +@Data +@NoArgsConstructor +@AllArgsConstructor +@Accessors(chain = true) +@ToString(callSuper = true) +@EqualsAndHashCode(callSuper = false) +@Builder +@ApiModel(value = "RoleQueryDTO", description = "角色") +public class RoleQueryDTO implements Serializable { + + private static final long serialVersionUID = 1L; + @ApiModelProperty(value = "ID") + private Long id; + + /** + * 角色名称 + */ + @ApiModelProperty(value = "角色名称") + private String name; + /** + * 描述 + */ + @ApiModelProperty(value = "描述") + private String describe; + + /** + * 数据范围 + */ + @ApiModelProperty(value = "数据范围") + private Integer dataScope; +} diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/sys/entity/dto/RoleSaveDTO.java b/pmapi/src/main/java/com/ningdatech/pmapi/sys/entity/dto/RoleSaveDTO.java new file mode 100644 index 0000000..bf62cad --- /dev/null +++ b/pmapi/src/main/java/com/ningdatech/pmapi/sys/entity/dto/RoleSaveDTO.java @@ -0,0 +1,63 @@ +package com.ningdatech.pmapi.sys.entity.dto; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.*; +import lombok.experimental.Accessors; + +import javax.validation.constraints.NotEmpty; +import javax.validation.constraints.Size; +import java.io.Serializable; +import java.util.List; + +/** + *

+ * 实体类 + * 角色 + *

+ * + * @author PoffyZhang + */ +@Data +@NoArgsConstructor +@AllArgsConstructor +@Accessors(chain = true) +@ToString(callSuper = true) +@EqualsAndHashCode(callSuper = false) +@Builder +@ApiModel(value = "RoleSaveDTO", description = "角色") +public class RoleSaveDTO implements Serializable { + + private static final long serialVersionUID = 1L; + + /** + * 名称 + */ + @ApiModelProperty(value = "名称") + @NotEmpty(message = "名称不能为空") + @Size(max = 50, message = "名称长度不能超过50") + private String name; + + /** + * 描述 + */ + @ApiModelProperty(value = "描述") + @Size(max = 200, message = "描述长度不能超过200") + private String describe; + + /** + * 数据范围 + */ + @ApiModelProperty(value = "管理角色ID") + private String manageRoleIds; + + /** + * 菜单id + */ + @ApiModelProperty(value = "菜单id") + private List menuIds; + + @ApiModelProperty("菜单数据权限") + private List menuDataScopeList; + +} diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/sys/entity/dto/RoleUpdateDTO.java b/pmapi/src/main/java/com/ningdatech/pmapi/sys/entity/dto/RoleUpdateDTO.java new file mode 100644 index 0000000..56a3a5b --- /dev/null +++ b/pmapi/src/main/java/com/ningdatech/pmapi/sys/entity/dto/RoleUpdateDTO.java @@ -0,0 +1,55 @@ +package com.ningdatech.pmapi.sys.entity.dto; + +import com.baomidou.mybatisplus.core.conditions.update.Update; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.*; +import lombok.experimental.Accessors; + +import javax.validation.constraints.NotNull; +import javax.validation.constraints.Size; +import java.io.Serializable; +import java.util.List; + +/** + *

+ * 实体类 + * 角色 + *

+ * + * @author PoffyZhang + */ +@Data +@NoArgsConstructor +@AllArgsConstructor +@Accessors(chain = true) +@ToString(callSuper = true) +@EqualsAndHashCode(callSuper = false) +@Builder +@ApiModel(value = "RoleUpdateDTO", description = "角色") +public class RoleUpdateDTO implements Serializable { + + private static final long serialVersionUID = 1L; + + @ApiModelProperty(value = "主键") + @NotNull(message = "id不能为空", groups = Update.class) + private Long id; + + @ApiModelProperty(value = "名称") + @Size(max = 50, message = "名称长度不能超过30") + private String name; + + @ApiModelProperty(value = "描述") + @Size(max = 200, message = "描述长度不能超过200") + private String describe; + + @ApiModelProperty(value = "菜单id") + private List menuIds; + + @ApiModelProperty(value = "管理角色ID") + private String manageRoleIds; + + @ApiModelProperty("菜单数据权限") + private List menuDataScopeList; + +} diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/sys/entity/dto/RoleUserSaveVO.java b/pmapi/src/main/java/com/ningdatech/pmapi/sys/entity/dto/RoleUserSaveVO.java new file mode 100644 index 0000000..1e2549d --- /dev/null +++ b/pmapi/src/main/java/com/ningdatech/pmapi/sys/entity/dto/RoleUserSaveVO.java @@ -0,0 +1,48 @@ +package com.ningdatech.pmapi.sys.entity.dto; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.*; +import lombok.experimental.Accessors; + +import javax.validation.constraints.NotNull; +import javax.validation.constraints.Size; +import java.io.Serializable; +import java.util.List; + +/** + *

+ * 实体类 + * 角色下的员工 + *

+ * + * @author PoffyZhang + */ +@Data +@NoArgsConstructor +@AllArgsConstructor +@Accessors(chain = true) +@ToString(callSuper = true) +@EqualsAndHashCode(callSuper = false) +@Builder +@ApiModel(value = "RoleUserSaveVO", description = "给角色分配员工") +public class RoleUserSaveVO implements Serializable { + + private static final long serialVersionUID = 1L; + @ApiModelProperty(value = "绑定或取消") + @NotNull(message = "请填写绑定或取消参数") + private Boolean flag; + /** + * 角色;#c_role + */ + @ApiModelProperty(value = "角色") + @NotNull(message = "请选择角色") + private Long roleId; + /** + * 用户;#c_user + */ + @ApiModelProperty(value = "用户") + @Size(min = 1, message = "请选择用户") + private List userIdList; + +} diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/sys/entity/dto/UserRoleSaveDTO.java b/pmapi/src/main/java/com/ningdatech/pmapi/sys/entity/dto/UserRoleSaveDTO.java new file mode 100644 index 0000000..799acd0 --- /dev/null +++ b/pmapi/src/main/java/com/ningdatech/pmapi/sys/entity/dto/UserRoleSaveDTO.java @@ -0,0 +1,47 @@ +package com.ningdatech.pmapi.sys.entity.dto; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.*; +import lombok.experimental.Accessors; + +import javax.validation.constraints.NotNull; +import java.io.Serializable; +import java.util.List; + +/** + *

+ * 实体类 + * 角色分配 + * 账号角色绑定 + *

+ * + * @author PoffyZhang + */ +@Data +@NoArgsConstructor +@AllArgsConstructor +@Accessors(chain = true) +@ToString(callSuper = true) +@EqualsAndHashCode(callSuper = false) +@Builder +@ApiModel(value = "UserRoleSaveDTO", description = "角色分配 账号角色绑定") +public class UserRoleSaveDTO implements Serializable { + + private static final long serialVersionUID = 1L; + + /** + * 角色ID + * #c_role + */ + @ApiModelProperty(value = "角色ID") + @NotNull(message = "请选择角色") + private Long roleId; + /** + * 用户ID + * #c_user + */ + @ApiModelProperty(value = "用户ID") + private List userIdList; + +} diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/sys/entity/enumeration/AuthorizeType.java b/pmapi/src/main/java/com/ningdatech/pmapi/sys/entity/enumeration/AuthorizeType.java new file mode 100644 index 0000000..01da87e --- /dev/null +++ b/pmapi/src/main/java/com/ningdatech/pmapi/sys/entity/enumeration/AuthorizeType.java @@ -0,0 +1,60 @@ +package com.ningdatech.pmapi.sys.entity.enumeration; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; + +import java.util.stream.Stream; + +/** + *

+ * 实体注释中生成的类型枚举 + * 角色的资源 + *

+ * + * @author PoffyZhang + * @since 2022-09-30 + */ +@Getter +@AllArgsConstructor +@NoArgsConstructor +@ApiModel(value = "AuthorizeType", description = "权限类型-枚举") +public enum AuthorizeType { + + /** + * MENU="菜单" + */ + MENU("菜单"), + DATA("数据"), + /** + * RESOURCE="资源" + */ + RESOURCE("资源"); + + @ApiModelProperty(value = "描述") + private String desc; + + + /** + * 根据当前枚举的name匹配 + */ + public static AuthorizeType match(String val, AuthorizeType def) { + return Stream.of(values()).parallel().filter(item -> item.name().equalsIgnoreCase(val)).findAny().orElse(def); + } + + public static AuthorizeType get(String val) { + return match(val, null); + } + + public boolean eq(AuthorizeType val) { + return val != null && getCode().equals(val.name()); + } + + @ApiModelProperty(value = "编码", allowableValues = "MENU,RESOURCE", example = "MENU") + public String getCode() { + return this.name(); + } + +} diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/sys/entity/enumeration/DataScopeEnum.java b/pmapi/src/main/java/com/ningdatech/pmapi/sys/entity/enumeration/DataScopeEnum.java new file mode 100644 index 0000000..1843fce --- /dev/null +++ b/pmapi/src/main/java/com/ningdatech/pmapi/sys/entity/enumeration/DataScopeEnum.java @@ -0,0 +1,31 @@ +package com.ningdatech.pmapi.sys.entity.enumeration; + +import lombok.Getter; + +/** + *

+ * DataScopeEnum + *

+ * + * @author WendyYang + * @since 15:59 2023/1/28 + */ +@Getter +public enum DataScopeEnum { + + /** + * 数据权限可见范围 + */ + CURRENT_ORG("本单位", 1), + CURRENT_AND_SUB_ORG("本单位及下属单位", 2), + CURRENT_REGION("当前区域", 3), + CURRENT_CITY("全市", 4); + + private final String desc; + private final Integer code; + + DataScopeEnum(String desc, Integer code) { + this.code = code; + this.desc = desc; + } +} diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/sys/entity/enumeration/MenuTypeEnum.java b/pmapi/src/main/java/com/ningdatech/pmapi/sys/entity/enumeration/MenuTypeEnum.java new file mode 100644 index 0000000..2e24913 --- /dev/null +++ b/pmapi/src/main/java/com/ningdatech/pmapi/sys/entity/enumeration/MenuTypeEnum.java @@ -0,0 +1,57 @@ +package com.ningdatech.pmapi.sys.entity.enumeration; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; + +/** + * 资源类型 + * + * @author PoffyZhang + */ +@Getter +@AllArgsConstructor +@NoArgsConstructor +@ApiModel(value = "MenuTypeEnum", description = "资源类型-枚举") +public enum MenuTypeEnum { + /** + * 菜单 + */ + MENU(0, "菜单"), + + /** + * 按钮 + */ + BUTTON(1, "按钮"); + + /** + * 资源类型 + */ + private Integer code; + + /** + * 资源描述 + */ + private String desc; + + public String getDesc() { + return desc; + } + + public void setDesc(String desc) { + this.desc = desc; + } + + @ApiModelProperty(value = "编码", allowableValues = "0,1", example = "0") + public Integer getCode() { + return this.code; + } + + + public boolean eq(String val) { + return this.name().equals(val); + } + +} diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/sys/entity/vo/MenuResourceTreeVO.java b/pmapi/src/main/java/com/ningdatech/pmapi/sys/entity/vo/MenuResourceTreeVO.java new file mode 100644 index 0000000..0eb7b07 --- /dev/null +++ b/pmapi/src/main/java/com/ningdatech/pmapi/sys/entity/vo/MenuResourceTreeVO.java @@ -0,0 +1,35 @@ +package com.ningdatech.pmapi.sys.entity.vo; + +import com.baomidou.mybatisplus.annotation.TableField; +import com.ningdatech.pmapi.sys.entity.enumeration.AuthorizeType; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.ToString; + +import javax.validation.constraints.Size; + +import static com.baomidou.mybatisplus.annotation.SqlCondition.LIKE; + +/** + * menuList + * 菜单资源树 + * + * @author PoffyZhang + */ +@Data +@ToString(callSuper = true) +public class MenuResourceTreeVO { + + private AuthorizeType type; + private String code; + private String icon; + private Boolean isDef; + /** + * 描述 + */ + @ApiModelProperty(value = "描述") + @Size(max = 200, message = "描述长度不能超过200") + @TableField(value = "describe_", condition = LIKE) + private String describe; + +} diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/sys/entity/vo/MenuRoleVO.java b/pmapi/src/main/java/com/ningdatech/pmapi/sys/entity/vo/MenuRoleVO.java new file mode 100644 index 0000000..e7b4990 --- /dev/null +++ b/pmapi/src/main/java/com/ningdatech/pmapi/sys/entity/vo/MenuRoleVO.java @@ -0,0 +1,78 @@ +package com.ningdatech.pmapi.sys.entity.vo; + +import com.baomidou.mybatisplus.annotation.TableField; +import com.ningdatech.pmapi.common.model.entity.MenuTreeEntity; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.*; +import lombok.experimental.Accessors; + +/** + *

+ * 实体类 + * 菜单 + *

+ * + * @author PoffyZhang + * @since 2022-9-30 + */ +@Data +@NoArgsConstructor +@ToString(callSuper = true) +@EqualsAndHashCode(callSuper = true) +@Accessors(chain = true) +@ApiModel(value = "RoleMenuVO", description = "菜单") +@AllArgsConstructor +public class MenuRoleVO extends MenuTreeEntity { + + private static final long serialVersionUID = 1L; + + /** + * 权限" + */ + @ApiModelProperty(value = "权限") + private String permission; + /** + * 类型;[0-菜单 1-目录 2-按钮] + */ + @ApiModelProperty(value = "类型") + private Integer type; + + /** + * 组件 + */ + @ApiModelProperty(value = "组件") + private String component; + + /** + * 菜单图标 + */ + @ApiModelProperty(value = "菜单图标") + private String icon; + + /** + * 是否隐藏 + */ + @ApiModelProperty(value = "是否隐藏") + private Integer hidden; + + /** + * 是否有权限 + */ + @ApiModelProperty(value = "是否有权限 0没有 1有") + private Integer hasPermission = 0; + + /** + * activeMenu + */ + @ApiModelProperty(value = "activeMenu") + private String activeMenu; + + /** + * 跳转 + */ + @ApiModelProperty(value = "跳转") + @TableField(value = "redirect") + private String redirect; + +} diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/sys/entity/vo/MenuVO.java b/pmapi/src/main/java/com/ningdatech/pmapi/sys/entity/vo/MenuVO.java new file mode 100644 index 0000000..83ad8bd --- /dev/null +++ b/pmapi/src/main/java/com/ningdatech/pmapi/sys/entity/vo/MenuVO.java @@ -0,0 +1,70 @@ +package com.ningdatech.pmapi.sys.entity.vo; + +import com.baomidou.mybatisplus.annotation.TableField; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.*; +import lombok.experimental.Accessors; + +/** + *

+ * 实体类 + * 菜单 + *

+ * + * @author PoffyZhang + * @since 2022-9-30 + */ +@Data +@NoArgsConstructor +@ToString(callSuper = true) +@Accessors(chain = true) +@ApiModel(value = "MenuVO", description = "菜单") +@AllArgsConstructor +@Builder +public class MenuVO { + + private static final long serialVersionUID = 1L; + + /** + * 权限" + */ + @ApiModelProperty(value = "权限") + private String permission; + /** + * 类型;[0-菜单 1按钮] + */ + @ApiModelProperty(value = "类型") + private Integer type; + + /** + * 组件 + */ + @ApiModelProperty(value = "组件") + private String component; + + /** + * 菜单图标 + */ + @ApiModelProperty(value = "菜单图标") + private String icon; + + /** + * 子菜单数目 + */ + @ApiModelProperty(value = "是否隐藏") + private Integer hidden; + + /** + * activeMenu + */ + @ApiModelProperty(value = "activeMenu") + private String activeMenu; + + /** + * 跳转 + */ + @ApiModelProperty(value = "跳转") + @TableField(value = "redirect") + private String redirect; +} diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/sys/entity/vo/RoleVO.java b/pmapi/src/main/java/com/ningdatech/pmapi/sys/entity/vo/RoleVO.java new file mode 100644 index 0000000..9945b7c --- /dev/null +++ b/pmapi/src/main/java/com/ningdatech/pmapi/sys/entity/vo/RoleVO.java @@ -0,0 +1,57 @@ +package com.ningdatech.pmapi.sys.entity.vo; + +import com.ningdatech.pmapi.sys.entity.BaseEntity; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.*; +import lombok.experimental.Accessors; + +import java.util.List; + +/** + *

+ * 实体类 + * 角色 + *

+ * + * @author PoffyZhang + * @since 2022-09-30 + */ +@Data +@NoArgsConstructor +@ToString(callSuper = true) +@EqualsAndHashCode(callSuper = true) +@Accessors(chain = true) +@ApiModel(value = "Role", description = "角色") +@AllArgsConstructor +@Builder +public class RoleVO extends BaseEntity { + + private Long id; + + private static final long serialVersionUID = 1L; + + /** + * 名称 + */ + @ApiModelProperty(value = "名称") + private String name; + + /** + * 描述 + */ + @ApiModelProperty(value = "描述") + private String describe; + + /** + * 数据范围 + */ + @ApiModelProperty(value = "数据范围 1全部 2本区域 3本区域以及下区域 4本公司") + private Integer dataScope; + + /** + * 菜单 + */ + @ApiModelProperty(value = "菜单") + private List menu; +} diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/sys/manage/MenuManage.java b/pmapi/src/main/java/com/ningdatech/pmapi/sys/manage/MenuManage.java new file mode 100644 index 0000000..3307485 --- /dev/null +++ b/pmapi/src/main/java/com/ningdatech/pmapi/sys/manage/MenuManage.java @@ -0,0 +1,44 @@ +package com.ningdatech.pmapi.sys.manage; + +import cn.hutool.core.bean.BeanUtil; +import cn.hutool.core.collection.CollUtil; +import com.baomidou.mybatisplus.core.toolkit.Wrappers; +import com.ningdatech.basic.util.CollUtils; +import com.ningdatech.pmapi.common.utils.TreeUtil; +import com.ningdatech.pmapi.sys.entity.Menu; +import com.ningdatech.pmapi.sys.entity.RoleMenu; +import com.ningdatech.pmapi.sys.entity.vo.MenuRoleVO; +import com.ningdatech.pmapi.sys.service.IRoleMenuService; +import com.ningdatech.pmapi.user.security.auth.model.UserInfoDetails; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Component; + +import java.util.Collections; +import java.util.List; +import java.util.Objects; + +/** + *

+ * MenuManage - 菜单管理业务层 + *

+ * + * @author WendyYang + * @since 14:23 2023/1/28 + */ +@Component +@RequiredArgsConstructor +public class MenuManage { + + private final IRoleMenuService roleMenuService; + + public List buildUserMenu(List list, UserInfoDetails loginUser) { + if (Objects.isNull(loginUser) || CollUtil.isEmpty(loginUser.getRoleIdList())) { + return Collections.emptyList(); + } + List roleMenus = roleMenuService.list(Wrappers.lambdaQuery(RoleMenu.class) + .in(RoleMenu::getRoleId, loginUser.getRoleIdList())); + List menuRoles = CollUtils.convert(list, w -> BeanUtil.copyProperties(w, MenuRoleVO.class)); + return TreeUtil.buildUserTree(menuRoles, roleMenus); + } + +} diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/sys/manage/RoleManage.java b/pmapi/src/main/java/com/ningdatech/pmapi/sys/manage/RoleManage.java new file mode 100644 index 0000000..102af3e --- /dev/null +++ b/pmapi/src/main/java/com/ningdatech/pmapi/sys/manage/RoleManage.java @@ -0,0 +1,74 @@ +package com.ningdatech.pmapi.sys.manage; + +import cn.hutool.core.bean.BeanUtil; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.core.toolkit.Wrappers; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.ningdatech.basic.model.PageVo; +import com.ningdatech.basic.util.CollUtils; +import com.ningdatech.pmapi.sys.entity.Menu; +import com.ningdatech.pmapi.sys.entity.Role; +import com.ningdatech.pmapi.sys.entity.RoleMenu; +import com.ningdatech.pmapi.sys.entity.dto.RolePageReq; +import com.ningdatech.pmapi.sys.entity.vo.MenuRoleVO; +import com.ningdatech.pmapi.sys.entity.vo.RoleVO; +import com.ningdatech.pmapi.sys.service.IRoleMenuService; +import com.ningdatech.pmapi.sys.service.IMenuService; +import com.ningdatech.pmapi.sys.service.IRoleService; +import lombok.RequiredArgsConstructor; +import org.apache.commons.lang3.StringUtils; +import org.springframework.stereotype.Component; + +import java.util.List; +import java.util.Objects; +import java.util.stream.Collectors; + +/** + *

+ * 角色管理 + *

+ * + * @author WendyYang + * @since 12:01 2023/1/28 + */ +@Component +@RequiredArgsConstructor +public class RoleManage { + + private final IRoleService IRoleService; + private final IMenuService IMenuService; + + private final IRoleMenuService roleMenuService; + + public PageVo queryList(RolePageReq rolePageReq) { + Page page = rolePageReq.page(); + LambdaQueryWrapper wrapper = Wrappers.lambdaQuery(Role.class); + searchList(page, wrapper, rolePageReq); + List data = CollUtils.convert(page.getRecords(), w -> BeanUtil.copyProperties(w, RoleVO.class)); + return PageVo.of(data, page.getTotal()); + } + + private void searchList(Page page, LambdaQueryWrapper wrapper, RolePageReq rolePageReq) { + wrapper.like(StringUtils.isNotBlank(rolePageReq.getName()), Role::getName, rolePageReq.getName()) + .orderByDesc(Role::getUpdateOn); + IRoleService.page(page, wrapper); + } + + + public void buildMenu(RoleVO query) { + //改成直接返回有权限的 + List list = IMenuService.list(Wrappers.lambdaQuery(Menu.class).orderByAsc(Menu::getSort)); + List roleMenus = roleMenuService.list(Wrappers.lambdaQuery(RoleMenu.class) + .eq(RoleMenu::getRoleId, query.getId())); + List menus = list.stream().map(menu -> { + for (RoleMenu roleMenu : roleMenus) { + if (roleMenu.getMenuId().equals(menu.getId())) { + return BeanUtil.copyProperties(menu, MenuRoleVO.class); + } + } + return null; + }).filter(Objects::nonNull).collect(Collectors.toList()); + query.setMenu(menus); + } + +} diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/sys/mapper/MenuMapper.java b/pmapi/src/main/java/com/ningdatech/pmapi/sys/mapper/MenuMapper.java new file mode 100644 index 0000000..bb0224a --- /dev/null +++ b/pmapi/src/main/java/com/ningdatech/pmapi/sys/mapper/MenuMapper.java @@ -0,0 +1,18 @@ +package com.ningdatech.pmapi.sys.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.ningdatech.pmapi.sys.entity.Menu; +import org.springframework.stereotype.Repository; + +/** + *

+ * Mapper 接口 + * 菜单 + *

+ * + * @author PoffyZhang + */ +@Repository +public interface MenuMapper extends BaseMapper { + +} diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/sys/mapper/MenuMapper.xml b/pmapi/src/main/java/com/ningdatech/pmapi/sys/mapper/MenuMapper.xml new file mode 100644 index 0000000..f1972d6 --- /dev/null +++ b/pmapi/src/main/java/com/ningdatech/pmapi/sys/mapper/MenuMapper.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/sys/mapper/ResourceMapper.java b/pmapi/src/main/java/com/ningdatech/pmapi/sys/mapper/ResourceMapper.java new file mode 100644 index 0000000..32b995d --- /dev/null +++ b/pmapi/src/main/java/com/ningdatech/pmapi/sys/mapper/ResourceMapper.java @@ -0,0 +1,44 @@ +package com.ningdatech.pmapi.sys.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.ningdatech.pmapi.sys.entity.Resource; +import com.ningdatech.pmapi.sys.entity.dto.ResourceQueryDTO; +import org.apache.ibatis.annotations.Param; +import org.springframework.stereotype.Repository; + +import java.util.List; + +/** + *

+ * Mapper 接口 + * 资源 + *

+ * + * @author PoffyZhang + */ +@Repository +public interface ResourceMapper extends BaseMapper { + /** + * 查询 拥有的资源 + * + * @param resource 查询参数 + * @return 可用资源 + */ + List findVisibleResource(ResourceQueryDTO resource); + + /** + * 根据唯一索引 保存或修改资源 + * + * @param resource 资源 + * @return 操作条数 + */ + int saveOrUpdateUnique(Resource resource); + + /** + * 根据资源id查询菜单id + * + * @param resourceIdList 资源id + * @return 菜单id + */ + List findMenuIdByResourceId(@Param("resourceIdList") List resourceIdList); +} diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/sys/mapper/ResourceMapper.xml b/pmapi/src/main/java/com/ningdatech/pmapi/sys/mapper/ResourceMapper.xml new file mode 100644 index 0000000..f07bbb5 --- /dev/null +++ b/pmapi/src/main/java/com/ningdatech/pmapi/sys/mapper/ResourceMapper.xml @@ -0,0 +1,57 @@ + + + + + + + + + + + + + + + + + + + + + id,created_by,create_time,updated_by,update_time, + code, name, menu_id, describe_, readonly_ + + + + + + + insert into nd_resource ( id, created_by, create_time, updated_by, update_time, + code, name, menu_id, describe_) + values (#{id,jdbcType=BIGINT}, #{createUser,jdbcType=BIGINT}, #{createTime,jdbcType=TIMESTAMP},#{updateUser,jdbcType=BIGINT}, #{updateTime,jdbcType=TIMESTAMP}, + #{code,jdbcType=VARCHAR}, #{name,jdbcType=VARCHAR}, #{menuId,jdbcType=BIGINT}, #{tags,jdbcType=VARCHAR}, #{describe,jdbcType=VARCHAR} ) + ON DUPLICATE KEY UPDATE + name = #{name,jdbcType=VARCHAR}, + describe_ = #{describe,jdbcType=VARCHAR}, + updated_by = #{updateUser,jdbcType=BIGINT}, + update_time = #{updateTime,jdbcType=TIMESTAMP} + + + + + diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/sys/mapper/RoleMapper.java b/pmapi/src/main/java/com/ningdatech/pmapi/sys/mapper/RoleMapper.java new file mode 100644 index 0000000..db19c23 --- /dev/null +++ b/pmapi/src/main/java/com/ningdatech/pmapi/sys/mapper/RoleMapper.java @@ -0,0 +1,35 @@ +package com.ningdatech.pmapi.sys.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.ningdatech.pmapi.sys.entity.Role; +import org.apache.ibatis.annotations.Param; +import org.springframework.stereotype.Repository; + +import java.util.List; + +/** + *

+ * Mapper 接口 + * 角色 + *

+ * + * @author PoffyZhang + */ +@Repository +public interface RoleMapper extends BaseMapper { + /** + * 查询用户拥有的角色 + * + * @param userId 用户id + * @return 角色 + */ + List findRoleByUserId(@Param("userId") Long userId); + + /** + * 根据角色编码查询用户ID + * + * @param codes 角色编码 + * @return 用户id + */ + List findUserIdByCode(@Param("codes") String[] codes); +} diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/sys/mapper/RoleMapper.xml b/pmapi/src/main/java/com/ningdatech/pmapi/sys/mapper/RoleMapper.xml new file mode 100644 index 0000000..901186c --- /dev/null +++ b/pmapi/src/main/java/com/ningdatech/pmapi/sys/mapper/RoleMapper.xml @@ -0,0 +1,32 @@ + + + + + + + + + + + + + + + + + + + + + + + diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/sys/mapper/RoleMenuDatascopeMapper.java b/pmapi/src/main/java/com/ningdatech/pmapi/sys/mapper/RoleMenuDatascopeMapper.java new file mode 100644 index 0000000..d46f5b2 --- /dev/null +++ b/pmapi/src/main/java/com/ningdatech/pmapi/sys/mapper/RoleMenuDatascopeMapper.java @@ -0,0 +1,16 @@ +package com.ningdatech.pmapi.sys.mapper; + +import com.ningdatech.pmapi.sys.entity.RoleMenuDatascope; +import com.baomidou.mybatisplus.core.mapper.BaseMapper; + +/** + *

+ * 角色菜单数据权限关联表 Mapper 接口 + *

+ * + * @author WendyYang + * @since 2023-01-28 + */ +public interface RoleMenuDatascopeMapper extends BaseMapper { + +} diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/sys/mapper/RoleMenuDatascopeMapper.xml b/pmapi/src/main/java/com/ningdatech/pmapi/sys/mapper/RoleMenuDatascopeMapper.xml new file mode 100644 index 0000000..d292558 --- /dev/null +++ b/pmapi/src/main/java/com/ningdatech/pmapi/sys/mapper/RoleMenuDatascopeMapper.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/sys/mapper/RoleMenuMapper.java b/pmapi/src/main/java/com/ningdatech/pmapi/sys/mapper/RoleMenuMapper.java new file mode 100644 index 0000000..be35845 --- /dev/null +++ b/pmapi/src/main/java/com/ningdatech/pmapi/sys/mapper/RoleMenuMapper.java @@ -0,0 +1,16 @@ +package com.ningdatech.pmapi.sys.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.ningdatech.pmapi.sys.entity.RoleMenu; + +/** + *

+ * Mapper 接口 + *

+ * + * @author PoffyZhang + * @since 2022-11-11 + */ +public interface RoleMenuMapper extends BaseMapper { + +} diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/sys/mapper/RoleMenuMapper.xml b/pmapi/src/main/java/com/ningdatech/pmapi/sys/mapper/RoleMenuMapper.xml new file mode 100644 index 0000000..dff428c --- /dev/null +++ b/pmapi/src/main/java/com/ningdatech/pmapi/sys/mapper/RoleMenuMapper.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/sys/mapper/UserRoleMapper.java b/pmapi/src/main/java/com/ningdatech/pmapi/sys/mapper/UserRoleMapper.java new file mode 100644 index 0000000..c975b26 --- /dev/null +++ b/pmapi/src/main/java/com/ningdatech/pmapi/sys/mapper/UserRoleMapper.java @@ -0,0 +1,19 @@ +package com.ningdatech.pmapi.sys.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.ningdatech.pmapi.sys.entity.UserRole; +import org.springframework.stereotype.Repository; + +/** + *

+ * Mapper 接口 + * 角色分配 + * 账号角色绑定 + *

+ * + * @author PoffyZhang + */ +@Repository +public interface UserRoleMapper extends BaseMapper { + +} diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/user/mapper/UserRoleMapper.xml b/pmapi/src/main/java/com/ningdatech/pmapi/sys/mapper/UserRoleMapper.xml similarity index 69% rename from pmapi/src/main/java/com/ningdatech/pmapi/user/mapper/UserRoleMapper.xml rename to pmapi/src/main/java/com/ningdatech/pmapi/sys/mapper/UserRoleMapper.xml index 7f18196..430001c 100644 --- a/pmapi/src/main/java/com/ningdatech/pmapi/user/mapper/UserRoleMapper.xml +++ b/pmapi/src/main/java/com/ningdatech/pmapi/sys/mapper/UserRoleMapper.xml @@ -1,5 +1,6 @@ - + + diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/sys/service/IMenuService.java b/pmapi/src/main/java/com/ningdatech/pmapi/sys/service/IMenuService.java new file mode 100644 index 0000000..38bb1a5 --- /dev/null +++ b/pmapi/src/main/java/com/ningdatech/pmapi/sys/service/IMenuService.java @@ -0,0 +1,46 @@ +package com.ningdatech.pmapi.sys.service; + +import com.baomidou.mybatisplus.extension.service.IService; +import com.ningdatech.pmapi.sys.entity.Menu; +import com.ningdatech.pmapi.sys.entity.dto.MenuSaveDTO; +import com.ningdatech.pmapi.sys.entity.dto.MenuUpdateDTO; + +import java.util.List; + +/** + *

+ * 业务接口 + * 菜单 + *

+ * + * @author WendyYang + * @since 2022-09-30 + */ +public interface IMenuService extends IService { + + /** + * 根据ID删除 + * + * @param ids id + * @return 是否成功 + */ + boolean removeByIdWithCache(List ids); + + /** + * 修改菜单 + * + * @param menu 菜单 + * @param userId / + * @return 是否成功 + */ + boolean update(MenuUpdateDTO menu, Long userId); + + /** + * 保存菜单 + * + * @param menu 菜单 + * @param userId / + * @return 是否成功 + */ + boolean save(MenuSaveDTO menu, Long userId); +} diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/sys/service/IRoleMenuDatascopeService.java b/pmapi/src/main/java/com/ningdatech/pmapi/sys/service/IRoleMenuDatascopeService.java new file mode 100644 index 0000000..5a39816 --- /dev/null +++ b/pmapi/src/main/java/com/ningdatech/pmapi/sys/service/IRoleMenuDatascopeService.java @@ -0,0 +1,16 @@ +package com.ningdatech.pmapi.sys.service; + +import com.ningdatech.pmapi.sys.entity.RoleMenuDatascope; +import com.baomidou.mybatisplus.extension.service.IService; + +/** + *

+ * 角色菜单数据权限关联表 服务类 + *

+ * + * @author WendyYang + * @since 2023-01-28 + */ +public interface IRoleMenuDatascopeService extends IService { + +} diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/sys/service/IRoleMenuService.java b/pmapi/src/main/java/com/ningdatech/pmapi/sys/service/IRoleMenuService.java new file mode 100644 index 0000000..2f26fac --- /dev/null +++ b/pmapi/src/main/java/com/ningdatech/pmapi/sys/service/IRoleMenuService.java @@ -0,0 +1,16 @@ +package com.ningdatech.pmapi.sys.service; + +import com.baomidou.mybatisplus.extension.service.IService; +import com.ningdatech.pmapi.sys.entity.RoleMenu; + +/** + *

+ * 服务类 + *

+ * + * @author PoffyZhang + * @since 2022-11-11 + */ +public interface IRoleMenuService extends IService { + +} diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/sys/service/IRoleService.java b/pmapi/src/main/java/com/ningdatech/pmapi/sys/service/IRoleService.java new file mode 100644 index 0000000..f26821a --- /dev/null +++ b/pmapi/src/main/java/com/ningdatech/pmapi/sys/service/IRoleService.java @@ -0,0 +1,78 @@ +package com.ningdatech.pmapi.sys.service; + +import com.baomidou.mybatisplus.extension.service.IService; +import com.ningdatech.pmapi.sys.entity.Role; +import com.ningdatech.pmapi.sys.entity.dto.RoleSaveDTO; +import com.ningdatech.pmapi.sys.entity.dto.RoleUpdateDTO; + +import java.util.List; + +/** + *

+ * 业务接口 + * 角色 + *

+ * + * @author PoffyZhang + * @since 2022-09-30 + */ +public interface IRoleService extends IService { + + + /** + * 根据ID删除 + * + * @param ids id + * @return 是否成功 + */ + boolean removeByIdWithCache(List ids); + + /** + * 查询用户拥有的角色 + * + * @param userId 用户id + * @return 角色 + */ + List findRoleByUserId(Long userId); + + /** + * 保存角色 + * + * @param data 角色 + * @param userId 用户id + */ + void saveRole(RoleSaveDTO data, Long userId); + + /** + * 修改 + * + * @param role 角色 + * @param userId 用户id + */ + void updateRole(RoleUpdateDTO role, Long userId); + + /** + * 根据角色编码查询用户ID + * + * @param codes 角色编码 + * @return 用户id + */ + List findUserIdByCode(String[] codes); + + /** + * 检测角色名重复 + * + * @param name / + * @return 存在返回真 + */ + Boolean check(String name); + + /** + * 校验角色名 + * + * @param name / + * @param id / + * @return boolean + */ + Boolean check(String name, Long id); +} diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/sys/service/IUserRoleService.java b/pmapi/src/main/java/com/ningdatech/pmapi/sys/service/IUserRoleService.java new file mode 100644 index 0000000..021f9f9 --- /dev/null +++ b/pmapi/src/main/java/com/ningdatech/pmapi/sys/service/IUserRoleService.java @@ -0,0 +1,23 @@ +package com.ningdatech.pmapi.sys.service; + +import com.baomidou.mybatisplus.extension.service.IService; +import com.ningdatech.pmapi.sys.entity.UserRole; + +/** + *

+ * 业务接口 + * 角色分配 + * 账号角色绑定 + *

+ * + * @author PoffyZhang + */ +public interface IUserRoleService extends IService { + /** + * 初始化超级管理员角色 权限 + * + * @param userId 用户id + * @return 是否正确 + */ + boolean initAdmin(Long userId); +} diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/sys/service/impl/MenuServiceImpl.java b/pmapi/src/main/java/com/ningdatech/pmapi/sys/service/impl/MenuServiceImpl.java new file mode 100644 index 0000000..a11ba42 --- /dev/null +++ b/pmapi/src/main/java/com/ningdatech/pmapi/sys/service/impl/MenuServiceImpl.java @@ -0,0 +1,153 @@ +package com.ningdatech.pmapi.sys.service.impl; + +import cn.hutool.core.bean.BeanUtil; +import cn.hutool.core.collection.CollUtil; +import cn.hutool.core.convert.Convert; +import cn.hutool.core.util.StrUtil; +import cn.hutool.http.HttpStatus; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.core.toolkit.Wrappers; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.google.common.collect.Lists; +import com.ningdatech.basic.exception.BaseUncheckedException; +import com.ningdatech.basic.util.ValidatorUtil; +import com.ningdatech.pmapi.common.constant.DefValConstants; +import com.ningdatech.pmapi.sys.entity.Menu; +import com.ningdatech.pmapi.sys.entity.enumeration.MenuTypeEnum; +import com.ningdatech.pmapi.sys.entity.dto.MenuSaveDTO; +import com.ningdatech.pmapi.sys.entity.dto.MenuUpdateDTO; +import com.ningdatech.pmapi.sys.mapper.MenuMapper; +import com.ningdatech.pmapi.sys.service.IMenuService; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.util.List; +import java.util.Objects; +import java.util.stream.Collectors; + +import static com.ningdatech.basic.util.StrPool.DEF_PARENT_ID; + + +/** + *

+ * 业务实现类 + * 菜单 + *

+ * + * @author WendyYang + */ +@Slf4j +@Service +@RequiredArgsConstructor +public class MenuServiceImpl extends ServiceImpl implements IMenuService { + + @Override + @Transactional(rollbackFor = Exception.class) + public boolean removeByIdWithCache(List ids) { + if (ids.isEmpty()) { + return true; + } + + List lastIds = Lists.newArrayList(); + lastIds.addAll(ids); + + //子菜单id + subMenus(ids, lastIds); + + return this.removeByIds(lastIds); + } + + private void subMenus(List ids, List lastIds) { + if (CollUtil.isEmpty(ids)) { + return; + } + ids.forEach(id -> { + List subMenus = list(Wrappers.lambdaQuery(Menu.class).eq(Menu::getPid, id)); + if (CollUtil.isNotEmpty(subMenus)) { + //添加子菜单ID + List subIds = subMenus.stream().map(Menu::getId).collect(Collectors.toList()); + lastIds.addAll(subIds); + //递归 + subMenus(subIds, lastIds); + } + }); + } + + @Override + @Transactional(rollbackFor = Exception.class) + public boolean update(MenuUpdateDTO data, Long userId) { + if (MenuTypeEnum.MENU.getCode().equals(data.getType())) { + if (StrUtil.isBlank(data.getPath())) { + throw new BaseUncheckedException(HttpStatus.HTTP_OK, "【地址栏路径】不能为空"); + } + if (StrUtil.isBlank(data.getComponent())) { + throw new BaseUncheckedException(HttpStatus.HTTP_OK, "【页面路径】不能为空"); + } + if (!ValidatorUtil.isUrl(data.getPath())) { + if (checkPath(data.getId(), data.getPath())) { + throw new BaseUncheckedException(HttpStatus.HTTP_OK, "【地址栏路径】:{}重复", data.getPath()); + } + } + } + Menu old = getById(data); + if (Objects.isNull(old)) { + throw new BaseUncheckedException(HttpStatus.HTTP_OK, "您修改的菜单已不存在"); + } + Menu menu = BeanUtil.toBean(data, Menu.class); + menu.setUpdateBy(userId); + return this.updateById(menu); + } + + public Boolean checkPath(Long id, String path) { + return baseMapper.selectCount(Wrappers.lambdaQuery(Menu.class).ne(Menu::getId, id).eq(Menu::getPath, path)) > 0; + } + + public Boolean checkTitle(Long id, String title) { + LambdaQueryWrapper wrapper = Wrappers.lambdaQuery(Menu.class) + .ne(Menu::getId, id).eq(Menu::getTitle, title); + return baseMapper.selectCount(wrapper) > 0; + } + + @Override + @Transactional(rollbackFor = Exception.class) + public boolean save(MenuSaveDTO data, Long userId) { + if (StrUtil.isBlank(data.getPath())) { + throw new BaseUncheckedException(HttpStatus.HTTP_OK, "【地址栏路径】不能为空"); + } + if (StrUtil.isBlank(data.getComponent())) { + throw new BaseUncheckedException(HttpStatus.HTTP_OK, "【页面路径】不能为空"); + } + if (!ValidatorUtil.isUrl(data.getPath())) { + if (checkPath(null, data.getPath())) { + throw new BaseUncheckedException(HttpStatus.HTTP_OK, "【地址栏路径】:{}重复", data.getPath()); + } + } + data.setPid(Convert.toLong(data.getPid(), DEF_PARENT_ID)); + Menu menu = BeanUtil.toBean(data, Menu.class); + menu.setCreateBy(userId); + menu.setUpdateBy(userId); + save(menu); + return Boolean.TRUE; + } + + public List findChildrenByParentId(Long pid) { + if (Objects.isNull(pid)) { + throw new BaseUncheckedException(HttpStatus.HTTP_OK, "pid 不能为空"); + } + return list(Wrappers.lambdaQuery(Menu.class).in(Menu::getPid, pid).orderByAsc(Menu::getSort)); + } + + private void fill(Menu resource) { + if (resource.getPid() == null || resource.getPid() <= 0) { + resource.setPid(DefValConstants.PARENT_ID); + } else { + Menu parent = getById(resource.getPid()); + if (Objects.isNull(parent)) { + throw new BaseUncheckedException(HttpStatus.HTTP_OK, "请正确填写父级"); + } + } + } + +} diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/sys/service/impl/RoleMenuDatascopeServiceImpl.java b/pmapi/src/main/java/com/ningdatech/pmapi/sys/service/impl/RoleMenuDatascopeServiceImpl.java new file mode 100644 index 0000000..09cda45 --- /dev/null +++ b/pmapi/src/main/java/com/ningdatech/pmapi/sys/service/impl/RoleMenuDatascopeServiceImpl.java @@ -0,0 +1,20 @@ +package com.ningdatech.pmapi.sys.service.impl; + +import com.ningdatech.pmapi.sys.entity.RoleMenuDatascope; +import com.ningdatech.pmapi.sys.mapper.RoleMenuDatascopeMapper; +import com.ningdatech.pmapi.sys.service.IRoleMenuDatascopeService; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import org.springframework.stereotype.Service; + +/** + *

+ * 角色菜单数据权限关联表 服务实现类 + *

+ * + * @author WendyYang + * @since 2023-01-28 + */ +@Service +public class RoleMenuDatascopeServiceImpl extends ServiceImpl implements IRoleMenuDatascopeService { + +} diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/sys/service/impl/RoleMenuServiceImpl.java b/pmapi/src/main/java/com/ningdatech/pmapi/sys/service/impl/RoleMenuServiceImpl.java new file mode 100644 index 0000000..27f1886 --- /dev/null +++ b/pmapi/src/main/java/com/ningdatech/pmapi/sys/service/impl/RoleMenuServiceImpl.java @@ -0,0 +1,20 @@ +package com.ningdatech.pmapi.sys.service.impl; + +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.ningdatech.pmapi.sys.entity.RoleMenu; +import com.ningdatech.pmapi.sys.mapper.RoleMenuMapper; +import com.ningdatech.pmapi.sys.service.IRoleMenuService; +import org.springframework.stereotype.Service; + +/** + *

+ * 服务实现类 + *

+ * + * @author PoffyZhang + * @since 2022-11-11 + */ +@Service +public class RoleMenuServiceImpl extends ServiceImpl implements IRoleMenuService { + +} diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/sys/service/impl/RoleServiceImpl.java b/pmapi/src/main/java/com/ningdatech/pmapi/sys/service/impl/RoleServiceImpl.java new file mode 100644 index 0000000..4304fd2 --- /dev/null +++ b/pmapi/src/main/java/com/ningdatech/pmapi/sys/service/impl/RoleServiceImpl.java @@ -0,0 +1,214 @@ +package com.ningdatech.pmapi.sys.service.impl; + +import cn.hutool.core.bean.BeanUtil; +import cn.hutool.core.collection.CollUtil; +import cn.hutool.core.util.StrUtil; +import cn.hutool.http.HttpStatus; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.core.toolkit.Wrappers; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.ningdatech.basic.exception.BaseUncheckedException; +import com.ningdatech.basic.exception.BizException; +import com.ningdatech.basic.exception.code.ExceptionCode; +import com.ningdatech.basic.util.CollUtils; +import com.ningdatech.cache.repository.CachePlusOps; +import com.ningdatech.pmapi.sys.entity.*; +import com.ningdatech.pmapi.sys.entity.dto.MenuDataScopeDTO; +import com.ningdatech.pmapi.sys.entity.dto.RoleSaveDTO; +import com.ningdatech.pmapi.sys.entity.dto.RoleUpdateDTO; +import com.ningdatech.pmapi.sys.mapper.RoleMapper; +import com.ningdatech.pmapi.sys.service.*; +import com.ningdatech.pmapi.sys.utils.AuthCacheKeyUtils; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.util.*; +import java.util.stream.Collectors; + +/** + *

+ * 业务实现类 + * 角色 + *

+ * + * @author PoffyZhang + */ +@Slf4j +@Service +@RequiredArgsConstructor +public class RoleServiceImpl extends ServiceImpl implements IRoleService { + + private final IUserRoleService IUserRoleService; + private final RoleMapper roleMapper; + private final IRoleMenuDatascopeService roleMenuDatascopeService; + + private final CachePlusOps cachePlusOps; + + private final IRoleMenuService roleMenuService; + + private final IMenuService IMenuService; + + private static final String SUPER_ADMIN = "SUPER_ADMIN"; + + + /** + * 删除角色时,需要级联删除跟角色相关的一切资源: + * 1,角色本身 + * 2,角色-组织: + * 3,角色-权限(菜单和按钮): + * 4,角色-用户:角色拥有的用户 + * 5,用户-权限: + */ + @Override + @Transactional(rollbackFor = Exception.class) + public boolean removeByIdWithCache(List ids) { + if (ids.isEmpty()) { + return true; + } + + if (IUserRoleService.count(Wrappers.lambdaQuery(UserRole.class).select(UserRole::getUserId) + .in(UserRole::getRoleId, ids)) > 0) { + throw new BizException(ExceptionCode.OPERATION_EX.getCode(), "该角色下还有用户 不能随意删除!"); + } + + // 角色 + boolean removeFlag = removeByIds(ids); + + //角色拥有的用户 + IUserRoleService.remove(Wrappers.lambdaQuery(UserRole.class).in(UserRole::getRoleId, ids)); + if (removeFlag) { + // 角色绑定了那些用户 + if (roleMenuService.remove(Wrappers.lambdaQuery(RoleMenu.class).in(RoleMenu::getRoleId, ids))) { + return Boolean.TRUE; + } + } + return removeFlag; + } + + /** + * 1、根据 USER_ROLE:{userId} 查询用户拥有的角色ID集合 + * 2、缓存中有,则根据角色ID集合查询 角色集合 + * 3、缓存中有查不到,则从DB查询,并写入缓存, 立即返回 + * + * @param userId 用户id + */ + @Override + public List findRoleByUserId(Long userId) { + String cacheKey = AuthCacheKeyUtils.userRoleCacheKey(userId); + List roleList = new ArrayList<>(); + List list = cachePlusOps.get(cacheKey); + if (list == null) { + roleList.addAll(baseMapper.findRoleByUserId(userId)); + list = roleList.stream().map(Role::getId).collect(Collectors.toList()); + } + if (roleList.isEmpty()) { + return listByIds(list); + } + return roleList; + } + + /** + * 1,保存角色 + * 2,保存 与组织的关系 + */ + @Override + @Transactional(rollbackFor = Exception.class) + public void saveRole(RoleSaveDTO data, Long userId) { + if (StrUtil.isNotBlank(data.getName()) && check(data.getName())) { + throw new BaseUncheckedException(HttpStatus.HTTP_OK, "角色名称{} 已存在", data.getName()); + } + Role role = BeanUtil.toBean(data, Role.class); + role.setCreateBy(userId); + role.setUpdateBy(userId); + save(role); + saveRoleMenu(data.getMenuIds(), role.getId()); + saveRoleMenuDatascope(data.getMenuDataScopeList(), role.getId()); + } + + private void saveRoleMenuDatascope(List menuDataScopeList, Long roleId) { + LambdaQueryWrapper query = Wrappers.lambdaQuery(RoleMenuDatascope.class) + .eq(RoleMenuDatascope::getRoleId, roleId); + roleMenuDatascopeService.remove(query); + if (menuDataScopeList == null || menuDataScopeList.isEmpty()) { + return; + } + List datascopeList = CollUtils.convert(menuDataScopeList, w -> { + RoleMenuDatascope roleMenuDatascope = new RoleMenuDatascope(); + roleMenuDatascope.setMenuId(w.getMenuId()); + roleMenuDatascope.setDatascope(w.getDataScope()); + roleMenuDatascope.setRoleId(roleId); + return roleMenuDatascope; + }); + roleMenuDatascopeService.saveBatch(datascopeList); + } + + @Override + @Transactional(rollbackFor = Exception.class) + public void updateRole(RoleUpdateDTO data, Long userId) { + Role roleOld = roleMapper.selectById(data.getId()); + if (Objects.isNull(roleOld)) { + throw new BaseUncheckedException(HttpStatus.HTTP_OK, String.format("修改用户%d 为空", data.getId())); + } + + if (StrUtil.isNotBlank(data.getName()) && check(data.getName(), roleOld.getId())) { + throw BizException.wrap("角色名{} 已经存在", data.getName()); + } + Role role = BeanUtil.toBean(data, Role.class); + role.setUpdateBy(userId); + updateById(role); + saveRoleMenu(data.getMenuIds(), role.getId()); + saveRoleMenuDatascope(data.getMenuDataScopeList(), role.getId()); + cachePlusOps.del(AuthCacheKeyUtils.userResourceCacheKey(userId)); + } + + @Override + public List findUserIdByCode(String[] codes) { + return baseMapper.findUserIdByCode(codes); + } + + @Override + public Boolean check(String name) { + return super.count(Wrappers.lambdaQuery(Role.class).eq(Role::getName, name)) > 0; + } + + @Override + public Boolean check(String name, Long id) { + return super.count(Wrappers.lambdaQuery(Role.class).ne(Role::getId, id) + .eq(Role::getName, name)) > 0; + } + + private void saveRoleMenu(List menuIds, Long roleId) { + if (CollUtil.isNotEmpty(menuIds)) { + roleMenuService.remove(Wrappers.lambdaQuery(RoleMenu.class).eq(RoleMenu::getRoleId, roleId)); + Set toAddMenus = new HashSet<>(); + for (Long menuId : menuIds) { + Menu menu = IMenuService.getById(menuId); + if (Objects.isNull(menu)) { + continue; + } + RoleMenu roleMenu = new RoleMenu(null, menuId, roleId); + toAddMenus.add(roleMenu); + // 父级菜单 + // addParent(toAddMenus,menu,roleId); + } + if (CollUtil.isNotEmpty(toAddMenus)) { + roleMenuService.saveBatch(toAddMenus); + } + } + } + + private void addParent(Set toAddMenus, Menu menu, Long roleId) { + if (Objects.isNull(menu.getPid()) || menu.getPid().equals(0L)) { + return; + } + Menu parent = IMenuService.getById(menu.getPid()); + if (Objects.isNull(parent)) { + return; + } + RoleMenu roleMenu = new RoleMenu(null, parent.getId(), roleId); + toAddMenus.add(roleMenu); + addParent(toAddMenus, parent, roleId); + } +} diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/sys/service/impl/UserRoleServiceImpl.java b/pmapi/src/main/java/com/ningdatech/pmapi/sys/service/impl/UserRoleServiceImpl.java new file mode 100644 index 0000000..f2b85f8 --- /dev/null +++ b/pmapi/src/main/java/com/ningdatech/pmapi/sys/service/impl/UserRoleServiceImpl.java @@ -0,0 +1,49 @@ +package com.ningdatech.pmapi.sys.service.impl; + +import cn.hutool.http.HttpStatus; +import com.baomidou.mybatisplus.core.toolkit.Wrappers; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.ningdatech.basic.exception.BaseUncheckedException; +import com.ningdatech.pmapi.sys.entity.Role; +import com.ningdatech.pmapi.sys.entity.UserRole; +import com.ningdatech.pmapi.sys.mapper.RoleMapper; +import com.ningdatech.pmapi.sys.mapper.UserRoleMapper; +import com.ningdatech.pmapi.sys.service.IUserRoleService; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +/** + *

+ * 业务实现类 + * 角色分配 + * 账号角色绑定 + *

+ * + * @author PoffyZhang + */ +@Slf4j +@Service +@RequiredArgsConstructor +public class UserRoleServiceImpl extends ServiceImpl implements IUserRoleService { + + private static final String INIT_ROLE_CODE = "SUPER_ADMIN"; + + private final RoleMapper roleMapper; + + @Override + @Transactional(rollbackFor = Exception.class) + public boolean initAdmin(Long userId) { + Role role = roleMapper.selectOne(Wrappers.lambdaQuery(Role.class) + .eq(Role::getName, INIT_ROLE_CODE)); + if (role == null) { + throw new BaseUncheckedException(HttpStatus.HTTP_OK, String.format("初始化用户角色失败, 无法查询到内置角色:%s", INIT_ROLE_CODE)); + } + UserRole userRole = UserRole.builder() + .userId(userId).roleId(role.getId()) + .build(); + + return super.save(userRole); + } +} diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/sys/utils/AuthCacheKeyUtils.java b/pmapi/src/main/java/com/ningdatech/pmapi/sys/utils/AuthCacheKeyUtils.java new file mode 100644 index 0000000..407f275 --- /dev/null +++ b/pmapi/src/main/java/com/ningdatech/pmapi/sys/utils/AuthCacheKeyUtils.java @@ -0,0 +1,38 @@ +package com.ningdatech.pmapi.sys.utils; + +/** + *

+ * AuthCacheKeyUtils + *

+ * + * @author WendyYang + */ +public class AuthCacheKeyUtils { + + private static final String USER_RESOURCE_CKP = "user_resource:"; + private static final String USER_MENU_CKP = "user_menu:"; + private static final String USER_ROLE_CKP = "user_role:"; + private static final String ROLE_RESOURCE_CKP = "role_resource:"; + private static final String ROLE_MENU_CKP = "role_menu:"; + + public static String roleResourceCacheKey(Long roleId) { + return ROLE_RESOURCE_CKP + roleId; + } + + public static String roleMenuCacheKey(Long roleId) { + return ROLE_MENU_CKP + roleId; + } + + public static String userResourceCacheKey(Long userId) { + return USER_RESOURCE_CKP + userId; + } + + public static String userMenuCacheKey(Long userId) { + return USER_MENU_CKP + userId; + } + + public static String userRoleCacheKey(Long userId) { + return USER_ROLE_CKP + userId; + } + +} diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/user/mapper/UserRoleMapper.java b/pmapi/src/main/java/com/ningdatech/pmapi/user/mapper/UserRoleMapper.java deleted file mode 100644 index 69220bd..0000000 --- a/pmapi/src/main/java/com/ningdatech/pmapi/user/mapper/UserRoleMapper.java +++ /dev/null @@ -1,16 +0,0 @@ -package com.ningdatech.pmapi.user.mapper; - -import com.ningdatech.pmapi.user.entity.UserRole; -import com.baomidou.mybatisplus.core.mapper.BaseMapper; - -/** - *

- * 用户角色表 Mapper 接口 - *

- * - * @author Liuxinxin - * @since 2023-01-05 - */ -public interface UserRoleMapper extends BaseMapper { - -} diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/user/security/auth/model/UserInfoDetails.java b/pmapi/src/main/java/com/ningdatech/pmapi/user/security/auth/model/UserInfoDetails.java index a10e2c1..868fbff 100644 --- a/pmapi/src/main/java/com/ningdatech/pmapi/user/security/auth/model/UserInfoDetails.java +++ b/pmapi/src/main/java/com/ningdatech/pmapi/user/security/auth/model/UserInfoDetails.java @@ -9,6 +9,7 @@ import org.springframework.security.core.authority.SimpleGrantedAuthority; import org.springframework.security.core.userdetails.UserDetails; import java.util.Collection; +import java.util.List; /** * @author LiuXinXin @@ -24,6 +25,8 @@ public class UserInfoDetails extends AbstractLoginUser implements UserDetails { private String role; + private List roleIdList; + /** * 区域code */ diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/user/service/impl/UserRoleServiceImpl.java b/pmapi/src/main/java/com/ningdatech/pmapi/user/service/impl/UserRoleServiceImpl.java deleted file mode 100644 index da162e7..0000000 --- a/pmapi/src/main/java/com/ningdatech/pmapi/user/service/impl/UserRoleServiceImpl.java +++ /dev/null @@ -1,20 +0,0 @@ -package com.ningdatech.pmapi.user.service.impl; - -import com.ningdatech.pmapi.user.entity.UserRole; -import com.ningdatech.pmapi.user.mapper.UserRoleMapper; -import com.ningdatech.pmapi.user.service.IUserRoleService; -import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; -import org.springframework.stereotype.Service; - -/** - *

- * 用户角色表 服务实现类 - *

- * - * @author Liuxinxin - * @since 2023-01-05 - */ -@Service -public class UserRoleServiceImpl extends ServiceImpl implements IUserRoleService { - -} diff --git a/pmapi/src/main/resources/application-dev.yml b/pmapi/src/main/resources/application-dev.yml index cac4a8a..b3dadeb 100644 --- a/pmapi/src/main/resources/application-dev.yml +++ b/pmapi/src/main/resources/application-dev.yml @@ -87,7 +87,9 @@ spring: wall: config: multi-statement-allow: true - +mybatis-plus: + configuration: + log-impl: org.apache.ibatis.logging.stdout.StdOutImpl logging: config: classpath:logback-spring.xml #日志配置 diff --git a/pmapi/src/test/java/com/ningdatech/pmapi/AppTests.java b/pmapi/src/test/java/com/ningdatech/pmapi/AppTests.java new file mode 100644 index 0000000..be21a0e --- /dev/null +++ b/pmapi/src/test/java/com/ningdatech/pmapi/AppTests.java @@ -0,0 +1,19 @@ +package com.ningdatech.pmapi; + +import org.junit.runner.RunWith; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; + +/** + *

+ * AppRunTests + *

+ * + * @author WendyYang + * @since 19:27 2022/5/10 + */ +@RunWith(SpringRunner.class) +@SpringBootTest(classes = App.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) +public class AppTests { + +} diff --git a/pmapi/src/test/java/com/ningdatech/pmapi/sys/service/IMenuServiceTest.java b/pmapi/src/test/java/com/ningdatech/pmapi/sys/service/IMenuServiceTest.java new file mode 100644 index 0000000..c91ee0a --- /dev/null +++ b/pmapi/src/test/java/com/ningdatech/pmapi/sys/service/IMenuServiceTest.java @@ -0,0 +1,37 @@ +package com.ningdatech.pmapi.sys.service; + +import cn.hutool.db.Db; +import cn.hutool.db.Entity; +import com.ningdatech.pmapi.AppTests; +import com.ningdatech.pmapi.sys.entity.Menu; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; + +import java.sql.SQLException; +import java.util.List; + +/** + *

+ * IMenuServiceTest + *

+ * + * @author WendyYang + * @since 11:18 2023/1/29 + */ +class IMenuServiceTest extends AppTests { + + @Autowired + private IMenuService menuService; + + @Test + public void test() throws SQLException { + menuService.remove(null); + List menu = Db.use().findAll("nd_menu"); + menu.forEach(System.out::println); + menu.forEach(w -> { + Menu bean = w.toBean(Menu.class); + menuService.save(bean); + }); + } + +} \ No newline at end of file