|
|
@@ -1,39 +1,17 @@
|
|
|
package org.jetlinks.community.device.web;
|
|
|
|
|
|
-import cn.hutool.core.collection.CollectionUtil;
|
|
|
-import cn.hutool.core.util.StrUtil;
|
|
|
import io.swagger.v3.oas.annotations.Operation;
|
|
|
-import io.swagger.v3.oas.annotations.Parameter;
|
|
|
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.authorization.annotation.SaveAction;
|
|
|
-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.LocalDeviceInstanceService;
|
|
|
-import org.jetlinks.community.device.service.LocalGeoPropertyService;
|
|
|
-import org.jetlinks.community.device.web.request.GeoPayload;
|
|
|
-import org.jetlinks.community.device.web.request.GeoRequestParam;
|
|
|
-import org.jetlinks.core.metadata.types.GeoType;
|
|
|
+import org.hswebframework.web.crud.service.ReactiveTreeSortEntityService;
|
|
|
+import org.hswebframework.web.crud.web.reactive.ReactiveTreeServiceQueryController;
|
|
|
+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 reactor.util.function.Tuple2;
|
|
|
-
|
|
|
-import javax.validation.constraints.NotBlank;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Objects;
|
|
|
-import java.util.function.Function;
|
|
|
-import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
* @author lifang
|
|
|
@@ -43,67 +21,33 @@ import java.util.stream.Collectors;
|
|
|
* @createTime 2021年09月22日 14:35:00
|
|
|
*/
|
|
|
@RestController
|
|
|
-@RequestMapping("/geo/object")
|
|
|
+@RequestMapping("/geo/region")
|
|
|
@Authorize
|
|
|
-@Resource(id = "geo-manager", name = "地理位置管理")
|
|
|
-@Tag(name = "地理位置管理")
|
|
|
+@Resource(id = "geo-region", name = "地理区域管理")
|
|
|
+@Tag(name = "地理区域管理")
|
|
|
@AllArgsConstructor
|
|
|
-public class GeoController implements ReactiveServiceCrudController<GeoProperty, String> {
|
|
|
- private final LocalGeoPropertyService geoService;
|
|
|
- private final LocalDeviceInstanceService instanceService;
|
|
|
-
|
|
|
-
|
|
|
- @PostMapping("/_search/geo.json")
|
|
|
- public Mono<?> search(@RequestBody GeoRequestParam param){
|
|
|
- return geoService.queryPager(param.getQuery())
|
|
|
- .map(PagerResult::getData)
|
|
|
- .zipWith(Mono.just(new GeoPayload()))
|
|
|
- .doOnNext(tp2->{
|
|
|
- List<GeoProperty> properties = tp2.getT1();
|
|
|
- if(CollectionUtil.isNotEmpty(properties)){
|
|
|
- tp2.getT2().setFeatures(properties.stream().map(geoProperty -> {
|
|
|
- GeoEntity geoEntity = new GeoEntity();
|
|
|
- geoEntity.setGeometry(geoProperty.getGeometry());
|
|
|
- geoEntity.setProperties(geoProperty);
|
|
|
- return geoEntity;
|
|
|
- }).collect(Collectors.toList()));
|
|
|
- }
|
|
|
- })
|
|
|
- .map(Tuple2::getT2);
|
|
|
- }
|
|
|
+public class GeoController implements ReactiveTreeServiceQueryController<GeoRegionEntity, String> {
|
|
|
+ private final LocalGeoRegionService geoService;
|
|
|
|
|
|
/**
|
|
|
- * 区域管理新增
|
|
|
- * @param publisher
|
|
|
+ * 区域管理新增或新增
|
|
|
+ * @param region
|
|
|
* @return
|
|
|
*/
|
|
|
- @PostMapping("/geo.json")
|
|
|
- public Mono<Void> save(@RequestBody GeoPayload publisher){
|
|
|
- return Mono.just(publisher.getFeatures())
|
|
|
- .flatMap(features->{
|
|
|
- features.forEach(geo-> geo.getProperties().setGeometry(geo.getGeometry()));
|
|
|
- List<GeoProperty> collect = features.stream().map(GeoEntity::getProperties).collect(Collectors.toList());
|
|
|
- return geoService
|
|
|
- .insertBatch(Mono.just(collect))
|
|
|
- .map(ignore->
|
|
|
- Flux.fromStream(collect.stream())
|
|
|
- .filter(geoProperty -> StrUtil.isNotEmpty(geoProperty.getParentId()))
|
|
|
- .map(GeoProperty::getParentId)
|
|
|
- .collect(Collectors.toSet())
|
|
|
- .doOnNext(ids->ids.forEach(geoService::updateChildrenNum))
|
|
|
- );
|
|
|
- }).then();
|
|
|
+ @PatchMapping("")
|
|
|
+ public Mono<Void> save(@RequestBody GeoRegionEntity region){
|
|
|
+ return geoService.findById(region.getId())
|
|
|
+ .defaultIfEmpty(new GeoRegionEntity())
|
|
|
+ .zipWith(geoService.save(Mono.just(region)))
|
|
|
+ .flatMap(tp2->
|
|
|
+ Mono.just(tp2.getT1().getParentId()).flatMap(geoService::updateChildrenNum))
|
|
|
+ .thenReturn(Mono.just(region.getParentId()).flatMap(geoService::updateChildrenNum))
|
|
|
+ .then();
|
|
|
}
|
|
|
|
|
|
|
|
|
-
|
|
|
- @Override
|
|
|
- public Mono<PagerResult<GeoProperty>> queryPager(QueryParamEntity query) {
|
|
|
- return null;
|
|
|
- }
|
|
|
-
|
|
|
@Override
|
|
|
- public ReactiveCrudService<GeoProperty, String> getService() {
|
|
|
+ public ReactiveTreeSortEntityService<GeoRegionEntity, String> getService() {
|
|
|
return geoService;
|
|
|
}
|
|
|
}
|