Переглянути джерело

优化新增用户代码,与oicd联调成功

tags/v1.0.0^2
wanjing 1 рік тому
джерело
коміт
f143f1581f
6 змінених файлів з 101 додано та 26 видалено
  1. +1
    -1
      tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/controller/UserController.java
  2. +17
    -0
      tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/enums/UserTypeEnum.java
  3. +11
    -2
      tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/enums/code/user/AddUserCodeEnum.java
  4. +20
    -13
      tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/service/third/oidc/AddOidcUserService.java
  5. +8
    -6
      tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/service/user/IUserService.java
  6. +44
    -4
      tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/service/user/add/AddUserService.java

+ 1
- 1
tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/controller/UserController.java Переглянути файл

@@ -56,7 +56,7 @@ public class UserController {
*/
@PostMapping("/add")
public JsonResult add(@RequestBody User entity) {
return userService.edit(entity);
return userService.add(entity);
}

/**

+ 17
- 0
tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/enums/UserTypeEnum.java Переглянути файл

@@ -2,6 +2,9 @@ package com.tuoheng.admin.enums;

import lombok.Getter;

import java.util.HashMap;
import java.util.Map;

/**
* 用户类型
*
@@ -26,4 +29,18 @@ public enum UserTypeEnum {
@Getter
private String description;

private static Map<Integer, UserTypeEnum> data = new HashMap<>();

static {
for (UserTypeEnum type : UserTypeEnum.values()) {
data.put(type.code, type);
}
}

public static UserTypeEnum parse(int code) {
if (data.containsKey(code)) {
return data.get(code);
}
return null;
}
}

+ 11
- 2
tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/enums/code/user/AddUserCodeEnum.java Переглянути файл

@@ -12,8 +12,17 @@ package com.tuoheng.admin.enums.code.user;
public enum AddUserCodeEnum {

ADD_IS_FAILED(1100100, "添加失败"),
PHONE_NOT_IMATCH(1100101, "手机号不匹配"),
USERNAME_ALREADY_EXISTS(1100102, "系统中已经存在该用户名");
CODE_IS_NULL(1100101, "编号不能为空"),
USERNAME_IS_NULL(1100102, "账号不能为空"),
REALNAME_IS_NULL(1100103, "姓名不能为空"),
ROLE_ID_IS_NULL(1100104, "角色不能为空"),
DEPT_ID_IS_NULL(1100105, "部门不能为空"),
CLIENT_ID_IS_NULL(1100106, "ClientID不能为空"),
TYPE_ID_IS_NULL(1100107, "用户类型不能为空"),
TYPE_ID_IS_NOT_EXISTS(1100108, "用户类型不存在"),
PHONE_NOT_IMATCH(1100109, "手机号不匹配"),
USERNAME_ALREADY_EXISTS(1100110, "系统中已经存在该用户名"),
ROLE_IS_NOT_EXISTS(1100111, "该角色不存在");

/**
* 错误码

+ 20
- 13
tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/service/third/oidc/AddOidcUserService.java Переглянути файл

@@ -1,5 +1,6 @@
package com.tuoheng.admin.service.third.oidc;

import cn.hutool.core.util.ObjectUtil;
import com.tuoheng.admin.constant.OidcUrlConstant;
import com.tuoheng.admin.dto.ClientRoleDto;
import com.tuoheng.admin.entity.Tenant;
@@ -37,7 +38,6 @@ public class AddOidcUserService {
HttpHeaders resultRequestHeader = new HttpHeaders();
resultRequestHeader.add("Authorization", "Bearer " + SecurityUserUtils.token());
HttpEntity httpEntity = new HttpEntity(request, resultRequestHeader);

String url = CommonConfig.oidcUrl + OidcUrlConstant.USER_CREATE;
ResponseEntity<JsonResult> response;
try {
@@ -71,20 +71,27 @@ public class AddOidcUserService {
} else {
oidcCreateUserRequest.setPassword("123456");
}
// 普通用户新增
oidcCreateUserRequest.setTenantFlag(0);
oidcCreateUserRequest.setTenantName(tenant.getUsername());
if (ObjectUtil.isNull(tenant)) {
// 普通用户新增
oidcCreateUserRequest.setTenantFlag(0);
oidcCreateUserRequest.setTenantName("");
} else {
oidcCreateUserRequest.setTenantFlag(1);
oidcCreateUserRequest.setTenantName(tenant.getName());
}
List<ClientRoleDto> clientRoleDtoList = new ArrayList<>();
ClientRoleDto clientRoleDto;
String[] clientIdArr = user.getClientId().split(",");
for (String clientIdStr : clientIdArr) {
int clientId = Integer.valueOf(clientIdStr);
ClientEnum clientEnum = ClientEnum.parse(clientId);
if (null != clientEnum) {
clientRoleDto = new ClientRoleDto();
clientRoleDto.setClientId(clientEnum.getDescription());
clientRoleDto.setRoleId(user.getRoleId());
clientRoleDtoList.add(clientRoleDto);
if (StringUtils.isNotEmpty(user.getClientId())) {
String[] clientIdArr = user.getClientId().split(",");
for (String clientIdStr : clientIdArr) {
int clientId = Integer.valueOf(clientIdStr);
ClientEnum clientEnum = ClientEnum.parse(clientId);
if (null != clientEnum) {
clientRoleDto = new ClientRoleDto();
clientRoleDto.setClientId(clientEnum.getDescription());
clientRoleDto.setRoleId(user.getRoleId());
clientRoleDtoList.add(clientRoleDto);
}
}
}
oidcCreateUserRequest.setClientRoleDtoList(clientRoleDtoList);

+ 8
- 6
tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/service/user/IUserService.java Переглянути файл

@@ -38,18 +38,18 @@ public interface IUserService {
/**
* 添加用户
*
* @param entity 实体对象
* @param user 实体对象
* @return
*/
JsonResult add(@RequestBody User entity);
JsonResult add(@RequestBody User user);

/**
* 编辑用户
*
* @param entity 实体对象
* @param user 实体对象
* @return
*/
JsonResult edit(User entity);
JsonResult edit(User user);

/**
* 删除用户
@@ -62,7 +62,9 @@ public interface IUserService {
/**
* 设置状态
*
* @param entity 实体对象
* @param id
* @param status
*
* @return
*/
JsonResult updeateStatus(String id, Integer status);
@@ -70,7 +72,7 @@ public interface IUserService {
/**
* 重置密码
*
* @param request 参数
* @param id 参数
* @return
*/
JsonResult resetPwd(String id);

+ 44
- 4
tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/service/user/add/AddUserService.java Переглянути файл

@@ -1,9 +1,13 @@
package com.tuoheng.admin.service.user.add;

import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.tuoheng.admin.entity.Role;
import com.tuoheng.admin.entity.Tenant;
import com.tuoheng.admin.entity.User;
import com.tuoheng.admin.enums.UserTypeEnum;
import com.tuoheng.admin.enums.code.user.AddUserCodeEnum;
import com.tuoheng.admin.mapper.RoleMapper;
import com.tuoheng.admin.mapper.TenantMapper;
import com.tuoheng.admin.mapper.UserMapper;
import com.tuoheng.admin.service.third.oidc.OidcService;
@@ -31,6 +35,9 @@ public class AddUserService {
@Autowired
private UserMapper userMapper;

@Autowired
private RoleMapper roleMapper;

@Autowired
private TenantMapper tenantMapper;

@@ -66,10 +73,9 @@ public class AddUserService {
if (rowCount <= 0) {
return JsonResult.error(AddUserCodeEnum.ADD_IS_FAILED.getCode(), AddUserCodeEnum.ADD_IS_FAILED.getMsg());
}

return JsonResult.success();

}

/**
* 检查参数
* @param tenantId
@@ -77,6 +83,34 @@ public class AddUserService {
* @return
*/
private JsonResult check(String tenantId, User user) {
if (StringUtils.isEmpty(user.getCode())) {
return JsonResult.error(AddUserCodeEnum.CODE_IS_NULL.getCode(), AddUserCodeEnum.CODE_IS_NULL.getMsg());
}
if (StringUtils.isEmpty(user.getUsername())) {
return JsonResult.error(AddUserCodeEnum.USERNAME_IS_NULL.getCode(), AddUserCodeEnum.USERNAME_IS_NULL.getMsg());
}
if (StringUtils.isEmpty(user.getRealname())) {
return JsonResult.error(AddUserCodeEnum.REALNAME_IS_NULL.getCode(), AddUserCodeEnum.REALNAME_IS_NULL.getMsg());
}
if (ObjectUtil.isNull(user.getRoleId()) || 0 == user.getRoleId()) {
return JsonResult.error(AddUserCodeEnum.ROLE_ID_IS_NULL.getCode(), AddUserCodeEnum.ROLE_ID_IS_NULL.getMsg());
}
if (StringUtils.isEmpty(user.getDeptId())) {
return JsonResult.error(AddUserCodeEnum.DEPT_ID_IS_NULL.getCode(), AddUserCodeEnum.DEPT_ID_IS_NULL.getMsg());
}

if (ObjectUtil.isNull(user.getType()) || 0 == user.getType()) {
return JsonResult.error(AddUserCodeEnum.TYPE_ID_IS_NULL.getCode(), AddUserCodeEnum.TYPE_ID_IS_NULL.getMsg());
} else {
UserTypeEnum userTypeEnum = UserTypeEnum.parse(user.getType());
if (null == userTypeEnum) {
return JsonResult.error(AddUserCodeEnum.TYPE_ID_IS_NOT_EXISTS.getCode(), AddUserCodeEnum.TYPE_ID_IS_NOT_EXISTS.getMsg());
}
}

if (StringUtils.isEmpty(user.getClientId())) {
return JsonResult.error(AddUserCodeEnum.CLIENT_ID_IS_NULL.getCode(), AddUserCodeEnum.CLIENT_ID_IS_NULL.getMsg());
}
if (StringUtils.isNotEmpty(user.getMobile())) {
//校验手机号
boolean flag = CommonUtils.isMobile(user.getMobile());
@@ -91,6 +125,13 @@ public class AddUserService {
if (count > 0) {
return JsonResult.error(AddUserCodeEnum.USERNAME_ALREADY_EXISTS.getCode(), AddUserCodeEnum.USERNAME_ALREADY_EXISTS.getMsg());
}
count = roleMapper.selectCount(new LambdaQueryWrapper<Role>()
.eq(Role::getTenantId, tenantId)
.eq(Role::getId, user.getRoleId())
.eq(Role::getMark, 1));
if (count <= 0) {
return JsonResult.error(AddUserCodeEnum.ROLE_IS_NOT_EXISTS.getCode(), AddUserCodeEnum.ROLE_IS_NOT_EXISTS.getMsg());
}
return JsonResult.success();
}

@@ -118,9 +159,8 @@ public class AddUserService {
}

//id
user.setCreateUser(CurrentUserUtil.getUserId());
user.setTenantId(tenantId);
user.setCityName("");
user.setTenantId(tenantId);
user.setCreateUser(CurrentUserUtil.getUserId());
user.setCreateTime(DateUtils.now());
}

Завантаження…
Відмінити
Зберегти