Browse Source

🎉 优化租户逻辑

test
smallchill 5 years ago
parent
commit
efb585cfe7
  1. 6
      blade-service/blade-system/src/main/java/org/springblade/system/controller/TenantController.java
  2. 12
      blade-service/blade-user/src/main/java/org/springblade/system/user/service/impl/UserServiceImpl.java

6
blade-service/blade-system/src/main/java/org/springblade/system/controller/TenantController.java

@ -65,7 +65,7 @@ public class TenantController extends BladeController {
@GetMapping("/detail")
@ApiOperationSupport(order = 1)
@ApiOperation(value = "详情", notes = "传入tenant")
@PreAuth(RoleConstant.HAS_ROLE_ADMINISTRATOR)
@PreAuth(RoleConstant.HAS_ROLE_ADMIN)
public R<Tenant> detail(Tenant tenant) {
Tenant detail = tenantService.getOne(Condition.getQueryWrapper(tenant));
return R.data(detail);
@ -82,7 +82,7 @@ public class TenantController extends BladeController {
})
@ApiOperationSupport(order = 2)
@ApiOperation(value = "分页", notes = "传入tenant")
@PreAuth(RoleConstant.HAS_ROLE_ADMINISTRATOR)
@PreAuth(RoleConstant.HAS_ROLE_ADMIN)
public R<IPage<Tenant>> list(@ApiIgnore @RequestParam Map<String, Object> tenant, Query query, BladeUser bladeUser) {
QueryWrapper<Tenant> queryWrapper = Condition.getQueryWrapper(tenant, Tenant.class);
IPage<Tenant> pages = tenantService.page(Condition.getPage(query), (!bladeUser.getTenantId().equals(BladeConstant.ADMIN_TENANT_ID)) ? queryWrapper.lambda().eq(Tenant::getTenantId, bladeUser.getTenantId()) : queryWrapper);
@ -108,7 +108,7 @@ public class TenantController extends BladeController {
@GetMapping("/page")
@ApiOperationSupport(order = 4)
@ApiOperation(value = "分页", notes = "传入tenant")
@PreAuth(RoleConstant.HAS_ROLE_ADMINISTRATOR)
@PreAuth(RoleConstant.HAS_ROLE_ADMIN)
public R<IPage<Tenant>> page(Tenant tenant, Query query) {
IPage<Tenant> pages = tenantService.selectTenantPage(Condition.getPage(query), tenant);
return R.data(pages);

12
blade-service/blade-user/src/main/java/org/springblade/system/user/service/impl/UserServiceImpl.java

@ -62,15 +62,17 @@ public class UserServiceImpl extends BaseServiceImpl<UserMapper, User> implement
}
String tenantId = user.getTenantId();
Tenant tenant = SysCache.getTenant(tenantId);
Integer accountNumber = tenant.getAccountNumber();
Integer tenantCount = baseMapper.selectCount(Wrappers.<User>query().lambda().eq(User::getTenantId, Func.toStr(tenantId, BladeConstant.ADMIN_TENANT_ID)));
if (accountNumber != null && accountNumber > 0 && accountNumber < tenantCount) {
throw new ServiceException("当前租户已到最大账号额度");
if (Func.isNotEmpty(tenant)) {
Integer accountNumber = tenant.getAccountNumber();
Integer tenantCount = baseMapper.selectCount(Wrappers.<User>query().lambda().eq(User::getTenantId, tenantId));
if (accountNumber != null && accountNumber > 0 && accountNumber < tenantCount) {
throw new ServiceException("当前租户已到最大账号额度");
}
}
if (Func.isNotEmpty(user.getPassword())) {
user.setPassword(DigestUtil.encrypt(user.getPassword()));
}
Integer userCount = baseMapper.selectCount(Wrappers.<User>query().lambda().eq(User::getTenantId, Func.toStr(tenantId, BladeConstant.ADMIN_TENANT_ID)).eq(User::getAccount, user.getAccount()));
Integer userCount = baseMapper.selectCount(Wrappers.<User>query().lambda().eq(User::getTenantId, tenantId).eq(User::getAccount, user.getAccount()));
if (userCount > 0 && Func.isEmpty(user.getId())) {
throw new ServiceException("当前用户已存在!");
}

Loading…
Cancel
Save