feat: add notify handlers and routes to manage-app
This commit is contained in:
+41
@@ -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<ServerResponse> 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<ServerResponse> 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<ServerResponse> 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();
|
||||
}
|
||||
}
|
||||
+20
@@ -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<SysNotice> getAllNotices();
|
||||
|
||||
Mono<SysNotice> getNoticeById(Long id);
|
||||
|
||||
Flux<SysNotice> getNoticesByStatus(String status);
|
||||
|
||||
Mono<SysNotice> createNotice(SysNotice notice);
|
||||
|
||||
Mono<SysNotice> updateNotice(Long id, SysNotice notice);
|
||||
|
||||
Mono<Void> deleteNotice(Long id);
|
||||
}
|
||||
+20
@@ -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<SysUserMessage> getMessagesByUser(Long userId);
|
||||
|
||||
Mono<Long> getUnreadCount(Long userId);
|
||||
|
||||
Flux<SysUserMessage> getUnreadMessages(Long userId);
|
||||
|
||||
Mono<SysUserMessage> createMessage(SysUserMessage message);
|
||||
|
||||
Mono<SysUserMessage> markAsRead(Long id);
|
||||
|
||||
Mono<Void> deleteMessage(Long id);
|
||||
}
|
||||
+64
@@ -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<SysNotice> getAllNotices() {
|
||||
return noticeRepository.findByDeletedAtIsNull();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Mono<SysNotice> getNoticeById(Long id) {
|
||||
return noticeRepository.findById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Flux<SysNotice> getNoticesByStatus(String status) {
|
||||
return noticeRepository.findByStatusAndDeletedAtIsNull(status);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Mono<SysNotice> createNotice(SysNotice notice) {
|
||||
notice.setCreatedAt(LocalDateTime.now());
|
||||
return noticeRepository.save(notice);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Mono<SysNotice> 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<Void> deleteNotice(Long id) {
|
||||
return noticeRepository.findById(id)
|
||||
.flatMap(notice -> {
|
||||
notice.setDeletedAt(LocalDateTime.now());
|
||||
return noticeRepository.save(notice);
|
||||
})
|
||||
.then();
|
||||
}
|
||||
}
|
||||
+56
@@ -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<SysUserMessage> getMessagesByUser(Long userId) {
|
||||
return messageRepository.findByUserIdOrderByCreateTimeDesc(userId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Mono<Long> getUnreadCount(Long userId) {
|
||||
return messageRepository.countByUserIdAndIsRead(userId, "0");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Flux<SysUserMessage> getUnreadMessages(Long userId) {
|
||||
return messageRepository.findByUserIdAndIsReadOrderByCreateTimeDesc(userId, "0");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Mono<SysUserMessage> createMessage(SysUserMessage message) {
|
||||
message.setCreateTime(LocalDateTime.now());
|
||||
message.setIsRead("0");
|
||||
return messageRepository.save(message);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Mono<SysUserMessage> markAsRead(Long id) {
|
||||
return messageRepository.findById(id)
|
||||
.flatMap(message -> {
|
||||
message.setIsRead("1");
|
||||
return messageRepository.save(message);
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public Mono<Void> deleteMessage(Long id) {
|
||||
return messageRepository.deleteById(id);
|
||||
}
|
||||
}
|
||||
+58
@@ -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<ServerResponse> getAllNotices(ServerRequest request) {
|
||||
Flux<SysNotice> notices = noticeService.getAllNotices();
|
||||
return ServerResponse.ok().body(notices, SysNotice.class);
|
||||
}
|
||||
|
||||
public Mono<ServerResponse> 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<ServerResponse> getNoticesByStatus(ServerRequest request) {
|
||||
String status = request.pathVariable("status");
|
||||
Flux<SysNotice> notices = noticeService.getNoticesByStatus(status);
|
||||
return ServerResponse.ok().body(notices, SysNotice.class);
|
||||
}
|
||||
|
||||
public Mono<ServerResponse> createNotice(ServerRequest request) {
|
||||
return request.bodyToMono(SysNotice.class)
|
||||
.flatMap(noticeService::createNotice)
|
||||
.flatMap(notice -> ServerResponse.ok().bodyValue(notice));
|
||||
}
|
||||
|
||||
public Mono<ServerResponse> 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<ServerResponse> deleteNotice(ServerRequest request) {
|
||||
Long id = Long.parseLong(request.pathVariable("id"));
|
||||
return noticeService.deleteNotice(id)
|
||||
.then(ServerResponse.ok().build())
|
||||
.switchIfEmpty(ServerResponse.notFound().build());
|
||||
}
|
||||
}
|
||||
+57
@@ -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<ServerResponse> getMessagesByUser(ServerRequest request) {
|
||||
Long userId = Long.parseLong(request.pathVariable("userId"));
|
||||
Flux<SysUserMessage> messages = messageService.getMessagesByUser(userId);
|
||||
return ServerResponse.ok().body(messages, SysUserMessage.class);
|
||||
}
|
||||
|
||||
public Mono<ServerResponse> getUnreadCount(ServerRequest request) {
|
||||
Long userId = Long.parseLong(request.pathVariable("userId"));
|
||||
return messageService.getUnreadCount(userId)
|
||||
.flatMap(count -> ServerResponse.ok().bodyValue(count));
|
||||
}
|
||||
|
||||
public Mono<ServerResponse> getUnreadList(ServerRequest request) {
|
||||
Long userId = Long.parseLong(request.pathVariable("userId"));
|
||||
Flux<SysUserMessage> messages = messageService.getUnreadMessages(userId);
|
||||
return ServerResponse.ok().body(messages, SysUserMessage.class);
|
||||
}
|
||||
|
||||
public Mono<ServerResponse> createMessage(ServerRequest request) {
|
||||
return request.bodyToMono(SysUserMessage.class)
|
||||
.flatMap(messageService::createMessage)
|
||||
.flatMap(message -> ServerResponse.ok().bodyValue(message));
|
||||
}
|
||||
|
||||
public Mono<ServerResponse> 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<ServerResponse> deleteMessage(ServerRequest request) {
|
||||
Long id = Long.parseLong(request.pathVariable("id"));
|
||||
return messageService.deleteMessage(id)
|
||||
.then(ServerResponse.ok().build())
|
||||
.switchIfEmpty(ServerResponse.notFound().build());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user