| | |
| | | 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.flowable.task.api.history.HistoricTaskInstance; |
| | | import org.springblade.core.tool.api.R; |
| | | import org.springblade.core.tool.utils.Func; |
| | | import org.springblade.core.tool.utils.StringUtil; |
| | | import org.springblade.mdm.basesetting.machine.service.MachineService; |
| | | import org.springblade.mdm.basesetting.machine.entity.Machine; |
| | | import org.springblade.mdm.basesetting.producedivision.entity.ProduceDivision; |
| | | import org.springblade.mdm.basesetting.producedivision.service.ProduceDivisionService; |
| | | import org.springblade.mdm.commons.service.UserCommonService; |
| | | import org.springblade.mdm.flow.constants.FlowContants; |
| | | import org.springblade.mdm.flow.constants.FlowVariableContants; |
| | | import org.springblade.mdm.program.entity.NcNode; |
| | | import org.springblade.mdm.program.service.NodeDeptQueryService; |
| | | import org.springblade.system.feign.IUserClient; |
| | | import org.springblade.system.pojo.entity.User; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.web.bind.annotation.RequestBody; |
| | | |
| | | import java.util.List; |
| | | import java.util.Map; |
| | |
| | | private final RuntimeService runtimeService; |
| | | private final HistoryService historyService; |
| | | private final ProduceDivisionService produceDivisionService; |
| | | private final NodeDeptQueryService nodeDeptQueryService; |
| | | private final MachineService machineService; |
| | | private final UserCommonService userCommonService; |
| | | /** |
| | | * 根据流程实例id获取definitionKey |
| | | * @param processInstanceId |
| | |
| | | programProperties.setProcessInstanceId(processInstanceId); |
| | | |
| | | Map<String, Object> vars = runtimeService.getVariables(processInstanceId); |
| | | this.copyFlowPropertiesFromMap(programProperties, vars); |
| | | |
| | | ProcessInstance processInstance = runtimeService.createProcessInstanceQuery() |
| | | .processInstanceId(processInstanceId) |
| | | .singleResult(); |
| | | String processDefinitionKey = processInstance.getProcessDefinitionKey(); |
| | | programProperties.setProcessDefinitionKey(processDefinitionKey); |
| | | return programProperties; |
| | | } |
| | | public FlowProgramProperties getProgramPropertiesFromHis(String processInstanceId) { |
| | | HistoricProcessInstance historicInstance = historyService.createHistoricProcessInstanceQuery().includeProcessVariables() |
| | | .processInstanceId(processInstanceId) |
| | | .singleResult(); |
| | | |
| | | FlowProgramProperties programProperties = new FlowProgramProperties(); |
| | | programProperties.setProcessInstanceId(processInstanceId); |
| | | |
| | | Map<String, Object> vars =historicInstance.getProcessVariables(); |
| | | this.copyFlowPropertiesFromMap(programProperties,vars); |
| | | |
| | | programProperties.setProcessDefinitionKey(historicInstance.getProcessDefinitionKey()); |
| | | return programProperties; |
| | | } |
| | | |
| | | /** |
| | | * 从map中赋值流程便利到vo |
| | | * @param programProperties vo |
| | | * @param vars 变量map |
| | | */ |
| | | void copyFlowPropertiesFromMap(FlowProgramProperties programProperties,Map<String, Object> vars){ |
| | | |
| | | programProperties.setTitle(String.valueOf(vars.get(FlowContants.TITLE))); |
| | | programProperties.setIsTempFlow(Func.toStr(vars.get(FlowContants.IS_TEMP_FLOW))); |
| | | programProperties.setDrawingNo(String.valueOf(vars.get(FlowContants.DRAWING_NO))); |
| | | programProperties.setDrawingNoEdition(String.valueOf(vars.get(FlowContants.DRAWING_NO_EDITION))); |
| | | programProperties.setProductModel(String.valueOf(vars.get(FlowContants.PRODUCT_MODEL))); |
| | |
| | | if(vars.containsKey(FlowContants.CURED_NODE_ID)){ |
| | | programProperties.setCuredNodeId(Func.toLong(vars.get(FlowContants.CURED_NODE_ID))); |
| | | } |
| | | if(vars.containsKey(FlowContants.NODE_ID)){ |
| | | programProperties.setNodeId(Func.toLong(vars.get(FlowContants.NODE_ID))); |
| | | } |
| | | programProperties.setCureProgramUseable(String.valueOf(vars.get(FlowContants.CURE_PROGRAM_USEABLE))); |
| | | |
| | | programProperties.setTeamLeaderId(Func.toLong(vars.get(FlowContants.TEAM_LEADER))); |
| | | programProperties.setProgrammerId(Func.toLong(vars.get(FlowContants.PROGRAMMER))); |
| | | programProperties.setCheckerId(Func.toLong(vars.get(FlowContants.CHECKER))); |
| | | programProperties.setSeniorId(Func.toLong(vars.get(FlowContants.SENIOR))); |
| | | |
| | | ProcessInstance processInstance = runtimeService.createProcessInstanceQuery() |
| | | .processInstanceId(processInstanceId) |
| | | .singleResult(); |
| | | String processDefinitionKey = processInstance.getProcessDefinitionKey(); |
| | | programProperties.setProcessDefinitionKey(processDefinitionKey); |
| | | return programProperties; |
| | | programProperties.setProgramNo(programProperties.getDrawingNo()+"-"+programProperties.getProcessNo()+"-"+programProperties.getProcessEdition()); |
| | | |
| | | programProperties.setActProgrammerId(Func.toLong(vars.get(FlowVariableContants.ACT_PROGRAMMER))); |
| | | programProperties.setActCheckerId(Func.toLong(vars.get(FlowVariableContants.ACT_CHECKER))); |
| | | programProperties.setActSeniorId(Func.toLong(vars.get(FlowVariableContants.ACT_SENIOR))); |
| | | programProperties.setProgrammerName(Func.toStr(vars.get("programmerName"))); |
| | | } |
| | | |
| | | /** |
| | | * 流程是否在进行 |
| | | * @param processInstanceId 实例id |
| | |
| | | * @param processInstanceId 流程实例id |
| | | * @return assignee |
| | | */ |
| | | /* |
| | | public String previusAssignee(String processInstanceId) { |
| | | // 获取历史任务实例 |
| | | List<HistoricTaskInstance> historicTasks = historyService.createHistoricTaskInstanceQuery() |
| | |
| | | assignee = historicTasks.get(historicTasks.size() - 1).getAssignee(); |
| | | } |
| | | return assignee; |
| | | } |
| | | }*/ |
| | | |
| | | /** |
| | | * 将默认审批用户放入map中 |
| | |
| | | vars.put(FlowContants.ASSIGNEE, defaultAssignee);//第一个审批用户:组长 |
| | | } |
| | | |
| | | vars.put(FlowContants.PROGRAMMER_NAME, userCommonService.getUserNameById(div.getProgrammerId())); |
| | | return div; |
| | | } |
| | | |
| | | /** |
| | | * 根据程序包名节点,填充变量map |
| | | * @param vars |
| | | * @param programPackageNode |
| | | */ |
| | | public void putFlowVariablesByNode(Map<String, Object> vars, NcNode programPackageNode){ |
| | | //机床编号 |
| | | vars.put(FlowContants.MACHINE_CODE,programPackageNode.getMachineCode()); |
| | | Machine machine = machineService.getByCode(programPackageNode.getMachineCode()); |
| | | //机床型号 |
| | | if(machine != null) { |
| | | vars.put(FlowContants.MACHINE_MODE, machine.getName()); |
| | | } |
| | | vars.put(FlowContants.PROCESS_NO,programPackageNode.getProcessNo()); |
| | | vars.put(FlowContants.PROCESS_NAME,programPackageNode.getProcessName()); |
| | | vars.put(FlowContants.PROCESS_EDITION,programPackageNode.getProcessEdition()); |
| | | vars.put(FlowContants.CRAFT_EDITION,programPackageNode.getCraftEdition()); |
| | | |
| | | vars.put(FlowContants.DRAWING_NO,programPackageNode.getDrawingNo()); |
| | | vars.put(FlowContants.DRAWING_NO_EDITION,programPackageNode.getDrawingNoEdition()); |
| | | |
| | | vars.put(FlowContants.PROGRAM_PACKAGE_NAME,programPackageNode.getName()); |
| | | |
| | | vars.put(FlowContants.PRODUCT_MODEL,programPackageNode.getProductModel()); |
| | | vars.put(FlowContants.NODE_ID, programPackageNode.getId()); |
| | | vars.put(FlowContants.WORKSHOP,nodeDeptQueryService.getWorkshopNameByMachineCode(programPackageNode.getMachineCode())); |
| | | |
| | | } |
| | | } |
| | | |
| | | |