You've already forked FrameTour-BE
refactor(device): 重构设备配置获取逻辑
- 在 ViidController 中添加获取 DeviceConfigEntity 的逻辑 - 在 VideoPieceGetter 中使用 DeviceConfigManager 替代 DeviceConfigEntity - 优化设备配置参数的获取方式,使用 getBigDecimal 和 getString 方法 - 移除未使用的代码片段,提高代码可读性
This commit is contained in:
@@ -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<DeviceCropConfig> 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<DeviceCropConfig> 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);
|
||||
|
@@ -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());
|
||||
|
Reference in New Issue
Block a user