package com.tofly.common.core;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.google.zxing.WriterException;
import com.tofly.common.core.entity.TreeTest;
import com.tofly.common.core.util.JSONUtil;
import com.tofly.common.core.util.Qrqd.QRCodeMaker;
import com.tofly.common.core.util.io.PdfUtil;
import lombok.Data;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author Administrator
 * @date 2019/9/4  14:59
 */
public class Testmain {
    public static void main(String[] args) {
        /*String filename="/xnkd/demo/pic/QQ图片20191014133817.png";
        String fileType=filename.substring(filename.lastIndexOf("."));
        System.out.println(fileType);*/
//        String p="c984aed014aec7623a54f0591da07a85fd4b762d";
//        String pp= DigestUtils.sha1Hex("123456");
//        System.out.println(pp);

//        List<Map> list=new ArrayList();
//        Map map1=new HashMap(){{
//            put("aa","11");
//            put("bb","22");
//        }};
//        Map map2=new HashMap(){{
//            put("aa","111");
//            put("bb","222");
//        }};
//        list.add(map1);
//        list.add(map2);
//        list.forEach(m->{
//            m.put("cc","33");
//        });
//        System.out.println(list.get(0));
//        list.forEach(mm->{
//            System.out.println("-----------"+mm);
//        });

        //String aa="2019-10-11 00:00:00";
//        String startDate="2019-10-11";
//        System.out.println(Timestamp.valueOf(startDate+" 00:00:00"));
//        System.out.println(Timestamp.valueOf(startDate+" 23:59:59"));
        //System.out.println(DateUtil.getCurrentTime());
        //System.out.println(underlineToCamel("CREATE_BY"));
//        Map m = new HashMap();
//        map1.forEach((k,v)->{
//            m.put(k,v);
//            if(k.equals("aa")){
//                m.put(k,12345);
//            }
//        });
//        System.out.println(m);

//        Timestamp ts= DateUtil.getCurrentTime();
//        DateFormat sdf = new SimpleDateFormat(DateUtil.DATETIME_DEFAULT_FORMAT);
//        System.out.println(sdf.format(ts));

//        long start=System.currentTimeMillis();
//        String p=String.valueOf(System.currentTimeMillis());
//        System.out.println("时间戳耗时："+p+":"+(System.currentTimeMillis()-start));
//
//        long start1=System.currentTimeMillis();
//        String uuid= UUID.randomUUID().toString();
//        System.out.println("UUID耗时："+uuid+":"+(System.currentTimeMillis()-start1));
//        Map map1=new HashMap();
//        String start=(String)map1.get("start");
//        map1.put("start",Integer.valueOf(start).intValue()+1);
//        System.out.println(map1);

//        String path = System.getProperty("user.dir");
//        System.out.println(path);
//        List<String> list= Arrays.asList("2-3","1-2","4-5","10-20","小计");
//        list=list.stream().sorted(Comparator.comparing(a->{
//            String[] aa=a.split(",");
//            if(aa.length>1){
//                return Integer.parseInt(aa[0]);
//            }else{
//                return 99999999;
//            }
//        })).collect(Collectors.toList());
        /*System.out.println(list);

        String a="?,?,?,?,?,?,?,?,?,?,?,?,";
        String b=a.substring(0,a.lastIndexOf(","));
        System.out.println(b);*/
//        Map m=new HashMap();
//        for(int i=0;i<10000;i++){
//            m.put(i,i);
//        }
//
//        m.forEach((k,v)->{
//            System.out.print(k);
//        });
//        System.out.println(".....");
//        m.forEach((k,v)->{
//            System.out.print(k);
//        });

//        String a="/workflow/隐患管理流程/1229316577202167809.png";
//        String fileName= a.split("/")[2];
//        System.out.println(fileName);
//        String str="adasdasdasdda";
//        char[] cs=str.toCharArray();
//        cs[0]-=32;
//        System.out.println(String.valueOf(cs));
//          String sql="select  a as  aa       from bb";
//          String[] a=sql.split(" from");
//          String[] b=a[0].split(" ");
//        System.out.println(b.length);
//        List<String> collect = Arrays.stream(b).filter(k -> k != " ").collect(Collectors.toList());
//        System.out.println("bbbbbbbb:"+collect.get(collect.size()-1));

//        Testmain testDemo=new Testmain();
//
//        String json="{\"a\":\"aa\",\"b\":\"bb\",\"testA\":{\"a1\":\"aaa1\",\"a2\":\"aaa2\"}}";
//        testDemo.testPars(json);

//        System.out.println(DigestUtils.sha1Hex("000000"));
//        System.out.println(DigestUtils.sha1Hex("111111"));
//        System.out.println(DigestUtils.sha1Hex("123456"));
//        int[][] A={{0,0,0,0},{1,0,1,0},{0,1,1,0},{0,0,0,0}};
//        int[][] A={{0,0,0,1,1,1,0,1,0,0},{1,1,0,0,0,1,0,1,1,1},{0,0,0,1,1,1,0,1,0,0},{0,1,1,0,0,0,1,0,1,0},{0,1,1,1,1,1,0,0,1,0},{0,0,1,0,1,1,1,1,0,1},{0,1,1,0,0,0,1,1,1,1},{0,0,1,0,0,1,0,1,0,1},{1,0,1,0,1,1,0,0,0,0},{0,0,0,0,1,1,0,0,0,1}};
//        Testmain testmain=new Testmain();
//        for(int i=0;i<A.length;i++){
//            int[] B=A[i];
//            for(int j=0;j<B.length;j++){
//                System.out.print(A[i][j]);
//            }
//            System.out.println();
//        }
//        System.out.println(testmain.numEnclaves(A));
//        Testmain testmain=new Testmain();
//        testmain.te();
//
//        String S="asda,key,asdkey,asd key ,asdad keyada,key;2313,key";
//
//        String ss=S.replaceAll(String.format("(?<=[,\\s])%s(?=[,\\s])", "key"),"`key`");
//        System.out.println(S);
//        System.out.println(ss);
        File file=new File("D:\\a.png");
        try {
            QRCodeMaker.MakeQRCode("aaaaa",file,300,"bbbbbb");

        } catch (WriterException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }

    }




