| | |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * minio文件删除-指定桶 |
| | | */ |
| | | @ApiOperation("minio文件删除-指定桶") |
| | | @DeleteMapping("/deleteMinio/{bucketName}") |
| | | public AjaxResult deleteKmzFile(@PathVariable String bucketName, |
| | | @RequestParam String filePath) { |
| | | try { |
| | | boolean result = ossService.deleteObject(bucketName, filePath); |
| | | if (result) { |
| | | return AjaxResult.success("文件删除成功"); |
| | | } else { |
| | | return AjaxResult.error("文件删除失败"); |
| | | } |
| | | } catch (Exception e) { |
| | | return AjaxResult.error("删除文件失败: " + e.getMessage()); |
| | | } |
| | | } |
| | | } |
| | |
| | | @Override |
| | | public Boolean deleteObject(String bucket, String objectKey) { |
| | | try { |
| | | client.removeObject(RemoveObjectArgs.builder().bucket(bucket).object(objectKey).build()); |
| | | } catch (MinioException | NoSuchAlgorithmException | IOException | InvalidKeyException e) { |
| | | log.error("Failed to delete file."); |
| | | e.printStackTrace(); |
| | | // 检查文件是否存在 |
| | | client.statObject(StatObjectArgs.builder() |
| | | .bucket(bucket) |
| | | .object(objectKey) |
| | | .build()); |
| | | |
| | | // 文件存在,执行删除 |
| | | client.removeObject(RemoveObjectArgs.builder() |
| | | .bucket(bucket) |
| | | .object(objectKey) |
| | | .build()); |
| | | |
| | | log.info("成功删除文件: {}/{}", bucket, objectKey); |
| | | return true; |
| | | } catch (ErrorResponseException e) { |
| | | // 文件不存在的情况 |
| | | log.warn("文件不存在: {}/{}", bucket, objectKey); |
| | | return false; |
| | | } catch (Exception e) { |
| | | log.error("删除文件失败: {}/{}", bucket, objectKey, e); |
| | | throw new RuntimeException("删除文件失败: " + e.getMessage(), e); |
| | | } |
| | | return true; |
| | | } |
| | | |
| | | @Override |
| | |
| | | import java.util.List; |
| | | import com.ard.common.utils.DateUtils; |
| | | import com.ard.common.utils.uuid.IdUtils; |
| | | import com.ard.oss.service.impl.OssServiceContext; |
| | | import com.ard.route.domain.route.ArdRouteInformation; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | |
| | | |
| | | @Autowired |
| | | private ArdRouteInformationMapper ardRouteInformationMapper; |
| | | |
| | | @Autowired |
| | | private OssServiceContext ossService; |
| | | |
| | | /** |
| | | * 查询航线(kmz) |
| | |
| | | */ |
| | | @Override |
| | | public int deleteArdRouteInformationByIds(String[] ids) { |
| | | // 删除航线(kmz)文件 |
| | | for (String id : ids) { |
| | | ArdRouteInformation information = ardRouteInformationMapper.selectArdRouteInformationById(id); |
| | | ossService.deleteObject("kmz", information.getUpPath()); |
| | | } |
| | | return ardRouteInformationMapper.deleteArdRouteInformationByIds(ids); |
| | | } |
| | | |