package com.kcim.common.util;

import com.kcim.common.enums.DateStyleEnum;
import org.springframework.util.StringUtils;

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

/**
* @program: performace
* @program:  核算日期工具类
* @author : Wang.YS
* @since : 2023-01-08 21:50
**/

public class ComputeDateUtils {

    /**
     * 获取上一个核算年月
     * @param computeDate 当前核算年月
     * @return 上一个核算年月
     */
    public static String getPreComputeDate(String computeDate){
        if(StringUtils.isEmpty(computeDate)){
            return null;
        }
        Date date = DateUtils.StringToDate(computeDate, DateStyleEnum.YYYY_MM);
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        calendar.add(Calendar.MONTH,-1);
        return DateUtils.getStringFromDate(calendar.getTime(), DateStyleEnum.YYYY_MM.getValue());


    }

    /**
     * 获取下一个核算年月
     * @param computeDate 当前核算年月
     * @return 下一个核算年月
     */
    public static String getLastComputeDate(String computeDate){
        if(StringUtils.isEmpty(computeDate)){
            return null;
        }
        Date date = DateUtils.StringToDate(computeDate, DateStyleEnum.YYYY_MM);
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        calendar.add(Calendar.MONTH,1);
        return DateUtils.getStringFromDate(calendar.getTime(),DateStyleEnum.YYYY_MM.getValue());

    }

//    public static String getComputeYear(String computeDate){
//        if(StringUtils.isEmpty(computeDate)){
//            return null;
//        }
//        Date date = DateUtils.StringToDate(computeDate, DateStyleEnum.YYYY_MM);
//
//        return DateUtils.getStringFromDate(date,DateStyleEnum.YYYY_CN.getValue());
//    }
//
//    public static String getComputeMonth(String computeDate){
//        if(StringUtils.isEmpty(computeDate)){
//            return null;
//        }
//        Date date = DateUtils.StringToDate(computeDate, DateStyleEnum.YYYY_MM);
//        return DateUtils.getStringFromDate(date,DateStyleEnum.MM_CN.getValue());
//    }

    public static Integer getComputeYear(String computeDate){
        if(StringUtils.isEmpty(computeDate)){
            return null;
        }
        Date date = DateUtils.StringToDate(computeDate, DateStyleEnum.YYYY_MM);
        String stringFromDate = DateUtils.getStringFromDate(date, DateStyleEnum.YYYY.getValue());
        return Integer.valueOf(stringFromDate);
    }

    public static Integer getComputeMonth(String computeDate){
        if(StringUtils.isEmpty(computeDate)){
            return null;
        }
        Date date = DateUtils.StringToDate(computeDate, DateStyleEnum.YYYY_MM);
        String stringFromDate = DateUtils.getStringFromDate(date, DateStyleEnum.MM.getValue());
        return Integer.valueOf(stringFromDate);

    }

    /**
     * 获取上一年核算年月
     * @param computeDate 当前核算年月
     * @return 上一个核算年月
     */
    public static String getPreComputeDateYear(String computeDate){
        if(StringUtils.isEmpty(computeDate)){
            return null;
        }
        Date date = DateUtils.StringToDate(computeDate, DateStyleEnum.YYYY_MM);
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        calendar.add(Calendar.YEAR,-1);
        return DateUtils.getStringFromDate(calendar.getTime(), DateStyleEnum.YYYY_MM.getValue());


    }

}
