Ver código fonte

新增查询租户对应各个业务平台可用租户角色接口

tags/v2.4.1
xiaoying 1 ano atrás
pai
commit
964015b394
14 arquivos alterados com 225 adições e 35 exclusões
  1. +2
    -2
      tuoheng_oidc_admin/pom.xml
  2. +7
    -0
      tuoheng_oidc_admin/src/main/java/com/tuoheng/constant/HhzUrlConstant.java
  3. +24
    -9
      tuoheng_oidc_admin/src/main/java/com/tuoheng/controller/TenantController.java
  4. +23
    -0
      tuoheng_oidc_admin/src/main/java/com/tuoheng/model/dto/ClientRoleListDto.java
  5. +3
    -2
      tuoheng_oidc_admin/src/main/java/com/tuoheng/model/dto/OidcTenantDto.java
  6. +33
    -0
      tuoheng_oidc_admin/src/main/java/com/tuoheng/model/dto/RoleDto.java
  7. +9
    -0
      tuoheng_oidc_admin/src/main/java/com/tuoheng/service/ClientUserSevice.java
  8. +124
    -22
      tuoheng_oidc_admin/src/main/java/com/tuoheng/service/impl/ClientUserServiceImpl.java
  9. BIN
      tuoheng_oidc_admin/target/classes/com/tuoheng/constant/HhzUrlConstant.class
  10. BIN
      tuoheng_oidc_admin/target/classes/com/tuoheng/controller/TenantController.class
  11. BIN
      tuoheng_oidc_admin/target/classes/com/tuoheng/model/dto/OidcTenantDto.class
  12. BIN
      tuoheng_oidc_admin/target/classes/com/tuoheng/model/vo/TenantVo.class
  13. BIN
      tuoheng_oidc_admin/target/classes/com/tuoheng/service/ClientUserSevice.class
  14. BIN
      tuoheng_oidc_admin/target/classes/com/tuoheng/service/impl/ClientUserServiceImpl.class

+ 2
- 2
tuoheng_oidc_admin/pom.xml Ver arquivo

@@ -40,8 +40,8 @@

<dependency>
<groupId>cn.hutool</groupId>
<artifactId>hutool-core</artifactId>
<version>5.4.4</version>
<artifactId>hutool-all</artifactId>
<version>5.1.0</version>
</dependency>
<!-- 数据库 -->
<dependency>

+ 7
- 0
tuoheng_oidc_admin/src/main/java/com/tuoheng/constant/HhzUrlConstant.java Ver arquivo

@@ -30,6 +30,13 @@ public class HhzUrlConstant {

public static final String DELETE_TENANT = "/oidcTenant/delete";

/**
* 查询可用角色
*/
public static final String FIND_ROLE = "/oidcTenant/getRoleList";





}

+ 24
- 9
tuoheng_oidc_admin/src/main/java/com/tuoheng/controller/TenantController.java Ver arquivo

