|
|
@@ -8,10 +8,7 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
|
|
|
import com.tuoheng.common.ServiceException; |
|
|
|
import com.tuoheng.constant.*; |
|
|
|
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.po.AuthoritiesPo; |
|
|
|
import com.tuoheng.model.po.ClientUserRolePo; |
|
|
@@ -26,7 +23,7 @@ import com.tuoheng.service.ClientUserSevice; |
|
|
|
import com.tuoheng.until.JsonResult; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
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.security.crypto.bcrypt.BCryptPasswordEncoder; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
@@ -165,6 +162,9 @@ public class ClientUserServiceImpl implements ClientUserSevice { |
|
|
|
if (clientUserMapper.judgeCreateByUserName(createClientTenantDto.getUsername()) > 0) { |
|
|
|
return JsonResult.error("该用户名称已存在!"); |
|
|
|
} |
|
|
|
//1.开始判断租户对应需要的平台并进行匹对 |
|
|
|
|
|
|
|
|
|
|
|
UserPo userPo = new UserPo() |
|
|
|
.setIsTenant(1) |
|
|
|
.setUsername(createClientTenantDto.getUsername()) |
|
|
@@ -310,6 +310,108 @@ public class ClientUserServiceImpl implements ClientUserSevice { |
|
|
|
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; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 新增业务平台的租户基本数据 |
|
|
|
* |
|
|
@@ -331,8 +433,8 @@ public class ClientUserServiceImpl implements ClientUserSevice { |
|
|
|
if (ObjectUtil.isNotNull(tTenant)) { |
|
|
|
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) { |
|
|
|
JsonResult result = getResult(dto, code, loginUser); |
|
|
|
if (result.getCode() != JsonResult.SUCCESS) { |
|
|
@@ -340,7 +442,7 @@ public class ClientUserServiceImpl implements ClientUserSevice { |
|
|
|
} |
|
|
|
} |
|
|
|
} else { |
|
|
|
JsonResult result = getResult(dto, dto.getClientId(), loginUser); |
|
|
|
JsonResult result = getResult(dto, dto.getClientRoleDto().getClientId(), loginUser); |
|
|
|
if (result.getCode() != JsonResult.SUCCESS) { |
|
|
|
return result; |
|
|
|
} |
|
|
@@ -422,8 +524,8 @@ public class ClientUserServiceImpl implements ClientUserSevice { |
|
|
|
UserPo userPo = clientUserMapper.selectByUserId(tenantPo.getUserId()); |
|
|
|
userPo.setEnabled(0); |
|
|
|
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) { |
|
|
|
JsonResult jsonResult = deleteResult(dto, code, loginUser); |
|
|
|
if (jsonResult.getCode() != JsonResult.SUCCESS) { |
|
|
@@ -431,7 +533,7 @@ public class ClientUserServiceImpl implements ClientUserSevice { |
|
|
|
} |
|
|
|
} |
|
|
|
} else { |
|
|
|
JsonResult jsonResult = deleteResult(dto, dto.getClientId(), loginUser); |
|
|
|
JsonResult jsonResult = deleteResult(dto, dto.getClientRoleDto().getClientId(), loginUser); |
|
|
|
if (jsonResult.getCode() != JsonResult.SUCCESS) { |
|
|
|
return jsonResult; |
|
|
|
} |
|
|
@@ -453,8 +555,8 @@ public class ClientUserServiceImpl implements ClientUserSevice { |
|
|
|
if (ObjectUtil.isEmpty(dto.getTenantCode())) { |
|
|
|
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) { |
|
|
|
JsonResult jsonResult = editResult(dto, code, loginUser); |
|
|
|
if (jsonResult.getCode() != JsonResult.SUCCESS) { |
|
|
@@ -462,7 +564,7 @@ public class ClientUserServiceImpl implements ClientUserSevice { |
|
|
|
} |
|
|
|
} |
|
|
|
} else { |
|
|
|
JsonResult jsonResult = editResult(dto, dto.getClientId(), loginUser); |
|
|
|
JsonResult jsonResult = editResult(dto, dto.getClientRoleDto().getClientId(), loginUser); |
|
|
|
if (jsonResult.getCode() != JsonResult.SUCCESS) { |
|
|
|
return jsonResult; |
|
|
|
} |
|
|
@@ -516,7 +618,7 @@ public class ClientUserServiceImpl implements ClientUserSevice { |
|
|
|
//河湖长 |
|
|
|
case HhzUrlConstant.HHZ_CLIENT: |
|
|
|
url = url + HhzUrlConstant.CREATE_TENANT; |
|
|
|
dto.setClientId(HhzUrlConstant.HHZ_CLIENT_ADMIN); |
|
|
|
dto.getClientRoleDto().setClientId(HhzUrlConstant.HHZ_CLIENT_ADMIN); |
|
|
|
break; |
|
|
|
//机场 |
|
|
|
case AirportConstant.AIRPORT_CLIENT: |
|
|
@@ -525,17 +627,17 @@ public class ClientUserServiceImpl implements ClientUserSevice { |
|
|
|
//高速 |
|
|
|
case FreeWayConstant.FREEWAY_CLIENT: |
|
|
|
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; |
|
|
|
//航道 |
|
|
|
case WaterWayConstant.WATERWAY_CLIENT: |
|
|
|
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; |
|
|
|
//飞手 |
|
|
|
case PilotConstant.PILOT_CLIENT: |
|
|
|
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; |
|
|
|
default: |
|
|
|
break; |
|
|
@@ -585,7 +687,7 @@ public class ClientUserServiceImpl implements ClientUserSevice { |
|
|
|
//河湖长 |
|
|
|
case HhzUrlConstant.HHZ_CLIENT: |
|
|
|
url = url + HhzUrlConstant.UPDATE_TENANT; |
|
|
|
dto.setClientId(HhzUrlConstant.HHZ_CLIENT_ADMIN); |
|
|
|
dto.getClientRoleDto().setClientId(HhzUrlConstant.HHZ_CLIENT_ADMIN); |
|
|
|
break; |
|
|
|
//机场 |
|
|
|
case AirportConstant.AIRPORT_CLIENT: |
|
|
@@ -593,16 +695,16 @@ public class ClientUserServiceImpl implements ClientUserSevice { |
|
|
|
break; |
|
|
|
case FreeWayConstant.FREEWAY_CLIENT: |
|
|
|
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; |
|
|
|
case WaterWayConstant.WATERWAY_CLIENT: |
|
|
|
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; |
|
|
|
//飞手 |
|
|
|
case PilotConstant.PILOT_CLIENT: |
|
|
|
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; |
|
|
|
default: |
|
|
|
break; |