完善基础代码(角色)
This commit is contained in:
parent
fe4ea75b5a
commit
cabbd33c2c
@ -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 {
|
||||
}
|
@ -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<String, Object> 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<String, Object> params, String menuParentId) {
|
||||
private void initSavePermissionManage(Map<String, Object> 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<String, Object> params, String menuParentId) {
|
||||
private void initDeletePermissionManage(Map<String, Object> 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<String, Object> params, String menuParentId) {
|
||||
private void initUpdatePermissionManage(Map<String, Object> 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<String, Object> params, String menuParentId) {
|
||||
private void initQueryPermissionManage(Map<String, Object> 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<String, Object> 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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<String, Object> 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<String, Object> 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<String, Object> 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<String, Object> 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<RoleDTO> listRoles(@PathVariable("roleParentId") String roleParentId) {
|
||||
@GetMapping("listall/{roleParentId}")
|
||||
public List<RoleDTO> listall(@PathVariable("roleParentId") String roleParentId) {
|
||||
Map<String, Object> 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<String, Object> 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<ZTreeDTO> listZTreeRole() throws SearchException {
|
||||
@GetMapping("listztree")
|
||||
public List<ZTreeDTO> listZTree() throws SearchException {
|
||||
Map<String, Object> 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<List<RoleDTO>> listPageRole(ListPage page) throws SearchException {
|
||||
@GetMapping("listpage")
|
||||
public SuccessResultList<List<RoleDTO>> listPage(ListPage page) throws SearchException {
|
||||
Map<String, Object> 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<MenuDTO> listMenu(@PathVariable("menuParentId") String menuParentId,
|
||||
// @PathVariable("roleId") String roleId,
|
||||
// @PathVariable("type") String type) throws SearchException, ParamsException {
|
||||
// Map<String, Object> 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<String, Object> 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);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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");
|
||||
}
|
||||
|
||||
}
|
@ -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<String, Object> params) throws SaveException;
|
||||
void save(Map<String, Object> params) throws SaveException;
|
||||
|
||||
/**
|
||||
* 删除角色
|
||||
@ -42,7 +50,7 @@ public interface IRoleDao {
|
||||
* @param params
|
||||
* @throws RemoveException
|
||||
*/
|
||||
void removeRole(Map<String, Object> params) throws RemoveException;
|
||||
void remove(Map<String, Object> params) throws RemoveException;
|
||||
|
||||
/**
|
||||
* 修改角色
|
||||
@ -50,7 +58,7 @@ public interface IRoleDao {
|
||||
* @param params
|
||||
* @throws UpdateException
|
||||
*/
|
||||
void updateRole(Map<String, Object> params) throws UpdateException;
|
||||
void update(Map<String, Object> params) throws UpdateException;
|
||||
|
||||
/**
|
||||
* 角色列表
|
||||
@ -59,7 +67,7 @@ public interface IRoleDao {
|
||||
* @return
|
||||
* @throws SearchException
|
||||
*/
|
||||
List<RoleDTO> listRole(Map<String, Object> params) throws SearchException;
|
||||
List<RoleDTO> list(Map<String, Object> params) throws SearchException;
|
||||
|
||||
/**
|
||||
* 角色详情
|
||||
@ -68,16 +76,7 @@ public interface IRoleDao {
|
||||
* @return
|
||||
* @throws SearchException
|
||||
*/
|
||||
RoleDTO getRole(Map<String, Object> params) throws SearchException;
|
||||
|
||||
/**
|
||||
* 角色详情
|
||||
*
|
||||
* @param params
|
||||
* @return
|
||||
* @throws SearchException
|
||||
*/
|
||||
RolePO getRolePO(Map<String, Object> params) throws SearchException;
|
||||
RoleDTO get(Map<String, Object> params) throws SearchException;
|
||||
|
||||
/**
|
||||
* 获取最后一个字角色
|
||||
@ -95,7 +94,7 @@ public interface IRoleDao {
|
||||
* @return
|
||||
* @throws SearchException
|
||||
*/
|
||||
List<ZTreeDTO> listZTreeRoles(Map<String, Object> params) throws SearchException;
|
||||
List<ZTreeDTO> listZTree(Map<String, Object> params) throws SearchException;
|
||||
|
||||
/**
|
||||
* 子列表个数
|
||||
@ -106,83 +105,6 @@ public interface IRoleDao {
|
||||
*/
|
||||
Integer countByParentId(String id) throws SearchException;
|
||||
|
||||
/**
|
||||
* 通过用户获取角色
|
||||
*
|
||||
* @param params
|
||||
* @return
|
||||
* @throws SearchException
|
||||
*/
|
||||
List<RoleBO> listRoleBOByUser(Map<String, Object> params) throws SearchException;
|
||||
|
||||
/**
|
||||
* 通过用户组获取角色
|
||||
*
|
||||
* @param params
|
||||
* @return
|
||||
* @throws SearchException
|
||||
*/
|
||||
List<RoleBO> listRoleBOByGroup(Map<String, Object> params) throws SearchException;
|
||||
|
||||
/**
|
||||
* 删除角色菜单信息
|
||||
*
|
||||
* @param params
|
||||
* @throws RemoveException
|
||||
*/
|
||||
void removeRoleMenuInfo(Map<String, Object> params) throws RemoveException;
|
||||
|
||||
/**
|
||||
* 保存角色菜单信息
|
||||
*
|
||||
* @param params
|
||||
* @throws SaveException
|
||||
*/
|
||||
void saveRoleMenuInfo(Map<String, Object> params) throws SaveException;
|
||||
|
||||
/**
|
||||
* 角色菜单列表
|
||||
*
|
||||
* @param params
|
||||
* @return
|
||||
* @throws SearchException
|
||||
*/
|
||||
List<RoleMenuBO> listRoleMenuInfo(Map<String, Object> params) throws SearchException;
|
||||
|
||||
/**
|
||||
* 角色菜单列表详情
|
||||
*
|
||||
* @param params
|
||||
* @return
|
||||
* @throws SearchException
|
||||
*/
|
||||
List<RoleMenuBO> listRoleMenuDetail(Map<String, Object> params) throws SearchException;
|
||||
|
||||
/**
|
||||
* 新增自定义角色数据权限
|
||||
*
|
||||
* @param params
|
||||
* @throws SaveException
|
||||
*/
|
||||
void saveRoleDataAuthority(Map<String, Object> params) throws SaveException;
|
||||
|
||||
/**
|
||||
* 删除自定义角色数据权限
|
||||
*
|
||||
* @param params
|
||||
* @throws RemoveException
|
||||
*/
|
||||
void deleteRoleDataAuthority(Map<String, Object> params) throws RemoveException;
|
||||
|
||||
/**
|
||||
* 角色权限列表
|
||||
*
|
||||
* @param params
|
||||
* @return
|
||||
* @throws SearchException
|
||||
*/
|
||||
List<RoleDataAuthorityDTO> listRoleDataAuthority(Map<String, Object> params) throws SearchException;
|
||||
|
||||
/**
|
||||
* 统计角色
|
||||
*
|
||||
|
@ -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;
|
||||
|
@ -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<String, Object> params);
|
||||
void save(RoleVO roleVO);
|
||||
|
||||
/**
|
||||
* 删除角色
|
||||
*
|
||||
* @param params
|
||||
* @param ids
|
||||
* @return
|
||||
* @throws RemoveException
|
||||
*/
|
||||
SuccessResult removeRole(Map<String, Object> params);
|
||||
void remove(List<String> ids);
|
||||
|
||||
/**
|
||||
* 修改角色
|
||||
*
|
||||
* @param params
|
||||
* @param roleId
|
||||
* @param roleVO
|
||||
* @return
|
||||
* @throws UpdateException
|
||||
*/
|
||||
SuccessResult updateRole(Map<String, Object> params);
|
||||
|
||||
/**
|
||||
* 全部角色JSON列表
|
||||
*
|
||||
* @param params
|
||||
* @return
|
||||
* @throws SearchException
|
||||
*/
|
||||
List<RoleDTO> listRolesAllJson(Map<String, Object> params);
|
||||
void update(String roleId, RoleVO roleVO);
|
||||
|
||||
/**
|
||||
* 角色详情
|
||||
@ -121,7 +111,23 @@ public interface IRoleService extends IRoleBaseService {
|
||||
* @param params
|
||||
* @return
|
||||
*/
|
||||
RoleDTO getRole(Map<String, Object> params);
|
||||
RoleDTO get(Map<String, Object> params);
|
||||
|
||||
/**
|
||||
* 角色详情
|
||||
*
|
||||
* @param roleId 角色ID
|
||||
* @return
|
||||
*/
|
||||
RoleDTO get(String roleId);
|
||||
|
||||
/**
|
||||
* 角色列表
|
||||
*
|
||||
* @param params
|
||||
* @return
|
||||
*/
|
||||
List<RoleDTO> list(Map<String, Object> params);
|
||||
|
||||
/**
|
||||
* 角色列表,递归获取全部内容
|
||||
@ -130,7 +136,7 @@ public interface IRoleService extends IRoleBaseService {
|
||||
* @return
|
||||
* @throws SearchException
|
||||
*/
|
||||
List<RoleDTO> listRolesAll(Map<String, Object> params);
|
||||
List<RoleDTO> listAll(Map<String, Object> params);
|
||||
|
||||
/**
|
||||
* 角色zTree列表
|
||||
@ -139,7 +145,7 @@ public interface IRoleService extends IRoleBaseService {
|
||||
* @return
|
||||
* @throws SearchException
|
||||
*/
|
||||
List<ZTreeDTO> listZTreeRole(Map<String, Object> params);
|
||||
List<ZTreeDTO> listZTree(Map<String, Object> params);
|
||||
|
||||
/**
|
||||
* 角色EasyUI列表
|
||||
@ -147,145 +153,7 @@ public interface IRoleService extends IRoleBaseService {
|
||||
* @param page
|
||||
* @return
|
||||
*/
|
||||
SuccessResultList<List<RoleDTO>> listPageRole(ListPage page);
|
||||
|
||||
/**
|
||||
* 执行授权
|
||||
*
|
||||
* @param params
|
||||
* @return
|
||||
* @throws UpdateException
|
||||
*/
|
||||
SuccessResult authorization(Map<String, Object> params);
|
||||
|
||||
/**
|
||||
* 通过用户获取角色
|
||||
*
|
||||
* @param params
|
||||
* @return
|
||||
* @throws SearchException
|
||||
*/
|
||||
List<RoleBO> listRoleBOByUser(Map<String, Object> params);
|
||||
|
||||
/**
|
||||
* 通过用户组获取角色
|
||||
*
|
||||
* @param params
|
||||
* @return
|
||||
* @throws SearchException
|
||||
*/
|
||||
List<RoleBO> listRoleBOByGroup(Map<String, Object> params);
|
||||
|
||||
/**
|
||||
* 角色菜单列表
|
||||
*
|
||||
* @param params
|
||||
* @return
|
||||
* @throws SearchException
|
||||
*/
|
||||
List<RoleMenuBO> listRoleMenuDetail(Map<String, Object> params);
|
||||
|
||||
/**
|
||||
* 通过roleId获取角色
|
||||
*
|
||||
* @param roleId
|
||||
* @return
|
||||
* @throws SearchException
|
||||
*/
|
||||
public RoleBO getRoleBOByRoleId(String roleId);
|
||||
|
||||
/**
|
||||
* 获取角色权限集合
|
||||
*
|
||||
* @param roleIds
|
||||
* @return
|
||||
* @throws SearchException
|
||||
*/
|
||||
List<RoleBO> 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<RoleDataAuthorityDTO> listRoleDataAuthorityByRoleIdList(List<String> roleIds);
|
||||
|
||||
/**
|
||||
* 通过角色列表获取数据权限
|
||||
*
|
||||
* @param roleBOs
|
||||
* @return
|
||||
*/
|
||||
List<String> listDataAuthorityUserIdByRole(List<RoleBO> roleBOs);
|
||||
|
||||
/**
|
||||
* 通过部门获取用户数据数据权限
|
||||
*
|
||||
* @param departmentBOs
|
||||
* @return
|
||||
*/
|
||||
List<String> listDataAuthorityUserIdByDepartment(List<DepartmentBO> departmentBOs);
|
||||
|
||||
/**
|
||||
* 获取角色数据权限
|
||||
*
|
||||
* @param roleBOs
|
||||
* @return
|
||||
*/
|
||||
String getRoleDataAuthority(List<RoleBO> roleBOs);
|
||||
|
||||
/**
|
||||
* 设置角色菜单
|
||||
*
|
||||
* @param roleBO
|
||||
* @throws SearchException
|
||||
*/
|
||||
void setRoleMenu(RoleBO roleBO);
|
||||
|
||||
/**
|
||||
* 批量设置角色菜单
|
||||
*
|
||||
* @param roleBOs
|
||||
* @throws SearchException
|
||||
*/
|
||||
void setRoleMenus(List<RoleBO> roleBOs);
|
||||
|
||||
/**
|
||||
* 设置组角色列表
|
||||
*
|
||||
* @param groupRoles
|
||||
* @param roleBOs
|
||||
*/
|
||||
void setGroupRoles(List<GroupBO> groupRoles, List<RoleBO> roleBOs);
|
||||
|
||||
/**
|
||||
* 去除重复值
|
||||
*
|
||||
* @param roleBOs
|
||||
*/
|
||||
void removalDuplicateRole(List<RoleBO> roleBOs);
|
||||
SuccessResultList<List<RoleDTO>> listPage(ListPage page);
|
||||
|
||||
/**
|
||||
* 统计角色
|
||||
|
@ -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<String, Object> params) throws SaveException, SearchException {
|
||||
public void save(RoleVO roleVO) throws SaveException, SearchException {
|
||||
Map<String, Object> 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<String, Object> params) throws RemoveException {
|
||||
params.put("roleIds", Arrays.asList(params.get("roleIds").toString().split("_")));
|
||||
public void remove(List<String> ids) throws RemoveException {
|
||||
Map<String, Object> params = getHashMap(10);
|
||||
params.put("roleIds", ids);
|
||||
setUpdateInfo(params);
|
||||
roleDao.removeRole(params);
|
||||
return new SuccessResult();
|
||||
roleDao.remove(params);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SuccessResult updateRole(Map<String, Object> params) throws UpdateException {
|
||||
public void update(String roleId, RoleVO roleVO) throws UpdateException {
|
||||
Map<String, Object> params = HashMapUtil.beanToMap(roleVO);
|
||||
params.put("roleId", roleId);
|
||||
setUpdateInfo(params);
|
||||
roleDao.updateRole(params);
|
||||
return new SuccessResult();
|
||||
roleDao.update(params);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<RoleDTO> listRolesAllJson(Map<String, Object> params) throws SearchException {
|
||||
return listRolesAll(params);
|
||||
public RoleDTO get(Map<String, Object> params) throws SearchException {
|
||||
return roleDao.get(params);
|
||||
}
|
||||
|
||||
@Override
|
||||
public RoleDTO getRole(Map<String, Object> params) throws SearchException {
|
||||
return roleDao.getRole(params);
|
||||
public RoleDTO get(String roleId) {
|
||||
Map<String, Object> params = getHashMap(2);
|
||||
params.put("roleId", roleId);
|
||||
return get(params);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<RoleDTO> listRolesAll(Map<String, Object> params) throws SearchException {
|
||||
List<RoleDTO> roleDTOs = roleDao.listRole(params);
|
||||
public List<RoleDTO> list(Map<String, Object> params) {
|
||||
List<RoleDTO> srcRoleDTO = roleDao.list(params);
|
||||
List<RoleDTO> destRoleDTO = new ArrayList<>(Arrays.asList(new RoleDTO[srcRoleDTO.size()]));
|
||||
Collections.copy(destRoleDTO, srcRoleDTO);
|
||||
return destRoleDTO;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<RoleDTO> listAll(Map<String, Object> params) throws SearchException {
|
||||
List<RoleDTO> roleDTOs = roleDao.list(params);
|
||||
listSubRoles(roleDTOs, params);
|
||||
return roleDTOs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ZTreeDTO> listZTreeRole(Map<String, Object> params) throws SearchException {
|
||||
List<ZTreeDTO> zTreeDTOs = roleDao.listZTreeRoles(params);
|
||||
public List<ZTreeDTO> listZTree(Map<String, Object> params) throws SearchException {
|
||||
List<ZTreeDTO> 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<List<RoleDTO>> listPageRole(ListPage page) throws SearchException {
|
||||
public SuccessResultList<List<RoleDTO>> listPage(ListPage page) throws SearchException {
|
||||
PageHelper.startPage(page.getPage(), page.getRows());
|
||||
List<RoleDTO> roleDTOs = roleDao.listRole(page.getParams());
|
||||
List<RoleDTO> roleDTOs = list(page.getParams());
|
||||
PageInfo<RoleDTO> pageInfo = new PageInfo<>(roleDTOs);
|
||||
return new SuccessResultList<>(roleDTOs, pageInfo.getPageNum(), pageInfo.getTotal());
|
||||
}
|
||||
|
||||
@Override
|
||||
public SuccessResult authorization(Map<String, Object> params) throws UpdateException, RemoveException, SaveException {
|
||||
List<String> 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<RoleBO> listRoleBOByUser(Map<String, Object> params) throws SearchException {
|
||||
return roleDao.listRoleBOByUser(params);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<RoleBO> listRoleBOByGroup(Map<String, Object> params) throws SearchException {
|
||||
return roleDao.listRoleBOByGroup(params);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<RoleMenuBO> listRoleMenuDetail(Map<String, Object> params) throws SearchException {
|
||||
return roleDao.listRoleMenuDetail(params);
|
||||
}
|
||||
|
||||
@Override
|
||||
public RoleBO getRoleBOByRoleId(String roleId) throws SearchException {
|
||||
Map<String, Object> params = new HashMap<>(0);
|
||||
params.put("roleId", roleId);
|
||||
List<RoleMenuBO> roleMenuBOs = listRoleMenuDetail(params);
|
||||
|
||||
List<RoleMenuBO> apiSaveMenu = new ArrayList<>(0);
|
||||
List<RoleMenuBO> apiDeleteMenu = new ArrayList<>(0);
|
||||
List<RoleMenuBO> apiUpdateMenu = new ArrayList<>(0);
|
||||
List<RoleMenuBO> apiQueryMenu = new ArrayList<>(0);
|
||||
|
||||
List<RoleMenuBO> resourceSaveMenu = new ArrayList<>(0);
|
||||
List<RoleMenuBO> resourceDeleteMenu = new ArrayList<>(0);
|
||||
List<RoleMenuBO> resourceUpdateMenu = new ArrayList<>(0);
|
||||
List<RoleMenuBO> resourceQueryMenu = new ArrayList<>(0);
|
||||
|
||||
List<RoleMenuBO> routeSaveMenu = new ArrayList<>(0);
|
||||
List<RoleMenuBO> routeUpdateMenu = new ArrayList<>(0);
|
||||
List<RoleMenuBO> routeQueryMenu = new ArrayList<>(0);
|
||||
|
||||
List<PermissionBO> permissionInsert = new ArrayList<>(0);
|
||||
List<PermissionBO> permissionDelete = new ArrayList<>(0);
|
||||
List<PermissionBO> permissionUpdate = new ArrayList<>(0);
|
||||
List<PermissionBO> 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<PermissionBO> permissionInsert,
|
||||
List<PermissionBO> permissionDelete,
|
||||
List<PermissionBO> permissionUpdate,
|
||||
List<PermissionBO> permissionQuery) {
|
||||
List<RolePermissionDTO> 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<RoleBO> listRoleBO(String roleIds) throws SearchException {
|
||||
String[] roleIdArray = roleIds.split("_");
|
||||
List<RoleBO> 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<String, Object> 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<RoleBO> roleBOs) throws SearchException {
|
||||
for (RoleBO roleBO : roleBOs) {
|
||||
setRoleMenu(roleBO);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public RoleDataAuthorityTypeDTO getRoleDataAuthorityType(String roleId) throws SearchException {
|
||||
Map<String, Object> 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<RoleDataAuthorityDTO> 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<RoleDataAuthorityDTO> listRoleDataAuthorityByRoleIdList(List<String> roleIds) throws SearchException {
|
||||
Map<String, Object> params = getHashMap(1);
|
||||
params.put("roleIds", roleIds);
|
||||
return roleDao.listRoleDataAuthority(params);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> listDataAuthorityUserIdByRole(List<RoleBO> roleBOs) {
|
||||
List<String> userIds = new ArrayList<>();
|
||||
List<String> roleIds = new ArrayList<>();
|
||||
for (RoleBO roleBO : roleBOs) {
|
||||
roleIds.add(roleBO.getRoleId());
|
||||
}
|
||||
List<RoleDataAuthorityDTO> roleDataAuthorityDTOs = listRoleDataAuthorityByRoleIdList(roleIds);
|
||||
for (RoleDataAuthorityDTO roleDataAuthorityDTO : roleDataAuthorityDTOs) {
|
||||
userIds.add(roleDataAuthorityDTO.getUserId());
|
||||
}
|
||||
return userIds;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> listDataAuthorityUserIdByDepartment(List<DepartmentBO> departmentBOs) {
|
||||
List<String> userIds = new ArrayList<>();
|
||||
if (departmentBOs.isEmpty()) {
|
||||
return userIds;
|
||||
}
|
||||
List<String> departmentIds = new ArrayList<>();
|
||||
for (DepartmentBO departmentBO : departmentBOs) {
|
||||
departmentIds.add(departmentBO.getDepartmentId());
|
||||
}
|
||||
return departmentUserService.listUserId(departmentIds);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getRoleDataAuthority(List<RoleBO> 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<GroupBO> groupRoles, List<RoleBO> roleBOs) {
|
||||
Map<String, Object> params = getHashMap(1);
|
||||
groupRoles.forEach(groupBO -> {
|
||||
params.put("groupId", groupBO.getGroupId());
|
||||
roleBOs.addAll(listRoleBOByGroup(params));
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removalDuplicateRole(List<RoleBO> 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<String, Object> params) throws SearchException {
|
||||
Integer roleCount = roleDao.countRole(params);
|
||||
@ -454,7 +133,7 @@ public class RoleServiceImpl extends DefaultBaseService implements IRoleService
|
||||
private void listSubRoles(List<RoleDTO> roleDTOs, Map<String, Object> params) throws SearchException {
|
||||
for (RoleDTO roleDTO : roleDTOs) {
|
||||
params.put("roleParentId", roleDTO.getRoleId());
|
||||
List<RoleDTO> subRoleDTOs = roleDao.listRole(params);
|
||||
List<RoleDTO> subRoleDTOs = roleDao.list(params);
|
||||
roleDTO.setSubRoles(subRoleDTOs);
|
||||
listSubRoles(subRoleDTOs, params);
|
||||
}
|
||||
|
@ -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();
|
||||
}
|
||||
|
||||
}
|
217
service-role/src/main/resources/mybatis/mapper/role-mapper.xml
Normal file
217
service-role/src/main/resources/mybatis/mapper/role-mapper.xml
Normal file
@ -0,0 +1,217 @@
|
||||
<?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="ink.wgink.service.role.dao.IRoleDao">
|
||||
|
||||
<cache flushInterval="3600000"/>
|
||||
|
||||
<resultMap id="roleDTO" type="ink.wgink.pojo.dtos.role.RoleDTO">
|
||||
<id property="roleId" column="role_id"/>
|
||||
<result property="roleParentId" column="role_parent_id"/>
|
||||
<result property="roleParentName" column="role_parent_name"/>
|
||||
<result property="roleName" column="role_name"/>
|
||||
<result property="roleSummary" column="role_summary"/>
|
||||
<result property="roleCode" column="role_code"/>
|
||||
<result property="roleDataAuthority" column="role_data_authority"/>
|
||||
</resultMap>
|
||||
|
||||
<resultMap id="roleZTreeDTO" type="ink.wgink.pojo.dtos.ZTreeDTO">
|
||||
<id property="id" column="role_id"/>
|
||||
<result property="pId" column="role_parent_id"/>
|
||||
<result property="name" column="role_name"/>
|
||||
</resultMap>
|
||||
|
||||
<!-- 建表 -->
|
||||
<update id="createTable">
|
||||
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;
|
||||
|
||||
|
||||
</update>
|
||||
|
||||
<!-- 新增角色 -->
|
||||
<insert id="save" parameterType="map" flushCache="true">
|
||||
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}
|
||||
)
|
||||
</insert>
|
||||
|
||||
<!-- 删除角色 -->
|
||||
<update id="remove" parameterType="map" flushCache="true">
|
||||
UPDATE
|
||||
sys_role
|
||||
SET
|
||||
is_delete = 1,
|
||||
modifier = #{modifier},
|
||||
gmt_modified = #{gmtModified}
|
||||
WHERE
|
||||
role_id IN
|
||||
<foreach collection="roleIds" index="index" open="(" separator="," close=")">
|
||||
#{roleIds[${index}]}
|
||||
</foreach>
|
||||
</update>
|
||||
|
||||
<!-- 修改角色 -->
|
||||
<update id="update" parameterType="map" flushCache="true">
|
||||
UPDATE
|
||||
sys_role
|
||||
SET
|
||||
<if test="roleName != null and roleName != ''">
|
||||
role_name = #{roleName},
|
||||
</if>
|
||||
<if test="roleCode != null and roleCode != ''">
|
||||
role_code = #{roleCode},
|
||||
</if>
|
||||
<if test="roleSummary != null">
|
||||
role_summary = #{roleSummary},
|
||||
</if>
|
||||
<if test="roleDataAuthority != null and roleDataAuthority != ''">
|
||||
role_data_authority = #{roleDataAuthority},
|
||||
</if>
|
||||
modifier = #{modifier},
|
||||
gmt_modified = #{gmtModified}
|
||||
WHERE
|
||||
role_id = #{roleId}
|
||||
</update>
|
||||
|
||||
<!-- ztree列表 -->
|
||||
<select id="listZTree" parameterType="map" resultMap="roleZTreeDTO" useCache="false">
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
sys_role
|
||||
WHERE
|
||||
is_delete = 0
|
||||
<if test="roleParentId != null and roleParentId != ''">
|
||||
AND
|
||||
role_parent_id = #{roleParentId}
|
||||
</if>
|
||||
</select>
|
||||
|
||||
<!-- 角色列表 -->
|
||||
<select id="list" parameterType="map" resultMap="roleDTO" useCache="true">
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
sys_role
|
||||
WHERE
|
||||
is_delete = 0
|
||||
<if test="roleParentId != null and roleParentId != ''">
|
||||
AND
|
||||
role_parent_id = #{roleParentId}
|
||||
</if>
|
||||
<if test="keywords != null and keywords != ''">
|
||||
AND
|
||||
role_name LIKE CONCAT('%', #{keywords}, '%')
|
||||
</if>
|
||||
<if test="startTime != null and startTime != ''">
|
||||
AND
|
||||
gmt_create <![CDATA[ >= ]]> #{startTime}
|
||||
</if>
|
||||
<if test="startTime != null and startTime != ''">
|
||||
AND
|
||||
gmt_create <![CDATA[ <= ]]> #{endTime}
|
||||
</if>
|
||||
<choose>
|
||||
<when test="sort != null and (sort == 'roleName' or sort == 'roleCode')">
|
||||
ORDER BY
|
||||
<if test="sort == 'roleName'">
|
||||
role_name ${order}
|
||||
</if>
|
||||
<if test="sort == 'roleCode'">
|
||||
role_code ${order}
|
||||
</if>
|
||||
</when>
|
||||
</choose>
|
||||
</select>
|
||||
|
||||
<!-- 角色详情 -->
|
||||
<select id="get" parameterType="map" resultMap="roleDTO" useCache="false">
|
||||
SELECT
|
||||
t1.*,
|
||||
t2.role_name role_parent_name
|
||||
FROM
|
||||
sys_role t1
|
||||
LEFT JOIN
|
||||
sys_role t2
|
||||
ON
|
||||
t1.role_parent_id = t2.role_id
|
||||
AND
|
||||
t2.is_delete = 0
|
||||
WHERE
|
||||
t1.is_delete = 0
|
||||
<if test="roleId != null and roleId != ''">
|
||||
AND
|
||||
t1.role_id = #{roleId}
|
||||
</if>
|
||||
</select>
|
||||
|
||||
<!-- 子节点数量 -->
|
||||
<select id="countByParentId" parameterType="String" resultType="Integer" useCache="false">
|
||||
SELECT
|
||||
COUNT(*)
|
||||
FROM
|
||||
sys_role
|
||||
WHERE
|
||||
is_delete = 0
|
||||
AND
|
||||
role_parent_id = #{_parameter}
|
||||
</select>
|
||||
|
||||
<!-- 获取最后一个子角色,实际数据,包含已删除,方式编码重复 -->
|
||||
<select id="getLastByParentId" parameterType="String" resultMap="roleDTO" useCache="false">
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
sys_role
|
||||
WHERE
|
||||
role_parent_id = #{_parameter}
|
||||
ORDER BY
|
||||
role_code desc
|
||||
LIMIT 0, 1
|
||||
</select>
|
||||
|
||||
<!-- 统计角色 -->
|
||||
<select id="countRole" resultType="java.lang.Integer" useCache="true">
|
||||
SELECT
|
||||
COUNT(*)
|
||||
FROM
|
||||
sys_role
|
||||
WHERE
|
||||
is_delete = 0
|
||||
</select>
|
||||
|
||||
</mapper>
|
@ -1,7 +1,7 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<html xmlns:th="http://www.thymeleaf.org">
|
||||
<head>
|
||||
<base href="/usercenter/">
|
||||
<base th:href="${#request.getContextPath() + '/'}">
|
||||
<meta charset="utf-8">
|
||||
<meta name="renderer" content="webkit">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
|
||||
@ -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() {
|
||||
|
@ -1,7 +1,7 @@
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<html xmlns:th="http://www.thymeleaf.org">
|
||||
<head>
|
||||
<base href="/usercenter/">
|
||||
<base th:href="${#request.getContextPath() + '/'}">
|
||||
<meta charset="utf-8">
|
||||
<meta name="renderer" content="webkit">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
|
||||
@ -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 '<button type="button" class="layui-btn layui-btn-xs" lay-event="userEvent"><i class="fa fa-users"></i> 查看</button>';
|
||||
}
|
||||
},
|
||||
{field:'groups', width:100, title: '组列表', align:'center',
|
||||
templet: function(item) {
|
||||
return '<button type="button" class="layui-btn layui-btn-xs" lay-event="groupEvent"><i class="fa fa-users"></i> 查看</button>';
|
||||
}
|
||||
},
|
||||
{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 '<div class="layui-btn-group">' +
|
||||
'<button type="button" class="layui-btn layui-btn-xs" lay-event="saveEvent"><i class="fa fa-plus"></i> 增</button>' +
|
||||
'<button type="button" class="layui-btn layui-btn-danger layui-btn-xs" lay-event="removeEvent"><i class="fa fa-minus"></i> 删</button>' +
|
||||
'<button type="button" class="layui-btn layui-btn-normal layui-btn-xs" lay-event="updateEvent"><i class="fa fa-pencil"></i> 改</button>' +
|
||||
'<button type="button" class="layui-btn layui-btn-warm layui-btn-xs" lay-event="queryEvent"><i class="fa fa-search"></i> 查</button>'+
|
||||
'</div>'
|
||||
}
|
||||
},
|
||||
{field:'jurisdiction', width:200, title: '其他权限', align:'center',
|
||||
templet: function(item) {
|
||||
return '<div class="layui-btn-group">' +
|
||||
'<button type="button" class="layui-btn layui-btn-normal layui-btn-xs" lay-event="dataEvent"><i class="fa fa-database"></i> 数据</button>' +
|
||||
'<button type="button" class="layui-btn layui-btn-normal layui-btn-xs" lay-event="menuEvent"><i class="fa fa-list"></i> 菜单</button>'+
|
||||
'<button type="button" class="layui-btn layui-btn-normal layui-btn-xs" lay-event="permissionEvent"><i class="fa fa-link"></i> 接口</button>'+
|
||||
'</div>'
|
||||
}
|
||||
},
|
||||
]],
|
||||
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 '<button type="button" class="layui-btn layui-btn-xs" lay-event="userEvent"><i class="fa fa-users"></i> 查看</button>';
|
||||
}
|
||||
},
|
||||
{field:'groups', width:100, title: '组列表', align:'center',
|
||||
templet: function(item) {
|
||||
return '<button type="button" class="layui-btn layui-btn-xs" lay-event="groupEvent"><i class="fa fa-users"></i> 查看</button>';
|
||||
}
|
||||
},
|
||||
{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 '<div class="layui-btn-group">' +
|
||||
'<button type="button" class="layui-btn layui-btn-xs" lay-event="saveEvent"><i class="fa fa-plus"></i> 增</button>' +
|
||||
'<button type="button" class="layui-btn layui-btn-danger layui-btn-xs" lay-event="removeEvent"><i class="fa fa-minus"></i> 删</button>' +
|
||||
'<button type="button" class="layui-btn layui-btn-normal layui-btn-xs" lay-event="updateEvent"><i class="fa fa-pencil"></i> 改</button>' +
|
||||
'<button type="button" class="layui-btn layui-btn-warm layui-btn-xs" lay-event="queryEvent"><i class="fa fa-search"></i> 查</button>'+
|
||||
'</div>'
|
||||
}
|
||||
},
|
||||
{field:'jurisdiction', width:200, title: '其他权限', align:'center',
|
||||
templet: function(item) {
|
||||
return '<div class="layui-btn-group">' +
|
||||
'<button type="button" class="layui-btn layui-btn-normal layui-btn-xs" lay-event="dataEvent"><i class="fa fa-database"></i> 数据</button>' +
|
||||
'<button type="button" class="layui-btn layui-btn-normal layui-btn-xs" lay-event="menuEvent"><i class="fa fa-list"></i> 菜单</button>'+
|
||||
'<button type="button" class="layui-btn layui-btn-normal layui-btn-xs" lay-event="permissionEvent"><i class="fa fa-link"></i> 接口</button>'+
|
||||
'</div>'
|
||||
}
|
||||
},
|
||||
]
|
||||
],
|
||||
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();
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<html xmlns:th="http://www.thymeleaf.org">
|
||||
<head>
|
||||
<base href="/usercenter/">
|
||||
<base th:href="${#request.getContextPath() + '/'}">
|
||||
<meta charset="utf-8">
|
||||
<meta name="renderer" content="webkit">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
|
||||
|
@ -1,7 +1,7 @@
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<html xmlns:th="http://www.thymeleaf.org">
|
||||
<head>
|
||||
<base href="/usercenter/">
|
||||
<base th:href="${#request.getContextPath() + '/'}">
|
||||
<meta charset="utf-8">
|
||||
<meta name="renderer" content="webkit">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
|
||||
|
Loading…
Reference in New Issue
Block a user