fix: [Bug]高可用环境下,导出Excel下载报错问题 #16287

This commit is contained in:
taojinlong
2025-06-16 17:24:58 +08:00
committed by taojinlong
parent 4f39c7ec83
commit aeaa254ddf
5 changed files with 109 additions and 11 deletions

View File

@@ -0,0 +1,57 @@
package io.dataease.exportCenter.dao.auto.entity;
import com.baomidou.mybatisplus.annotation.TableName;
import java.io.Serializable;
/**
* <p>
* 下载任务列表
* </p>
*
* @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 +
"}";
}
}

View File

@@ -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;
/**
* <p>
* 下载任务列表 Mapper 接口
* </p>
*
* @author fit2cloud
* @since 2025-06-16
*/
@Mapper
public interface CoreExportDownloadTaskMapper extends BaseMapper<CoreExportDownloadTask> {
}

View File

@@ -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<DownLoadInfo> 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

View File

@@ -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='下载任务列表';

View File

@@ -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='下载任务列表';