package com.sckw.excel.utils;


import cn.hutool.core.date.DateField;
import cn.hutool.core.date.DateTime;
import com.sckw.core.exception.BusinessException;
import com.sckw.core.model.constant.Global;
import com.sckw.core.utils.StringUtils;
import org.springframework.util.Assert;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.*;
import java.time.format.DateTimeFormatter;
import java.util.*;

/**
 * @description: 时间工具类
 * @author: LengFaQiang
 * @copyright
 * @create: 2022-01-27 16:04
 **/
public class DateUtil {
    public static final String DEFAULT_DATE_PATTERN = "yyyy-MM-dd HH:mm:ss";
    public static final String DEF_DATE_FORMAT = "yyyy-MM-dd";
    public static final DateTimeFormatter YYYY_MM_DD_HH_MM_SS = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
    public static final DateTimeFormatter YYYYMMDDHHMMSS = DateTimeFormatter.ofPattern("yyyyMMddHHmmss");
    public static final DateTimeFormatter YYYY_MM_DD = DateTimeFormatter.ofPattern("yyyy-MM-dd");
    public static final DateTimeFormatter HH_MM_SS = DateTimeFormatter.ofPattern("HH:mm:ss");

    public DateUtil() {
    }

    /**
     * 获取当前时间
     *
     * @return
     */
    public static long getSystemTimeMillis() {
        Clock clock = Clock.systemDefaultZone();
        return clock.millis();
    }

    public static String getDateTime(String pattern) {
        if (StringUtils.isEmpty(pattern)) {
            pattern = "yyyy-MM-dd HH:mm:ss";
        }

        return LocalDateTime.now().format(DateTimeFormatter.ofPattern(pattern));
    }

    /**
     * 2023-07-14T09:43:40.511+00:00 -> 2023-07-14 09:13:40
     *
     * @param date
     * @return
     */
    public static String getDateTime(Date date) {
        if (date == null) {
            return null;
        }
        Instant instant = date.toInstant();
        ZoneId zoneId = ZoneId.systemDefault();
        LocalDateTime localDateTime = instant.atZone(zoneId).toLocalDateTime();
        return localDateTime.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
    }

    /**
     * data
     *
     * @param date Date 时间
     * @return
     * @throws ParseException
     */
    public static String dateTimeFormatter(Date date) {
        String format = new SimpleDateFormat(DEFAULT_DATE_PATTERN).format(date);
        return format;
    }

    public static LocalDateTime localDateToLocalDateTimeEnd(LocalDate date) {
        String str = dateToStr(date, "yyyy-MM-dd") + " 23:59:59";
//        LocalDate localDate = parseLocalDate(str);
        LocalDateTime localDateTime = LocalDateTime.parse(str, YYYY_MM_DD_HH_MM_SS);
        return localDateTime;
    }

    public static LocalDateTime localDateToLocalDateTimeStart(LocalDate date) {
        String str = dateToStr(date, "yyyy-MM-dd") + " 00:00:00";
//        LocalDate localDate = parseLocalDate(str);
        LocalDateTime localDateTime = LocalDateTime.parse(str, YYYY_MM_DD_HH_MM_SS);
        return localDateTime;
    }


    public static String dateToStr(LocalDate date) {
        return dateToStr(date, "yyyy-MM-dd");
    }

    public static String dateToStr(LocalDate date, String pattern) {
        String dateStr = date.format(DateTimeFormatter.ofPattern(pattern));
        return dateStr;
    }

    public static String timeToStr(LocalDateTime date) {
        return timeToStr(date, "yyyy-MM-dd HH:mm:ss");
    }

    public static String timeToStr(LocalDateTime date, String pattern) {
        String dateStr = date.format(DateTimeFormatter.ofPattern(pattern));
        return dateStr;
    }

