Skip to content

Commit

Permalink
[UPDATE]3.2
Browse files Browse the repository at this point in the history
  • Loading branch information
Exrick committed Dec 13, 2020
1 parent 3cf6c3a commit 85775c8
Show file tree
Hide file tree
Showing 25 changed files with 785 additions and 520 deletions.
8 changes: 4 additions & 4 deletions xboot-fast/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.3.6.RELEASE</version>
<version>2.3.7.RELEASE</version>
</parent>

<properties>
Expand Down Expand Up @@ -129,7 +129,7 @@
<dependency>
<groupId>cn.hutool</groupId>
<artifactId>hutool-all</artifactId>
<version>5.5.1</version>
<version>5.5.2</version>
</dependency>
<!-- Lombok -->
<dependency>
Expand All @@ -141,7 +141,7 @@
<dependency>
<groupId>com.qiniu</groupId>
<artifactId>qiniu-java-sdk</artifactId>
<version>7.3.0</version>
<version>7.4.0</version>
</dependency>
<!-- Jasypt加密 -->
<dependency>
Expand Down Expand Up @@ -200,7 +200,7 @@
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>2.3.6.RELEASE</version>
<version>2.3.7.RELEASE</version>
</plugin>
</plugins>
</build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public Boolean acquireByRedis(String name, Long rate, Long rateInterval) {
getToken = rateLimiter.tryAcquire();
rateLimiter.expireAsync(rateInterval * 2, TimeUnit.MILLISECONDS);
} catch (Exception e) {
getToken = false;
getToken = true;
}
return getToken;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,11 @@ public Result<Object> edit(Department department,
@RequestParam(required = false) String[] mainHeader,
@RequestParam(required = false) String[] viceHeader) {

if (department.getId().equals(department.getParentId())) {
return ResultUtil.error("上级节点不能为自己");
}
Department old = departmentService.get(department.getId());
String oldParentId = old.getParentId();
Department d = departmentService.update(department);
// 先删除原数据
departmentHeaderService.deleteByDepartmentId(department.getId());
Expand All @@ -128,14 +132,23 @@ public Result<Object> edit(Department department,
}
// 批量保存
departmentHeaderService.saveOrUpdateAll(headers);
// 如果该节点不是一级节点 且修改了级别 判断上级还有无子节点
if (!"0".equals(oldParentId) && !oldParentId.equals(department.getParentId())) {
Department parent = departmentService.get(oldParentId);
List<Department> children = departmentService.findByParentIdOrderBySortOrder(parent.getId(), false);
if (parent != null && (children == null || children.isEmpty())) {
parent.setIsParent(false);
departmentService.update(parent);
}
}
// 若修改了部门名称
if (!old.getTitle().equals(department.getTitle())) {
userService.updateDepartmentTitle(department.getId(), department.getTitle());
// 删除所有用户缓存
redisTemplate.deleteByPattern("user:" + "*");
redisTemplate.deleteByPattern("user:*");
}
// 手动删除所有部门缓存
redisTemplate.deleteByPattern("department:" + "*");
redisTemplate.deleteByPattern("department:*");
return ResultUtil.success("编辑成功");
}

Expand All @@ -147,9 +160,9 @@ public Result<Object> delByIds(@RequestParam String[] ids) {
deleteRecursion(id, ids);
}
// 手动删除所有部门缓存
redisTemplate.deleteByPattern("department:" + "*");
redisTemplate.deleteByPattern("department:*");
// 删除数据权限缓存
redisTemplate.deleteByPattern("userRole::depIds:" + "*");
redisTemplate.deleteByPattern("userRole::depIds:*");
return ResultUtil.success("批量通过id删除数据成功");
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package cn.exrick.xboot.modules.base.controller.manage;

import cn.exrick.xboot.common.constant.CommonConstant;
import cn.exrick.xboot.common.exception.XbootException;
import cn.exrick.xboot.common.redis.RedisTemplateHelper;
import cn.exrick.xboot.common.utils.CommonUtil;
import cn.exrick.xboot.common.utils.ResultUtil;
import cn.exrick.xboot.common.utils.SecurityUtil;
import cn.exrick.xboot.common.vo.Result;
Expand All @@ -25,10 +27,7 @@
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;

import java.util.Comparator;
import java.util.List;
Expand Down Expand Up @@ -134,55 +133,90 @@ private void getAllByRecursion(List<Permission> curr, List<Permission> list) {
List<Permission> children = list.stream().filter(p -> (e.getId()).equals(p.getParentId()))
.sorted(Comparator.comparing(Permission::getSortOrder)).collect(Collectors.toList());
e.setChildren(children);
setInfo(e);
if (e.getLevel() < 3) {
getAllByRecursion(children, list);
}
});
}

