{"id":1635,"date":"2025-12-11T16:11:35","date_gmt":"2025-12-11T08:11:35","guid":{"rendered":"https:\/\/blog.ttwow.top\/?p=1635"},"modified":"2026-06-19T21:59:39","modified_gmt":"2026-06-19T13:59:39","slug":"mysql-sortpaix","status":"publish","type":"post","link":"https:\/\/blog.ttwow.top\/?p=1635","title":{"rendered":"java \u6587\u4ef6\u751f\u6210\u5de5\u5177\u7c7b"},"content":{"rendered":"<h2>\u52a0\u8f7d\u6587\u4ef6<\/h2>\n<pre><code class=\"language-java\">       InputStream file = null;\n        try {\n            ClassPathResource classPathResource = new ClassPathResource(\"ab155\/\" + gameType + \"\/attr\");\n            file = classPathResource.getInputStream();\n            return IOUtils.toString(file, StandardCharsets.UTF_8);\n        } catch (Exception e) {\n            e.printStackTrace();\n        }\n        return null;<\/code><\/pre>\n<h2>\u52a0\u8f7d\u6587\u4ef6\u6587\u4ef6\u5939\u4e0b\u7b2c\u4e00\u4e2a\u6587\u4ef6<\/h2>\n<pre><code class=\"language-java\">        try {\n            ClassPathResource dirResource = new ClassPathResource(\"ab157\/\" + gameType + \"\/\");\n            File dir = dirResource.getFile();\n            File[] files = dir.listFiles();\n            if (files == null || files.length == 0) {\n                System.err.println(\"\u76ee\u5f55\u4e3a\u7a7a: \" + dir.getAbsolutePath());\n                return null;\n            }\n            File firstFile = files[0];\n            return IOUtils.toString(\n                    new FileInputStream(firstFile),\n                    StandardCharsets.UTF_8\n            );\n        } catch (Exception e) {\n            e.printStackTrace();\n        }<\/code><\/pre>\n<h2>\u904d\u5386\u6587\u4ef6<\/h2>\n<pre><code class=\"language-java\">public static void genNote(){\n            String basePath = \"D:\\\\code\\\\\";\n            String savePath = basePath + \"tt.txt\";\n            Path path = Paths.get(basePath);\n            StringBuilder stringBuilder = new StringBuilder();\n            try (Stream<Path> paths = Files.walk(path)) {\n                paths.filter(Files::isRegularFile)  \/\/ \u53ea\u83b7\u53d6\u6587\u4ef6\uff0c\u6392\u9664\u76ee\u5f55\n                        .forEach(filePath -> {\n                            System.out.println(\"\u6587\u4ef6: \" + filePath.toString());\n                            try {\n                                String s = FileUtils.readFileToString(new File(filePath.toString()), \"utf-8\");\n                                JSONObject jsonObject = JSONObject.parseObject(s);\n                                String gameName = jsonObject.getString(\"gameName\");\n                                stringBuilder.append(\"\\n\");\n                                stringBuilder.append(gameName + \" --------------\");\n                                stringBuilder.append(\"\\n\");\n                                JSONArray templateArr = jsonObject.getJSONArray(\"templates\");\n                                for (int i = 0; i < templateArr.size(); i++) {\n                                    JSONObject jsonObject1 = JSONObject.parseObject(templateArr.get(i).toString());\n                                    String id = jsonObject1.getString(\"id\");\n                                    String field_name = jsonObject1.getString(\"field_name\");\n                                    String field_type = jsonObject1.getString(\"field_type\");\n                                    String is_required = jsonObject1.getString(\"is_required\");\n\n                                    stringBuilder.append(\"\\t\\t\\t\\t\");\n                                    stringBuilder.append( \"\/\/ \" + field_name  +\"  \" + id  +\"   \" + field_type );\n                                    if(is_required.equals(\"true\")){\n                                        stringBuilder.append( \"  is_required : \" + is_required);\n                                    }\n                                    if(\"input\".equals(field_type) || \"number\".equals(field_type)){\n                                        stringBuilder.append(\"\\n\");\n                                        stringBuilder.append(\"\\t\\t\\t\\t\");\n                                        stringBuilder.append( \"util157.addDataValues(gameData,\"+id+\",sysRecovery,jsonObject.getString(\\\" \\\"));\");\n                                    } else if (\"checkbox\".equals(field_type)) {\n                                        stringBuilder.append(\"\\n\");\n                                        stringBuilder.append(\"\\t\\t\\t\\t\");\n                                        stringBuilder.append( \"util157.addDataValues(gameData,\"+id+\",sysRecovery,null);\");\n                                    }\n                                    stringBuilder.append(\"\\n\\n\");\n                                }\n                                stringBuilder.append(\"\\n\");\n                            } catch (IOException e) {\n                                throw new RuntimeException(e);\n                            }\n\n                        });\n            } catch (IOException e) {\n                e.printStackTrace();\n            }\n\n        try {\n            FileUtils.writeStringToFile(new File(savePath), stringBuilder.toString(), StandardCharsets.UTF_8);\n        } catch (IOException e) {\n            throw new RuntimeException(e);\n        }\n    }<\/code><\/pre>\n<h2>\u751f\u6210json\u6587\u4ef6<\/h2>\n<pre><code class=\"language-java\">public void tt() {\n        List<GameInfo> gameInfos = gameInfoMapper.selectGameInfoList(new GameInfo());\n        JSONArray allGames = new JSONArray();\n\n        for (GameInfo gameInfo : gameInfos) {\n            JSONObject finalJson = new JSONObject();\n            finalJson.put(\"gameId\", gameInfo.getId());\n            finalJson.put(\"gameName\", gameInfo.getName());\n\n            \/\/ \u67e5\u8be2\u6a21\u677f\n            GameAttrTemplate tpl1 = new GameAttrTemplate();\n            tpl1.setFieldType(\"radio\");\n            tpl1.setGameId(gameInfo.getId());\n            List<GameAttrTemplate> list1 = gameAttrTemplateMapper.selectGameAttrTemplateList(tpl1);\n\n            GameAttrTemplate tpl2 = new GameAttrTemplate();\n            tpl2.setFieldType(\"boxradio\");\n            tpl2.setGameId(gameInfo.getId());\n            List<GameAttrTemplate> list2 = gameAttrTemplateMapper.selectGameAttrTemplateList(tpl2);\n\n            List<GameAttrTemplate> templateList = new ArrayList<>();\n            if (list1 != null) templateList.addAll(list1);\n            if (list2 != null) templateList.addAll(list2);\n\n            if (templateList.isEmpty()) {\n                System.out.println(\"empty templates for game \" + gameInfo.getId());\n                continue; \/\/ \u4e0d return\n            }\n\n            JSONObject groupJson = new JSONObject();\n            for (GameAttrTemplate tpl : templateList) {\n                Long groupId = tpl.getAttributeId();\n                String groupName = tpl.getFieldName();\n\n                GameAttribute query = new GameAttribute();\n                query.setParentId(groupId);\n                List<GameAttribute> attrList = gameAttributeMapper.selectGameAttributeList(query);\n\n                if (attrList == null || attrList.isEmpty()) continue;\n\n                \/\/ \u6bcf\u4e2a group \u662f key-value \u5bf9\u8c61\n                JSONObject data = new JSONObject();\n                for (GameAttribute attr : attrList) {\n                    data.put(attr.getId().toString(), attr.getFieldName());\n                }\n\n                groupJson.put(groupName, data);\n            }\n\n            finalJson.put(\"data\", groupJson);\n            allGames.add(finalJson);\n        }\n\n        System.out.println(allGames.toJSONString());\n        FileUtil.writeUtf8String(allGames.toJSONString(), \"tt\");\n\n    }\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u52a0\u8f7d\u6587\u4ef6 InputStream file = null; try { ClassPathResource c [&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":[],"class_list":["post-1635","post","type-post","status-publish","format-standard","hentry","category-code-snippets"],"_links":{"self":[{"href":"https:\/\/blog.ttwow.top\/index.php?rest_route=\/wp\/v2\/posts\/1635","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=1635"}],"version-history":[{"count":8,"href":"https:\/\/blog.ttwow.top\/index.php?rest_route=\/wp\/v2\/posts\/1635\/revisions"}],"predecessor-version":[{"id":1644,"href":"https:\/\/blog.ttwow.top\/index.php?rest_route=\/wp\/v2\/posts\/1635\/revisions\/1644"}],"wp:attachment":[{"href":"https:\/\/blog.ttwow.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1635"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.ttwow.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1635"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.ttwow.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1635"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}