package com.srs.flowable.listener;

import com.srs.common.utils.DateUtils;
import com.srs.common.utils.SecurityUtils;
import com.srs.common.utils.spring.SpringUtils;
import com.srs.flowable.domain.StuLeaveApplication;
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;

/**
 * 销假核实监听
 */
@Slf4j
@Component
public class CancellationListener implements ExecutionListener {
    @Override
    public void notify(DelegateExecution delegateExecution) {
        LeaveMapper leaveMapper = (LeaveMapper) SpringUtils.getBean("leaveMapper");

        log.info("任务流相关数据",delegateExecution);

        // 辅导员审批结果
        String approval = delegateExecution.getVariable("approval").toString();

        // 拿到流程所有参数
        String approved = delegateExecution.getVariable("approved").toString();


        // 请假单id
        // 报错信息
        String leaveApplicationId = delegateExecution.getVariable("leaveApplicationId").toString();

        log.info("审批结果为：", approval);

        StuLeaveApplication stuLeaveApplication = leaveMapper.selectRtStuLeaveApplicationByLeaveApplicationId(leaveApplicationId);

        if (stuLeaveApplication != null) {
            stuLeaveApplication.setCancellation(2);
        }
        stuLeaveApplication.setUpdateBy(SecurityUtils.getUsername());

        stuLeaveApplication.setUpdateTime(DateUtils.getNowDate());

        leaveMapper.updateRtStuLeaveApplication(stuLeaveApplication);
    }
}
