package com.ruoyi.common.utils;

import java.util.Calendar;
import java.util.Date;

//年级与学年计算
public class GradeYearUtils {

    /** 根据当前年的实际学年及学生的年级得到学生的学年
     *  当前学年为2021，高一，则得到的时间为2021-1+1 =2021（学生填写的学年应为2021才正确）
     *  当前学年为2021，高二，则得到的时间为2021-2+1 =2020（学生填写的学年应为2020才正确）
     */
    public static int getRealYear(int currentYear,int grade){
        int gradeValue = 0;
        if(grade==500||grade==200||grade==110){
            gradeValue = 1 ;//高一、初一、小学一年级
        }else if(grade==600||grade==300||grade==120){
            gradeValue = 2 ;//高二、初二、小学二年级
        }else if(grade==700||grade==400||grade==130){
            gradeValue = 3 ;//高一、初三、小学三年级
        }else if(grade==140){
            gradeValue = 4 ;//小学四年级
        }else if(grade==150){
            gradeValue = 5 ;//小学五年级
        }else if(grade==160){
            gradeValue = 6 ;//小学六年级
        }
        currentYear = currentYear-gradeValue+1 ;
        return currentYear;
    }

    /**
     * 根据年级，当前年获取卡过期日期
     * @param currentYear
     * @param grade
     * @return
     */
    public static Date getCardOutDate(int currentYear,int grade){
        int outYear = getRealYear(currentYear,grade);
        return getCardOutDate(outYear);
    }

    /**
     * 根据学年获取过期日期
     * @param outYear
     * @return
     */
    public static Date getCardOutDate(int outYear){
        return DateUtils.dateTime("yyyy-MM-dd",(outYear+3)+"-08-31");
    }

    public static void main(String[] args) {
        System.out.println(getRealYear(2021,500));
        System.out.println(getRealYear(2021,600));

        System.out.println(getRealYear(2022,500));
        System.out.println(getRealYear(2022,600));
        System.out.println(getRealYear(2022,700));
        System.out.println("=====================================");

        System.out.println(getCardOutDate(2023,700));
        System.out.println(getCardOutDate(2023));
        System.out.println(Calendar.getInstance().get(Calendar.YEAR));

        System.out.println(getCardOutDate(400));

    }

}
