package com.ruoyi.project.listener;

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.domain.SysUser;
import com.ruoyi.project.system.service.ISysUserService;
import org.activiti.engine.delegate.DelegateTask;
import org.activiti.engine.delegate.TaskListener;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import java.io.Serializable;

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

    @Override
    public void notify(DelegateTask delegateTask) {
        String id = delegateTask.getExecution().getProcessInstanceBusinessKey();
        logger.info("--------------------------executor--------------------------");
        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 executorId = (Long) delegateTask.getVariables().get("executor");
        logger.info("executorId:" + executorId);
        SysUser executor = sysUserService.selectUserById(executorId);
        logger.info("executor:" + executor);

        String submitType = (String) delegateTask.getVariables().get("submitType");
        logger.info("submitType:" + submitType);
        if (submitType == null) {
            logger.info("发起流程，给流程种所有人员发送邮件");
        }
    }
}
