|
|
|
|
|
|
|
|
import com.tuoheng.common.ServiceException; |
|
|
import com.tuoheng.common.ServiceException; |
|
|
import com.tuoheng.constant.*; |
|
|
import com.tuoheng.constant.*; |
|
|
import com.tuoheng.mapper.*; |
|
|
import com.tuoheng.mapper.*; |
|
|
import com.tuoheng.model.dto.LoginUser; |
|
|
|
|
|
import com.tuoheng.model.dto.OidcTenantDto; |
|
|
|
|
|
import com.tuoheng.model.dto.Platform; |
|
|
|
|
|
import com.tuoheng.model.dto.TTenant; |
|
|
|
|
|
|
|
|
import com.tuoheng.model.dto.*; |
|
|
import com.tuoheng.model.param.*; |
|
|
import com.tuoheng.model.param.*; |
|
|
import com.tuoheng.model.po.AuthoritiesPo; |
|
|
import com.tuoheng.model.po.AuthoritiesPo; |
|
|
import com.tuoheng.model.po.ClientUserRolePo; |
|
|
import com.tuoheng.model.po.ClientUserRolePo; |
|
|
|
|
|
|
|
|
import com.tuoheng.until.JsonResult; |
|
|
import com.tuoheng.until.JsonResult; |
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
import org.springframework.data.annotation.Id; |
|
|
|
|
|
|
|
|
import org.springframework.core.ParameterizedTypeReference; |
|
|
import org.springframework.http.*; |
|
|
import org.springframework.http.*; |
|
|
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; |
|
|
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; |
|
|
import org.springframework.stereotype.Service; |
|
|
import org.springframework.stereotype.Service; |
|
|
|
|
|
|
|
|
if (clientUserMapper.judgeCreateByUserName(createClientTenantDto.getUsername()) > 0) { |
|
|
if (clientUserMapper.judgeCreateByUserName(createClientTenantDto.getUsername()) > 0) { |
|
|
return JsonResult.error("该用户名称已存在!"); |
|
|
return JsonResult.error("该用户名称已存在!"); |
|
|
} |
|
|
} |
|
|
|
|
|
//1.开始判断租户对应需要的平台并进行匹对 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
UserPo userPo = new UserPo() |
|
|
UserPo userPo = new UserPo() |
|
|
.setIsTenant(1) |
|
|
.setIsTenant(1) |
|
|
.setUsername(createClientTenantDto.getUsername()) |
|
|
.setUsername(createClientTenantDto.getUsername()) |
|
|
|
|
|
|
|
|
return JsonResult.success(); |
|
|
return JsonResult.success(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* 查询对应业务平台的所有角色 |
|
|
|
|
|
* |
|
|
|
|
|
* @param clientId 平台标识 |
|
|
|
|
|
* @param loginUser |
|
|
|
|
|
* @return |
|
|
|
|
|
*/ |
|
|
|
|
|
@Override |
|
|
|
|
|
public JsonResult getRoleList(String clientId, LoginUser loginUser) { |
|
|
|
|
|
|
|
|
|
|
|
if (ObjectUtil.isEmpty(clientId)) { |
|
|
|
|
|
return JsonResult.error("clientId不能为空"); |
|
|
|
|
|
} |
|
|
|
|
|
List<ClientRoleListDto> clientRoleListDtos = new ArrayList<>(); |
|
|
|
|
|
|
|
|
|
|
|
if (clientId.contains(CommonConstant.COMMA)) { |
|
|
|
|
|
String[] clientIds = clientId.split(CommonConstant.COMMA); |
|
|
|
|
|
for (String id : clientIds) { |
|
|
|
|
|
ClientRoleListDto dto = getRoleListByClinetId(id, loginUser); |
|
|
|
|
|
clientRoleListDtos.add(dto); |
|
|
|
|
|
} |
|
|
|
|
|
} else { |
|
|
|
|
|
ClientRoleListDto dto = getRoleListByClinetId(clientId, loginUser); |
|
|
|
|
|
clientRoleListDtos.add(dto); |
|
|
|
|
|
} |
|
|
|
|
|
return JsonResult.success(clientRoleListDtos); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* 访问对应系统获取对应业务平台可关联的角色 |
|
|
|
|
|
* |
|
|
|
|
|
* @param clientId |
|
|
|
|
|
* @param loginUser |
|
|
|
|
|
* @return |
|
|
|
|
|
*/ |
|
|
|
|
|
private ClientRoleListDto getRoleListByClinetId(String clientId, LoginUser loginUser) { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Platform platform = platformMapper.selectOne(Wrappers.<Platform>lambdaQuery() |
|
|
|
|
|
.eq(Platform::getPlatformCode, clientId) |
|
|
|
|
|
.eq(Platform::getMark, 1)); |
|
|
|
|
|
if (ObjectUtil.isNull(platform)) { |
|
|
|
|
|
throw new ServiceException(HttpStatus.BAD_REQUEST.value(), "该业务平台不存在"); |
|
|
|
|
|
} |
|
|
|
|
|
ClientRoleListDto clientRoleListDto = new ClientRoleListDto(); |
|
|
|
|
|
clientRoleListDto.setPlatformName(platform.getPlatformName()); |
|
|
|
|
|
clientRoleListDto.setClientId(platform.getPlatformCode()); |
|
|
|
|
|
|
|
|
|
|
|
String url = platform.getPlatformUrl(); |
|
|
|
|
|
//根据不同业务平台进行动态匹配 ->并修改对应标识权限 |
|
|
|
|
|
switch (platform.getPlatformCode()) { |
|
|
|
|
|
//河湖长 |
|
|
|
|
|
case HhzUrlConstant.HHZ_CLIENT: |
|
|
|
|
|
url = url + HhzUrlConstant.FIND_ROLE; |
|
|
|
|
|
break; |
|
|
|
|
|
////机场 |
|
|
|
|
|
//case AirportConstant.AIRPORT_CLIENT: |
|
|
|
|
|
// url = url + AirportConstant.CREATE_TENANT; |
|
|
|
|
|
// break; |
|
|
|
|
|
////高速 |
|
|
|
|
|
//case FreeWayConstant.FREEWAY_CLIENT: |
|
|
|
|
|
// url = url + FreeWayConstant.CREATE_TENANT; |
|
|
|
|
|
// dto.getClientRoleDto().setClientId(FreeWayConstant.FREEWAY_CLIENT_ADMIN + CommonConstant.COMMA + FreeWayConstant.FREEWAY_CLIENT_MP); |
|
|
|
|
|
// break; |
|
|
|
|
|
////航道 |
|
|
|
|
|
//case WaterWayConstant.WATERWAY_CLIENT: |
|
|
|
|
|
// url = url + WaterWayConstant.CREATE_TENANT; |
|
|
|
|
|
// dto.getClientRoleDto().setClientId(WaterWayConstant.WATERWAY_CLIENT_ADMIN + CommonConstant.COMMA + WaterWayConstant.WATERWAY_CLIENT_MP); |
|
|
|
|
|
// break; |
|
|
|
|
|
////飞手 |
|
|
|
|
|
//case PilotConstant.PILOT_CLIENT: |
|
|
|
|
|
// url = url + PilotConstant.CREATE_TENANT; |
|
|
|
|
|
// dto.getClientRoleDto().setClientId(PilotConstant.PILOT_CLIENT + CommonConstant.COMMA + PilotConstant.PILOT_CLIENT_MP); |
|
|
|
|
|
// break; |
|
|
|
|
|
default: |
|
|
|
|
|
break; |
|
|
|
|
|
} |
|
|
|
|
|
ParameterizedTypeReference<JsonResult<List<RoleDto>>> parameterizedTypeReference = |
|
|
|
|
|
new ParameterizedTypeReference<JsonResult<List<RoleDto>>>() { |
|
|
|
|
|
}; |
|
|
|
|
|
ResponseEntity<JsonResult<List<RoleDto>>> response; |
|
|
|
|
|
org.springframework.http.HttpHeaders resultRequestHeader = new HttpHeaders(); |
|
|
|
|
|
resultRequestHeader.add("Authorization", "Bearer " + loginUser.getThToken()); |
|
|
|
|
|
HttpEntity httpEntity = new HttpEntity(resultRequestHeader); |
|
|
|
|
|
try { |
|
|
|
|
|
log.info("url:{}", url); |
|
|
|
|
|
response = restTemplate.exchange(url, HttpMethod.GET, httpEntity, parameterizedTypeReference); |
|
|
|
|
|
} catch (Exception e) { |
|
|
|
|
|
log.error("对应平台标识:{}", platform.getPlatformName()); |
|
|
|
|
|
throw new ServiceException(HttpStatus.BAD_REQUEST.value(), "获取角色列表失败!"); |
|
|
|
|
|
} |
|
|
|
|
|
if (response == null || !response.hasBody() || response.getBody().getCode() != JsonResult.SUCCESS) { |
|
|
|
|
|
throw new ServiceException(HttpStatus.BAD_REQUEST.value(), "获取角色列表响应失败!"); |
|
|
|
|
|
} |
|
|
|
|
|
List<RoleDto> roleDtos = response.getBody().getData(); |
|
|
|
|
|
|
|
|
|
|
|
clientRoleListDto.setRoleDtoList(roleDtos); |
|
|
|
|
|
|
|
|
|
|
|
return clientRoleListDto; |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* 新增业务平台的租户基本数据 |
|
|
* 新增业务平台的租户基本数据 |
|
|
* |
|
|
* |
|
|
|
|
|
|
|
|
if (ObjectUtil.isNotNull(tTenant)) { |
|
|
if (ObjectUtil.isNotNull(tTenant)) { |
|
|
return JsonResult.error("该租户code已存在,请重新输入"); |
|
|
return JsonResult.error("该租户code已存在,请重新输入"); |
|
|
} |
|
|
} |
|
|
if (dto.getClientId().contains(CommonConstant.COMMA)) { |
|
|
|
|
|
String[] codes = dto.getClientId().split(CommonConstant.COMMA); |
|
|
|
|
|
|
|
|
if (dto.getClientRoleDto().getClientId().contains(CommonConstant.COMMA)) { |
|
|
|
|
|
String[] codes = dto.getClientRoleDto().getClientId().split(CommonConstant.COMMA); |
|
|
for (String code : codes) { |
|
|
for (String code : codes) { |
|
|
JsonResult result = getResult(dto, code, loginUser); |
|
|
JsonResult result = getResult(dto, code, loginUser); |
|
|
if (result.getCode() != JsonResult.SUCCESS) { |
|
|
if (result.getCode() != JsonResult.SUCCESS) { |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} else { |
|
|
} else { |
|
|
JsonResult result = getResult(dto, dto.getClientId(), loginUser); |
|
|
|
|
|
|
|
|
JsonResult result = getResult(dto, dto.getClientRoleDto().getClientId(), loginUser); |
|
|
if (result.getCode() != JsonResult.SUCCESS) { |
|
|
if (result.getCode() != JsonResult.SUCCESS) { |
|
|
return result; |
|
|
return result; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
UserPo userPo = clientUserMapper.selectByUserId(tenantPo.getUserId()); |
|
|
UserPo userPo = clientUserMapper.selectByUserId(tenantPo.getUserId()); |
|
|
userPo.setEnabled(0); |
|
|
userPo.setEnabled(0); |
|
|
clientUserMapper.updatePass(userPo); |
|
|
clientUserMapper.updatePass(userPo); |
|
|
if (dto.getClientId().contains(CommonConstant.COMMA)) { |
|
|
|
|
|
String[] codes = dto.getClientId().split(CommonConstant.COMMA); |
|
|
|
|
|
|
|
|
if (dto.getClientRoleDto().getClientId().contains(CommonConstant.COMMA)) { |
|
|
|
|
|
String[] codes = dto.getClientRoleDto().getClientId().split(CommonConstant.COMMA); |
|
|
for (String code : codes) { |
|
|
for (String code : codes) { |
|
|
JsonResult jsonResult = deleteResult(dto, code, loginUser); |
|
|
JsonResult jsonResult = deleteResult(dto, code, loginUser); |
|
|
if (jsonResult.getCode() != JsonResult.SUCCESS) { |
|
|
if (jsonResult.getCode() != JsonResult.SUCCESS) { |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} else { |
|
|
} else { |
|
|
JsonResult jsonResult = deleteResult(dto, dto.getClientId(), loginUser); |
|
|
|
|
|
|
|
|
JsonResult jsonResult = deleteResult(dto, dto.getClientRoleDto().getClientId(), loginUser); |
|
|
if (jsonResult.getCode() != JsonResult.SUCCESS) { |
|
|
if (jsonResult.getCode() != JsonResult.SUCCESS) { |
|
|
return jsonResult; |
|
|
return jsonResult; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if (ObjectUtil.isEmpty(dto.getTenantCode())) { |
|
|
if (ObjectUtil.isEmpty(dto.getTenantCode())) { |
|
|
return JsonResult.error("租户code不能为空"); |
|
|
return JsonResult.error("租户code不能为空"); |
|
|
} |
|
|
} |
|
|
if (dto.getClientId().contains(CommonConstant.COMMA)) { |
|
|
|
|
|
String[] codes = dto.getClientId().split(CommonConstant.COMMA); |
|
|
|
|
|
|
|
|
if (dto.getClientRoleDto().getClientId().contains(CommonConstant.COMMA)) { |
|
|
|
|
|
String[] codes = dto.getClientRoleDto().getClientId().split(CommonConstant.COMMA); |
|
|
for (String code : codes) { |
|
|
for (String code : codes) { |
|
|
JsonResult jsonResult = editResult(dto, code, loginUser); |
|
|
JsonResult jsonResult = editResult(dto, code, loginUser); |
|
|
if (jsonResult.getCode() != JsonResult.SUCCESS) { |
|
|
if (jsonResult.getCode() != JsonResult.SUCCESS) { |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} else { |
|
|
} else { |
|
|
JsonResult jsonResult = editResult(dto, dto.getClientId(), loginUser); |
|
|
|
|
|
|
|
|
JsonResult jsonResult = editResult(dto, dto.getClientRoleDto().getClientId(), loginUser); |
|
|
if (jsonResult.getCode() != JsonResult.SUCCESS) { |
|
|
if (jsonResult.getCode() != JsonResult.SUCCESS) { |
|
|
return jsonResult; |
|
|
return jsonResult; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
//河湖长 |
|
|
//河湖长 |
|
|
case HhzUrlConstant.HHZ_CLIENT: |
|
|
case HhzUrlConstant.HHZ_CLIENT: |
|
|
url = url + HhzUrlConstant.CREATE_TENANT; |
|
|
url = url + HhzUrlConstant.CREATE_TENANT; |
|
|
dto.setClientId(HhzUrlConstant.HHZ_CLIENT_ADMIN); |
|
|
|
|
|
|
|
|
dto.getClientRoleDto().setClientId(HhzUrlConstant.HHZ_CLIENT_ADMIN); |
|
|
break; |
|
|
break; |
|
|
//机场 |
|
|
//机场 |
|
|
case AirportConstant.AIRPORT_CLIENT: |
|
|
case AirportConstant.AIRPORT_CLIENT: |
|
|
|
|
|
|
|
|
//高速 |
|
|
//高速 |
|
|
case FreeWayConstant.FREEWAY_CLIENT: |
|
|
case FreeWayConstant.FREEWAY_CLIENT: |
|
|
url = url + FreeWayConstant.CREATE_TENANT; |
|
|
url = url + FreeWayConstant.CREATE_TENANT; |
|
|
dto.setClientId(FreeWayConstant.FREEWAY_CLIENT_ADMIN + CommonConstant.COMMA + FreeWayConstant.FREEWAY_CLIENT_MP); |
|
|
|
|
|
|
|
|
dto.getClientRoleDto().setClientId(FreeWayConstant.FREEWAY_CLIENT_ADMIN + CommonConstant.COMMA + FreeWayConstant.FREEWAY_CLIENT_MP); |
|
|
break; |
|
|
break; |
|
|
//航道 |
|
|
//航道 |
|
|
case WaterWayConstant.WATERWAY_CLIENT: |
|
|
case WaterWayConstant.WATERWAY_CLIENT: |
|
|
url = url + WaterWayConstant.CREATE_TENANT; |
|
|
url = url + WaterWayConstant.CREATE_TENANT; |
|
|
dto.setClientId(WaterWayConstant.WATERWAY_CLIENT_ADMIN + CommonConstant.COMMA + WaterWayConstant.WATERWAY_CLIENT_MP); |
|
|
|
|
|
|
|
|
dto.getClientRoleDto().setClientId(WaterWayConstant.WATERWAY_CLIENT_ADMIN + CommonConstant.COMMA + WaterWayConstant.WATERWAY_CLIENT_MP); |
|
|
break; |
|
|
break; |
|
|
//飞手 |
|
|
//飞手 |
|
|
case PilotConstant.PILOT_CLIENT: |
|
|
case PilotConstant.PILOT_CLIENT: |
|
|
url = url + PilotConstant.CREATE_TENANT; |
|
|
url = url + PilotConstant.CREATE_TENANT; |
|
|
dto.setClientId(PilotConstant.PILOT_CLIENT + CommonConstant.COMMA + PilotConstant.PILOT_CLIENT_MP); |
|
|
|
|
|
|
|
|
dto.getClientRoleDto().setClientId(PilotConstant.PILOT_CLIENT + CommonConstant.COMMA + PilotConstant.PILOT_CLIENT_MP); |
|
|
break; |
|
|
break; |
|
|
default: |
|
|
default: |
|
|
break; |
|
|
break; |
|
|
|
|
|
|
|
|
//河湖长 |
|
|
//河湖长 |
|
|
case HhzUrlConstant.HHZ_CLIENT: |
|
|
case HhzUrlConstant.HHZ_CLIENT: |
|
|
url = url + HhzUrlConstant.UPDATE_TENANT; |
|
|
url = url + HhzUrlConstant.UPDATE_TENANT; |
|
|
dto.setClientId(HhzUrlConstant.HHZ_CLIENT_ADMIN); |
|
|
|
|
|
|
|
|
dto.getClientRoleDto().setClientId(HhzUrlConstant.HHZ_CLIENT_ADMIN); |
|
|
break; |
|
|
break; |
|
|
//机场 |
|
|
//机场 |
|
|
case AirportConstant.AIRPORT_CLIENT: |
|
|
case AirportConstant.AIRPORT_CLIENT: |
|
|
|
|
|
|
|
|
break; |
|
|
break; |
|
|
case FreeWayConstant.FREEWAY_CLIENT: |
|
|
case FreeWayConstant.FREEWAY_CLIENT: |
|
|
url = url + FreeWayConstant.UPDATE_TENANT; |
|
|
url = url + FreeWayConstant.UPDATE_TENANT; |
|
|
dto.setClientId(FreeWayConstant.FREEWAY_CLIENT_ADMIN + CommonConstant.COMMA + FreeWayConstant.FREEWAY_CLIENT_MP); |
|
|
|
|
|
|
|
|
dto.getClientRoleDto().setClientId(FreeWayConstant.FREEWAY_CLIENT_ADMIN + CommonConstant.COMMA + FreeWayConstant.FREEWAY_CLIENT_MP); |
|
|
break; |
|
|
break; |
|
|
case WaterWayConstant.WATERWAY_CLIENT: |
|
|
case WaterWayConstant.WATERWAY_CLIENT: |
|
|
url = url + WaterWayConstant.UPDATE_TENANT; |
|
|
url = url + WaterWayConstant.UPDATE_TENANT; |
|
|
dto.setClientId(WaterWayConstant.WATERWAY_CLIENT_ADMIN + CommonConstant.COMMA + WaterWayConstant.WATERWAY_CLIENT_MP); |
|
|
|
|
|
|
|
|
dto.getClientRoleDto().setClientId(WaterWayConstant.WATERWAY_CLIENT_ADMIN + CommonConstant.COMMA + WaterWayConstant.WATERWAY_CLIENT_MP); |
|
|
break; |
|
|
break; |
|
|
//飞手 |
|
|
//飞手 |
|
|
case PilotConstant.PILOT_CLIENT: |
|
|
case PilotConstant.PILOT_CLIENT: |
|
|
url = url + PilotConstant.UPDATE_TENANT; |
|
|
url = url + PilotConstant.UPDATE_TENANT; |
|
|
dto.setClientId(PilotConstant.PILOT_CLIENT + CommonConstant.COMMA + PilotConstant.PILOT_CLIENT_MP); |
|
|
|
|
|
|
|
|
dto.getClientRoleDto().setClientId(PilotConstant.PILOT_CLIENT + CommonConstant.COMMA + PilotConstant.PILOT_CLIENT_MP); |
|
|
break; |
|
|
break; |
|
|
default: |
|
|
default: |
|
|
break; |
|
|
break; |