From 6b9ad96023005f239e2306f736684a385a1f9ff6 Mon Sep 17 00:00:00 2001 From: fit2cloud-chenyw Date: Wed, 13 Jul 2022 11:11:48 +0800 Subject: [PATCH] =?UTF-8?q?perf(=E7=B3=BB=E7=BB=9F=E7=AE=A1=E7=90=86):=20?= =?UTF-8?q?=E4=BC=98=E5=8C=96=E7=BB=84=E7=BB=87=E7=AE=A1=E7=90=86=E9=80=82?= =?UTF-8?q?=E9=85=8D=E6=96=B0=E7=89=88ui?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dataease/plugins/server/XDeptServer.java | 54 +++++++++++++++++-- .../dataease/plugins/server/XRoleServer.java | 10 ++++ 2 files changed, 61 insertions(+), 3 deletions(-) diff --git a/backend/src/main/java/io/dataease/plugins/server/XDeptServer.java b/backend/src/main/java/io/dataease/plugins/server/XDeptServer.java index 1f74bfa203..eed3a3d7b2 100644 --- a/backend/src/main/java/io/dataease/plugins/server/XDeptServer.java +++ b/backend/src/main/java/io/dataease/plugins/server/XDeptServer.java @@ -1,23 +1,33 @@ package io.dataease.plugins.server; +import cn.hutool.core.collection.CollectionUtil; +import com.github.pagehelper.Page; +import com.github.pagehelper.PageHelper; import io.dataease.auth.annotation.DeLog; import io.dataease.auth.service.ExtAuthService; +import io.dataease.commons.constants.AuthConstants; import io.dataease.commons.constants.SysLogConstants; +import io.dataease.commons.exception.DEException; import io.dataease.commons.utils.BeanUtils; +import io.dataease.commons.utils.PageUtils; +import io.dataease.commons.utils.Pager; import io.dataease.controller.sys.response.DeptNodeResponse; +import io.dataease.listener.util.CacheUtils; import io.dataease.plugins.common.entity.XpackGridRequest; import io.dataease.plugins.config.SpringContextUtil; -import io.dataease.plugins.xpack.dept.dto.request.XpackCreateDept; -import io.dataease.plugins.xpack.dept.dto.request.XpackDeleteDept; -import io.dataease.plugins.xpack.dept.dto.request.XpackMoveDept; +import io.dataease.plugins.xpack.dept.dto.request.*; +import io.dataease.plugins.xpack.dept.dto.response.DeptUserItemDTO; import io.dataease.plugins.xpack.dept.dto.response.XpackDeptTreeNode; import io.dataease.plugins.xpack.dept.dto.response.XpackSysDept; import io.dataease.plugins.xpack.dept.service.DeptXpackService; import io.swagger.annotations.Api; +import io.swagger.annotations.ApiImplicitParam; +import io.swagger.annotations.ApiImplicitParams; import io.swagger.annotations.ApiOperation; import org.apache.shiro.authz.annotation.RequiresPermissions; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.cache.annotation.CacheEvict; import org.springframework.web.bind.annotation.*; import springfox.documentation.annotations.ApiIgnore; @@ -123,6 +133,7 @@ public class XDeptServer { return deptService.searchTree(deptId); } + @RequiresPermissions("dept:edit") @ApiOperation("移动") @PostMapping("/move") @@ -130,4 +141,41 @@ public class XDeptServer { DeptXpackService deptService = SpringContextUtil.getBean(DeptXpackService.class); deptService.move(xpackMoveDept); } + + @RequiresPermissions({"dept:read", "user:read"}) + @ApiOperation("查询用户") + @ApiImplicitParams({ + @ApiImplicitParam(paramType = "path", name = "goPage", value = "页码", required = true, dataType = "Integer"), + @ApiImplicitParam(paramType = "path", name = "pageSize", value = "页容量", required = true, dataType = "Integer"), + @ApiImplicitParam(name = "request", value = "查询条件", required = true) + }) + @PostMapping("/userGrid/{goPage}/{pageSize}") + public Pager> userGrid(@PathVariable int goPage, @PathVariable int pageSize, @RequestBody XpackDeptUserRequest request) { + DeptXpackService deptService = SpringContextUtil.getBean(DeptXpackService.class); + Page page = PageHelper.startPage(goPage, pageSize, true); + List userItems = deptService.queryBinded(request); + Pager> setPageInfo = PageUtils.setPageInfo(page, userItems); + return setPageInfo; + } + + @RequiresPermissions({"dept:edit", "user:edit"}) + @CacheEvict(value = AuthConstants.USER_CACHE_NAME, key = "'user' + #request.userId") + @PostMapping("/bindUser") + public void bindUser(@RequestBody XpackDeptBindRequest request) { + DeptXpackService deptService = SpringContextUtil.getBean(DeptXpackService.class); + deptService.bindUser(request); + } + + @RequiresPermissions({"dept:edit", "user:edit"}) + @PostMapping("/unBindUser") + public void unBindUser(@RequestBody XpackDeptUnBindRequest request) { + DeptXpackService deptService = SpringContextUtil.getBean(DeptXpackService.class); + if (CollectionUtil.isEmpty(request.getUserIds())) { + DEException.throwException("userIds can not be empty"); + } + request.getUserIds().forEach(userId -> { + CacheUtils.remove( AuthConstants.USER_CACHE_NAME, "user" + userId); + }); + deptService.unBindUsers(request); + } } diff --git a/backend/src/main/java/io/dataease/plugins/server/XRoleServer.java b/backend/src/main/java/io/dataease/plugins/server/XRoleServer.java index 6980aa9d09..57aa1fc02f 100644 --- a/backend/src/main/java/io/dataease/plugins/server/XRoleServer.java +++ b/backend/src/main/java/io/dataease/plugins/server/XRoleServer.java @@ -5,9 +5,11 @@ import com.github.pagehelper.Page; import com.github.pagehelper.PageHelper; import io.dataease.auth.annotation.DeLog; import io.dataease.auth.service.ExtAuthService; +import io.dataease.commons.constants.AuthConstants; import io.dataease.commons.constants.SysLogConstants; import io.dataease.commons.utils.PageUtils; import io.dataease.commons.utils.Pager; +import io.dataease.listener.util.CacheUtils; import io.dataease.plugins.common.entity.XpackGridRequest; import io.dataease.plugins.config.SpringContextUtil; import io.dataease.plugins.xpack.role.dto.request.RoleUserMappingDelRequest; @@ -21,8 +23,10 @@ import io.swagger.annotations.Api; import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiImplicitParams; import io.swagger.annotations.ApiOperation; +import org.apache.commons.collections4.CollectionUtils; import org.apache.shiro.authz.annotation.RequiresPermissions; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.cache.annotation.CacheEvict; import org.springframework.web.bind.annotation.*; import springfox.documentation.annotations.ApiIgnore; @@ -116,6 +120,7 @@ public class XRoleServer { @RequiresPermissions({"role:edit", "user:edit"}) @ApiOperation("绑定用户") + @CacheEvict(value = AuthConstants.USER_CACHE_NAME, key = "'user' + #request.userId") @PostMapping("/bindUser") public void bindUser(@RequestBody RoleUserMappingRequest request) { RoleXpackService roleXpackService = SpringContextUtil.getBean(RoleXpackService.class); @@ -127,6 +132,11 @@ public class XRoleServer { @PostMapping("/unBindUsers") public void unBindUsers(@RequestBody RoleUserMappingDelRequest request) { RoleXpackService roleXpackService = SpringContextUtil.getBean(RoleXpackService.class); + if (CollectionUtils.isNotEmpty(request.getUserIds())) { + request.getUserIds().forEach(userId -> { + CacheUtils.remove( AuthConstants.USER_CACHE_NAME, "user" + userId); + }); + } roleXpackService.batchDelUser(request); } }