|
|
|
@ -67,9 +67,10 @@ public class YaoDuShopServiceImpl implements YaoDuShopService { |
|
|
|
|
|
|
|
int x = byId.getQrCodeX() != null ? byId.getQrCodeX() : 0; |
|
|
|
int y = byId.getQrCodeY() != null ? byId.getQrCodeY() : 0; |
|
|
|
double whl = 2.5; |
|
|
|
|
|
|
|
if (StringUtil.isNotEmpty(byId.getQrCodeBg())){ |
|
|
|
String finalPath = String.format("gourmet/gourmetDetail/final/%s_%s_%s_%s.jpg", |
|
|
|
String finalPath = String.format("gourmet/gourmetDetail/final/%s_%s_%s_%s_%s.jpg", |
|
|
|
id, byId.getQrCodeBg().hashCode(), x, y); |
|
|
|
try { |
|
|
|
InputStream ossFile = OssBootUtil.getOssFile(finalPath, null); |
|
|
|
@ -105,11 +106,11 @@ public class YaoDuShopServiceImpl implements YaoDuShopService { |
|
|
|
} |
|
|
|
|
|
|
|
// 生成最终合成图片,传递已获取的配置参数避免重复调用 |
|
|
|
byte[] finalImage = this.generateAndCombineImagesFromUrl2(qrCodeBytes, byId.getQrCodeBg(), x, y); |
|
|
|
byte[] finalImage = this.generateAndCombineImagesFromUrl2(qrCodeBytes, byId.getQrCodeBg(), x, y, whl); |
|
|
|
|
|
|
|
// 异步上传到OSS(移除Redis缓存) |
|
|
|
uploadToOssAsync(finalImage, String.format("gourmet/gourmetDetail/final/%s_%s_%s_%s.jpg", |
|
|
|
id, byId.getQrCodeBg().hashCode(), x, y)); |
|
|
|
uploadToOssAsync(finalImage, String.format("gourmet/gourmetDetail/final/%s_%s_%s_%s_%s.jpg", |
|
|
|
id, byId.getQrCodeBg().hashCode(), x, y, whl)); |
|
|
|
|
|
|
|
return finalImage; |
|
|
|
} catch (Exception e) { |
|
|
|
@ -232,7 +233,7 @@ public class YaoDuShopServiceImpl implements YaoDuShopService { |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public byte[] generateAndCombineImagesFromUrl2(byte[] qrCodeImageByte, String backgroundUrl, int qr_code_x, int qr_code_y) { |
|
|
|
public byte[] generateAndCombineImagesFromUrl2(byte[] qrCodeImageByte, String backgroundUrl, int qr_code_x, int qr_code_y, double whl) { |
|
|
|
File file = null; |
|
|
|
try { |
|
|
|
// 直接从URL加载背景图像,移除Redis缓存避免类型转换问题 |
|
|
|
@ -262,7 +263,7 @@ public class YaoDuShopServiceImpl implements YaoDuShopService { |
|
|
|
// 先绘制背景图像,完全覆盖画布 |
|
|
|
g2d.drawImage(backgroundImage, 0, 0, backgroundImage.getWidth(), backgroundImage.getHeight(), null); |
|
|
|
|
|
|
|
int wh = backgroundImage.getWidth() / 3; |
|
|
|
int wh = (int) (backgroundImage.getWidth() / whl); |
|
|
|
|
|
|
|
// 计算小程序码放置的位置(这里以中心位置为例) |
|
|
|
int qrCodeX = (backgroundImage.getWidth() - wh) / 2; |
|
|
|
|