{"id":1483,"date":"2024-03-11T09:36:31","date_gmt":"2024-03-11T01:36:31","guid":{"rendered":"https:\/\/blog.ttwow.top\/?p=1483"},"modified":"2026-06-19T21:08:26","modified_gmt":"2026-06-19T13:08:26","slug":"%e6%a0%91%e7%bb%93%e6%9e%84%e5%ad%97%e5%85%b8%ef%bc%8c%e7%a1%ac%e5%86%99%e5%85%a5","status":"publish","type":"post","link":"https:\/\/blog.ttwow.top\/?p=1483","title":{"rendered":"\u6811\u7ed3\u6784\u5b57\u5178\uff0c\u786c\u5199\u5165"},"content":{"rendered":"<h3>\u786c\u5199\u5165\uff0c\u65e0\u7b97\u6cd5\u540e\u671f\u4f18\u5316<\/h3>\n<h2>sql\u6309\u7ea7\u522b\u67e5\u8be2<\/h2>\n<pre><code class=\"language-sql\">WITH RECURSIVE TreeLevel AS (\n            SELECT id, parent_id, tree_name, 1 AS level\n            FROM sys_classification_maintenance\n            WHERE parent_id = 0\n            UNION ALL\n            SELECT c.id, c.parent_id, c.tree_name, p.level + 1 AS level\n            FROM sys_classification_maintenance c\n                     INNER JOIN TreeLevel p ON c.parent_id = p.id\n        )\n        SELECT id, parent_id, tree_name, level\n        FROM TreeLevel\n        &lt;if test=&quot;level != null and level != &#039;&#039; &quot;&gt;\n            WHERE level = #{level}\n        &lt;\/if&gt;\n        ORDER BY level, id;<\/code><\/pre>\n<pre><code class=\"language-java\">\/\/ 1. \u8bfb\u53d6 Excel \u6587\u4ef6\nExcelReader reader = cn.hutool.poi.excel.ExcelUtil.getReader(&quot;C:\\\\Users\\\\\u5206\u7c7b.xlsx&quot;);\nList&lt;List&lt;Object&gt;&gt; rows = reader.read();\n\nfor (List&lt;Object&gt; row : rows) {\n    String level1 = row.get(0).toString();\n    List&lt;SysClassificationMaintenance&gt; list = sysClassificationMaintenanceService.dictFoodListForLevel(&quot;2&quot;);\n    SysClassificationMaintenance maintenance1 = list.stream().filter(e -&gt; e.getTreeName().equals(level1)).findFirst().orElse(null);\n\n    SysClassificationMaintenance maintenance11 = null;\n    if(maintenance1 == null){\n        SysClassificationMaintenance maintenance = new SysClassificationMaintenance();\n        maintenance.setParentId(1l);\n        maintenance.setTreeName(level1);\n        sysClassificationMaintenanceService.insertSysClassificationMaintenance(maintenance);\n\n        List&lt;SysClassificationMaintenance&gt; list11 = sysClassificationMaintenanceService.dictFoodListForLevel(&quot;2&quot;);\n        maintenance11 = list11.stream().filter(e -&gt; e.getTreeName().equals(level1)).findFirst().orElse(null);\n    }\n\n    SysClassificationMaintenance maintenance22 = null;\n    String level2 = row.get(1).toString();\n    List&lt;SysClassificationMaintenance&gt; list2 = sysClassificationMaintenanceService.dictFoodListForLevel(&quot;3&quot;);\n    SysClassificationMaintenance maintenance2 = list2.stream().filter(e -&gt; e.getTreeName().equals(level2)).findFirst().orElse(null);\n    if(maintenance2 == null){\n        SysClassificationMaintenance maintenance = new SysClassificationMaintenance();\n        if(maintenance1 == null){\n            maintenance.setParentId(maintenance11.getId());\n        }else {\n            maintenance.setParentId(maintenance1.getId());\n        }\n        maintenance.setTreeName(level2);\n        sysClassificationMaintenanceService.insertSysClassificationMaintenance(maintenance);\n\n        List&lt;SysClassificationMaintenance&gt; list22 = sysClassificationMaintenanceService.dictFoodListForLevel(&quot;3&quot;);\n        maintenance22 = list22.stream().filter(e -&gt; e.getTreeName().equals(level2)).findFirst().orElse(null);\n\n    }\n\n    SysClassificationMaintenance maintenance33 = null;\n    String level3 = row.get(2).toString();\n    List&lt;SysClassificationMaintenance&gt; list3 = sysClassificationMaintenanceService.dictFoodListForLevel(&quot;4&quot;);\n    SysClassificationMaintenance maintenance3 = list3.stream().filter(e -&gt; e.getTreeName().equals(level3)).findFirst().orElse(null);\n    if(maintenance3 == null){\n        SysClassificationMaintenance maintenance = new SysClassificationMaintenance();\n        if(maintenance2 == null){\n            maintenance.setParentId(maintenance22.getId());\n        }else {\n            maintenance.setParentId(maintenance2.getId());\n        }\n\n        maintenance.setTreeName(level3);\n        sysClassificationMaintenanceService.insertSysClassificationMaintenance(maintenance);\n\n        List&lt;SysClassificationMaintenance&gt; list33 = sysClassificationMaintenanceService.dictFoodListForLevel(&quot;4&quot;);\n        maintenance33 = list33.stream().filter(e -&gt; e.getTreeName().equals(level3)).findFirst().orElse(null);\n\n    }\n\n    String level4 = row.get(3).toString();\n    List&lt;SysClassificationMaintenance&gt; list4 = sysClassificationMaintenanceService.dictFoodListForLevel(&quot;5&quot;);\n    SysClassificationMaintenance maintenance4 = list4.stream().filter(e -&gt; e.getTreeName().equals(level4)).findFirst().orElse(null);\n    if(maintenance4 == null){\n        SysClassificationMaintenance maintenance = new SysClassificationMaintenance();\n        if(maintenance3 == null){\n            maintenance.setParentId(maintenance33.getId());\n        }else {\n            maintenance.setParentId(maintenance3.getId());\n        }\n\n        maintenance.setTreeName(level4);\n        sysClassificationMaintenanceService.insertSysClassificationMaintenance(maintenance);\n    }\n\n}\n\nreturn null;\n}<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u786c\u5199\u5165\uff0c\u65e0\u7b97\u6cd5\u540e\u671f\u4f18\u5316 sql\u6309\u7ea7\u522b\u67e5\u8be2 WITH RECURSIVE TreeLevel AS ( SELE [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[135],"tags":[158],"class_list":["post-1483","post","type-post","status-publish","format-standard","hentry","category-code-snippets","tag-tree"],"_links":{"self":[{"href":"https:\/\/blog.ttwow.top\/index.php?rest_route=\/wp\/v2\/posts\/1483","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.ttwow.top\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.ttwow.top\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.ttwow.top\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.ttwow.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1483"}],"version-history":[{"count":4,"href":"https:\/\/blog.ttwow.top\/index.php?rest_route=\/wp\/v2\/posts\/1483\/revisions"}],"predecessor-version":[{"id":1487,"href":"https:\/\/blog.ttwow.top\/index.php?rest_route=\/wp\/v2\/posts\/1483\/revisions\/1487"}],"wp:attachment":[{"href":"https:\/\/blog.ttwow.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1483"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.ttwow.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1483"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.ttwow.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1483"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}