package com.srs.flowable.listener.disciplinary;

import com.srs.common.utils.spring.SpringUtils;
import com.srs.flowable.mapper.DisciplinaryMapper;
import lombok.extern.slf4j.Slf4j;
import org.flowable.engine.delegate.DelegateExecution;
import org.flowable.engine.delegate.ExecutionListener;
import org.springframework.stereotype.Component;

/**
 * 根据辅导员部门id获取二级学院书记
 */
@Component
@Slf4j
public class EJXYSJListener implements ExecutionListener {

    @Override
    public void notify(DelegateExecution delegateExecution) {
        DisciplinaryMapper disciplinaryMapper = (DisciplinaryMapper)SpringUtils.getBean("disciplinaryMapper");

        Long deptId = (Long) delegateExecution.getVariable("deptId");

        Long userId = disciplinaryMapper.getApprovalByDeptIdAndRoleKey(deptId, "xywjclwyh");
        if (userId!=null){
            delegateExecution.setVariable("approval", userId);
            // todo 企业微信推送消息

        }else{
            throw new RuntimeException("该二级学院书记审批人未配置");
        }
    }
}
