package com.bonus.sgzb.common.core.utils;

import org.apache.commons.lang3.time.DateUtils;

import java.text.*;
import java.time.LocalDate;
import java.time.YearMonth;
import java.time.format.DateTimeFormatter;
import java.time.temporal.ChronoUnit;
import java.time.temporal.TemporalAdjusters;
import java.util.*;

/**
 * 日期工具类
 * @author bns
 */
public class DateTimeHelper {


    public static String format(Date d, String f) {
        SimpleDateFormat df = new SimpleDateFormat(f, Locale.US);
        return df.format(d);
    }

    public static String format(String timeLong, String defaut) {
        try {
            long tmpLong = Long.parseLong(timeLong);
            Date d = new Date(tmpLong);
            DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            String timeStr = formatter.format(d);
            return timeStr;
        } catch (Exception e) {
            return defaut;
        }
    }

    /**
     * 获取当前时间
     *
     * @return
     */
    public static String getNowTime() {
        return format(new Date(), "yyyy-MM-dd HH:mm:ss");
    }

    /**
     * 获取当前时间的年份
     *
     * @return
     */
    public static String getNowYear() {
        return format(new Date(), "yyyy");
    }

    public static String getYear(Date d) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(d);
        int year = calendar.get(Calendar.YEAR);
        return String.valueOf(year);
    }

    /**
     * 获取当前月份
     *
     * @return
     */
    public static String getNowMonths() {
        return format(new Date(), "MM");
    }

    /**
     * 获取当前小时
     *
     * @return
     */
    public static String getNowHours() {
        return format(new Date(), "HH");
    }

    public static String getNowDms() {
        String time = new SimpleDateFormat("yyyyMMddHHmmss").format(new Date());
        return time;
    }

    public static String getNowYmd() {
        String time = new SimpleDateFormat("yyyyMMdd").format(new Date());
        return time;
    }

    public static String getMonth(Date d) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(d);
        int month = calendar.get(Calendar.MONTH) + 1;
        return StringHelper.fillPrefixZero(month, 2);
    }

    public static String getNowDay() {
        String time = new SimpleDateFormat("yyyy-MM-dd").format(new Date());
        return time;
    }

    public static String getNowDayHms() {
        String time = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date());
        return time;
    }

    @SuppressWarnings("static-access")
    public static String getHouDay() {
        Date date = new Date();
        Calendar calendar = new GregorianCalendar();
        calendar.setTime(new Date());
        // 把日期往后增加一天.整数往后推,负数往前移动
        calendar.add(calendar.DATE, 1);
        // 这个时间就是日期往后推一天的结果
        date = calendar.getTime();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        String day = sdf.format(date);
        return day;
    }

    @SuppressWarnings("static-access")
    public static String getYesTodayt() {
        Date date = new Date();
        Calendar calendar = new GregorianCalendar();
        calendar.setTime(new Date());
        // 把日期往后增加一天.整数往后推,负数往前移动
        calendar.add(calendar.DATE, -1);
        // 这个时间就是日期往后推一天的结果
        date = calendar.getTime();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        String day = sdf.format(date);
        return day;
    }

    @SuppressWarnings("static-access")
    public static String getQtDay() {
        Date date = new Date();
        Calendar calendar = new GregorianCalendar();
        calendar.setTime(new Date());
        // 把日期往后增加一天.整数往后推,负数往前移动
        calendar.add(calendar.DATE, -2);
        // 这个时间就是日期往后推一天的结果
        date = calendar.getTime();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        String day = sdf.format(date);
        return day;
    }


    public static String format(String str, String format, String disFormat) {
        Date d = parse(str, format);
        return format(d, disFormat);
    }

    /**
     * 格式化 时间
     *
     * @param format
     * @return
     */
    public static String format(Date d, DateFormat format) {
        return format.format(d);
    }

    /**
     * 格式化 时间
     *
     * @param format
     * @return Date
     * @throws ParseException
     */
    public static Date parse(String dateStr, String format) {
        SimpleDateFormat df = new SimpleDateFormat(format);
        try {
            return df.parse(dateStr);
        } catch (ParseException e) {
            return new Date();
        }
    }

    public static Date parse(String dateStr, String format, Date d) {
        try {
            SimpleDateFormat df = new SimpleDateFormat(format);
            return df.parse(dateStr);
        } catch (Exception e) {
            return d;
        }
    }

    /**
     * 解析时间
     *
     * @return Date
     * @throws ParseException
     */
    public static Date parse(String dateStr, DateFormat format) throws ParseException {
        return format.parse(dateStr);
    }

    /**
     * 获取上月的年月
     *
     * @return
     */
    public static String getPrevMonth() {
        return minusMonth(new Date(), 1);
    }

    /**
     * 获取当前时间的年月
     *
     * @return
     */
    public static String getCurrentMonth() {
        return minusMonth(new Date(), 0);
    }

    /**
     * 获取当前时间的年月
     *
     * @return
     */
    public static String getNowMonth() {
        return format(new Date(), "yyyy-MM");
    }

    /**
     * 获取指定时间的年月
     *
     * @return
     */
    public static String getNowMonth(Date date) {
        return format(date, "yyyy-MM");
    }

    /**
     * 获取当前时间的年月日
     *
     * @return
     */
    public static String getNowDate() {
        return format(new Date(), "yyyy-MM-dd");
    }

    /**
     * @return
     */
    public static String minusMonth(Date date, int c) {
        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM");
        try {
            Calendar cal = Calendar.getInstance();
            cal.setTime(date);
            cal.add(Calendar.MONTH, -c);
            return format(cal.getTime(), df);
        } catch (Exception e) {
            return format(date, df);
        }
    }

    /**
     * @param month
     * @return
     */
    public static String minusMonth(String month, int c) {
        try {
            SimpleDateFormat df = new SimpleDateFormat("yyyy-MM");
            Date date = parse(month, df);

            Calendar cal = Calendar.getInstance();
            cal.setTime(date);
            cal.add(Calendar.MONTH, -c);

            return format(cal.getTime(), df);
        } catch (Exception e) {
            return month;
        }
    }

    /**
     * @return
     */
    public static Date minus(Date d, int type, int c) {
        try {
            Calendar cal = Calendar.getInstance();
            cal.setTime(d);
            cal.add(type, -c);
            return cal.getTime();
        } catch (Exception e) {
            return new Date();
        }
    }

    /**
     * 得到前一个月
     *
     * @param month
     * @return
     */
    public static String prevMonth(String month) {
        return minusMonth(month, 1);
    }

    /**
     * 得到前一个月
     *
     * @param month
     * @return
     */
    public static String prevMonth(String month, int c) {
        return minusMonth(month, c);
    }

    public static float duration(String startTime, String stopTime) {
        Date sd = DateTimeHelper.parse(startTime, "yyyy-MM-dd HH:mm");
        long sl = sd.getTime();

        Date ed = DateTimeHelper.parse(stopTime, "yyyy-MM-dd HH:mm");
        long el = ed.getTime();

        float l = el - sl;
        if (l <= 0) {
            l = 0;
        }
        l = l / (1000 * 60);
        return l;
    }

    public static String getStartYearMonthBySeason(String year, int season) {
        switch (season) {
            case 1:
                return getYearMonth(year, "01");
            case 2:
                return getYearMonth(year, "04");
            case 3:
                return getYearMonth(year, "07");
            case 4:
                return getYearMonth(year, "10");
            default:
                return getYearMonth(year, "01");
        }
    }

    private static String getYearMonth(String year, String month) {
        return year + "-" + month;
    }

    public static String getEndYearMonthBySeason(String year, int season) {
        switch (season) {
            case 1:
                return getYearMonth(year, "03");
            case 2:
                return getYearMonth(year, "06");
            case 3:
                return getYearMonth(year, "09");
            case 4:
                return getYearMonth(year, "12");
            default:
                return getYearMonth(year, "03");
        }
    }

    /**
     * 获取本周的时间段 本周一至本周日
     *
     * @return
     */
    public static String getCurrentWeekTime() {
        String result = "";
        String currentDay = getNowDay();
        //设置时间格式
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        Calendar cal = Calendar.getInstance();
        Date time;
        try {
            time = sdf.parse(currentDay);
            cal.setTime(time);
            //输出要计算日期
            System.out.println("要计算日期为:" + sdf.format(cal.getTime()));

            //判断要计算的日期是否是周日，如果是则减一天计算周六的，否则会出问题，计算到下一周去了
            //获得当前日期是一个星期的第几天
            int dayWeek = cal.get(Calendar.DAY_OF_WEEK);
            if (1 == dayWeek) {
                cal.add(Calendar.DAY_OF_MONTH, -1);
            }

            //设置一个星期的第一天，按中国的习惯一个星期的第一天是星期一
            cal.setFirstDayOfWeek(Calendar.MONDAY);
            //获得当前日期是一个星期的第几天
            int day = cal.get(Calendar.DAY_OF_WEEK);
            //根据日历的规则，给当前日期减去星期几与一个星期第一天的差值
            cal.add(Calendar.DATE, cal.getFirstDayOfWeek() - day);
            System.out.println("所在周一的日期：" + sdf.format(cal.getTime()));
            result += sdf.format(cal.getTime());
            System.out.println(cal.getFirstDayOfWeek() + "-" + day + "+6=" + (cal.getFirstDayOfWeek() - day + 6));

            cal.add(Calendar.DATE, 6);
            result += "," + sdf.format(cal.getTime());
            System.out.println("所在下周日的日期：" + sdf.format(cal.getTime()));
            return result;

        } catch (ParseException e) {
            e.printStackTrace();
        }
        return null;
    }

    /**
     * 获取下周的开始时间和结束时间
     *
     * @return
     */
    public static String getNextWeekTime() {
        Date date = getBeginDayOfWeek();
        String time = format(date, "yyyy-MM-dd");
        Date date2 = getEndDayOfWeek();
        String time2 = format(date2, "yyyy-MM-dd");

        return time + "," + time2;
    }

    public static Date getBeginDayOfWeek() {
        Date date = new Date();
        Calendar cal = Calendar.getInstance();
        cal.setTime(date);
        int dayofweek = cal.get(Calendar.DAY_OF_WEEK);
        cal.add(Calendar.WEEK_OF_MONTH, 1);
        if (dayofweek == 1) {
            dayofweek += 7;
        }
        cal.add(Calendar.DATE, 2 - dayofweek);
        return cal.getTime();
    }

    /**
     * 获取前一周的开始和结束时间
     *
     * @return
     */
    public static String getPrevWeek() {
        Date date = getBeginDayOfPrevWeek();
        String time = format(date, "yyyy-MM-dd");
        Date date2 = getEndDayOfPrevWeek();
        String time2 = format(date2, "yyyy-MM-dd");

        return time + "," + time2;
    }

    /**
     * 获取前一周的开始时间
     */
    public static Date getBeginDayOfPrevWeek() {
        Date date = new Date();
        Calendar cal = Calendar.getInstance();
        cal.setTime(date);
        int dayofweek = cal.get(Calendar.DAY_OF_WEEK);
        cal.add(Calendar.WEEK_OF_MONTH, -1);
        if (dayofweek == 1) {
            dayofweek -= 7;
        }
        cal.add(Calendar.DATE, 2 - dayofweek);
        return cal.getTime();
    }

    public static Date getEndDayOfPrevWeek() {
        Calendar cal = Calendar.getInstance();
        cal.setTime(getBeginDayOfPrevWeek());
        cal.add(Calendar.DAY_OF_WEEK, 6);
        Date weekEndSta = cal.getTime();
        return weekEndSta;
    }

    /**
     * 获取前一天的日期
     *
     * @return
     */
    public static String getFrontDay() {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        Date date = new Date();
        Calendar now = Calendar.getInstance();
        now.setTime(date);
        now.add(Calendar.DAY_OF_MONTH, -1);
        return sdf.format(now.getTime());

    }

    public static Date getEndDayOfWeek() {
        Calendar cal = Calendar.getInstance();
        cal.setTime(getBeginDayOfWeek());
        cal.add(Calendar.DAY_OF_WEEK, 6);
        Date weekEndSta = cal.getTime();
        return weekEndSta;
    }

    /**
     * 获取两个时间之间的所有日期
     *
     * @param startTime
     * @param endTime
     * @return
     */
    public static List<String> getBetweenDate(String startTime, String endTime) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        List<String> list = new ArrayList<>();
        try {
            //转化日期类型
            Date startDate = sdf.parse(startTime);
            Date endDate = sdf.parse(endTime);
            //用calendar 进行日期比较判断
            Calendar calendar = Calendar.getInstance();
            while (startDate.getTime() <= endDate.getTime()) {
                //把日期添加到集合中
                list.add(sdf.format(startDate));
                //设置日期
                calendar.setTime(startDate);

                //把日期加一天
                calendar.add(Calendar.DATE, 1);

                //获取增加后的日期
                startDate = calendar.getTime();
            }

        } catch (ParseException e) {
            e.printStackTrace();
        }
        return list;
    }

    /**
     * @return float
     * @Author ccw
     * @Description 秒换算成小时
     * @Date 14:08 2022/6/24
     * @Param [seconds]
     */
    public static String getHours(int seconds) {
        NumberFormat numberFormat = NumberFormat.getInstance();
        //保留几位小数填写几
        numberFormat.setMaximumFractionDigits(3);
        String hours = numberFormat.format((float) seconds / (float) 3600);
        return hours;
    }

    /**
     * @return int
     * @Author ccw
     * @Description 时间差
     * @Date 14:05 2022/6/24
     * @Param [startTime, endTime]
     */
    public static int getTimeDifference2(String startTime, String endTime) throws ParseException {
        SimpleDateFormat simpleFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date date = simpleFormat.parse(startTime);
        long time = date.getTime();
        Date date2 = simpleFormat.parse(endTime);
        long time2 = date2.getTime();
        long timestamp = time2 - time;
        int seconds = (int) (timestamp / 1000);
        return seconds;
    }

    /**
     * 小时差
     *
     * @param endTime
     * @param startTime
     * @return
     * @throws ParseException
     */
    public static Double getTimeHours(String endTime, String startTime) throws ParseException {
        try {
            SimpleDateFormat simpleFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            Date st = simpleFormat.parse(startTime);
            Date et = simpleFormat.parse(endTime);
            long time = et.getTime() - st.getTime();
            DecimalFormat decimalFormat = new DecimalFormat("0.00");
            String format = decimalFormat.format(time * 1.0 / 3600000 * 1.0);
            return Double.valueOf(format);
        } catch (Exception e) {
            return 0.0;
        }
    }

    /**
     * 分钟差
     *
     * @param endTime
     * @param startTime
     * @return
     * @throws ParseException
     */
    public static Long getTimeMine(String endTime, String startTime) throws ParseException {
        try {
            SimpleDateFormat simpleFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            Date st = simpleFormat.parse(startTime);
            Date et = simpleFormat.parse(endTime);
            long time = et.getTime() - st.getTime();
            long hours = time / 60 / 1000;
            return hours;
        } catch (Exception e) {
            return 0L;
        }
    }

    /**
     * @return java.lang.String
     * @author cw chen
     * @description 获取当前月第一天和最后一天
     * @Param
     * @date 2023-09-01 22:12
     */
    public static Map<String, String> getNowOneMonthDay() {
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
        Map<String, String> map = new HashMap<>(16);

        // 本月起始
        Calendar thisMonthFirstDateCal = Calendar.getInstance();
        thisMonthFirstDateCal.set(Calendar.DAY_OF_MONTH, 1);
        String thisMonthFirstTime = format.format(thisMonthFirstDateCal.getTime());

        // 本月末尾
        Calendar thisMonthEndDateCal = Calendar.getInstance();
        thisMonthEndDateCal.set(Calendar.DAY_OF_MONTH, thisMonthEndDateCal.getActualMaximum(Calendar.DAY_OF_MONTH));
        String thisMonthEndTime = format.format(thisMonthEndDateCal.getTime());

        map.put("beginDate", thisMonthFirstTime);
        map.put("endDate", thisMonthEndTime);
        return map;
    }

    /**
     * @return java.util.List<java.lang.String>
     * @author cw chen
     * @description 近七天/近30天
     * @Param
     * @date 2023-09-01 22:47
     */
    public static List<String> getDateList(int num) {
        List<String> dateList = new ArrayList<>();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        for (int i = 0; i < num; i++) {
            Date date = DateUtils.addDays(new Date(), -i);
            String formatDate = sdf.format(date);
            dateList.add(formatDate);
        }
        return dateList;
    }

    /**
     * @return java.util.List
     * @author cw chen
     * @description 近一年
     * @Param
     * @date 2023-09-01 22:55
     */
    public static List getYearAndMonth() {
        List inventoryDateList = new ArrayList<>();
        LocalDate currentDate = LocalDate.now();
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM");
        String currentYearMonth = currentDate.format(formatter);
        inventoryDateList.add(currentYearMonth);
        for (int i = 0; i < GlobalConstants.INT_11; i++) {
            // 减去一个月
            currentDate = currentDate.minusMonths(1);
            String yearMonth = currentDate.format(formatter);
            inventoryDateList.add(yearMonth);
        }
        return inventoryDateList;
    }


    /**
     * 当前时间三十分钟后
     */
    public static String getTimeAfter() {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date now = new Date();
        System.out.println("当前时间：" + sdf.format(now));
        //30分钟
        int time = 30 * 60 * 1000;
        //30分钟后的时间
        Date afterDate = new Date(now.getTime() + time);
        System.out.println(sdf.format(afterDate));
        return sdf.format(afterDate);
    }

    public static String getTimeAfterThirtyDay() {
        //制定日期格式
        SimpleDateFormat df=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Calendar c=Calendar.getInstance();
        Date date=new Date();
        c.setTime(date);
        //将当前日期加一个月
        c.add(Calendar.MONTH,1);
        //返回String型的时间
        String validityDate=df.format(c.getTime());
        return validityDate;
    }

    /**
     * 获取时间戳
     */
    public static long getTimeStampConverter(String dateStr) {
        // 定义一个日期格式化对象，用于将字符串解析为日期对象
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        try {
            if (Objects.isNull(dateStr)) {
                return 0;
            }
            // 将字符串解析为日期对象
            Date date = sdf.parse(dateStr);
            // 获取日期对象对应的时间戳
            long timeStamp = date.getTime();
            // 打印时间戳
            return timeStamp;
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return 0;
    }

    /**
     * 获取当前月的第一天和最后一天
     */
    public static String getMonthFirstAndLastDay() {
        Calendar a = Calendar.getInstance();
        //把日期设置为当月第一天
        a.set(Calendar.DATE, 1);
        //日期回滚一天，也就是最后一天
        a.roll(Calendar.DATE, -1);
        //当月有多少天
        int maxDate = a.get(Calendar.DATE);
        SimpleDateFormat sdfTwo = new SimpleDateFormat("yyyy-MM-");
        String startTime = sdfTwo.format(new Date()) + "01";
        String endTime = sdfTwo.format(new Date()) + maxDate;
        return startTime + " - " + endTime;
    }

    /**
     * 获取上个月的第一天
     */
    public static String getBeforeFirstMonthDate() throws Exception {
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
        Calendar calendar = Calendar.getInstance();
        calendar.add(Calendar.MONTH, -1);
        calendar.set(Calendar.DAY_OF_MONTH, 1);
        String format1 = format.format(calendar.getTime());
        return format1;
    }

    /**
     * 获取上个月的最后一天
     */
    public static String getBeforeLastMonthDate() throws Exception {
        SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd");
        Calendar calendar = Calendar.getInstance();
        int month = calendar.get(Calendar.MONTH);
        calendar.set(Calendar.MONTH, month - 1);
        calendar.set(Calendar.DAY_OF_MONTH, calendar.getActualMaximum(Calendar.DAY_OF_MONTH));
        String format = sf.format(calendar.getTime());
        return format;
    }


    public static String getFisrtDayOfMonth(int year, int month) {
        Calendar cal = Calendar.getInstance();
        //设置年份
        cal.set(Calendar.YEAR, year);
        //设置月份
        cal.set(Calendar.MONTH, month - 1);
        //获取某月最小天数
        int firstDay = cal.getActualMinimum(Calendar.DAY_OF_MONTH);
        //设置日历中月份的最小天数
        cal.set(Calendar.DAY_OF_MONTH, firstDay);
        //格式化日期
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        String firstDayOfMonth = sdf.format(cal.getTime());
        return firstDayOfMonth;
    }

    public static String getLastDayOfMonth(int year, int month) {
        Calendar cal = Calendar.getInstance();
        //设置年份
        cal.set(Calendar.YEAR, year);
        //设置月份
        cal.set(Calendar.MONTH, month - 1);
        //获取某月最大天数
        int lastDay = cal.getActualMaximum(Calendar.DAY_OF_MONTH);
        //设置日历中月份的最大天数
        cal.set(Calendar.DAY_OF_MONTH, lastDay);
        //格式化日期
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        String lastDayOfMonth = sdf.format(cal.getTime());
        return lastDayOfMonth;
    }

    // 获取上个月的年月
    public static String getLastMonthYearMonth() {
        // 获取当前时间的年月
        YearMonth now = YearMonth.now();

        // 减去一个月
        YearMonth lastMonth = now.minusMonths(1);

        // 将YearMonth对象格式化为字符串
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM");
        return lastMonth.format(formatter);
    }

    public static void main(String[] args) {
        System.err.println(getTimeAfterThirtyDay());
        System.err.println(getNowTime());
    }

    /**
     * @return int
     * @description 获取当前月的天数
     * @author cwchen
     * @date 2023/9/28 17:03
     */
    public static int getDaysOfCurrentMonth() {
        Calendar calendar = Calendar.getInstance();
        return calendar.getActualMaximum(Calendar.DAY_OF_MONTH);
    }

    /**
     * @return String
     * @description 获取昨天的日期
     * @author cwchen
     * @date 2023/11/7 13:20
     */
    public static String getYesterday() {
        // 获取当前日期
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(new Date());
        // 将日期减去一天
        calendar.add(Calendar.DAY_OF_YEAR, -1);
        // 获取昨天的日期
        Date yesterday = calendar.getTime();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        String format = sdf.format(yesterday);
        return format;
    }

    /**
     * @param year
     * @return Long
     * @description 当前日期距离本年第一天的天数
     * @author cwchen
     * @date 2023/11/7 13:50
     */
    public static Long getDays(int year) {
        LocalDate startDate = LocalDate.of(year, 1, 1);
        LocalDate endDate = LocalDate.now();
        long daysDiff = startDate.until(endDate, ChronoUnit.DAYS);
        System.out.println("相差的天数为：" + daysDiff);
        return daysDiff;
    }

    public static String getLastOneMonthDay(int value) {
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
        Map<String, String> map = new HashMap<>(16);
        Calendar lastMonthEndDateCal = Calendar.getInstance();
        lastMonthEndDateCal.add(Calendar.MONTH, value);
        lastMonthEndDateCal.set(Calendar.DAY_OF_MONTH, lastMonthEndDateCal.getActualMaximum(Calendar.DAY_OF_MONTH));
        String lastMonthEndTime = format.format(lastMonthEndDateCal.getTime());
        return lastMonthEndTime;
    }

    public static List<String> getMonthAllDay() {
        List<String> list = new ArrayList<>();
        // 获取当前日期
        LocalDate currentDate = LocalDate.now();
        // 获取本月的第一天
        LocalDate firstDayOfMonth = currentDate.with(TemporalAdjusters.firstDayOfMonth());

        // 获取本月的最后一天
        LocalDate lastDayOfMonth = currentDate.with(TemporalAdjusters.lastDayOfMonth());
        // 遍历获取本月所有日期
        List<LocalDate> allDates = new ArrayList<>();
        for (LocalDate date = firstDayOfMonth; date.isBefore(lastDayOfMonth.plusDays(1)); date = date.plusDays(1)) {
            allDates.add(date);
        }
        // 输出所有日期
        for (LocalDate date : allDates) {
            list.add(date.toString());
        }
        return list;
    }

    /**
     * @param date
     * @param date2
     * @return long
     * @description 获取两个日期间的天数
     * @author cwchen
     * @date 2023/11/19 16:55
     */
    public static long getDayNum(String date, String date2) {
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
        try {
            Date parseDate = format.parse(date);
            Date parseDate2 = format.parse(date2);
            long time = parseDate.getTime();
            long time2 = parseDate2.getTime();
            long time3 = time2 - time;
            return time3 / (24 * 60 * 60 * 1000);
        } catch (ParseException e) {
            return 0;
        }
    }

    public static boolean isExceed(String date, String date2) {
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
        try {
            Date parseDate = format.parse(date);
            Date parseDate2 = format.parse(date2);
            long time = parseDate.getTime();
            long time2 = parseDate2.getTime();
            long time3 = time2 - time;
            return time3 < 0 ? false : true;
        } catch (ParseException e) {
            return false;
        }
    }

    public static List<String> getYearMonth() {
        Calendar calendar = Calendar.getInstance();
        int year = calendar.get(Calendar.YEAR);
        List<String> list = new ArrayList<>();
        for (int i = 1; i < GlobalConstants.INT_13; i++) {
            String month = i + "";
            if (i < 10) {
                month = "0" + i;
            }
            list.add(year + "-" + month);
        }
        return list;
    }

    public static String getPreMonthFirstDay() {
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
        // 获取当前月第一天：
        Calendar c = Calendar.getInstance();
        c.add(Calendar.MONTH, -1);
        c.set(Calendar.DAY_OF_MONTH, 1);// 设置为1号,当前日期既为本月第一天
        String first = format.format(c.getTime());
        return first;
    }

    public static String getCurrentMonthFirstDay() {
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
        // 获取当前月第一天：
        Calendar c = Calendar.getInstance();
        c.add(Calendar.MONTH, 0);
        c.set(Calendar.DAY_OF_MONTH, 1);// 设置为1号,当前日期既为本月第一天
        String first = format.format(c.getTime());
        return first;
    }

    public static String getPreLastDay() {
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
        // 获取当前月最后一天
        Calendar c = Calendar.getInstance();
        c.add(Calendar.MONTH, -1);
        c.set(Calendar.DAY_OF_MONTH, c.getActualMaximum(Calendar.DAY_OF_MONTH));
        String last = format.format(c.getTime());
        return last;
    }

    public static String getPreMonthCalStartDay(int day) {
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
        Calendar c = Calendar.getInstance();
        c.add(Calendar.MONTH, -1);
        c.set(Calendar.DAY_OF_MONTH, day);
        String first = format.format(c.getTime());
        return first;
    }

    public static String getCurrentMonthCalEndDay(int day) {
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
        Calendar c = Calendar.getInstance();
        c.add(Calendar.MONTH, 0);
        c.set(Calendar.DAY_OF_MONTH, day);
        return format.format(c.getTime());
    }
}
