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

@@ -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;