package com.ruoyi.system.test;

import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONException;
import com.alibaba.fastjson2.JSONObject;
import com.ruoyi.common.utils.sql.SqlUtil;
import org.apache.ibatis.jdbc.SQL;

import java.time.DayOfWeek;
import java.time.LocalDate;
import java.util.*;
import java.util.stream.Collectors;

/**
 * @author hanzihang
 * @date 2023/8/24 3:36 PM
 */
public class ljj {

    static String SQL_START = "CONCAT(";
    static final String SQL_MIDDLE = "IFNULL( #{VAL}, '' )";
    static final String SQLSERVER_MIDDLE = "COALESCE( #{VAL}, '' )";
    static final String SQL_END = "LIKE '%#{val}%'";

    public static void main(String[] args) {

        JSONArray jsonArray = JSON.parseArray("[{\"createById\":201,\"createBy\":\"tenant1116\",\"createTime\":\"2023-11-27 15:50:41\",\"updateById\":201,\"updateBy\":\"tenant1116\",\"updateTime\":\"2023-11-29 16:43:16\",\"remark\":null,\"dictCode\":1,\"dictSort\":0,\"dictLabel\":\"未投产\",\"dictValue\":\"1\",\"dictType\":\"qqq\",\"cssClass\":null,\"listClass\":\"default\",\"isDefault\":\"N\",\"status\":\"0\",\"default\":false},{\"createById\":201,\"createBy\":\"tenant1116\",\"createTime\":\"2023-11-27 15:50:54\",\"updateById\":201,\"updateBy\":\"tenant1116\",\"updateTime\":\"2023-11-29 16:43:16\",\"remark\":null,\"dictCode\":2,\"dictSort\":0,\"dictLabel\":\"已投产\",\"dictValue\":\"2\",\"dictType\":\"qqq\",\"cssClass\":null,\"listClass\":\"default\",\"isDefault\":\"N\",\"status\":\"0\",\"default\":false},{\"createById\":201,\"createBy\":\"tenant1116\",\"createTime\":\"2023-11-27 15:51:07\",\"updateById\":201,\"updateBy\":\"tenant1116\",\"updateTime\":\"2023-11-29 16:43:16\",\"remark\":null,\"dictCode\":3,\"dictSort\":0,\"dictLabel\":\"已完成\",\"dictValue\":\"3\",\"dictType\":\"qqq\",\"cssClass\":null,\"listClass\":\"default\",\"isDefault\":\"N\",\"status\":\"0\",\"default\":false},{\"createById\":201,\"createBy\":\"tenant1116\",\"createTime\":\"2023-11-27 17:08:03\",\"updateById\":201,\"updateBy\":\"tenant1116\",\"updateTime\":\"2023-11-29 16:43:16\",\"remark\":null,\"dictCode\":4,\"dictSort\":0,\"dictLabel\":\"未绑定\",\"dictValue\":\"0\",\"dictType\":\"ruku_status\",\"cssClass\":null,\"listClass\":\"primary\",\"isDefault\":\"N\",\"status\":\"0\",\"default\":false},{\"createById\":201,\"createBy\":\"tenant1116\",\"createTime\":\"2023-11-29 15:40:55\",\"updateById\":201,\"updateBy\":\"tenant1116\",\"updateTime\":\"2023-11-29 16:43:16\",\"remark\":\"计划名称\",\"dictCode\":9,\"dictSort\":0,\"dictLabel\":\"planName\",\"dictValue\":\"planname\",\"dictType\":\"plan_execution_data\",\"cssClass\":null,\"listClass\":\"default\",\"isDefault\":\"N\",\"status\":\"0\",\"default\":false},{\"createById\":201,\"createBy\":\"tenant1116\",\"createTime\":\"2023-11-29 15:41:46\",\"updateById\":201,\"updateBy\":\"tenant1116\",\"updateTime\":\"2023-11-29 16:43:16\",\"remark\":\"租户计划表名称\",\"dictCode\":10,\"dictSort\":0,\"dictLabel\":\"planTableName\",\"dictValue\":\"plan_productionplan\",\"dictType\":\"plan_execution_data\",\"cssClass\":null,\"listClass\":\"default\",\"isDefault\":\"N\",\"status\":\"0\",\"default\":false},{\"createById\":201,\"createBy\":\"tenant1116\",\"createTime\":\"2023-11-29 15:42:11\",\"updateById\":201,\"updateBy\":\"tenant1116\",\"updateTime\":\"2023-11-29 16:43:16\",\"remark\":\"计划表中的主键名\",\"dictCode\":11,\"dictSort\":0,\"dictLabel\":\"planID\",\"dictValue\":\"id\",\"dictType\":\"plan_execution_data\",\"cssClass\":null,\"listClass\":\"default\",\"isDefault\":\"N\",\"status\":\"0\",\"default\":false},{\"createById\":201,\"createBy\":\"tenant1116\",\"createTime\":\"2023-11-27 17:08:15\",\"updateById\":201,\"updateBy\":\"tenant1116\",\"updateTime\":\"2023-11-29 16:43:16\",\"remark\":null,\"dictCode\":5,\"dictSort\":1,\"dictLabel\":\"已绑定\",\"dictValue\":\"1\",\"dictType\":\"ruku_status\",\"cssClass\":null,\"listClass\":\"success\",\"isDefault\":\"N\",\"status\":\"0\",\"default\":false},{\"createById\":201,\"createBy\":\"tenant1116\",\"createTime\":\"2023-11-27 17:09:29\",\"updateById\":201,\"updateBy\":\"tenant1116\",\"updateTime\":\"2023-11-29 16:43:16\",\"remark\":null,\"dictCode\":7,\"dictSort\":1,\"dictLabel\":\"成品\",\"dictValue\":\"1\",\"dictType\":\"stash_type\",\"cssClass\":null,\"listClass\":\"default\",\"isDefault\":\"N\",\"status\":\"0\",\"default\":false},{\"createById\":201,\"createBy\":\"tenant1116\",\"createTime\":\"2023-11-27 17:08:27\",\"updateById\":201,\"updateBy\":\"tenant1116\",\"updateTime\":\"2023-11-29 16:43:16\",\"remark\":null,\"dictCode\":6,\"dictSort\":2,\"dictLabel\":\"已出库\",\"dictValue\":\"2\",\"dictType\":\"ruku_status\",\"cssClass\":null,\"listClass\":\"warning\",\"isDefault\":\"N\",\"status\":\"0\",\"default\":false}]");
        System.out.println("初始化的JSONArray:" + jsonArray.toJSONString());



//        JSONArray newJSONArray = jsonArray.stream().sorted(
//                Comparator.comparingLong(
//                        // 根据对象中的ID进行排序
//                        e -> JSONObject.parseObject(e.toString()).getLongValue("ID")
//                )
//        ).collect(Collectors.toCollection(JSONArray::new));
//        System.out.println("排序后的newJSONArray:" + newJSONArray.toJSONString());
//
//        String asd = "qwe,asd,";
//        String asd1 = "qwe";
//        String a[] = asd.split(",");
//        System.out.println(a);
//        System.out.println(asd1.split(","));

//        String qwe = "id=2";
//        String[] as = qwe.split("=");
//        System.out.println(as[0]);
//        System.out.println(as[1]);
//
//        System.out.println(qwe.contains("0"));

//            String condition = "ceshi_link1.del_flag = '0' AND ceshi_link1.province=1";
//
//        List<Map<String, Object>> mapList = new ArrayList<>();
//        Map<String, Object> objectMap = new HashMap<>();
//        objectMap.put("one.qwe", "1");
////        objectMap.put("two", "2");
////        objectMap.put("three", "3");
////        objectMap.put("four", "4");
//        mapList.add(objectMap);
//        System.out.println(objectMap.get("one.qwe"));
//        System.out.println(mapList.get(0).keySet());
//
//
//            // 移除包含 "=1" 的条件
//            String result = removeConditionFromString(condition, "=1");
//
//            // 打印结果
//            System.out.println(result);


//        List<String> bigList = new ArrayList<>();
//        bigList.add("1");
//        int batchSize = 2;
////        List<String> bigList = new ArrayList<>(); // 这里假设bigList是你要插入数据库的10000条数据
//
//        for(int i = 0; i < bigList.size(); i += batchSize) {
//            int end = Math.min(bigList.size(), i + batchSize);
//            List<String> smallList = bigList.subList(i, end);
//            // 这里smallList就是你要插入数据库的1000条数据
//            // 将smallList插入数据库的代码放在这里
//            System.out.println(smallList);
//        }

//        String qwe = "123456222221111";
//        String asd = qwe.replace("2", "。");
//        System.out.println(asd);
//        System.out.println(qwe);
//
//        List<String> bigList = new ArrayList<>();
//        bigList.add("1");
//        int batchSize = 2;
////        List<String> bigList = new ArrayList<>(); // 这里假设bigList是你要插入数据库的10000条数据
//
//        for(int i = 0; i < bigList.size(); i += batchSize) {
//            int end = Math.min(bigList.size(), i + batchSize);
//            List<String> smallList = bigList.subList(i, end);
//            // 这里smallList就是你要插入数据库的1000条数据
//            // 将smallList插入数据库的代码放在这里
//            System.out.println(smallList);
//        }


//        List<Map<String, String>> list = new ArrayList<Map<String, String>>();
//        Map<String, String> map1 = new HashMap<>();
//        map1.put("苹果手机", "2");//添加键值对
//        map1.put("智能手表", "1");
//        map1.put("java书", "1");
//        map1.put("c语言书", "1");
//        map1.put("西瓜", "2");
//        Map<String, String> map2 = new HashMap<>();
//        map2.put("苹果手机", "20");//添加键值对
//        map2.put("智能手表", "10");
//        map2.put("java书", "10");
//        map2.put("c语言书", "10");
//        map2.put("西瓜", "20");
//        list.add(map1);
//        list.add(map2);
//        for (Map<String, String> map : list) {
//            System.out.println(map);
//        }
//        System.out.println("--------------------------------");
//        for (Map<String, String> map : list) {
//            Set<String> set = map.keySet();
//            Iterator<String> it = set.iterator();
//            while (it.hasNext()) {
//                String key = it.next();
//                if (key.equals("苹果手机")) {
//                    it.remove();
//                }
//            }
//            System.out.println(map);
//        }


//        System.out.println(SqlUtil.isValidOrderBySql("M_F.M_F_ID"));
//        String a = "asdjkl";
//        System.out.println(a.replaceAll("k", "QQ"));


//        for (int i = 0; i < 10; i++) {
//
//            System.out.println(SQL_MIDDLE + "1");
//        }


//        String a = "\u200B冀J1T697";
//
//        System.out.println(a.length());
//        System.out.println("\u200B冀J1T697".equals("冀J1T697"));


//        if (true) {
//            test2(1);
//            return;
//        }
//
//        List<String> tests = new ArrayList<>();
//
//        tests.add("name");
//        tests.add("age");
//        tests.add("sex");
//        tests.add("rem");
//        tests.add("pass");
//        //  NAME || age LIKE '%18%'
//        //  CONCAT ( COALESCE ( name, '' ), COALESCE ( age, '' ) ) LIKE '%18%';
//        //  CONCAT(
//        //	IFNULL( `name`, '' ),
//        //	IFNULL( `age`, '' )
//        //	) LIKE '%#{val}%'
//
//        switch ("ORACLE") {
//            case "MYSQL":
//            case "DM":
//                for (int i = 0; tests.size() > i; i++) {
//                    SQL_START += SQL_MIDDLE.replace("#{VAL}", tests.get(i));
//                    SQL_START += tests.size() - 1 == i ? ")" : ",\n";
//                }
//                break;
//            case "SQLSERVER":
//                for (int i = 0; tests.size() > i; i++) {
//                    SQL_START += SQLSERVER_MIDDLE.replace("#{VAL}", tests.get(i));
//                    SQL_START += tests.size() - 1 == i ? ")" : ",\n";
//                }
//                break;
//            case "ORACLE":
//                SQL_START = "";
//                for (int i = 0; tests.size() > i; i++) {
//                    SQL_START += tests.get(i);
//                    SQL_START += tests.size() - 1 == i ? " " : "||";
//                }
//                break;
//        }
//
//        System.out.println(SQL_START + SQL_END);
    }


