¶Ô±ÈÐÂÎļþ |
| | |
| | | /* |
| | | * Copyright (c) 2018-2028, Chill Zhuang All rights reserved. |
| | | * |
| | | * Redistribution and use in source and binary forms, with or without |
| | | * modification, are permitted provided that the following conditions are met: |
| | | * |
| | | * Redistributions of source code must retain the above copyright notice, |
| | | * this list of conditions and the following disclaimer. |
| | | * Redistributions in binary form must reproduce the above copyright |
| | | * notice, this list of conditions and the following disclaimer in the |
| | | * documentation and/or other materials provided with the distribution. |
| | | * Neither the name of the dreamlu.net developer nor the names of its |
| | | * contributors may be used to endorse or promote products derived from |
| | | * this software without specific prior written permission. |
| | | * Author: Chill åºéª (smallchill@163.com) |
| | | */ |
| | | package com.vci.ubcs.flow.engine.service.impl; |
| | | |
| | | import com.vci.ubcs.flow.core.constant.ProcessConstant; |
| | | import com.vci.ubcs.flow.core.entity.BladeFlow; |
| | | import com.vci.ubcs.flow.core.utils.TaskUtil; |
| | | import com.vci.ubcs.flow.engine.entity.*; |
| | | import com.vci.ubcs.flow.engine.service.FlowEngineService; |
| | | import com.vci.ubcs.flow.engine.service.FlowTaskUserService; |
| | | import com.vci.ubcs.flow.engine.service.VICFlowService; |
| | | import lombok.AllArgsConstructor; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.flowable.bpmn.model.*; |
| | | import org.flowable.engine.*; |
| | | import org.flowable.engine.impl.persistence.entity.ExecutionEntity; |
| | | import org.flowable.engine.repository.ProcessDefinition; |
| | | import org.flowable.engine.runtime.ProcessInstance; |
| | | import org.flowable.task.api.Task; |
| | | import org.springblade.core.secure.utils.AuthUtil; |
| | | import org.springblade.core.tool.api.R; |
| | | import org.springblade.core.tool.support.Kv; |
| | | import org.springframework.stereotype.Service; |
| | | import java.util.*; |
| | | |
| | | /** |
| | | * 工使µæå¡å®ç°ç±» |
| | | * |
| | | * @author Chill |
| | | */ |
| | | @Slf4j |
| | | @Service |
| | | @AllArgsConstructor |
| | | public class VCIFlowserviceImpl implements VICFlowService { |
| | | |
| | | private final RuntimeService runtimeService; |
| | | private final IdentityService identityService; |
| | | private final RepositoryService repositoryService; |
| | | private final TaskService taskService; |
| | | private final FlowTaskUserService flowTaskUserService; |
| | | private final FlowEngineService flowEngineService; |
| | | private final HistoryService historyService; |
| | | |
| | | @Override |
| | | public R<BladeFlow> startProcess(FlowTaskDTO flowTaskUserC){ |
| | | String modelKey = flowTaskUserC.getModelKey(); |
| | | String templateId = flowTaskUserC.getTemplateId(); |
| | | |
| | | Kv kv = Kv.create() |
| | | .set(ProcessConstant.TASK_VARIABLE_CREATE_USER, AuthUtil.getUserName()); |
| | | |
| | | // 设置æµç¨å¯å¨ç¨æ· |
| | | identityService.setAuthenticatedUserId(TaskUtil.getTaskUser()); |
| | | |
| | | // å¼å¯æµç¨ |
| | | //æ¥è¯¢ææ°çæµç¨é¨ç½²id |
| | | ProcessDefinition latesDefinition = repositoryService.createProcessDefinitionQuery().latestVersion().processDefinitionKey(modelKey).singleResult(); |
| | | String processDefinitionId = latesDefinition.getId(); |
| | | |
| | | //æ¥è¯¢æ¯ä¸æ¥å®¡æ ¸äºº |
| | | List<FlowTaskUser> taskUsers = flowTaskUserService.getTaskUserByTemplateAndModelKey(templateId,modelKey); |
| | | Set<String> taskIdSet = new HashSet<>(); |
| | | for (FlowTaskUser taskUser:taskUsers){ |
| | | kv.put(taskUser.getTaskId(),TaskUtil.getTaskUser(taskUser.getUserId())); |
| | | taskIdSet.add(taskUser.getTaskId()); |
| | | } |
| | | |
| | | //对æ¯é
ç½®çå®¡æ ¸äººååæµç¨ä¸èç¹æ¯å¦ä¸è´ï¼å¯è½å卿µç¨èç¹åæ´äºï¼å¤äºæè
å°äºèç¹ï¼ä½æ¯é
ç½®å®¡æ ¸äººåçèç¹æ²¡æå |
| | | // List<Map<String,String>> processTasks = flowEngineService.getNodeByFlowableKey(modelKey); |
| | | // for (Map<String,String> mi:processTasks){ |
| | | // String taskId = mi.get(flowEngineService.getTaskIdString()); |
| | | // if(!taskIdSet.contains(taskId)){ |
| | | // throw new ServiceException("æµç¨å·²éæ°é¨ç½²ï¼èç¹å·²æ¹åï¼è¯·è®¾ç½®å®¡æ ¸äººåï¼"); |
| | | // } |
| | | // } |
| | | // if(taskIdSet.size()!=processTasks.size()){ |
| | | // throw new ServiceException("æµç¨å·²éæ°é¨ç½²ï¼èç¹å·²æ¹åï¼è¯·è®¾ç½®å®¡æ ¸äººåï¼"); |
| | | // } |
| | | |
| | | //æµç¨ä¸æä»¶ãåéç |
| | | //do.. |
| | | |
| | | ProcessInstance processInstance = runtimeService.startProcessInstanceById(processDefinitionId, modelKey, kv); |
| | | // ç»è£
æµç¨éç¨ç±» |
| | | BladeFlow flow = new BladeFlow(); |
| | | flow.setProcessInstanceId(processInstance.getId()); |
| | | |
| | | return R.data(flow); |
| | | } |
| | | |
| | | public static String NODE_NOW = "now"; |
| | | public static String NODE_NEXT = "next"; |
| | | /** |
| | | * è·åä»»å¡èç¹ |
| | | * |
| | | * @param node æ¥è¯¢èç¹éæ© |
| | | * @param processInstanceId æµç¨å®ä¾id |
| | | */ |
| | | public FlowTaskDTO nextFlowNode(String node, String processInstanceId) { |
| | | FlowTaskDTO flowTaskDTO = new FlowTaskDTO(); |
| | | List<FlowTaskDTO> taskList = new ArrayList<>();//èç¹æé® |
| | | flowTaskDTO.setToTasks(taskList); |
| | | |
| | | Task task = taskService.createTaskQuery().processInstanceId(processInstanceId).active().singleResult(); |
| | | ExecutionEntity ee = (ExecutionEntity) runtimeService.createExecutionQuery() |
| | | .executionId(task.getExecutionId()).singleResult(); |
| | | // å½å审æ¹èç¹ |
| | | String crruentActivityId = ee.getActivityId(); |
| | | BpmnModel bpmnModel = repositoryService.getBpmnModel(task.getProcessDefinitionId()); |
| | | FlowNode flowNode = (FlowNode) bpmnModel.getFlowElement(crruentActivityId); |
| | | |
| | | //è¿ä¸ªå®ä¾çææèç¹ |
| | | ProcessInstance processInstance = runtimeService.createProcessInstanceQuery().processInstanceId(processInstanceId).singleResult(); |
| | | Map<String, Object> processVariables = processInstance.getProcessVariables();//ææåæ° |
| | | flowTaskDTO.setVars(processVariables); |
| | | |
| | | String modelKey = processInstance.getProcessDefinitionKey(); |
| | | List<FlowTaskDTO> mis = flowEngineService.getNodeByFlowableKey(modelKey); |
| | | |
| | | // è¾åºè¿çº¿ |
| | | List<SequenceFlow> outFlows = flowNode.getOutgoingFlows(); |
| | | for (SequenceFlow sequenceFlow : outFlows) { |
| | | //å½å审æ¹èç¹ |
| | | if (NODE_NOW.equals(node)) { |
| | | FlowElement sourceFlowElement = sequenceFlow.getSourceFlowElement(); |
| | | System.out.println("å½åèç¹: id=" + sourceFlowElement.getId() + ",name=" + sourceFlowElement.getName()); |
| | | } else if (NODE_NEXT.equals(node)) { |
| | | // ä¸ä¸ä¸ªå®¡æ¹èç¹ |
| | | FlowElement targetFlow = sequenceFlow.getTargetFlowElement(); |
| | | if (targetFlow instanceof UserTask) { |
| | | System.out.println("ä¸ä¸èç¹: id=" + targetFlow.getId() + ",name=" + targetFlow.getName()); |
| | | } |
| | | // 妿ä¸ä¸ªå®¡æ¹èç¹ä¸ºæä»ç½å
³ |
| | | if (targetFlow instanceof ExclusiveGateway) { |
| | | |
| | | ExclusiveGateway exclusiveGateway = (ExclusiveGateway) targetFlow; |
| | | List<SequenceFlow> exclusiveGatewayOutgoingFlows = exclusiveGateway.getOutgoingFlows(); |
| | | for (SequenceFlow nexti:exclusiveGatewayOutgoingFlows){ |
| | | String conditionExpression = nexti.getConditionExpression();//condition |
| | | String taskId = nexti.getTargetRef();//taskId |
| | | String name = nexti.getName();//toName,驳åãåæ |
| | | |
| | | for (FlowTaskDTO flowTaskUserCi:mis){ |
| | | if(taskId.equals(flowTaskUserCi.getTaskId())){ |
| | | flowTaskUserCi.setCondition(conditionExpression); |
| | | if(conditionExpression.split("=").length>1) { |
| | | flowTaskUserCi.setConditionKey(conditionExpression.split("=")[0]); |
| | | flowTaskUserCi.setConditionValue(conditionExpression.split("=")[1]); |
| | | } |
| | | flowTaskUserCi.setToName(name); |
| | | flowTaskUserCi.setToTaskId(taskId); |
| | | flowTaskUserCi.setToTaskName(flowTaskUserCi.getTaskName()); |
| | | taskList.add(flowTaskUserCi); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | return flowTaskDTO; |
| | | } |
| | | } |