|
|
@@ -3,6 +3,7 @@ package com.tuoheng.service.impl; |
|
|
|
import cn.hutool.core.convert.Convert; |
|
|
|
import cn.hutool.core.util.ObjectUtil; |
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage; |
|
|
|
import com.baomidou.mybatisplus.core.toolkit.StringUtils; |
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
|
|
|
import com.tuoheng.common.ServiceException; |
|
|
@@ -60,8 +61,6 @@ public class TenantServiceImpl implements TenantService { |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private PlatformMapper platformMapper; |
|
|
|
@Autowired |
|
|
|
private Oauth2RegisteredClientMapper oauth2RegisteredClientMapper; |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
@@ -71,12 +70,14 @@ public class TenantServiceImpl implements TenantService { |
|
|
|
if (clientUserMapper.judgeCreateByUserName(createClientTenantDto.getUsername()) > 0) { |
|
|
|
return JsonResult.error("该用户名称已存在!"); |
|
|
|
} |
|
|
|
//用户表 |
|
|
|
UserPo userPo = new UserPo() |
|
|
|
.setIsTenant(1) |
|
|
|
.setUsername(createClientTenantDto.getUsername()) |
|
|
|
.setPassword("{bcrypt}" + new BCryptPasswordEncoder().encode(createClientTenantDto.getPassword())); |
|
|
|
userPo.setCreateUser(loginUser.getUserId()); |
|
|
|
clientUserMapper.insertClientUser(userPo); |
|
|
|
//租户表 |
|
|
|
TenantPo tenantPo = new TenantPo(); |
|
|
|
BeanUtils.copyProperties(createClientTenantDto, tenantPo); |
|
|
|
tenantPo.setName(createClientTenantDto.getTenantName()) |
|
|
@@ -102,18 +103,25 @@ public class TenantServiceImpl implements TenantService { |
|
|
|
.setRoleId(clientRoleDto.getRoleId()); |
|
|
|
clientUserRolePo.setCreateUser(loginUser.getUserId()); |
|
|
|
clientUserRolePoArrayList.add(clientUserRolePo); |
|
|
|
|
|
|
|
} |
|
|
|
authoritiesMapper.batchInsert(authoritiesPos); |
|
|
|
clientUserRoleMapper.batchInsert(clientUserRolePoArrayList); |
|
|
|
//todo:调用业务系统完成租户创建 |
|
|
|
List<ClientRoleDto> list = createClientTenantDto.getClientRoleDtoList(); |
|
|
|
for (ClientRoleDto clientRoleDto : list) { |
|
|
|
log.info("参数:{}",clientRoleDto.toString()); |
|
|
|
JsonResult result = getResult(createClientTenantDto, clientRoleDto.getClientId(),loginUser); |
|
|
|
if (JsonResult.SUCCESS != result.getCode()) { |
|
|
|
throw new ServiceException(HttpStatus.BAD_REQUEST.value(), result.getMsg()); |
|
|
|
try { |
|
|
|
log.info("参数:{}", clientRoleDto.toString()); |
|
|
|
JsonResult result = getResult(createClientTenantDto, clientRoleDto.getClientId(), loginUser); |
|
|
|
if (JsonResult.SUCCESS != result.getCode()) { |
|
|
|
throw new ServiceException(HttpStatus.BAD_REQUEST.value(), result.getMsg()); |
|
|
|
} |
|
|
|
} catch (Exception e) { |
|
|
|
//e.printStackTrace(); |
|
|
|
//事务并不会回滚 |
|
|
|
log.info("异常信息捕获,平台标识:{}", clientRoleDto.getClientId()); |
|
|
|
log.info("异常信息:{}", e.getMessage()); |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return JsonResult.success(userPo.getId()); |
|
|
@@ -133,12 +141,12 @@ public class TenantServiceImpl implements TenantService { |
|
|
|
switch (dto.getClientId()) { |
|
|
|
//暂时河湖长,动态匹配其他平台 |
|
|
|
case HhzUrlConstant.HHZ_CLIENT: |
|
|
|
addClientRoleDtoList(HhzUrlConstant.HHZ_CLIENT_MP,dto.getRoleId(),clientRoleDtoList); |
|
|
|
addClientRoleDtoList(HhzUrlConstant.HHZ_CLIENT_ADMIN,dto.getRoleId(),clientRoleDtoList); |
|
|
|
addClientRoleDtoList(HhzUrlConstant.HHZ_CLIENT_MP, dto.getRoleId(), clientRoleDtoList); |
|
|
|
addClientRoleDtoList(HhzUrlConstant.HHZ_CLIENT_ADMIN, dto.getRoleId(), clientRoleDtoList); |
|
|
|
break; |
|
|
|
case PilotConstant.PILOT_CLIENT: |
|
|
|
addClientRoleDtoList(PilotConstant.PILOT_CLIENT_ADMIN,dto.getRoleId(),clientRoleDtoList); |
|
|
|
addClientRoleDtoList(PilotConstant.PILOT_CLIENT_MP,dto.getRoleId(),clientRoleDtoList); |
|
|
|
addClientRoleDtoList(PilotConstant.PILOT_CLIENT_ADMIN, dto.getRoleId(), clientRoleDtoList); |
|
|
|
addClientRoleDtoList(PilotConstant.PILOT_CLIENT_MP, dto.getRoleId(), clientRoleDtoList); |
|
|
|
break; |
|
|
|
////暂时河湖长,动态匹配其他平台 |
|
|
|
//case HhzUrlConstant.HHZ_CLIENT: |
|
|
@@ -155,8 +163,10 @@ public class TenantServiceImpl implements TenantService { |
|
|
|
} |
|
|
|
return clientRoleDtoList; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 封装数据到 clientRoleDtoList |
|
|
|
* |
|
|
|
* @param clientId |
|
|
|
* @param roleId |
|
|
|
* @param clientRoleDtoList |
|
|
@@ -339,6 +349,7 @@ public class TenantServiceImpl implements TenantService { |
|
|
|
return clientRoleListDto; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 查询租户以及该租户对应绑定的系统等 |
|
|
|
* |
|
|
@@ -350,14 +361,13 @@ public class TenantServiceImpl implements TenantService { |
|
|
|
query.checkParam(); |
|
|
|
//开启分页 |
|
|
|
IPage<TenantVo> page = new Page<>(query.getPage(), query.getLimit()); |
|
|
|
IPage<TenantPo> pageData = tenantMapper.findList(page, query); |
|
|
|
pageData.convert(x -> { |
|
|
|
TenantVo vo = Convert.convert(TenantVo.class, x); |
|
|
|
IPage<TenantVo> pageData = tenantMapper.findList(page, query); |
|
|
|
List<TenantVo> collect = pageData.getRecords().stream().map(x -> { |
|
|
|
TenantVo vo = new TenantVo(); |
|
|
|
BeanUtils.copyProperties(x, vo); |
|
|
|
vo.setTenantId(x.getUserId()); |
|
|
|
vo.setTenantCode(x.getCode()); |
|
|
|
vo.setTenantName(x.getName()); |
|
|
|
Long userId = x.getUserId(); |
|
|
|
List<AuthoritiesPo> poList = authoritiesMapper.selectByUserId(userId); |
|
|
|
//此处userId = tenantId 效果一致 |
|
|
|
List<AuthoritiesPo> poList = authoritiesMapper.selectListByUserIdAndClientId(x.getUserId(), query); |
|
|
|
List<BusinessSystemVo> businessSystemVoList = new ArrayList<>(); |
|
|
|
for (AuthoritiesPo authoritiesPo : poList) { |
|
|
|
//TODO 后期维护各个业务平台 |
|
|
@@ -375,8 +385,13 @@ public class TenantServiceImpl implements TenantService { |
|
|
|
} |
|
|
|
businessSystemVoList = businessSystemVoList.stream().distinct().collect(Collectors.toList()); |
|
|
|
vo.setList(businessSystemVoList); |
|
|
|
return vo; |
|
|
|
}); |
|
|
|
if (ObjectUtil.isNotEmpty(businessSystemVoList)) { |
|
|
|
return vo; |
|
|
|
} else { |
|
|
|
return null; |
|
|
|
} |
|
|
|
}).filter(x -> x != null).collect(Collectors.toList()); |
|
|
|
pageData.setRecords(collect); |
|
|
|
return JsonResult.success(pageData); |
|
|
|
} |
|
|
|
|
|
|
@@ -489,9 +504,9 @@ public class TenantServiceImpl implements TenantService { |
|
|
|
* @param loginUser |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
private JsonResult getResult(CreateClientTenantDto dto,String code, LoginUser loginUser) { |
|
|
|
private JsonResult getResult(CreateClientTenantDto dto, String code, LoginUser loginUser) { |
|
|
|
Platform platform = platformMapper.selectOne(Wrappers.<Platform>lambdaQuery() |
|
|
|
.eq(Platform::getPlatformCode,code) |
|
|
|
.eq(Platform::getPlatformCode, code) |
|
|
|
.eq(Platform::getMark, 1)); |
|
|
|
if (ObjectUtil.isNull(platform)) { |
|
|
|
return JsonResult.error("该业务平台不存在"); |