    public static LocalDateTime strToTime(String str) {
        return LocalDateTime.parse(str, DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
    }

    /**
     * yyyy-MM-dd 转换成 LocalDate
     *
     * @param str
     * @return
     */
    public static LocalDate strToDate(String str) {
        return LocalDate.parse(str, DateTimeFormatter.ofPattern("yyyy-MM-dd"));
    }


    public static String localDateTimeToString(LocalDateTime localDateTime) {
        String localDateTimeNowStr = localDateTime.format(YYYYMMDDHHMMSS);
        return localDateTimeNowStr;
    }


    /**
     * yyyy-MM-dd 转换成 LocalDateTime-添加00:00:00
     *
     * @param str
     * @return
     */
    public static LocalDateTime strToLocalDateTime(String str) {
        LocalDate localDate = LocalDate.parse(str, DateTimeFormatter.ofPattern("yyyy-MM-dd"));
        LocalDateTime localDateTime = localDate.atStartOfDay();
        String format = localDateTime.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
        LocalDateTime parse = LocalDateTime.parse(format, DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
        return parse;
    }

    /**
     * yyyyMMdd 转换成 LocalDate
     *
     * @param str
     * @return
     */
    public static LocalDate stringToDate(String str) {
        return LocalDate.parse(str, DateTimeFormatter.ofPattern("yyyyMMdd"));
    }

    /**
     * yyyyMMdd 转换成 LocalDate
     *
     * @param str
     * @return
     */
    public static LocalDate strToDateTime(String str) {
        return LocalDate.parse(str, DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
    }

    /**
     * yyyy-MM-dd HH:mm:ss 转换成 Date
     *
     * @param str
     * @return
     */
    public static Date strDateTimeToDateTime(String str) {
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat(DEFAULT_DATE_PATTERN);
        Date parse = null;
        try {
            parse = simpleDateFormat.parse(str);
        } catch (ParseException e) {
            throw new RuntimeException(e);
        }
        return parse;
    }


    /**
     * 上个月
     *
     * @return 上个月
     */
    public static DateTime lastMonth(int offset) {
        return offsetMonth(new DateTime(), -offset);
    }

    /**
     * 偏移月
     *
     * @param date   日期
     * @param offset 偏移月数，正数向未来偏移，负数向历史偏移
     * @return 偏移后的日期
     */
    public static DateTime offsetMonth(Date date, int offset) {
        return offset(date, DateField.MONTH, offset);
    }

    /**
     * 获取指定日期偏移指定时间后的时间，生成的偏移日期不影响原日期
     *
     * @param date      基准日期
     * @param dateField 偏移的粒度大小（小时、天、月等）{@link DateField}
     * @param offset    偏移量，正数为向后偏移，负数为向前偏移
     * @return 偏移后的日期
     */
    public static DateTime offset(Date date, DateField dateField, int offset) {
        return dateNew(date).offset(dateField, offset);
    }

    /**
     * 根据已有{@link Date} 产生新的{@link DateTime}对象
     *
     * @param date Date对象，如果传入{@code null}，返回{@code null}
     * @return {@link DateTime}对象
     * @since 4.3.1
     */
    public static DateTime dateNew(Date date) {
        if (date == null) {
            return null;
        }
        return new DateTime(date);
    }

    /**
     * @param time yyyy-MM-dd
     * @return String yyyy-MM-dd HH:mm:ss
     * @throws RuntimeException
     */
    public static String fillStart(String time) {
        formatCheck(time);
        return time + " 00:00:00";
    }

    @SuppressWarnings("all")
    private static void formatCheck(String time) {
        try {
            LocalDate.parse(time, YYYY_MM_DD);
        } catch (Exception e) {
            throw new BusinessException("时间格式化错误!");
        }
    }


    /**
     * 获取上周和上上周的开始时间和结束时间
     *
     * @return
     */
    private static Map<String, String> getLastWeekTime() {
        cn.hutool.core.date.Week week = DateTime.now().dayOfWeekEnum();
        switch (week) {
            /** 周一 */
            case MONDAY:
                return getRealizeLastWeekTime(-14, -8, -7, -1);
            /** 周二 */
            case TUESDAY:
                return getRealizeLastWeekTime(-15, -9, -8, -2);
            /** 周三 */
            case WEDNESDAY:
                return getRealizeLastWeekTime(-16, -10, -9, -3);
            /** 周四 */
            case THURSDAY:
                return getRealizeLastWeekTime(-17, -11, -10, -4);
            /** 周五 */
            case FRIDAY:
                return getRealizeLastWeekTime(-18, -12, -11, -5);
            /** 周六 */
            case SATURDAY:
                return getRealizeLastWeekTime(-19, -13, -12, -6);
            /** 周日 */
            case SUNDAY:
                return getRealizeLastWeekTime(-20, -14, -13, -7);
            default:
                throw new RuntimeException("method：getLastWeekTime，获取当前时间是周几异常");
        }
    }


    private static Map<String, String> getRealizeLastWeekTime(int upLastStartOffset, int upLastEndOffset, int lastStartOffset, int lastEndOffset) {
        // 获取上上周的开始时间和结束时间
        String startUpLastWeekTime = DateTime.now().offset(DateField.DAY_OF_YEAR, upLastStartOffset)
                .setField(DateField.HOUR_OF_DAY, 0).setField(DateField.MINUTE, 0)
                .setField(DateField.SECOND, 0).setField(DateField.MILLISECOND, 0).toString();
        String endUpLastWeekTime = DateTime.now().offset(DateField.DAY_OF_YEAR, upLastEndOffset)
                .setField(DateField.HOUR_OF_DAY, 23).setField(DateField.MINUTE, 59)
                .setField(DateField.SECOND, 59).setField(DateField.MILLISECOND, 0).toString();
        // 获取上周的开始时间和结束时间
        String startLastWeekTime = DateTime.now().offset(DateField.DAY_OF_YEAR, lastStartOffset)
                .setField(DateField.HOUR_OF_DAY, 0).setField(DateField.MINUTE, 0)
                .setField(DateField.SECOND, 0).setField(DateField.MILLISECOND, 0).toString();
        String endLastWeekTime = DateTime.now().offset(DateField.DAY_OF_YEAR, lastEndOffset)
                .setField(DateField.HOUR_OF_DAY, 23).setField(DateField.MINUTE, 59)
                .setField(DateField.SECOND, 59).setField(DateField.MILLISECOND, 0).toString();
        Map<String, String> maps = new HashMap<>(Global.NUMERICAL_SIXTEEN);
        maps.put("startUpLastWeekTime", startUpLastWeekTime);
        maps.put("endUpLastWeekTime", endUpLastWeekTime);
        maps.put("startLastWeekTime", startLastWeekTime);
        maps.put("endLastWeekTime", endLastWeekTime);
        return maps;
    }

    /**
     * yyyy-MM-dd 转换成 Date
     *
     * @param str
     * @return
     */
    public static Date stringToDateTime(String str) {
        SimpleDateFormat simpleDateFormat1 = new SimpleDateFormat(DEFAULT_DATE_PATTERN);
        Date date = null;
        try {
            date = simpleDateFormat1.parse(str);
        } catch (ParseException e) {
            throw new RuntimeException(e);
        }
        return date;
    }

    /**
     * yyyy-MM-dd 转换成 Date
     *
     * @param str
     * @return
     */
    public static Date stringPatchingStartToDateTime(String str) {
        str = str + " 00:00:00";
        SimpleDateFormat simpleDateFormat1 = new SimpleDateFormat(DEFAULT_DATE_PATTERN);
        Date date = null;
        try {
            date = simpleDateFormat1.parse(str);
        } catch (ParseException e) {
            throw new RuntimeException(e);
        }
        return date;
    }

    /**
     * yyyy-MM-dd 转换成 Date
     *
     * @param str
     * @return
     */
    public static Date stringPatchingEndToDateTime(String str) {
        str = str + " 23:59:59";
        SimpleDateFormat simpleDateFormat1 = new SimpleDateFormat(DEFAULT_DATE_PATTERN);
        Date date = null;
        try {
            date = simpleDateFormat1.parse(str);
        } catch (ParseException e) {
            throw new RuntimeException(e);
        }
        return date;
    }


    /**
     * 日期字符串转换为LocalDateTime方法
     *
     * @param dateString 日期字符串，格式：yyyyMMdd
     * @return
     */
    public static LocalDateTime handleDateTimeString(String dateString) {
        //日期字符串的长度
        Integer dateLength = 10;
        if (org.apache.commons.lang3.StringUtils.isNotBlank(dateString) && dateString.length() == dateLength) {
            StringBuilder sb = new StringBuilder(dateString);
            return LocalDateTime.parse(sb.toString() + "T00:00:00");
        }
        return null;
    }

    /**
     * 日期字符串转换为LocalDateTime方法
     *
     * @param dateString 日期字符串，格式：yyyyMMdd
     * @return
     */
    public static LocalDateTime handleDateString(String dateString) {
        //日期字符串的长度
        Integer dateLength = 8;
        if (org.apache.commons.lang3.StringUtils.isNotBlank(dateString) && dateString.length() == dateLength) {
            StringBuilder sb = new StringBuilder(dateString);
            sb.insert(4, "-");
            sb.insert(7, "-");
            return LocalDateTime.parse(sb.toString() + "T00:00:00");
        }
        return null;
    }

    /**
     * 日期字符串转换为LocalDateTime方法-添加00:00:00
     *
     * @param dateString 日期字符串，格式：yyyy-MM-dd
     * @return
     */
    public static LocalDateTime strToLocalDateTimeStart(String dateString) {
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
        LocalDateTime localDateTime = LocalDate.parse(dateString, formatter).atStartOfDay();
//        LocalDateTime localDateTime1 = strToLocalDateTime(dateString);
        return localDateTime;
    }


    /**
     * 日期字符串转换为LocalDateTime方法-添加00:00:00
     *
     * @param dateString 日期字符串，格式：yyyy-MM-dd
     * @return
     */
    public static LocalDateTime strToLocalDateTimeEnd(String dateString) {
        String timeString = " 23:59:59";
        String dateTimeString = timeString + timeString;
        DateTimeFormatter formatter1 = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        LocalDateTime localDateTime = LocalDateTime.now();
        try {
            localDateTime = LocalDateTime.parse(dateTimeString, formatter1);
            return localDateTime;
        } catch (java.time.format.DateTimeParseException e) {
            throw new RuntimeException("Invalid date strToLocalDateTimeEnd error" + e.getMessage());
        }
    }


    public static String date() {
        return LocalDate.now().format(YYYY_MM_DD);
    }

    public static int year() {
        return LocalDate.now().getYear();
    }

    public static int month() {
        return LocalDate.now().getMonthValue();
    }

    public static int dayOfMonth() {
        return LocalDate.now().getDayOfMonth();
    }

    public static int dayOfYear() {
        return LocalDate.now().getDayOfYear();
    }

    public static int dayOfWeek() {
        return LocalDate.now().getDayOfWeek().getValue();
    }

    public static String newDate(int year, int month, int day) {
        return LocalDate.of(year, month, day).toString();
    }

    public static String newDate(int year, int dayNum) {
        return LocalDate.ofYearDay(year, dayNum).toString();
    }

    public static String time() {
        return LocalTime.now().format(HH_MM_SS);
    }

    public static int hour() {
        return LocalTime.now().getHour();
    }

    public static int minute() {
        return LocalTime.now().getMinute();
    }

    public static int second() {
        return LocalTime.now().getSecond();
    }

    public static String dateTime() {
        return LocalDateTime.now().format(YYYY_MM_DD_HH_MM_SS);
    }

    public static LocalDateTime parseDateTime(long time) {
        return LocalDateTime.ofInstant(Instant.ofEpochMilli(time), ZoneId.systemDefault());
    }

    public static LocalDateTime parseDateTime(String time) {
        return LocalDateTime.parse(time, YYYY_MM_DD_HH_MM_SS);
    }

    public static LocalDate parseLocalDate(String time) {
        return LocalDate.parse(time, YYYY_MM_DD_HH_MM_SS);
    }


    public static LocalDate parseDate(long time) {
        return LocalDate.from(parseDateTime(time));
    }

    public static LocalDate parseDate(String time) {
        return LocalDate.parse(time, YYYY_MM_DD);
    }

    public static String format(LocalDate date) {
        return date.format(YYYY_MM_DD);
    }

    public static String format(LocalDateTime dateTime) {
        return dateTime.format(YYYY_MM_DD_HH_MM_SS);
    }

    public static long millis(LocalDate date) {
        return millis(date.atStartOfDay());
    }

    public static long millis(LocalDateTime dateTime) {
        return dateTime.atZone(ZoneId.systemDefault()).toInstant().toEpochMilli();
    }

    public static String getDateString(Date date, String pattern) {
        Instant instant = date.toInstant();
        ZoneId zoneId = ZoneId.systemDefault();
        LocalDateTime localDateTime = instant.atZone(zoneId).toLocalDateTime();
        return localDateTime.format(DateTimeFormatter.ofPattern(pattern));
    }

    public static long getBetweenDays(Date startDate, Date endDate) {
        return betweenDate(startDate, endDate).toDays();
    }

    public static long getBetweenHours(Date startDate, Date endDate) {
        return betweenDate(startDate, endDate).toHours();
    }

    public static long getBetweenMinutes(Date startDate, Date endDate) {
        return betweenDate(startDate, endDate).toMinutes();
    }

    private static Duration betweenDate(Date startDate, Date endDate) {
        ZoneId zoneId = ZoneId.systemDefault();
        Instant startDateInstant = startDate.toInstant();
        LocalDateTime startDateLocalDateTime = startDateInstant.atZone(zoneId).toLocalDateTime();
        Instant endDateInstant = endDate.toInstant();
        LocalDateTime endDateLocalDateTime = endDateInstant.atZone(zoneId).toLocalDateTime();
        return Duration.between(startDateLocalDateTime, endDateLocalDateTime);
    }

    /**
     * 自定义 字符串转date
     *
     * @param dateStr
     * @param pattern
     * @return
     * @throws ParseException
     */
    public static Date strToDate(String dateStr, String pattern) throws ParseException {
        SimpleDateFormat dateFormat = new SimpleDateFormat();
        if (pattern != null && !pattern.isEmpty()) {
            dateFormat.applyPattern(pattern);
        }

        Date date = dateFormat.parse(dateStr);
        return date;
    }

    public static void main(String[] args) throws ParseException {
//        String lastTwoMonthDate = getLastTwoMonthDateStart();
//        String lastTwoMonthDateEnd = getLastTwoMonthDateEnd();
//        String s = "2023-12-12";
//        Date date = DateUtil.stringPatchingStartToDateTime(s);
//        Date date1 = DateUtil.stringPatchingEndToDateTime(s);
//        System.out.println(date);
//        System.out.println(date1);
//        String lastWeekDateStart = getLastWeekDateStart();
//        String lastWeekDateEnd = getLastWeekDateEnd();
//        System.out.println(lastWeekDateStart);
//        System.out.println(lastWeekDateEnd);
//        String beforeWeekDate = DateUtil.getBeforeWeekDate(6) + " 00:00:00";
//        String beforeWeekDate1 = DateUtil.getBeforeWeekDate(7) + " 23:59:59";
//        ;
//        System.out.println(beforeWeekDate);
//        System.out.println(beforeWeekDate1);
//        DateTime dateTime = lastMonth();
//        System.out.println(dateTime);

//        // 获取当前日期
//        LocalDate currentDate = LocalDate.now();
//        // 计算一年前的日期
//        LocalDate oneYearAgo = currentDate.minusYears(1);
//        LocalDateTime localDateTime = oneYearAgo.atStartOfDay();
//        System.out.println(localDateTime);
//        LocalDateTime beforeWeekDateEnd = getBeforeWeekDateEnd(6);
//        System.out.println(beforeWeekDateEnd);
//        String format = LocalDateTime.now().format(DateTimeFormatter.ofPattern(DEFAULT_DATE_PATTERN));
//        System.out.println(format);
//        DateTimeFormatter formatter = DateTimeFormatter.ofPattern(DEFAULT_DATE_PATTERN);
//        LocalDateTime parse = LocalDateTime.parse(format, formatter);
//        System.out.println(parse);
//        LocalDateTime lastWeekDateStart = getLastWeekDateStart(6);
//        System.out.println(lastWeekDateStart);
//        LocalDateTime lastWeekDateEnd = getLastWeekDateEnd(6);
//        System.out.println(lastWeekDateEnd);


//        //本月
//        //开始时间
//
//        String weekDateStart = getBeforeMonthDateAndDaysStartToString(1, -1);
//        System.out.println(weekDateStart);
//        //结束时间
//        String weekDateEnd = getLastWeekDateEndToString(0);
//        System.out.println(weekDateEnd);
//        //环比本月
//        //开始时间
//        String beforeMonthDateAndDaysEndToString = getBeforeMonthDateAndDaysStartToString(2, -1);
//        System.out.println(beforeMonthDateAndDaysEndToString);
//        //结束时间
//        String beforeMonthDateAndDaysEndToString1 = getBeforeMonthDateAndDaysEndToString(1, 0);
//        System.out.println(beforeMonthDateAndDaysEndToString1);
        String SS = cn.hutool.core.date.DateUtil.format(LocalDateTime.now(), "yyyy-MM-dd") + " 00:00:00";
        //月
        //开始时间
        String monthDateStart = DateUtil.getBeforeMonthDateAndDaysStartToString(LocalDateTime.now(), 1, -1);
        //结束时间
        String monthDateEnd = DateUtil.getLastWeekDateEndToString(0);
        //环比上月
        //开始时间
        String lastMonthDateStart = DateUtil.getBeforeMonthDateAndDaysStartToString(LocalDateTime.now(), 2, -1);
        //结束时间
        String lastMonthDateEnd = DateUtil.getBeforeMonthDateAndDaysEndToString(LocalDateTime.now(), 1, 0);

    }

    public static int getCurrentMonthDays() {
        Calendar calendar = Calendar.getInstance();
        calendar.set(5, 1);
        calendar.roll(5, -1);
        int days = calendar.get(5);
        return days;
    }

    public static int getMonthDays(int year, int month) {
        Calendar calendar = Calendar.getInstance();
        calendar.set(1, year);
        calendar.set(2, month - 1);
        calendar.set(5, 1);
        calendar.roll(5, -1);
        int days = calendar.get(5);
        return days;
    }

    public static Date subtractionOneDay(Date date) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        calendar.add(5, -1);
        Date startDate = calendar.getTime();
        return startDate;
    }

    public static Date getDay(int offset, Date date) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        calendar.add(5, offset);
        return calendar.getTime();
    }

    public static Date getDelay(int offset, Date date) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        calendar.add(1, offset);
        return calendar.getTime();
    }

