feat: 添加SysFileRepository数据访问层~
This commit is contained in:
+11
@@ -1,6 +1,7 @@
|
||||
package cn.novalon.manage.sys.infrastructure.db.dao;
|
||||
|
||||
import cn.novalon.manage.sys.infrastructure.db.entity.SysFileEntity;
|
||||
import org.springframework.data.domain.Sort;
|
||||
import org.springframework.data.r2dbc.repository.R2dbcRepository;
|
||||
import org.springframework.stereotype.Repository;
|
||||
import reactor.core.publisher.Flux;
|
||||
@@ -9,9 +10,19 @@ import reactor.core.publisher.Mono;
|
||||
@Repository
|
||||
public interface SysFileDao extends R2dbcRepository<SysFileEntity, Long> {
|
||||
|
||||
Flux<SysFileEntity> findByCreateBy(String createBy);
|
||||
|
||||
Flux<SysFileEntity> findByCreateBy(String createBy, Sort sort);
|
||||
|
||||
Flux<SysFileEntity> findByCreateByOrderByCreatedAtDesc(String createBy);
|
||||
|
||||
Flux<SysFileEntity> findByDeletedAtIsNull();
|
||||
|
||||
Flux<SysFileEntity> findByDeletedAtIsNull(Sort sort);
|
||||
|
||||
Flux<SysFileEntity> findByDeletedAtIsNullOrderByCreatedAtDesc();
|
||||
|
||||
Mono<Long> countByDeletedAtIsNull();
|
||||
|
||||
Mono<Void> deleteByIdAndDeletedAtIsNull(Long id);
|
||||
}
|
||||
|
||||
+96
@@ -0,0 +1,96 @@
|
||||
package cn.novalon.manage.sys.infrastructure.db.repository;
|
||||
|
||||
import cn.novalon.manage.sys.core.domain.SysFile;
|
||||
import cn.novalon.manage.sys.infrastructure.db.converter.SysFileConverter;
|
||||
import cn.novalon.manage.sys.infrastructure.db.dao.SysFileDao;
|
||||
import cn.novalon.manage.sys.infrastructure.db.entity.SysFileEntity;
|
||||
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 SysFileRepository {
|
||||
|
||||
private final SysFileDao dao;
|
||||
private final SysFileConverter converter;
|
||||
|
||||
public SysFileRepository(SysFileDao dao, SysFileConverter converter) {
|
||||
this.dao = dao;
|
||||
this.converter = converter;
|
||||
}
|
||||
|
||||
public Mono<SysFile> findById(Long id) {
|
||||
return dao.findById(id)
|
||||
.filter(entity -> entity.getDeletedAt() == null)
|
||||
.map(converter::toDomain);
|
||||
}
|
||||
|
||||
public Mono<SysFile> save(SysFile sysFile) {
|
||||
return dao.save(converter.toEntity(sysFile))
|
||||
.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<SysFile> findByCreateBy(String createBy) {
|
||||
return dao.findByCreateBy(createBy)
|
||||
.map(converter::toDomain);
|
||||
}
|
||||
|
||||
public Flux<SysFile> findByCreateBy(String createBy, Sort sort) {
|
||||
return dao.findByCreateBy(createBy, sort)
|
||||
.map(converter::toDomain);
|
||||
}
|
||||
|
||||
public Flux<SysFile> findByCreateByOrderByCreatedAtDesc(String createBy) {
|
||||
return dao.findByCreateByOrderByCreatedAtDesc(createBy)
|
||||
.map(converter::toDomain);
|
||||
}
|
||||
|
||||
public Flux<SysFile> findAll() {
|
||||
return dao.findByDeletedAtIsNull()
|
||||
.map(converter::toDomain);
|
||||
}
|
||||
|
||||
public Flux<SysFile> findAll(Sort sort) {
|
||||
return dao.findByDeletedAtIsNull(sort)
|
||||
.map(converter::toDomain);
|
||||
}
|
||||
|
||||
public Flux<SysFile> findAllByOrderByCreatedAtDesc() {
|
||||
return dao.findByDeletedAtIsNullOrderByCreatedAtDesc()
|
||||
.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