Browse Source

Merge branch 'develop' of gitadmin/tuoheng_oidc into release

tags/v2.3.0^2
gitadmin 1 year ago
parent
commit
e9b22705c7
7 changed files with 172 additions and 5 deletions
  1. +35
    -0
      tuoheng_oidc_admin/src/main/java/com/tuoheng/controller/TenantController.java
  2. +16
    -0
      tuoheng_oidc_admin/src/main/java/com/tuoheng/mapper/TenantMapper.java
  3. +28
    -0
      tuoheng_oidc_admin/src/main/java/com/tuoheng/model/param/CreateClientTenantDto.java
  4. +23
    -0
      tuoheng_oidc_admin/src/main/java/com/tuoheng/model/po/TenantPo.java
  5. +3
    -0
      tuoheng_oidc_admin/src/main/java/com/tuoheng/service/ClientUserSevice.java
  6. +58
    -5
      tuoheng_oidc_admin/src/main/java/com/tuoheng/service/impl/ClientUserServiceImpl.java
  7. +9
    -0
      tuoheng_oidc_admin/src/main/resources/mapper/TenantMapper.xml

+ 35
- 0
tuoheng_oidc_admin/src/main/java/com/tuoheng/controller/TenantController.java View File

@@ -0,0 +1,35 @@
package com.tuoheng.controller;

import com.tuoheng.model.dto.LoginUser;
import com.tuoheng.model.param.CreateClientTenantDto;
import com.tuoheng.model.param.CreateClientUserDto;
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("/tenant")
@Slf4j
public class TenantController {

@Autowired
private ClientUserSevice clientUserSevice;

@PostMapping("/create")
public JsonResult createClientTenant(@RequestBody CreateClientTenantDto createClientTenantDto,
@CurrentUser LoginUser loginUser){
return clientUserSevice.createClientTenant(createClientTenantDto, loginUser);
}

}

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

@@ -0,0 +1,16 @@
package com.tuoheng.mapper;

import com.tuoheng.model.po.TenantPo;
import org.apache.ibatis.annotations.Mapper;

/**
* @author chenjiandong
* @description: TODO
* @date 2022/12/9 9:30
*/
@Mapper
public interface TenantMapper {

int insertTenant(TenantPo tenantPo);

}

+ 28
- 0
tuoheng_oidc_admin/src/main/java/com/tuoheng/model/param/CreateClientTenantDto.java View File

@@ -0,0 +1,28 @@
package com.tuoheng.model.param;

import lombok.Data;

import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.util.List;

/**
* @author chenjiandong
* @description: TODO
* @date 2022/12/8 10:16
*/
@Data
public class CreateClientTenantDto {

@NotEmpty(message = "username can not be empty!")
private String username;

@NotEmpty(message = "password can not be empty!")
private String password;

private String remark;

@NotNull(message = "clientRoleDtoList can not be null!")
private List<ClientRoleDto> clientRoleDtoList;

}

+ 23
- 0
tuoheng_oidc_admin/src/main/java/com/tuoheng/model/po/TenantPo.java View File

@@ -0,0 +1,23 @@
package com.tuoheng.model.po;

import lombok.Data;
import lombok.experimental.Accessors;

/**
* @author chenjiandong
* @description: TODO
* @date 2022/12/9 9:10
*/
@Data
@Accessors(chain = true)
public class TenantPo extends BasePo {

private Long id;

private Long userId;

private String remark;

private Integer enabled;

}

+ 3
- 0
tuoheng_oidc_admin/src/main/java/com/tuoheng/service/ClientUserSevice.java View File

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

