代码更新

This commit is contained in:
ludj
2022-11-30 15:36:43 +08:00
parent d054ae574b
commit 135c93413c
6 changed files with 34 additions and 28 deletions

View File

@@ -145,13 +145,13 @@ public class RoleController {
* @return /
*/
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);
if(level != null){
if(level < min){
throw new BadRequestException("权限不足,你的角色级别:" + min + ",低于操作的角色级别:" + level);
}
}
return min;
}*/
return 2;
}
}

View File

@@ -149,11 +149,11 @@ public class UserController {
@SaCheckPermission("user:del")
public ResponseEntity<Object> delete(@RequestBody Set<Long> 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()));
if (currentLevel > optLevel) {
throw new BadRequestException("角色权限不足,不能删除:" + userService.findById(id).getUsername());
}
}*/
// 删除缓存信息
User userDto = userService.findById(id);
redisUtils.del("data::user:" + userDto.getUser_id());

View File

@@ -71,7 +71,7 @@ public interface RoleService {
* @param id 用户ID
* @return /
*/
List<Role> findByUsersId(Long id);
List<RoleSmallDto> findByUsersId(Long id);
/**
* 根据角色查询角色级别
@@ -91,7 +91,7 @@ public interface RoleService {
* 解绑菜单
* @param id /
*/
void untiedMenu(String id);
void untiedMenu(Long id);
/**
* 待条件分页查询
@@ -134,7 +134,7 @@ public interface RoleService {
* 验证是否被用户关联
* @param ids /
*/
void verification(Set<String> ids);
void verification(Set<Long> ids);
/**
* 根据菜单Id查询

View File

@@ -45,6 +45,7 @@ public class MenuDto extends BaseDTO implements Serializable {
private Integer menu_sort;
private String path;
private String name;
private String component;

View File

@@ -109,6 +109,7 @@ public class MenuServiceImpl implements MenuService {
@Override
public MenuDto menuJsonToMenuDto(JSONObject json) {
MenuDto menuDto = new MenuDto();
menuDto.setName(json.getString("title"));
menuDto.setMenu_id(json.getString("menu_id"));
menuDto.setType(json.getInteger("type"));
menuDto.setPermission(json.getString("permission"));
@@ -116,7 +117,13 @@ public class MenuServiceImpl implements MenuService {
menuDto.setMenu_sort(json.getInteger("menu_sort"));
menuDto.setPath(json.getString("path"));
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.setI_frame("1".equals(json.getString("i_frame")));
menuDto.setCache("1".equals(json.getString("cache")));
@@ -177,14 +184,14 @@ public class MenuServiceImpl implements MenuService {
form.put("update_time", DateUtil.now());
//根节点数据库存为null
if ("0".equals(form.getString("pid"))){
if ("0".equals(form.getString("pid"))) {
form.remove("pid");
}
//外链外联菜单
if("1".equals(form.getString("i_frame"))){
if ("1".equals(form.getString("i_frame"))) {
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://开头");
}
}
@@ -219,7 +226,7 @@ public class MenuServiceImpl implements MenuService {
for (MenuDto menu : menuSet) {
// 清理缓存
delCaches(menu.getMenu_id());
roleService.untiedMenu(menu.getMenu_id());
// roleService.untiedMenu(menu.getMenu_id());
WQLObject.getWQLObject("sys_menu").delete("menu_id = '" + menu.getMenu_id() + "'");
updateSubCnt(menu.getPid());
}

View File

@@ -17,7 +17,6 @@ package org.nl.modules.system.service.impl;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.date.DateUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
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.RoleQueryCriteria;
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.RoleSmallMapper;
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.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Service;
@@ -123,7 +124,9 @@ public class RoleServiceImpl implements RoleService {
throw new EntityExistException(Role.class, "username", 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());
roleRepository.save(role);
// 更新相关缓存
@@ -141,16 +144,11 @@ public class RoleServiceImpl implements RoleService {
}
@Override
public void untiedMenu(String id) {
}
/* @Override
@Transactional(rollbackFor = Exception.class)
public void untiedMenu(Long menuId) {
// 更新菜单
roleRepository.untiedMenu(menuId);
}*/
}
@Override
@Transactional(rollbackFor = Exception.class)
@@ -163,8 +161,8 @@ public class RoleServiceImpl implements RoleService {
}
@Override
public List<Role> findByUsersId(Long id) {
return roleRepository.findByUserId(id);
public List<RoleSmallDto> findByUsersId(Long id) {
return roleSmallMapper.toDto(new ArrayList<>(roleRepository.findByUserId(id)));
}
@Override
@@ -201,17 +199,17 @@ public class RoleServiceImpl implements RoleService {
map.put("角色名称", role.getName());
map.put("角色级别", role.getLevel());
map.put("描述", role.getDescription());
map.put("创建日期", role.getCreate_time());
// map.put("创建日期", role.getCreateTime());
list.add(map);
}
FileUtil.downloadExcel(list, response);
}
@Override
public void verification(Set<String> ids) {
/*if (userRepository.countByRoles(ids) > 0) {
public void verification(Set<Long> ids) {
if (userRepository.countByRoles(ids) > 0) {
throw new BadRequestException("所选角色存在用户关联,请解除关联再试!");
}*/
}
}
@Override
@@ -228,7 +226,7 @@ public class RoleServiceImpl implements RoleService {
users = CollectionUtil.isEmpty(users) ? userRepository.findByRoleId(id) : users;
if (CollectionUtil.isNotEmpty(users)) {
// 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.MENU_USER, userIds);
redisUtils.delByKeys(CacheKey.ROLE_AUTH, userIds);