fix(config): update database credentials in application-dev.yml
This commit is contained in:
@@ -1,55 +0,0 @@
|
||||
package com.youlai.boot.system.controller;
|
||||
|
||||
import com.youlai.boot.core.web.Result;
|
||||
import com.youlai.boot.system.service.UserOnlineService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 在线用户控制器
|
||||
*
|
||||
* @author You Lai
|
||||
* @since 3.0.0
|
||||
*/
|
||||
@Tag(name = "13.在线用户接口")
|
||||
@RestController
|
||||
@RequestMapping("/api/v1/users/online")
|
||||
@RequiredArgsConstructor
|
||||
public class UserOnlineController {
|
||||
|
||||
private final UserOnlineService userOnlineService;
|
||||
|
||||
/**
|
||||
* 获取在线用户列表
|
||||
*
|
||||
* @return 在线用户列表
|
||||
*/
|
||||
@Operation(summary = "获取在线用户列表")
|
||||
@GetMapping
|
||||
@PreAuthorize("@ss.hasPerm('sys:monitor:online')")
|
||||
public Result<List<UserOnlineService.UserOnlineDTO>> getOnlineUsers() {
|
||||
return Result.success(userOnlineService.getOnlineUsers());
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取在线用户统计信息
|
||||
*
|
||||
* @return 在线用户统计
|
||||
*/
|
||||
@Operation(summary = "获取在线用户统计")
|
||||
@GetMapping("/stats")
|
||||
@PreAuthorize("@ss.hasPerm('sys:monitor:online')")
|
||||
public Result<Map<String, Object>> getOnlineStats() {
|
||||
return Result.success(Map.of(
|
||||
"count", userOnlineService.getOnlineUserCount()
|
||||
));
|
||||
}
|
||||
}
|
||||
@@ -1,83 +0,0 @@
|
||||
package com.youlai.boot.system.controller;
|
||||
|
||||
import com.youlai.boot.core.security.model.SysUserDetails;
|
||||
import com.youlai.boot.system.service.WebSocketMessageService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.messaging.handler.annotation.MessageMapping;
|
||||
import org.springframework.messaging.handler.annotation.Payload;
|
||||
import org.springframework.messaging.simp.SimpMessageHeaderAccessor;
|
||||
import org.springframework.security.core.Authentication;
|
||||
import org.springframework.stereotype.Controller;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* WebSocket消息控制器
|
||||
* 用于处理WebSocket客户端发送的消息
|
||||
*
|
||||
* @author You Lai
|
||||
* @since 3.0.0
|
||||
*/
|
||||
@Controller
|
||||
@RequiredArgsConstructor
|
||||
@Slf4j
|
||||
public class WebSocketMessageController {
|
||||
|
||||
private final WebSocketMessageService webSocketMessageService;
|
||||
|
||||
/**
|
||||
* 处理发送到指定用户的消息
|
||||
* 客户端发送消息到 /app/sendToUser/{username}
|
||||
*
|
||||
* @param message 消息内容
|
||||
* @param headerAccessor 消息头访问器
|
||||
* @param username 接收消息的用户名
|
||||
*/
|
||||
@MessageMapping("/sendToUser/{username}")
|
||||
public void sendToUser(@Payload String message, SimpMessageHeaderAccessor headerAccessor, String username) {
|
||||
Authentication authentication = (Authentication) headerAccessor.getUser();
|
||||
if (authentication != null) {
|
||||
SysUserDetails userDetails = (SysUserDetails) authentication.getPrincipal();
|
||||
String sender = userDetails.getUsername();
|
||||
|
||||
// 构建消息
|
||||
Map<String, Object> messageData = Map.of(
|
||||
"sender", sender,
|
||||
"content", message,
|
||||
"timestamp", System.currentTimeMillis()
|
||||
);
|
||||
|
||||
// 发送点对点消息
|
||||
webSocketMessageService.sendPrivateMessage(username, messageData);
|
||||
log.info("用户[{}]向用户[{}]发送消息: {}", sender, username, message);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理广播消息
|
||||
* 客户端发送消息到 /app/broadcast
|
||||
*
|
||||
* @param message 消息内容
|
||||
* @param headerAccessor 消息头访问器
|
||||
*/
|
||||
@MessageMapping("/broadcast")
|
||||
public void broadcast(@Payload String message, SimpMessageHeaderAccessor headerAccessor) {
|
||||
Authentication authentication = (Authentication) headerAccessor.getUser();
|
||||
if (authentication != null) {
|
||||
SysUserDetails userDetails = (SysUserDetails) authentication.getPrincipal();
|
||||
String sender = userDetails.getUsername();
|
||||
|
||||
// 构建消息
|
||||
Map<String, Object> messageData = Map.of(
|
||||
"sender", sender,
|
||||
"content", message,
|
||||
"timestamp", System.currentTimeMillis()
|
||||
);
|
||||
|
||||
// 发送广播消息
|
||||
webSocketMessageService.broadcastMessage(messageData);
|
||||
log.info("用户[{}]发送广播消息: {}", sender, message);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,54 +0,0 @@
|
||||
package com.youlai.boot.system.controller;
|
||||
|
||||
import com.youlai.boot.common.result.Result;
|
||||
import com.youlai.boot.system.service.WebSocketMessageService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
/**
|
||||
* WebSocket测试控制器
|
||||
*
|
||||
* @author You Lai
|
||||
* @since 3.0.0
|
||||
*/
|
||||
@Tag(name = "12.WebSocket接口")
|
||||
@RestController
|
||||
@RequestMapping("/api/v1/websocket")
|
||||
@RequiredArgsConstructor
|
||||
public class WebSocketTestController {
|
||||
|
||||
private final WebSocketMessageService webSocketMessageService;
|
||||
|
||||
/**
|
||||
* 发送字典更新事件
|
||||
*
|
||||
* @param dictCode 字典编码
|
||||
* @return 操作结果
|
||||
*/
|
||||
@Operation(summary = "发送字典更新事件")
|
||||
@PostMapping("/dict/{dictCode}/updated")
|
||||
public Result<Void> sendDictUpdatedEvent(
|
||||
@Parameter(description = "字典编码") @PathVariable String dictCode
|
||||
) {
|
||||
webSocketMessageService.sendDictUpdatedEvent(dictCode);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送字典删除事件
|
||||
*
|
||||
* @param dictCode 字典编码
|
||||
* @return 操作结果
|
||||
*/
|
||||
@Operation(summary = "发送字典删除事件")
|
||||
@PostMapping("/dict/{dictCode}/deleted")
|
||||
public Result<Void> sendDictDeletedEvent(
|
||||
@Parameter(description = "字典编码") @PathVariable String dictCode
|
||||
) {
|
||||
webSocketMessageService.sendDictDeletedEvent(dictCode);
|
||||
return Result.success();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user