    public static Date offsetDay(Date date, int offset) {
        Calendar calendar = new GregorianCalendar();
        calendar.setTime(date);
        calendar.add(Calendar.DATE, offset);
        return calendar.getTime();
    }

    public static String getWeekOfDate(Date date, Lanagues language) {
        String name = "";
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        int weekIndex = calendar.get(7) - 1;
        if (weekIndex < 0) {
            weekIndex = 0;
        }

        switch (language) {
            case CHINESE:
                name = Week.getName(weekIndex);
                break;
            case ENGLISH:
                name = Week.getEnName(weekIndex);
        }

        return name;
    }

    public static Date LocalDateTimeToDate(LocalDateTime localDateTime) {
        return Date.from(localDateTime.atZone(ZoneId.systemDefault()).toInstant());
    }

    public static enum Week {
        SUNDAY("星期日", "Sunday", 0),
        MONDAY("星期一", "Monday", 1),
        TUESDAY("星期二", "Tuesday", 2),
        WEDNESDAY("星期三", "Sunday", 3),
        THURSDAY("星期四", "Thursday", 4),
        FRIDAY("星期五", "Friday ", 5),
        SATURDAY("星期六", "Saturday", 6);

        private String name;
        private String enName;
        private int index;

        public static String getName(int index) {
            String name = null;
            Week[] var2 = values();
            int var3 = var2.length;

            for (int var4 = 0; var4 < var3; ++var4) {
                Week week = var2[var4];
                if (week.getIndex() == index) {
                    name = week.getName();
                }
            }

            return name;
        }

