feat(puzzle): 优化二维码生成与去重逻辑

- 避免重复上传已存在的微信小程序二维码
- 在去重检测中跳过 dateStr 字段以提高准确性
- 添加文件存在性检查,减少不必要的上传操作
- 记录并返回已存在文件的访问 URL
- 提升 puzzle 服务的性能与资源利用率
This commit is contained in:
2025-11-21 18:09:59 +08:00
parent c0daa4d3b2
commit 302b6811c4
2 changed files with 10 additions and 5 deletions

View File

@@ -348,10 +348,12 @@ public class PuzzleGenerateServiceImpl implements IPuzzleGenerateService {
// 上传到OSS
try (FileInputStream fis = new FileInputStream(qrcode)) {
String fileName = String.format("qrcode_%d_%s.jpg",
faceId,
UUID.randomUUID().toString().replace("-", "").substring(0, 16));
String fileName = String.format("qrcode_%d.jpg", faceId);
boolean exists = StorageFactory.use().isExists("puzzle", "wechat_qrcode", fileName);
if (exists) {
log.debug("微信小程序二维码已存在, 不重复上传: faceId={}, url={}", faceId, StorageFactory.use().getUrl("puzzle", "wechat_qrcode", fileName));
return StorageFactory.use().getUrl("puzzle", "wechat_qrcode", fileName);
}
return StorageFactory.use().uploadFile(
"image/jpeg",
fis,

View File

@@ -25,7 +25,7 @@ import java.util.stream.Collectors;
@Component
@RequiredArgsConstructor
public class PuzzleDuplicationDetector {
private final Set<String> skippedElementKeys = Set.of("dateStr");
private final PuzzleGenerationRecordMapper recordMapper;
/**
@@ -50,6 +50,9 @@ public class PuzzleDuplicationDetector {
StringBuilder sb = new StringBuilder();
for (int i = 0; i < sortedKeys.size(); i++) {
String key = sortedKeys.get(i);
if (skippedElementKeys.contains(key)) {
continue;
}
String value = finalData.get(key);
sb.append(key).append(":").append(value != null ? value : "");
if (i < sortedKeys.size() - 1) {