feat:增加事务
This commit is contained in:
parent
4c518d423f
commit
d5420fea49
@ -38,7 +38,8 @@ public final class DepartUtils {
|
|||||||
.collect(Collectors.toSet());
|
.collect(Collectors.toSet());
|
||||||
List<String> removing = new ArrayList<>();
|
List<String> removing = new ArrayList<>();
|
||||||
for (Department department : departments) {
|
for (Department department : departments) {
|
||||||
if (CollectionUtils.containsAny(department.getParentIds(), departs)) {
|
if (CollectionUtils.isNotEmpty(department.getParentIds()) &&
|
||||||
|
CollectionUtils.containsAny(department.getParentIds(), departs)) {
|
||||||
removing.add(department.getId());
|
removing.add(department.getId());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -20,6 +20,7 @@ import org.springframework.data.domain.PageImpl;
|
|||||||
import org.springframework.data.domain.Pageable;
|
import org.springframework.data.domain.Pageable;
|
||||||
import org.springframework.data.mongodb.repository.query.MongoEntityInformation;
|
import org.springframework.data.mongodb.repository.query.MongoEntityInformation;
|
||||||
import org.springframework.data.util.CastUtils;
|
import org.springframework.data.util.CastUtils;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
import reactor.core.publisher.Flux;
|
import reactor.core.publisher.Flux;
|
||||||
import reactor.core.publisher.Mono;
|
import reactor.core.publisher.Mono;
|
||||||
|
|
||||||
@ -227,6 +228,7 @@ public class BaseReactiveServiceImpl<T extends Domain> implements BaseReactiveSe
|
|||||||
* @param entity 实体
|
* @param entity 实体
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public Mono<T> create(T entity) {
|
public Mono<T> create(T entity) {
|
||||||
return audit(entity).flatMap(repository::insert).flatMap(this::post);
|
return audit(entity).flatMap(repository::insert).flatMap(this::post);
|
||||||
}
|
}
|
||||||
@ -237,6 +239,7 @@ public class BaseReactiveServiceImpl<T extends Domain> implements BaseReactiveSe
|
|||||||
* @param entity 实体
|
* @param entity 实体
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public Mono<T> createSelective(T entity) {
|
public Mono<T> createSelective(T entity) {
|
||||||
return audit(entity).flatMap(repository::insert).flatMap(this::post);
|
return audit(entity).flatMap(repository::insert).flatMap(this::post);
|
||||||
}
|
}
|
||||||
@ -247,6 +250,7 @@ public class BaseReactiveServiceImpl<T extends Domain> implements BaseReactiveSe
|
|||||||
* @param entity 实体
|
* @param entity 实体
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public Mono<Void> delete(T entity) {
|
public Mono<Void> delete(T entity) {
|
||||||
return repository.delete(entity);
|
return repository.delete(entity);
|
||||||
}
|
}
|
||||||
@ -257,6 +261,7 @@ public class BaseReactiveServiceImpl<T extends Domain> implements BaseReactiveSe
|
|||||||
* @param id 主键
|
* @param id 主键
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public Mono<Void> deleteById(String id) {
|
public Mono<Void> deleteById(String id) {
|
||||||
return repository.deleteById(id);
|
return repository.deleteById(id);
|
||||||
}
|
}
|
||||||
@ -267,6 +272,7 @@ public class BaseReactiveServiceImpl<T extends Domain> implements BaseReactiveSe
|
|||||||
* @param entity 实体
|
* @param entity 实体
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public Mono<T> updateById(T entity) {
|
public Mono<T> updateById(T entity) {
|
||||||
return audit(entity).flatMap(repository::save).flatMap(this::post);
|
return audit(entity).flatMap(repository::save).flatMap(this::post);
|
||||||
}
|
}
|
||||||
@ -277,6 +283,7 @@ public class BaseReactiveServiceImpl<T extends Domain> implements BaseReactiveSe
|
|||||||
* @param entity 实体
|
* @param entity 实体
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public Mono<T> updateSelectiveById(T entity) {
|
public Mono<T> updateSelectiveById(T entity) {
|
||||||
Assert.hasText(entity.getId(), "更新的主键不可为空!");
|
Assert.hasText(entity.getId(), "更新的主键不可为空!");
|
||||||
return repository.findById(entity.getId())
|
return repository.findById(entity.getId())
|
||||||
@ -291,6 +298,7 @@ public class BaseReactiveServiceImpl<T extends Domain> implements BaseReactiveSe
|
|||||||
* @param ids id结合
|
* @param ids id结合
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public Mono<Void> deleteBatchByIds(List<String> ids) {
|
public Mono<Void> deleteBatchByIds(List<String> ids) {
|
||||||
return Flux.fromIterable(ids)
|
return Flux.fromIterable(ids)
|
||||||
.flatMap(t -> repository.deleteById(t))
|
.flatMap(t -> repository.deleteById(t))
|
||||||
@ -303,6 +311,7 @@ public class BaseReactiveServiceImpl<T extends Domain> implements BaseReactiveSe
|
|||||||
* @param qo 查询实体
|
* @param qo 查询实体
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public Mono<Void> deleteAll(Qo<T> qo) {
|
public Mono<Void> deleteAll(Qo<T> qo) {
|
||||||
return repository.deleteAll(qo);
|
return repository.deleteAll(qo);
|
||||||
}
|
}
|
||||||
@ -313,6 +322,7 @@ public class BaseReactiveServiceImpl<T extends Domain> implements BaseReactiveSe
|
|||||||
* @param entity 查询
|
* @param entity 查询
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public Mono<Void> deleteAll(T entity) {
|
public Mono<Void> deleteAll(T entity) {
|
||||||
return repository.delete(entity);
|
return repository.delete(entity);
|
||||||
}
|
}
|
||||||
@ -321,6 +331,7 @@ public class BaseReactiveServiceImpl<T extends Domain> implements BaseReactiveSe
|
|||||||
* 删除全部实体,危险!
|
* 删除全部实体,危险!
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public Mono<Void> deleteAll() {
|
public Mono<Void> deleteAll() {
|
||||||
return repository.deleteAll();
|
return repository.deleteAll();
|
||||||
}
|
}
|
||||||
@ -331,6 +342,7 @@ public class BaseReactiveServiceImpl<T extends Domain> implements BaseReactiveSe
|
|||||||
* @param entities 要批量更新的集合
|
* @param entities 要批量更新的集合
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public Flux<T> updateBatch(List<T> entities) {
|
public Flux<T> updateBatch(List<T> entities) {
|
||||||
if (CollectionUtils.isNotEmpty(entities)) {
|
if (CollectionUtils.isNotEmpty(entities)) {
|
||||||
// 带有id的集合
|
// 带有id的集合
|
||||||
@ -361,6 +373,7 @@ public class BaseReactiveServiceImpl<T extends Domain> implements BaseReactiveSe
|
|||||||
* @return 结果
|
* @return 结果
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public Mono<SyncVo<T>> sync(List<T> entities) {
|
public Mono<SyncVo<T>> sync(List<T> entities) {
|
||||||
return this.updateBatch(entities)
|
return this.updateBatch(entities)
|
||||||
.collectList()
|
.collectList()
|
||||||
|
Loading…
Reference in New Issue
Block a user