角色修改&&去除缓存

This commit is contained in:
ludj
2022-12-05 14:38:16 +08:00
parent 7c3f1075be
commit 8d182add61
12 changed files with 73 additions and 117 deletions

View File

@@ -7,14 +7,12 @@ import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.nl.modules.logging.annotation.Log;
import org.nl.modules.system.domain.Role;
import org.nl.modules.system.domain.vo.RoleVo;
import org.nl.modules.system.service.RoleService;
import org.nl.modules.wql.core.bean.WQLObject;
import org.springframework.data.domain.Pageable;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import java.util.List;
@@ -22,8 +20,8 @@ import java.util.Map;
import java.util.Set;
/**
* @author Zheng Jie
* @date 2018-12-03
* @author ludj
* @date 2022-12-05
*/
@RestController
@RequiredArgsConstructor
@@ -33,14 +31,6 @@ public class RoleController {
private final RoleService roleService;
private static final String ENTITY_NAME = "role";
@ApiOperation("获取单个role")
@GetMapping(value = "/{id}")
@SaCheckPermission("roles:list")
public ResponseEntity<Object> query(@PathVariable Long id) {
return new ResponseEntity<>(roleService.findById(id), HttpStatus.OK);
}
@ApiOperation("获取单个role")
@GetMapping(value = "/all")
@@ -61,28 +51,27 @@ public class RoleController {
@Log("新增角色")
@ApiOperation("新增角色")
@PostMapping
@SaCheckPermission("roles:add")
public ResponseEntity<Object> create(@Validated @RequestBody Role resources) {
// roleService.create(resources);
// @SaCheckPermission("roles:add")
public ResponseEntity<Object> create(@RequestBody JSONObject param) {
roleService.create(param);
return new ResponseEntity<>(HttpStatus.CREATED);
}
/* @Log("修改角色")
@ApiOperation("修改角色")
@PutMapping
@SaCheckPermission("roles:edit")
public ResponseEntity<Object> update(@Validated(Role.Update.class) @RequestBody Role resources) {
getLevels(resources.getLevel());
roleService.update(resources);
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
}
*/
@Log("修改角色")
@ApiOperation("修改角色")
@PutMapping
// @SaCheckPermission("roles:edit")
public ResponseEntity<Object> update(@RequestBody JSONObject param) {
roleService.update(param);
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
}
@Log("修改角色菜单")
@ApiOperation("修改角色菜单")
@PutMapping(value = "/menu")
// @SaCheckPermission("roles:edit")
public ResponseEntity<Object> updateMenu(@RequestBody JSONObject form) {
String role_id = form.getString("id");
String role_id = form.getString("role_id");
JSONArray menus = form.getJSONArray("menus");
WQLObject rmTab = WQLObject.getWQLObject("sys_roles_menus");
rmTab.delete("role_id = " + role_id + "");

View File

@@ -51,8 +51,6 @@ public interface RoleService {
*/
<T> List<T> findRoles(Long id, Class<T>target);
RoleDto findById(Long id);
/**
* 创建
* @param form /
@@ -61,9 +59,9 @@ public interface RoleService {
/**
* 编辑
* @param resources /
* @param form /
*/
void update(Role resources);
void update(JSONObject form);
/**
* 删除
@@ -78,12 +76,7 @@ public interface RoleService {
*/
List<RoleSmallDto> findByUsersId(Long id);
/**
* 根据角色查询角色级别
* @param roles /
* @return /
*/
Integer findByRoles(Set<Role> roles);
/**
* 修改绑定的菜单
@@ -97,20 +90,6 @@ public interface RoleService {
* @param id /
*/
void untiedMenu(Long id);
/**
* 查询全部
* @param criteria 条件
* @return /
*/
List<RoleDto> queryAll(RoleQueryCriteria criteria);
/**
* 获取用户权限信息
* @param user 用户信息
* @return 权限信息
*/
// List<String> mapToGrantedAuthorities(UserDto user);
/**
* 通过id获取用户的权限
@@ -119,6 +98,4 @@ public interface RoleService {
*/
List<String> getPermissionList(JSONObject userDto);
}

View File

@@ -15,21 +15,19 @@
*/
package org.nl.modules.system.service.impl;
import cn.hutool.core.util.ObjectUtil;
import lombok.RequiredArgsConstructor;
import org.nl.modules.common.utils.enums.DataScopeEnum;
import org.nl.modules.system.domain.Dept;
import org.nl.modules.system.domain.User;
import org.nl.modules.system.service.DataService;
import org.nl.modules.system.service.DeptService;
import org.nl.modules.system.service.RoleService;
import org.nl.modules.system.service.dto.RoleSmallDto;
import org.nl.modules.system.service.dto.UserDto;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import java.util.*;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
/**
* @author Zheng Jie
@@ -51,7 +49,6 @@ public class DataServiceImpl implements DataService {
* @return /
*/
@Override
@Cacheable(key = "'user:' + #p0.id")
public List<Long> getDeptIds(User user) {
// 用于存储部门id
Set<Long> deptIds = new HashSet<>();

View File

@@ -32,7 +32,6 @@ import org.nl.modules.wql.WQL;
import org.nl.modules.wql.core.bean.WQLObject;
import org.nl.modules.wql.util.WqlUtil;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@@ -116,7 +115,6 @@ public class DictDetailServiceImpl implements DictDetailService {
}
@Override
@Cacheable(key = "'name:' + #p0")
public List<DictDto> getDictByName(String name) {
List<DictDto> dictDtos = this.findByDictName(name);
return dictDtos;

View File

@@ -101,7 +101,6 @@ public class MenuServiceImpl implements MenuService {
@Override
// @Cacheable(key = "'id:' + #p0")
public MenuDto findById(String id) {
WQLObject menuTab = WQLObject.getWQLObject("sys_menu");
JSONObject json = menuTab.query("menu_id = '" + id + "'").uniqueResult(0);
@@ -115,7 +114,6 @@ public class MenuServiceImpl implements MenuService {
* @return /
*/
@Override
// @Cacheable(key = "'user:' + #p0")
public List<MenuDto> findByUser(String currentUserId) {
JSONArray arr = WQL.getWO("QSYS_MENU01").addParam("flag", "4").addParam("user_id", String.valueOf(currentUserId)).process().getResultJSONArray(0);
List<MenuDto> list = new ArrayList<>();

View File

@@ -15,11 +15,15 @@
*/
package org.nl.modules.system.service.impl;
import cn.dev33.satoken.stp.StpUtil;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import lombok.RequiredArgsConstructor;
import org.nl.modules.common.exception.BadRequestException;
import org.nl.modules.common.utils.CacheKey;
import org.nl.modules.common.utils.RedisUtils;
import org.nl.modules.common.utils.SecurityUtils;
@@ -29,14 +33,12 @@ 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.tools.MapOf;
import org.nl.modules.wql.WQL;
import org.nl.modules.wql.core.bean.ResultBean;
import org.nl.modules.wql.core.bean.WQLObject;
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.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@@ -45,8 +47,8 @@ import java.util.*;
import java.util.stream.Collectors;
/**
* @author Zheng Jie
* @date 2018-12-03
* @author ludj
* @date 2022-12-05
*/
@Service
@RequiredArgsConstructor
@@ -72,34 +74,30 @@ public class RoleServiceImpl implements RoleService {
}
@Override
public List<RoleDto> queryAll(RoleQueryCriteria criteria) {
return null;
}
@Override
@Cacheable(key = "'id:' + #p0")
@Transactional(rollbackFor = Exception.class)
public <T> List<T> findRoles(Long id,Class<T> target) {
public <T> List<T> findRoles(Long id, Class<T> target) {
String sql = "is_used = '1' and is_delete = '0' ";
if (id != null){
sql=sql+"role_id = '"+id+"'";
if (id != null) {
sql = sql + "role_id = '" + id + "'";
}
JSONArray array = WQLObject.getWQLObject("sys_role").query(sql).getResultJSONArray(0);
return array.toJavaList(target);
return array.toJavaList(target);
}
@Override
public RoleDto findById(Long id) {
return null;
}
@Override
@Transactional(rollbackFor = Exception.class)
public void create(JSONObject form) {
//角色表【sys_role】
//判断角色名字是否存在
String name = form.getString("name");
if (StrUtil.isEmpty(name)) throw new BadRequestException("角色名字不能为空!");
WQLObject roleTab = WQLObject.getWQLObject("sys_role");
//判断角色名字是否存在
JSONObject json = roleTab.query("name = '" + name + "'").uniqueResult(0);
if (ObjectUtil.isNotEmpty(json)) throw new BadRequestException("角色【" + name + "】已存在!");
String role_id = IdUtil.getStringId();
form.put("role_id", role_id);
form.put("create_id", SecurityUtils.getCurrentUserId());
@@ -114,8 +112,22 @@ public class RoleServiceImpl implements RoleService {
@Override
@Transactional(rollbackFor = Exception.class)
public void update(Role resources) {
public void update(JSONObject form) {
WQLObject roleTab = WQLObject.getWQLObject("sys_role");
//判断角色名字是否存在
String name = form.getString("name");
if (StrUtil.isEmpty(name)) throw new BadRequestException("角色名字不能为空!");
JSONObject json = roleTab.query("name = '" + name + "' and role_id <> '" + form.getString("role_id") + "'").uniqueResult(0);
if (ObjectUtil.isNotEmpty(json)) throw new BadRequestException("角色【" + name + "】已存在!");
String now = DateUtil.now();
form.put("update_id", StpUtil.getLoginIdAsLong());
form.put("update_time", now);
form.put("update_optname", SecurityUtils.getCurrentNickName());
roleTab.update(form);
}
@Override
@@ -142,20 +154,11 @@ public class RoleServiceImpl implements RoleService {
@Override
public List<RoleSmallDto> findByUsersId(Long id) {
return null;
return null;
}
@Override
public Integer findByRoles(Set<Role> roles) {
Set<RoleDto> roleDtos = new HashSet<>();
for (Role role : roles) {
roleDtos.add(findById(role.getId()));
}
return Collections.min(roleDtos.stream().map(RoleDto::getLevel).collect(Collectors.toList()));
}
@Override
// @Cacheable(key = "'auth:' + #p0.id")
public List<String> getPermissionList(JSONObject userDto) {
List<String> permission = new LinkedList<>();
// 查看是否为管理员

View File

@@ -22,21 +22,22 @@ import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.serializer.SerializeConfig;
import lombok.RequiredArgsConstructor;
import lombok.SneakyThrows;
import org.apache.commons.lang3.StringUtils;
import org.nl.modules.common.config.FileProperties;
import org.nl.modules.common.exception.EntityExistException;
import org.nl.modules.common.exception.EntityNotFoundException;
import org.nl.modules.common.utils.*;
import org.nl.modules.common.utils.CacheKey;
import org.nl.modules.common.utils.FileUtil;
import org.nl.modules.common.utils.RedisUtils;
import org.nl.modules.common.utils.SecurityUtils;
import org.nl.modules.common.utils.dto.CurrentUser;
import org.nl.modules.security.service.OnlineUserService;
import org.nl.modules.system.domain.User;
import org.nl.modules.system.service.DeptService;
import org.nl.modules.system.service.UserRelateService;
import org.nl.modules.system.service.UserService;
import org.nl.modules.system.service.dto.UserQueryCriteria;
import org.nl.modules.tools.MapOf;
import org.nl.modules.wql.WQL;
@@ -44,17 +45,13 @@ import org.nl.modules.wql.core.bean.ResultBean;
import org.nl.modules.wql.core.bean.WQLObject;
import org.nl.modules.wql.util.WqlUtil;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.NotBlank;
import java.io.File;
import java.io.IOException;
import java.util.*;
import java.util.stream.Collectors;
@@ -124,7 +121,6 @@ public class UserServiceImpl implements UserService {
}
@Override
@Cacheable(key = "'id:' + #p0")
@Transactional(rollbackFor = Exception.class)
public User findById(long id) {
JSONObject result = WQLObject.getWQLObject("sys_user").query("user_id = '" + id + "'").uniqueResult(0);
@@ -228,7 +224,6 @@ public class UserServiceImpl implements UserService {
}
@Override
@Cacheable(key = "'username:' + #p0")
public User findByName(String userName) {
JSONObject result = WQLObject.getWQLObject("sys_user").query("userName = '" + userName + "'").uniqueResult(0);
if (result == null) {