@RequestMapping(value = "/getByParentId/{parentId}", method = RequestMethod.GET)
@ApiOperation(value = "通过id获取")
@Cacheable(key = "#parentId")
public Result<List<Permission>> getByParentId(@PathVariable String parentId) {

List<Permission> list = permissionService.findByParentIdOrderBySortOrder(parentId);
list.forEach(e -> setInfo(e));
return ResultUtil.data(list);
}

@RequestMapping(value = "/add", method = RequestMethod.POST)
@ApiOperation(value = "添加")
@CacheEvict(key = "'menuList'")
public Result<Permission> add(Permission permission) {

if (permission.getId().equals(permission.getParentId())) {
return ResultUtil.error("上级节点不能为自己");
}
// 判断拦截请求的操作权限按钮名是否已存在
if (CommonConstant.PERMISSION_OPERATION.equals(permission.getType())) {
List<Permission> list = permissionService.findByTitle(permission.getTitle());
if (list != null && list.size() > 0) {
return new ResultUtil<Permission>().setErrorMsg("名称已存在");
}
}
// 如果不是添加的一级 判断设置上级为父节点标识
if (!CommonConstant.PARENT_ID.equals(permission.getParentId())) {
Permission parent = permissionService.get(permission.getParentId());
if (parent.getIsParent() == null || !parent.getIsParent()) {
parent.setIsParent(true);
permissionService.update(parent);
}
}
Permission u = permissionService.save(permission);
//重新加载权限
// 重新加载权限
mySecurityMetadataSource.loadResourceDefine();
//手动删除缓存
redisTemplate.delete("permission::allList");
// 手动删除缓存
redisTemplate.deleteByPattern("permission:*");
return new ResultUtil<Permission>().setData(u);
}

@RequestMapping(value = "/edit", method = RequestMethod.POST)
@ApiOperation(value = "编辑")
public Result<Permission> edit(Permission permission) {

if (permission.getId().equals(permission.getParentId())) {
return ResultUtil.error("上级节点不能为自己");
}
// 判断拦截请求的操作权限按钮名是否已存在
if (CommonConstant.PERMISSION_OPERATION.equals(permission.getType())) {
// 若名称修改
Permission p = permissionService.get(permission.getId());
if (!p.getTitle().equals(permission.getTitle())) {
List<Permission> list = permissionService.findByTitle(permission.getTitle());
if (list != null && list.size() > 0) {
return new ResultUtil<Permission>().setErrorMsg("名称已存在");
return ResultUtil.error("名称已存在");
}
}
}
Permission old = permissionService.get(permission.getId());
String oldParentId = old.getParentId();
Permission u = permissionService.update(permission);
// 如果该节点不是一级节点 且修改了级别 判断上级还有无子节点
if (!CommonConstant.PARENT_ID.equals(oldParentId) && !oldParentId.equals(permission.getParentId())) {
Permission parent = permissionService.get(oldParentId);
List<Permission> children = permissionService.findByParentIdOrderBySortOrder(parent.getId());
if (parent != null && (children == null || children.isEmpty())) {
parent.setIsParent(false);
permissionService.update(parent);
}
}
// 重新加载权限
mySecurityMetadataSource.loadResourceDefine();
// 手动批量删除缓存
redisTemplate.deleteByPattern("user:" + "*");
redisTemplate.deleteByPattern("permission::userMenuList:*");
redisTemplate.delete("permission::allList");
return new ResultUtil<Permission>().setData(u);
redisTemplate.deleteByPattern("user:*");
redisTemplate.deleteByPattern("permission:*");
return ResultUtil.data(u);
}

