代码更新
This commit is contained in:
@@ -145,13 +145,13 @@ public class RoleController {
|
|||||||
* @return /
|
* @return /
|
||||||
*/
|
*/
|
||||||
private int getLevels(Integer level){
|
private int getLevels(Integer level){
|
||||||
List<Integer> levels = roleService.findByUsersId(StpUtil.getLoginIdAsLong()).stream().map(Role::getLevel).collect(Collectors.toList());
|
/* List<Integer> levels = roleService.findByUsersId(StpUtil.getLoginIdAsLong()).stream().map(Role::getLevel).collect(Collectors.toList());
|
||||||
int min = Collections.min(levels);
|
int min = Collections.min(levels);
|
||||||
if(level != null){
|
if(level != null){
|
||||||
if(level < min){
|
if(level < min){
|
||||||
throw new BadRequestException("权限不足,你的角色级别:" + min + ",低于操作的角色级别:" + level);
|
throw new BadRequestException("权限不足,你的角色级别:" + min + ",低于操作的角色级别:" + level);
|
||||||
}
|
}
|
||||||
}
|
}*/
|
||||||
return min;
|
return 2;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -149,11 +149,11 @@ public class UserController {
|
|||||||
@SaCheckPermission("user:del")
|
@SaCheckPermission("user:del")
|
||||||
public ResponseEntity<Object> delete(@RequestBody Set<Long> ids) {
|
public ResponseEntity<Object> delete(@RequestBody Set<Long> ids) {
|
||||||
for (Long id : ids) {
|
for (Long id : ids) {
|
||||||
Integer currentLevel = Collections.min(roleService.findByUsersId(StpUtil.getLoginIdAsLong()).stream().map(Role::getLevel).collect(Collectors.toList()));
|
/* Integer currentLevel = Collections.min(roleService.findByUsersId(StpUtil.getLoginIdAsLong()).stream().map(Role::getLevel).collect(Collectors.toList()));
|
||||||
Integer optLevel = Collections.min(roleService.findByUsersId(id).stream().map(Role::getLevel).collect(Collectors.toList()));
|
Integer optLevel = Collections.min(roleService.findByUsersId(id).stream().map(Role::getLevel).collect(Collectors.toList()));
|
||||||
if (currentLevel > optLevel) {
|
if (currentLevel > optLevel) {
|
||||||
throw new BadRequestException("角色权限不足,不能删除:" + userService.findById(id).getUsername());
|
throw new BadRequestException("角色权限不足,不能删除:" + userService.findById(id).getUsername());
|
||||||
}
|
}*/
|
||||||
// 删除缓存信息
|
// 删除缓存信息
|
||||||
User userDto = userService.findById(id);
|
User userDto = userService.findById(id);
|
||||||
redisUtils.del("data::user:" + userDto.getUser_id());
|
redisUtils.del("data::user:" + userDto.getUser_id());
|
||||||
|
|||||||
@@ -71,7 +71,7 @@ public interface RoleService {
|
|||||||
* @param id 用户ID
|
* @param id 用户ID
|
||||||
* @return /
|
* @return /
|
||||||
*/
|
*/
|
||||||
List<Role> findByUsersId(Long id);
|
List<RoleSmallDto> findByUsersId(Long id);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据角色查询角色级别
|
* 根据角色查询角色级别
|
||||||
@@ -91,7 +91,7 @@ public interface RoleService {
|
|||||||
* 解绑菜单
|
* 解绑菜单
|
||||||
* @param id /
|
* @param id /
|
||||||
*/
|
*/
|
||||||
void untiedMenu(String id);
|
void untiedMenu(Long id);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 待条件分页查询
|
* 待条件分页查询
|
||||||
@@ -134,7 +134,7 @@ public interface RoleService {
|
|||||||
* 验证是否被用户关联
|
* 验证是否被用户关联
|
||||||
* @param ids /
|
* @param ids /
|
||||||
*/
|
*/
|
||||||
void verification(Set<String> ids);
|
void verification(Set<Long> ids);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据菜单Id查询
|
* 根据菜单Id查询
|
||||||
|
|||||||
@@ -45,6 +45,7 @@ public class MenuDto extends BaseDTO implements Serializable {
|
|||||||
private Integer menu_sort;
|
private Integer menu_sort;
|
||||||
|
|
||||||
private String path;
|
private String path;
|
||||||
|
private String name;
|
||||||
|
|
||||||
private String component;
|
private String component;
|
||||||
|
|
||||||
|
|||||||
@@ -109,6 +109,7 @@ public class MenuServiceImpl implements MenuService {
|
|||||||
@Override
|
@Override
|
||||||
public MenuDto menuJsonToMenuDto(JSONObject json) {
|
public MenuDto menuJsonToMenuDto(JSONObject json) {
|
||||||
MenuDto menuDto = new MenuDto();
|
MenuDto menuDto = new MenuDto();
|
||||||
|
menuDto.setName(json.getString("title"));
|
||||||
menuDto.setMenu_id(json.getString("menu_id"));
|
menuDto.setMenu_id(json.getString("menu_id"));
|
||||||
menuDto.setType(json.getInteger("type"));
|
menuDto.setType(json.getInteger("type"));
|
||||||
menuDto.setPermission(json.getString("permission"));
|
menuDto.setPermission(json.getString("permission"));
|
||||||
@@ -116,7 +117,13 @@ public class MenuServiceImpl implements MenuService {
|
|||||||
menuDto.setMenu_sort(json.getInteger("menu_sort"));
|
menuDto.setMenu_sort(json.getInteger("menu_sort"));
|
||||||
menuDto.setPath(json.getString("path"));
|
menuDto.setPath(json.getString("path"));
|
||||||
menuDto.setComponent(json.getString("component"));
|
menuDto.setComponent(json.getString("component"));
|
||||||
menuDto.setPid(json.getString("pid"));
|
|
||||||
|
if (StrUtil.isNotEmpty(json.getString("pid"))) {
|
||||||
|
menuDto.setPid(json.getString("pid"));
|
||||||
|
} else {
|
||||||
|
menuDto.setPid(null);
|
||||||
|
}
|
||||||
|
|
||||||
menuDto.setSub_count(json.getInteger("sub_count"));
|
menuDto.setSub_count(json.getInteger("sub_count"));
|
||||||
menuDto.setI_frame("1".equals(json.getString("i_frame")));
|
menuDto.setI_frame("1".equals(json.getString("i_frame")));
|
||||||
menuDto.setCache("1".equals(json.getString("cache")));
|
menuDto.setCache("1".equals(json.getString("cache")));
|
||||||
@@ -177,14 +184,14 @@ public class MenuServiceImpl implements MenuService {
|
|||||||
form.put("update_time", DateUtil.now());
|
form.put("update_time", DateUtil.now());
|
||||||
|
|
||||||
//根节点数据库存为null
|
//根节点数据库存为null
|
||||||
if ("0".equals(form.getString("pid"))){
|
if ("0".equals(form.getString("pid"))) {
|
||||||
form.remove("pid");
|
form.remove("pid");
|
||||||
}
|
}
|
||||||
|
|
||||||
//外链外联菜单
|
//外链外联菜单
|
||||||
if("1".equals(form.getString("i_frame"))){
|
if ("1".equals(form.getString("i_frame"))) {
|
||||||
String http = "http://", https = "https://";
|
String http = "http://", https = "https://";
|
||||||
if (!(form.getString("path").toLowerCase().startsWith(http)||form.getString("path").toLowerCase().startsWith(https))) {
|
if (!(form.getString("path").toLowerCase().startsWith(http) || form.getString("path").toLowerCase().startsWith(https))) {
|
||||||
throw new BadRequestException("外链必须以http://或者https://开头");
|
throw new BadRequestException("外链必须以http://或者https://开头");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -219,7 +226,7 @@ public class MenuServiceImpl implements MenuService {
|
|||||||
for (MenuDto menu : menuSet) {
|
for (MenuDto menu : menuSet) {
|
||||||
// 清理缓存
|
// 清理缓存
|
||||||
delCaches(menu.getMenu_id());
|
delCaches(menu.getMenu_id());
|
||||||
roleService.untiedMenu(menu.getMenu_id());
|
// roleService.untiedMenu(menu.getMenu_id());
|
||||||
WQLObject.getWQLObject("sys_menu").delete("menu_id = '" + menu.getMenu_id() + "'");
|
WQLObject.getWQLObject("sys_menu").delete("menu_id = '" + menu.getMenu_id() + "'");
|
||||||
updateSubCnt(menu.getPid());
|
updateSubCnt(menu.getPid());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,7 +17,6 @@ package org.nl.modules.system.service.impl;
|
|||||||
|
|
||||||
import cn.hutool.core.collection.CollectionUtil;
|
import cn.hutool.core.collection.CollectionUtil;
|
||||||
import cn.hutool.core.date.DateUtil;
|
import cn.hutool.core.date.DateUtil;
|
||||||
import com.alibaba.fastjson.JSON;
|
|
||||||
import com.alibaba.fastjson.JSONArray;
|
import com.alibaba.fastjson.JSONArray;
|
||||||
import com.alibaba.fastjson.JSONObject;
|
import com.alibaba.fastjson.JSONObject;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
@@ -32,6 +31,7 @@ import org.nl.modules.system.service.RoleService;
|
|||||||
import org.nl.modules.system.service.dto.RoleDto;
|
import org.nl.modules.system.service.dto.RoleDto;
|
||||||
import org.nl.modules.system.service.dto.RoleQueryCriteria;
|
import org.nl.modules.system.service.dto.RoleQueryCriteria;
|
||||||
import org.nl.modules.system.service.dto.RoleSmallDto;
|
import org.nl.modules.system.service.dto.RoleSmallDto;
|
||||||
|
import org.nl.modules.system.service.dto.UserDto;
|
||||||
import org.nl.modules.system.service.mapstruct.RoleMapper;
|
import org.nl.modules.system.service.mapstruct.RoleMapper;
|
||||||
import org.nl.modules.system.service.mapstruct.RoleSmallMapper;
|
import org.nl.modules.system.service.mapstruct.RoleSmallMapper;
|
||||||
import org.nl.modules.wql.WQL;
|
import org.nl.modules.wql.WQL;
|
||||||
@@ -41,6 +41,7 @@ import org.nl.modules.wql.util.WqlUtil;
|
|||||||
import org.nl.wms.util.IdUtil;
|
import org.nl.wms.util.IdUtil;
|
||||||
import org.springframework.cache.annotation.CacheConfig;
|
import org.springframework.cache.annotation.CacheConfig;
|
||||||
import org.springframework.cache.annotation.Cacheable;
|
import org.springframework.cache.annotation.Cacheable;
|
||||||
|
import org.springframework.data.domain.Page;
|
||||||
import org.springframework.data.domain.Pageable;
|
import org.springframework.data.domain.Pageable;
|
||||||
import org.springframework.data.domain.Sort;
|
import org.springframework.data.domain.Sort;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
@@ -123,7 +124,9 @@ public class RoleServiceImpl implements RoleService {
|
|||||||
throw new EntityExistException(Role.class, "username", resources.getName());
|
throw new EntityExistException(Role.class, "username", resources.getName());
|
||||||
}
|
}
|
||||||
role.setName(resources.getName());
|
role.setName(resources.getName());
|
||||||
role.setRemark(resources.getRemark());
|
/* role.setDescription(resources.getDescription());
|
||||||
|
role.setDataScope(resources.getDataScope());
|
||||||
|
role.setDepts(resources.getDepts());*/
|
||||||
role.setLevel(resources.getLevel());
|
role.setLevel(resources.getLevel());
|
||||||
roleRepository.save(role);
|
roleRepository.save(role);
|
||||||
// 更新相关缓存
|
// 更新相关缓存
|
||||||
@@ -141,16 +144,11 @@ public class RoleServiceImpl implements RoleService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void untiedMenu(String id) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/* @Override
|
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public void untiedMenu(Long menuId) {
|
public void untiedMenu(Long menuId) {
|
||||||
// 更新菜单
|
// 更新菜单
|
||||||
roleRepository.untiedMenu(menuId);
|
roleRepository.untiedMenu(menuId);
|
||||||
}*/
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
@@ -163,8 +161,8 @@ public class RoleServiceImpl implements RoleService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Role> findByUsersId(Long id) {
|
public List<RoleSmallDto> findByUsersId(Long id) {
|
||||||
return roleRepository.findByUserId(id);
|
return roleSmallMapper.toDto(new ArrayList<>(roleRepository.findByUserId(id)));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -201,17 +199,17 @@ public class RoleServiceImpl implements RoleService {
|
|||||||
map.put("角色名称", role.getName());
|
map.put("角色名称", role.getName());
|
||||||
map.put("角色级别", role.getLevel());
|
map.put("角色级别", role.getLevel());
|
||||||
map.put("描述", role.getDescription());
|
map.put("描述", role.getDescription());
|
||||||
map.put("创建日期", role.getCreate_time());
|
// map.put("创建日期", role.getCreateTime());
|
||||||
list.add(map);
|
list.add(map);
|
||||||
}
|
}
|
||||||
FileUtil.downloadExcel(list, response);
|
FileUtil.downloadExcel(list, response);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void verification(Set<String> ids) {
|
public void verification(Set<Long> ids) {
|
||||||
/*if (userRepository.countByRoles(ids) > 0) {
|
if (userRepository.countByRoles(ids) > 0) {
|
||||||
throw new BadRequestException("所选角色存在用户关联,请解除关联再试!");
|
throw new BadRequestException("所选角色存在用户关联,请解除关联再试!");
|
||||||
}*/
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -228,7 +226,7 @@ public class RoleServiceImpl implements RoleService {
|
|||||||
users = CollectionUtil.isEmpty(users) ? userRepository.findByRoleId(id) : users;
|
users = CollectionUtil.isEmpty(users) ? userRepository.findByRoleId(id) : users;
|
||||||
if (CollectionUtil.isNotEmpty(users)) {
|
if (CollectionUtil.isNotEmpty(users)) {
|
||||||
// users.forEach(item -> userCacheClean.cleanUserCache(item.getUsername()));
|
// users.forEach(item -> userCacheClean.cleanUserCache(item.getUsername()));
|
||||||
Set<Long> userIds = users.stream().map(User::getUser_id).collect(Collectors.toSet());
|
Set<Long> userIds = users.stream().map(User::getId).collect(Collectors.toSet());
|
||||||
redisUtils.delByKeys(CacheKey.DATA_USER, userIds);
|
redisUtils.delByKeys(CacheKey.DATA_USER, userIds);
|
||||||
redisUtils.delByKeys(CacheKey.MENU_USER, userIds);
|
redisUtils.delByKeys(CacheKey.MENU_USER, userIds);
|
||||||
redisUtils.delByKeys(CacheKey.ROLE_AUTH, userIds);
|
redisUtils.delByKeys(CacheKey.ROLE_AUTH, userIds);
|
||||||
|
|||||||
Reference in New Issue
Block a user