        public static String getEnName(int index) {
            String name = null;
            Week[] var2 = values();
            int var3 = var2.length;

            for (int var4 = 0; var4 < var3; ++var4) {
                Week week = var2[var4];
                if (week.getIndex() == index) {
                    name = week.getEnName();
                }
            }

            return name;
        }

        public String getName() {
            return this.name;
        }

        public void setName(String name) {
            this.name = name;
        }

        public String getEnName() {
            return this.enName;
        }

        public void setEnName(String enName) {
            this.enName = enName;
        }

        public int getIndex() {
            return this.index;
        }

        public void setIndex(int index) {
            this.index = index;
        }

        private Week(String name, String enName, int index) {
            this.name = name;
            this.enName = enName;
            this.index = index;
        }

        @Override
        public String toString() {
            return "Week [name=" + this.name + ", enName=" + this.enName + ", index=" + this.index + "]";
        }
    }

    public static enum Lanagues {
        CHINESE,
        ENGLISH;

        private Lanagues() {
        }
    }

    /**
     * 当前时间的前一个星期
     *
     * @return
     */
    public static String getLastWeekDate() {
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Calendar c = Calendar.getInstance();
        c.add(Calendar.DAY_OF_MONTH, -6);
        String start = format.format(c.getTime());
        System.out.println(start);
        return start;
    }

