package com.mortals.flowable.listener;

import lombok.extern.apachecommons.CommonsLog;
import org.flowable.common.engine.api.delegate.event.FlowableEngineEntityEvent;
import org.flowable.common.engine.api.delegate.event.FlowableEvent;
import org.flowable.engine.FormService;
import org.flowable.engine.RuntimeService;
import org.flowable.engine.TaskService;
import org.flowable.engine.delegate.event.AbstractFlowableEngineEventListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Map;

/**
 * @author: zxfei
 * @date: 2021/8/10 7:23
 * @description:
 **/
//@Component
@CommonsLog
public class ProcessInstanceCompleteListener extends AbstractFlowableEngineEventListener {

    @Autowired
    private RuntimeService runtimeService;
    @Override
    protected void processCompleted(FlowableEngineEntityEvent event) {
        log.info("进入流程结束监听器……");

        String processInstanceId = event.getProcessInstanceId();
        Map<String, Object> variables = runtimeService.getVariables(processInstanceId);
        Map<String, Object> startForm = (Map<String, Object>) variables.get("startForm");
      //  Form form = formService..getById(new Long((String) startForm.get("formId")));

        log.info("variables: "+variables);
        log.info("startForm: "+startForm);
        //System.out.println("form: " + form);

        super.processCompleted(event);
    }

    @Override
    protected void taskCompleted(FlowableEngineEntityEvent event) {
        log.info("进入taskCompleted监听器……");
        super.taskCompleted(event);
    }

    @Override
    public void onEvent(FlowableEvent flowableEvent) {
        log.info("进入taskCompleted监听器--onEvent……");
        super.onEvent(flowableEvent);
    }

}