feat(face): 添加小程序码异步预生成功能

- 在人脸创建后异步预生成小程序码,提升后续获取速度
- 实现小程序码文件按日期目录存储优化文件管理
- 添加阿里云OSS内网域名替换为公网域名的逻辑
- 增加小程序码文件存在性检查避免重复生成
- 添加异步任务异常处理和日志记录机制
- 优化文件路径命名规则提高系统可维护性
This commit is contained in:
2026-01-16 11:57:14 +08:00
parent d15d070cb4
commit 27a18096b5

View File

@@ -331,6 +331,15 @@ public class FaceServiceImpl implements FaceService {
Long finalFaceId = newFaceId; Long finalFaceId = newFaceId;
Thread thread = new Thread(() -> printerService.autoAddPhotosToPreferPrint(finalFaceId), "auto-add-print-" + newFaceId); Thread thread = new Thread(() -> printerService.autoAddPhotosToPreferPrint(finalFaceId), "auto-add-print-" + newFaceId);
thread.start(); thread.start();
new Thread(() -> {
try {
bindWxaCode(finalFaceId);
log.debug("预生成小程序码成功, faceId: {}", finalFaceId);
} catch (Exception e) {
log.warn("预生成小程序码失败, faceId: {}, 原因: {}", finalFaceId, e.getMessage());
}
}, "pre-generate-wxacode-" + newFaceId).start();
if (Strings.CI.equals("print", scene)) { if (Strings.CI.equals("print", scene)) {
try { try {
thread.join(); thread.join();
@@ -716,25 +725,29 @@ public class FaceServiceImpl implements FaceService {
public String bindWxaCode(Long faceId) { public String bindWxaCode(Long faceId) {
FaceEntity face = faceRepository.getFace(faceId); FaceEntity face = faceRepository.getFace(faceId);
String dt = DateUtil.format(face.getCreateAt(), "yyyyMMdd");
String path = "pages/videoSynthesis/bind_face";
String filePath = "wxa_face/"+dt+"/f" + faceId + ".jpg";
IStorageAdapter adapter = StorageFactory.use();
if (adapter.isExists(filePath)) {
String url = adapter.getUrl(filePath);
url = url.replace("-internal.aliyuncs.com", ".aliyuncs.com");
return url;
}
MpConfigEntity mpConfig = scenicRepository.getScenicMpConfig(face.getScenicId()); MpConfigEntity mpConfig = scenicRepository.getScenicMpConfig(face.getScenicId());
if (mpConfig == null) { if (mpConfig == null) {
throw new BaseException("小程序配置不存在"); throw new BaseException("小程序配置不存在");
} }
String appId = mpConfig.getAppId(); String appId = mpConfig.getAppId();
String appSecret = mpConfig.getAppSecret(); String appSecret = mpConfig.getAppSecret();
String path = "pages/videoSynthesis/bind_face";
String filePath = "qr_code_bf" + faceId + ".jpg";
IStorageAdapter adapter = StorageFactory.use();
if (adapter.isExists(filePath)) {
return adapter.getUrl(filePath);
}
try { try {
File file = new File(filePath); File file = new File(filePath);
WxMpUtil.generateUnlimitedWXAQRCode(appId, appSecret, path, faceId.toString(), file); WxMpUtil.generateUnlimitedWXAQRCode(appId, appSecret, path, faceId.toString(), file);
String s = adapter.uploadFile(null, file, filePath); String url = adapter.uploadFile(null, file, filePath);
file.delete(); file.delete();
adapter.setAcl(StorageAcl.PUBLIC_READ, filePath); adapter.setAcl(StorageAcl.PUBLIC_READ, filePath);
return s; url = url.replace("-internal.aliyuncs.com", ".aliyuncs.com");
return url;
} catch (Exception e) { } catch (Exception e) {
throw new BaseException("生成二维码失败"); throw new BaseException("生成二维码失败");
} }