From 27a18096b513deb4ba0b78ef14dfa79f4e9e7f13 Mon Sep 17 00:00:00 2001 From: Jerry Yan <792602257@qq.com> Date: Fri, 16 Jan 2026 11:57:14 +0800 Subject: [PATCH] =?UTF-8?q?feat(face):=20=E6=B7=BB=E5=8A=A0=E5=B0=8F?= =?UTF-8?q?=E7=A8=8B=E5=BA=8F=E7=A0=81=E5=BC=82=E6=AD=A5=E9=A2=84=E7=94=9F?= =?UTF-8?q?=E6=88=90=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 在人脸创建后异步预生成小程序码,提升后续获取速度 - 实现小程序码文件按日期目录存储优化文件管理 - 添加阿里云OSS内网域名替换为公网域名的逻辑 - 增加小程序码文件存在性检查避免重复生成 - 添加异步任务异常处理和日志记录机制 - 优化文件路径命名规则提高系统可维护性 --- .../service/pc/impl/FaceServiceImpl.java | 29 ++++++++++++++----- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/ycwl/basic/service/pc/impl/FaceServiceImpl.java b/src/main/java/com/ycwl/basic/service/pc/impl/FaceServiceImpl.java index 29d83341..903e3c06 100644 --- a/src/main/java/com/ycwl/basic/service/pc/impl/FaceServiceImpl.java +++ b/src/main/java/com/ycwl/basic/service/pc/impl/FaceServiceImpl.java @@ -331,6 +331,15 @@ public class FaceServiceImpl implements FaceService { Long finalFaceId = newFaceId; Thread thread = new Thread(() -> printerService.autoAddPhotosToPreferPrint(finalFaceId), "auto-add-print-" + newFaceId); 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)) { try { thread.join(); @@ -716,25 +725,29 @@ public class FaceServiceImpl implements FaceService { public String bindWxaCode(Long 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()); if (mpConfig == null) { throw new BaseException("小程序配置不存在"); } String appId = mpConfig.getAppId(); 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 { File file = new File(filePath); WxMpUtil.generateUnlimitedWXAQRCode(appId, appSecret, path, faceId.toString(), file); - String s = adapter.uploadFile(null, file, filePath); + String url = adapter.uploadFile(null, file, filePath); file.delete(); adapter.setAcl(StorageAcl.PUBLIC_READ, filePath); - return s; + url = url.replace("-internal.aliyuncs.com", ".aliyuncs.com"); + return url; } catch (Exception e) { throw new BaseException("生成二维码失败"); }