|
|
@@ -13,6 +13,8 @@ import com.tuoheng.admin.service.ITenantService; |
|
|
|
import com.tuoheng.common.common.BaseServiceImpl; |
|
|
|
import com.tuoheng.common.config.CommonConfig; |
|
|
|
import com.tuoheng.common.utils.*; |
|
|
|
import com.tuoheng.system.entity.User; |
|
|
|
import com.tuoheng.system.mapper.UserMapper; |
|
|
|
import com.tuoheng.system.utils.ShiroUtils; |
|
|
|
import org.springframework.beans.BeanUtils; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
@@ -36,6 +38,9 @@ public class TenantServiceImpl extends BaseServiceImpl<TenantMapper, Tenant> imp |
|
|
|
@Autowired |
|
|
|
private TenantMapper tenantMapper; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private UserMapper userMapper; |
|
|
|
|
|
|
|
/** |
|
|
|
* 获取租户列表 |
|
|
|
* |
|
|
@@ -83,12 +88,12 @@ public class TenantServiceImpl extends BaseServiceImpl<TenantMapper, Tenant> imp |
|
|
|
} |
|
|
|
|
|
|
|
// 验证租户超管账号是否存在 |
|
|
|
// Integer count2 = tenantMapper.selectCount(new LambdaQueryWrapper<Tenant>() |
|
|
|
// .eq(Tenant::getUsername, tenantDto.getUsername()) |
|
|
|
// .eq(Tenant::getMark, 1)); |
|
|
|
// if (count2 > 0) { |
|
|
|
// return JsonResult.error("系统中已经存在相同的租户账号"); |
|
|
|
// } |
|
|
|
Integer count2 = tenantMapper.selectCount(new LambdaQueryWrapper<Tenant>() |
|
|
|
.eq(Tenant::getUsername, tenantDto.getUsername()) |
|
|
|
.eq(Tenant::getMark, 1)); |
|
|
|
if (count2 > 0) { |
|
|
|
return JsonResult.error("系统中已经存在相同的租户账号"); |
|
|
|
} |
|
|
|
|
|
|
|
// 参数转换 |
|
|
|
Tenant tenant = new Tenant(); |
|
|
@@ -107,14 +112,15 @@ public class TenantServiceImpl extends BaseServiceImpl<TenantMapper, Tenant> imp |
|
|
|
return JsonResult.error("租户创建失败"); |
|
|
|
} |
|
|
|
|
|
|
|
// // 创建租户账号 |
|
|
|
// Map<String, String> accountMap = new HashMap<>(); |
|
|
|
// accountMap.put("tenant_id", tenant.getId().toString()); |
|
|
|
// accountMap.put("tenant_name", tenant.getName()); |
|
|
|
// accountMap.put("username", tenantDto.getUsername()); |
|
|
|
// accountMap.put("password", tenantDto.getPassword()); |
|
|
|
// // 添加 |
|
|
|
// accountMap.put("type", "1"); |
|
|
|
// 创建租户账号 |
|
|
|
Map<String, String> accountMap = new HashMap<>(); |
|
|
|
accountMap.put("tenant_id", tenant.getId().toString()); |
|
|
|
accountMap.put("tenant_name", tenant.getName()); |
|
|
|
accountMap.put("username", tenantDto.getUsername()); |
|
|
|
accountMap.put("password", tenantDto.getPassword()); |
|
|
|
// 添加 |
|
|
|
accountMap.put("type", "1"); |
|
|
|
account(accountMap); |
|
|
|
|
|
|
|
// 调用网络请求处理租户账号信息 |
|
|
|
// String result = handleTenantAccount(accountMap); |
|
|
@@ -147,13 +153,13 @@ public class TenantServiceImpl extends BaseServiceImpl<TenantMapper, Tenant> imp |
|
|
|
} |
|
|
|
|
|
|
|
// 验证租户账号 |
|
|
|
// Integer count2 = tenantMapper.selectCount(new LambdaQueryWrapper<Tenant>() |
|
|
|
// .ne(Tenant::getId, tenant.getId()) |
|
|
|
// .eq(Tenant::getUsername, tenantDto.getUsername()) |
|
|
|
// .eq(Tenant::getMark, 1)); |
|
|
|
// if (count2 > 0) { |
|
|
|
// return JsonResult.error("系统中已经存在相同的租户账号"); |
|
|
|
// } |
|
|
|
Integer count2 = tenantMapper.selectCount(new LambdaQueryWrapper<Tenant>() |
|
|
|
.ne(Tenant::getId, tenant.getId()) |
|
|
|
.eq(Tenant::getUsername, tenantDto.getUsername()) |
|
|
|
.eq(Tenant::getMark, 1)); |
|
|
|
if (count2 > 0) { |
|
|
|
return JsonResult.error("系统中已经存在相同的租户账号"); |
|
|
|
} |
|
|
|
|
|
|
|
BeanUtils.copyProperties(tenantDto, tenant); |
|
|
|
tenant.setUpdateUser(ShiroUtils.getUserId()); |
|
|
@@ -169,13 +175,14 @@ public class TenantServiceImpl extends BaseServiceImpl<TenantMapper, Tenant> imp |
|
|
|
} |
|
|
|
|
|
|
|
// // 更新租户账号 |
|
|
|
// Map<String, String> accountMap = new HashMap<>(); |
|
|
|
// accountMap.put("tenant_id", tenant.getId().toString()); |
|
|
|
// accountMap.put("tenant_name", tenant.getName()); |
|
|
|
// accountMap.put("username", tenantDto.getUsername()); |
|
|
|
// accountMap.put("password", tenantDto.getPassword()); |
|
|
|
// // 更新 |
|
|
|
// accountMap.put("type", "2"); |
|
|
|
Map<String, String> accountMap = new HashMap<>(); |
|
|
|
accountMap.put("tenant_id", tenant.getId().toString()); |
|
|
|
accountMap.put("tenant_name", tenant.getName()); |
|
|
|
accountMap.put("username", tenantDto.getUsername()); |
|
|
|
accountMap.put("password", tenantDto.getPassword()); |
|
|
|
// 更新 |
|
|
|
accountMap.put("type", "2"); |
|
|
|
account(accountMap); |
|
|
|
|
|
|
|
// 调用网络请求处理租户账号信息 |
|
|
|
// String result = handleTenantAccount(accountMap); |
|
|
@@ -185,6 +192,89 @@ public class TenantServiceImpl extends BaseServiceImpl<TenantMapper, Tenant> imp |
|
|
|
return JsonResult.success(); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 租户账号 |
|
|
|
* |
|
|
|
* @param accountMap 参数 |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
@Override |
|
|
|
public String account(Map<String, String> accountMap) { |
|
|
|
// 租户ID |
|
|
|
String tenantId = accountMap.get("tenant_id"); |
|
|
|
// 租户名称 |
|
|
|
String tenantName = accountMap.get("tenant_name"); |
|
|
|
// 登录账号 |
|
|
|
String username = accountMap.get("username"); |
|
|
|
// 密码 |
|
|
|
String password = accountMap.get("password"); |
|
|
|
// 类型 |
|
|
|
String type = accountMap.get("type"); |
|
|
|
if (StringUtils.isEmpty(tenantId) |
|
|
|
|| StringUtils.isEmpty(username) |
|
|
|
|| (type.equals("1") && StringUtils.isEmpty(password))) { |
|
|
|
return "参数不能为空"; |
|
|
|
} |
|
|
|
|
|
|
|
// 重复账号计数 |
|
|
|
if (type.equals("1")) { |
|
|
|
// 添加 |
|
|
|
// 验证是否账号已存在 |
|
|
|
Integer count = userMapper.selectCount(new LambdaQueryWrapper<User>() |
|
|
|
.eq(User::getUsername, username) |
|
|
|
.eq(User::getMark, 1)); |
|
|
|
if (count > 0) { |
|
|
|
return "系统中已存在相同的登录账号"; |
|
|
|
} |
|
|
|
// 创建账号 |
|
|
|
User user = new User(); |
|
|
|
user.setTenantId(Integer.valueOf(tenantId)); |
|
|
|
user.setRealname(tenantName); |
|
|
|
user.setNickname(tenantName); |
|
|
|
user.setUsername(username); |
|
|
|
user.setPassword(CommonUtils.password(password)); |
|
|
|
user.setType(1); |
|
|
|
user.setIsAdmin(1); |
|
|
|
user.setCreateTime(DateUtils.now()); |
|
|
|
int count2 = userMapper.insert(user); |
|
|
|
if (count2 == 0) { |
|
|
|
return "租户账号创建失败"; |
|
|
|
} |
|
|
|
return "SUCCESS"; |
|
|
|
} else if (type.equals("2")) { |
|
|
|
// 更新 |
|
|
|
// 查询租户账号信息 |
|
|
|
User user = userMapper.selectOne(new LambdaQueryWrapper<User>() |
|
|
|
.eq(User::getTenantId, Integer.valueOf(tenantId)) |
|
|
|
.eq(User::getIsAdmin, 1) |
|
|
|
.eq(User::getMark, 1)); |
|
|
|
if (StringUtils.isNull(user)) { |
|
|
|
return "租户账号不存在"; |
|
|
|
} |
|
|
|
// 验证账号 |
|
|
|
Integer count = userMapper.selectCount(new LambdaQueryWrapper<User>() |
|
|
|
.ne(User::getId, user.getId()) |
|
|
|
.eq(User::getUsername, username) |
|
|
|
.eq(User::getMark, 1)); |
|
|
|
if (count > 0) { |
|
|
|
return "系统中已存在相同的账户名称"; |
|
|
|
} |
|
|
|
user.setRealname(tenantName); |
|
|
|
user.setNickname(tenantName); |
|
|
|
user.setUsername(username); |
|
|
|
if (StringUtils.isNotEmpty(password)) { |
|
|
|
user.setPassword(CommonUtils.password(password)); |
|
|
|
} |
|
|
|
user.setUpdateTime(DateUtils.now()); |
|
|
|
int count2 = userMapper.updateById(user); |
|
|
|
if (count2 == 0) { |
|
|
|
return "租户账号更新失败"; |
|
|
|
} |
|
|
|
return "SUCCESS"; |
|
|
|
} |
|
|
|
return "FAIL"; |
|
|
|
} |
|
|
|
|
|
|
|
// /** |
|
|
|
// * 处理租户账号 |
|
|
|
// * |