    /**
     * 当前时间的前一个星期[传递6即为一周]
     *
     * @return 2023-09-12 00:00:00
     */
    public static LocalDateTime getLastWeekDateStart(long amount) {
//        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
//        Calendar c = Calendar.getInstance();
//        c.add(Calendar.DAY_OF_MONTH, -6);
//        String start = format.format(c.getTime()) + " 00:00:00";
//        DateTimeFormatter formatter = DateTimeFormatter.ofPattern(DEFAULT_DATE_PATTERN);
//        LocalDateTime localDateTime = LocalDateTime.parse(start, formatter);
        LocalDateTime localDateTime = LocalDate.now().minusDays(amount).atStartOfDay();
        return localDateTime;
    }

    /**
     * 当前时间的前一个星期[传递6即为一周]
     *
     * @return 2023-09-12 00:00:00
     */
    public static String getLastWeekDateStartToString(LocalDate localDate, long amount) {
//        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
//        Calendar c = Calendar.getInstance();
//        c.add(Calendar.DAY_OF_MONTH, -6);
//        String start = format.format(c.getTime()) + " 00:00:00";
//        DateTimeFormatter formatter = DateTimeFormatter.ofPattern(DEFAULT_DATE_PATTERN);
//        LocalDateTime localDateTime = LocalDateTime.parse(start, formatter);
        LocalDateTime localDateTime = localDate.minusDays(amount).atStartOfDay();
        String format = localDateTime.format(YYYY_MM_DD_HH_MM_SS);
        return format;
    }


