From aeaa254ddf9bfeafe4595af8647c12d84e825f70 Mon Sep 17 00:00:00 2001 From: taojinlong Date: Mon, 16 Jun 2025 17:24:58 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20[Bug]=E9=AB=98=E5=8F=AF=E7=94=A8?= =?UTF-8?q?=E7=8E=AF=E5=A2=83=E4=B8=8B=EF=BC=8C=E5=AF=BC=E5=87=BAExcel?= =?UTF-8?q?=E4=B8=8B=E8=BD=BD=E6=8A=A5=E9=94=99=E9=97=AE=E9=A2=98=20#16287?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../auto/entity/CoreExportDownloadTask.java | 57 +++++++++++++++++++ .../mapper/CoreExportDownloadTaskMapper.java | 18 ++++++ .../manage/ExportCenterManage.java | 29 ++++++---- .../resources/db/desktop/V2.10.11__ddl.sql | 8 +++ .../resources/db/migration/V2.10.11__ddl.sql | 8 +++ 5 files changed, 109 insertions(+), 11 deletions(-) create mode 100644 core/core-backend/src/main/java/io/dataease/exportCenter/dao/auto/entity/CoreExportDownloadTask.java create mode 100644 core/core-backend/src/main/java/io/dataease/exportCenter/dao/auto/mapper/CoreExportDownloadTaskMapper.java create mode 100644 core/core-backend/src/main/resources/db/desktop/V2.10.11__ddl.sql create mode 100644 core/core-backend/src/main/resources/db/migration/V2.10.11__ddl.sql diff --git a/core/core-backend/src/main/java/io/dataease/exportCenter/dao/auto/entity/CoreExportDownloadTask.java b/core/core-backend/src/main/java/io/dataease/exportCenter/dao/auto/entity/CoreExportDownloadTask.java new file mode 100644 index 0000000000..c2b11aa364 --- /dev/null +++ b/core/core-backend/src/main/java/io/dataease/exportCenter/dao/auto/entity/CoreExportDownloadTask.java @@ -0,0 +1,57 @@ +package io.dataease.exportCenter.dao.auto.entity; + +import com.baomidou.mybatisplus.annotation.TableName; +import java.io.Serializable; + +/** + *

+ * 下载任务列表 + *

