package com.zfire.jiasm.syncdata;

import cn.hutool.core.date.DateUtil;
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import com.zfire.jiasm.syncdata.utils.MyBeanUtils;
import lombok.Data;
import org.springframework.beans.BeanUtils;

import java.sql.Timestamp;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.util.*;

import static jdk.nashorn.internal.objects.NativeString.substr;
import static jdk.nashorn.internal.objects.NativeString.trim;


public class test {

    @Data
    public static class A{
        private Integer id;
        private String websitId;
        private String orderBaseId;
    }

    @Data
    public static class B{
        private Integer id;
        private String websitId;
        private String orderBaseId;
    }

    public static void main(String[] args) throws ParseException {

        System.out.println(IdWorker.getId());

        // 获取该日期所在年的第一天
        String firstDay = getYearFirstDay(new Date());
        System.out.println("指定日期所在年的第一天为：" + firstDay);

        // 获取该日期所在年的最后一天
        String lastDay = getYearLastDay(new Date());
        System.out.println("指定日期所在年的最后一天为：" + lastDay);


        Date insureStartTime = DateUtil.offsetMonth(new Date(),-24);
        System.out.println(insureStartTime);
        // 大于今年取今年的第一天
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy");
        SimpleDateFormat sdft = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String insureStartTimes = sdf.format(insureStartTime);
        String curDates = sdf.format(new Date());
        System.out.println(insureStartTimes);
        System.out.println(curDates);
        if (insureStartTimes.compareTo(curDates)>0){
            insureStartTime=getYearFirstDayt(new Date());
        }

        System.out.println(sdft.format(insureStartTime));




    }


    public static Date getYearFirstDayt(Date date) throws ParseException {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        calendar.set(Calendar.MONTH, 0);
        calendar.set(Calendar.DATE, 1);
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        return sdf.parse(sdf.format(calendar.getTime()));
    }

    /**
     * 获取指定日期所在年的第一天
     * @param date 指定日期
     * @return 日期字符串
     */
    public static String getYearFirstDay(Date date) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        calendar.set(Calendar.MONTH, 0);
        calendar.set(Calendar.DATE, 1);
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        return sdf.format(calendar.getTime());
    }

    /**
     * 获取指定日期所在年的最后一天
     * @param date 指定日期
     * @return 日期字符串
     */
    public static String getYearLastDay(Date date) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        calendar.set(Calendar.MONTH, 11);
        calendar.set(Calendar.DATE, 31);
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        return sdf.format(calendar.getTime());
    }
}
