merge
This commit is contained in:
@@ -69,7 +69,12 @@ public class SysAuthorityService {
|
||||
SysAuthority one = getById(id);
|
||||
if (one == null)
|
||||
throw new BusinessException("该权限不存在");
|
||||
//删除自身
|
||||
sysAuthorityRepository.delete(id);
|
||||
//如果有子节点,递归删除子节点
|
||||
List<SysAuthority> list = listChildrenForRemove(id);
|
||||
if (CollectionUtils.isNotEmpty(list))
|
||||
sysAuthorityRepository.deleteInBatch(list);
|
||||
result.setMessage("删除成功");
|
||||
result.setSuccess(true);
|
||||
return result;
|
||||
@@ -172,7 +177,7 @@ public class SysAuthorityService {
|
||||
* @return
|
||||
*/
|
||||
public boolean disableChildrenByParentId(String parentId) {
|
||||
List<SysAuthority> sysAuthorities = queryAllChildren(parentId);
|
||||
List<SysAuthority> sysAuthorities = listChildren(parentId);
|
||||
if (CollectionUtils.isNotEmpty(sysAuthorities)) {
|
||||
List<SysAuthority> save = sysAuthorityRepository.save(sysAuthorities);
|
||||
return CollectionUtils.isNotEmpty(save);
|
||||
@@ -187,7 +192,7 @@ public class SysAuthorityService {
|
||||
* @param enable
|
||||
* @return
|
||||
*/
|
||||
public List<SysAuthVo> queryAllChildren(String parentId, String enable) {
|
||||
public List<SysAuthVo> listChildren(String parentId, String enable) {
|
||||
List<SysAuthVo> list = new ArrayList<>();
|
||||
List<SysAuthority> authoritys;
|
||||
if (StringUtils.isNotEmpty(enable))
|
||||
@@ -199,7 +204,7 @@ public class SysAuthorityService {
|
||||
SysAuthVo vo;
|
||||
for (SysAuthority authority : authoritys) {
|
||||
vo = new SysAuthVo(authority);
|
||||
vo.setChildren(queryAllChildren(vo.getId(), enable));
|
||||
vo.setChildren(listChildren(vo.getId(), enable));
|
||||
list.add(vo);
|
||||
}
|
||||
return list;
|
||||
@@ -211,7 +216,7 @@ public class SysAuthorityService {
|
||||
* @param parentId
|
||||
* @return
|
||||
*/
|
||||
private List<SysAuthority> queryAllChildren(String parentId) {
|
||||
private List<SysAuthority> listChildren(String parentId) {
|
||||
//获取结果
|
||||
List<SysAuthority> sysAuthoritys = listByParentEnable(parentId, CommonConstant.ISENABLE);
|
||||
//遍历子集
|
||||
@@ -221,7 +226,27 @@ public class SysAuthorityService {
|
||||
sysAuthority.setEnable(CommonConstant.ISNOTENABLE);
|
||||
sysAuthority.setModifiedTime(new Date());
|
||||
list.add(sysAuthority);
|
||||
list.addAll(queryAllChildren(sysAuthority.getId()));
|
||||
list.addAll(listChildren(sysAuthority.getId()));
|
||||
}
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
/**
|
||||
* 刪除时递归获取所有子节点
|
||||
*
|
||||
* @param parentId
|
||||
* @return
|
||||
*/
|
||||
private List<SysAuthority> listChildrenForRemove(String parentId) {
|
||||
//获取结果
|
||||
List<SysAuthority> sysAuthoritys = listByParentEnable(parentId, null);
|
||||
//遍历子集
|
||||
List<SysAuthority> list = new ArrayList<>();
|
||||
if (CollectionUtils.isNotEmpty(sysAuthoritys)) {
|
||||
for (SysAuthority sysAuthority : sysAuthoritys) {
|
||||
list.add(sysAuthority);
|
||||
list.addAll(listChildren(sysAuthority.getId()));
|
||||
}
|
||||
}
|
||||
return list;
|
||||
|
||||
@@ -51,7 +51,7 @@ public class SysUserService {
|
||||
if (old != null) {
|
||||
throw new BusinessException("已经存在此用户名");
|
||||
}
|
||||
String id=PassWordUtil.createId();
|
||||
String id = PassWordUtil.createId();
|
||||
sysUser.setId(id);
|
||||
sysUser.setCreateTime(new Date());
|
||||
// 获取初始密码
|
||||
@@ -85,7 +85,7 @@ public class SysUserService {
|
||||
RestMessage result = new RestMessage();
|
||||
SysUser old = getOne(id);
|
||||
if (old == null) {
|
||||
throw new BusinessException("该对象不存在");
|
||||
throw new BusinessException("该用户不存在");
|
||||
}
|
||||
if (id.equals(CommonDataUtil.getToken(CommonConstant.CURRENT_USER_ID))) {
|
||||
throw new BusinessException("不能删除当前登录用户");
|
||||
@@ -116,7 +116,7 @@ public class SysUserService {
|
||||
RestMessage result = new RestMessage();
|
||||
SysUser old = getOne(sysUser.getId());
|
||||
if (old == null) {
|
||||
throw new BusinessException("该对象不存在");
|
||||
throw new BusinessException("该用户不存在");
|
||||
}
|
||||
if (old.getId().equals(CommonDataUtil.getToken(CommonConstant.CURRENT_USER_ID))) {
|
||||
throw new BusinessException("不能修改当前登录用户");
|
||||
|
||||
@@ -70,7 +70,15 @@ public class SysAuthorityControl {
|
||||
return JSONObjResult.toJSONObj(result);
|
||||
}
|
||||
|
||||
@LogInfo("根据父节点查询子节点(非递归)")
|
||||
@LogInfo("根据是否启用查询所有权限")
|
||||
@GetMapping("listByEnable")
|
||||
@ApiImplicitParam(name = "enable", value = "是否启用,格式Y|N", paramType = "query", dataType = "string")
|
||||
public JSONObject listByEnable(String enable) {
|
||||
List<SysAuthority> authoritys = sysAuthorityService.listByEnable(enable);
|
||||
return JSONObjResult.toJSONObj(authoritys, true, "");
|
||||
}
|
||||
|
||||
@LogInfo("根据父节点查询子节点")
|
||||
@GetMapping("listByParentId")
|
||||
@ApiImplicitParam(name = "parentId", value = "父id,可为空", paramType = "query", dataType = "string")
|
||||
public JSONObject listByParentId(String parentId) {
|
||||
@@ -82,19 +90,11 @@ public class SysAuthorityControl {
|
||||
return JSONObjResult.toJSONObj(queryByParentId, true, "");
|
||||
}
|
||||
|
||||
@LogInfo("根据是否启用查询所有权限")
|
||||
@GetMapping("listByEnable")
|
||||
@ApiImplicitParam(name = "enable", value = "是否启用,格式Y|N", paramType = "query", dataType = "string")
|
||||
public JSONObject listByEnable(String enable) {
|
||||
List<SysAuthority> authoritys = sysAuthorityService.listByEnable(enable);
|
||||
return JSONObjResult.toJSONObj(authoritys, true, "");
|
||||
}
|
||||
|
||||
@LogInfo("递归查询所有权限")
|
||||
@GetMapping("queryTree")
|
||||
@GetMapping("listTree")
|
||||
@ApiImplicitParam(name = "enable", value = "是否启用,格式Y|N", paramType = "query", dataType = "string")
|
||||
public JSONObject queryTree(String enable) {
|
||||
List<SysAuthVo> authoritys = sysAuthorityService.queryAllChildren(CommonConstant.ROOT, enable);
|
||||
public JSONObject listTree(String enable) {
|
||||
List<SysAuthVo> authoritys = sysAuthorityService.listChildren(CommonConstant.ROOT, enable);
|
||||
return JSONObjResult.toJSONObj(authoritys, true, "");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -72,9 +72,17 @@ public class SysRoleControl {
|
||||
return JSONObjResult.toJSONObj(sysRole, true, "");
|
||||
}
|
||||
|
||||
@LogInfo("根据是否启用查询所有角色")
|
||||
@GetMapping("listByEnable")
|
||||
@ApiImplicitParam(name = "enable", value = "是否启用,格式Y|N", paramType = "query", dataType = "string")
|
||||
public JSONObject listByEnable(String enable) {
|
||||
List<SysRole> sysRoles = sysRoleService.listAllByEnable(enable);
|
||||
return JSONObjResult.toJSONObj(sysRoles, true, "");
|
||||
}
|
||||
|
||||
@LogInfo("根据角色主键查找权限")
|
||||
@PostMapping("listAuthorityByRoleId")
|
||||
@ApiImplicitParam(name = "enable", value = "是否启用,格式Y|N", paramType = "query",dataType = "string")
|
||||
@ApiImplicitParam(name = "enable", value = "是否启用,格式Y|N", paramType = "query", dataType = "string")
|
||||
public JSONObject listAuthorityByRoleId(@RequestParam String roleId, String enable) {
|
||||
if (StringUtils.isEmpty(roleId))
|
||||
return JSONObjResult.toJSONObj("角色主键不能为空");
|
||||
@@ -106,12 +114,4 @@ public class SysRoleControl {
|
||||
RestMessage restMessage = sysRoleAuthorityService.saveBatch(list, roleId);
|
||||
return JSONObjResult.toJSONObj(restMessage);
|
||||
}
|
||||
|
||||
@LogInfo("根据是否启用查询所有角色")
|
||||
@GetMapping("listByEnable")
|
||||
@ApiImplicitParam(name = "enable", value = "是否启用,格式Y|N", paramType = "query",dataType = "string")
|
||||
public JSONObject listByEnable(String enable) {
|
||||
List<SysRole> sysRoles = sysRoleService.listAllByEnable(enable);
|
||||
return JSONObjResult.toJSONObj(sysRoles, true, "");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -56,9 +56,8 @@ public class SysUserControl {
|
||||
@LogInfo("删除用户")
|
||||
@GetMapping("removeById")
|
||||
public JSONObject removeById(@RequestParam String id) {
|
||||
if (StringUtils.isEmpty(id)) {
|
||||
if (StringUtils.isEmpty(id))
|
||||
return JSONObjResult.toJSONObj("主键不能为空");
|
||||
}
|
||||
RestMessage result = sysUserService.removeById(id);
|
||||
return JSONObjResult.toJSONObj(result);
|
||||
}
|
||||
@@ -66,9 +65,8 @@ public class SysUserControl {
|
||||
@LogInfo("修改用户信息")
|
||||
@PostMapping("update")
|
||||
public JSONObject update(@RequestBody @Valid SysUser sysUser) {
|
||||
if (StringUtils.isEmpty(sysUser.getId())) {
|
||||
if (StringUtils.isEmpty(sysUser.getId()))
|
||||
return JSONObjResult.toJSONObj("主键不能为空");
|
||||
}
|
||||
RestMessage result = sysUserService.update(sysUser);
|
||||
return JSONObjResult.toJSONObj(result);
|
||||
}
|
||||
@@ -76,13 +74,11 @@ public class SysUserControl {
|
||||
@LogInfo("获取用户详情")
|
||||
@GetMapping("getById")
|
||||
public JSONObject getById(@RequestParam String id) {
|
||||
if (StringUtils.isEmpty(id)) {
|
||||
if (StringUtils.isEmpty(id))
|
||||
return JSONObjResult.toJSONObj("主键不能为空");
|
||||
}
|
||||
SysUser sysUser = sysUserService.getOne(id);
|
||||
if (sysUser == null) {
|
||||
if (sysUser == null)
|
||||
return JSONObjResult.toJSONObj("未查到该对象");
|
||||
}
|
||||
return JSONObjResult.toJSONObj(sysUser, true, "");
|
||||
}
|
||||
|
||||
@@ -114,10 +110,10 @@ public class SysUserControl {
|
||||
@LogInfo("修改密码")
|
||||
@PostMapping("updatePassWord")
|
||||
public JSONObject updatePassWord(@RequestParam String newPassWord, @RequestParam String oldPassWord, @RequestParam String id) {
|
||||
if (StringUtils.isEmpty(newPassWord) || StringUtils.isEmpty(oldPassWord))
|
||||
return JSONObjResult.toJSONObj("原密码或新密码不能为空");
|
||||
if (StringUtils.isEmpty(id))
|
||||
return JSONObjResult.toJSONObj("主键不能为空");
|
||||
if (StringUtils.isEmpty(newPassWord) || StringUtils.isEmpty(oldPassWord))
|
||||
return JSONObjResult.toJSONObj("原密码或新密码不能为空");
|
||||
RestMessage restMessage = sysUserService.updatePassWord(newPassWord, oldPassWord, id);
|
||||
return JSONObjResult.toJSONObj(restMessage);
|
||||
}
|
||||
@@ -165,12 +161,10 @@ public class SysUserControl {
|
||||
if (StringUtils.isEmpty(userId))
|
||||
return JSONObjResult.toJSONObj("用户主键不能为空");
|
||||
SysUser old = sysUserService.getOne(userId);
|
||||
if (old == null) {
|
||||
if (old == null)
|
||||
return JSONObjResult.toJSONObj("该用户不存在");
|
||||
}
|
||||
if (CommonEnum.YesOrNoEnum.YES.getCode().equalsIgnoreCase(old.getAdmin())) {
|
||||
if (CommonEnum.YesOrNoEnum.YES.getCode().equalsIgnoreCase(old.getAdmin()))
|
||||
return JSONObjResult.toJSONObj("不能对管理员进行操作");
|
||||
}
|
||||
String ids[] = roleIds.split(",");
|
||||
List<SysUserRole> list = new ArrayList<>();
|
||||
for (String id : ids) {
|
||||
@@ -185,7 +179,7 @@ public class SysUserControl {
|
||||
|
||||
@LogInfo("根据用户主键查找所拥有的角色")
|
||||
@PostMapping("listRoleByUserId")
|
||||
@ApiImplicitParam(name = "enable", value = "是否启用,格式Y|N", paramType = "query",dataType = "string")
|
||||
@ApiImplicitParam(name = "enable", value = "是否启用,格式Y|N", paramType = "query", dataType = "string")
|
||||
public JSONObject listRoleByUserId(@RequestParam String userId, String enable) {
|
||||
if (StringUtils.isEmpty(userId))
|
||||
return JSONObjResult.toJSONObj("用户主键不能为空");
|
||||
@@ -195,8 +189,8 @@ public class SysUserControl {
|
||||
|
||||
@LogInfo("根据用户主键查找所拥有的权限")
|
||||
@PostMapping("listAuthorityByUserId")
|
||||
@ApiImplicitParam(name = "enable", value = "是否启用,格式Y|N", paramType = "query",dataType = "string")
|
||||
public JSONObject listAuthorityByUserId(@RequestParam String userId,String enable) {
|
||||
@ApiImplicitParam(name = "enable", value = "是否启用,格式Y|N", paramType = "query", dataType = "string")
|
||||
public JSONObject listAuthorityByUserId(@RequestParam String userId, String enable) {
|
||||
if (StringUtils.isEmpty(userId))
|
||||
return JSONObjResult.toJSONObj("用户主键不能为空");
|
||||
List<SysAuthority> list = sysUserService.queryAuthority(userId, enable);
|
||||
|
||||
Reference in New Issue
Block a user