From 6492718f58b3c2c236f15d4fd89016afdfc4dce2 Mon Sep 17 00:00:00 2001 From: lijiarao Date: Mon, 25 Sep 2023 18:06:31 +0800 Subject: [PATCH] =?UTF-8?q?update=20=E6=B5=81=E7=A8=8B=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- db/activiti表注释.sql | 2 +- db/流程.sql | 40 ++ .../activiti/config/ActivitiConfig.java | 46 +- .../activiti/controller/AController.java | 78 +-- .../entity/LawsProcessNodeOrigin.java | 125 +++++ .../mapper/LawsProcessNodeOriginMapper.java | 16 + .../xml/LawsProcessNodeOriginMapper.xml | 78 +++ .../activiti/service/ProcessService.java | 2 + .../service/impl/ProcessServiceImpl.java | 224 ++++++-- .../modules/activiti/util/ConversionUtil.java | 178 ------- .../main/resources/bpmn/diagram_1.bpmn20.xml | 77 ++- .../bpmn/企标制修订流程2 - 副本.bpmn20.xml | 491 ++++++++++++++++++ 12 files changed, 1074 insertions(+), 283 deletions(-) create mode 100644 db/流程.sql create mode 100644 laws-modules/src/main/java/com/jero/modules/activiti/entity/LawsProcessNodeOrigin.java create mode 100644 laws-modules/src/main/java/com/jero/modules/activiti/mapper/LawsProcessNodeOriginMapper.java create mode 100644 laws-modules/src/main/java/com/jero/modules/activiti/mapper/xml/LawsProcessNodeOriginMapper.xml delete mode 100644 laws-modules/src/main/java/com/jero/modules/activiti/util/ConversionUtil.java create mode 100644 laws-modules/src/main/resources/bpmn/企标制修订流程2 - 副本.bpmn20.xml diff --git a/db/activiti表注释.sql b/db/activiti表注释.sql index 58cad012..42cf81e7 100644 --- a/db/activiti表注释.sql +++ b/db/activiti表注释.sql @@ -17,7 +17,7 @@ alter table act_ru_deadletter_job comment = '运行时死信作业表'; alter table act_ru_event_subscr comment = '运行时事件表'; alter table act_ru_execution comment = '运行时流程执行实例表'; alter table act_ru_identitylink comment = '运行时用户关系信息,存储任务节点与参与者的相关信息表'; -alter table act_ru_integration comment = '运行时积分表'; +-- alter table act_ru_integration comment = '运行时积分表'; alter table act_ru_job comment = '运行时作业表'; alter table act_ru_suspended_job comment = '运行时挂起的定时作业表'; alter table act_ru_task comment = '运行时任务表'; diff --git a/db/流程.sql b/db/流程.sql new file mode 100644 index 00000000..a166c0dc --- /dev/null +++ b/db/流程.sql @@ -0,0 +1,40 @@ +DROP TABLE IF EXISTS laws_process_node_origin; +create table laws_process_node_origin +( + id varchar(36) not null primary key comment '主键id', + process_definition_id varchar(64) comment '流程定义id', + node_name varchar(50) comment '节点名称', + node_type varchar(50) comment '节点类型', + xml_node_id varchar(50) comment 'xml节点Id', + xml_source_ref varchar(50) comment 'xml来源节点id', + xml_target_ref varchar(50) comment 'xml目标节点id', + is_approval_node tinyint(4) comment '是否审批节点', + is_can_deleted tinyint(4) comment '是否可删除', + sort tinyint(4) comment '排序', + create_by varchar(36) comment '创建人', + create_time datetime comment '创建时间', + update_by varchar(36) comment '更新人', + update_time datetime comment '更新时间', + sys_code varchar(64) comment '所属部门' +) comment = '流程节点_来源'; + +create table laws_process_node +( + id varchar(36) not null primary key comment '主键id', + create_by varchar(36) comment '创建人', + create_time datetime(0) comment '创建时间', + update_by varchar(36) comment '更新人', + update_time datetime(0) comment '更新时间', + sys_code varchar(64) comment '所属部门', + replaced varchar(50) comment '代替标准', + replaced_by varchar(50) comment '被代替标准', + type int(1) comment '类型(1-代替、2-引用)' +) comment = '流程节点'; + +create table laws_process_node_link +( + id varchar(36) not null primary key comment '主键id', + process_node_id varchar(36) comment '流程节点id', + type int(1) comment '类型(1-用户、2-部门)', + user_depart_id varchar(36) comment '用户id,部门id)' +) comment = '流程节点'; \ No newline at end of file diff --git a/laws-modules/src/main/java/com/jero/modules/activiti/config/ActivitiConfig.java b/laws-modules/src/main/java/com/jero/modules/activiti/config/ActivitiConfig.java index 64b34801..4ebe76ba 100644 --- a/laws-modules/src/main/java/com/jero/modules/activiti/config/ActivitiConfig.java +++ b/laws-modules/src/main/java/com/jero/modules/activiti/config/ActivitiConfig.java @@ -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; + } } diff --git a/laws-modules/src/main/java/com/jero/modules/activiti/controller/AController.java b/laws-modules/src/main/java/com/jero/modules/activiti/controller/AController.java index b59ba940..b98ceb8b 100644 --- a/laws-modules/src/main/java/com/jero/modules/activiti/controller/AController.java +++ b/laws-modules/src/main/java/com/jero/modules/activiti/controller/AController.java @@ -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 map = new HashMap<>(); @@ -110,22 +107,28 @@ public class AController { processDefinitionQuery.processDefinitionNameLike(processDefinitionName); } - List processDefinitionList = processDefinitionQuery.list(); - - for (ProcessDefinition processDefinition : processDefinitionList) { - Map 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 processDefinitionList = processDefinitionQuery + .orderByProcessDefinitionVersion().asc() + .list(); + //定义有序map,相同的key,添加map值后,后面的会覆盖前面的值 + Map 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> start(@RequestParam(value = "key", required = false) String key) { + @PostMapping("/start") + public Result> start(@RequestBody Map 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 map = new HashMap<>(); - map.put("流程Id:", processInstance.getDeploymentId()); - map.put("流程定义id:", processInstance.getProcessDefinitionId()); - map.put("流程实例id:", processInstance.getId()); - map.put("当前活动Id:", processInstance.getActivityId()); + Map 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 complete(@RequestParam(value = "taskId") String taskId) { - Map vars = new HashMap<>(); - List otherDrafterList = new ArrayList<>(); - otherDrafterList.add("zhangsan"); - otherDrafterList.add("lisi"); - otherDrafterList.add("wangwu"); - vars.put("leaderList", otherDrafterList); - Map map = new HashMap<>(); - map.put("status", 2); - taskService.complete(taskId, map, vars); + @PostMapping("/complete") + public Result complete(@RequestBody Map map) { + String taskId = map.get("taskId").toString(); + //Map vars = new HashMap<>(); + //List otherDrafterList = new ArrayList<>(); + //otherDrafterList.add("zhangsan"); + //otherDrafterList.add("lisi"); + //otherDrafterList.add("wangwu"); + //vars.put("leaderList", otherDrafterList); + //Map 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 = "获取实时流程图,输出跟踪流程信息") diff --git a/laws-modules/src/main/java/com/jero/modules/activiti/entity/LawsProcessNodeOrigin.java b/laws-modules/src/main/java/com/jero/modules/activiti/entity/LawsProcessNodeOrigin.java new file mode 100644 index 00000000..bd3bc19c --- /dev/null +++ b/laws-modules/src/main/java/com/jero/modules/activiti/entity/LawsProcessNodeOrigin.java @@ -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; +} \ No newline at end of file diff --git a/laws-modules/src/main/java/com/jero/modules/activiti/mapper/LawsProcessNodeOriginMapper.java b/laws-modules/src/main/java/com/jero/modules/activiti/mapper/LawsProcessNodeOriginMapper.java new file mode 100644 index 00000000..9a9fa9a2 --- /dev/null +++ b/laws-modules/src/main/java/com/jero/modules/activiti/mapper/LawsProcessNodeOriginMapper.java @@ -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 { + int insertList(@Param("list")List list); + + +} \ No newline at end of file diff --git a/laws-modules/src/main/java/com/jero/modules/activiti/mapper/xml/LawsProcessNodeOriginMapper.xml b/laws-modules/src/main/java/com/jero/modules/activiti/mapper/xml/LawsProcessNodeOriginMapper.xml new file mode 100644 index 00000000..33f29a66 --- /dev/null +++ b/laws-modules/src/main/java/com/jero/modules/activiti/mapper/xml/LawsProcessNodeOriginMapper.xml @@ -0,0 +1,78 @@ + + + + + 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 + + + + + + + + + + + + + + + + + + + + + + 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 + + ( + #{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} + ) + + + \ No newline at end of file diff --git a/laws-modules/src/main/java/com/jero/modules/activiti/service/ProcessService.java b/laws-modules/src/main/java/com/jero/modules/activiti/service/ProcessService.java index 37af6b42..8164433b 100644 --- a/laws-modules/src/main/java/com/jero/modules/activiti/service/ProcessService.java +++ b/laws-modules/src/main/java/com/jero/modules/activiti/service/ProcessService.java @@ -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); } diff --git a/laws-modules/src/main/java/com/jero/modules/activiti/service/impl/ProcessServiceImpl.java b/laws-modules/src/main/java/com/jero/modules/activiti/service/impl/ProcessServiceImpl.java index aa9366b0..9861d724 100644 --- a/laws-modules/src/main/java/com/jero/modules/activiti/service/impl/ProcessServiceImpl.java +++ b/laws-modules/src/main/java/com/jero/modules/activiti/service/impl/ProcessServiceImpl.java @@ -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 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 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 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 incomingFlows, List outgoingFlows) { + ExclusiveGateway gateway = new ExclusiveGateway(); + gateway.setId("Gateway_"+ UUID.randomUUID()); + gateway.setIncomingFlows(incomingFlows); + gateway.setOutgoingFlows(outgoingFlows); + return gateway; + } + private List getHighLightedFlows(BpmnModel bpmnModel, ProcessDefinitionEntity processDefinitionEntity, List historicActivityInstances) { // 高亮流程已发生流转的线id集合 List 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 flowElements = process.getFlowElements(); + List processNodeOriginList = new ArrayList<>(); + int sort = 1; + List 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 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 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 handlerLawsProcessNodeOrigin( + Collection flowElements, + int sort, + List gatewayIdList, + String processDefinitionId) { + List 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 flowElements1 = subProcess.getFlowElements(); + List 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; + } + /** * 获取流程图像,已执行节点和流程线高亮显示 */ diff --git a/laws-modules/src/main/java/com/jero/modules/activiti/util/ConversionUtil.java b/laws-modules/src/main/java/com/jero/modules/activiti/util/ConversionUtil.java deleted file mode 100644 index b8112076..00000000 --- a/laws-modules/src/main/java/com/jero/modules/activiti/util/ConversionUtil.java +++ /dev/null @@ -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 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 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 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 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(); - } -} - diff --git a/laws-modules/src/main/resources/bpmn/diagram_1.bpmn20.xml b/laws-modules/src/main/resources/bpmn/diagram_1.bpmn20.xml index f68b744f..670d8563 100644 --- a/laws-modules/src/main/resources/bpmn/diagram_1.bpmn20.xml +++ b/laws-modules/src/main/resources/bpmn/diagram_1.bpmn20.xml @@ -4,22 +4,21 @@ Flow_0ln2zen - + Flow_0ln2zen Flow_1dmfby6 - Flow_1dmfby6 Flow_0hkyh3o - + Flow_0hkyh3o Flow_0iw6bki - + Flow_0iw6bki Flow_0stcykp @@ -27,51 +26,75 @@ Flow_0stcykp - + + + + + + + + + - + - - + + - - + + - - + + - - + + - + - - - - - - + + - - + + + - - + + - - + + + + + + + + + + + + + + + + + + + + + diff --git a/laws-modules/src/main/resources/bpmn/企标制修订流程2 - 副本.bpmn20.xml b/laws-modules/src/main/resources/bpmn/企标制修订流程2 - 副本.bpmn20.xml new file mode 100644 index 00000000..2fce00b1 --- /dev/null +++ b/laws-modules/src/main/resources/bpmn/企标制修订流程2 - 副本.bpmn20.xml @@ -0,0 +1,491 @@ + + + + + Flow_0ln2zen + + + + Flow_0ln2zen + Flow_1dmfby6 + + + + + Flow_0hkyh3o + Flow_0dlfvoz + Flow_0iw6bki + + + Flow_0iw6bki + Flow_0rw7rph + + + + + + + Flow_1dmfby6 + Flow_0hkyh3o + + ${nrOfInstances== nrOfCompletedInstances} + + + + Flow_0rw7rph + Flow_0dlfvoz + Flow_07x6x68 + + + + ${!pass} + + + ${pass} + + + Flow_07x6x68 + Flow_1gc5b6z + + + Flow_1gc5b6z + Flow_0lxhrf3 + Flow_0s3et9m + + + + Flow_0s3et9m + Flow_1yn3bo0 + Flow_1ts1npj + + + + ${!open} + + + + Flow_02ojuiw + Flow_0lxhrf3 + + + + Flow_0114fp7 + Flow_15vlua6 + + ${nrOfInstances== nrOfCompletedInstances} + + + + Flow_1uaxx7p + Flow_02wh2wo + + + + ${pass} + + + Flow_15vlua6 + Flow_1uaxx7p + Flow_1k4inp1 + + + + ${!pass} + + + Flow_02wh2wo + Flow_0v50urt + Flow_0rkg4il + + + + ${pass} + + + ${!pass} + + + Flow_1cg7p7q + Flow_0jc597n + Flow_03b0vp0 + + + + ${pass} + + + ${!pass} + + + Flow_0jc597n + Flow_093us1v + + ${nrOfInstances== nrOfCompletedInstances} + + + + Flow_0v50urt + Flow_1cg7p7q + + + + Flow_093us1v + Flow_09gf9nd + + + + Flow_09gf9nd + Flow_0r1lb59 + + + Flow_1yn3bo0 + Flow_1k4inp1 + Flow_0rkg4il + Flow_03b0vp0 + Flow_0114fp7 + + + Flow_0r1lb59 + + + + Flow_1ts1npj + Flow_02ojuiw + + ${nrOfInstances== nrOfCompletedInstances} + + + Flow_1stk4cs + + + + Flow_14y4j6o + Flow_1x9nrbh + + ${nrOfInstances== nrOfCompletedInstances} + + + + Flow_1stk4cs + Flow_14y4j6o + + + Flow_1x9nrbh + Flow_0b6hwpr + Flow_1jfhrkk + + + Flow_1jfhrkk + Flow_0n3oqju + + ${nrOfInstances== nrOfCompletedInstances} + + + + Flow_0n3oqju + Flow_0b6hwpr + Flow_0xzqhwi + + + + + ${!pass} + + + + + Flow_0xzqhwi + + + ${!pass} + + + + + ${open} + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +