package com.zfire.jiasm.syncdata;

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 {
       /* A a = new A();
        B b = new B();

        B c = new B();

        a.setWebsitId(a.getOrderBaseId());

        a.setId(1);
        a.setWebsitId("A");
        a.setOrderBaseId("A");

        BeanUtils.copyProperties(a, b);

        BeanUtils.copyProperties(a, c,new String[] {"websitId"});

        System.out.println(IdWorker.getIdStr());
        System.out.println(UUID.randomUUID().toString());


        Date date = new Date();
        System.out.println("写代码的当前时间是"+date);
        long time = date.getTime();
//        System.out.println(time);
        Date newDate = new Date();
        newDate.setTime(time + 1000);
        System.out.println("加一秒"+ newDate);
        newDate.setTime(time + 1000*60);
        System.out.println("加一分"+ newDate);
        newDate.setTime(time + 1000*60*60);
        System.out.println("加一时"+ newDate);
        newDate.setTime(time + 1000*60*60*24);*/

/*

        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        DateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

        Date date = new Timestamp(1689651148);

        System.out.println(sdf.format(date));
        System.out.println(format.parse(sdf.format(date)));

*/



/* A a = new A();
        A b = new A();
        List<A> list = new ArrayList<>();


        a.setId(1);
        a.setWebsitId("A");
        a.setOrderBaseId("A");

        MyBeanUtils.copyProperties(a,b);
        b.setId(2);

        list.add(a);
        list.add(b);

        for (A i:list){
            i.setId(0);
        }

        System.out.println(a);
        System.out.println(b);


        System.out.println("uploadfile/");

        long timeStamp = 1691132713 * 1000L; // 时间戳，单位：毫秒
        Date date = new Date(timeStamp);
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String formatTime = sdf.format(date);
        System.out.println(formatTime);



        String s = "1_p_230720_S9219801_cAwTQeZ4rP-Np3f-2RFN76.png";
        if (s.contains(",")){
            System.out.println("有");
            System.out.println(s);
        }
        System.out.println("无");


        List<String> roleIds = new ArrayList<>();
        List<String> tt = new ArrayList<>();

        List<String> xx = new ArrayList<>();

        roleIds.add("1");
        roleIds.add("3");
        roleIds.add("2");

        tt.add("3");
        tt.add("4");

        xx.addAll(roleIds);

        System.out.println("交");
        roleIds.retainAll(tt);

        tt.removeAll(roleIds);

        xx.addAll(tt);

        System.out.println(xx);




        System.out.println(roleIds);

        Date ssDate = new Date();
        System.out.println(ssDate);
        ssDate.setTime(ssDate.getTime() - 24 * 60 * 60 * 1000);
        System.out.println(ssDate);

        // 创建一个Calendar对象
        Calendar calendar = Calendar.getInstance();
        // 设置日期为当前日期
        calendar.setTime(new Date());
        // 减去一年
        calendar.add(Calendar.YEAR, -1);
        // 获取减去一年后的日期
        Date newDate = calendar.getTime();
        System.out.println("减去一年后的日期: " + newDate);*/
/*

        String s="1_p_230913_nobody01_FpNaEGLBtpw5XaYjRgfH59.jpg||1_p_230913_nobody01_4ajNwJC8sS46aWHeScpd97.jpg||1_p_230913_nobody01_w0NQb8gut0KH3tytSOEx95.jpg";
        String x=s.replace("||",",");
        System.out.println(x);


        System.out.println(UUID.randomUUID().toString());

        String uuId = UUID.randomUUID().toString().replace("-","").toUpperCase();
        System.out.println(uuId);

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

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

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

    }


    /**
     * 获取指定日期所在年的第一天
     * @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());
    }
}
