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);