From 6453c8c6fb664f895a7a3b6030dfc08d6dfd72dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E7=BF=94?= Date: Sat, 14 Mar 2026 11:40:34 +0800 Subject: [PATCH] feat: add notify handlers and routes to manage-app --- .../manage/app/config/SystemRouter.java | 41 ++++++++++++ .../core/service/ISysNoticeService.java | 20 ++++++ .../core/service/ISysUserMessageService.java | 20 ++++++ .../service/impl/SysNoticeServiceImpl.java | 64 +++++++++++++++++++ .../impl/SysUserMessageServiceImpl.java | 56 ++++++++++++++++ .../notify/handler/SysNoticeHandler.java | 58 +++++++++++++++++ .../notify/handler/SysUserMessageHandler.java | 57 +++++++++++++++++ 7 files changed, 316 insertions(+) create mode 100644 novalon-manage-api/manage-notify/src/main/java/cn/novalon/manage/notify/core/service/ISysNoticeService.java create mode 100644 novalon-manage-api/manage-notify/src/main/java/cn/novalon/manage/notify/core/service/ISysUserMessageService.java create mode 100644 novalon-manage-api/manage-notify/src/main/java/cn/novalon/manage/notify/core/service/impl/SysNoticeServiceImpl.java create mode 100644 novalon-manage-api/manage-notify/src/main/java/cn/novalon/manage/notify/core/service/impl/SysUserMessageServiceImpl.java create mode 100644 novalon-manage-api/manage-notify/src/main/java/cn/novalon/manage/notify/handler/SysNoticeHandler.java create mode 100644 novalon-manage-api/manage-notify/src/main/java/cn/novalon/manage/notify/handler/SysUserMessageHandler.java diff --git a/novalon-manage-api/manage-app/src/main/java/cn/novalon/manage/app/config/SystemRouter.java b/novalon-manage-api/manage-app/src/main/java/cn/novalon/manage/app/config/SystemRouter.java index 2b8ebfc..77b3468 100644 --- a/novalon-manage-api/manage-app/src/main/java/cn/novalon/manage/app/config/SystemRouter.java +++ b/novalon-manage-api/manage-app/src/main/java/cn/novalon/manage/app/config/SystemRouter.java @@ -9,6 +9,9 @@ import cn.novalon.manage.sys.handler.menu.MenuHandler; import cn.novalon.manage.sys.handler.role.SysRoleHandler; import cn.novalon.manage.sys.handler.stats.StatsHandler; import cn.novalon.manage.sys.handler.user.SysUserHandler; +import cn.novalon.manage.notify.handler.SysNoticeHandler; +import cn.novalon.manage.notify.handler.SysUserMessageHandler; +import cn.novalon.manage.file.handler.SysFileHandler; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.web.reactive.function.server.RouterFunction; @@ -152,4 +155,42 @@ public class SystemRouter { .DELETE("/api/dict/data/{id}", dictHandler::deleteDictData) .build(); } + + @Bean + public RouterFunction noticeRoutes(SysNoticeHandler noticeHandler) { + return route() + .GET("/api/notices", noticeHandler::getAllNotices) + .GET("/api/notices/{id}", noticeHandler::getNoticeById) + .GET("/api/notices/status/{status}", noticeHandler::getNoticesByStatus) + .POST("/api/notices", noticeHandler::createNotice) + .PUT("/api/notices/{id}", noticeHandler::updateNotice) + .DELETE("/api/notices/{id}", noticeHandler::deleteNotice) + .build(); + } + + @Bean + public RouterFunction messageRoutes(SysUserMessageHandler messageHandler) { + return route() + .GET("/api/messages/user/{userId}", messageHandler::getMessagesByUser) + .GET("/api/messages/user/{userId}/unread", messageHandler::getUnreadCount) + .GET("/api/messages/user/{userId}/unread/list", messageHandler::getUnreadList) + .POST("/api/messages", messageHandler::createMessage) + .PUT("/api/messages/{id}/read", messageHandler::markAsRead) + .DELETE("/api/messages/{id}", messageHandler::deleteMessage) + .build(); + } + + @Bean + public RouterFunction fileRoutes(SysFileHandler fileHandler) { + return route() + .GET("/api/files", fileHandler::getAllFiles) + .GET("/api/files/{id}", fileHandler::getFileById) + .POST("/api/files/upload", fileHandler::uploadFile) + .GET("/api/files/{id}/download", fileHandler::downloadFile) + .GET("/api/files/download/{fileName}", fileHandler::downloadFileByName) + .GET("/api/files/{id}/preview", fileHandler::previewFile) + .GET("/api/files/preview/{fileName}", fileHandler::previewFileByName) + .DELETE("/api/files/{id}", fileHandler::deleteFile) + .build(); + } } \ No newline at end of file diff --git a/novalon-manage-api/manage-notify/src/main/java/cn/novalon/manage/notify/core/service/ISysNoticeService.java b/novalon-manage-api/manage-notify/src/main/java/cn/novalon/manage/notify/core/service/ISysNoticeService.java new file mode 100644 index 0000000..284575e --- /dev/null +++ b/novalon-manage-api/manage-notify/src/main/java/cn/novalon/manage/notify/core/service/ISysNoticeService.java @@ -0,0 +1,20 @@ +package cn.novalon.manage.notify.core.service; + +import cn.novalon.manage.notify.core.domain.SysNotice; +import reactor.core.publisher.Flux; +import reactor.core.publisher.Mono; + +public interface ISysNoticeService { + + Flux getAllNotices(); + + Mono getNoticeById(Long id); + + Flux getNoticesByStatus(String status); + + Mono createNotice(SysNotice notice); + + Mono updateNotice(Long id, SysNotice notice); + + Mono deleteNotice(Long id); +} \ No newline at end of file diff --git a/novalon-manage-api/manage-notify/src/main/java/cn/novalon/manage/notify/core/service/ISysUserMessageService.java b/novalon-manage-api/manage-notify/src/main/java/cn/novalon/manage/notify/core/service/ISysUserMessageService.java new file mode 100644 index 0000000..ca0cdf6 --- /dev/null +++ b/novalon-manage-api/manage-notify/src/main/java/cn/novalon/manage/notify/core/service/ISysUserMessageService.java @@ -0,0 +1,20 @@ +package cn.novalon.manage.notify.core.service; + +import cn.novalon.manage.notify.core.domain.SysUserMessage; +import reactor.core.publisher.Flux; +import reactor.core.publisher.Mono; + +public interface ISysUserMessageService { + + Flux getMessagesByUser(Long userId); + + Mono getUnreadCount(Long userId); + + Flux getUnreadMessages(Long userId); + + Mono createMessage(SysUserMessage message); + + Mono markAsRead(Long id); + + Mono deleteMessage(Long id); +} \ No newline at end of file diff --git a/novalon-manage-api/manage-notify/src/main/java/cn/novalon/manage/notify/core/service/impl/SysNoticeServiceImpl.java b/novalon-manage-api/manage-notify/src/main/java/cn/novalon/manage/notify/core/service/impl/SysNoticeServiceImpl.java new file mode 100644 index 0000000..2fca7e4 --- /dev/null +++ b/novalon-manage-api/manage-notify/src/main/java/cn/novalon/manage/notify/core/service/impl/SysNoticeServiceImpl.java @@ -0,0 +1,64 @@ +package cn.novalon.manage.notify.core.service.impl; + +import cn.novalon.manage.notify.core.domain.SysNotice; +import cn.novalon.manage.notify.core.repository.ISysNoticeRepository; +import cn.novalon.manage.notify.core.service.ISysNoticeService; +import org.springframework.stereotype.Service; +import reactor.core.publisher.Flux; +import reactor.core.publisher.Mono; + +import java.time.LocalDateTime; + +@Service +public class SysNoticeServiceImpl implements ISysNoticeService { + + private final ISysNoticeRepository noticeRepository; + + public SysNoticeServiceImpl(ISysNoticeRepository noticeRepository) { + this.noticeRepository = noticeRepository; + } + + @Override + public Flux getAllNotices() { + return noticeRepository.findByDeletedAtIsNull(); + } + + @Override + public Mono getNoticeById(Long id) { + return noticeRepository.findById(id); + } + + @Override + public Flux getNoticesByStatus(String status) { + return noticeRepository.findByStatusAndDeletedAtIsNull(status); + } + + @Override + public Mono createNotice(SysNotice notice) { + notice.setCreatedAt(LocalDateTime.now()); + return noticeRepository.save(notice); + } + + @Override + public Mono updateNotice(Long id, SysNotice notice) { + return noticeRepository.findById(id) + .flatMap(existingNotice -> { + existingNotice.setNoticeTitle(notice.getNoticeTitle()); + existingNotice.setNoticeContent(notice.getNoticeContent()); + existingNotice.setStatus(notice.getStatus()); + existingNotice.setNoticeType(notice.getNoticeType()); + existingNotice.setUpdatedAt(LocalDateTime.now()); + return noticeRepository.save(existingNotice); + }); + } + + @Override + public Mono deleteNotice(Long id) { + return noticeRepository.findById(id) + .flatMap(notice -> { + notice.setDeletedAt(LocalDateTime.now()); + return noticeRepository.save(notice); + }) + .then(); + } +} \ No newline at end of file diff --git a/novalon-manage-api/manage-notify/src/main/java/cn/novalon/manage/notify/core/service/impl/SysUserMessageServiceImpl.java b/novalon-manage-api/manage-notify/src/main/java/cn/novalon/manage/notify/core/service/impl/SysUserMessageServiceImpl.java new file mode 100644 index 0000000..8eb195b --- /dev/null +++ b/novalon-manage-api/manage-notify/src/main/java/cn/novalon/manage/notify/core/service/impl/SysUserMessageServiceImpl.java @@ -0,0 +1,56 @@ +package cn.novalon.manage.notify.core.service.impl; + +import cn.novalon.manage.notify.core.domain.SysUserMessage; +import cn.novalon.manage.notify.core.repository.ISysUserMessageRepository; +import cn.novalon.manage.notify.core.service.ISysUserMessageService; +import org.springframework.stereotype.Service; +import reactor.core.publisher.Flux; +import reactor.core.publisher.Mono; + +import java.time.LocalDateTime; + +@Service +public class SysUserMessageServiceImpl implements ISysUserMessageService { + + private final ISysUserMessageRepository messageRepository; + + public SysUserMessageServiceImpl(ISysUserMessageRepository messageRepository) { + this.messageRepository = messageRepository; + } + + @Override + public Flux getMessagesByUser(Long userId) { + return messageRepository.findByUserIdOrderByCreateTimeDesc(userId); + } + + @Override + public Mono getUnreadCount(Long userId) { + return messageRepository.countByUserIdAndIsRead(userId, "0"); + } + + @Override + public Flux getUnreadMessages(Long userId) { + return messageRepository.findByUserIdAndIsReadOrderByCreateTimeDesc(userId, "0"); + } + + @Override + public Mono createMessage(SysUserMessage message) { + message.setCreateTime(LocalDateTime.now()); + message.setIsRead("0"); + return messageRepository.save(message); + } + + @Override + public Mono markAsRead(Long id) { + return messageRepository.findById(id) + .flatMap(message -> { + message.setIsRead("1"); + return messageRepository.save(message); + }); + } + + @Override + public Mono deleteMessage(Long id) { + return messageRepository.deleteById(id); + } +} \ No newline at end of file diff --git a/novalon-manage-api/manage-notify/src/main/java/cn/novalon/manage/notify/handler/SysNoticeHandler.java b/novalon-manage-api/manage-notify/src/main/java/cn/novalon/manage/notify/handler/SysNoticeHandler.java new file mode 100644 index 0000000..8b3670c --- /dev/null +++ b/novalon-manage-api/manage-notify/src/main/java/cn/novalon/manage/notify/handler/SysNoticeHandler.java @@ -0,0 +1,58 @@ +package cn.novalon.manage.notify.handler; + +import cn.novalon.manage.notify.core.domain.SysNotice; +import cn.novalon.manage.notify.core.service.ISysNoticeService; +import org.springframework.stereotype.Component; +import org.springframework.web.reactive.function.server.ServerRequest; +import org.springframework.web.reactive.function.server.ServerResponse; +import reactor.core.publisher.Flux; +import reactor.core.publisher.Mono; + +@Component +public class SysNoticeHandler { + + private final ISysNoticeService noticeService; + + public SysNoticeHandler(ISysNoticeService noticeService) { + this.noticeService = noticeService; + } + + public Mono getAllNotices(ServerRequest request) { + Flux notices = noticeService.getAllNotices(); + return ServerResponse.ok().body(notices, SysNotice.class); + } + + public Mono getNoticeById(ServerRequest request) { + Long id = Long.parseLong(request.pathVariable("id")); + return noticeService.getNoticeById(id) + .flatMap(notice -> ServerResponse.ok().bodyValue(notice)) + .switchIfEmpty(ServerResponse.notFound().build()); + } + + public Mono getNoticesByStatus(ServerRequest request) { + String status = request.pathVariable("status"); + Flux notices = noticeService.getNoticesByStatus(status); + return ServerResponse.ok().body(notices, SysNotice.class); + } + + public Mono createNotice(ServerRequest request) { + return request.bodyToMono(SysNotice.class) + .flatMap(noticeService::createNotice) + .flatMap(notice -> ServerResponse.ok().bodyValue(notice)); + } + + public Mono updateNotice(ServerRequest request) { + Long id = Long.parseLong(request.pathVariable("id")); + return request.bodyToMono(SysNotice.class) + .flatMap(notice -> noticeService.updateNotice(id, notice)) + .flatMap(notice -> ServerResponse.ok().bodyValue(notice)) + .switchIfEmpty(ServerResponse.notFound().build()); + } + + public Mono deleteNotice(ServerRequest request) { + Long id = Long.parseLong(request.pathVariable("id")); + return noticeService.deleteNotice(id) + .then(ServerResponse.ok().build()) + .switchIfEmpty(ServerResponse.notFound().build()); + } +} \ No newline at end of file diff --git a/novalon-manage-api/manage-notify/src/main/java/cn/novalon/manage/notify/handler/SysUserMessageHandler.java b/novalon-manage-api/manage-notify/src/main/java/cn/novalon/manage/notify/handler/SysUserMessageHandler.java new file mode 100644 index 0000000..e06745d --- /dev/null +++ b/novalon-manage-api/manage-notify/src/main/java/cn/novalon/manage/notify/handler/SysUserMessageHandler.java @@ -0,0 +1,57 @@ +package cn.novalon.manage.notify.handler; + +import cn.novalon.manage.notify.core.domain.SysUserMessage; +import cn.novalon.manage.notify.core.service.ISysUserMessageService; +import org.springframework.stereotype.Component; +import org.springframework.web.reactive.function.server.ServerRequest; +import org.springframework.web.reactive.function.server.ServerResponse; +import reactor.core.publisher.Flux; +import reactor.core.publisher.Mono; + +@Component +public class SysUserMessageHandler { + + private final ISysUserMessageService messageService; + + public SysUserMessageHandler(ISysUserMessageService messageService) { + this.messageService = messageService; + } + + public Mono getMessagesByUser(ServerRequest request) { + Long userId = Long.parseLong(request.pathVariable("userId")); + Flux messages = messageService.getMessagesByUser(userId); + return ServerResponse.ok().body(messages, SysUserMessage.class); + } + + public Mono getUnreadCount(ServerRequest request) { + Long userId = Long.parseLong(request.pathVariable("userId")); + return messageService.getUnreadCount(userId) + .flatMap(count -> ServerResponse.ok().bodyValue(count)); + } + + public Mono getUnreadList(ServerRequest request) { + Long userId = Long.parseLong(request.pathVariable("userId")); + Flux messages = messageService.getUnreadMessages(userId); + return ServerResponse.ok().body(messages, SysUserMessage.class); + } + + public Mono createMessage(ServerRequest request) { + return request.bodyToMono(SysUserMessage.class) + .flatMap(messageService::createMessage) + .flatMap(message -> ServerResponse.ok().bodyValue(message)); + } + + public Mono markAsRead(ServerRequest request) { + Long id = Long.parseLong(request.pathVariable("id")); + return messageService.markAsRead(id) + .flatMap(message -> ServerResponse.ok().bodyValue(message)) + .switchIfEmpty(ServerResponse.notFound().build()); + } + + public Mono deleteMessage(ServerRequest request) { + Long id = Long.parseLong(request.pathVariable("id")); + return messageService.deleteMessage(id) + .then(ServerResponse.ok().build()) + .switchIfEmpty(ServerResponse.notFound().build()); + } +} \ No newline at end of file