package cn.axzo.workflow.server.controller.listener.process;

import cn.axzo.workflow.core.listener.BpmnProcessEventListener;
import com.alibaba.fastjson.JSON;
import lombok.extern.slf4j.Slf4j;
import org.flowable.common.engine.api.delegate.event.FlowableEngineEntityEvent;
import org.flowable.engine.delegate.event.FlowableCancelledEvent;
import org.flowable.engine.delegate.event.FlowableProcessStartedEvent;
import org.springframework.core.Ordered;

/**
 * 自定义实现的流程监听器, 实现了 Ordered 接口
 *
 * 注意:Order 值越小,优先级越高
 *
 * @author wangli
 * @since 2023/7/10 18:22
 */
@Slf4j
//@Component
public class CustomBpmnProcessEventListener implements BpmnProcessEventListener, Ordered {
    @Override
    public void onCreated(FlowableEngineEntityEvent event) {
        log.info("Process onCreated: ClassName: {}, event: {}", event.getClass().getName(), JSON.toJSONString(event));
    }

    @Override
    public void onStarted(FlowableProcessStartedEvent event) {
        log.info("Process onStarted: ClassName: {}, event: {}", event.getClass().getName(), JSON.toJSONString(event));
    }

    @Override
    public void onCancelled(FlowableCancelledEvent event) {
        log.info("Process onCancelled: ClassName: {}, event: {}", event.getClass().getName(), JSON.toJSONString(event));
    }

    /**
     * 流程实例被拒绝后回调
     *
     * @param event
     */
    @Override
    public void onRejected(FlowableCancelledEvent event) {
        log.info("Process onRejected: ClassName: {}, event: {}", event.getClass().getName(), JSON.toJSONString(event));
    }

    @Override
    public void onCompleted(FlowableEngineEntityEvent event) {
        log.info("Process onCompleted: ClassName: {}, event: {}", event.getClass().getName(), JSON.toJSONString(event));
    }

    @Override
    public int getOrder() {
        return 99;
    }
}
