|
|
@@ -3,17 +3,21 @@ package org.jetlinks.community.device.web;
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
|
|
import lombok.AllArgsConstructor;
|
|
|
+import org.hibernate.validator.constraints.Length;
|
|
|
import org.hswebframework.web.api.crud.entity.PagerResult;
|
|
|
-import org.hswebframework.web.api.crud.entity.QueryParamEntity;
|
|
|
import org.hswebframework.web.authorization.annotation.Authorize;
|
|
|
import org.hswebframework.web.authorization.annotation.Resource;
|
|
|
import org.hswebframework.web.crud.service.ReactiveCrudService;
|
|
|
import org.hswebframework.web.crud.web.reactive.ReactiveServiceCrudController;
|
|
|
+import org.jetlinks.community.device.entity.DeviceTagEntity;
|
|
|
import org.jetlinks.community.device.entity.geo.GeoEntity;
|
|
|
import org.jetlinks.community.device.entity.geo.GeoProperty;
|
|
|
+import org.jetlinks.community.device.entity.geo.Geometry;
|
|
|
+import org.jetlinks.community.device.service.DeviceTagsService;
|
|
|
import org.jetlinks.community.device.service.LocalGeoPropertyService;
|
|
|
import org.jetlinks.community.device.web.request.GeoPayload;
|
|
|
-import org.jetlinks.core.metadata.types.GeoShape;
|
|
|
+import org.jetlinks.community.device.web.request.GeoRequestParam;
|
|
|
+import org.jetlinks.core.metadata.types.GeoType;
|
|
|
import org.springframework.web.bind.annotation.PostMapping;
|
|
|
import org.springframework.web.bind.annotation.RequestBody;
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
@@ -21,7 +25,9 @@ import org.springframework.web.bind.annotation.RestController;
|
|
|
import reactor.core.publisher.Flux;
|
|
|
import reactor.core.publisher.Mono;
|
|
|
|
|
|
+import javax.validation.constraints.NotBlank;
|
|
|
import java.util.List;
|
|
|
+import java.util.function.Function;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
@@ -39,24 +45,46 @@ import java.util.stream.Collectors;
|
|
|
@AllArgsConstructor
|
|
|
public class GeoController implements ReactiveServiceCrudController<GeoProperty, String> {
|
|
|
private final LocalGeoPropertyService geoService;
|
|
|
+ private final DeviceTagsService tagsService;
|
|
|
|
|
|
|
|
|
@PostMapping("/_search/geo.json")
|
|
|
- public Mono<?> search(@RequestBody Mono<QueryParamEntity> filter){
|
|
|
-
|
|
|
- return geoService.queryPager(filter)
|
|
|
+ public Flux<?> search(@RequestBody GeoRequestParam param){
|
|
|
+ return geoService.queryPager(param.getFilter())
|
|
|
.map(PagerResult::getData)
|
|
|
- .map(result->{
|
|
|
- GeoPayload geoPayload = new GeoPayload();
|
|
|
- result.stream()
|
|
|
- .filter(geoProperty->null!=geoProperty.getGeometry())
|
|
|
- .forEach(property->{
|
|
|
+ .zipWith(Mono.just(new GeoPayload()))
|
|
|
+ .flux()
|
|
|
+ .map(tp2-> {
|
|
|
+ //区域管理
|
|
|
+ GeoPayload geoPayload =tp2.getT2();
|
|
|
+ return Flux.fromStream(tp2.getT1().stream())
|
|
|
+ .flatMap(property->{
|
|
|
GeoEntity geoEntity = new GeoEntity();
|
|
|
geoEntity.with(property);
|
|
|
- geoPayload.getFeatures().add(geoEntity);
|
|
|
+ if (null == property.getGeometry()) {
|
|
|
+ return tagsService.createQuery()
|
|
|
+ .where(DeviceTagEntity::getDeviceId, property.getObjectId())
|
|
|
+ .where(DeviceTagEntity::getKey, "coordinate")
|
|
|
+ .where(DeviceTagEntity::getType, GeoType.ID)
|
|
|
+ .fetchOne()
|
|
|
+ .switchIfEmpty(Mono.just(new DeviceTagEntity()))
|
|
|
+ .doOnNext(tag -> {
|
|
|
+ if (!StrUtil.isEmpty(tag.getId())) {
|
|
|
+ Geometry geometry = new Geometry();
|
|
|
+ String[] split = tag.getValue().split(",");
|
|
|
+ geometry.getCoordinates().add(split[0]);
|
|
|
+ geometry.getCoordinates().add(split[1]);
|
|
|
+ geometry.setType(GeoType.ID);
|
|
|
+ geoEntity.setGeometry(geometry);
|
|
|
+ }
|
|
|
+ geoPayload.getFeatures().add(geoEntity);
|
|
|
+ })
|
|
|
+ .map(ignore->tp2.getT2());
|
|
|
+ }
|
|
|
+ return Flux.just(tp2.getT2());
|
|
|
});
|
|
|
- return geoPayload;}
|
|
|
- );
|
|
|
+ })
|
|
|
+ .flatMap(Function.identity());
|
|
|
};
|
|
|
|
|
|
/**
|