feat: 添加SysNoticeRepository数据访问层~
This commit is contained in:
+7
@@ -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);
|
||||
}
|
||||
|
||||
+86
@@ -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();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user