refactor: 移除WebSocket功能并优化用户导入逻辑

移除WebSocket相关菜单和代码,优化用户导入时部门和角色的匹配逻辑,支持通过编码或名称匹配
This commit is contained in:
Ray.Hao
2026-02-25 09:12:18 +08:00
parent 3067a3672c
commit e794ffa03d
6 changed files with 23 additions and 97 deletions

View File

@@ -228,11 +228,10 @@ INSERT INTO `sys_menu` VALUES (708, 6, '0,6', '滚动文本', 'M', 'TextScroll',
INSERT INTO `sys_menu` VALUES (709, 6, '0,6', '自适应表格操作列', 'M', 'AutoOperationColumn', 'operation-column', 'demo/auto-operation-column', NULL, NULL, 1, 1, 1, '', '', now(), now(), NULL);
-- 功能演示
INSERT INTO `sys_menu` VALUES (801, 7, '0,7', 'Websocket', 'M', 'WebSocket', '/function/websocket', 'demo/websocket', NULL, NULL, 1, 1, 1, '', '', now(), now(), NULL);
INSERT INTO `sys_menu` VALUES (802, 7, '0,7', 'Icons', 'M', 'IconDemo', 'icon-demo', 'demo/icons', NULL, NULL, 1, 1, 2, 'el-icon-Notification', '', now(), now(), NULL);
INSERT INTO `sys_menu` VALUES (803, 7, '0,7', '字典实时同步', 'M', 'DictSync', 'dict-sync', 'demo/dict-sync', NULL, NULL, NULL, 1, 3, '', '', now(), now(), NULL);
INSERT INTO `sys_menu` VALUES (804, 7, '0,7', 'VxeTable', 'M', 'VxeTable', 'vxe-table', 'demo/vxe-table/index', NULL, NULL, 1, 1, 4, 'el-icon-MagicStick', '', now(), now(), NULL);
INSERT INTO `sys_menu` VALUES (805, 7, '0,7', 'CURD单文件', 'M', 'CurdSingle', 'curd-single', 'demo/curd-single', NULL, NULL, 1, 1, 5, 'el-icon-Reading', '', now(), now(), NULL);
INSERT INTO `sys_menu` VALUES (801, 7, '0,7', 'Icons', 'M', 'IconDemo', 'icon-demo', 'demo/icons', NULL, NULL, 1, 1, 2, 'el-icon-Notification', '', now(), now(), NULL);
INSERT INTO `sys_menu` VALUES (802, 7, '0,7', '字典实时同步', 'M', 'DictSync', 'dict-sync', 'demo/dict-sync', NULL, NULL, NULL, 1, 3, '', '', now(), now(), NULL);
INSERT INTO `sys_menu` VALUES (803, 7, '0,7', 'VxeTable', 'M', 'VxeTable', 'vxe-table', 'demo/vxe-table/index', NULL, NULL, 1, 1, 4, 'el-icon-MagicStick', '', now(), now(), NULL);
INSERT INTO `sys_menu` VALUES (804, 7, '0,7', 'CURD单文件', 'M', 'CurdSingle', 'curd-single', 'demo/curd-single', NULL, NULL, 1, 1, 5, 'el-icon-Reading', '', now(), now(), NULL);
-- 多级菜单示例
INSERT INTO `sys_menu` VALUES (910, 8, '0,8', '菜单一级', 'C', NULL, 'multi-level1', 'Layout', NULL, 1, NULL, 1, 1, '', '', now(), now(), NULL);
@@ -341,7 +340,7 @@ INSERT INTO `sys_role_menu` VALUES (2, 601);
-- 组件封装
INSERT INTO `sys_role_menu` VALUES (2, 701), (2, 702), (2, 703), (2, 704), (2, 705), (2, 706), (2, 707), (2, 708), (2, 709);
-- 功能演示 / 多级菜单
INSERT INTO `sys_role_menu` VALUES (2, 801), (2, 802), (2, 803), (2, 804), (2, 805), (2, 910), (2, 911), (2, 912), (2, 913);
INSERT INTO `sys_role_menu` VALUES (2, 801), (2, 802), (2, 803), (2, 804), (2, 910), (2, 911), (2, 912), (2, 913);
-- 路由参数
INSERT INTO `sys_role_menu` VALUES (2, 1001), (2, 1002);

View File

@@ -1,65 +0,0 @@
package com.youlai.boot.platform.websocket.controller;
import com.youlai.boot.platform.websocket.dto.TextMessage;
import com.youlai.boot.platform.websocket.publisher.WebSocketPublisher;
import com.youlai.boot.platform.websocket.topic.WebSocketTopics;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.messaging.handler.annotation.DestinationVariable;
import org.springframework.messaging.handler.annotation.MessageMapping;
import org.springframework.messaging.handler.annotation.SendTo;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.security.Principal;
/**
* WebSocket 测试用例控制层
* <p>
* 包含点对点/广播发送消息
*
* @author Ray.Hao
* @since 2.3.0
*/
@RestController
@RequestMapping("/api/v1/websocket")
@RequiredArgsConstructor
@Slf4j
public class WebsocketController {
private final WebSocketPublisher webSocketPublisher;
/**
* 广播发送消息
*
* @param message 消息内容
*/
@MessageMapping("/sendToAll")
@SendTo("/topic/notice")
public String sendToAll(String message) {
return "服务端通知: " + message;
}
/**
* 点对点发送消息
* <p>
* 模拟 张三 给 李四 发送消息场景
*
* @param principal 当前用户
* @param username 接收消息的用户
* @param message 消息内容
*/
@MessageMapping("/sendToUser/{username}")
public void sendToUser(Principal principal, @DestinationVariable String username, String message) {
// 发送人
String sender = principal.getName();
// 接收人
String receiver = username;
log.info("发送人:{}; 接收人:{}", sender, receiver);
// 发送消息给指定用户,拼接后路径 /user/{receiver}/queue/greeting
webSocketPublisher.publishToUser(receiver, WebSocketTopics.USER_QUEUE_GREETING, new TextMessage(sender, message, System.currentTimeMillis()));
}
}

View File

@@ -1,15 +0,0 @@
package com.youlai.boot.platform.websocket.dto;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
@Data
@AllArgsConstructor
@NoArgsConstructor
public class TextMessage {
private String sender;
private String content;
private Long timestamp;
}

View File

@@ -2,7 +2,6 @@ package com.youlai.boot.platform.websocket.service.impl;
import com.youlai.boot.platform.websocket.dto.DictChangeEvent;
import com.youlai.boot.platform.websocket.dto.OnlineUserDTO;
import com.youlai.boot.platform.websocket.dto.TextMessage;
import com.youlai.boot.platform.websocket.publisher.WebSocketPublisher;
import com.youlai.boot.platform.websocket.session.UserSessionRegistry;
import com.youlai.boot.platform.websocket.service.WebSocketService;
@@ -11,6 +10,7 @@ import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.Map;
/**
* WebSocket 服务实现类
@@ -215,7 +215,11 @@ public class WebSocketServiceImpl implements WebSocketService {
return;
}
TextMessage systemMessage = new TextMessage("系统通知", message, System.currentTimeMillis());
Map<String, Object> systemMessage = Map.of(
"sender", "系统通知",
"content", message,
"timestamp", System.currentTimeMillis()
);
webSocketPublisher.publish(WebSocketTopics.TOPIC_PUBLIC, systemMessage);
log.info("✓ 已广播系统消息: {}", message);
}

View File

@@ -11,5 +11,4 @@ public final class WebSocketTopics {
public static final String USER_QUEUE_MESSAGES = "/queue/messages";
public static final String USER_QUEUE_MESSAGE = "/queue/message";
public static final String USER_QUEUE_GREETING = "/queue/greeting";
}

View File

@@ -68,9 +68,9 @@ public class UserImportListener extends AnalysisEventListener<UserImportDTO> {
this.userConverter = SpringUtil.getBean(UserConverter.class);
this.roleList = SpringUtil.getBean(RoleService.class)
.list(new LambdaQueryWrapper<Role>().eq(Role::getStatus, StatusEnum.ENABLE.getValue())
.select(Role::getId, Role::getCode));
.select(Role::getId, Role::getCode, Role::getName));
this.deptList = SpringUtil.getBean(DeptService.class)
.list(new LambdaQueryWrapper<Dept>().select(Dept::getId, Dept::getCode));
.list(new LambdaQueryWrapper<Dept>().select(Dept::getId, Dept::getCode, Dept::getName));
this.genderList = SpringUtil.getBean(DictItemService.class)
.list(new LambdaQueryWrapper<DictItem>().eq(DictItem::getDictCode, DictCodeEnum.GENDER.getValue()));
this.excelResult = new ExcelResult();
@@ -157,9 +157,9 @@ public class UserImportListener extends AnalysisEventListener<UserImportDTO> {
/**
* 根据角色编码获取角色ID
* 根据角色编码或名称获取角色ID
*
* @param roleCodes 角色编码 逗号分隔
* @param roleCodes 角色编码或名称,逗号分隔
* @return 角色ID集合
*/
private List<Long> getRoleIds(String roleCodes) {
@@ -168,7 +168,9 @@ public class UserImportListener extends AnalysisEventListener<UserImportDTO> {
if (split.length > 0) {
List<Long> roleIds = new ArrayList<>();
for (String roleCode : split) {
this.roleList.stream().filter(r -> r.getCode().equals(roleCode))
String trimmed = roleCode.trim();
this.roleList.stream()
.filter(r -> r.getCode().equals(trimmed) || r.getName().equals(trimmed))
.findFirst().ifPresent(role -> roleIds.add(role.getId()));
}
return roleIds.stream().distinct().toList();
@@ -178,14 +180,16 @@ public class UserImportListener extends AnalysisEventListener<UserImportDTO> {
}
/**
* 根据部门编码获取部门ID
* 根据部门编码或名称获取部门ID
*
* @param deptCode 部门编码
* @param deptCode 部门编码或名称
* @return 部门ID
*/
private Long getDeptId(String deptCode) {
if (StrUtil.isNotBlank(deptCode)) {
return this.deptList.stream().filter(r -> r.getCode().equals(deptCode))
String trimmed = deptCode.trim();
return this.deptList.stream()
.filter(r -> r.getCode().equals(trimmed) || r.getName().equals(trimmed))
.findFirst().map(Dept::getId).orElse(null);
}
return null;