@@ -1,5 +1,6 @@ | |||
package com.tuoheng.config; | |||
import com.alibaba.druid.util.StringUtils; | |||
import com.alibaba.fastjson.JSON; | |||
import com.alibaba.fastjson.JSONObject; | |||
import com.tuoheng.mapper.ClientUserMapper; | |||
@@ -35,6 +36,9 @@ public class LoginUserHandler implements HandlerMethodArgumentResolver { | |||
// header中获取用户token | |||
String token = request.getHeader("th-token"); | |||
String oUserJson = request.getHeader("o-user-json"); | |||
if(StringUtils.isEmpty(token) || StringUtils.isEmpty(oUserJson)){ | |||
return new LoginUser(); | |||
} | |||
String json = EncryptUtil.decodeUTF8StringBase64(oUserJson); | |||
JSONObject jsonObject = JSON.parseObject(json); | |||
String username = jsonObject.getString("username"); |
@@ -0,0 +1,41 @@ | |||
package com.tuoheng.controller; | |||
import com.tuoheng.model.dto.LoginUser; | |||
import com.tuoheng.model.param.CreateClientTenantDto; | |||
import com.tuoheng.model.param.GetClientTenantRoleDto; | |||
import com.tuoheng.service.ClientSevice; | |||
import com.tuoheng.service.ClientUserSevice; | |||
import com.tuoheng.service.CurrentUser; | |||
import com.tuoheng.until.JsonResult; | |||
import lombok.extern.slf4j.Slf4j; | |||
import org.springframework.beans.factory.annotation.Autowired; | |||
import org.springframework.web.bind.annotation.PostMapping; | |||
import org.springframework.web.bind.annotation.RequestBody; | |||
import org.springframework.web.bind.annotation.RequestMapping; | |||
import org.springframework.web.bind.annotation.RestController; | |||
/** | |||
* @author chenjiandong | |||
* @description: TODO | |||
* @date 2022/12/7 16:17 | |||
*/ | |||
@RestController | |||
@RequestMapping("/client") | |||
@Slf4j | |||
public class ClientController { | |||
@Autowired | |||
private ClientSevice clientSevice; | |||
@PostMapping("/getAllClient") | |||
public JsonResult getAllClient(@CurrentUser LoginUser loginUser){ | |||
return clientSevice.getAllClient(); | |||
} | |||
@PostMapping("/getClientTenantRole") | |||
public JsonResult getClientTenantRole(@RequestBody GetClientTenantRoleDto getClientTenantRoleDto, | |||
@CurrentUser LoginUser loginUser){ | |||
return clientSevice.getClientTenantRole(getClientTenantRoleDto); | |||
} | |||
} |
@@ -0,0 +1,19 @@ | |||
package com.tuoheng.mapper; | |||
import com.tuoheng.model.dto.ClientDto; | |||
import com.tuoheng.model.po.UserPo; | |||
import org.apache.ibatis.annotations.Mapper; | |||
import java.util.List; | |||
/** | |||
* @author chenjiandong | |||
* @description: TODO | |||
* @date 2022/10/8 11:59 | |||
*/ | |||
@Mapper | |||
public interface ClientMapper { | |||
List<ClientDto> getAllClient(); | |||
} |
@@ -14,6 +14,8 @@ import java.util.List; | |||
@Mapper | |||
public interface ClientUserRoleMapper { | |||
int insert(ClientUserRolePo clientUserRolePo); | |||
int batchInsert(List<ClientUserRolePo> list); | |||
int updateUserClientRole(ClientUserRolePo clientUserRolePo); |
@@ -0,0 +1,17 @@ | |||
package com.tuoheng.model.dto; | |||
import lombok.Data; | |||
/** | |||
* @author chenjiandong | |||
* @description: TODO | |||
* @date 2022/12/12 9:16 | |||
*/ | |||
@Data | |||
public class ClientDto { | |||
private String clientId; | |||
private String clientName; | |||
} |
@@ -0,0 +1,19 @@ | |||
package com.tuoheng.model.dto; | |||
import lombok.Data; | |||
import lombok.experimental.Accessors; | |||
/** | |||
* @author chenjiandong | |||
* @description: TODO | |||
* @date 2022/12/12 10:01 | |||
*/ | |||
@Data | |||
@Accessors(chain = true) | |||
public class ClientRoleInfoDto { | |||
private Integer roleId; | |||
private String roleName; | |||
} |
@@ -0,0 +1,15 @@ | |||
package com.tuoheng.model.param; | |||
import lombok.Data; | |||
/** | |||
* @author chenjiandong | |||
* @description: TODO | |||
* @date 2022/12/12 9:53 | |||
*/ | |||
@Data | |||
public class GetClientTenantRoleDto { | |||
private String clientId; | |||
} |
@@ -0,0 +1,17 @@ | |||
package com.tuoheng.service; | |||
import com.tuoheng.model.param.GetClientTenantRoleDto; | |||
import com.tuoheng.until.JsonResult; | |||
/** | |||
* @author chenjiandong | |||
* @description: TODO | |||
* @date 2022/10/8 11:35 | |||
*/ | |||
public interface ClientSevice { | |||
JsonResult getAllClient(); | |||
JsonResult getClientTenantRole(GetClientTenantRoleDto getClientTenantRoleDto); | |||
} |
@@ -0,0 +1,45 @@ | |||
package com.tuoheng.service.impl; | |||
import com.tuoheng.mapper.ClientMapper; | |||
import com.tuoheng.model.dto.ClientRoleInfoDto; | |||
import com.tuoheng.model.param.ClientRoleDto; | |||
import com.tuoheng.model.param.GetClientTenantRoleDto; | |||
import com.tuoheng.service.ClientSevice; | |||
import com.tuoheng.until.JsonResult; | |||
import org.springframework.beans.factory.annotation.Autowired; | |||
import org.springframework.stereotype.Service; | |||
import org.springframework.transaction.annotation.Transactional; | |||
import java.util.ArrayList; | |||
import java.util.List; | |||
/** | |||
* @author chenjiandong | |||
* @description: TODO | |||
* @date 2022/10/8 11:35 | |||
*/ | |||
@Service | |||
public class ClientServiceImpl implements ClientSevice { | |||
@Autowired | |||
private ClientMapper clientMapper; | |||
@Override | |||
@Transactional(readOnly = true) | |||
public JsonResult getAllClient(){ | |||
return JsonResult.success(clientMapper.getAllClient()); | |||
} | |||
@Override | |||
@Transactional(readOnly = true) | |||
public JsonResult getClientTenantRole(GetClientTenantRoleDto getClientTenantRoleDto){ | |||
List<ClientRoleInfoDto> clientRoleInfoDtos = new ArrayList<>(); | |||
ClientRoleInfoDto clientRoleInfoDto = new ClientRoleInfoDto() | |||
.setRoleId(1).setRoleName("租户管理员角色"); | |||
clientRoleInfoDtos.add(clientRoleInfoDto); | |||
//todo:根据不同的 client 调用不同系统的接口,获取租户所对应的角色 | |||
return JsonResult.success(clientRoleInfoDtos); | |||
} | |||
} |
@@ -143,6 +143,7 @@ public class ClientUserServiceImpl implements ClientUserSevice { | |||
} | |||
authoritiesMapper.batchInsert(authoritiesPos); | |||
clientUserRoleMapper.batchInsert(clientUserRolePoArrayList); | |||
//todo:调用业务系统完成租户创建 | |||
return JsonResult.success(userPo.getId()); | |||
} | |||
@@ -176,7 +177,14 @@ public class ClientUserServiceImpl implements ClientUserSevice { | |||
.setClientId(dto.getClientId()) | |||
.setRoleId(dto.getRoleId()); | |||
clientUserRolePo.setUpdateUser(loginUser.getUserId()); | |||
clientUserRoleMapper.updateUserClientRole(clientUserRolePo); | |||
if(clientUserRoleMapper.updateUserClientRole(clientUserRolePo) == 0){ | |||
ClientUserRolePo insert = new ClientUserRolePo(); | |||
insert.setUserId(userPo.getId()) | |||
.setClientId(dto.getClientId()) | |||
.setRoleId(dto.getRoleId()) | |||
.setCreateUser(loginUser.getUserId()); | |||
clientUserRoleMapper.insert(insert); | |||
} | |||
} | |||
return JsonResult.success(true); | |||
} |
@@ -0,0 +1,9 @@ | |||
<?xml version="1.0" encoding="UTF-8"?> | |||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> | |||
<mapper namespace="com.tuoheng.mapper.ClientMapper"> | |||
<select id="getAllClient" resultType="com.tuoheng.model.dto.ClientDto"> | |||
select client_id as clientId, client_name as clientName from oauth2_registered_client | |||
</select> | |||
</mapper> |
@@ -10,6 +10,11 @@ | |||
</foreach > | |||
</insert> | |||
<insert id="insert" parameterType="com.tuoheng.model.po.ClientUserRolePo"> | |||
insert into t_client_user_role (user_id, client_id, role_id, create_user) | |||
VALUES (#{userId}, #{clientId}, #{roleId}, #{createUser}) | |||
</insert> | |||
<update id="updateUserClientRole" parameterType="com.tuoheng.model.po.ClientUserRolePo"> | |||
update t_client_user_role | |||
<set> |