package com.srs.flowable.listener.disqualification;

import com.srs.common.utils.DateUtils;
import com.srs.common.utils.SecurityUtils;
import com.srs.common.utils.spring.SpringUtils;
import com.srs.dormitory.domain.SrsDormitoryStudent;
import com.srs.flowable.domain.StuDisqualification;
import com.srs.flowable.domain.Student;
import com.srs.flowable.mapper.DisciplinaryMapper;
import com.srs.flowable.mapper.StuDisqualificationMapper;
import lombok.extern.slf4j.Slf4j;
import org.flowable.engine.delegate.TaskListener;
import org.flowable.task.service.delegate.DelegateTask;
import org.springframework.stereotype.Component;

/**
 * 给予退学修改申请状态
 *
 * @author lsd
 */
@Component
@Slf4j
public class DisqualificationStatusListener implements TaskListener {

    @Override
    public void notify(DelegateTask delegateTask) {

        StuDisqualificationMapper stuDisqualificationMapper = SpringUtils.getBean("stuDisqualificationMapper");

        DisciplinaryMapper disciplinaryMapper = SpringUtils.getBean("disciplinaryMapper");

        StuDisqualification disqualificationId = stuDisqualificationMapper.selectRtStuDisqualificationByDisqualificationId(Long.valueOf(delegateTask.getVariable("disqualificationId").toString()));
        if (disqualificationId != null) {
            disqualificationId.setApplyStatus(1L);
            disqualificationId.setUpdateBy(SecurityUtils.getUsername());
            disqualificationId.setUpdateTime(DateUtils.getNowDate());
            stuDisqualificationMapper.updateRtStuDisqualification(disqualificationId);

            // 修改学生学籍状态
            Student student = new Student();
            // 状态（01：在校  02：变更离校   03：毕业
            student.setStatus("02");
            student.setStuNo(disqualificationId.getStuNo());
            student.setUpdateBy(SecurityUtils.getUsername());
            student.setUpdateTime(DateUtils.getNowDate());
            disciplinaryMapper.updateStudentStatus(student);
            disciplinaryMapper.updateStudentStatus(student);
            // todo 辅导员给予退学：1、宿舍
            SrsDormitoryStudent dormitoryStudent=new SrsDormitoryStudent();
            dormitoryStudent.setStuNo(disqualificationId.getStuNo());
            disciplinaryMapper.deleteDormitoryStudent(dormitoryStudent);
            //2、综测
            //3、班级
        }


    }
}
