feat(printer): 添加照片来源ID字段并更新相关逻辑

- 在MemberPrintEntity中新增sourceId字段用于记录照片来源
- 更新addUserPhoto方法签名,增加sourceId参数
- 修改照片上传接口,支持传递sourceId参数
- 完善自动添加照片到打印列表的逻辑,关联sourceId
- 更新数据库映射文件,添加source_id字段的读写配置- 优化重复照片检测逻辑,确保数据一致性
This commit is contained in:
2025-11-08 15:12:15 +08:00
parent 88c31d4fdc
commit 1bbfe8d092
5 changed files with 16 additions and 9 deletions

View File

@@ -72,7 +72,7 @@ public class AppPrinterController {
String[] split = file.getOriginalFilename().split("\\.");
String ext = split[split.length - 1];
String url = StorageFactory.use().uploadFile(file, "printer", UUID.randomUUID() + "." + ext);
Integer id = printerService.addUserPhoto(JwtTokenUtil.getWorker().getUserId(), scenicId, url, parseFaceId(faceId));
Integer id = printerService.addUserPhoto(JwtTokenUtil.getWorker().getUserId(), scenicId, url, parseFaceId(faceId), null);
return ApiResponse.success(id);
}
@PostMapping(value = "/uploadTo/{scenicId}/cropped/{id}", consumes = "multipart/form-data")

View File

@@ -15,6 +15,7 @@ public class MemberPrintEntity {
private Long scenicId;
private Long memberId;
private Long faceId;
private Long sourceId;
private String origUrl;
private String cropUrl;
private String printUrl;

View File

@@ -39,7 +39,7 @@ public interface PrinterService {
boolean deleteUserPhoto(Long memberId, Long scenicId, Long relationId);
Integer addUserPhoto(Long memberId, Long scenicId, String url, Long faceId);
Integer addUserPhoto(Long memberId, Long scenicId, String url, Long faceId, Long sourceId);
MemberPrintResp getUserPhoto(Long memberId, Long scenicId, Long id);

View File

@@ -272,11 +272,12 @@ public class PrinterServiceImpl implements PrinterService {
}
@Override
public Integer addUserPhoto(Long memberId, Long scenicId, String url, Long faceId) {
public Integer addUserPhoto(Long memberId, Long scenicId, String url, Long faceId, Long sourceId) {
MemberPrintEntity entity = new MemberPrintEntity();
entity.setMemberId(memberId);
entity.setScenicId(scenicId);
entity.setFaceId(faceId);
entity.setSourceId(sourceId);
entity.setOrigUrl(url);
// 获取打印尺寸
@@ -411,6 +412,7 @@ public class PrinterServiceImpl implements PrinterService {
entity.setMemberId(memberId);
entity.setScenicId(scenicId);
entity.setFaceId(faceId);
entity.setSourceId(id);
entity.setOrigUrl(url);
// 获取打印尺寸并裁剪图片
@@ -808,11 +810,13 @@ public class PrinterServiceImpl implements PrinterService {
resp.setScenicId(scenicId);
faceService.matchFaceId(faceId);
autoAddPhotosToPreferPrint(faceId);
List<MemberPrintResp> userPhotoList = getUserPhotoList(userId, scenicId, faceId);
boolean noneMatch = userPhotoList.stream()
.noneMatch(item -> Strings.CI.equals(item.getOrigUrl(), sourceEntity.getUrl()));
if (noneMatch) {
addUserPhoto(userId, scenicId, sourceEntity.getUrl(), faceId);
if (sourceEntity != null) {
List<MemberPrintResp> userPhotoList = getUserPhotoList(userId, scenicId, faceId);
boolean noneMatch = userPhotoList.stream()
.noneMatch(item -> Strings.CI.equals(item.getOrigUrl(), sourceEntity.getUrl()));
if (noneMatch) {
addUserPhoto(userId, scenicId, sourceEntity.getUrl(), faceId, sourceEntity.getId());
}
}
return resp;
}
@@ -916,7 +920,7 @@ public class PrinterServiceImpl implements PrinterService {
int deviceAdded = 0;
for (SourceEntity source : sourcesToAdd) {
try {
addUserPhoto(memberId, scenicId, source.getUrl(), faceId);
addUserPhoto(memberId, scenicId, source.getUrl(), faceId, source.getId());
deviceAdded++;
} catch (Exception e) {
log.warn("添加照片到打印列表失败: sourceId={}, url={}, error={}",

View File

@@ -102,6 +102,7 @@
member_id,
scenic_id,
face_id,
source_id,
orig_url,
crop_url,
quantity,
@@ -112,6 +113,7 @@
#{memberId},
#{scenicId},
#{faceId},
#{sourceId},
#{origUrl},
#{cropUrl},
1,