mirror of
https://github.com/dromara/RuoYi-Vue-Plus.git
synced 2025-09-30 07:06:39 +08:00
添加流程定义分页,查看图片,查看xml
This commit is contained in:
parent
3a5e34acc7
commit
d1abc3daa5
@ -42,6 +42,11 @@ public class ActModelController extends BaseController {
|
|||||||
private final IActModelService iActModelService;
|
private final IActModelService iActModelService;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 分页查询模型
|
||||||
|
*
|
||||||
|
* @param modelBo 模型参数
|
||||||
|
*/
|
||||||
@GetMapping("/list")
|
@GetMapping("/list")
|
||||||
public TableDataInfo<Model> getByPage(ModelBo modelBo) {
|
public TableDataInfo<Model> getByPage(ModelBo modelBo) {
|
||||||
return iActModelService.getByPage(modelBo);
|
return iActModelService.getByPage(modelBo);
|
||||||
|
@ -0,0 +1,81 @@
|
|||||||
|
package org.dromara.workflow.controller;
|
||||||
|
|
||||||
|
import jakarta.servlet.http.HttpServletResponse;
|
||||||
|
import jakarta.validation.constraints.NotBlank;
|
||||||
|
import jakarta.validation.constraints.NotEmpty;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import org.dromara.common.core.domain.R;
|
||||||
|
import org.dromara.common.mybatis.core.page.TableDataInfo;
|
||||||
|
import org.dromara.common.web.core.BaseController;
|
||||||
|
import org.dromara.workflow.domain.bo.ProcessDefinitionBo;
|
||||||
|
import org.dromara.workflow.domain.vo.ProcessDefinitionVo;
|
||||||
|
import org.dromara.workflow.service.IActProcessDefinitionService;
|
||||||
|
import org.flowable.engine.repository.ProcessDefinition;
|
||||||
|
import org.springframework.validation.annotation.Validated;
|
||||||
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
import org.springframework.web.bind.annotation.PathVariable;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 流程定义管理 控制层
|
||||||
|
*
|
||||||
|
* @author may
|
||||||
|
*/
|
||||||
|
@Validated
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/workflow/processDefinition")
|
||||||
|
public class ActProcessDefinitionController extends BaseController {
|
||||||
|
|
||||||
|
private final IActProcessDefinitionService iActProcessDefinitionService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 分页查询
|
||||||
|
*
|
||||||
|
* @param processDefinitionBo 参数
|
||||||
|
*/
|
||||||
|
@GetMapping("/list")
|
||||||
|
public TableDataInfo<ProcessDefinitionVo> getByPage(ProcessDefinitionBo processDefinitionBo) {
|
||||||
|
return iActProcessDefinitionService.getByPage(processDefinitionBo);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询历史流程定义列表
|
||||||
|
*
|
||||||
|
* @param key 流程定义key
|
||||||
|
*/
|
||||||
|
@GetMapping("/getProcessDefinitionListByKey/{key}")
|
||||||
|
public R<List<ProcessDefinitionVo>> getProcessDefinitionList(@NotEmpty(message = "流程定义key不能为空") @PathVariable String key) {
|
||||||
|
return R.ok("操作成功", iActProcessDefinitionService.getProcessDefinitionListByKey(key));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查看流程定义图片
|
||||||
|
*
|
||||||
|
* @param processDefinitionId 流程定义id
|
||||||
|
* @param response 响应
|
||||||
|
*/
|
||||||
|
@GetMapping("/processDefinitionImage/{processDefinitionId}")
|
||||||
|
public void processDefinitionImage(@PathVariable String processDefinitionId, HttpServletResponse response) {
|
||||||
|
iActProcessDefinitionService.processDefinitionImage(processDefinitionId, response);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查看流程定义xml文件
|
||||||
|
*
|
||||||
|
* @param processDefinitionId 流程定义id
|
||||||
|
*/
|
||||||
|
@GetMapping("/processDefinitionXml/{processDefinitionId}")
|
||||||
|
public R<Map<String, Object>> getXml(@NotBlank(message = "流程定义id不能为空") @PathVariable String processDefinitionId) {
|
||||||
|
Map<String, Object> map = new HashMap<>();
|
||||||
|
String xmlStr = iActProcessDefinitionService.processDefinitionXml(processDefinitionId);
|
||||||
|
List<String> xml = new ArrayList<>(Arrays.asList(xmlStr.split("\n")));
|
||||||
|
map.put("xml", xml);
|
||||||
|
map.put("xmlStr", xmlStr);
|
||||||
|
return R.ok(map);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,31 @@
|
|||||||
|
package org.dromara.workflow.domain.bo;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
import org.dromara.workflow.common.PageEntity;
|
||||||
|
|
||||||
|
import java.io.Serial;
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 流程定义请求对象
|
||||||
|
*
|
||||||
|
* @author may
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@EqualsAndHashCode(callSuper = true)
|
||||||
|
public class ProcessDefinitionBo extends PageEntity implements Serializable {
|
||||||
|
|
||||||
|
@Serial
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 流程定义名称key
|
||||||
|
*/
|
||||||
|
private String key;
|
||||||
|
/**
|
||||||
|
* 流程定义名称
|
||||||
|
*/
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,65 @@
|
|||||||
|
package org.dromara.workflow.domain.vo;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.io.Serial;
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 流程定义视图
|
||||||
|
*
|
||||||
|
* @author may
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class ProcessDefinitionVo implements Serializable {
|
||||||
|
|
||||||
|
@Serial
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 流程定义id
|
||||||
|
*/
|
||||||
|
private String id;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 流程定义名称
|
||||||
|
*/
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 流程定义标识key
|
||||||
|
*/
|
||||||
|
private String key;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 流程定义版本
|
||||||
|
*/
|
||||||
|
private int version;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 流程定义挂起或激活 1激活 2挂起
|
||||||
|
*/
|
||||||
|
private int suspensionState;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 流程xml名称
|
||||||
|
*/
|
||||||
|
private String resourceName;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 流程图片名称
|
||||||
|
*/
|
||||||
|
private String diagramResourceName;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 流程部署id
|
||||||
|
*/
|
||||||
|
private String deploymentId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 流程部署时间
|
||||||
|
*/
|
||||||
|
private Date deploymentTime;
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,48 @@
|
|||||||
|
package org.dromara.workflow.service;
|
||||||
|
|
||||||
|
import jakarta.servlet.http.HttpServletResponse;
|
||||||
|
import org.dromara.common.mybatis.core.page.TableDataInfo;
|
||||||
|
import org.dromara.workflow.domain.bo.ProcessDefinitionBo;
|
||||||
|
import org.dromara.workflow.domain.vo.ProcessDefinitionVo;
|
||||||
|
import org.flowable.engine.repository.ProcessDefinition;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 流程定义 服务层
|
||||||
|
*
|
||||||
|
* @author may
|
||||||
|
*/
|
||||||
|
public interface IActProcessDefinitionService {
|
||||||
|
/**
|
||||||
|
* 分页查询
|
||||||
|
*
|
||||||
|
* @param processDefinitionBo 参数
|
||||||
|
* @return 返回分页列表
|
||||||
|
*/
|
||||||
|
TableDataInfo<ProcessDefinitionVo> getByPage(ProcessDefinitionBo processDefinitionBo);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询历史流程定义列表
|
||||||
|
*
|
||||||
|
* @param key 流程定义key
|
||||||
|
* @return 结果
|
||||||
|
*/
|
||||||
|
List<ProcessDefinitionVo> getProcessDefinitionListByKey(String key);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查看流程定义图片
|
||||||
|
*
|
||||||
|
* @param processDefinitionId 流程定义id
|
||||||
|
* @param response 响应
|
||||||
|
*/
|
||||||
|
void processDefinitionImage(String processDefinitionId, HttpServletResponse response);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查看流程定义xml文件
|
||||||
|
*
|
||||||
|
* @param processDefinitionId 流程定义id
|
||||||
|
* @return 结果
|
||||||
|
*/
|
||||||
|
String processDefinitionXml(String processDefinitionId);
|
||||||
|
}
|
@ -0,0 +1,166 @@
|
|||||||
|
package org.dromara.workflow.service.impl;
|
||||||
|
|
||||||
|
import cn.hutool.core.bean.BeanUtil;
|
||||||
|
import cn.hutool.core.collection.CollUtil;
|
||||||
|
import cn.hutool.core.collection.CollectionUtil;
|
||||||
|
import jakarta.servlet.ServletOutputStream;
|
||||||
|
import jakarta.servlet.http.HttpServletResponse;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import org.apache.commons.io.IOUtils;
|
||||||
|
import org.dromara.common.core.utils.StringUtils;
|
||||||
|
import org.dromara.common.mybatis.core.page.TableDataInfo;
|
||||||
|
import org.dromara.common.satoken.utils.LoginHelper;
|
||||||
|
import org.dromara.workflow.domain.bo.ProcessDefinitionBo;
|
||||||
|
import org.dromara.workflow.domain.vo.ProcessDefinitionVo;
|
||||||
|
import org.dromara.workflow.service.IActProcessDefinitionService;
|
||||||
|
import org.flowable.engine.RepositoryService;
|
||||||
|
import org.flowable.engine.repository.Deployment;
|
||||||
|
import org.flowable.engine.repository.ProcessDefinition;
|
||||||
|
import org.flowable.engine.repository.ProcessDefinitionQuery;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 流程定义 服务层实现
|
||||||
|
*
|
||||||
|
* @author may
|
||||||
|
*/
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
@Service
|
||||||
|
public class ActProcessDefinitionServiceImpl implements IActProcessDefinitionService {
|
||||||
|
|
||||||
|
private final RepositoryService repositoryService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 分页查询
|
||||||
|
*
|
||||||
|
* @param processDefinitionBo 参数
|
||||||
|
* @return 返回分页列表
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public TableDataInfo<ProcessDefinitionVo> getByPage(ProcessDefinitionBo processDefinitionBo) {
|
||||||
|
ProcessDefinitionQuery query = repositoryService.createProcessDefinitionQuery();
|
||||||
|
query.processDefinitionTenantId(LoginHelper.getTenantId());
|
||||||
|
if (StringUtils.isNotEmpty(processDefinitionBo.getKey())) {
|
||||||
|
query.processDefinitionKey(processDefinitionBo.getKey());
|
||||||
|
}
|
||||||
|
if (StringUtils.isNotEmpty(processDefinitionBo.getName())) {
|
||||||
|
query.processDefinitionNameLike("%" + processDefinitionBo.getName() + "%");
|
||||||
|
}
|
||||||
|
// 分页查询
|
||||||
|
List<ProcessDefinitionVo> processDefinitionVoList = new ArrayList<>();
|
||||||
|
List<ProcessDefinition> definitionList = query.latestVersion().listPage(processDefinitionBo.getPageNum(), processDefinitionBo.getPageSize());
|
||||||
|
List<Deployment> deploymentList = null;
|
||||||
|
if (CollUtil.isNotEmpty(definitionList)) {
|
||||||
|
List<String> deploymentIds = definitionList.stream().map(ProcessDefinition::getDeploymentId).collect(Collectors.toList());
|
||||||
|
deploymentList = repositoryService.createDeploymentQuery()
|
||||||
|
.deploymentIds(deploymentIds).list();
|
||||||
|
}
|
||||||
|
for (ProcessDefinition processDefinition : definitionList) {
|
||||||
|
ProcessDefinitionVo processDefinitionVo = BeanUtil.toBean(processDefinition, ProcessDefinitionVo.class);
|
||||||
|
if (CollUtil.isNotEmpty(deploymentList)) {
|
||||||
|
// 部署时间
|
||||||
|
deploymentList.stream().filter(e -> e.getId().equals(processDefinition.getDeploymentId())).findFirst().ifPresent(e -> {
|
||||||
|
processDefinitionVo.setDeploymentTime(e.getDeploymentTime());
|
||||||
|
});
|
||||||
|
}
|
||||||
|
processDefinitionVoList.add(processDefinitionVo);
|
||||||
|
}
|
||||||
|
// 总记录数
|
||||||
|
long total = query.count();
|
||||||
|
|
||||||
|
return new TableDataInfo<>(processDefinitionVoList, total);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询历史流程定义列表
|
||||||
|
*
|
||||||
|
* @param key 流程定义key
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public List<ProcessDefinitionVo> getProcessDefinitionListByKey(String key) {
|
||||||
|
List<ProcessDefinitionVo> processDefinitionVoList = new ArrayList<>();
|
||||||
|
ProcessDefinitionQuery query = repositoryService.createProcessDefinitionQuery();
|
||||||
|
List<ProcessDefinition> definitionList = query.processDefinitionTenantId(LoginHelper.getTenantId()).processDefinitionKey(key).list();
|
||||||
|
List<Deployment> deploymentList = null;
|
||||||
|
if (CollUtil.isNotEmpty(definitionList)) {
|
||||||
|
List<String> deploymentIds = definitionList.stream().map(ProcessDefinition::getDeploymentId).collect(Collectors.toList());
|
||||||
|
deploymentList = repositoryService.createDeploymentQuery()
|
||||||
|
.deploymentIds(deploymentIds).list();
|
||||||
|
}
|
||||||
|
for (ProcessDefinition processDefinition : definitionList) {
|
||||||
|
ProcessDefinitionVo processDefinitionVo = BeanUtil.toBean(processDefinition, ProcessDefinitionVo.class);
|
||||||
|
if (CollUtil.isNotEmpty(deploymentList)) {
|
||||||
|
// 部署时间
|
||||||
|
deploymentList.stream().filter(e -> e.getId().equals(processDefinition.getDeploymentId())).findFirst().ifPresent(e -> {
|
||||||
|
processDefinitionVo.setDeploymentTime(e.getDeploymentTime());
|
||||||
|
});
|
||||||
|
}
|
||||||
|
processDefinitionVoList.add(processDefinitionVo);
|
||||||
|
}
|
||||||
|
return CollectionUtil.reverse(processDefinitionVoList);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查看流程定义图片
|
||||||
|
*
|
||||||
|
* @param processDefinitionId 流程定义id
|
||||||
|
* @param response 响应
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void processDefinitionImage(String processDefinitionId, HttpServletResponse response) {
|
||||||
|
InputStream inputStream = null;
|
||||||
|
try {
|
||||||
|
// 设置页面不缓存
|
||||||
|
response.setHeader("Pragma", "no-cache");
|
||||||
|
response.addHeader("Cache-Control", "must-revalidate");
|
||||||
|
response.addHeader("Cache-Control", "no-cache");
|
||||||
|
response.addHeader("Cache-Control", "no-store");
|
||||||
|
response.setDateHeader("Expires", 0);
|
||||||
|
inputStream = repositoryService.getProcessDiagram(processDefinitionId);
|
||||||
|
// 响应相关图片
|
||||||
|
response.setContentType("image/png");
|
||||||
|
|
||||||
|
byte[] bytes = IOUtils.toByteArray(inputStream);
|
||||||
|
ServletOutputStream outputStream = response.getOutputStream();
|
||||||
|
outputStream.write(bytes);
|
||||||
|
outputStream.flush();
|
||||||
|
outputStream.close();
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
} finally {
|
||||||
|
if (inputStream != null) {
|
||||||
|
try {
|
||||||
|
inputStream.close();
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查看流程定义xml文件
|
||||||
|
*
|
||||||
|
* @param processDefinitionId 流程定义id
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public String processDefinitionXml(String processDefinitionId) {
|
||||||
|
StringBuilder xml = new StringBuilder();
|
||||||
|
ProcessDefinition processDefinition = repositoryService.getProcessDefinition(processDefinitionId);
|
||||||
|
InputStream inputStream;
|
||||||
|
try {
|
||||||
|
inputStream = repositoryService.getResourceAsStream(processDefinition.getDeploymentId(), processDefinition.getResourceName());
|
||||||
|
xml.append(IOUtils.toString(inputStream, StandardCharsets.UTF_8));
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return xml.toString();
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user