mirror of
https://github.com/CodePhiliaX/Chat2DB.git
synced 2025-08-02 21:50:43 +08:00
Complete team user code
This commit is contained in:
@ -53,6 +53,7 @@ public class Team implements Serializable {
|
||||
/**
|
||||
* 角色编码
|
||||
*/
|
||||
@NotNull
|
||||
private String roleCode;
|
||||
|
||||
|
||||
|
@ -30,6 +30,15 @@ public class TeamCreateParam {
|
||||
@NotNull
|
||||
private String status;
|
||||
|
||||
|
||||
/**
|
||||
* 角色编码
|
||||
*
|
||||
* @see ai.chat2db.server.domain.api.enums.RoleCodeEnum
|
||||
*/
|
||||
@NotNull
|
||||
private String roleCode;
|
||||
|
||||
/**
|
||||
* 团队描述
|
||||
*/
|
||||
|
@ -28,6 +28,13 @@ public class TeamUpdateParam {
|
||||
*/
|
||||
private String status;
|
||||
|
||||
/**
|
||||
* 角色编码
|
||||
*
|
||||
* @see ai.chat2db.server.domain.api.enums.RoleCodeEnum
|
||||
*/
|
||||
private String roleCode;
|
||||
|
||||
/**
|
||||
* 团队描述
|
||||
*/
|
||||
|
@ -1,5 +1,6 @@
|
||||
package ai.chat2db.server.domain.api.param.user;
|
||||
|
||||
import ai.chat2db.server.domain.api.enums.RoleCodeEnum;
|
||||
import ai.chat2db.server.domain.api.enums.ValidStatusEnum;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.Data;
|
||||
@ -35,6 +36,14 @@ public class UserCreateParam {
|
||||
@NotNull
|
||||
private String email;
|
||||
|
||||
/**
|
||||
* 角色编码
|
||||
*
|
||||
* @see RoleCodeEnum
|
||||
*/
|
||||
@NotNull
|
||||
private String roleCode;
|
||||
|
||||
/**
|
||||
* 用户状态
|
||||
*
|
||||
|
@ -1,5 +1,6 @@
|
||||
package ai.chat2db.server.domain.api.param.user;
|
||||
|
||||
import ai.chat2db.server.domain.api.enums.RoleCodeEnum;
|
||||
import ai.chat2db.server.domain.api.enums.ValidStatusEnum;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.Data;
|
||||
@ -17,12 +18,6 @@ public class UserUpdateParam {
|
||||
@NotNull
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 用户名
|
||||
*/
|
||||
@NotNull
|
||||
private String userName;
|
||||
|
||||
/**
|
||||
* 密码
|
||||
*/
|
||||
@ -41,6 +36,14 @@ public class UserUpdateParam {
|
||||
@NotNull
|
||||
private String email;
|
||||
|
||||
|
||||
/**
|
||||
* 角色编码
|
||||
*
|
||||
* @see RoleCodeEnum
|
||||
*/
|
||||
private String roleCode;
|
||||
|
||||
/**
|
||||
* 用户状态
|
||||
*
|
||||
|
@ -45,7 +45,11 @@ public abstract class TeamConverter {
|
||||
* @param param
|
||||
* @return
|
||||
*/
|
||||
public abstract TeamDO param2do(TeamCreateParam param);
|
||||
@Mappings({
|
||||
@Mapping(target = "createUserId", source = "userId"),
|
||||
@Mapping(target = "modifiedUserId", source = "userId"),
|
||||
})
|
||||
public abstract TeamDO param2do(TeamCreateParam param, Long userId);
|
||||
|
||||
/**
|
||||
* convert
|
||||
@ -53,7 +57,10 @@ public abstract class TeamConverter {
|
||||
* @param param
|
||||
* @return
|
||||
*/
|
||||
public abstract TeamDO param2do(TeamUpdateParam param);
|
||||
@Mappings({
|
||||
@Mapping(target = "modifiedUserId", source = "userId"),
|
||||
})
|
||||
public abstract TeamDO param2do(TeamUpdateParam param, Long userId);
|
||||
|
||||
/**
|
||||
* Fill in detailed information
|
||||
|
@ -2,6 +2,7 @@ package ai.chat2db.server.domain.core.impl;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import ai.chat2db.server.domain.api.enums.RoleCodeEnum;
|
||||
import ai.chat2db.server.domain.api.model.Team;
|
||||
import ai.chat2db.server.domain.api.param.team.TeamCreateParam;
|
||||
import ai.chat2db.server.domain.api.param.team.TeamPageQueryParam;
|
||||
@ -15,6 +16,9 @@ import ai.chat2db.server.tools.base.wrapper.result.ActionResult;
|
||||
import ai.chat2db.server.tools.base.wrapper.result.DataResult;
|
||||
import ai.chat2db.server.tools.base.wrapper.result.ListResult;
|
||||
import ai.chat2db.server.tools.base.wrapper.result.PageResult;
|
||||
import ai.chat2db.server.tools.common.exception.DataAlreadyExistsBusinessException;
|
||||
import ai.chat2db.server.tools.common.exception.ParamBusinessException;
|
||||
import ai.chat2db.server.tools.common.util.ContextUtils;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
@ -70,14 +74,26 @@ public class TeamServiceImpl implements TeamService {
|
||||
|
||||
@Override
|
||||
public DataResult<Long> create(TeamCreateParam param) {
|
||||
TeamDO data = teamConverter.param2do(param);
|
||||
LambdaQueryWrapper<TeamDO> queryWrapper = new LambdaQueryWrapper<>();
|
||||
queryWrapper.eq(TeamDO::getCode, param.getCode());
|
||||
Page<TeamDO> page = new Page<>(1, 1);
|
||||
page.setSearchCount(false);
|
||||
IPage<TeamDO> iPage = teamMapper.selectPage(page, queryWrapper);
|
||||
if (CollectionUtils.isNotEmpty(iPage.getRecords())) {
|
||||
throw new DataAlreadyExistsBusinessException("code", param.getCode());
|
||||
}
|
||||
if (RoleCodeEnum.DESKTOP.getCode().equals(param.getRoleCode())) {
|
||||
throw new ParamBusinessException("roleCode");
|
||||
}
|
||||
|
||||
TeamDO data = teamConverter.param2do(param, ContextUtils.getUserId());
|
||||
teamMapper.insert(data);
|
||||
return DataResult.of(data.getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public DataResult<Long> update(TeamUpdateParam param) {
|
||||
TeamDO data = teamConverter.param2do(param);
|
||||
TeamDO data = teamConverter.param2do(param, ContextUtils.getUserId());
|
||||
teamMapper.updateById(data);
|
||||
return DataResult.of(data.getId());
|
||||
}
|
||||
|
@ -18,6 +18,8 @@ import ai.chat2db.server.tools.base.wrapper.result.ActionResult;
|
||||
import ai.chat2db.server.tools.base.wrapper.result.DataResult;
|
||||
import ai.chat2db.server.tools.base.wrapper.result.ListResult;
|
||||
import ai.chat2db.server.tools.base.wrapper.result.PageResult;
|
||||
import ai.chat2db.server.tools.common.exception.DataAlreadyExistsBusinessException;
|
||||
import ai.chat2db.server.tools.common.exception.ParamBusinessException;
|
||||
import cn.hutool.crypto.digest.DigestUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
@ -86,17 +88,21 @@ public class UserServiceImpl implements UserService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public DataResult<Long> update(UserUpdateParam user) {
|
||||
if (RoleCodeEnum.DESKTOP.getDefaultUserId().equals(user.getId())) {
|
||||
public DataResult<Long> update(UserUpdateParam param) {
|
||||
if (RoleCodeEnum.DESKTOP.getDefaultUserId().equals(param.getId())) {
|
||||
throw new BusinessException("user.canNotOperateSystemAccount");
|
||||
}
|
||||
DbhubUserDO data = userConverter.param2do(user);
|
||||
if (RoleCodeEnum.DESKTOP.getCode().equals(param.getRoleCode())) {
|
||||
throw new ParamBusinessException("roleCode");
|
||||
}
|
||||
|
||||
DbhubUserDO data = userConverter.param2do(param);
|
||||
if (Objects.nonNull(data.getPassword())) {
|
||||
String bcryptPassword = DigestUtil.bcrypt(data.getPassword());
|
||||
data.setPassword(bcryptPassword);
|
||||
}
|
||||
|
||||
if (RoleCodeEnum.ADMIN.getDefaultUserId().equals(user.getId())) {
|
||||
if (RoleCodeEnum.ADMIN.getDefaultUserId().equals(param.getId())) {
|
||||
data.setStatus(null);
|
||||
data.setEmail(null);
|
||||
data.setUserName(null);
|
||||
@ -116,8 +122,23 @@ public class UserServiceImpl implements UserService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public DataResult<Long> create(UserCreateParam user) {
|
||||
DbhubUserDO data = userConverter.param2do(user);
|
||||
public DataResult<Long> create(UserCreateParam param) {
|
||||
LambdaQueryWrapper<DbhubUserDO> queryWrapper = new LambdaQueryWrapper<>();
|
||||
queryWrapper.and(wrapper -> wrapper.eq(DbhubUserDO::getUserName, param.getUserName())
|
||||
.or()
|
||||
.eq(DbhubUserDO::getEmail, param.getEmail()));
|
||||
Page<DbhubUserDO> page = new Page<>(1, 1);
|
||||
page.setSearchCount(false);
|
||||
IPage<DbhubUserDO> iPage = dbhubUserMapper.selectPage(page, queryWrapper);
|
||||
if (CollectionUtils.isNotEmpty(iPage.getRecords())) {
|
||||
throw new DataAlreadyExistsBusinessException("userName or email",
|
||||
param.getUserName() + " or " + param.getEmail());
|
||||
}
|
||||
if (RoleCodeEnum.DESKTOP.getCode().equals(param.getRoleCode())) {
|
||||
throw new ParamBusinessException("roleCode");
|
||||
}
|
||||
|
||||
DbhubUserDO data = userConverter.param2do(param);
|
||||
String bcryptPassword = DigestUtil.bcrypt(data.getPassword());
|
||||
data.setPassword(bcryptPassword);
|
||||
dbhubUserMapper.insert(data);
|
||||
|
@ -14,6 +14,7 @@ public class BusinessExceptionConvertor implements ExceptionConvertor<BusinessEx
|
||||
|
||||
@Override
|
||||
public ActionResult convert(BusinessException exception) {
|
||||
return ActionResult.fail(exception.getCode(), I18nUtils.getMessage(exception.getCode()), ExceptionUtils.getErrorInfoFromException(exception));
|
||||
return ActionResult.fail(exception.getCode(), I18nUtils.getMessage(exception.getCode(), exception.getArgs()),
|
||||
ExceptionUtils.getErrorInfoFromException(exception));
|
||||
}
|
||||
}
|
||||
|
@ -9,6 +9,8 @@ common.paramCheckError=The following parameters are not valid:
|
||||
common.maxUploadSize=The file exceeds the maximum limit
|
||||
common.permissionDenied=Permission denied
|
||||
common.dataNotFound=Data not found
|
||||
common.dataAlreadyExists=The data already exists in the database
|
||||
common.dataAlreadyExistsWithParam=The data already exists in the database,{0}:{1}
|
||||
|
||||
oauth.userNameNotExits=The current account does not exist
|
||||
oauth.IllegalUserName=The current account cannot be logged in. Please change your account
|
||||
|
@ -8,6 +8,8 @@ common.paramCheckError=The following parameters are not valid
|
||||
common.maxUploadSize=The file exceeds the maximum limit
|
||||
common.permissionDenied=Permission denied
|
||||
common.dataNotFound=Data not found
|
||||
common.dataAlreadyExists=The data already exists in the database
|
||||
common.dataAlreadyExistsWithParam=The data already exists in the database,{0}:{1}
|
||||
|
||||
oauth.userNameNotExits=The current account does not exist
|
||||
oauth.IllegalUserName=The current account cannot be logged in. Please change your account
|
||||
|
@ -8,6 +8,8 @@ common.paramCheckError=请检查以下参数:
|
||||
common.maxUploadSize=您输入的文件超过最大限制
|
||||
common.permissionDenied=您没有权限访问该页面
|
||||
common.dataNotFound=您访问的数据不存在
|
||||
common.dataAlreadyExists=数据库总已经存在该数据
|
||||
common.dataAlreadyExistsWithParam=数据库总已经存在该数据,{0}:{1}
|
||||
|
||||
oauth.userNameNotExits=当前账号不存在
|
||||
oauth.IllegalUserName=当前账号无法登录,请换一个账号
|
||||
|
@ -0,0 +1,27 @@
|
||||
package ai.chat2db.server.tools.common.exception;
|
||||
|
||||
import java.io.Serial;
|
||||
|
||||
import ai.chat2db.server.tools.base.constant.EasyToolsConstant;
|
||||
import ai.chat2db.server.tools.base.excption.BusinessException;
|
||||
import lombok.Getter;
|
||||
|
||||
/**
|
||||
* Data already exists exception
|
||||
*
|
||||
* @author Jiaju Zhuang
|
||||
*/
|
||||
@Getter
|
||||
public class DataAlreadyExistsBusinessException extends BusinessException {
|
||||
|
||||
@Serial
|
||||
private static final long serialVersionUID = EasyToolsConstant.SERIAL_VERSION_UID;
|
||||
|
||||
public DataAlreadyExistsBusinessException() {
|
||||
super("common.dataAlreadyExists");
|
||||
}
|
||||
|
||||
public DataAlreadyExistsBusinessException(String key, Object value) {
|
||||
super("common.dataAlreadyExistsWithParam", new Object[] {key, value});
|
||||
}
|
||||
}
|
@ -31,6 +31,14 @@ public class TeamCreateRequest {
|
||||
@NotNull
|
||||
private String status;
|
||||
|
||||
/**
|
||||
* 角色编码
|
||||
*
|
||||
* @see ai.chat2db.server.domain.api.enums.RoleCodeEnum
|
||||
*/
|
||||
@NotNull
|
||||
private String roleCode;
|
||||
|
||||
/**
|
||||
* 团队描述
|
||||
*/
|
||||
|
@ -30,6 +30,14 @@ public class TeamUpdateRequest {
|
||||
@NotNull
|
||||
private String status;
|
||||
|
||||
/**
|
||||
* 角色编码
|
||||
*
|
||||
* @see ai.chat2db.server.domain.api.enums.RoleCodeEnum
|
||||
*/
|
||||
@NotNull
|
||||
private String roleCode;
|
||||
|
||||
/**
|
||||
* 团队描述
|
||||
*/
|
||||
|
@ -1,5 +1,6 @@
|
||||
package ai.chat2db.server.admin.api.controller.user.request;
|
||||
|
||||
import ai.chat2db.server.domain.api.enums.RoleCodeEnum;
|
||||
import ai.chat2db.server.domain.api.enums.ValidStatusEnum;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.Data;
|
||||
@ -34,6 +35,15 @@ public class UserCreateRequest {
|
||||
@NotNull
|
||||
private String email;
|
||||
|
||||
|
||||
/**
|
||||
* 角色编码
|
||||
*
|
||||
* @see RoleCodeEnum
|
||||
*/
|
||||
@NotNull
|
||||
private String roleCode;
|
||||
|
||||
/**
|
||||
* 用户状态
|
||||
*
|
||||
|
@ -1,5 +1,6 @@
|
||||
package ai.chat2db.server.admin.api.controller.user.request;
|
||||
|
||||
import ai.chat2db.server.domain.api.enums.RoleCodeEnum;
|
||||
import ai.chat2db.server.domain.api.enums.ValidStatusEnum;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.Data;
|
||||
@ -16,12 +17,6 @@ public class UserUpdateRequest {
|
||||
@NotNull
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 用户名
|
||||
*/
|
||||
@NotNull
|
||||
private String userName;
|
||||
|
||||
/**
|
||||
* 密码
|
||||
*/
|
||||
@ -40,6 +35,14 @@ public class UserUpdateRequest {
|
||||
@NotNull
|
||||
private String email;
|
||||
|
||||
|
||||
/**
|
||||
* 角色编码
|
||||
*
|
||||
* @see RoleCodeEnum
|
||||
*/
|
||||
private String roleCode;
|
||||
|
||||
/**
|
||||
* 用户状态
|
||||
*
|
||||
|
Reference in New Issue
Block a user