新增DB模块,将DB文件数据导入数据库,DB文件数据生成航线。新增成果展示,对图斑成果进行上传和删除。
17 files modified
5 files added
1 files deleted
| | |
| | | mediaFileEntity.setUserId(claims.getId()); |
| | | return ResponseResult.success(fileService.updateMediaFile(workspaceId, mediaFileEntity)); |
| | | } |
| | | @DeleteMapping("/{workspace_id}/deleteFile") |
| | | |
| | | public ResponseResult deleteFile(@PathVariable(name = "workspace_id") String workspaceId, @RequestParam String fileId) { |
| | | int count=fileService.deleteMedia(workspaceId, fileId); |
| | | if(count==0){ |
| | | return ResponseResult.error("删除失败"); |
| | | } |
| | | return ResponseResult.success(); |
| | | } |
| | | |
| | | |
| | | /** |
| | |
| | | * @return |
| | | */ |
| | | Boolean updateMediaFile(String workspaceId, MediaFileEntity mediaFileEntity); |
| | | |
| | | int deleteMedia(String workspaceId, String fileId); |
| | | } |
| | |
| | | return new PaginationData<MediaFileEntity>(records, new Pagination(pageData)); |
| | | } |
| | | |
| | | public int deleteMedia(String workspaceId, String fileId) { |
| | | int count=mapper.delete(new LambdaUpdateWrapper<MediaFileEntity>().eq(MediaFileEntity::getFileId, fileId) |
| | | .eq(MediaFileEntity::getWorkspaceId, workspaceId)); |
| | | return count; |
| | | } |
| | | @Override |
| | | public URL getObjectUrl(String workspaceId, String fileId) { |
| | | Optional<MediaFileEntity> mediaFileOpt = getMediaByFileId(workspaceId, fileId); |
| | |
| | | import com.dji.sample.patches.model.Param.PatchesParam; |
| | | import com.dji.sample.patches.model.entity.LotInfo; |
| | | import com.dji.sample.patches.service.GetPatchesService; |
| | | import com.dji.sample.patches.service.ShpToDataSourceService; |
| | | import com.dji.sample.patches.service.impl.ShpToDataSourceServiceImpl; |
| | | import com.dji.sample.territory.service.impl.TbDkjbxxServiceImpl; |
| | | import com.dji.sample.wayline.model.entity.WaylineFileEntity; |
| | | import com.dji.sample.wayline.service.IWaylineFileService; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | |
| | | import java.net.URL; |
| | | import java.sql.SQLException; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | import static com.dji.sample.component.AuthInterceptor.TOKEN_CLAIM; |
| | |
| | | @Autowired |
| | | private GetPatchesService getPatchesService; |
| | | @Autowired |
| | | private ShpToDataSourceServiceImpl shpToDataSourceServiceImpl; |
| | | private ShpToDataSourceService shpToDataSourceService; |
| | | @Autowired |
| | | private IWaylineFileService waylineFileService; |
| | | @Autowired |
| | | private TbDkjbxxServiceImpl tbDkjbxxService; |
| | | |
| | | //获取图斑信息 |
| | | /** |
| | | * 根据workspaceId获取图斑列表信息 |
| | | * |
| | | * @param page |
| | | * @param pageSize |
| | | * @param workspaceId |
| | | * @return |
| | | */ |
| | | @GetMapping("/listPatches") |
| | | @SysLogAnnotation(operModul = "图斑", operType = "查询", operDesc = "查询图斑的全部信息") |
| | | public ResponseResult<PaginationData<LotInfo>> page(@RequestParam Integer page, |
| | |
| | | PaginationData<LotInfo> data = getPatchesService.limitGet(param); |
| | | return ResponseResult.success(data); |
| | | } |
| | | //清空图斑文件 |
| | | |
| | | /** |
| | | * 删除图斑信息 |
| | | * 本接口不需要接收任何参数,调用成功后会删除相应的补丁信息。 |
| | | * |
| | | * @return 返回操作结果,如果操作成功,则返回一个成功的响应结果。 |
| | | */ |
| | | @DeleteMapping("/deletePatches") |
| | | public ResponseResult del() { |
| | | getPatchesService.delPatches(); |
| | | return ResponseResult.success(); |
| | | } |
| | | //根据dkbh获取图斑图片 |
| | | |
| | | /** |
| | | * 根据图斑的地块编号获取相对应音视频 |
| | | * |
| | | * @param page |
| | | * @param pageSize |
| | | * @param workspaceId |
| | | * @param dkbh |
| | | * @return |
| | | */ |
| | | @GetMapping("/listPhoto") |
| | | public ResponseResult<PaginationData<MediaFileEntity>> GetPatchesPhoto(@RequestParam(name = "page", defaultValue = "1") Integer page, |
| | | @RequestParam(name = "page_size", defaultValue = "10") Integer pageSize, |
| | |
| | | return ResponseResult.error("未匹配到相关图片"); // 返回错误信息,可以根据实际情况自定义 |
| | | } |
| | | } |
| | | //上传图斑文件并返回航线 |
| | | |
| | | /** |
| | | * 上传图斑文件,解析文件并入库,再生成航线并返回 |
| | | * |
| | | * @param file |
| | | * @param workspaceId |
| | | * @param waylineName |
| | | * @param airportLat |
| | | * @param airportLon |
| | | * @param request |
| | | * @return |
| | | * @throws Exception |
| | | */ |
| | | @PostMapping("/uploadLot") |
| | | public ResponseResult getGeo(@RequestParam("file") MultipartFile file, |
| | | @RequestParam String workspaceId, |
| | |
| | | @RequestParam double airportLat, |
| | | @RequestParam double airportLon, |
| | | HttpServletRequest request) throws Exception { |
| | | MultipartFile multipartFile = shpToDataSourceServiceImpl.insertGeo(file, workspaceId, waylineName, airportLat, airportLon); |
| | | MultipartFile multipartFile = shpToDataSourceService.insertGeo(file, workspaceId, waylineName, airportLat, airportLon); |
| | | CustomClaim customClaim = (CustomClaim) request.getAttribute(TOKEN_CLAIM); |
| | | String creator = customClaim.getUsername(); |
| | | waylineFileService.importKmzFileBack(multipartFile, workspaceId, creator); |
| | |
| | | throw new RuntimeException(e); |
| | | } |
| | | return ResponseResult.success(infoMap); |
| | | // return ResponseResult.success(MinioUrlUtils.getUrl(url)); |
| | | } |
| | | } |
| | |
| | | import com.dji.sample.patches.model.Param.PatchesParam; |
| | | import com.dji.sample.patches.model.entity.LotInfo; |
| | | |
| | | import java.util.List; |
| | | |
| | | public interface GetPatchesService { |
| | | /** |
| | | * 分页获取数据的接口实现。 |
| | | * @param param 包含分页信息和查询条件的工作空间ID。 |
| | | * @return 返回一个包含查询结果和分页信息的PaginationData对象。 |
| | | */ |
| | | PaginationData<LotInfo> limitGet(PatchesParam param); |
| | | void delPatches(); |
| | | |
| | | /** |
| | | * 根据条件获取照片的分页数据 |
| | | * |
| | | * @param param 包含分页信息和查询条件的参数对象 |
| | | * @param dkbh 查询条件中带有地块编号关键字,用于文件名的模糊搜索 |
| | | * @return 返回照片的分页数据,包括分页信息和照片实体列表 |
| | | */ |
| | | PaginationData<MediaFileEntity> getPhoto(PatchesParam param,String dkbh); |
| | | |
| | | /** |
| | | * 根据条件获取照片的分页数据 |
| | | * |
| | | * @param workspaceId 工作空间的ID,用于指定查询的工作空间 |
| | | * @param dkbh 查询条件中带有地块编号关键字,用于文件名的模糊搜索 |
| | | * @return 返回照片的分页数据,包括分页信息和照片实体列表 |
| | | */ |
| | | List<MediaFileEntity> listPohto(String dkbh, String workspaceId); |
| | | |
| | | /** |
| | | * 根据地块编号和工作空间ID获取地块信息。 |
| | | * @param dkbh 地块编号,用于查询特定定单的地块信息。 |
| | | * @param workspaceId 工作空间ID,用于查询属于特定工作空间的地块信息。 |
| | | * @return 返回匹配给定地块编号和工作空间ID的地块信息对象。如果找不到匹配的记录,则返回null。 |
| | | */ |
| | | LotInfo getLotinfo(String dkbh,String workspaceId); |
| | | } |
| | |
| | | package com.dji.sample.patches.service; |
| | | |
| | | import com.dji.sample.patches.model.entity.LotInfo; |
| | | import com.dji.sample.territory.model.entity.TbDkjbxxEntity; |
| | | import com.dji.sample.wayline.model.dto.WaylineFileDTO; |
| | | import org.springframework.core.io.Resource; |
| | | import org.springframework.http.ResponseEntity; |
| | |
| | | import java.util.List; |
| | | |
| | | public interface ShpToDataSourceService { |
| | | |
| | | /** |
| | | * 上传图斑zip文件,解析内容入库,返回生成的航线 |
| | | * @param file 图斑文件 |
| | | * @param workspaceId 工作空间 |
| | | * @param waylineName 航线名 |
| | | * @param airportLat 机场纬度 |
| | | * @param airportLon 机场经度 |
| | | * @return 图斑生成的航线 |
| | | * @throws Exception 处理过程中可能出现的任何异常 |
| | | */ |
| | | MultipartFile insertGeo(MultipartFile file , String workspaceId,String waylineName, double airportLat, double airportLon) throws Exception; |
| | | |
| | | /** |
| | | * 将List<TbDkjbxxEntity>类型的数据批量插入到数据库中。 |
| | | * @param list 需要保存到数据库的TbDkjbxxEntity实体列表。 |
| | | */ |
| | | void savaInMysql(List<TbDkjbxxEntity> list); |
| | | } |
| | |
| | | @Autowired |
| | | private IFileMapper fileMapper; |
| | | |
| | | /** |
| | | * 分页获取数据的接口实现。 |
| | | * @param param 包含分页信息和查询条件的工作空间ID。 |
| | | * @return 返回一个包含查询结果和分页信息的PaginationData对象。 |
| | | */ |
| | | @Override |
| | | public PaginationData<LotInfo> limitGet(PatchesParam param) { |
| | | Page<LotInfo> page = mapper.selectPage(new Page<LotInfo>(param.getPage(), param.getPageSize()), |
| | |
| | | public void delPatches() { |
| | | mapper.delete(null); |
| | | } |
| | | |
| | | /** |
| | | * 根据条件获取照片的分页数据 |
| | | * |
| | | * @param param 包含分页信息和查询条件的参数对象 |
| | | * @param dkbh 查询条件中带有地块编号关键字,用于文件名的模糊搜索 |
| | | * @return 返回照片的分页数据,包括分页信息和照片实体列表 |
| | | */ |
| | | @Override |
| | | public PaginationData<MediaFileEntity> getPhoto(PatchesParam param,String dkbh) { |
| | | Page<MediaFileEntity> page=fileMapper.selectPage(new Page<MediaFileEntity>(param.getPage(), param.getPageSize()), |
| | |
| | | .collect(Collectors.toList()); |
| | | return new PaginationData<MediaFileEntity>(records, new Pagination(page)); |
| | | } |
| | | /** |
| | | * 根据条件获取照片的分页数据 |
| | | * |
| | | * @param workspaceId 工作空间的ID,用于指定查询的工作空间 |
| | | * @param dkbh 查询条件中带有地块编号关键字,用于文件名的模糊搜索 |
| | | * @return 返回照片的分页数据,包括分页信息和照片实体列表 |
| | | */ |
| | | public List<MediaFileEntity> listPohto(String dkbh,String workspaceId){ |
| | | return fileMapper.selectList(new LambdaQueryWrapper<MediaFileEntity>().like(MediaFileEntity::getFileName, "%" + dkbh + "%") |
| | | .eq(MediaFileEntity::getWorkspaceId,workspaceId)); |
| | | } |
| | | /** |
| | | * 根据地块编号和工作空间ID获取地块信息。 |
| | | * @param dkbh 地块编号,用于查询特定定单的地块信息。 |
| | | * @param workspaceId 工作空间ID,用于查询属于特定工作空间的地块信息。 |
| | | * @return 返回匹配给定地块编号和工作空间ID的地块信息对象。如果找不到匹配的记录,则返回null。 |
| | | */ |
| | | public LotInfo getLotinfo(String dkbh,String workspaceId) { |
| | | return mapper.selectOne(new LambdaQueryWrapper<LotInfo>().eq(LotInfo::getDkbh, dkbh) |
| | | .eq(LotInfo::getWorkspaceId, workspaceId)); |
| | | } |
| | | } |
| | |
| | | import com.dji.sample.patches.utils.ShapeFileUtil; |
| | | import com.dji.sample.patches.xml.mode.XMLTemplateModel; |
| | | import com.dji.sample.patches.xml.utils.CreateWaylineFileUtils; |
| | | import com.dji.sample.territory.model.entity.TbDkjbxxEntity; |
| | | import com.dji.sample.wayline.service.IWaylineFileService; |
| | | import org.locationtech.jts.geom.Coordinate; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | |
| | | import java.io.File; |
| | |
| | | |
| | | @Autowired |
| | | private PatchesConfigPojo patchesConfigPojo; |
| | | |
| | | @Transactional |
| | | public MultipartFile insertGeo(MultipartFile file, String workspaceId, String waylineName, double airportLat, double airportLon) throws Exception { |
| | | List<LotInfo> list = new ArrayList<>(); |
| | | File file1 = MultipartFileTOFileUtil.multipartFile2File(file, patchesConfigPojo.getUnzip()); |
| | |
| | | String destKMZFile = patchesConfigPojo.getDestKMZFile() + waylineName + ".kmz"; // 输出的KMZ文件路径 |
| | | zipFolder(patchesConfigPojo.getSourceDir(), destKMZFile); |
| | | multipartFile = convert(new File(destKMZFile)); |
| | | MultipartFileTOFileUtil.deleteFile(file1); |
| | | return multipartFile; |
| | | } |
| | | @Transactional |
| | | public void savaInMysql(List<TbDkjbxxEntity> list){ |
| | | for (int i = 0; i <list.size() ; i++) { |
| | | LotInfo lotInfo = new LotInfo(); |
| | | lotInfo=dbConvertToEntity(list.get(i)); |
| | | mapper.insert(lotInfo); |
| | | } |
| | | } |
| | | /** |
| | | * 将SQlite数据库中DKJBXX对象转换为LotInfo对象。 |
| | | * @param file 需要转换的DKJBXX对象。 |
| | | * @return 返回一个构建好的LotInfo对象,包含从数据库实体中转换来的信息。 |
| | | */ |
| | | private LotInfo dbConvertToEntity(TbDkjbxxEntity file) { |
| | | LotInfo.LotInfoBuilder builder = LotInfo.builder(); |
| | | if (file != null) { |
| | | builder.bsm(file.getBsm()) |
| | | .bz(file.getBz()) |
| | | .dkmj(file.getDkmj()) |
| | | .dkmc(file.getDkmc()) |
| | | .dkbh(file.getDkbh()) |
| | | .xmc(file.getXmc()) |
| | | .xzb(file.getXzb()) |
| | | .sfbhzdk(file.getSfbhzdk()) |
| | | .sjlx(file.getSjlx()) |
| | | .dkfw(file.getDkfw()) |
| | | .xzqdm(file.getXzqdm()) |
| | | .yzb(file.getYzb()) |
| | | .kzxx(file.getKzxx()) |
| | | .dklx(file.getDklx()) |
| | | .build(); |
| | | } |
| | | return builder.build(); |
| | | } |
| | | } |
| | | |
| | | |
| | |
| | | package com.dji.sample.patches.utils; |
| | | |
| | | import com.dji.sample.patches.config.pojo.PatchesConfigPojo; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.mock.web.MockMultipartFile; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | |
| | |
| | | import java.util.UUID; |
| | | |
| | | public class MultipartFileTOFileUtil { |
| | | |
| | | |
| | | /** |
| | | * MultiparFile转File |
| | | * @param multipartFile |
| | |
| | | * @return |
| | | */ |
| | | public static File multipartFile2File(MultipartFile multipartFile, String unzipPath) { |
| | | String tmpFileDir = null; |
| | | // 创建临时文件 |
| | | String randomFileName = UUID.randomUUID().toString(); |
| | | tmpFileDir = unzipPath + randomFileName; |
| | | String tmpFileDir = unzipPath + randomFileName; |
| | | File file = new File(tmpFileDir); |
| | | InputStream inputStream = null; |
| | | FileOutputStream outputStream = null; |
| | | try { |
| | | // 获取文件输入流 |
| | | inputStream = multipartFile.getInputStream(); |
| | | |
| | | if (!file.exists()) { |
| | | file.createNewFile(); |
| | | } |
| | |
| | | } catch (Exception e) { |
| | | throw new RuntimeException(e); |
| | | } |
| | | ZipUtil.deleteFiles(tmpFileDir); |
| | | return file; |
| | | } |
| | | |
| | | //File转MultiparFile |
| | | public static MultipartFile convert(File file) throws IOException { |
| | | FileInputStream input = new FileInputStream(file); |
| | | MultipartFile multipartFile = new MockMultipartFile("file", |
| | | file.getName(), "application/octet-stream", input); |
| | | return multipartFile; |
| | | } |
| | | |
| | | /** |
| | | * 将文件转换为MultipartFile类型。 |
| | | * @param file 需要转换的文件对象,不可为null。 |
| | | * @throws IOException 如果在读取文件时发生错误,则抛出IOException。 |
| | | */ |
| | | public static void deleteFile(File file) { |
| | | if (file.exists()) { |
| | | file.delete(); |
| | | } |
| | | } |
| | | } |
| | |
| | | } |
| | | return list; |
| | | } |
| | | |
| | | /** |
| | | * @param filePath 临时文件的删除 |
| | | * 删除文件夹里面子目录 |
| | | * 再删除文件夹 |
| | | */ |
| | | public static void deleteFiles(String filePath) { |
| | | File file = new File(filePath); |
| | | if ((!file.exists()) || (!file.isDirectory())) { |
| | | |
| | | return; |
| | | } |
| | | String[] tempList = file.list(); |
| | | File temp = null; |
| | | for (int i = 0; i < tempList.length; i++) { |
| | | if (filePath.endsWith(File.separator)) { |
| | | temp = new File(filePath + tempList[i]); |
| | | } else { |
| | | temp = new File(filePath + File.separator + tempList[i]); |
| | | } |
| | | if (temp.isFile()) { |
| | | temp.delete(); |
| | | } |
| | | if (temp.isDirectory()) { |
| | | deleteFiles(filePath + "\\" + tempList[i]); |
| | | } |
| | | } |
| | | // 空文件的删除 |
| | | file.delete(); |
| | | } |
| | | |
| | | // 定义一个公共的静态方法zipFolder,用于压缩文件夹 |
| | | // 参数sourceFolderPath是源文件夹的路径,zipFilePath是压缩后的zip文件路径 |
| | | public static boolean zipFolder(String sourceFolderPath, String zipFilePath) { |
| | |
| | | package com.dji.sample.territory.controller; |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.dji.sample.common.model.CustomClaim; |
| | | import com.dji.sample.common.model.PaginationData; |
| | | import com.dji.sample.common.model.ResponseResult; |
| | | import com.dji.sample.common.util.MinioUrlUtils; |
| | | import com.dji.sample.log.model.entity.DroneFlightLogEntity; |
| | | import com.dji.sample.media.model.MediaFileEntity; |
| | | import com.dji.sample.patches.dao.GetPatchesMapper; |
| | | import com.dji.sample.patches.model.Param.PatchesParam; |
| | | import com.dji.sample.patches.model.entity.LotInfo; |
| | | import com.dji.sample.patches.service.GetPatchesService; |
| | | import com.dji.sample.patches.service.ShpToDataSourceService; |
| | | import com.dji.sample.patches.utils.GeoToolsUtil; |
| | | import com.dji.sample.patches.utils.MultipartFileTOFileUtil; |
| | | import com.dji.sample.patches.xml.mode.XMLTemplateModel; |
| | | import com.dji.sample.patches.xml.utils.CreateWaylineFileUtils; |
| | | import com.dji.sample.territory.model.entity.TbDkjbxxEntity; |
| | | import com.dji.sample.territory.service.ITbDkjbxxService; |
| | | import com.dji.sample.territory.service.ITbFJService; |
| | | import com.dji.sample.wayline.model.entity.WaylineFileEntity; |
| | | import com.dji.sample.wayline.service.IWaylineFileService; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.locationtech.jts.geom.Coordinate; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.web.bind.annotation.GetMapping; |
| | | import org.springframework.web.bind.annotation.RequestMapping; |
| | | import org.springframework.web.bind.annotation.RequestParam; |
| | | import org.springframework.web.bind.annotation.RestController; |
| | | import org.springframework.web.bind.annotation.*; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import java.io.File; |
| | | import java.io.IOException; |
| | | import java.net.URL; |
| | | import java.sql.SQLException; |
| | | import java.util.Arrays; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | import static com.dji.sample.component.AuthInterceptor.TOKEN_CLAIM; |
| | | |
| | | /** |
| | | * @PROJECT_NAME: drone |
| | |
| | | |
| | | @Autowired |
| | | private ITbDkjbxxService tbDkjbxxService; |
| | | @Autowired |
| | | private ShpToDataSourceService service; |
| | | @Autowired |
| | | private IWaylineFileService waylineFileService; |
| | | |
| | | @GetMapping("/list") |
| | | public ResponseResult list() { |
| | |
| | | return ResponseResult.success(list); |
| | | } |
| | | |
| | | } |
| | | /** |
| | | * 上传文件并保存到数据库 |
| | | * @param file 需要上传的文件,通过multipart/form-data方式提交 |
| | | * @return 返回上传结果的ResponseResult对象,其中包含上传成功的消息 |
| | | */ |
| | | @PostMapping("/upload") |
| | | public ResponseResult<String> uploadFile(@RequestParam("file") MultipartFile file) { |
| | | tbDkjbxxService.uploadFile(file); |
| | | List<TbDkjbxxEntity> list = tbDkjbxxService.list(); |
| | | service.savaInMysql(list); |
| | | return tbDkjbxxService.uploadFile(file); |
| | | } |
| | | |
| | | @PostMapping("/uploadLot") |
| | | public ResponseResult getGeo(@RequestParam String workspaceId, |
| | | @RequestParam String waylineName, |
| | | @RequestParam double airportLat, |
| | | @RequestParam double airportLon, |
| | | HttpServletRequest request) throws Exception { |
| | | MultipartFile multipartFile = tbDkjbxxService.listFile(workspaceId, waylineName, airportLat, airportLon); |
| | | CustomClaim customClaim = (CustomClaim) request.getAttribute(TOKEN_CLAIM); |
| | | String creator = customClaim.getUsername(); |
| | | waylineFileService.importKmzFileBack(multipartFile, workspaceId, creator); |
| | | WaylineFileEntity entity = waylineFileService.selectByName(waylineName); |
| | | Map<String, String> infoMap = new HashMap<>(); |
| | | URL url = null; |
| | | try { |
| | | url = waylineFileService.getObjectUrl(workspaceId, entity.getWaylineId()); |
| | | infoMap.put("url", String.valueOf(MinioUrlUtils.getUrl(url))); |
| | | infoMap.put("waylineId", entity.getWaylineId()); |
| | | } catch (SQLException e) { |
| | | throw new RuntimeException(e); |
| | | } |
| | | return ResponseResult.success(infoMap); |
| | | } |
| | | } |
| New file |
| | |
| | | package com.dji.sample.territory.controller; |
| | | import com.dji.sample.common.model.ResponseResult; |
| | | import com.dji.sample.media.model.MediaFileEntity; |
| | | import com.dji.sample.patches.model.entity.LotInfo; |
| | | import com.dji.sample.patches.service.GetPatchesService; |
| | | import com.dji.sample.territory.model.entity.TbFjEntity; |
| | | import com.dji.sample.territory.service.ITbFJService; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.web.bind.annotation.PostMapping; |
| | | import org.springframework.web.bind.annotation.RequestMapping; |
| | | import org.springframework.web.bind.annotation.RestController; |
| | | import java.io.IOException; |
| | | import java.util.List; |
| | | |
| | | @RestController |
| | | @Slf4j |
| | | @RequestMapping("/territory/tbfj") |
| | | public class TbFjController { |
| | | |
| | | @Autowired |
| | | private ITbFJService tbFJService; |
| | | @Autowired |
| | | private GetPatchesService getPatches; |
| | | |
| | | @PostMapping("/insertDb") |
| | | public ResponseResult insertDb(String dkbh, String workspaceId) throws IOException { |
| | | List<MediaFileEntity> list = getPatches.listPohto(dkbh, workspaceId); |
| | | if(list.size()==0){ |
| | | return ResponseResult.error("未找到照片信息");} |
| | | LotInfo lotInfo = getPatches.getLotinfo(dkbh, workspaceId); |
| | | if(lotInfo==null){ |
| | | return ResponseResult.error("未找到图斑信息");} |
| | | TbFjEntity entity=tbFJService.insertData(list, lotInfo); |
| | | if (entity!=null){ |
| | | return ResponseResult.success("上传成功"); |
| | | } |
| | | return ResponseResult.error("上传失败"); |
| | | } |
| | | } |
| | |
| | | |
| | | import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
| | | import com.dji.sample.territory.model.entity.TbDkjbxxEntity; |
| | | import org.apache.ibatis.annotations.Mapper; |
| | | |
| | | /** |
| | | * @PROJECT_NAME: drone |
| | |
| | | * @USER: aix |
| | | * @DATE: 2024/4/10 11:18 |
| | | */ |
| | | @Mapper |
| | | public interface ITbDkjbxxMapper extends BaseMapper<TbDkjbxxEntity> { |
| | | } |
| New file |
| | |
| | | package com.dji.sample.territory.dao; |
| | | |
| | | import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
| | | import com.dji.sample.territory.model.entity.TbFjEntity; |
| | | import org.apache.ibatis.annotations.Mapper; |
| | | |
| | | @Mapper |
| | | public interface ITbFjMapper extends BaseMapper<TbFjEntity> { |
| | | } |
| | |
| | | |
| | | private String dklx; |
| | | |
| | | } |
| | | private String xzqdm; |
| | | |
| | | private String xmc; |
| | | |
| | | private String dkbh; |
| | | |
| | | private String dkmc; |
| | | |
| | | private Double dkmj; |
| | | |
| | | private String sfbhzdk; |
| | | |
| | | private Double xzb; |
| | | |
| | | private Double yzb; |
| | | |
| | | private String bz; |
| | | |
| | | private String kzxx; |
| | | |
| | | private String dkfw; |
| | | |
| | | private String sjlx; |
| | | } |
| New file |
| | |
| | | package com.dji.sample.territory.model.entity; |
| | | |
| | | import com.baomidou.mybatisplus.annotation.IdType; |
| | | import com.baomidou.mybatisplus.annotation.TableId; |
| | | import com.baomidou.mybatisplus.annotation.TableName; |
| | | import lombok.AllArgsConstructor; |
| | | import lombok.Builder; |
| | | import lombok.Data; |
| | | import lombok.NoArgsConstructor; |
| | | |
| | | @Data |
| | | @Builder |
| | | @NoArgsConstructor |
| | | @AllArgsConstructor |
| | | @TableName(value = "FJ") |
| | | public class TbFjEntity { |
| | | |
| | | |
| | | private String bsm; |
| | | |
| | | private String dklx; |
| | | |
| | | private String dkbsm; |
| | | |
| | | private String xzqdm; |
| | | |
| | | private byte[] fj; |
| | | |
| | | private String pssj; |
| | | |
| | | private Double xdgd; |
| | | |
| | | private Double jdgd; |
| | | |
| | | private Double longitude; |
| | | |
| | | private Double Latitude; |
| | | } |
| | |
| | | package com.dji.sample.territory.service; |
| | | |
| | | import com.baomidou.mybatisplus.extension.service.IService; |
| | | import com.dji.sample.common.model.ResponseResult; |
| | | import com.dji.sample.media.model.MediaFileEntity; |
| | | import com.dji.sample.patches.model.entity.LotInfo; |
| | | import com.dji.sample.territory.model.entity.TbDkjbxxEntity; |
| | | import com.dji.sample.territory.model.entity.TbFjEntity; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | |
| | | import java.io.IOException; |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * @PROJECT_NAME: drone |
| | |
| | | * @DATE: 2024/4/10 11:19 |
| | | */ |
| | | public interface ITbDkjbxxService extends IService<TbDkjbxxEntity> { |
| | | /** |
| | | * 上传DB文件并覆盖之前DB文件,自动读取数据到本地数据库 |
| | | * @param file |
| | | * @return |
| | | */ |
| | | ResponseResult<String> uploadFile(MultipartFile file); |
| | | MultipartFile listFile( String workspaceId,String waylineName, double airportLat, double airportLon) throws IOException; |
| | | |
| | | } |
| New file |
| | |
| | | package com.dji.sample.territory.service; |
| | | |
| | | import com.dji.sample.media.model.MediaFileEntity; |
| | | import com.dji.sample.patches.model.entity.LotInfo; |
| | | import com.dji.sample.territory.model.entity.TbFjEntity; |
| | | |
| | | import java.io.IOException; |
| | | import java.util.List; |
| | | |
| | | public interface ITbFJService { |
| | | /** |
| | | * 按照地块编号所对应的信息和音视频文件存入sqlite数据库 |
| | | * @param mediaFile |
| | | * @param lotInfo |
| | | * @return |
| | | * @throws IOException |
| | | */ |
| | | TbFjEntity insertData(List<MediaFileEntity> mediaFile, LotInfo lotInfo) throws IOException; |
| | | } |
| | |
| | | |
| | | import com.baomidou.dynamic.datasource.annotation.DS; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.dji.sample.common.model.ResponseResult; |
| | | import com.dji.sample.media.model.MediaFileEntity; |
| | | import com.dji.sample.patches.config.pojo.PatchesConfigPojo; |
| | | import com.dji.sample.patches.model.entity.LotInfo; |
| | | import com.dji.sample.patches.utils.GeoToolsUtil; |
| | | import com.dji.sample.patches.utils.MultipartFileTOFileUtil; |
| | | import com.dji.sample.patches.xml.mode.XMLTemplateModel; |
| | | import com.dji.sample.patches.xml.utils.CreateWaylineFileUtils; |
| | | import com.dji.sample.territory.dao.ITbDkjbxxMapper; |
| | | import com.dji.sample.territory.dao.ITbFjMapper; |
| | | import com.dji.sample.territory.model.entity.TbDkjbxxEntity; |
| | | import com.dji.sample.territory.model.entity.TbFjEntity; |
| | | import com.dji.sample.territory.service.ITbDkjbxxService; |
| | | import org.locationtech.jts.geom.Coordinate; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.util.FileCopyUtils; |
| | | import org.springframework.web.bind.annotation.PostMapping; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | |
| | | import java.io.*; |
| | | import java.net.HttpURLConnection; |
| | | import java.net.URL; |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | |
| | | import static com.dji.sample.patches.utils.MultipartFileTOFileUtil.convert; |
| | | import static com.dji.sample.patches.utils.ZipUtil.zipFolder; |
| | | |
| | | /** |
| | | * @PROJECT_NAME: drone |
| | |
| | | @Service |
| | | @DS("sqlite") |
| | | public class TbDkjbxxServiceImpl extends ServiceImpl<ITbDkjbxxMapper, TbDkjbxxEntity> implements ITbDkjbxxService { |
| | | } |
| | | private static final String RESOURCE_FILE_PATH = "DB/resource_db.db"; |
| | | @Autowired |
| | | private ITbDkjbxxMapper mapper; |
| | | @Autowired |
| | | private PatchesConfigPojo patchesConfigPojo; |
| | | |
| | | /** |
| | | * 上传DB文件并覆盖之前DB文件,自动读取数据到本地数据库 |
| | | * |
| | | * @param file |
| | | * @return |
| | | */ |
| | | public ResponseResult<String> uploadFile(MultipartFile file) { |
| | | if (file.isEmpty()) { |
| | | return ResponseResult.error("所上传的文件为空"); |
| | | } |
| | | try { |
| | | // 获取上传的文件输入流 |
| | | InputStream inputStream = file.getInputStream(); |
| | | // 创建输出流,将文件内容写入资源文件 |
| | | OutputStream outputStream = new FileOutputStream(RESOURCE_FILE_PATH); |
| | | byte[] buffer = new byte[1024]; |
| | | int bytesRead; |
| | | while ((bytesRead = inputStream.read(buffer)) != -1) { |
| | | outputStream.write(buffer, 0, bytesRead); |
| | | } |
| | | outputStream.close(); |
| | | inputStream.close(); |
| | | return ResponseResult.success("文件上传成功"); |
| | | } catch (IOException e) { |
| | | e.printStackTrace(); |
| | | return ResponseResult.error(e.getMessage()); // 将异常信息包含在响应中返回给客户端 |
| | | } |
| | | } |
| | | |
| | | public MultipartFile listFile(String workspaceId, String waylineName, double airportLat, double airportLon) throws IOException { |
| | | List<TbDkjbxxEntity> list = mapper.selectList(null); |
| | | List<LotInfo> info = dbConvertToEntity(list); |
| | | Coordinate[] coordinates = GeoToolsUtil.getRoutePointOrder(info, airportLat, airportLon); |
| | | XMLTemplateModel xmlModel = XMLTemplateModel.init(coordinates, info); |
| | | CreateWaylineFileUtils.createWaylineFile(xmlModel, patchesConfigPojo.getTemplate(), patchesConfigPojo.getTargetTemplate(), patchesConfigPojo.getWaylines(), patchesConfigPojo.getTargetWaylines()); |
| | | // 压缩文件夹中的内容 |
| | | String destKMZFile = patchesConfigPojo.getDestKMZFile() + waylineName + ".kmz"; // 输出的KMZ文件路径 |
| | | zipFolder(patchesConfigPojo.getSourceDir(), destKMZFile); |
| | | MultipartFile multipartFile = convert(new File(destKMZFile)); |
| | | return multipartFile; |
| | | } |
| | | |
| | | private List<LotInfo> dbConvertToEntity(List<TbDkjbxxEntity> list) { |
| | | List<LotInfo> infos =new ArrayList<>(); |
| | | for (TbDkjbxxEntity file : list) { |
| | | LotInfo.LotInfoBuilder builder = LotInfo.builder(); |
| | | if (file != null) { |
| | | builder.bsm(file.getBsm()) |
| | | .bz(file.getBz()) |
| | | .dkmj(file.getDkmj()) |
| | | .dkmc(file.getDkmc()) |
| | | .dkbh(file.getDkbh()) |
| | | .xmc(file.getXmc()) |
| | | .xzb(file.getXzb()) |
| | | .sfbhzdk(file.getSfbhzdk()) |
| | | .sjlx(file.getSjlx()) |
| | | .dkfw(file.getDkfw()) |
| | | .xzqdm(file.getXzqdm()) |
| | | .yzb(file.getYzb()) |
| | | .kzxx(file.getKzxx()) |
| | | .dklx(file.getDklx()) |
| | | .build(); |
| | | infos.add(builder.build()); |
| | | } |
| | | } |
| | | return infos; |
| | | } |
| | | public void insert(List<LotInfo> list) { |
| | | for (LotInfo lotInfo : list) { |
| | | TbDkjbxxEntity entity = new TbDkjbxxEntity(); |
| | | entity.setBsm(lotInfo.getBsm()); |
| | | entity.setDkbh(lotInfo.getDkbh()); |
| | | entity.setXzb(lotInfo.getXzb()); |
| | | entity.setYzb(lotInfo.getYzb()); |
| | | entity.setDkfw(lotInfo.getDkfw()); |
| | | mapper.insert(entity); |
| | | } |
| | | } |
| | | } |
| New file |
| | |
| | | package com.dji.sample.territory.service.impl; |
| | | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.baomidou.dynamic.datasource.annotation.DS; |
| | | import com.dji.sample.media.model.MediaFileEntity; |
| | | import com.dji.sample.patches.model.entity.LotInfo; |
| | | import com.dji.sample.territory.dao.ITbFjMapper; |
| | | import com.dji.sample.territory.model.entity.TbFjEntity; |
| | | import com.dji.sample.territory.service.ITbFJService; |
| | | import com.google.gson.JsonObject; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import java.io.*; |
| | | import java.net.HttpURLConnection; |
| | | import java.net.URL; |
| | | import java.util.List; |
| | | import java.util.UUID; |
| | | |
| | | @Service |
| | | @DS("sqlite") |
| | | public class TbFjServiceImpl implements ITbFJService { |
| | | @Autowired |
| | | private ITbFjMapper mapper; |
| | | |
| | | /** |
| | | * 按照地块编号所对应的信息和音视频文件存入sqlite数据库 |
| | | * |
| | | * @param mediaFile |
| | | * @param lotInfo |
| | | * @return |
| | | * @throws IOException |
| | | */ |
| | | public TbFjEntity insertData(List<MediaFileEntity> mediaFile, LotInfo lotInfo) throws IOException { |
| | | TbFjEntity tbFj = new TbFjEntity(); |
| | | for (int i = 0; i < mediaFile.size(); i++) { |
| | | MediaFileEntity file = mediaFile.get(i); |
| | | tbFj = dbConvertToEntity(file, lotInfo); |
| | | try { |
| | | mapper.insert(tbFj); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | return tbFj; |
| | | } |
| | | |
| | | /** |
| | | * 将Media和Lotinfo实体类转化为TbFjEntity实体类 |
| | | * |
| | | * @param mediaFile |
| | | * @param lotInfo |
| | | * @return |
| | | * @throws IOException |
| | | */ |
| | | private TbFjEntity dbConvertToEntity(MediaFileEntity mediaFile, LotInfo lotInfo) { |
| | | String jsonString = JSONObject.toJSONString(mediaFile.getMetadata()); |
| | | JSONObject jsonObject = JSONObject.parseObject(jsonString); |
| | | Double absoluteAltitude = jsonObject.getDouble("absoluteAltitude"); |
| | | Double relativeAltitude = jsonObject.getDouble("relativeAltitude"); |
| | | JSONObject shootPosition = jsonObject.getJSONObject("shootPosition"); |
| | | Double lat = shootPosition.getDouble("lat"); |
| | | Double lng = shootPosition.getDouble("lng"); |
| | | Long pssj = mediaFile.getCreateTime(); |
| | | String bsm= UUID.randomUUID().toString(); |
| | | String key = mediaFile.getObjectKey(); |
| | | String head = "http://dev.jxpskj.com:9000/cloud-bucket"; |
| | | String url = head + key; |
| | | byte[] FJ = downloadFileAsBytes(url); |
| | | TbFjEntity.TbFjEntityBuilder builder = TbFjEntity.builder(); |
| | | if (lotInfo != null){ |
| | | builder.bsm(bsm) |
| | | .dkbsm(lotInfo.getDkbh()) |
| | | .xzqdm(lotInfo.getXzqdm()) |
| | | .dklx(lotInfo.getDklx()) |
| | | .xdgd(relativeAltitude) |
| | | .jdgd(absoluteAltitude) |
| | | .Latitude(lat) |
| | | .longitude(lng) |
| | | .fj(FJ) |
| | | .pssj(String.valueOf(pssj)) |
| | | .build();} |
| | | else { |
| | | throw new IllegalArgumentException("未匹配到相关地块"); |
| | | } |
| | | return builder.build(); |
| | | } |
| | | |
| | | /** |
| | | * 将音视频文件转换成字节流 |
| | | * |
| | | * @param fileUrl |
| | | * @return |
| | | */ |
| | | public static byte[] downloadFileAsBytes(String fileUrl) { |
| | | ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); |
| | | |
| | | try { |
| | | URL url = new URL(fileUrl); |
| | | HttpURLConnection connection = (HttpURLConnection) url.openConnection(); |
| | | connection.setRequestMethod("GET"); |
| | | |
| | | try (InputStream inputStream = connection.getInputStream()) { |
| | | byte[] buffer = new byte[1024]; |
| | | int bytesRead; |
| | | while ((bytesRead = inputStream.read(buffer)) != -1) { |
| | | outputStream.write(buffer, 0, bytesRead); |
| | | } |
| | | } |
| | | |
| | | } catch (IOException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | |
| | | return outputStream.toByteArray(); |
| | | } |
| | | |
| | | } |
| | |
| | | password: yshb@123 |
| | | sqlite: |
| | | driver-class-name: org.sqlite.JDBC |
| | | url: jdbc:sqlite::resource:static/sqlite/resource_db.db |
| | | url: jdbc:sqlite:DB/resource_db.db |
| | | username: |
| | | password: |
| | | # url: jdbc:mysql://192.168.2.104:3306/drone_test?useSSL=false&allowPublicKeyRetrieval=true |
| | |
| | | password: jxpskj_2018 |
| | | sqlite: |
| | | driver-class-name: org.sqlite.JDBC |
| | | url: jdbc:sqlite::resource:static/sqlite/resource_db.db |
| | | url: jdbc:sqlite::/home/drone/server/sqlite/resource_db.db |
| | | username: |
| | | password: |
| | | # url: jdbc:mysql://182.108.40.114:3308/drone_zt_test?useSSL=false&allowPublicKeyRetrieval=true |