perf(定时报告): 发送完消息删除临时文件
This commit is contained in:
parent
6596ca9d71
commit
47bb7d29ce
@ -18,8 +18,9 @@ import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
|||||||
|
|
||||||
public class ExcelUtils {
|
public class ExcelUtils {
|
||||||
private static final String suffix = ".xlsx";
|
private static final String suffix = ".xlsx";
|
||||||
|
private static final String BASE_ROOT = "/opt/dataease/data/";
|
||||||
|
|
||||||
public static File exportExcel(List<ExcelSheetModel> sheets, String fileName) throws Exception {
|
public static File exportExcel(List<ExcelSheetModel> sheets, String fileName, String folderId) throws Exception {
|
||||||
AtomicReference<String> realFileName = new AtomicReference<>(fileName);
|
AtomicReference<String> realFileName = new AtomicReference<>(fileName);
|
||||||
Workbook wb = new XSSFWorkbook();
|
Workbook wb = new XSSFWorkbook();
|
||||||
|
|
||||||
@ -63,7 +64,14 @@ public class ExcelUtils {
|
|||||||
if (!StringUtils.endsWith(fileName, suffix)) {
|
if (!StringUtils.endsWith(fileName, suffix)) {
|
||||||
realFileName.set(realFileName.get() + suffix);
|
realFileName.set(realFileName.get() + suffix);
|
||||||
}
|
}
|
||||||
File result = new File("/opt/dataease/data/" + realFileName.get());
|
String folderPath = BASE_ROOT;
|
||||||
|
if (StringUtils.isNotBlank(folderId)) {
|
||||||
|
folderPath = BASE_ROOT + folderId + "/";
|
||||||
|
}
|
||||||
|
if (!FileUtil.exist(folderPath)) {
|
||||||
|
FileUtil.mkdir(folderPath);
|
||||||
|
}
|
||||||
|
File result = new File(folderPath + realFileName.get());
|
||||||
BufferedOutputStream outputStream = FileUtil.getOutputStream(result);
|
BufferedOutputStream outputStream = FileUtil.getOutputStream(result);
|
||||||
try {
|
try {
|
||||||
wb.write(outputStream);
|
wb.write(outputStream);
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
package io.dataease.job.sechedule.strategy.impl;
|
package io.dataease.job.sechedule.strategy.impl;
|
||||||
|
|
||||||
|
import cn.hutool.core.io.FileUtil;
|
||||||
import io.dataease.auth.entity.SysUserEntity;
|
import io.dataease.auth.entity.SysUserEntity;
|
||||||
import io.dataease.auth.entity.TokenInfo;
|
import io.dataease.auth.entity.TokenInfo;
|
||||||
import io.dataease.auth.service.AuthUserService;
|
import io.dataease.auth.service.AuthUserService;
|
||||||
@ -160,6 +161,7 @@ public class EmailTaskHandler extends TaskHandler implements Job {
|
|||||||
EmailXpackService emailXpackService = SpringContextUtil.getBean(EmailXpackService.class);
|
EmailXpackService emailXpackService = SpringContextUtil.getBean(EmailXpackService.class);
|
||||||
AuthUserServiceImpl userService = SpringContextUtil.getBean(AuthUserServiceImpl.class);
|
AuthUserServiceImpl userService = SpringContextUtil.getBean(AuthUserServiceImpl.class);
|
||||||
SysUserService sysUserService = SpringContextUtil.getBean(SysUserService.class);
|
SysUserService sysUserService = SpringContextUtil.getBean(SysUserService.class);
|
||||||
|
List<File> files = null;
|
||||||
try {
|
try {
|
||||||
XpackEmailTaskRequest taskForm = emailXpackService.taskForm(taskInstance.getTaskId());
|
XpackEmailTaskRequest taskForm = emailXpackService.taskForm(taskInstance.getTaskId());
|
||||||
if (ObjectUtils.isEmpty(taskForm) || CronUtils.taskExpire(taskForm.getEndTime())) {
|
if (ObjectUtils.isEmpty(taskForm) || CronUtils.taskExpire(taskForm.getEndTime())) {
|
||||||
@ -199,7 +201,7 @@ public class EmailTaskHandler extends TaskHandler implements Job {
|
|||||||
contentStr = new String(content, "UTF-8");
|
contentStr = new String(content, "UTF-8");
|
||||||
}
|
}
|
||||||
|
|
||||||
List<File> files = null;
|
|
||||||
String viewIds = emailTemplateDTO.getViewIds();
|
String viewIds = emailTemplateDTO.getViewIds();
|
||||||
ChartViewService chartViewService = SpringContextUtil.getBean(ChartViewService.class);
|
ChartViewService chartViewService = SpringContextUtil.getBean(ChartViewService.class);
|
||||||
List<ViewOption> viewOptions = chartViewService.viewOptions(panelId);
|
List<ViewOption> viewOptions = chartViewService.viewOptions(panelId);
|
||||||
@ -343,6 +345,14 @@ public class EmailTaskHandler extends TaskHandler implements Job {
|
|||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
error(taskInstance, e);
|
error(taskInstance, e);
|
||||||
LogUtil.error(e.getMessage(), e);
|
LogUtil.error(e.getMessage(), e);
|
||||||
|
} finally {
|
||||||
|
if (CollectionUtils.isNotEmpty(files)) {
|
||||||
|
files.forEach(file -> {
|
||||||
|
if (file.exists()) {
|
||||||
|
FileUtil.del(file);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -233,7 +233,7 @@ public class XEmailTaskServer {
|
|||||||
ExcelSheetModel excelSheetModel = excelSheetModel(instanceDTOS);
|
ExcelSheetModel excelSheetModel = excelSheetModel(instanceDTOS);
|
||||||
List<ExcelSheetModel> sheetModels = new ArrayList<>();
|
List<ExcelSheetModel> sheetModels = new ArrayList<>();
|
||||||
sheetModels.add(excelSheetModel);
|
sheetModels.add(excelSheetModel);
|
||||||
File file = ExcelUtils.exportExcel(sheetModels, null);
|
File file = ExcelUtils.exportExcel(sheetModels, null, null);
|
||||||
InputStream inputStream = new FileInputStream(file);
|
InputStream inputStream = new FileInputStream(file);
|
||||||
HttpServletResponse response = ServletUtils.response();
|
HttpServletResponse response = ServletUtils.response();
|
||||||
try {
|
try {
|
||||||
|
|||||||
@ -51,7 +51,7 @@ public class ViewExportExcel {
|
|||||||
Map<String, ChartExtRequest> stringChartExtRequestMap = buildViewRequest(panelDto, justView);
|
Map<String, ChartExtRequest> stringChartExtRequestMap = buildViewRequest(panelDto, justView);
|
||||||
List<File> results = new ArrayList<>();
|
List<File> results = new ArrayList<>();
|
||||||
List<ExcelSheetModel> sheets = viewIds.stream().map(viewId -> viewFiles(viewId, stringChartExtRequestMap.get(viewId))).collect(Collectors.toList());
|
List<ExcelSheetModel> sheets = viewIds.stream().map(viewId -> viewFiles(viewId, stringChartExtRequestMap.get(viewId))).collect(Collectors.toList());
|
||||||
File excelFile = ExcelUtils.exportExcel(sheets, panelDto.getName());
|
File excelFile = ExcelUtils.exportExcel(sheets, panelDto.getName(), panelDto.getId());
|
||||||
results.add(excelFile);
|
results.add(excelFile);
|
||||||
return results;
|
return results;
|
||||||
}
|
}
|
||||||
@ -62,7 +62,7 @@ public class ViewExportExcel {
|
|||||||
List<Map<String, Object>> components = gson.fromJson(componentsJson, tokenType);
|
List<Map<String, Object>> components = gson.fromJson(componentsJson, tokenType);
|
||||||
String panelStyle = panelDto.getPanelStyle();
|
String panelStyle = panelDto.getPanelStyle();
|
||||||
Map map = gson.fromJson(panelStyle, Map.class);
|
Map map = gson.fromJson(panelStyle, Map.class);
|
||||||
Map panelMap = (LinkedTreeMap)map.get("panel");
|
Map panelMap = (LinkedTreeMap) map.get("panel");
|
||||||
double resultCount = Double.parseDouble(panelMap.get("resultCount").toString());
|
double resultCount = Double.parseDouble(panelMap.get("resultCount").toString());
|
||||||
String resultMode = panelMap.get("resultMode").toString();
|
String resultMode = panelMap.get("resultMode").toString();
|
||||||
|
|
||||||
@ -73,7 +73,7 @@ public class ViewExportExcel {
|
|||||||
ChartExtRequest chartExtRequest = new ChartExtRequest();
|
ChartExtRequest chartExtRequest = new ChartExtRequest();
|
||||||
chartExtRequest.setQueryFrom("panel");
|
chartExtRequest.setQueryFrom("panel");
|
||||||
chartExtRequest.setFilter(chartExtFilterRequests);
|
chartExtRequest.setFilter(chartExtFilterRequests);
|
||||||
chartExtRequest.setResultCount((int)resultCount);
|
chartExtRequest.setResultCount((int) resultCount);
|
||||||
chartExtRequest.setResultMode(resultMode);
|
chartExtRequest.setResultMode(resultMode);
|
||||||
result.put(entry.getKey(), chartExtRequest);
|
result.put(entry.getKey(), chartExtRequest);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user