优化
This commit is contained in:
@@ -13,7 +13,6 @@ import top.wms.admin.common.context.UserContext;
|
||||
import top.wms.admin.common.context.UserContextHolder;
|
||||
import top.wms.admin.common.context.UserExtraContext;
|
||||
import top.wms.admin.common.enums.DisEnableStatusEnum;
|
||||
import top.wms.admin.system.model.entity.DeptDO;
|
||||
import top.wms.admin.system.model.entity.UserDO;
|
||||
import top.wms.admin.system.model.resp.ClientResp;
|
||||
import top.wms.admin.system.service.DeptService;
|
||||
@@ -106,7 +105,5 @@ public abstract class AbstractLoginHandler<T extends LoginReq> implements LoginH
|
||||
*/
|
||||
protected void checkUserStatus(UserDO user) {
|
||||
CheckUtils.throwIfEqual(DisEnableStatusEnum.DISABLE, user.getStatus(), "此账号已被禁用,如有疑问,请联系管理员");
|
||||
DeptDO dept = deptService.getById(user.getDeptId());
|
||||
CheckUtils.throwIfEqual(DisEnableStatusEnum.DISABLE, dept.getStatus(), "此账号所属部门已被禁用,如有疑问,请联系管理员");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -76,21 +76,15 @@ public class SocialLoginHandler extends AbstractLoginHandler<SocialLoginReq> {
|
||||
UserDO user;
|
||||
if (null == userSocial) {
|
||||
String username = authUser.getUsername();
|
||||
String nickname = authUser.getNickname();
|
||||
UserDO existsUser = userService.getByUsername(username);
|
||||
String randomStr = RandomUtil.randomString(RandomUtil.BASE_CHAR, 5);
|
||||
if (null != existsUser || !ReUtil.isMatch(RegexConstants.USERNAME, username)) {
|
||||
username = randomStr + IdUtil.fastSimpleUUID();
|
||||
}
|
||||
if (!ReUtil.isMatch(RegexConstants.GENERAL_NAME, nickname)) {
|
||||
nickname = source.toLowerCase() + randomStr;
|
||||
}
|
||||
user = new UserDO();
|
||||
user.setUsername(username);
|
||||
user.setNickname(nickname);
|
||||
user.setGender(GenderEnum.valueOf(authUser.getGender().name()));
|
||||
user.setAvatar(authUser.getAvatar());
|
||||
user.setDeptId(SysConstants.SUPER_DEPT_ID);
|
||||
user.setStatus(DisEnableStatusEnum.ENABLE);
|
||||
userService.save(user);
|
||||
Long userId = user.getId();
|
||||
@@ -150,7 +144,7 @@ public class SocialLoginHandler extends AbstractLoginHandler<SocialLoginReq> {
|
||||
MessageReq req = new MessageReq();
|
||||
MessageTemplateEnum socialRegister = MessageTemplateEnum.SOCIAL_REGISTER;
|
||||
req.setTitle(socialRegister.getTitle().formatted(projectProperties.getName()));
|
||||
req.setContent(socialRegister.getContent().formatted(user.getNickname()));
|
||||
req.setContent(socialRegister.getContent().formatted(user.getUsername()));
|
||||
req.setType(MessageTypeEnum.SECURITY);
|
||||
messageService.add(req, CollUtil.toList(user.getId()));
|
||||
List<String> tokenList = StpUtil.getTokenValueListByLoginId(user.getId());
|
||||
|
||||
@@ -38,12 +38,6 @@ public class UserInfoResp implements Serializable {
|
||||
@Schema(description = "用户名", example = "zhangsan")
|
||||
private String username;
|
||||
|
||||
/**
|
||||
* 昵称
|
||||
*/
|
||||
@Schema(description = "昵称", example = "张三")
|
||||
private String nickname;
|
||||
|
||||
/**
|
||||
* 性别
|
||||
*/
|
||||
|
||||
@@ -38,7 +38,6 @@ public class UserDO extends BaseDO {
|
||||
// @FieldEncrypt(encryptor = BCryptEncryptor.class)
|
||||
private String password;
|
||||
|
||||
|
||||
/*
|
||||
* 卡号
|
||||
* */
|
||||
|
||||
@@ -25,12 +25,12 @@ public class UserBasicInfoUpdateReq implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 昵称
|
||||
* 用户名
|
||||
*/
|
||||
@Schema(description = "昵称", example = "张三")
|
||||
@NotBlank(message = "昵称不能为空")
|
||||
@Schema(description = "用户名", example = "张三")
|
||||
@NotBlank(message = "用户名不能为空")
|
||||
@Pattern(regexp = RegexConstants.GENERAL_NAME, message = "昵称长度为 2-30 个字符,支持中文、字母、数字、下划线,短横线")
|
||||
private String nickname;
|
||||
private String userName;
|
||||
|
||||
/**
|
||||
* 性别
|
||||
|
||||
@@ -38,7 +38,6 @@ public class UserReq implements Serializable {
|
||||
@Pattern(regexp = RegexConstants.USERNAME, message = "用户名长度为 4-64 个字符,支持大小写字母、数字、下划线,以字母开头")
|
||||
private String username;
|
||||
|
||||
|
||||
/**
|
||||
* 密码(加密)
|
||||
*/
|
||||
|
||||
@@ -1,10 +1,6 @@
|
||||
package top.wms.admin.system.model.resp.user;
|
||||
|
||||
import cn.crane4j.annotation.Assemble;
|
||||
import cn.crane4j.annotation.AssembleMethod;
|
||||
import cn.crane4j.annotation.ContainerMethod;
|
||||
import cn.crane4j.annotation.Mapping;
|
||||
import cn.crane4j.annotation.condition.ConditionOnExpression;
|
||||
import cn.crane4j.core.executor.handler.ManyToManyAssembleOperationHandler;
|
||||
import com.alibaba.excel.annotation.ExcelIgnoreUnannotated;
|
||||
import com.alibaba.excel.annotation.ExcelProperty;
|
||||
@@ -15,8 +11,6 @@ import top.wms.admin.common.constant.ContainerConstants;
|
||||
import top.wms.admin.common.context.UserContextHolder;
|
||||
import top.wms.admin.common.enums.DisEnableStatusEnum;
|
||||
import top.wms.admin.common.enums.GenderEnum;
|
||||
import top.wms.admin.system.model.resp.DeptResp;
|
||||
import top.wms.admin.system.service.DeptService;
|
||||
import top.continew.starter.file.excel.converter.ExcelBaseEnumConverter;
|
||||
import top.continew.starter.file.excel.converter.ExcelListConverter;
|
||||
import top.continew.starter.security.crypto.annotation.FieldEncrypt;
|
||||
@@ -48,13 +42,6 @@ public class UserDetailResp extends BaseDetailResp {
|
||||
@ExcelProperty(value = "用户名", order = 2)
|
||||
private String username;
|
||||
|
||||
/**
|
||||
* 昵称
|
||||
*/
|
||||
@Schema(description = "昵称", example = "张三")
|
||||
@ExcelProperty(value = "昵称", order = 3)
|
||||
private String nickname;
|
||||
|
||||
/**
|
||||
* 状态
|
||||
*/
|
||||
@@ -69,22 +56,6 @@ public class UserDetailResp extends BaseDetailResp {
|
||||
@ExcelProperty(value = "性别", converter = ExcelBaseEnumConverter.class, order = 5)
|
||||
private GenderEnum gender;
|
||||
|
||||
/**
|
||||
* 部门 ID
|
||||
*/
|
||||
@Schema(description = "部门 ID", example = "5")
|
||||
@ConditionOnExpression("#target.deptName == null")
|
||||
@AssembleMethod(props = @Mapping(src = "name", ref = "deptName"), targetType = DeptService.class, method = @ContainerMethod(bindMethod = "get", resultType = DeptResp.class))
|
||||
@ExcelProperty(value = "部门 ID", order = 6)
|
||||
private Long deptId;
|
||||
|
||||
/**
|
||||
* 所属部门
|
||||
*/
|
||||
@Schema(description = "所属部门", example = "测试部")
|
||||
@ExcelProperty(value = "所属部门", order = 7)
|
||||
private String deptName;
|
||||
|
||||
/**
|
||||
* 角色 ID 列表
|
||||
*/
|
||||
@@ -112,14 +83,6 @@ public class UserDetailResp extends BaseDetailResp {
|
||||
@ExcelProperty(value = "卡号", order = 11)
|
||||
private String cardNo;
|
||||
|
||||
/**
|
||||
* 邮箱
|
||||
*/
|
||||
@Schema(description = "邮箱", example = "123456789@qq.com")
|
||||
@ExcelProperty(value = "邮箱", order = 12)
|
||||
@FieldEncrypt
|
||||
private String email;
|
||||
|
||||
/**
|
||||
* 是否为系统内置数据
|
||||
*/
|
||||
|
||||
@@ -1,12 +1,10 @@
|
||||
package top.wms.admin.system.model.resp.user;
|
||||
|
||||
import cn.crane4j.annotation.Assemble;
|
||||
import cn.crane4j.core.executor.handler.ManyToManyAssembleOperationHandler;
|
||||
import com.alibaba.excel.annotation.ExcelIgnore;
|
||||
import com.alibaba.excel.annotation.ExcelProperty;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
import lombok.Value;
|
||||
import top.wms.admin.common.model.resp.BaseDetailResp;
|
||||
import top.wms.admin.common.constant.ContainerConstants;
|
||||
import top.wms.admin.common.context.UserContextHolder;
|
||||
@@ -40,18 +38,10 @@ public class UserResp extends BaseDetailResp {
|
||||
@ExcelProperty(value = "用户名")
|
||||
private String username;
|
||||
|
||||
|
||||
@Schema(description = "卡号")
|
||||
@ExcelProperty(value = "卡号")
|
||||
private String cardNo;
|
||||
|
||||
/**
|
||||
* 昵称
|
||||
*/
|
||||
@Schema(description = "昵称", example = "张三")
|
||||
@ExcelIgnore
|
||||
private String nickname;
|
||||
|
||||
/**
|
||||
* 性别
|
||||
*/
|
||||
@@ -65,14 +55,6 @@ public class UserResp extends BaseDetailResp {
|
||||
@ExcelIgnore
|
||||
private String avatar;
|
||||
|
||||
/**
|
||||
* 邮箱
|
||||
*/
|
||||
@Schema(description = "邮箱", example = "c*******@126.com")
|
||||
@JsonMask(MaskType.EMAIL)
|
||||
@ExcelIgnore
|
||||
private String email;
|
||||
|
||||
/**
|
||||
* 手机号码
|
||||
*/
|
||||
@@ -99,27 +81,6 @@ public class UserResp extends BaseDetailResp {
|
||||
@Schema(description = "描述", example = "张三描述信息")
|
||||
private String description;
|
||||
|
||||
/**
|
||||
* 部门 ID
|
||||
*/
|
||||
@Schema(description = "部门 ID", example = "5")
|
||||
@ExcelIgnore
|
||||
private Long deptId;
|
||||
|
||||
/**
|
||||
* 所属部门
|
||||
*/
|
||||
@Schema(description = "所属部门", example = "测试部")
|
||||
@ExcelIgnore
|
||||
private String deptName;
|
||||
|
||||
/**
|
||||
* 角色 ID 列表
|
||||
*/
|
||||
@Schema(description = "角色 ID 列表", example = "2")
|
||||
@Assemble(prop = ":roleNames", container = ContainerConstants.USER_ROLE_NAME_LIST, handlerType = ManyToManyAssembleOperationHandler.class)
|
||||
private List<Long> roleIds;
|
||||
|
||||
/**
|
||||
* 角色名称列表
|
||||
*/
|
||||
|
||||
@@ -24,7 +24,6 @@ import javax.sql.DataSource;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* 部门业务实现
|
||||
@@ -87,17 +86,7 @@ public class DeptServiceImpl extends BaseServiceImpl<DeptMapper, DeptDO, DeptRes
|
||||
|
||||
@Override
|
||||
public void beforeDelete(List<Long> ids) {
|
||||
List<DeptDO> list = baseMapper.lambdaQuery()
|
||||
.select(DeptDO::getName, DeptDO::getIsSystem)
|
||||
.in(DeptDO::getId, ids)
|
||||
.list();
|
||||
Optional<DeptDO> isSystemData = list.stream().filter(DeptDO::getIsSystem).findFirst();
|
||||
CheckUtils.throwIf(isSystemData::isPresent, "所选部门 [{}] 是系统内置部门,不允许删除", isSystemData.orElseGet(DeptDO::new)
|
||||
.getName());
|
||||
CheckUtils.throwIf(this.countChildren(ids) > 0, "所选部门存在下级部门,不允许删除");
|
||||
CheckUtils.throwIf(userService.countByDeptIds(ids) > 0, "所选部门存在用户关联,请解除关联后重试");
|
||||
// 删除角色和部门关联
|
||||
roleDeptService.deleteByDeptIds(ids);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -158,10 +158,10 @@ public class UserServiceImpl extends BaseServiceImpl<UserMapper, UserDO, UserRes
|
||||
UserDO oldUser = super.getById(id);
|
||||
if (Boolean.TRUE.equals(oldUser.getIsSystem())) {
|
||||
CheckUtils.throwIfEqual(DisEnableStatusEnum.DISABLE, newStatus, "[{}] 是系统内置用户,不允许禁用", oldUser
|
||||
.getNickname());
|
||||
.getUsername());
|
||||
Collection<Long> disjunctionRoleIds = CollUtil.disjunction(req.getRoleIds(), userRoleService
|
||||
.listRoleIdByUserId(id));
|
||||
CheckUtils.throwIfNotEmpty(disjunctionRoleIds, "[{}] 是系统内置用户,不允许变更角色", oldUser.getNickname());
|
||||
CheckUtils.throwIfNotEmpty(disjunctionRoleIds, "[{}] 是系统内置用户,不允许变更角色", oldUser.getUsername());
|
||||
}
|
||||
// 更新信息
|
||||
UserDO newUser = BeanUtil.toBean(req, UserDO.class);
|
||||
@@ -186,12 +186,12 @@ public class UserServiceImpl extends BaseServiceImpl<UserMapper, UserDO, UserRes
|
||||
public void delete(List<Long> ids) {
|
||||
CheckUtils.throwIf(CollUtil.contains(ids, UserContextHolder.getUserId()), "不允许删除当前用户");
|
||||
List<UserDO> list = baseMapper.lambdaQuery()
|
||||
.select(UserDO::getNickname, UserDO::getIsSystem)
|
||||
.select(UserDO::getUsername, UserDO::getIsSystem)
|
||||
.in(UserDO::getId, ids)
|
||||
.list();
|
||||
Optional<UserDO> isSystemData = list.stream().filter(UserDO::getIsSystem).findFirst();
|
||||
CheckUtils.throwIf(isSystemData::isPresent, "所选用户 [{}] 是系统内置用户,不允许删除", isSystemData.orElseGet(UserDO::new)
|
||||
.getNickname());
|
||||
.getUsername());
|
||||
// 删除用户和角色关联
|
||||
userRoleService.deleteByUserIds(ids);
|
||||
// 删除历史密码
|
||||
@@ -335,7 +335,6 @@ public class UserServiceImpl extends BaseServiceImpl<UserMapper, UserDO, UserRes
|
||||
userDO.setStatus(req.getDefaultStatus());
|
||||
userDO.setPwdResetTime(LocalDateTime.now());
|
||||
userDO.setGender(EnumUtil.getBy(GenderEnum::getDescription, row.getGender(), GenderEnum.UNKNOWN));
|
||||
userDO.setDeptId(deptMap.get(row.getDeptName()));
|
||||
// 修改 or 新增
|
||||
if (UPDATE.validate(req.getDuplicateUser(), row.getUsername(), existUsernames)) {
|
||||
userDO.setId(userMap.get(row.getUsername()));
|
||||
@@ -396,7 +395,7 @@ public class UserServiceImpl extends BaseServiceImpl<UserMapper, UserDO, UserRes
|
||||
public void updateBasicInfo(UserBasicInfoUpdateReq req, Long id) {
|
||||
super.getById(id);
|
||||
baseMapper.lambdaUpdate()
|
||||
.set(UserDO::getNickname, req.getNickname())
|
||||
.set(UserDO::getUsername, req.getUserName())
|
||||
.set(UserDO::getGender, req.getGender())
|
||||
.eq(UserDO::getId, id)
|
||||
.update();
|
||||
@@ -462,10 +461,7 @@ public class UserServiceImpl extends BaseServiceImpl<UserMapper, UserDO, UserRes
|
||||
|
||||
@Override
|
||||
public Long countByDeptIds(List<Long> deptIds) {
|
||||
if (CollUtil.isEmpty(deptIds)) {
|
||||
return 0L;
|
||||
}
|
||||
return baseMapper.lambdaQuery().in(UserDO::getDeptId, deptIds).count();
|
||||
return 0L;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -737,6 +733,4 @@ public class UserServiceImpl extends BaseServiceImpl<UserMapper, UserDO, UserRes
|
||||
return null == userDO ? "" : userDO.getUsername();
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user