Browse Source

🚑 优化租户部门操作逻辑

test
smallchill 5 years ago
parent
commit
b1618ddc53
  1. 5
      blade-service/blade-system/src/main/java/org/springblade/system/controller/DeptController.java
  2. 8
      blade-service/blade-system/src/main/java/org/springblade/system/service/impl/DeptServiceImpl.java
  3. 1
      blade-service/blade-system/src/main/java/org/springblade/system/service/impl/TenantServiceImpl.java

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

8
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<DeptMapper, Dept> 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);
}

1
blade-service/blade-system/src/main/java/org/springblade/system/service/impl/TenantServiceImpl.java

@ -75,6 +75,7 @@ public class TenantServiceImpl extends BaseServiceImpl<TenantMapper, Tenant> 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);

Loading…
Cancel
Save