浏览代码

新增更新租户接口

tags/v2.4.0
xiaoying 1年前
父节点
当前提交
55152ca7f9
共有 6 个文件被更改,包括 103 次插入6 次删除
  1. +3
    -0
      tuoheng_oidc_admin/src/main/java/com/tuoheng/mapper/TenantMapper.java
  2. +4
    -0
      tuoheng_oidc_admin/src/main/java/com/tuoheng/model/dto/OidcTenantDto.java
  3. +87
    -5
      tuoheng_oidc_admin/src/main/java/com/tuoheng/service/impl/ClientUserServiceImpl.java
  4. +9
    -1
      tuoheng_oidc_admin/src/main/resources/mapper/TenantMapper.xml
  5. 二进制
      tuoheng_oidc_admin/target/classes/com/tuoheng/mapper/TenantMapper.class
  6. 二进制
      tuoheng_oidc_admin/target/classes/com/tuoheng/service/impl/ClientUserServiceImpl.class

+ 3
- 0
tuoheng_oidc_admin/src/main/java/com/tuoheng/mapper/TenantMapper.java 查看文件

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

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.tuoheng.model.dto.OidcTenantDto;
import com.tuoheng.model.dto.TTenant;
import com.tuoheng.model.po.TenantPo;
import com.tuoheng.model.query.TenantQuery;
@@ -25,4 +26,6 @@ public interface TenantMapper {

IPage<TenantPo> 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/dto/OidcTenantDto.java 查看文件

@@ -9,6 +9,10 @@ import lombok.Data;
*/
@Data
public class OidcTenantDto {
/**
* 租户id
*/
private Long id;
/**
* 用户名
*/

+ 87
- 5
tuoheng_oidc_admin/src/main/java/com/tuoheng/service/impl/ClientUserServiceImpl.java 查看文件

@@ -257,7 +257,7 @@ public class ClientUserServiceImpl implements ClientUserSevice {
}
//开启分页
IPage<TenantVo> page = new Page<>(query.getPage(), query.getLimit());
IPage<TenantPo> pageData = tenantMapper.findList(page,query);
IPage<TenantPo> pageData = tenantMapper.findList(page, query);
pageData.convert(x -> {
TenantVo vo = Convert.convert(TenantVo.class, x);
Long userId = x.getUserId();
@@ -289,14 +289,49 @@ public class ClientUserServiceImpl implements ClientUserSevice {
* @return
*/
@Override
@Transactional(rollbackFor = Exception.class)
public JsonResult editTenant(OidcTenantDto dto, LoginUser loginUser) {


//TODO
return null;
if (ObjectUtil.isEmpty(dto.getCode())) {
return JsonResult.error("租户code不能为空");
}
if (dto.getClientId().contains(",")) {
String[] codes = dto.getClientId().split(",");
for (String code : codes) {
JsonResult jsonResult = editResult(dto, code, loginUser);
if (!"操作成功".equals(jsonResult.getMsg())) {
return jsonResult;
}
}
} else {
JsonResult jsonResult = editResult(dto, dto.getClientId(), loginUser);
if (!"操作成功".equals(jsonResult.getMsg())) {
return jsonResult;
}
}
TTenant tTenant = tenantMapper.getByCode(dto.getCode());
dto.setId(tTenant.getId());
//更新密码
dto.setPassword("{bcrypt}" + new BCryptPasswordEncoder().encode(dto.getPassword()));
TenantPo tenantPo = new TenantPo();
tenantPo.setName(dto.getName())
.setId(dto.getId());
tenantMapper.updateById(tenantPo);
UserPo userPo = new UserPo();
userPo.setUsername(dto.getUsername())
.setPassword(dto.getPassword());
clientUserMapper.updatePass(userPo);
return JsonResult.success();
}


/**
* 新增请求
*
* @param dto
* @param code
* @param loginUser
* @return
*/
private JsonResult getResult(OidcTenantDto dto, String code, LoginUser loginUser) {
Platform platform = platformMapper.selectOne(Wrappers.<Platform>lambdaQuery()
.eq(Platform::getPlatformCode, code)
@@ -330,4 +365,51 @@ public class ClientUserServiceImpl implements ClientUserSevice {
}
return JsonResult.success();
}

/**
* 更新请求
*
* @param dto
* @param code
* @param loginUser
* @return
*/
private JsonResult editResult(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.UPDATE_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();
}
}

+ 9
- 1
tuoheng_oidc_admin/src/main/resources/mapper/TenantMapper.xml 查看文件

@@ -6,7 +6,15 @@
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>
</set>
where id = #{id}
</update>
<select id="getByCode" resultType="com.tuoheng.model.dto.TTenant">
select *
from tuoheng_oidc.t_tenant

二进制
tuoheng_oidc_admin/target/classes/com/tuoheng/mapper/TenantMapper.class 查看文件


二进制
tuoheng_oidc_admin/target/classes/com/tuoheng/service/impl/ClientUserServiceImpl.class 查看文件


正在加载...
取消
保存