🔨 修改路由配置.

This commit is contained in:
lijiahangmax
2024-12-11 22:47:56 +08:00
parent 32e4859ba7
commit f52a81f9d0
35 changed files with 552 additions and 225 deletions

View File

@@ -19,8 +19,8 @@ import org.dromara.visor.framework.common.security.LoginUser;
import org.dromara.visor.module.infra.entity.domain.SystemUserDO;
import org.dromara.visor.module.infra.entity.dto.UserInfoDTO;
import org.dromara.visor.module.infra.entity.request.user.*;
import org.dromara.visor.module.infra.entity.vo.SystemUserBaseVO;
import org.dromara.visor.module.infra.entity.vo.SystemUserVO;
import org.dromara.visor.module.infra.entity.vo.UserCollectInfoVO;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;
@@ -58,6 +58,6 @@ public interface SystemUserConvert {
UserInfoDTO toUserInfo(SystemUserDO domain);
UserCollectInfoVO toCollectInfo(LoginUser user);
SystemUserBaseVO toBase(SystemUserDO user);
}

View File

@@ -75,6 +75,14 @@ public class SystemUserDO extends BaseDO {
@TableField("status")
private Integer status;
@Schema(description = "修改密码状态")
@TableField("update_password_status")
private Integer passwordUpdateStatus;
@Schema(description = "修改密码原因")
@TableField("update_password_reason")
private String passwordUpdateReason;
@Schema(description = "最后登录时间")
@TableField("last_login_time")
private Date lastLoginTime;

View File

@@ -21,9 +21,6 @@ import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.List;
import java.util.Map;
/**
* 用户基本信息 视图响应对象
*
@@ -35,8 +32,8 @@ import java.util.Map;
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Schema(name = "UserCollectInfoVO", description = "用户聚合信息 视图响应对象")
public class UserCollectInfoVO {
@Schema(name = "SystemUserBaseVO", description = "用户基本信息 视图响应对象")
public class SystemUserBaseVO {
@Schema(description = "id")
private Long id;
@@ -50,10 +47,10 @@ public class UserCollectInfoVO {
@Schema(description = "头像地址")
private String avatar;
@Schema(description = "系统偏好")
private Map<String, Object> systemPreference;
@Schema(description = "修改密码状态")
private Integer passwordUpdateStatus;
@Schema(description = "已经提示的key")
private List<String> tippedKeys;
@Schema(description = "修改密码原因")
private String passwordUpdateReason;
}

View File

@@ -23,6 +23,7 @@ import lombok.NoArgsConstructor;
import java.util.Collection;
import java.util.List;
import java.util.Map;
/**
* 用户权限 视图响应对象
@@ -38,8 +39,8 @@ import java.util.List;
@Schema(name = "UserPermissionVO", description = "用户权限 视图响应对象")
public class UserPermissionVO {
@Schema(description = "用户聚合信息")
private UserCollectInfoVO user;
@Schema(description = "用户信息")
private SystemUserBaseVO user;
@Schema(description = "该用户已启用的角色")
private Collection<String> roles;
@@ -47,4 +48,10 @@ public class UserPermissionVO {
@Schema(description = "该用户已启用的权限")
private List<String> permissions;
@Schema(description = "系统偏好")
private Map<String, Object> systemPreference;
@Schema(description = "已经提示的key")
private List<String> tippedKeys;
}

View File

@@ -0,0 +1,37 @@
/*
* Copyright (c) 2023 - present Jiahang Li (visor.orionsec.cn ljh1553488six@139.com).
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.dromara.visor.module.infra.enums;
import lombok.AllArgsConstructor;
import lombok.Getter;
/**
* 更新密码原因
*
* @author Jiahang Li
* @version 1.0.0
* @since 2024/12/11 14:37
*/
@Getter
@AllArgsConstructor
public enum UpdatePasswordReasonEnum {
/**
* 新用户
*/
NEW,
}

View File

@@ -0,0 +1,46 @@
/*
* Copyright (c) 2023 - present Jiahang Li (visor.orionsec.cn ljh1553488six@139.com).
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.dromara.visor.module.infra.enums;
import lombok.AllArgsConstructor;
import lombok.Getter;
/**
* 更新密码状态
*
* @author Jiahang Li
* @version 1.0.0
* @since 2024/12/11 14:37
*/
@Getter
@AllArgsConstructor
public enum UpdatePasswordStatusEnum {
/**
* 无需修改
*/
NO_REQUIRE(0),
/**
* 需要修改
*/
REQUIRED(1),
;
private final Integer status;
}

View File

@@ -49,6 +49,8 @@ import org.dromara.visor.module.infra.entity.domain.SystemUserDO;
import org.dromara.visor.module.infra.entity.dto.UserInfoDTO;
import org.dromara.visor.module.infra.entity.request.user.*;
import org.dromara.visor.module.infra.entity.vo.SystemUserVO;
import org.dromara.visor.module.infra.enums.UpdatePasswordReasonEnum;
import org.dromara.visor.module.infra.enums.UpdatePasswordStatusEnum;
import org.dromara.visor.module.infra.enums.UserStatusEnum;
import org.dromara.visor.module.infra.service.*;
import org.springframework.scheduling.annotation.Async;
@@ -118,6 +120,8 @@ public class SystemUserServiceImpl implements SystemUserService {
this.checkNicknamePresent(record);
// 加密密码
record.setPassword(Signatures.md5(request.getPassword()));
record.setPasswordUpdateStatus(UpdatePasswordStatusEnum.REQUIRED.getStatus());
record.setPasswordUpdateReason(UpdatePasswordReasonEnum.NEW.name());
// 插入
int effect = systemUserDAO.insert(record);
log.info("SystemUserService-createSystemUser effect: {}, record: {}", effect, JSON.toJSONString(record));
@@ -309,6 +313,8 @@ public class SystemUserServiceImpl implements SystemUserService {
SystemUserDO update = new SystemUserDO();
update.setId(id);
update.setPassword(Signatures.md5(request.getPassword()));
update.setPasswordUpdateStatus(UpdatePasswordStatusEnum.NO_REQUIRE.getStatus());
update.setPasswordUpdateReason(Const.EMPTY);
int effect = systemUserDAO.updateById(update);
log.info("SystemUserService-resetPassword record: {}, effect: {}", JSON.toJSONString(update), effect);
// 删除登录失败次数缓存

View File

@@ -30,13 +30,14 @@ import org.dromara.visor.module.infra.convert.SystemUserConvert;
import org.dromara.visor.module.infra.dao.SystemMenuDAO;
import org.dromara.visor.module.infra.dao.SystemRoleDAO;
import org.dromara.visor.module.infra.dao.SystemRoleMenuDAO;
import org.dromara.visor.module.infra.dao.SystemUserDAO;
import org.dromara.visor.module.infra.define.RoleDefine;
import org.dromara.visor.module.infra.entity.domain.SystemMenuDO;
import org.dromara.visor.module.infra.entity.domain.SystemRoleDO;
import org.dromara.visor.module.infra.entity.domain.SystemRoleMenuDO;
import org.dromara.visor.module.infra.entity.domain.SystemUserDO;
import org.dromara.visor.module.infra.entity.dto.SystemMenuCacheDTO;
import org.dromara.visor.module.infra.entity.vo.SystemMenuVO;
import org.dromara.visor.module.infra.entity.vo.UserCollectInfoVO;
import org.dromara.visor.module.infra.entity.vo.UserPermissionVO;
import org.dromara.visor.module.infra.enums.MenuStatusEnum;
import org.dromara.visor.module.infra.enums.MenuTypeEnum;
@@ -76,6 +77,9 @@ public class UserPermissionServiceImpl implements UserPermissionService {
@Getter
private final Map<Long, List<SystemMenuCacheDTO>> roleMenuCache = new HashMap<>();
@Resource
private SystemUserDAO systemUserDAO;
@Resource
private SystemRoleDAO systemRoleDAO;
@@ -229,43 +233,24 @@ public class UserPermissionServiceImpl implements UserPermissionService {
@Override
public UserPermissionVO getUserPermission() {
// 获取用户信息
UserCollectInfoVO user = SystemUserConvert.MAPPER.toCollectInfo(SecurityUtils.getLoginUser());
Long id = user.getId();
Long userId = SecurityUtils.getLoginUserId();
// 获取用户系统偏好
Future<Map<String, Object>> systemPreference = preferenceService.getPreferenceAsync(id, PreferenceTypeEnum.SYSTEM);
Future<Map<String, Object>> systemPreference = preferenceService.getPreferenceAsync(userId, PreferenceTypeEnum.SYSTEM);
// 查询用户信息
SystemUserDO user = systemUserDAO.selectById(userId);
// 获取用户角色
Map<Long, String> roles = this.getUserEnabledRoles();
// 获取用户权限
List<String> permissions;
if (roles.isEmpty()) {
permissions = Lists.empty();
} else {
if (RoleDefine.containsAdmin(roles.values())) {
// 管理员拥有全部权限
permissions = Lists.of(Const.ASTERISK);
} else {
// 当前用户所适配的角色的权限
permissions = roles.keySet()
.stream()
.map(roleMenuCache::get)
.filter(Objects::nonNull)
.flatMap(Collection::stream)
.filter(s -> MenuStatusEnum.ENABLED.getStatus().equals(s.getStatus()))
.map(SystemMenuCacheDTO::getPermission)
.filter(Objects::nonNull)
.distinct()
.collect(Collectors.toList());
}
}
// 设置已提示的 key
user.setTippedKeys(tipsService.getTippedKeys());
// 获取异步结果
user.setSystemPreference(systemPreference.get());
// 获取角色权限
List<String> permissions = this.getRolePermissions(roles);
// 提示信息
List<String> tippedKeys = tipsService.getTippedKeys();
// 组装数据
return UserPermissionVO.builder()
.user(user)
.user(SystemUserConvert.MAPPER.toBase(user))
.roles(roles.values())
.permissions(permissions)
.systemPreference(systemPreference.get())
.tippedKeys(tippedKeys)
.build();
}
@@ -317,4 +302,31 @@ public class UserPermissionServiceImpl implements UserPermissionService {
return roles;
}
/**
* 获取角色对应的权限
*
* @param roles roles
* @return 权限
*/
private List<String> getRolePermissions(Map<Long, String> roles) {
if (Maps.isEmpty(roles)) {
return Lists.empty();
}
// 管理员拥有全部权限
if (RoleDefine.containsAdmin(roles.values())) {
return Lists.singleton(Const.ASTERISK);
}
// 角色权限
return roles.keySet()
.stream()
.map(roleMenuCache::get)
.filter(Objects::nonNull)
.flatMap(Collection::stream)
.filter(s -> MenuStatusEnum.ENABLED.getStatus().equals(s.getStatus()))
.map(SystemMenuCacheDTO::getPermission)
.filter(Objects::nonNull)
.distinct()
.collect(Collectors.toList());
}
}

View File

@@ -17,12 +17,14 @@
<result column="mobile" property="mobile"/>
<result column="email" property="email"/>
<result column="status" property="status"/>
<result column="update_password_status" property="passwordUpdateStatus"/>
<result column="update_password_reason" property="passwordUpdateReason"/>
<result column="last_login_time" property="lastLoginTime"/>
</resultMap>
<!-- 通用查询结果列 -->
<sql id="Base_Column_List">
id, username, password, nickname, avatar, mobile, email, status, last_login_time, create_time, update_time, creator, updater, deleted
id, username, password, nickname, avatar, mobile, email, status, update_password_status, update_password_reason, last_login_time, create_time, update_time, creator, updater, deleted
</sql>
</mapper>