    /**
     * 当前时间的前一个星期 [传递6即为一周]
     *
     * @return 2023-09-12 23:59:59
     */
    public static LocalDateTime getLastWeekDateEnd(int amount) {
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
        Calendar c = Calendar.getInstance();
        c.add(Calendar.DAY_OF_MONTH, -amount);
        String start = format.format(c.getTime()) + " 23:59:59";
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern(DEFAULT_DATE_PATTERN);
        LocalDateTime parse = LocalDateTime.parse(start, formatter);
        return parse;
    }

    /**
     * 当前时间的前一个星期 [传递6即为一周]
     *
     * @return 2023-09-12 23:59:59
     */
    public static String getLastWeekDateEndToString(int amount) {
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
        Calendar c = Calendar.getInstance();
        c.add(Calendar.DAY_OF_MONTH, -amount);
        String start = format.format(c.getTime()) + " 23:59:59";
        return start;
    }

    /**
     * 当前时间的前一个星期
     *
     * @return
     */
    public static String getLastDateStart(Integer type) {
        Assert.notNull(type, "获取上周/月结束时间，日期类型参数缺失");
        int days = Objects.equals(type, 1) ? 6 : 29;
        String start = LocalDate.now().atStartOfDay().minusDays(days).format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
        return start;
    }


    /**
     * 获取当前日期之前的时间
     *
     * @param amount 往前推多久时间[天为单位]
     * @return
     */
    public static String getBeforeWeekDate(int amount) {
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
        Calendar c = Calendar.getInstance();
        c.add(Calendar.DAY_OF_MONTH, -amount);
        String start = format.format(c.getTime());
        return start;
    }

