package com.qmth.sop.server.config;

import com.qmth.sop.business.activiti.listener.ProcessEventListener;
import com.qmth.sop.common.contant.SystemConstant;
import org.activiti.engine.delegate.event.ActivitiEventListener;
import org.activiti.engine.impl.cfg.IdGenerator;
import org.activiti.spring.SpringProcessEngineConfiguration;
import org.activiti.spring.boot.ProcessEngineConfigurationConfigurer;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * @Description: activiti配置
 * @Param:
 * @return:
 * @Author: wangliang
 * @Date: 2021/7/14
 */
@Component
public class ActivitiConfig implements IdGenerator, ProcessEngineConfigurationConfigurer {

    @Resource
    ProcessEventListener processEventListener;

    /**
     * activiti 分布式id
     *
     * @return
     */
    @Override
    public String getNextId() {
        return String.valueOf(SystemConstant.getDbUuid());
    }

    /**
     * activiti 全局监听
     *
     * @param springProcessEngineConfiguration
     */
    @Override
    public void configure(SpringProcessEngineConfiguration springProcessEngineConfiguration) {
        List<ActivitiEventListener> activitiEventListener = new ArrayList<ActivitiEventListener>();
        activitiEventListener.add(processEventListener);//配置全局监听器
        springProcessEngineConfiguration.setEventListeners(activitiEventListener);

    }
}
