| | |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | | import lombok.AllArgsConstructor; |
| | | import org.springblade.common.constant.CommonConstant; |
| | | import org.springblade.common.constant.TenantConstant; |
| | | import org.springblade.core.log.exception.ServiceException; |
| | | import org.springblade.core.mp.base.BaseServiceImpl; |
| | | import org.springblade.core.mp.support.Condition; |
| | |
| | | import org.springblade.core.tenant.BladeTenantProperties; |
| | | import org.springblade.core.tool.api.R; |
| | | import org.springblade.core.tool.constant.BladeConstant; |
| | | import org.springblade.core.tool.jackson.JsonUtil; |
| | | import org.springblade.core.tool.support.Kv; |
| | | import org.springblade.core.tool.utils.*; |
| | | import org.springblade.system.cache.DictCache; |
| | |
| | | user.setTenantId(BladeConstant.ADMIN_TENANT_ID); |
| | | } |
| | | String tenantId = user.getTenantId(); |
| | | Tenant tenant = SysCache.getTenant(tenantId); |
| | | if (Func.isNotEmpty(tenant)) { |
| | | Integer accountNumber = tenant.getAccountNumber(); |
| | | if (tenantProperties.getLicense()) { |
| | | String licenseKey = tenant.getLicenseKey(); |
| | | String decrypt = DesUtil.decryptFormHex(licenseKey, TenantConstant.DES_KEY); |
| | | accountNumber = JsonUtil.parse(decrypt, Tenant.class).getAccountNumber(); |
| | | } |
| | | Long tenantCount = baseMapper.selectCount(Wrappers.<User>query().lambda().eq(User::getTenantId, tenantId)); |
| | | if (accountNumber != null && accountNumber > 0 && accountNumber <= tenantCount) { |
| | | throw new ServiceException("当前租户已到最大账号额度!"); |
| | | } |
| | | } |
| | | //Tenant tenant = SysCache.getTenant(tenantId); |
| | | if (Func.isNotEmpty(user.getPassword())) { |
| | | user.setPassword(DigestUtil.encrypt(user.getPassword())); |
| | | } |
| | |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public boolean submitList(List<User> users) { |
| | | Boolean flag = true; |
| | | for (User user : users){ |
| | | if (StringUtil.isBlank(user.getTenantId())) { |
| | | user.setTenantId(BladeConstant.ADMIN_TENANT_ID); |
| | | } |
| | | String tenantId = user.getTenantId(); |
| | | if (Func.isNotEmpty(user.getPassword())) { |
| | | user.setPassword(DigestUtil.encrypt(user.getPassword())); |
| | | } |
| | | Long userCount = baseMapper.selectCount(Wrappers.<User>query().lambda().eq(User::getTenantId, tenantId).eq(User::getAccount, user.getAccount())); |
| | | if (userCount > 0L && Func.isEmpty(user.getId())) { |
| | | throw new ServiceException(StringUtil.format("当前用户 [{}] 已存在!", user.getAccount())); |
| | | } |
| | | flag = save(user) && submitUserDept(user); |
| | | |
| | | } |
| | | return flag; |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public boolean updateUser(User user) { |
| | | String tenantId = user.getTenantId(); |
| | | Long userCount = baseMapper.selectCount( |