update 优化 替换过期工具类与优化代码用法
This commit is contained in:
parent
fb43fb9af7
commit
2472d531f5
@ -13,7 +13,6 @@ import lombok.RequiredArgsConstructor;
|
|||||||
import org.apache.batik.transcoder.TranscoderInput;
|
import org.apache.batik.transcoder.TranscoderInput;
|
||||||
import org.apache.batik.transcoder.TranscoderOutput;
|
import org.apache.batik.transcoder.TranscoderOutput;
|
||||||
import org.apache.batik.transcoder.image.PNGTranscoder;
|
import org.apache.batik.transcoder.image.PNGTranscoder;
|
||||||
import org.apache.commons.io.IOUtils;
|
|
||||||
import org.dromara.common.core.exception.ServiceException;
|
import org.dromara.common.core.exception.ServiceException;
|
||||||
import org.dromara.common.mybatis.core.page.PageQuery;
|
import org.dromara.common.mybatis.core.page.PageQuery;
|
||||||
import org.dromara.common.mybatis.core.page.TableDataInfo;
|
import org.dromara.common.mybatis.core.page.TableDataInfo;
|
||||||
@ -34,7 +33,10 @@ import org.flowable.bpmn.model.BpmnModel;
|
|||||||
import org.flowable.bpmn.model.Process;
|
import org.flowable.bpmn.model.Process;
|
||||||
import org.flowable.bpmn.model.UserTask;
|
import org.flowable.bpmn.model.UserTask;
|
||||||
import org.flowable.engine.RepositoryService;
|
import org.flowable.engine.RepositoryService;
|
||||||
import org.flowable.engine.repository.*;
|
import org.flowable.engine.repository.Deployment;
|
||||||
|
import org.flowable.engine.repository.Model;
|
||||||
|
import org.flowable.engine.repository.ModelQuery;
|
||||||
|
import org.flowable.engine.repository.ProcessDefinition;
|
||||||
import org.flowable.validation.ValidationError;
|
import org.flowable.validation.ValidationError;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
@ -46,7 +48,6 @@ import java.io.InputStream;
|
|||||||
import java.net.URLEncoder;
|
import java.net.URLEncoder;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
@ -249,7 +250,7 @@ public class ActModelServiceImpl implements IActModelService {
|
|||||||
if (ArrayUtil.isEmpty(xmlBytes)) {
|
if (ArrayUtil.isEmpty(xmlBytes)) {
|
||||||
throw new ServiceException("模型数据为空,请先设计流程定义模型,再进行部署!");
|
throw new ServiceException("模型数据为空,请先设计流程定义模型,再进行部署!");
|
||||||
}
|
}
|
||||||
if (JSONUtil.isTypeJSON(IOUtils.toString(xmlBytes, StandardCharsets.UTF_8.toString()))) {
|
if (JSONUtil.isTypeJSON(new String(xmlBytes, StandardCharsets.UTF_8))) {
|
||||||
byte[] bytes = ModelUtils.bpmnJsonToXmlBytes(xmlBytes);
|
byte[] bytes = ModelUtils.bpmnJsonToXmlBytes(xmlBytes);
|
||||||
if (ArrayUtil.isEmpty(bytes)) {
|
if (ArrayUtil.isEmpty(bytes)) {
|
||||||
throw new ServiceException("模型不能为空,请至少设计一条主线流程!");
|
throw new ServiceException("模型不能为空,请至少设计一条主线流程!");
|
||||||
@ -337,9 +338,7 @@ public class ActModelServiceImpl implements IActModelService {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void exportZip(List<String> modelIds, HttpServletResponse response) {
|
public void exportZip(List<String> modelIds, HttpServletResponse response) {
|
||||||
ZipOutputStream zos = null;
|
try (ZipOutputStream zos = ZipUtil.getZipOutputStream(response.getOutputStream(), StandardCharsets.UTF_8)) {
|
||||||
try {
|
|
||||||
zos = ZipUtil.getZipOutputStream(response.getOutputStream(), StandardCharsets.UTF_8);
|
|
||||||
// 压缩包文件名
|
// 压缩包文件名
|
||||||
String zipName = "模型不存在";
|
String zipName = "模型不存在";
|
||||||
// 查询模型基本信息
|
// 查询模型基本信息
|
||||||
@ -347,7 +346,7 @@ public class ActModelServiceImpl implements IActModelService {
|
|||||||
Model model = repositoryService.getModel(modelId);
|
Model model = repositoryService.getModel(modelId);
|
||||||
byte[] xmlBytes = repositoryService.getModelEditorSource(modelId);
|
byte[] xmlBytes = repositoryService.getModelEditorSource(modelId);
|
||||||
if (ObjectUtil.isNotNull(model)) {
|
if (ObjectUtil.isNotNull(model)) {
|
||||||
if (JSONUtil.isTypeJSON(IOUtils.toString(xmlBytes, StandardCharsets.UTF_8.toString())) && ArrayUtil.isEmpty(ModelUtils.bpmnJsonToXmlBytes(xmlBytes))) {
|
if (JSONUtil.isTypeJSON(new String(xmlBytes, StandardCharsets.UTF_8)) && ArrayUtil.isEmpty(ModelUtils.bpmnJsonToXmlBytes(xmlBytes))) {
|
||||||
zipName = "模型不能为空,请至少设计一条主线流程!";
|
zipName = "模型不能为空,请至少设计一条主线流程!";
|
||||||
zos.putNextEntry(new ZipEntry(zipName + ".txt"));
|
zos.putNextEntry(new ZipEntry(zipName + ".txt"));
|
||||||
zos.write(zipName.getBytes(StandardCharsets.UTF_8));
|
zos.write(zipName.getBytes(StandardCharsets.UTF_8));
|
||||||
@ -367,19 +366,11 @@ public class ActModelServiceImpl implements IActModelService {
|
|||||||
}
|
}
|
||||||
response.setHeader("Content-Disposition",
|
response.setHeader("Content-Disposition",
|
||||||
"attachment; filename=" + URLEncoder.encode(zipName, StandardCharsets.UTF_8) + ".zip");
|
"attachment; filename=" + URLEncoder.encode(zipName, StandardCharsets.UTF_8) + ".zip");
|
||||||
|
response.addHeader("Access-Control-Expose-Headers", "Content-Disposition");
|
||||||
// 刷出响应流
|
// 刷出响应流
|
||||||
response.flushBuffer();
|
response.flushBuffer();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
} finally {
|
|
||||||
if (zos != null) {
|
|
||||||
try {
|
|
||||||
zos.closeEntry();
|
|
||||||
zos.close();
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -9,7 +9,6 @@ import cn.hutool.core.util.ObjectUtil;
|
|||||||
import cn.hutool.core.util.StrUtil;
|
import cn.hutool.core.util.StrUtil;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import lombok.SneakyThrows;
|
import lombok.SneakyThrows;
|
||||||
import org.apache.commons.io.IOUtils;
|
|
||||||
import org.dromara.common.core.exception.ServiceException;
|
import org.dromara.common.core.exception.ServiceException;
|
||||||
import org.dromara.common.core.utils.StreamUtils;
|
import org.dromara.common.core.utils.StreamUtils;
|
||||||
import org.dromara.common.core.utils.StringUtils;
|
import org.dromara.common.core.utils.StringUtils;
|
||||||
@ -37,7 +36,6 @@ import org.flowable.engine.RepositoryService;
|
|||||||
import org.flowable.engine.history.HistoricProcessInstance;
|
import org.flowable.engine.history.HistoricProcessInstance;
|
||||||
import org.flowable.engine.impl.bpmn.deployer.ResourceNameUtil;
|
import org.flowable.engine.impl.bpmn.deployer.ResourceNameUtil;
|
||||||
import org.flowable.engine.repository.*;
|
import org.flowable.engine.repository.*;
|
||||||
import org.flowable.task.api.history.HistoricTaskInstance;
|
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
import org.springframework.web.multipart.MultipartFile;
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
@ -45,7 +43,10 @@ import org.springframework.web.multipart.MultipartFile;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.*;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
import java.util.zip.ZipEntry;
|
import java.util.zip.ZipEntry;
|
||||||
import java.util.zip.ZipInputStream;
|
import java.util.zip.ZipInputStream;
|
||||||
|
|
||||||
@ -161,7 +162,7 @@ public class ActProcessDefinitionServiceImpl implements IActProcessDefinitionSer
|
|||||||
@Override
|
@Override
|
||||||
public String definitionImage(String processDefinitionId) {
|
public String definitionImage(String processDefinitionId) {
|
||||||
InputStream inputStream = repositoryService.getProcessDiagram(processDefinitionId);
|
InputStream inputStream = repositoryService.getProcessDiagram(processDefinitionId);
|
||||||
return Base64.encode(IOUtils.toByteArray(inputStream));
|
return Base64.encode(IoUtil.readBytes(inputStream));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -173,13 +174,8 @@ public class ActProcessDefinitionServiceImpl implements IActProcessDefinitionSer
|
|||||||
public String definitionXml(String processDefinitionId) {
|
public String definitionXml(String processDefinitionId) {
|
||||||
StringBuilder xml = new StringBuilder();
|
StringBuilder xml = new StringBuilder();
|
||||||
ProcessDefinition processDefinition = repositoryService.getProcessDefinition(processDefinitionId);
|
ProcessDefinition processDefinition = repositoryService.getProcessDefinition(processDefinitionId);
|
||||||
InputStream inputStream;
|
InputStream inputStream = repositoryService.getResourceAsStream(processDefinition.getDeploymentId(), processDefinition.getResourceName());
|
||||||
try {
|
xml.append(IoUtil.read(inputStream, StandardCharsets.UTF_8));
|
||||||
inputStream = repositoryService.getResourceAsStream(processDefinition.getDeploymentId(), processDefinition.getResourceName());
|
|
||||||
xml.append(IOUtils.toString(inputStream, StandardCharsets.UTF_8));
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
return xml.toString();
|
return xml.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,11 +3,11 @@ package org.dromara.workflow.service.impl;
|
|||||||
import cn.hutool.core.bean.BeanUtil;
|
import cn.hutool.core.bean.BeanUtil;
|
||||||
import cn.hutool.core.codec.Base64;
|
import cn.hutool.core.codec.Base64;
|
||||||
import cn.hutool.core.collection.CollUtil;
|
import cn.hutool.core.collection.CollUtil;
|
||||||
|
import cn.hutool.core.io.IoUtil;
|
||||||
import cn.hutool.core.util.ObjectUtil;
|
import cn.hutool.core.util.ObjectUtil;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import lombok.SneakyThrows;
|
import lombok.SneakyThrows;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.apache.commons.io.IOUtils;
|
|
||||||
import org.dromara.common.core.exception.ServiceException;
|
import org.dromara.common.core.exception.ServiceException;
|
||||||
import org.dromara.common.core.utils.StreamUtils;
|
import org.dromara.common.core.utils.StreamUtils;
|
||||||
import org.dromara.common.core.utils.StringUtils;
|
import org.dromara.common.core.utils.StringUtils;
|
||||||
@ -52,7 +52,6 @@ import org.springframework.stereotype.Service;
|
|||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -236,7 +235,7 @@ public class ActProcessInstanceServiceImpl implements IActProcessInstanceService
|
|||||||
BpmnModel bpmnModel = repositoryService.getBpmnModel(processDefinitionId);
|
BpmnModel bpmnModel = repositoryService.getBpmnModel(processDefinitionId);
|
||||||
CustomDefaultProcessDiagramGenerator diagramGenerator = new CustomDefaultProcessDiagramGenerator();
|
CustomDefaultProcessDiagramGenerator diagramGenerator = new CustomDefaultProcessDiagramGenerator();
|
||||||
InputStream inputStream = diagramGenerator.generateDiagram(bpmnModel, "png", highLightedNodeList, highLightedFlows, activityFontName, labelFontName, annotationFontName, null, 1.0, true);
|
InputStream inputStream = diagramGenerator.generateDiagram(bpmnModel, "png", highLightedNodeList, highLightedFlows, activityFontName, labelFontName, annotationFontName, null, 1.0, true);
|
||||||
return Base64.encode(IOUtils.toByteArray(inputStream));
|
return Base64.encode(IoUtil.readBytes(inputStream));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -282,14 +281,9 @@ public class ActProcessInstanceServiceImpl implements IActProcessInstanceService
|
|||||||
map.put("taskList", taskList);
|
map.put("taskList", taskList);
|
||||||
List<ActHistoryInfoVo> historyTaskList = getHistoryTaskList(processInstanceId);
|
List<ActHistoryInfoVo> historyTaskList = getHistoryTaskList(processInstanceId);
|
||||||
map.put("historyList", historyTaskList);
|
map.put("historyList", historyTaskList);
|
||||||
InputStream inputStream;
|
InputStream inputStream = repositoryService.getResourceAsStream(processDefinition.getDeploymentId(), processDefinition.getResourceName());
|
||||||
try {
|
xml.append(IoUtil.read(inputStream, StandardCharsets.UTF_8));
|
||||||
inputStream = repositoryService.getResourceAsStream(processDefinition.getDeploymentId(), processDefinition.getResourceName());
|
map.put("xml", xml.toString());
|
||||||
xml.append(IOUtils.toString(inputStream, String.valueOf(StandardCharsets.UTF_8)));
|
|
||||||
map.put("xml", xml.toString());
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
return map;
|
return map;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user