From 9a086fc86dac1fe51cba8f6503723fe93bdf840b Mon Sep 17 00:00:00 2001 From: Jerry Yan <792602257@qq.com> Date: Wed, 3 Sep 2025 17:32:14 +0800 Subject: [PATCH] =?UTF-8?q?refactor(device):=20=E9=87=8D=E6=9E=84=E8=AE=BE?= =?UTF-8?q?=E5=A4=87=E9=85=8D=E7=BD=AE=E8=8E=B7=E5=8F=96=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 在 ViidController 中添加获取 DeviceConfigEntity 的逻辑 - 在 VideoPieceGetter 中使用 DeviceConfigManager 替代 DeviceConfigEntity - 优化设备配置参数的获取方式,使用 getBigDecimal 和 getString 方法 - 移除未使用的代码片段,提高代码可读性 --- .../basic/controller/viid/ViidController.java | 69 ++++++++++--------- .../com/ycwl/basic/task/VideoPieceGetter.java | 26 +++---- 2 files changed, 44 insertions(+), 51 deletions(-) diff --git a/src/main/java/com/ycwl/basic/controller/viid/ViidController.java b/src/main/java/com/ycwl/basic/controller/viid/ViidController.java index 72b069e..cb81a47 100644 --- a/src/main/java/com/ycwl/basic/controller/viid/ViidController.java +++ b/src/main/java/com/ycwl/basic/controller/viid/ViidController.java @@ -244,6 +244,7 @@ public class ViidController { continue; } DeviceConfigManager deviceConfig = deviceRepository.getDeviceConfigManager(device.getId()); + DeviceConfigEntity deviceConfigEntity = deviceRepository.getDeviceConfig(device.getId()); if (deviceConfig == null) { log.warn("设备配置不存在:" + deviceID); return new VIIDBaseResp( @@ -347,40 +348,40 @@ public class ViidController { MultipartFile _file = ImageUtils.base64ToMultipartFile(_subImage.getData()); ThreadPoolExecutor executor = getExecutor(scenicId); executor.execute(() -> { -// List cropConfigs = deviceConfig._getCropConfig(); -// for (DeviceCropConfig cropConfig : cropConfigs) { -// source.setId(SnowFlakeUtil.getLongId()); -// String filename = StorageUtil.joinPath(PHOTO_PATH, UUID.randomUUID() + "." + ext); -// MultipartFile _finalFile = _file; -// if (cropConfig.getCropType() == 1) { -// // 按固定位置截图 -// try { -// _finalFile = ImageUtils.cropImage(_file, cropConfig.getTargetX(), cropConfig.getTargetY(), cropConfig.getTargetWidth(), cropConfig.getTargetHeight()); -// } catch (IOException e) { -// log.error("裁切图片失败!", e); -// } catch (RasterFormatException e) { -// log.error("裁切图片出错!", e); -// } -// } else if (cropConfig.getCropType() == 2) { -// // 按人脸位置 -// try { -// int targetX = facePosition.getLtX() - (cropConfig.getTargetWidth() - facePosition.getWidth())/2; -// int targetY = facePosition.getLtY() - (cropConfig.getTargetHeight() - facePosition.getHeight())/2; -// _finalFile = ImageUtils.cropImage(_file, targetX, targetY, cropConfig.getTargetWidth(), cropConfig.getTargetHeight()); -// } catch (IOException e) { -// log.error("裁切图片失败!", e); -// } catch (RasterFormatException e) { -// log.error("裁切图片出错!", e); -// } -// facePosition.setImgHeight(cropConfig.getTargetHeight()); -// facePosition.setImgWidth(cropConfig.getTargetWidth()); -// } -// String _sourceUrl = scenicStorageAdapter.uploadFile(_finalFile, filename); -// scenicStorageAdapter.setAcl(StorageAcl.PUBLIC_READ, filename); -// source.setUrl(_sourceUrl); -// source.setPosJson(JacksonUtil.toJSONString(facePosition)); -// sourceMapper.add(source); -// } + List cropConfigs = deviceConfigEntity._getCropConfig(); + for (DeviceCropConfig cropConfig : cropConfigs) { + source.setId(SnowFlakeUtil.getLongId()); + String filename = StorageUtil.joinPath(PHOTO_PATH, UUID.randomUUID() + "." + ext); + MultipartFile _finalFile = _file; + if (cropConfig.getCropType() == 1) { + // 按固定位置截图 + try { + _finalFile = ImageUtils.cropImage(_file, cropConfig.getTargetX(), cropConfig.getTargetY(), cropConfig.getTargetWidth(), cropConfig.getTargetHeight()); + } catch (IOException e) { + log.error("裁切图片失败!", e); + } catch (RasterFormatException e) { + log.error("裁切图片出错!", e); + } + } else if (cropConfig.getCropType() == 2) { + // 按人脸位置 + try { + int targetX = facePosition.getLtX() - (cropConfig.getTargetWidth() - facePosition.getWidth())/2; + int targetY = facePosition.getLtY() - (cropConfig.getTargetHeight() - facePosition.getHeight())/2; + _finalFile = ImageUtils.cropImage(_file, targetX, targetY, cropConfig.getTargetWidth(), cropConfig.getTargetHeight()); + } catch (IOException e) { + log.error("裁切图片失败!", e); + } catch (RasterFormatException e) { + log.error("裁切图片出错!", e); + } + facePosition.setImgHeight(cropConfig.getTargetHeight()); + facePosition.setImgWidth(cropConfig.getTargetWidth()); + } + String _sourceUrl = scenicStorageAdapter.uploadFile(_finalFile, filename); + scenicStorageAdapter.setAcl(StorageAcl.PUBLIC_READ, filename); + source.setUrl(_sourceUrl); + source.setPosJson(JacksonUtil.toJSONString(facePosition)); + sourceMapper.add(source); + } }); } log.info("人脸信息及原图{}张入库成功!设备ID:{}", type14ImageList.size(), deviceID); diff --git a/src/main/java/com/ycwl/basic/task/VideoPieceGetter.java b/src/main/java/com/ycwl/basic/task/VideoPieceGetter.java index 8fd42a8..45476d2 100644 --- a/src/main/java/com/ycwl/basic/task/VideoPieceGetter.java +++ b/src/main/java/com/ycwl/basic/task/VideoPieceGetter.java @@ -257,23 +257,15 @@ public class VideoPieceGetter { private boolean doCut(Long deviceId, Long faceSampleId, Date baseTime, Task task) { DeviceEntity device = deviceRepository.getDevice(deviceId); - DeviceConfigEntity config = deviceRepository.getDeviceConfig(deviceId); + DeviceConfigManager config = deviceRepository.getDeviceConfigManager(deviceId); + DeviceConfigEntity dConfig = deviceRepository.getDeviceConfig(deviceId); SourceEntity source = sourceMapper.querySameVideo(faceSampleId, device.getId()); if (source == null || task.force) { - BigDecimal cutPre = BigDecimal.valueOf(5L); - BigDecimal cutPost = BigDecimal.valueOf(4L); - if (config != null) { - // 有配置 - if (config.getCutPre() != null) { - cutPre = config.getCutPre(); - } - if (config.getCutPost() != null) { - cutPost = config.getCutPost(); - } - } - IDeviceStorageOperator pieceGetter = DeviceFactory.getDeviceStorageOperator(device, config); + BigDecimal cutPre = config.getBigDecimal("cut_pre", BigDecimal.valueOf(5L)); + BigDecimal cutPost = config.getBigDecimal("cut_post", BigDecimal.valueOf(5L)); + IDeviceStorageOperator pieceGetter = DeviceFactory.getDeviceStorageOperator(device, dConfig); if (pieceGetter == null) { return false; } @@ -319,8 +311,8 @@ public class VideoPieceGetter { sourceEntity.setUrl(imgSource.getUrl()); sourceEntity.setPosJson(imgSource.getPosJson()); } - if (StringUtils.isNotBlank(config.getVideoCrop())) { - sourceEntity.setPosJson(config.getVideoCrop()); + if (StringUtils.isNotBlank(config.getString("video_crop"))) { + sourceEntity.setPosJson(config.getString("video_crop")); } sourceEntity.setVideoUrl(url); sourceEntity.setFaceSampleId(faceSampleId); @@ -348,8 +340,8 @@ public class VideoPieceGetter { videoReUploader.addTask(sourceEntity.getId()); } else { source.setVideoUrl(url); - if (StringUtils.isNotBlank(config.getVideoCrop())) { - source.setPosJson(config.getVideoCrop()); + if (StringUtils.isNotBlank(config.getString("video_crop"))) { + source.setPosJson(config.getString("video_crop")); } sourceMapper.update(source); videoReUploader.addTask(source.getId());