From d5420fea491f2da8de873524ca3b82606c4da8f2 Mon Sep 17 00:00:00 2001 From: wangyu <727842003@qq.com> Date: Wed, 9 Mar 2022 10:04:49 +0800 Subject: [PATCH] =?UTF-8?q?feat=EF=BC=9A=E5=A2=9E=E5=8A=A0=E4=BA=8B?= =?UTF-8?q?=E5=8A=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/flyfish/framework/utils/DepartUtils.java | 3 ++- .../service/impl/BaseReactiveServiceImpl.java | 13 +++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/flyfish-data/src/main/java/com/flyfish/framework/utils/DepartUtils.java b/flyfish-data/src/main/java/com/flyfish/framework/utils/DepartUtils.java index bfa0c58..cd30069 100644 --- a/flyfish-data/src/main/java/com/flyfish/framework/utils/DepartUtils.java +++ b/flyfish-data/src/main/java/com/flyfish/framework/utils/DepartUtils.java @@ -38,7 +38,8 @@ public final class DepartUtils { .collect(Collectors.toSet()); List removing = new ArrayList<>(); for (Department department : departments) { - if (CollectionUtils.containsAny(department.getParentIds(), departs)) { + if (CollectionUtils.isNotEmpty(department.getParentIds()) && + CollectionUtils.containsAny(department.getParentIds(), departs)) { removing.add(department.getId()); } } diff --git a/flyfish-web/src/main/java/com/flyfish/framework/service/impl/BaseReactiveServiceImpl.java b/flyfish-web/src/main/java/com/flyfish/framework/service/impl/BaseReactiveServiceImpl.java index 8c323b0..4751747 100644 --- a/flyfish-web/src/main/java/com/flyfish/framework/service/impl/BaseReactiveServiceImpl.java +++ b/flyfish-web/src/main/java/com/flyfish/framework/service/impl/BaseReactiveServiceImpl.java @@ -20,6 +20,7 @@ import org.springframework.data.domain.PageImpl; import org.springframework.data.domain.Pageable; import org.springframework.data.mongodb.repository.query.MongoEntityInformation; import org.springframework.data.util.CastUtils; +import org.springframework.transaction.annotation.Transactional; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; @@ -227,6 +228,7 @@ public class BaseReactiveServiceImpl implements BaseReactiveSe * @param entity 实体 */ @Override + @Transactional(rollbackFor = Exception.class) public Mono create(T entity) { return audit(entity).flatMap(repository::insert).flatMap(this::post); } @@ -237,6 +239,7 @@ public class BaseReactiveServiceImpl implements BaseReactiveSe * @param entity 实体 */ @Override + @Transactional(rollbackFor = Exception.class) public Mono createSelective(T entity) { return audit(entity).flatMap(repository::insert).flatMap(this::post); } @@ -247,6 +250,7 @@ public class BaseReactiveServiceImpl implements BaseReactiveSe * @param entity 实体 */ @Override + @Transactional(rollbackFor = Exception.class) public Mono delete(T entity) { return repository.delete(entity); } @@ -257,6 +261,7 @@ public class BaseReactiveServiceImpl implements BaseReactiveSe * @param id 主键 */ @Override + @Transactional(rollbackFor = Exception.class) public Mono deleteById(String id) { return repository.deleteById(id); } @@ -267,6 +272,7 @@ public class BaseReactiveServiceImpl implements BaseReactiveSe * @param entity 实体 */ @Override + @Transactional(rollbackFor = Exception.class) public Mono updateById(T entity) { return audit(entity).flatMap(repository::save).flatMap(this::post); } @@ -277,6 +283,7 @@ public class BaseReactiveServiceImpl implements BaseReactiveSe * @param entity 实体 */ @Override + @Transactional(rollbackFor = Exception.class) public Mono updateSelectiveById(T entity) { Assert.hasText(entity.getId(), "更新的主键不可为空!"); return repository.findById(entity.getId()) @@ -291,6 +298,7 @@ public class BaseReactiveServiceImpl implements BaseReactiveSe * @param ids id结合 */ @Override + @Transactional(rollbackFor = Exception.class) public Mono deleteBatchByIds(List ids) { return Flux.fromIterable(ids) .flatMap(t -> repository.deleteById(t)) @@ -303,6 +311,7 @@ public class BaseReactiveServiceImpl implements BaseReactiveSe * @param qo 查询实体 */ @Override + @Transactional(rollbackFor = Exception.class) public Mono deleteAll(Qo qo) { return repository.deleteAll(qo); } @@ -313,6 +322,7 @@ public class BaseReactiveServiceImpl implements BaseReactiveSe * @param entity 查询 */ @Override + @Transactional(rollbackFor = Exception.class) public Mono deleteAll(T entity) { return repository.delete(entity); } @@ -321,6 +331,7 @@ public class BaseReactiveServiceImpl implements BaseReactiveSe * 删除全部实体,危险! */ @Override + @Transactional(rollbackFor = Exception.class) public Mono deleteAll() { return repository.deleteAll(); } @@ -331,6 +342,7 @@ public class BaseReactiveServiceImpl implements BaseReactiveSe * @param entities 要批量更新的集合 */ @Override + @Transactional(rollbackFor = Exception.class) public Flux updateBatch(List entities) { if (CollectionUtils.isNotEmpty(entities)) { // 带有id的集合 @@ -361,6 +373,7 @@ public class BaseReactiveServiceImpl implements BaseReactiveSe * @return 结果 */ @Override + @Transactional(rollbackFor = Exception.class) public Mono> sync(List entities) { return this.updateBatch(entities) .collectList()