package com.sw.mes;

import com.alibaba.fastjson.JSONObject;
import com.sw.mes.yb.production.entity.ProcessWorkingHours;
import io.swagger.models.auth.In;
import org.junit.Test;

import java.math.BigDecimal;
import java.time.Duration;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.*;

public class Test1 {

     @Test
    public void test7(){
         List<String> list = new ArrayList<>();
         list.add("10001");
         list.add("10002");
         list.add("1003");
         list.add("10004");
         list.add("101");
         System.out.println(list.size());
         for (String s : list) {
             if (s.contains("01")){
                 System.out.println(s);
             }
         }
    }

    // @Test
    public void test6(){
        String s1 = "sddd===T=-=sss";
        String[] split = s1.split("=T=");
        System.out.println(split.toString());
    }

    // @Test
    public void test5(){
        String crystalNo = "TJNF422C107122ND";
        // 复投次数
        crystalNo = replaceIndex(13 - 1, crystalNo, "8");

        // 颗次
        crystalNo = replaceIndex(14 - 1, crystalNo, "9");

        // 收尾方式
        crystalNo = replaceIndex(15 - 1, crystalNo, ("W".equals("N")? "W" : "N"));

        System.out.println(crystalNo);
    }
    private static String replaceIndex(int index, String res, String str) {
        return res.substring(0, index) + str + res.substring(index + 1);
    }

//     @Test
    public void test4(){
        /*String str = "1B0012";
        String s1 = str.substring(str.length()-3);
        System.out.println(s1);*/

        String str = "2C118";
        String s1 = str.substring(0, 2);
        System.out.println(s1);
    }


    // @Test
    public void test3(){
        Calendar calendar = Calendar.getInstance();
        calendar.set(2024, 1, 23, 10, 0);
        Date d1 = calendar.getTime();
        calendar.set(2024, 1, 24, 10, 25);
        Date d2 = calendar.getTime();

        LocalDateTime start = LocalDateTime.ofInstant(d1.toInstant(), ZoneId.systemDefault());
        LocalDateTime stop = LocalDateTime.ofInstant(d2.toInstant(), ZoneId.systemDefault());

        // 计算工时
        if (start != null && start.compareTo(stop) < 0){
            long minutesDiff = Duration.between(start, stop).toMinutes();
            double hoursDiff = (double)minutesDiff / 60;
            String format = String.format("%.2f", hoursDiff);
            System.out.println(format);
        }
    }

    // @Test
    public void test2(){
        Calendar calendar = Calendar.getInstance();
        calendar.set(2024, 0, 19);
        Date d1 = calendar.getTime();
        calendar.set(2024, 1, 21);
        Date d2 = calendar.getTime();
        Date now = new Date();
        if (now.compareTo(d1) <= 0 || now.compareTo(d2) >=0){
            System.out.println("不合适");
        }else {
            System.out.println("合格");
        }
    }

    // @Test
    public void test1(){
        LocalDate now = LocalDate.now();
        int year = now.getYear();
        int month = now.getMonthValue();
        int day = now.getDayOfMonth();
        System.out.println(year + " : " + month + " : " + day);
    }



}
