package com.qqchen.deploy.backend.workflow.listener.business;

import com.qqchen.deploy.backend.workflow.dto.event.WorkflowNodeInstanceStatusChangeEvent;
import com.qqchen.deploy.backend.workflow.service.IWorkflowNodeInstanceService;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.event.EventListener;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

@Slf4j
@Component
public class WorkflowNodeInstanceStatusChangeListener {

    @Resource
    private IWorkflowNodeInstanceService workflowNodeInstanceService;

    @EventListener
    @Transactional(propagation = Propagation.REQUIRES_NEW)
    public void handleWorkflowStatusChange(WorkflowNodeInstanceStatusChangeEvent event) {
//        log.info("Handling workflow node instance status change event: {}", event);
        workflowNodeInstanceService.saveOrUpdateWorkflowNodeInstance(event);
    }
}
