1.增加修改航线分组ID接口。
2.Minio格式优化。
3.分组管理查询列表优化。
4.航线信息增加航线类型字段。
5.修改航线(kmz)功能优化。
6.增加定制删除旧的文件名的文件,并添加新文件名的文件接口。
| | |
| | | return AjaxResult.error(e.getMessage()); |
| | | } |
| | | } |
| | | |
| | | } |
| | |
| | | return success(minioUploadResult); |
| | | } |
| | | |
| | | /** |
| | | * 修改航线分组ID |
| | | */ |
| | | @ApiOperation("修改航线分组ID") |
| | | @Log(title = "航线(kmz)", businessType = BusinessType.UPDATE) |
| | | @PutMapping("/updateFolderId/{id}/{folderId}") |
| | | public AjaxResult updateFolderId(@PathVariable("id") String id, |
| | | @PathVariable("folderId") String folderId) { |
| | | return toAjax(ardRouteInformationService.updateRouteInformationFolderId(id,folderId)); |
| | | } |
| | | |
| | | } |
| | |
| | | */ |
| | | public interface IOssService { |
| | | |
| | | String getOssType(); |
| | | public String getOssType(); |
| | | |
| | | /** |
| | | * Get temporary credentials. |
| | | * |
| | | * @return |
| | | */ |
| | | CredentialsDTO getCredentials(); |
| | | public CredentialsDTO getCredentials(); |
| | | |
| | | /** |
| | | * Get the address of the object based on the bucket name and the object name. |
| | |
| | | * @param objectKey object name |
| | | * @return download link |
| | | */ |
| | | URL getObjectUrl(String bucket, String objectKey); |
| | | public URL getObjectUrl(String bucket, String objectKey); |
| | | |
| | | /** |
| | | * Deletes the object in the storage bucket. |
| | |
| | | * @param objectKey |
| | | * @return |
| | | */ |
| | | Boolean deleteObject(String bucket, String objectKey); |
| | | public Boolean deleteObject(String bucket, String objectKey); |
| | | |
| | | /** |
| | | * Get the contents of an object. |
| | |
| | | * @param objectKey |
| | | * @return |
| | | */ |
| | | InputStream getObject(String bucket, String objectKey); |
| | | public InputStream getObject(String bucket, String objectKey); |
| | | |
| | | void putObject(String bucket, String objectKey, InputStream input); |
| | | public void putObject(String bucket, String objectKey, InputStream input); |
| | | |
| | | void putObject(String bucket, String objectKey, InputStream input, String contentType); |
| | | public void putObject(String bucket, String objectKey, InputStream input, String contentType); |
| | | |
| | | void createClient(); |
| | | public void createClient(); |
| | | |
| | | } |
| | |
| | | @Override |
| | | public Boolean deleteObject(String bucket, String objectKey) { |
| | | try { |
| | | client.removeObject(RemoveObjectArgs.builder().bucket(bucket).object(objectKey).build()); |
| | | client.removeObject(RemoveObjectArgs.builder() |
| | | .bucket(bucket) |
| | | .object(objectKey) |
| | | .build()); |
| | | } catch (MinioException | NoSuchAlgorithmException | IOException | InvalidKeyException e) { |
| | | log.error("Failed to delete file."); |
| | | e.printStackTrace(); |
| | |
| | | @Override |
| | | public InputStream getObject(String bucket, String objectKey) { |
| | | try { |
| | | GetObjectResponse object = client.getObject(GetObjectArgs.builder().bucket(bucket).object(objectKey).build()); |
| | | GetObjectResponse object = client.getObject(GetObjectArgs.builder() |
| | | .bucket(bucket) |
| | | .object(objectKey) |
| | | .build()); |
| | | return new ByteArrayInputStream(object.readAllBytes()); |
| | | } catch (ErrorResponseException | InsufficientDataException | InternalException | InvalidKeyException | InvalidResponseException | IOException | NoSuchAlgorithmException | ServerException | XmlParserException e) { |
| | | e.printStackTrace(); |
| | |
| | | @Override |
| | | public void putObject(String bucket, String objectKey, InputStream input) { |
| | | try { |
| | | client.statObject(StatObjectArgs.builder().bucket(bucket).object(objectKey).build()); |
| | | client.statObject(StatObjectArgs.builder() |
| | | .bucket(bucket) |
| | | .object(objectKey) |
| | | .build()); |
| | | throw new RuntimeException("The filename already exists."); |
| | | } catch (MinioException | InvalidKeyException | IOException | NoSuchAlgorithmException e) { |
| | | log.info("The file does not exist, start uploading."); |
| | |
| | | // 设置 partSize 为 10MB |
| | | long partSize = 10 * 1024 * 1024; |
| | | ObjectWriteResponse response = client.putObject( |
| | | PutObjectArgs.builder().bucket(bucket).object(objectKey).stream(input, -1, partSize).build()); |
| | | PutObjectArgs.builder() |
| | | .bucket(bucket) |
| | | .object(objectKey) |
| | | .stream(input, -1, partSize) |
| | | .build()); |
| | | log.info("Upload File: {}", response.etag()); |
| | | } catch (MinioException | IOException | InvalidKeyException | NoSuchAlgorithmException ex) { |
| | | log.error("Failed to upload File {}.", objectKey); |
| | |
| | | public void putObject(String bucket, String objectKey, InputStream input, String contentType) { |
| | | try { |
| | | // 检查文件是否已经存在 |
| | | client.statObject(StatObjectArgs.builder().bucket(bucket).object(objectKey).build()); |
| | | client.statObject(StatObjectArgs.builder() |
| | | .bucket(bucket) |
| | | .object(objectKey) |
| | | .build()); |
| | | throw new RuntimeException("The file already exists: " + objectKey); |
| | | } catch (ErrorResponseException e) { |
| | | // 如果文件不存在,则继续上传 |
| | |
| | | /** 分组ID */ |
| | | private String folderId; |
| | | |
| | | /** 航线类型 */ |
| | | private String routeType; |
| | | |
| | | /** 飞行器 */ |
| | | private String aircraft; |
| | | |
| | |
| | | |
| | | private Double upFileSize; |
| | | |
| | | private String data; |
| | | |
| | | } |
| | |
| | | package com.ard.route.mapper; |
| | | |
| | | import com.ard.route.domain.route.ArdRouteInformation; |
| | | import org.apache.ibatis.annotations.Param; |
| | | |
| | | import java.util.List; |
| | | |
| | |
| | | */ |
| | | public int deleteRouteInformationByFolderIds(String[] folderIds); |
| | | |
| | | /** |
| | | * 查询航线(kmz)列表 |
| | | * |
| | | * @param folderId 所属文件夹ID |
| | | * @return 航线(kmz)集合 |
| | | */ |
| | | public List<ArdRouteInformation> selectArdRouteInformationByFolderId(String folderId); |
| | | |
| | | /** |
| | | * 修改航线分组ID |
| | | * |
| | | * @param id ID |
| | | * @param folderId 分组ID |
| | | * @return 结果 |
| | | */ |
| | | public int updateRouteInformationFolderId(@Param("id") String id, @Param("folderId")String folderId); |
| | | |
| | | } |
| | |
| | | */ |
| | | public ArdRouteInformation selectArdRouteInformationByName(String name); |
| | | |
| | | /** |
| | | * 修改航线分组ID |
| | | * |
| | | * @param id ID |
| | | * @param folderId 分组ID |
| | | * @return 结果 |
| | | */ |
| | | public int updateRouteInformationFolderId(String id,String folderId); |
| | | |
| | | } |
| | |
| | | /** |
| | | * 编辑kmz文件 |
| | | */ |
| | | public String updateKmz(UavRouteReq uavRouteReq,String fileName); |
| | | public KmzResultVo updateKmz(UavRouteReq uavRouteReq,String fileName); |
| | | |
| | | /** |
| | | * 生成kmz文件(带航点) |
| | |
| | | */ |
| | | public KmzInfoVO parseKmz(String file); |
| | | |
| | | /** |
| | | * 编辑kmz文件 |
| | | * 定制:删除旧的文件名的文件,并添加新文件名的文件 |
| | | */ |
| | | public KmzResultVo updateKmzNew(UavRouteReq uavRouteReq, String oldFileName, String newFilePath) ; |
| | | |
| | | } |
| | |
| | | @Override |
| | | public ArdRouteFolder selectArdRouteFolderById(String id) { |
| | | ArdRouteFolder ardRouteFolder = ardRouteFolderMapper.selectArdRouteFolderById(id); |
| | | ArdRouteInformation ardRouteInformation = new ArdRouteInformation(); |
| | | ardRouteInformation.setFolderId(id); |
| | | ardRouteFolder.setArdRouteInformationLs(ardRouteInformationMapper.selectArdRouteInformationList(ardRouteInformation)); |
| | | ardRouteFolder.setArdRouteInformationLs(ardRouteInformationMapper.selectArdRouteInformationByFolderId(id)); |
| | | return ardRouteFolder; |
| | | } |
| | | |
| | |
| | | public List<ArdRouteFolder> selectArdRouteFolderList(ArdRouteFolder ardRouteFolder) { |
| | | List<ArdRouteFolder> list = ardRouteFolderMapper.selectArdRouteFolderList(ardRouteFolder); |
| | | for (ArdRouteFolder routeFolder : list) { |
| | | routeFolder.setArdRouteInformationLs(getArdRouteInformation(routeFolder.getId())); |
| | | routeFolder.setArdRouteInformationLs(ardRouteInformationMapper.selectArdRouteInformationByFolderId(routeFolder.getId())); |
| | | } |
| | | return list; |
| | | } |
| | | |
| | | /** |
| | | * 查询文件列表 |
| | | */ |
| | | private List<ArdRouteInformation> getArdRouteInformation(String folderId) { |
| | | ArdRouteInformation ardRouteInformation = new ArdRouteInformation(); |
| | | ardRouteInformation.setFolderId(folderId); |
| | | return ardRouteInformationMapper.selectArdRouteInformationList(ardRouteInformation); |
| | | } |
| | | |
| | | /** |
| | |
| | | ardRouteInformation.setFolderId("0"); |
| | | } |
| | | KmzResultVo kmzResult = routeService.buildKmz(ardRouteInformation.getUavRouteReq(), ardRouteInformation.getFileName()); |
| | | // 将KmzResult中的信息设置到ardRouteInformation中 |
| | | ardRouteInformation.setFileNameNew(kmzResult.getFileNameNew()); |
| | | ardRouteInformation.setMinioUpPath(kmzResult.getMinioUpPath()); |
| | | ardRouteInformation.setUpPath(kmzResult.getUpPath()); |
| | | ardRouteInformation.setUpFileSize(kmzResult.getUpFileSize()); |
| | | ardRouteInformationMapper.insertArdRouteInformation(ardRouteInformation); |
| | | ardRouteInformationMapper.insertArdRouteInformation(assembly(ardRouteInformation,kmzResult)); |
| | | return kmzResult.getUpPath(); |
| | | } |
| | | |
| | |
| | | @Override |
| | | public int updateArdRouteInformation(ArdRouteInformation ardRouteInformation) { |
| | | ardRouteInformation.setUpdateTime(DateUtils.getNowDate()); |
| | | return ardRouteInformationMapper.updateArdRouteInformation(ardRouteInformation); |
| | | KmzResultVo kmzResult = new KmzResultVo(); |
| | | // 获取源文件名字 |
| | | ArdRouteInformation route = ardRouteInformationMapper.selectArdRouteInformationById(ardRouteInformation.getId()); |
| | | if (route.getFileName().equals(ardRouteInformation.getFileName())) { |
| | | kmzResult = routeService.updateKmz(ardRouteInformation.getUavRouteReq(), ardRouteInformation.getFileName()); |
| | | }else { |
| | | kmzResult = routeService.updateKmzNew(ardRouteInformation.getUavRouteReq(), route.getFileName(),ardRouteInformation.getFileName()); |
| | | } |
| | | if ("更新航线kmz文件失败".equals(kmzResult.getData())) { |
| | | return 0; |
| | | } |
| | | return ardRouteInformationMapper.updateArdRouteInformation(assembly(ardRouteInformation,kmzResult)); |
| | | } |
| | | |
| | | //组装数据 |
| | | private ArdRouteInformation assembly(ArdRouteInformation information,KmzResultVo kmzResult){ |
| | | information.setFileNameNew(kmzResult.getFileNameNew()); |
| | | information.setMinioUpPath(kmzResult.getMinioUpPath()); |
| | | information.setUpPath(kmzResult.getUpPath()); |
| | | information.setUpFileSize(kmzResult.getUpFileSize()); |
| | | return information; |
| | | } |
| | | |
| | | /** |
| | |
| | | } |
| | | |
| | | /** |
| | | * 修改航线分组ID |
| | | * |
| | | * @param id ID |
| | | * @param folderId 分组ID |
| | | * @return 结果 |
| | | */ |
| | | @Override |
| | | public int updateRouteInformationFolderId(String id, String folderId) { |
| | | return ardRouteInformationMapper.updateRouteInformationFolderId(id, folderId); |
| | | } |
| | | |
| | | /** |
| | | * 数据新增航线信息 |
| | | */ |
| | | private void insertRouteInformation(ArdRouteInformation ardRouteInformation){ |
| | |
| | | * 编辑kmz文件 |
| | | */ |
| | | @Override |
| | | public String updateKmz(UavRouteReq uavRouteReq,String fileName){ |
| | | public KmzResultVo updateKmz(UavRouteReq uavRouteReq,String fileName){ |
| | | KmzResultVo result = new KmzResultVo(); |
| | | // 校验修改的文件是否存在 |
| | | ArdRouteInformation routeInformation = ardRouteInformationService.selectArdRouteInformationByName(fileName); |
| | | if ( routeInformation == null ){ |
| | | return "修改航线文件失败,请检查文件是否存在"; |
| | | result.setData("修改航线文件失败,请检查文件是否存在"); |
| | | return result; |
| | | } |
| | | |
| | | // 获取文件 |
| | | String minioUrl = routeInformation.getMinioUpPath(); |
| | | try (InputStream inputStream = ossService.getObject(kmzPath,minioUrl); |
| | |
| | | this.handleRouteUpdate(wpmlInfo, uavRouteReq, FileTypeConstants.WPML, kmlParams); |
| | | } |
| | | } |
| | | // 删除minio的文件 |
| | | |
| | | // 插入修改好的minio文件 |
| | | |
| | | return RouteFileUtils.buildKmz("更新航线kmz文件111111", kmlInfo, wpmlInfo, kmzPath); |
| | | // 删除文件 |
| | | ossService.deleteObject(kmzPath, minioUrl); |
| | | return buildKmzMethod(routeInformation.getFileName(), kmlInfo, wpmlInfo); |
| | | } catch (Exception e) { |
| | | return "更新航线kmz文件失败"; |
| | | e.printStackTrace(); |
| | | result.setData("更新航线kmz文件失败"); |
| | | return result; |
| | | } |
| | | } |
| | | |
| | |
| | | public KmzResultVo buildKmz(String fileName, KmlParams kmlParams) { |
| | | KmlInfo kmlInfo = buildKml(kmlParams); |
| | | KmlInfo wpmlInfo = buildWpml(kmlParams); |
| | | return buildKmz(fileName, kmlInfo, wpmlInfo); |
| | | return buildKmzMethod(fileName, kmlInfo, wpmlInfo); |
| | | } |
| | | |
| | | /** |
| | |
| | | * @param wpmlInfo wpml 文件信息 |
| | | * @return 本地文件路径 |
| | | */ |
| | | public KmzResultVo buildKmz(String fileName, KmlInfo kmlInfo, KmlInfo wpmlInfo) { |
| | | public KmzResultVo buildKmzMethod(String fileName, KmlInfo kmlInfo, KmlInfo wpmlInfo) { |
| | | XStream xStream = new XStream(new DomDriver()); |
| | | xStream.processAnnotations(KmlInfo.class); |
| | | xStream.addImplicitCollection(KmlActionGroup.class, "action"); |
| | |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | @Override |
| | | public KmzResultVo updateKmzNew(UavRouteReq uavRouteReq, String oldFile, String newFile) { |
| | | KmzResultVo result = new KmzResultVo(); |
| | | // 校验修改的文件是否存在 |
| | | ArdRouteInformation routeInformation = ardRouteInformationService.selectArdRouteInformationByName(oldFile); |
| | | if ( routeInformation == null ){ |
| | | result.setData("修改航线文件失败,请检查文件是否存在"); |
| | | return result; |
| | | } |
| | | |
| | | // 获取文件 |
| | | String minioUrl = routeInformation.getMinioUpPath(); |
| | | try (InputStream inputStream = ossService.getObject(kmzPath,minioUrl); |
| | | ArchiveInputStream archiveInputStream = new ZipArchiveInputStream(inputStream)){ |
| | | ArchiveEntry entry; |
| | | KmlInfo kmlInfo = new KmlInfo(); |
| | | KmlInfo wpmlInfo = new KmlInfo(); |
| | | KmlParams kmlParams = new KmlParams(); |
| | | while (!Objects.isNull(entry = archiveInputStream.getNextEntry())) { |
| | | String name = entry.getName(); |
| | | if (name.toLowerCase().endsWith(".kml")) { |
| | | kmlInfo = RouteFileUtils.parseKml(archiveInputStream); |
| | | buildKmlParams(kmlParams, kmlInfo); |
| | | this.handleRouteUpdate(kmlInfo, uavRouteReq, FileTypeConstants.KML, kmlParams); |
| | | } else if (name.toLowerCase().endsWith(".wpml")) { |
| | | wpmlInfo = RouteFileUtils.parseKml(archiveInputStream); |
| | | this.handleRouteUpdate(wpmlInfo, uavRouteReq, FileTypeConstants.WPML, kmlParams); |
| | | } |
| | | } |
| | | // 删除文件 |
| | | ossService.deleteObject(kmzPath, minioUrl); |
| | | return buildKmzMethod(newFile, kmlInfo, wpmlInfo); |
| | | } catch (Exception e) { |
| | | result.setData("更新航线kmz文件失败"); |
| | | return result; |
| | | } |
| | | } |
| | | |
| | | } |
| | |
| | | * @param wpmlInfo wpml 文件信息 |
| | | * @return 本地文件路径 |
| | | */ |
| | | public static String buildKmz(String fileName, KmlInfo kmlInfo, KmlInfo wpmlInfo, String kmzFilePath) { |
| | | public static String buildKmzA(String fileName, KmlInfo kmlInfo, KmlInfo wpmlInfo, String kmzFilePath) { |
| | | XStream xStream = new XStream(new DomDriver()); |
| | | xStream.processAnnotations(KmlInfo.class); |
| | | xStream.addImplicitCollection(KmlActionGroup.class, "action"); |
| | | xStream.addImplicitCollection(KmlPlacemark.class, "actionGroup"); |
| | | |
| | | String kml = XML_HEADER + xStream.toXML(kmlInfo); |
| | | String wpml = XML_HEADER + xStream.toXML(wpmlInfo); |
| | |
| | | <result property="createTime" column="create_time" /> |
| | | <result property="updateBy" column="update_by" /> |
| | | <result property="updateTime" column="update_time" /> |
| | | <!-- 关联 ArdRouteFile 对象 --> |
| | | <association property="ardRouteFile" |
| | | javaType="com.ard.route.domain.route.ArdRouteFile" |
| | | column="folder_id" |
| | | autoMapping="true" |
| | | select="selectArdRouteFile"> |
| | | </association> |
| | | </resultMap> |
| | | |
| | | <select id="selectArdRouteFile" resultType="com.ard.route.domain.route.ArdRouteFile"> |
| | | select * from ard_route_file where id = #{folderId} |
| | | </select> |
| | | |
| | | <sql id="selectArdRouteFolderVo"> |
| | | select id, |
| | |
| | | <result property="minioUpPath" column="minio_up_path" /> |
| | | <result property="upFileSize" column="up_file_size" /> |
| | | <result property="folderId" column="folder_id" /> |
| | | <result property="routeType" column="route_type" /> |
| | | <result property="aircraft" column="aircraft" /> |
| | | <result property="aircraftModel" column="aircraft_model" /> |
| | | <result property="createBy" column="create_by" /> |
| | |
| | | minio_up_path, |
| | | up_file_size, |
| | | folder_id, |
| | | route_type, |
| | | aircraft, |
| | | aircraft_model, |
| | | create_by, |
| | |
| | | <include refid="selectArdRouteInformationVo"/> |
| | | <where> |
| | | <if test="fileName != null and fileName != ''"> and file_name like concat('%', #{fileName}, '%')</if> |
| | | <if test="aircraft != null and aircraft != ''"> and aircraft = #{aircraft}</if> |
| | | <if test="aircraftModel != null and aircraftModel != ''"> and aircraft_model = #{aircraftModel}</if> |
| | | <if test="routeType != null and routeType != ''"> and route_type = #{routeType}</if> |
| | | <if test="upPath != null and upPath != ''"> and up_path = #{upPath}</if> |
| | | <if test="upFileSize != null "> and up_file_size = #{upFileSize}</if> |
| | | </where> |
| | |
| | | <if test="minioUpPath != null">minio_up_path,</if> |
| | | <if test="upFileSize != null">up_file_size,</if> |
| | | <if test="folderId != null">folder_id,</if> |
| | | <if test="routeType != null">route_type,</if> |
| | | <if test="aircraft != null">aircraft,</if> |
| | | <if test="aircraftModel != null">aircraft_model,</if> |
| | | <if test="createBy != null">create_by,</if> |
| | |
| | | <if test="minioUpPath != null">#{minioUpPath},</if> |
| | | <if test="upFileSize != null">#{upFileSize},</if> |
| | | <if test="folderId != null">#{folderId},</if> |
| | | <if test="routeType != null">#{routeType},</if> |
| | | <if test="aircraft != null">#{aircraft},</if> |
| | | <if test="aircraftModel != null">#{aircraftModel},</if> |
| | | <if test="createBy != null">#{createBy},</if> |
| | |
| | | <if test="minioUpPath != null">minio_up_path = #{minioUpPath},</if> |
| | | <if test="upFileSize != null">up_file_size = #{upFileSize},</if> |
| | | <if test="folderId != null">folder_id = #{folderId},</if> |
| | | <if test="routeType != null">route_type = #{routeType},</if> |
| | | <if test="aircraft != null">aircraft = #{aircraft},</if> |
| | | <if test="aircraftModel != null">aircraft_model = #{aircraftModel},</if> |
| | | <if test="createBy != null">create_by = #{createBy},</if> |
| | |
| | | </foreach> |
| | | </delete> |
| | | |
| | | <select id="selectArdRouteInformationByFolderId" parameterType="String" resultMap="ArdRouteInformationResult"> |
| | | <include refid="selectArdRouteInformationVo"/> |
| | | <where> |
| | | <if test="folderId != null "> and folder_id = #{folderId}</if> |
| | | </where> |
| | | </select> |
| | | |
| | | <update id="updateRouteInformationFolderId"> |
| | | update ard_route_information |
| | | <trim prefix="SET" suffixOverrides=","> |
| | | <if test="folderId != null">folder_id = #{folderId},</if> |
| | | </trim> |
| | | where id = #{id} |
| | | </update> |
| | | |
| | | </mapper> |