package com.admin.major.manager.impl;

import com.admin.common.utils.DateUtils;
import com.admin.common.utils.SecurityUtils;
import com.admin.major.domain.AdjustResult;
import com.admin.major.domain.SpecialApply;
import com.admin.major.manager.ISpecialApplyResultManager;
import com.admin.major.mapper.AdjustResultMapper;
import com.admin.major.mapper.SpecialApplyMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author liangjunxing
 * @date 2022/4/20 0020
 */
@Service
public class SpecialApplyResultManagerImpl implements ISpecialApplyResultManager {
    @Autowired
    private SpecialApplyMapper specialApplyMapper;
    @Autowired
    private AdjustResultMapper adjustResultMapper;

    @Override
    public int updateSpecialApplyAndGetResult(SpecialApply specialApply) {
        specialApply.setUpdateTime(DateUtils.getNowDate());
        specialApply.setUpdateUserId(SecurityUtils.getUserId());
        if (specialApply.getApplyStatus().equals("2") && adjustResultMapper.selectAdjustResultByBatchId(specialApply.getStudentId()) == null) {
            AdjustResult adjustResult =
                    AdjustResult.builder()
                            .batchId(specialApply.getYear())
                            .studentId(specialApply.getStudentId())
                            .admitMajorId(specialApply.getMajorId())
                            .specialFlag(1L)
                            .adjustFlag(0L)
                            .collegeId(specialApply.getCollegeId())
                            .year(specialApply.getYear())
                            .build();
            adjustResultMapper.insertAdjustResult(adjustResult);
        }
        return specialApplyMapper.updateSpecialApply(specialApply);
    }
}
