diff --git a/src/main/java/com/sztzjy/resource_center/controller/api/ResourceDataApi.java b/src/main/java/com/sztzjy/resource_center/controller/api/ResourceDataApi.java index 674590f..d802ce9 100644 --- a/src/main/java/com/sztzjy/resource_center/controller/api/ResourceDataApi.java +++ b/src/main/java/com/sztzjy/resource_center/controller/api/ResourceDataApi.java @@ -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 ids, HttpServletResponse response) { + this.downloadFile(ids, response); + } + + + public void downloadFile(List ids, HttpServletResponse response) { + if (ids != null && !ids.isEmpty()) { + List> 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(); } } + } diff --git a/src/main/java/com/sztzjy/resource_center/mapper/SysResourceDataMapper.java b/src/main/java/com/sztzjy/resource_center/mapper/SysResourceDataMapper.java index 5f8129c..6feb42c 100644 --- a/src/main/java/com/sztzjy/resource_center/mapper/SysResourceDataMapper.java +++ b/src/main/java/com/sztzjy/resource_center/mapper/SysResourceDataMapper.java @@ -3,6 +3,7 @@ package com.sztzjy.resource_center.mapper; import com.sztzjy.resource_center.entity.SysResourceData; import com.sztzjy.resource_center.entity.SysResourceDataExample; import java.util.List; +import java.util.Map; import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Param; @@ -29,4 +30,6 @@ public interface SysResourceDataMapper { int updateByPrimaryKeySelective(SysResourceData record); int updateByPrimaryKey(SysResourceData record); + + List> getByIds(@Param("ids") List ids); } \ No newline at end of file diff --git a/src/main/resources/mapper/SysResourceDataMapper.xml b/src/main/resources/mapper/SysResourceDataMapper.xml index 5178c53..40164ea 100644 --- a/src/main/resources/mapper/SysResourceDataMapper.xml +++ b/src/main/resources/mapper/SysResourceDataMapper.xml @@ -223,4 +223,12 @@ source = #{source,jdbcType=VARCHAR} where resource_data_id = #{resourceDataId,jdbcType=VARCHAR} + \ No newline at end of file