import com.tuoheng.model.dto.LoginUser;
import com.tuoheng.model.param.CreateClientTenantDto;
import com.tuoheng.model.param.CreateClientUserDto;
import com.tuoheng.model.param.UpdateUserClientRoleDto;
import com.tuoheng.model.param.UpdateUserPassDto;
@@ -17,6 +18,8 @@ public interface ClientUserSevice {

JsonResult createClientUser(CreateClientUserDto createClientUserDto, LoginUser loginUser);

JsonResult createClientTenant(CreateClientTenantDto createClientTenantDto, LoginUser loginUser);

JsonResult updateUserPassword(UpdateUserPassDto updateUserPassDto, LoginUser loginUser);

JsonResult updateUserClientRole(UpdateUserClientRoleDto updateUserClientRoleDto, LoginUser loginUser);

+ 58
- 5
tuoheng_oidc_admin/src/main/java/com/tuoheng/service/impl/ClientUserServiceImpl.java View File

@@ -3,13 +3,12 @@ package com.tuoheng.service.impl;
import com.tuoheng.mapper.AuthoritiesMapper;
import com.tuoheng.mapper.ClientUserMapper;
import com.tuoheng.mapper.ClientUserRoleMapper;
import com.tuoheng.mapper.TenantMapper;
import com.tuoheng.model.dto.LoginUser;
import com.tuoheng.model.param.ClientRoleDto;
import com.tuoheng.model.param.CreateClientUserDto;
import com.tuoheng.model.param.UpdateUserClientRoleDto;
import com.tuoheng.model.param.UpdateUserPassDto;
import com.tuoheng.model.param.*;
import com.tuoheng.model.po.AuthoritiesPo;
import com.tuoheng.model.po.ClientUserRolePo;
import com.tuoheng.model.po.TenantPo;
import com.tuoheng.model.po.UserPo;
import com.tuoheng.service.ClientUserSevice;
import com.tuoheng.until.JsonResult;
@@ -32,12 +31,16 @@ public class ClientUserServiceImpl implements ClientUserSevice {
@Autowired
private ClientUserMapper clientUserMapper;

@Autowired
private TenantMapper tenantMapper;

@Autowired
private AuthoritiesMapper authoritiesMapper;

@Autowired
private ClientUserRoleMapper clientUserRoleMapper;

@Override
@Transactional(readOnly = true)
public JsonResult judgeCreate(String username){
if(clientUserMapper.judgeCreateByUserName(username) > 0){
@@ -46,6 +49,7 @@ public class ClientUserServiceImpl implements ClientUserSevice {
return JsonResult.success(true);
}

@Override
@Transactional(rollbackFor = Exception.class)
public JsonResult createClientUser(CreateClientUserDto createClientUserDto, LoginUser loginUser){

@@ -71,7 +75,13 @@ public class ClientUserServiceImpl implements ClientUserSevice {
}
//租户逻辑新增 end
clientUserMapper.insertClientUser(userPo);

if(createClientUserDto.getTenantFlag() != null){
if(createClientUserDto.getTenantFlag() == 1){
TenantPo tenantPo = new TenantPo()
.setUserId(userPo.getId());
tenantMapper.insertTenant(tenantPo);
}
}
List<AuthoritiesPo> authoritiesPos = new ArrayList<>();
List<ClientUserRolePo> clientUserRolePoArrayList = new ArrayList<>();
for(ClientRoleDto clientRoleDto : createClientUserDto.getClientRoleDtoList()){
@@ -95,6 +105,48 @@ public class ClientUserServiceImpl implements ClientUserSevice {
return JsonResult.success(userPo.getId());
}


@Override
@Transactional(rollbackFor = Exception.class)
public JsonResult createClientTenant(CreateClientTenantDto createClientTenantDto, LoginUser loginUser){

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()
.setUserId(userPo.getId())
.setRemark(createClientTenantDto.getRemark());
tenantMapper.insertTenant(tenantPo);
List<AuthoritiesPo> authoritiesPos = new ArrayList<>();
List<ClientUserRolePo> clientUserRolePoArrayList = new ArrayList<>();
for(ClientRoleDto clientRoleDto : createClientTenantDto.getClientRoleDtoList()){
AuthoritiesPo authoritiesPo = new AuthoritiesPo()
.setUserId(userPo.getId())
.setUsername(createClientTenantDto.getUsername())
.setAuthority(clientRoleDto.getClientId());
authoritiesPo.setCreateUser(loginUser.getUserId());
authoritiesPos.add(authoritiesPo);

ClientUserRolePo clientUserRolePo = new ClientUserRolePo()
.setUserId(userPo.getId())
.setClientId(clientRoleDto.getClientId())
.setRoleId(clientRoleDto.getRoleId());
clientUserRolePo.setCreateUser(loginUser.getUserId());
clientUserRolePoArrayList.add(clientUserRolePo);

}
authoritiesMapper.batchInsert(authoritiesPos);
clientUserRoleMapper.batchInsert(clientUserRolePoArrayList);
return JsonResult.success(userPo.getId());
}

@Override
@Transactional(rollbackFor = Exception.class)
public JsonResult updateUserPassword(UpdateUserPassDto updateUserPassDto, LoginUser loginUser){

@@ -110,6 +162,7 @@ public class ClientUserServiceImpl implements ClientUserSevice {
return JsonResult.success(true);
}

@Override
@Transactional(rollbackFor = Exception.class)
public JsonResult updateUserClientRole(UpdateUserClientRoleDto updateUserClientRoleDto, LoginUser loginUser){
UserPo userPo = clientUserMapper.getUserByUserName(updateUserClientRoleDto.getUsername());

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

@@ -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.TenantMapper">

<insert id="insertTenant" parameterType="com.tuoheng.model.po.TenantPo" keyProperty="id" useGeneratedKeys="true">
insert into t_tenant (user_id, remark) values (#{userId}, #{remark})
</insert>

</mapper>

Loading…
Cancel
Save