|
|
@@ -618,100 +618,6 @@ public class ResourceManageImpl implements ResourceManage {
|
|
|
});
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * 自动对焦预览
|
|
|
- *
|
|
|
- * @param focusPreviewQueryDTO
|
|
|
- * @return com.aivfo.business.manage.entity.vo.resource.picture.FocusPreviewVO
|
|
|
- * @Date 2024/4/29
|
|
|
- * @Author wangyl
|
|
|
- */
|
|
|
- @Override
|
|
|
- public FocusPreviewVO getAutofocusPictures(FocusPreviewQueryDTO focusPreviewQueryDTO) {
|
|
|
- return resourceService.getAutofocusPictures(focusPreviewQueryDTO);
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 下载对焦图片
|
|
|
- *
|
|
|
- * @param focusPreviewQueryDTO
|
|
|
- */
|
|
|
- @Override
|
|
|
- public void downloadFocusPicture(FocusPreviewQueryDTO focusPreviewQueryDTO, HttpServletRequest request, HttpServletResponse response) {
|
|
|
- List<PictureDAO> pictureList = resourceService.getAllFocusPictureByEmbryoId(focusPreviewQueryDTO);
|
|
|
- if (CollectionUtils.isEmpty(pictureList)) {
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- Map<String, List<PictureDAO>> dayMap = pictureList.stream().collect(Collectors.groupingBy(item -> DateUtil.format(item.getImageTime(), "yyyyMMdd")));
|
|
|
-
|
|
|
- Map<String, Map<String, String>> pictureMap = new HashMap<>();
|
|
|
- for (String key : dayMap.keySet()) {
|
|
|
- List<PictureDAO> pictures = dayMap.get(key);
|
|
|
- Map<String, String> urlMap = getPictureDownloadMap(pictures, true);
|
|
|
- pictureMap.put(key, urlMap);
|
|
|
- }
|
|
|
-
|
|
|
- // 设置响应头
|
|
|
- response.setHeader("content-type", "application/octet-stream");
|
|
|
- response.setCharacterEncoding("utf-8");
|
|
|
-
|
|
|
- try {
|
|
|
- // 设置下载文件名
|
|
|
- String encodedFileName = URLEncoder.encode(String.valueOf(focusPreviewQueryDTO.getEmbryoId()), "UTF-8").replaceAll("\\+", "%20");
|
|
|
- response.setHeader("Content-Disposition", "attachment;filename*=utf-8''" + encodedFileName + ".zip");
|
|
|
-
|
|
|
- // 创建ZIP输出流
|
|
|
- ZipOutputStream zos = new ZipOutputStream(response.getOutputStream());
|
|
|
- zos.setMethod(ZipOutputStream.DEFLATED);
|
|
|
- byte[] buffer = new byte[1024];
|
|
|
-
|
|
|
- // 遍历每个文件夹
|
|
|
- for (Map.Entry<String, Map<String, String>> entry : pictureMap.entrySet()) {
|
|
|
- String folderName = entry.getKey();
|
|
|
- Map<String, String> fileMap = entry.getValue();
|
|
|
-
|
|
|
- // 确保文件夹名以/结尾
|
|
|
- if (!folderName.endsWith("/")) {
|
|
|
- folderName += "/";
|
|
|
- }
|
|
|
-
|
|
|
- // 遍历文件夹中的每个文件
|
|
|
- for (Map.Entry<String, String> fileEntry : fileMap.entrySet()) {
|
|
|
- String[] split = fileEntry.getKey().split("/");
|
|
|
- String fileNameInFolder = (String) split[split.length - 1];
|
|
|
- String fileUrl = fileEntry.getValue();
|
|
|
-
|
|
|
- try {
|
|
|
- // 下载文件内容
|
|
|
- byte[] fileBytes = client.downloadFile(fileUrl);
|
|
|
- ByteArrayInputStream fis = new ByteArrayInputStream(fileBytes);
|
|
|
-
|
|
|
- // 创建带文件夹路径的条目
|
|
|
- String entryName = folderName + fileNameInFolder;
|
|
|
- zos.putNextEntry(new ZipEntry(entryName));
|
|
|
-
|
|
|
- // 写入文件内容
|
|
|
- int length;
|
|
|
- while ((length = fis.read(buffer)) > 0) {
|
|
|
- zos.write(buffer, 0, length);
|
|
|
- }
|
|
|
- zos.closeEntry();
|
|
|
- } catch (Exception e) {
|
|
|
- log.error("下载文件失败: 文件夹={}, 文件={}, 路径={}", folderName, fileNameInFolder, fileUrl, e);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- // 关闭ZIP输出流
|
|
|
- zos.finish();
|
|
|
- zos.close();
|
|
|
- } catch (Exception e) {
|
|
|
- log.error("打包下载文件夹失败", e);
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
/**
|
|
|
* 分页获取源图
|
|
|
*
|