Browse Source

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

tags/v2.4.0
xiaoying 1 year ago
parent
commit
efaeb1d0ac
14 changed files with 133 additions and 8 deletions
  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. BIN
      tuoheng_oidc_admin/target/classes/com/tuoheng/constant/HhzUrlConstant.class
  9. BIN
      tuoheng_oidc_admin/target/classes/com/tuoheng/controller/TenantController.class
  10. BIN
      tuoheng_oidc_admin/target/classes/com/tuoheng/mapper/TenantMapper.class
  11. BIN
      tuoheng_oidc_admin/target/classes/com/tuoheng/model/dto/OidcTenantDto.class
  12. BIN
      tuoheng_oidc_admin/target/classes/com/tuoheng/service/ClientUserSevice.class
  13. BIN
      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 View File

package com.tuoheng.constant; package com.tuoheng.constant;


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


public static String HHZ_CLIENT="tuoheng-hhz";

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

/** /**
* 创建租户 * 创建租户
*/ */
*/ */
public static String UPDATE_TENANT = "/oidcTenant/edit"; 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 View File



} }


/**
* 删除租户(逻辑删除)
* @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 View File



void updateById(TenantPo tenantPo); void updateById(TenantPo tenantPo);


TenantPo selectById(Long id);
} }

+ 5
- 1
tuoheng_oidc_admin/src/main/java/com/tuoheng/service/ClientUserSevice.java View File

JsonResult findTenants(TenantQuery query); JsonResult findTenants(TenantQuery query);


JsonResult editTenant(OidcTenantDto dto, LoginUser loginUser); 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 View File



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


/** /**
* @author chenjiandong * @author chenjiandong
List<BusinessSystemVo> businessSystemVoList = new ArrayList<>(); List<BusinessSystemVo> businessSystemVoList = new ArrayList<>();
for (AuthoritiesPo authoritiesPo : poList) { for (AuthoritiesPo authoritiesPo : poList) {
BusinessSystemVo businessSystemVo = new BusinessSystemVo(); 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); vo.setList(businessSystemVoList);
return vo; return vo;
}); });
return JsonResult.success(pageData); 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();
}

/** /**
* 更新业务平台租户的相关基本信息 * 更新业务平台租户的相关基本信息
* *
//设置地址(hhz平台) //设置地址(hhz平台)
String url = platform.getPlatformUrl(); String url = platform.getPlatformUrl();
//根据不同业务平台进行动态匹配 //根据不同业务平台进行动态匹配
//TODO 后期维护各个业务平台
if (url.contains("hhz")) { if (url.contains("hhz")) {
url = url + HhzUrlConstant.CREATE_TENANT; url = url + HhzUrlConstant.CREATE_TENANT;
} }
} }
return JsonResult.success(); 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 View File

<if test="updateUser != null"> <if test="updateUser != null">
update_user = #{updateUser}, update_user = #{updateUser},
</if> </if>
<if test="enabled != null">
enabled = #{enabled},
</if>
</set> </set>
where username = #{username,jdbcType=VARCHAR} where username = #{username,jdbcType=VARCHAR}
</update> </update>

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

<if test="name !=null and name !=''"> <if test="name !=null and name !=''">
name = #{name}, name = #{name},
</if> </if>
<if test="enabled !=null">
enabled = #{enabled},
</if>
</set> </set>
where id = #{id} where id = #{id}
</update> </update>
</if> </if>
ORDER BY create_time desc ORDER BY create_time desc
</select> </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> </mapper>

BIN
tuoheng_oidc_admin/target/classes/com/tuoheng/constant/HhzUrlConstant.class View File


BIN
tuoheng_oidc_admin/target/classes/com/tuoheng/controller/TenantController.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/dto/OidcTenantDto.class View File


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


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


+ 17
- 1
tuoheng_oidc_admin/target/classes/mapper/TenantMapper.xml View File

INSERT INTO t_tenant (user_id, remark, `code`, `name`) INSERT INTO t_tenant (user_id, remark, `code`, `name`)
VALUES (#{userId}, #{remark}, #{code}, #{name}) VALUES (#{userId}, #{remark}, #{code}, #{name})
</insert> </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 id="getByCode" resultType="com.tuoheng.model.dto.TTenant">
select * select *
from tuoheng_oidc.t_tenant from tuoheng_oidc.t_tenant
</if> </if>
ORDER BY create_time desc ORDER BY create_time desc
</select> </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> </mapper>

Loading…
Cancel
Save