@@ -4,33 +4,25 @@ import cn.hutool.core.bean.BeanUtil; | |||||
import cn.hutool.core.collection.CollUtil; | import cn.hutool.core.collection.CollUtil; | ||||
import cn.hutool.core.date.StopWatch; | import cn.hutool.core.date.StopWatch; | ||||
import cn.hutool.core.util.IdUtil; | import cn.hutool.core.util.IdUtil; | ||||
import com.alibaba.fastjson.JSON; | |||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers; | import com.baomidou.mybatisplus.core.toolkit.Wrappers; | ||||
import com.google.common.collect.Maps; | |||||
import com.ningdatech.basic.exception.BizException; | import com.ningdatech.basic.exception.BizException; | ||||
import com.ningdatech.pmapi.scheduler.contants.TaskContant; | 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.entity.Region; | ||||
import com.ningdatech.pmapi.sys.service.IRegionService; | import com.ningdatech.pmapi.sys.service.IRegionService; | ||||
import com.wflow.bean.entity.WflowForms; | |||||
import com.wflow.bean.entity.WflowModelHistorys; | import com.wflow.bean.entity.WflowModelHistorys; | ||||
import com.wflow.bean.entity.WflowModels; | import com.wflow.bean.entity.WflowModels; | ||||
import com.wflow.contants.WflowContant; | |||||
import com.wflow.mapper.WflowModelHistorysMapper; | import com.wflow.mapper.WflowModelHistorysMapper; | ||||
import com.wflow.mapper.WflowModelsMapper; | import com.wflow.mapper.WflowModelsMapper; | ||||
import com.wflow.workflow.service.ProcessModelService; | import com.wflow.workflow.service.ProcessModelService; | ||||
import com.wflow.workflow.service.WflowFormsService; | import com.wflow.workflow.service.WflowFormsService; | ||||
import lombok.RequiredArgsConstructor; | import lombok.RequiredArgsConstructor; | ||||
import lombok.extern.slf4j.Slf4j; | import lombok.extern.slf4j.Slf4j; | ||||
import org.apache.commons.lang3.StringUtils; | |||||
import org.springframework.scheduling.annotation.Scheduled; | import org.springframework.scheduling.annotation.Scheduled; | ||||
import org.springframework.stereotype.Component; | import org.springframework.stereotype.Component; | ||||
import javax.annotation.Resource; | |||||
import java.net.InetAddress; | import java.net.InetAddress; | ||||
import java.net.UnknownHostException; | import java.net.UnknownHostException; | ||||
import java.time.LocalDateTime; | |||||
import java.time.ZoneOffset; | |||||
import java.util.*; | import java.util.*; | ||||
/** | /** | ||||
@@ -63,7 +55,7 @@ public class InitProcessTask { | |||||
//1.查出丽水市下的 区县 分别去初始化 表单和流程配置数据 | //1.查出丽水市下的 区县 分别去初始化 表单和流程配置数据 | ||||
List<Region> regions = regionService.list(Wrappers.lambdaQuery(Region.class) | List<Region> regions = regionService.list(Wrappers.lambdaQuery(Region.class) | ||||
.eq(Region::getDeleted,Boolean.FALSE) | .eq(Region::getDeleted,Boolean.FALSE) | ||||
.eq(Region::getParentCode, RegionContant.LS_REGION_CODE)); | |||||
.eq(Region::getParentCode, RegionConst.LS_REGION_CODE)); | |||||
if(CollUtil.isEmpty(regions)){ | if(CollUtil.isEmpty(regions)){ | ||||
throw new BizException("丽水地区数据为空 任务结束!"); | throw new BizException("丽水地区数据为空 任务结束!"); | ||||
@@ -0,0 +1,26 @@ | |||||
package com.ningdatech.pmapi.sys.contant; | |||||
/** | |||||
* <p> | |||||
* 地区常量 | |||||
* </p> | |||||
* | |||||
* @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"; | |||||
} |
@@ -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"; | |||||
} |
@@ -1,9 +1,12 @@ | |||||
package com.ningdatech.pmapi.sys.controller; | package com.ningdatech.pmapi.sys.controller; | ||||
import cn.hutool.core.bean.BeanUtil; | 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.core.toolkit.Wrappers; | ||||
import com.ningdatech.basic.auth.AbstractLoginUserUtil; | import com.ningdatech.basic.auth.AbstractLoginUserUtil; | ||||
import com.ningdatech.basic.util.CollUtils; | |||||
import com.ningdatech.log.annotation.WebLog; | 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.common.utils.TreeUtil; | ||||
import com.ningdatech.pmapi.sys.entity.Menu; | import com.ningdatech.pmapi.sys.entity.Menu; | ||||
import com.ningdatech.pmapi.sys.entity.dto.MenuQueryDTO; | 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.MenuRoleVO; | ||||
import com.ningdatech.pmapi.sys.entity.vo.MenuVO; | import com.ningdatech.pmapi.sys.entity.vo.MenuVO; | ||||
import com.ningdatech.pmapi.sys.manage.MenuManage; | 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.Api; | ||||
import io.swagger.annotations.ApiOperation; | import io.swagger.annotations.ApiOperation; | ||||
import lombok.RequiredArgsConstructor; | import lombok.RequiredArgsConstructor; | ||||
@@ -25,11 +28,10 @@ import java.util.List; | |||||
/** | /** | ||||
* <p> | * <p> | ||||
* 前端控制器 | |||||
* 菜单 | |||||
* 前端控制器-菜单 | |||||
* </p> | * </p> | ||||
* | * | ||||
* @author PoffyZhang | |||||
* @author WendyYang | |||||
* @since 2022-09-30 | * @since 2022-09-30 | ||||
*/ | */ | ||||
@Slf4j | @Slf4j | ||||
@@ -40,39 +42,43 @@ import java.util.List; | |||||
@Api(value = "Menu", tags = "系统管理-菜单") | @Api(value = "Menu", tags = "系统管理-菜单") | ||||
public class MenuController { | public class MenuController { | ||||
private final MenuService menuService; | |||||
private final IMenuService menuService; | |||||
private final MenuManage menuManage; | private final MenuManage menuManage; | ||||
/** | |||||
* 查询系统中所有的的菜单树结构, 不用缓存,因为该接口很少会使用,就算使用,也会管理员维护菜单时使用 | |||||
*/ | |||||
@ApiOperation(value = "查询系统所有的菜单", notes = "查询系统所有的菜单") | |||||
@ApiOperation("查询系统所有的菜单") | |||||
@GetMapping("/list") | @GetMapping("/list") | ||||
public List<Menu> allTree(@Valid @RequestParam(required = false, value = "title") String title) { | public List<Menu> allTree(@Valid @RequestParam(required = false, value = "title") String title) { | ||||
List<Menu> list = menuService.list(Wrappers.lambdaQuery(Menu.class).orderByAsc(Menu::getSort)); | List<Menu> list = menuService.list(Wrappers.lambdaQuery(Menu.class).orderByAsc(Menu::getSort)); | ||||
return TreeUtil.buildTree(list, title); | return TreeUtil.buildTree(list, title); | ||||
} | } | ||||
@ApiOperation("查询系统所有数据权限的菜单") | |||||
@GetMapping("/listByDataScope") | |||||
public List<Menu> allTreeByDataScope() { | |||||
LambdaQueryWrapper<Menu> dsQuery = Wrappers.lambdaQuery(Menu.class) | |||||
.eq(Menu::getHasDataScope, Boolean.TRUE) | |||||
.orderByAsc(Menu::getSort); | |||||
List<Menu> list = menuService.list(dsQuery); | |||||
if (!list.isEmpty()) { | |||||
List<Long> pidList = CollUtils.fieldList(list, MenuTreeEntity::getPid); | |||||
list.addAll(menuService.listByIds(pidList)); | |||||
} | |||||
return TreeUtil.buildTree(list); | |||||
} | |||||
@ApiOperation(value = "查询当前登录用户的菜单", notes = "查询当前登录用户的菜单") | @ApiOperation(value = "查询当前登录用户的菜单", notes = "查询当前登录用户的菜单") | ||||
@GetMapping("/current_user_menu") | |||||
@GetMapping("/myMenu") | |||||
public List<MenuRoleVO> currentUserMenu() { | public List<MenuRoleVO> currentUserMenu() { | ||||
List<Menu> list = menuService.list(Wrappers.lambdaQuery(Menu.class).orderByAsc(Menu::getSort)); | List<Menu> list = menuService.list(Wrappers.lambdaQuery(Menu.class).orderByAsc(Menu::getSort)); | ||||
// TODO:登录用户信息 | // TODO:登录用户信息 | ||||
return menuManage.buildUserMenu(list, null); | return menuManage.buildUserMenu(list, null); | ||||
} | } | ||||
/** | |||||
* 查询某个菜单 | |||||
* | |||||
* @param id 主键id | |||||
* @return 查询结果 | |||||
*/ | |||||
@ApiOperation(value = "查询菜单", notes = "查询菜单") | @ApiOperation(value = "查询菜单", notes = "查询菜单") | ||||
@GetMapping("/details") | @GetMapping("/details") | ||||
public MenuQueryDTO getDetails(@RequestParam Long id) { | public MenuQueryDTO getDetails(@RequestParam Long id) { | ||||
Menu menu = menuService.getById(id); | Menu menu = menuService.getById(id); | ||||
MenuQueryDTO query = BeanUtil.toBean(menu, MenuQueryDTO.class); | |||||
return query; | |||||
return BeanUtil.toBean(menu, MenuQueryDTO.class); | |||||
} | } | ||||
@ApiOperation(value = "保存新菜单", notes = "保存新菜单") | @ApiOperation(value = "保存新菜单", notes = "保存新菜单") | ||||
@@ -86,6 +92,7 @@ public class MenuController { | |||||
@ApiOperation(value = "编辑菜单", notes = "编辑菜单") | @ApiOperation(value = "编辑菜单", notes = "编辑菜单") | ||||
@PostMapping("/modify") | @PostMapping("/modify") | ||||
@WebLog("编辑菜单") | |||||
public MenuVO handlerUpdate(@RequestBody MenuUpdateDTO data) { | public MenuVO handlerUpdate(@RequestBody MenuUpdateDTO data) { | ||||
menuService.update(data, AbstractLoginUserUtil.getUserId()); | menuService.update(data, AbstractLoginUserUtil.getUserId()); | ||||
return BeanUtil.toBean(data, MenuVO.class); | return BeanUtil.toBean(data, MenuVO.class); | ||||
@@ -93,6 +100,7 @@ public class MenuController { | |||||
@ApiOperation(value = "删除菜单", notes = "删除菜单") | @ApiOperation(value = "删除菜单", notes = "删除菜单") | ||||
@PostMapping("/remove") | @PostMapping("/remove") | ||||
@WebLog("删除菜单") | |||||
public Boolean handlerDelete(@RequestBody List<Long> ids) { | public Boolean handlerDelete(@RequestBody List<Long> ids) { | ||||
return menuService.removeByIdWithCache(ids); | return menuService.removeByIdWithCache(ids); | ||||
} | } | ||||
@@ -1,20 +0,0 @@ | |||||
package com.ningdatech.pmapi.sys.controller; | |||||
import org.springframework.web.bind.annotation.RequestMapping; | |||||
import org.springframework.stereotype.Controller; | |||||
/** | |||||
* <p> | |||||
* 角色菜单数据权限关联表 前端控制器 | |||||
* </p> | |||||
* | |||||
* @author WendyYang | |||||
* @since 2023-01-28 | |||||
*/ | |||||
@Controller | |||||
@RequestMapping("/pmapi.sys/nd-role-menu-datascope") | |||||
public class NdRoleMenuDatascopeController { | |||||
} |
@@ -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.dto.RoleUpdateDTO; | ||||
import com.ningdatech.pmapi.sys.entity.vo.RoleVO; | import com.ningdatech.pmapi.sys.entity.vo.RoleVO; | ||||
import com.ningdatech.pmapi.sys.manage.RoleManage; | 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.Api; | ||||
import io.swagger.annotations.ApiOperation; | import io.swagger.annotations.ApiOperation; | ||||
import lombok.RequiredArgsConstructor; | import lombok.RequiredArgsConstructor; | ||||
@@ -24,11 +24,10 @@ import java.util.Objects; | |||||
/** | /** | ||||
* <p> | * <p> | ||||
* 前端控制器 | |||||
* 角色 | |||||
* 前端控制器-角色 | |||||
* </p> | * </p> | ||||
* | * | ||||
* @author PoffyZhang | |||||
* @author WendyYang | |||||
* @since 2022-09-30 | * @since 2022-09-30 | ||||
*/ | */ | ||||
@Slf4j | @Slf4j | ||||
@@ -39,7 +38,7 @@ import java.util.Objects; | |||||
@RequiredArgsConstructor | @RequiredArgsConstructor | ||||
public class RoleController { | public class RoleController { | ||||
private final RoleService roleService; | |||||
private final IRoleService roleService; | |||||
private final RoleManage roleManage; | private final RoleManage roleManage; | ||||
@@ -34,62 +34,40 @@ public class Menu extends MenuTreeEntity<Menu, Long> { | |||||
private static final long serialVersionUID = 1L; | 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 = "组件") | @ApiModelProperty(value = "组件") | ||||
@Size(max = 255, message = "组件长度不能超过255") | @Size(max = 255, message = "组件长度不能超过255") | ||||
@TableField(value = "component", condition = LIKE) | @TableField(value = "component", condition = LIKE) | ||||
private String component; | private String component; | ||||
/** | |||||
* 菜单图标 | |||||
*/ | |||||
@ApiModelProperty(value = "菜单图标") | @ApiModelProperty(value = "菜单图标") | ||||
@Size(max = 255, message = "菜单图标长度不能超过255") | @Size(max = 255, message = "菜单图标长度不能超过255") | ||||
@TableField(value = "icon", condition = LIKE) | @TableField(value = "icon", condition = LIKE) | ||||
private String icon; | private String icon; | ||||
/** | |||||
* 子菜单数目 | |||||
*/ | |||||
@ApiModelProperty(value = "是否隐藏") | @ApiModelProperty(value = "是否隐藏") | ||||
@TableField(value = "hidden") | @TableField(value = "hidden") | ||||
private Boolean hidden; | private Boolean hidden; | ||||
/** | |||||
* activeMenu | |||||
*/ | |||||
@ApiModelProperty(value = "activeMenu") | @ApiModelProperty(value = "activeMenu") | ||||
@TableField(value = "active_menu") | @TableField(value = "active_menu") | ||||
private String activeMenu; | private String activeMenu; | ||||
/** | |||||
* 跳转 | |||||
*/ | |||||
@ApiModelProperty(value = "跳转") | @ApiModelProperty(value = "跳转") | ||||
@TableField(value = "redirect") | @TableField(value = "redirect") | ||||
private String redirect; | private String redirect; | ||||
@ApiModelProperty("是否有数据权限") | |||||
private Boolean hasDataScope; | |||||
@ApiModelProperty("数据权限选项") | |||||
private String dataScopeOption; | |||||
private Long updateBy; | private Long updateBy; | ||||
private Long createBy; | private Long createBy; | ||||
private LocalDateTime updateOn; | private LocalDateTime updateOn; | ||||
private LocalDateTime createOn; | private LocalDateTime createOn; | ||||
} | } |
@@ -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; | |||||
/** | |||||
* <p> | |||||
* 角色菜单数据权限关联表 | |||||
* </p> | |||||
* | |||||
* @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 + | |||||
"}"; | |||||
} | |||||
} |
@@ -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.MenuRoleVO; | ||||
import com.ningdatech.pmapi.sys.entity.vo.RoleVO; | import com.ningdatech.pmapi.sys.entity.vo.RoleVO; | ||||
import com.ningdatech.pmapi.sys.service.IRoleMenuService; | 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 lombok.RequiredArgsConstructor; | ||||
import org.apache.commons.lang3.StringUtils; | import org.apache.commons.lang3.StringUtils; | ||||
import org.springframework.stereotype.Component; | import org.springframework.stereotype.Component; | ||||
@@ -35,8 +35,8 @@ import java.util.stream.Collectors; | |||||
@RequiredArgsConstructor | @RequiredArgsConstructor | ||||
public class RoleManage { | public class RoleManage { | ||||
private final RoleService roleService; | |||||
private final MenuService menuService; | |||||
private final IRoleService IRoleService; | |||||
private final IMenuService IMenuService; | |||||
private final IRoleMenuService roleMenuService; | private final IRoleMenuService roleMenuService; | ||||
@@ -51,13 +51,13 @@ public class RoleManage { | |||||
private void searchList(Page<Role> page, LambdaQueryWrapper<Role> wrapper, RolePageReq rolePageReq) { | private void searchList(Page<Role> page, LambdaQueryWrapper<Role> wrapper, RolePageReq rolePageReq) { | ||||
wrapper.like(StringUtils.isNotBlank(rolePageReq.getName()), Role::getName, rolePageReq.getName()) | wrapper.like(StringUtils.isNotBlank(rolePageReq.getName()), Role::getName, rolePageReq.getName()) | ||||
.orderByDesc(Role::getUpdateOn); | .orderByDesc(Role::getUpdateOn); | ||||
roleService.page(page, wrapper); | |||||
IRoleService.page(page, wrapper); | |||||
} | } | ||||
public void buildMenu(RoleVO query) { | public void buildMenu(RoleVO query) { | ||||
//改成直接返回有权限的 | //改成直接返回有权限的 | ||||
List<Menu> list = menuService.list(Wrappers.lambdaQuery(Menu.class).orderByAsc(Menu::getSort)); | |||||
List<Menu> list = IMenuService.list(Wrappers.lambdaQuery(Menu.class).orderByAsc(Menu::getSort)); | |||||
List<RoleMenu> roleMenus = roleMenuService.list(Wrappers.lambdaQuery(RoleMenu.class) | List<RoleMenu> roleMenus = roleMenuService.list(Wrappers.lambdaQuery(RoleMenu.class) | ||||
.eq(RoleMenu::getRoleId, query.getId())); | .eq(RoleMenu::getRoleId, query.getId())); | ||||
List<MenuRoleVO> menus = list.stream().map(menu -> { | List<MenuRoleVO> menus = list.stream().map(menu -> { | ||||
@@ -1,16 +0,0 @@ | |||||
package com.ningdatech.pmapi.sys.mapper; | |||||
import com.ningdatech.pmapi.sys.entity.NdRoleMenuDatascope; | |||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper; | |||||
/** | |||||
* <p> | |||||
* 角色菜单数据权限关联表 Mapper 接口 | |||||
* </p> | |||||
* | |||||
* @author WendyYang | |||||
* @since 2023-01-28 | |||||
*/ | |||||
public interface NdRoleMenuDatascopeMapper extends BaseMapper<NdRoleMenuDatascope> { | |||||
} |
@@ -1,5 +0,0 @@ | |||||
<?xml version="1.0" encoding="UTF-8"?> | |||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> | |||||
<mapper namespace="com.ningdatech.pmapi.sys.mapper.NdRoleMenuDatascopeMapper"> | |||||
</mapper> |
@@ -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; | |||||
/** | |||||
* <p> | |||||
* Mapper 接口 | |||||
* 角色的资源 | |||||
* </p> | |||||
* | |||||
* @author PoffyZhang | |||||
*/ | |||||
@Repository | |||||
public interface RoleAuthorityMapper extends BaseMapper<RoleAuthority> { | |||||
/** | |||||
* 根据用户-角色-数据权限关系,查询可用的数据权限ID | |||||
* <p> | |||||
* 角色被禁用后,用户不在拥有此角色的权限 | |||||
* | |||||
* @param userId 用户ID | |||||
* @param category 角色类别 | |||||
* @return / | |||||
*/ | |||||
List<Long> selectDataScopeIdFromRoleByUserId(@Param("userId") Long userId, @Param("category") String category); | |||||
} |
@@ -1,15 +0,0 @@ | |||||
<?xml version="1.0" encoding="UTF-8"?> | |||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> | |||||
<mapper namespace="com.ningdatech.pmapi.sys.mapper.RoleAuthorityMapper"> | |||||
<select id="selectDataScopeIdFromRoleByUserId" parameterType="map" resultType="java.lang.Long"> | |||||
SELECT DISTINCT rrds.authority_id | |||||
FROM nd_role_authority rrds | |||||
INNER JOIN nd_role r on r.id = rrds.role_id | |||||
INNER JOIN nd_user_role er on er.role_id = r.id | |||||
WHERE r.category = #{category} | |||||
and er.user_id = #{userId} | |||||
and r.state = true | |||||
</select> | |||||
</mapper> |
@@ -16,7 +16,7 @@ import java.util.List; | |||||
* @author WendyYang | * @author WendyYang | ||||
* @since 2022-09-30 | * @since 2022-09-30 | ||||
*/ | */ | ||||
public interface MenuService extends IService<Menu> { | |||||
public interface IMenuService extends IService<Menu> { | |||||
/** | /** | ||||
* 根据ID删除 | * 根据ID删除 |
@@ -1,16 +0,0 @@ | |||||
package com.ningdatech.pmapi.sys.service; | |||||
import com.ningdatech.pmapi.sys.entity.NdRoleMenuDatascope; | |||||
import com.baomidou.mybatisplus.extension.service.IService; | |||||
/** | |||||
* <p> | |||||
* 角色菜单数据权限关联表 服务类 | |||||
* </p> | |||||
* | |||||
* @author WendyYang | |||||
* @since 2023-01-28 | |||||
*/ | |||||
public interface INdRoleMenuDatascopeService extends IService<NdRoleMenuDatascope> { | |||||
} |
@@ -16,7 +16,7 @@ import java.util.List; | |||||
* @author PoffyZhang | * @author PoffyZhang | ||||
* @since 2022-09-30 | * @since 2022-09-30 | ||||
*/ | */ | ||||
public interface RoleService extends IService<Role> { | |||||
public interface IRoleService extends IService<Role> { | |||||
/** | /** | ||||
@@ -28,14 +28,6 @@ public interface RoleService extends IService<Role> { | |||||
boolean removeByIdWithCache(List<Long> ids); | boolean removeByIdWithCache(List<Long> ids); | ||||
/** | /** | ||||
* 判断用户是否 租户系统的超级管理员 | |||||
* | |||||
* @param code 角色编码 | |||||
* @return 是否成功 | |||||
*/ | |||||
boolean isPtAdmin(String code); | |||||
/** | |||||
* 查询用户拥有的角色 | * 查询用户拥有的角色 | ||||
* | * | ||||
* @param userId 用户id | * @param userId 用户id |
@@ -12,7 +12,7 @@ import com.ningdatech.pmapi.sys.entity.UserRole; | |||||
* | * | ||||
* @author PoffyZhang | * @author PoffyZhang | ||||
*/ | */ | ||||
public interface UserRoleService extends IService<UserRole> { | |||||
public interface IUserRoleService extends IService<UserRole> { | |||||
/** | /** | ||||
* 初始化超级管理员角色 权限 | * 初始化超级管理员角色 权限 | ||||
* | * |
@@ -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; | |||||
/** | |||||
* <p> | |||||
* 业务接口 | |||||
* 角色的资源 | |||||
* </p> | |||||
* | |||||
* @author PoffyZhang | |||||
*/ | |||||
public interface RoleAuthorityService extends IService<RoleAuthority> { | |||||
/** | |||||
* 根据用户-角色-数据权限关系,查询可用的数据权限ID | |||||
* <p> | |||||
* 角色被禁用后,用户不在拥有此角色的权限 | |||||
* | |||||
* @param userId 用户ID | |||||
* @param category 角色类别 | |||||
* @return | |||||
*/ | |||||
List<Long> selectDataScopeIdFromRoleByUserId(Long userId, String category); | |||||
/** | |||||
* 给用户分配角色 | |||||
* | |||||
* @param userRole 用于角色 | |||||
* @return 是否成功 | |||||
*/ | |||||
boolean saveUserRole(UserRoleSaveDTO userRole); | |||||
/** | |||||
* 给角色绑定用户 | |||||
* | |||||
* @param roleUser 用于角色 | |||||
* @return 是否成功 | |||||
*/ | |||||
List<Long> saveRoleUser(RoleUserSaveVO roleUser); | |||||
/** | |||||
* 根据角色查找用户 | |||||
* | |||||
* @param roleId 角色ID | |||||
* @return | |||||
*/ | |||||
List<Long> findUserIdByRoleId(Long roleId); | |||||
/** | |||||
* 给角色重新分配 权限(资源/菜单) | |||||
* | |||||
* @param roleAuthoritySaveDTO 角色授权信息 | |||||
* @return 是否成功 | |||||
*/ | |||||
boolean saveRoleAuthority(RoleAuthoritySaveDTO roleAuthoritySaveDTO); | |||||
/** | |||||
* 根据权限id 删除 | |||||
* | |||||
* @param ids id | |||||
* @return 是否成功 | |||||
*/ | |||||
boolean removeByAuthorityId(List<Long> ids); | |||||
} |
@@ -5,6 +5,7 @@ import cn.hutool.core.collection.CollUtil; | |||||
import cn.hutool.core.convert.Convert; | import cn.hutool.core.convert.Convert; | ||||
import cn.hutool.core.util.StrUtil; | import cn.hutool.core.util.StrUtil; | ||||
import cn.hutool.http.HttpStatus; | import cn.hutool.http.HttpStatus; | ||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; | |||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers; | import com.baomidou.mybatisplus.core.toolkit.Wrappers; | ||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; | ||||
import com.google.common.collect.Lists; | 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.MenuSaveDTO; | ||||
import com.ningdatech.pmapi.sys.entity.dto.MenuUpdateDTO; | import com.ningdatech.pmapi.sys.entity.dto.MenuUpdateDTO; | ||||
import com.ningdatech.pmapi.sys.mapper.MenuMapper; | 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.RequiredArgsConstructor; | ||||
import lombok.extern.slf4j.Slf4j; | import lombok.extern.slf4j.Slf4j; | ||||
import org.springframework.stereotype.Service; | import org.springframework.stereotype.Service; | ||||
@@ -40,7 +41,7 @@ import static com.ningdatech.basic.util.StrPool.DEF_PARENT_ID; | |||||
@Slf4j | @Slf4j | ||||
@Service | @Service | ||||
@RequiredArgsConstructor | @RequiredArgsConstructor | ||||
public class MenuServiceImpl extends ServiceImpl<MenuMapper, Menu> implements MenuService { | |||||
public class MenuServiceImpl extends ServiceImpl<MenuMapper, Menu> implements IMenuService { | |||||
@Override | @Override | ||||
@Transactional(rollbackFor = Exception.class) | @Transactional(rollbackFor = Exception.class) | ||||
@@ -55,8 +56,7 @@ public class MenuServiceImpl extends ServiceImpl<MenuMapper, Menu> implements Me | |||||
//子菜单id | //子菜单id | ||||
subMenus(ids, lastIds); | subMenus(ids, lastIds); | ||||
boolean result = this.removeByIds(lastIds); | |||||
return result; | |||||
return this.removeByIds(lastIds); | |||||
} | } | ||||
private void subMenus(List<Long> ids, List<Long> lastIds) { | private void subMenus(List<Long> ids, List<Long> lastIds) { | ||||
@@ -105,8 +105,9 @@ public class MenuServiceImpl extends ServiceImpl<MenuMapper, Menu> implements Me | |||||
} | } | ||||
public Boolean checkTitle(Long id, String title) { | 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<Menu> wrapper = Wrappers.lambdaQuery(Menu.class) | |||||
.ne(Menu::getId, id).eq(Menu::getTitle, title); | |||||
return baseMapper.selectCount(wrapper) > 0; | |||||
} | } | ||||
@Override | @Override | ||||
@@ -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; | |||||
/** | |||||
* <p> | |||||
* 角色菜单数据权限关联表 服务实现类 | |||||
* </p> | |||||
* | |||||
* @author WendyYang | |||||
* @since 2023-01-28 | |||||
*/ | |||||
@Service | |||||
public class NdRoleMenuDatascopeServiceImpl extends ServiceImpl<NdRoleMenuDatascopeMapper, NdRoleMenuDatascope> implements INdRoleMenuDatascopeService { | |||||
} |
@@ -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; | |||||
/** | |||||
* <p> | |||||
* 业务实现类 | |||||
* 角色的资源 | |||||
* </p> | |||||
* | |||||
* @author PoffyZhang | |||||
*/ | |||||
@Slf4j | |||||
@Service | |||||
@RequiredArgsConstructor | |||||
public class RoleAuthorityServiceImpl extends ServiceImpl<RoleAuthorityMapper, RoleAuthority> implements RoleAuthorityService { | |||||
private final UserRoleService userRoleService; | |||||
private final ResourceMapper resourceMapper; | |||||
private final CachePlusOps cachePlusOps; | |||||
@Override | |||||
public List<Long> selectDataScopeIdFromRoleByUserId(Long userId, String category) { | |||||
return baseMapper.selectDataScopeIdFromRoleByUserId(userId, category); | |||||
} | |||||
@Override | |||||
@Transactional(rollbackFor = Exception.class) | |||||
public List<Long> 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<UserRole> 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<Long> 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<UserRole> oldUserRoleList = userRoleService.list(Wrappers.lambdaQuery(UserRole.class).eq(UserRole::getRoleId, userRole.getRoleId())); | |||||
userRoleService.remove(Wrappers.lambdaQuery(UserRole.class).eq(UserRole::getRoleId, userRole.getRoleId())); | |||||
Set<Long> delIdList = new HashSet<>(); | |||||
if (CollUtil.isNotEmpty(userRole.getUserIdList())) { | |||||
List<UserRole> 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<RoleAuthority> list = new ArrayList<>(); | |||||
if (dto.getResourceIdList() != null && !dto.getResourceIdList().isEmpty()) { | |||||
List<Long> menuIdList = resourceMapper.findMenuIdByResourceId(dto.getResourceIdList()); | |||||
if (dto.getMenuIdList() == null || dto.getMenuIdList().isEmpty()) { | |||||
dto.setMenuIdList(menuIdList); | |||||
} else { | |||||
dto.getMenuIdList().addAll(menuIdList); | |||||
} | |||||
//保存授予的资源resourceMapper | |||||
List<RoleAuthority> 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<RoleAuthority> 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<Long> 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<Long> ids) { | |||||
List<Long> 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<Long> 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<Long> collections) { | |||||
collections.forEach(userId -> { | |||||
cachePlusOps.del(AuthCacheKeyUtils.userResourceCacheKey(userId)); | |||||
cachePlusOps.del(AuthCacheKeyUtils.userMenuCacheKey(userId)); | |||||
cachePlusOps.del(AuthCacheKeyUtils.userRoleCacheKey(userId)); | |||||
}); | |||||
} | |||||
} |
@@ -38,10 +38,9 @@ import java.util.stream.Collectors; | |||||
@Slf4j | @Slf4j | ||||
@Service | @Service | ||||
@RequiredArgsConstructor | @RequiredArgsConstructor | ||||
public class RoleServiceImpl extends ServiceImpl<RoleMapper, Role> implements RoleService { | |||||
public class RoleServiceImpl extends ServiceImpl<RoleMapper, Role> implements IRoleService { | |||||
private final RoleAuthorityService roleAuthorityService; | |||||
private final UserRoleService userRoleService; | |||||
private final IUserRoleService IUserRoleService; | |||||
private final RoleMapper roleMapper; | private final RoleMapper roleMapper; | ||||
private final IRoleMenuDatascopeService roleMenuDatascopeService; | private final IRoleMenuDatascopeService roleMenuDatascopeService; | ||||
@@ -49,15 +48,10 @@ public class RoleServiceImpl extends ServiceImpl<RoleMapper, Role> implements Ro | |||||
private final IRoleMenuService roleMenuService; | private final IRoleMenuService roleMenuService; | ||||
private final MenuService menuService; | |||||
private final IMenuService IMenuService; | |||||
private static final String SUPER_ADMIN = "SUPER_ADMIN"; | 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<RoleMapper, Role> implements Ro | |||||
return true; | 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) { | .in(UserRole::getRoleId, ids)) > 0) { | ||||
throw new BizException(ExceptionCode.OPERATION_EX.getCode(), "该角色下还有用户 不能随意删除!"); | throw new BizException(ExceptionCode.OPERATION_EX.getCode(), "该角色下还有用户 不能随意删除!"); | ||||
} | } | ||||
@@ -83,7 +77,7 @@ public class RoleServiceImpl extends ServiceImpl<RoleMapper, Role> implements Ro | |||||
boolean removeFlag = removeByIds(ids); | 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 (removeFlag) { | ||||
// 角色绑定了那些用户 | // 角色绑定了那些用户 | ||||
if (roleMenuService.remove(Wrappers.lambdaQuery(RoleMenu.class).in(RoleMenu::getRoleId, ids))) { | if (roleMenuService.remove(Wrappers.lambdaQuery(RoleMenu.class).in(RoleMenu::getRoleId, ids))) { | ||||
@@ -190,14 +184,14 @@ public class RoleServiceImpl extends ServiceImpl<RoleMapper, Role> implements Ro | |||||
roleMenuService.remove(Wrappers.lambdaQuery(RoleMenu.class).eq(RoleMenu::getRoleId, roleId)); | roleMenuService.remove(Wrappers.lambdaQuery(RoleMenu.class).eq(RoleMenu::getRoleId, roleId)); | ||||
Set<RoleMenu> toAddMenus = new HashSet<>(); | Set<RoleMenu> toAddMenus = new HashSet<>(); | ||||
for (Long menuId : menuIds) { | for (Long menuId : menuIds) { | ||||
Menu menu = menuService.getById(menuId); | |||||
Menu menu = IMenuService.getById(menuId); | |||||
if (Objects.isNull(menu)) { | if (Objects.isNull(menu)) { | ||||
continue; | continue; | ||||
} | } | ||||
RoleMenu roleMenu = new RoleMenu(null, menuId, roleId); | RoleMenu roleMenu = new RoleMenu(null, menuId, roleId); | ||||
toAddMenus.add(roleMenu); | toAddMenus.add(roleMenu); | ||||
//父级菜单 | |||||
// addParent(toAddMenus,menu,roleId); | |||||
// 父级菜单 | |||||
// addParent(toAddMenus,menu,roleId); | |||||
} | } | ||||
if (CollUtil.isNotEmpty(toAddMenus)) { | if (CollUtil.isNotEmpty(toAddMenus)) { | ||||
roleMenuService.saveBatch(toAddMenus); | roleMenuService.saveBatch(toAddMenus); | ||||
@@ -206,15 +200,15 @@ public class RoleServiceImpl extends ServiceImpl<RoleMapper, Role> implements Ro | |||||
} | } | ||||
private void addParent(Set<RoleMenu> toAddMenus, Menu menu, Long roleId) { | private void addParent(Set<RoleMenu> toAddMenus, Menu menu, Long roleId) { | ||||
if (Objects.isNull(menu.getPid()) || menu.getPid().equals(0)) { | |||||
if (Objects.isNull(menu.getPid()) || menu.getPid().equals(0L)) { | |||||
return; | return; | ||||
} | } | ||||
Menu parant = menuService.getById(menu.getPid()); | |||||
if (Objects.isNull(parant)) { | |||||
Menu parent = IMenuService.getById(menu.getPid()); | |||||
if (Objects.isNull(parent)) { | |||||
return; | return; | ||||
} | } | ||||
RoleMenu roleMenu = new RoleMenu(null, parant.getId(), roleId); | |||||
RoleMenu roleMenu = new RoleMenu(null, parent.getId(), roleId); | |||||
toAddMenus.add(roleMenu); | toAddMenus.add(roleMenu); | ||||
addParent(toAddMenus, parant, roleId); | |||||
addParent(toAddMenus, parent, roleId); | |||||
} | } | ||||
} | } |
@@ -8,7 +8,7 @@ import com.ningdatech.pmapi.sys.entity.Role; | |||||
import com.ningdatech.pmapi.sys.entity.UserRole; | import com.ningdatech.pmapi.sys.entity.UserRole; | ||||
import com.ningdatech.pmapi.sys.mapper.RoleMapper; | import com.ningdatech.pmapi.sys.mapper.RoleMapper; | ||||
import com.ningdatech.pmapi.sys.mapper.UserRoleMapper; | 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.RequiredArgsConstructor; | ||||
import lombok.extern.slf4j.Slf4j; | import lombok.extern.slf4j.Slf4j; | ||||
import org.springframework.stereotype.Service; | import org.springframework.stereotype.Service; | ||||
@@ -26,7 +26,7 @@ import org.springframework.transaction.annotation.Transactional; | |||||
@Slf4j | @Slf4j | ||||
@Service | @Service | ||||
@RequiredArgsConstructor | @RequiredArgsConstructor | ||||
public class UserRoleServiceImpl extends ServiceImpl<UserRoleMapper, UserRole> implements UserRoleService { | |||||
public class UserRoleServiceImpl extends ServiceImpl<UserRoleMapper, UserRole> implements IUserRoleService { | |||||
private static final String INIT_ROLE_CODE = "SUPER_ADMIN"; | private static final String INIT_ROLE_CODE = "SUPER_ADMIN"; | ||||
@@ -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; | |||||
/** | |||||
* <p> | |||||
* AppRunTests | |||||
* </p> | |||||
* | |||||
* @author WendyYang | |||||
* @since 19:27 2022/5/10 | |||||
*/ | |||||
@RunWith(SpringRunner.class) | |||||
@SpringBootTest(classes = App.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) | |||||
public class AppTests { | |||||
} |
@@ -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; | |||||
/** | |||||
* <p> | |||||
* IMenuServiceTest | |||||
* </p> | |||||
* | |||||
* @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<Entity> menu = Db.use().findAll("nd_menu"); | |||||
menu.forEach(System.out::println); | |||||
menu.forEach(w -> { | |||||
Menu bean = w.toBean(Menu.class); | |||||
menuService.save(bean); | |||||
}); | |||||
} | |||||
} |