merge
This commit is contained in:
@@ -40,7 +40,7 @@ public class SysUserRoleService {
|
||||
//用户新增角色
|
||||
list.forEach(sysUserRole -> {
|
||||
sysUserRole.setId(PassWordUtil.createId());
|
||||
sysUserRole.setModifiedTime(new Date());
|
||||
sysUserRole.setCreateTime(new Date());
|
||||
});
|
||||
List<SysUserRole> save = sysUserRoleRepository.save(list);
|
||||
if (CollectionUtils.isNotEmpty(save)) {
|
||||
|
||||
@@ -2,7 +2,11 @@ package com.xwbing.controller;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.xwbing.annotation.LogInfo;
|
||||
import com.xwbing.entity.SysAuthority;
|
||||
import com.xwbing.entity.SysRole;
|
||||
import com.xwbing.entity.SysRoleAuthority;
|
||||
import com.xwbing.service.SysAuthorityService;
|
||||
import com.xwbing.service.SysRoleAuthorityService;
|
||||
import com.xwbing.service.SysRoleService;
|
||||
import com.xwbing.util.JSONObjResult;
|
||||
import com.xwbing.util.RestMessage;
|
||||
@@ -11,6 +15,7 @@ import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@@ -25,6 +30,10 @@ import java.util.List;
|
||||
public class SysRoleControl {
|
||||
@Resource
|
||||
private SysRoleService sysRoleService;
|
||||
@Resource
|
||||
private SysAuthorityService sysAuthorityService;
|
||||
@Resource
|
||||
private SysRoleAuthorityService sysRoleAuthorityService;
|
||||
|
||||
@LogInfo("添加角色")
|
||||
@PostMapping("save")
|
||||
@@ -66,6 +75,43 @@ public class SysRoleControl {
|
||||
return JSONObjResult.toJSONObj(sysRole, true, "");
|
||||
}
|
||||
|
||||
@LogInfo("根据角色主键查找权限")
|
||||
@PostMapping("listAuthorityByRoleId")
|
||||
public JSONObject listAuthorityByRoleId(@RequestParam String roleId, String enable) {
|
||||
if (StringUtils.isEmpty(roleId)) {
|
||||
return JSONObjResult.toJSONObj("角色主键不能为空");
|
||||
}
|
||||
SysRole sysRole = sysRoleService.getById(roleId);
|
||||
if (sysRole == null) {
|
||||
return JSONObjResult.toJSONObj("该角色不存在");
|
||||
}
|
||||
List<SysAuthority> authoritys = sysAuthorityService.listByRoleIdEnable(roleId, enable);
|
||||
return JSONObjResult.toJSONObj(authoritys, true, "");
|
||||
}
|
||||
|
||||
@LogInfo("保存角色 权限主键")
|
||||
@PostMapping("saveAuthoritys")
|
||||
public JSONObject saveAuthoritys(@RequestParam String authorityIds, @RequestParam String roleId) {
|
||||
if (StringUtils.isEmpty(authorityIds))
|
||||
return JSONObjResult.toJSONObj("权限主键集合不能为空");
|
||||
if (StringUtils.isEmpty(roleId))
|
||||
return JSONObjResult.toJSONObj("角色主键不能为空");
|
||||
SysRole sysRole = sysRoleService.getById(roleId);
|
||||
if (sysRole == null) {
|
||||
return JSONObjResult.toJSONObj("该角色不存在");
|
||||
}
|
||||
String ids[] = authorityIds.split(",");
|
||||
List<SysRoleAuthority> list = new ArrayList<>();
|
||||
for (String id : ids) {
|
||||
SysRoleAuthority roleAuthority = new SysRoleAuthority();
|
||||
roleAuthority.setRoleId(roleId);
|
||||
roleAuthority.setAuthorityId(id);
|
||||
list.add(roleAuthority);
|
||||
}
|
||||
RestMessage restMessage = sysRoleAuthorityService.saveBatch(list, roleId);
|
||||
return JSONObjResult.toJSONObj(restMessage);
|
||||
}
|
||||
|
||||
@LogInfo("根据是否启用查询所有角色")
|
||||
@GetMapping("listAllByEnable")
|
||||
public JSONObject listAllByEnable(@RequestParam String enable) {
|
||||
|
||||
@@ -136,8 +136,6 @@ public class SysUserControl {
|
||||
SysUser sysUser = sysUserService.getOne((String) CommonDataUtil.getToken(CommonConstant.CURRENT_USER_ID));
|
||||
if (sysUser == null)
|
||||
return JSONObjResult.toJSONObj("未获取到当前登录用户信息");
|
||||
SysUser result = new SysUser();
|
||||
result.setUserName(sysUser.getUserName());
|
||||
List<SysAuthority> other = new ArrayList<>();
|
||||
List<SysAuthority> menu = new ArrayList<>();
|
||||
List<SysAuthority> list;
|
||||
@@ -153,13 +151,13 @@ public class SysUserControl {
|
||||
other.add(sysAuthority);
|
||||
}
|
||||
}
|
||||
result.setMenuArray(menu);
|
||||
result.setOtherArray(other);
|
||||
return JSONObjResult.toJSONObj(result, true, "");
|
||||
sysUser.setMenuArray(menu);
|
||||
sysUser.setOtherArray(other);
|
||||
return JSONObjResult.toJSONObj(sysUser, true, "");
|
||||
}
|
||||
|
||||
@LogInfo("保存用户角色")
|
||||
@GetMapping("saveRole")
|
||||
@PostMapping("saveRole")
|
||||
public JSONObject saveRole(@RequestParam String roleIds, @RequestParam String userId) {
|
||||
if (StringUtils.isEmpty(roleIds))
|
||||
return JSONObjResult.toJSONObj("角色主键不能为空");
|
||||
@@ -185,8 +183,8 @@ public class SysUserControl {
|
||||
}
|
||||
|
||||
@LogInfo("根据用户主键查找所拥有的角色")
|
||||
@GetMapping("queryRole")
|
||||
public JSONObject queryRole(@RequestParam String userId, @RequestParam String enable) {
|
||||
@PostMapping("listRoles")
|
||||
public JSONObject listRoles(@RequestParam String userId, @RequestParam String enable) {
|
||||
if (StringUtils.isEmpty(userId))
|
||||
return JSONObjResult.toJSONObj("用户主键不能为空");
|
||||
if (StringUtils.isEmpty(enable))
|
||||
@@ -196,7 +194,7 @@ public class SysUserControl {
|
||||
}
|
||||
|
||||
@LogInfo("根据用户主键查找所拥有的权限")
|
||||
@GetMapping("queryAuthority")
|
||||
@PostMapping("queryAuthority")
|
||||
public JSONObject queryAuthority(@RequestParam String userId, @RequestParam String enable) {
|
||||
if (StringUtils.isEmpty(userId))
|
||||
return JSONObjResult.toJSONObj("用户主键不能为空");
|
||||
|
||||
Reference in New Issue
Block a user