| | |
| | | import com.ard.common.core.exception.ServiceException; |
| | | import com.ard.common.core.exception.device.CameraSDKException; |
| | | import com.ard.common.core.utils.StringUtils; |
| | | import com.ard.common.core.utils.file.FileMultipartFile; |
| | | import com.ard.common.core.utils.file.MimeTypeUtils; |
| | | import com.ard.common.redis.service.RedisService; |
| | | import com.ard.system.api.RemoteFileService; |
| | |
| | | import com.ard.work.sdk.zlxd.netty.tcp.NettyTcpClient; |
| | | import com.ard.work.sdk.zlxd.utils.PTZ3DLocationConverter; |
| | | import com.ard.work.sdk.zlxd.utils.XmlUtils; |
| | | import com.ard.work.utils.file.MultipartFileUtil; |
| | | import com.ard.work.utils.gis.GisUtil; |
| | | import com.galaxy.sdk.RecordSdk; |
| | | import com.galaxy.sdk.SDKConfig; |
| | |
| | | log.warn("抓图失败,错误码:{},原因:{}", errorCode, errorDesc); |
| | | return ""; |
| | | } |
| | | |
| | | String base64Str = getRes.getParameters().getPicBuf(); |
| | | //存储到minio |
| | | if (base64Str == null || base64Str.isEmpty()) { |
| | | log.warn("Base64图片数据为空"); |
| | | return ""; |
| | | } |
| | | |
| | | // 处理 Base64 前缀(如果有 data:image/jpeg;base64, 这样的前缀) |
| | | String pureBase64 = base64Str; |
| | | if (base64Str.contains(",")) { |
| | | pureBase64 = base64Str.split(",")[1]; |
| | | } |
| | | |
| | | // 存储到minio |
| | | String objectName = cameraId + "_" + chanNo + ".jpeg"; |
| | | String url = ""; |
| | | MultipartFile multipartFile = MultipartFileUtil.base64ToMultipartFile(base64Str, objectName, |
| | | MimeTypeUtils.IMAGE_JPEG); |
| | | R<SysFile> sysFileR = remoteFileService.upload(multipartFile, bucketName, type); |
| | | if (sysFileR.getCode() == R.SUCCESS) { |
| | | url = sysFileR.getData().getUrl(); |
| | | log.debug("上传文件成功:{}", url); |
| | | File tempFile = null; |
| | | |
| | | try { |
| | | // Base64 解码 |
| | | byte[] imageBytes = Base64.getDecoder().decode(pureBase64); |
| | | |
| | | // 创建临时文件 |
| | | tempFile = File.createTempFile("snap_", ".jpeg"); |
| | | java.nio.file.Files.write(tempFile.toPath(), imageBytes); |
| | | |
| | | // 使用 FileMultipartFile 转换 |
| | | MultipartFile multipartFile = new FileMultipartFile(tempFile, objectName, MimeTypeUtils.IMAGE_JPEG); |
| | | |
| | | R<SysFile> sysFileR = remoteFileService.upload(multipartFile, bucketName, type); |
| | | if (sysFileR.getCode() == R.SUCCESS) { |
| | | url = sysFileR.getData().getUrl(); |
| | | log.debug("上传文件成功:{}", url); |
| | | } |
| | | |
| | | } catch (Exception e) { |
| | | log.error("上传失败", e); |
| | | } finally { |
| | | // 删除临时文件 |
| | | if (tempFile != null && tempFile.exists()) { |
| | | tempFile.delete(); |
| | | } |
| | | } |
| | | |
| | | return url; |
| | | } |
| | | |
| | |
| | | log.error("获取ptz异常:{}", ex.getMessage()); |
| | | return null; |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public PtzDto getPtzHigh(CameraCmd cmd) { |
| | | return getPtz(cmd); |
| | | } |
| | | |
| | | @Override |
| | |
| | | log.error("设置ptz异常:{}", ex.getMessage()); |
| | | return false; |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public Boolean setPtzHigh(CameraCmd cmd) { |
| | | return setPtz(cmd); |
| | | } |
| | | |
| | | @Override |
| | | public Boolean setPtzHighT(CameraCmd cmd) { |
| | | return setPtz(cmd); |
| | | } |
| | | |
| | | @Override |
| | |
| | | localFilePath = filePaths.get(0); |
| | | log.info("录像停止成功,本地文件: {}", localFilePath); |
| | | |
| | | // 3. 上传到 MinIO |
| | | // 校验文件是否存在 |
| | | java.io.File file = new java.io.File(localFilePath); |
| | | // 3. 校验文件是否存在 |
| | | File file = new File(localFilePath); |
| | | if (!file.exists()) { |
| | | log.error("录像文件不存在,无法上传: {}", localFilePath); |
| | | return ""; |
| | | } |
| | | |
| | | MultipartFile multipartFile = MultipartFileUtil.filePathToMultipartFile( |
| | | localFilePath, name, MediaType.APPLICATION_OCTET_STREAM_VALUE); // 建议使用具体的 MimeType |
| | | // 4. 使用 FileMultipartFile 转换(不用 MultipartFileUtil) |
| | | String objectName = cameraId + "_" + chanNo + ".mp4"; |
| | | String type = cmd.getType() == null ? "record" : cmd.getType(); |
| | | |
| | | R<SysFile> sysFileR = remoteFileService.upload(multipartFile, "record", cmd.getType()); |
| | | MultipartFile multipartFile = new FileMultipartFile(file, objectName, MimeTypeUtils.VIDEO_MP4); |
| | | |
| | | R<SysFile> sysFileR = remoteFileService.upload(multipartFile, "record", type); |
| | | |
| | | if (sysFileR.getCode() == R.SUCCESS && sysFileR.getData() != null) { |
| | | String url = sysFileR.getData().getUrl(); |
| | |
| | | |
| | | } catch (Exception ex) { |
| | | log.error("停止录像过程发生异常: {}", name, ex); |
| | | // 即使异常,SessionId 已经在第一步移除了,防止死锁 |
| | | // 但这里可能需要记录日志以便人工排查残留文件 |
| | | return ""; |
| | | } finally { |
| | | // 4. 【重要】清理本地临时文件 |
| | | // 无论成功还是失败,只要生成了本地文件,上传完后都应该删除,防止磁盘爆满 |
| | | // 5. 【重要】清理本地临时文件 |
| | | if (localFilePath != null) { |
| | | try { |
| | | java.nio.file.Files.deleteIfExists(java.nio.file.Paths.get(localFilePath)); |