From 03581dd73f7ac98b11f6b2de59966d0eba6c20e8 Mon Sep 17 00:00:00 2001 From: WendyYang Date: Sun, 29 Jan 2023 11:44:24 +0800 Subject: [PATCH] =?UTF-8?q?=E7=94=A8=E6=88=B7=E8=A7=92=E8=89=B2=E4=BF=AE?= =?UTF-8?q?=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../pmapi/scheduler/task/InitProcessTask.java | 12 +- .../ningdatech/pmapi/sys/contant/RegionConst.java | 26 +++ .../pmapi/sys/contants/RegionContant.java | 20 --- .../pmapi/sys/controller/MenuController.java | 44 +++-- .../controller/NdRoleMenuDatascopeController.java | 20 --- .../pmapi/sys/controller/RoleController.java | 9 +- .../java/com/ningdatech/pmapi/sys/entity/Menu.java | 38 +---- .../pmapi/sys/entity/NdRoleMenuDatascope.java | 72 -------- .../ningdatech/pmapi/sys/manage/RoleManage.java | 12 +- .../sys/mapper/NdRoleMenuDatascopeMapper.java | 16 -- .../pmapi/sys/mapper/NdRoleMenuDatascopeMapper.xml | 5 - .../pmapi/sys/mapper/RoleAuthorityMapper.java | 32 ---- .../pmapi/sys/mapper/RoleAuthorityMapper.xml | 15 -- .../ningdatech/pmapi/sys/service/IMenuService.java | 46 +++++ .../sys/service/INdRoleMenuDatascopeService.java | 16 -- .../ningdatech/pmapi/sys/service/IRoleService.java | 78 +++++++++ .../pmapi/sys/service/IUserRoleService.java | 23 +++ .../ningdatech/pmapi/sys/service/MenuService.java | 46 ----- .../pmapi/sys/service/RoleAuthorityService.java | 71 -------- .../ningdatech/pmapi/sys/service/RoleService.java | 86 ---------- .../pmapi/sys/service/UserRoleService.java | 23 --- .../pmapi/sys/service/impl/MenuServiceImpl.java | 13 +- .../impl/NdRoleMenuDatascopeServiceImpl.java | 20 --- .../sys/service/impl/RoleAuthorityServiceImpl.java | 185 --------------------- .../pmapi/sys/service/impl/RoleServiceImpl.java | 32 ++-- .../sys/service/impl/UserRoleServiceImpl.java | 4 +- .../test/java/com/ningdatech/pmapi/AppTests.java | 19 +++ .../pmapi/sys/service/IMenuServiceTest.java | 37 +++++ 28 files changed, 297 insertions(+), 723 deletions(-) create mode 100644 pmapi/src/main/java/com/ningdatech/pmapi/sys/contant/RegionConst.java delete mode 100644 pmapi/src/main/java/com/ningdatech/pmapi/sys/contants/RegionContant.java delete mode 100644 pmapi/src/main/java/com/ningdatech/pmapi/sys/controller/NdRoleMenuDatascopeController.java delete mode 100644 pmapi/src/main/java/com/ningdatech/pmapi/sys/entity/NdRoleMenuDatascope.java delete mode 100644 pmapi/src/main/java/com/ningdatech/pmapi/sys/mapper/NdRoleMenuDatascopeMapper.java delete mode 100644 pmapi/src/main/java/com/ningdatech/pmapi/sys/mapper/NdRoleMenuDatascopeMapper.xml delete mode 100644 pmapi/src/main/java/com/ningdatech/pmapi/sys/mapper/RoleAuthorityMapper.java delete mode 100644 pmapi/src/main/java/com/ningdatech/pmapi/sys/mapper/RoleAuthorityMapper.xml create mode 100644 pmapi/src/main/java/com/ningdatech/pmapi/sys/service/IMenuService.java delete mode 100644 pmapi/src/main/java/com/ningdatech/pmapi/sys/service/INdRoleMenuDatascopeService.java create mode 100644 pmapi/src/main/java/com/ningdatech/pmapi/sys/service/IRoleService.java create mode 100644 pmapi/src/main/java/com/ningdatech/pmapi/sys/service/IUserRoleService.java delete mode 100644 pmapi/src/main/java/com/ningdatech/pmapi/sys/service/MenuService.java delete mode 100644 pmapi/src/main/java/com/ningdatech/pmapi/sys/service/RoleAuthorityService.java delete mode 100644 pmapi/src/main/java/com/ningdatech/pmapi/sys/service/RoleService.java delete mode 100644 pmapi/src/main/java/com/ningdatech/pmapi/sys/service/UserRoleService.java delete mode 100644 pmapi/src/main/java/com/ningdatech/pmapi/sys/service/impl/NdRoleMenuDatascopeServiceImpl.java delete mode 100644 pmapi/src/main/java/com/ningdatech/pmapi/sys/service/impl/RoleAuthorityServiceImpl.java create mode 100644 pmapi/src/test/java/com/ningdatech/pmapi/AppTests.java create mode 100644 pmapi/src/test/java/com/ningdatech/pmapi/sys/service/IMenuServiceTest.java 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 e2df0b0..86f95e4 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 index e8a91f3..5018ab1 100644 --- a/pmapi/src/main/java/com/ningdatech/pmapi/sys/controller/MenuController.java +++ b/pmapi/src/main/java/com/ningdatech/pmapi/sys/controller/MenuController.java @@ -1,9 +1,12 @@ 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; @@ -12,7 +15,7 @@ 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.MenuService; +import com.ningdatech.pmapi.sys.service.IMenuService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import lombok.RequiredArgsConstructor; @@ -25,11 +28,10 @@ import java.util.List; /** *

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

* - * @author PoffyZhang + * @author WendyYang * @since 2022-09-30 */ @Slf4j @@ -40,39 +42,43 @@ import java.util.List; @Api(value = "Menu", tags = "系统管理-菜单") public class MenuController { - private final MenuService menuService; + private final IMenuService menuService; private final MenuManage menuManage; - /** - * 查询系统中所有的的菜单树结构, 不用缓存,因为该接口很少会使用,就算使用,也会管理员维护菜单时使用 - */ - @ApiOperation(value = "查询系统所有的菜单", notes = "查询系统所有的菜单") + @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("/current_user_menu") + @GetMapping("/myMenu") public List currentUserMenu() { List list = menuService.list(Wrappers.lambdaQuery(Menu.class).orderByAsc(Menu::getSort)); // TODO:登录用户信息 return menuManage.buildUserMenu(list, null); } - /** - * 查询某个菜单 - * - * @param id 主键id - * @return 查询结果 - */ @ApiOperation(value = "查询菜单", notes = "查询菜单") @GetMapping("/details") public MenuQueryDTO getDetails(@RequestParam Long id) { Menu menu = menuService.getById(id); - MenuQueryDTO query = BeanUtil.toBean(menu, MenuQueryDTO.class); - return query; + return BeanUtil.toBean(menu, MenuQueryDTO.class); } @ApiOperation(value = "保存新菜单", notes = "保存新菜单") @@ -86,6 +92,7 @@ public class MenuController { @ApiOperation(value = "编辑菜单", notes = "编辑菜单") @PostMapping("/modify") + @WebLog("编辑菜单") public MenuVO handlerUpdate(@RequestBody MenuUpdateDTO data) { menuService.update(data, AbstractLoginUserUtil.getUserId()); return BeanUtil.toBean(data, MenuVO.class); @@ -93,6 +100,7 @@ public class MenuController { @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/NdRoleMenuDatascopeController.java b/pmapi/src/main/java/com/ningdatech/pmapi/sys/controller/NdRoleMenuDatascopeController.java deleted file mode 100644 index 698a62d..0000000 --- a/pmapi/src/main/java/com/ningdatech/pmapi/sys/controller/NdRoleMenuDatascopeController.java +++ /dev/null @@ -1,20 +0,0 @@ -package com.ningdatech.pmapi.sys.controller; - - -import org.springframework.web.bind.annotation.RequestMapping; - -import org.springframework.stereotype.Controller; - -/** - *

- * 角色菜单数据权限关联表 前端控制器 - *

- * - * @author WendyYang - * @since 2023-01-28 - */ -@Controller -@RequestMapping("/pmapi.sys/nd-role-menu-datascope") -public class NdRoleMenuDatascopeController { - -} 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 index bc698c6..09fd7c5 100644 --- a/pmapi/src/main/java/com/ningdatech/pmapi/sys/controller/RoleController.java +++ b/pmapi/src/main/java/com/ningdatech/pmapi/sys/controller/RoleController.java @@ -10,7 +10,7 @@ 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.RoleService; +import com.ningdatech.pmapi.sys.service.IRoleService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import lombok.RequiredArgsConstructor; @@ -24,11 +24,10 @@ import java.util.Objects; /** *

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

* - * @author PoffyZhang + * @author WendyYang * @since 2022-09-30 */ @Slf4j @@ -39,7 +38,7 @@ import java.util.Objects; @RequiredArgsConstructor public class RoleController { - private final RoleService roleService; + private final IRoleService roleService; private final RoleManage roleManage; 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 index 58383d3..3db4378 100644 --- a/pmapi/src/main/java/com/ningdatech/pmapi/sys/entity/Menu.java +++ b/pmapi/src/main/java/com/ningdatech/pmapi/sys/entity/Menu.java @@ -34,62 +34,40 @@ public class Menu extends MenuTreeEntity { private static final long serialVersionUID = 1L; - /** - * 权限" - */ - @ApiModelProperty(value = "权限") - @Size(max = 200, message = "权限长度不能超过200") - @TableField(value = "permission", condition = LIKE) - private String permission; - /** - * 类型;[0-菜单 1-目录 2-按钮] - */ - @ApiModelProperty(value = "类型") - @TableField(value = "type") - private Integer type; - - /** - * 组件 - */ @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; - /** - * activeMenu - */ @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/NdRoleMenuDatascope.java b/pmapi/src/main/java/com/ningdatech/pmapi/sys/entity/NdRoleMenuDatascope.java deleted file mode 100644 index 830476c..0000000 --- a/pmapi/src/main/java/com/ningdatech/pmapi/sys/entity/NdRoleMenuDatascope.java +++ /dev/null @@ -1,72 +0,0 @@ -package com.ningdatech.pmapi.sys.entity; - -import com.baomidou.mybatisplus.annotation.TableName; -import java.io.Serializable; -import io.swagger.annotations.ApiModel; -import io.swagger.annotations.ApiModelProperty; - -/** - *

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

- * - * @author WendyYang - * @since 2023-01-28 - */ -@TableName("nd_role_menu_datascope") -@ApiModel(value = "NdRoleMenuDatascope对象", description = "角色菜单数据权限关联表") -public class NdRoleMenuDatascope implements Serializable { - - private static final long serialVersionUID = 1L; - - @ApiModelProperty("主键") - private Long id; - - @ApiModelProperty("角色ID") - private Long roleId; - - @ApiModelProperty("菜单ID") - private Long menuId; - - @ApiModelProperty("数据权限") - private Integer datascope; - - public Long getId() { - return id; - } - - public void setId(Long id) { - this.id = id; - } - public Long getRoleId() { - return roleId; - } - - public void setRoleId(Long roleId) { - this.roleId = roleId; - } - public Long getMenuId() { - return menuId; - } - - public void setMenuId(Long menuId) { - this.menuId = menuId; - } - public Integer getDatascope() { - return datascope; - } - - public void setDatascope(Integer datascope) { - this.datascope = datascope; - } - - @Override - public String toString() { - return "NdRoleMenuDatascope{" + - "id=" + id + - ", roleId=" + roleId + - ", menuId=" + menuId + - ", datascope=" + datascope + - "}"; - } -} 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 index 36552a3..102af3e 100644 --- a/pmapi/src/main/java/com/ningdatech/pmapi/sys/manage/RoleManage.java +++ b/pmapi/src/main/java/com/ningdatech/pmapi/sys/manage/RoleManage.java @@ -13,8 +13,8 @@ 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.MenuService; -import com.ningdatech.pmapi.sys.service.RoleService; +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; @@ -35,8 +35,8 @@ import java.util.stream.Collectors; @RequiredArgsConstructor public class RoleManage { - private final RoleService roleService; - private final MenuService menuService; + private final IRoleService IRoleService; + private final IMenuService IMenuService; private final IRoleMenuService roleMenuService; @@ -51,13 +51,13 @@ public class RoleManage { private void searchList(Page page, LambdaQueryWrapper wrapper, RolePageReq rolePageReq) { wrapper.like(StringUtils.isNotBlank(rolePageReq.getName()), Role::getName, rolePageReq.getName()) .orderByDesc(Role::getUpdateOn); - roleService.page(page, wrapper); + IRoleService.page(page, wrapper); } public void buildMenu(RoleVO query) { //改成直接返回有权限的 - List list = menuService.list(Wrappers.lambdaQuery(Menu.class).orderByAsc(Menu::getSort)); + 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 -> { diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/sys/mapper/NdRoleMenuDatascopeMapper.java b/pmapi/src/main/java/com/ningdatech/pmapi/sys/mapper/NdRoleMenuDatascopeMapper.java deleted file mode 100644 index ef1b8fb..0000000 --- a/pmapi/src/main/java/com/ningdatech/pmapi/sys/mapper/NdRoleMenuDatascopeMapper.java +++ /dev/null @@ -1,16 +0,0 @@ -package com.ningdatech.pmapi.sys.mapper; - -import com.ningdatech.pmapi.sys.entity.NdRoleMenuDatascope; -import com.baomidou.mybatisplus.core.mapper.BaseMapper; - -/** - *

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

- * - * @author WendyYang - * @since 2023-01-28 - */ -public interface NdRoleMenuDatascopeMapper extends BaseMapper { - -} diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/sys/mapper/NdRoleMenuDatascopeMapper.xml b/pmapi/src/main/java/com/ningdatech/pmapi/sys/mapper/NdRoleMenuDatascopeMapper.xml deleted file mode 100644 index 0940c06..0000000 --- a/pmapi/src/main/java/com/ningdatech/pmapi/sys/mapper/NdRoleMenuDatascopeMapper.xml +++ /dev/null @@ -1,5 +0,0 @@ - - - - - diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/sys/mapper/RoleAuthorityMapper.java b/pmapi/src/main/java/com/ningdatech/pmapi/sys/mapper/RoleAuthorityMapper.java deleted file mode 100644 index 0261da4..0000000 --- a/pmapi/src/main/java/com/ningdatech/pmapi/sys/mapper/RoleAuthorityMapper.java +++ /dev/null @@ -1,32 +0,0 @@ -package com.ningdatech.pmapi.sys.mapper; - -import com.baomidou.mybatisplus.core.mapper.BaseMapper; -import com.ningdatech.pmapi.sys.entity.RoleAuthority; -import org.apache.ibatis.annotations.Param; -import org.springframework.stereotype.Repository; - -import java.util.List; - -/** - *

- * Mapper 接口 - * 角色的资源 - *

- * - * @author PoffyZhang - */ -@Repository -public interface RoleAuthorityMapper extends BaseMapper { - - /** - * 根据用户-角色-数据权限关系,查询可用的数据权限ID - *

- * 角色被禁用后,用户不在拥有此角色的权限 - * - * @param userId 用户ID - * @param category 角色类别 - * @return / - */ - List selectDataScopeIdFromRoleByUserId(@Param("userId") Long userId, @Param("category") String category); - -} diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/sys/mapper/RoleAuthorityMapper.xml b/pmapi/src/main/java/com/ningdatech/pmapi/sys/mapper/RoleAuthorityMapper.xml deleted file mode 100644 index 494cdf4..0000000 --- a/pmapi/src/main/java/com/ningdatech/pmapi/sys/mapper/RoleAuthorityMapper.xml +++ /dev/null @@ -1,15 +0,0 @@ - - - - - - - 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/INdRoleMenuDatascopeService.java b/pmapi/src/main/java/com/ningdatech/pmapi/sys/service/INdRoleMenuDatascopeService.java deleted file mode 100644 index e350e48..0000000 --- a/pmapi/src/main/java/com/ningdatech/pmapi/sys/service/INdRoleMenuDatascopeService.java +++ /dev/null @@ -1,16 +0,0 @@ -package com.ningdatech.pmapi.sys.service; - -import com.ningdatech.pmapi.sys.entity.NdRoleMenuDatascope; -import com.baomidou.mybatisplus.extension.service.IService; - -/** - *

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

- * - * @author WendyYang - * @since 2023-01-28 - */ -public interface INdRoleMenuDatascopeService 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/MenuService.java b/pmapi/src/main/java/com/ningdatech/pmapi/sys/service/MenuService.java deleted file mode 100644 index a9d5839..0000000 --- a/pmapi/src/main/java/com/ningdatech/pmapi/sys/service/MenuService.java +++ /dev/null @@ -1,46 +0,0 @@ -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 MenuService 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/RoleAuthorityService.java b/pmapi/src/main/java/com/ningdatech/pmapi/sys/service/RoleAuthorityService.java deleted file mode 100644 index 49f1542..0000000 --- a/pmapi/src/main/java/com/ningdatech/pmapi/sys/service/RoleAuthorityService.java +++ /dev/null @@ -1,71 +0,0 @@ -package com.ningdatech.pmapi.sys.service; - -import com.baomidou.mybatisplus.extension.service.IService; -import com.ningdatech.pmapi.sys.entity.RoleAuthority; -import com.ningdatech.pmapi.sys.entity.dto.RoleAuthoritySaveDTO; -import com.ningdatech.pmapi.sys.entity.dto.RoleUserSaveVO; -import com.ningdatech.pmapi.sys.entity.dto.UserRoleSaveDTO; - -import java.util.List; - -/** - *

- * 业务接口 - * 角色的资源 - *

- * - * @author PoffyZhang - */ -public interface RoleAuthorityService extends IService { - /** - * 根据用户-角色-数据权限关系,查询可用的数据权限ID - *

- * 角色被禁用后,用户不在拥有此角色的权限 - * - * @param userId 用户ID - * @param category 角色类别 - * @return - */ - List selectDataScopeIdFromRoleByUserId(Long userId, String category); - - /** - * 给用户分配角色 - * - * @param userRole 用于角色 - * @return 是否成功 - */ - boolean saveUserRole(UserRoleSaveDTO userRole); - - /** - * 给角色绑定用户 - * - * @param roleUser 用于角色 - * @return 是否成功 - */ - List saveRoleUser(RoleUserSaveVO roleUser); - - /** - * 根据角色查找用户 - * - * @param roleId 角色ID - * @return - */ - List findUserIdByRoleId(Long roleId); - - /** - * 给角色重新分配 权限(资源/菜单) - * - * @param roleAuthoritySaveDTO 角色授权信息 - * @return 是否成功 - */ - boolean saveRoleAuthority(RoleAuthoritySaveDTO roleAuthoritySaveDTO); - - /** - * 根据权限id 删除 - * - * @param ids id - * @return 是否成功 - */ - boolean removeByAuthorityId(List ids); - -} diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/sys/service/RoleService.java b/pmapi/src/main/java/com/ningdatech/pmapi/sys/service/RoleService.java deleted file mode 100644 index 55c136a..0000000 --- a/pmapi/src/main/java/com/ningdatech/pmapi/sys/service/RoleService.java +++ /dev/null @@ -1,86 +0,0 @@ -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 RoleService extends IService { - - - /** - * 根据ID删除 - * - * @param ids id - * @return 是否成功 - */ - boolean removeByIdWithCache(List ids); - - /** - * 判断用户是否 租户系统的超级管理员 - * - * @param code 角色编码 - * @return 是否成功 - */ - boolean isPtAdmin(String code); - - /** - * 查询用户拥有的角色 - * - * @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/UserRoleService.java b/pmapi/src/main/java/com/ningdatech/pmapi/sys/service/UserRoleService.java deleted file mode 100644 index e688d8d..0000000 --- a/pmapi/src/main/java/com/ningdatech/pmapi/sys/service/UserRoleService.java +++ /dev/null @@ -1,23 +0,0 @@ -package com.ningdatech.pmapi.sys.service; - -import com.baomidou.mybatisplus.extension.service.IService; -import com.ningdatech.pmapi.sys.entity.UserRole; - -/** - *

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

- * - * @author PoffyZhang - */ -public interface UserRoleService 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 index c15d26b..a11ba42 100644 --- 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 @@ -5,6 +5,7 @@ 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; @@ -16,7 +17,7 @@ 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.MenuService; +import com.ningdatech.pmapi.sys.service.IMenuService; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; @@ -40,7 +41,7 @@ import static com.ningdatech.basic.util.StrPool.DEF_PARENT_ID; @Slf4j @Service @RequiredArgsConstructor -public class MenuServiceImpl extends ServiceImpl implements MenuService { +public class MenuServiceImpl extends ServiceImpl implements IMenuService { @Override @Transactional(rollbackFor = Exception.class) @@ -55,8 +56,7 @@ public class MenuServiceImpl extends ServiceImpl implements Me //子菜单id subMenus(ids, lastIds); - boolean result = this.removeByIds(lastIds); - return result; + return this.removeByIds(lastIds); } private void subMenus(List ids, List lastIds) { @@ -105,8 +105,9 @@ public class MenuServiceImpl extends ServiceImpl implements Me } public Boolean checkTitle(Long id, String title) { - return baseMapper.selectCount(Wrappers.lambdaQuery(Menu.class).ne(Menu::getId, id) - .in(Menu::getType, MenuTypeEnum.MENU.getCode()).eq(Menu::getTitle, title)) > 0; + LambdaQueryWrapper wrapper = Wrappers.lambdaQuery(Menu.class) + .ne(Menu::getId, id).eq(Menu::getTitle, title); + return baseMapper.selectCount(wrapper) > 0; } @Override diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/sys/service/impl/NdRoleMenuDatascopeServiceImpl.java b/pmapi/src/main/java/com/ningdatech/pmapi/sys/service/impl/NdRoleMenuDatascopeServiceImpl.java deleted file mode 100644 index 162917b..0000000 --- a/pmapi/src/main/java/com/ningdatech/pmapi/sys/service/impl/NdRoleMenuDatascopeServiceImpl.java +++ /dev/null @@ -1,20 +0,0 @@ -package com.ningdatech.pmapi.sys.service.impl; - -import com.ningdatech.pmapi.sys.entity.NdRoleMenuDatascope; -import com.ningdatech.pmapi.sys.mapper.NdRoleMenuDatascopeMapper; -import com.ningdatech.pmapi.sys.service.INdRoleMenuDatascopeService; -import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; -import org.springframework.stereotype.Service; - -/** - *

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

- * - * @author WendyYang - * @since 2023-01-28 - */ -@Service -public class NdRoleMenuDatascopeServiceImpl extends ServiceImpl implements INdRoleMenuDatascopeService { - -} diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/sys/service/impl/RoleAuthorityServiceImpl.java b/pmapi/src/main/java/com/ningdatech/pmapi/sys/service/impl/RoleAuthorityServiceImpl.java deleted file mode 100644 index bc2dea3..0000000 --- a/pmapi/src/main/java/com/ningdatech/pmapi/sys/service/impl/RoleAuthorityServiceImpl.java +++ /dev/null @@ -1,185 +0,0 @@ -package com.ningdatech.pmapi.sys.service.impl; - -import cn.hutool.core.collection.CollUtil; -import cn.hutool.core.convert.Convert; -import cn.hutool.core.lang.Assert; -import com.baomidou.mybatisplus.core.toolkit.Wrappers; -import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; -import com.ningdatech.cache.repository.CachePlusOps; -import com.ningdatech.pmapi.sys.entity.RoleAuthority; -import com.ningdatech.pmapi.sys.entity.UserRole; -import com.ningdatech.pmapi.sys.entity.dto.RoleAuthoritySaveDTO; -import com.ningdatech.pmapi.sys.entity.dto.RoleUserSaveVO; -import com.ningdatech.pmapi.sys.entity.dto.UserRoleSaveDTO; -import com.ningdatech.pmapi.sys.entity.enumeration.AuthorizeType; -import com.ningdatech.pmapi.sys.mapper.ResourceMapper; -import com.ningdatech.pmapi.sys.mapper.RoleAuthorityMapper; -import com.ningdatech.pmapi.sys.service.RoleAuthorityService; -import com.ningdatech.pmapi.sys.service.UserRoleService; -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 RoleAuthorityServiceImpl extends ServiceImpl implements RoleAuthorityService { - - private final UserRoleService userRoleService; - private final ResourceMapper resourceMapper; - private final CachePlusOps cachePlusOps; - - @Override - public List selectDataScopeIdFromRoleByUserId(Long userId, String category) { - return baseMapper.selectDataScopeIdFromRoleByUserId(userId, category); - } - - @Override - @Transactional(rollbackFor = Exception.class) - public List saveRoleUser(RoleUserSaveVO saveVO) { - Assert.notEmpty(saveVO.getUserIdList(), "请选择用户"); - if (saveVO.getFlag() == null) { - saveVO.setFlag(true); - } - - userRoleService.remove(Wrappers.lambdaQuery(UserRole.class).eq(UserRole::getRoleId, saveVO.getRoleId()).in(UserRole::getUserId, saveVO.getUserIdList())); - if (saveVO.getFlag()) { - List list = saveVO.getUserIdList().stream().map(employeeId -> - UserRole.builder().userId(employeeId).roleId(saveVO.getRoleId()).build()).collect(Collectors.toList()); - userRoleService.saveBatch(list); - } - return findUserIdByRoleId(saveVO.getRoleId()); - } - - @Override - public List findUserIdByRoleId(Long roleId) { - return userRoleService.listObjs(Wrappers.lambdaQuery(UserRole.class) - .select(UserRole::getUserId).eq(UserRole::getRoleId, roleId), - Convert::toLong); - } - - @Override - @Transactional(rollbackFor = Exception.class) - public boolean saveUserRole(UserRoleSaveDTO userRole) { - List oldUserRoleList = userRoleService.list(Wrappers.lambdaQuery(UserRole.class).eq(UserRole::getRoleId, userRole.getRoleId())); - userRoleService.remove(Wrappers.lambdaQuery(UserRole.class).eq(UserRole::getRoleId, userRole.getRoleId())); - - Set delIdList = new HashSet<>(); - if (CollUtil.isNotEmpty(userRole.getUserIdList())) { - List list = userRole.getUserIdList() - .stream() - .map(userId -> UserRole.builder() - .userId(userId) - .roleId(userRole.getRoleId()) - .build()) - .collect(Collectors.toList()); - userRoleService.saveBatch(list); - delIdList.addAll(userRole.getUserIdList()); - } - if (!oldUserRoleList.isEmpty()) { - delIdList.addAll(oldUserRoleList.stream().map(UserRole::getUserId).collect(Collectors.toSet())); - } - delUserAuthority(delIdList); - return true; - } - - @Override - @Transactional(rollbackFor = Exception.class) - public boolean saveRoleAuthority(RoleAuthoritySaveDTO dto) { - Assert.notNull(dto.getRoleId(), "请选择角色"); - - //删除角色和资源的关联 - super.remove(Wrappers.lambdaQuery(RoleAuthority.class).eq(RoleAuthority::getRoleId, dto.getRoleId())); - - List list = new ArrayList<>(); - if (dto.getResourceIdList() != null && !dto.getResourceIdList().isEmpty()) { - List menuIdList = resourceMapper.findMenuIdByResourceId(dto.getResourceIdList()); - if (dto.getMenuIdList() == null || dto.getMenuIdList().isEmpty()) { - dto.setMenuIdList(menuIdList); - } else { - dto.getMenuIdList().addAll(menuIdList); - } - - //保存授予的资源resourceMapper - List resourceList = new HashSet<>(dto.getResourceIdList()) - .stream() - .map(resourceId -> RoleAuthority.builder() - .authorityType(AuthorizeType.RESOURCE) - .authorityId(resourceId) - .roleId(dto.getRoleId()) - .build()) - .collect(Collectors.toList()); - list.addAll(resourceList); - } - if (dto.getMenuIdList() != null && !dto.getMenuIdList().isEmpty()) { - //保存授予的菜单 - List menuList = new HashSet<>(dto.getMenuIdList()) - .stream() - .map(menuId -> RoleAuthority.builder() - .authorityType(AuthorizeType.MENU) - .authorityId(menuId) - .roleId(dto.getRoleId()) - .build()) - .collect(Collectors.toList()); - list.addAll(menuList); - } - super.saveBatch(list); - - // 角色下的所有用户 - List userIdList = userRoleService.listObjs( - Wrappers.lambdaQuery(UserRole.class) - .select(UserRole::getUserId) - .eq(UserRole::getRoleId, dto.getRoleId()), - Convert::toLong); - - delUserAuthority(userIdList); - cachePlusOps.del(AuthCacheKeyUtils.roleResourceCacheKey(dto.getRoleId())); - cachePlusOps.del(AuthCacheKeyUtils.roleResourceCacheKey((dto.getRoleId()))); - return true; - } - - @Override - @Transactional(rollbackFor = Exception.class) - public boolean removeByAuthorityId(List ids) { - List roleIds = listObjs( - Wrappers.lambdaQuery(RoleAuthority.class) - .select(RoleAuthority::getRoleId) - .in(RoleAuthority::getAuthorityId, ids), - Convert::toLong); - - if (!roleIds.isEmpty()) { - remove(Wrappers.lambdaQuery(RoleAuthority.class).in(RoleAuthority::getAuthorityId, ids)); - List userIdList = userRoleService.listObjs( - Wrappers.lambdaQuery(UserRole.class).select(UserRole::getUserId).in(UserRole::getRoleId, roleIds), - Convert::toLong); - - delUserAuthority(userIdList); - roleIds.forEach(roleId -> { - cachePlusOps.del(AuthCacheKeyUtils.roleResourceCacheKey(roleId)); - cachePlusOps.del(AuthCacheKeyUtils.roleMenuCacheKey(roleId)); - }); - } - return true; - } - - private void delUserAuthority(Collection collections) { - collections.forEach(userId -> { - cachePlusOps.del(AuthCacheKeyUtils.userResourceCacheKey(userId)); - cachePlusOps.del(AuthCacheKeyUtils.userMenuCacheKey(userId)); - cachePlusOps.del(AuthCacheKeyUtils.userRoleCacheKey(userId)); - }); - } -} 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 index 1fa0ade..4304fd2 100644 --- 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 @@ -38,10 +38,9 @@ import java.util.stream.Collectors; @Slf4j @Service @RequiredArgsConstructor -public class RoleServiceImpl extends ServiceImpl implements RoleService { +public class RoleServiceImpl extends ServiceImpl implements IRoleService { - private final RoleAuthorityService roleAuthorityService; - private final UserRoleService userRoleService; + private final IUserRoleService IUserRoleService; private final RoleMapper roleMapper; private final IRoleMenuDatascopeService roleMenuDatascopeService; @@ -49,15 +48,10 @@ public class RoleServiceImpl extends ServiceImpl implements Ro private final IRoleMenuService roleMenuService; - private final MenuService menuService; + private final IMenuService IMenuService; private static final String SUPER_ADMIN = "SUPER_ADMIN"; - @Override - public boolean isPtAdmin(String code) { - return SUPER_ADMIN.equals(code); - } - /** * 删除角色时,需要级联删除跟角色相关的一切资源: @@ -74,7 +68,7 @@ public class RoleServiceImpl extends ServiceImpl implements Ro return true; } - if (userRoleService.count(Wrappers.lambdaQuery(UserRole.class).select(UserRole::getUserId) + if (IUserRoleService.count(Wrappers.lambdaQuery(UserRole.class).select(UserRole::getUserId) .in(UserRole::getRoleId, ids)) > 0) { throw new BizException(ExceptionCode.OPERATION_EX.getCode(), "该角色下还有用户 不能随意删除!"); } @@ -83,7 +77,7 @@ public class RoleServiceImpl extends ServiceImpl implements Ro boolean removeFlag = removeByIds(ids); //角色拥有的用户 - userRoleService.remove(Wrappers.lambdaQuery(UserRole.class).in(UserRole::getRoleId, ids)); + IUserRoleService.remove(Wrappers.lambdaQuery(UserRole.class).in(UserRole::getRoleId, ids)); if (removeFlag) { // 角色绑定了那些用户 if (roleMenuService.remove(Wrappers.lambdaQuery(RoleMenu.class).in(RoleMenu::getRoleId, ids))) { @@ -190,14 +184,14 @@ public class RoleServiceImpl extends ServiceImpl implements Ro roleMenuService.remove(Wrappers.lambdaQuery(RoleMenu.class).eq(RoleMenu::getRoleId, roleId)); Set toAddMenus = new HashSet<>(); for (Long menuId : menuIds) { - Menu menu = menuService.getById(menuId); + Menu menu = IMenuService.getById(menuId); if (Objects.isNull(menu)) { continue; } RoleMenu roleMenu = new RoleMenu(null, menuId, roleId); toAddMenus.add(roleMenu); - //父级菜单 -// addParent(toAddMenus,menu,roleId); + // 父级菜单 + // addParent(toAddMenus,menu,roleId); } if (CollUtil.isNotEmpty(toAddMenus)) { roleMenuService.saveBatch(toAddMenus); @@ -206,15 +200,15 @@ public class RoleServiceImpl extends ServiceImpl implements Ro } private void addParent(Set toAddMenus, Menu menu, Long roleId) { - if (Objects.isNull(menu.getPid()) || menu.getPid().equals(0)) { + if (Objects.isNull(menu.getPid()) || menu.getPid().equals(0L)) { return; } - Menu parant = menuService.getById(menu.getPid()); - if (Objects.isNull(parant)) { + Menu parent = IMenuService.getById(menu.getPid()); + if (Objects.isNull(parent)) { return; } - RoleMenu roleMenu = new RoleMenu(null, parant.getId(), roleId); + RoleMenu roleMenu = new RoleMenu(null, parent.getId(), roleId); toAddMenus.add(roleMenu); - addParent(toAddMenus, parant, roleId); + 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 index aea2f8e..f2b85f8 100644 --- 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 @@ -8,7 +8,7 @@ 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.UserRoleService; +import com.ningdatech.pmapi.sys.service.IUserRoleService; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; @@ -26,7 +26,7 @@ import org.springframework.transaction.annotation.Transactional; @Slf4j @Service @RequiredArgsConstructor -public class UserRoleServiceImpl extends ServiceImpl implements UserRoleService { +public class UserRoleServiceImpl extends ServiceImpl implements IUserRoleService { private static final String INIT_ROLE_CODE = "SUPER_ADMIN"; 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