package org.springblade.flow.engine.custom.event.flusher;

import org.flowable.common.engine.impl.interceptor.CommandContext;
import org.flowable.engine.impl.event.logger.AbstractEventFlusher;
import org.flowable.engine.impl.event.logger.handler.EventLoggerEventHandler;
import org.flowable.engine.impl.persistence.entity.EventLogEntryEntity;
import org.flowable.engine.impl.persistence.entity.EventLogEntryEntityManager;
import org.flowable.engine.impl.util.CommandContextUtil;

/**
 * @author LoveMyOrange
 * @create 2022-02-02 11:42
 */
public class ElasticSearchFlusher extends AbstractEventFlusher {
    @Override
    public void closing(CommandContext commandContext) {
        EventLogEntryEntityManager eventLogEntryEntityManager = CommandContextUtil.getEventLogEntryEntityManager();
        for (EventLoggerEventHandler eventHandler : eventHandlers) {
            EventLogEntryEntity eventLogEntryEntity = eventHandler.generateEventLogEntry(commandContext);
            //TODO 将获取之后的日志实体转换为符合业务的实体对象
//            eventLogEntryEntityManager.insert(eventHandler.generateEventLogEntry(commandContext));
        }
    }

    @Override
    public void afterSessionsFlush(CommandContext commandContext) {

    }

    @Override
    public void closeFailure(CommandContext commandContext) {

    }

    @Override
    public Integer order() {
        return 200;
    }

    @Override
    public boolean multipleAllowed() {
        return false;
    }
}