    /**
     * 获取当前日期之前的时间
     *
     * @param amount 往前推多久时间[天为单位]
     * @return
     */
    public static String getBeforeWeekDateStart(int amount) {
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
        Calendar c = Calendar.getInstance();
        c.add(Calendar.DAY_OF_MONTH, -amount);
        String start = format.format(c.getTime()) + " 00:00:00";
        return start;
    }

    /**
     * 获取当前日期之前的时间
     *
     * @param amount 往前推多久时间[天为单位]
     * @return
     */
    public static LocalDateTime getBeforeWeekDateEnd(int amount) {
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
        Calendar c = Calendar.getInstance();
        c.add(Calendar.DAY_OF_MONTH, -amount);
        String start = format.format(c.getTime()) + " 23:59:59";
        LocalDateTime parse = LocalDateTime.parse(start);
        return parse;
    }


    /**
     * 当天日期前一个月
     *
     * @return
     */
    public static String getLastMonthDate() {
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Calendar c = Calendar.getInstance();
        c.add(Calendar.MONTH, -1);
        String start = format.format(c.getTime());
        System.out.println(start);
        return start;
    }


    /**
     * 当天日期前一个月
     *
     * @return 2023-09-06 00:00:00
     */
    public static String getLastMonthDateStart() {
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
        Calendar c = Calendar.getInstance();
        c.add(Calendar.MONTH, -1);
        String start = format.format(c.getTime()) + " 00:00:00";
        System.out.println(start);
        return start;
    }

    /**
     * 当天日期前一个月
     *
     * @return 2023-09-06 23:59:59
     */
    public static String getLastMonthDateEnd() {
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
        Calendar c = Calendar.getInstance();
        c.add(Calendar.MONTH, -1);
        String start = format.format(c.getTime()) + " 23:59:59";
        return start;
    }


    /**
     * 获取当前日期之前的时间
     *
     * @param amount 往前推多久时间[月为单位]
     * @return
     */
    public static String getBeforeMonthDate(int amount) {
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
        Calendar c = Calendar.getInstance();
        c.add(Calendar.MONTH, -amount);
        String start = format.format(c.getTime());
        return start;
    }

    /**
     * 获取当前日期之前的时间
     *
     * @param amount 往前推多久时间[月为单位]
     * @return 2023-09-13 00:00:00
     */
    public static LocalDateTime getBeforeMonthDateStart(int amount) {
        LocalDateTime localDateTime = LocalDateTime.now().minusMonths(amount);
        String start = localDateTime.format(DateTimeFormatter.ofPattern(DEF_DATE_FORMAT)) + " 00:00:00";
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern(DEFAULT_DATE_PATTERN);
        LocalDateTime returnLocalDateTime = LocalDateTime.parse(start, formatter);
        return returnLocalDateTime;
    }

    /**
     * 获取当前日期之前的时间
     *
     * @param amount 往前推多久时间[月为单位]
     * @return 2023-09-13 00:00:00
     */
    public static LocalDateTime getBeforeMonthDateAndDaysStart(int amount, long days) {
        LocalDateTime localDateTime = LocalDateTime.now().minusMonths(amount).minusDays(days);
        String start = localDateTime.format(DateTimeFormatter.ofPattern(DEF_DATE_FORMAT)) + " 00:00:00";
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern(DEFAULT_DATE_PATTERN);
        LocalDateTime returnLocalDateTime = LocalDateTime.parse(start, formatter);
        return returnLocalDateTime;
    }

    /**
     * 获取当前日期之前的时间
     *
     * @param amount 往前推多久时间[月为单位]
     * @return 2023-09-13 00:00:00
     */
    public static String getBeforeMonthDateStartToString(int amount) {
        LocalDateTime localDateTime = LocalDateTime.now().minusMonths(amount);
        String start = localDateTime.format(DateTimeFormatter.ofPattern(DEF_DATE_FORMAT)) + " 00:00:00";
        return start;
    }

    /**
     * 获取当前日期之前的时间
     *
     * @param amount 往前推多久时间[月为单位]
     * @return 2023-09-13 00:00:00
     */
    public static String getBeforeMonthDateAndDaysStartToString(LocalDateTime localDateTime, int amount, long days) {
        localDateTime = localDateTime.minusMonths(amount).minusDays(days);
        String start = localDateTime.format(DateTimeFormatter.ofPattern(DEF_DATE_FORMAT)) + " 00:00:00";
        return start;
    }

