update 流程处理
This commit is contained in:
@@ -1,34 +1,56 @@
|
||||
package com.jero.modules.activiti.config;
|
||||
|
||||
import com.jero.modules.activiti.service.impl.image.ICustomProcessDiagramGenerator;
|
||||
import org.activiti.engine.ProcessEngineConfiguration;
|
||||
import org.activiti.engine.impl.form.DoubleFormType;
|
||||
import org.activiti.engine.impl.history.HistoryLevel;
|
||||
import org.activiti.spring.SpringProcessEngineConfiguration;
|
||||
import org.activiti.spring.boot.ProcessEngineConfigurationConfigurer;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.transaction.PlatformTransactionManager;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.sql.DataSource;
|
||||
|
||||
|
||||
/**
|
||||
* @author liJiaRao
|
||||
* @date 2023-09-05 17:53
|
||||
*/
|
||||
public class ActivitiConfig implements ProcessEngineConfigurationConfigurer {
|
||||
@Autowired
|
||||
@Configuration
|
||||
public class ActivitiConfig {
|
||||
@Resource
|
||||
private ICustomProcessDiagramGenerator customProcessDiagramGenerator;
|
||||
@Autowired
|
||||
private DoubleFormType doubleFormType;
|
||||
private DataSource dataSource;
|
||||
@Autowired
|
||||
private PlatformTransactionManager transactionManager;
|
||||
|
||||
/**
|
||||
* 解決工作流生成图片乱码问题
|
||||
* 初始化配置
|
||||
*
|
||||
* @param processEngineConfiguration
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public void configure(SpringProcessEngineConfiguration processEngineConfiguration) {
|
||||
int[] result = {};
|
||||
processEngineConfiguration.setActivityFontName("宋体");
|
||||
processEngineConfiguration.setAnnotationFontName("宋体");
|
||||
processEngineConfiguration.setLabelFontName("宋体");
|
||||
processEngineConfiguration.setProcessDiagramGenerator(customProcessDiagramGenerator);
|
||||
@Bean
|
||||
public SpringProcessEngineConfiguration processEngineConfiguration() {
|
||||
SpringProcessEngineConfiguration configuration = new SpringProcessEngineConfiguration();
|
||||
// 执行工作流对应的数据源
|
||||
configuration.setDataSource(dataSource);
|
||||
// 是否自动创建流程引擎表
|
||||
configuration.setDatabaseSchemaUpdate(ProcessEngineConfiguration.DB_SCHEMA_UPDATE_TRUE);
|
||||
configuration.setAsyncExecutorActivate(false);
|
||||
// 流程历史等级
|
||||
configuration.setHistoryLevel(HistoryLevel.FULL);
|
||||
// 流程图字体
|
||||
configuration.setActivityFontName("宋体");
|
||||
configuration.setAnnotationFontName("宋体");
|
||||
configuration.setLabelFontName("宋体");
|
||||
configuration.setTransactionManager(transactionManager);
|
||||
configuration.setProcessDiagramGenerator(customProcessDiagramGenerator);
|
||||
return configuration;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -10,10 +10,7 @@ import io.swagger.annotations.ApiParam;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.activiti.bpmn.converter.BpmnXMLConverter;
|
||||
import org.activiti.bpmn.model.BpmnModel;
|
||||
import org.activiti.bpmn.model.FlowElement;
|
||||
import org.activiti.bpmn.model.UserTask;
|
||||
import org.activiti.engine.*;
|
||||
import org.activiti.engine.delegate.DelegateExecution;
|
||||
import org.activiti.engine.repository.Deployment;
|
||||
import org.activiti.engine.repository.ProcessDefinition;
|
||||
import org.activiti.engine.repository.ProcessDefinitionQuery;
|
||||
@@ -23,8 +20,6 @@ import org.activiti.engine.task.TaskQuery;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.i18n.LocaleContextHolder;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
@@ -73,9 +68,11 @@ public class AController {
|
||||
.key(name)
|
||||
.name(name)
|
||||
.deploy();
|
||||
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
// 4、输出部署信息
|
||||
Map<String, String> map = new HashMap<>();
|
||||
|
||||
@@ -110,22 +107,28 @@ public class AController {
|
||||
processDefinitionQuery.processDefinitionNameLike(processDefinitionName);
|
||||
}
|
||||
|
||||
List<ProcessDefinition> processDefinitionList = processDefinitionQuery.list();
|
||||
|
||||
for (ProcessDefinition processDefinition : processDefinitionList) {
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
String deploymentId = processDefinition.getDeploymentId();
|
||||
Deployment deployment = repositoryService.createDeploymentQuery().deploymentId(deploymentId).singleResult();
|
||||
map.put("processDefinition", BeanUtil.beanToMap(processDefinition));
|
||||
map.put("deployment", deployment.toString());
|
||||
allList.add(map);
|
||||
List<ProcessDefinition> processDefinitionList = processDefinitionQuery
|
||||
.orderByProcessDefinitionVersion().asc()
|
||||
.list();
|
||||
//定义有序map,相同的key,添加map值后,后面的会覆盖前面的值
|
||||
Map<String,ProcessDefinition> processDefinitionMap = new LinkedHashMap<>();
|
||||
//遍历相同的key,替换最新的值
|
||||
for(ProcessDefinition pd : processDefinitionList){
|
||||
processDefinitionMap.put(pd.getKey(), pd);
|
||||
}
|
||||
for (ProcessDefinition processDefinition : processDefinitionMap.values()) {
|
||||
//String deploymentId = processDefinition.getDeploymentId();
|
||||
//Deployment deployment = repositoryService.createDeploymentQuery().deploymentId(deploymentId).singleResult();
|
||||
//map.put("processDefinition", BeanUtil.beanToMap(processDefinition));
|
||||
allList.add(BeanUtil.beanToMap(processDefinition));
|
||||
}
|
||||
return Result.OK(allList);
|
||||
}
|
||||
|
||||
|
||||
@GetMapping("/start")
|
||||
public Result<Map<String, String>> start(@RequestParam(value = "key", required = false) String key) {
|
||||
@PostMapping("/start")
|
||||
public Result<Map<String, String>> start(@RequestBody Map<String,Object> map) {
|
||||
String key = map.get("key").toString();
|
||||
// 1、创建ProcessEngine
|
||||
ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
|
||||
// 2、获取RunTimeService
|
||||
@@ -135,17 +138,17 @@ public class AController {
|
||||
|
||||
// 3、根据流程定义Id启动流程
|
||||
ProcessInstance processInstance = runtimeService
|
||||
.startProcessInstanceByKey(key, vars);
|
||||
.startProcessInstanceByKey(key, map);
|
||||
|
||||
// 输出内容
|
||||
Map<String, String> map = new HashMap<>();
|
||||
map.put("流程Id:", processInstance.getDeploymentId());
|
||||
map.put("流程定义id:", processInstance.getProcessDefinitionId());
|
||||
map.put("流程实例id:", processInstance.getId());
|
||||
map.put("当前活动Id:", processInstance.getActivityId());
|
||||
Map<String, String> map1 = new HashMap<>();
|
||||
map1.put("流程Id:", processInstance.getDeploymentId());
|
||||
map1.put("流程定义id:", processInstance.getProcessDefinitionId());
|
||||
map1.put("流程实例id:", processInstance.getId());
|
||||
map1.put("当前活动Id:", processInstance.getActivityId());
|
||||
|
||||
|
||||
return Result.OK(map);
|
||||
return Result.OK(map1);
|
||||
}
|
||||
|
||||
@GetMapping("/getTaskList")
|
||||
@@ -172,17 +175,18 @@ public class AController {
|
||||
return Result.OK(resut);
|
||||
}
|
||||
|
||||
@GetMapping("/complete")
|
||||
public Result<Object> complete(@RequestParam(value = "taskId") String taskId) {
|
||||
Map<String, Object> vars = new HashMap<>();
|
||||
List<String> otherDrafterList = new ArrayList<>();
|
||||
otherDrafterList.add("zhangsan");
|
||||
otherDrafterList.add("lisi");
|
||||
otherDrafterList.add("wangwu");
|
||||
vars.put("leaderList", otherDrafterList);
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.put("status", 2);
|
||||
taskService.complete(taskId, map, vars);
|
||||
@PostMapping("/complete")
|
||||
public Result<Object> complete(@RequestBody Map<String,Object> map) {
|
||||
String taskId = map.get("taskId").toString();
|
||||
//Map<String, Object> vars = new HashMap<>();
|
||||
//List<String> otherDrafterList = new ArrayList<>();
|
||||
//otherDrafterList.add("zhangsan");
|
||||
//otherDrafterList.add("lisi");
|
||||
//otherDrafterList.add("wangwu");
|
||||
//vars.put("leaderList", otherDrafterList);
|
||||
//Map<String, Object> map = new HashMap<>();
|
||||
//map.put("status", 2);
|
||||
taskService.complete(taskId, map);
|
||||
return Result.OK();
|
||||
}
|
||||
|
||||
@@ -212,6 +216,12 @@ public class AController {
|
||||
return processService.addTask(taskId, assignee);
|
||||
}
|
||||
|
||||
@GetMapping("/getNodeList")
|
||||
public Object getNodeList(String processDefinitionId) {
|
||||
processService.getNodeList(processDefinitionId);
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@GetMapping(value = "/readResource")
|
||||
@ApiOperation(value = "获取实时流程图", notes = "获取实时流程图,输出跟踪流程信息")
|
||||
|
||||
+125
@@ -0,0 +1,125 @@
|
||||
package com.jero.modules.activiti.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import java.util.Date;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
*流程节点_来源
|
||||
*@author liJiaRao
|
||||
*@date 2023-09-25 15:17
|
||||
*/
|
||||
@ApiModel(description = "流程节点_来源")
|
||||
@Data
|
||||
@TableName(value = "laws_process_node_origin")
|
||||
public class LawsProcessNodeOrigin {
|
||||
/**
|
||||
* 主键id
|
||||
*/
|
||||
@TableId(value = "id", type = IdType.ASSIGN_ID)
|
||||
@ApiModelProperty(value = "主键id")
|
||||
private String id;
|
||||
|
||||
/**
|
||||
* 流程定义id
|
||||
*/
|
||||
@TableField(value = "process_definition_id")
|
||||
@ApiModelProperty(value = "流程定义id")
|
||||
private String processDefinitionId;
|
||||
|
||||
/**
|
||||
* 节点名称
|
||||
*/
|
||||
@TableField(value = "node_name")
|
||||
@ApiModelProperty(value = "节点名称")
|
||||
private String nodeName;
|
||||
|
||||
/**
|
||||
* 节点类型
|
||||
*/
|
||||
@TableField(value = "node_type")
|
||||
@ApiModelProperty(value = "节点类型")
|
||||
private String nodeType;
|
||||
|
||||
/**
|
||||
* xml节点Id
|
||||
*/
|
||||
@TableField(value = "xml_node_id")
|
||||
@ApiModelProperty(value = "xml节点Id")
|
||||
private String xmlNodeId;
|
||||
|
||||
/**
|
||||
* xml来源节点id
|
||||
*/
|
||||
@TableField(value = "xml_source_ref")
|
||||
@ApiModelProperty(value = "xml来源节点id")
|
||||
private String xmlSourceRef;
|
||||
|
||||
/**
|
||||
* xml目标节点id
|
||||
*/
|
||||
@TableField(value = "xml_target_ref")
|
||||
@ApiModelProperty(value = "xml目标节点id")
|
||||
private String xmlTargetRef;
|
||||
|
||||
/**
|
||||
* 是否审批节点
|
||||
*/
|
||||
@TableField(value = "is_approval_node")
|
||||
@ApiModelProperty(value = "是否审批节点")
|
||||
private Integer isApprovalNode;
|
||||
|
||||
/**
|
||||
* 是否可删除
|
||||
*/
|
||||
@TableField(value = "is_can_deleted")
|
||||
@ApiModelProperty(value = "是否可删除")
|
||||
private Integer isCanDeleted;
|
||||
|
||||
/**
|
||||
* 排序
|
||||
*/
|
||||
@TableField(value = "sort")
|
||||
@ApiModelProperty(value = "排序")
|
||||
private Integer sort;
|
||||
|
||||
/**
|
||||
* 创建人
|
||||
*/
|
||||
@TableField(value = "create_by")
|
||||
@ApiModelProperty(value = "创建人")
|
||||
private String createBy;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
@TableField(value = "create_time")
|
||||
@ApiModelProperty(value = "创建时间")
|
||||
private Date createTime;
|
||||
|
||||
/**
|
||||
* 更新人
|
||||
*/
|
||||
@TableField(value = "update_by")
|
||||
@ApiModelProperty(value = "更新人")
|
||||
private String updateBy;
|
||||
|
||||
/**
|
||||
* 更新时间
|
||||
*/
|
||||
@TableField(value = "update_time")
|
||||
@ApiModelProperty(value = "更新时间")
|
||||
private Date updateTime;
|
||||
|
||||
/**
|
||||
* 所属部门
|
||||
*/
|
||||
@TableField(value = "sys_code")
|
||||
@ApiModelProperty(value = "所属部门")
|
||||
private String sysCode;
|
||||
}
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
package com.jero.modules.activiti.mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import java.util.List;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.jero.modules.activiti.entity.LawsProcessNodeOrigin;
|
||||
|
||||
/**
|
||||
* @author liJiaRao
|
||||
* @date 2023-09-25 15:02
|
||||
*/
|
||||
public interface LawsProcessNodeOriginMapper extends BaseMapper<LawsProcessNodeOrigin> {
|
||||
int insertList(@Param("list")List<LawsProcessNodeOrigin> list);
|
||||
|
||||
|
||||
}
|
||||
+78
@@ -0,0 +1,78 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.jero.modules.activiti.mapper.LawsProcessNodeOriginMapper">
|
||||
<sql id="Base_Column_List">
|
||||
id,
|
||||
process_definition_id,
|
||||
node_name,
|
||||
node_type,
|
||||
xml_node_id,
|
||||
xml_source_ref,
|
||||
xml_target_ref,
|
||||
is_approval_node,
|
||||
is_can_deleted,
|
||||
sort,
|
||||
create_by,
|
||||
create_time,
|
||||
update_by,
|
||||
update_time,
|
||||
sys_code
|
||||
</sql>
|
||||
<resultMap id="BaseResultMap" type="com.jero.modules.activiti.entity.LawsProcessNodeOrigin">
|
||||
<result column="id" property="id"/>
|
||||
<result column="process_definition_id" property="processDefinitionId"/>
|
||||
<result column="node_name" property="nodeName"/>
|
||||
<result column="node_type" property="nodeType"/>
|
||||
<result column="xml_node_id" property="xmlNodeId"/>
|
||||
<result column="xml_source_ref" property="xmlSourceRef"/>
|
||||
<result column="xml_target_ref" property="xmlTargetRef"/>
|
||||
<result column="is_approval_node" property="isApprovalNode"/>
|
||||
<result column="is_can_deleted" property="isCanDeleted"/>
|
||||
<result column="sort" property="sort"/>
|
||||
<result column="create_by" property="createBy"/>
|
||||
<result column="create_time" property="createTime"/>
|
||||
<result column="update_by" property="updateBy"/>
|
||||
<result column="update_time" property="updateTime"/>
|
||||
<result column="sys_code" property="sysCode"/>
|
||||
</resultMap>
|
||||
|
||||
<!--auto generated by MybatisCodeHelper on 2023-09-25-->
|
||||
<insert id="insertList">
|
||||
INSERT INTO laws_process_node_origin(
|
||||
id,
|
||||
process_definition_id,
|
||||
node_name,
|
||||
node_type,
|
||||
xml_node_id,
|
||||
xml_source_ref,
|
||||
xml_target_ref,
|
||||
is_approval_node,
|
||||
is_can_deleted,
|
||||
sort,
|
||||
create_by,
|
||||
create_time,
|
||||
update_by,
|
||||
update_time,
|
||||
sys_code
|
||||
)VALUES
|
||||
<foreach collection="list" item="element" index="index" separator=",">
|
||||
(
|
||||
#{element.id},
|
||||
#{element.processDefinitionId},
|
||||
#{element.nodeName},
|
||||
#{element.nodeType},
|
||||
#{element.xmlNodeId},
|
||||
#{element.xmlSourceRef},
|
||||
#{element.xmlTargetRef},
|
||||
#{element.isApprovalNode},
|
||||
#{element.isCanDeleted},
|
||||
#{element.sort},
|
||||
#{element.createBy},
|
||||
#{element.createTime},
|
||||
#{element.updateBy},
|
||||
#{element.updateTime},
|
||||
#{element.sysCode}
|
||||
)
|
||||
</foreach>
|
||||
</insert>
|
||||
</mapper>
|
||||
@@ -10,4 +10,6 @@ public interface ProcessService {
|
||||
Object addTask(String taskId, String assignee);
|
||||
|
||||
void readResource(String pProcessInstanceId, HttpServletResponse response) throws Exception;
|
||||
|
||||
void getNodeList(String processDefinitionId);
|
||||
}
|
||||
|
||||
+193
-31
@@ -1,9 +1,17 @@
|
||||
package com.jero.modules.activiti.service.impl;
|
||||
import java.util.Date;
|
||||
|
||||
import cn.hutool.core.lang.UUID;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.jero.common.constant.enums.YesOrNoEnum;
|
||||
import com.jero.common.exception.JeroBootException;
|
||||
import com.jero.modules.activiti.config.WorkflowConstants;
|
||||
import com.jero.modules.activiti.entity.ActGeBytearray;
|
||||
import com.jero.modules.activiti.entity.LawsProcessNodeOrigin;
|
||||
import com.jero.modules.activiti.mapper.ActGeBytearrayMapper;
|
||||
import com.jero.modules.activiti.mapper.LawsProcessNodeOriginMapper;
|
||||
import com.jero.modules.activiti.service.ProcessService;
|
||||
import com.jero.modules.activiti.service.impl.image.ICustomProcessDiagramGenerator;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
@@ -61,28 +69,38 @@ public class ProcessServiceImpl implements ProcessService {
|
||||
private ManagementService managementService;
|
||||
@Resource
|
||||
private ActGeBytearrayMapper actGeBytearrayMapper;
|
||||
|
||||
@Resource
|
||||
private LawsProcessNodeOriginMapper processNodeOriginMapper;
|
||||
@Override
|
||||
public Object addTask(String taskId, String assignee) {
|
||||
// 1、创建ProcessEngine
|
||||
ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
|
||||
final TaskService taskService = processEngine.getTaskService();
|
||||
final RepositoryService repositoryService = processEngine.getRepositoryService();
|
||||
Task userTask = taskService.createTaskQuery()
|
||||
.taskId(taskId)
|
||||
// .taskAssignee(assignee)
|
||||
.singleResult();
|
||||
|
||||
final BpmnModel bpmnModel = repositoryService.getBpmnModel(userTask.getProcessDefinitionId());
|
||||
public Object addTask(String processDefinitionId, String assignee) {
|
||||
final BpmnModel bpmnModel = repositoryService.getBpmnModel(processDefinitionId);
|
||||
Process process = bpmnModel.getMainProcess();
|
||||
process.removeFlowElement("add");//移除最终节点连线
|
||||
process.removeFlowElement("sequenceFlow-5d7e3faa-6c00-4010-8485-fe79c286448b");//移除最终节点连线
|
||||
process.removeFlowElement("sequenceFlow-aba52ded-835d-4863-b303-1b9771ae93cf");//移除最终节点连线
|
||||
process.addFlowElement(createSequenceFlow("Activity_0m576ex", "Event_17e1txx"));//新增节点 于原节点连线
|
||||
/*process.removeFlowElement("Flow_0stcykp");//移除最终节点连线
|
||||
process.addFlowElement(createUserTask("add", "First task", "fred"));//新增节点
|
||||
process.addFlowElement(createSequenceFlow("Activity_0m576ex", "add"));//新增节点 于原节点连线
|
||||
process.addFlowElement(createSequenceFlow("add", "Event_17e1txx"));//新增节点 于原节点连线*/
|
||||
Collection<FlowElement> flowElements = process.getFlowElements();
|
||||
for (FlowElement flowElement : flowElements) {
|
||||
if (flowElement instanceof UserTask) {
|
||||
UserTask userTask = (UserTask)flowElement;
|
||||
System.out.println(userTask.getId() + ":" + userTask.getName());
|
||||
}
|
||||
if (flowElement instanceof SequenceFlow) {
|
||||
SequenceFlow sequenceFlow = (SequenceFlow)flowElement;
|
||||
System.out.println(sequenceFlow.getId() + ":" + sequenceFlow.getName());
|
||||
}
|
||||
if (flowElement instanceof ExclusiveGateway) {
|
||||
ExclusiveGateway gateway = (ExclusiveGateway)flowElement;
|
||||
System.out.println(gateway.getId() + ":" + gateway.getName());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
//process.removeFlowElement("add");//移除最终节点连线
|
||||
//process.removeFlowElement("sequenceFlow-5d7e3faa-6c00-4010-8485-fe79c286448b");//移除最终节点连线
|
||||
//process.removeFlowElement("sequenceFlow-aba52ded-835d-4863-b303-1b9771ae93cf");//移除最终节点连线
|
||||
//process.addFlowElement(createSequenceFlow("Activity_0m576ex", "Event_17e1txx"));//新增节点 于原节点连线
|
||||
//process.removeFlowElement("Flow_0stcykp");//移除最终节点连线
|
||||
//process.addFlowElement(createUserTask("First task", "fred"));//新增节点
|
||||
//process.addFlowElement(createSequenceFlow("Activity_0m576ex", "add"));//新增节点 于原节点连线
|
||||
//process.addFlowElement(createSequenceFlow("add", "Event_17e1txx"));//新增节点 于原节点连线
|
||||
//重新绘画图形
|
||||
BpmnAutoLayout bpmnAutoLayout = new BpmnAutoLayout(bpmnModel);
|
||||
bpmnAutoLayout.execute();
|
||||
@@ -92,22 +110,21 @@ public class ProcessServiceImpl implements ProcessService {
|
||||
//清除缓存
|
||||
ProcessEngineConfigurationImpl configuration = (ProcessEngineConfigurationImpl) processEngine.getProcessEngineConfiguration();
|
||||
DeploymentManager deploymentManager = configuration.getDeploymentManager();
|
||||
deploymentManager.getProcessDefinitionCache().remove(userTask.getProcessDefinitionId());
|
||||
deploymentManager.getProcessDefinitionCache().remove(processDefinitionId);
|
||||
|
||||
// String xmlContenxt = new String(bytes);
|
||||
List<ActGeBytearray> actGeBytearrayList = actGeBytearrayMapper.getActGeBytearrayList(userTask.getProcessDefinitionId());
|
||||
actGeBytearrayList = actGeBytearrayList.stream().filter(item -> item.getName().endsWith(".bpmn")).peek(item -> {
|
||||
item.setBytes(bytes);
|
||||
}).collect(Collectors.toList());
|
||||
if (ObjectUtils.isNotEmpty(actGeBytearrayList)) {
|
||||
actGeBytearrayMapper.updateById(actGeBytearrayList.get(0));
|
||||
}
|
||||
// List<ActGeBytearray> actGeBytearrayList = actGeBytearrayMapper.getActGeBytearrayList(userTask.getProcessDefinitionId());
|
||||
// actGeBytearrayList = actGeBytearrayList.stream().filter(item -> item.getName().endsWith(".bpmn")).peek(item -> {
|
||||
// item.setBytes(bytes);
|
||||
// }).collect(Collectors.toList());
|
||||
// if (ObjectUtils.isNotEmpty(actGeBytearrayList)) {
|
||||
// actGeBytearrayMapper.updateById(actGeBytearrayList.get(0));
|
||||
// }
|
||||
return null;
|
||||
}
|
||||
protected static UserTask createUserTask(String id, String name, String assignee) {
|
||||
protected static UserTask createUserTask(String name, String assignee) {
|
||||
UserTask userTask = new UserTask();
|
||||
userTask.setName(name);
|
||||
userTask.setId(id);
|
||||
userTask.setId("Activity_"+UUID.randomUUID());
|
||||
userTask.setAssignee(assignee);
|
||||
return userTask;
|
||||
}
|
||||
@@ -116,9 +133,18 @@ public class ProcessServiceImpl implements ProcessService {
|
||||
SequenceFlow flow = new SequenceFlow();
|
||||
flow.setSourceRef(from);
|
||||
flow.setTargetRef(to);
|
||||
flow.setId("Flow_"+ UUID.randomUUID());
|
||||
return flow;
|
||||
}
|
||||
|
||||
protected static ExclusiveGateway createGateway(List<SequenceFlow> incomingFlows, List<SequenceFlow> outgoingFlows) {
|
||||
ExclusiveGateway gateway = new ExclusiveGateway();
|
||||
gateway.setId("Gateway_"+ UUID.randomUUID());
|
||||
gateway.setIncomingFlows(incomingFlows);
|
||||
gateway.setOutgoingFlows(outgoingFlows);
|
||||
return gateway;
|
||||
}
|
||||
|
||||
private List<String> getHighLightedFlows(BpmnModel bpmnModel, ProcessDefinitionEntity processDefinitionEntity, List<HistoricActivityInstance> historicActivityInstances) {
|
||||
// 高亮流程已发生流转的线id集合
|
||||
List<String> highLightedFlowIds = new ArrayList<>();
|
||||
@@ -228,6 +254,142 @@ public class ProcessServiceImpl implements ProcessService {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getNodeList(String processDefinitionId) {
|
||||
final BpmnModel bpmnModel = repositoryService.getBpmnModel(processDefinitionId);
|
||||
Process process = bpmnModel.getMainProcess();
|
||||
Collection<FlowElement> flowElements = process.getFlowElements();
|
||||
List<LawsProcessNodeOrigin> processNodeOriginList = new ArrayList<>();
|
||||
int sort = 1;
|
||||
List<String> gatewayIdList = new ArrayList<>();
|
||||
processNodeOriginList = handlerLawsProcessNodeOrigin(flowElements,sort,gatewayIdList,processDefinitionId);
|
||||
//for (FlowElement flowElement : flowElements) {
|
||||
// LawsProcessNodeOrigin processNodeOrigin = new LawsProcessNodeOrigin();
|
||||
//
|
||||
// String nodeName = processNodeOrigin.getNodeName();
|
||||
// String nodeType = processNodeOrigin.getNodeType();
|
||||
// String xmlNodeId = processNodeOrigin.getXmlNodeId();
|
||||
// String xmlSourceRef = processNodeOrigin.getXmlSourceRef();
|
||||
// String xmlTargetRef = processNodeOrigin.getXmlTargetRef();
|
||||
// if (flowElement instanceof UserTask) {
|
||||
// UserTask userTask = (UserTask)flowElement;
|
||||
// nodeType = "userTask";
|
||||
// nodeName = userTask.getName();
|
||||
// xmlNodeId = userTask.getId();
|
||||
// }else
|
||||
// if (flowElement instanceof SequenceFlow) {
|
||||
// SequenceFlow sequenceFlow = (SequenceFlow)flowElement;
|
||||
// nodeType = "sequenceFlow";
|
||||
// nodeName = sequenceFlow.getName();
|
||||
// xmlNodeId = sequenceFlow.getId();
|
||||
// xmlSourceRef = sequenceFlow.getSourceRef();
|
||||
// xmlTargetRef = sequenceFlow.getTargetRef();
|
||||
// }else
|
||||
// if (flowElement instanceof ExclusiveGateway) {
|
||||
// ExclusiveGateway gateway = (ExclusiveGateway)flowElement;
|
||||
// nodeType = "gateway";
|
||||
// nodeName = gateway.getName();
|
||||
// xmlNodeId = gateway.getId();
|
||||
// gatewayIdList.add(xmlNodeId);
|
||||
// }else
|
||||
// if (flowElement instanceof SubProcess) {
|
||||
// SubProcess subProcess = (SubProcess)flowElement;
|
||||
// Collection<FlowElement> flowElements1 = subProcess.getFlowElements();
|
||||
//
|
||||
// nodeType = "subProcess";
|
||||
// nodeName = subProcess.getName();
|
||||
// xmlNodeId = subProcess.getId();
|
||||
// gatewayIdList.add(xmlNodeId);
|
||||
// }else {
|
||||
// continue;
|
||||
// }
|
||||
// processNodeOrigin.setProcessDefinitionId(processDefinitionId);
|
||||
// processNodeOrigin.setNodeName(nodeName);
|
||||
// processNodeOrigin.setNodeType(nodeType);
|
||||
// processNodeOrigin.setXmlNodeId(xmlNodeId);
|
||||
// processNodeOrigin.setXmlSourceRef(xmlSourceRef);
|
||||
// processNodeOrigin.setXmlTargetRef(xmlTargetRef);
|
||||
// processNodeOrigin.setSort(sort++);
|
||||
// processNodeOrigin.setIsApprovalNode(YesOrNoEnum.NO.getInteger());
|
||||
// processNodeOrigin.setIsCanDeleted(YesOrNoEnum.NO.getInteger());
|
||||
// processNodeOriginList.add(processNodeOrigin);
|
||||
//}
|
||||
List<String> approvalNodeIdList = processNodeOriginList.stream()
|
||||
.filter(item -> gatewayIdList.contains(item.getXmlTargetRef()))
|
||||
.map(LawsProcessNodeOrigin::getXmlSourceRef)
|
||||
.collect(Collectors.toList());
|
||||
|
||||
for (LawsProcessNodeOrigin processNodeOrigin : processNodeOriginList) {
|
||||
String xmlNodeId = processNodeOrigin.getXmlNodeId();
|
||||
if (approvalNodeIdList.contains(xmlNodeId) ){
|
||||
processNodeOrigin.setIsApprovalNode(YesOrNoEnum.YES.getInteger());
|
||||
}
|
||||
}
|
||||
processNodeOriginMapper.insertList(processNodeOriginList);
|
||||
}
|
||||
|
||||
private List<LawsProcessNodeOrigin> handlerLawsProcessNodeOrigin(
|
||||
Collection<FlowElement> flowElements,
|
||||
int sort,
|
||||
List<String> gatewayIdList,
|
||||
String processDefinitionId) {
|
||||
List<LawsProcessNodeOrigin> processNodeOriginList = new ArrayList<>();
|
||||
for (FlowElement flowElement : flowElements) {
|
||||
LawsProcessNodeOrigin processNodeOrigin = new LawsProcessNodeOrigin();
|
||||
|
||||
String nodeName = processNodeOrigin.getNodeName();
|
||||
String nodeType = processNodeOrigin.getNodeType();
|
||||
String xmlNodeId = processNodeOrigin.getXmlNodeId();
|
||||
String xmlSourceRef = processNodeOrigin.getXmlSourceRef();
|
||||
String xmlTargetRef = processNodeOrigin.getXmlTargetRef();
|
||||
if (flowElement instanceof UserTask) {
|
||||
UserTask userTask = (UserTask) flowElement;
|
||||
nodeType = "userTask";
|
||||
nodeName = userTask.getName();
|
||||
xmlNodeId = userTask.getId();
|
||||
} else if (flowElement instanceof SequenceFlow) {
|
||||
SequenceFlow sequenceFlow = (SequenceFlow) flowElement;
|
||||
nodeType = "sequenceFlow";
|
||||
nodeName = sequenceFlow.getName();
|
||||
xmlNodeId = sequenceFlow.getId();
|
||||
xmlSourceRef = sequenceFlow.getSourceRef();
|
||||
xmlTargetRef = sequenceFlow.getTargetRef();
|
||||
} else if (flowElement instanceof ExclusiveGateway) {
|
||||
ExclusiveGateway gateway = (ExclusiveGateway) flowElement;
|
||||
nodeType = "gateway";
|
||||
nodeName = gateway.getName();
|
||||
xmlNodeId = gateway.getId();
|
||||
gatewayIdList.add(xmlNodeId);
|
||||
} else if (flowElement instanceof SubProcess) {
|
||||
SubProcess subProcess = (SubProcess) flowElement;
|
||||
Collection<FlowElement> flowElements1 = subProcess.getFlowElements();
|
||||
List<LawsProcessNodeOrigin> processNodeOrigins = handlerLawsProcessNodeOrigin(flowElements1, sort, gatewayIdList, processDefinitionId);
|
||||
processNodeOriginList.addAll(processNodeOrigins);
|
||||
nodeType = "subProcess";
|
||||
nodeName = subProcess.getName();
|
||||
xmlNodeId = subProcess.getId();
|
||||
} else if (flowElement instanceof EndEvent) {
|
||||
EndEvent endEvent = (EndEvent) flowElement;
|
||||
nodeType = "endEvent";
|
||||
nodeName = endEvent.getName();
|
||||
xmlNodeId = endEvent.getId();
|
||||
} else {
|
||||
continue;
|
||||
}
|
||||
processNodeOrigin.setProcessDefinitionId(processDefinitionId);
|
||||
processNodeOrigin.setNodeName(nodeName);
|
||||
processNodeOrigin.setNodeType(nodeType);
|
||||
processNodeOrigin.setXmlNodeId(xmlNodeId);
|
||||
processNodeOrigin.setXmlSourceRef(xmlSourceRef);
|
||||
processNodeOrigin.setXmlTargetRef(xmlTargetRef);
|
||||
processNodeOrigin.setSort(sort++);
|
||||
processNodeOrigin.setIsApprovalNode(YesOrNoEnum.NO.getInteger());
|
||||
processNodeOrigin.setIsCanDeleted(YesOrNoEnum.NO.getInteger());
|
||||
processNodeOriginList.add(processNodeOrigin);
|
||||
}
|
||||
return processNodeOriginList;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取流程图像,已执行节点和流程线高亮显示
|
||||
*/
|
||||
|
||||
@@ -1,178 +0,0 @@
|
||||
package com.jero.modules.activiti.util;
|
||||
|
||||
import cn.hutool.core.io.FileUtil;
|
||||
import org.dom4j.*;
|
||||
import org.dom4j.io.OutputFormat;
|
||||
import org.dom4j.io.SAXReader;
|
||||
import org.dom4j.io.XMLWriter;
|
||||
import org.dom4j.tree.AbstractAttribute;
|
||||
import org.dom4j.tree.DefaultAttribute;
|
||||
import org.dom4j.tree.DefaultElement;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 作者 CG
|
||||
* 时间 2021/4/12 14:21
|
||||
* 备注 camunda 和 activiti xml 互相转换
|
||||
* 参数
|
||||
*/
|
||||
public class ConversionUtil {
|
||||
public static void main(String[] args) {
|
||||
File file1 = new File("E:\\Data\\Downloads\\sign.bpmn");
|
||||
camundaToActiviti(file1,true);
|
||||
}
|
||||
|
||||
/**
|
||||
* 作者 CG
|
||||
* 时间 2021/4/12 14:22
|
||||
* 备注 判断文件名字是否是xml,不是xml转换为xml
|
||||
* 参数
|
||||
*/
|
||||
public static File isXml(File file) {
|
||||
// 判断是否为null
|
||||
String name = FileUtil.mainName(file);
|
||||
String parent = file.getParent();
|
||||
boolean bpmn = FileUtil.pathEndsWith(file, "bpmn");
|
||||
if (bpmn) {
|
||||
//转换为xml
|
||||
File xmlFile = FileUtil.file(parent, name + ".xml");
|
||||
File copy = FileUtil.copy(file, xmlFile, true);
|
||||
return copy;
|
||||
}
|
||||
return file;
|
||||
}
|
||||
/**
|
||||
* 作者 CG
|
||||
* 时间 2021/4/12 15:57
|
||||
* 备注 属性转换
|
||||
* 参数 [file, flag camunda->activiti=true activiti->camunda=false]
|
||||
*/
|
||||
public static void camundaToActiviti(File file, Boolean flag) {
|
||||
//判断文件后缀名是否正确
|
||||
try {
|
||||
File xml = isXml(file);
|
||||
//转换为文档
|
||||
SAXReader reader = new SAXReader();
|
||||
// 转换为Document
|
||||
Document doc = reader.read(xml);
|
||||
//获取根节点
|
||||
Element rootElement = doc.getRootElement();
|
||||
//获取命名空间
|
||||
//flag camunda->activiti=true activiti->camunda=false
|
||||
NamespaceHandler(rootElement, flag);
|
||||
//处理userTask
|
||||
Element process = rootElement.element("process");
|
||||
List<Element> userTask = process.elements("userTask");
|
||||
CamundaTag[] values = CamundaTag.values();
|
||||
if (!CollectionUtils.isEmpty(userTask)) {
|
||||
for (CamundaTag value : values) {
|
||||
userTask(userTask, value, flag);
|
||||
}
|
||||
//处理监听
|
||||
userTaskListener(userTask, flag);
|
||||
}
|
||||
//保存文档
|
||||
saveDocument(doc, file);
|
||||
} catch (DocumentException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 作者 CG
|
||||
* 时间 2021/4/12 17:45
|
||||
* 备注 处理命名空间
|
||||
* 参数 [rootElement, flag]
|
||||
*/
|
||||
public static void NamespaceHandler(Element rootElement, Boolean flag) {
|
||||
NamespaceName camundaNamespace = NamespaceName.camunda;
|
||||
NamespaceName activitiNamespace = NamespaceName.activiti;
|
||||
Namespace activiti = rootElement.getNamespaceForPrefix(flag ? camundaNamespace.getName() : activitiNamespace.getName());
|
||||
if (activiti != null) {
|
||||
//删除camunda命名空间
|
||||
rootElement.remove(activiti);
|
||||
//添加activiti命名空间
|
||||
Namespace namespace = new Namespace(flag ? activitiNamespace.getName() : camundaNamespace.getName(), flag ? activitiNamespace.getUrl() : camundaNamespace.getUrl());
|
||||
rootElement.add(namespace);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 作者 CG
|
||||
* 时间 2021/4/12 15:36
|
||||
* 备注 userTask 参数转换
|
||||
* 参数 [userTask 要处理的集合, camundaTag 要处理的参数类型, flag camunda->activiti=true activiti->camunda=false]
|
||||
*/
|
||||
public static void userTask(List<Element> userTask, CamundaTag camundaTag, Boolean flag) {
|
||||
for (Element element : userTask) {
|
||||
Attribute assignee = element.attribute(camundaTag.getAttribute());
|
||||
if (assignee != null) {
|
||||
element.remove(assignee);
|
||||
AbstractAttribute abstractAttribute = new AbstractAttribute() {
|
||||
@Override
|
||||
public QName getQName() {
|
||||
QName qName = new QName(flag ? camundaTag.getActivitiName() : camundaTag.getCamundaName());
|
||||
return qName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getValue() {
|
||||
return assignee.getValue();
|
||||
}
|
||||
};
|
||||
element.add(abstractAttribute);
|
||||
}
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 作者 CG
|
||||
* 时间 2021/4/12 15:36
|
||||
* 备注 userTask 参数转换
|
||||
* 参数 [userTask 要处理的集合, camundaTag 要处理的参数类型, flag camunda->activiti=true activiti->camunda=false]
|
||||
*/
|
||||
public static void userTaskListener(List<Element> userTask, Boolean flag) {
|
||||
CamundaTag listener = CamundaTag.taskListener;
|
||||
for (Element element : userTask) {
|
||||
Element extensionElements = element.element("extensionElements");
|
||||
if (extensionElements!=null){
|
||||
//是否有监听
|
||||
Element taskListener = extensionElements.element(listener.getAttribute());
|
||||
if (taskListener!=null){
|
||||
//获取节点所有参数
|
||||
List<Attribute> attributes = taskListener.attributes();
|
||||
DefaultElement defaultElement = new DefaultElement(flag?listener.getActivitiName():listener.getCamundaName());
|
||||
//将参数拷贝到新的节点
|
||||
for (Attribute attribute : attributes) {
|
||||
DefaultAttribute defaultAttribute = new DefaultAttribute(attribute.getName(), attribute.getValue());
|
||||
defaultElement.add(defaultAttribute);
|
||||
}
|
||||
//删除原有节点
|
||||
extensionElements.remove(taskListener);
|
||||
//添加新构建的节点
|
||||
extensionElements.add(defaultElement);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 作者 CG
|
||||
* 时间 2021/4/12 15:45
|
||||
* 备注 文档保存
|
||||
* 参数 [document, xmlFile]
|
||||
*/
|
||||
public static void saveDocument(Document document, File xmlFile) throws IOException {
|
||||
Writer osWrite = new OutputStreamWriter(new FileOutputStream(xmlFile));//创建输出流
|
||||
OutputFormat format = OutputFormat.createPrettyPrint(); //获取输出的指定格式
|
||||
format.setEncoding("UTF-8");//设置编码 ,确保解析的xml为UTF-8格式
|
||||
XMLWriter writer = new XMLWriter(osWrite, format);//XMLWriter 指定输出文件以及格式
|
||||
writer.write(document);//把document写入xmlFile指定的文件(可以为被解析的文件或者新创建的文件)
|
||||
writer.flush();
|
||||
writer.close();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user