| | |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; |
| | | import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.dji.sample.common.model.Pagination; |
| | | import com.dji.sample.common.model.PaginationData; |
| | |
| | | import com.dji.sample.wayline.dao.IWaylineFileMapper; |
| | | import com.dji.sample.wayline.model.dto.KmzFileProperties; |
| | | import com.dji.sample.wayline.model.dto.WaylineFileDTO; |
| | | import com.dji.sample.wayline.model.dto.WaylineListDTO; |
| | | import com.dji.sample.wayline.model.entity.WaylineFileEntity; |
| | | import com.dji.sample.wayline.model.enums.WaylineTemplateTypeEnum; |
| | | import com.dji.sample.wayline.model.param.WaylineQueryParam; |
| | |
| | | public URL getObjectUrl(String workspaceId, String waylineId) throws SQLException { |
| | | Optional<WaylineFileDTO> waylineOpt = this.getWaylineByWaylineId(workspaceId, waylineId); |
| | | if (waylineOpt.isEmpty()) { |
| | | throw new SQLException(waylineId + " does not exist."); |
| | | throw new SQLException(waylineId + " 不存在"); |
| | | } |
| | | return ossService.getObjectUrl(OssConfiguration.bucket, waylineOpt.get().getObjectKey()); |
| | | } |
| | |
| | | if (!StringUtils.hasText(file.getSign())) { |
| | | try (InputStream object = ossService.getObject(OssConfiguration.bucket, metadata.getObjectKey())) { |
| | | if (object.available() == 0) { |
| | | throw new RuntimeException("The file " + metadata.getObjectKey() + |
| | | " does not exist in the bucket[" + OssConfiguration.bucket + "]."); |
| | | throw new RuntimeException("文件" + metadata.getObjectKey() + |
| | | " 在空间中不存在[" + OssConfiguration.bucket + "]."); |
| | | } |
| | | file.setSign(DigestUtils.md5DigestAsHex(object)); |
| | | } catch (IOException e) { |
| | |
| | | public void importKmzFile(MultipartFile file, String workspaceId, String creator) { |
| | | Optional<WaylineFileDTO> waylineFileOpt = validKmzFile(file); |
| | | if (waylineFileOpt.isEmpty()) { |
| | | throw new RuntimeException("The file format is incorrect."); |
| | | throw new RuntimeException("文件格式错误"); |
| | | } |
| | | |
| | | try { |
| | |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public List<WaylineListDTO> waylineList(String workspaceId) { |
| | | return new LambdaQueryChainWrapper<>(mapper).eq(WaylineFileEntity::getWorkspaceId, workspaceId) |
| | | .list().stream().map(r -> WaylineListDTO.builder().waylineFileId(r.getWaylineId()).name(r.getName()).build()) |
| | | .collect(Collectors.toList()); |
| | | |
| | | } |
| | | |
| | | private Optional<WaylineFileDTO> validKmzFile(MultipartFile file) { |
| | | String filename = file.getOriginalFilename(); |
| | | if (Objects.nonNull(filename) && !filename.endsWith(WAYLINE_FILE_SUFFIX)) { |
| | | throw new RuntimeException("The file format is incorrect."); |
| | | throw new RuntimeException("文件格式错误"); |
| | | } |
| | | try (ZipInputStream unzipFile = new ZipInputStream(file.getInputStream(), StandardCharsets.UTF_8)) { |
| | | |
| | |
| | | SAXReader reader = new SAXReader(); |
| | | Document document = reader.read(unzipFile); |
| | | if (!StandardCharsets.UTF_8.name().equals(document.getXMLEncoding())) { |
| | | throw new RuntimeException("The file encoding format is incorrect."); |
| | | throw new RuntimeException("文件编码格式错误"); |
| | | } |
| | | |
| | | Node droneNode = document.selectSingleNode("//" + KmzFileProperties.TAG_WPML_PREFIX + KmzFileProperties.TAG_DRONE_INFO); |
| | | Node payloadNode = document.selectSingleNode("//" + KmzFileProperties.TAG_WPML_PREFIX + KmzFileProperties.TAG_PAYLOAD_INFO); |
| | | if (Objects.isNull(droneNode) || Objects.isNull(payloadNode)) { |
| | | throw new RuntimeException("The file format is incorrect."); |
| | | throw new RuntimeException("文件格式错误"); |
| | | } |
| | | |
| | | String type = droneNode.valueOf(KmzFileProperties.TAG_WPML_PREFIX + KmzFileProperties.TAG_DRONE_ENUM_VALUE); |
| | |
| | | if (!StringUtils.hasText(type) || !StringUtils.hasText(subType) || |
| | | !StringUtils.hasText(payloadSubType) || !StringUtils.hasText(payloadType) || |
| | | !StringUtils.hasText(templateType)) { |
| | | throw new RuntimeException("The file format is incorrect."); |
| | | throw new RuntimeException("文件格式错误"); |
| | | } |
| | | |
| | | return Optional.of(WaylineFileDTO.builder() |
| | | .droneModelKey(String.format("%s-%s-%s", DeviceDomainEnum.SUB_DEVICE.getVal(), type, subType)) |
| | | .payloadModelKeys(List.of(String.format("%s-%s-%s",DeviceDomainEnum.PAYLOAD.getVal(), payloadType, payloadSubType))) |
| | | .objectKey(OssConfiguration.objectDirPrefix + File.separator + filename) |
| | | // .objectKey(OssConfiguration.objectDirPrefix + File.separator + filename) |
| | | .objectKey(OssConfiguration.objectDirPrefix + "/" + filename) |
| | | .name(filename.substring(0, filename.lastIndexOf(WAYLINE_FILE_SUFFIX))) |
| | | .sign(DigestUtils.md5DigestAsHex(file.getInputStream())) |
| | | .templateTypes(List.of(WaylineTemplateTypeEnum.find(templateType).map(WaylineTemplateTypeEnum::getVal).orElse(-1))) |