@GetMapping("/downLoadImgs")
@Transactional
public void downLoadImgs(HttpServletRequest request,@RequestParam(name = "ids", required = true) String ids, HttpServletResponse response) {
String[] array = ids.split(",");
ArrayList<String> idList = new ArrayList<>(Arrays.asList(array));
List<XzFile> xzFiles = xzFileService.selectBatchIds(idList);
ArrayList<String> urls = new ArrayList<>();
for (XzFile xzFile : xzFiles) {
urls.add("http:*****"+xzFile.getIdPhoto());
}
String[] files = new String[urls.size()];
urls.toArray(files);
try {
String downloadFilename = "证件照" + ".zip";
downloadFilename = URLEncoder.encode(downloadFilename, "UTF-8");
response.setContentType("application/octet-stream");
response.setHeader("Content-Disposition", "attachment;filename=" + downloadFilename);
ZipOutputStream zos = new ZipOutputStream(response.getOutputStream());
for (int i = 0; i < files.length; i++) {
URL url = new URL(files[i]);
String spath=xzFiles.get(i).getIdPhoto();
int pos = spath.lastIndexOf('\\');
String sfilename = spath.substring(pos + 1);
pos = sfilename.lastIndexOf('.');
String sfilenameEx = sfilename.substring(0,pos);
zos.putNextEntry(new ZipEntry(sfilenameEx + ".jpg"));
InputStream fis = url.openConnection().getInputStream();
byte[] buffer = new byte[1024];
int r = 0;
while ((r = fis.read(buffer)) != -1) {
zos.write(buffer, 0, r);
}
fis.close();
}
zos.flush();
zos.close();
} catch (Exception e) {
return ;
}
}