package com.srs.flowable.listener.disciplinary;


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

/**
 * 根据辅导员的部门id，查询该部门的学无干事人员
 */
@Component
@Slf4j
public class XWGSListener implements ExecutionListener {

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

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

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

            } else {
                throw new RuntimeException("该学院学务干事审批人员未设置");

            }
        } else {
            throw new RuntimeException("未找到部门相关信息");
        }


    }
}
