package com.xjrsoft.module.liteflow.node;

import cn.hutool.core.convert.Convert;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.xjrsoft.common.enums.ArchivesStatusEnum;
import com.xjrsoft.common.enums.DeleteMark;
import com.xjrsoft.module.student.entity.BaseStudentSchoolRoll;
import com.xjrsoft.module.student.entity.StudentDropOut;
import com.xjrsoft.module.student.mapper.StudentDropOutMapper;
import com.xjrsoft.module.student.service.IBaseStudentSchoolRollService;
import com.yomahub.liteflow.core.NodeComponent;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Map;

/**
 * 学生退学
 */
@Component("student_drop_out_node")
public class StudentDropOutNode extends NodeComponent {
    @Autowired
    private StudentDropOutMapper studentDropOutMapper;
    @Autowired
    private IBaseStudentSchoolRollService studentSchoolRollService;

    @Override
    public void process() throws Exception {
        // 获取表单中数据编号
        Map<String, Object> params = this.getFirstContextBean();
        Object value = util.getFormDatKey(params,"id");
        Long formId = Convert.toLong(value);
        if (formId != null) {
            //查询出数据
            StudentDropOut studentDropOut = studentDropOutMapper.selectById(formId);
            //跟新学籍信息
            BaseStudentSchoolRoll schoolRoll = studentSchoolRollService.getOne(
                new QueryWrapper<BaseStudentSchoolRoll>().lambda()
                .eq(BaseStudentSchoolRoll::getClassId, studentDropOut.getClassId())
                .eq(BaseStudentSchoolRoll::getUserId, studentDropOut.getStudentUserId())
                .eq(BaseStudentSchoolRoll::getDeleteMark, DeleteMark.NODELETE.getCode())
            );
            schoolRoll.setArchivesStatus(ArchivesStatusEnum.FB2904.getCode());
            studentSchoolRollService.updateById(schoolRoll);
        }
    }
}
