Browse Source

地图元素

S0025136190 1 year ago
parent
commit
93bea8aefa

+ 15 - 0
Backend/cloud-sdk/src/main/java/com/dji/sdk/cloudapi/map/MapGroupElement.java

@@ -25,6 +25,11 @@ public class MapGroupElement {
     @Schema(description = "element name", example = "PILOT 1")
     private String name;
 
+    @NotNull
+    @Schema(description = "element from", example = "1")
+    @JsonProperty(value = "element_from")
+    private Integer elementFrom;
+
     @NotNull
     @Schema(description = "element create time", example = "123456789012")
     @JsonProperty(value = "create_time")
@@ -49,6 +54,7 @@ public class MapGroupElement {
         return "MapGroupElement{" +
                 "id='" + id + '\'' +
                 ", name='" + name + '\'' +
+                ", elementFrom='" + elementFrom + '\'' +
                 ", createTime=" + createTime +
                 ", updateTime=" + updateTime +
                 ", resource=" + resource +
@@ -99,4 +105,13 @@ public class MapGroupElement {
         this.resource = resource;
         return this;
     }
+
+    public Integer getElementFrom() {
+        return elementFrom;
+    }
+
+    public MapGroupElement setElementFrom(Integer elementFrom) {
+        this.elementFrom = elementFrom;
+        return this;
+    }
 }

+ 2 - 0
Backend/cloud-sdk/src/main/java/com/dji/sdk/mqtt/state/RcStateDataKeyEnum.java

@@ -25,6 +25,8 @@ public enum RcStateDataKeyEnum {
     LIVE_STATUS(Set.of("live_status"), RcLiveStatus.class),
 
     PAYLOAD_FIRMWARE(PayloadModelConst.getAllModelWithPosition(), PayloadFirmwareVersion.class),
+
+//    WPMZ_VERSION(Set.of("wpmz_version"),DockDroneWpmzVersion.class)
     ;
 
     private final Set<String> keys;

+ 1 - 1
Backend/sample/src/main/java/com/dji/sample/component/oss/service/impl/MinIOServiceImpl.java

@@ -134,7 +134,7 @@ public class MinIOServiceImpl implements IOssService {
     private void putObjectToMinIO(String bucket, String objectKey, InputStream input, Map<String,String> userMetadata) {
         try {
             client.statObject(StatObjectArgs.builder().bucket(bucket).object(objectKey).build());
-            throw new RuntimeException("The filename already exists.");
+            throw new RuntimeException("The filename already exists:" + objectKey);
         } catch (MinioException | InvalidKeyException | IOException | NoSuchAlgorithmException e) {
             log.info("The file does not exist, start uploading.");
             try {

+ 1 - 1
Backend/sample/src/main/java/com/dji/sample/map/controller/WorkspaceElementController.java

@@ -78,7 +78,7 @@ public class WorkspaceElementController implements IHttpMapService {
         // Set the creator of the element
         elementCreate.getResource().setUsername(claims.getUsername());
 
-        HttpResultResponse response = elementService.saveElement(workspaceId, groupId, elementCreate, true);
+        HttpResultResponse response = elementService.saveElement(workspaceId, groupId, claims.getUserType(), elementCreate, true);
         if (response.getCode() != HttpResultResponse.CODE_SUCCESS) {
             return response;
         }

+ 3 - 0
Backend/sample/src/main/java/com/dji/sample/map/model/entity/GroupElementEntity.java

@@ -52,4 +52,7 @@ public class GroupElementEntity implements Serializable {
 
     @TableField(value = "update_time", fill = FieldFill.INSERT_UPDATE)
     private Long updateTime;
+
+    @TableField("element_from")
+    private Integer elementFrom;
 }

+ 3 - 0
Backend/sample/src/main/java/com/dji/sample/map/model/entity/GroupEntity.java

@@ -41,6 +41,9 @@ public class GroupEntity implements Serializable {
     @TableField("is_lock")
     private Boolean isLock;
 
+    @TableField("enabled")
+    private Boolean enabled;
+
     @TableField(value = "create_time", fill = FieldFill.INSERT)
     private Long createTime;
 

+ 2 - 1
Backend/sample/src/main/java/com/dji/sample/map/service/IGroupElementService.java

@@ -26,9 +26,10 @@ public interface IGroupElementService {
      * Save all the elements.
      * @param groupId
      * @param elementCreate
+     * @param elementFrom
      * @return
      */
-    Boolean saveElement(String groupId, CreateMapElementRequest elementCreate);
+    Boolean saveElement(String groupId, Integer elementFrom, CreateMapElementRequest elementCreate);
 
     /**
      * Query the element information based on the element id and update element.

+ 1 - 1
Backend/sample/src/main/java/com/dji/sample/map/service/IWorkspaceElementService.java

@@ -34,7 +34,7 @@ public interface IWorkspaceElementService {
      * @param notify
      * @return
      */
-    HttpResultResponse saveElement(String workspaceId, String groupId, CreateMapElementRequest elementCreate, boolean notify);
+    HttpResultResponse saveElement(String workspaceId, String groupId, Integer elementFrom, CreateMapElementRequest elementCreate, boolean notify);
 
     /**
      * Update the element information based on the element id,

+ 2 - 0
Backend/sample/src/main/java/com/dji/sample/map/service/impl/FlightAreaServiceImpl.java

@@ -1,6 +1,7 @@
 package com.dji.sample.map.service.impl;
 
 import com.dji.sample.common.error.CommonErrorEnum;
+import com.dji.sample.common.util.UserRequest;
 import com.dji.sample.component.oss.model.OssConfiguration;
 import com.dji.sample.component.oss.service.impl.OssServiceContext;
 import com.dji.sample.component.websocket.model.BizCodeEnum;
@@ -124,6 +125,7 @@ public class FlightAreaServiceImpl extends AbstractFlightAreaService implements
             typeEnum = ElementResourceTypeEnum.find(type);
         }
         HttpResultResponse response = workspaceElementService.saveElement(workspaceId, groupOpt.get().getId(),
+                UserRequest.getCurrentUser().getUserType(),
                 new CreateMapElementRequest().setId(param.getId()).setName(param.getName())
                         .setResource(new ElementResource()
                                 .setUsername(username)

+ 13 - 4
Backend/sample/src/main/java/com/dji/sample/map/service/impl/GroupElementServiceImpl.java

@@ -48,13 +48,18 @@ public class GroupElementServiceImpl implements IGroupElementService {
     }
 
     @Override
-    public Boolean saveElement(String groupId, CreateMapElementRequest elementCreate) {
+    public Boolean saveElement(String groupId, Integer elementFrom, CreateMapElementRequest elementCreate) {
+        //获取序号
+        Integer elementCount = mapper.selectCount(new LambdaQueryWrapper<GroupElementEntity>()
+                .eq(GroupElementEntity::getGroupId, groupId)
+                .eq(GroupElementEntity::getElementType,ElementTypeEnum.findVal(elementCreate.getResource().getContent().getGeometry().getType())));
+
         Optional<GroupElementEntity> groupElementOpt = this.getEntityByElementId(elementCreate.getId());
 
         if (groupElementOpt.isPresent()) {
             return false;
         }
-        GroupElementEntity groupElement = this.createDtoConvertToEntity(elementCreate);
+        GroupElementEntity groupElement = this.createDtoConvertToEntity(elementFrom, elementCount, elementCreate);
         groupElement.setGroupId(groupId);
 
         boolean saveElement = mapper.insert(groupElement) > 0;
@@ -172,6 +177,7 @@ public class GroupElementServiceImpl implements IGroupElementService {
         return new MapGroupElement()
                 .setId(entity.getElementId())
                 .setName(entity.getElementName())
+                .setElementFrom(entity.getElementFrom())
                 .setCreateTime(entity.getCreateTime())
                 .setUpdateTime(entity.getUpdateTime())
                 .setResource(new ElementResource()
@@ -184,15 +190,18 @@ public class GroupElementServiceImpl implements IGroupElementService {
      * @param elementCreate
      * @return
      */
-    private GroupElementEntity createDtoConvertToEntity(CreateMapElementRequest elementCreate) {
+    private GroupElementEntity createDtoConvertToEntity(Integer elementFrom, Integer elementCnt, CreateMapElementRequest elementCreate) {
+
         ElementProperty properties = elementCreate.getResource().getContent().getProperties();
         return GroupElementEntity.builder()
                 .elementId(elementCreate.getId())
-                .elementName(elementCreate.getName())
+                //.elementName(elementCreate.getName())
+                .elementName(elementCreate.getResource().getUsername() + ++elementCnt)
                 .username(elementCreate.getResource().getUsername())
                 .elementType(ElementTypeEnum.findVal(elementCreate.getResource().getContent().getGeometry().getType()))
                 .clampToGround(properties.getClampToGround() != null && properties.getClampToGround())
                 .color(properties.getColor())
+                .elementFrom(elementFrom)
                 .build();
     }
 

+ 24 - 2
Backend/sample/src/main/java/com/dji/sample/map/service/impl/GroupServiceImpl.java

@@ -13,8 +13,10 @@ import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 import org.springframework.util.StringUtils;
 
+import java.time.LocalDateTime;
 import java.util.List;
 import java.util.Optional;
+import java.util.UUID;
 import java.util.stream.Collectors;
 
 /**
@@ -32,19 +34,39 @@ public class GroupServiceImpl implements IGroupService {
     @Autowired
     private IGroupElementService groupElementService;
 
+    private static final String PILOT_SHARE_LAYER = "默认文件夹";
+    private static final String DEFAULT_LAYER = "默认标注";
+    private static final String CUSTOM_FLIGHT_AREA = "自定义飞行范围";
+
     @Override
     public List<GetMapElementsResponse> getAllGroupsByWorkspaceId(String workspaceId, String groupId, Boolean isDistributed) {
-
+        createDefaultGroups(workspaceId);
         return mapper.selectList(
                 new LambdaQueryWrapper<GroupEntity>()
                         .eq(GroupEntity::getWorkspaceId, workspaceId)
                         .eq(StringUtils.hasText(groupId), GroupEntity::getGroupId, groupId)
-                        .eq(isDistributed != null, GroupEntity::getIsDistributed, isDistributed))
+                        .eq(isDistributed != null, GroupEntity::getIsDistributed, isDistributed)
+                        .eq(GroupEntity::getEnabled,true))
                 .stream()
                 .map(this::entityConvertToDto)
                 .collect(Collectors.toList());
     }
 
+    private void createDefaultGroups(String workspaceId) {
+        int count = mapper.selectCount(new LambdaQueryWrapper<GroupEntity>()
+                .eq(GroupEntity::getWorkspaceId, workspaceId));
+        if(count <= 0) {
+            //创建默认文件夹
+            mapper.insert(GroupEntity.builder().groupId(UUID.randomUUID().toString())
+                    .groupName(PILOT_SHARE_LAYER)
+                    .groupType(GroupTypeEnum.SHARED.getType())
+                    .workspaceId(workspaceId)
+                    .createTime(System.currentTimeMillis())
+                    .updateTime(System.currentTimeMillis())
+                    .build());
+        }
+    }
+
     @Override
     public Optional<GetMapElementsResponse> getCustomGroupByWorkspaceId(String workspaceId) {
         return Optional.ofNullable(mapper.selectOne(

+ 2 - 2
Backend/sample/src/main/java/com/dji/sample/map/service/impl/WorkspaceElementServiceImpl.java

@@ -45,8 +45,8 @@ public class WorkspaceElementServiceImpl implements IWorkspaceElementService {
     }
 
     @Override
-    public HttpResultResponse saveElement(String workspaceId, String groupId, CreateMapElementRequest elementCreate, boolean notify) {
-        boolean saveElement = groupElementService.saveElement(groupId, elementCreate);
+    public HttpResultResponse saveElement(String workspaceId, String groupId, Integer elementFrom, CreateMapElementRequest elementCreate, boolean notify) {
+        boolean saveElement = groupElementService.saveElement(groupId, elementFrom,elementCreate);
         if (!saveElement) {
             return HttpResultResponse.error("Failed to save the element.");
         }

+ 3 - 2
Backend/sample/src/main/java/com/dji/sample/media/service/impl/FileServiceImpl.java

@@ -368,7 +368,8 @@ public class FileServiceImpl implements IFileService {
             }
             MediaTypeEnum mediaTypeEnum = convertMediaType(entity);
             String url = ossService.getObjectUrl(OssConfiguration.bucket, entity.getObjectKey()).toString();
-            String thumbnailURL = getThumbnailURL(entity);
+//            String thumbnailURL = getThumbnailURL(entity);
+            String thumbnailURL = null;
             builder.fileName(entity.getFileName())
                     .fileId(entity.getFileId())
                     .filePath(entity.getFilePath())
@@ -442,7 +443,7 @@ public class FileServiceImpl implements IFileService {
     private String getThumbnailObjectKey(String originFileName) {
         String[] nameSplit = originFileName.split(SPLIT_DOT);
         //缩略图路径
-        return T_PATH + nameSplit[0] + TAIL + DOT + PicExifUtil.JPG;
+        return T_PATH + nameSplit[0] + TAIL + PicExifUtil.JPG;
     }
 
     private MediaTypeEnum convertMediaType(MediaFileEntity entity) {