processus en cours Activiti souligné

annuaire

 

Avant-propos:

Fonction (1) pour mettre en évidence la mise en œuvre du processus

Fonction (2) suspendez une instance de workflow

Fonction (3) activer l'instance de workflow

 


Avant-propos:

Avant cela, petit écrit deux articles, l' un est ce qui est Activiti (débutants)  , le chapitre d' introduction à la fin de 19 je l' ai écrit, je ne me donne un but, l'article doit Activiti flux de travail n'a pas été tout à fait le flux de travail entièrement digéré, 20,200,327 articles Activiti réels que j'ai écrit  , je suis très heureux, parce que c'est un blog complet, je voudrais ajouter le contenu de cet article n'a pas dit que certains des articles.

 

 

Je sais pas beaucoup, mais je suis en train d'étudier la manière.

 

Fonction (1) pour mettre en évidence la mise en œuvre du processus

1.1 Tout d'abord d'abord dessiner un organigramme simple

Génération d'une instance de workflow 1.2

    /**
     * 1.创建一个流程实例
     */
    @GetMapping(value = "/createLeaveFlow")
    public void createLeaveFlow() throws IOException {
        //1.举个例子,soup_tang 需要请假 ,我在页面上添加请假申请,任务申请人是soup_tang,
        // 我选择审核人为汤总,请汤总给我审核这个请假流程。
        String checkPeople = "汤总";
        activitiService.createLeaveWorkFlow(checkPeople);
    }

 

 @Override
    public void createLeaveWorkFlow(String checkPeople) throws IOException {
            //先判断这个流程文件有没有部署(只需部署一次)
            Model modelData = repositoryService.getModel("1");
            ObjectNode modelNode = (ObjectNode) new ObjectMapper()
                    .readTree(repositoryService.getModelEditorSource(modelData.getId()));
            byte[] bpmnBytes = null;
            BpmnModel bpmnModel = new BpmnJsonConverter().convertToBpmnModel(modelNode);
            bpmnBytes = new BpmnXMLConverter().convertToXML(bpmnModel);

            String processName = modelData.getName() + ".bpmn20.xml";

            Deployment deployment = repositoryService.createDeployment()
                    .name(modelData.getName()).addString(processName, new String(bpmnBytes, "UTF-8"))
                    .deploy();
            //获取流程定义
            ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().deploymentId(deployment.getId()).singleResult();
            //启动流程定义,返回流程实例
            Map<String,Object> map = new HashMap<>();
            map.put("checkPeople",checkPeople);
            ProcessInstance pi = runtimeService.startProcessInstanceById(processDefinition.getId(),map);
            System.out.println("流程定义的ID:" + pi.getProcessDefinitionId());
            System.out.println("流程实例的ID:" + pi.getId());

    }

Obtenez l'ID d'instance de processus

Figure 1.3 montre un organigramme mettant en évidence l'état d'exécution

