From 939e76b90691c8f4e66e437791bce9e11bc4bfad Mon Sep 17 00:00:00 2001
From: xiebin <vip_xiaobin810@163.com>
Date: Wed, 01 Apr 2026 17:08:38 +0800
Subject: [PATCH] opt:兼容人大金仓
---
drone-ops/drone-resource/src/main/java/org/sxkj/resource/controller/AttachController.java | 71 ++++++++++++++++++++++++-----------
1 files changed, 49 insertions(+), 22 deletions(-)
diff --git a/drone-ops/drone-resource/src/main/java/org/sxkj/resource/controller/AttachController.java b/drone-ops/drone-resource/src/main/java/org/sxkj/resource/controller/AttachController.java
index 00970a7..f3cb06d 100644
--- a/drone-ops/drone-resource/src/main/java/org/sxkj/resource/controller/AttachController.java
+++ b/drone-ops/drone-resource/src/main/java/org/sxkj/resource/controller/AttachController.java
@@ -12,35 +12,23 @@
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springblade.core.boot.ctrl.BladeController;
-import org.springblade.core.cache.utils.CacheUtil;
-import org.springblade.core.log.annotation.ApiLog;
import org.springblade.core.mp.support.Condition;
import org.springblade.core.mp.support.Query;
-import org.springblade.core.secure.annotation.PreAuth;
import org.springblade.core.tenant.annotation.NonDS;
import org.springblade.core.tool.api.R;
-import org.springblade.core.tool.constant.RoleConstant;
import org.springblade.core.tool.utils.BeanUtil;
import org.springblade.core.tool.utils.DateTimeUtil;
import org.springblade.core.tool.utils.Func;
-import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;
-import org.sxkj.common.constant.CommonConstant;
import org.sxkj.common.model.ResponseResult;
-import org.sxkj.common.model.TimeRange;
-import org.sxkj.common.utils.HeaderUtils;
-import org.sxkj.common.utils.TimeRangeUtils;
import org.sxkj.resource.dto.AttachDto;
-import org.sxkj.resource.dto.WaylineJobInfoQueryDto;
-import org.sxkj.resource.dto.WaylineJobInfoQueryParam;
import org.sxkj.resource.entity.Attach;
-import org.sxkj.resource.feign.IAttachClient;
import org.sxkj.resource.param.AttachPageParam;
import org.sxkj.resource.param.AttachParam;
import org.sxkj.resource.service.IAttachService;
-import org.sxkj.resource.vo.*;
-import org.sxkj.system.vo.TreeVo;
+import org.sxkj.resource.vo.AttachVO;
+import org.sxkj.resource.vo.AttachmentDownloadParam;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;
@@ -49,12 +37,7 @@
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.time.LocalDateTime;
-import java.util.Arrays;
-import java.util.Date;
-import java.util.List;
import java.util.Objects;
-
-import static org.springblade.core.cache.constant.CacheConstant.RESOURCE_CACHE;
/**
* 附件表 控制器
@@ -136,9 +119,9 @@
@ApiOperationSupport(order = 2)
@ApiOperation(value = "附件分页", notes = "传入attach")
public R<IPage<Attach>> list(Attach attach, Query query) {
- List<String> wayLineJobIds = attach.getWayLineJobIds();
- QueryWrapper<Attach> queryWrapper1 = Condition.getQueryWrapper(attach);
- QueryWrapper<Attach> queryWrapper = queryWrapper1.in(!CollectionUtils.isEmpty(wayLineJobIds), "wayline_job_id", wayLineJobIds);
+ String patrolTaskId = attach.getPatrolTaskId();
+ QueryWrapper<Attach> queryWrapper1 = Condition.getQueryWrapper(attach);
+ QueryWrapper<Attach> queryWrapper = queryWrapper1.eq(!StringUtils.isEmpty(patrolTaskId), "patrol_task_id", patrolTaskId);
queryWrapper.eq("is_deleted", 0);
IPage<Attach> pages = attachService.page(Condition.getPage(query), queryWrapper);
return R.data(pages);
@@ -206,7 +189,51 @@
return R.status(attachService.updateById(attach));
}
+ /**
+ * 流式附件下载接口,支持下载zip压缩包,不使用本地存储
+ * @param response
+ * @throws IOException
+ */
+ @ApiOperation(value = "流式附件下载接口", notes = "使用流方式返回数据,不使用本地存储")
+ @GetMapping("/downloadByByte")
+ public void downloadByByte(
+ @ApiParam(value = "附件下载参数") @RequestParam("attachIds") String attachIds, HttpServletResponse response) throws IOException {
+ // 设置文件名
+ String timestamp = DateTimeUtil.format(LocalDateTime.now(), "yyyyMMdd_HHmmss");
+ String fileName = "attachments_" + timestamp + ".zip";
+
+ // 设置响应头
+ response.setContentType("application/zip");
+ response.setHeader("Content-Disposition", "attachment; filename=" + URLEncoder.encode(fileName, StandardCharsets.UTF_8.name()));
+
+ // 获取响应输出流
+ ServletOutputStream outputStream = null;
+ try {
+ outputStream = response.getOutputStream();
+
+ Boolean result = attachService.downloadByByte(attachIds, outputStream);
+ if (!result) {
+ return;
+ }
+ } catch (Exception e) {
+ if (!response.isCommitted()) {
+ response.reset();
+ response.setContentType("application/json;charset=UTF-8");
+ ResponseResult errorResult = ResponseResult.error("下载文件失败: " + e.getMessage());
+
+ // 使用输出流写入错误信息,避免getWriter()冲突
+ try {
+ byte[] errorBytes = JSON.toJSONString(errorResult).getBytes(StandardCharsets.UTF_8);
+ outputStream.write(errorBytes);
+ } catch (IOException ioException) {
+ log.error("Error writing error response: {}", ioException.getMessage());
+ }
+ } else {
+ log.error("Cannot send error response: response already committed. Exception: {}", e.getMessage());
+ }
+ }
+ }
/**
* 删除 附件表及对应的附件信息
--
Gitblit v1.9.3