package com.ruoyi.project.listener;

import com.alibaba.fastjson.JSON;
import com.ruoyi.common.sendEmail.IMailService;
import com.ruoyi.common.utils.SpringContextUtils;
import com.ruoyi.project.ehs.domain.TApproveDanger;
import com.ruoyi.project.ehs.service.ITApproveDangerService;
import com.ruoyi.project.system.service.ISysUserService;
import org.activiti.engine.delegate.DelegateExecution;
import org.activiti.engine.delegate.DelegateTask;
import org.activiti.engine.delegate.ExecutionListener;
import org.activiti.engine.delegate.TaskListener;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.Map;

@Service("recorderTaskCreateListener")
public class RecorderTaskCreateListener implements Serializable, TaskListener {
    protected Logger logger = LoggerFactory.getLogger(getClass());
    private static final long serialVersionUID = -375905405805540186L;

    @Override
    public void notify(DelegateTask delegateTask) {
        logger.info("--------------------------recorder--------------------------");
        String id = delegateTask.getExecution().getProcessInstanceBusinessKey();
        logger.info("id:" + id);
        ITApproveDangerService approveDangerService = (ITApproveDangerService) SpringContextUtils.getBean("approveDangerService");
        ISysUserService sysUserService = (ISysUserService) SpringContextUtils.getBean("sysUserService");
        IMailService mailService = (IMailService) SpringContextUtils.getBean("mailService");
        TApproveDanger approveDanger = approveDangerService.selectTApproveDangerById(Long.parseLong(id));
        logger.info("approveDanger" + approveDanger);

        Long recorder = (Long) delegateTask.getVariables().get("recorder");
        logger.info("recorder:" + recorder);
    }
}