ActivitiController

     @Autowired
    private HistoryService historyService;

    @Autowired
    ProcessEngineConfiguration processEngineConfiguration;

    @Autowired
    ProcessEngineFactoryBean processEngine;


 /**
     * 查询流程实例 已高亮的形式流程执行状态
     * @param response
     * @throws Exception
     */
    @GetMapping("/queryActivitiByProcessInstanceId")
    public void queryProPlan(HttpServletResponse response) throws Exception {
        //实例id
        String processInstanceId = "10";
        //获取历史流程实例
        HistoricProcessInstance processInstance = historyService.createHistoricProcessInstanceQuery().processInstanceId(processInstanceId).singleResult();
        //获取流程图
        BpmnModel bpmnModel = repositoryService.getBpmnModel(processInstance.getProcessDefinitionId());
        processEngineConfiguration = processEngine.getProcessEngineConfiguration();
        Context.setProcessEngineConfiguration((ProcessEngineConfigurationImpl) processEngineConfiguration);

        ProcessDiagramGenerator diagramGenerator = processEngineConfiguration.getProcessDiagramGenerator();
        ProcessDefinitionEntity definitionEntity = (ProcessDefinitionEntity) repositoryService.getProcessDefinition(processInstance.getProcessDefinitionId());

        List<HistoricActivityInstance> highLightedActivitList = historyService.createHistoricActivityInstanceQuery().processInstanceId(processInstanceId).list();
        //高亮环节id集合
        List<String> highLightedActivitis = new ArrayList<String>();

        //高亮线路id集合
        List<String> highLightedFlows = getHighLightedFlows(definitionEntity, highLightedActivitList);

        for (HistoricActivityInstance tempActivity : highLightedActivitList) {
            String activityId = tempActivity.getActivityId();
            highLightedActivitis.add(activityId);
        }

        //中文显示的是口口口,设置字体就好了
        InputStream imageStream = diagramGenerator.generateDiagram(bpmnModel, "png", highLightedActivitis, highLightedFlows, "", "宋体", "宋体", null, 1.0);
        //单独返回流程图,不高亮显示
        byte[] b = new byte[1024];
        int len;
        while ((len = imageStream.read(b, 0, 1024)) != -1) {
            response.getOutputStream().write(b, 0, len);
        }

    }
 /**
     * 获取需要高亮的线
     *
     * @param processDefinitionEntity
     * @param historicActivityInstances
     * @return
     */
    private List<String> getHighLightedFlows(
            ProcessDefinitionEntity processDefinitionEntity,
            List<HistoricActivityInstance> historicActivityInstances) {

        // 用以保存高亮的线flowId
        List<String> highFlows = new ArrayList<String>();
        // 对历史流程节点进行遍历
        for (int i = 0; i < historicActivityInstances.size() - 1; i++) {
            ActivityImpl activityImpl = processDefinitionEntity
                    .findActivity(historicActivityInstances.get(i)
                            .getActivityId());// 得到节点定义的详细信息
            // 用以保存后需开始时间相同的节点
            List<ActivityImpl> sameStartTimeNodes = new ArrayList<ActivityImpl>();
            ActivityImpl sameActivityImpl1 = processDefinitionEntity
                    .findActivity(historicActivityInstances.get(i + 1)
                            .getActivityId());
            // 将后面第一个节点放在时间相同节点的集合里
            sameStartTimeNodes.add(sameActivityImpl1);
            for (int j = i + 1; j < historicActivityInstances.size() - 1; j++) {
                // 后续第一个节点
                HistoricActivityInstance activityImpl1 = historicActivityInstances
                        .get(j);
                // 后续第二个节点
                HistoricActivityInstance activityImpl2 = historicActivityInstances
                        .get(j + 1);
                if (activityImpl1.getStartTime().equals(
                        activityImpl2.getStartTime())) {
                    // 如果第一个节点和第二个节点开始时间相同保存
                    ActivityImpl sameActivityImpl2 = processDefinitionEntity
                            .findActivity(activityImpl2.getActivityId());
                    sameStartTimeNodes.add(sameActivityImpl2);
                } else {
                    // 有不相同跳出循环
                    break;
                }
            }
            List<PvmTransition> pvmTransitions = activityImpl
                    .getOutgoingTransitions();// 取出节点的所有出去的线
            for (PvmTransition pvmTransition : pvmTransitions) {
                // 对所有的线进行遍历
                ActivityImpl pvmActivityImpl = (ActivityImpl) pvmTransition
                        .getDestination();
                // 如果取出的线的目标节点存在时间相同的节点里,保存该线的id,进行高亮显示
                if (sameStartTimeNodes.contains(pvmActivityImpl)) {
                    highFlows.add(pvmTransition.getId());
                }
            }
        }
        return highFlows;
    }

 

Pour accéder à cette interface dans le navigateur:   http: // localhost: 8005 / queryActivitiByProcessInstanceId

Peut obtenir cette image ci-dessous, cette image peut également être affiché sur la page, cela devra se définir.

 

Fonction (2) suspendez une instance de workflow

Flux de travail par exemple exécutera normalement complété conformément à certaines règles, parfois besoin de faire avorter le processus, cette fois-ci, vous pouvez peut-être utiliser les méthodes suivantes.

Cliquez sur avorté après le processus normal, le processus de mise en œuvre arrêtera, seul le processus d'activation, le processus se poursuivra.

   @Autowired
    private RuntimeService runtimeService;

 /**
     * 挂起工作流
     * @return
     */
    @GetMapping(value = "/hangUpBusinessWorkFlow")
    public void hangUpBusinessWorkFlow() {
        //挂起一个流程
        String processInstanceId = "10";
        ProcessInstance processInstance = runtimeService.createProcessInstanceQuery().processInstanceId(processInstanceId).singleResult();
        if(processInstance!=null) {
            runtimeService.suspendProcessInstanceById(processInstanceId);
        }
    }

Fonction (3) activer l'instance de workflow

  @Autowired
    private RuntimeService runtimeService;

 /**
     * 激活工作流
     */
    @GetMapping(value = "/activateBusinessWorkFlow")
    public void activateBusinessWorkFlow() {
        //激活一个流程
        String processInstanceId = "10";
        ProcessInstance processInstance = runtimeService.createProcessInstanceQuery().processInstanceId(processInstanceId).singleResult();
        if(processInstance!=null) {
            runtimeService.activateProcessInstanceById(processInstanceId);
        }
    }

 

Cet article sur le sujet ici, si vous vous sentez bien d'écrire de petits mots, des petites séries pourrait donner une louange Oh, zone de commentaires d'échange de messages de bienvenue, venez ensemble!

 

 

Publié 73 articles originaux · éloge de won 59 · vues 30000 +

Je suppose que tu aimes

Origine blog.csdn.net/tangthh123/article/details/105141755
conseillé
Classement