提交 85775c86 编写于 作者: Exrick's avatar Exrick

[UPDATE]3.2

上级 3cf6c3a4
......@@ -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>
......@@ -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>
......@@ -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>
......@@ -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>
......
......@@ -42,7 +42,7 @@ public class RedisRaterLimiter {
getToken = rateLimiter.tryAcquire();
rateLimiter.expireAsync(rateInterval * 2, TimeUnit.MILLISECONDS);
} catch (Exception e) {
getToken = false;
getToken = true;
}
return getToken;
}
......
......@@ -107,7 +107,11 @@ public class DepartmentController {
@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());
......@@ -128,14 +132,23 @@ public class DepartmentController {
}
// 批量保存
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("编辑成功");
}
......@@ -147,9 +160,9 @@ public class DepartmentController {
deleteRecursion(id, ids);
}
// 手动删除所有部门缓存
redisTemplate.deleteByPattern("department:" + "*");
redisTemplate.deleteByPattern("department:*");
// 删除数据权限缓存
redisTemplate.deleteByPattern("userRole::depIds:" + "*");
redisTemplate.deleteByPattern("userRole::depIds:*");
return ResultUtil.success("批量通过id删除数据成功");
}
......
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;
......@@ -25,10 +27,7 @@ import org.springframework.cache.annotation.CacheConfig;
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;
......@@ -134,17 +133,31 @@ public class PermissionController {
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());
......@@ -152,11 +165,19 @@ public class PermissionController {
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);
}
......@@ -164,6 +185,9 @@ public class PermissionController {
@ApiOperation(value = "编辑")
public Result<Permission> edit(Permission permission) {
if (permission.getId().equals(permission.getParentId())) {
return ResultUtil.error("上级节点不能为自己");
}
// 判断拦截请求的操作权限按钮名是否已存在
if (CommonConstant.PERMISSION_OPERATION.equals(permission.getType())) {
// 若名称修改
......@@ -171,18 +195,28 @@ public class PermissionController {
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)
......@@ -191,21 +225,45 @@ public class PermissionController {
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) {
......@@ -213,4 +271,14 @@ public class PermissionController {
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("一级菜单");
}
}
}
......@@ -107,9 +107,9 @@ public class RoleController {
}).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);
}
......@@ -135,8 +135,8 @@ public class RoleController {
}
}
// 手动删除相关缓存
redisTemplate.deleteByPattern("department:" + "*");
redisTemplate.deleteByPattern("userRole:" + "*");
redisTemplate.deleteByPattern("department:*");
redisTemplate.deleteByPattern("userRole:*");
return ResultUtil.data(null);
}
......@@ -155,8 +155,8 @@ public class RoleController {
Role r = roleService.update(entity);
// 手动批量删除缓存
redisTemplate.deleteByPattern("user:" + "*");
redisTemplate.deleteByPattern("userRole:" + "*");
redisTemplate.deleteByPattern("user:*");
redisTemplate.deleteByPattern("userRole:*");
return new ResultUtil<Role>().setData(r);
}
......@@ -179,5 +179,4 @@ public class RoleController {
}
return ResultUtil.success("批量通过id删除数据成功");
}
}
......@@ -35,6 +35,7 @@ public class Department extends XbootBaseEntity {
private String title;
@ApiModelProperty(value = "父id")
@Column(nullable = false)
private String parentId;
@ApiModelProperty(value = "是否为父节点(含子节点) 默认false")
......
......@@ -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;
......@@ -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 = "节点展开 前端所需")
......
......@@ -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:
......
___________ .__ __
\_ _____/__ __________|__| ____ | | __
| __)_\ \/ /\_ __ \ |/ ___\| |/ /
| \> < | | \/ \ \___| <
/_______ /__/\_ \ |__| |__|\___ >__|_ \
\/ \/ \/ \/
\ No newline at end of file
____ _____________ __
\ \/ /\______ \ ____ ____ _/ |_
\ / | | _/ / _ \ / _ \ \ __\
/ \ | | \( <_> )( <_> ) | |
/___/\ \ |______ / \____/ \____/ |__|
\_/ \/
v3.2.0 By Exrick :: Spring Boot v2.3.7.RELEASE
\ No newline at end of file
......@@ -42,6 +42,7 @@ public class ${entity.className} extends XbootBaseEntity {
private String title;
@ApiModelProperty(value = "父id")
@Column(nullable = false)
private String parentId;
@ApiModelProperty(value = "是否为父节点(含子节点) 默认false")
......
......@@ -69,9 +69,23 @@ public class ${entity.className}Controller {
@ApiOperation(value = "编辑")
public Result<Object> edit(${entity.className} ${entity.classNameLowerCase}) {
if (${entity.classNameLowerCase}.getId().equals(${entity.classNameLowerCase}.getParentId())) {
return ResultUtil.error("上级节点不能为自己");
}
${entity.className} old = ${entity.classNameLowerCase}Service.get(${entity.classNameLowerCase}.getId());
String oldParentId = old.getParentId();
${entity.classNameLowerCase}Service.update(${entity.classNameLowerCase});
// 如果该节点不是一级节点 且修改了级别 判断上级还有无子节点
if (!"0".equals(oldParentId) && !oldParentId.equals(${entity.classNameLowerCase}.getParentId())) {
${entity.className} parent = ${entity.classNameLowerCase}Service.get(oldParentId);
List<${entity.className}> children = ${entity.classNameLowerCase}Service.findByParentIdOrderBySortOrder(parent.getId());
if (parent != null && (children == null || children.isEmpty())) {
parent.setIsParent(false);
${entity.classNameLowerCase}Service.update(parent);
}
}
// 手动删除所有分类缓存
redisTemplate.deleteByPattern("${entity.classNameLowerCase}:" + "*");
redisTemplate.deleteByPattern("${entity.classNameLowerCase}:*");
return ResultUtil.success("编辑成功");
}
......@@ -83,7 +97,7 @@ public class ${entity.className}Controller {
deleteRecursion(id, ids);
}
// 手动删除所有缓存
redisTemplate.deleteByPattern("${entity.classNameLowerCase}:" + "*");
redisTemplate.deleteByPattern("${entity.classNameLowerCase}:*");
return ResultUtil.success("批量通过id删除数据成功");
}
......
......@@ -70,9 +70,23 @@ public class ${entity.className}Controller {
@ApiOperation(value = "编辑")
public Result<Object> edit(${entity.className} ${entity.classNameLowerCase}) {
if (${entity.classNameLowerCase}.getId().equals(${entity.classNameLowerCase}.getParentId())) {
return ResultUtil.error("上级节点不能为自己");
}
${entity.className} old = i${entity.className}Service.getById(${entity.classNameLowerCase}.getId());
String oldParentId = old.getParentId();
i${entity.className}Service.updateById(${entity.classNameLowerCase});
// 如果该节点不是一级节点 且修改了级别 判断上级还有无子节点
if (!"0".equals(oldParentId) && !oldParentId.equals(${entity.classNameLowerCase}.getParentId())) {
${entity.className} parent = i${entity.className}Service.getById(oldParentId);
List<${entity.className}> children = iStudentService.list(new QueryWrapper<Student>().eq("parent_id", parent.getIsParent()));
if (parent != null && (children == null || children.isEmpty())) {
parent.setIsParent(false);
i${entity.className}Service.updateById(parent);
}
}
// 手动删除所有分类缓存
redisTemplate.deleteByPattern("${entity.classNameLowerCase}:" + "*");
redisTemplate.deleteByPattern("${entity.classNameLowerCase}:*");
return ResultUtil.success("编辑成功");
}
......@@ -84,7 +98,7 @@ public class ${entity.className}Controller {
deleteRecursion(id, ids);
}
// 手动删除所有缓存
redisTemplate.deleteByPattern("${entity.classNameLowerCase}:" + "*");
redisTemplate.deleteByPattern("${entity.classNameLowerCase}:*");
return ResultUtil.success("批量通过id删除数据成功");
}
......
......@@ -22,7 +22,7 @@
<maven.compiler.target>1.8</maven.compiler.target>
<encoding>UTF-8</encoding>
<!-- 依赖包版本 -->
<spring.boot.version>2.3.6.RELEASE</spring.boot.version>
<spring.boot.version>2.3.7.RELEASE</spring.boot.version>
<spring.boot.admin.version>2.3.1</spring.boot.admin.version>
<druid.version>1.2.3</druid.version>
<jjwt.version>0.9.1</jjwt.version>
......@@ -31,16 +31,16 @@
<redission.version>3.14.0</redission.version>
<knife4j.version>2.0.8</knife4j.version>
<gson.version>2.8.6</gson.version>
<hutool.version>5.5.1</hutool.version>
<hutool.version>5.5.2</hutool.version>
<lombok.version>1.18.16</lombok.version>
<jasypt.version>3.0.3</jasypt.version>
<beetl.version>2.9.10</beetl.version>
<antlr.version>4.8</antlr.version>
<qiniu.version>7.3.0</qiniu.version>
<qiniu.version>7.4.0</qiniu.version>
<guava.version>30.0-jre</guava.version>
<!-- 测试 -->
<extentreports.testng.version>1.2.2</extentreports.testng.version>
<selenuim.version>4.0.0-alpha-6</selenuim.version>
<selenuim.version>4.0.0-alpha-7</selenuim.version>
</properties>
<dependencyManagement>
......
......@@ -98,25 +98,29 @@ 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限制30个请求
limit: 30
# 每个ip限制20个请求(单位个)
limit: 20
# 后台token交互方式
token:
# 默认为true,token将存入redis,并具有单点登录功能 设为false使用JWT交互
......
___________ .__ __
\_ _____/__ __________|__| ____ | | __
| __)_\ \/ /\_ __ \ |/ ___\| |/ /
| \> < | | \/ \ \___| <
/_______ /__/\_ \ |__| |__|\___ >__|_ \
\/ \/ \/ \/
\ No newline at end of file
____ _____________ __
\ \/ /\______ \ ____ ____ _/ |_
\ / | | _/ / _ \ / _ \ \ __\
/ \ | | \( <_> )( <_> ) | |
/___/\ \ |______ / \____/ \____/ |__|
\_/ \/
v3.2.0 By Exrick :: Spring Boot v2.3.7.RELEASE
\ No newline at end of file
......@@ -42,7 +42,7 @@ public class RedisRaterLimiter {
getToken = rateLimiter.tryAcquire();
rateLimiter.expireAsync(rateInterval * 2, TimeUnit.MILLISECONDS);
} catch (Exception e) {
getToken = false;
getToken = true;
}
return getToken;
}
......
......@@ -35,6 +35,7 @@ public class Department extends XbootBaseEntity {
private String title;
@ApiModelProperty(value = "父id")
@Column(nullable = false)
private String parentId;
@ApiModelProperty(value = "是否为父节点(含子节点) 默认false")
......
......@@ -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;
......@@ -87,6 +91,11 @@ public class Permission extends XbootBaseEntity {