桌码打包下载失败修复
This commit is contained in:
parent
67c17e6f92
commit
9f035cd1fa
|
|
@ -105,7 +105,8 @@ public class ShopTableServiceImpl extends ServiceImpl<ShopTableMapper, ShopTable
|
|||
response.setHeader("Content-Disposition", "attachment; filename=shop_qrcodes_" + shopId + ".zip");
|
||||
|
||||
ArrayList<ShopTableCode> codeList = new ArrayList<>();
|
||||
// 使用 ZipOutputStream 将二维码写入 zip
|
||||
|
||||
// 使用 ZipOutputStream 直接将二维码写入 ZIP
|
||||
try (ZipOutputStream zipOut = new ZipOutputStream(response.getOutputStream())) {
|
||||
for (int i = 0; i < num; i++) {
|
||||
String tableCode = generateCode(1, shopId, ++maxId, codeMap);
|
||||
|
|
@ -113,25 +114,25 @@ public class ShopTableServiceImpl extends ServiceImpl<ShopTableMapper, ShopTable
|
|||
|
||||
codeList.add(new ShopTableCode().setShopId(shopId).setTableCode(tableCode));
|
||||
|
||||
// 生成二维码并写入 ByteArrayOutputStream
|
||||
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
|
||||
// 生成二维码
|
||||
BufferedImage qrImage = QrCodeUtil.generate(tableCode, 300, 300);
|
||||
|
||||
// 转换为字节数组
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||
ImgUtil.write(qrImage, ImgUtil.IMAGE_TYPE_PNG, out);
|
||||
out.flush(); // 确保所有数据都已写入
|
||||
byte[] qrBytes = out.toByteArray();
|
||||
ImgUtil.write(qrImage, ImgUtil.IMAGE_TYPE_PNG, byteArrayOutputStream);
|
||||
byte[] qrBytes = byteArrayOutputStream.toByteArray();
|
||||
|
||||
// 添加到 ZIP
|
||||
// 创建一个新的 ZipEntry
|
||||
zipOut.putNextEntry(new ZipEntry(tableCode + ".png"));
|
||||
zipOut.write(qrBytes);
|
||||
zipOut.closeEntry(); // 确保当前文件的条目被关闭
|
||||
zipOut.closeEntry(); // 确保当前文件条目被关闭
|
||||
}
|
||||
|
||||
// 刷新并完成文件输出
|
||||
zipOut.finish();
|
||||
}
|
||||
|
||||
// 保存二维码信息
|
||||
shopTableCodeService.saveBatch(codeList);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue