feat(printer): 优化自动添加照片到打印列表逻辑

- 修改autoAddPhotosToPreferPrint方法返回值为List<SourceEntity>
- 当自动添加成功时直接返回添加的照片列表
- 添加失败或无照片时返回空列表而非数量
- 控制器根据返回结果判断是否生成二维码URL
- 提升代码可读性和维护性
This commit is contained in:
2025-12-04 21:23:23 +08:00
parent 42540e2dc4
commit eade5f8092
3 changed files with 31 additions and 19 deletions

View File

@@ -230,16 +230,23 @@ public class PrinterTvController {
// 3. 在景区人脸库中搜索(注意:这里使用scenicId作为数据库名,搜索的是景区内的人脸样本)
pcFaceService.matchFaceId(faceId);
// 4. 自动添加照片到打印列表
int addedCount = printerService.autoAddPhotosToPreferPrint(faceId);
// 4. 自动添加照片到打印列表,并获取添加成功的照片列表
List<SourceEntity> addedSources = printerService.autoAddPhotosToPreferPrint(faceId);
// 5. 查询匹配到的图像素材(type=2)
List<SourceEntity> sources = new ArrayList<>();
List<MemberSourceEntity> memberSourceEntities = memberRelationRepository.listSourceByFaceRelation(faceId, 2);
for (MemberSourceEntity memberSourceEntity : memberSourceEntities) {
SourceEntity source = sourceRepository.getSource(memberSourceEntity.getSourceId());
if (source != null) {
sources.add(source);
// 5. 根据自动添加结果决定返回的sources
List<SourceEntity> sources;
if (addedSources != null && !addedSources.isEmpty()) {
// 如果自动添加成功,返回添加的照片列表
sources = addedSources;
} else {
// 如果自动添加为空,按原逻辑查询匹配到的图像素材(type=2)
sources = new ArrayList<>();
List<MemberSourceEntity> memberSourceEntities = memberRelationRepository.listSourceByFaceRelation(faceId, 2);
for (MemberSourceEntity memberSourceEntity : memberSourceEntities) {
SourceEntity source = sourceRepository.getSource(memberSourceEntity.getSourceId());
if (source != null) {
sources.add(source);
}
}
}
@@ -250,7 +257,7 @@ public class PrinterTvController {
resp.setScenicId(scenicId);
resp.setSources(sources);
// 只有当添加了照片时才返回二维码URL
if (addedCount > 0) {
if (addedSources != null && !addedSources.isEmpty()) {
resp.setQrcodeUrl("https://zhentuai.com/printer/v1/tv/face/" + faceId + "/qrcode");
} else {
resp.setQrcodeUrl(null);