refactor(device): 重构设备配置获取逻辑

- 在 ViidController 中添加获取 DeviceConfigEntity 的逻辑
- 在 VideoPieceGetter 中使用 DeviceConfigManager 替代 DeviceConfigEntity
- 优化设备配置参数的获取方式,使用 getBigDecimal 和 getString 方法
- 移除未使用的代码片段,提高代码可读性
This commit is contained in:
2025-09-03 17:32:14 +08:00
parent 982e9180f1
commit 9a086fc86d
2 changed files with 44 additions and 51 deletions

View File

@@ -244,6 +244,7 @@ public class ViidController {
continue; continue;
} }
DeviceConfigManager deviceConfig = deviceRepository.getDeviceConfigManager(device.getId()); DeviceConfigManager deviceConfig = deviceRepository.getDeviceConfigManager(device.getId());
DeviceConfigEntity deviceConfigEntity = deviceRepository.getDeviceConfig(device.getId());
if (deviceConfig == null) { if (deviceConfig == null) {
log.warn("设备配置不存在:" + deviceID); log.warn("设备配置不存在:" + deviceID);
return new VIIDBaseResp( return new VIIDBaseResp(
@@ -347,40 +348,40 @@ public class ViidController {
MultipartFile _file = ImageUtils.base64ToMultipartFile(_subImage.getData()); MultipartFile _file = ImageUtils.base64ToMultipartFile(_subImage.getData());
ThreadPoolExecutor executor = getExecutor(scenicId); ThreadPoolExecutor executor = getExecutor(scenicId);
executor.execute(() -> { executor.execute(() -> {
// List<DeviceCropConfig> cropConfigs = deviceConfig._getCropConfig(); List<DeviceCropConfig> cropConfigs = deviceConfigEntity._getCropConfig();
// for (DeviceCropConfig cropConfig : cropConfigs) { for (DeviceCropConfig cropConfig : cropConfigs) {
// source.setId(SnowFlakeUtil.getLongId()); source.setId(SnowFlakeUtil.getLongId());
// String filename = StorageUtil.joinPath(PHOTO_PATH, UUID.randomUUID() + "." + ext); String filename = StorageUtil.joinPath(PHOTO_PATH, UUID.randomUUID() + "." + ext);
// MultipartFile _finalFile = _file; MultipartFile _finalFile = _file;
// if (cropConfig.getCropType() == 1) { if (cropConfig.getCropType() == 1) {
// // 按固定位置截图 // 按固定位置截图
// try { try {
// _finalFile = ImageUtils.cropImage(_file, cropConfig.getTargetX(), cropConfig.getTargetY(), cropConfig.getTargetWidth(), cropConfig.getTargetHeight()); _finalFile = ImageUtils.cropImage(_file, cropConfig.getTargetX(), cropConfig.getTargetY(), cropConfig.getTargetWidth(), cropConfig.getTargetHeight());
// } catch (IOException e) { } catch (IOException e) {
// log.error("裁切图片失败!", e); log.error("裁切图片失败!", e);
// } catch (RasterFormatException e) { } catch (RasterFormatException e) {
// log.error("裁切图片出错!", e); log.error("裁切图片出错!", e);
// } }
// } else if (cropConfig.getCropType() == 2) { } else if (cropConfig.getCropType() == 2) {
// // 按人脸位置 // 按人脸位置
// try { try {
// int targetX = facePosition.getLtX() - (cropConfig.getTargetWidth() - facePosition.getWidth())/2; int targetX = facePosition.getLtX() - (cropConfig.getTargetWidth() - facePosition.getWidth())/2;
// int targetY = facePosition.getLtY() - (cropConfig.getTargetHeight() - facePosition.getHeight())/2; int targetY = facePosition.getLtY() - (cropConfig.getTargetHeight() - facePosition.getHeight())/2;
// _finalFile = ImageUtils.cropImage(_file, targetX, targetY, cropConfig.getTargetWidth(), cropConfig.getTargetHeight()); _finalFile = ImageUtils.cropImage(_file, targetX, targetY, cropConfig.getTargetWidth(), cropConfig.getTargetHeight());
// } catch (IOException e) { } catch (IOException e) {
// log.error("裁切图片失败!", e); log.error("裁切图片失败!", e);
// } catch (RasterFormatException e) { } catch (RasterFormatException e) {
// log.error("裁切图片出错!", e); log.error("裁切图片出错!", e);
// } }
// facePosition.setImgHeight(cropConfig.getTargetHeight()); facePosition.setImgHeight(cropConfig.getTargetHeight());
// facePosition.setImgWidth(cropConfig.getTargetWidth()); facePosition.setImgWidth(cropConfig.getTargetWidth());
// } }
// String _sourceUrl = scenicStorageAdapter.uploadFile(_finalFile, filename); String _sourceUrl = scenicStorageAdapter.uploadFile(_finalFile, filename);
// scenicStorageAdapter.setAcl(StorageAcl.PUBLIC_READ, filename); scenicStorageAdapter.setAcl(StorageAcl.PUBLIC_READ, filename);
// source.setUrl(_sourceUrl); source.setUrl(_sourceUrl);
// source.setPosJson(JacksonUtil.toJSONString(facePosition)); source.setPosJson(JacksonUtil.toJSONString(facePosition));
// sourceMapper.add(source); sourceMapper.add(source);
// } }
}); });
} }
log.info("人脸信息及原图{}张入库成功!设备ID:{}", type14ImageList.size(), deviceID); log.info("人脸信息及原图{}张入库成功!设备ID:{}", type14ImageList.size(), deviceID);

View File

@@ -257,23 +257,15 @@ public class VideoPieceGetter {
private boolean doCut(Long deviceId, Long faceSampleId, Date baseTime, Task task) { private boolean doCut(Long deviceId, Long faceSampleId, Date baseTime, Task task) {
DeviceEntity device = deviceRepository.getDevice(deviceId); 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()); SourceEntity source = sourceMapper.querySameVideo(faceSampleId, device.getId());
if (source == null || task.force) { if (source == null || task.force) {
BigDecimal cutPre = BigDecimal.valueOf(5L); BigDecimal cutPre = config.getBigDecimal("cut_pre", BigDecimal.valueOf(5L));
BigDecimal cutPost = BigDecimal.valueOf(4L); BigDecimal cutPost = config.getBigDecimal("cut_post", BigDecimal.valueOf(5L));
if (config != null) { IDeviceStorageOperator pieceGetter = DeviceFactory.getDeviceStorageOperator(device, dConfig);
// 有配置
if (config.getCutPre() != null) {
cutPre = config.getCutPre();
}
if (config.getCutPost() != null) {
cutPost = config.getCutPost();
}
}
IDeviceStorageOperator pieceGetter = DeviceFactory.getDeviceStorageOperator(device, config);
if (pieceGetter == null) { if (pieceGetter == null) {
return false; return false;
} }
@@ -319,8 +311,8 @@ public class VideoPieceGetter {
sourceEntity.setUrl(imgSource.getUrl()); sourceEntity.setUrl(imgSource.getUrl());
sourceEntity.setPosJson(imgSource.getPosJson()); sourceEntity.setPosJson(imgSource.getPosJson());
} }
if (StringUtils.isNotBlank(config.getVideoCrop())) { if (StringUtils.isNotBlank(config.getString("video_crop"))) {
sourceEntity.setPosJson(config.getVideoCrop()); sourceEntity.setPosJson(config.getString("video_crop"));
} }
sourceEntity.setVideoUrl(url); sourceEntity.setVideoUrl(url);
sourceEntity.setFaceSampleId(faceSampleId); sourceEntity.setFaceSampleId(faceSampleId);
@@ -348,8 +340,8 @@ public class VideoPieceGetter {
videoReUploader.addTask(sourceEntity.getId()); videoReUploader.addTask(sourceEntity.getId());
} else { } else {
source.setVideoUrl(url); source.setVideoUrl(url);
if (StringUtils.isNotBlank(config.getVideoCrop())) { if (StringUtils.isNotBlank(config.getString("video_crop"))) {
source.setPosJson(config.getVideoCrop()); source.setPosJson(config.getString("video_crop"));
} }
sourceMapper.update(source); sourceMapper.update(source);
videoReUploader.addTask(source.getId()); videoReUploader.addTask(source.getId());