    public static void test1() {
        String ret = "{\"msg\":\"操作成功\",\"code\":200,\"data\":[{\"createBy\":\"hanzihang\",\"createTime\":\"2023-08-17 16:00:20\",\"updateBy\":null,\"updateTime\":null,\"remark\":\"数据库名\",\"dictCode\":226,\"dictSort\":1,\"dictLabel\":\"databaseName\",\"dictValue\":\"zkqy-call\",\"dictType\":\"mysql_connection_information\",\"cssClass\":null,\"listClass\":\"default\",\"isDefault\":\"N\",\"status\":\"0\",\"default\":false},{\"createBy\":\"hanzihang\",\"createTime\":\"2023-08-17 16:00:46\",\"updateBy\":null,\"updateTime\":null,\"remark\":\"数据库IP\",\"dictCode\":227,\"dictSort\":2,\"dictLabel\":\"databaseIp\",\"dictValue\":\"192.168.110.59\",\"dictType\":\"mysql_connection_information\",\"cssClass\":null,\"listClass\":\"default\",\"isDefault\":\"N\",\"status\":\"0\",\"default\":false},{\"createBy\":\"hanzihang\",\"createTime\":\"2023-08-17 16:01:41\",\"updateBy\":null,\"updateTime\":null,\"remark\":\"用户名\",\"dictCode\":228,\"dictSort\":3,\"dictLabel\":\"username\",\"dictValue\":\"root\",\"dictType\":\"mysql_connection_information\",\"cssClass\":null,\"listClass\":\"default\",\"isDefault\":\"N\",\"status\":\"0\",\"default\":false},{\"createBy\":\"hanzihang\",\"createTime\":\"2023-08-17 16:02:06\",\"updateBy\":null,\"updateTime\":null,\"remark\":\"密码\",\"dictCode\":229,\"dictSort\":4,\"dictLabel\":\"password\",\"dictValue\":\"zkqy8888\",\"dictType\":\"mysql_connection_information\",\"cssClass\":null,\"listClass\":\"default\",\"isDefault\":\"N\",\"status\":\"0\",\"default\":false},{\"createBy\":\"hanzihang\",\"createTime\":\"2023-08-17 16:02:38\",\"updateBy\":null,\"updateTime\":null,\"remark\":\"端口号\",\"dictCode\":230,\"dictSort\":5,\"dictLabel\":\"portNumber\",\"dictValue\":\"3306\",\"dictType\":\"mysql_connection_information\",\"cssClass\":null,\"listClass\":\"default\",\"isDefault\":\"N\",\"status\":\"0\",\"default\":false},{\"createBy\":\"hanzihang\",\"createTime\":\"2023-08-17 16:02:59\",\"updateBy\":null,\"updateTime\":null,\"remark\":\"数据库类型\",\"dictCode\":231,\"dictSort\":6,\"dictLabel\":\"databaseType\",\"dictValue\":\"mysql\",\"dictType\":\"mysql_connection_information\",\"cssClass\":null,\"listClass\":\"default\",\"isDefault\":\"N\",\"status\":\"0\",\"default\":false}]}";
        Map<String, List<Map<String, Object>>> asd = (Map<String, List<Map<String, Object>>>) JSON.parse(ret);


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

        asd.get("data").forEach(item -> {
            System.out.println(item);
        });

    }

}

/**
 * Type definition error:
 * [simple type, class dm.jdbc.c.a.a];
 * nested exception is com.fasterxml.jackson.databind.exc.InvalidDefinitionException:
 * No serializer found for class dm.jdbc.c.a.a and no properties discovered to create BeanSerializer (to avoid exception, disable SerializationFeature.FAIL_ON_EMPTY_BEANS) (through reference chain: com.ruoyi.common.core.domain.AjaxResult["data"]->com.ruoyi.system.entity.vo.DragTableVo["dtColumnName"]->dm.jdbc.driver.DmdbNClob["connection"]->dm.jdbc.driver.DmdbConnection["hd"]->dm.jdbc.c.a["kQ"])
 */