Преглед на файлове

新增删除租户接口 及租户查询的回显

tags/v2.4.0
xiaoying преди 1 година
родител
ревизия
efaeb1d0ac
променени са 14 файла, в които са добавени 133 реда и са изтрити 8 реда
  1. +9
    -1
      tuoheng_oidc_admin/src/main/java/com/tuoheng/constant/HhzUrlConstant.java
  2. +9
    -0
      tuoheng_oidc_admin/src/main/java/com/tuoheng/controller/TenantController.java
  3. +1
    -0
      tuoheng_oidc_admin/src/main/java/com/tuoheng/mapper/TenantMapper.java
  4. +5
    -1
      tuoheng_oidc_admin/src/main/java/com/tuoheng/service/ClientUserSevice.java
  5. +81
    -5
      tuoheng_oidc_admin/src/main/java/com/tuoheng/service/impl/ClientUserServiceImpl.java
  6. +3
    -0
      tuoheng_oidc_admin/src/main/resources/mapper/ClientUserMapper.xml
  7. +8
    -0
      tuoheng_oidc_admin/src/main/resources/mapper/TenantMapper.xml
  8. Двоични данни
      tuoheng_oidc_admin/target/classes/com/tuoheng/constant/HhzUrlConstant.class
  9. Двоични данни
      tuoheng_oidc_admin/target/classes/com/tuoheng/controller/TenantController.class
  10. Двоични данни
      tuoheng_oidc_admin/target/classes/com/tuoheng/mapper/TenantMapper.class
  11. Двоични данни
      tuoheng_oidc_admin/target/classes/com/tuoheng/model/dto/OidcTenantDto.class
  12. Двоични данни
      tuoheng_oidc_admin/target/classes/com/tuoheng/service/ClientUserSevice.class
  13. Двоични данни
      tuoheng_oidc_admin/target/classes/com/tuoheng/service/impl/ClientUserServiceImpl.class
  14. +17
    -1
      tuoheng_oidc_admin/target/classes/mapper/TenantMapper.xml

+ 9
- 1
tuoheng_oidc_admin/src/main/java/com/tuoheng/constant/HhzUrlConstant.java Целия файл

@@ -1,12 +1,16 @@
package com.tuoheng.constant;

/**
* hhz平台接口常量url
* hhz平台接口常量
* @Author xiaoying
* @Date 2022/10/18 10:52
*/
public class HhzUrlConstant {

public static String HHZ_CLIENT="tuoheng-hhz";

public static String HHZ_NAME="河湖长业务平台";

/**
* 创建租户
*/
@@ -16,4 +20,8 @@ public class HhzUrlConstant {
*/
public static String UPDATE_TENANT = "/oidcTenant/edit";

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



}

+ 9
- 0
tuoheng_oidc_admin/src/main/java/com/tuoheng/controller/TenantController.java Целия файл

@@ -61,4 +61,13 @@ public class TenantController {

}

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

}

+ 1
- 0
tuoheng_oidc_admin/src/main/java/com/tuoheng/mapper/TenantMapper.java Целия файл

@@ -28,4 +28,5 @@ public interface TenantMapper {

void updateById(TenantPo tenantPo);

TenantPo selectById(Long id);
}

+ 5
- 1
tuoheng_oidc_admin/src/main/java/com/tuoheng/service/ClientUserSevice.java Целия файл

@@ -36,5 +36,9 @@ public interface ClientUserSevice {
JsonResult findTenants(TenantQuery query);

JsonResult editTenant(OidcTenantDto dto, LoginUser loginUser);

/**
* 删除租户(逻辑删除)
* @return
*/
JsonResult deleteTenant(OidcTenantDto dto, LoginUser loginUser);
}

+ 81
- 5
tuoheng_oidc_admin/src/main/java/com/tuoheng/service/impl/ClientUserServiceImpl.java Целия файл

@@ -32,6 +32,7 @@ import org.springframework.web.client.RestTemplate;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

/**
* @author chenjiandong
@@ -269,18 +270,45 @@ public class ClientUserServiceImpl implements ClientUserSevice {
List<BusinessSystemVo> businessSystemVoList = new ArrayList<>();
for (AuthoritiesPo authoritiesPo : poList) {
BusinessSystemVo businessSystemVo = new BusinessSystemVo();
Oauth2RegisteredClient oauth2RegisteredClient = oauth2RegisteredClientMapper.selectOne(Wrappers.<Oauth2RegisteredClient>lambdaQuery()
.eq(Oauth2RegisteredClient::getClientId, authoritiesPo.getAuthority()));
businessSystemVo.setClientId(authoritiesPo.getAuthority());
businessSystemVo.setName(oauth2RegisteredClient.getClientName());
businessSystemVoList.add(businessSystemVo);
//TODO 后期维护各个业务平台
if ( authoritiesPo.getAuthority().contains("hhz")){
businessSystemVo.setClientId(HhzUrlConstant.HHZ_CLIENT);
businessSystemVo.setName(HhzUrlConstant.HHZ_NAME);
businessSystemVoList.add(businessSystemVo);
}
}
businessSystemVoList=businessSystemVoList.stream().distinct().collect(Collectors.toList());
vo.setList(businessSystemVoList);
return vo;
});
return JsonResult.success(pageData);
}

/**
* 删除租户(逻辑删除)
*
* @return
*/
@Override
@Transactional(rollbackFor = Exception.class)
public JsonResult deleteTenant(OidcTenantDto dto, LoginUser loginUser) {
TenantPo tenantPo = tenantMapper.selectById(dto.getId());
tenantPo.setEnabled(0);
tenantMapper.updateById(tenantPo);
UserPo userPo = clientUserMapper.selectByUserId(tenantPo.getUserId());
userPo.setEnabled(0);
clientUserMapper.updatePass(userPo);
if (dto.getClientId().contains(",")) {
String[] codes = dto.getClientId().split(",");
for (String code : codes) {
return deleteResult(dto, code, loginUser);
}
} else {
return deleteResult(dto, dto.getClientId(), loginUser);
}
return JsonResult.success();
}

