package com.srs.flowable.listener.relieve;

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

import java.util.Map;

/**
 * 根据学生userId获取辅导员id
 */
@Component
@Slf4j
public class StuCounselorListener implements ExecutionListener {

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

        // 获取辅导员的sys_user表id
        Map<String ,Long> map = relieveMapper.getCounselorInfo(Long.valueOf(delegateExecution.getVariable("stuUserId").toString()));

        if (map != null){
            // 辅导员的信息
            delegateExecution.setVariable("approval",map.get("userId"));
            // 辅导员的部门id
            delegateExecution.setVariable("deptId",map.get("deptId"));

            // todo 企业微信推送消息

        }else {
            throw new RuntimeException("获取辅导员信息失败");
        }

    }
}
