| | |
| | | package org.springblade.mdm.flow.service; |
| | | |
| | | import lombok.AllArgsConstructor; |
| | | import org.flowable.engine.HistoryService; |
| | | import org.flowable.engine.RuntimeService; |
| | | import org.flowable.engine.TaskService; |
| | | import org.flowable.engine.history.HistoricProcessInstance; |
| | | import org.flowable.engine.runtime.ProcessInstance; |
| | | import org.flowable.task.api.Task; |
| | | import org.springblade.core.tool.api.R; |
| | | import org.springblade.core.tool.utils.StringUtil; |
| | | import org.springblade.mdm.flow.constants.FlowContants; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.web.bind.annotation.RequestBody; |
| | | |
| | | import java.util.Map; |
| | | |
| | |
| | | @Service |
| | | public class FlowCommonService { |
| | | private final RuntimeService runtimeService; |
| | | private final HistoryService historyService; |
| | | |
| | | /** |
| | | * 根据流程实例id获取definitionKey |
| | |
| | | */ |
| | | public FlowProgramProperties getProgramProperties(String processInstanceId){ |
| | | FlowProgramProperties programProperties = new FlowProgramProperties(); |
| | | programProperties.setProcessInstanceId(processInstanceId); |
| | | |
| | | Map<String, Object> vars = runtimeService.getVariables(processInstanceId); |
| | | |
| | |
| | | |
| | | programProperties.setProcessNo(String.valueOf(vars.get(FlowContants.PROCESS_NO))); |
| | | programProperties.setProcessEdition(String.valueOf(vars.get(FlowContants.PROCESS_EDITION)));//工序版次 |
| | | programProperties.setProcessName(String.valueOf(vars.get(FlowContants.PROCESS_NAME))); |
| | | programProperties.setMachineCode(String.valueOf(vars.get(FlowContants.MACHINE_CODE))); |
| | | //数据处理名称为版次以前,零件号加工序号:YZL4-1100-01-50 零组件号:YZL4-1100-01 工序号 50 |
| | | |
| | | programProperties.setCraftEdition(String.valueOf(vars.get(FlowContants.CRAFT_EDITION))); |
| | | programProperties.setHasCuredProgram(String.valueOf(vars.get(FlowContants.HAS_CURED_PROGRAM))); |
| | | |
| | | ProcessInstance processInstance = runtimeService.createProcessInstanceQuery() |
| | | .processInstanceId(processInstanceId) |
| | | .singleResult(); |
| | | String processDefinitionKey = processInstance.getProcessDefinitionKey(); |
| | | programProperties.setProcessDefinitionKey(processDefinitionKey); |
| | | return programProperties; |
| | | } |
| | | |
| | | /** |
| | | * 流程是否在进行 |
| | | * @param processInstanceId 实例id |
| | | */ |
| | | public boolean isProcessInstanceActive(String processInstanceId) { |
| | | if(processInstanceId == null){ |
| | | return false; |
| | | } |
| | | // 先查运行时表 |
| | | ProcessInstance instance = runtimeService.createProcessInstanceQuery() |
| | | .processInstanceId(processInstanceId) |
| | | .singleResult(); |
| | | |
| | | if (instance != null) { |
| | | return true; |
| | | } |
| | | |
| | | // 再查历史表确认是否曾经存在 |
| | | HistoricProcessInstance historicInstance = historyService.createHistoricProcessInstanceQuery() |
| | | .processInstanceId(processInstanceId) |
| | | .singleResult(); |
| | | |
| | | return historicInstance != null && historicInstance.getEndTime() == null; |
| | | } |
| | | |
| | | |
| | | } |
| | | |
| | | |