package com.xjrsoft.xjrsoftboot;

import cn.hutool.core.date.DateUtil;
import org.junit.jupiter.api.Test;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.*;

public class DateTime {
    @Test
    public void DateTimeTest(){
//        cn.hutool.core.date.DateTime now = DateUtil.date();
//        System.out.println(now.dayOfWeek());

        System.out.println(new Date());
    }

    @Test
    public void collectionTest(){
        Long num1 = 23L;
        Long num2 = 25L;
        List<Long> list = new ArrayList<>();
        list.add(num1);
        list.add(num2);
        Long num3 = 23L;
        List<Long> classIdList = new ArrayList<>();
        System.err.println(list.contains(classIdList));
    }

    @Test
    public void LocalDateTimeTest(){
        String dateString = "2022-01-01";
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        LocalDateTime dateTime = LocalDateTime.parse(dateString, formatter);
        System.err.println(dateTime);
    }

    @Test
    public void MapTest(){
        List<String> data = Arrays.asList(
                "2023年秋期", "2023年春期", "2022年秋期", "2022年春期",
                "2021年秋期", "2021年春期", "2020年秋期", "2020年春期",
                "2019年秋期", "2019年春期", "2018年秋期", "2018年春期",
                "2017年秋期", "2017年春期", "2024年春期"
        );

        List<TreeNode> treeNodes = new ArrayList<>();
        for (String item : data) {
            int year = Integer.parseInt(item.substring(0, 4));
            String season = item.substring(5);
            TreeNode node = new TreeNode(year, season);
            treeNodes.add(node);
        }

        Map<Integer, TreeNode> yearMap = new HashMap<>();
        for (TreeNode node : treeNodes) {
            int year = node.year;
            if (!yearMap.containsKey(year)) {
                yearMap.put(year, new TreeNode(year, ""));
            }
            yearMap.get(year).children.add(node);
        }

        List<TreeNode> tree = new ArrayList<>(yearMap.values());
        for (TreeNode node : tree) {
            System.out.println("Year: " + node.year);
            for (TreeNode child : node.children) {
                System.out.println("  Season: " + child.season);
            }
        }
    }
    class TreeNode {
        int year;
        String season;
        List<TreeNode> children;

        public TreeNode(int year, String season) {
            this.year = year;
            this.season = season;
            this.children = new ArrayList<>();
        }
    }
}
