package com.weaver.seconddev.chapanda.test;


import com.lsy.baselib.crypto.util.Base64;
import com.lsy.baselib.crypto.util.CryptUtil;
import com.lsy.baselib.crypto.util.FileUtil;
import java.io.*;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.security.PrivateKey;
import java.util.UUID;

public class test8 {

    public static void main(String[] args) {
//        String hiredate = "2024-08-09 00:00:00";
//        if(StringUtils.isNotBlank(hiredate)){
//            hiredate = hiredate.substring(0,10);
//        }
//        System.out.println(hiredate);
//        System.out.println(hiredate);
//
//        String lzrq = "2025-08-09";
//        String lznf = "2025";
//        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
//
//        LocalDate rzDate = LocalDate.parse(lznf+"-01-01", formatter);
//        LocalDate lzDate = LocalDate.parse(lzrq, formatter);
//        long workDays = ChronoUnit.DAYS.between(rzDate,lzDate);
//        System.out.println(workDays);
        //

//        String jsonStr = "{\"templateId\": \"JMHT-ZXSJ\"}";
//        try {
//            String secret = "7f067a08f5c675137e6e72aa298e2c07";
//            String processed = jsonStr
//                    .replaceAll("\\\\.", Matcher.quoteReplacement("$0"));
//
//            System.out.println(processed);
//            Mac sha256 = Mac.getInstance("HmacSHA256");
//            sha256.init(new SecretKeySpec(secret.getBytes(), "HmacSHA256"));
//            byte[] hash = sha256.doFinal(processed.getBytes());
//            String data = Hex.encodeHexString(hash);
//            System.out.println(data);
//        } catch (Exception e) {
//            throw new RuntimeException("加密失败", e);
//        }

//        String date ="2025-06-10";
//        System.out.println(date.length());
        String uuid = UUID.randomUUID().toString();
        System.out.println(uuid);
//
//        String message = "{\"code\":0,\"data\":{\"calendars\":[{\"calendar\":{\"calendar_id\":\"feishu.cn_CyZB7DD34hJrcBwosRTtDf@group.calendar.feishu.cn\",\"color\":-11034625,\"description\":\"\",\"permissions\":\"private\",\"role\":\"owner\",\"summary\":\"聚才林HR\",\"summary_alias\":\"\",\"type\":\"primary\"},\"user_id\":\"ou_f102af8c3620c64b37077cc949bcc8fe\"}]},\"msg\":\"success\"}";
//        if(StringUtils.isNotBlank(message)){
//            JSONObject returnData = JSONObject.parseObject(message);
//            if(returnData.containsKey("code")){
//                String code = returnData.getString("code");
//                if("0".equals(code)){
//                    JSONObject dataJson = returnData.getJSONObject("data");
//                    JSONArray calendarsArray = dataJson.getJSONArray("calendars");
//                    for(int i=0;i<calendarsArray.size();i++){
//                        JSONObject calendarJson = calendarsArray.getJSONObject(i);
//                        System.out.println(calendarJson.toJSONString());
//
//                        JSONObject calendarData = calendarJson.getJSONObject("calendar");
//
//                        String type = calendarData.getString("type");
//                        System.out.println(type);
//                        if("primary".equals(type)){
//                            String calendar_id = calendarData.getString("calendar_id");
//                            System.out.println(calendar_id);
//                        }
//                    }
//                }
//            }
//        }

//        String keyfile = test8.class.getClassLoader().getResource("signkey/server_sign.key").getPath();
//        System.out.println(keyfile);
////        byte[] base64EncodedPrivatekey = FileUtil.read4file(keyfile);
//
//        byte[] base64EncodedPrivatekey = read4file(keyfile);
//
//        //私钥密码文件路径
//        String pwdfile = test8.class.getClassLoader().getResource("signkey/server_sign.pwd")
//                .getPath();
//        byte[] base64EncodedPrivatekeyPass = read4file(pwdfile);
//
//        char[] keyPassword = new char[0];
//        try {
//            keyPassword = new String(base64EncodedPrivatekeyPass, "UTF-8").toCharArray();
//        } catch (UnsupportedEncodingException e) {
//            throw new RuntimeException(e);
//        }
//
//        PrivateKey signerPrivatekey = CryptUtil.decryptPrivateKey(Base64.decode(base64EncodedPrivatekey), keyPassword);


//        Path path = Paths.get(keyfile);
//        byte[] data = new byte[0];
//        try {
//            data = Files.readAllBytes(path);
//        } catch (IOException e) {
//            throw new RuntimeException(e);
//        }
//        try {
//            String result = new String(data, "utf-8");
//            System.out.println(result);
//        } catch (UnsupportedEncodingException e) {
//            throw new RuntimeException(e);
//        }

        System.out.println(System.currentTimeMillis()+"");

    }

    private PrivateKey getPrivateKey() throws Exception {
        //私钥文件路径
        String keyfile = test8.class.getClassLoader().getResource("signkey/server_sign.key")
                .getPath();
        byte[] base64EncodedPrivatekey = FileUtil.read4file(keyfile);

        //私钥密码文件路径
        String pwdfile = test8.class.getClassLoader().getResource("signkey/server_sign.pwd")
                .getPath();
        byte[] base64EncodedPrivatekeyPass = FileUtil.read4file(pwdfile);

        char[] keyPassword = new String(base64EncodedPrivatekeyPass, "UTF-8").toCharArray();

        PrivateKey signerPrivatekey = CryptUtil.decryptPrivateKey(
                Base64.decode(base64EncodedPrivatekey), keyPassword);
        return signerPrivatekey;


    }

}


