桌码下载修改
This commit is contained in:
parent
f9343694d7
commit
a8ad15932a
|
|
@ -114,7 +114,7 @@ public class ShopTableServiceImpl extends ServiceImpl<ShopTableMapper, ShopTable
|
|||
|
||||
// 预生成所有二维码数据和记录,避免在写入ZIP过程中出现异常
|
||||
List<ShopTableCode> codeList = new ArrayList<>();
|
||||
List<ByteArrayOutputStream> qrBytesList = new ArrayList<>();
|
||||
List<byte[]> qrBytesList = new ArrayList<>();
|
||||
List<String> fileNames = new ArrayList<>();
|
||||
|
||||
for (int i = 0; i < num; i++) {
|
||||
|
|
@ -129,7 +129,8 @@ public class ShopTableServiceImpl extends ServiceImpl<ShopTableMapper, ShopTable
|
|||
BufferedImage qrImage = QrCodeUtil.generate(tableCode, 300, 300);
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
ImgUtil.write(qrImage, ImgUtil.IMAGE_TYPE_PNG, baos);
|
||||
qrBytesList.add(baos);
|
||||
qrBytesList.add(baos.toByteArray());
|
||||
baos.close();
|
||||
fileNames.add(tableCode + ".png");
|
||||
}
|
||||
|
||||
|
|
@ -143,18 +144,19 @@ public class ShopTableServiceImpl extends ServiceImpl<ShopTableMapper, ShopTable
|
|||
|
||||
// 写入ZIP文件
|
||||
|
||||
try (ZipOutputStream zipOut = new ZipOutputStream(response.getOutputStream())) {
|
||||
ZipOutputStream zipOut = new ZipOutputStream(response.getOutputStream());
|
||||
try {
|
||||
for (int i = 0; i < num; i++) {
|
||||
ZipEntry entry = new ZipEntry(fileNames.get(i));
|
||||
zipOut.putNextEntry(entry);
|
||||
ByteArrayOutputStream byteArrayOutputStream = qrBytesList.get(i);
|
||||
byte[] byteArray = byteArrayOutputStream.toByteArray();
|
||||
byte[] byteArray = qrBytesList.get(i);
|
||||
zipOut.write(byteArray, 0, byteArray.length);
|
||||
zipOut.flush();
|
||||
zipOut.closeEntry();
|
||||
byteArrayOutputStream.close();
|
||||
}
|
||||
}finally {
|
||||
zipOut.finish();
|
||||
zipOut.close();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue