Browse Source

增加查询租户列表进行平台过滤筛选

tags/v2.4.1
xiaoying 1 year ago
parent
commit
6ee2f9a03a
14 changed files with 59 additions and 36 deletions
  1. +1
    -1
      tuoheng_oidc_admin/src/main/java/com/tuoheng/controller/AreaController.java
  2. +2
    -0
      tuoheng_oidc_admin/src/main/java/com/tuoheng/mapper/AuthoritiesMapper.java
  3. +1
    -1
      tuoheng_oidc_admin/src/main/java/com/tuoheng/mapper/TenantMapper.java
  4. +4
    -0
      tuoheng_oidc_admin/src/main/java/com/tuoheng/model/query/TenantQuery.java
  5. +3
    -0
      tuoheng_oidc_admin/src/main/java/com/tuoheng/model/vo/TenantVo.java
  6. +0
    -8
      tuoheng_oidc_admin/src/main/java/com/tuoheng/service/impl/ClientUserServiceImpl.java
  7. +37
    -22
      tuoheng_oidc_admin/src/main/java/com/tuoheng/service/impl/TenantServiceImpl.java
  8. +8
    -1
      tuoheng_oidc_admin/src/main/resources/mapper/AuthoritiesMapper.xml
  9. +3
    -3
      tuoheng_oidc_admin/src/main/resources/mapper/TenantMapper.xml
  10. BIN
      tuoheng_oidc_admin/target/classes/com/tuoheng/controller/TenantController.class
  11. BIN
      tuoheng_oidc_admin/target/classes/com/tuoheng/mapper/AuthoritiesMapper.class
  12. BIN
      tuoheng_oidc_admin/target/classes/com/tuoheng/mapper/TenantMapper.class
  13. BIN
      tuoheng_oidc_admin/target/classes/com/tuoheng/model/vo/TenantVo.class
  14. BIN
      tuoheng_oidc_admin/target/classes/com/tuoheng/service/impl/ClientUserServiceImpl.class

+ 1
- 1
tuoheng_oidc_admin/src/main/java/com/tuoheng/controller/AreaController.java View File

@@ -38,7 +38,7 @@ public class AreaController {
* @param entity
* @return
*/
@GetMapping("/index")
@PostMapping("/add")
public JsonResult add(@Valid @RequestBody Area entity){
return areaService.add(entity);
}

+ 2
- 0
tuoheng_oidc_admin/src/main/java/com/tuoheng/mapper/AuthoritiesMapper.java View File

@@ -1,6 +1,7 @@
package com.tuoheng.mapper;

import com.tuoheng.model.po.AuthoritiesPo;
import com.tuoheng.model.query.TenantQuery;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;

@@ -18,4 +19,5 @@ public interface AuthoritiesMapper {

List<AuthoritiesPo> selectByUserId(@Param("userId") Long userId);

List<AuthoritiesPo> selectListByUserIdAndClientId(@Param("userId") Long userId, @Param("query") TenantQuery query);
}

+ 1
- 1
tuoheng_oidc_admin/src/main/java/com/tuoheng/mapper/TenantMapper.java View File

@@ -24,7 +24,7 @@ public interface TenantMapper {

TTenant getByCode(@Param("code") String code);

IPage<TenantPo> findList(@Param("page") IPage<TenantVo> page, @Param("query") TenantQuery query);
IPage<TenantVo> findList(@Param("page") IPage<TenantVo> page, @Param("query") TenantQuery query);

void updateById(TenantPo tenantPo);


+ 4
- 0
tuoheng_oidc_admin/src/main/java/com/tuoheng/model/query/TenantQuery.java View File

@@ -17,4 +17,8 @@ public class TenantQuery extends BaseQuery {
* 租户账号
*/
private String username;
/**
* 平台标识
*/
private String clientId;
}

+ 3
- 0
tuoheng_oidc_admin/src/main/java/com/tuoheng/model/vo/TenantVo.java View File

@@ -72,4 +72,7 @@ public class TenantVo {
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
private Date updateTime;

private Long userId;


}

+ 0
- 8
tuoheng_oidc_admin/src/main/java/com/tuoheng/service/impl/ClientUserServiceImpl.java View File

@@ -56,14 +56,6 @@ public class ClientUserServiceImpl implements ClientUserSevice {
@Autowired
private ClientUserRoleMapper clientUserRoleMapper;

@Autowired
private RestTemplate restTemplate;

@Autowired
private PlatformMapper platformMapper;
@Autowired
private Oauth2RegisteredClientMapper oauth2RegisteredClientMapper;

@Override
@Transactional(readOnly = true)
public JsonResult judgeCreate(String username) {

+ 37
- 22
tuoheng_oidc_admin/src/main/java/com/tuoheng/service/impl/TenantServiceImpl.java View File

@@ -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("该业务平台不存在");

+ 8
- 1
tuoheng_oidc_admin/src/main/resources/mapper/AuthoritiesMapper.xml View File

@@ -14,5 +14,12 @@
FROM authorities
WHERE user_id = #{userId}
</select>

<select id="selectListByUserIdAndClientId" resultType="com.tuoheng.model.po.AuthoritiesPo">
SELECT id, user_id, username, authority
FROM authorities
WHERE user_id = #{userId}
<if test="query.clientId != null and query.clientId != ''">
and authority LIKE concat('%',#{query.clientId},'%')
</if>
</select>
</mapper>

+ 3
- 3
tuoheng_oidc_admin/src/main/resources/mapper/TenantMapper.xml View File

@@ -46,9 +46,9 @@
where code = #{code}
and enabled = 1
</select>
<select id="findList" resultType="com.tuoheng.model.po.TenantPo">
SELECT t.id, t.user_id, t.remark, t.code,
t.name,t.province_code,t.province_name,t.city_code,t.city_name,t.district_code,t.district_name,u.username
<select id="findList" resultType="com.tuoheng.model.vo.TenantVo">
SELECT t.id, t.user_id userId, t.remark, t.code tenantCode,
t.name tenantName,t.province_code,t.province_name,t.city_code,t.city_name,t.district_code,t.district_name,u.username
username
FROM t_tenant t,users u
WHERE t.enabled = 1 and u.enabled =1 and t.user_id =u.id

BIN
tuoheng_oidc_admin/target/classes/com/tuoheng/controller/TenantController.class View File


BIN
tuoheng_oidc_admin/target/classes/com/tuoheng/mapper/AuthoritiesMapper.class View File


BIN
tuoheng_oidc_admin/target/classes/com/tuoheng/mapper/TenantMapper.class View File


BIN
tuoheng_oidc_admin/target/classes/com/tuoheng/model/vo/TenantVo.class View File


BIN
tuoheng_oidc_admin/target/classes/com/tuoheng/service/impl/ClientUserServiceImpl.class View File


Loading…
Cancel
Save