/**
* 更新业务平台租户的相关基本信息
*
@@ -346,6 +374,7 @@ public class ClientUserServiceImpl implements ClientUserSevice {
//设置地址(hhz平台)
String url = platform.getPlatformUrl();
//根据不同业务平台进行动态匹配
//TODO 后期维护各个业务平台
if (url.contains("hhz")) {
url = url + HhzUrlConstant.CREATE_TENANT;
}
@@ -412,4 +441,51 @@ public class ClientUserServiceImpl implements ClientUserSevice {
}
return JsonResult.success();
}

/**
* 删除请求
*
* @param dto
* @param code
* @param loginUser
* @return
*/
private JsonResult deleteResult(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();
//根据不同业务平台进行动态匹配
if (url.contains("hhz")) {
url = url + HhzUrlConstant.DELETE_TENANT;
}
//else if (url.contains("lc")) {
// url = url + HhzUrlConstant.UPDATE_TENANT;
//} else if (url.contains("gs")) {
// url = url + HhzUrlConstant.UPDATE_TENANT;
//}
ResponseEntity<JsonResult> response;
try {
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("业务平台删除租户响应失败" + response.getBody());
return JsonResult.error(response.getBody().getMsg());
}
return JsonResult.success();
}
}

+ 3
- 0
tuoheng_oidc_admin/src/main/resources/mapper/ClientUserMapper.xml Целия файл

@@ -39,6 +39,9 @@
<if test="updateUser != null">
update_user = #{updateUser},
</if>
<if test="enabled != null">
enabled = #{enabled},
</if>
</set>
where username = #{username,jdbcType=VARCHAR}
</update>

+ 8
- 0
tuoheng_oidc_admin/src/main/resources/mapper/TenantMapper.xml Целия файл

@@ -12,6 +12,9 @@
<if test="name !=null and name !=''">
name = #{name},
</if>
<if test="enabled !=null">
enabled = #{enabled},
</if>
</set>
where id = #{id}
</update>
@@ -29,4 +32,9 @@
</if>
ORDER BY create_time desc
</select>
<select id="selectById" resultType="com.tuoheng.model.po.TenantPo">
SELECT id, user_id, remark, enabled, code, name
FROM t_tenant
WHERE id = #{id}
</select>
</mapper>

Двоични данни
tuoheng_oidc_admin/target/classes/com/tuoheng/constant/HhzUrlConstant.class Целия файл


Двоични данни
tuoheng_oidc_admin/target/classes/com/tuoheng/controller/TenantController.class Целия файл


Двоични данни
tuoheng_oidc_admin/target/classes/com/tuoheng/mapper/TenantMapper.class Целия файл


Двоични данни
tuoheng_oidc_admin/target/classes/com/tuoheng/model/dto/OidcTenantDto.class Целия файл


Двоични данни
tuoheng_oidc_admin/target/classes/com/tuoheng/service/ClientUserSevice.class Целия файл


Двоични данни
tuoheng_oidc_admin/target/classes/com/tuoheng/service/impl/ClientUserServiceImpl.class Целия файл


+ 17
- 1
tuoheng_oidc_admin/target/classes/mapper/TenantMapper.xml Целия файл

@@ -6,7 +6,18 @@
INSERT INTO t_tenant (user_id, remark, `code`, `name`)
VALUES (#{userId}, #{remark}, #{code}, #{name})
</insert>

<update id="updateById" parameterType="com.tuoheng.model.po.TenantPo">
update t_tenant
<set>
<if test="name !=null and name !=''">
name = #{name},
</if>
<if test="enabled !=null">
enabled = #{enabled},
</if>
</set>
where id = #{id}
</update>
<select id="getByCode" resultType="com.tuoheng.model.dto.TTenant">
select *
from tuoheng_oidc.t_tenant
@@ -21,4 +32,9 @@
</if>
ORDER BY create_time desc
</select>
<select id="selectById" resultType="com.tuoheng.model.po.TenantPo">
SELECT id, user_id, remark, enabled, code, name
FROM t_tenant
WHERE id = #{id}
</select>
</mapper>

Loading…
Отказ
Запис