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);
|
||||
|
Reference in New Issue
Block a user