mirror of
https://gitee.com/qqtt-ah/ecom-dmb.git
synced 2026-11-25 16:29:20 +08:00
Compare commits
3
Commits
1aafccc289
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e9aeef7607 | ||
|
|
f40788db9a | ||
|
|
b0ad57e442 |
@@ -8,9 +8,9 @@
|
|||||||
DROP TABLE IF EXISTS `sys_user`;
|
DROP TABLE IF EXISTS `sys_user`;
|
||||||
CREATE TABLE `sys_user` (
|
CREATE TABLE `sys_user` (
|
||||||
`id` bigint UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '用户ID',
|
`id` bigint UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '用户ID',
|
||||||
`login_code` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT '登录账号',
|
`username` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '登录用户名(可空,用户自行设置)',
|
||||||
`password` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT '登录密码',
|
`password` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT '登录密码',
|
||||||
`phone` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '手机号码',
|
`phone` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT '手机号码',
|
||||||
`real_name` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT '用户名称',
|
`real_name` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT '用户名称',
|
||||||
`avatar` varchar(500) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '头像路径(冗余字段)',
|
`avatar` varchar(500) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '头像路径(冗余字段)',
|
||||||
`avatar_image_id` bigint NULL DEFAULT NULL COMMENT '头像文件ID',
|
`avatar_image_id` bigint NULL DEFAULT NULL COMMENT '头像文件ID',
|
||||||
@@ -29,7 +29,7 @@ CREATE TABLE `sys_user` (
|
|||||||
`create_by` bigint UNSIGNED NULL DEFAULT NULL COMMENT '创建者',
|
`create_by` bigint UNSIGNED NULL DEFAULT NULL COMMENT '创建者',
|
||||||
`update_by` bigint UNSIGNED NULL DEFAULT NULL COMMENT '更新者',
|
`update_by` bigint UNSIGNED NULL DEFAULT NULL COMMENT '更新者',
|
||||||
PRIMARY KEY (`id`) USING BTREE,
|
PRIMARY KEY (`id`) USING BTREE,
|
||||||
UNIQUE INDEX `uk_login_code`(`login_code` ASC) USING BTREE,
|
UNIQUE INDEX `uk_username`(`username` ASC) USING BTREE,
|
||||||
UNIQUE INDEX `uk_phone`(`phone` ASC) USING BTREE,
|
UNIQUE INDEX `uk_phone`(`phone` ASC) USING BTREE,
|
||||||
INDEX `idx_super`(`super` ASC) USING BTREE,
|
INDEX `idx_super`(`super` ASC) USING BTREE,
|
||||||
INDEX `idx_status`(`status` ASC) USING BTREE,
|
INDEX `idx_status`(`status` ASC) USING BTREE,
|
||||||
|
|||||||
@@ -0,0 +1,17 @@
|
|||||||
|
-- sys_user.login_code → username(可空);phone 改为非空;无手机号的测试账号直接删除
|
||||||
|
ALTER TABLE `sys_user` DROP INDEX `uk_login_code`;
|
||||||
|
|
||||||
|
ALTER TABLE `sys_user`
|
||||||
|
CHANGE COLUMN `login_code` `username` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '登录用户名(可空,用户自行设置)';
|
||||||
|
|
||||||
|
UPDATE `sys_user` SET `username` = NULL;
|
||||||
|
|
||||||
|
-- 无手机号均为测试账号,连带依赖一并清理后删除
|
||||||
|
SET FOREIGN_KEY_CHECKS = 0;
|
||||||
|
DELETE FROM `sys_user` WHERE `phone` IS NULL OR TRIM(`phone`) = '';
|
||||||
|
SET FOREIGN_KEY_CHECKS = 1;
|
||||||
|
|
||||||
|
ALTER TABLE `sys_user`
|
||||||
|
MODIFY COLUMN `phone` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT '手机号码';
|
||||||
|
|
||||||
|
ALTER TABLE `sys_user` ADD UNIQUE INDEX `uk_username` (`username` ASC) USING BTREE;
|
||||||
+25
@@ -0,0 +1,25 @@
|
|||||||
|
package top.xyquan.ecomdmbbackend.modules.notify.access;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 权限/菜单已变更:事务提交后由 SSE 监听器推送给在线用户,促其重拉 codes/menu。
|
||||||
|
* <p>
|
||||||
|
* 范围优先级:userId > positionId > companyId(只填生效的那一层)。
|
||||||
|
*/
|
||||||
|
public record AccessChangedEvent(
|
||||||
|
String reason,
|
||||||
|
Long companyId,
|
||||||
|
Long positionId,
|
||||||
|
Long userId
|
||||||
|
) {
|
||||||
|
public static AccessChangedEvent forCompany(String reason, Long companyId) {
|
||||||
|
return new AccessChangedEvent(reason, companyId, null, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static AccessChangedEvent forPosition(String reason, Long companyId, Long positionId) {
|
||||||
|
return new AccessChangedEvent(reason, companyId, positionId, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static AccessChangedEvent forUser(String reason, Long companyId, Long userId) {
|
||||||
|
return new AccessChangedEvent(reason, companyId, null, userId);
|
||||||
|
}
|
||||||
|
}
|
||||||
+17
@@ -0,0 +1,17 @@
|
|||||||
|
package top.xyquan.ecomdmbbackend.modules.notify.access;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 权限/菜单变更原因(与前端约定,便于日志与去重策略)
|
||||||
|
*/
|
||||||
|
public final class AccessChangedReason {
|
||||||
|
|
||||||
|
private AccessChangedReason() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public static final String COMPANY_MENU = "company_menu";
|
||||||
|
public static final String COMPANY_PERMISSION = "company_permission";
|
||||||
|
public static final String POSITION_MENU = "position_menu";
|
||||||
|
public static final String POSITION_PERMISSION = "position_permission";
|
||||||
|
public static final String MEMBER_POSITION = "member_position";
|
||||||
|
public static final String MEMBER_ROLE = "member_role";
|
||||||
|
}
|
||||||
+89
@@ -0,0 +1,89 @@
|
|||||||
|
package top.xyquan.ecomdmbbackend.modules.notify.access;
|
||||||
|
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
import org.springframework.transaction.event.TransactionPhase;
|
||||||
|
import org.springframework.transaction.event.TransactionalEventListener;
|
||||||
|
import top.xyquan.ecomdmbbackend.modules.notify.sse.RealtimeSseEvents;
|
||||||
|
import top.xyquan.ecomdmbbackend.modules.notify.sse.RealtimeSseService;
|
||||||
|
import top.xyquan.ecomdmbbackend.modules.org.company.member.model.vo.CompanyMemberVO;
|
||||||
|
import top.xyquan.ecomdmbbackend.modules.org.company.member.service.CompanyMemberService;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 事务提交后推送 access_changed;失败不影响主业务。
|
||||||
|
*/
|
||||||
|
@Slf4j
|
||||||
|
@Component
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
public class AccessChangedSseListener {
|
||||||
|
|
||||||
|
private final RealtimeSseService realtimeSseService;
|
||||||
|
private final CompanyMemberService companyMemberService;
|
||||||
|
|
||||||
|
@TransactionalEventListener(phase = TransactionPhase.AFTER_COMMIT, fallbackExecution = true)
|
||||||
|
public void onAccessChanged(AccessChangedEvent event) {
|
||||||
|
if (event == null || event.reason() == null || event.reason().isBlank()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
Map<String, Object> payload = buildPayload(event);
|
||||||
|
if (event.userId() != null) {
|
||||||
|
realtimeSseService.sendToUser(
|
||||||
|
event.userId(), RealtimeSseEvents.ACCESS_CHANGED, payload);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (event.positionId() != null) {
|
||||||
|
notifyPositionMembers(event.positionId(), payload);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (event.companyId() != null) {
|
||||||
|
realtimeSseService.sendToCompany(
|
||||||
|
event.companyId(), RealtimeSseEvents.ACCESS_CHANGED, payload);
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.warn("推送 access_changed 失败 reason={} companyId={} positionId={} userId={}: {}",
|
||||||
|
event.reason(), event.companyId(), event.positionId(), event.userId(),
|
||||||
|
e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void notifyPositionMembers(Long positionId, Map<String, Object> payload) {
|
||||||
|
List<CompanyMemberVO> members = companyMemberService.getByPositionId(positionId);
|
||||||
|
if (members == null || members.isEmpty()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Set<Long> userIds = new HashSet<>();
|
||||||
|
for (CompanyMemberVO member : members) {
|
||||||
|
if (member != null && member.getUserId() != null) {
|
||||||
|
userIds.add(member.getUserId());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (Long userId : userIds) {
|
||||||
|
realtimeSseService.sendToUser(userId, RealtimeSseEvents.ACCESS_CHANGED, payload);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Map<String, Object> buildPayload(AccessChangedEvent event) {
|
||||||
|
Map<String, Object> payload = new HashMap<>(8);
|
||||||
|
payload.put("type", RealtimeSseEvents.ACCESS_CHANGED);
|
||||||
|
payload.put("reason", event.reason());
|
||||||
|
payload.put("ts", System.currentTimeMillis());
|
||||||
|
if (event.companyId() != null) {
|
||||||
|
payload.put("companyId", event.companyId());
|
||||||
|
}
|
||||||
|
if (event.positionId() != null) {
|
||||||
|
payload.put("positionId", event.positionId());
|
||||||
|
}
|
||||||
|
if (event.userId() != null) {
|
||||||
|
payload.put("userId", event.userId());
|
||||||
|
}
|
||||||
|
return payload;
|
||||||
|
}
|
||||||
|
}
|
||||||
+3
@@ -16,4 +16,7 @@ public final class RealtimeSseEvents {
|
|||||||
|
|
||||||
/** 拼多多订单全量同步任务进度 */
|
/** 拼多多订单全量同步任务进度 */
|
||||||
public static final String PDD_ORDER_FULL_SYNC_PROGRESS = "pdd_order_full_sync_progress";
|
public static final String PDD_ORDER_FULL_SYNC_PROGRESS = "pdd_order_full_sync_progress";
|
||||||
|
|
||||||
|
/** 菜单/权限变更:前端收到后主动重拉 codes + menu */
|
||||||
|
public static final String ACCESS_CHANGED = "access_changed";
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -8,7 +8,7 @@ import lombok.Data;
|
|||||||
@Data
|
@Data
|
||||||
public class AccountFilterDTO {
|
public class AccountFilterDTO {
|
||||||
|
|
||||||
private String loginCode;
|
private String username;
|
||||||
|
|
||||||
private String realName;
|
private String realName;
|
||||||
|
|
||||||
|
|||||||
+3
-2
@@ -8,7 +8,7 @@ import lombok.Data;
|
|||||||
/**
|
/**
|
||||||
* 创建公司账户请求 DTO
|
* 创建公司账户请求 DTO
|
||||||
* <p>
|
* <p>
|
||||||
* 由公司拥有者调用;手机号决定走「拉入已有用户」还是「新建用户」分支。
|
* 由公司拥有者调用;仅按手机号判断「拉入已有用户」还是「新建用户」。
|
||||||
*/
|
*/
|
||||||
@Data
|
@Data
|
||||||
public class CreateAccountDTO {
|
public class CreateAccountDTO {
|
||||||
@@ -20,8 +20,9 @@ public class CreateAccountDTO {
|
|||||||
@Size(min = 6, max = 20, message = "密码长度为6-20个字符")
|
@Size(min = 6, max = 20, message = "密码长度为6-20个字符")
|
||||||
private String password;
|
private String password;
|
||||||
|
|
||||||
/** 手机号,同时作为新用户的登录账号(login_code) */
|
/** 手机号(必填);新建用户时仅写 phone,username 留空 */
|
||||||
@NotBlank(message = "手机号不能为空")
|
@NotBlank(message = "手机号不能为空")
|
||||||
|
@Pattern(regexp = "^1[3-9]\\d{9}$", message = "手机号码格式不正确")
|
||||||
private String phone;
|
private String phone;
|
||||||
|
|
||||||
@NotBlank(message = "用户姓名不能为空")
|
@NotBlank(message = "用户姓名不能为空")
|
||||||
|
|||||||
+1
-1
@@ -30,7 +30,7 @@ public class CompanyAccountVO {
|
|||||||
/** 公司成员角色展示名 */
|
/** 公司成员角色展示名 */
|
||||||
private String roleName;
|
private String roleName;
|
||||||
|
|
||||||
private String loginCode;
|
private String username;
|
||||||
|
|
||||||
private String phone;
|
private String phone;
|
||||||
|
|
||||||
|
|||||||
+6
-6
@@ -80,7 +80,7 @@ public class AccountServiceImpl extends ServiceImpl<UserMapper, UserPO> implemen
|
|||||||
* <ul>
|
* <ul>
|
||||||
* <li>仅公司拥有者可操作,超管不受此限</li>
|
* <li>仅公司拥有者可操作,超管不受此限</li>
|
||||||
* <li>手机号已存在:不新建用户,将其加入当前公司(已是成员则报错)</li>
|
* <li>手机号已存在:不新建用户,将其加入当前公司(已是成员则报错)</li>
|
||||||
* <li>手机号不存在:新建 sys_user,密码必填,系统角色固定为 user</li>
|
* <li>手机号不存在:新建 sys_user(仅设手机号,username 留空由用户自行设置),密码必填</li>
|
||||||
* <li>companyRole 决定其在公司成员表中的角色(owner / member)</li>
|
* <li>companyRole 决定其在公司成员表中的角色(owner / member)</li>
|
||||||
* </ul>
|
* </ul>
|
||||||
*
|
*
|
||||||
@@ -98,7 +98,7 @@ public class AccountServiceImpl extends ServiceImpl<UserMapper, UserPO> implemen
|
|||||||
CompanyMemberRole memberRole = CompanyMemberRole.fromCode(createAccountDTO.getCompanyRole());
|
CompanyMemberRole memberRole = CompanyMemberRole.fromCode(createAccountDTO.getCompanyRole());
|
||||||
assertOwnerCanCreateAccount(companyId);
|
assertOwnerCanCreateAccount(companyId);
|
||||||
|
|
||||||
// 按手机号分流:已注册走「拉入公司」,未注册走「新建用户」
|
// 仅按手机号分流:已注册走「拉入公司」,未注册走「新建用户」
|
||||||
UserPO existingUser = findUserByPhone(createAccountDTO.getPhone());
|
UserPO existingUser = findUserByPhone(createAccountDTO.getPhone());
|
||||||
if (existingUser != null) {
|
if (existingUser != null) {
|
||||||
return addExistingUserToCompany(existingUser, companyId, createAccountDTO, memberRole);
|
return addExistingUserToCompany(existingUser, companyId, createAccountDTO, memberRole);
|
||||||
@@ -169,7 +169,7 @@ public class AccountServiceImpl extends ServiceImpl<UserMapper, UserPO> implemen
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 新建用户并加入当前公司
|
* 新建用户并加入当前公司
|
||||||
* 登录账号与手机号相同,系统角色固定为 user,须传入密码
|
* 仅设置手机号与密码,username 留空(用户可在个人中心自行设置),系统角色固定为 user
|
||||||
*/
|
*/
|
||||||
private CompanyAccountVO createNewUserAndAddToCompany(
|
private CompanyAccountVO createNewUserAndAddToCompany(
|
||||||
Long companyId,
|
Long companyId,
|
||||||
@@ -182,7 +182,7 @@ public class AccountServiceImpl extends ServiceImpl<UserMapper, UserPO> implemen
|
|||||||
UserPO user = new UserPO();
|
UserPO user = new UserPO();
|
||||||
BeanCopyUtils.copyProperties(createAccountDTO, user);
|
BeanCopyUtils.copyProperties(createAccountDTO, user);
|
||||||
user.setPassword(passwordEncoder.encode(createAccountDTO.getPassword()));
|
user.setPassword(passwordEncoder.encode(createAccountDTO.getPassword()));
|
||||||
user.setLoginCode(createAccountDTO.getPhone());
|
user.setUsername(null);
|
||||||
user.setIsSuper(0);
|
user.setIsSuper(0);
|
||||||
user.setStatus(1);
|
user.setStatus(1);
|
||||||
user.setPwdSecurityLevel(calculatePasswordSecurityLevel(createAccountDTO.getPassword()));
|
user.setPwdSecurityLevel(calculatePasswordSecurityLevel(createAccountDTO.getPassword()));
|
||||||
@@ -410,8 +410,8 @@ public class AccountServiceImpl extends ServiceImpl<UserMapper, UserPO> implemen
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 登录账号
|
// 登录账号
|
||||||
if (StringUtils.hasText(filterDTO.getLoginCode())) {
|
if (StringUtils.hasText(filterDTO.getUsername())) {
|
||||||
wrapper.like(UserPO::getLoginCode, filterDTO.getLoginCode());
|
wrapper.like(UserPO::getUsername, filterDTO.getUsername());
|
||||||
}
|
}
|
||||||
|
|
||||||
// 用户姓名
|
// 用户姓名
|
||||||
|
|||||||
+1
-1
@@ -34,7 +34,7 @@ public class CompanyMemberVO {
|
|||||||
|
|
||||||
private String phone;
|
private String phone;
|
||||||
|
|
||||||
private String loginCode;
|
private String username;
|
||||||
|
|
||||||
private LocalDateTime createTime;
|
private LocalDateTime createTime;
|
||||||
|
|
||||||
|
|||||||
+12
-2
@@ -3,9 +3,12 @@ package top.xyquan.ecomdmbbackend.modules.org.company.member.service.impl;
|
|||||||
import top.xyquan.ecomdmbbackend.common.utils.BeanCopyUtils;
|
import top.xyquan.ecomdmbbackend.common.utils.BeanCopyUtils;
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
|
import org.springframework.context.ApplicationEventPublisher;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
import top.xyquan.ecomdmbbackend.common.exception.BusinessException;
|
import top.xyquan.ecomdmbbackend.common.exception.BusinessException;
|
||||||
|
import top.xyquan.ecomdmbbackend.modules.notify.access.AccessChangedEvent;
|
||||||
|
import top.xyquan.ecomdmbbackend.modules.notify.access.AccessChangedReason;
|
||||||
import top.xyquan.ecomdmbbackend.modules.org.company.member.enums.CompanyMemberRole;
|
import top.xyquan.ecomdmbbackend.modules.org.company.member.enums.CompanyMemberRole;
|
||||||
import top.xyquan.ecomdmbbackend.modules.org.company.member.mapper.CompanyMemberMapper;
|
import top.xyquan.ecomdmbbackend.modules.org.company.member.mapper.CompanyMemberMapper;
|
||||||
import top.xyquan.ecomdmbbackend.modules.org.company.member.model.dto.CreateCompanyMemberDTO;
|
import top.xyquan.ecomdmbbackend.modules.org.company.member.model.dto.CreateCompanyMemberDTO;
|
||||||
@@ -36,15 +39,18 @@ public class CompanyMemberServiceImpl extends ServiceImpl<CompanyMemberMapper, C
|
|||||||
private final CompanyService companyService;
|
private final CompanyService companyService;
|
||||||
private final PositionService positionService;
|
private final PositionService positionService;
|
||||||
private final UserMapper userMapper;
|
private final UserMapper userMapper;
|
||||||
|
private final ApplicationEventPublisher eventPublisher;
|
||||||
|
|
||||||
public CompanyMemberServiceImpl(@Lazy CurrentUserContext currentUserContext,
|
public CompanyMemberServiceImpl(@Lazy CurrentUserContext currentUserContext,
|
||||||
@Lazy CompanyService companyService,
|
@Lazy CompanyService companyService,
|
||||||
PositionService positionService,
|
PositionService positionService,
|
||||||
UserMapper userMapper) {
|
UserMapper userMapper,
|
||||||
|
ApplicationEventPublisher eventPublisher) {
|
||||||
this.currentUserContext = currentUserContext;
|
this.currentUserContext = currentUserContext;
|
||||||
this.companyService = companyService;
|
this.companyService = companyService;
|
||||||
this.positionService = positionService;
|
this.positionService = positionService;
|
||||||
this.userMapper = userMapper;
|
this.userMapper = userMapper;
|
||||||
|
this.eventPublisher = eventPublisher;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -108,6 +114,8 @@ public class CompanyMemberServiceImpl extends ServiceImpl<CompanyMemberMapper, C
|
|||||||
member.setUpdateBy(currentUserContext.getCurrentUserId());
|
member.setUpdateBy(currentUserContext.getCurrentUserId());
|
||||||
this.updateById(member);
|
this.updateById(member);
|
||||||
|
|
||||||
|
eventPublisher.publishEvent(AccessChangedEvent.forUser(
|
||||||
|
AccessChangedReason.MEMBER_POSITION, member.getCompanyId(), member.getUserId()));
|
||||||
return convertToVO(member);
|
return convertToVO(member);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -122,6 +130,8 @@ public class CompanyMemberServiceImpl extends ServiceImpl<CompanyMemberMapper, C
|
|||||||
member.setUpdateBy(currentUserContext.getCurrentUserId());
|
member.setUpdateBy(currentUserContext.getCurrentUserId());
|
||||||
this.updateById(member);
|
this.updateById(member);
|
||||||
|
|
||||||
|
eventPublisher.publishEvent(AccessChangedEvent.forUser(
|
||||||
|
AccessChangedReason.MEMBER_ROLE, member.getCompanyId(), member.getUserId()));
|
||||||
return convertToVO(member);
|
return convertToVO(member);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -263,7 +273,7 @@ public class CompanyMemberServiceImpl extends ServiceImpl<CompanyMemberMapper, C
|
|||||||
if (user != null) {
|
if (user != null) {
|
||||||
vo.setRealName(user.getRealName());
|
vo.setRealName(user.getRealName());
|
||||||
vo.setPhone(user.getPhone());
|
vo.setPhone(user.getPhone());
|
||||||
vo.setLoginCode(user.getLoginCode());
|
vo.setUsername(user.getUsername());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+10
-1
@@ -3,9 +3,12 @@ package top.xyquan.ecomdmbbackend.modules.org.company.menu.service.impl;
|
|||||||
import top.xyquan.ecomdmbbackend.common.utils.BeanCopyUtils;
|
import top.xyquan.ecomdmbbackend.common.utils.BeanCopyUtils;
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
|
import org.springframework.context.ApplicationEventPublisher;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
import top.xyquan.ecomdmbbackend.common.exception.BusinessException;
|
import top.xyquan.ecomdmbbackend.common.exception.BusinessException;
|
||||||
|
import top.xyquan.ecomdmbbackend.modules.notify.access.AccessChangedEvent;
|
||||||
|
import top.xyquan.ecomdmbbackend.modules.notify.access.AccessChangedReason;
|
||||||
import top.xyquan.ecomdmbbackend.modules.org.company.menu.mapper.CompanyMenuMapper;
|
import top.xyquan.ecomdmbbackend.modules.org.company.menu.mapper.CompanyMenuMapper;
|
||||||
import top.xyquan.ecomdmbbackend.modules.org.company.menu.model.dto.CreateCompanyMenuDTO;
|
import top.xyquan.ecomdmbbackend.modules.org.company.menu.model.dto.CreateCompanyMenuDTO;
|
||||||
import top.xyquan.ecomdmbbackend.modules.org.company.menu.model.po.CompanyMenuPO;
|
import top.xyquan.ecomdmbbackend.modules.org.company.menu.model.po.CompanyMenuPO;
|
||||||
@@ -38,17 +41,20 @@ public class CompanyMenuServiceImpl extends ServiceImpl<CompanyMenuMapper, Compa
|
|||||||
private final MenuPermissionMapper menuPermissionMapper;
|
private final MenuPermissionMapper menuPermissionMapper;
|
||||||
private final CompanyPermissionService companyPermissionService;
|
private final CompanyPermissionService companyPermissionService;
|
||||||
private final CurrentUserContext currentUserContext;
|
private final CurrentUserContext currentUserContext;
|
||||||
|
private final ApplicationEventPublisher eventPublisher;
|
||||||
|
|
||||||
public CompanyMenuServiceImpl(MenuService menuService,
|
public CompanyMenuServiceImpl(MenuService menuService,
|
||||||
MenuMapper menuMapper,
|
MenuMapper menuMapper,
|
||||||
MenuPermissionMapper menuPermissionMapper,
|
MenuPermissionMapper menuPermissionMapper,
|
||||||
CompanyPermissionService companyPermissionService,
|
CompanyPermissionService companyPermissionService,
|
||||||
CurrentUserContext currentUserContext) {
|
CurrentUserContext currentUserContext,
|
||||||
|
ApplicationEventPublisher eventPublisher) {
|
||||||
this.menuService = menuService;
|
this.menuService = menuService;
|
||||||
this.menuMapper = menuMapper;
|
this.menuMapper = menuMapper;
|
||||||
this.menuPermissionMapper = menuPermissionMapper;
|
this.menuPermissionMapper = menuPermissionMapper;
|
||||||
this.companyPermissionService = companyPermissionService;
|
this.companyPermissionService = companyPermissionService;
|
||||||
this.currentUserContext = currentUserContext;
|
this.currentUserContext = currentUserContext;
|
||||||
|
this.eventPublisher = eventPublisher;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -180,6 +186,9 @@ public class CompanyMenuServiceImpl extends ServiceImpl<CompanyMenuMapper, Compa
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
eventPublisher.publishEvent(
|
||||||
|
AccessChangedEvent.forCompany(AccessChangedReason.COMPANY_MENU, companyId));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
+3
-1
@@ -1,6 +1,7 @@
|
|||||||
package top.xyquan.ecomdmbbackend.modules.org.company.model.dto;
|
package top.xyquan.ecomdmbbackend.modules.org.company.model.dto;
|
||||||
|
|
||||||
import jakarta.validation.constraints.NotBlank;
|
import jakarta.validation.constraints.NotBlank;
|
||||||
|
import jakarta.validation.constraints.Pattern;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
@@ -34,9 +35,10 @@ public class CreateCompanyDTO {
|
|||||||
private String ownerName;
|
private String ownerName;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 公司拥有者电话(作为登录账号)
|
* 公司拥有者电话(必填,用于创建/匹配用户)
|
||||||
*/
|
*/
|
||||||
@NotBlank(message = "公司拥有者电话不能为空")
|
@NotBlank(message = "公司拥有者电话不能为空")
|
||||||
|
@Pattern(regexp = "^1[3-9]\\d{9}$", message = "公司拥有者电话格式不正确")
|
||||||
private String ownerPhone;
|
private String ownerPhone;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
+6
@@ -4,8 +4,11 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|||||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.context.ApplicationEventPublisher;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
import top.xyquan.ecomdmbbackend.modules.notify.access.AccessChangedEvent;
|
||||||
|
import top.xyquan.ecomdmbbackend.modules.notify.access.AccessChangedReason;
|
||||||
import top.xyquan.ecomdmbbackend.modules.org.company.permission.mapper.CompanyPermissionMapper;
|
import top.xyquan.ecomdmbbackend.modules.org.company.permission.mapper.CompanyPermissionMapper;
|
||||||
import top.xyquan.ecomdmbbackend.modules.org.company.permission.model.dto.BatchAssignCompanyPermissionDTO;
|
import top.xyquan.ecomdmbbackend.modules.org.company.permission.model.dto.BatchAssignCompanyPermissionDTO;
|
||||||
import top.xyquan.ecomdmbbackend.modules.org.company.permission.model.po.CompanyPermissionPO;
|
import top.xyquan.ecomdmbbackend.modules.org.company.permission.model.po.CompanyPermissionPO;
|
||||||
@@ -33,6 +36,7 @@ public class CompanyPermissionServiceImpl extends ServiceImpl<CompanyPermissionM
|
|||||||
private final CompanyPermissionMapper companyPermissionMapper;
|
private final CompanyPermissionMapper companyPermissionMapper;
|
||||||
private final PermissionMapper permissionMapper;
|
private final PermissionMapper permissionMapper;
|
||||||
private final CurrentUserContext currentUserContext;
|
private final CurrentUserContext currentUserContext;
|
||||||
|
private final ApplicationEventPublisher eventPublisher;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
@@ -58,6 +62,8 @@ public class CompanyPermissionServiceImpl extends ServiceImpl<CompanyPermissionM
|
|||||||
}
|
}
|
||||||
|
|
||||||
log.info("批量分配公司权限完成,公司ID:{},权限数量:{}", companyId, expandedPermissionIds.size());
|
log.info("批量分配公司权限完成,公司ID:{},权限数量:{}", companyId, expandedPermissionIds.size());
|
||||||
|
eventPublisher.publishEvent(
|
||||||
|
AccessChangedEvent.forCompany(AccessChangedReason.COMPANY_PERMISSION, companyId));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
+1
-1
@@ -146,10 +146,10 @@ public class CompanyServiceImpl extends ServiceImpl<CompanyMapper, CompanyPO> im
|
|||||||
if (ownerUser == null) {
|
if (ownerUser == null) {
|
||||||
// 手机号未注册,创建新用户
|
// 手机号未注册,创建新用户
|
||||||
ownerUser = new UserPO();
|
ownerUser = new UserPO();
|
||||||
ownerUser.setLoginCode(createCompanyDTO.getOwnerPhone());
|
|
||||||
ownerUser.setPhone(createCompanyDTO.getOwnerPhone());
|
ownerUser.setPhone(createCompanyDTO.getOwnerPhone());
|
||||||
ownerUser.setRealName(createCompanyDTO.getOwnerName());
|
ownerUser.setRealName(createCompanyDTO.getOwnerName());
|
||||||
ownerUser.setPassword(passwordEncoder.encode("123456")); // 默认密码
|
ownerUser.setPassword(passwordEncoder.encode("123456")); // 默认密码
|
||||||
|
ownerUser.setUsername(null);
|
||||||
ownerUser.setIsSuper(0);
|
ownerUser.setIsSuper(0);
|
||||||
ownerUser.setStatus(1);
|
ownerUser.setStatus(1);
|
||||||
ownerUser.setPwdSecurityLevel(1);
|
ownerUser.setPwdSecurityLevel(1);
|
||||||
|
|||||||
+1
-1
@@ -26,7 +26,7 @@ public class DepartmentMemberVO {
|
|||||||
|
|
||||||
private String phone;
|
private String phone;
|
||||||
|
|
||||||
private String loginCode;
|
private String username;
|
||||||
|
|
||||||
private LocalDateTime createTime;
|
private LocalDateTime createTime;
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -148,7 +148,7 @@ public class DepartmentMemberServiceImpl extends ServiceImpl<DepartmentMemberMap
|
|||||||
if (user != null) {
|
if (user != null) {
|
||||||
vo.setRealName(user.getRealName());
|
vo.setRealName(user.getRealName());
|
||||||
vo.setPhone(user.getPhone());
|
vo.setPhone(user.getPhone());
|
||||||
vo.setLoginCode(user.getLoginCode());
|
vo.setUsername(user.getUsername());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+12
-1
@@ -2,9 +2,12 @@ package top.xyquan.ecomdmbbackend.modules.org.position.menu.service.impl;
|
|||||||
|
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
|
import org.springframework.context.ApplicationEventPublisher;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
import top.xyquan.ecomdmbbackend.common.exception.BusinessException;
|
import top.xyquan.ecomdmbbackend.common.exception.BusinessException;
|
||||||
|
import top.xyquan.ecomdmbbackend.modules.notify.access.AccessChangedEvent;
|
||||||
|
import top.xyquan.ecomdmbbackend.modules.notify.access.AccessChangedReason;
|
||||||
import top.xyquan.ecomdmbbackend.modules.org.position.menu.mapper.PositionMenuMapper;
|
import top.xyquan.ecomdmbbackend.modules.org.position.menu.mapper.PositionMenuMapper;
|
||||||
import top.xyquan.ecomdmbbackend.modules.org.position.menu.model.dto.BatchAssignPositionMenuDTO;
|
import top.xyquan.ecomdmbbackend.modules.org.position.menu.model.dto.BatchAssignPositionMenuDTO;
|
||||||
import top.xyquan.ecomdmbbackend.modules.org.position.menu.model.po.PositionMenuPO;
|
import top.xyquan.ecomdmbbackend.modules.org.position.menu.model.po.PositionMenuPO;
|
||||||
@@ -39,17 +42,20 @@ public class PositionMenuServiceImpl extends ServiceImpl<PositionMenuMapper, Pos
|
|||||||
private final MenuService menuService;
|
private final MenuService menuService;
|
||||||
private final MenuPermissionMapper menuPermissionMapper;
|
private final MenuPermissionMapper menuPermissionMapper;
|
||||||
private final PositionPermissionService positionPermissionService;
|
private final PositionPermissionService positionPermissionService;
|
||||||
|
private final ApplicationEventPublisher eventPublisher;
|
||||||
|
|
||||||
public PositionMenuServiceImpl(CurrentUserContext currentUserContext,
|
public PositionMenuServiceImpl(CurrentUserContext currentUserContext,
|
||||||
PositionService positionService,
|
PositionService positionService,
|
||||||
MenuService menuService,
|
MenuService menuService,
|
||||||
MenuPermissionMapper menuPermissionMapper,
|
MenuPermissionMapper menuPermissionMapper,
|
||||||
PositionPermissionService positionPermissionService) {
|
PositionPermissionService positionPermissionService,
|
||||||
|
ApplicationEventPublisher eventPublisher) {
|
||||||
this.currentUserContext = currentUserContext;
|
this.currentUserContext = currentUserContext;
|
||||||
this.positionService = positionService;
|
this.positionService = positionService;
|
||||||
this.menuService = menuService;
|
this.menuService = menuService;
|
||||||
this.menuPermissionMapper = menuPermissionMapper;
|
this.menuPermissionMapper = menuPermissionMapper;
|
||||||
this.positionPermissionService = positionPermissionService;
|
this.positionPermissionService = positionPermissionService;
|
||||||
|
this.eventPublisher = eventPublisher;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -83,6 +89,11 @@ public class PositionMenuServiceImpl extends ServiceImpl<PositionMenuMapper, Pos
|
|||||||
for (Long menuId : expandedMenuIds) {
|
for (Long menuId : expandedMenuIds) {
|
||||||
assignPermissionsForPosition(positionId, menuId);
|
assignPermissionsForPosition(positionId, menuId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
PositionPO position = positionService.getById(positionId);
|
||||||
|
Long companyId = position != null ? position.getCompanyId() : null;
|
||||||
|
eventPublisher.publishEvent(AccessChangedEvent.forPosition(
|
||||||
|
AccessChangedReason.POSITION_MENU, companyId, positionId));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
+11
@@ -4,14 +4,19 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|||||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.context.ApplicationEventPublisher;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
import top.xyquan.ecomdmbbackend.common.exception.BusinessException;
|
import top.xyquan.ecomdmbbackend.common.exception.BusinessException;
|
||||||
|
import top.xyquan.ecomdmbbackend.modules.notify.access.AccessChangedEvent;
|
||||||
|
import top.xyquan.ecomdmbbackend.modules.notify.access.AccessChangedReason;
|
||||||
import top.xyquan.ecomdmbbackend.modules.org.position.permission.mapper.PositionPermissionMapper;
|
import top.xyquan.ecomdmbbackend.modules.org.position.permission.mapper.PositionPermissionMapper;
|
||||||
import top.xyquan.ecomdmbbackend.modules.org.position.permission.model.dto.BatchAssignPositionPermissionDTO;
|
import top.xyquan.ecomdmbbackend.modules.org.position.permission.model.dto.BatchAssignPositionPermissionDTO;
|
||||||
import top.xyquan.ecomdmbbackend.modules.org.position.permission.model.po.PositionPermissionPO;
|
import top.xyquan.ecomdmbbackend.modules.org.position.permission.model.po.PositionPermissionPO;
|
||||||
import top.xyquan.ecomdmbbackend.modules.org.position.permission.model.vo.PositionPermissionVO;
|
import top.xyquan.ecomdmbbackend.modules.org.position.permission.model.vo.PositionPermissionVO;
|
||||||
import top.xyquan.ecomdmbbackend.modules.org.position.permission.service.PositionPermissionService;
|
import top.xyquan.ecomdmbbackend.modules.org.position.permission.service.PositionPermissionService;
|
||||||
|
import top.xyquan.ecomdmbbackend.modules.org.position.service.PositionService;
|
||||||
|
import top.xyquan.ecomdmbbackend.modules.org.position.model.po.PositionPO;
|
||||||
import top.xyquan.ecomdmbbackend.modules.sys.permission.mapper.PermissionMapper;
|
import top.xyquan.ecomdmbbackend.modules.sys.permission.mapper.PermissionMapper;
|
||||||
import top.xyquan.ecomdmbbackend.modules.sys.permission.model.po.PermissionPO;
|
import top.xyquan.ecomdmbbackend.modules.sys.permission.model.po.PermissionPO;
|
||||||
|
|
||||||
@@ -35,6 +40,8 @@ public class PositionPermissionServiceImpl extends ServiceImpl<PositionPermissio
|
|||||||
private final PositionPermissionMapper positionPermissionMapper;
|
private final PositionPermissionMapper positionPermissionMapper;
|
||||||
private final PermissionMapper permissionMapper;
|
private final PermissionMapper permissionMapper;
|
||||||
private final CurrentUserContext currentUserContext;
|
private final CurrentUserContext currentUserContext;
|
||||||
|
private final PositionService positionService;
|
||||||
|
private final ApplicationEventPublisher eventPublisher;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 批量分配岗位权限
|
* 批量分配岗位权限
|
||||||
@@ -64,6 +71,10 @@ public class PositionPermissionServiceImpl extends ServiceImpl<PositionPermissio
|
|||||||
}
|
}
|
||||||
|
|
||||||
log.info("批量分配岗位权限完成,岗位ID:{},权限数量:{}", positionId, expandedPermissionIds.size());
|
log.info("批量分配岗位权限完成,岗位ID:{},权限数量:{}", positionId, expandedPermissionIds.size());
|
||||||
|
PositionPO position = positionService.getById(positionId);
|
||||||
|
Long companyId = position != null ? position.getCompanyId() : null;
|
||||||
|
eventPublisher.publishEvent(AccessChangedEvent.forPosition(
|
||||||
|
AccessChangedReason.POSITION_PERMISSION, companyId, positionId));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
+6
-4
@@ -8,14 +8,15 @@ import lombok.Data;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 平台创建系统账户。
|
* 平台创建系统账户。
|
||||||
|
* <p>
|
||||||
|
* 手机号必填;username 可选(留空由用户自行设置)。
|
||||||
*/
|
*/
|
||||||
@Data
|
@Data
|
||||||
public class CreateSysAccountDTO {
|
public class CreateSysAccountDTO {
|
||||||
|
|
||||||
@NotBlank(message = "登录账号不能为空")
|
@Size(min = 3, max = 20, message = "登录用户名长度必须在3-20个字符之间")
|
||||||
@Size(min = 3, max = 20, message = "登录账号长度必须在3-20个字符之间")
|
@Pattern(regexp = "^$|^[a-zA-Z0-9_]+$", message = "登录用户名只能包含字母、数字和下划线")
|
||||||
@Pattern(regexp = "^[a-zA-Z0-9_]+$", message = "登录账号只能包含字母、数字和下划线")
|
private String username;
|
||||||
private String loginCode;
|
|
||||||
|
|
||||||
@NotBlank(message = "密码不能为空")
|
@NotBlank(message = "密码不能为空")
|
||||||
@Size(min = 8, max = 20, message = "密码长度必须在8-20个字符之间")
|
@Size(min = 8, max = 20, message = "密码长度必须在8-20个字符之间")
|
||||||
@@ -25,6 +26,7 @@ public class CreateSysAccountDTO {
|
|||||||
@Size(max = 50, message = "用户姓名长度不能超过50个字符")
|
@Size(max = 50, message = "用户姓名长度不能超过50个字符")
|
||||||
private String realName;
|
private String realName;
|
||||||
|
|
||||||
|
@NotBlank(message = "手机号码不能为空")
|
||||||
@Pattern(regexp = "^1[3-9]\\d{9}$", message = "手机号码格式不正确")
|
@Pattern(regexp = "^1[3-9]\\d{9}$", message = "手机号码格式不正确")
|
||||||
private String phone;
|
private String phone;
|
||||||
|
|
||||||
|
|||||||
+3
-3
@@ -10,9 +10,9 @@ import lombok.Data;
|
|||||||
@Data
|
@Data
|
||||||
public class UpdateSysAccountDTO {
|
public class UpdateSysAccountDTO {
|
||||||
|
|
||||||
@Size(min = 3, max = 20, message = "登录账号长度必须在3-20个字符之间")
|
@Size(min = 3, max = 20, message = "登录用户名长度必须在3-20个字符之间")
|
||||||
@Pattern(regexp = "^[a-zA-Z0-9_]+$", message = "登录账号只能包含字母、数字和下划线")
|
@Pattern(regexp = "^[a-zA-Z0-9_]+$", message = "登录用户名只能包含字母、数字和下划线")
|
||||||
private String loginCode;
|
private String username;
|
||||||
|
|
||||||
@Size(max = 50, message = "用户姓名长度不能超过50个字符")
|
@Size(max = 50, message = "用户姓名长度不能超过50个字符")
|
||||||
private String realName;
|
private String realName;
|
||||||
|
|||||||
+17
-13
@@ -68,12 +68,15 @@ public class SysAccountServiceImpl extends ServiceImpl<UserMapper, UserPO> imple
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public CompanyAccountVO createAccount(CreateSysAccountDTO createAccountDTO) {
|
public CompanyAccountVO createAccount(CreateSysAccountDTO createAccountDTO) {
|
||||||
// 验证登录账号是否已存在
|
// 验证登录用户名是否已存在(可选)
|
||||||
if (StringUtils.hasText(createAccountDTO.getLoginCode())) {
|
String username = StringUtils.hasText(createAccountDTO.getUsername())
|
||||||
|
? createAccountDTO.getUsername().trim()
|
||||||
|
: null;
|
||||||
|
if (username != null) {
|
||||||
LambdaQueryWrapper<UserPO> wrapper = new LambdaQueryWrapper<>();
|
LambdaQueryWrapper<UserPO> wrapper = new LambdaQueryWrapper<>();
|
||||||
wrapper.eq(UserPO::getLoginCode, createAccountDTO.getLoginCode());
|
wrapper.eq(UserPO::getUsername, username);
|
||||||
if (this.count(wrapper) > 0) {
|
if (this.count(wrapper) > 0) {
|
||||||
throw new BusinessException("登录账号已存在");
|
throw new BusinessException("登录用户名已存在");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -89,6 +92,7 @@ public class SysAccountServiceImpl extends ServiceImpl<UserMapper, UserPO> imple
|
|||||||
// 创建账户
|
// 创建账户
|
||||||
UserPO user = new UserPO();
|
UserPO user = new UserPO();
|
||||||
BeanCopyUtils.copyProperties(createAccountDTO, user);
|
BeanCopyUtils.copyProperties(createAccountDTO, user);
|
||||||
|
user.setUsername(username);
|
||||||
if (user.getIsSuper() == null) {
|
if (user.getIsSuper() == null) {
|
||||||
user.setIsSuper(0);
|
user.setIsSuper(0);
|
||||||
}
|
}
|
||||||
@@ -130,14 +134,14 @@ public class SysAccountServiceImpl extends ServiceImpl<UserMapper, UserPO> imple
|
|||||||
throw new BusinessException("账户不存在");
|
throw new BusinessException("账户不存在");
|
||||||
}
|
}
|
||||||
|
|
||||||
// 检查登录账号是否被其他用户使用
|
// 检查登录用户名是否被其他用户使用
|
||||||
if (StringUtils.hasText(updateAccountDTO.getLoginCode()) &&
|
if (StringUtils.hasText(updateAccountDTO.getUsername()) &&
|
||||||
!updateAccountDTO.getLoginCode().equals(user.getLoginCode())) {
|
!updateAccountDTO.getUsername().equals(user.getUsername())) {
|
||||||
LambdaQueryWrapper<UserPO> wrapper = new LambdaQueryWrapper<>();
|
LambdaQueryWrapper<UserPO> wrapper = new LambdaQueryWrapper<>();
|
||||||
wrapper.eq(UserPO::getLoginCode, updateAccountDTO.getLoginCode());
|
wrapper.eq(UserPO::getUsername, updateAccountDTO.getUsername());
|
||||||
wrapper.ne(UserPO::getId, accountId);
|
wrapper.ne(UserPO::getId, accountId);
|
||||||
if (this.count(wrapper) > 0) {
|
if (this.count(wrapper) > 0) {
|
||||||
throw new BusinessException("登录账号已被其他用户使用");
|
throw new BusinessException("登录用户名已被其他用户使用");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -153,8 +157,8 @@ public class SysAccountServiceImpl extends ServiceImpl<UserMapper, UserPO> imple
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 更新账户信息
|
// 更新账户信息
|
||||||
if (StringUtils.hasText(updateAccountDTO.getLoginCode())) {
|
if (StringUtils.hasText(updateAccountDTO.getUsername())) {
|
||||||
user.setLoginCode(updateAccountDTO.getLoginCode());
|
user.setUsername(updateAccountDTO.getUsername());
|
||||||
}
|
}
|
||||||
if (StringUtils.hasText(updateAccountDTO.getPhone())) {
|
if (StringUtils.hasText(updateAccountDTO.getPhone())) {
|
||||||
user.setPhone(updateAccountDTO.getPhone());
|
user.setPhone(updateAccountDTO.getPhone());
|
||||||
@@ -298,8 +302,8 @@ public class SysAccountServiceImpl extends ServiceImpl<UserMapper, UserPO> imple
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 登录账号
|
// 登录账号
|
||||||
if (StringUtils.hasText(filterDTO.getLoginCode())) {
|
if (StringUtils.hasText(filterDTO.getUsername())) {
|
||||||
wrapper.like(UserPO::getLoginCode, filterDTO.getLoginCode());
|
wrapper.like(UserPO::getUsername, filterDTO.getUsername());
|
||||||
}
|
}
|
||||||
|
|
||||||
// 用户姓名
|
// 用户姓名
|
||||||
|
|||||||
+4
-2
@@ -4,13 +4,15 @@ import jakarta.validation.constraints.NotBlank;
|
|||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 用户登录DTO
|
* 用户登录 DTO
|
||||||
|
* <p>
|
||||||
|
* account 可为登录用户名或手机号(先匹配 username,再匹配 phone)。
|
||||||
*/
|
*/
|
||||||
@Data
|
@Data
|
||||||
public class LoginDTO {
|
public class LoginDTO {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 登录账号(可以是loginCode或phone)
|
* 登录标识(用户名或手机号)
|
||||||
*/
|
*/
|
||||||
@NotBlank(message = "登录账号不能为空")
|
@NotBlank(message = "登录账号不能为空")
|
||||||
private String account;
|
private String account;
|
||||||
|
|||||||
+6
-15
@@ -5,35 +5,26 @@ import jakarta.validation.constraints.Pattern;
|
|||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 用户注册DTO
|
* 用户注册 DTO(手机号必填;登录用户名可选)
|
||||||
*/
|
*/
|
||||||
@Data
|
@Data
|
||||||
public class RegisterDTO {
|
public class RegisterDTO {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 登录账号
|
* 登录用户名(可选,用户可稍后自行设置)
|
||||||
*/
|
*/
|
||||||
private String loginCode;
|
private String username;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 手机号码
|
* 手机号码(必填)
|
||||||
*/
|
*/
|
||||||
@Pattern(regexp = "^(|1[3-9]\\d{9})$", message = "手机号码格式不正确")
|
@NotBlank(message = "手机号码不能为空")
|
||||||
|
@Pattern(regexp = "^1[3-9]\\d{9}$", message = "手机号码格式不正确")
|
||||||
private String phone;
|
private String phone;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 登录密码
|
* 登录密码
|
||||||
*/
|
*/
|
||||||
@NotBlank(message = "密码不能为空")
|
@NotBlank(message = "密码不能为空")
|
||||||
// @Pattern(regexp = "^(?=.*[a-z])(?=.*[A-Z])(?=.*\\d)[a-zA-Z\\d@$!%*?&]{8,}$",
|
|
||||||
// message = "密码必须包含大小写字母和数字,长度至少8位")
|
|
||||||
private String password;
|
private String password;
|
||||||
|
|
||||||
/**
|
|
||||||
* 验证登录账号和手机号码至少填写一个
|
|
||||||
*/
|
|
||||||
public boolean isValid() {
|
|
||||||
return (loginCode != null && !loginCode.trim().isEmpty()) ||
|
|
||||||
(phone != null && !phone.trim().isEmpty());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -658,7 +658,7 @@ public class FeedbackServiceImpl implements FeedbackService {
|
|||||||
if (StringUtils.hasText(u.getRealName())) {
|
if (StringUtils.hasText(u.getRealName())) {
|
||||||
return u.getRealName();
|
return u.getRealName();
|
||||||
}
|
}
|
||||||
return u.getLoginCode() != null ? u.getLoginCode() : String.valueOf(u.getId());
|
return u.getUsername() != null ? u.getUsername() : String.valueOf(u.getId());
|
||||||
}, (a, b) -> a));
|
}, (a, b) -> a));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -19,7 +19,7 @@ public class SysInitProperties {
|
|||||||
private String companyName = "系统公司";
|
private String companyName = "系统公司";
|
||||||
|
|
||||||
/** 超级管理员登录账号 */
|
/** 超级管理员登录账号 */
|
||||||
private String adminLoginCode = "admin";
|
private String adminUsername = "admin";
|
||||||
|
|
||||||
/** 超级管理员手机号 */
|
/** 超级管理员手机号 */
|
||||||
private String adminPhone = "13800000001";
|
private String adminPhone = "13800000001";
|
||||||
|
|||||||
+9
-9
@@ -90,20 +90,20 @@ public class SysInitService {
|
|||||||
init.setUpdatedAt(LocalDateTime.now());
|
init.setUpdatedAt(LocalDateTime.now());
|
||||||
sysInitMapper.updateById(init);
|
sysInitMapper.updateById(init);
|
||||||
|
|
||||||
log.info("系统初始化完成:系统公司=[{}],超管账号=[{}]", companyDTO.getName(), admin.getLoginCode());
|
log.info("系统初始化完成:系统公司=[{}],超管账号=[{}]", companyDTO.getName(), admin.getUsername());
|
||||||
}
|
}
|
||||||
|
|
||||||
private UserPO createSuperAdmin() {
|
private UserPO createSuperAdmin() {
|
||||||
String loginCode = initProperties.getAdminLoginCode();
|
String username = initProperties.getAdminUsername();
|
||||||
if (!StringUtils.hasText(loginCode)) {
|
if (!StringUtils.hasText(username)) {
|
||||||
throw new BusinessException("超级管理员登录账号未配置");
|
throw new BusinessException("超级管理员登录用户名未配置");
|
||||||
}
|
}
|
||||||
|
|
||||||
LambdaQueryWrapper<UserPO> wrapper = new LambdaQueryWrapper<>();
|
LambdaQueryWrapper<UserPO> wrapper = new LambdaQueryWrapper<>();
|
||||||
wrapper.eq(UserPO::getLoginCode, loginCode);
|
wrapper.eq(UserPO::getUsername, username);
|
||||||
UserPO existing = userMapper.selectOne(wrapper);
|
UserPO existing = userMapper.selectOne(wrapper);
|
||||||
if (existing != null) {
|
if (existing != null) {
|
||||||
log.warn("超级管理员账号 [{}] 已存在,直接使用", loginCode);
|
log.warn("超级管理员账号 [{}] 已存在,直接使用", username);
|
||||||
return existing;
|
return existing;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -115,7 +115,7 @@ public class SysInitService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
UserPO user = new UserPO();
|
UserPO user = new UserPO();
|
||||||
user.setLoginCode(loginCode);
|
user.setUsername(username);
|
||||||
user.setPhone(initProperties.getAdminPhone());
|
user.setPhone(initProperties.getAdminPhone());
|
||||||
user.setPassword(passwordEncoder.encode(rawPassword));
|
user.setPassword(passwordEncoder.encode(rawPassword));
|
||||||
user.setRealName(initProperties.getAdminRealName());
|
user.setRealName(initProperties.getAdminRealName());
|
||||||
@@ -128,12 +128,12 @@ public class SysInitService {
|
|||||||
if (generated) {
|
if (generated) {
|
||||||
log.warn("==================================================");
|
log.warn("==================================================");
|
||||||
log.warn("超级管理员密码已随机生成,请首次登录后尽快修改:");
|
log.warn("超级管理员密码已随机生成,请首次登录后尽快修改:");
|
||||||
log.warn("账号:{},密码:{}", loginCode, rawPassword);
|
log.warn("账号:{},密码:{}", username, rawPassword);
|
||||||
log.warn("==================================================");
|
log.warn("==================================================");
|
||||||
} else {
|
} else {
|
||||||
log.warn("==================================================");
|
log.warn("==================================================");
|
||||||
log.warn("超级管理员使用默认密码,生产环境请务必修改:");
|
log.warn("超级管理员使用默认密码,生产环境请务必修改:");
|
||||||
log.warn("账号:{},密码:{}", loginCode, rawPassword);
|
log.warn("账号:{},密码:{}", username, rawPassword);
|
||||||
log.warn("==================================================");
|
log.warn("==================================================");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+3
-3
@@ -12,7 +12,7 @@ public class UpdateUserInfoDTO {
|
|||||||
/**
|
/**
|
||||||
* 登录账号(用户名)
|
* 登录账号(用户名)
|
||||||
*/
|
*/
|
||||||
private String loginCode;
|
private String username;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 用户名称
|
* 用户名称
|
||||||
@@ -25,9 +25,9 @@ public class UpdateUserInfoDTO {
|
|||||||
private Long avatarImageId;
|
private Long avatarImageId;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 手机号码
|
* 手机号码(必填;更新时不可清空)
|
||||||
*/
|
*/
|
||||||
@Pattern(regexp = "^(|1[3-9]\\d{9})$", message = "手机号码格式不正确")
|
@Pattern(regexp = "^1[3-9]\\d{9}$", message = "手机号码格式不正确")
|
||||||
private String phone;
|
private String phone;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
+1
-1
@@ -16,7 +16,7 @@ public class UserFilterDTO {
|
|||||||
/**
|
/**
|
||||||
* 登录账号(模糊查询)
|
* 登录账号(模糊查询)
|
||||||
*/
|
*/
|
||||||
private String loginCode;
|
private String username;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 手机号码(精确查询)
|
* 手机号码(精确查询)
|
||||||
|
|||||||
+3
-3
@@ -21,10 +21,10 @@ public class UserPO {
|
|||||||
private Long id;
|
private Long id;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 登录账号
|
* 登录用户名(可空,用户自行设置;账号登录用)
|
||||||
*/
|
*/
|
||||||
@TableField("login_code")
|
@TableField(value = "username", updateStrategy = FieldStrategy.ALWAYS)
|
||||||
private String loginCode;
|
private String username;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 登录密码
|
* 登录密码
|
||||||
|
|||||||
+1
-1
@@ -38,7 +38,7 @@ public class UserVO {
|
|||||||
/**
|
/**
|
||||||
* 登录账号
|
* 登录账号
|
||||||
*/
|
*/
|
||||||
private String loginCode;
|
private String username;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 手机号码
|
* 手机号码
|
||||||
|
|||||||
+2
-2
@@ -38,9 +38,9 @@ public interface UserService extends IService<UserPO> {
|
|||||||
LoginVO login(LoginDTO loginDTO);
|
LoginVO login(LoginDTO loginDTO);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据登录账号或手机号查询用户
|
* 根据登录账号查询用户(用户名或手机号)
|
||||||
*
|
*
|
||||||
* @param account 登录账号或手机号
|
* @param account 登录用户名或手机号
|
||||||
* @return 用户信息
|
* @return 用户信息
|
||||||
*/
|
*/
|
||||||
UserPO findByAccount(String account);
|
UserPO findByAccount(String account);
|
||||||
|
|||||||
+50
-34
@@ -70,35 +70,30 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, UserPO> implements
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public LoginVO register(RegisterDTO registerDTO) {
|
public LoginVO register(RegisterDTO registerDTO) {
|
||||||
// 验证登录账号和手机号码至少填写一个
|
// 检查登录用户名是否已存在
|
||||||
if (!registerDTO.isValid()) {
|
if (StringUtils.hasText(registerDTO.getUsername())) {
|
||||||
throw new BusinessException("登录账号和手机号码至少填写一个");
|
|
||||||
}
|
|
||||||
|
|
||||||
// 检查登录账号是否已存在
|
|
||||||
if (StringUtils.hasText(registerDTO.getLoginCode())) {
|
|
||||||
LambdaQueryWrapper<UserPO> wrapper = new LambdaQueryWrapper<>();
|
LambdaQueryWrapper<UserPO> wrapper = new LambdaQueryWrapper<>();
|
||||||
wrapper.eq(UserPO::getLoginCode, registerDTO.getLoginCode());
|
wrapper.eq(UserPO::getUsername, registerDTO.getUsername().trim());
|
||||||
if (this.count(wrapper) > 0) {
|
if (this.count(wrapper) > 0) {
|
||||||
throw new BusinessException("登录账号已存在");
|
throw new BusinessException("登录用户名已存在");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 检查手机号码是否已存在
|
// 手机号必填且唯一
|
||||||
if (StringUtils.hasText(registerDTO.getPhone())) {
|
LambdaQueryWrapper<UserPO> phoneWrapper = new LambdaQueryWrapper<>();
|
||||||
LambdaQueryWrapper<UserPO> wrapper = new LambdaQueryWrapper<>();
|
phoneWrapper.eq(UserPO::getPhone, registerDTO.getPhone());
|
||||||
wrapper.eq(UserPO::getPhone, registerDTO.getPhone());
|
if (this.count(phoneWrapper) > 0) {
|
||||||
if (this.count(wrapper) > 0) {
|
|
||||||
throw new BusinessException("手机号码已存在");
|
throw new BusinessException("手机号码已存在");
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// 创建用户
|
// 创建用户
|
||||||
UserPO user = new UserPO();
|
UserPO user = new UserPO();
|
||||||
user.setLoginCode(registerDTO.getLoginCode());
|
if (StringUtils.hasText(registerDTO.getUsername())) {
|
||||||
|
user.setUsername(registerDTO.getUsername().trim());
|
||||||
|
}
|
||||||
user.setPhone(registerDTO.getPhone());
|
user.setPhone(registerDTO.getPhone());
|
||||||
user.setPassword(passwordEncoder.encode(registerDTO.getPassword()));
|
user.setPassword(passwordEncoder.encode(registerDTO.getPassword()));
|
||||||
user.setRealName("用户" + System.currentTimeMillis()); // 默认用户名
|
user.setRealName("用户" + System.currentTimeMillis()); // 默认展示名
|
||||||
user.setIsSuper(0); // 默认非超管
|
user.setIsSuper(0); // 默认非超管
|
||||||
user.setStatus(1); // 正常状态
|
user.setStatus(1); // 正常状态
|
||||||
user.setPwdSecurityLevel(0); // 初始密码安全级别
|
user.setPwdSecurityLevel(0); // 初始密码安全级别
|
||||||
@@ -118,7 +113,6 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, UserPO> implements
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public LoginVO login(LoginDTO loginDTO) {
|
public LoginVO login(LoginDTO loginDTO) {
|
||||||
// 根据账号查询用户
|
|
||||||
UserPO user = findByAccount(loginDTO.getAccount());
|
UserPO user = findByAccount(loginDTO.getAccount());
|
||||||
if (user == null) {
|
if (user == null) {
|
||||||
throw new BusinessException("用户不存在");
|
throw new BusinessException("用户不存在");
|
||||||
@@ -149,19 +143,39 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, UserPO> implements
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据账号查询用户
|
* 根据登录账号查询用户:先匹配 username,再匹配 phone(避免 OR 混查撞两条)。
|
||||||
* @param account 账号
|
|
||||||
* @return 用户PO
|
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public UserPO findByAccount(String account) {
|
public UserPO findByAccount(String account) {
|
||||||
|
if (!StringUtils.hasText(account)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
UserPO byUsername = findByUsername(account);
|
||||||
|
if (byUsername != null) {
|
||||||
|
return byUsername;
|
||||||
|
}
|
||||||
|
return findByPhoneForLogin(account);
|
||||||
|
}
|
||||||
|
|
||||||
|
private UserPO findByUsername(String username) {
|
||||||
LambdaQueryWrapper<UserPO> wrapper = new LambdaQueryWrapper<>();
|
LambdaQueryWrapper<UserPO> wrapper = new LambdaQueryWrapper<>();
|
||||||
wrapper.and(w -> w.eq(UserPO::getLoginCode, account)
|
wrapper.eq(UserPO::getUsername, username);
|
||||||
.or()
|
|
||||||
.eq(UserPO::getPhone, account));
|
|
||||||
return this.getOne(wrapper);
|
return this.getOne(wrapper);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private UserPO findByPhoneForLogin(String phone) {
|
||||||
|
LambdaQueryWrapper<UserPO> wrapper = new LambdaQueryWrapper<>();
|
||||||
|
wrapper.eq(UserPO::getPhone, phone);
|
||||||
|
List<UserPO> users = this.list(wrapper);
|
||||||
|
if (users == null || users.isEmpty()) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
if (users.size() > 1) {
|
||||||
|
throw new BusinessException("手机号对应多个账号,请使用登录用户名登录");
|
||||||
|
}
|
||||||
|
return users.get(0);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取当前用户信息
|
* 获取当前用户信息
|
||||||
* @return 用户VO
|
* @return 用户VO
|
||||||
@@ -217,20 +231,22 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, UserPO> implements
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 检查登录账号是否已被其他用户使用
|
// 检查登录用户名是否已被其他用户使用
|
||||||
if (StringUtils.hasText(updateUserInfoDTO.getLoginCode()) &&
|
if (updateUserInfoDTO.getUsername() != null) {
|
||||||
!updateUserInfoDTO.getLoginCode().equals(user.getLoginCode())) {
|
String username = StringUtils.hasText(updateUserInfoDTO.getUsername())
|
||||||
|
? updateUserInfoDTO.getUsername().trim()
|
||||||
|
: null;
|
||||||
|
if (username != null && !username.equals(user.getUsername())) {
|
||||||
LambdaQueryWrapper<UserPO> wrapper = new LambdaQueryWrapper<>();
|
LambdaQueryWrapper<UserPO> wrapper = new LambdaQueryWrapper<>();
|
||||||
wrapper.eq(UserPO::getLoginCode, updateUserInfoDTO.getLoginCode());
|
wrapper.eq(UserPO::getUsername, username);
|
||||||
if (this.count(wrapper) > 0) {
|
if (this.count(wrapper) > 0) {
|
||||||
throw new BusinessException("登录账号已被其他用户使用");
|
throw new BusinessException("登录用户名已被其他用户使用");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
user.setUsername(username);
|
||||||
|
}
|
||||||
|
|
||||||
// 更新用户信息
|
// 更新用户信息
|
||||||
if (StringUtils.hasText(updateUserInfoDTO.getLoginCode())) {
|
|
||||||
user.setLoginCode(updateUserInfoDTO.getLoginCode());
|
|
||||||
}
|
|
||||||
if (StringUtils.hasText(updateUserInfoDTO.getRealName())) {
|
if (StringUtils.hasText(updateUserInfoDTO.getRealName())) {
|
||||||
user.setRealName(updateUserInfoDTO.getRealName());
|
user.setRealName(updateUserInfoDTO.getRealName());
|
||||||
}
|
}
|
||||||
@@ -444,8 +460,8 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, UserPO> implements
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 登录账号模糊查询
|
// 登录账号模糊查询
|
||||||
if (StringUtils.hasText(filter.getLoginCode())) {
|
if (StringUtils.hasText(filter.getUsername())) {
|
||||||
queryWrapper.like(UserPO::getLoginCode, filter.getLoginCode());
|
queryWrapper.like(UserPO::getUsername, filter.getUsername());
|
||||||
}
|
}
|
||||||
|
|
||||||
// 手机号码精确查询
|
// 手机号码精确查询
|
||||||
|
|||||||
@@ -88,7 +88,7 @@ ecom:
|
|||||||
init:
|
init:
|
||||||
auto-init: true
|
auto-init: true
|
||||||
company-name: 系统公司
|
company-name: 系统公司
|
||||||
admin-login-code: admin
|
admin-username: admin
|
||||||
admin-real-name: 超级管理员
|
admin-real-name: 超级管理员
|
||||||
admin-phone: 13800000001
|
admin-phone: 13800000001
|
||||||
admin-password: admin123
|
admin-password: admin123
|
||||||
|
|||||||
+4
-4
@@ -25,7 +25,7 @@
|
|||||||
// @Test
|
// @Test
|
||||||
// public void testRegister() {
|
// public void testRegister() {
|
||||||
// RegisterDTO registerDTO = new RegisterDTO();
|
// RegisterDTO registerDTO = new RegisterDTO();
|
||||||
// registerDTO.setLoginCode("testuser");
|
// registerDTO.setUsername("testuser");
|
||||||
// registerDTO.setPassword("TestPass123");
|
// registerDTO.setPassword("TestPass123");
|
||||||
//
|
//
|
||||||
// LoginVO loginVO = userService.register(registerDTO);
|
// LoginVO loginVO = userService.register(registerDTO);
|
||||||
@@ -33,7 +33,7 @@
|
|||||||
// assertNotNull(loginVO);
|
// assertNotNull(loginVO);
|
||||||
// assertNotNull(loginVO.getToken());
|
// assertNotNull(loginVO.getToken());
|
||||||
// assertNotNull(loginVO.getUser());
|
// assertNotNull(loginVO.getUser());
|
||||||
// assertEquals("testuser", loginVO.getUser().getLoginCode());
|
// assertEquals("testuser", loginVO.getUser().getUsername());
|
||||||
// assertEquals("user", loginVO.getUser().getRole());
|
// assertEquals("user", loginVO.getUser().getRole());
|
||||||
// assertEquals(0, loginVO.getUser().getStatus());
|
// assertEquals(0, loginVO.getUser().getStatus());
|
||||||
// }
|
// }
|
||||||
@@ -42,7 +42,7 @@
|
|||||||
// public void testLogin() {
|
// public void testLogin() {
|
||||||
// // 先注册一个用户
|
// // 先注册一个用户
|
||||||
// RegisterDTO registerDTO = new RegisterDTO();
|
// RegisterDTO registerDTO = new RegisterDTO();
|
||||||
// registerDTO.setLoginCode("logintest");
|
// registerDTO.setUsername("logintest");
|
||||||
// registerDTO.setPassword("TestPass123");
|
// registerDTO.setPassword("TestPass123");
|
||||||
// userService.register(registerDTO);
|
// userService.register(registerDTO);
|
||||||
//
|
//
|
||||||
@@ -56,7 +56,7 @@
|
|||||||
// assertNotNull(loginVO);
|
// assertNotNull(loginVO);
|
||||||
// assertNotNull(loginVO.getToken());
|
// assertNotNull(loginVO.getToken());
|
||||||
// assertNotNull(loginVO.getUser());
|
// assertNotNull(loginVO.getUser());
|
||||||
// assertEquals("logintest", loginVO.getUser().getLoginCode());
|
// assertEquals("logintest", loginVO.getUser().getUsername());
|
||||||
// }
|
// }
|
||||||
//
|
//
|
||||||
// @Test
|
// @Test
|
||||||
|
|||||||
@@ -41,8 +41,8 @@ export namespace AccountDTO {
|
|||||||
|
|
||||||
/** 账户过滤条件 */
|
/** 账户过滤条件 */
|
||||||
export interface AccountFilterDTO {
|
export interface AccountFilterDTO {
|
||||||
/** 登录账号(模糊查询) */
|
/** 登录用户名(模糊查询) */
|
||||||
loginCode?: string;
|
username?: string;
|
||||||
/** 用户姓名(模糊查询) */
|
/** 用户姓名(模糊查询) */
|
||||||
realName?: string;
|
realName?: string;
|
||||||
/** 手机号码(精确查询) */
|
/** 手机号码(精确查询) */
|
||||||
|
|||||||
@@ -23,10 +23,10 @@ export namespace AccountVO {
|
|||||||
role?: 'member' | 'owner';
|
role?: 'member' | 'owner';
|
||||||
/** 公司成员角色展示名 */
|
/** 公司成员角色展示名 */
|
||||||
roleName?: string;
|
roleName?: string;
|
||||||
/** 登录账号 */
|
/** 登录用户名(可空) */
|
||||||
loginCode: string;
|
username?: string | null;
|
||||||
/** 手机号码 */
|
/** 手机号码 */
|
||||||
phone?: string;
|
phone: string;
|
||||||
/** 用户姓名 */
|
/** 用户姓名 */
|
||||||
realName: string;
|
realName: string;
|
||||||
/** 头像路径 */
|
/** 头像路径 */
|
||||||
|
|||||||
@@ -16,8 +16,8 @@ export namespace AuthApi {
|
|||||||
|
|
||||||
/** 注册接口参数 */
|
/** 注册接口参数 */
|
||||||
export interface RegisterParams {
|
export interface RegisterParams {
|
||||||
loginCode?: string;
|
username?: string;
|
||||||
phone?: string;
|
phone: string;
|
||||||
password: string;
|
password: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -38,8 +38,8 @@ export namespace AuthApi {
|
|||||||
};
|
};
|
||||||
departmentId?: number;
|
departmentId?: number;
|
||||||
positionId?: number;
|
positionId?: number;
|
||||||
loginCode: string;
|
username?: string | null;
|
||||||
phone?: string;
|
phone: string;
|
||||||
realName: string;
|
realName: string;
|
||||||
avatar?: string;
|
avatar?: string;
|
||||||
role: string;
|
role: string;
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ export const RealtimeSseEvent = {
|
|||||||
CONNECTED: 'message',
|
CONNECTED: 'message',
|
||||||
PING: 'ping',
|
PING: 'ping',
|
||||||
PDD_ORDER_FULL_SYNC_PROGRESS: 'pdd_order_full_sync_progress',
|
PDD_ORDER_FULL_SYNC_PROGRESS: 'pdd_order_full_sync_progress',
|
||||||
|
ACCESS_CHANGED: 'access_changed',
|
||||||
} as const;
|
} as const;
|
||||||
|
|
||||||
export type RealtimeSseEventName =
|
export type RealtimeSseEventName =
|
||||||
|
|||||||
@@ -5,14 +5,14 @@
|
|||||||
export namespace SuperAccountDTO {
|
export namespace SuperAccountDTO {
|
||||||
/** 超管创建账户参数 */
|
/** 超管创建账户参数 */
|
||||||
export interface SuperCreateAccountDTO {
|
export interface SuperCreateAccountDTO {
|
||||||
/** 登录账号 */
|
/** 登录用户名(可选) */
|
||||||
loginCode: string;
|
username?: string;
|
||||||
/** 密码 */
|
/** 密码 */
|
||||||
password: string;
|
password: string;
|
||||||
/** 用户姓名 */
|
/** 用户姓名 */
|
||||||
realName: string;
|
realName: string;
|
||||||
/** 手机号码 */
|
/** 手机号码 */
|
||||||
phone?: string;
|
phone: string;
|
||||||
/** 公司ID */
|
/** 公司ID */
|
||||||
companyId: number;
|
companyId: number;
|
||||||
/** 部门ID */
|
/** 部门ID */
|
||||||
@@ -29,8 +29,8 @@ export namespace SuperAccountDTO {
|
|||||||
|
|
||||||
/** 超管更新账户参数 */
|
/** 超管更新账户参数 */
|
||||||
export interface SuperUpdateAccountDTO {
|
export interface SuperUpdateAccountDTO {
|
||||||
/** 登录账号 */
|
/** 登录用户名 */
|
||||||
loginCode?: string;
|
username?: string;
|
||||||
/** 用户姓名 */
|
/** 用户姓名 */
|
||||||
realName?: string;
|
realName?: string;
|
||||||
/** 手机号码 */
|
/** 手机号码 */
|
||||||
@@ -53,8 +53,8 @@ export namespace SuperAccountDTO {
|
|||||||
|
|
||||||
/** 账户过滤条件 */
|
/** 账户过滤条件 */
|
||||||
export interface AccountFilterDTO {
|
export interface AccountFilterDTO {
|
||||||
/** 登录账号(模糊查询) */
|
/** 登录用户名(模糊查询) */
|
||||||
loginCode?: string;
|
username?: string;
|
||||||
/** 用户姓名(模糊查询) */
|
/** 用户姓名(模糊查询) */
|
||||||
realName?: string;
|
realName?: string;
|
||||||
/** 手机号码(精确查询) */
|
/** 手机号码(精确查询) */
|
||||||
|
|||||||
@@ -19,10 +19,10 @@ export namespace SuperAccountVO {
|
|||||||
positionId?: number;
|
positionId?: number;
|
||||||
/** 岗位名称 */
|
/** 岗位名称 */
|
||||||
positionName?: string;
|
positionName?: string;
|
||||||
/** 登录账号 */
|
/** 登录用户名(可空) */
|
||||||
loginCode: string;
|
username?: string | null;
|
||||||
/** 手机号码 */
|
/** 手机号码 */
|
||||||
phone?: string;
|
phone: string;
|
||||||
/** 用户姓名 */
|
/** 用户姓名 */
|
||||||
realName: string;
|
realName: string;
|
||||||
/** 头像路径 */
|
/** 头像路径 */
|
||||||
|
|||||||
@@ -5,8 +5,8 @@
|
|||||||
export namespace UserDTO {
|
export namespace UserDTO {
|
||||||
/** 更新用户信息参数 */
|
/** 更新用户信息参数 */
|
||||||
export interface UpdateUserInfoDTO {
|
export interface UpdateUserInfoDTO {
|
||||||
/** 登录账号(用户名) */
|
/** 登录用户名(用户名) */
|
||||||
loginCode?: string;
|
username?: string;
|
||||||
/** 用户名称 */
|
/** 用户名称 */
|
||||||
realName?: string;
|
realName?: string;
|
||||||
/** 头像图片ID */
|
/** 头像图片ID */
|
||||||
@@ -29,8 +29,8 @@ export namespace UserDTO {
|
|||||||
export interface UserFilterDTO {
|
export interface UserFilterDTO {
|
||||||
/** 用户名称(模糊查询) */
|
/** 用户名称(模糊查询) */
|
||||||
realName?: string;
|
realName?: string;
|
||||||
/** 登录账号(模糊查询) */
|
/** 登录用户名(模糊查询) */
|
||||||
loginCode?: string;
|
username?: string;
|
||||||
/** 手机号码(精确查询) */
|
/** 手机号码(精确查询) */
|
||||||
phone?: string;
|
phone?: string;
|
||||||
/** 用户角色 */
|
/** 用户角色 */
|
||||||
|
|||||||
@@ -18,10 +18,10 @@ export namespace UserVO {
|
|||||||
departmentId?: number;
|
departmentId?: number;
|
||||||
/** 岗位id */
|
/** 岗位id */
|
||||||
positionId?: number;
|
positionId?: number;
|
||||||
/** 登录账号 */
|
/** 登录用户名(可空) */
|
||||||
loginCode: string;
|
username?: string | null;
|
||||||
/** 手机号码 */
|
/** 手机号码 */
|
||||||
phone?: string;
|
phone: string;
|
||||||
/** 用户名称 */
|
/** 用户名称 */
|
||||||
realName: string;
|
realName: string;
|
||||||
/** 头像路径 */
|
/** 头像路径 */
|
||||||
|
|||||||
@@ -56,7 +56,7 @@ const companyOptions = computed(() =>
|
|||||||
// 用户选项
|
// 用户选项
|
||||||
const userOptions = computed(() =>
|
const userOptions = computed(() =>
|
||||||
userList.value.map((user) => ({
|
userList.value.map((user) => ({
|
||||||
label: `${user.realName} (${user.loginCode})`,
|
label: `${user.realName} (${user.username})`,
|
||||||
value: user.id,
|
value: user.id,
|
||||||
user,
|
user,
|
||||||
})),
|
})),
|
||||||
@@ -146,14 +146,14 @@ const loadUsers = async (reset = false) => {
|
|||||||
|
|
||||||
const params: PageQueryDTO<{
|
const params: PageQueryDTO<{
|
||||||
companyId?: number;
|
companyId?: number;
|
||||||
loginCode?: string;
|
username?: string;
|
||||||
realName?: string;
|
realName?: string;
|
||||||
}> = {
|
}> = {
|
||||||
page: userPage.value,
|
page: userPage.value,
|
||||||
pageSize: userPageSize.value,
|
pageSize: userPageSize.value,
|
||||||
filters: {
|
filters: {
|
||||||
realName: userSearchValue.value || undefined,
|
realName: userSearchValue.value || undefined,
|
||||||
loginCode: userSearchValue.value || undefined,
|
username: userSearchValue.value || undefined,
|
||||||
companyId: formData.value.companyId,
|
companyId: formData.value.companyId,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
@@ -369,7 +369,7 @@ defineExpose({
|
|||||||
<div class="flex-1">
|
<div class="flex-1">
|
||||||
<div class="text-lg font-medium">{{ selectedUser.realName }}</div>
|
<div class="text-lg font-medium">{{ selectedUser.realName }}</div>
|
||||||
<div class="text-gray-500">
|
<div class="text-gray-500">
|
||||||
登录账号: {{ selectedUser.loginCode }}
|
登录用户名: {{ selectedUser.username }}
|
||||||
</div>
|
</div>
|
||||||
<div class="text-gray-500">
|
<div class="text-gray-500">
|
||||||
手机号码: {{ selectedUser.phone || '-' }}
|
手机号码: {{ selectedUser.phone || '-' }}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import type { NotificationItem } from '@vben/layouts';
|
import type { NotificationItem } from '@vben/layouts';
|
||||||
|
|
||||||
import { computed, onMounted, ref, watch } from 'vue';
|
import { computed, onMounted, onUnmounted, ref, watch } from 'vue';
|
||||||
import { useRouter } from 'vue-router';
|
import { useRouter } from 'vue-router';
|
||||||
|
|
||||||
import { AuthenticationLoginExpiredModal } from '@vben/common-ui';
|
import { AuthenticationLoginExpiredModal } from '@vben/common-ui';
|
||||||
@@ -19,6 +19,7 @@ import { useAccessStore, useUserStore } from '@vben/stores';
|
|||||||
import SwitchAccountModal from '#/components/SwitchAccountModal.vue';
|
import SwitchAccountModal from '#/components/SwitchAccountModal.vue';
|
||||||
import SwitchCompanyModal from '#/components/SwitchCompanyModal.vue';
|
import SwitchCompanyModal from '#/components/SwitchCompanyModal.vue';
|
||||||
import { usePermission } from '#/composables/use-permission';
|
import { usePermission } from '#/composables/use-permission';
|
||||||
|
import { RealtimeSseEvent } from '#/api/notify/sse';
|
||||||
import { useAuthStore, useRealtimeStore } from '#/store';
|
import { useAuthStore, useRealtimeStore } from '#/store';
|
||||||
import LoginForm from '#/views/_core/authentication/login.vue';
|
import LoginForm from '#/views/_core/authentication/login.vue';
|
||||||
|
|
||||||
@@ -69,12 +70,33 @@ const showDot = computed(() =>
|
|||||||
notifications.value.some((item) => !item.isRead),
|
notifications.value.some((item) => !item.isRead),
|
||||||
);
|
);
|
||||||
|
|
||||||
// 登录布局挂载:已登录才建 SSE
|
// 登录布局挂载:已登录才建 SSE,并订阅权限变更
|
||||||
|
let accessChangedHandler: ((event: MessageEvent) => void) | null = null;
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
if (!accessStore.accessToken) {
|
if (!accessStore.accessToken) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
realtimeStore.start();
|
realtimeStore.start();
|
||||||
|
|
||||||
|
accessChangedHandler = (event: MessageEvent) => {
|
||||||
|
let ts: number | undefined;
|
||||||
|
try {
|
||||||
|
const data = JSON.parse(event.data as string) as { ts?: number };
|
||||||
|
ts = typeof data?.ts === 'number' ? data.ts : undefined;
|
||||||
|
} catch {
|
||||||
|
// ignore parse error,仍尝试刷新
|
||||||
|
}
|
||||||
|
void authStore.refreshAccess(ts);
|
||||||
|
};
|
||||||
|
realtimeStore.on(RealtimeSseEvent.ACCESS_CHANGED, accessChangedHandler);
|
||||||
|
});
|
||||||
|
|
||||||
|
onUnmounted(() => {
|
||||||
|
if (accessChangedHandler) {
|
||||||
|
realtimeStore.off(RealtimeSseEvent.ACCESS_CHANGED, accessChangedHandler);
|
||||||
|
accessChangedHandler = null;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// 切换账户模态框引用
|
// 切换账户模态框引用
|
||||||
|
|||||||
@@ -61,7 +61,10 @@ function filterMissingPageRoutes(
|
|||||||
return walk(routes);
|
return walk(routes);
|
||||||
}
|
}
|
||||||
|
|
||||||
async function generateAccess(options: GenerateMenuAndRoutesOptions) {
|
async function generateAccess(
|
||||||
|
options: GenerateMenuAndRoutesOptions & { silent?: boolean },
|
||||||
|
) {
|
||||||
|
const { silent, ...rest } = options;
|
||||||
const pageMap: ComponentRecordType = import.meta.glob('../views/**/*.vue');
|
const pageMap: ComponentRecordType = import.meta.glob('../views/**/*.vue');
|
||||||
|
|
||||||
const layoutMap: ComponentRecordType = {
|
const layoutMap: ComponentRecordType = {
|
||||||
@@ -70,12 +73,14 @@ async function generateAccess(options: GenerateMenuAndRoutesOptions) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
return await generateAccessible(preferences.app.accessMode, {
|
return await generateAccessible(preferences.app.accessMode, {
|
||||||
...options,
|
...rest,
|
||||||
fetchMenuListAsync: async () => {
|
fetchMenuListAsync: async () => {
|
||||||
|
if (!silent) {
|
||||||
message.loading({
|
message.loading({
|
||||||
content: `${$t('common.loadingMenu')}...`,
|
content: `${$t('common.loadingMenu')}...`,
|
||||||
duration: 1.5,
|
duration: 1.5,
|
||||||
});
|
});
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
const routes = await getUserMenuApi();
|
const routes = await getUserMenuApi();
|
||||||
return filterMissingPageRoutes(routes || [], pageMap, layoutMap);
|
return filterMissingPageRoutes(routes || [], pageMap, layoutMap);
|
||||||
|
|||||||
@@ -20,6 +20,8 @@ import {
|
|||||||
} from '#/api';
|
} from '#/api';
|
||||||
import { $t } from '#/locales';
|
import { $t } from '#/locales';
|
||||||
import { useAppConfigStore } from '#/store/app-config';
|
import { useAppConfigStore } from '#/store/app-config';
|
||||||
|
import { generateAccess } from '#/router/access';
|
||||||
|
import { accessRoutes, coreRouteNames } from '#/router/routes';
|
||||||
|
|
||||||
export const useAuthStore = defineStore('auth', () => {
|
export const useAuthStore = defineStore('auth', () => {
|
||||||
const accessStore = useAccessStore();
|
const accessStore = useAccessStore();
|
||||||
@@ -28,6 +30,9 @@ export const useAuthStore = defineStore('auth', () => {
|
|||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
|
|
||||||
const loginLoading = ref(false);
|
const loginLoading = ref(false);
|
||||||
|
/** 防止 SSE 短时间连发导致并发重拉 */
|
||||||
|
let accessRefreshing = false;
|
||||||
|
let lastAccessRefreshTs = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 异步处理登录操作
|
* 异步处理登录操作
|
||||||
@@ -206,7 +211,7 @@ export const useAuthStore = defineStore('auth', () => {
|
|||||||
userInfo = {
|
userInfo = {
|
||||||
...user,
|
...user,
|
||||||
userId: user.id.toString(),
|
userId: user.id.toString(),
|
||||||
username: user.loginCode,
|
username: user.username || user.phone || '',
|
||||||
desc: user.remark || '',
|
desc: user.remark || '',
|
||||||
homePath: preferences.app.defaultHomePath,
|
homePath: preferences.app.defaultHomePath,
|
||||||
avatar: user.avatar || '',
|
avatar: user.avatar || '',
|
||||||
@@ -228,6 +233,97 @@ export const useAuthStore = defineStore('auth', () => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* SSE access_changed 后重拉权限码与菜单路由(不整页刷新)。
|
||||||
|
* @param eventTs 服务端 payload.ts,用于去重
|
||||||
|
*/
|
||||||
|
async function refreshAccess(eventTs?: number) {
|
||||||
|
if (!accessStore.accessToken) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (typeof eventTs === 'number' && eventTs > 0 && eventTs <= lastAccessRefreshTs) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (accessRefreshing) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
accessRefreshing = true;
|
||||||
|
try {
|
||||||
|
await fetchAccessCodes();
|
||||||
|
|
||||||
|
const prevNames = collectRouteNames(accessStore.accessRoutes);
|
||||||
|
const userInfo = userStore.userInfo;
|
||||||
|
accessStore.setIsAccessChecked(false);
|
||||||
|
const { accessibleMenus, accessibleRoutes } = await generateAccess({
|
||||||
|
roles: userInfo?.roles ?? [],
|
||||||
|
router,
|
||||||
|
routes: accessRoutes,
|
||||||
|
silent: true,
|
||||||
|
});
|
||||||
|
accessStore.setAccessMenus(accessibleMenus);
|
||||||
|
accessStore.setAccessRoutes(accessibleRoutes);
|
||||||
|
accessStore.setIsAccessChecked(true);
|
||||||
|
|
||||||
|
const nextNames = new Set(collectRouteNames(accessibleRoutes));
|
||||||
|
for (const name of prevNames) {
|
||||||
|
if (!nextNames.has(name) && router.hasRoute(name)) {
|
||||||
|
router.removeRoute(name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (typeof eventTs === 'number' && eventTs > 0) {
|
||||||
|
lastAccessRefreshTs = eventTs;
|
||||||
|
} else {
|
||||||
|
lastAccessRefreshTs = Date.now();
|
||||||
|
}
|
||||||
|
|
||||||
|
const current = router.currentRoute.value;
|
||||||
|
const currentName = current.name as string | undefined;
|
||||||
|
if (
|
||||||
|
currentName &&
|
||||||
|
!coreRouteNames.includes(currentName) &&
|
||||||
|
currentName !== 'FallbackNotFound'
|
||||||
|
) {
|
||||||
|
const reachable = router.hasRoute(currentName);
|
||||||
|
if (!reachable) {
|
||||||
|
await router.replace(
|
||||||
|
userInfo?.homePath || preferences.app.defaultHomePath,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
notification.info({
|
||||||
|
duration: 3,
|
||||||
|
message: '权限已更新',
|
||||||
|
description: '菜单与权限码已自动刷新',
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
console.warn('刷新菜单/权限失败:', error);
|
||||||
|
} finally {
|
||||||
|
accessRefreshing = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 收集路由树中的 name,用于撤销权限后卸掉旧动态路由 */
|
||||||
|
function collectRouteNames(routes: { name?: unknown; children?: any[] }[] | undefined) {
|
||||||
|
const names: string[] = [];
|
||||||
|
const walk = (list: { name?: unknown; children?: any[] }[] | undefined) => {
|
||||||
|
if (!list?.length) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
for (const r of list) {
|
||||||
|
if (typeof r.name === 'string' && r.name) {
|
||||||
|
names.push(r.name);
|
||||||
|
}
|
||||||
|
if (r.children?.length) {
|
||||||
|
walk(r.children);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
walk(routes);
|
||||||
|
return names;
|
||||||
|
}
|
||||||
|
|
||||||
function $reset() {
|
function $reset() {
|
||||||
loginLoading.value = false;
|
loginLoading.value = false;
|
||||||
}
|
}
|
||||||
@@ -240,5 +336,6 @@ export const useAuthStore = defineStore('auth', () => {
|
|||||||
fetchUserInfo,
|
fetchUserInfo,
|
||||||
loginLoading,
|
loginLoading,
|
||||||
logout,
|
logout,
|
||||||
|
refreshAccess,
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -17,11 +17,11 @@ const formSchema = computed((): VbenFormSchema[] => {
|
|||||||
{
|
{
|
||||||
component: 'VbenInput',
|
component: 'VbenInput',
|
||||||
componentProps: {
|
componentProps: {
|
||||||
placeholder: '请输入登录账号或手机号',
|
placeholder: '请输入登录用户名或手机号',
|
||||||
},
|
},
|
||||||
fieldName: 'account',
|
fieldName: 'account',
|
||||||
label: '登录账号',
|
label: '登录账号',
|
||||||
rules: z.string().min(1, { message: '请输入登录账号或手机号' }),
|
rules: z.string().min(1, { message: '请输入登录用户名或手机号' }),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
component: 'VbenInputPassword',
|
component: 'VbenInputPassword',
|
||||||
|
|||||||
@@ -18,29 +18,25 @@ const formSchema = computed((): VbenFormSchema[] => {
|
|||||||
{
|
{
|
||||||
component: 'VbenInput',
|
component: 'VbenInput',
|
||||||
componentProps: {
|
componentProps: {
|
||||||
placeholder: '请输入登录账号(可选)',
|
placeholder: '请输入登录用户名(可选)',
|
||||||
},
|
},
|
||||||
fieldName: 'loginCode',
|
fieldName: 'username',
|
||||||
label: '登录账号',
|
label: '登录用户名',
|
||||||
rules: z.string().optional(),
|
rules: z.string().optional(),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
component: 'VbenInput',
|
component: 'VbenInput',
|
||||||
componentProps: {
|
componentProps: {
|
||||||
placeholder: '请输入手机号(可选)',
|
placeholder: '请输入手机号',
|
||||||
},
|
},
|
||||||
fieldName: 'phone',
|
fieldName: 'phone',
|
||||||
label: '手机号',
|
label: '手机号',
|
||||||
rules: z
|
rules: z
|
||||||
.string()
|
.string()
|
||||||
.optional()
|
.min(1, { message: '请输入手机号' })
|
||||||
.refine(
|
.refine((value) => /^1[3-9]\d{9}$/.test(value), {
|
||||||
(value) => {
|
message: '请输入正确的手机号格式',
|
||||||
if (!value) return true;
|
}),
|
||||||
return /^1[3-9]\d{9}$/.test(value);
|
|
||||||
},
|
|
||||||
{ message: '请输入正确的手机号格式' },
|
|
||||||
),
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
component: 'VbenInputPassword',
|
component: 'VbenInputPassword',
|
||||||
@@ -102,15 +98,7 @@ const formSchema = computed((): VbenFormSchema[] => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
function handleSubmit(value: Recordable<any>) {
|
function handleSubmit(value: Recordable<any>) {
|
||||||
// 验证至少填写一个登录方式
|
const { confirmPassword: _, agreePolicy: __, ...registerData } = value;
|
||||||
if (!value.loginCode && !value.phone) {
|
|
||||||
// 这里可以添加错误提示
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 移除不需要的字段
|
|
||||||
const { ...registerData } = value;
|
|
||||||
|
|
||||||
authStore.authRegister(registerData);
|
authStore.authRegister(registerData);
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ const accountFormModalRef = ref();
|
|||||||
|
|
||||||
// 搜索表单
|
// 搜索表单
|
||||||
const searchForm = ref({
|
const searchForm = ref({
|
||||||
loginCode: undefined as string | undefined,
|
username: undefined as string | undefined,
|
||||||
realName: undefined as string | undefined,
|
realName: undefined as string | undefined,
|
||||||
phone: undefined as string | undefined,
|
phone: undefined as string | undefined,
|
||||||
companyId: undefined as number | undefined,
|
companyId: undefined as number | undefined,
|
||||||
@@ -68,11 +68,11 @@ const gridReloadRef = ref<(() => void) | null>(null);
|
|||||||
const formOptions = computed(() => ({
|
const formOptions = computed(() => ({
|
||||||
schemas: [
|
schemas: [
|
||||||
{
|
{
|
||||||
fieldName: 'loginCode',
|
fieldName: 'username',
|
||||||
label: '登录账号',
|
label: '登录用户名',
|
||||||
component: 'Input',
|
component: 'Input',
|
||||||
componentProps: {
|
componentProps: {
|
||||||
placeholder: '请输入登录账号(回车搜索)',
|
placeholder: '请输入登录用户名(回车搜索)',
|
||||||
onPressEnter: () => gridReloadRef.value?.(),
|
onPressEnter: () => gridReloadRef.value?.(),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@@ -127,8 +127,8 @@ const accountTableBaseColumns: VxeGridProps<any>['columns'] = [
|
|||||||
title: '序号',
|
title: '序号',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
field: 'loginCode',
|
field: 'username',
|
||||||
title: '登录账号',
|
title: '登录用户名',
|
||||||
minWidth: 120,
|
minWidth: 120,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ const presetCompany = ref<CompanyVO.CompanyInfoVO | null>(null);
|
|||||||
const formData = ref<
|
const formData = ref<
|
||||||
SuperAccountDTO.SuperCreateAccountDTO & { status?: number }
|
SuperAccountDTO.SuperCreateAccountDTO & { status?: number }
|
||||||
>({
|
>({
|
||||||
loginCode: '',
|
username: '',
|
||||||
password: '',
|
password: '',
|
||||||
realName: '',
|
realName: '',
|
||||||
phone: '',
|
phone: '',
|
||||||
@@ -66,7 +66,7 @@ const statusOptions = [
|
|||||||
|
|
||||||
function resetForm() {
|
function resetForm() {
|
||||||
formData.value = {
|
formData.value = {
|
||||||
loginCode: '',
|
username: '',
|
||||||
password: '',
|
password: '',
|
||||||
realName: '',
|
realName: '',
|
||||||
phone: '',
|
phone: '',
|
||||||
@@ -97,7 +97,7 @@ function open(
|
|||||||
|
|
||||||
if (accountData) {
|
if (accountData) {
|
||||||
formData.value = {
|
formData.value = {
|
||||||
loginCode: accountData.loginCode,
|
username: accountData.username,
|
||||||
password: '',
|
password: '',
|
||||||
realName: accountData.realName,
|
realName: accountData.realName,
|
||||||
phone: accountData.phone || '',
|
phone: accountData.phone || '',
|
||||||
@@ -170,20 +170,20 @@ defineExpose({
|
|||||||
</Form.Item>
|
</Form.Item>
|
||||||
|
|
||||||
<Form.Item
|
<Form.Item
|
||||||
label="登录账号"
|
label="登录用户名"
|
||||||
name="loginCode"
|
name="username"
|
||||||
:rules="[
|
:rules="[
|
||||||
{ required: true, message: '请输入登录账号' },
|
{ min: 3, max: 20, message: '登录用户名长度为3-20个字符' },
|
||||||
{ min: 3, max: 20, message: '登录账号长度为3-20个字符' },
|
|
||||||
{
|
{
|
||||||
pattern: /^[a-zA-Z0-9_]+$/,
|
pattern: /^$|^[a-zA-Z0-9_]+$/,
|
||||||
message: '登录账号只能包含字母、数字和下划线',
|
message: '登录用户名只能包含字母、数字和下划线',
|
||||||
},
|
},
|
||||||
]"
|
]"
|
||||||
>
|
>
|
||||||
<Input
|
<Input
|
||||||
v-model:value="formData.loginCode"
|
v-model:value="formData.username"
|
||||||
placeholder="请输入登录账号"
|
placeholder="可选,留空由用户自行设置"
|
||||||
|
allow-clear
|
||||||
/>
|
/>
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
|
|
||||||
@@ -218,7 +218,10 @@ defineExpose({
|
|||||||
<Form.Item
|
<Form.Item
|
||||||
label="手机号"
|
label="手机号"
|
||||||
name="phone"
|
name="phone"
|
||||||
:rules="[{ pattern: /^1[3-9]\d{9}$/, message: '请输入有效的手机号' }]"
|
:rules="[
|
||||||
|
{ required: true, message: '请输入手机号' },
|
||||||
|
{ pattern: /^1[3-9]\d{9}$/, message: '请输入有效的手机号' },
|
||||||
|
]"
|
||||||
>
|
>
|
||||||
<Input v-model:value="formData.phone" placeholder="请输入手机号" />
|
<Input v-model:value="formData.phone" placeholder="请输入手机号" />
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
|
|||||||
@@ -69,7 +69,7 @@ const companyPagination = ref({
|
|||||||
const currentCompany = ref<CompanyVO.CompanyInfoVO | null>(null);
|
const currentCompany = ref<CompanyVO.CompanyInfoVO | null>(null);
|
||||||
|
|
||||||
const searchForm = ref({
|
const searchForm = ref({
|
||||||
loginCode: undefined as string | undefined,
|
username: undefined as string | undefined,
|
||||||
realName: undefined as string | undefined,
|
realName: undefined as string | undefined,
|
||||||
phone: undefined as string | undefined,
|
phone: undefined as string | undefined,
|
||||||
status: undefined as number | undefined,
|
status: undefined as number | undefined,
|
||||||
@@ -98,8 +98,8 @@ const accountTableBaseColumns: VxeGridProps<SuperAccountVO.AccountInfoVO>['colum
|
|||||||
[
|
[
|
||||||
{ type: 'seq' as const, minWidth: 56, title: '序号' },
|
{ type: 'seq' as const, minWidth: 56, title: '序号' },
|
||||||
{
|
{
|
||||||
field: 'loginCode',
|
field: 'username',
|
||||||
title: '登录账号',
|
title: '登录用户名',
|
||||||
minWidth: 120,
|
minWidth: 120,
|
||||||
showOverflow: 'tooltip' as const,
|
showOverflow: 'tooltip' as const,
|
||||||
},
|
},
|
||||||
@@ -214,7 +214,7 @@ const gridOptions: VxeGridProps<SuperAccountVO.AccountInfoVO> = {
|
|||||||
page: page.currentPage,
|
page: page.currentPage,
|
||||||
pageSize: page.pageSize,
|
pageSize: page.pageSize,
|
||||||
filters: {
|
filters: {
|
||||||
loginCode: searchForm.value.loginCode || undefined,
|
username: searchForm.value.username || undefined,
|
||||||
realName: searchForm.value.realName || undefined,
|
realName: searchForm.value.realName || undefined,
|
||||||
phone: searchForm.value.phone || undefined,
|
phone: searchForm.value.phone || undefined,
|
||||||
status: searchForm.value.status,
|
status: searchForm.value.status,
|
||||||
@@ -502,9 +502,9 @@ onMounted(() => {
|
|||||||
<template #extra>
|
<template #extra>
|
||||||
<Space wrap size="small" class="max-w-[min(100%,42rem)]">
|
<Space wrap size="small" class="max-w-[min(100%,42rem)]">
|
||||||
<Input
|
<Input
|
||||||
v-model:value="searchForm.loginCode"
|
v-model:value="searchForm.username"
|
||||||
allow-clear
|
allow-clear
|
||||||
placeholder="登录账号"
|
placeholder="登录用户名"
|
||||||
class="w-[120px]"
|
class="w-[120px]"
|
||||||
@press-enter="refreshTable"
|
@press-enter="refreshTable"
|
||||||
/>
|
/>
|
||||||
|
|||||||
@@ -141,8 +141,8 @@ async function loadAccounts() {
|
|||||||
(a: AccountVO.AccountInfoVO) => ({
|
(a: AccountVO.AccountInfoVO) => ({
|
||||||
value: a.id,
|
value: a.id,
|
||||||
label: a.realName
|
label: a.realName
|
||||||
? `${a.realName}${a.loginCode ? `(${a.loginCode})` : ''}`
|
? `${a.realName}${a.username ? `(${a.username})` : ''}`
|
||||||
: a.loginCode || `用户#${a.id}`,
|
: a.username || `用户#${a.id}`,
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
} catch {
|
} catch {
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ const avatarSrc = computed(() => {
|
|||||||
|
|
||||||
// 表单数据(与更新接口 DTO 一致,头像 ID 用 undefined 表示未变更/未上传)
|
// 表单数据(与更新接口 DTO 一致,头像 ID 用 undefined 表示未变更/未上传)
|
||||||
const formData = reactive<UserDTO.UpdateUserInfoDTO>({
|
const formData = reactive<UserDTO.UpdateUserInfoDTO>({
|
||||||
loginCode: '',
|
username: '',
|
||||||
realName: '',
|
realName: '',
|
||||||
phone: '',
|
phone: '',
|
||||||
remark: '',
|
remark: '',
|
||||||
@@ -50,7 +50,7 @@ async function fetchUserInfo() {
|
|||||||
loading.value = true;
|
loading.value = true;
|
||||||
const data = await getUserInfoApi();
|
const data = await getUserInfoApi();
|
||||||
userInfo.value = data;
|
userInfo.value = data;
|
||||||
formData.loginCode = data.loginCode || '';
|
formData.username = data.username || '';
|
||||||
formData.realName = data.realName || '';
|
formData.realName = data.realName || '';
|
||||||
formData.phone = data.phone || '';
|
formData.phone = data.phone || '';
|
||||||
formData.remark = data.remark || '';
|
formData.remark = data.remark || '';
|
||||||
@@ -118,7 +118,7 @@ async function handleSubmit() {
|
|||||||
|
|
||||||
function handleReset() {
|
function handleReset() {
|
||||||
if (userInfo.value) {
|
if (userInfo.value) {
|
||||||
formData.loginCode = userInfo.value.loginCode || '';
|
formData.username = userInfo.value.username || '';
|
||||||
formData.realName = userInfo.value.realName || '';
|
formData.realName = userInfo.value.realName || '';
|
||||||
formData.phone = userInfo.value.phone || '';
|
formData.phone = userInfo.value.phone || '';
|
||||||
formData.remark = userInfo.value.remark || '';
|
formData.remark = userInfo.value.remark || '';
|
||||||
@@ -210,13 +210,23 @@ fetchUserInfo();
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- 用户名 -->
|
<!-- 登录用户名(可选,用于账号登录) -->
|
||||||
<Form.Item
|
<Form.Item
|
||||||
label="用户名"
|
label="登录用户名"
|
||||||
name="loginCode"
|
name="username"
|
||||||
:rules="[{ required: true, message: '请输入用户名' }]"
|
:rules="[
|
||||||
|
{ min: 3, max: 20, message: '登录用户名长度为3-20个字符' },
|
||||||
|
{
|
||||||
|
pattern: /^$|^[a-zA-Z0-9_]+$/,
|
||||||
|
message: '登录用户名只能包含字母、数字和下划线',
|
||||||
|
},
|
||||||
|
]"
|
||||||
>
|
>
|
||||||
<Input v-model:value="formData.loginCode" placeholder="请输入用户名" />
|
<Input
|
||||||
|
v-model:value="formData.username"
|
||||||
|
placeholder="可选,设置后可用账号登录"
|
||||||
|
allow-clear
|
||||||
|
/>
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
|
|
||||||
<!-- 真实姓名 -->
|
<!-- 真实姓名 -->
|
||||||
@@ -229,7 +239,14 @@ fetchUserInfo();
|
|||||||
</Form.Item>
|
</Form.Item>
|
||||||
|
|
||||||
<!-- 手机号 -->
|
<!-- 手机号 -->
|
||||||
<Form.Item label="手机号" name="phone">
|
<Form.Item
|
||||||
|
label="手机号"
|
||||||
|
name="phone"
|
||||||
|
:rules="[
|
||||||
|
{ required: true, message: '请输入手机号' },
|
||||||
|
{ pattern: /^1[3-9]\d{9}$/, message: '请输入有效的手机号' },
|
||||||
|
]"
|
||||||
|
>
|
||||||
<Input
|
<Input
|
||||||
v-model:value="formData.phone"
|
v-model:value="formData.phone"
|
||||||
placeholder="请输入手机号"
|
placeholder="请输入手机号"
|
||||||
|
|||||||
@@ -22,13 +22,13 @@ interface UserInfo extends Omit<BasicUserInfo, 'userId' | 'username'> {
|
|||||||
*/
|
*/
|
||||||
positionId?: number;
|
positionId?: number;
|
||||||
/**
|
/**
|
||||||
* 登录账号
|
* 登录用户名(可空)
|
||||||
*/
|
*/
|
||||||
loginCode: string;
|
username?: string | null;
|
||||||
/**
|
/**
|
||||||
* 手机号码
|
* 手机号码
|
||||||
*/
|
*/
|
||||||
phone?: string;
|
phone: string;
|
||||||
/**
|
/**
|
||||||
* 用户名称
|
* 用户名称
|
||||||
*/
|
*/
|
||||||
@@ -101,10 +101,6 @@ interface UserInfo extends Omit<BasicUserInfo, 'userId' | 'username'> {
|
|||||||
* 用户id(兼容性字段)
|
* 用户id(兼容性字段)
|
||||||
*/
|
*/
|
||||||
userId?: string;
|
userId?: string;
|
||||||
/**
|
|
||||||
* 用户名(兼容性字段)
|
|
||||||
*/
|
|
||||||
username?: string;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export type { UserInfo };
|
export type { UserInfo };
|
||||||
|
|||||||
Reference in New Issue
Block a user