|
|
|
@ -1,6 +1,7 @@
|
|
|
|
package com.da.dangan.controller;
|
|
|
|
package com.da.dangan.controller;
|
|
|
|
|
|
|
|
|
|
|
|
import cn.hutool.core.util.URLUtil;
|
|
|
|
import cn.hutool.core.util.URLUtil;
|
|
|
|
|
|
|
|
import cn.hutool.http.HttpUtil;
|
|
|
|
import com.da.common.annotation.Log;
|
|
|
|
import com.da.common.annotation.Log;
|
|
|
|
import com.da.common.core.controller.BaseController;
|
|
|
|
import com.da.common.core.controller.BaseController;
|
|
|
|
import com.da.common.core.domain.AjaxResult;
|
|
|
|
import com.da.common.core.domain.AjaxResult;
|
|
|
|
@ -22,39 +23,37 @@ import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
|
|
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
|
import java.io.*;
|
|
|
|
import java.io.IOException;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.concurrent.ExecutorService;
|
|
|
|
import java.util.concurrent.ExecutorService;
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
import java.util.zip.ZipEntry;
|
|
|
|
|
|
|
|
import java.util.zip.ZipOutputStream;
|
|
|
|
import java.util.zip.ZipOutputStream;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* 档案图片信息记录Controller
|
|
|
|
* 档案图片信息记录Controller
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @author hs
|
|
|
|
* @author hs
|
|
|
|
* @date 2024-05-13
|
|
|
|
* @date 2024-05-13
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
@RestController
|
|
|
|
@RestController
|
|
|
|
@RequestMapping("/dangan/pictureRecard")
|
|
|
|
@RequestMapping("/dangan/pictureRecard")
|
|
|
|
public class DaPicturesRecardController extends BaseController
|
|
|
|
public class DaPicturesRecardController extends BaseController {
|
|
|
|
{
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
@Autowired
|
|
|
|
private ExecutorService executorService;
|
|
|
|
private ExecutorService executorService;
|
|
|
|
@Autowired
|
|
|
|
@Autowired
|
|
|
|
private IDaPicturesRecardService daPicturesRecardService;
|
|
|
|
private IDaPicturesRecardService daPicturesRecardService;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* 查询档案图片信息记录列表
|
|
|
|
* 查询档案图片信息记录列表
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
@PreAuthorize("@ss.hasPermi('dangan:pictureRecard:list')")
|
|
|
|
@PreAuthorize("@ss.hasPermi('dangan:pictureRecard:list')")
|
|
|
|
@GetMapping("/list")
|
|
|
|
@GetMapping("/list")
|
|
|
|
public TableDataInfo list(DaPicturesRecard daPicturesRecard)
|
|
|
|
public TableDataInfo list(DaPicturesRecard daPicturesRecard) {
|
|
|
|
{
|
|
|
|
|
|
|
|
// 超管及角色为管理员显示所有目录信息
|
|
|
|
// 超管及角色为管理员显示所有目录信息
|
|
|
|
LoginUser loginUser = getLoginUser();
|
|
|
|
LoginUser loginUser = getLoginUser();
|
|
|
|
if (SysUser.isAdmin(getUserId()) ||
|
|
|
|
if (SysUser.isAdmin(getUserId()) ||
|
|
|
|
loginUser.getUser().getRoles().stream().anyMatch(sysRole -> sysRole.getRoleKey().equals("sysAdmin"))) {
|
|
|
|
loginUser.getUser().getRoles().stream().anyMatch(sysRole -> sysRole.getRoleKey().equals("sysAdmin"))) {
|
|
|
|
}else{
|
|
|
|
} else {
|
|
|
|
daPicturesRecard.setUserId(getUserId());
|
|
|
|
daPicturesRecard.setUserId(getUserId());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
startPage();
|
|
|
|
startPage();
|
|
|
|
@ -65,10 +64,9 @@ public class DaPicturesRecardController extends BaseController
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* 任务记录查询相关 档案图片信息记录列表
|
|
|
|
* 任务记录查询相关 档案图片信息记录列表
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
// @PreAuthorize("@ss.hasPermi('dangan:pictureRecard:list')")
|
|
|
|
// @PreAuthorize("@ss.hasPermi('dangan:pictureRecard:list')")
|
|
|
|
@GetMapping("/listByIds")
|
|
|
|
@GetMapping("/listByIds")
|
|
|
|
public TableDataInfo listByIds(Long[] ids)
|
|
|
|
public TableDataInfo listByIds(Long[] ids) {
|
|
|
|
{
|
|
|
|
|
|
|
|
startPage();
|
|
|
|
startPage();
|
|
|
|
List<DaPicturesRecard> list = daPicturesRecardService.selectDaPicturesRecardByIds(ids);
|
|
|
|
List<DaPicturesRecard> list = daPicturesRecardService.selectDaPicturesRecardByIds(ids);
|
|
|
|
return getDataTable(list);
|
|
|
|
return getDataTable(list);
|
|
|
|
@ -80,8 +78,7 @@ public class DaPicturesRecardController extends BaseController
|
|
|
|
@PreAuthorize("@ss.hasPermi('dangan:pictureRecard:export')")
|
|
|
|
@PreAuthorize("@ss.hasPermi('dangan:pictureRecard:export')")
|
|
|
|
@Log(title = "档案图片信息记录", businessType = BusinessType.EXPORT)
|
|
|
|
@Log(title = "档案图片信息记录", businessType = BusinessType.EXPORT)
|
|
|
|
@PostMapping("/export")
|
|
|
|
@PostMapping("/export")
|
|
|
|
public void export(HttpServletResponse response, DaPicturesRecard daPicturesRecard)
|
|
|
|
public void export(HttpServletResponse response, DaPicturesRecard daPicturesRecard) {
|
|
|
|
{
|
|
|
|
|
|
|
|
List<DaPicturesRecard> list = daPicturesRecardService.selectDaPicturesRecardList(daPicturesRecard);
|
|
|
|
List<DaPicturesRecard> list = daPicturesRecardService.selectDaPicturesRecardList(daPicturesRecard);
|
|
|
|
ExcelUtil<DaPicturesRecard> util = new ExcelUtil<DaPicturesRecard>(DaPicturesRecard.class);
|
|
|
|
ExcelUtil<DaPicturesRecard> util = new ExcelUtil<DaPicturesRecard>(DaPicturesRecard.class);
|
|
|
|
util.exportExcel(response, list, "档案图片信息记录数据");
|
|
|
|
util.exportExcel(response, list, "档案图片信息记录数据");
|
|
|
|
@ -93,12 +90,11 @@ public class DaPicturesRecardController extends BaseController
|
|
|
|
@PreAuthorize("@ss.hasPermi('dangan:pictureRecard:export')")
|
|
|
|
@PreAuthorize("@ss.hasPermi('dangan:pictureRecard:export')")
|
|
|
|
@Log(title = "图片下载", businessType = BusinessType.EXPORT)
|
|
|
|
@Log(title = "图片下载", businessType = BusinessType.EXPORT)
|
|
|
|
@PostMapping("/exportImage")
|
|
|
|
@PostMapping("/exportImage")
|
|
|
|
public void export2(HttpServletRequest request,HttpServletResponse response, DaPicturesRecard daPicturesRecard)
|
|
|
|
public void export2(HttpServletRequest request, HttpServletResponse response, DaPicturesRecard daPicturesRecard) {
|
|
|
|
{
|
|
|
|
|
|
|
|
List<DaPicturesRecard> list = daPicturesRecardService.selectDaPicturesRecardList(daPicturesRecard);
|
|
|
|
List<DaPicturesRecard> list = daPicturesRecardService.selectDaPicturesRecardList(daPicturesRecard);
|
|
|
|
List<String> images = list.stream().map(DaPicturesRecard ::getPicUrl).collect(Collectors.toList());
|
|
|
|
List<String> images = list.stream().map(DaPicturesRecard::getPicUrl).collect(Collectors.toList());
|
|
|
|
//exportImages(request,response,images,"档案图片");
|
|
|
|
exportImages(response,images);
|
|
|
|
exportImages1(response,images,"档案图片");
|
|
|
|
//exportImages1(response, images);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
@ -106,8 +102,7 @@ public class DaPicturesRecardController extends BaseController
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
@PreAuthorize("@ss.hasPermi('dangan:pictureRecard:query')")
|
|
|
|
@PreAuthorize("@ss.hasPermi('dangan:pictureRecard:query')")
|
|
|
|
@GetMapping(value = "/{id}")
|
|
|
|
@GetMapping(value = "/{id}")
|
|
|
|
public AjaxResult getInfo(@PathVariable("id") Long id)
|
|
|
|
public AjaxResult getInfo(@PathVariable("id") Long id) {
|
|
|
|
{
|
|
|
|
|
|
|
|
return success(daPicturesRecardService.selectDaPicturesRecardById(id));
|
|
|
|
return success(daPicturesRecardService.selectDaPicturesRecardById(id));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@ -117,8 +112,7 @@ public class DaPicturesRecardController extends BaseController
|
|
|
|
@PreAuthorize("@ss.hasPermi('dangan:pictureRecard:add')")
|
|
|
|
@PreAuthorize("@ss.hasPermi('dangan:pictureRecard:add')")
|
|
|
|
@Log(title = "档案图片信息记录", businessType = BusinessType.INSERT)
|
|
|
|
@Log(title = "档案图片信息记录", businessType = BusinessType.INSERT)
|
|
|
|
@PostMapping
|
|
|
|
@PostMapping
|
|
|
|
public AjaxResult add(@RequestBody DaPicturesRecard daPicturesRecard)
|
|
|
|
public AjaxResult add(@RequestBody DaPicturesRecard daPicturesRecard) {
|
|
|
|
{
|
|
|
|
|
|
|
|
daPicturesRecard.setCreateBy(getUsername());
|
|
|
|
daPicturesRecard.setCreateBy(getUsername());
|
|
|
|
return toAjax(daPicturesRecardService.insertDaPicturesRecard(daPicturesRecard));
|
|
|
|
return toAjax(daPicturesRecardService.insertDaPicturesRecard(daPicturesRecard));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@ -129,8 +123,7 @@ public class DaPicturesRecardController extends BaseController
|
|
|
|
@PreAuthorize("@ss.hasPermi('dangan:pictureRecard:edit')")
|
|
|
|
@PreAuthorize("@ss.hasPermi('dangan:pictureRecard:edit')")
|
|
|
|
@Log(title = "档案图片信息记录", businessType = BusinessType.UPDATE)
|
|
|
|
@Log(title = "档案图片信息记录", businessType = BusinessType.UPDATE)
|
|
|
|
@PutMapping
|
|
|
|
@PutMapping
|
|
|
|
public AjaxResult edit(@RequestBody DaPicturesRecard daPicturesRecard)
|
|
|
|
public AjaxResult edit(@RequestBody DaPicturesRecard daPicturesRecard) {
|
|
|
|
{
|
|
|
|
|
|
|
|
return toAjax(daPicturesRecardService.updateDaPicturesRecard(daPicturesRecard));
|
|
|
|
return toAjax(daPicturesRecardService.updateDaPicturesRecard(daPicturesRecard));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@ -139,26 +132,25 @@ public class DaPicturesRecardController extends BaseController
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
@PreAuthorize("@ss.hasPermi('dangan:pictureRecard:remove')")
|
|
|
|
@PreAuthorize("@ss.hasPermi('dangan:pictureRecard:remove')")
|
|
|
|
@Log(title = "档案图片信息记录", businessType = BusinessType.DELETE)
|
|
|
|
@Log(title = "档案图片信息记录", businessType = BusinessType.DELETE)
|
|
|
|
@DeleteMapping("/{ids}")
|
|
|
|
@DeleteMapping("/{ids}")
|
|
|
|
public AjaxResult remove(@PathVariable Long[] ids)
|
|
|
|
public AjaxResult remove(@PathVariable Long[] ids) {
|
|
|
|
{
|
|
|
|
|
|
|
|
return daPicturesRecardService.deleteDaPicturesRecardByIds(ids);
|
|
|
|
return daPicturesRecardService.deleteDaPicturesRecardByIds(ids);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* 使用多线程打包下载
|
|
|
|
* 使用多线程打包下载
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
private void exportImages1( HttpServletResponse response, List<String> images, String name) {
|
|
|
|
private void exportImages1(HttpServletResponse response, List<String> images) {
|
|
|
|
response.setContentType("application/zip");
|
|
|
|
response.setContentType("application/zip");
|
|
|
|
response.setHeader("Content-Disposition", "attachment;filename=demo.zip");
|
|
|
|
response.setHeader("Content-Disposition", "attachment;filename=image.zip");
|
|
|
|
ParallelScatterZipCreator parallelScatterZipCreator = new ParallelScatterZipCreator(executorService);
|
|
|
|
ParallelScatterZipCreator parallelScatterZipCreator = new ParallelScatterZipCreator(executorService);
|
|
|
|
try (ZipArchiveOutputStream zipArchiveOutputStream = new ZipArchiveOutputStream(response.getOutputStream())) {
|
|
|
|
try (ZipArchiveOutputStream zipArchiveOutputStream = new ZipArchiveOutputStream(response.getOutputStream())) {
|
|
|
|
zipArchiveOutputStream.setLevel(0);
|
|
|
|
zipArchiveOutputStream.setLevel(0);
|
|
|
|
images.forEach(x -> {
|
|
|
|
images.forEach(x -> {
|
|
|
|
ZipArchiveEntry zipArchiveEntry = new ZipArchiveEntry(StringUtils.getFilename(x));
|
|
|
|
ZipArchiveEntry zipEntry = new ZipArchiveEntry(StringUtils.getFilename(x));
|
|
|
|
zipArchiveEntry.setMethod(ZipArchiveEntry.STORED);
|
|
|
|
zipEntry.setMethod(ZipArchiveEntry.STORED);
|
|
|
|
InputStreamSupplier inputStreamSupplier = () -> URLUtil.getStream(URLUtil.url(x));
|
|
|
|
InputStreamSupplier inputStreamSupplier = () -> URLUtil.getStream(URLUtil.url(x));
|
|
|
|
parallelScatterZipCreator.addArchiveEntry(zipArchiveEntry, inputStreamSupplier);
|
|
|
|
parallelScatterZipCreator.addArchiveEntry(zipEntry, inputStreamSupplier);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
parallelScatterZipCreator.writeTo(zipArchiveOutputStream);
|
|
|
|
parallelScatterZipCreator.writeTo(zipArchiveOutputStream);
|
|
|
|
} catch (Exception e) {
|
|
|
|
} catch (Exception e) {
|
|
|
|
@ -166,76 +158,28 @@ public class DaPicturesRecardController extends BaseController
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void exportImages(HttpServletRequest request, HttpServletResponse response, List<String> images, String name) {
|
|
|
|
/**
|
|
|
|
//响应头的设置
|
|
|
|
* 单线程打包下载
|
|
|
|
response.reset();
|
|
|
|
*/
|
|
|
|
response.setCharacterEncoding("utf-8");
|
|
|
|
private void exportImages(HttpServletResponse response, List<String> images) {
|
|
|
|
response.setContentType("multipart/form-data");
|
|
|
|
response.setContentType("application/zip");
|
|
|
|
//设置压缩包的名字
|
|
|
|
response.setHeader("Content-Disposition", "attachment;filename=image.zip");
|
|
|
|
//解决不同浏览器压缩包名字含有中文乱码的问题
|
|
|
|
try (ZipOutputStream zipOutputStream = new ZipOutputStream(response.getOutputStream())) {
|
|
|
|
String billname ="workerCard";
|
|
|
|
zipOutputStream.setLevel(0);
|
|
|
|
String downloadName=name+".zip";
|
|
|
|
images.forEach(x -> {
|
|
|
|
//返回客户端浏览器的版本号、类型
|
|
|
|
try {
|
|
|
|
String agent = request.getHeader("USER-AGENT");
|
|
|
|
zipOutputStream.putNextEntry(new ZipArchiveEntry(StringUtils.getFilename(x)));
|
|
|
|
try {
|
|
|
|
HttpUtil.download(x, zipOutputStream, false);
|
|
|
|
//针对IE或者以IE为内核的浏览器处理
|
|
|
|
zipOutputStream.closeEntry();
|
|
|
|
if (agent.contains("MSIE")||agent.contains("Trident")){
|
|
|
|
} catch (IOException e) {
|
|
|
|
|
|
|
|
e.printStackTrace();
|
|
|
|
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) {
|
|
|
|
zipOutputStream.flush();
|
|
|
|
e.printStackTrace();
|
|
|
|
zipOutputStream.finish();
|
|
|
|
}
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|