feat: 添加SysDictTypeRepository数据访问层~
This commit is contained in:
+5
@@ -1,6 +1,7 @@
|
||||
package cn.novalon.manage.sys.infrastructure.db.dao;
|
||||
|
||||
import cn.novalon.manage.sys.infrastructure.db.entity.SysDictTypeEntity;
|
||||
import org.springframework.data.domain.Sort;
|
||||
import org.springframework.data.r2dbc.repository.R2dbcRepository;
|
||||
import org.springframework.stereotype.Repository;
|
||||
import reactor.core.publisher.Flux;
|
||||
@@ -13,5 +14,9 @@ public interface SysDictTypeDao extends R2dbcRepository<SysDictTypeEntity, Long>
|
||||
|
||||
Flux<SysDictTypeEntity> findByDeletedAtIsNull();
|
||||
|
||||
Flux<SysDictTypeEntity> findByDeletedAtIsNull(Sort sort);
|
||||
|
||||
Mono<Long> countByDeletedAtIsNull();
|
||||
|
||||
Mono<Void> deleteByIdAndDeletedAtIsNull(Long id);
|
||||
}
|
||||
|
||||
+81
@@ -0,0 +1,81 @@
|
||||
package cn.novalon.manage.sys.infrastructure.db.repository;
|
||||
|
||||
import cn.novalon.manage.sys.core.domain.SysDictType;
|
||||
import cn.novalon.manage.sys.infrastructure.db.converter.SysDictTypeConverter;
|
||||
import cn.novalon.manage.sys.infrastructure.db.dao.SysDictTypeDao;
|
||||
import cn.novalon.manage.sys.infrastructure.db.entity.SysDictTypeEntity;
|
||||
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 SysDictTypeRepository {
|
||||
|
||||
private final SysDictTypeDao dao;
|
||||
private final SysDictTypeConverter converter;
|
||||
|
||||
public SysDictTypeRepository(SysDictTypeDao dao, SysDictTypeConverter converter) {
|
||||
this.dao = dao;
|
||||
this.converter = converter;
|
||||
}
|
||||
|
||||
public Mono<SysDictType> findByDictType(String dictType) {
|
||||
return dao.findByDictTypeAndDeletedAtIsNull(dictType)
|
||||
.map(converter::toDomain);
|
||||
}
|
||||
|
||||
public Mono<SysDictType> findById(Long id) {
|
||||
return dao.findById(id)
|
||||
.filter(entity -> entity.getDeletedAt() == null)
|
||||
.map(converter::toDomain);
|
||||
}
|
||||
|
||||
public Mono<SysDictType> save(SysDictType sysDictType) {
|
||||
return dao.save(converter.toEntity(sysDictType))
|
||||
.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<SysDictType> findAll() {
|
||||
return dao.findByDeletedAtIsNull()
|
||||
.map(converter::toDomain);
|
||||
}
|
||||
|
||||
public Flux<SysDictType> 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