+ * + * @author fit2cloud + * @since 2025-06-16 + */ +@TableName("core_export_download_task") +public class CoreExportDownloadTask implements Serializable { + + private static final long serialVersionUID = 1L; + + private String id; + + private Long createTime; + + private Long validTime; + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public Long getCreateTime() { + return createTime; + } + + public void setCreateTime(Long createTime) { + this.createTime = createTime; + } + + public Long getValidTime() { + return validTime; + } + + public void setValidTime(Long validTime) { + this.validTime = validTime; + } + + @Override + public String toString() { + return "CoreExportDownloadTask{" + + "id = " + id + + ", createTime = " + createTime + + ", validTime = " + validTime + + "}"; + } +} diff --git a/core/core-backend/src/main/java/io/dataease/exportCenter/dao/auto/mapper/CoreExportDownloadTaskMapper.java b/core/core-backend/src/main/java/io/dataease/exportCenter/dao/auto/mapper/CoreExportDownloadTaskMapper.java new file mode 100644 index 0000000000..304b623d54 --- /dev/null +++ b/core/core-backend/src/main/java/io/dataease/exportCenter/dao/auto/mapper/CoreExportDownloadTaskMapper.java @@ -0,0 +1,18 @@ +package io.dataease.exportCenter.dao.auto.mapper; + +import io.dataease.exportCenter.dao.auto.entity.CoreExportDownloadTask; +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import org.apache.ibatis.annotations.Mapper; + +/** + *

+ * 下载任务列表 Mapper 接口 + *

+ * + * @author fit2cloud + * @since 2025-06-16 + */ +@Mapper +public interface CoreExportDownloadTaskMapper extends BaseMapper { + +} diff --git a/core/core-backend/src/main/java/io/dataease/exportCenter/manage/ExportCenterManage.java b/core/core-backend/src/main/java/io/dataease/exportCenter/manage/ExportCenterManage.java index 24a73ea7ec..9d2513cea2 100644 --- a/core/core-backend/src/main/java/io/dataease/exportCenter/manage/ExportCenterManage.java +++ b/core/core-backend/src/main/java/io/dataease/exportCenter/manage/ExportCenterManage.java @@ -180,7 +180,7 @@ public class ExportCenterManage implements BaseExportApi { public void download(String id, HttpServletResponse response) throws Exception { - if (!downLoadInfos.stream().anyMatch(downLoadInfo -> downLoadInfo.getId().equals(id))) { + if (coreExportDownloadTaskMapper.selectById(id) == null) { DEException.throwException("任务不存在"); } CoreExportTask exportTask = coreExportTaskRepository.findById(id).orElse(null); @@ -367,7 +367,7 @@ public class ExportCenterManage implements BaseExportApi { exportTask.setExportTime(System.currentTimeMillis()); exportTask.setParams(JsonUtil.toJSONString(request).toString()); exportTask.setExportMachineName(hostName()); - coreExportTaskRepository.saveAndFlush(exportTask); + exportTaskMapper.insert(exportTask); if(busiFlag.equalsIgnoreCase("dashboard")){ exportCenterDownLoadManage.startPanelViewTask(exportTask, request); }else { @@ -829,20 +829,27 @@ public class ExportCenterManage implements BaseExportApi { @DeLog(id = "#p0", ot = LogOT.DOWNLOAD, st = LogST.DATA) public void generateDownloadUri(String id) { - if (!downLoadInfos.stream().anyMatch(downLoadInfo -> downLoadInfo.getId().equals(id))) { - DownLoadInfo downLoadInfo = new DownLoadInfo(); - downLoadInfo.setId(id); - downLoadInfo.setCreateTime(System.currentTimeMillis()); - downLoadInfo.setValidTime(5L); - downLoadInfos.add(downLoadInfo); + CoreExportDownloadTask coreExportDownloadTask = coreExportDownloadTaskMapper.selectById(id); + if (coreExportDownloadTask != null) { + coreExportDownloadTask.setCreateTime(System.currentTimeMillis()); + coreExportDownloadTaskMapper.updateById(coreExportDownloadTask); + } else { + coreExportDownloadTask = new CoreExportDownloadTask(); + coreExportDownloadTask.setId(id); + coreExportDownloadTask.setCreateTime(System.currentTimeMillis()); + coreExportDownloadTask.setValidTime(5L); + coreExportDownloadTaskMapper.insert(coreExportDownloadTask); } } - private List downLoadInfos = new ArrayList<>(); - @Scheduled(fixedRate = 10 * 1000) + @Scheduled(fixedRate = 60 * 60 * 1000) public void checkDownLoadInfos() { - downLoadInfos.removeIf(downLoadInfo -> System.currentTimeMillis() - downLoadInfo.createTime > downLoadInfo.validTime * 60 * 1000); + coreExportDownloadTaskMapper.selectList(null).forEach(downLoadInfo -> { + if (System.currentTimeMillis() - downLoadInfo.getCreateTime() > downLoadInfo.getValidTime() * 60 * 1000) { + coreExportDownloadTaskMapper.deleteById(downLoadInfo.getId()); + } + }); } @Data diff --git a/core/core-backend/src/main/resources/db/desktop/V2.10.11__ddl.sql b/core/core-backend/src/main/resources/db/desktop/V2.10.11__ddl.sql new file mode 100644 index 0000000000..04053fbd77 --- /dev/null +++ b/core/core-backend/src/main/resources/db/desktop/V2.10.11__ddl.sql @@ -0,0 +1,8 @@ +DROP TABLE IF EXISTS `core_export_download_task`; +CREATE TABLE `core_export_download_task` +( + `id` varchar(255) NOT NULL, + `create_time` bigint(20) DEFAULT NULL, + `valid_time` bigint(20) DEFAULT NULL, + PRIMARY KEY (`id`) +) COMMENT='下载任务列表'; diff --git a/core/core-backend/src/main/resources/db/migration/V2.10.11__ddl.sql b/core/core-backend/src/main/resources/db/migration/V2.10.11__ddl.sql new file mode 100644 index 0000000000..04053fbd77 --- /dev/null +++ b/core/core-backend/src/main/resources/db/migration/V2.10.11__ddl.sql @@ -0,0 +1,8 @@ +DROP TABLE IF EXISTS `core_export_download_task`; +CREATE TABLE `core_export_download_task` +( + `id` varchar(255) NOT NULL, + `create_time` bigint(20) DEFAULT NULL, + `valid_time` bigint(20) DEFAULT NULL, + PRIMARY KEY (`id`) +) COMMENT='下载任务列表';