|
|
@@ -54,6 +54,8 @@ import java.util.stream.Collectors; |
|
|
|
@Slf4j |
|
|
|
public class TenantServiceImpl implements TenantService { |
|
|
|
|
|
|
|
//默认密码 |
|
|
|
private static final String passward = "thjs2023"; |
|
|
|
@Autowired |
|
|
|
private ClientUserMapper clientUserMapper; |
|
|
|
|
|
|
@@ -88,7 +90,7 @@ public class TenantServiceImpl implements TenantService { |
|
|
|
} |
|
|
|
//创建租户创建成功后的返回实体类 |
|
|
|
CreateTenantVo vo = new CreateTenantVo(); |
|
|
|
vo.setPassword(createClientTenantDto.getPassword()); |
|
|
|
vo.setPassword(passward); |
|
|
|
vo.setTenantName(createClientTenantDto.getTenantName()); |
|
|
|
vo.setUsername(createClientTenantDto.getUsername()); |
|
|
|
//code复用username |
|
|
@@ -184,7 +186,6 @@ public class TenantServiceImpl implements TenantService { |
|
|
|
log.info("异常信息捕获,平台标识:{}", clientRoleDto.getClientId()); |
|
|
|
log.info("异常信息:{}", e.getMessage()); |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
log.info("业务系统完成创建"); |
|
|
|
return JsonResult.success(vo); |
|
|
@@ -379,10 +380,11 @@ public class TenantServiceImpl implements TenantService { |
|
|
|
return JsonResult.error("租户id不能为空"); |
|
|
|
} |
|
|
|
CreateClientTenantDto dto = new CreateClientTenantDto(); |
|
|
|
dto.setId(query.getId()); |
|
|
|
//查询出租户的相关信息 |
|
|
|
Long tenantId = query.getId(); |
|
|
|
//项目相关信息 |
|
|
|
TenantItem tenantItem = tenantItemMapper.selectOne(Wrappers.<TenantItem>lambdaQuery().eq(TenantItem::getTenantId,tenantId)); |
|
|
|
TenantItem tenantItem = tenantItemMapper.selectOne(Wrappers.<TenantItem>lambdaQuery().eq(TenantItem::getTenantId, tenantId)); |
|
|
|
dto.setTenantItem(tenantItem); |
|
|
|
//租户基本信息 |
|
|
|
TenantPo tenantPo = tenantMapper.selectById(tenantId); |
|
|
@@ -397,10 +399,10 @@ public class TenantServiceImpl implements TenantService { |
|
|
|
ClientRoleDto clientRoleDto = null; |
|
|
|
for (ClientUserRolePo clientUserRolePo : clientUserRolePos) { |
|
|
|
|
|
|
|
clientRoleDto =new ClientRoleDto(); |
|
|
|
clientRoleDto = new ClientRoleDto(); |
|
|
|
//此处 暂时格式都为 tuoheng-hhz-web 等格式 如后续维护需要变更形式则此处代码需要更改 |
|
|
|
clientRoleDto.setRoleId(clientUserRolePo.getRoleId()); |
|
|
|
clientRoleDto.setClientId(clientUserRolePo.getClientId().substring(CommonConstant.ZERO,clientUserRolePo.getClientId().lastIndexOf(CommonConstant.BARS))); |
|
|
|
clientRoleDto.setClientId(clientUserRolePo.getClientId().substring(CommonConstant.ZERO, clientUserRolePo.getClientId().lastIndexOf(CommonConstant.BARS))); |
|
|
|
TenantEmploy tenantEmploy = tenantEmployMapper.selectOne(Wrappers.<TenantEmploy>lambdaQuery() |
|
|
|
.eq(TenantEmploy::getTenantId, tenantId) |
|
|
|
.eq(TenantEmploy::getPlatformCode, clientRoleDto.getClientId())); |
|
|
@@ -436,32 +438,11 @@ public class TenantServiceImpl implements TenantService { |
|
|
|
*/ |
|
|
|
@Override |
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
|
public JsonResult deleteTenant(OidcTenantDto dto, LoginUser loginUser) { |
|
|
|
// |
|
|
|
//TenantPo tenantPo = tenantMapper.selectById(dto.getId()); |
|
|
|
//List<UserPo> list = clientUserMapper.selectByTenantId(tenantPo.getUserId()); |
|
|
|
//if (ObjectUtil.isNotEmpty(list)) { |
|
|
|
// return JsonResult.error("该租户下含有关联用户,不能进行删除"); |
|
|
|
//} |
|
|
|
//tenantPo.setEnabled(0); |
|
|
|
//tenantMapper.updateById(tenantPo); |
|
|
|
//UserPo userPo = clientUserMapper.selectByUserId(tenantPo.getUserId()); |
|
|
|
//userPo.setEnabled(0); |
|
|
|
//clientUserMapper.updatePass(userPo); |
|
|
|
//if (dto.getClientRoleDto().getClientId().contains(CommonConstant.COMMA)) { |
|
|
|
// String[] codes = dto.getClientRoleDto().getClientId().split(CommonConstant.COMMA); |
|
|
|
// for (String code : codes) { |
|
|
|
// JsonResult jsonResult = deleteResult(dto, code, loginUser); |
|
|
|
// if (jsonResult.getCode() != JsonResult.SUCCESS) { |
|
|
|
// return jsonResult; |
|
|
|
// } |
|
|
|
// } |
|
|
|
//} else { |
|
|
|
// JsonResult jsonResult = deleteResult(dto, dto.getClientRoleDto().getClientId(), loginUser); |
|
|
|
// if (jsonResult.getCode() != JsonResult.SUCCESS) { |
|
|
|
// return jsonResult; |
|
|
|
// } |
|
|
|
//} |
|
|
|
public JsonResult deleteTenant(CreateClientTenantDto dto, LoginUser loginUser) { |
|
|
|
//通知业务系统进行删除 |
|
|
|
for (ClientRoleDto clientRoleDto : dto.getClientRoleDtoList()) { |
|
|
|
deleteResult(dto, clientRoleDto.getClientId(), loginUser); |
|
|
|
} |
|
|
|
return JsonResult.success(); |
|
|
|
} |
|
|
|
|
|
|
@@ -474,46 +455,67 @@ public class TenantServiceImpl implements TenantService { |
|
|
|
*/ |
|
|
|
@Override |
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
|
public JsonResult editTenant(OidcTenantDto dto, LoginUser loginUser) { |
|
|
|
// |
|
|
|
//if (ObjectUtil.isEmpty(dto.getTenantCode())) { |
|
|
|
// return JsonResult.error("租户code不能为空"); |
|
|
|
//} |
|
|
|
//if (dto.getClientRoleDto().getClientId().contains(CommonConstant.COMMA)) { |
|
|
|
// String[] codes = dto.getClientRoleDto().getClientId().split(CommonConstant.COMMA); |
|
|
|
// for (String code : codes) { |
|
|
|
// JsonResult jsonResult = editResult(dto, code, loginUser); |
|
|
|
// if (jsonResult.getCode() != JsonResult.SUCCESS) { |
|
|
|
// return jsonResult; |
|
|
|
// } |
|
|
|
// } |
|
|
|
//} else { |
|
|
|
// JsonResult jsonResult = editResult(dto, dto.getClientRoleDto().getClientId(), loginUser); |
|
|
|
// if (jsonResult.getCode() != JsonResult.SUCCESS) { |
|
|
|
// return jsonResult; |
|
|
|
// } |
|
|
|
//} |
|
|
|
//TTenant tTenant = tenantMapper.getByCode(dto.getTenantCode()); |
|
|
|
//dto.setId(tTenant.getId()); |
|
|
|
// |
|
|
|
//TenantPo tenantPo = new TenantPo(); |
|
|
|
//tenantPo.setName(dto.getTenantName()) |
|
|
|
// .setId(dto.getId()) |
|
|
|
// .setCityCode(dto.getCityCode()) |
|
|
|
// .setCityName(dto.getCityName()) |
|
|
|
// .setProvinceName(dto.getProvinceName()) |
|
|
|
// .setProvinceCode(dto.getProvinceCode()) |
|
|
|
// .setDistrictCode(dto.getDistrictCode()) |
|
|
|
// .setDistrictName(dto.getDistrictName()); |
|
|
|
//tenantMapper.updateById(tenantPo); |
|
|
|
////更新密码 |
|
|
|
//if (ObjectUtil.isNotEmpty(dto.getPassword())) { |
|
|
|
// UserPo userPo = new UserPo(); |
|
|
|
// userPo.setUsername(dto.getUsername()); |
|
|
|
// dto.setPassword("{bcrypt}" + new BCryptPasswordEncoder().encode(dto.getPassword())); |
|
|
|
// userPo.setPassword(dto.getPassword()); |
|
|
|
// clientUserMapper.updatePass(userPo); |
|
|
|
//} |
|
|
|
public JsonResult editTenant(CreateClientTenantDto dto, LoginUser loginUser) { |
|
|
|
|
|
|
|
dto.setTenantCode(dto.getUsername()); |
|
|
|
//默认密码 |
|
|
|
dto.setPassword(passward); |
|
|
|
//符合先删后增逻辑 则直接将原有租户已经对应的关联业务数据清除 |
|
|
|
JsonResult jsonResult = deleteTenant(dto, loginUser); |
|
|
|
if (jsonResult.getCode() != JsonResult.SUCCESS) { |
|
|
|
return jsonResult; |
|
|
|
} |
|
|
|
log.info("租户原始数据删除完毕"); |
|
|
|
//删除原本租户关联的业务实例相关表 |
|
|
|
List<TenantEmploy> tenantEmploys = tenantEmployMapper.selectList(Wrappers.<TenantEmploy>lambdaQuery() |
|
|
|
.eq(TenantEmploy::getTenantId, dto.getId())); |
|
|
|
tenantEmploys.forEach(t -> tenantEmployMapper.deleteById(t)); |
|
|
|
List<ClientRoleDto> list = dto.getClientRoleDtoList(); |
|
|
|
//新增租户关联业务服务实例相关 |
|
|
|
for (ClientRoleDto clientRoleDto : list) { |
|
|
|
TenantEmploy tenantEmploy = new TenantEmploy(); |
|
|
|
tenantEmploy.setDescription(clientRoleDto.getDescription()); |
|
|
|
tenantEmploy.setTenantId(dto.getId()); |
|
|
|
tenantEmploy.setServiceId(clientRoleDto.getServiceId()); |
|
|
|
tenantEmploy.setPlatformCode(clientRoleDto.getClientId()); |
|
|
|
tenantEmployMapper.insert(tenantEmploy); |
|
|
|
} |
|
|
|
log.info("租户更新的业务服务实例表更新完毕"); |
|
|
|
//更新租户原有数据基本 |
|
|
|
TenantPo tenantPo = new TenantPo(); |
|
|
|
BeanUtils.copyProperties(dto, tenantPo); |
|
|
|
tenantPo.setName(dto.getTenantName()) |
|
|
|
.setCode(dto.getTenantCode()) |
|
|
|
.setId(dto.getId()); |
|
|
|
tenantMapper.updateById(tenantPo); |
|
|
|
log.info("租户基本信息更新完毕"); |
|
|
|
TenantItem tenantItem = dto.getTenantItem(); |
|
|
|
tenantItemMapper.updateById(tenantItem); |
|
|
|
log.info("租户项目相关信息更新完毕"); |
|
|
|
|
|
|
|
//todo:调用业务系统完成租户创建 |
|
|
|
for (ClientRoleDto clientRoleDto : list) { |
|
|
|
try { |
|
|
|
log.info("参数:{}", clientRoleDto.toString()); |
|
|
|
JsonResult result = getResult(dto, 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()); |
|
|
|
} |
|
|
|
} |
|
|
|
//更新密码 |
|
|
|
if (ObjectUtil.isNotEmpty(dto.getPassword())) { |
|
|
|
UserPo userPo = new UserPo(); |
|
|
|
userPo.setUsername(dto.getUsername()); |
|
|
|
dto.setPassword("{bcrypt}" + new BCryptPasswordEncoder().encode(dto.getPassword())); |
|
|
|
userPo.setPassword(dto.getPassword()); |
|
|
|
clientUserMapper.updatePass(userPo); |
|
|
|
} |
|
|
|
return JsonResult.success(); |
|
|
|
} |
|
|
|
|
|
|
@@ -580,72 +582,6 @@ public class TenantServiceImpl implements TenantService { |
|
|
|
return JsonResult.success(); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 更新请求 |
|
|
|
* |
|
|
|
* @param dto |
|
|
|
* @param code |
|
|
|
* @param loginUser |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
private JsonResult editResult(OidcTenantDto dto, String code, LoginUser loginUser) { |
|
|
|
//Platform platform = platformMapper.selectOne(Wrappers.<Platform>lambdaQuery() |
|
|
|
// .eq(Platform::getPlatformCode, code) |
|
|
|
// .eq(Platform::getMark, 1)); |
|
|
|
//if (ObjectUtil.isNull(platform)) { |
|
|
|
// return JsonResult.error("该业务平台不存在"); |
|
|
|
//} |
|
|
|
////设置请求头 |
|
|
|
//HttpHeaders resultRequestHeader = new HttpHeaders(); |
|
|
|
//resultRequestHeader.add("Authorization", "Bearer " + loginUser.getThToken()); |
|
|
|
//HttpEntity httpEntity = new HttpEntity(dto, resultRequestHeader); |
|
|
|
////设置地址(hhz平台) |
|
|
|
//String url = platform.getPlatformUrl(); |
|
|
|
////根据不同业务平台进行动态匹配 |
|
|
|
//switch (platform.getPlatformCode()) { |
|
|
|
// //河湖长 |
|
|
|
// case HhzUrlConstant.HHZ_CLIENT: |
|
|
|
// url = url + HhzUrlConstant.UPDATE_TENANT; |
|
|
|
// dto.getClientRoleDto().setClientId(HhzUrlConstant.HHZ_CLIENT_ADMIN); |
|
|
|
// break; |
|
|
|
// //机场 |
|
|
|
// case AirportConstant.AIRPORT_CLIENT: |
|
|
|
// url = url + AirportConstant.EDIT_TENANT; |
|
|
|
// break; |
|
|
|
// case FreeWayConstant.FREEWAY_CLIENT: |
|
|
|
// url = url + FreeWayConstant.UPDATE_TENANT; |
|
|
|
// dto.getClientRoleDto().setClientId(FreeWayConstant.FREEWAY_CLIENT_ADMIN + CommonConstant.COMMA + FreeWayConstant.FREEWAY_CLIENT_MP); |
|
|
|
// break; |
|
|
|
// case WaterWayConstant.WATERWAY_CLIENT: |
|
|
|
// url = url + WaterWayConstant.UPDATE_TENANT; |
|
|
|
// dto.getClientRoleDto().setClientId(WaterWayConstant.WATERWAY_CLIENT_ADMIN + CommonConstant.COMMA + WaterWayConstant.WATERWAY_CLIENT_MP); |
|
|
|
// break; |
|
|
|
// //飞手 |
|
|
|
// case PilotConstant.PILOT_CLIENT: |
|
|
|
// url = url + PilotConstant.UPDATE_TENANT; |
|
|
|
// dto.getClientRoleDto().setClientId(PilotConstant.PILOT_CLIENT + CommonConstant.COMMA + PilotConstant.PILOT_CLIENT_MP); |
|
|
|
// break; |
|
|
|
// default: |
|
|
|
// break; |
|
|
|
//} |
|
|
|
//ResponseEntity<JsonResult> response; |
|
|
|
//try { |
|
|
|
// log.info("请求url:{}", url); |
|
|
|
// response = restTemplate.exchange(url, HttpMethod.POST, httpEntity, JsonResult.class); |
|
|
|
//} catch (Exception e) { |
|
|
|
// throw new ServiceException(HttpStatus.BAD_REQUEST.value(), "业务平台更新租户失败"); |
|
|
|
//} |
|
|
|
//if (null == response || !response.hasBody()) { |
|
|
|
// log.error("业务平台更新租户响应失败"); |
|
|
|
// throw new ServiceException(HttpStatus.BAD_REQUEST.value(), "业务平台更新租户失败"); |
|
|
|
//} |
|
|
|
//if (response.getBody().getCode() != JsonResult.SUCCESS) { |
|
|
|
// log.error("业务平台更新租户响应失败,数据来源:" + platform.getPlatformName()); |
|
|
|
// throw new ServiceException(HttpStatus.BAD_REQUEST.value(), response.getBody().getMsg()); |
|
|
|
//} |
|
|
|
return JsonResult.success(); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 删除请求 |
|
|
|
* |
|
|
@@ -654,7 +590,7 @@ public class TenantServiceImpl implements TenantService { |
|
|
|
* @param loginUser |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
private JsonResult deleteResult(OidcTenantDto dto, String code, LoginUser loginUser) { |
|
|
|
private JsonResult deleteResult(CreateClientTenantDto dto, String code, LoginUser loginUser) { |
|
|
|
Platform platform = platformMapper.selectOne(Wrappers.<Platform>lambdaQuery() |
|
|
|
.eq(Platform::getPlatformCode, code) |
|
|
|
.eq(Platform::getMark, 1)); |