diff --git a/basic-interface/src/main/java/ink/wgink/interfaces/role/IRoleCheckService.java b/basic-interface/src/main/java/ink/wgink/interfaces/role/IRoleCheckService.java new file mode 100644 index 00000000..cfa99dd5 --- /dev/null +++ b/basic-interface/src/main/java/ink/wgink/interfaces/role/IRoleCheckService.java @@ -0,0 +1,14 @@ +package ink.wgink.interfaces.role; + +/** + * When you feel like quitting. Think about why you started + * 当你想要放弃的时候,想想当初你为何开始 + * + * @ClassName: IRoleCheckService + * @Description: 角色检查 + * @Author: WangGeng + * @Date: 2021/2/17 22:51 + * @Version: 1.0 + **/ +public interface IRoleCheckService { +} diff --git a/service-menu/src/main/java/ink/wgink/module/menu/startup/ServiceMenuStartUp.java b/service-menu/src/main/java/ink/wgink/module/menu/startup/ServiceMenuStartUp.java index fe21f05d..1e098466 100644 --- a/service-menu/src/main/java/ink/wgink/module/menu/startup/ServiceMenuStartUp.java +++ b/service-menu/src/main/java/ink/wgink/module/menu/startup/ServiceMenuStartUp.java @@ -6,6 +6,7 @@ import ink.wgink.interfaces.group.IGroupCheckService; import ink.wgink.interfaces.menu.IMenuBaseService; import ink.wgink.interfaces.permission.IPermissionCheckService; import ink.wgink.interfaces.position.IPositionCheckService; +import ink.wgink.interfaces.role.IRoleCheckService; import ink.wgink.interfaces.user.IUserCheckService; import ink.wgink.pojo.dtos.menu.MenuDTO; import ink.wgink.module.menu.dao.IMenuDao; @@ -33,6 +34,7 @@ import java.util.Map; */ @Component public class ServiceMenuStartUp implements ApplicationRunner { + private static final Logger LOG = LoggerFactory.getLogger(ServiceMenuStartUp.class); @Autowired private IMenuDao menuDao; @@ -48,6 +50,8 @@ public class ServiceMenuStartUp implements ApplicationRunner { private IPositionCheckService positionCheckService; @Autowired(required = false) private IPermissionCheckService permissionCheckService; + @Autowired(required = false) + private IRoleCheckService roleCheckService; @Override public void run(ApplicationArguments args) throws Exception { @@ -257,8 +261,8 @@ public class ServiceMenuStartUp implements ApplicationRunner { if (menuDTO == null) { params.put("menuId", menuId); params.put("menuParentId", menuParentId); - params.put("menuName", "用户"); - params.put("menuSummary", "用户管理"); + params.put("menuName", "用户账号"); + params.put("menuSummary", "用户账号管理"); params.put("menuUrl", "/route/user/list"); params.put("menuType", "1"); params.put("menuIcon", "fa-icon-color-white fa fa-address-book"); @@ -288,8 +292,8 @@ public class ServiceMenuStartUp implements ApplicationRunner { if (menuDTO == null) { params.put("menuId", menuId); params.put("menuParentId", menuParentId); - params.put("menuName", "机构"); - params.put("menuSummary", "机构管理"); + params.put("menuName", "组织机构"); + params.put("menuSummary", "组织机构管理"); params.put("menuUrl", "/route/department/list-tree"); params.put("menuType", "1"); params.put("menuIcon", "fa-icon-color-white fa fa-bank"); @@ -319,7 +323,7 @@ public class ServiceMenuStartUp implements ApplicationRunner { if (menuDTO == null) { params.put("menuId", menuId); params.put("menuParentId", menuParentId); - params.put("menuName", "用户组"); + params.put("menuName", "用户组管理"); params.put("menuSummary", "用户组管理"); params.put("menuUrl", "/route/group/list-tree"); params.put("menuType", "1"); @@ -349,7 +353,7 @@ public class ServiceMenuStartUp implements ApplicationRunner { if (menuDTO == null) { params.put("menuId", menuId); params.put("menuParentId", menuParentId); - params.put("menuName", "职位"); + params.put("menuName", "职位管理"); params.put("menuSummary", "职位管理"); params.put("menuUrl", "/route/position/list-tree"); params.put("menuType", "1"); @@ -368,10 +372,10 @@ public class ServiceMenuStartUp implements ApplicationRunner { * @param menuParentId */ private void initPermissionManager(Map params, String menuParentId) { - if (permissionCheckService == null) { + if (permissionCheckService == null && roleCheckService == null) { return; } - LOG.debug("初始化菜单:角色与权限管理"); + LOG.debug("初始化菜单:权限与角色"); params.remove("menuId"); params.put("menuCode", "00010003"); MenuDTO menuDTO = menuDao.getSimple(params); @@ -380,8 +384,8 @@ public class ServiceMenuStartUp implements ApplicationRunner { menuId = UUIDUtil.getUUID(); params.put("menuId", menuId); params.put("menuParentId", menuParentId); - params.put("menuName", "角色与权限管理"); - params.put("menuSummary", "角色与权限管理"); + params.put("menuName", "权限与角色"); + params.put("menuSummary", "权限与角色管理"); params.put("menuUrl", "javascript:void(0);"); params.put("menuType", "1"); params.put("menuIcon", "fa-icon-color-white fa fa-users"); @@ -392,10 +396,17 @@ public class ServiceMenuStartUp implements ApplicationRunner { } else { menuId = menuDTO.getMenuId(); } - initSavePermissionManager(params, menuId); - initDeletePermissionManager(params, menuId); - initUpdatePermissionManager(params, menuId); - initQueryPermissionManager(params, menuId); + + if (permissionCheckService != null) { + initSavePermissionManage(params, menuId); + initDeletePermissionManage(params, menuId); + initUpdatePermissionManage(params, menuId); + initQueryPermissionManage(params, menuId); + } + + if (roleCheckService != null) { + initRoleManage(params, menuId); + } } /** @@ -404,7 +415,7 @@ public class ServiceMenuStartUp implements ApplicationRunner { * @param params * @param menuParentId */ - private void initSavePermissionManager(Map params, String menuParentId) { + private void initSavePermissionManage(Map params, String menuParentId) { LOG.debug("初始化菜单:新增权限"); params.remove("menuId"); params.put("menuCode", "000100030001"); @@ -432,7 +443,7 @@ public class ServiceMenuStartUp implements ApplicationRunner { * @param params * @param menuParentId */ - private void initDeletePermissionManager(Map params, String menuParentId) { + private void initDeletePermissionManage(Map params, String menuParentId) { LOG.debug("初始化菜单:删除权限"); params.remove("menuId"); params.put("menuCode", "000100030002"); @@ -460,7 +471,7 @@ public class ServiceMenuStartUp implements ApplicationRunner { * @param params * @param menuParentId */ - private void initUpdatePermissionManager(Map params, String menuParentId) { + private void initUpdatePermissionManage(Map params, String menuParentId) { LOG.debug("初始化菜单:修改权限"); params.remove("menuId"); params.put("menuCode", "000100030003"); @@ -488,7 +499,7 @@ public class ServiceMenuStartUp implements ApplicationRunner { * @param params * @param menuParentId */ - private void initQueryPermissionManager(Map params, String menuParentId) { + private void initQueryPermissionManage(Map params, String menuParentId) { LOG.debug("初始化菜单:查询权限"); params.remove("menuId"); params.put("menuCode", "000100030004"); @@ -510,8 +521,31 @@ public class ServiceMenuStartUp implements ApplicationRunner { } } - private void initMenuRole() { + /** + * 角色管理 + * + * @param params + * @param menuParentId + */ + private void initRoleManage(Map params, String menuParentId) { LOG.debug("初始化菜单:角色管理"); - + params.remove("menuId"); + params.put("menuCode", "000100030005"); + MenuDTO menuDTO = menuDao.getSimple(params); + String menuId; + if (menuDTO == null) { + menuId = UUIDUtil.getUUID(); + params.put("menuId", menuId); + params.put("menuParentId", menuParentId); + params.put("menuName", "角色管理"); + params.put("menuSummary", "角色管理"); + params.put("menuUrl", "/route/role/list-tree?permissionType=permissionQuery"); + params.put("menuType", "1"); + params.put("menuIcon", "fa-icon-color-white fa fa-users"); + params.put("menuOrder", "5"); + params.put("menuStatus", "0"); + params.put("openType", "1"); + menuDao.save(params); + } } } diff --git a/service-role/src/main/java/ink/wgink/service/role/controller/api/RoleController.java b/service-role/src/main/java/ink/wgink/service/role/controller/api/RoleController.java index e2aa9402..76ca595c 100644 --- a/service-role/src/main/java/ink/wgink/service/role/controller/api/RoleController.java +++ b/service-role/src/main/java/ink/wgink/service/role/controller/api/RoleController.java @@ -7,12 +7,9 @@ import ink.wgink.interfaces.consts.ISystemConstant; import ink.wgink.pojo.ListPage; import ink.wgink.pojo.dtos.ZTreeDTO; import ink.wgink.pojo.dtos.role.RoleDTO; -import ink.wgink.pojo.dtos.role.RoleDataAuthorityTypeDTO; import ink.wgink.pojo.result.ErrorResult; import ink.wgink.pojo.result.SuccessResult; import ink.wgink.pojo.result.SuccessResultList; -import ink.wgink.service.role.pojo.vos.RoleDataAuthorityVO; -import ink.wgink.service.role.pojo.vos.RoleUserAuthorizationVO; import ink.wgink.service.role.pojo.vos.RoleVO; import ink.wgink.service.role.service.IRoleService; import io.swagger.annotations.*; @@ -20,6 +17,7 @@ import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; +import java.util.Arrays; import java.util.List; import java.util.Map; @@ -38,16 +36,14 @@ public class RoleController extends DefaultBaseController { @Autowired private IRoleService roleService; -// @Autowired -// private IMenuService menuService; @ApiOperation(value = "角色新增", notes = "角色新增接口") @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)}) - @PostMapping("saverole") - public SuccessResult saveRole(@RequestBody RoleVO roleVO) { - Map params = getParams(); - checkParams(roleVO, params); - return roleService.saveRole(params); + @PostMapping("save") + @CheckRequestBodyAnnotation + public SuccessResult save(@RequestBody RoleVO roleVO) { + roleService.save(roleVO); + return new SuccessResult(); } @ApiOperation(value = "角色删除", notes = "通过id列表批量删除角色接口") @@ -55,11 +51,10 @@ public class RoleController extends DefaultBaseController { @ApiImplicitParam(name = "ids", value = "角色ID列表,用下划线分隔", paramType = "path") }) @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)}) - @DeleteMapping("removerole/{ids}") - public SuccessResult removeRole(@PathVariable("ids") String ids) throws RemoveException { - Map params = getParams(); - params.put("roleIds", ids); - return roleService.removeRole(params); + @DeleteMapping("remove/{ids}") + public SuccessResult remove(@PathVariable("ids") String ids) throws RemoveException { + roleService.remove(Arrays.asList(ids.split("\\_"))); + return new SuccessResult(); } @ApiOperation(value = "角色修改", notes = "角色修改接口") @@ -67,33 +62,11 @@ public class RoleController extends DefaultBaseController { @ApiImplicitParam(name = "roleId", value = "角色ID", paramType = "path"), }) @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)}) - @PutMapping("updaterole/{roleId}") - public SuccessResult updateRole(@PathVariable("roleId") String roleId, @RequestBody RoleVO roleVO) { - Map params = getParams(); - params.put("roleId", roleId); - checkParams(roleVO, params); - return roleService.updateRole(params); - } - - /** - * 参数校验 - * - * @param roleVO - * @param params - * @throws ParamsException - */ - private void checkParams(RoleVO roleVO, Map params) { - if (StringUtils.isBlank(roleVO.getRoleParentId())) { - throw new ParamsException("上级ID不能为空"); - } - params.put("roleParentId", roleVO.getRoleParentId()); - - if (StringUtils.isBlank(roleVO.getRoleName())) { - throw new ParamsException("角色名称不能为空"); - } - params.put("roleName", roleVO.getRoleName()); - - params.put("roleSummary", roleVO.getRoleSummary()); + @PutMapping("update/{roleId}") + @CheckRequestBodyAnnotation + public SuccessResult update(@PathVariable("roleId") String roleId, @RequestBody RoleVO roleVO) { + roleService.update(roleId, roleVO); + return new SuccessResult(); } @ApiOperation(value = "角色列表", notes = "角色列表接口") @@ -101,11 +74,11 @@ public class RoleController extends DefaultBaseController { @ApiImplicitParam(name = "roleParentId", value = "角色上级ID", paramType = "path") }) @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)}) - @GetMapping("listrolesalljson/{roleParentId}") - public List listRoles(@PathVariable("roleParentId") String roleParentId) { + @GetMapping("listall/{roleParentId}") + public List listall(@PathVariable("roleParentId") String roleParentId) { Map params = getParams(); params.put("roleParentId", roleParentId); - return roleService.listRolesAllJson(params); + return roleService.listAll(params); } @ApiOperation(value = "角色详情", notes = "角色详情接口") @@ -113,11 +86,9 @@ public class RoleController extends DefaultBaseController { @ApiImplicitParam(name = "roleId", value = "角色ID", paramType = "path") }) @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)}) - @GetMapping("getrole/{roleId}") + @GetMapping("get/{roleId}") public RoleDTO getRole(@PathVariable("roleId") String roleId) { - Map params = getParams(); - params.put("roleId", roleId); - return roleService.getRole(params); + return roleService.get(roleId); } @ApiOperation(value = "zTree列表", notes = "zTree列表接口") @@ -125,18 +96,18 @@ public class RoleController extends DefaultBaseController { @ApiImplicitParam(name = "id", value = "上级ID", paramType = "query", dataType = "String") }) @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)}) - @GetMapping("listztreerole") - public List listZTreeRole() throws SearchException { + @GetMapping("listztree") + public List listZTree() throws SearchException { Map params = requestParams(); - String roleParentId = "0"; - if (!StringUtils.isBlank(params.get("id") == null ? null : params.get("id").toString())) { - roleParentId = params.get("id").toString(); + String roleParentId = ISystemConstant.TREE_ROOT_ID; + if (!StringUtils.isBlank(params.get(ISystemConstant.PARAMS_ID) == null ? null : params.get(ISystemConstant.PARAMS_ID).toString())) { + roleParentId = params.get(ISystemConstant.PARAMS_ID).toString(); } params.put("roleParentId", roleParentId); - return roleService.listZTreeRole(params); + return roleService.listZTree(params); } - @ApiOperation(value = "easyui角色列表", notes = "easyui角色列表接口") + @ApiOperation(value = "角色列表", notes = "角色列表接口") @ApiImplicitParams({ @ApiImplicitParam(name = "parentId", value = "上级ID", paramType = "query", dataType = "String"), @ApiImplicitParam(name = "page", value = "当前页码", paramType = "query", dataType = "int", defaultValue = "1"), @@ -146,83 +117,16 @@ public class RoleController extends DefaultBaseController { @ApiImplicitParam(name = "endTime", value = "结束时间", paramType = "query", dataType = "String") }) @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)}) - @GetMapping("listpagerole") - public SuccessResultList> listPageRole(ListPage page) throws SearchException { + @GetMapping("listpage") + public SuccessResultList> listPage(ListPage page) throws SearchException { Map params = requestParams(); String roleParentId = "0"; - if (!StringUtils.isBlank(params.get("parentId") == null ? null : params.get("parentId").toString())) { - roleParentId = params.get("parentId").toString(); + if (!StringUtils.isBlank(params.get(ISystemConstant.PARAMS_PARENT_ID) == null ? null : params.get(ISystemConstant.PARAMS_PARENT_ID).toString())) { + roleParentId = params.get(ISystemConstant.PARAMS_PARENT_ID).toString(); } params.put("roleParentId", roleParentId); page.setParams(params); - return roleService.listPageRole(page); - } - -// @ApiOperation(value = "角色菜单列表", notes = "角色菜单列表接口") -// @ApiImplicitParams({ -// @ApiImplicitParam(name = "menuParentId", value = "上级菜单ID", paramType = "path", dataType = "String"), -// @ApiImplicitParam(name = "roleId", value = "角色ID", paramType = "path", dataType = "String"), -// @ApiImplicitParam(name = "type", value = "类型", paramType = "path", dataType = "String") -// }) -// @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)}) -// @GetMapping("listmenu/{menuParentId}/{roleId}/{type}") -// public List listMenu(@PathVariable("menuParentId") String menuParentId, -// @PathVariable("roleId") String roleId, -// @PathVariable("type") String type) throws SearchException, ParamsException { -// Map params = requestParams(); -// params.put("menuParentId", menuParentId); -// params.put("roleId", roleId); -// if (!IRoleService.AUTH_TYPE_INSERT.equals(type) && -// !IRoleService.AUTH_TYPE_DELETE.equals(type) && -// !IRoleService.AUTH_TYPE_UPDATE.equals(type) && -// !IRoleService.AUTH_TYPE_QUERY.equals(type) && -// !IRoleService.AUTH_TYPE_MENU.equals(type)) { -// throw new ParamsException("授权类型错误"); -// } -// params.put("type", type); -// if (IRoleService.AUTH_TYPE_MENU.equals(type)) { -// params.put("menuType", 1); -// } -// return menuService.listMenuAllJson(params); -// } - - @ApiOperation(value = "执行授权", notes = "执行授权接口") - @ApiImplicitParams({ - @ApiImplicitParam(name = "roleId", value = "角色ID", paramType = "path", dataType = "String"), - @ApiImplicitParam(name = "type", value = "类型", paramType = "path", dataType = "String") - }) - @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)}) - @PutMapping("authorization/{roleId}/{type}") - public SuccessResult authorization(@PathVariable("roleId") String roleId, - @PathVariable("type") String type, - @RequestBody RoleUserAuthorizationVO roleUserAuthorizationVO) { - Map params = getParams(); - params.put("roleId", roleId); - if (!IRoleService.AUTH_TYPE_INSERT.equals(type) && - !IRoleService.AUTH_TYPE_DELETE.equals(type) && - !IRoleService.AUTH_TYPE_UPDATE.equals(type) && - !IRoleService.AUTH_TYPE_QUERY.equals(type) && - !IRoleService.AUTH_TYPE_MENU.equals(type)) { - throw new ParamsException("授权类型错误"); - } - params.put("type", type); - params.put("menuIds", roleUserAuthorizationVO.getMenuIds()); - return roleService.authorization(params); - } - - @ApiOperation(value = "更新角色数据权限", notes = "更新角色数据权限接口") - @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)}) - @PutMapping("updateroledataauthority/{roleId}") - @CheckRequestBodyAnnotation - public SuccessResult updateRoleDataAuthority(@PathVariable("roleId") String roleId, @RequestBody RoleDataAuthorityVO roleDataAuthorityVO) { - return roleService.updateRoleDataAuthority(roleId, roleDataAuthorityVO); - } - - @ApiOperation(value = "获取角色数据权限类型", notes = "获取角色数据权限类型接口") - @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)}) - @GetMapping("getroledataauthoritytype/{roleId}") - public RoleDataAuthorityTypeDTO getRoleDataAuthorityType(@PathVariable("roleId") String roleId) { - return roleService.getRoleDataAuthorityType(roleId); + return roleService.listPage(page); } } diff --git a/service-role/src/main/java/ink/wgink/service/role/controller/route/RoleRouteController.java b/service-role/src/main/java/ink/wgink/service/role/controller/route/RoleRouteController.java new file mode 100644 index 00000000..b5af0353 --- /dev/null +++ b/service-role/src/main/java/ink/wgink/service/role/controller/route/RoleRouteController.java @@ -0,0 +1,45 @@ +package ink.wgink.service.role.controller.route; + +import ink.wgink.interfaces.consts.ISystemConstant; +import io.swagger.annotations.Api; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.servlet.ModelAndView; + +/** + * When you feel like quitting. Think about why you started + * 当你想要放弃的时候,想想当初你为何开始 + * + * @ClassName: RoleRouteController + * @Description: 角色路由 + * @Author: WangGeng + * @Date: 2021/2/17 22:47 + * @Version: 1.0 + **/ +@Api(tags = ISystemConstant.ROUTE_TAGS_PREFIX + "职位路由接口") +@Controller +@RequestMapping(ISystemConstant.ROUTE_PREFIX + "/role") +public class RoleRouteController { + + @GetMapping("save") + public ModelAndView save() { + return new ModelAndView("role/save"); + } + + @GetMapping("update") + public ModelAndView update() { + return new ModelAndView("role/update"); + } + + @GetMapping("list-tree") + public ModelAndView listTree() { + return new ModelAndView("role/list-tree"); + } + + @GetMapping("list") + public ModelAndView list() { + return new ModelAndView("role/list"); + } + +} diff --git a/service-role/src/main/java/ink/wgink/service/role/dao/IRoleDao.java b/service-role/src/main/java/ink/wgink/service/role/dao/IRoleDao.java index 12d78baa..ca5ec72a 100644 --- a/service-role/src/main/java/ink/wgink/service/role/dao/IRoleDao.java +++ b/service-role/src/main/java/ink/wgink/service/role/dao/IRoleDao.java @@ -10,6 +10,7 @@ import ink.wgink.pojo.bos.RoleMenuBO; import ink.wgink.pojo.dtos.ZTreeDTO; import ink.wgink.pojo.dtos.role.RoleDTO; import ink.wgink.pojo.dtos.role.RoleDataAuthorityDTO; +import net.sf.jsqlparser.statement.update.Update; import org.springframework.stereotype.Repository; import java.util.List; @@ -28,13 +29,20 @@ import java.util.Map; @Repository public interface IRoleDao { + /** + * 建表 + * + * @throws UpdateException + */ + void createTable() throws UpdateException; + /** * 新增角色 * * @param params * @throws SaveException */ - void saveRole(Map params) throws SaveException; + void save(Map params) throws SaveException; /** * 删除角色 @@ -42,7 +50,7 @@ public interface IRoleDao { * @param params * @throws RemoveException */ - void removeRole(Map params) throws RemoveException; + void remove(Map params) throws RemoveException; /** * 修改角色 @@ -50,7 +58,7 @@ public interface IRoleDao { * @param params * @throws UpdateException */ - void updateRole(Map params) throws UpdateException; + void update(Map params) throws UpdateException; /** * 角色列表 @@ -59,7 +67,7 @@ public interface IRoleDao { * @return * @throws SearchException */ - List listRole(Map params) throws SearchException; + List list(Map params) throws SearchException; /** * 角色详情 @@ -68,16 +76,7 @@ public interface IRoleDao { * @return * @throws SearchException */ - RoleDTO getRole(Map params) throws SearchException; - - /** - * 角色详情 - * - * @param params - * @return - * @throws SearchException - */ - RolePO getRolePO(Map params) throws SearchException; + RoleDTO get(Map params) throws SearchException; /** * 获取最后一个字角色 @@ -95,7 +94,7 @@ public interface IRoleDao { * @return * @throws SearchException */ - List listZTreeRoles(Map params) throws SearchException; + List listZTree(Map params) throws SearchException; /** * 子列表个数 @@ -106,83 +105,6 @@ public interface IRoleDao { */ Integer countByParentId(String id) throws SearchException; - /** - * 通过用户获取角色 - * - * @param params - * @return - * @throws SearchException - */ - List listRoleBOByUser(Map params) throws SearchException; - - /** - * 通过用户组获取角色 - * - * @param params - * @return - * @throws SearchException - */ - List listRoleBOByGroup(Map params) throws SearchException; - - /** - * 删除角色菜单信息 - * - * @param params - * @throws RemoveException - */ - void removeRoleMenuInfo(Map params) throws RemoveException; - - /** - * 保存角色菜单信息 - * - * @param params - * @throws SaveException - */ - void saveRoleMenuInfo(Map params) throws SaveException; - - /** - * 角色菜单列表 - * - * @param params - * @return - * @throws SearchException - */ - List listRoleMenuInfo(Map params) throws SearchException; - - /** - * 角色菜单列表详情 - * - * @param params - * @return - * @throws SearchException - */ - List listRoleMenuDetail(Map params) throws SearchException; - - /** - * 新增自定义角色数据权限 - * - * @param params - * @throws SaveException - */ - void saveRoleDataAuthority(Map params) throws SaveException; - - /** - * 删除自定义角色数据权限 - * - * @param params - * @throws RemoveException - */ - void deleteRoleDataAuthority(Map params) throws RemoveException; - - /** - * 角色权限列表 - * - * @param params - * @return - * @throws SearchException - */ - List listRoleDataAuthority(Map params) throws SearchException; - /** * 统计角色 * diff --git a/service-role/src/main/java/ink/wgink/service/role/pojo/vos/RoleVO.java b/service-role/src/main/java/ink/wgink/service/role/pojo/vos/RoleVO.java index 05ce2d0f..67ff6060 100644 --- a/service-role/src/main/java/ink/wgink/service/role/pojo/vos/RoleVO.java +++ b/service-role/src/main/java/ink/wgink/service/role/pojo/vos/RoleVO.java @@ -1,5 +1,6 @@ package ink.wgink.service.role.pojo.vos; +import ink.wgink.annotation.CheckEmptyAnnotation; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; @@ -14,8 +15,10 @@ import io.swagger.annotations.ApiModelProperty; public class RoleVO { @ApiModelProperty(name = "roleParentId", value = "上级ID", required = true) + @CheckEmptyAnnotation(name = "上级ID不能为空") private String roleParentId; @ApiModelProperty(name = "roleName", value = "角色名称", required = true, example = "角色名称") + @CheckEmptyAnnotation(name = "角色名称不能为空") private String roleName; @ApiModelProperty(name = "roleSummary", value = "角色说明", example = "这是说明") private String roleSummary; diff --git a/service-role/src/main/java/ink/wgink/service/role/service/IRoleService.java b/service-role/src/main/java/ink/wgink/service/role/service/IRoleService.java index 12a841ad..e3fd6b0a 100644 --- a/service-role/src/main/java/ink/wgink/service/role/service/IRoleService.java +++ b/service-role/src/main/java/ink/wgink/service/role/service/IRoleService.java @@ -5,6 +5,7 @@ import ink.wgink.exceptions.SaveException; import ink.wgink.exceptions.SearchException; import ink.wgink.exceptions.UpdateException; import ink.wgink.interfaces.role.IRoleBaseService; +import ink.wgink.interfaces.role.IRoleCheckService; import ink.wgink.pojo.ListPage; import ink.wgink.pojo.bos.DepartmentBO; import ink.wgink.pojo.bos.GroupBO; @@ -17,6 +18,7 @@ import ink.wgink.pojo.dtos.role.RoleDataAuthorityTypeDTO; import ink.wgink.pojo.result.SuccessResult; import ink.wgink.pojo.result.SuccessResultList; import ink.wgink.service.role.pojo.vos.RoleDataAuthorityVO; +import ink.wgink.service.role.pojo.vos.RoleVO; import java.util.List; import java.util.Map; @@ -31,7 +33,7 @@ import java.util.Map; * @Date: 2021/1/31 18:50 * @Version: 1.0 **/ -public interface IRoleService extends IRoleBaseService { +public interface IRoleService extends IRoleBaseService, IRoleCheckService { /** * 授权新增 @@ -81,39 +83,27 @@ public interface IRoleService extends IRoleBaseService { /** * 新增角色 * - * @param params + * @param roleVO * @return - * @throws SaveException - * @throws SearchException */ - SuccessResult saveRole(Map params); + void save(RoleVO roleVO); /** * 删除角色 * - * @param params + * @param ids * @return - * @throws RemoveException */ - SuccessResult removeRole(Map params); + void remove(List ids); /** * 修改角色 * - * @param params + * @param roleId + * @param roleVO * @return - * @throws UpdateException */ - SuccessResult updateRole(Map params); - - /** - * 全部角色JSON列表 - * - * @param params - * @return - * @throws SearchException - */ - List listRolesAllJson(Map params); + void update(String roleId, RoleVO roleVO); /** * 角色详情 @@ -121,7 +111,23 @@ public interface IRoleService extends IRoleBaseService { * @param params * @return */ - RoleDTO getRole(Map params); + RoleDTO get(Map params); + + /** + * 角色详情 + * + * @param roleId 角色ID + * @return + */ + RoleDTO get(String roleId); + + /** + * 角色列表 + * + * @param params + * @return + */ + List list(Map params); /** * 角色列表,递归获取全部内容 @@ -130,7 +136,7 @@ public interface IRoleService extends IRoleBaseService { * @return * @throws SearchException */ - List listRolesAll(Map params); + List listAll(Map params); /** * 角色zTree列表 @@ -139,7 +145,7 @@ public interface IRoleService extends IRoleBaseService { * @return * @throws SearchException */ - List listZTreeRole(Map params); + List listZTree(Map params); /** * 角色EasyUI列表 @@ -147,145 +153,7 @@ public interface IRoleService extends IRoleBaseService { * @param page * @return */ - SuccessResultList> listPageRole(ListPage page); - - /** - * 执行授权 - * - * @param params - * @return - * @throws UpdateException - */ - SuccessResult authorization(Map params); - - /** - * 通过用户获取角色 - * - * @param params - * @return - * @throws SearchException - */ - List listRoleBOByUser(Map params); - - /** - * 通过用户组获取角色 - * - * @param params - * @return - * @throws SearchException - */ - List listRoleBOByGroup(Map params); - - /** - * 角色菜单列表 - * - * @param params - * @return - * @throws SearchException - */ - List listRoleMenuDetail(Map params); - - /** - * 通过roleId获取角色 - * - * @param roleId - * @return - * @throws SearchException - */ - public RoleBO getRoleBOByRoleId(String roleId); - - /** - * 获取角色权限集合 - * - * @param roleIds - * @return - * @throws SearchException - */ - List listRoleBO(String roleIds); - - /** - * 更新角色数据权限 - * - * @param roleId - * @param roleDataAuthorityVO - * @return - * @throws SaveException - * @throws RemoveException - */ - SuccessResult updateRoleDataAuthority(String roleId, RoleDataAuthorityVO roleDataAuthorityVO); - - /** - * 获取角色数据权限类型 - * - * @param roleId - * @return - * @throws SearchException - */ - RoleDataAuthorityTypeDTO getRoleDataAuthorityType(String roleId); - - /** - * 获取角色数据权限列表(通过ID列表) - * - * @param roleIds - * @return - * @throws SearchException - */ - List listRoleDataAuthorityByRoleIdList(List roleIds); - - /** - * 通过角色列表获取数据权限 - * - * @param roleBOs - * @return - */ - List listDataAuthorityUserIdByRole(List roleBOs); - - /** - * 通过部门获取用户数据数据权限 - * - * @param departmentBOs - * @return - */ - List listDataAuthorityUserIdByDepartment(List departmentBOs); - - /** - * 获取角色数据权限 - * - * @param roleBOs - * @return - */ - String getRoleDataAuthority(List roleBOs); - - /** - * 设置角色菜单 - * - * @param roleBO - * @throws SearchException - */ - void setRoleMenu(RoleBO roleBO); - - /** - * 批量设置角色菜单 - * - * @param roleBOs - * @throws SearchException - */ - void setRoleMenus(List roleBOs); - - /** - * 设置组角色列表 - * - * @param groupRoles - * @param roleBOs - */ - void setGroupRoles(List groupRoles, List roleBOs); - - /** - * 去除重复值 - * - * @param roleBOs - */ - void removalDuplicateRole(List roleBOs); + SuccessResultList> listPage(ListPage page); /** * 统计角色 diff --git a/service-role/src/main/java/ink/wgink/service/role/service/impl/RoleServiceImpl.java b/service-role/src/main/java/ink/wgink/service/role/service/impl/RoleServiceImpl.java index b734e333..3ceddabb 100644 --- a/service-role/src/main/java/ink/wgink/service/role/service/impl/RoleServiceImpl.java +++ b/service-role/src/main/java/ink/wgink/service/role/service/impl/RoleServiceImpl.java @@ -3,30 +3,20 @@ package ink.wgink.service.role.service.impl; import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageInfo; import ink.wgink.common.base.DefaultBaseService; -import ink.wgink.common.enums.RoleDataAuthorityEnum; import ink.wgink.exceptions.RemoveException; import ink.wgink.exceptions.SaveException; import ink.wgink.exceptions.SearchException; import ink.wgink.exceptions.UpdateException; +import ink.wgink.interfaces.consts.ISystemConstant; import ink.wgink.pojo.ListPage; -import ink.wgink.pojo.bos.*; import ink.wgink.pojo.dtos.ZTreeDTO; import ink.wgink.pojo.dtos.role.RoleDTO; -import ink.wgink.pojo.dtos.role.RoleDataAuthorityDTO; -import ink.wgink.pojo.dtos.role.RoleDataAuthorityTypeDTO; -import ink.wgink.pojo.dtos.role.RolePermissionDTO; -import ink.wgink.pojo.result.SuccessResult; import ink.wgink.pojo.result.SuccessResultList; -import ink.wgink.service.department.service.IDepartmentUserService; -import ink.wgink.module.permission.enums.PermissionTypeEnum; -import ink.wgink.module.permission.service.IPermissionService; import ink.wgink.service.role.dao.IRoleDao; -import ink.wgink.service.role.pojo.vos.RoleDataAuthorityVO; -import ink.wgink.service.role.pojo.vos.RoleUserAuthorityVO; -import ink.wgink.service.role.service.IRolePermissionService; +import ink.wgink.service.role.pojo.vos.RoleVO; import ink.wgink.service.role.service.IRoleService; -import ink.wgink.service.user.service.IUserService; import ink.wgink.util.UUIDUtil; +import ink.wgink.util.map.HashMapUtil; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -48,67 +38,70 @@ public class RoleServiceImpl extends DefaultBaseService implements IRoleService @Autowired private IRoleDao roleDao; - @Autowired - private IUserService userService; - @Autowired - private IDepartmentUserService departmentUserService; - @Autowired - private IPermissionService permissionService; - @Autowired - private IRolePermissionService rolePermissionService; @Override - public SuccessResult saveRole(Map params) throws SaveException, SearchException { + public void save(RoleVO roleVO) throws SaveException, SearchException { + Map params = HashMapUtil.beanToMap(roleVO); String parentCode = null; - String roleParentId = params.get("roleParentId").toString(); - if (!"0".equals(roleParentId)) { + String roleParentId = roleVO.getRoleParentId(); + if (!StringUtils.equals(ISystemConstant.TREE_ROOT_ID, roleVO.getRoleParentId())) { params.put("roleId", roleParentId); - RoleDTO roleDTO = roleDao.getRole(params); + RoleDTO roleDTO = roleDao.get(params); parentCode = roleDTO.getRoleCode(); } String roleCode = getCode(parentCode, roleParentId); params.put("roleCode", roleCode); params.put("roleId", UUIDUtil.getUUID()); setSaveInfo(params); - roleDao.saveRole(params); - return new SuccessResult(); + roleDao.save(params); } @Override - public SuccessResult removeRole(Map params) throws RemoveException { - params.put("roleIds", Arrays.asList(params.get("roleIds").toString().split("_"))); + public void remove(List ids) throws RemoveException { + Map params = getHashMap(10); + params.put("roleIds", ids); setUpdateInfo(params); - roleDao.removeRole(params); - return new SuccessResult(); + roleDao.remove(params); } @Override - public SuccessResult updateRole(Map params) throws UpdateException { + public void update(String roleId, RoleVO roleVO) throws UpdateException { + Map params = HashMapUtil.beanToMap(roleVO); + params.put("roleId", roleId); setUpdateInfo(params); - roleDao.updateRole(params); - return new SuccessResult(); + roleDao.update(params); } @Override - public List listRolesAllJson(Map params) throws SearchException { - return listRolesAll(params); + public RoleDTO get(Map params) throws SearchException { + return roleDao.get(params); } @Override - public RoleDTO getRole(Map params) throws SearchException { - return roleDao.getRole(params); + public RoleDTO get(String roleId) { + Map params = getHashMap(2); + params.put("roleId", roleId); + return get(params); } @Override - public List listRolesAll(Map params) throws SearchException { - List roleDTOs = roleDao.listRole(params); + public List list(Map params) { + List srcRoleDTO = roleDao.list(params); + List destRoleDTO = new ArrayList<>(Arrays.asList(new RoleDTO[srcRoleDTO.size()])); + Collections.copy(destRoleDTO, srcRoleDTO); + return destRoleDTO; + } + + @Override + public List listAll(Map params) throws SearchException { + List roleDTOs = roleDao.list(params); listSubRoles(roleDTOs, params); return roleDTOs; } @Override - public List listZTreeRole(Map params) throws SearchException { - List zTreeDTOs = roleDao.listZTreeRoles(params); + public List listZTree(Map params) throws SearchException { + List zTreeDTOs = roleDao.listZTree(params); for (ZTreeDTO zTreeDTO : zTreeDTOs) { Integer subCount = roleDao.countByParentId(zTreeDTO.getId()); setZTreeInfo(zTreeDTO, subCount); @@ -117,327 +110,13 @@ public class RoleServiceImpl extends DefaultBaseService implements IRoleService } @Override - public SuccessResultList> listPageRole(ListPage page) throws SearchException { + public SuccessResultList> listPage(ListPage page) throws SearchException { PageHelper.startPage(page.getPage(), page.getRows()); - List roleDTOs = roleDao.listRole(page.getParams()); + List roleDTOs = list(page.getParams()); PageInfo pageInfo = new PageInfo<>(roleDTOs); return new SuccessResultList<>(roleDTOs, pageInfo.getPageNum(), pageInfo.getTotal()); } - @Override - public SuccessResult authorization(Map params) throws UpdateException, RemoveException, SaveException { - List menuIds = new ArrayList<>(); - if (!StringUtils.isBlank(params.get("menuIds") == null ? null : params.get("menuIds").toString())) { - menuIds.addAll(Arrays.asList(params.get("menuIds").toString().trim().split("_"))); - } - String type = params.get("type").toString(); - if (IRoleService.AUTH_TYPE_INSERT.equals(type)) { - params.put(IRoleService.ROLE_TYPE, IRoleService.ROLE_INSERT); - } else if (IRoleService.AUTH_TYPE_DELETE.equals(type)) { - params.put(IRoleService.ROLE_TYPE, IRoleService.ROLE_DELETE); - } else if (IRoleService.AUTH_TYPE_UPDATE.equals(type)) { - params.put(IRoleService.ROLE_TYPE, IRoleService.ROLE_UPDATE); - } else if (IRoleService.AUTH_TYPE_QUERY.equals(type)) { - params.put(IRoleService.ROLE_TYPE, IRoleService.ROLE_QUERY); - } else { - params.put(IRoleService.ROLE_TYPE, IRoleService.ROLE_MENU); - } - LOG.debug("删除原有角色和菜单信息"); - roleDao.removeRoleMenuInfo(params); - LOG.debug("新增角色菜单信息"); - for (String menuId : menuIds) { - params.put("menuId", menuId); - roleDao.saveRoleMenuInfo(params); - } - return new SuccessResult(); - } - - @Override - public List listRoleBOByUser(Map params) throws SearchException { - return roleDao.listRoleBOByUser(params); - } - - @Override - public List listRoleBOByGroup(Map params) throws SearchException { - return roleDao.listRoleBOByGroup(params); - } - - @Override - public List listRoleMenuDetail(Map params) throws SearchException { - return roleDao.listRoleMenuDetail(params); - } - - @Override - public RoleBO getRoleBOByRoleId(String roleId) throws SearchException { - Map params = new HashMap<>(0); - params.put("roleId", roleId); - List roleMenuBOs = listRoleMenuDetail(params); - - List apiSaveMenu = new ArrayList<>(0); - List apiDeleteMenu = new ArrayList<>(0); - List apiUpdateMenu = new ArrayList<>(0); - List apiQueryMenu = new ArrayList<>(0); - - List resourceSaveMenu = new ArrayList<>(0); - List resourceDeleteMenu = new ArrayList<>(0); - List resourceUpdateMenu = new ArrayList<>(0); - List resourceQueryMenu = new ArrayList<>(0); - - List routeSaveMenu = new ArrayList<>(0); - List routeUpdateMenu = new ArrayList<>(0); - List routeQueryMenu = new ArrayList<>(0); - - List permissionInsert = new ArrayList<>(0); - List permissionDelete = new ArrayList<>(0); - List permissionUpdate = new ArrayList<>(0); - List permissionQuery = new ArrayList<>(0); - - LOG.debug("角色菜单权限"); - for (RoleMenuBO roleMenuBO : roleMenuBOs) { - roleMenuBO.setApiPrefix(roleMenuBO.getApiPrefix()); - roleMenuBO.setResourcePrefix(roleMenuBO.getResourcePrefix()); - roleMenuBO.setRoutePrefix(roleMenuBO.getRoutePrefix()); - if (IRoleService.ROLE_INSERT.equals(roleMenuBO.getRoleType())) { - apiSaveMenu.add(roleMenuBO); - resourceSaveMenu.add(roleMenuBO); - routeSaveMenu.add(roleMenuBO); - } else if (IRoleService.ROLE_DELETE.equals(roleMenuBO.getRoleType())) { - apiDeleteMenu.add(roleMenuBO); - resourceDeleteMenu.add(roleMenuBO); - } else if (IRoleService.ROLE_UPDATE.equals(roleMenuBO.getRoleType())) { - apiUpdateMenu.add(roleMenuBO); - resourceUpdateMenu.add(roleMenuBO); - routeUpdateMenu.add(roleMenuBO); - } else if (IRoleService.ROLE_QUERY.equals(roleMenuBO.getRoleType())) { - apiQueryMenu.add(roleMenuBO); - resourceQueryMenu.add(roleMenuBO); - routeQueryMenu.add(roleMenuBO); - } - } - LOG.debug("角色接口权限"); - setApiPermission(roleId, permissionInsert, permissionDelete, permissionUpdate, permissionQuery); - RoleBO roleBO = new RoleBO(); - roleBO.setRoleId(roleId); - roleBO.setApiSaveMenu(apiSaveMenu); - roleBO.setApiDeleteMenu(apiDeleteMenu); - roleBO.setApiUpdateMenu(apiUpdateMenu); - roleBO.setApiQueryMenu(apiQueryMenu); - roleBO.setResourceSaveMenu(resourceSaveMenu); - roleBO.setResourceDeleteMenu(resourceDeleteMenu); - roleBO.setResourceUpdateMenu(resourceUpdateMenu); - roleBO.setResourceQueryMenu(resourceQueryMenu); - roleBO.setRouteSaveMenu(routeSaveMenu); - roleBO.setRouteUpdateMenu(routeUpdateMenu); - roleBO.setRouteQueryMenu(routeQueryMenu); - roleBO.setPermissionInsert(permissionInsert); - roleBO.setPermissionDelete(permissionDelete); - roleBO.setPermissionUpdate(permissionUpdate); - roleBO.setPermissionQuery(permissionQuery); - return roleBO; - } - - /** - * 设置API权限 - * - * @param roleId - * @param permissionInsert - * @param permissionDelete - * @param permissionUpdate - * @param permissionQuery - */ - private void setApiPermission(String roleId, - List permissionInsert, - List permissionDelete, - List permissionUpdate, - List permissionQuery) { - List permissionRoleDTOs = rolePermissionService.listByRoleId(roleId); - for (RolePermissionDTO permissionRoleDTO : permissionRoleDTOs) { - if (StringUtils.equals(PermissionTypeEnum.PERMISSION_INSERT.getValue(), permissionRoleDTO.getPermissionType())) { - PermissionBO permissionBO = new PermissionBO(); - permissionBO.setPermissionType(permissionRoleDTO.getPermissionType()); - permissionBO.setPermissionUrl(permissionRoleDTO.getPermissionUrl()); - permissionInsert.add(permissionBO); - } else if (StringUtils.equals(PermissionTypeEnum.PERMISSION_DELETE.getValue(), permissionRoleDTO.getPermissionType())) { - PermissionBO permissionBO = new PermissionBO(); - permissionBO.setPermissionType(permissionRoleDTO.getPermissionType()); - permissionBO.setPermissionUrl(permissionRoleDTO.getPermissionUrl()); - permissionDelete.add(permissionBO); - } else if (StringUtils.equals(PermissionTypeEnum.PERMISSION_UPDATE.getValue(), permissionRoleDTO.getPermissionType())) { - PermissionBO permissionBO = new PermissionBO(); - permissionBO.setPermissionType(permissionRoleDTO.getPermissionType()); - permissionBO.setPermissionUrl(permissionRoleDTO.getPermissionUrl()); - permissionUpdate.add(permissionBO); - } else if (StringUtils.equals(PermissionTypeEnum.PERMISSION_QUERY.getValue(), permissionRoleDTO.getPermissionType())) { - PermissionBO permissionBO = new PermissionBO(); - permissionBO.setPermissionType(permissionRoleDTO.getPermissionType()); - permissionBO.setPermissionUrl(permissionRoleDTO.getPermissionUrl()); - permissionQuery.add(permissionBO); - } - } - } - - @Override - public List listRoleBO(String roleIds) throws SearchException { - String[] roleIdArray = roleIds.split("_"); - List roleBOs = new ArrayList<>(); - for (String roleId : roleIdArray) { - RoleBO roleBO = getRoleBOByRoleId(roleId); - roleBOs.add(roleBO); - } - return roleBOs; - } - - @Override - public SuccessResult updateRoleDataAuthority(String roleId, RoleDataAuthorityVO roleDataAuthorityVO) throws SaveException, RemoveException { - LOG.debug("更新角色数据权限"); - Map params = getHashMap(2); - params.put("roleId", roleId); - params.put("roleDataAuthority", roleDataAuthorityVO.getDataAuthorityType()); - roleDao.updateRole(params); - if (StringUtils.equals(roleDataAuthorityVO.getDataAuthorityType(), RoleDataAuthorityEnum.CUSTOM.getDataAuthorityType())) { - params.remove("roleDataAuthority"); - LOG.debug("删除原有的自定义权限列表"); - roleDao.deleteRoleDataAuthority(params); - LOG.debug("更新自定义权限列表"); - for (RoleUserAuthorityVO roleUserAuthorityVO : roleDataAuthorityVO.getRoleUserAuthorityList()) { - params.put("departmentId", roleUserAuthorityVO.getDepartmentId()); - params.put("userId", roleUserAuthorityVO.getUserId()); - roleDao.saveRoleDataAuthority(params); - } - } - return new SuccessResult(); - } - - @Override - public void setRoleMenu(RoleBO roleBO) throws SearchException { - RoleBO role = getRoleBOByRoleId(roleBO.getRoleId()); - roleBO.setApiSaveMenu(role.getApiSaveMenu()); - roleBO.setApiDeleteMenu(role.getApiDeleteMenu()); - roleBO.setApiUpdateMenu(role.getApiUpdateMenu()); - roleBO.setApiQueryMenu(role.getApiQueryMenu()); - roleBO.setResourceSaveMenu(role.getResourceSaveMenu()); - roleBO.setResourceDeleteMenu(role.getResourceDeleteMenu()); - roleBO.setResourceUpdateMenu(role.getResourceUpdateMenu()); - roleBO.setResourceQueryMenu(role.getResourceQueryMenu()); - roleBO.setRouteSaveMenu(role.getRouteSaveMenu()); - roleBO.setRouteUpdateMenu(role.getRouteUpdateMenu()); - roleBO.setRouteQueryMenu(role.getRouteQueryMenu()); - roleBO.setPermissionInsert(role.getPermissionInsert()); - roleBO.setPermissionDelete(role.getPermissionDelete()); - roleBO.setPermissionUpdate(role.getPermissionUpdate()); - roleBO.setPermissionQuery(role.getPermissionQuery()); - } - - @Override - public void setRoleMenus(List roleBOs) throws SearchException { - for (RoleBO roleBO : roleBOs) { - setRoleMenu(roleBO); - } - } - - @Override - public RoleDataAuthorityTypeDTO getRoleDataAuthorityType(String roleId) throws SearchException { - Map params = getHashMap(1); - params.put("roleId", roleId); - RoleDTO roleDTO = roleDao.getRole(params); - StringBuilder roleDataAuthority = new StringBuilder(); - if (StringUtils.equals(roleDTO.getRoleDataAuthority(), RoleDataAuthorityEnum.CUSTOM.getDataAuthorityType())) { - List roleDataAuthorityDTOs = roleDao.listRoleDataAuthority(params); - for (RoleDataAuthorityDTO roleDataAuthorityDTO : roleDataAuthorityDTOs) { - if (roleDataAuthority.length() > 0) { - roleDataAuthority.append("_"); - } - roleDataAuthority.append(roleDataAuthorityDTO.getUserId()); - } - } - RoleDataAuthorityTypeDTO roleDataAuthorityTypeDTO = new RoleDataAuthorityTypeDTO(); - roleDataAuthorityTypeDTO.setRoleDataAuthorityType(roleDTO.getRoleDataAuthority()); - roleDataAuthorityTypeDTO.setRoleDataAuthority(roleDataAuthority.toString()); - return roleDataAuthorityTypeDTO; - } - - @Override - public List listRoleDataAuthorityByRoleIdList(List roleIds) throws SearchException { - Map params = getHashMap(1); - params.put("roleIds", roleIds); - return roleDao.listRoleDataAuthority(params); - } - - @Override - public List listDataAuthorityUserIdByRole(List roleBOs) { - List userIds = new ArrayList<>(); - List roleIds = new ArrayList<>(); - for (RoleBO roleBO : roleBOs) { - roleIds.add(roleBO.getRoleId()); - } - List roleDataAuthorityDTOs = listRoleDataAuthorityByRoleIdList(roleIds); - for (RoleDataAuthorityDTO roleDataAuthorityDTO : roleDataAuthorityDTOs) { - userIds.add(roleDataAuthorityDTO.getUserId()); - } - return userIds; - } - - @Override - public List listDataAuthorityUserIdByDepartment(List departmentBOs) { - List userIds = new ArrayList<>(); - if (departmentBOs.isEmpty()) { - return userIds; - } - List departmentIds = new ArrayList<>(); - for (DepartmentBO departmentBO : departmentBOs) { - departmentIds.add(departmentBO.getDepartmentId()); - } - return departmentUserService.listUserId(departmentIds); - } - - @Override - public String getRoleDataAuthority(List roleBOs) { - String roleDataAuthority = RoleDataAuthorityEnum.SELF.getDataAuthorityType(); - for (RoleBO roleBO : roleBOs) { - if (StringUtils.equals(RoleDataAuthorityEnum.ALL.getDataAuthorityType(), roleBO.getRoleDataAuthority())) { - roleDataAuthority = RoleDataAuthorityEnum.ALL.getDataAuthorityType(); - break; - } - if (StringUtils.equals(RoleDataAuthorityEnum.DEPARTMENT.getDataAuthorityType(), roleBO.getRoleDataAuthority())) { - roleDataAuthority = RoleDataAuthorityEnum.DEPARTMENT.getDataAuthorityType(); - break; - } - if (StringUtils.equals(RoleDataAuthorityEnum.CUSTOM.getDataAuthorityType(), roleBO.getRoleDataAuthority())) { - roleDataAuthority = RoleDataAuthorityEnum.CUSTOM.getDataAuthorityType(); - break; - } - } - return roleDataAuthority; - } - - @Override - public void setGroupRoles(List groupRoles, List roleBOs) { - Map params = getHashMap(1); - groupRoles.forEach(groupBO -> { - params.put("groupId", groupBO.getGroupId()); - roleBOs.addAll(listRoleBOByGroup(params)); - }); - } - - @Override - public void removalDuplicateRole(List roleBOs) { - for (int i = 0; i < roleBOs.size(); i++) { - RoleBO roleBO = roleBOs.get(i); - boolean isExist = false; - for (int j = i + 1; j < roleBOs.size(); j++) { - if (StringUtils.equals(roleBO.getRoleId(), roleBOs.get(j).getRoleId())) { - isExist = true; - break; - } - } - if (isExist) { - roleBOs.remove(i); - i--; - break; - } - } - } - @Override public Integer countRole(Map params) throws SearchException { Integer roleCount = roleDao.countRole(params); @@ -454,7 +133,7 @@ public class RoleServiceImpl extends DefaultBaseService implements IRoleService private void listSubRoles(List roleDTOs, Map params) throws SearchException { for (RoleDTO roleDTO : roleDTOs) { params.put("roleParentId", roleDTO.getRoleId()); - List subRoleDTOs = roleDao.listRole(params); + List subRoleDTOs = roleDao.list(params); roleDTO.setSubRoles(subRoleDTOs); listSubRoles(subRoleDTOs, params); } diff --git a/service-role/src/main/java/ink/wgink/service/role/startup/ServiceRoleStartUp.java b/service-role/src/main/java/ink/wgink/service/role/startup/ServiceRoleStartUp.java new file mode 100644 index 00000000..d04f8593 --- /dev/null +++ b/service-role/src/main/java/ink/wgink/service/role/startup/ServiceRoleStartUp.java @@ -0,0 +1,46 @@ +package ink.wgink.service.role.startup; + +import ink.wgink.pojo.dtos.user.UserDTO; +import ink.wgink.service.role.dao.IRoleDao; +import ink.wgink.util.date.DateUtil; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.ApplicationArguments; +import org.springframework.boot.ApplicationRunner; +import org.springframework.stereotype.Component; + +import java.util.HashMap; +import java.util.Map; + +/** + * When you feel like quitting. Think about why you started + * 当你想要放弃的时候,想想当初你为何开始 + * + * @ClassName: ServiceRoleStartUp + * @Description: 角色业务 + * @Author: WangGeng + * @Date: 2021/2/17 22:58 + * @Version: 1.0 + **/ +@Component +public class ServiceRoleStartUp implements ApplicationRunner { + + private static final Logger LOG = LoggerFactory.getLogger(ServiceRoleStartUp.class); + @Autowired + private IRoleDao roleDao; + + @Override + public void run(ApplicationArguments args) throws Exception { + initTable(); + } + + /** + * 建表 + */ + private void initTable() { + LOG.debug("创建 sys_role 表"); + roleDao.createTable(); + } + +} diff --git a/service-role/src/main/resources/mybatis/mapper/role-mapper.xml b/service-role/src/main/resources/mybatis/mapper/role-mapper.xml new file mode 100644 index 00000000..1ea53a97 --- /dev/null +++ b/service-role/src/main/resources/mybatis/mapper/role-mapper.xml @@ -0,0 +1,217 @@ + + + + + + + + + + + + + + + + + + + + + + + + + CREATE TABLE IF NOT EXISTS `sys_role` ( + `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT, + `role_id` char(36) NOT NULL, + `role_parent_id` char(36) DEFAULT '0', + `role_name` varchar(255) DEFAULT NULL COMMENT '角色名称', + `role_summary` varchar(255) DEFAULT NULL COMMENT '角色说明', + `role_code` varchar(255) DEFAULT NULL COMMENT '角色编码', + `role_data_authority` varchar(20) DEFAULT 'self' COMMENT '数据权限', + `creator` char(36) DEFAULT NULL, + `gmt_create` datetime DEFAULT NULL, + `modifier` char(36) DEFAULT NULL, + `gmt_modified` datetime DEFAULT NULL, + `is_delete` int(2) DEFAULT '0', + PRIMARY KEY (`id`,`role_id`), + UNIQUE KEY `role_id` (`role_id`) + ) ENGINE=InnoDB AUTO_INCREMENT=30 DEFAULT CHARSET=utf8; + + + + + + + INSERT INTO sys_role( + role_id, + role_parent_id, + role_name, + role_summary, + role_code, + creator, + gmt_create, + modifier, + gmt_modified, + is_delete + ) VALUES( + #{roleId}, + #{roleParentId}, + #{roleName}, + #{roleSummary}, + #{roleCode}, + #{creator}, + #{gmtCreate}, + #{modifier}, + #{gmtModified}, + #{isDelete} + ) + + + + + UPDATE + sys_role + SET + is_delete = 1, + modifier = #{modifier}, + gmt_modified = #{gmtModified} + WHERE + role_id IN + + #{roleIds[${index}]} + + + + + + UPDATE + sys_role + SET + + role_name = #{roleName}, + + + role_code = #{roleCode}, + + + role_summary = #{roleSummary}, + + + role_data_authority = #{roleDataAuthority}, + + modifier = #{modifier}, + gmt_modified = #{gmtModified} + WHERE + role_id = #{roleId} + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/service-role/src/main/resources/templates/role/list-tree.html b/service-role/src/main/resources/templates/role/list-tree.html index 42fbdc0a..0040abc2 100644 --- a/service-role/src/main/resources/templates/role/list-tree.html +++ b/service-role/src/main/resources/templates/role/list-tree.html @@ -1,7 +1,7 @@ - + - + @@ -49,7 +49,7 @@ // 初始化IFrame function initIFrame() { - $('#listContent').attr('src', top.restAjax.path('route/system/role/list.html?parentId={parentId}', [parentId])); + $('#listContent').attr('src', top.restAjax.path('route/role/list?parentId={parentId}', [parentId])); } // 初始化大小 function initSize() { diff --git a/service-role/src/main/resources/templates/role/list.html b/service-role/src/main/resources/templates/role/list.html index df0e7121..ca1ec9a4 100644 --- a/service-role/src/main/resources/templates/role/list.html +++ b/service-role/src/main/resources/templates/role/list.html @@ -1,7 +1,7 @@ - + - + @@ -64,13 +64,14 @@ var admin = layui.admin; var laydate = layui.laydate; var parentId = top.restAjax.params(window.location.href).parentId; + var tableUrl = 'api/role/listpage?parentId={parentId}'; // 初始化表格 function initTable() { table.render({ elem: '#dataTable', id: 'dataTable', - url: top.restAjax.path('api/role/listpagerole?parentId={parentId}', [parentId]), + url: top.restAjax.path(tableUrl, [parentId]), width: admin.screen() > 1 ? '100%' : '', height: $win.height() - 60, limit: 20, @@ -80,42 +81,44 @@ pageName: 'page', limitName: 'rows' }, - cols: [[ - {type:'checkbox', fixed: 'left'}, - {field:'rowNum', width:80, title: '序号', fixed: 'left', align:'center', templet: '#rowNum'}, - {field:'users', width:100, title: '人员列表', align:'center', - templet: function(item) { - return ''; - } - }, - {field:'groups', width:100, title: '组列表', align:'center', - templet: function(item) { - return ''; - } - }, - {field:'roleName', width:170, title: '角色名称', align:'center',}, - {field:'roleSummary', width:170, title: '角色说明', align:'center',}, - {field:'roleCode', width:170, title: '角色编码', align:'center',}, - {field:'jurisdiction', width:200, title: '快捷权限', align:'center', - templet: function(item) { - return '
' + - '' + - '' + - '' + - ''+ - '
' - } - }, - {field:'jurisdiction', width:200, title: '其他权限', align:'center', - templet: function(item) { - return '
' + - '' + - ''+ - ''+ - '
' - } - }, - ]], + cols: [ + [ + {type:'checkbox', fixed: 'left'}, + {field:'rowNum', width:80, title: '序号', fixed: 'left', align:'center', templet: '#rowNum'}, + {field:'users', width:100, title: '人员列表', align:'center', + templet: function(item) { + return ''; + } + }, + {field:'groups', width:100, title: '组列表', align:'center', + templet: function(item) { + return ''; + } + }, + {field:'roleName', width:170, title: '角色名称', align:'center',}, + {field:'roleSummary', width:170, title: '角色说明', align:'center',}, + {field:'roleCode', width:170, title: '角色编码', align:'center',}, + {field:'jurisdiction', width:200, title: '快捷权限', align:'center', + templet: function(item) { + return '
' + + '' + + '' + + '' + + ''+ + '
' + } + }, + {field:'jurisdiction', width:200, title: '其他权限', align:'center', + templet: function(item) { + return '
' + + '' + + ''+ + ''+ + '
' + } + }, + ] + ], page: true, parseData: function(data) { return { @@ -130,7 +133,7 @@ // 重载表格 function reloadTable(currentPage) { table.reload('dataTable', { - url: top.restAjax.path('api/role/listpagerole?parentId={parentId}', [parentId]), + url: top.restAjax.path(tableUrl, [parentId]), where: { keywords: $('#keywords').val(), }, @@ -165,7 +168,7 @@ yes: function (index) { top.dialog.close(index); var layIndex; - top.restAjax.delete(top.restAjax.path('api/role/removerole/{ids}', [ids]), {}, null, function (code, data) { + top.restAjax.delete(top.restAjax.path('api/role/remove/{ids}', [ids]), {}, null, function (code, data) { top.dialog.msg(top.dataMessage.deleteSuccess, {time: 1000}, function () { refreshTable(); }); @@ -207,7 +210,7 @@ area: ['100%', '100%'], shadeClose: true, anim: 2, - content: top.restAjax.path('route/system/role/save.html?roleParentId={parentId}', [parentId]), + content: top.restAjax.path('route/role/save?roleParentId={parentId}', [parentId]), end: function() { refreshTable(); } @@ -225,7 +228,7 @@ area: ['100%', '100%'], shadeClose: true, anim: 2, - content: top.restAjax.path('route/system/role/update.html?roleId={roleId}', [checkDatas[0].roleId]), + content: top.restAjax.path('route/role/update?roleId={roleId}', [checkDatas[0].roleId]), end: function() { refreshTable(); } diff --git a/service-role/src/main/resources/templates/role/save.html b/service-role/src/main/resources/templates/role/save.html index 2651ebde..c8fb13af 100644 --- a/service-role/src/main/resources/templates/role/save.html +++ b/service-role/src/main/resources/templates/role/save.html @@ -1,7 +1,7 @@ - + - + diff --git a/service-role/src/main/resources/templates/role/update.html b/service-role/src/main/resources/templates/role/update.html index c1d0c6ea..0471dc76 100644 --- a/service-role/src/main/resources/templates/role/update.html +++ b/service-role/src/main/resources/templates/role/update.html @@ -1,7 +1,7 @@ - + - +