feat: 集成WebSocket到NoticeService
This commit is contained in:
+59
@@ -0,0 +1,59 @@
|
|||||||
|
package cn.novalon.manage.sys.core.service.impl;
|
||||||
|
|
||||||
|
import cn.novalon.manage.sys.core.domain.SysNotice;
|
||||||
|
import cn.novalon.manage.sys.core.service.ISysNoticeService;
|
||||||
|
import cn.novalon.manage.sys.core.service.IWebSocketService;
|
||||||
|
import cn.novalon.manage.sys.infrastructure.db.converter.SysNoticeConverter;
|
||||||
|
import cn.novalon.manage.sys.infrastructure.db.dao.SysNoticeDao;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import reactor.core.publisher.Flux;
|
||||||
|
import reactor.core.publisher.Mono;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class SysNoticeService implements ISysNoticeService {
|
||||||
|
|
||||||
|
private final SysNoticeDao dao;
|
||||||
|
private final SysNoticeConverter converter;
|
||||||
|
private final IWebSocketService webSocketService;
|
||||||
|
|
||||||
|
public SysNoticeService(SysNoticeDao dao, SysNoticeConverter converter, IWebSocketService webSocketService) {
|
||||||
|
this.dao = dao;
|
||||||
|
this.converter = converter;
|
||||||
|
this.webSocketService = webSocketService;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Flux<SysNotice> findAll() {
|
||||||
|
return dao.findByDeletedAtIsNull()
|
||||||
|
.map(converter::toDomain);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Flux<SysNotice> findByStatus(String status) {
|
||||||
|
return dao.findByStatusAndDeletedAtIsNull(status)
|
||||||
|
.map(converter::toDomain);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Mono<SysNotice> findById(Long id) {
|
||||||
|
return dao.findById(id)
|
||||||
|
.map(converter::toDomain);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Mono<SysNotice> save(SysNotice notice) {
|
||||||
|
return dao.save(converter.toEntity(notice))
|
||||||
|
.map(converter::toDomain)
|
||||||
|
.flatMap(savedNotice -> {
|
||||||
|
return webSocketService.notifyNewNotice(
|
||||||
|
savedNotice.getNoticeTitle(),
|
||||||
|
savedNotice.getNoticeContent()
|
||||||
|
).thenReturn(savedNotice);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Mono<Void> deleteById(Long id) {
|
||||||
|
return dao.deleteByIdAndDeletedAtIsNull(id);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user