|
|
@@ -1,5 +1,6 @@
|
|
|
package org.jetlinks.community.device.service;
|
|
|
|
|
|
+import cn.hutool.core.collection.CollectionUtil;
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
import org.hswebframework.web.crud.service.GenericReactiveTreeSupportCrudService;
|
|
|
import org.hswebframework.web.id.IDGenerator;
|
|
|
@@ -27,14 +28,17 @@ public class LocalGeoRegionService extends GenericReactiveTreeSupportCrudService
|
|
|
* @return
|
|
|
*/
|
|
|
public Mono<Void> updateChildrenNum(String parentId){
|
|
|
- return Mono.justOrEmpty(parentId)
|
|
|
- .defaultIfEmpty("")
|
|
|
- .filter(StrUtil::isNotBlank)
|
|
|
- .zipWith(Mono.defer(()->this.createQuery().where(GeoRegionEntity::getParentId,parentId).count()))
|
|
|
- .map(tp2->
|
|
|
+ if(StrUtil.isEmpty(parentId)){
|
|
|
+ return Mono.empty();
|
|
|
+ }
|
|
|
+ return this.createQuery()
|
|
|
+ .where(GeoRegionEntity::getParentId,parentId)
|
|
|
+ .count()
|
|
|
+ .flatMap(count->
|
|
|
this.createUpdate()
|
|
|
.where(GeoRegionEntity::getId,parentId)
|
|
|
- .set(GeoRegionEntity::getChildrenNum,tp2.getT2()))
|
|
|
+ .set(GeoRegionEntity::getChildrenNum,count)
|
|
|
+ .execute())
|
|
|
.then();
|
|
|
}
|
|
|
|
|
|
@@ -45,7 +49,9 @@ public class LocalGeoRegionService extends GenericReactiveTreeSupportCrudService
|
|
|
|
|
|
@Override
|
|
|
public void setChildren(GeoRegionEntity entity, List<GeoRegionEntity> children) {
|
|
|
- entity.setChildren( Optional.ofNullable(entity.getChildren()).orElse(new ArrayList<>()));
|
|
|
- entity.getChildren().addAll(children);
|
|
|
+ entity.setChildren( Optional.ofNullable(entity.getChildren()).orElse(new ArrayList<>()));
|
|
|
+ if (CollectionUtil.isNotEmpty(children)) {
|
|
|
+ entity.getChildren().addAll(children);
|
|
|
+ }
|
|
|
}
|
|
|
}
|