@@ -27,48 +27,63 @@ public class TenantController {

@PostMapping("/create")
public JsonResult createClientTenant(@RequestBody CreateClientTenantDto createClientTenantDto,
@CurrentUser LoginUser loginUser){
@CurrentUser LoginUser loginUser) {
return clientUserSevice.createClientTenant(createClientTenantDto, loginUser);
}

/**
* 新增业务平台的租户基本数据
*
* @param dto
* @return
*/
@PostMapping("/add")
public JsonResult add(@RequestBody OidcTenantDto dto,@CurrentUser LoginUser loginUser){
return clientUserSevice.addTenant(dto,loginUser);
public JsonResult add(@RequestBody OidcTenantDto dto, @CurrentUser LoginUser loginUser) {
return clientUserSevice.addTenant(dto, loginUser);
}

/**
* 查询租户列表
*
* @return
*/
@GetMapping("/list")
public JsonResult list(TenantQuery query){
public JsonResult list(TenantQuery query) {
return clientUserSevice.findTenants(query);
}

/**
* 更新业务租户信息及密码接口
*
* @param dto
* @param loginUser
* @return
*/
@PostMapping("/edit")
public JsonResult edit(@RequestBody OidcTenantDto dto,@CurrentUser LoginUser loginUser){
return clientUserSevice.editTenant(dto,loginUser);
public JsonResult edit(@RequestBody OidcTenantDto dto, @CurrentUser LoginUser loginUser) {
return clientUserSevice.editTenant(dto, loginUser);

}

/**
* 删除租户(逻辑删除)
*
* @return
*/
@PostMapping ("/delete")
public JsonResult delete(@RequestBody OidcTenantDto dto,@CurrentUser LoginUser loginUser){
return clientUserSevice.deleteTenant(dto,loginUser);
@PostMapping("/delete")
public JsonResult delete(@RequestBody OidcTenantDto dto, @CurrentUser LoginUser loginUser) {
return clientUserSevice.deleteTenant(dto, loginUser);
}

/**
* 查询对应业务平台的所有角色
*
* @param clientId 平台标识
* @param loginUser
* @return
*/
@GetMapping("/getRoleList")
public JsonResult getRoleList(String clientId, @CurrentUser LoginUser loginUser) {
return clientUserSevice.getRoleList(clientId, loginUser);
}
}

+ 23
- 0
tuoheng_oidc_admin/src/main/java/com/tuoheng/model/dto/ClientRoleListDto.java Ver arquivo

@@ -0,0 +1,23 @@
package com.tuoheng.model.dto;

import lombok.Data;

import java.util.List;

/**
* @Author xiaoying
* @Date 2023/3/3 17:44
*/
@Data
public class ClientRoleListDto {

private String clientId;
/**
* 平台名称
*/
private String platformName;

private List<RoleDto> roleDtoList;


}

+ 3
- 2
tuoheng_oidc_admin/src/main/java/com/tuoheng/model/dto/OidcTenantDto.java Ver arquivo

@@ -1,5 +1,6 @@
package com.tuoheng.model.dto;

import com.tuoheng.model.param.ClientRoleDto;
import lombok.Data;

/**
@@ -22,9 +23,9 @@ public class OidcTenantDto {
*/
private String tenantName;
/**
* 平台
* 平台集合
*/
private String clientId;
private ClientRoleDto clientRoleDto;
/**
* 密码
*/

+ 33
- 0
tuoheng_oidc_admin/src/main/java/com/tuoheng/model/dto/RoleDto.java Ver arquivo

@@ -0,0 +1,33 @@
package com.tuoheng.model.dto;

import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;

/**
* <p>
* 系统角色表
* </p>
*
* @author 拓恒
* @since 2020-10-31
*/
@Data
public class RoleDto {

/**
* 角色id
*/
private Integer id;

/**
* 角色名称
*/
private String roleName;

/**
* 角色标签
*/
private String code;
}

+ 9
- 0
tuoheng_oidc_admin/src/main/java/com/tuoheng/service/ClientUserSevice.java Ver arquivo

@@ -55,4 +55,13 @@ public interface ClientUserSevice {
* @return
*/
JsonResult findUserList(UserQuery query);
/**
* 查询对应业务平台的所有角色
*
* @param clientId 平台标识
* @param loginUser
* @return
*/
JsonResult getRoleList(String clientId, LoginUser loginUser);

}

+ 124
- 22
tuoheng_oidc_admin/src/main/java/com/tuoheng/service/impl/ClientUserServiceImpl.java Ver arquivo

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

BIN
tuoheng_oidc_admin/target/classes/com/tuoheng/constant/HhzUrlConstant.class Ver arquivo


BIN
tuoheng_oidc_admin/target/classes/com/tuoheng/controller/TenantController.class Ver arquivo


BIN
tuoheng_oidc_admin/target/classes/com/tuoheng/model/dto/OidcTenantDto.class Ver arquivo


BIN
tuoheng_oidc_admin/target/classes/com/tuoheng/model/vo/TenantVo.class Ver arquivo


BIN
tuoheng_oidc_admin/target/classes/com/tuoheng/service/ClientUserSevice.class Ver arquivo


BIN
tuoheng_oidc_admin/target/classes/com/tuoheng/service/impl/ClientUserServiceImpl.class Ver arquivo


Carregando…
Cancelar
Salvar