Sfoglia il codice sorgente

add 地图区域管理

18339543638 4 anni fa
parent
commit
b32557a067

+ 12 - 9
jetlinks-manager/device-manager/src/main/java/org/jetlinks/community/device/entity/GeoEntity.java

@@ -3,6 +3,7 @@ package org.jetlinks.community.device.entity;
 import io.swagger.v3.oas.annotations.media.Schema;
 import lombok.Data;
 import org.hswebframework.ezorm.rdb.mapping.annotation.ColumnType;
+import org.hswebframework.web.api.crud.entity.GenericEntity;
 import org.hswebframework.web.validator.CreateGroup;
 import org.jetlinks.community.device.enums.GeoType;
 
@@ -10,40 +11,42 @@ import javax.persistence.Column;
 import javax.persistence.Index;
 import javax.persistence.Table;
 import javax.validation.constraints.NotBlank;
+import javax.validation.constraints.NotNull;
 import java.io.Serializable;
 import java.sql.JDBCType;
 import java.util.*;
 /**
  * @author lifang
  * @version 1.0.0
- * @ClassName GeoEntity.java
+ * @ClassName GeoFeature.java
  * @Description TODO
  * @createTime 2021年09月27日 10:54:00
  */
 @Data
 @Table(name = "geo")
-public class GeoEntity {
+public class GeoEntity  implements Serializable{
 
-    @Column(length = 64, nullable = false, updatable = false)
-    @Schema(description = "地图信息")
+    @Column(name = "type")
+    @NotNull(message = "类型不为空", groups = CreateGroup.class)
+    @Schema(description = "类型")
     private String type;
 
     @Column(name = "gemoetry")
-    @NotBlank(message = "地图信息不为空", groups = CreateGroup.class)
-    @ColumnType(jdbcType = JDBCType.CLOB,javaType = Geometry.class)
+    @NotNull(message = "地图信息不为空", groups = CreateGroup.class)
+    @ColumnType(jdbcType = JDBCType.VARCHAR,javaType = Geometry.class)
     @Schema(description = "地图信息")
     private Geometry geometry;
 
     @Column(name="properties")
-    @NotBlank(message = "实体属性不能为空", groups = CreateGroup.class)
-    @ColumnType(jdbcType = JDBCType.CLOB,javaType = Property.class)
+    @NotNull(message = "实体属性不能为空", groups = CreateGroup.class)
+    @ColumnType(jdbcType = JDBCType.VARCHAR,javaType = Property.class)
     @Schema(description = "实体属性")
     private Property properties;
 
 
     @Data
     public static class Geometry implements Serializable {
-        private GeoType type;
+        private String type;
         private List<Object> coordinates;
     }
 

+ 11 - 3
jetlinks-manager/device-manager/src/main/java/org/jetlinks/community/device/web/GeoController.java

@@ -7,11 +7,11 @@ 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.DeviceProductEntity;
 import org.jetlinks.community.device.entity.GeoEntity;
-import org.jetlinks.community.device.service.LocalDeviceInstanceService;
 import org.jetlinks.community.device.service.LocalGeoService;
+import org.jetlinks.community.device.web.request.GeoPayload;
 import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestBody;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
 import reactor.core.publisher.Mono;
@@ -34,10 +34,18 @@ public class GeoController  implements ReactiveServiceCrudController<GeoEntity,
 
 
     @PostMapping("/_search/geo.json")
-    public Mono<?> search(Mono<QueryParamEntity> filter){
+    public Mono<?> search(@RequestBody Mono<QueryParamEntity> filter){
         return geoService.queryPager(filter);
     }
 
+    @PostMapping("/geo.json")
+    public Mono<Void> save(@RequestBody Mono<GeoPayload> publisher){
+        return publisher.map(GeoPayload::getFeatures)
+            .map(Mono::just)
+            .flatMap(geoService::insertBatch)
+            .then();
+    }
+
     @Override
     public ReactiveCrudService<GeoEntity, String> getService() {
         return geoService;

+ 17 - 0
jetlinks-manager/device-manager/src/main/java/org/jetlinks/community/device/web/request/GeoPayload.java

@@ -0,0 +1,17 @@
+package org.jetlinks.community.device.web.request;
+
+import lombok.Data;
+import org.jetlinks.community.device.entity.GeoEntity;
+import java.util.*;
+/**
+ * @author lifang
+ * @version 1.0.0
+ * @ClassName GeoPayload.java
+ * @Description TODO
+ * @createTime 2021年09月27日 13:48:00
+ */
+@Data
+public class GeoPayload {
+    private String type;
+    private List<GeoEntity> features;
+}