Browse Source

修改租户新增

master
wanghaoran 2 years ago
parent
commit
5015a6587b
5 changed files with 149 additions and 28 deletions
  1. +5
    -0
      tuoheng-admin/src/main/java/com/tuoheng/admin/dto/TenantDto.java
  2. +5
    -0
      tuoheng-admin/src/main/java/com/tuoheng/admin/entity/Tenant.java
  3. +11
    -0
      tuoheng-admin/src/main/java/com/tuoheng/admin/service/ITenantService.java
  4. +118
    -28
      tuoheng-admin/src/main/java/com/tuoheng/admin/service/impl/TenantServiceImpl.java
  5. +10
    -0
      tuoheng-system/src/main/java/com/tuoheng/system/entity/User.java

+ 5
- 0
tuoheng-admin/src/main/java/com/tuoheng/admin/dto/TenantDto.java View File

@@ -23,6 +23,11 @@ public class TenantDto {
*/
private String code;

/**
* 租户账号
*/
private String username;

/**
* 租户LOGO
*/

+ 5
- 0
tuoheng-admin/src/main/java/com/tuoheng/admin/entity/Tenant.java View File

@@ -35,6 +35,11 @@ public class Tenant extends BaseEntity {
*/
private String code;

/**
* 租户账号
*/
private String username;

/**
* 租户LOGO
*/

+ 11
- 0
tuoheng-admin/src/main/java/com/tuoheng/admin/service/ITenantService.java View File

@@ -6,6 +6,9 @@ import com.tuoheng.admin.entity.Tenant;
import com.tuoheng.admin.query.TenantQuery;
import com.tuoheng.common.common.IBaseService;
import com.tuoheng.common.utils.JsonResult;
import org.springframework.web.bind.annotation.RequestBody;

import java.util.Map;

/**
* <p>
@@ -41,5 +44,13 @@ public interface ITenantService extends IBaseService<Tenant> {
*/
JsonResult editTenant(TenantDto tenantDto);

/**
* 租户账号
*
* @param accountMap
* @return
*/
String account(@RequestBody Map<String, String> accountMap);


}

+ 118
- 28
tuoheng-admin/src/main/java/com/tuoheng/admin/service/impl/TenantServiceImpl.java View File

@@ -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";
}

// /**
// * 处理租户账号
// *

+ 10
- 0
tuoheng-system/src/main/java/com/tuoheng/system/entity/User.java View File

@@ -36,6 +36,11 @@ public class User implements Serializable {
@TableId(value = "id", type = IdType.AUTO)
private Integer id;

/**
* 租户ID
*/
private Integer tenantId;

/**
* 用户编号
*/
@@ -168,6 +173,11 @@ public class User implements Serializable {
*/
private Integer sort;

/**
* 是否管理员:1是 2否
*/
private Integer isAdmin;

/**
* 登录次数
*/

Loading…
Cancel
Save