feat: 新增 WebSocket 消息通知 (#67)

This commit is contained in:
Claudio Lecher
2024-05-22 10:50:57 +08:00
committed by GitHub
parent af22df8adb
commit 9970c461cc
10 changed files with 665 additions and 0 deletions

View File

@@ -16,6 +16,7 @@
package top.continew.admin.webapi.system;
import cn.hutool.core.util.IdUtil;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.enums.ParameterIn;
@@ -23,8 +24,12 @@ import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import top.continew.admin.common.enums.MessageTypeEnum;
import top.continew.admin.common.util.NoticeMsgUtils;
import top.continew.admin.common.util.WsUtils;
import top.continew.admin.common.util.helper.LoginHelper;
import top.continew.admin.system.model.query.MessageQuery;
import top.continew.admin.system.model.req.MessageReq;
import top.continew.admin.system.model.resp.MessageResp;
import top.continew.admin.system.model.resp.MessageUnreadResp;
import top.continew.admin.system.service.MessageService;
@@ -34,6 +39,7 @@ import top.continew.starter.extension.crud.model.resp.PageResp;
import top.continew.starter.web.model.R;
import top.continew.starter.log.core.annotation.Log;
import java.util.ArrayList;
import java.util.List;
/**
@@ -81,4 +87,17 @@ public class MessageController {
public R<MessageUnreadResp> countUnreadMessage(@RequestParam(required = false) Boolean detail) {
return R.ok(messageUserService.countUnreadMessageByUserId(LoginHelper.getUserId(), detail));
}
@GetMapping("/testSend")
public R<Object> testSend(String msg) {
List<Long> userIdList = new ArrayList<>();
userIdList.add(LoginHelper.getUserId());
MessageReq req = new MessageReq();
req.setTitle(msg);
req.setContent(msg);
req.setType(MessageTypeEnum.SYSTEM);
baseService.add(req, userIdList);
WsUtils.sendToUser(LoginHelper.getUserId().toString(), NoticeMsgUtils.conversion(msg, IdUtil.fastSimpleUUID()));
return R.ok();
}
}