    /**
     * 获取当前日期之前的时间
     *
     * @param amount 往前推多久时间[月为单位]
     * @return 2023-09-13 23:59:59
     */
    public static LocalDateTime getBeforeMonthDateEnd(int amount) {
        LocalDateTime localDateTime = LocalDateTime.now().minusMonths(amount);
        String start = localDateTime.format(DateTimeFormatter.ofPattern(DEF_DATE_FORMAT)) + " 23:59:59";
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern(DEFAULT_DATE_PATTERN);
        LocalDateTime returnLocalDateTime = LocalDateTime.parse(start, formatter);
        return returnLocalDateTime;
    }


    /**
     * 获取当前日期之前的时间
     *
     * @param amount 往前推多久时间[月为单位]
     * @param days   减去几天
     * @return 2023-09-13 23:59:59
     */
    public static String getBeforeMonthDateAndDaysEndToString(LocalDateTime localDateTime, int amount, long days) {
        localDateTime = localDateTime.minusMonths(amount).minusDays(days);
        String start = localDateTime.format(DateTimeFormatter.ofPattern(DEF_DATE_FORMAT)) + " 23:59:59";
        return start;
    }

    /**
     * 获取当前日期之前的时间
     *
     * @param amount 往前推多久时间[月为单位]
     * @param days   减去几天
     * @return 2023-09-13 23:59:59
     */
    public static LocalDateTime getBeforeMonthDateAndDaysEndToLocalDateTime(int amount, long days) {
        LocalDateTime localDateTime = LocalDateTime.now().minusMonths(amount).minusDays(days);
        String start = localDateTime.format(DateTimeFormatter.ofPattern(DEF_DATE_FORMAT)) + " 23:59:59";
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern(DEFAULT_DATE_PATTERN);
        LocalDateTime returnLocalDateTime = LocalDateTime.parse(start, formatter);
        return returnLocalDateTime;
    }


    /**
     * 当天日期前两个月
     *
     * @return 2023-09-13 00:00:00
     */
    public static String getLastTwoMonthDateStart() {
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Calendar c = Calendar.getInstance();
        c.setTime(strDateTimeToDateTime(getLastMonthDateStart()));
        c.add(Calendar.MONTH, -1);
        String start = format.format(c.getTime());
        return start;
    }

    /**
     * 当天日期前两个月
     *
     * @return 2023-09-13 23:59:59
     */
    public static String getLastTwoMonthDateEnd() {
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Calendar c = Calendar.getInstance();
        c.setTime(strDateTimeToDateTime(getLastMonthDateEnd()));
        c.add(Calendar.MONTH, -1);
        String start = format.format(c.getTime());
        return start;
    }

    /**
     * 当前时间的前一年开始时间
     *
     * @return
     */
    public static String getLastYearDate() {
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Calendar c = Calendar.getInstance();
        c.add(Calendar.YEAR, -1);
        String start = format.format(c.getTime());
        System.out.println(start);
        return start;
    }

    /**
     * 当天时间(含当天)往前推日期
     * amount 传递29时,即固定往前推送30天
     *
     * @param dateTime 2023-07-17
     * @return 2023-06-18
     * @throws ParseException
     */
    public static String getThirtyDaysDate(String dateTime, int amount) throws ParseException {
        //获取当前日期
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        //Date today = new Date();
        Date parse = sdf.parse(dateTime);
        //当前日期
        String endDate = sdf.format(parse);
        //获取三十天前日期
        Calendar theCa = Calendar.getInstance();
        theCa.setTime(parse);
        //最后一个数字30可改，30天的意思
        theCa.add(Calendar.DATE, -amount);
        Date start = theCa.getTime();
        //三十天之前日期
        String startDate = sdf.format(start);
        System.out.println(endDate);
        System.out.println(startDate);
        return startDate;
    }

    /**
     * 计算两个Date之间的时长（毫秒）
     */
    public static Long getDifferenceInMillis(Date start, Date end) {
        if (start == null || end == null) {
            return null;
        }
        return Math.abs(end.getTime() - start.getTime());
    }

    /**
     * 计算两个Date之间的时长（秒）
     */
    public static long getDifferenceInSeconds(Date start, Date end) {
        Duration duration = Duration.between(
                start.toInstant(),
                end.toInstant()
        );
        return Math.abs(duration.getSeconds());
    }

    /**
     * 计算两个Date之间的时长（分钟）
     */
    public static long getDifferenceInMinutes(Date start, Date end) {
        Duration duration = Duration.between(
                start.toInstant(),
                end.toInstant()
        );
        return Math.abs(duration.toMinutes());
    }

    /**
     * 计算两个Date之间的时长（小时）
     */
    public static long getDifferenceInHours(Date start, Date end) {
        Duration duration = Duration.between(
                start.toInstant(),
                end.toInstant()
        );
        return Math.abs(duration.toHours());
    }

    /**
     * 计算两个Date之间的时长（天）
     */
    public static long getDifferenceInDays(Date start, Date end) {
        Duration duration = Duration.between(
                start.toInstant(),
                end.toInstant()
        );
        return Math.abs(duration.toDays());
    }

}
