|
|
|
@ -1,32 +1,24 @@
|
|
|
|
|
package com.sztzjy.resource_center.controller.api;
|
|
|
|
|
|
|
|
|
|
import cn.hutool.core.util.CharsetUtil;
|
|
|
|
|
import com.sztzjy.resource_center.annotation.AnonymousAccess;
|
|
|
|
|
import com.sztzjy.resource_center.entity.SysCaseQuestion;
|
|
|
|
|
import com.sztzjy.resource_center.entity.SysResourceData;
|
|
|
|
|
import com.sztzjy.resource_center.entity.SysResourceDataExample;
|
|
|
|
|
import com.sztzjy.resource_center.mapper.SysCaseQuestionMapper;
|
|
|
|
|
import com.sztzjy.resource_center.mapper.SysResourceDataMapper;
|
|
|
|
|
import com.sztzjy.resource_center.util.CompressUtil;
|
|
|
|
|
import com.sztzjy.resource_center.util.file.IFileUtil;
|
|
|
|
|
import io.swagger.annotations.Api;
|
|
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
|
|
import org.springframework.util.Assert;
|
|
|
|
|
import org.springframework.util.StringUtils;
|
|
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
|
|
|
|
import javax.servlet.ServletOutputStream;
|
|
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
|
|
import java.io.BufferedInputStream;
|
|
|
|
|
import java.io.File;
|
|
|
|
|
import java.io.IOException;
|
|
|
|
|
import java.io.InputStream;
|
|
|
|
|
import java.net.URLEncoder;
|
|
|
|
|
import java.nio.file.Files;
|
|
|
|
|
import java.util.Arrays;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
import java.util.UUID;
|
|
|
|
|
|
|
|
|
|
@RestController
|
|
|
|
@ -40,7 +32,8 @@ public class ResourceDataApi {
|
|
|
|
|
private SysCaseQuestionMapper caseQuestionMapper;
|
|
|
|
|
@Autowired
|
|
|
|
|
IFileUtil fileUtil;
|
|
|
|
|
|
|
|
|
|
@Value("${file.path}")
|
|
|
|
|
private String filePath;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 数据集文件上传
|
|
|
|
@ -91,6 +84,8 @@ public class ResourceDataApi {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 数据集删除
|
|
|
|
|
* 方法名:deleteResourceData
|
|
|
|
@ -120,14 +115,22 @@ public class ResourceDataApi {
|
|
|
|
|
*/
|
|
|
|
|
@AnonymousAccess
|
|
|
|
|
@ApiOperation("数据集下载")
|
|
|
|
|
@GetMapping("downloadResourceData")
|
|
|
|
|
private void downloadResourceData(@RequestParam String resourceId,
|
|
|
|
|
HttpServletResponse response) {
|
|
|
|
|
try {
|
|
|
|
|
SysResourceData sysResourceData = sysResourceDataMapper.selectByPrimaryKey(resourceId);
|
|
|
|
|
String resourceName = sysResourceData.getResourceName();
|
|
|
|
|
fileUtil.download(response, resourceName, sysResourceData.getUrl());
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
@PostMapping("downloadResourceData")
|
|
|
|
|
private void downloadResourceData(@RequestBody List<String> ids, HttpServletResponse response) {
|
|
|
|
|
this.downloadFile(ids, response);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void downloadFile(List<String> ids, HttpServletResponse response) {
|
|
|
|
|
if (ids != null && !ids.isEmpty()) {
|
|
|
|
|
List<Map<String, String>> filePaths = sysResourceDataMapper.getByIds(ids);
|
|
|
|
|
String zipName = "TZ_" + ((int) (Math.random() * 10000)) + ".zip";
|
|
|
|
|
String zipPath = filePath + "/" + zipName;
|
|
|
|
|
CompressUtil.compress(filePaths, zipPath, false);
|
|
|
|
|
File pocZipFile = new File(zipPath);
|
|
|
|
|
CompressUtil.downloadZip(response, zipName, pocZipFile);
|
|
|
|
|
pocZipFile.delete();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|