|
|
|
|
@ -1,5 +1,6 @@
|
|
|
|
|
package com.da.dangan.controller;
|
|
|
|
|
|
|
|
|
|
import cn.hutool.core.util.URLUtil;
|
|
|
|
|
import com.da.common.annotation.Log;
|
|
|
|
|
import com.da.common.core.controller.BaseController;
|
|
|
|
|
import com.da.common.core.domain.AjaxResult;
|
|
|
|
|
@ -8,12 +9,23 @@ import com.da.common.enums.BusinessType;
|
|
|
|
|
import com.da.common.utils.poi.ExcelUtil;
|
|
|
|
|
import com.da.dangan.domain.DaPicturesRecard;
|
|
|
|
|
import com.da.dangan.service.IDaPicturesRecardService;
|
|
|
|
|
import org.apache.commons.compress.archivers.zip.ParallelScatterZipCreator;
|
|
|
|
|
import org.apache.commons.compress.archivers.zip.ZipArchiveEntry;
|
|
|
|
|
import org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream;
|
|
|
|
|
import org.apache.commons.compress.parallel.InputStreamSupplier;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
import org.springframework.security.access.prepost.PreAuthorize;
|
|
|
|
|
import org.springframework.util.StringUtils;
|
|
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
|
|
import java.io.*;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.concurrent.*;
|
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
import java.util.zip.ZipEntry;
|
|
|
|
|
import java.util.zip.ZipOutputStream;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 档案图片信息记录Controller
|
|
|
|
|
@ -25,9 +37,10 @@ import java.util.List;
|
|
|
|
|
@RequestMapping("/dangan/pictureRecard")
|
|
|
|
|
public class DaPicturesRecardController extends BaseController
|
|
|
|
|
{
|
|
|
|
|
@Autowired
|
|
|
|
|
private ExecutorService executorService;
|
|
|
|
|
@Autowired
|
|
|
|
|
private IDaPicturesRecardService daPicturesRecardService;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 查询档案图片信息记录列表
|
|
|
|
|
*/
|
|
|
|
|
@ -53,6 +66,20 @@ public class DaPicturesRecardController extends BaseController
|
|
|
|
|
util.exportExcel(response, list, "档案图片信息记录数据");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 导出档案图片信息记录列表
|
|
|
|
|
*/
|
|
|
|
|
@PreAuthorize("@ss.hasPermi('dangan:pictureRecard:export')")
|
|
|
|
|
@Log(title = "图片下载", businessType = BusinessType.EXPORT)
|
|
|
|
|
@PostMapping("/exportImage")
|
|
|
|
|
public void export2(HttpServletRequest request,HttpServletResponse response, DaPicturesRecard daPicturesRecard)
|
|
|
|
|
{
|
|
|
|
|
List<DaPicturesRecard> list = daPicturesRecardService.selectDaPicturesRecardList(daPicturesRecard);
|
|
|
|
|
List<String> images = list.stream().map(DaPicturesRecard ::getPicUrl).collect(Collectors.toList());
|
|
|
|
|
//exportImages(request,response,images,"档案图片");
|
|
|
|
|
exportImages1(response,images,"档案图片");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 获取档案图片信息记录详细信息
|
|
|
|
|
*/
|
|
|
|
|
@ -106,4 +133,97 @@ public class DaPicturesRecardController extends BaseController
|
|
|
|
|
{
|
|
|
|
|
return daPicturesRecardService.deleteDaPicturesRecardByIds(ids);
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* 使用多线程打包下载
|
|
|
|
|
*/
|
|
|
|
|
private void exportImages1( HttpServletResponse response, List<String> images, String name) {
|
|
|
|
|
response.setContentType("application/zip");
|
|
|
|
|
response.setHeader("Content-Disposition", "attachment;filename=demo.zip");
|
|
|
|
|
ParallelScatterZipCreator parallelScatterZipCreator = new ParallelScatterZipCreator(executorService);
|
|
|
|
|
try (ZipArchiveOutputStream zipArchiveOutputStream = new ZipArchiveOutputStream(response.getOutputStream())) {
|
|
|
|
|
zipArchiveOutputStream.setLevel(0);
|
|
|
|
|
images.forEach(x -> {
|
|
|
|
|
ZipArchiveEntry zipArchiveEntry = new ZipArchiveEntry(StringUtils.getFilename(x));
|
|
|
|
|
zipArchiveEntry.setMethod(ZipArchiveEntry.STORED);
|
|
|
|
|
InputStreamSupplier inputStreamSupplier = () -> URLUtil.getStream(URLUtil.url(x));
|
|
|
|
|
parallelScatterZipCreator.addArchiveEntry(zipArchiveEntry, inputStreamSupplier);
|
|
|
|
|
});
|
|
|
|
|
parallelScatterZipCreator.writeTo(zipArchiveOutputStream);
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void exportImages(HttpServletRequest request, HttpServletResponse response, List<String> images, String name) {
|
|
|
|
|
//响应头的设置
|
|
|
|
|
response.reset();
|
|
|
|
|
response.setCharacterEncoding("utf-8");
|
|
|
|
|
response.setContentType("multipart/form-data");
|
|
|
|
|
//设置压缩包的名字
|
|
|
|
|
//解决不同浏览器压缩包名字含有中文乱码的问题
|
|
|
|
|
String billname ="workerCard";
|
|
|
|
|
String downloadName=name+".zip";
|
|
|
|
|
//返回客户端浏览器的版本号、类型
|
|
|
|
|
String agent = request.getHeader("USER-AGENT");
|
|
|
|
|
try {
|
|
|
|
|
//针对IE或者以IE为内核的浏览器处理
|
|
|
|
|
if (agent.contains("MSIE")||agent.contains("Trident")){
|
|
|
|
|
|
|
|
|
|
downloadName=java.net.URLEncoder.encode(downloadName, "UTF-8");
|
|
|
|
|
}else {
|
|
|
|
|
downloadName=new String(downloadName.getBytes("UTF-8"),"ISO-8859-1");
|
|
|
|
|
}
|
|
|
|
|
}catch (Exception e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
response.setHeader("Content-Disposition","attachment;fileName=\"" + downloadName + "\"");
|
|
|
|
|
//设置压缩流
|
|
|
|
|
ZipOutputStream zip=null;
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
zip=new ZipOutputStream(new BufferedOutputStream(response.getOutputStream()));
|
|
|
|
|
//设置压缩方法
|
|
|
|
|
zip.setMethod(ZipOutputStream.DEFLATED);
|
|
|
|
|
} catch (IOException e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
DataOutputStream os=null;
|
|
|
|
|
//从数据库中取出要下载的图片路径
|
|
|
|
|
|
|
|
|
|
for (String image : images) {
|
|
|
|
|
File file = new File(image);
|
|
|
|
|
if (file.exists()){
|
|
|
|
|
//添加ZipEntry,并ZipEntry中写入文件流
|
|
|
|
|
//这里,加上i是防止要下载的文件有重名的导致下载失败
|
|
|
|
|
try {
|
|
|
|
|
zip.putNextEntry(new ZipEntry(file.getName()));
|
|
|
|
|
os=new DataOutputStream(zip);
|
|
|
|
|
InputStream is = new FileInputStream(file);
|
|
|
|
|
byte[]b= new byte [1024];
|
|
|
|
|
int length =0;
|
|
|
|
|
while ((length=is.read(b))!=-1){
|
|
|
|
|
os.write(b,0,length);
|
|
|
|
|
}
|
|
|
|
|
is.close();
|
|
|
|
|
//zip.closeEntry();
|
|
|
|
|
} catch (IOException e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//关闭流
|
|
|
|
|
try {
|
|
|
|
|
if (os!=null){
|
|
|
|
|
os.flush();
|
|
|
|
|
os.close();
|
|
|
|
|
zip.close();
|
|
|
|
|
}else {
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} catch (IOException e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|