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("生成二维码失败"); }