|
|
@@ -1,33 +1,25 @@
|
|
|
package org.jetlinks.community.device.web;
|
|
|
|
|
|
-import cn.hutool.core.collection.CollectionUtil;
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
-import groovy.lang.Tuple2;
|
|
|
-import io.swagger.v3.oas.annotations.Operation;
|
|
|
import io.swagger.v3.oas.annotations.Parameter;
|
|
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
|
|
import io.vavr.Tuple;
|
|
|
import lombok.AllArgsConstructor;
|
|
|
-import org.hswebframework.ezorm.rdb.mapping.ReactiveRepository;
|
|
|
import org.hswebframework.web.api.crud.entity.QueryOperation;
|
|
|
import org.hswebframework.web.api.crud.entity.QueryParamEntity;
|
|
|
import org.hswebframework.web.authorization.annotation.Authorize;
|
|
|
import org.hswebframework.web.authorization.annotation.QueryAction;
|
|
|
import org.hswebframework.web.authorization.annotation.Resource;
|
|
|
import org.hswebframework.web.crud.service.ReactiveTreeSortEntityService;
|
|
|
-import org.hswebframework.web.crud.web.reactive.ReactiveDeleteController;
|
|
|
import org.hswebframework.web.crud.web.reactive.ReactiveTreeServiceQueryController;
|
|
|
-import org.hswebframework.web.exception.NotFoundException;
|
|
|
-import org.jetlinks.community.device.entity.DeviceInstanceEntity;
|
|
|
import org.jetlinks.community.device.entity.GeoJson;
|
|
|
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.List;
|
|
|
import java.util.Objects;
|
|
|
-import java.util.Optional;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
@@ -46,15 +38,22 @@ import java.util.stream.Collectors;
|
|
|
public class GeoController implements ReactiveTreeServiceQueryController<GeoRegionEntity, String>{
|
|
|
private final LocalGeoRegionService geoService;
|
|
|
|
|
|
- @GetMapping("/_query/tree/tp2")
|
|
|
+ @GetMapping("/_query/tree/geo.json")
|
|
|
@QueryAction
|
|
|
@QueryOperation(summary = "使用GET动态查询并返回树形结构以及geo集合信息")
|
|
|
public Mono<?> findAllTreeTp2(@Parameter(hidden = true) QueryParamEntity paramEntity) {
|
|
|
- return getService().queryResultToTree(paramEntity)
|
|
|
- .map(result-> Tuple.of(result, GeoJson.of(result.stream().map(GeoRegionEntity::getRegion)
|
|
|
- .filter(Objects::nonNull).collect(Collectors.toList()), "FeatureCollection")));
|
|
|
+ return getService().query(paramEntity)
|
|
|
+ .collectList()
|
|
|
+ .map(result-> GeoJson.of(result.stream().map(GeoRegionEntity::getRegion)
|
|
|
+ .filter(Objects::nonNull).collect(Collectors.toList()), "FeatureCollection"));
|
|
|
}
|
|
|
|
|
|
+ @GetMapping("/_query/all")
|
|
|
+ @QueryAction
|
|
|
+ @QueryOperation(summary = "使用GET动态查询并返回树形结构以及geo集合信息")
|
|
|
+ public Flux<GeoRegionEntity> findAll(QueryParamEntity paramEntity) {
|
|
|
+ return getService().query(paramEntity);
|
|
|
+ }
|
|
|
/**
|
|
|
* 区域管理新增或新增
|
|
|
* @param region
|
|
|
@@ -65,8 +64,8 @@ public class GeoController implements ReactiveTreeServiceQueryController<GeoReg
|
|
|
String id = region.getId();
|
|
|
return StrUtil.isEmpty(id)?
|
|
|
geoService
|
|
|
- .save(Mono.just(region))
|
|
|
- .flatMap(ignore-> geoService.updateChildrenNum(region.getParentId())).then():
|
|
|
+ .save(Mono.just(region))
|
|
|
+ .flatMap(ignore-> geoService.updateChildrenNum(region.getParentId())).then():
|
|
|
geoService.findById(id)
|
|
|
.zipWith(geoService.save(Mono.just(region)))
|
|
|
.flatMap(tp2->geoService.updateChildrenNum(tp2.getT1().getParentId()))
|