修改案例题模板下载和打包压缩

master
xiaoCJ 8 months ago
parent 986315e077
commit 630fc6fd1c

@ -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();
}
}
}

@ -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<Map<String, String>> getByIds(@Param("ids") List<String> ids);
}

@ -223,4 +223,12 @@
source = #{source,jdbcType=VARCHAR}
where resource_data_id = #{resourceDataId,jdbcType=VARCHAR}
</update>
<select id="getByIds" parameterType="String" resultType="map">
SELECT af.url,af.resource_name FROM sys_resource_data af
WHERE af.url IS NOT NULL
AND af.resource_data_id IN
<foreach collection="ids" item="id" open="(" separator="," close=")">
#{id}
</foreach>
</select>
</mapper>
Loading…
Cancel
Save