From fd7b66bba9b28506f140e83819e9aeb4c9871021 Mon Sep 17 00:00:00 2001 From: wangliwen Date: Mon, 31 Oct 2022 13:49:45 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8C=BA=E5=9F=9F=E9=83=A8=E9=97=A8=E7=AE=A1?= =?UTF-8?q?=E7=90=86=E5=91=98=E5=8F=AA=E5=87=BA=E6=9C=AC=E5=8C=BA=E5=9F=9F?= =?UTF-8?q?=E9=83=A8=E9=97=A8=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../sys/controller/SysDeptController.java | 22 +++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/renren-admin/src/main/java/io/renren/modules/sys/controller/SysDeptController.java b/renren-admin/src/main/java/io/renren/modules/sys/controller/SysDeptController.java index cd1e026d..100e4698 100644 --- a/renren-admin/src/main/java/io/renren/modules/sys/controller/SysDeptController.java +++ b/renren-admin/src/main/java/io/renren/modules/sys/controller/SysDeptController.java @@ -8,8 +8,10 @@ import io.renren.common.validator.group.AddGroup; import io.renren.common.validator.group.DefaultGroup; import io.renren.common.validator.group.UpdateGroup; import io.renren.modules.security.user.SecurityUser; +import io.renren.modules.security.user.UserDetail; import io.renren.modules.sys.dto.SysDeptDTO; import io.renren.modules.sys.dto.SysUserDTO; +import io.renren.modules.sys.enums.SuperAdminEnum; import io.renren.modules.sys.service.SysDeptService; import io.renren.modules.sys.service.SysUserService; import io.swagger.annotations.Api; @@ -66,11 +68,23 @@ public class SysDeptController { @LogOperation("查询所有部门列表") // @RequiresPermissions("sys:dept:list") public Result>> all(String name) { + UserDetail user = SecurityUser.getUser(); List> list = new ArrayList<>(); - if (StringUtils.isNotEmpty(name)) { - list = jdbcTemplate.queryForList(String.format("SELECT id,`name` FROM sys_dept WHERE `name` LIKE '%s';", "%" + name + "%")); - } else { - list = jdbcTemplate.queryForList("SELECT id,`name` FROM sys_dept;"); + if (user.getSuperAdmin() == SuperAdminEnum.YES.value()) { // 超级管理员 + if (StringUtils.isNotEmpty(name)) { + list = jdbcTemplate.queryForList(String.format("SELECT id,`name` FROM sys_dept WHERE `name` LIKE '%s';", "%" + name + "%")); + } else { + list = jdbcTemplate.queryForList("SELECT id,`name` FROM sys_dept;"); + } + } else { // 区域管理员 + SysDeptDTO sysDeptDTO = sysDeptService.get(user.getDeptId()); + if (sysDeptDTO.getDistrict() != null) { + if (StringUtils.isNotEmpty(name)) { + list = jdbcTemplate.queryForList(String.format("SELECT id,`name` FROM sys_dept WHERE `name` LIKE '%s' AND WHERE district = %d;", "%" + name + "%", sysDeptDTO.getDistrict())); + } else { + list = jdbcTemplate.queryForList(String.format("SELECT id,`name` FROM sys_dept WHERE district = %d;", sysDeptDTO.getDistrict())); + } + } } return new Result>>().ok(list); }