You've already forked FrameTour-BE
- 在任务筛选逻辑中增加设备照片数量限制筛选 - 根据设备配置的 limit_photo 值限制每个设备的照片数量 - 对于未设置限制或限制为 0 的设备,不做筛选 - 对于设置了限制的设备,按创建时间倒序排序,取前 N 张照片- 记录筛选过程的日志信息
This commit is contained in:
@@ -374,7 +374,13 @@ public class TaskFaceServiceImpl implements TaskFaceService {
|
|||||||
log.debug("时间范围逻辑:景区未设置游览时间限制");
|
log.debug("时间范围逻辑:景区未设置游览时间限制");
|
||||||
}
|
}
|
||||||
|
|
||||||
// 3. TODO: 基于景区配置的其他筛选策略
|
|
||||||
|
|
||||||
|
// 3. 应用设备照片数量限制筛选
|
||||||
|
filteredIds = applyDevicePhotoLimit(filteredIds, allFaceSampleList);
|
||||||
|
log.debug("应用设备照片数量限制筛选完成");
|
||||||
|
|
||||||
|
// 4. TODO: 基于景区配置的其他筛选策略
|
||||||
// 可以根据 scenicConfig 中的配置来决定是否启用特定筛选
|
// 可以根据 scenicConfig 中的配置来决定是否启用特定筛选
|
||||||
// 示例:未来可能的筛选策略
|
// 示例:未来可能的筛选策略
|
||||||
// if (scenicConfig.getEnableLocationFilter() != null && scenicConfig.getEnableLocationFilter()) {
|
// if (scenicConfig.getEnableLocationFilter() != null && scenicConfig.getEnableLocationFilter()) {
|
||||||
@@ -423,4 +429,71 @@ public class TaskFaceServiceImpl implements TaskFaceService {
|
|||||||
|
|
||||||
return filteredIds;
|
return filteredIds;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据设备配置的limit_photo值限制每个设备的照片数量
|
||||||
|
*
|
||||||
|
* @param acceptedSampleIds 已接受的样本ID列表
|
||||||
|
* @param allFaceSampleList 所有人脸样本实体列表
|
||||||
|
* @return 应用设备照片数量限制后的样本ID列表
|
||||||
|
*/
|
||||||
|
private List<Long> applyDevicePhotoLimit(List<Long> acceptedSampleIds,
|
||||||
|
List<FaceSampleEntity> allFaceSampleList) {
|
||||||
|
if (acceptedSampleIds == null || acceptedSampleIds.isEmpty()) {
|
||||||
|
return acceptedSampleIds;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 获取过滤后的样本列表
|
||||||
|
List<FaceSampleEntity> filteredSamples = allFaceSampleList.stream()
|
||||||
|
.filter(sample -> acceptedSampleIds.contains(sample.getId()))
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
|
||||||
|
// 按设备ID分组
|
||||||
|
Map<Long, List<FaceSampleEntity>> samplesByDevice = filteredSamples.stream()
|
||||||
|
.collect(Collectors.groupingBy(FaceSampleEntity::getDeviceId));
|
||||||
|
|
||||||
|
List<Long> resultIds = new ArrayList<>();
|
||||||
|
|
||||||
|
// 处理每个设备的样本
|
||||||
|
for (Map.Entry<Long, List<FaceSampleEntity>> entry : samplesByDevice.entrySet()) {
|
||||||
|
Long deviceId = entry.getKey();
|
||||||
|
List<FaceSampleEntity> deviceSamples = entry.getValue();
|
||||||
|
|
||||||
|
// 获取设备配置
|
||||||
|
DeviceConfigManager deviceConfig = deviceRepository.getDeviceConfigManager(deviceId);
|
||||||
|
Integer limitPhoto = null;
|
||||||
|
if (deviceConfig != null) {
|
||||||
|
limitPhoto = deviceConfig.getInteger("limit_photo");
|
||||||
|
}
|
||||||
|
|
||||||
|
// 如果没有配置或配置为0,不限制
|
||||||
|
if (limitPhoto == null || limitPhoto <= 0) {
|
||||||
|
List<Long> deviceSampleIds = deviceSamples.stream()
|
||||||
|
.map(FaceSampleEntity::getId)
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
resultIds.addAll(deviceSampleIds);
|
||||||
|
log.debug("设备照片限制:设备ID={}, 无限制,保留{}张照片",
|
||||||
|
deviceId, deviceSampleIds.size());
|
||||||
|
} else {
|
||||||
|
// 按创建时间倒序排序,取前N张
|
||||||
|
List<FaceSampleEntity> limitedSamples = deviceSamples.stream()
|
||||||
|
.sorted(Comparator.comparing(FaceSampleEntity::getCreateAt).reversed())
|
||||||
|
.limit(limitPhoto)
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
|
||||||
|
List<Long> limitedIds = limitedSamples.stream()
|
||||||
|
.map(FaceSampleEntity::getId)
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
|
||||||
|
resultIds.addAll(limitedIds);
|
||||||
|
log.debug("设备照片限制:设备ID={}, 限制={}张, 原始{}张,最终{}张",
|
||||||
|
deviceId, limitPhoto, deviceSamples.size(), limitedIds.size());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
log.info("设备照片数量限制筛选:原始样本数量={}, 筛选后数量={}",
|
||||||
|
acceptedSampleIds.size(), resultIds.size());
|
||||||
|
|
||||||
|
return resultIds;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user