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[] split = file.getOriginalFilename().split("\\.");
String ext = split[split.length - 1]; String ext = split[split.length - 1];
String url = StorageFactory.use().uploadFile(file, "printer", UUID.randomUUID() + "." + ext); 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); return ApiResponse.success(id);
} }
@PostMapping(value = "/uploadTo/{scenicId}/cropped/{id}", consumes = "multipart/form-data") @PostMapping(value = "/uploadTo/{scenicId}/cropped/{id}", consumes = "multipart/form-data")

View File

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

View File

@@ -39,7 +39,7 @@ public interface PrinterService {
boolean deleteUserPhoto(Long memberId, Long scenicId, Long relationId); 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); MemberPrintResp getUserPhoto(Long memberId, Long scenicId, Long id);

View File

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

View File

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