    private void te(){
        List<TreeTest> list=new ArrayList(){{
            add(new TreeTest("1"));
            add(new TreeTest("2"));
            add(new TreeTest("3"));
            add(new TreeTest("4","1"));
            add(new TreeTest("5","2"));
            add(new TreeTest("6","3"));
            add(new TreeTest("7","4"));
            add(new TreeTest("8","4"));
            add(new TreeTest("9","7"));
            add(new TreeTest("10","7"));
        }};

        List<TreeTest> list1 = JSONUtil.parTree(list, TreeTest::getId, TreeTest::getParentId,
                TreeTest::getChildren);
        System.out.println(list1);
    }

    private void testPars(String json){
        TestDemo testDemo=JSONObject.parseObject(json,TestDemo.class);
        System.out.println(testDemo);
    }

    private void  test(){
        TestDemo testDemo=new TestDemo("a","b");

        testDemo.setB("bb");
        TestA testA=new TestA();
        testA.setA1("aaa1");
        testA.setA2("aaa2");
        testDemo.setTestA(testA);
        System.out.println(JSON.toJSONString(testDemo));
    }




    @Data
    class TestDemo{
         String a;
         String b;
         TestA testA;
        public TestDemo(){};
        public TestDemo(String a,String b){
            this.a=a;
            this.b=b;
        }



    }
    @Data
    class TestA{
        private String a1;
        private String a2;
        public TestA(){};
    }
    Map<String,Boolean> map=new HashMap();

    public int numEnclaves(int[][] A) {
        int returnNum=0;

        for(int i=0;i<A.length;i++){
            int[] B=A[i];
            int blength=B.length;
            for(int j=0;j<B.length;j++){

                if(A[i][j]==1){
                    boolean b;
                    if(map.containsKey(i+","+j)){
                        b= map.get(i+","+j);
                    }else{
                        b=check(i,j,A,blength,0,new ArrayList<String>());
                    }
                    if(b){
                        returnNum++;
                    }

                }
            }
        }
        return returnNum;
    }

    public boolean check(int i, int j, int[][] A, int blength, int come, List<String> exists){
        if(map.containsKey(i+","+j)){
            return map.get(i+","+j);
        }
        if(i==0 || j==0){
            map.put(i+","+j,false);
            return false;
        }
        if(i==A.length-1|| j==blength-1){
            map.put(i+","+j,false);
            return false;
        }
        boolean flag=true;
        if(A[i-1][j]==1 && come!=1 && !exists.contains((i-1)+","+j)){
            exists.add((i-1)+","+j);
            flag = check(i-1,j,A,blength,2,exists);
            if(!flag){
                map.put(i+","+j,false);
                exists.stream().forEach(k->map.put(k,false));
                return flag;
            }
        }
        if(A[i+1][j]==1 && come!=2 && !exists.contains((i+1)+","+j)){
            exists.add((i+1)+","+j);
            flag = check(i+1,j,A,blength,1,exists);
            if(!flag){
                map.put(i+","+j,false);
                exists.stream().forEach(k->map.put(k,false));
                return flag;
            }
        }
        if(A[i][j-1]==1 && come!=4 && !exists.contains(i+","+(j-1))){
            exists.add(i+","+(j-1));
            flag = check(i,j-1,A,blength,3,exists);
            if(!flag){
                map.put(i+","+j,false);
                exists.stream().forEach(k->map.put(k,false));
                return flag;
            }
        }
        if(A[i][j+1]==1 && come!=3 && !exists.contains(i+","+(j+1))){
            exists.add(i+","+(j+1));
            flag = check(i,j+1,A,blength,4,exists);
            if(!flag){
                map.put(i+","+j,false);
                exists.stream().forEach(k->map.put(k,false));
                return flag;
            }
        }

        map.put(i+","+j,true);
        exists.add(i+","+j);
        return true;

    }

}
