feat: 添加SysConfigRepository数据访问层~
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.SysConfigEntity;
|
||||
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 SysConfigDao extends R2dbcRepository<SysConfigEntity, Long> {
|
||||
|
||||
Flux<SysConfigEntity> findByDeletedAtIsNull();
|
||||
|
||||
Flux<SysConfigEntity> 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.SysConfig;
|
||||
import cn.novalon.manage.sys.infrastructure.db.converter.SysConfigConverter;
|
||||
import cn.novalon.manage.sys.infrastructure.db.dao.SysConfigDao;
|
||||
import cn.novalon.manage.sys.infrastructure.db.entity.SysConfigEntity;
|
||||
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 SysConfigRepository {
|
||||
|
||||
private final SysConfigDao dao;
|
||||
private final SysConfigConverter converter;
|
||||
|
||||
public SysConfigRepository(SysConfigDao dao, SysConfigConverter converter) {
|
||||
this.dao = dao;
|
||||
this.converter = converter;
|
||||
}
|
||||
|
||||
public Mono<SysConfig> findByConfigKey(String configKey) {
|
||||
return dao.findByConfigKeyAndDeletedAtIsNull(configKey)
|
||||
.map(converter::toDomain);
|
||||
}
|
||||
|
||||
public Mono<SysConfig> findById(Long id) {
|
||||
return dao.findById(id)
|
||||
.filter(entity -> entity.getDeletedAt() == null)
|
||||
.map(converter::toDomain);
|
||||
}
|
||||
|
||||
public Mono<SysConfig> save(SysConfig sysConfig) {
|
||||
return dao.save(converter.toEntity(sysConfig))
|
||||
.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<SysConfig> findAll() {
|
||||
return dao.findByDeletedAtIsNull()
|
||||
.map(converter::toDomain);
|
||||
}
|
||||
|
||||
public Flux<SysConfig> 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