From b1618ddc534a5b29adab7fc72c0e95f71f060f11 Mon Sep 17 00:00:00 2001 From: smallchill Date: Fri, 20 Dec 2019 13:34:13 +0800 Subject: [PATCH] =?UTF-8?q?:ambulance:=20=E4=BC=98=E5=8C=96=E7=A7=9F?= =?UTF-8?q?=E6=88=B7=E9=83=A8=E9=97=A8=E6=93=8D=E4=BD=9C=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../org/springblade/system/controller/DeptController.java | 5 +---- .../springblade/system/service/impl/DeptServiceImpl.java | 8 +++++++- .../system/service/impl/TenantServiceImpl.java | 1 + 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/blade-service/blade-system/src/main/java/org/springblade/system/controller/DeptController.java b/blade-service/blade-system/src/main/java/org/springblade/system/controller/DeptController.java index 68f04f2a..5bd02cba 100644 --- a/blade-service/blade-system/src/main/java/org/springblade/system/controller/DeptController.java +++ b/blade-service/blade-system/src/main/java/org/springblade/system/controller/DeptController.java @@ -104,10 +104,7 @@ public class DeptController extends BladeController { @ApiOperationSupport(order = 4) @ApiOperation(value = "新增或修改", notes = "传入dept") @CacheEvict(cacheNames = {SYS_CACHE}, allEntries = true) - public R submit(@Valid @RequestBody Dept dept, BladeUser user) { - if (Func.isEmpty(dept.getId())) { - dept.setTenantId(user.getTenantId()); - } + public R submit(@Valid @RequestBody Dept dept) { return R.status(deptService.submit(dept)); } diff --git a/blade-service/blade-system/src/main/java/org/springblade/system/service/impl/DeptServiceImpl.java b/blade-service/blade-system/src/main/java/org/springblade/system/service/impl/DeptServiceImpl.java index fbf5d64c..e7bc2872 100644 --- a/blade-service/blade-system/src/main/java/org/springblade/system/service/impl/DeptServiceImpl.java +++ b/blade-service/blade-system/src/main/java/org/springblade/system/service/impl/DeptServiceImpl.java @@ -20,6 +20,7 @@ import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.baomidou.mybatisplus.extension.exceptions.ApiException; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import org.springblade.core.log.exception.ServiceException; import org.springblade.core.secure.utils.AuthUtil; import org.springblade.core.tool.constant.BladeConstant; import org.springblade.core.tool.node.ForestNodeMerger; @@ -71,11 +72,16 @@ public class DeptServiceImpl extends ServiceImpl implements ID @Override public boolean submit(Dept dept) { if (Func.isEmpty(dept.getParentId())) { + dept.setTenantId(AuthUtil.getTenantId()); dept.setParentId(BladeConstant.TOP_PARENT_ID); - dept.setAncestors("0"); + dept.setAncestors(String.valueOf(BladeConstant.TOP_PARENT_ID)); } if (dept.getParentId() > 0) { Dept parent = getById(dept.getParentId()); + if (Func.toLong(dept.getParentId()) == Func.toLong(dept.getId())) { + throw new ServiceException("父节点不选选择自身!"); + } + dept.setTenantId(parent.getTenantId()); String ancestors = parent.getAncestors() + StringPool.COMMA + dept.getParentId(); dept.setAncestors(ancestors); } diff --git a/blade-service/blade-system/src/main/java/org/springblade/system/service/impl/TenantServiceImpl.java b/blade-service/blade-system/src/main/java/org/springblade/system/service/impl/TenantServiceImpl.java index 7aa8a102..441eb0ef 100644 --- a/blade-service/blade-system/src/main/java/org/springblade/system/service/impl/TenantServiceImpl.java +++ b/blade-service/blade-system/src/main/java/org/springblade/system/service/impl/TenantServiceImpl.java @@ -75,6 +75,7 @@ public class TenantServiceImpl extends BaseServiceImpl imp Dept dept = new Dept(); dept.setTenantId(tenantId); dept.setParentId(BladeConstant.TOP_PARENT_ID); + dept.setAncestors(String.valueOf(BladeConstant.TOP_PARENT_ID)); dept.setDeptName(tenant.getTenantName()); dept.setFullName(tenant.getTenantName()); dept.setDeptCategory(1);