feat: 添加SysNoticeRepository数据访问层~

This commit is contained in:
张翔
2026-03-12 07:39:19 +08:00
parent 38fe0079d5
commit 684a8a8699
2 changed files with 93 additions and 0 deletions
@@ -1,6 +1,7 @@
package cn.novalon.manage.sys.infrastructure.db.dao;
import cn.novalon.manage.sys.infrastructure.db.entity.SysNoticeEntity;
import org.springframework.data.domain.Sort;
import org.springframework.data.r2dbc.repository.R2dbcRepository;
import org.springframework.stereotype.Repository;
import reactor.core.publisher.Flux;
@@ -11,7 +12,13 @@ public interface SysNoticeDao extends R2dbcRepository<SysNoticeEntity, Long> {
Flux<SysNoticeEntity> findByStatusAndDeletedAtIsNull(String status);
Flux<SysNoticeEntity> findByStatusAndDeletedAtIsNull(String status, Sort sort);
Flux<SysNoticeEntity> findByDeletedAtIsNull();
Flux<SysNoticeEntity> findByDeletedAtIsNull(Sort sort);
Mono<Long> countByDeletedAtIsNull();
Mono<Void> deleteByIdAndDeletedAtIsNull(Long id);
}
@@ -0,0 +1,86 @@
package cn.novalon.manage.sys.infrastructure.db.repository;
import cn.novalon.manage.sys.core.domain.SysNotice;
import cn.novalon.manage.sys.infrastructure.db.converter.SysNoticeConverter;
import cn.novalon.manage.sys.infrastructure.db.dao.SysNoticeDao;
import cn.novalon.manage.sys.infrastructure.db.entity.SysNoticeEntity;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Repository;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
import java.time.LocalDateTime;
@Repository
public class SysNoticeRepository {
private final SysNoticeDao dao;
private final SysNoticeConverter converter;
public SysNoticeRepository(SysNoticeDao dao, SysNoticeConverter converter) {
this.dao = dao;
this.converter = converter;
}
public Mono<SysNotice> findById(Long id) {
return dao.findById(id)
.filter(entity -> entity.getDeletedAt() == null)
.map(converter::toDomain);
}
public Mono<SysNotice> save(SysNotice sysNotice) {
return dao.save(converter.toEntity(sysNotice))
.map(converter::toDomain);
}
public Mono<Void> deleteById(Long id) {
return dao.findById(id)
.flatMap(entity -> {
entity.setDeletedAt(LocalDateTime.now());
return dao.save(entity);
})
.then();
}
public Flux<SysNotice> findByStatus(String status) {
return dao.findByStatusAndDeletedAtIsNull(status)
.map(converter::toDomain);
}
public Flux<SysNotice> findByStatus(String status, Sort sort) {
return dao.findByStatusAndDeletedAtIsNull(status, sort)
.map(converter::toDomain);
}
public Flux<SysNotice> findAll() {
return dao.findByDeletedAtIsNull()
.map(converter::toDomain);
}
public Flux<SysNotice> findAll(Sort sort) {
return dao.findByDeletedAtIsNull(sort)
.map(converter::toDomain);
}
public Mono<Long> count() {
return dao.countByDeletedAtIsNull();
}
public Mono<Void> logicalDeleteById(Long id) {
return dao.findById(id)
.flatMap(entity -> {
entity.setDeletedAt(LocalDateTime.now());
return dao.save(entity);
})
.then();
}
public Mono<Void> restoreById(Long id) {
return dao.findById(id)
.flatMap(entity -> {
entity.setDeletedAt(null);
return dao.save(entity);
})
.then();
}
}