@RequestMapping(value = "/delByIds", method = RequestMethod.POST)
Expand All @@ -191,26 +225,60 @@ public Result<Permission> edit(Permission permission) {
public Result<Object> delByIds(@RequestParam String[] ids) {

for (String id : ids) {
List<RolePermission> list = rolePermissionService.findByPermissionId(id);
if (list != null && list.size() > 0) {
return ResultUtil.error("删除失败,包含正被角色使用关联的菜单或权限");
}
}
for (String id : ids) {
permissionService.delete(id);
deleteRecursion(id, ids);
}
// 重新加载权限
mySecurityMetadataSource.loadResourceDefine();
// 手动删除缓存
redisTemplate.delete("permission::allList");
redisTemplate.deleteByPattern("permission:*");
return ResultUtil.success("批量通过id删除数据成功");
}

public void deleteRecursion(String id, String[] ids) {

List<RolePermission> list = rolePermissionService.findByPermissionId(id);
if (list != null && list.size() > 0) {
throw new XbootException("删除失败,包含正被用户使用关联的部门");
}
// 获得其父节点
Permission p = permissionService.get(id);
Permission parent = null;
if (p != null && StrUtil.isNotBlank(p.getParentId())) {
parent = permissionService.get(p.getParentId());
}
permissionService.delete(id);
// 判断父节点是否还有子节点
if (parent != null) {
List<Permission> children = permissionService.findByParentIdOrderBySortOrder(parent.getId());
if (children == null || children.isEmpty()) {
parent.setIsParent(false);
permissionService.update(parent);
}
}
// 递归删除
List<Permission> permissions = permissionService.findByParentIdOrderBySortOrder(id);
for (Permission pe : permissions) {
if (!CommonUtil.judgeIds(pe.getId(), ids)) {
deleteRecursion(pe.getId(), ids);
}
}
}

@RequestMapping(value = "/search", method = RequestMethod.GET)
@ApiOperation(value = "搜索菜单")
public Result<List<Permission>> searchPermissionList(@RequestParam String title) {

List<Permission> list = permissionService.findByTitleLikeOrderBySortOrder("%" + title + "%");
return new ResultUtil<List<Permission>>().setData(list);
}

public void setInfo(Permission permission) {

if (!CommonConstant.PARENT_ID.equals(permission.getParentId())) {
Permission parent = permissionService.get(permission.getParentId());
permission.setParentTitle(parent.getTitle());
} else {
permission.setParentTitle("一级菜单");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,9 @@ public Result<Object> editRolePerm(@RequestParam String roleId,
}).collect(Collectors.toList());
rolePermissionService.saveOrUpdateAll(list);
}
//手动批量删除缓存
redisTemplate.deleteByPattern("user:" + "*");
redisTemplate.deleteByPattern("userRole:" + "*");
// 手动批量删除缓存
redisTemplate.deleteByPattern("user:*");
redisTemplate.deleteByPattern("userRole:*");
redisTemplate.deleteByPattern("permission::userMenuList:*");
return ResultUtil.data(null);
}
Expand All @@ -135,8 +135,8 @@ public Result<Object> editRoleDep(@RequestParam String roleId,
}
}
// 手动删除相关缓存
redisTemplate.deleteByPattern("department:" + "*");
redisTemplate.deleteByPattern("userRole:" + "*");
redisTemplate.deleteByPattern("department:*");
redisTemplate.deleteByPattern("userRole:*");

return ResultUtil.data(null);
}
Expand All @@ -155,8 +155,8 @@ public Result<Role> edit(Role entity) {

Role r = roleService.update(entity);
// 手动批量删除缓存
redisTemplate.deleteByPattern("user:" + "*");
redisTemplate.deleteByPattern("userRole:" + "*");
redisTemplate.deleteByPattern("user:*");
redisTemplate.deleteByPattern("userRole:*");
return new ResultUtil<Role>().setData(r);
}

Expand All @@ -179,5 +179,4 @@ public Result<Object> delByIds(@RequestParam String[] ids) {
}
return ResultUtil.success("批量通过id删除数据成功");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public class Department extends XbootBaseEntity {
private String title;

@ApiModelProperty(value = "父id")
@Column(nullable = false)
private String parentId;

@ApiModelProperty(value = "是否为父节点(含子节点) 默认false")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,12 @@ public class Permission extends XbootBaseEntity {
private String description;

@ApiModelProperty(value = "父id")
@Column(nullable = false)
private String parentId;

@ApiModelProperty(value = "是否为父节点(含子节点) 默认false")
private Boolean isParent = false;

@ApiModelProperty(value = "排序值")
@Column(precision = 10, scale = 2)
private BigDecimal sortOrder;
Expand All @@ -87,6 +91,11 @@ public class Permission extends XbootBaseEntity {
@ApiModelProperty(value = "页面拥有的权限类型")
private List<String> permTypes;

@Transient
@TableField(exist = false)
@ApiModelProperty(value = "父节点名称")
private String parentTitle;

@Transient
@TableField(exist = false)
@ApiModelProperty(value = "节点展开 前端所需")
Expand Down
12 changes: 8 additions & 4 deletions xboot-fast/src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -97,24 +97,28 @@ spring:
# 修改上下文路径
context-path: /xboot/admin
client:
# 服务端url
url: http://127.0.0.1:${server.port}/xboot/admin
instance:
# 实例url
service-base-url: http://127.0.0.1:${server.port}/

xboot:
# 全局限流
ratelimit:
# 开启
enable: true
# 每1秒内
# 每1秒内(单位毫秒)
timeout: 1000
# 总限制200个请求
# 总限制200个请求(单位个)
limit: 200
# IP限流
iplimit:
# 开启
enable: true
# 每1秒内
# 每1秒内(单位毫秒)
timeout: 1000
# 每个ip限制20个请求
# 每个ip限制20个请求(单位个)
limit: 20
# token交互方式
token:
Expand Down
Loading

0 comments on commit 85775c8

Please sign in to comment.