|
|
@@ -1,5 +1,6 @@
|
|
|
package org.jetlinks.community.device.web;
|
|
|
|
|
|
+import cn.hutool.core.util.StrUtil;
|
|
|
import io.swagger.v3.oas.annotations.Operation;
|
|
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
|
|
import lombok.AllArgsConstructor;
|
|
|
@@ -10,9 +11,10 @@ import org.hswebframework.web.crud.web.reactive.ReactiveTreeServiceQueryControll
|
|
|
import org.jetlinks.community.device.entity.GeoRegionEntity;
|
|
|
import org.jetlinks.community.device.service.LocalGeoRegionService;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
-import reactor.core.publisher.Flux;
|
|
|
import reactor.core.publisher.Mono;
|
|
|
|
|
|
+import java.util.Optional;
|
|
|
+
|
|
|
/**
|
|
|
* @author lifang
|
|
|
* @version 1.0.0
|
|
|
@@ -34,14 +36,17 @@ public class GeoController implements ReactiveTreeServiceQueryController<GeoReg
|
|
|
* @param region
|
|
|
* @return
|
|
|
*/
|
|
|
- @PatchMapping("")
|
|
|
+ @PatchMapping
|
|
|
public Mono<Void> save(@RequestBody GeoRegionEntity region){
|
|
|
- return geoService.findById(region.getId())
|
|
|
- .defaultIfEmpty(new GeoRegionEntity())
|
|
|
- .zipWith(geoService.save(Mono.just(region)))
|
|
|
+ return Mono.zip(
|
|
|
+ StrUtil.isEmpty(region.getId())?Mono.just(new GeoRegionEntity()):geoService.findById(region.getId())
|
|
|
+ .defaultIfEmpty(new GeoRegionEntity()),geoService.save(Mono.just(region)))
|
|
|
.flatMap(tp2->
|
|
|
- Mono.just(tp2.getT1().getParentId()).flatMap(geoService::updateChildrenNum))
|
|
|
- .thenReturn(Mono.just(region.getParentId()).flatMap(geoService::updateChildrenNum))
|
|
|
+ Mono.justOrEmpty(tp2.getT1().getParentId())
|
|
|
+ .defaultIfEmpty("")
|
|
|
+ .flatMap(geoService::updateChildrenNum))
|
|
|
+ .thenReturn(Mono.justOrEmpty(region.getParentId())
|
|
|
+ .defaultIfEmpty("").flatMap(geoService::updateChildrenNum))
|
|
|
.then();
|
|
|
}
|
|
|
|