package net.ferrum.workflow.listener;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import net.ferrum.common.constant.BusinessConstants;
import net.ferrum.common.enums.NoticeType;
import net.ferrum.common.utils.JsonUtils;
import net.ferrum.system.domain.SysNotice;
import net.ferrum.system.service.ISysNoticeService;
import net.ferrum.workflow.domain.vo.WfDetailVo;
import net.ferrum.workflow.service.IWfProcessService;
import org.flowable.engine.delegate.DelegateExecution;
import org.flowable.engine.delegate.ExecutionListener;
import org.springframework.stereotype.Component;

import java.util.Map;

/**
 * 发布规格事件监听类
 *
 * @author 26554
 * @version 1.0.0
 * @since 2025/2/18
 */

@Slf4j
@Component("publishSpecificationListener")
@RequiredArgsConstructor
public class PublishSpecificationListener implements ExecutionListener {

    private final IWfProcessService processService;
    private final ISysNoticeService noticeService;

    @Override
    public void notify(DelegateExecution delegateExecution) {
        // 获取所有流程变量
        Map<String, Object> allVariables = delegateExecution.getVariables();
        for (Map.Entry<String, Object> entry : allVariables.entrySet()) {
            String key = entry.getKey();
            Object value = entry.getValue();
            System.out.println("Key: " + key + ", Value: " + value);
        }

        //WfDetailVo wfDetailVo = processService.queryProcessDetail(delegateExecution.getProcessInstanceId(), delegateExecution.getId());
        SysNotice notice = new SysNotice();
        notice.setNoticeTitle(BusinessConstants.NOTICE_TITLE);
        notice.setNoticeType(NoticeType.DESIGN_PUBLISH.getType());
        //notice.setNoticeContent(JsonUtils.toJsonString(wfDetailVo.getProcessFormList()));
        log.info("参数详情：{}", delegateExecution.getProcessInstanceId());
        log.info("插入通知内容：{}", notice);
        noticeService.insertNotice(notice);
    }


}
